Skip to content

Commit 7e6f934

Browse files
committed
Fix some ILM tests for searchable snapshots
These tests are very prone to the "quiet test cluster syndrome" and sometimes need a little push by means of some artificial cluster state updates. To hopefully be done with these test failures once and for all (famous last words), I've updated all tests in this class to trigger cluster state updates where necessary. This is basically a follow-up of #108162. Fixes #125683 Fixes #125789
1 parent 37f6ebe commit 7e6f934

File tree

2 files changed

+29
-80
lines changed

2 files changed

+29
-80
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,6 @@ tests:
368368
- class: org.elasticsearch.packaging.test.DockerTests
369369
method: test010Install
370370
issue: https://github.com/elastic/elasticsearch/issues/125680
371-
- class: org.elasticsearch.xpack.ilm.actions.SearchableSnapshotActionIT
372-
method: testSearchableSnapshotsInHotPhasePinnedToHotNodes
373-
issue: https://github.com/elastic/elasticsearch/issues/125683
374371
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
375372
method: test {p0=cat.allocation/10_basic/Node forecasts}
376373
issue: https://github.com/elastic/elasticsearch/issues/125711

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java

Lines changed: 29 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ public void testSearchableSnapshotAction() throws Exception {
106106
assertThat(backingIndices.size(), equalTo(2));
107107
String backingIndexName = backingIndices.getFirst();
108108
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
109-
assertTrue(waitUntil(() -> {
110-
try {
111-
return indexExists(restoredIndexName);
112-
} catch (IOException e) {
113-
return false;
114-
}
115-
}, 30, TimeUnit.SECONDS));
109+
waitForIndexToExist(restoredIndexName, 30);
116110

117111
assertBusy(() -> {
118112
triggerStateChange();
@@ -146,6 +140,7 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio
146140
updateIndexSettings(dataStream, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
147141
assertTrue(waitUntil(() -> {
148142
try {
143+
triggerStateChange();
149144
Integer numberOfSegments = getNumberOfPrimarySegments(client(), backingIndexName);
150145
logger.info("index {} has {} segments", backingIndexName, numberOfSegments);
151146
// this is a loose assertion here as forcemerge is best effort
@@ -166,13 +161,7 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio
166161
}, 60, TimeUnit.SECONDS));
167162

168163
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
169-
assertTrue(waitUntil(() -> {
170-
try {
171-
return indexExists(restoredIndexName);
172-
} catch (IOException e) {
173-
return false;
174-
}
175-
}, 60, TimeUnit.SECONDS));
164+
waitForIndexToExist(restoredIndexName, 60);
176165

177166
assertBusy(() -> {
178167
triggerStateChange();
@@ -221,6 +210,7 @@ public void testDeleteActionDeletesSearchableSnapshot() throws Exception {
221210

222211
assertTrue("the snapshot we generate in the cold phase should be deleted by the delete phase", waitUntil(() -> {
223212
try {
213+
triggerStateChange();
224214
Request getSnapshotsRequest = new Request("GET", "_snapshot/" + snapshotRepo + "/_all");
225215
Response getSnapshotsResponse = client().performRequest(getSnapshotsRequest);
226216

@@ -306,13 +296,7 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
306296

307297
var backingIndices = getDataStreamBackingIndexNames(dataStream);
308298
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndices.get(0);
309-
assertTrue(waitUntil(() -> {
310-
try {
311-
return indexExists(restoredIndexName);
312-
} catch (IOException e) {
313-
return false;
314-
}
315-
}, 30, TimeUnit.SECONDS));
299+
waitForIndexToExist(restoredIndexName, 30);
316300

317301
assertBusy(() -> {
318302
triggerStateChange();
@@ -385,13 +369,7 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
385369

386370
String backingIndexName = getDataStreamBackingIndexNames(dataStream).getFirst();
387371
String searchableSnapMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
388-
assertTrue(waitUntil(() -> {
389-
try {
390-
return indexExists(searchableSnapMountedIndexName);
391-
} catch (IOException e) {
392-
return false;
393-
}
394-
}, 30, TimeUnit.SECONDS));
372+
waitForIndexToExist(searchableSnapMountedIndexName, 30);
395373

396374
assertBusy(() -> {
397375
triggerStateChange();
@@ -442,6 +420,7 @@ public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Ex
442420

443421
// the restored index is now managed by the now updated ILM policy and needs to go through the warm and cold phase
444422
assertBusy(() -> {
423+
triggerStateChange();
445424
Step.StepKey stepKeyForIndex;
446425
try {
447426
stepKeyForIndex = getStepKeyForIndex(client(), searchableSnapMountedIndexName);
@@ -493,10 +472,7 @@ public void testIdenticalSearchableSnapshotActionIsNoop() throws Exception {
493472

494473
final String searchableSnapMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index;
495474

496-
assertBusy(() -> {
497-
logger.info("--> waiting for [{}] to exist...", searchableSnapMountedIndexName);
498-
assertTrue(indexExists(searchableSnapMountedIndexName));
499-
}, 30, TimeUnit.SECONDS);
475+
waitForIndexToExist(searchableSnapMountedIndexName, 30);
500476

501477
assertBusy(() -> {
502478
triggerStateChange();
@@ -555,10 +531,7 @@ public void testConvertingSearchableSnapshotFromFullToPartial() throws Exception
555531
final String searchableSnapMountedIndexName = SearchableSnapshotAction.PARTIAL_RESTORED_INDEX_PREFIX
556532
+ SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index;
557533

558-
assertBusy(() -> {
559-
logger.info("--> waiting for [{}] to exist...", searchableSnapMountedIndexName);
560-
assertTrue(indexExists(searchableSnapMountedIndexName));
561-
}, 30, TimeUnit.SECONDS);
534+
waitForIndexToExist(searchableSnapMountedIndexName, 30);
562535

563536
assertBusy(() -> {
564537
triggerStateChange();
@@ -638,10 +611,7 @@ public void testResumingSearchableSnapshotFromFullToPartial() throws Exception {
638611

639612
final String fullMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index;
640613

641-
assertBusy(() -> {
642-
logger.info("--> waiting for [{}] to exist...", fullMountedIndexName);
643-
assertTrue(indexExists(fullMountedIndexName));
644-
}, 30, TimeUnit.SECONDS);
614+
waitForIndexToExist(fullMountedIndexName, 30);
645615

646616
assertBusy(() -> {
647617
triggerStateChange();
@@ -659,10 +629,7 @@ public void testResumingSearchableSnapshotFromFullToPartial() throws Exception {
659629
// add cold-frozen
660630
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policyFrozen));
661631
String partiallyMountedIndexName = SearchableSnapshotAction.PARTIAL_RESTORED_INDEX_PREFIX + fullMountedIndexName;
662-
assertBusy(() -> {
663-
logger.info("--> waiting for [{}] to exist...", partiallyMountedIndexName);
664-
assertTrue(indexExists(partiallyMountedIndexName));
665-
}, 30, TimeUnit.SECONDS);
632+
waitForIndexToExist(partiallyMountedIndexName, 30);
666633

667634
assertBusy(() -> {
668635
triggerStateChange();
@@ -693,6 +660,7 @@ public void testResumingSearchableSnapshotFromFullToPartial() throws Exception {
693660
);
694661
assertBusy(() -> {
695662
logger.info("--> waiting for [{}] to be deleted...", partiallyMountedIndexName);
663+
triggerStateChange();
696664
assertThat(indexExists(partiallyMountedIndexName), is(false));
697665
Request getSnaps = new Request("GET", "/_snapshot/" + snapshotRepo + "/_all");
698666
Map<String, Object> responseMap = responseAsMap(client().performRequest(getSnaps));
@@ -749,10 +717,7 @@ public void testResumingSearchableSnapshotFromPartialToFull() throws Exception {
749717
final String fullMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index;
750718
final String partialMountedIndexName = SearchableSnapshotAction.PARTIAL_RESTORED_INDEX_PREFIX + fullMountedIndexName;
751719

752-
assertBusy(() -> {
753-
logger.info("--> waiting for [{}] to exist...", partialMountedIndexName);
754-
assertTrue(indexExists(partialMountedIndexName));
755-
}, 30, TimeUnit.SECONDS);
720+
waitForIndexToExist(partialMountedIndexName, 30);
756721

757722
assertBusy(() -> {
758723
triggerStateChange();
@@ -770,10 +735,7 @@ public void testResumingSearchableSnapshotFromPartialToFull() throws Exception {
770735
// add a policy that will only include the fully mounted searchable snapshot
771736
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policyCold));
772737
String restoredPartiallyMountedIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + partialMountedIndexName;
773-
assertBusy(() -> {
774-
logger.info("--> waiting for [{}] to exist...", restoredPartiallyMountedIndexName);
775-
assertTrue(indexExists(restoredPartiallyMountedIndexName));
776-
}, 30, TimeUnit.SECONDS);
738+
waitForIndexToExist(restoredPartiallyMountedIndexName, 30);
777739

778740
assertBusy(() -> {
779741
triggerStateChange();
@@ -800,6 +762,7 @@ public void testResumingSearchableSnapshotFromPartialToFull() throws Exception {
800762
);
801763
assertBusy(() -> {
802764
logger.info("--> waiting for [{}] to be deleted...", restoredPartiallyMountedIndexName);
765+
triggerStateChange();
803766
assertThat(indexExists(restoredPartiallyMountedIndexName), is(false));
804767
Request getSnaps = new Request("GET", "/_snapshot/" + snapshotRepo + "/_all");
805768
Map<String, Object> responseMap = responseAsMap(client().performRequest(getSnaps));
@@ -882,15 +845,11 @@ public void testSearchableSnapshotsInHotPhasePinnedToHotNodes() throws Exception
882845
indexDocument(client(), dataStream, true);
883846

884847
final String restoredIndex = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + firstGenIndex;
848+
waitForIndexToExist(restoredIndex, 30);
885849
assertBusy(() -> {
886-
logger.info("--> waiting for [{}] to exist...", restoredIndex);
887-
assertTrue(indexExists(restoredIndex));
850+
triggerStateChange();
851+
assertThat(getStepKeyForIndex(client(), restoredIndex), is(PhaseCompleteStep.finalStep("hot").getKey()));
888852
}, 30, TimeUnit.SECONDS);
889-
assertBusy(
890-
() -> assertThat(getStepKeyForIndex(client(), restoredIndex), is(PhaseCompleteStep.finalStep("hot").getKey())),
891-
30,
892-
TimeUnit.SECONDS
893-
);
894853

895854
Map<String, Object> hotIndexSettings = getIndexSettingsAsMap(restoredIndex);
896855
// searchable snapshots mounted in the hot phase should be pinned to hot nodes
@@ -928,13 +887,7 @@ public void testSearchableSnapshotInvokesAsyncActionOnNewIndex() throws Exceptio
928887
assertThat(backingIndices.size(), equalTo(2));
929888
String backingIndexName = backingIndices.getFirst();
930889
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
931-
assertTrue(waitUntil(() -> {
932-
try {
933-
return indexExists(restoredIndexName);
934-
} catch (IOException e) {
935-
return false;
936-
}
937-
}, 30, TimeUnit.SECONDS));
890+
waitForIndexToExist(restoredIndexName, 30);
938891

939892
assertBusy(() -> {
940893
triggerStateChange();
@@ -975,10 +928,7 @@ public void testSearchableSnapshotTotalShardsPerNode() throws Exception {
975928
// wait for snapshot successfully mounted and ILM execution completed
976929
final String searchableSnapMountedIndexName = SearchableSnapshotAction.PARTIAL_RESTORED_INDEX_PREFIX
977930
+ SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + index;
978-
assertBusy(() -> {
979-
logger.info("--> waiting for [{}] to exist...", searchableSnapMountedIndexName);
980-
assertTrue(indexExists(searchableSnapMountedIndexName));
981-
}, 30, TimeUnit.SECONDS);
931+
waitForIndexToExist(searchableSnapMountedIndexName, 30);
982932
assertBusy(() -> {
983933
triggerStateChange();
984934
Step.StepKey stepKeyForIndex = getStepKeyForIndex(client(), searchableSnapMountedIndexName);
@@ -1034,13 +984,7 @@ public void testSearchableSnapshotReplicateFor() throws Exception {
1034984
assertThat(backingIndices.size(), equalTo(2));
1035985
String backingIndexName = backingIndices.getFirst();
1036986
String restoredIndexName = SearchableSnapshotAction.FULL_RESTORED_INDEX_PREFIX + backingIndexName;
1037-
assertTrue(waitUntil(() -> {
1038-
try {
1039-
return indexExists(restoredIndexName);
1040-
} catch (IOException e) {
1041-
return false;
1042-
}
1043-
}, 30, TimeUnit.SECONDS));
987+
waitForIndexToExist(restoredIndexName, 30);
1044988

1045989
// check that the index is in the expected step and has the expected step_info.message
1046990
assertBusy(() -> {
@@ -1097,6 +1041,14 @@ public void testSearchableSnapshotReplicateFor() throws Exception {
10971041
}
10981042
}
10991043

1044+
private void waitForIndexToExist(String indexName, int timeoutInSeconds) throws Exception {
1045+
assertBusy(() -> {
1046+
logger.info("--> waiting for [{}] to exist...", indexName);
1047+
triggerStateChange();
1048+
assertTrue(indexExists(indexName));
1049+
}, timeoutInSeconds, TimeUnit.SECONDS);
1050+
}
1051+
11001052
/**
11011053
* Cause a bit of cluster activity using an empty reroute call in case the `wait-for-index-colour` ILM step missed the
11021054
* notification that partial-index is now GREEN.

0 commit comments

Comments
 (0)