Skip to content

Commit 18c4b92

Browse files
Fix testSnapshotRelocatingPrimary to Actually Run Relocations (#46594)
* Fix testSnapshotRelocatingPrimary to Actually Run Relocations Without replicas we won't actually get any relocations going when removing the node constraints in this test. Adjusted the code to force relocations by forbidding nodes that hold primaries instead. Also, fixed the timeouts and asserted that we actually get relocations. Fixes #46276
1 parent f5b2ac3 commit 18c4b92

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

server/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,8 +2218,12 @@ public void testSnapshotRelocatingPrimary() throws Exception {
22182218
.put("compress", randomBoolean())
22192219
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
22202220

2221-
// Create index on 1 nodes and make sure each node has a primary by setting no replicas
2222-
assertAcked(prepareCreate("test-idx", 1, Settings.builder().put("number_of_replicas", 0)));
2221+
// Create index on two nodes and make sure each node has a primary by setting no replicas
2222+
assertAcked(prepareCreate("test-idx", 2, Settings.builder()
2223+
.put(SETTING_NUMBER_OF_REPLICAS, 0)
2224+
.put(SETTING_NUMBER_OF_SHARDS, between(2, 10))));
2225+
2226+
ensureGreen("test-idx");
22232227

22242228
logger.info("--> indexing some data");
22252229
for (int i = 0; i < 100; i++) {
@@ -2229,11 +2233,13 @@ public void testSnapshotRelocatingPrimary() throws Exception {
22292233
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().getTotalHits().value, equalTo(100L));
22302234

22312235
logger.info("--> start relocations");
2232-
allowNodes("test-idx", internalCluster().numDataNodes());
2236+
allowNodes("test-idx", 1);
22332237

22342238
logger.info("--> wait for relocations to start");
22352239

2236-
waitForRelocationsToStart("test-idx", TimeValue.timeValueMillis(300));
2240+
assertBusy(() -> assertThat(
2241+
client().admin().cluster().prepareHealth("test-idx").execute().actionGet().getRelocatingShards(), greaterThan(0)),
2242+
1L, TimeUnit.MINUTES);
22372243

22382244
logger.info("--> snapshot");
22392245
client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(false).setIndices("test-idx").get();
@@ -2806,11 +2812,6 @@ private boolean waitForIndex(final String index, TimeValue timeout) throws Inter
28062812
return awaitBusy(() -> indexExists(index), timeout.millis(), TimeUnit.MILLISECONDS);
28072813
}
28082814

2809-
private boolean waitForRelocationsToStart(final String index, TimeValue timeout) throws InterruptedException {
2810-
return awaitBusy(() -> client().admin().cluster().prepareHealth(index).execute().actionGet().getRelocatingShards() > 0,
2811-
timeout.millis(), TimeUnit.MILLISECONDS);
2812-
}
2813-
28142815
public void testSnapshotName() throws Exception {
28152816
disableRepoConsistencyCheck("This test does not create any data in the repository");
28162817

0 commit comments

Comments
 (0)