|
27 | 27 | import org.elasticsearch.cluster.metadata.IndexMetaData; |
28 | 28 | import org.elasticsearch.common.settings.Settings; |
29 | 29 | import org.elasticsearch.common.util.concurrent.AbstractRunnable; |
| 30 | +import org.elasticsearch.common.xcontent.support.XContentMapValues; |
30 | 31 | import org.elasticsearch.index.IndexSettings; |
31 | 32 | import org.elasticsearch.rest.action.document.RestIndexAction; |
32 | 33 | import org.elasticsearch.test.rest.yaml.ObjectPath; |
|
36 | 37 | import java.util.List; |
37 | 38 | import java.util.Map; |
38 | 39 | import java.util.concurrent.Future; |
| 40 | +import java.util.concurrent.TimeUnit; |
39 | 41 | import java.util.function.Predicate; |
40 | 42 |
|
41 | 43 | import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength; |
|
44 | 46 | import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY; |
45 | 47 | import static org.hamcrest.Matchers.equalTo; |
46 | 48 | import static org.hamcrest.Matchers.hasSize; |
| 49 | +import static org.hamcrest.Matchers.isIn; |
47 | 50 | import static org.hamcrest.Matchers.notNullValue; |
48 | 51 |
|
49 | 52 | /** |
@@ -198,7 +201,6 @@ private String getNodeId(Predicate<Version> versionPredicate) throws IOException |
198 | 201 | return null; |
199 | 202 | } |
200 | 203 |
|
201 | | - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/34950") |
202 | 204 | public void testRelocationWithConcurrentIndexing() throws Exception { |
203 | 205 | final String index = "relocation_with_concurrent_indexing"; |
204 | 206 | switch (CLUSTER_TYPE) { |
@@ -232,6 +234,15 @@ public void testRelocationWithConcurrentIndexing() throws Exception { |
232 | 234 | ensureNoInitializingShards(); // wait for all other shard activity to finish |
233 | 235 | updateIndexSettings(index, Settings.builder().put("index.routing.allocation.include._id", newNode)); |
234 | 236 | 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); |
235 | 246 | ensureGreen(index); |
236 | 247 | client().performRequest(new Request("POST", index + "/_refresh")); |
237 | 248 | assertCount(index, "_only_nodes:" + newNode, 60); |
|
0 commit comments