mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Raise IOException or ChronicleHashRecoveryFailed exception instead of generic RuntimeException in VanillaChronileHash.initBeforeMapping() method
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user