|
26 | 26 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
27 | 27 | import org.elasticsearch.common.settings.Settings;
|
28 | 28 | import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
| 29 | +import org.elasticsearch.common.xcontent.support.XContentMapValues; |
29 | 30 | import org.elasticsearch.index.IndexSettings;
|
30 | 31 | import org.elasticsearch.test.rest.yaml.ObjectPath;
|
31 | 32 |
|
|
34 | 35 | import java.util.List;
|
35 | 36 | import java.util.Map;
|
36 | 37 | import java.util.concurrent.Future;
|
| 38 | +import java.util.concurrent.TimeUnit; |
37 | 39 | import java.util.function.Predicate;
|
38 | 40 |
|
39 | 41 | import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength;
|
|
42 | 44 | import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
|
43 | 45 | import static org.hamcrest.Matchers.equalTo;
|
44 | 46 | import static org.hamcrest.Matchers.hasSize;
|
| 47 | +import static org.hamcrest.Matchers.isIn; |
45 | 48 | import static org.hamcrest.Matchers.notNullValue;
|
46 | 49 |
|
47 | 50 | /**
|
@@ -186,7 +189,6 @@ private String getNodeId(Predicate<Version> versionPredicate) throws IOException
|
186 | 189 | return null;
|
187 | 190 | }
|
188 | 191 |
|
189 |
| - |
190 | 192 | public void testRelocationWithConcurrentIndexing() throws Exception {
|
191 | 193 | final String index = "relocation_with_concurrent_indexing";
|
192 | 194 | switch (CLUSTER_TYPE) {
|
@@ -220,6 +222,15 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
|
220 | 222 | ensureNoInitializingShards(); // wait for all other shard activity to finish
|
221 | 223 | updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
|
222 | 224 | 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); |
223 | 234 | ensureGreen(index);
|
224 | 235 | client().performRequest(new Request("POST", index + "/_refresh"));
|
225 | 236 | assertCount(index, "_primary", 60);
|
|
0 commit comments