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
This commit is contained in:
Francisco Fernández Castaño 2020-08-19 19:28:47 +02:00 committed by GitHub
parent 1182248994
commit 89a7f32100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -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));
});