From 89a7f32100a5b5d1d1d87f9ff3b31c1d97339ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Fern=C3=A1ndez=20Casta=C3=B1o?= Date: Wed, 19 Aug 2020 19:28:47 +0200 Subject: [PATCH] Fix SearchableSnapshotDirectoryTests#testRecoveryStateIsKeptOpenAfterPreWarmFailure (#61343) The test didn't take into account the case where 0 documents are indexed into the shard, meaning that files aren't loaded during the pre-warm phase. The test injects FileSystem failures, if the snapshot doesn't contain any files, pre-warm doesn't read any files and the recovery completes normally. Closes #61295 Backport of #61317 --- .../index/store/SearchableSnapshotDirectoryTests.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java index feabc88f6f7..e8886df30f3 100644 --- a/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java +++ b/x-pack/plugin/searchable-snapshots/src/test/java/org/elasticsearch/index/store/SearchableSnapshotDirectoryTests.java @@ -776,7 +776,16 @@ public class SearchableSnapshotDirectoryTests extends ESTestCase { try { SearchableSnapshotRecoveryState recoveryState = createRecoveryState(); testDirectories(true, true, recoveryState, Settings.EMPTY, (directory, snapshotDirectory) -> { - assertBusy(() -> assertThat(recoveryState.getStage(), equalTo(RecoveryState.Stage.FINALIZE))); + boolean areAllFilesReused = snapshotDirectory.snapshot() + .indexFiles() + .stream() + .allMatch(fileInfo -> fileInfo.metadata().hashEqualsContents()); + assertBusy(() -> { + // When the number of indexed documents == 0, the index snapshot only contains the + // commit file, meaning that the recovery won't fail in that case. + RecoveryState.Stage expectedStage = areAllFilesReused ? RecoveryState.Stage.DONE : RecoveryState.Stage.FINALIZE; + assertThat(recoveryState.getStage(), equalTo(expectedStage)); + }); // All pre-warm tasks failed assertThat(recoveryState.getIndex().recoveredBytes(), equalTo(0L)); });