Skip to content

Commit f9060c5

Browse files
atrisjainankitk
authored andcommitted
Fix LocalTranslogTests handling of corrupted translog recovery (opensearch-project#19177)
Partial writes can corrupt translog files during simulated failures. When recovering these files, TranslogCorruptedException is thrown but wasn't caught since it extends OpenSearchException, not TranslogException. Add TranslogCorruptedException to catch blocks alongside other expected exceptions during translog recovery attempts. Signed-off-by: Atri Sharma <atri.jiit@gmail.com> Signed-off-by: Ankit Jain <jainankitk@apache.org>
1 parent 9f74249 commit f9060c5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

server/src/test/java/org/opensearch/index/translog/LocalTranslogTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,8 +3368,8 @@ public void testWithRandomException() throws IOException {
33683368
localCheckpointOfSafeCommit = failableTLog.getDeletionPolicy().getLocalCheckpointOfSafeCommit();
33693369
IOUtils.closeWhileHandlingException(failableTLog);
33703370
}
3371-
} catch (TranslogException | MockDirectoryWrapper.FakeIOException ex) {
3372-
// failed - that's ok, we didn't even create it
3371+
} catch (TranslogException | MockDirectoryWrapper.FakeIOException | TranslogCorruptedException ex) {
3372+
// failed - that's ok, we didn't even create it or it was corrupted from partial writes
33733373
} catch (IOException ex) {
33743374
assertEquals(ex.getMessage(), "__FAKE__ no space left on device");
33753375
}
@@ -3379,8 +3379,8 @@ public void testWithRandomException() throws IOException {
33793379
TranslogDeletionPolicy deletionPolicy = createTranslogDeletionPolicy();
33803380
deletionPolicy.setLocalCheckpointOfSafeCommit(localCheckpointOfSafeCommit);
33813381
IOUtils.close(getFailableTranslog(fail, config, randomBoolean(), false, generationUUID, deletionPolicy));
3382-
} catch (TranslogException | MockDirectoryWrapper.FakeIOException ex) {
3383-
// failed - that's ok, we didn't even create it
3382+
} catch (TranslogException | MockDirectoryWrapper.FakeIOException | TranslogCorruptedException ex) {
3383+
// failed - that's ok, we didn't even create it or it was corrupted from partial writes
33843384
} catch (IOException ex) {
33853385
assertEquals(ex.getMessage(), "__FAKE__ no space left on device");
33863386
}

0 commit comments

Comments
 (0)