Skip to content

Commit 36b887e

Browse files
authored
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
1 parent f5b07e4 commit 36b887e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/src/main/java/org/elasticsearch/index/translog/Translog.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ static Translog.Operation readOperation(BufferedChecksumStreamInput in) throws I
11281128
try {
11291129
final int opSize = in.readInt();
11301130
if (opSize < 4) { // 4byte for the checksum
1131-
throw new AssertionError("operation size must be at least 4 but was: " + opSize);
1131+
throw new TranslogCorruptedException("operation size must be at least 4 but was: " + opSize);
11321132
}
11331133
in.resetDigest(); // size is not part of the checksum!
11341134
if (in.markSupported()) { // if we can we validate the checksum first
@@ -1143,10 +1143,10 @@ static Translog.Operation readOperation(BufferedChecksumStreamInput in) throws I
11431143
}
11441144
operation = Translog.Operation.readType(in);
11451145
verifyChecksum(in);
1146+
} catch (TranslogCorruptedException e) {
1147+
throw e;
11461148
} catch (EOFException e) {
11471149
throw new TruncatedTranslogException("reached premature end of file, translog is truncated", e);
1148-
} catch (AssertionError | Exception e) {
1149-
throw new TranslogCorruptedException("translog corruption while reading from stream", e);
11501150
}
11511151
return operation;
11521152
}

0 commit comments

Comments
 (0)