diff options
author | Yannick Welsch <yannick@welsch.lu> | 2017-06-28 15:48:47 +0200 |
---|---|---|
committer | Jason Tedor <jason@tedor.me> | 2017-06-28 09:48:47 -0400 |
commit | 5a4a47332c5a9a21531eb29c3ab4fd264e7fcf36 (patch) | |
tree | 0b2b4fe630b8a4c3d80f5882835c01304287332f /core/src/test/java | |
parent | ebdae09df3137e3dee3a7556de0909d2223ea96b (diff) |
Use a single method to update shard state
This commit refactors index shard to provide a single method for
updating the shard state on an incoming cluster state update.
Relates #25431
Diffstat (limited to 'core/src/test/java')
7 files changed, 100 insertions, 87 deletions
diff --git a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java index b74596cda6..75a59a36d7 100644 --- a/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java @@ -44,6 +44,7 @@ import org.elasticsearch.action.support.replication.TransportWriteActionTestHelp import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.routing.AllocationId; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingHelper; @@ -223,9 +224,14 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase final DiscoveryNode pNode = getDiscoveryNode(primary.routingEntry().currentNodeId()); primary.markAsRecovering("store", new RecoveryState(primary.routingEntry(), pNode, null)); primary.recoverFromStore(); - primary.updateRoutingEntry(ShardRoutingHelper.moveToStarted(primary.routingEntry())); - clusterStateVersion++; - updateAllocationIDsOnPrimary(); + HashSet<String> activeIds = new HashSet<>(); + activeIds.addAll(activeIds()); + activeIds.add(primary.routingEntry().allocationId().getId()); + HashSet<String> initializingIds = new HashSet<>(); + initializingIds.addAll(initializingIds()); + initializingIds.remove(primary.routingEntry().allocationId().getId()); + primary.updateShardState(ShardRoutingHelper.moveToStarted(primary.routingEntry()), primary.getPrimaryTerm(), null, + ++clusterStateVersion, activeIds, initializingIds); for (final IndexShard replica : replicas) { recoverReplica(replica); } @@ -239,7 +245,7 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase return replica; } - public synchronized void addReplica(IndexShard replica) { + public synchronized void addReplica(IndexShard replica) throws IOException { assert shardRoutings().stream() .filter(shardRouting -> shardRouting.isSameAllocation(replica.routingEntry())).findFirst().isPresent() == false : "replica with aId [" + replica.routingEntry().allocationId() + "] already exists"; @@ -278,29 +284,43 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase assertTrue(replicas.remove(replica)); closeShards(primary); primary = replica; - primary.updateRoutingEntry(replica.routingEntry().moveActiveReplicaToPrimary()); - PlainActionFuture<PrimaryReplicaSyncer.ResyncTask> fut = new PlainActionFuture<>(); - primary.updatePrimaryTerm(newTerm, (shard, listener) -> primaryReplicaSyncer.resync(shard, - new ActionListener<PrimaryReplicaSyncer.ResyncTask>() { - @Override - public void onResponse(PrimaryReplicaSyncer.ResyncTask resyncTask) { - listener.onResponse(resyncTask); - fut.onResponse(resyncTask); - } + HashSet<String> activeIds = new HashSet<>(); + activeIds.addAll(activeIds()); + activeIds.add(replica.routingEntry().allocationId().getId()); + HashSet<String> initializingIds = new HashSet<>(); + initializingIds.addAll(initializingIds()); + initializingIds.remove(replica.routingEntry().allocationId().getId()); + primary.updateShardState(replica.routingEntry().moveActiveReplicaToPrimary(), + newTerm, (shard, listener) -> primaryReplicaSyncer.resync(shard, + new ActionListener<PrimaryReplicaSyncer.ResyncTask>() { + @Override + public void onResponse(PrimaryReplicaSyncer.ResyncTask resyncTask) { + listener.onResponse(resyncTask); + fut.onResponse(resyncTask); + } + + @Override + public void onFailure(Exception e) { + listener.onFailure(e); + fut.onFailure(e); + } + }), ++clusterStateVersion, activeIds, initializingIds); - @Override - public void onFailure(Exception e) { - listener.onFailure(e); - fut.onFailure(e); - } - })); - clusterStateVersion++; - updateAllocationIDsOnPrimary(); return fut; } - synchronized boolean removeReplica(IndexShard replica) { + private synchronized Set<String> activeIds() { + return shardRoutings().stream() + .filter(ShardRouting::active).map(ShardRouting::allocationId).map(AllocationId::getId).collect(Collectors.toSet()); + } + + private synchronized Set<String> initializingIds() { + return shardRoutings().stream() + .filter(ShardRouting::initializing).map(ShardRouting::allocationId).map(AllocationId::getId).collect(Collectors.toSet()); + } + + synchronized boolean removeReplica(IndexShard replica) throws IOException { final boolean removed = replicas.remove(replica); if (removed) { clusterStateVersion++; @@ -401,17 +421,9 @@ public abstract class ESIndexLevelReplicationTestCase extends IndexShardTestCase } } - private void updateAllocationIDsOnPrimary() { - Set<String> active = new HashSet<>(); - Set<String> initializing = new HashSet<>(); - for (ShardRouting shard: shardRoutings()) { - if (shard.active()) { - active.add(shard.allocationId().getId()); - } else { - initializing.add(shard.allocationId().getId()); - } - } - primary.updateAllocationIdsFromMaster(clusterStateVersion, active, initializing); + private void updateAllocationIDsOnPrimary() throws IOException { + primary.updateShardState(primary.routingEntry(), primary.getPrimaryTerm(), null, clusterStateVersion, + activeIds(), initializingIds()); } } diff --git a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java index 8b585c4e65..0c07f4cf77 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardIT.java @@ -525,16 +525,16 @@ public class IndexShardIT extends ESSingleNodeTestCase { } - public static final IndexShard recoverShard(IndexShard newShard) throws IOException { + public static final IndexShard recoverShard(IndexShard newShard) throws IOException { DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null)); assertTrue(newShard.recoverFromStore()); - newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted()); return newShard; } - public static final IndexShard newIndexShard(IndexService indexService, IndexShard shard, IndexSearcherWrapper wrapper, - IndexingOperationListener... listeners) throws IOException { + public static final IndexShard newIndexShard(IndexService indexService, IndexShard shard, IndexSearcherWrapper wrapper, + IndexingOperationListener... listeners) throws IOException { ShardRouting initializingShardRouting = getInitializingShardRouting(shard.routingEntry()); IndexShard newShard = new IndexShard(initializingShardRouting, indexService.getIndexSettings(), shard.shardPath(), shard.store(), indexService.getIndexSortSupplier(), indexService.cache(), indexService.mapperService(), indexService.similarityService(), 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 16baf57fd7..9093274a49 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java @@ -192,7 +192,7 @@ public class IndexShardTests extends IndexShardTestCase { ShardStateMetaData shardStateMetaData = load(logger, shardStatePath); assertEquals(getShardStateMetadata(shard), shardStateMetaData); ShardRouting routing = shard.shardRouting; - shard.updateRoutingEntry(routing); + IndexShardTestCase.updateRoutingEntry(shard, routing); shardStateMetaData = load(logger, shardStatePath); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); @@ -200,7 +200,7 @@ public class IndexShardTests extends IndexShardTestCase { new ShardStateMetaData(routing.primary(), shard.indexSettings().getUUID(), routing.allocationId())); routing = TestShardRouting.relocate(shard.shardRouting, "some node", 42L); - shard.updateRoutingEntry(routing); + IndexShardTestCase.updateRoutingEntry(shard, routing); shardStateMetaData = load(logger, shardStatePath); assertEquals(shardStateMetaData, getShardStateMetadata(shard)); assertEquals(shardStateMetaData, @@ -345,8 +345,8 @@ public class IndexShardTests extends IndexShardTestCase { true, ShardRoutingState.STARTED, replicaRouting.allocationId()); - indexShard.updateRoutingEntry(primaryRouting); - indexShard.updatePrimaryTerm(indexShard.getPrimaryTerm() + 1, (shard, listener) -> {}); + indexShard.updateShardState(primaryRouting, indexShard.getPrimaryTerm() + 1, (shard, listener) -> {}, + 0L, Collections.emptySet(), Collections.emptySet()); final int delayedOperations = scaledRandomIntBetween(1, 64); final CyclicBarrier delayedOperationsBarrier = new CyclicBarrier(1 + delayedOperations); @@ -436,8 +436,8 @@ public class IndexShardTests extends IndexShardTestCase { true, ShardRoutingState.STARTED, replicaRouting.allocationId()); - indexShard.updateRoutingEntry(primaryRouting); - indexShard.updatePrimaryTerm(indexShard.getPrimaryTerm() + 1, (shard, listener) -> {}); + indexShard.updateShardState(primaryRouting, indexShard.getPrimaryTerm() + 1, (shard, listener) -> {}, + 0L, Collections.emptySet(), Collections.emptySet()); /* * This operation completing means that the delay operation executed as part of increasing the primary term has completed and the @@ -478,8 +478,8 @@ public class IndexShardTests extends IndexShardTestCase { ShardRouting replicaRouting = indexShard.routingEntry(); ShardRouting primaryRouting = TestShardRouting.newShardRouting(replicaRouting.shardId(), replicaRouting.currentNodeId(), null, true, ShardRoutingState.STARTED, replicaRouting.allocationId()); - indexShard.updateRoutingEntry(primaryRouting); - indexShard.updatePrimaryTerm(indexShard.getPrimaryTerm() + 1, (shard, listener) -> {}); + indexShard.updateShardState(primaryRouting, indexShard.getPrimaryTerm() + 1, (shard, listener) -> {}, + 0L, Collections.emptySet(), Collections.emptySet()); } else { indexShard = newStartedShard(true); } @@ -545,7 +545,7 @@ public class IndexShardTests extends IndexShardTestCase { ShardRouting routing = indexShard.routingEntry(); routing = TestShardRouting.newShardRouting(routing.shardId(), routing.currentNodeId(), "otherNode", true, ShardRoutingState.RELOCATING, AllocationId.newRelocation(routing.allocationId())); - indexShard.updateRoutingEntry(routing); + IndexShardTestCase.updateRoutingEntry(indexShard, routing); indexShard.relocated("test", primaryContext -> {}); engineClosed = false; break; @@ -830,7 +830,7 @@ public class IndexShardTests extends IndexShardTestCase { snapshot = newShard.snapshotStoreMetadata(); assertThat(snapshot.getSegmentsFile().name(), equalTo("segments_2")); - newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted()); snapshot = newShard.snapshotStoreMetadata(); assertThat(snapshot.getSegmentsFile().name(), equalTo("segments_2")); @@ -1088,7 +1088,7 @@ public class IndexShardTests extends IndexShardTestCase { public void testLockingBeforeAndAfterRelocated() throws Exception { final IndexShard shard = newStartedShard(true); - shard.updateRoutingEntry(ShardRoutingHelper.relocate(shard.routingEntry(), "other_node")); + IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(shard.routingEntry(), "other_node")); CountDownLatch latch = new CountDownLatch(1); Thread recoveryThread = new Thread(() -> { latch.countDown(); @@ -1119,7 +1119,7 @@ public class IndexShardTests extends IndexShardTestCase { public void testDelayedOperationsBeforeAndAfterRelocated() throws Exception { final IndexShard shard = newStartedShard(true); - shard.updateRoutingEntry(ShardRoutingHelper.relocate(shard.routingEntry(), "other_node")); + IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(shard.routingEntry(), "other_node")); Thread recoveryThread = new Thread(() -> { try { shard.relocated("simulated recovery", primaryContext -> {}); @@ -1153,7 +1153,7 @@ public class IndexShardTests extends IndexShardTestCase { public void testStressRelocated() throws Exception { final IndexShard shard = newStartedShard(true); - shard.updateRoutingEntry(ShardRoutingHelper.relocate(shard.routingEntry(), "other_node")); + IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(shard.routingEntry(), "other_node")); final int numThreads = randomIntBetween(2, 4); Thread[] indexThreads = new Thread[numThreads]; CountDownLatch allPrimaryOperationLocksAcquired = new CountDownLatch(numThreads); @@ -1208,17 +1208,17 @@ public class IndexShardTests extends IndexShardTestCase { public void testRelocatedShardCanNotBeRevived() throws IOException, InterruptedException { final IndexShard shard = newStartedShard(true); final ShardRouting originalRouting = shard.routingEntry(); - shard.updateRoutingEntry(ShardRoutingHelper.relocate(originalRouting, "other_node")); + IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(originalRouting, "other_node")); shard.relocated("test", primaryContext -> {}); - expectThrows(IllegalIndexShardStateException.class, () -> shard.updateRoutingEntry(originalRouting)); + expectThrows(IllegalIndexShardStateException.class, () -> IndexShardTestCase.updateRoutingEntry(shard, originalRouting)); closeShards(shard); } public void testShardCanNotBeMarkedAsRelocatedIfRelocationCancelled() throws IOException, InterruptedException { final IndexShard shard = newStartedShard(true); final ShardRouting originalRouting = shard.routingEntry(); - shard.updateRoutingEntry(ShardRoutingHelper.relocate(originalRouting, "other_node")); - shard.updateRoutingEntry(originalRouting); + IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(originalRouting, "other_node")); + IndexShardTestCase.updateRoutingEntry(shard, originalRouting); expectThrows(IllegalIndexShardStateException.class, () -> shard.relocated("test", primaryContext -> {})); closeShards(shard); } @@ -1227,7 +1227,7 @@ public class IndexShardTests extends IndexShardTestCase { public void testRelocatedShardCanNotBeRevivedConcurrently() throws IOException, InterruptedException, BrokenBarrierException { final IndexShard shard = newStartedShard(true); final ShardRouting originalRouting = shard.routingEntry(); - shard.updateRoutingEntry(ShardRoutingHelper.relocate(originalRouting, "other_node")); + IndexShardTestCase.updateRoutingEntry(shard, ShardRoutingHelper.relocate(originalRouting, "other_node")); CyclicBarrier cyclicBarrier = new CyclicBarrier(3); AtomicReference<Exception> relocationException = new AtomicReference<>(); Thread relocationThread = new Thread(new AbstractRunnable() { @@ -1253,7 +1253,7 @@ public class IndexShardTests extends IndexShardTestCase { @Override protected void doRun() throws Exception { cyclicBarrier.await(); - shard.updateRoutingEntry(originalRouting); + IndexShardTestCase.updateRoutingEntry(shard, originalRouting); } }); cancellingThread.start(); @@ -1291,7 +1291,7 @@ public class IndexShardTests extends IndexShardTestCase { assertEquals(translogOps, newShard.recoveryState().getTranslog().totalOperations()); assertEquals(translogOps, newShard.recoveryState().getTranslog().totalOperationsOnStart()); assertEquals(100.0f, newShard.recoveryState().getTranslog().recoveredPercent(), 0.01f); - newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted()); assertDocCount(newShard, 1); closeShards(newShard); } @@ -1330,7 +1330,7 @@ public class IndexShardTests extends IndexShardTestCase { } } assertEquals(1, numNoops); - newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted()); assertDocCount(newShard, 1); assertDocCount(shard, 2); closeShards(newShard, shard); @@ -1354,7 +1354,7 @@ public class IndexShardTests extends IndexShardTestCase { assertEquals(0, newShard.recoveryState().getTranslog().totalOperations()); assertEquals(0, newShard.recoveryState().getTranslog().totalOperationsOnStart()); assertEquals(100.0f, newShard.recoveryState().getTranslog().recoveredPercent(), 0.01f); - newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted()); assertDocCount(newShard, 0); closeShards(newShard); } @@ -1397,7 +1397,7 @@ public class IndexShardTests extends IndexShardTestCase { newShard.markAsRecovering("store", new RecoveryState(newShard.routingEntry(), localNode, null)); assertTrue("recover even if there is nothing to recover", newShard.recoverFromStore()); - newShard.updateRoutingEntry(newShard.routingEntry().moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, newShard.routingEntry().moveToStarted()); assertDocCount(newShard, 0); // we can't issue this request through a client because of the inconsistencies we created with the cluster state // doing it directly instead @@ -1413,11 +1413,11 @@ public class IndexShardTests extends IndexShardTestCase { ShardRouting origRouting = shard.routingEntry(); assertThat(shard.state(), equalTo(IndexShardState.STARTED)); ShardRouting inRecoveryRouting = ShardRoutingHelper.relocate(origRouting, "some_node"); - shard.updateRoutingEntry(inRecoveryRouting); + IndexShardTestCase.updateRoutingEntry(shard, inRecoveryRouting); shard.relocated("simulate mark as relocated", primaryContext -> {}); assertThat(shard.state(), equalTo(IndexShardState.RELOCATED)); try { - shard.updateRoutingEntry(origRouting); + IndexShardTestCase.updateRoutingEntry(shard, origRouting); fail("Expected IndexShardRelocatedException"); } catch (IndexShardRelocatedException expected) { } @@ -1466,7 +1466,7 @@ public class IndexShardTests extends IndexShardTestCase { } })); - target.updateRoutingEntry(routing.moveToStarted()); + IndexShardTestCase.updateRoutingEntry(target, routing.moveToStarted()); assertDocs(target, "0"); closeShards(source, target); @@ -1843,7 +1843,7 @@ public class IndexShardTests extends IndexShardTestCase { assertEquals(file.recovered(), file.length()); } } - targetShard.updateRoutingEntry(ShardRoutingHelper.moveToStarted(targetShard.routingEntry())); + IndexShardTestCase.updateRoutingEntry(targetShard, ShardRoutingHelper.moveToStarted(targetShard.routingEntry())); assertDocCount(targetShard, 2); } // now check that it's persistent ie. that the added shards are committed diff --git a/core/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java b/core/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java index bf0b728674..c2c44421b8 100644 --- a/core/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java +++ b/core/src/test/java/org/elasticsearch/index/shard/PrimaryReplicaSyncerTests.java @@ -62,7 +62,8 @@ public class PrimaryReplicaSyncerTests extends IndexShardTestCase { boolean syncNeeded = numDocs > 0 && globalCheckPoint < numDocs - 1; String allocationId = shard.routingEntry().allocationId().getId(); - shard.updateAllocationIdsFromMaster(randomNonNegativeLong(), Collections.singleton(allocationId), Collections.emptySet()); + shard.updateShardState(shard.routingEntry(), shard.getPrimaryTerm(), null, 1000L, Collections.singleton(allocationId), + Collections.emptySet()); shard.updateLocalCheckpointForShard(allocationId, globalCheckPoint); assertEquals(globalCheckPoint, shard.getGlobalCheckpoint()); diff --git a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java index 0c34bb54eb..d8367b0d6a 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.index.engine.Engine; import org.elasticsearch.index.shard.IndexSearcherWrapper; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShardIT; +import org.elasticsearch.index.shard.IndexShardTestCase; import org.elasticsearch.indices.recovery.RecoveryState; import org.elasticsearch.test.ESSingleNodeTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -450,7 +451,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { assertEquals(1, imc.availableShards().size()); assertTrue(newShard.recoverFromStore()); assertTrue("we should have flushed in IMC at least once but did: " + flushes.get(), flushes.get() >= 1); - newShard.updateRoutingEntry(routing.moveToStarted()); + IndexShardTestCase.updateRoutingEntry(newShard, routing.moveToStarted()); } finally { newShard.close("simon says", false); } diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java b/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java index 1fe4def962..0dc760d63b 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesLifecycleListenerSingleNodeTests.java @@ -31,6 +31,7 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; +import org.elasticsearch.index.shard.IndexShardTestCase; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason; import org.elasticsearch.indices.recovery.RecoveryState; @@ -130,14 +131,14 @@ public class IndicesLifecycleListenerSingleNodeTests extends ESSingleNodeTestCas .updateUnassigned(unassignedInfo, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE); newRouting = ShardRoutingHelper.initialize(newRouting, nodeId); IndexShard shard = index.createShard(newRouting); - shard.updateRoutingEntry(newRouting); + IndexShardTestCase.updateRoutingEntry(shard, newRouting); assertEquals(5, counter.get()); final DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); shard.markAsRecovering("store", new RecoveryState(newRouting, localNode, null)); shard.recoverFromStore(); newRouting = ShardRoutingHelper.moveToStarted(newRouting); - shard.updateRoutingEntry(newRouting); + IndexShardTestCase.updateRoutingEntry(shard, newRouting); assertEquals(6, counter.get()); } finally { indicesService.removeIndex(idx, DELETED, "simon says"); diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/AbstractIndicesClusterStateServiceTestCase.java b/core/src/test/java/org/elasticsearch/indices/cluster/AbstractIndicesClusterStateServiceTestCase.java index 73e2d7eb0b..419b7a430d 100644 --- a/core/src/test/java/org/elasticsearch/indices/cluster/AbstractIndicesClusterStateServiceTestCase.java +++ b/core/src/test/java/org/elasticsearch/indices/cluster/AbstractIndicesClusterStateServiceTestCase.java @@ -35,6 +35,7 @@ import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.shard.IndexEventListener; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShardState; +import org.elasticsearch.index.shard.PrimaryReplicaSyncer; import org.elasticsearch.index.shard.PrimaryReplicaSyncer.ResyncTask; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndicesService; @@ -345,17 +346,12 @@ public abstract class AbstractIndicesClusterStateServiceTestCase extends ESTestC } @Override - public ShardRouting routingEntry() { - return shardRouting; - } - - @Override - public IndexShardState state() { - return null; - } - - @Override - public void updateRoutingEntry(ShardRouting shardRouting) throws IOException { + public void updateShardState(ShardRouting shardRouting, + long newPrimaryTerm, + CheckedBiConsumer<IndexShard, ActionListener<ResyncTask>, IOException> primaryReplicaSyncer, + long applyingClusterStateVersion, + Set<String> activeAllocationIds, + Set<String> initializingAllocationIds) throws IOException { failRandomly(); assertThat(this.shardId(), equalTo(shardRouting.shardId())); assertTrue("current: " + this.shardRouting + ", got: " + shardRouting, this.shardRouting.isSameAllocation(shardRouting)); @@ -364,20 +360,22 @@ public abstract class AbstractIndicesClusterStateServiceTestCase extends ESTestC shardRouting.active()); } this.shardRouting = shardRouting; + if (shardRouting.primary()) { + term = newPrimaryTerm; + this.clusterStateVersion = applyingClusterStateVersion; + this.activeAllocationIds = activeAllocationIds; + this.initializingAllocationIds = initializingAllocationIds; + } } @Override - public void updatePrimaryTerm(final long newPrimaryTerm, - CheckedBiConsumer<IndexShard, ActionListener<ResyncTask>, IOException> primaryReplicaSyncer) { - term = newPrimaryTerm; + public ShardRouting routingEntry() { + return shardRouting; } @Override - public void updateAllocationIdsFromMaster( - long applyingClusterStateVersion, Set<String> activeAllocationIds, Set<String> initializingAllocationIds) { - this.clusterStateVersion = applyingClusterStateVersion; - this.activeAllocationIds = activeAllocationIds; - this.initializingAllocationIds = initializingAllocationIds; + public IndexShardState state() { + return null; } public void updateTerm(long newTerm) { |