From 32445bbc3acf9327bb99d99d5848f5802b55d56f Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 20 Jul 2015 14:56:52 +0200 Subject: [PATCH] Simplify handling of ignored unassigned shards Fold ignored unassigned to a UnassignedShards and have simpler handling of them. Also remove the trapy way of adding an ignored unassigned shards today directly to the list, and have dedicated methods for it. This change also removes the useless moving of unassigned shards to the end, since anyhow we first, sort those unassigned shards, and second, we now have persistent "store exceptions" that should not cause "dead letter" shard allocation. --- .../cluster/routing/RoutingNodes.java | 137 ++++++++++++------ .../cluster/routing/RoutingTable.java | 2 +- .../routing/allocation/AllocationService.java | 16 -- .../allocator/BalancedShardsAllocator.java | 13 +- .../command/AllocateAllocationCommand.java | 5 +- .../gateway/PrimaryShardAllocator.java | 17 +-- .../gateway/ReplicaShardAllocator.java | 17 +-- .../gateway/PrimaryShardAllocatorTests.java | 44 +++--- .../gateway/PriorityComparatorTests.java | 2 +- 9 files changed, 140 insertions(+), 113 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 b348afbc192..4306be8b24e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingNodes.java @@ -52,9 +52,7 @@ public class RoutingNodes implements Iterable { private final Map nodesToShards = newHashMap(); - private final UnassignedShards unassignedShards = new UnassignedShards(); - - private final List ignoredUnassignedShards = newArrayList(); + private final UnassignedShards unassignedShards = new UnassignedShards(this); private final Map> assignedShards = newHashMap(); @@ -185,10 +183,6 @@ public class RoutingNodes implements Iterable { return !unassignedShards.isEmpty(); } - public List ignoredUnassigned() { - return this.ignoredUnassignedShards; - } - public UnassignedShards unassigned() { return this.unassignedShards; } @@ -526,9 +520,11 @@ public class RoutingNodes implements Iterable { } - public final static class UnassignedShards implements Iterable { + public static final class UnassignedShards implements Iterable { + private final RoutingNodes nodes; private final List unassigned; + private final List ignored; private int primaries = 0; private long transactionId = 0; @@ -536,14 +532,18 @@ public class RoutingNodes implements Iterable { private final long sourceTransactionId; public UnassignedShards(UnassignedShards other) { + this.nodes = other.nodes; source = other; sourceTransactionId = other.transactionId; unassigned = new ArrayList<>(other.unassigned); + ignored = new ArrayList<>(other.ignored); primaries = other.primaries; } - public UnassignedShards() { + public UnassignedShards(RoutingNodes nodes) { + this.nodes = nodes; unassigned = new ArrayList<>(); + ignored = new ArrayList<>(); source = null; sourceTransactionId = -1; } @@ -556,12 +556,6 @@ public class RoutingNodes implements Iterable { transactionId++; } - public void addAll(Collection mutableShardRoutings) { - for (ShardRouting r : mutableShardRoutings) { - add(r); - } - } - public void sort(Comparator comparator) { CollectionUtil.timSort(unassigned, comparator); } @@ -575,29 +569,87 @@ public class RoutingNodes implements Iterable { } @Override - public Iterator iterator() { - final Iterator iterator = unassigned.iterator(); - return new Iterator() { - private ShardRouting current; - @Override - public boolean hasNext() { - return iterator.hasNext(); - } + public UnassignedIterator iterator() { + return new UnassignedIterator(); + } - @Override - public ShardRouting next() { - return current = iterator.next(); - } + /** + * The list of ignored unassigned shards (read only). The ignored unassigned shards + * are not part of the formal unassigned list, but are kept around and used to build + * back the list of unassigned shards as part of the routing table. + */ + public List ignored() { + return Collections.unmodifiableList(ignored); + } - @Override - public void remove() { - iterator.remove(); - if (current.primary()) { - primaries--; - } - transactionId++; + /** + * Adds a shard to the ignore unassigned list. Should be used with caution, typically, + * the correct usage is to removeAndIgnore from the iterator. + */ + public void ignoreShard(ShardRouting shard) { + ignored.add(shard); + transactionId++; + } + + public class UnassignedIterator implements Iterator { + + private final Iterator iterator; + private ShardRouting current; + + public UnassignedIterator() { + this.iterator = unassigned.iterator(); + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public ShardRouting next() { + return current = iterator.next(); + } + + /** + * Initializes the current unassigned shard and moves it from the unassigned list. + */ + public void initialize(String nodeId) { + initialize(nodeId, current.version()); + } + + /** + * Initializes the current unassigned shard and moves it from the unassigned list. + */ + public void initialize(String nodeId, long version) { + innerRemove(); + nodes.initialize(new ShardRouting(current, version), nodeId); + } + + /** + * Removes and ignores the unassigned shard (will be ignored for this run, but + * will be added back to unassigned once the metadata is constructed again). + */ + public void removeAndIgnore() { + innerRemove(); + ignoreShard(current); + } + + /** + * Unsupported operation, just there for the interface. Use {@link #removeAndIgnore()} or + * {@link #initialize(String)}. + */ + @Override + public void remove() { + throw new UnsupportedOperationException("remove is not supported in unassigned iterator, use removeAndIgnore or initialize"); + } + + private void innerRemove() { + iterator.remove(); + if (current.primary()) { + primaries--; } - }; + transactionId++; + } } public boolean isEmpty() { @@ -611,16 +663,19 @@ public class RoutingNodes implements Iterable { public void clear() { transactionId++; unassigned.clear(); + ignored.clear(); primaries = 0; } public void transactionEnd(UnassignedShards shards) { - assert shards.source == this && shards.sourceTransactionId == transactionId : - "Expected ID: " + shards.sourceTransactionId + " actual: " + transactionId + " Expected Source: " + shards.source + " actual: " + this; - transactionId++; - this.unassigned.clear(); - this.unassigned.addAll(shards.unassigned); - this.primaries = shards.primaries; + assert shards.source == this && shards.sourceTransactionId == transactionId : + "Expected ID: " + shards.sourceTransactionId + " actual: " + transactionId + " Expected Source: " + shards.source + " actual: " + this; + transactionId++; + this.unassigned.clear(); + this.unassigned.addAll(shards.unassigned); + this.ignored.clear(); + this.ignored.addAll(shards.ignored); + this.primaries = shards.primaries; } public UnassignedShards transactionBegin() { diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java index 0359849a6fb..156f54112f2 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingTable.java @@ -362,7 +362,7 @@ public class RoutingTable implements Iterable, Diffable shardsToMove = Lists.newArrayList(); - for (Iterator unassignedIt = routingNodes.unassigned().iterator(); unassignedIt.hasNext(); ) { - ShardRouting unassignedShardRouting = unassignedIt.next(); - if (unassignedShardRouting.shardId().equals(failedShard.shardId())) { - unassignedIt.remove(); - shardsToMove.add(unassignedShardRouting); - } - } - if (!shardsToMove.isEmpty()) { - routingNodes.unassigned().addAll(shardsToMove); - } - matchedNode.moveToUnassigned(unassignedInfo); } assert matchedNode.isRemoved() : "failedShard " + failedShard + " was matched but wasn't removed"; diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java index 7873d906aa5..9c42256de95 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java @@ -41,7 +41,6 @@ import org.elasticsearch.node.settings.NodeSettingsService; import java.util.*; -import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING; /** @@ -292,7 +291,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards } indices.addAll(allocation.routingTable().indicesRouting().keySet()); buildModelFromAssigned(routing.shards(assignedFilter)); - return allocateUnassigned(unassigned, routing.ignoredUnassigned()); + return allocateUnassigned(unassigned); } private static float absDelta(float lower, float higher) { @@ -551,7 +550,7 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards * Allocates all given shards on the minimal eligable node for the shards index * with respect to the weight function. All given shards must be unassigned. */ - private boolean allocateUnassigned(RoutingNodes.UnassignedShards unassigned, List ignoredUnassigned) { + private boolean allocateUnassigned(RoutingNodes.UnassignedShards unassigned) { assert !nodes.isEmpty(); if (logger.isTraceEnabled()) { logger.trace("Start allocating unassigned shards"); @@ -600,9 +599,9 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards if (!shard.primary()) { boolean drop = deciders.canAllocate(shard, allocation).type() == Type.NO; if (drop) { - ignoredUnassigned.add(shard); + unassigned.ignoreShard(shard); while(i < primaryLength-1 && comparator.compare(primary[i], primary[i+1]) == 0) { - ignoredUnassigned.add(primary[++i]); + unassigned.ignoreShard(primary[++i]); } continue; } else { @@ -706,10 +705,10 @@ public class BalancedShardsAllocator extends AbstractComponent implements Shards } else if (logger.isTraceEnabled()) { logger.trace("No Node found to assign shard [{}]", shard); } - ignoredUnassigned.add(shard); + unassigned.ignoreShard(shard); if (!shard.primary()) { // we could not allocate it and we are a replica - check if we can ignore the other replicas while(secondaryLength > 0 && comparator.compare(shard, secondary[secondaryLength-1]) == 0) { - ignoredUnassigned.add(secondary[--secondaryLength]); + unassigned.ignoreShard(secondary[--secondaryLength]); } } } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateAllocationCommand.java index 670ccb52317..c7598700341 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateAllocationCommand.java @@ -220,12 +220,11 @@ public class AllocateAllocationCommand implements AllocationCommand { throw new IllegalArgumentException("[allocate] allocation of " + shardId + " on node " + discoNode + " is not allowed, reason: " + decision); } // go over and remove it from the unassigned - for (Iterator it = routingNodes.unassigned().iterator(); it.hasNext(); ) { + for (RoutingNodes.UnassignedShards.UnassignedIterator it = routingNodes.unassigned().iterator(); it.hasNext(); ) { if (it.next() != shardRouting) { continue; } - it.remove(); - routingNodes.initialize(shardRouting, routingNode.nodeId()); + it.initialize(routingNode.nodeId()); if (shardRouting.primary()) { // we need to clear the post allocation flag, since its an explicit allocation of the primary shard // and we want to force allocate it (and create a new index for it) diff --git a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java index 55f9db47985..6b23a0c96e9 100644 --- a/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java +++ b/core/src/main/java/org/elasticsearch/gateway/PrimaryShardAllocator.java @@ -58,7 +58,7 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { final RoutingNodes routingNodes = allocation.routingNodes(); final MetaData metaData = routingNodes.metaData(); - final Iterator unassignedIterator = routingNodes.unassigned().iterator(); + final RoutingNodes.UnassignedShards.UnassignedIterator unassignedIterator = routingNodes.unassigned().iterator(); while (unassignedIterator.hasNext()) { ShardRouting shard = unassignedIterator.next(); @@ -69,8 +69,7 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { AsyncShardFetch.FetchResult shardState = fetchData(shard, allocation); if (shardState.hasData() == false) { logger.trace("{}: ignoring allocation, still fetching shard started state", shard); - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); continue; } @@ -83,8 +82,7 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { // if we are restoring this shard we still can allocate if (shard.restoreSource() == null) { // we can't really allocate, so ignore it and continue - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); logger.debug("[{}][{}]: not allocating, number_of_allocated_shards_found [{}]", shard.index(), shard.id(), nodesAndVersions.allocationsFound); } else { logger.debug("[{}][{}]: missing local data, will restore from [{}]", shard.index(), shard.id(), shard.restoreSource()); @@ -97,19 +95,16 @@ public abstract class PrimaryShardAllocator extends AbstractComponent { DiscoveryNode node = nodesToAllocate.yesNodes.get(0); logger.debug("[{}][{}]: allocating [{}] to [{}] on primary allocation", shard.index(), shard.id(), shard, node); changed = true; - routingNodes.initialize(new ShardRouting(shard, nodesAndVersions.highestVersion), node.id()); - unassignedIterator.remove(); + unassignedIterator.initialize(node.id(), nodesAndVersions.highestVersion); } else if (nodesToAllocate.throttleNodes.isEmpty() == true && nodesToAllocate.noNodes.isEmpty() == false) { DiscoveryNode node = nodesToAllocate.noNodes.get(0); logger.debug("[{}][{}]: forcing allocating [{}] to [{}] on primary allocation", shard.index(), shard.id(), shard, node); changed = true; - routingNodes.initialize(new ShardRouting(shard, nodesAndVersions.highestVersion), node.id()); - unassignedIterator.remove(); + unassignedIterator.initialize(node.id(), nodesAndVersions.highestVersion); } else { // we are throttling this, but we have enough to allocate to this node, ignore it for now logger.debug("[{}][{}]: throttling allocation [{}] to [{}] on primary allocation", shard.index(), shard.id(), shard, nodesToAllocate.throttleNodes); - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); } } return changed; diff --git a/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java b/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java index 06469c05de4..6879bda4fa2 100644 --- a/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java +++ b/core/src/main/java/org/elasticsearch/gateway/ReplicaShardAllocator.java @@ -52,7 +52,7 @@ public abstract class ReplicaShardAllocator extends AbstractComponent { final RoutingNodes routingNodes = allocation.routingNodes(); final MetaData metaData = routingNodes.metaData(); - final Iterator unassignedIterator = routingNodes.unassigned().iterator(); + final RoutingNodes.UnassignedShards.UnassignedIterator unassignedIterator = routingNodes.unassigned().iterator(); while (unassignedIterator.hasNext()) { ShardRouting shard = unassignedIterator.next(); if (shard.primary()) { @@ -77,16 +77,14 @@ public abstract class ReplicaShardAllocator extends AbstractComponent { if (!canBeAllocatedToAtLeastOneNode) { logger.trace("{}: ignoring allocation, can't be allocated on any node", shard); - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); continue; } AsyncShardFetch.FetchResult shardStores = fetchData(shard, allocation); if (shardStores.hasData() == false) { logger.trace("{}: ignoring allocation, still fetching shard stores", shard); - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); continue; // still fetching } @@ -175,16 +173,14 @@ public abstract class ReplicaShardAllocator extends AbstractComponent { logger.debug("[{}][{}]: throttling allocation [{}] to [{}] in order to reuse its unallocated persistent store with total_size [{}]", shard.index(), shard.id(), shard, lastDiscoNodeMatched, new ByteSizeValue(lastSizeMatched)); } // we are throttling this, but we have enough to allocate to this node, ignore it for now - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); } else { if (logger.isDebugEnabled()) { logger.debug("[{}][{}]: allocating [{}] to [{}] in order to reuse its unallocated persistent store with total_size [{}]", shard.index(), shard.id(), shard, lastDiscoNodeMatched, new ByteSizeValue(lastSizeMatched)); } // we found a match changed = true; - routingNodes.initialize(shard, lastNodeMatched.nodeId()); - unassignedIterator.remove(); + unassignedIterator.initialize(lastNodeMatched.nodeId()); } } else if (hasReplicaData == false) { // if we didn't manage to find *any* data (regardless of matching sizes), check if the allocation @@ -200,8 +196,7 @@ public abstract class ReplicaShardAllocator extends AbstractComponent { * see {@link org.elasticsearch.cluster.routing.RoutingService#clusterChanged(ClusterChangedEvent)}). */ changed = true; - unassignedIterator.remove(); - routingNodes.ignoredUnassigned().add(shard); + unassignedIterator.removeAndIgnore(); } } } diff --git a/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java b/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java index 8796c91340e..c5d41d9acd1 100644 --- a/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/PrimaryShardAllocatorTests.java @@ -77,8 +77,8 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase RoutingAllocation allocation = routingAllocationWithOnePrimaryNoReplicas(yesAllocationDeciders()); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); } /** @@ -90,8 +90,8 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, -1); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); } /** @@ -103,8 +103,8 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, 3, new CorruptIndexException("test", "test")); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); } /** @@ -116,7 +116,7 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, 10); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(true)); - assertThat(allocation.routingNodes().ignoredUnassigned().isEmpty(), equalTo(true)); + assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node1.id())); } @@ -131,8 +131,8 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, 10); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); } /** @@ -145,7 +145,7 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, 10); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(true)); - assertThat(allocation.routingNodes().ignoredUnassigned().isEmpty(), equalTo(true)); + assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node1.id())); } @@ -159,7 +159,7 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, 10).addData(node2, 12); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(true)); - assertThat(allocation.routingNodes().ignoredUnassigned().isEmpty(), equalTo(true)); + assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node2.id())); } @@ -185,7 +185,7 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase testAllocator.addData(node1, -1).addData(node2, -1); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().isEmpty(), equalTo(true)); + assertThat(allocation.routingNodes().unassigned().ignored().isEmpty(), equalTo(true)); } /** @@ -208,23 +208,23 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase RoutingAllocation allocation = new RoutingAllocation(yesAllocationDeciders(), state.routingNodes(), state.nodes(), null); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(2)); // replicas testAllocator.addData(node1, 1); allocation = new RoutingAllocation(yesAllocationDeciders(), state.routingNodes(), state.nodes(), null); changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(2)); // replicas testAllocator.addData(node2, 1); allocation = new RoutingAllocation(yesAllocationDeciders(), state.routingNodes(), state.nodes(), null); changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(true)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(0)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(0)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(2)); // replicas assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), anyOf(equalTo(node2.id()), equalTo(node1.id()))); @@ -250,23 +250,23 @@ public class PrimaryShardAllocatorTests extends ElasticsearchAllocationTestCase RoutingAllocation allocation = new RoutingAllocation(yesAllocationDeciders(), state.routingNodes(), state.nodes(), null); boolean changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(2)); // replicas testAllocator.addData(node1, 1); allocation = new RoutingAllocation(yesAllocationDeciders(), state.routingNodes(), state.nodes(), null); changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(false)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(1)); - assertThat(allocation.routingNodes().ignoredUnassigned().get(0).shardId(), equalTo(shardId)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(1)); + assertThat(allocation.routingNodes().unassigned().ignored().get(0).shardId(), equalTo(shardId)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(2)); // replicas testAllocator.addData(node2, 2); allocation = new RoutingAllocation(yesAllocationDeciders(), state.routingNodes(), state.nodes(), null); changed = testAllocator.allocateUnassigned(allocation); assertThat(changed, equalTo(true)); - assertThat(allocation.routingNodes().ignoredUnassigned().size(), equalTo(0)); + assertThat(allocation.routingNodes().unassigned().ignored().size(), equalTo(0)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.UNASSIGNED).size(), equalTo(2)); // replicas assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1)); assertThat(allocation.routingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo(node2.id())); diff --git a/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java b/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java index f6d205f4b92..aaf1bc0e25e 100644 --- a/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java +++ b/core/src/test/java/org/elasticsearch/gateway/PriorityComparatorTests.java @@ -30,7 +30,7 @@ import java.util.Map; public class PriorityComparatorTests extends ElasticsearchTestCase { public void testPriorityComparatorSort() { - RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards(); + RoutingNodes.UnassignedShards shards = new RoutingNodes.UnassignedShards((RoutingNodes) null); int numIndices = randomIntBetween(3, 99); IndexMeta[] indices = new IndexMeta[numIndices]; final Map map = new HashMap<>();