Throw translog corrupted exception on malformed op
Today when reading a malformed operation from the translog, we throw an assertion error that is immediately caught and wrapped into a translog corrupted exception. This commit replaces this by electing to directly throw a translog corrupted exception instead. Additionally, this cleanup also addressed a double-wrapped translog corrupted exception. Namely, verifying the checksum can throw a translog corrupted exception which the existing code would catch and wrap again in a translog corrupted exception. Relates #19256
This commit is contained in:
parent
f5b07e438f
commit
36b887ee7c
|
@ -1128,7 +1128,7 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|||
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);
|
||||
throw new TranslogCorruptedException("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
|
||||
|
@ -1143,10 +1143,10 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC
|
|||
}
|
||||
operation = Translog.Operation.readType(in);
|
||||
verifyChecksum(in);
|
||||
} catch (TranslogCorruptedException e) {
|
||||
throw e;
|
||||
} catch (EOFException e) {
|
||||
throw new TruncatedTranslogException("reached premature end of file, translog is truncated", e);
|
||||
} catch (AssertionError | Exception e) {
|
||||
throw new TranslogCorruptedException("translog corruption while reading from stream", e);
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue