Skip to content

Commit 59e9721

Browse files
authored
Ensure relocation occur in testRelocationWithConcurrentIndexing (#40801)
If the relocation is throttled, the subsequent search request on the target node (i.e., with preference _only_nodes=target_node) will fail because some shards have not moved to that node yet. With this change, we will wait for the relocation happens by busily checking the routing table of the testing index on the target node. Closes #34950
1 parent ac6a594 commit 59e9721

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/RecoveryIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.Locale;
4242
import java.util.Map;
4343
import java.util.concurrent.Future;
44+
import java.util.concurrent.TimeUnit;
4445
import java.util.function.Predicate;
4546

4647
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
@@ -50,6 +51,7 @@
5051
import static org.hamcrest.Matchers.equalTo;
5152
import static org.hamcrest.Matchers.hasSize;
5253
import static org.hamcrest.Matchers.is;
54+
import static org.hamcrest.Matchers.isIn;
5355
import static org.hamcrest.Matchers.notNullValue;
5456
import static org.hamcrest.Matchers.nullValue;
5557

@@ -205,7 +207,6 @@ private String getNodeId(Predicate<Version> versionPredicate) throws IOException
205207
return null;
206208
}
207209

208-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/34950")
209210
public void testRelocationWithConcurrentIndexing() throws Exception {
210211
final String index = "relocation_with_concurrent_indexing";
211212
switch (CLUSTER_TYPE) {
@@ -239,6 +240,15 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
239240
ensureNoInitializingShards(); // wait for all other shard activity to finish
240241
updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
241242
asyncIndexDocs(index, 10, 50).get();
243+
// ensure the relocation from old node to new node has occurred; otherwise ensureGreen can
244+
// return true even though shards haven't moved to the new node yet (allocation was throttled).
245+
assertBusy(() -> {
246+
Map<String, ?> state = entityAsMap(client().performRequest(new Request("GET", "/_cluster/state")));
247+
String xpath = "routing_table.indices." + index + ".shards.0.node";
248+
@SuppressWarnings("unchecked") List<String> assignedNodes = (List<String>) XContentMapValues.extractValue(xpath, state);
249+
assertNotNull(state.toString(), assignedNodes);
250+
assertThat(state.toString(), newNode, isIn(assignedNodes));
251+
}, 60, TimeUnit.SECONDS);
242252
ensureGreen(index);
243253
client().performRequest(new Request("POST", index + "/_refresh"));
244254
assertCount(index, "_only_nodes:" + newNode, 60);

0 commit comments

Comments
 (0)