Skip to content

Commit 924b99e

Browse files
committed
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 a43a265 commit 924b99e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.cluster.metadata.IndexMetaData;
2828
import org.elasticsearch.common.settings.Settings;
2929
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
30+
import org.elasticsearch.common.xcontent.support.XContentMapValues;
3031
import org.elasticsearch.index.IndexSettings;
3132
import org.elasticsearch.rest.action.document.RestIndexAction;
3233
import org.elasticsearch.test.rest.yaml.ObjectPath;
@@ -36,6 +37,7 @@
3637
import java.util.List;
3738
import java.util.Map;
3839
import java.util.concurrent.Future;
40+
import java.util.concurrent.TimeUnit;
3941
import java.util.function.Predicate;
4042

4143
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
@@ -44,6 +46,7 @@
4446
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
4547
import static org.hamcrest.Matchers.equalTo;
4648
import static org.hamcrest.Matchers.hasSize;
49+
import static org.hamcrest.Matchers.isIn;
4750
import static org.hamcrest.Matchers.notNullValue;
4851

4952
/**
@@ -198,7 +201,6 @@ private String getNodeId(Predicate<Version> versionPredicate) throws IOException
198201
return null;
199202
}
200203

201-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/34950")
202204
public void testRelocationWithConcurrentIndexing() throws Exception {
203205
final String index = "relocation_with_concurrent_indexing";
204206
switch (CLUSTER_TYPE) {
@@ -232,6 +234,15 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
232234
ensureNoInitializingShards(); // wait for all other shard activity to finish
233235
updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
234236
asyncIndexDocs(index, 10, 50).get();
237+
// ensure the relocation from old node to new node has occurred; otherwise ensureGreen can
238+
// return true even though shards haven't moved to the new node yet (allocation was throttled).
239+
assertBusy(() -> {
240+
Map<String, ?> state = entityAsMap(client().performRequest(new Request("GET", "/_cluster/state")));
241+
String xpath = "routing_table.indices." + index + ".shards.0.node";
242+
@SuppressWarnings("unchecked") List<String> assignedNodes = (List<String>) XContentMapValues.extractValue(xpath, state);
243+
assertNotNull(state.toString(), assignedNodes);
244+
assertThat(state.toString(), newNode, isIn(assignedNodes));
245+
}, 60, TimeUnit.SECONDS);
235246
ensureGreen(index);
236247
client().performRequest(new Request("POST", index + "/_refresh"));
237248
assertCount(index, "_only_nodes:" + newNode, 60);

0 commit comments

Comments
 (0)