From a82f2e31b4b00cc25b07afb59ed2295a5279aa94 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 31 May 2018 08:03:53 +0200 Subject: [PATCH] [CCR] Also copy routing_num_shards from leader to follow index. (#30894) Bug was introduced when create and follow api was added in #30602 --- .../ccr/action/CreateAndFollowIndexAction.java | 17 +++++++++++------ .../elasticsearch/xpack/ccr/ShardChangesIT.java | 5 +++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java index 423dba222ea..7fc42dad276 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/CreateAndFollowIndexAction.java @@ -45,7 +45,6 @@ import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.ccr.CcrSettings; import java.io.IOException; -import java.util.HashSet; import java.util.List; import java.util.Map; @@ -247,20 +246,21 @@ public class CreateAndFollowIndexAction extends Action cursor : leaderIndexMetaData.getMappings()) { imdBuilder.putMapping(cursor.value); } - mdBuilder.put(imdBuilder.build(), false); + imdBuilder.setRoutingNumShards(leaderIndexMetaData.getRoutingNumShards()); + IndexMetaData followIMD = imdBuilder.build(); + mdBuilder.put(followIMD, false); ClusterState.Builder builder = ClusterState.builder(currentState); builder.metaData(mdBuilder.build()); @@ -279,7 +281,10 @@ public class CreateAndFollowIndexAction extends Action assertExpectedDocumentRunnable(final int value) { return () -> { final GetResponse getResponse = client().prepareGet("index2", "doc", Integer.toString(value)).get(); - assertTrue("doc with id [" + value + "] does not exist", getResponse.isExists()); + assertTrue("Doc with id [" + value + "] is missing", getResponse.isExists()); assertTrue((getResponse.getSource().containsKey("f"))); assertThat(getResponse.getSource().get("f"), equalTo(value)); };