From 0390c76f0a456279255f1da4a00a0a103aa2503c Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Fri, 25 Aug 2017 10:37:51 +0930 Subject: [PATCH] Remove reinitShadowPrimary (#26349) With shadow replicas gone, there is no need to have this method anymore. --- .../cluster/routing/RoutingNodes.java | 12 ------------ .../cluster/routing/ShardRouting.java | 11 ----------- .../cluster/routing/AllocationIdTests.java | 14 -------------- .../elasticsearch/index/shard/IndexShardTests.java | 10 ++++++---- .../cluster/routing/ShardRoutingHelper.java | 8 -------- 5 files changed, 6 insertions(+), 49 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java index 8268b98f34d..c5f0cb82feb 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -748,18 +748,6 @@ public class RoutingNodes implements Iterable { assert false : "No shard found to remove"; } - private ShardRouting reinitShadowPrimary(ShardRouting candidate) { - if (candidate.relocating()) { - cancelRelocation(candidate); - } - ShardRouting reinitializedShard = candidate.reinitializePrimaryShard(); - updateAssigned(candidate, reinitializedShard); - inactivePrimaryCount++; - inactiveShardCount++; - addRecovery(reinitializedShard); - return reinitializedShard; - } - private ShardRouting reinitReplica(ShardRouting shard) { assert shard.primary() == false : "shard must be a replica: " + shard; assert shard.initializing() : "can only reinitialize an initializing replica: " + shard; diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java b/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java index b4dba56b63d..be1213ad134 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/ShardRouting.java @@ -384,17 +384,6 @@ public final class ShardRouting implements Writeable, ToXContentObject { AllocationId.finishRelocation(allocationId), expectedShardSize); } - /** - * Moves the primary shard from started to initializing - */ - public ShardRouting reinitializePrimaryShard() { - assert state == ShardRoutingState.STARTED : this; - assert primary : this; - return new ShardRouting(shardId, currentNodeId, null, primary, ShardRoutingState.INITIALIZING, - StoreRecoverySource.EXISTING_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.REINITIALIZED, null), - allocationId, UNAVAILABLE_EXPECTED_SHARD_SIZE); - } - /** * Reinitializes a replica shard, giving it a fresh allocation id */ diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java index f6b5fc1bd3f..949d4f35008 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/AllocationIdTests.java @@ -109,20 +109,6 @@ public class AllocationIdTests extends ESTestCase { assertThat(shard.allocationId(), nullValue()); } - public void testReinitializing() { - logger.info("-- build started shard"); - ShardRouting shard = ShardRouting.newUnassigned(new ShardId("test","_na_", 0), true, StoreRecoverySource.EXISTING_STORE_INSTANCE, new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, null)); - shard = shard.initialize("node1", null, -1); - shard = shard.moveToStarted(); - AllocationId allocationId = shard.allocationId(); - - logger.info("-- reinitializing shard"); - shard = shard.reinitializePrimaryShard(); - assertThat(shard.allocationId().getId(), notNullValue()); - assertThat(shard.allocationId().getRelocationId(), nullValue()); - assertThat(shard.allocationId().getId(), equalTo(allocationId.getId())); - } - public void testSerialization() throws IOException { AllocationId allocationId = AllocationId.newInitializing(); if (randomBoolean()) { diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java index 1332df658c4..7e140dd35fe 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -1613,8 +1613,8 @@ public class IndexShardTests extends IndexShardTestCase { target.refresh("test"); assertDocs(target, "1"); flushShard(source); // only flush source - final ShardRouting origRouting = target.routingEntry(); - ShardRouting routing = ShardRoutingHelper.reinitPrimary(origRouting); + ShardRouting routing = ShardRoutingHelper.initWithSameId(target.routingEntry(), + RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE); final Snapshot snapshot = new Snapshot("foo", new SnapshotId("bar", UUIDs.randomBase64UUID())); routing = ShardRoutingHelper.newWithRestoreSource(routing, new RecoverySource.SnapshotRecoverySource(snapshot, Version.CURRENT, "test")); @@ -1676,7 +1676,8 @@ public class IndexShardTests extends IndexShardTestCase { } }; closeShards(shard); - IndexShard newShard = newShard(ShardRoutingHelper.reinitPrimary(shard.routingEntry()), + IndexShard newShard = newShard( + ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE), shard.shardPath(), shard.indexSettings().getIndexMetaData(), wrapper, null); recoverShardFromStore(newShard); @@ -1821,7 +1822,8 @@ public class IndexShardTests extends IndexShardTestCase { }; closeShards(shard); - IndexShard newShard = newShard(ShardRoutingHelper.reinitPrimary(shard.routingEntry()), + IndexShard newShard = newShard( + ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.StoreRecoverySource.EXISTING_STORE_INSTANCE), shard.shardPath(), shard.indexSettings().getIndexMetaData(), wrapper, null); recoverShardFromStore(newShard); diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java b/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java index 8eadc728a1f..aa61292ed08 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/routing/ShardRoutingHelper.java @@ -46,14 +46,6 @@ public class ShardRoutingHelper { return routing.initialize(nodeId, null, expectedSize); } - public static ShardRouting reinitPrimary(ShardRouting routing) { - return routing.reinitializePrimaryShard(); - } - - public static ShardRouting reinitPrimary(ShardRouting routing, UnassignedInfo.Reason reason, RecoverySource recoverySource) { - return routing.reinitializePrimaryShard().updateUnassigned(new UnassignedInfo(reason, "test_reinit"), recoverySource); - } - public static ShardRouting initWithSameId(ShardRouting copy, RecoverySource recoverySource) { return new ShardRouting(copy.shardId(), copy.currentNodeId(), copy.relocatingNodeId(), copy.primary(), ShardRoutingState.INITIALIZING, recoverySource, new UnassignedInfo(UnassignedInfo.Reason.REINITIALIZED, null),