Skip to content

Commit 094d17e

Browse files
Make unwrapCorrupt Check Suppressed Ex.
* As discussed in elastic#24800 we want to check for suppressed corruption indicating exceptions here as well to more reliably categorize corruption related exceptions * Closes elastic#24800, 41201
1 parent d94b147 commit 094d17e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

server/src/main/java/org/elasticsearch/ExceptionsHelper.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,17 @@ public static <T extends Throwable> T useOrSuppress(T first, T second) {
176176
}
177177

178178
public static IOException unwrapCorruption(Throwable t) {
179-
return (IOException) unwrap(t, CorruptIndexException.class,
180-
IndexFormatTooOldException.class,
181-
IndexFormatTooNewException.class);
179+
IOException corruptionException =
180+
(IOException) unwrap(t, CorruptIndexException.class, IndexFormatTooOldException.class, IndexFormatTooNewException.class);
181+
if (corruptionException == null && t != null) {
182+
for (Throwable suppressed : t.getSuppressed()) {
183+
corruptionException = unwrapCorruption(suppressed);
184+
if (corruptionException != null) {
185+
return corruptionException;
186+
}
187+
}
188+
}
189+
return corruptionException;
182190
}
183191

184192
public static Throwable unwrap(Throwable t, Class<?>... clazzes) {

server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,12 @@ protected void failEngine(IOException cause) {
438438
handler.sendFiles(store, metas.toArray(new StoreFileMetaData[0]), () -> 0);
439439
fail("exception index");
440440
} catch (RuntimeException ex) {
441-
assertNull(ExceptionsHelper.unwrapCorruption(ex));
441+
final IOException unwrappedCorruption = ExceptionsHelper.unwrapCorruption(ex);
442442
if (throwCorruptedIndexException) {
443+
assertNotNull(unwrappedCorruption);
443444
assertEquals(ex.getMessage(), "[File corruption occurred on recovery but checksums are ok]");
444445
} else {
446+
assertNull(unwrappedCorruption);
445447
assertEquals(ex.getMessage(), "boom");
446448
}
447449
} catch (CorruptIndexException ex) {

0 commit comments

Comments
 (0)