@@ -156,7 +156,7 @@ public void testSearchableSnapshotForceMergesClonedIndex() throws Exception {
156156 configureClusterAllocation (true );
157157 }
158158
159- assertForceMergedSnapshotDone (phase , backingIndexName , numberOfPrimaries > 1 , true );
159+ assertForceMergedSnapshotDone (phase , backingIndexName , numberOfPrimaries , true );
160160 } catch (Exception | AssertionError e ) {
161161 // Make sure we re-enable allocation in case of failure so that the remaining tests in the suite are not affected.
162162 configureClusterAllocation (true );
@@ -172,12 +172,13 @@ public void testSearchableSnapshotForceMergesSourceIndex() throws Exception {
172172 // Data streams have 1 primary shard by default.
173173 // The test suite runs with 4 nodes, so we can have up to 3 (allocated) replicas.
174174 final String phase = randomBoolean () ? "cold" : "frozen" ;
175- final String backingIndexName = prepareDataStreamWithDocs (phase , 1 , 0 );
175+ final int numberOfPrimaries = 1 ;
176+ final String backingIndexName = prepareDataStreamWithDocs (phase , numberOfPrimaries , 0 );
176177
177178 // Enable/start ILM on the data stream.
178179 updateIndexSettings (dataStream , Settings .builder ().put (LifecycleSettings .LIFECYCLE_NAME , policy ));
179180
180- assertForceMergedSnapshotDone (phase , backingIndexName , false , false );
181+ assertForceMergedSnapshotDone (phase , backingIndexName , numberOfPrimaries , false );
181182 }
182183
183184 /**
@@ -209,7 +210,7 @@ public void testSearchableSnapshotForceMergesClonedIndexAfterRetry() throws Exce
209210
210211 configureClusterAllocation (true );
211212
212- assertForceMergedSnapshotDone (phase , backingIndexName , numberOfPrimaries > 1 , true );
213+ assertForceMergedSnapshotDone (phase , backingIndexName , numberOfPrimaries , true );
213214 } catch (Exception | AssertionError e ) {
214215 // Make sure we re-enable allocation in case of failure so that the remaining tests in the suite are not affected.
215216 configureClusterAllocation (true );
@@ -1156,6 +1157,13 @@ private Step.StepKey getKeyForIndex(Response response, String indexName) throws
11561157 * first generation backing index.
11571158 */
11581159 private String prepareDataStreamWithDocs (String phase , int numberOfPrimaries , int numberOfReplicas ) throws Exception {
1160+ logger .info (
1161+ "--> running [{}] with [{}] primaries, [{}] replicas, in phase [{}}" ,
1162+ getTestName (),
1163+ numberOfPrimaries ,
1164+ numberOfReplicas ,
1165+ phase
1166+ );
11591167 createSnapshotRepo (client (), snapshotRepo , randomBoolean ());
11601168 createNewSingletonPolicy (client (), policy , phase , new SearchableSnapshotAction (snapshotRepo , true ));
11611169
@@ -1223,10 +1231,10 @@ private static void assertForceMergeCloneIndexSettings(String backingIndexName,
12231231 *
12241232 * @param phase The phase of the ILM policy that the searchable snapshot action runs in.
12251233 * @param backingIndexName The original backing index name.
1226- * @param multiplePrimaries True if the original backing index had multiple primaries , affecting segment assertions.
1234+ * @param numberOfPrimaries The number of primaries that the original backing index had, affecting segment count assertions.
12271235 * @param withReplicas True if the original backing index had one or more replicas, affecting snapshot index naming assertions.
12281236 */
1229- private void assertForceMergedSnapshotDone (String phase , String backingIndexName , boolean multiplePrimaries , boolean withReplicas )
1237+ private void assertForceMergedSnapshotDone (String phase , String backingIndexName , int numberOfPrimaries , boolean withReplicas )
12301238 throws Exception {
12311239 final String prefix = phase .equals ("cold" )
12321240 ? SearchableSnapshotAction .FULL_RESTORED_INDEX_PREFIX
@@ -1240,11 +1248,11 @@ private void assertForceMergedSnapshotDone(String phase, String backingIndexName
12401248 // Regardless of whether we force merged the backing index or a clone, the cloned index should not exist (anymore).
12411249 awaitIndexDoesNotExist (FORCE_MERGE_CLONE_INDEX_PREFIX + "-*-" + backingIndexName );
12421250
1243- // Retrieve the number of segments in the first (random) shard of the backing index.
1251+ // Retrieve the total number of segments across all primary shards of the restored index.
12441252 final Integer numberOfPrimarySegments = getNumberOfPrimarySegments (client (), restoredIndexName );
1245- // If the backing index had multiple primaries, some primaries might be empty, but others should have no more than 1 segment
1246- if (multiplePrimaries || phase .equals ("frozen" )) {
1247- assertThat (numberOfPrimarySegments , lessThanOrEqualTo (1 ));
1253+ // If the backing index had multiple primaries, some primaries might be empty, but others should have no more than 1 segment.
1254+ if (numberOfPrimaries > 1 || phase .equals ("frozen" )) {
1255+ assertThat (numberOfPrimarySegments , lessThanOrEqualTo (numberOfPrimaries ));
12481256 } else {
12491257 // If the backing index had only one primary, we expect exactly 1 segment after force merging.
12501258 assertThat (numberOfPrimarySegments , equalTo (1 ));
0 commit comments