Skip to content

Commit

Permalink
testRelocationWithConcurrentIndexing: wait for green (on relevan inde…
Browse files Browse the repository at this point in the history
…x) and shard initialization to settle down before starting relocation
  • Loading branch information
bleskes committed Dec 4, 2017
1 parent 5218972 commit 3e81598
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ public void testRelocationWithConcurrentIndexing() throws Exception {
case MIXED:
final String newNode = getNodeId(v -> v.equals(Version.CURRENT));
final String oldNode = getNodeId(v -> v.before(Version.CURRENT));
// remove the replica now that we know that the primary is an old node
// remove the replica and guaranteed the primary is placed on the old node
updateIndexSetting(index, Settings.builder()
.put(IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 0)
.put(INDEX_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), (String)null)
.put("index.routing.allocation.include._id", oldNode)
);
ensureGreen(index); // wait for the primary to be assigned
ensureNoInitializingShards(); // wait for all other shard activity to finish
updateIndexSetting(index, Settings.builder().put("index.routing.allocation.include._id", newNode));
asyncIndexDocs(index, 10, 50).get();
ensureGreen(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,18 @@ protected void ensureGreen(String index) throws IOException {
assertOK(client().performRequest("GET", "_cluster/health/" + index, params));
}

/**
* waits until all shard initialization is completed. This is a handy alternative to ensureGreen as it relates to all shards
* in the cluster and doesn't require to know how many nodes/replica there are.
*/
protected void ensureNoInitializingShards() throws IOException {
Map<String, String> params = new HashMap<>();
params.put("wait_for_no_initializing_shards", "true");
params.put("timeout", "70s");
params.put("level", "shards");
assertOK(client().performRequest("GET", "_cluster/health/", params));
}

protected void createIndex(String name, Settings settings) throws IOException {
createIndex(name, settings, "");
}
Expand Down

0 comments on commit 3e81598

Please sign in to comment.