Skip to content

Commit

Permalink
Ensure relocation occur in testRelocationWithConcurrentIndexing (#40801)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dnhatn authored Apr 7, 2019
1 parent ac6a594 commit 59e9721
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;

import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
Expand All @@ -50,6 +51,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

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

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

0 comments on commit 59e9721

Please sign in to comment.