move reading opSize into the catch block to transform EOF into TruncatedTranslogException

This commit is contained in:
Simon Willnauer 2015-05-13 21:12:54 +02:00
parent 19155d8fd8
commit 91cfba3485
1 changed files with 7 additions and 6 deletions

View File

@ -1574,16 +1574,17 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
}
static Translog.Operation readOperation(BufferedChecksumStreamInput in) throws IOException {
final int opSize = in.readInt();
if (opSize < 4) { // 4byte for the checksum
throw new TranslogCorruptedException("operation size must be at least 4 but was: " + opSize);
}
Translog.Operation operation;
try {
final int opSize = in.readInt();
if (opSize < 4) { // 4byte for the checksum
throw new AssertionError("operation size must be at least 4 but was: " + opSize);
}
in.resetDigest(); // size is not part of the checksum!
if (in.markSupported()) { // if we can we validate the checksum first
// we are sometimes called when mark is not supported this is the case when
// we are sending translogs across the network - currently there is no way to prevent this unfortunately.
// we are sending translogs across the network with LZ4 compression enabled - currently there is no way s
// to prevent this unfortunately.
in.mark(opSize);
in.skip(opSize-4);
@ -1596,7 +1597,7 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
verifyChecksum(in);
} catch (EOFException e) {
throw new TruncatedTranslogException("reached premature end of file, translog is truncated", e);
} catch (AssertionError|Exception e) {
} catch (AssertionError | Exception e) {
throw new TranslogCorruptedException("translog corruption while reading from stream", e);
}
return operation;