Raise IOException or ChronicleHashRecoveryFailed exception instead of generic RuntimeException in VanillaChronileHash.initBeforeMapping() method

This commit is contained in:
leventov
2016-02-09 14:46:18 +07:00
parent 189d40d1ca
commit 001b710084
2 changed files with 13 additions and 12 deletions
@@ -382,7 +382,7 @@ public abstract class VanillaChronicleHash<K,
}
}
public final void initBeforeMapping(File file, FileChannel ch, long headerEnd)
public final void initBeforeMapping(File file, FileChannel ch, long headerEnd, boolean recover)
throws IOException {
this.headerSize = roundUpMapHeaderSize(headerEnd);
if (!createdOrInMemory) {
@@ -394,7 +394,7 @@ public abstract class VanillaChronicleHash<K,
if (ch.read(globalMutableStateBuffer,
this.headerSize + GLOBAL_MUTABLE_STATE_VALUE_OFFSET +
globalMutableStateBuffer.position()) == -1) {
throw new RuntimeException(file + " truncated");
throw throwRecoveryOrReturnIOException(file + " truncated", recover);
}
}
globalMutableStateBuffer.flip();
@@ -404,6 +404,14 @@ public abstract class VanillaChronicleHash<K,
}
}
public static IOException throwRecoveryOrReturnIOException(String message, boolean recover) {
if (recover) {
throw new ChronicleHashRecoveryFailedException(message);
} else {
return new IOException(message);
}
}
private static long roundUpMapHeaderSize(long headerSize) {
return CACHE_LINES.align(headerSize, BYTES);
}