Skip to content

Commit 70cca88

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 3c591fa commit 70cca88

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
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.cluster.metadata.IndexMetaData;
2727
import org.elasticsearch.common.settings.Settings;
2828
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
29+
import org.elasticsearch.common.xcontent.support.XContentMapValues;
2930
import org.elasticsearch.index.IndexSettings;
3031
import org.elasticsearch.test.rest.yaml.ObjectPath;
3132

@@ -34,6 +35,7 @@
3435
import java.util.List;
3536
import java.util.Map;
3637
import java.util.concurrent.Future;
38+
import java.util.concurrent.TimeUnit;
3739
import java.util.function.Predicate;
3840

3941
import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
@@ -42,6 +44,7 @@
4244
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
4345
import static org.hamcrest.Matchers.equalTo;
4446
import static org.hamcrest.Matchers.hasSize;
47+
import static org.hamcrest.Matchers.isIn;
4548
import static org.hamcrest.Matchers.notNullValue;
4649

4750
/**
@@ -186,7 +189,6 @@ private String getNodeId(Predicate<Version> versionPredicate) throws IOException
186189
return null;
187190
}
188191

189-
190192
public void testRelocationWithConcurrentIndexing() throws Exception {
191193
final String index = "relocation_with_concurrent_indexing";
192194
switch (CLUSTER_TYPE) {
@@ -220,6 +222,15 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
220222
ensureNoInitializingShards(); // wait for all other shard activity to finish
221223
updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
222224
asyncIndexDocs(index, 10, 50).get();
225+
// ensure the relocation from old node to new node has occurred; otherwise ensureGreen can
226+
// return true even though shards haven't moved to the new node yet (allocation was throttled).
227+
assertBusy(() -> {
228+
Map<String, ?> state = entityAsMap(client().performRequest(new Request("GET", "/_cluster/state")));
229+
String xpath = "routing_table.indices." + index + ".shards.0.node";
230+
@SuppressWarnings("unchecked") List<String> assignedNodes = (List<String>) XContentMapValues.extractValue(xpath, state);
231+
assertNotNull(state.toString(), assignedNodes);
232+
assertThat(state.toString(), newNode, isIn(assignedNodes));
233+
}, 60, TimeUnit.SECONDS);
223234
ensureGreen(index);
224235
client().performRequest(new Request("POST", index + "/_refresh"));
225236
assertCount(index, "_primary", 60);

0 commit comments

Comments
 (0)