Let primary own its replication group

Companion commit for elastic/x-pack-elasticsearch#25692

Original commit: elastic/x-pack-elasticsearch@ed93c56f07
This commit is contained in:
Yannick Welsch 2017-07-14 12:48:21 +02:00
parent 81ec1a7ba5
commit dbbec0d37e
3 changed files with 16 additions and 9 deletions

View File

@ -374,7 +374,7 @@ public class WatcherIndexingListenerTests extends ESTestCase {
Index index = new Index(Watch.INDEX, "foo");
ShardId shardId = new ShardId(index, 0);
ShardRoutingState randomState = randomFrom(STARTED, RELOCATING);
ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, "current", true,
ShardRouting shardRouting = TestShardRouting.newShardRouting(shardId, "current", randomState == RELOCATING ? "other" : null, true,
randomState);
IndexRoutingTable indexRoutingTable = IndexRoutingTable.builder(index)
.addShard(shardRouting).build();

View File

@ -194,7 +194,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
).build();
IndexRoutingTable watchRoutingTable = IndexRoutingTable.builder(watchIndex)
.addShard(TestShardRouting.newShardRouting(shardId, "node_1", true, randomFrom(STARTED, RELOCATING)))
.addShard(randomBoolean() ?
TestShardRouting.newShardRouting(shardId, "node_1", true, STARTED) :
TestShardRouting.newShardRouting(shardId, "node_1", "node_2", true, RELOCATING))
.build();
ClusterState clusterStateWithLocalShards = ClusterState.builder(new ClusterName("my-cluster"))
.nodes(nodes)
@ -204,7 +206,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
// shard moved over to node 2
IndexRoutingTable watchRoutingTableNode2 = IndexRoutingTable.builder(watchIndex)
.addShard(TestShardRouting.newShardRouting(shardId, "node_2", true, randomFrom(STARTED, RELOCATING)))
.addShard(randomBoolean() ?
TestShardRouting.newShardRouting(shardId, "node_2", true, STARTED) :
TestShardRouting.newShardRouting(shardId, "node_2", "node_1", true, RELOCATING))
.build();
ClusterState clusterStateWithoutLocalShards = ClusterState.builder(new ClusterName("my-cluster"))
.nodes(nodes)
@ -237,8 +241,8 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
.build();
IndexRoutingTable previousWatchRoutingTable = IndexRoutingTable.builder(watchIndex)
.addShard(TestShardRouting.newShardRouting(secondShardId, "node_1", true, randomFrom(STARTED, RELOCATING)))
.addShard(TestShardRouting.newShardRouting(shardId, "node_2", true, randomFrom(STARTED, RELOCATING)))
.addShard(TestShardRouting.newShardRouting(secondShardId, "node_1", true, STARTED))
.addShard(TestShardRouting.newShardRouting(shardId, "node_2", true, STARTED))
.build();
IndexMetaData indexMetaData = IndexMetaData.builder(Watch.INDEX)
@ -255,8 +259,8 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
.build();
IndexRoutingTable currentWatchRoutingTable = IndexRoutingTable.builder(watchIndex)
.addShard(TestShardRouting.newShardRouting(shardId, "node_1", false, randomFrom(STARTED, RELOCATING)))
.addShard(TestShardRouting.newShardRouting(secondShardId, "node_1", true, randomFrom(STARTED, RELOCATING)))
.addShard(TestShardRouting.newShardRouting(shardId, "node_1", false, STARTED))
.addShard(TestShardRouting.newShardRouting(secondShardId, "node_1", true, STARTED))
.addShard(TestShardRouting.newShardRouting(shardId, "node_2", true, STARTED))
.build();

View File

@ -125,15 +125,18 @@ public class TriggeredWatchStoreTests extends ESTestCase {
final Index index = metaDataBuilder.get(TriggeredWatchStore.INDEX_NAME).getIndex();
IndexRoutingTable.Builder indexRoutingTableBuilder = IndexRoutingTable.builder(index);
for (int i = 0; i < numShards; i++) {
ShardRoutingState state;
final ShardRoutingState state;
final String currentNodeId;
if (numStartedShards-- > 0) {
state = ShardRoutingState.STARTED;
currentNodeId = "_node_id";
} else {
state = ShardRoutingState.UNASSIGNED;
currentNodeId = null;
}
ShardId shardId = new ShardId(index, 0);
indexRoutingTableBuilder.addIndexShard(new IndexShardRoutingTable.Builder(shardId)
.addShard(TestShardRouting.newShardRouting(shardId, "_node_id", null, true, state,
.addShard(TestShardRouting.newShardRouting(shardId, currentNodeId, null, true, state,
new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "")))
.build());
indexRoutingTableBuilder.addReplica();