summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoaz Leskes <b.leskes@gmail.com>2016-09-19 13:54:35 +0200
committerGitHub <noreply@github.com>2016-09-19 13:54:35 +0200
commit2ee9ab25d9055cc8355921a0f94612c0a1bb4d65 (patch)
tree0822a5c9df647930ee069df49ab4afc8724be447
parent7cd0316b511c3e5acf5fc3749fcc3ba3597d5974 (diff)
Remove `RoutingAllocation.Result` (#20538)
Currently all the reroute-like methods of `AllocationService` return a result object of type `RoutingAllocation.Result`. The result object contains the new `RoutingTable` and `MetaData` plus an indication whether those were changed. The caller is then responsible of updating a cluster state with these. These means that things can easily go wrong and one can take one of these but not the other causing inconsistencies. We already have a utility method on the `ClusterState` builder that does but no one forces you to do so. Also 99% of the callers do the same thing: i.e., check if the result was changed and if so update the very same cluster state that was passed to `AllocationService`. This PR folds this pattern into `AllocationService` and changes almost all it's methods to return a new cluster state (potentially the original one). This saves some 500 lines of code. The one exception here is the reroute API which executes allocation commands and potentially returns an explanation as well (next to the routing table and metadata). That API now returns a `CommandsResult` object which encapsulate a cluster state and the explanation.
-rw-r--r--benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java7
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java12
-rw-r--r--core/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java7
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/ClusterState.java8
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java14
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java4
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java10
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java11
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java4
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/routing/DelayedAllocationService.java7
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java8
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java106
-rw-r--r--core/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java77
-rw-r--r--core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java11
-rw-r--r--core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java21
-rw-r--r--core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java5
-rw-r--r--core/src/main/java/org/elasticsearch/gateway/GatewayService.java8
-rw-r--r--core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java5
-rw-r--r--core/src/main/java/org/elasticsearch/snapshots/RestoreService.java6
-rw-r--r--core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java11
-rw-r--r--core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java6
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexServiceTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java57
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java37
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java128
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java38
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java219
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java131
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java17
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java215
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java24
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTests.java6
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java10
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java129
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java23
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java57
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java23
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java28
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java14
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java141
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java12
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java47
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/InSyncAllocationIdTests.java53
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java148
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java70
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java54
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java15
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java14
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java30
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java14
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java18
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java20
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java100
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java11
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java41
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java94
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java43
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java20
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java43
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java76
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java34
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java83
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java8
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java42
-rw-r--r--core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java39
-rw-r--r--core/src/test/java/org/elasticsearch/discovery/zen/NodeRemovalClusterStateTaskExecutorTests.java3
-rw-r--r--core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java4
-rw-r--r--core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java7
-rw-r--r--test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java11
70 files changed, 1129 insertions, 1678 deletions
diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java
index 86902b380c..39cfdb6582 100644
--- a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java
+++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/AllocationBenchmark.java
@@ -27,7 +27,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.settings.Settings;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -160,11 +159,9 @@ public class AllocationBenchmark {
public ClusterState measureAllocation() {
ClusterState clusterState = initialClusterState;
while (clusterState.getRoutingNodes().hasUnassignedShards()) {
- RoutingAllocation.Result result = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes()
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes()
.shardsWithState(ShardRoutingState.INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
- result = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
}
return clusterState;
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java
index fbfe3ad371..7aade821f8 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java
@@ -31,7 +31,6 @@ import org.elasticsearch.cluster.block.ClusterBlockException;
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.routing.allocation.RoutingExplanations;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
@@ -111,15 +110,14 @@ public class TransportClusterRerouteAction extends TransportMasterNodeAction<Clu
@Override
public ClusterState execute(ClusterState currentState) {
- RoutingAllocation.Result routingResult = allocationService.reroute(currentState, request.getCommands(), request.explain(),
- request.isRetryFailed());
- ClusterState newState = ClusterState.builder(currentState).routingResult(routingResult).build();
- clusterStateToSend = newState;
- explanations = routingResult.explanations();
+ AllocationService.CommandsResult commandsResult =
+ allocationService.reroute(currentState, request.getCommands(), request.explain(), request.isRetryFailed());
+ clusterStateToSend = commandsResult.getClusterState();
+ explanations = commandsResult.explanations();
if (request.dryRun()) {
return currentState;
}
- return newState;
+ return commandsResult.getClusterState();
}
}
}
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java
index 2907716eaa..7e77d22243 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java
@@ -33,7 +33,6 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Priority;
@@ -157,11 +156,7 @@ public class TransportClusterUpdateSettingsAction extends TransportMasterNodeAct
@Override
public ClusterState execute(final ClusterState currentState) {
// now, reroute in case things that require it changed (e.g. number of replicas)
- RoutingAllocation.Result routingResult = allocationService.reroute(currentState, "reroute after cluster update settings");
- if (!routingResult.changed()) {
- return currentState;
- }
- return ClusterState.builder(currentState).routingResult(routingResult).build();
+ return allocationService.reroute(currentState, "reroute after cluster update settings");
}
});
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java
index 202fc0f7ba..085cc513f2 100644
--- a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java
+++ b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java
@@ -22,7 +22,6 @@ package org.elasticsearch.cluster;
import com.carrotsearch.hppc.cursors.IntObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
-
import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.IndexMetaData;
@@ -37,7 +36,6 @@ import org.elasticsearch.cluster.routing.RoutingNode;
import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
@@ -629,12 +627,6 @@ public class ClusterState implements ToXContent, Diffable<ClusterState> {
return nodes;
}
- public Builder routingResult(RoutingAllocation.Result routingResult) {
- this.routingTable = routingResult.routingTable();
- this.metaData = routingResult.metaData();
- return this;
- }
-
public Builder routingTable(RoutingTable routingTable) {
this.routingTable = routingTable;
return this;
diff --git a/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java b/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java
index 13aa148f8b..a2c9a7b5f8 100644
--- a/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java
+++ b/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java
@@ -38,7 +38,6 @@ import org.elasticsearch.cluster.routing.RoutingService;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Priority;
@@ -311,10 +310,7 @@ public class ShardStateAction extends AbstractComponent {
ClusterState maybeUpdatedState = currentState;
try {
- RoutingAllocation.Result result = applyFailedShards(currentState, shardRoutingsToBeApplied, staleShardsToBeApplied);
- if (result.changed()) {
- maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
- }
+ maybeUpdatedState = applyFailedShards(currentState, shardRoutingsToBeApplied, staleShardsToBeApplied);
batchResultBuilder.successes(tasksToBeApplied);
} catch (Exception e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to apply failed shards {}", shardRoutingsToBeApplied), e);
@@ -327,7 +323,7 @@ public class ShardStateAction extends AbstractComponent {
}
// visible for testing
- RoutingAllocation.Result applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
+ ClusterState applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
List<FailedRerouteAllocation.StaleShard> staleShards) {
return allocationService.applyFailedShards(currentState, failedShards, staleShards);
}
@@ -426,11 +422,7 @@ public class ShardStateAction extends AbstractComponent {
ClusterState maybeUpdatedState = currentState;
try {
- RoutingAllocation.Result result =
- allocationService.applyStartedShards(currentState, shardRoutingsToBeApplied, true);
- if (result.changed()) {
- maybeUpdatedState = ClusterState.builder(currentState).routingResult(result).build();
- }
+ maybeUpdatedState = allocationService.applyStartedShards(currentState, shardRoutingsToBeApplied, true);
builder.successes(tasksToBeApplied);
} catch (Exception e) {
logger.warn((Supplier<?>) () -> new ParameterizedMessage("failed to apply started shards {}", shardRoutingsToBeApplied), e);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
index f24c1bba3f..6f58785482 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataCreateIndexService.java
@@ -46,7 +46,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.Strings;
@@ -430,10 +429,9 @@ public class MetaDataCreateIndexService extends AbstractComponent {
if (request.state() == State.OPEN) {
RoutingTable.Builder routingTableBuilder = RoutingTable.builder(updatedState.routingTable())
.addAsNew(updatedState.metaData().index(request.index()));
- RoutingAllocation.Result routingResult = allocationService.reroute(
+ updatedState = allocationService.reroute(
ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
"index [" + request.index() + "] created");
- updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
}
removalReason = "cleaning up after validating index on master";
return updatedState;
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java
index 07e64eac61..22553dd992 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexService.java
@@ -27,7 +27,6 @@ import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractComponent;
@@ -108,9 +107,12 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
MetaData newMetaData = metaDataBuilder.build();
ClusterBlocks blocks = clusterBlocksBuilder.build();
- RoutingAllocation.Result routingResult = allocationService.reroute(
- ClusterState.builder(currentState).routingTable(routingTableBuilder.build()).metaData(newMetaData).build(),
+ return allocationService.reroute(
+ ClusterState.builder(currentState)
+ .routingTable(routingTableBuilder.build())
+ .metaData(newMetaData)
+ .blocks(blocks)
+ .build(),
"deleted indices [" + indices + "]");
- return ClusterState.builder(currentState).routingResult(routingResult).metaData(newMetaData).blocks(blocks).build();
}
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java
index 53a0ede809..fd7c34dbe6 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateService.java
@@ -31,7 +31,6 @@ import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractComponent;
@@ -125,11 +124,10 @@ public class MetaDataIndexStateService extends AbstractComponent {
rtBuilder.remove(index.getIndex().getName());
}
- RoutingAllocation.Result routingResult = allocationService.reroute(
+ //no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
+ return allocationService.reroute(
ClusterState.builder(updatedState).routingTable(rtBuilder.build()).build(),
"indices closed [" + indicesAsString + "]");
- //no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
- return ClusterState.builder(updatedState).routingResult(routingResult).build();
}
});
}
@@ -188,11 +186,10 @@ public class MetaDataIndexStateService extends AbstractComponent {
rtBuilder.addAsFromCloseToOpen(updatedState.metaData().getIndexSafe(index.getIndex()));
}
- RoutingAllocation.Result routingResult = allocationService.reroute(
+ //no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
+ return allocationService.reroute(
ClusterState.builder(updatedState).routingTable(rtBuilder.build()).build(),
"indices opened [" + indicesAsString + "]");
- //no explicit wait for other nodes needed as we use AckedClusterStateUpdateTask
- return ClusterState.builder(updatedState).routingResult(routingResult).build();
}
});
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java
index 9db777a479..41dd64cf86 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/MetaDataUpdateSettingsService.java
@@ -33,7 +33,6 @@ import org.elasticsearch.cluster.block.ClusterBlock;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.collect.Tuple;
@@ -271,8 +270,7 @@ public class MetaDataUpdateSettingsService extends AbstractComponent implements
ClusterState updatedState = ClusterState.builder(currentState).metaData(metaDataBuilder).routingTable(routingTableBuilder.build()).blocks(blocks).build();
// now, reroute in case things change that require it (like number of replicas)
- RoutingAllocation.Result routingResult = allocationService.reroute(updatedState, "settings update");
- updatedState = ClusterState.builder(updatedState).routingResult(routingResult).build();
+ updatedState = allocationService.reroute(updatedState, "settings update");
try {
for (Index index : openIndices) {
final IndexMetaData currentMetaData = currentState.getMetaData().getIndexSafe(index);
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/DelayedAllocationService.java b/core/src/main/java/org/elasticsearch/cluster/routing/DelayedAllocationService.java
index 29d74dd893..55c6750b82 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/DelayedAllocationService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/DelayedAllocationService.java
@@ -106,12 +106,7 @@ public class DelayedAllocationService extends AbstractLifecycleComponent impleme
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
removeIfSameTask(this);
- RoutingAllocation.Result routingResult = allocationService.reroute(currentState, "assign delayed unassigned shards");
- if (routingResult.changed()) {
- return ClusterState.builder(currentState).routingResult(routingResult).build();
- } else {
- return currentState;
- }
+ return allocationService.reroute(currentState, "assign delayed unassigned shards");
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java
index 8300d3e37f..9dd2cc72da 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/RoutingService.java
@@ -25,7 +25,6 @@ import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
@@ -96,12 +95,7 @@ public class RoutingService extends AbstractLifecycleComponent {
@Override
public ClusterState execute(ClusterState currentState) {
rerouting.set(false);
- RoutingAllocation.Result routingResult = allocationService.reroute(currentState, reason);
- if (!routingResult.changed()) {
- // no state changed
- return currentState;
- }
- return ClusterState.builder(currentState).routingResult(routingResult).build();
+ return allocationService.reroute(currentState, reason);
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
index 214bedc324..77926fd742 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java
@@ -32,7 +32,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.cluster.routing.UnassignedInfo.AllocationStatus;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation.Result;
import org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator;
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
@@ -79,15 +78,15 @@ public class AllocationService extends AbstractComponent {
* Applies the started shards. Note, only initializing ShardRouting instances that exist in the routing table should be
* provided as parameter and no duplicates should be contained.
* <p>
- * If the same instance of the routing table is returned, then no change has been made.</p>
+ * If the same instance of the {@link ClusterState} is returned, then no change has been made.</p>
*/
- public Result applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards) {
+ public ClusterState applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards) {
return applyStartedShards(clusterState, startedShards, true);
}
- public Result applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards, boolean withReroute) {
+ public ClusterState applyStartedShards(ClusterState clusterState, List<ShardRouting> startedShards, boolean withReroute) {
if (startedShards.isEmpty()) {
- return Result.unchanged(clusterState);
+ return clusterState;
}
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
@@ -100,35 +99,35 @@ public class AllocationService extends AbstractComponent {
reroute(allocation);
}
String startedShardsAsString = firstListElementsToCommaDelimitedString(startedShards, s -> s.shardId().toString());
- return buildResultAndLogHealthChange(allocation, "shards started [" + startedShardsAsString + "] ...");
+ return buildResultAndLogHealthChange(clusterState, allocation, "shards started [" + startedShardsAsString + "] ...");
}
- protected Result buildResultAndLogHealthChange(RoutingAllocation allocation, String reason) {
- return buildResultAndLogHealthChange(allocation, reason, new RoutingExplanations());
+ protected ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, String reason) {
+ return buildResultAndLogHealthChange(oldState, allocation, reason, new RoutingExplanations());
}
- protected Result buildResultAndLogHealthChange(RoutingAllocation allocation, String reason, RoutingExplanations explanations) {
- RoutingTable oldRoutingTable = allocation.routingTable();
+ protected ClusterState buildResultAndLogHealthChange(ClusterState oldState, RoutingAllocation allocation, String reason,
+ RoutingExplanations explanations) {
+ RoutingTable oldRoutingTable = oldState.routingTable();
RoutingNodes newRoutingNodes = allocation.routingNodes();
final RoutingTable newRoutingTable = new RoutingTable.Builder().updateNodes(oldRoutingTable.version(), newRoutingNodes).build();
MetaData newMetaData = allocation.updateMetaDataWithRoutingChanges(newRoutingTable);
assert newRoutingTable.validate(newMetaData); // validates the routing table is coherent with the cluster state metadata
+ final ClusterState newState = ClusterState.builder(oldState).routingTable(newRoutingTable).metaData(newMetaData).build();
logClusterHealthStateChange(
- new ClusterStateHealth(ClusterState.builder(clusterName).
- metaData(allocation.metaData()).routingTable(oldRoutingTable).build()),
- new ClusterStateHealth(ClusterState.builder(clusterName).
- metaData(newMetaData).routingTable(newRoutingTable).build()),
+ new ClusterStateHealth(oldState),
+ new ClusterStateHealth(newState),
reason
);
- return Result.changed(newRoutingTable, newMetaData, explanations);
+ return newState;
}
- public Result applyFailedShard(ClusterState clusterState, ShardRouting failedShard) {
+ public ClusterState applyFailedShard(ClusterState clusterState, ShardRouting failedShard) {
return applyFailedShards(clusterState, Collections.singletonList(new FailedRerouteAllocation.FailedShard(failedShard, null, null)),
Collections.emptyList());
}
- public Result applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards) {
+ public ClusterState applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards) {
return applyFailedShards(clusterState, failedShards, Collections.emptyList());
}
@@ -138,20 +137,20 @@ public class AllocationService extends AbstractComponent {
* are no routing entries in the routing table.
*
* <p>
- * If the same instance of the routing table is returned, then no change has been made.</p>
+ * If the same instance of ClusterState is returned, then no change has been made.</p>
*/
- public Result applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards,
- List<FailedRerouteAllocation.StaleShard> staleShards) {
+ public ClusterState applyFailedShards(final ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards,
+ List<FailedRerouteAllocation.StaleShard> staleShards) {
if (staleShards.isEmpty() && failedShards.isEmpty()) {
- return Result.unchanged(clusterState);
+ return clusterState;
}
- clusterState = IndexMetaDataUpdater.removeStaleIdsWithoutRoutings(clusterState, staleShards);
+ ClusterState tmpState = IndexMetaDataUpdater.removeStaleIdsWithoutRoutings(clusterState, staleShards);
- RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
+ RoutingNodes routingNodes = getMutableRoutingNodes(tmpState);
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
routingNodes.unassigned().shuffle();
long currentNanoTime = currentNanoTime();
- FailedRerouteAllocation allocation = new FailedRerouteAllocation(allocationDeciders, routingNodes, clusterState, failedShards,
+ FailedRerouteAllocation allocation = new FailedRerouteAllocation(allocationDeciders, routingNodes, tmpState, failedShards,
clusterInfoService.getClusterInfo(), currentNanoTime);
for (FailedRerouteAllocation.FailedShard failedShardEntry : failedShards) {
@@ -178,14 +177,14 @@ public class AllocationService extends AbstractComponent {
reroute(allocation);
String failedShardsAsString = firstListElementsToCommaDelimitedString(failedShards, s -> s.routingEntry.shardId().toString());
- return buildResultAndLogHealthChange(allocation, "shards failed [" + failedShardsAsString + "] ...");
+ return buildResultAndLogHealthChange(clusterState, allocation, "shards failed [" + failedShardsAsString + "] ...");
}
/**
* unassigned an shards that are associated with nodes that are no longer part of the cluster, potentially promoting replicas
* if needed.
*/
- public RoutingAllocation.Result deassociateDeadNodes(ClusterState clusterState, boolean reroute, String reason) {
+ public ClusterState deassociateDeadNodes(final ClusterState clusterState, boolean reroute, String reason) {
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
routingNodes.unassigned().shuffle();
@@ -200,9 +199,9 @@ public class AllocationService extends AbstractComponent {
}
if (allocation.routingNodesChanged() == false) {
- return Result.unchanged(clusterState);
+ return clusterState;
}
- return buildResultAndLogHealthChange(allocation, reason);
+ return buildResultAndLogHealthChange(clusterState, allocation, reason);
}
/**
@@ -244,7 +243,7 @@ public class AllocationService extends AbstractComponent {
.collect(Collectors.joining(", "));
}
- public Result reroute(ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed) {
+ public CommandsResult reroute(final ClusterState clusterState, AllocationCommands commands, boolean explain, boolean retryFailed) {
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
// we don't shuffle the unassigned shards here, to try and get as close as possible to
// a consistent result of the effect the commands have on the routing
@@ -261,25 +260,25 @@ public class AllocationService extends AbstractComponent {
// the assumption is that commands will move / act on shards (or fail through exceptions)
// so, there will always be shard "movements", so no need to check on reroute
reroute(allocation);
- return buildResultAndLogHealthChange(allocation, "reroute commands", explanations);
+ return new CommandsResult(explanations, buildResultAndLogHealthChange(clusterState, allocation, "reroute commands"));
}
/**
* Reroutes the routing table based on the live nodes.
* <p>
- * If the same instance of the routing table is returned, then no change has been made.
+ * If the same instance of ClusterState is returned, then no change has been made.
*/
- public Result reroute(ClusterState clusterState, String reason) {
+ public ClusterState reroute(ClusterState clusterState, String reason) {
return reroute(clusterState, reason, false);
}
/**
* Reroutes the routing table based on the live nodes.
* <p>
- * If the same instance of the routing table is returned, then no change has been made.
+ * If the same instance of ClusterState is returned, then no change has been made.
*/
- protected Result reroute(ClusterState clusterState, String reason, boolean debug) {
+ protected ClusterState reroute(final ClusterState clusterState, String reason, boolean debug) {
RoutingNodes routingNodes = getMutableRoutingNodes(clusterState);
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
routingNodes.unassigned().shuffle();
@@ -288,9 +287,9 @@ public class AllocationService extends AbstractComponent {
allocation.debugDecision(debug);
reroute(allocation);
if (allocation.routingNodesChanged() == false) {
- return Result.unchanged(clusterState);
+ return clusterState;
}
- return buildResultAndLogHealthChange(allocation, reason);
+ return buildResultAndLogHealthChange(clusterState, allocation, reason);
}
private void logClusterHealthStateChange(ClusterStateHealth previousStateHealth, ClusterStateHealth newStateHealth, String reason) {
@@ -368,4 +367,39 @@ public class AllocationService extends AbstractComponent {
protected long currentNanoTime() {
return System.nanoTime();
}
+
+ /**
+ * this class is used to describe results of applying a set of
+ * {@link org.elasticsearch.cluster.routing.allocation.command.AllocationCommand}
+ */
+ public static class CommandsResult {
+
+ private final RoutingExplanations explanations;
+
+ private final ClusterState clusterState;
+
+ /**
+ * Creates a new {@link CommandsResult}
+ * @param explanations Explanation for the reroute actions
+ * @param clusterState Resulting cluster state
+ */
+ private CommandsResult(RoutingExplanations explanations, ClusterState clusterState) {
+ this.clusterState = clusterState;
+ this.explanations = explanations;
+ }
+
+ /**
+ * Get the explanation of this result
+ */
+ public RoutingExplanations explanations() {
+ return explanations;
+ }
+
+ /**
+ * thre resulting cluster state, after the commands were applied
+ */
+ public ClusterState getClusterState() {
+ return clusterState;
+ }
+ }
}
diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java
index f2d40b38a4..8429493b0e 100644
--- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java
+++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/RoutingAllocation.java
@@ -46,83 +46,6 @@ import static java.util.Collections.unmodifiableSet;
*/
public class RoutingAllocation {
- /**
- * this class is used to describe results of a {@link RoutingAllocation}
- */
- public static class Result {
-
- private final boolean changed;
-
- private final RoutingTable routingTable;
-
- private final MetaData metaData;
-
- private final RoutingExplanations explanations;
-
- /**
- * Creates a new {@link RoutingAllocation.Result} where no change to the routing table was made.
- * @param clusterState the unchanged {@link ClusterState}
- */
- public static Result unchanged(ClusterState clusterState) {
- return new Result(false, clusterState.routingTable(), clusterState.metaData(), new RoutingExplanations());
- }
-
- /**
- * Creates a new {@link RoutingAllocation.Result} where changes were made to the routing table.
- * @param routingTable the {@link RoutingTable} this Result references
- * @param metaData the {@link MetaData} this Result references
- * @param explanations Explanation for the reroute actions
- */
- public static Result changed(RoutingTable routingTable, MetaData metaData, RoutingExplanations explanations) {
- return new Result(true, routingTable, metaData, explanations);
- }
-
- /**
- * Creates a new {@link RoutingAllocation.Result}
- * @param changed a flag to determine whether the actual {@link RoutingTable} has been changed
- * @param routingTable the {@link RoutingTable} this Result references
- * @param metaData the {@link MetaData} this Result references
- * @param explanations Explanation for the reroute actions
- */
- private Result(boolean changed, RoutingTable routingTable, MetaData metaData, RoutingExplanations explanations) {
- this.changed = changed;
- this.routingTable = routingTable;
- this.metaData = metaData;
- this.explanations = explanations;
- }
-
- /** determine whether the actual {@link RoutingTable} has been changed
- * @return <code>true</code> if the {@link RoutingTable} has been changed by allocation. Otherwise <code>false</code>
- */
- public boolean changed() {
- return this.changed;
- }
-
- /**
- * Get the {@link MetaData} referenced by this result
- * @return referenced {@link MetaData}
- */
- public MetaData metaData() {
- return metaData;
- }
-
- /**
- * Get the {@link RoutingTable} referenced by this result
- * @return referenced {@link RoutingTable}
- */
- public RoutingTable routingTable() {
- return routingTable;
- }
-
- /**
- * Get the explanation of this result
- * @return explanation
- */
- public RoutingExplanations explanations() {
- return explanations;
- }
- }
-
private final AllocationDeciders deciders;
private final RoutingNodes routingNodes;
diff --git a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java
index d84f471cff..6b943bde78 100644
--- a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java
+++ b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java
@@ -31,7 +31,6 @@ import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
@@ -167,11 +166,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implements Discov
}
nodesBuilder.localNodeId(master.localNode().getId()).masterNodeId(master.localNode().getId());
currentState = ClusterState.builder(currentState).nodes(nodesBuilder).build();
- RoutingAllocation.Result result = master.allocationService.reroute(currentState, "node_add");
- if (result.changed()) {
- currentState = ClusterState.builder(currentState).routingResult(result).build();
- }
- return currentState;
+ return master.allocationService.reroute(currentState, "node_add");
}
@Override
@@ -234,9 +229,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implements Discov
}
// reroute here, so we eagerly remove dead nodes from the routing
ClusterState updatedState = ClusterState.builder(currentState).nodes(newNodes).build();
- RoutingAllocation.Result routingResult = master.allocationService.deassociateDeadNodes(
- ClusterState.builder(updatedState).build(), true, "node stopped");
- return ClusterState.builder(updatedState).routingResult(routingResult).build();
+ return master.allocationService.deassociateDeadNodes(updatedState, true, "node stopped");
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java b/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java
index bf8559fb94..75cce69535 100644
--- a/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java
+++ b/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java
@@ -33,7 +33,6 @@ import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractComponent;
@@ -456,17 +455,12 @@ public class NodeJoinController extends AbstractComponent {
if (nodesChanged) {
newState.nodes(nodesBuilder);
- final ClusterState tmpState = newState.build();
- RoutingAllocation.Result result = allocationService.reroute(tmpState, "node_join");
- newState = ClusterState.builder(tmpState);
- if (result.changed()) {
- newState.routingResult(result);
- }
+ return results.build(allocationService.reroute(newState.build(), "node_join"));
+ } else {
+ // we must return a new cluster state instance to force publishing. This is important
+ // for the joining node to finalize its join and set us as a master
+ return results.build(newState.build());
}
-
- // we must return a new cluster state instance to force publishing. This is important
- // for the joining node to finalize its join and set us as a master
- return results.build(newState.build());
}
private ClusterState.Builder becomeMasterAndTrimConflictingNodes(ClusterState currentState, List<DiscoveryNode> joiningNodes) {
@@ -486,9 +480,8 @@ public class NodeJoinController extends AbstractComponent {
// now trim any left over dead nodes - either left there when the previous master stepped down
// or removed by us above
ClusterState tmpState = ClusterState.builder(currentState).nodes(nodesBuilder).blocks(clusterBlocks).build();
- RoutingAllocation.Result result = allocationService.deassociateDeadNodes(tmpState, false,
- "removed dead nodes on election");
- return ClusterState.builder(tmpState).routingResult(result);
+ return ClusterState.builder(allocationService.deassociateDeadNodes(tmpState, false,
+ "removed dead nodes on election"));
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
index 43739a2f41..7f47f29175 100644
--- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
+++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java
@@ -38,7 +38,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Priority;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
@@ -571,9 +570,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
if (!electMasterService.hasEnoughMasterNodes(remainingNodesClusterState.nodes())) {
return resultBuilder.build(rejoin.apply(remainingNodesClusterState, "not enough master nodes"));
} else {
- final RoutingAllocation.Result routingResult =
- allocationService.deassociateDeadNodes(remainingNodesClusterState, true, describeTasks(tasks));
- return resultBuilder.build(ClusterState.builder(remainingNodesClusterState).routingResult(routingResult).build());
+ return resultBuilder.build(allocationService.deassociateDeadNodes(remainingNodesClusterState, true, describeTasks(tasks)));
}
}
diff --git a/core/src/main/java/org/elasticsearch/gateway/GatewayService.java b/core/src/main/java/org/elasticsearch/gateway/GatewayService.java
index b953173c68..856574748d 100644
--- a/core/src/main/java/org/elasticsearch/gateway/GatewayService.java
+++ b/core/src/main/java/org/elasticsearch/gateway/GatewayService.java
@@ -34,7 +34,6 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
@@ -282,11 +281,8 @@ public class GatewayService extends AbstractLifecycleComponent implements Cluste
routingTableBuilder.version(0);
// now, reroute
- RoutingAllocation.Result routingResult = allocationService.reroute(
- ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build(),
- "state recovered");
-
- return ClusterState.builder(updatedState).routingResult(routingResult).build();
+ updatedState = ClusterState.builder(updatedState).routingTable(routingTableBuilder.build()).build();
+ return allocationService.reroute(updatedState, "state recovered");
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java b/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java
index 707cc89704..24562b5216 100644
--- a/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java
+++ b/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java
@@ -30,7 +30,6 @@ import org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
@@ -169,10 +168,8 @@ public class LocalAllocateDangledIndices extends AbstractComponent {
ClusterState updatedState = ClusterState.builder(currentState).metaData(metaData).blocks(blocks).routingTable(routingTable).build();
// now, reroute
- RoutingAllocation.Result routingResult = allocationService.reroute(
+ return allocationService.reroute(
ClusterState.builder(updatedState).routingTable(routingTable).build(), "dangling indices allocated");
-
- return ClusterState.builder(updatedState).routingResult(routingResult).build();
}
@Override
diff --git a/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java b/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java
index 180f8f0af1..5e30a3b52b 100644
--- a/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java
+++ b/core/src/main/java/org/elasticsearch/snapshots/RestoreService.java
@@ -47,7 +47,6 @@ import org.elasticsearch.cluster.routing.RecoverySource.SnapshotRecoverySource;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.UUIDs;
@@ -336,10 +335,7 @@ public class RestoreService extends AbstractComponent implements ClusterStateLis
RoutingTable rt = rtBuilder.build();
ClusterState updatedState = builder.metaData(mdBuilder).blocks(blocks).routingTable(rt).build();
- RoutingAllocation.Result routingResult = allocationService.reroute(
- ClusterState.builder(updatedState).routingTable(rt).build(),
- "restored snapshot [" + snapshot + "]");
- return ClusterState.builder(updatedState).routingResult(routingResult).build();
+ return allocationService.reroute(updatedState, "restored snapshot [" + snapshot + "]");
}
private void checkAliasNameConflicts(Map<String, String> renamedIndices, Set<String> aliases) {
diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java
index 58ea503529..f13e848ae7 100644
--- a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java
+++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.action.admin.cluster.reroute;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.EmptyClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -28,7 +29,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
import org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand;
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
@@ -41,7 +41,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import java.io.IOException;
@@ -51,6 +50,8 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
public class ClusterRerouteTests extends ESAllocationTestCase {
@@ -121,9 +122,9 @@ public class ClusterRerouteTests extends ESAllocationTestCase {
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i,
new UnsupportedOperationException()));
- RoutingAllocation.Result result = allocationService.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- clusterState = ClusterState.builder(clusterState).routingTable(result.routingTable()).build();
+ newState = allocationService.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingTable = clusterState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
if (i == retries-1) {
diff --git a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java
index b9bda2ec65..f1e51d6224 100644
--- a/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java
+++ b/core/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationActionTests.java
@@ -42,7 +42,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.io.stream.StreamInput;
@@ -296,8 +295,7 @@ public class TransportReplicationActionTests extends ESTestCase {
ShardRouting relocationTarget = clusterService.state().getRoutingTable().shardRoutingTable(shardId)
.shardsWithState(ShardRoutingState.INITIALIZING).get(0);
AllocationService allocationService = ESAllocationTestCase.createAllocationService();
- RoutingAllocation.Result result = allocationService.applyStartedShards(state, Arrays.asList(relocationTarget));
- ClusterState updatedState = ClusterState.builder(clusterService.state()).routingResult(result).build();
+ ClusterState updatedState = allocationService.applyStartedShards(state, Arrays.asList(relocationTarget));
setState(clusterService, updatedState);
logger.debug("--> relocation complete state:\n{}", clusterService.state().prettyPrint());
diff --git a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java
index ff0e0ba7a2..13ec55a41c 100644
--- a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardFailedClusterStateTaskExecutorTests.java
@@ -38,7 +38,6 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.UUIDs;
import org.elasticsearch.common.settings.Settings;
@@ -116,7 +115,7 @@ public class ShardFailedClusterStateTaskExecutorTests extends ESAllocationTestCa
List<ShardStateAction.ShardEntry> nonExistentTasks = createNonExistentShards(currentState, reason);
ShardStateAction.ShardFailedClusterStateTaskExecutor failingExecutor = new ShardStateAction.ShardFailedClusterStateTaskExecutor(allocationService, null, logger) {
@Override
- RoutingAllocation.Result applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
+ ClusterState applyFailedShards(ClusterState currentState, List<FailedRerouteAllocation.FailedShard> failedShards,
List<FailedRerouteAllocation.StaleShard> staleShards) {
throw new RuntimeException("simulated applyFailedShards failure");
}
@@ -161,8 +160,7 @@ public class ShardFailedClusterStateTaskExecutorTests extends ESAllocationTestCa
allocationService.reroute(stateAfterAddingNode, reason).routingTable();
ClusterState stateAfterReroute = ClusterState.builder(stateAfterAddingNode).routingTable(afterReroute).build();
RoutingNodes routingNodes = stateAfterReroute.getRoutingNodes();
- RoutingAllocation.Result afterStart = allocationService.applyStartedShards(stateAfterReroute, routingNodes.shardsWithState(ShardRoutingState.INITIALIZING));
- return ClusterState.builder(stateAfterReroute).routingResult(afterStart).build();
+ return allocationService.applyStartedShards(stateAfterReroute, routingNodes.shardsWithState(ShardRoutingState.INITIALIZING));
}
private List<ShardStateAction.ShardEntry> createExistingShards(ClusterState currentState, String reason) {
diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexServiceTests.java
index f172b7ffdf..a48f3ae3e1 100644
--- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataDeleteIndexServiceTests.java
@@ -25,7 +25,6 @@ import org.elasticsearch.cluster.SnapshotsInProgress;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
@@ -76,8 +75,7 @@ public class MetaDataDeleteIndexServiceTests extends ESTestCase {
ClusterState before = clusterState(index);
// Mock the built reroute
- when(allocationService.reroute(any(ClusterState.class), any(String.class))).then(
- i -> RoutingAllocation.Result.unchanged((ClusterState) i.getArguments()[0]));
+ when(allocationService.reroute(any(ClusterState.class), any(String.class))).then(i -> i.getArguments()[0]);
// Remove it
ClusterState after = service.deleteIndices(before, singleton(before.metaData().getIndices().get(index).getIndex()));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java
index 3dc7e7d221..a700358384 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/DelayedAllocationServiceTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateUpdateTask;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -32,7 +33,6 @@ import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool;
import org.junit.After;
@@ -92,15 +92,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).localNodeId("node1").masterNodeId("node1"))
.build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
+ clusterState = allocationService.reroute(clusterState, "reroute");
// starting primaries
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
ClusterState prevState = clusterState;
// remove node2 and reroute
@@ -110,8 +106,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
nodes.add(newNode("node3"));
}
clusterState = ClusterState.builder(clusterState).nodes(nodes).build();
- clusterState = ClusterState.builder(clusterState).routingResult(
- allocationService.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
ClusterState newState = clusterState;
List<ShardRouting> unassignedShards = newState.getRoutingTable().shardsWithState(ShardRoutingState.UNASSIGNED);
if (nodeAvailableForAllocation) {
@@ -141,15 +136,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
.build();
final long baseTimestampNanos = System.nanoTime();
allocationService.setNanoTimeOverride(baseTimestampNanos);
- clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
+ clusterState = allocationService.reroute(clusterState, "reroute");
// starting primaries
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertFalse("no shards should be unassigned", clusterState.getRoutingNodes().unassigned().size() > 0);
String nodeId = null;
final List<ShardRouting> allShards = clusterState.getRoutingTable().allShards("test");
@@ -164,8 +155,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
// remove node that has replica and reroute
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(nodeId)).build();
- clusterState = ClusterState.builder(clusterState).routingResult(
- allocationService.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
ClusterState stateWithDelayedShard = clusterState;
// make sure the replica is marked as delayed (i.e. not reallocated)
assertEquals(1, UnassignedInfo.getNumberOfDelayedUnassigned(stateWithDelayedShard));
@@ -238,15 +228,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
.add(newNode("node0", singleton(DiscoveryNode.Role.MASTER))).localNodeId("node0").masterNodeId("node0")
.add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4"))).build();
// allocate shards
- clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
+ clusterState = allocationService.reroute(clusterState, "reroute");
// start primaries
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// start replicas
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat("all shards should be started", clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
// find replica of short_delay
@@ -280,8 +266,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
.build();
// make sure both replicas are marked as delayed (i.e. not reallocated)
allocationService.setNanoTimeOverride(baseTimestampNanos);
- clusterState = ClusterState.builder(clusterState).routingResult(
- allocationService.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = allocationService.deassociateDeadNodes(clusterState, true, "reroute");
final ClusterState stateWithDelayedShards = clusterState;
assertEquals(2, UnassignedInfo.getNumberOfDelayedUnassigned(stateWithDelayedShards));
RoutingNodes.UnassignedShards.UnassignedIterator iter = stateWithDelayedShards.getRoutingNodes().unassigned().iterator();
@@ -400,15 +385,11 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
.build();
final long nodeLeftTimestampNanos = System.nanoTime();
allocationService.setNanoTimeOverride(nodeLeftTimestampNanos);
- clusterState = ClusterState.builder(clusterState).routingResult(allocationService.reroute(clusterState, "reroute")).build();
+ clusterState = allocationService.reroute(clusterState, "reroute");
// starting primaries
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState)
- .routingResult(allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)))
- .build();
+ clusterState = allocationService.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertFalse("no shards should be unassigned", clusterState.getRoutingNodes().unassigned().size() > 0);
String nodeIdOfFooReplica = null;
for (ShardRouting shardRouting : clusterState.getRoutingTable().allShards("foo")) {
@@ -422,8 +403,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
// remove node that has replica and reroute
clusterState = ClusterState.builder(clusterState).nodes(
DiscoveryNodes.builder(clusterState.nodes()).remove(nodeIdOfFooReplica)).build();
- clusterState = ClusterState.builder(clusterState).routingResult(
- allocationService.deassociateDeadNodes(clusterState, true, "fake node left")).build();
+ clusterState = allocationService.deassociateDeadNodes(clusterState, true, "fake node left");
ClusterState stateWithDelayedShard = clusterState;
// make sure the replica is marked as delayed (i.e. not reallocated)
assertEquals(1, UnassignedInfo.getNumberOfDelayedUnassigned(stateWithDelayedShard));
@@ -466,8 +446,7 @@ public class DelayedAllocationServiceTests extends ESAllocationTestCase {
// remove node that has replica and reroute
clusterState = ClusterState.builder(stateWithDelayedShard).nodes(
DiscoveryNodes.builder(stateWithDelayedShard.nodes()).remove(nodeIdOfBarReplica)).build();
- ClusterState stateWithShorterDelay = ClusterState.builder(clusterState).routingResult(
- allocationService.deassociateDeadNodes(clusterState, true, "fake node left")).build();
+ ClusterState stateWithShorterDelay = allocationService.deassociateDeadNodes(clusterState, true, "fake node left");
delayedAllocationService.setNanoTimeOverride(clusterChangeEventTimestampNanos);
delayedAllocationService.clusterChanged(
new ClusterChangedEvent("fake node left", stateWithShorterDelay, stateWithDelayedShard));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java
index 388d454813..cf22462865 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/PrimaryTermsTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.health.ClusterStateHealth;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -28,9 +29,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.node.DiscoveryNodes.Builder;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.ArrayList;
import java.util.Collections;
@@ -42,13 +41,12 @@ import java.util.Set;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
public class PrimaryTermsTests extends ESAllocationTestCase {
private static final String TEST_INDEX_1 = "test1";
private static final String TEST_INDEX_2 = "test2";
- private RoutingTable testRoutingTable;
private int numberOfShards;
private int numberOfReplicas;
private static final Settings DEFAULT_SETTINGS = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
@@ -73,7 +71,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
.put(createIndexMetaData(TEST_INDEX_2))
.build();
- this.testRoutingTable = new RoutingTable.Builder()
+ RoutingTable routingTable = new RoutingTable.Builder()
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_1).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_1))
.build())
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_2).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_2))
@@ -81,7 +79,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
.build();
this.clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
- .metaData(metaData).routingTable(testRoutingTable).build();
+ .metaData(metaData).routingTable(routingTable).build();
}
/**
@@ -94,9 +92,8 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
discoBuilder = discoBuilder.add(newNode("node" + i));
}
this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
- RoutingAllocation.Result rerouteResult = allocationService.reroute(clusterState, "reroute");
- this.testRoutingTable = rerouteResult.routingTable();
- assertThat(rerouteResult.changed(), is(true));
+ ClusterState rerouteResult = allocationService.reroute(clusterState, "reroute");
+ assertThat(rerouteResult, not(equalTo(this.clusterState)));
applyRerouteResult(rerouteResult);
primaryTermsPerIndex.keySet().forEach(this::incrementPrimaryTerm);
}
@@ -113,17 +110,16 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
}
private boolean startInitializingShards(String index) {
- this.clusterState = ClusterState.builder(clusterState).routingTable(this.testRoutingTable).build();
final List<ShardRouting> startedShards = this.clusterState.getRoutingNodes().shardsWithState(index, INITIALIZING);
logger.info("start primary shards for index [{}]: {} ", index, startedShards);
- RoutingAllocation.Result rerouteResult = allocationService.applyStartedShards(this.clusterState, startedShards);
+ ClusterState rerouteResult = allocationService.applyStartedShards(this.clusterState, startedShards);
+ boolean changed = rerouteResult.equals(this.clusterState) == false;
applyRerouteResult(rerouteResult);
- return rerouteResult.changed();
+ return changed;
}
- private void applyRerouteResult(RoutingAllocation.Result rerouteResult) {
+ private void applyRerouteResult(ClusterState newClusterState) {
ClusterState previousClusterState = this.clusterState;
- ClusterState newClusterState = ClusterState.builder(previousClusterState).routingResult(rerouteResult).build();
ClusterState.Builder builder = ClusterState.builder(newClusterState).incrementVersion();
if (previousClusterState.routingTable() != newClusterState.routingTable()) {
builder.routingTable(RoutingTable.builder(newClusterState.routingTable()).version(newClusterState.routingTable().version() + 1)
@@ -133,7 +129,6 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
builder.metaData(MetaData.builder(newClusterState.metaData()).version(newClusterState.metaData().version() + 1));
}
this.clusterState = builder.build();
- this.testRoutingTable = rerouteResult.routingTable();
final ClusterStateHealth clusterHealth = new ClusterStateHealth(clusterState);
logger.info("applied reroute. active shards: p [{}], t [{}], init shards: [{}], relocating: [{}]",
clusterHealth.getActivePrimaryShards(), clusterHealth.getActiveShards(),
@@ -141,8 +136,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
}
private void failSomePrimaries(String index) {
- this.clusterState = ClusterState.builder(clusterState).routingTable(this.testRoutingTable).build();
- final IndexRoutingTable indexShardRoutingTable = testRoutingTable.index(index);
+ final IndexRoutingTable indexShardRoutingTable = clusterState.routingTable().index(index);
Set<Integer> shardIdsToFail = new HashSet<>();
for (int i = 1 + randomInt(numberOfShards - 1); i > 0; i--) {
shardIdsToFail.add(randomInt(numberOfShards - 1));
@@ -153,9 +147,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
failedShards.add(new FailedRerouteAllocation.FailedShard(indexShardRoutingTable.shard(shard).primaryShard(), "test", null));
incrementPrimaryTerm(index, shard); // the primary failure should increment the primary term;
}
- RoutingAllocation.Result rerouteResult = allocationService.applyFailedShards(this.clusterState, failedShards,
- Collections.emptyList());
- applyRerouteResult(rerouteResult);
+ applyRerouteResult(allocationService.applyFailedShards(this.clusterState, failedShards,Collections.emptyList()));
}
private void addNodes() {
@@ -166,8 +158,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
nodesBuilder.add(newNode("extra_" + i));
}
this.clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build();
- RoutingAllocation.Result rerouteResult = allocationService.reroute(this.clusterState, "nodes added");
- applyRerouteResult(rerouteResult);
+ applyRerouteResult(allocationService.reroute(this.clusterState, "nodes added"));
}
@@ -191,7 +182,7 @@ public class PrimaryTermsTests extends ESAllocationTestCase {
private void assertPrimaryTerm(String index) {
final long[] terms = primaryTermsPerIndex.get(index);
final IndexMetaData indexMetaData = clusterState.metaData().index(index);
- for (IndexShardRoutingTable shardRoutingTable : this.testRoutingTable.index(index)) {
+ for (IndexShardRoutingTable shardRoutingTable : this.clusterState.routingTable().index(index)) {
final int shard = shardRoutingTable.shardId().id();
assertThat("primary term mismatch between indexMetaData of [" + index + "] and shard [" + shard + "]'s routing",
indexMetaData.primaryTerm(shard), equalTo(terms[shard]));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java
index 2ac427374e..f0514794a5 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/RoutingTableTests.java
@@ -21,15 +21,14 @@ package org.elasticsearch.cluster.routing;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.node.DiscoveryNodes.Builder;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexNotFoundException;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.junit.Before;
import java.util.Set;
@@ -37,7 +36,9 @@ import java.util.stream.Collectors;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
public class RoutingTableTests extends ESAllocationTestCase {
@@ -45,7 +46,6 @@ public class RoutingTableTests extends ESAllocationTestCase {
private static final String TEST_INDEX_1 = "test1";
private static final String TEST_INDEX_2 = "test2";
private RoutingTable emptyRoutingTable;
- private RoutingTable testRoutingTable;
private int numberOfShards;
private int numberOfReplicas;
private int shardsPerIndex;
@@ -72,7 +72,7 @@ public class RoutingTableTests extends ESAllocationTestCase {
.put(createIndexMetaData(TEST_INDEX_2))
.build();
- this.testRoutingTable = new RoutingTable.Builder()
+ RoutingTable testRoutingTable = new RoutingTable.Builder()
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_1).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_1)).build())
.add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX_2).getIndex()).initializeAsNew(metaData.index(TEST_INDEX_2)).build())
.build();
@@ -89,18 +89,14 @@ public class RoutingTableTests extends ESAllocationTestCase {
discoBuilder = discoBuilder.add(newNode("node" + i));
}
this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
- RoutingAllocation.Result rerouteResult = ALLOCATION_SERVICE.reroute(clusterState, "reroute");
- this.testRoutingTable = rerouteResult.routingTable();
- assertThat(rerouteResult.changed(), is(true));
- this.clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ ClusterState rerouteResult = ALLOCATION_SERVICE.reroute(clusterState, "reroute");
+ assertThat(rerouteResult, not(equalTo(this.clusterState)));
+ this.clusterState = rerouteResult;
}
private void startInitializingShards(String index) {
- this.clusterState = ClusterState.builder(clusterState).routingTable(this.testRoutingTable).build();
logger.info("start primary shards for index {}", index);
- RoutingAllocation.Result rerouteResult = ALLOCATION_SERVICE.applyStartedShards(this.clusterState, this.clusterState.getRoutingNodes().shardsWithState(index, INITIALIZING));
- this.clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
- this.testRoutingTable = rerouteResult.routingTable();
+ this.clusterState = ALLOCATION_SERVICE.applyStartedShards(this.clusterState, this.clusterState.getRoutingNodes().shardsWithState(index, INITIALIZING));
}
private IndexMetaData.Builder createIndexMetaData(String indexName) {
@@ -112,11 +108,11 @@ public class RoutingTableTests extends ESAllocationTestCase {
public void testAllShards() {
assertThat(this.emptyRoutingTable.allShards().size(), is(0));
- assertThat(this.testRoutingTable.allShards().size(), is(this.totalNumberOfShards));
+ assertThat(this.clusterState.routingTable().allShards().size(), is(this.totalNumberOfShards));
- assertThat(this.testRoutingTable.allShards(TEST_INDEX_1).size(), is(this.shardsPerIndex));
+ assertThat(this.clusterState.routingTable().allShards(TEST_INDEX_1).size(), is(this.shardsPerIndex));
try {
- assertThat(this.testRoutingTable.allShards("not_existing").size(), is(0));
+ assertThat(this.clusterState.routingTable().allShards("not_existing").size(), is(0));
fail("Exception expected when calling allShards() with non existing index name");
} catch (IndexNotFoundException e) {
// expected
@@ -124,69 +120,69 @@ public class RoutingTableTests extends ESAllocationTestCase {
}
public void testHasIndex() {
- assertThat(this.testRoutingTable.hasIndex(TEST_INDEX_1), is(true));
- assertThat(this.testRoutingTable.hasIndex("foobar"), is(false));
+ assertThat(clusterState.routingTable().hasIndex(TEST_INDEX_1), is(true));
+ assertThat(clusterState.routingTable().hasIndex("foobar"), is(false));
}
public void testIndex() {
- assertThat(this.testRoutingTable.index(TEST_INDEX_1).getIndex().getName(), is(TEST_INDEX_1));
- assertThat(this.testRoutingTable.index("foobar"), is(nullValue()));
+ assertThat(clusterState.routingTable().index(TEST_INDEX_1).getIndex().getName(), is(TEST_INDEX_1));
+ assertThat(clusterState.routingTable().index("foobar"), is(nullValue()));
}
public void testIndicesRouting() {
- assertThat(this.testRoutingTable.indicesRouting().size(), is(2));
- assertThat(this.testRoutingTable.getIndicesRouting().size(), is(2));
- assertSame(this.testRoutingTable.getIndicesRouting(), this.testRoutingTable.indicesRouting());
+ assertThat(clusterState.routingTable().indicesRouting().size(), is(2));
+ assertThat(clusterState.routingTable().getIndicesRouting().size(), is(2));
+ assertSame(clusterState.routingTable().getIndicesRouting(), clusterState.routingTable().indicesRouting());
}
public void testShardsWithState() {
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards));
initPrimaries();
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - 2 * this.numberOfShards));
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.INITIALIZING).size(), is(2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - 2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.INITIALIZING).size(), is(2 * this.numberOfShards));
startInitializingShards(TEST_INDEX_1);
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.STARTED).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.STARTED).size(), is(this.numberOfShards));
int initializingExpected = this.numberOfShards + this.numberOfShards * this.numberOfReplicas;
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - this.numberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - this.numberOfShards));
startInitializingShards(TEST_INDEX_2);
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.STARTED).size(), is(2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.STARTED).size(), is(2 * this.numberOfShards));
initializingExpected = 2 * this.numberOfShards * this.numberOfReplicas;
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - 2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.INITIALIZING).size(), is(initializingExpected));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.UNASSIGNED).size(), is(this.totalNumberOfShards - initializingExpected - 2 * this.numberOfShards));
// now start all replicas too
startInitializingShards(TEST_INDEX_1);
startInitializingShards(TEST_INDEX_2);
- assertThat(this.testRoutingTable.shardsWithState(ShardRoutingState.STARTED).size(), is(this.totalNumberOfShards));
+ assertThat(clusterState.routingTable().shardsWithState(ShardRoutingState.STARTED).size(), is(this.totalNumberOfShards));
}
public void testActivePrimaryShardsGrouped() {
assertThat(this.emptyRoutingTable.activePrimaryShardsGrouped(new String[0], true).size(), is(0));
assertThat(this.emptyRoutingTable.activePrimaryShardsGrouped(new String[0], false).size(), is(0));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
initPrimaries();
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
startInitializingShards(TEST_INDEX_1);
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.numberOfShards));
startInitializingShards(TEST_INDEX_2);
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
- assertThat(this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(2 * this.numberOfShards));
try {
- this.testRoutingTable.activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
+ clusterState.routingTable().activePrimaryShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
fail("Calling with non-existing index name should raise IndexMissingException");
} catch (IndexNotFoundException e) {
// expected
@@ -197,43 +193,43 @@ public class RoutingTableTests extends ESAllocationTestCase {
assertThat(this.emptyRoutingTable.allActiveShardsGrouped(new String[0], true).size(), is(0));
assertThat(this.emptyRoutingTable.allActiveShardsGrouped(new String[0], false).size(), is(0));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
initPrimaries();
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
startInitializingShards(TEST_INDEX_1);
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
startInitializingShards(TEST_INDEX_2);
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
- assertThat(this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_2}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
try {
- this.testRoutingTable.allActiveShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
+ clusterState.routingTable().allActiveShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, true);
} catch (IndexNotFoundException e) {
fail("Calling with non-existing index should be ignored at the moment");
}
}
public void testAllAssignedShardsGrouped() {
- assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
- assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(0));
+ assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
initPrimaries();
- assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
- assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, false).size(), is(this.numberOfShards));
+ assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1}, true).size(), is(this.shardsPerIndex));
- assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
- assertThat(this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
+ assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, false).size(), is(2 * this.numberOfShards));
+ assertThat(clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, TEST_INDEX_2}, true).size(), is(this.totalNumberOfShards));
try {
- this.testRoutingTable.allAssignedShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, false);
+ clusterState.routingTable().allAssignedShardsGrouped(new String[]{TEST_INDEX_1, "not_exists"}, false);
} catch (IndexNotFoundException e) {
fail("Calling with non-existing index should be ignored at the moment");
}
@@ -242,19 +238,19 @@ public class RoutingTableTests extends ESAllocationTestCase {
public void testAllShardsForMultipleIndices() {
assertThat(this.emptyRoutingTable.allShards(new String[0]).size(), is(0));
- assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
initPrimaries();
- assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
startInitializingShards(TEST_INDEX_1);
- assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
+ assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1}).size(), is(this.shardsPerIndex));
startInitializingShards(TEST_INDEX_2);
- assertThat(this.testRoutingTable.allShards(new String[]{TEST_INDEX_1, TEST_INDEX_2}).size(), is(this.totalNumberOfShards));
+ assertThat(clusterState.routingTable().allShards(new String[]{TEST_INDEX_1, TEST_INDEX_2}).size(), is(this.totalNumberOfShards));
try {
- this.testRoutingTable.allShards(new String[]{TEST_INDEX_1, "not_exists"});
+ clusterState.routingTable().allShards(new String[]{TEST_INDEX_1, "not_exists"});
} catch (IndexNotFoundException e) {
fail("Calling with non-existing index should be ignored at the moment");
}
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java
index f5cfedc9c7..4b7e81df38 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/UnassignedInfoTests.java
@@ -178,9 +178,9 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
.metaData(metaData)
.routingTable(RoutingTable.builder().addAsNew(metaData.index(index)).build()).build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
IndexRoutingTable.Builder builder = IndexRoutingTable.builder(index);
for (IndexShardRoutingTable indexShardRoutingTable : clusterState.routingTable().index(index)) {
builder.addIndexShard(indexShardRoutingTable);
@@ -218,15 +218,15 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
.metaData(metaData)
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
// remove node2 and reroute
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
// verify that NODE_LEAVE is the reason for meta
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(true));
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1));
@@ -247,15 +247,15 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
.metaData(metaData)
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test")).build()).build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
// fail shard
ShardRouting shardToFail = clusterState.getRoutingNodes().shardsWithState(STARTED).get(0);
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyFailedShards(clusterState, Collections.singletonList(new FailedRerouteAllocation.FailedShard(shardToFail, "test fail", null)))).build();
+ clusterState = allocation.applyFailedShards(clusterState, Collections.singletonList(new FailedRerouteAllocation.FailedShard(shardToFail, "test fail", null)));
// verify the reason and details
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(true));
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1));
@@ -297,17 +297,17 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
.metaData(metaData)
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(0));
// starting primaries
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
// remove node2 and reroute
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
// make sure both replicas are marked as delayed (i.e. not reallocated)
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
assertThat(clusterState.prettyPrint(), UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(2));
}
@@ -325,24 +325,24 @@ public class UnassignedInfoTests extends ESAllocationTestCase {
.metaData(metaData)
.routingTable(RoutingTable.builder().addAsNew(metaData.index("test1")).addAsNew(metaData.index("test2")).build()).build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), equalTo(0));
// starting primaries
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().unassigned().size() > 0, equalTo(false));
// remove node2 and reroute
final long baseTime = System.nanoTime();
allocation.setNanoTimeOverride(baseTime);
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node2")).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
final long delta = randomBoolean() ? 0 : randomInt((int) expectMinDelaySettingsNanos - 1);
if (delta > 0) {
allocation.setNanoTimeOverride(baseTime + delta);
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "time moved")).build();
+ clusterState = allocation.reroute(clusterState, "time moved");
}
assertThat(UnassignedInfo.findNextDelayedAllocation(baseTime + delta, clusterState), equalTo(expectMinDelaySettingsNanos - delta));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java
index 3803f54ba7..ed7a944963 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AddIncrementallyTests.java
@@ -23,6 +23,7 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
@@ -43,6 +43,8 @@ import java.util.Collections;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
public class AddIncrementallyTests extends ESAllocationTestCase {
private final Logger logger = Loggers.getLogger(AddIncrementallyTests.class);
@@ -53,40 +55,40 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
AllocationService service = createAllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(9));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
int nodeOffset = 1;
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
+ assertNumIndexShardsPerNode(clusterState, equalTo(3));
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
+ assertNumIndexShardsPerNode(clusterState, equalTo(2));
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
assertAtLeastOneIndexShardPerNode(clusterState);
clusterState = removeNodes(clusterState, service, 1);
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
+ assertNumIndexShardsPerNode(clusterState, equalTo(2));
clusterState = addIndex(clusterState, service, 3, 2, 3);
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(2));
- assertNumIndexShardsPerNode(clusterState, "test3", Matchers.equalTo(2));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(2));
+ assertNumIndexShardsPerNode(clusterState, "test3", equalTo(2));
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
clusterState = addIndex(clusterState, service, 4, 2, 3);
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(4));
- assertNumIndexShardsPerNode(clusterState, "test4", Matchers.equalTo(2));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(4));
+ assertNumIndexShardsPerNode(clusterState, "test4", equalTo(2));
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
clusterState = removeNodes(clusterState, service, 1);
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(4));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(4));
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
assertNumIndexShardsPerNode(clusterState, Matchers.lessThanOrEqualTo(2));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
}
@@ -97,59 +99,57 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
AllocationService service = createAllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(9));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
int nodeOffset = 1;
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
+ assertNumIndexShardsPerNode(clusterState, equalTo(3));
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());
nodes.add(newNode("node2"));
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
- RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.reroute(clusterState, "reroute");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
-
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
+
+ newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(4));
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertTrue(routingResult.changed());
-
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(4));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
+
+ newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(6));
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertTrue(routingResult.changed());
-
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- assertFalse(routingResult.changed());
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(6));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
+
+ newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, equalTo(clusterState));
+ assertNumIndexShardsPerNode(clusterState, equalTo(2));
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
}
@@ -161,59 +161,57 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
AllocationService service = createAllocationService(settings.build());
ClusterState clusterState = initCluster(service, 1, 3, 3, 1);
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(9));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(9));
int nodeOffset = 1;
clusterState = addNodes(clusterState, service, 1, nodeOffset++);
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), Matchers.equalTo(9));
- assertThat(clusterState.getRoutingNodes().unassigned().size(), Matchers.equalTo(0));
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(3));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(9));
+ assertThat(clusterState.getRoutingNodes().unassigned().size(), equalTo(0));
+ assertNumIndexShardsPerNode(clusterState, equalTo(3));
logger.info("now, start one more node, check that rebalancing will happen because we set it to always");
DiscoveryNodes.Builder nodes = DiscoveryNodes.builder(clusterState.nodes());
nodes.add(newNode("node2"));
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
- RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.reroute(clusterState, "reroute");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
-
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
+
+ newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(4));
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(2));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertTrue(routingResult.changed());
-
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(4));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
+
+ newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), Matchers.equalTo(6));
- assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), Matchers.equalTo(0));
- assertTrue(routingResult.changed());
-
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- assertFalse(routingResult.changed());
- assertNumIndexShardsPerNode(clusterState, Matchers.equalTo(2));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(6));
+ assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node0").shardsWithState(INITIALIZING).size(), equalTo(0));
+ assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(0));
+
+ newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, equalTo(clusterState));
+ assertNumIndexShardsPerNode(clusterState, equalTo(2));
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
}
@@ -250,8 +248,7 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
- RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.reroute(clusterState, "reroute");
// move initializing to started
return applyStartedShardsUntilNoChange(clusterState, service);
@@ -282,18 +279,15 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
nodes.add(newNode("node" + i));
}
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(initialRoutingTable).build();
- RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.reroute(clusterState, "reroute");
logger.info("restart all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
logger.info("complete rebalancing");
@@ -313,18 +307,15 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
MetaData metaData = metaDataBuilder.build();
clusterState = ClusterState.builder(clusterState).metaData(metaData).routingTable(routingTableBuilder.build()).build();
- RoutingAllocation.Result routingResult = service.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.reroute(clusterState, "reroute");
logger.info("restart all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("complete rebalancing");
return applyStartedShardsUntilNoChange(clusterState, service);
@@ -344,22 +335,18 @@ public class AddIncrementallyTests extends ESAllocationTestCase {
}
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
- clusterState = ClusterState.builder(clusterState)
- .routingResult(service.deassociateDeadNodes(clusterState, true, "reroute")).build();
+ clusterState = service.deassociateDeadNodes(clusterState, true, "reroute");
logger.info("start all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- RoutingAllocation.Result routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("rebalancing");
- routingResult = service.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.reroute(clusterState, "reroute");
logger.info("complete rebalancing");
clusterState = applyStartedShardsUntilNoChange(clusterState, service);
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java
index 24faf9c45a..e4ab63f00d 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -51,7 +52,6 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.index.shard.ShardNotFoundException;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.Collections;
@@ -61,6 +61,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
/**
@@ -82,12 +83,10 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
logger.info("adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
logger.info("start primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("move the shard");
String existingNodeId = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
@@ -97,15 +96,15 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
} else {
toNodeId = "node1";
}
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ ClusterState newState = allocation.reroute(clusterState,
+ new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node(existingNodeId).iterator().next().state(), equalTo(ShardRoutingState.RELOCATING));
assertThat(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
logger.info("finish moving the shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node(existingNodeId).isEmpty(), equalTo(true));
assertThat(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
@@ -146,8 +145,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
.add(newNode("node3"))
.add(newNode("node4", singleton(DiscoveryNode.Role.MASTER)))
).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
logger.info("--> allocating to non-existent node, should fail");
@@ -199,16 +197,16 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
}
logger.info("--> allocating empty primary with acceptDataLoss flag set to true");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ ClusterState newState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
logger.info("--> start the primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
@@ -221,9 +219,10 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
}
logger.info("--> allocate the replica shard on on the second node");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
@@ -231,8 +230,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
logger.info("--> start the replica shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
@@ -267,14 +265,14 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
.add(newNode("node2"))
.add(newNode("node3"))
).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
logger.info("--> allocating empty primary shard with accept_data_loss flag set to true");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ ClusterState newState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
@@ -287,8 +285,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
}
logger.info("--> start the primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
@@ -301,27 +298,30 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
}
logger.info("--> allocate the replica shard on on the second node");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> cancel the relocation allocation");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
logger.info("--> allocate the replica shard on on the second node");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
@@ -335,41 +335,41 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
}
logger.info("--> start the replica shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
logger.info("--> cancel allocation of the replica shard");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
logger.info("--> allocate the replica shard on on the second node");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
- assertThat(rerouteResult.changed(), equalTo(true));
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the replica shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
logger.info("--> move the replica shard");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState,
+ new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false).getClusterState();
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
@@ -379,24 +379,25 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
if (randomBoolean()) {
logger.info("--> cancel the primary allocation (with allow_primary set to true)");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
- assertThat(rerouteResult.changed(), equalTo(true));
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).iterator().next().primary(), equalTo(true));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
} else {
logger.info("--> cancel the move of the replica shard");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node3", false)), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState,
+ new AllocationCommands(new CancelAllocationCommand("test", 0, "node3", false)), false, false).getClusterState();
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
logger.info("--> move the replica shard again");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState,
+ new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false).getClusterState();
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
@@ -405,8 +406,8 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> cancel the source replica shard");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState,
+ new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
@@ -415,17 +416,17 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).get(0).relocatingNodeId(), nullValue());
logger.info("--> start the former target replica shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
- assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
+ assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(STARTED).size(), equalTo(1));
logger.info("--> cancel the primary allocation (with allow_primary set to true)");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
- assertThat(rerouteResult.changed(), equalTo(true));
+ newState = allocation.reroute(clusterState,
+ new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(STARTED).iterator().next().primary(), equalTo(true));
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java
index 7e93fa040d..684985801c 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationPriorityTests.java
@@ -20,13 +20,13 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -68,29 +68,24 @@ public class AllocationPriorityTests extends ESAllocationTestCase {
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
- RoutingAllocation.Result routingResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertEquals(2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
- routingResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertEquals(2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
- routingResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertEquals(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).toString(),2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
assertEquals(highPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
- routingResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertEquals(2, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size());
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0).getIndexName());
assertEquals(lowPriorityName, clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(1).getIndexName());
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java
index f85cc97560..e7eacf94f9 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AwarenessAllocationTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -73,17 +73,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node1", singletonMap("rack_id", "1")))
.add(newNode("node2", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -91,16 +88,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node3"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -111,9 +106,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
}
@@ -140,17 +134,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node2", singletonMap("rack_id", "1")))
.add(newNode("node3", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -158,16 +149,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node4"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -178,9 +167,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node5", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
}
@@ -213,8 +201,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node1", singletonMap("rack_id", "1")))
.add(newNode("node2", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Initializing shards: {}", clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("Started shards: {}", clusterState.getRoutingNodes().shardsWithState(STARTED));
@@ -224,12 +211,10 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(5));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
@@ -237,8 +222,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(5));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(5));
@@ -246,12 +230,10 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node3"));
logger.info("--> complete initializing");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> run it again, since we still might have relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
@@ -262,13 +244,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), greaterThan(0));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
@@ -304,17 +284,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node1", singletonMap("rack_id", "1")))
.add(newNode("node2", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(10));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
@@ -322,8 +299,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(10));
@@ -333,11 +309,9 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
logger.info("--> complete initializing");
for (int i = 0; i < 2; i++) {
logger.info("--> complete initializing round: [{}]", i);
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- }
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
+ }
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(10));
@@ -351,16 +325,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), greaterThan(0));
logger.info("--> complete relocation");
for (int i = 0; i < 2; i++) {
logger.info("--> complete initializing round: [{}]", i);
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- }
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
+ }
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(5));
assertThat(clusterState.getRoutingNodes().node("node4").size(), equalTo(5));
@@ -395,17 +367,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node1", singletonMap("rack_id", "1")))
.add(newNode("node2", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -413,16 +382,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(3));
@@ -433,15 +400,13 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node4"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(3));
@@ -475,17 +440,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node3", singletonMap("rack_id", "1")))
.add(newNode("node4", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));
@@ -493,16 +455,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node5", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(3));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node5"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));
@@ -513,15 +473,13 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node6", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(3));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).get(0).relocatingNodeId(), equalTo("node6"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(4));
@@ -554,13 +512,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node1", singletonMap("rack_id", "1")))
.add(newNode("node2", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> replica will not start because we have only one rack value");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
@@ -570,16 +526,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -590,9 +544,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
}
@@ -622,13 +575,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node2", singletonMap("rack_id", "1")))
.add(newNode("node3", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> replica will not start because we have only one rack value");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
@@ -638,16 +589,14 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node4"));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
@@ -658,9 +607,8 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node5", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
}
@@ -696,13 +644,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("node1", singletonMap("rack_id", "1")))
.add(newNode("node2", singletonMap("rack_id", "1")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(10));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
@@ -710,20 +656,17 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", singletonMap("rack_id", "2")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(10));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
logger.info("--> complete initializing");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> run it again, since we still might have relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
@@ -734,13 +677,11 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4", singletonMap("rack_id", "3")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), greaterThan(0));
logger.info("--> complete relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(20));
@@ -775,19 +716,16 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("A-0", singletonMap("zone", "a")))
.add(newNode("B-0", singletonMap("zone", "b")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(5));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(5));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(5));
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> all replicas are allocated and started since we have on node in each zone");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(10));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -796,15 +734,13 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("A-1", singletonMap("zone", "a")))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(8));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).get(0).currentNodeId(), equalTo("A-1"));
logger.info("--> starting initializing shards on the new node");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(10));
assertThat(clusterState.getRoutingNodes().node("A-1").size(), equalTo(2));
@@ -840,14 +776,12 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
.add(newNode("A-4", singletonMap("zone", "a")))
.add(newNode("B-0", singletonMap("zone", "b")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shard (primary)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(3));
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(1)); // Unassigned shard is expected.
@@ -864,8 +798,7 @@ public class AwarenessAllocationTests extends ESAllocationTestCase {
}
commands.add(new MoveAllocationCommand("test", 0, primaryNode, "A-4"));
- routingResult = strategy.reroute(clusterState, commands, false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, commands, false, false).getClusterState();
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(1));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java
index b426220614..b2dd5ae0d2 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceConfigurationTests.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.ArrayUtil;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.EmptyClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -40,7 +41,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import org.hamcrest.Matchers;
@@ -132,18 +132,15 @@ public class BalanceConfigurationTests extends ESAllocationTestCase {
nodes.add(newNode("node" + i));
}
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).nodes(nodes).metaData(metaData).routingTable(initialRoutingTable).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("restart all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("complete rebalancing");
return applyStartedShardsUntilNoChange(clusterState, strategy);
@@ -174,24 +171,19 @@ public class BalanceConfigurationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(nodes.build()).build();
if (removed) {
- clusterState = ClusterState.builder(clusterState).routingResult(
- strategy.deassociateDeadNodes(clusterState, randomBoolean(), "removed nodes")
- ).build();
+ clusterState = strategy.deassociateDeadNodes(clusterState, randomBoolean(), "removed nodes");
}
logger.info("start all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- RoutingAllocation.Result routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("rebalancing");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("complete rebalancing");
return applyStartedShardsUntilNoChange(clusterState, strategy);
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTests.java
index 3890be6a4b..254ba81f93 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/BalanceUnbalancedClusterTests.java
@@ -65,14 +65,12 @@ public class BalanceUnbalancedClusterTests extends CatAllocationTestCase {
.build();
ClusterState clusterState = ClusterState.builder(state).metaData(metaData).routingTable(initialRoutingTable).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
while (true) {
if (clusterState.routingTable().shardsWithState(INITIALIZING).isEmpty()) {
break;
}
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
}
Map<String, Integer> counts = new HashMap<>();
for (IndexShardRoutingTable table : clusterState.routingTable().index(index)) {
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java
index 7adc7a4917..db707c5478 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/CatAllocationTestCase.java
@@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.io.BufferedReader;
import java.io.IOException;
@@ -149,10 +149,9 @@ public abstract class CatAllocationTestCase extends ESAllocationTestCase {
}
private ClusterState rebalance(ClusterState clusterState) {
- RoutingTable routingTable;AllocationService strategy = createAllocationService(Settings.builder()
+ AllocationService strategy = createAllocationService(Settings.builder()
.build());
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
int numRelocations = 0;
while (true) {
List<ShardRouting> initializing = clusterState.routingTable().shardsWithState(INITIALIZING);
@@ -161,8 +160,7 @@ public abstract class CatAllocationTestCase extends ESAllocationTestCase {
}
logger.debug("Initializing shards: {}", initializing);
numRelocations += initializing.size();
- routingResult = strategy.applyStartedShards(clusterState, initializing);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, initializing);
}
logger.debug("--> num relocations to get balance: {}", numRelocations);
return clusterState;
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java
index 7d7db4ef21..953ad1535e 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ClusterRebalanceRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -32,7 +33,6 @@ import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -43,6 +43,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
private final Logger logger = Loggers.getLogger(ClusterRebalanceRoutingTests.class);
@@ -65,8 +66,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
@@ -82,9 +82,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test1, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- routingNodes = clusterState.getRoutingNodes();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
@@ -100,8 +98,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test1 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -120,8 +117,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node3").size(), equalTo(1));
@@ -147,9 +143,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(INITIALIZING));
@@ -164,8 +158,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test1, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -182,8 +175,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test1 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -200,8 +192,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test2, replicas will start initializing");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -220,8 +211,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node3").size(), equalTo(1));
@@ -246,8 +236,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
@@ -263,8 +252,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test1, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -281,8 +269,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test1 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -301,8 +288,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
@@ -326,8 +312,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
@@ -343,8 +328,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test1, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -361,8 +345,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test1 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -379,8 +362,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test2, replicas will start initializing");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -397,8 +379,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test2 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -417,8 +398,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node3").size(), equalTo(1));
@@ -443,8 +423,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
@@ -460,8 +439,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test1, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -478,8 +456,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test1 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -498,8 +475,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
@@ -523,8 +499,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(2));
@@ -540,8 +515,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test1, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -558,8 +532,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the test1 replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -576,8 +549,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards for test2, replicas will start initializing");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test2", INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
@@ -596,8 +568,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node3").isEmpty(), equalTo(true));
@@ -638,8 +609,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
@@ -648,9 +618,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.debug("start all the primary shards for test");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(i).primaryShard().state(), equalTo(STARTED));
@@ -661,10 +629,8 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
.add(newNode("node2")))
.build();
logger.debug("reroute and check that nothing has changed");
- RoutingAllocation.Result reroute = strategy.reroute(clusterState, "reroute");
- assertFalse(reroute.changed());
- routingResult = reroute;
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState resultingState = strategy.reroute(clusterState, "reroute");
+ assertThat(resultingState, equalTo(clusterState));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
@@ -676,10 +642,9 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
}
logger.debug("now set allocateTest1 to true and reroute we should see the [test1] index initializing");
allocateTest1.set(true);
- reroute = strategy.reroute(clusterState, "reroute");
- assertTrue(reroute.changed());
- routingResult = reroute;
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ resultingState = strategy.reroute(clusterState, "reroute");
+ assertThat(resultingState, not(equalTo(clusterState)));
+ clusterState = resultingState;
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test1").shard(i).primaryShard().state(), equalTo(INITIALIZING));
@@ -688,8 +653,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.debug("now start initializing shards and expect exactly one rebalance from node1 to node 2 since index [test] is all on node1");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test1", INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).shards().size(), equalTo(1));
@@ -738,8 +702,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
@@ -748,9 +711,7 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
logger.debug("start all the primary shards for test");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState("test", INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(i).primaryShard().state(), equalTo(STARTED));
@@ -761,8 +722,8 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
.add(newNode("node2")))
.build();
logger.debug("reroute and check that nothing has changed");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ ClusterState resultState = strategy.reroute(clusterState, "reroute");
+ assertThat(resultState, equalTo(clusterState));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(1));
@@ -774,9 +735,9 @@ public class ClusterRebalanceRoutingTests extends ESAllocationTestCase {
}
logger.debug("now set hasFetches to true and reroute we should now see exactly one relocating shard");
hasFetches.set(false);
- routingResult = strategy.reroute(clusterState, "reroute");
- assertTrue(routingResult.changed());
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ resultState = strategy.reroute(clusterState, "reroute");
+ assertThat(resultState, not(equalTo(clusterState)));
+ clusterState = resultState;
int numStarted = 0;
int numRelocating = 0;
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java
index d7b56c6508..aa7be906a6 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ConcurrentRebalanceRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
@@ -70,8 +70,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start two nodes and fully start the shards");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
@@ -81,8 +80,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
@@ -94,8 +92,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")).add(newNode("node4")).add(newNode("node5")).add(newNode("node6")).add(newNode("node7")).add(newNode("node8")).add(newNode("node9")).add(newNode("node10")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
@@ -105,8 +102,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("start the replica shards, rebalancing should start, but, only 3 should be rebalancing");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
// we only allow one relocation at a time
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(7));
@@ -114,8 +110,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("finalize this session relocation, 3 more should relocate now");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
// we only allow one relocation at a time
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(7));
@@ -123,8 +118,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("finalize this session relocation, 2 more should relocate now");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
// we only allow one relocation at a time
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(8));
@@ -132,8 +126,7 @@ public class ConcurrentRebalanceRoutingTests extends ESAllocationTestCase {
logger.info("finalize this session relocation, no more relocation");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
// we only allow one relocation at a time
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(10));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java
index c4d8545e97..9076dde19f 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/DeadNodesAllocationTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -31,12 +32,12 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
/**
*/
@@ -64,15 +65,12 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
.add(newNode("node2"))
).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> verifying all is allocated");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
@@ -87,8 +85,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
.add(newNode(nodeIdRemaining))
).build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
assertThat(clusterState.getRoutingNodes().node(nodeIdRemaining).iterator().next().primary(), equalTo(true));
assertThat(clusterState.getRoutingNodes().node(nodeIdRemaining).iterator().next().state(), equalTo(STARTED));
@@ -115,15 +112,12 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
.add(newNode("node2"))
).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> verifying all is allocated");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
@@ -135,8 +129,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3"))
).build();
- rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").iterator().next().state(), equalTo(STARTED));
@@ -148,11 +141,11 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
String origReplicaNodeId = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
logger.info("--> moving primary shard to node3");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
+ AllocationService.CommandsResult commandsResult = allocation.reroute(clusterState, new AllocationCommands(
new MoveAllocationCommand("test", 0, clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
+ clusterState = commandsResult.getClusterState();
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
@@ -161,8 +154,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
.add(newNode(origPrimaryNodeId))
.add(newNode(origReplicaNodeId))
).build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(STARTED));
assertThat(clusterState.getRoutingNodes().node(origReplicaNodeId).iterator().next().state(), equalTo(STARTED));
@@ -189,15 +181,12 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
.add(newNode("node2"))
).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> verifying all is allocated");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
@@ -209,8 +198,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3"))
).build();
- rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").iterator().next().state(), equalTo(STARTED));
@@ -222,11 +210,11 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
String origReplicaNodeId = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
logger.info("--> moving primary shard to node3");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
+ AllocationService.CommandsResult commandsResult = allocation.reroute(clusterState, new AllocationCommands(
new MoveAllocationCommand("test",0 , clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
+ clusterState = commandsResult.getClusterState();
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
@@ -235,8 +223,7 @@ public class DeadNodesAllocationTests extends ESAllocationTestCase {
.add(newNode("node3"))
.add(newNode(origReplicaNodeId))
).build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
assertThat(clusterState.getRoutingNodes().node(origReplicaNodeId).iterator().next().state(), equalTo(STARTED));
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java
index 5707a229da..77e83fd665 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -30,11 +31,11 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
/**
*
@@ -59,29 +60,26 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the primary shards");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("Start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- routingNodes = clusterState.getRoutingNodes();
+ ClusterState resultingState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(resultingState, not(equalTo(clusterState)));
+ clusterState = resultingState;
- assertTrue(routingResult.changed());
+ routingNodes = clusterState.getRoutingNodes();
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(2));
assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(2));
logger.info("Start another node and perform rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("find the replica shard that gets relocated");
IndexShardRoutingTable indexShardRoutingTable = null;
@@ -95,8 +93,7 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest
if (indexShardRoutingTable != null) {
logger.info("kill the node [{}] of the primary shard for the relocating replica", indexShardRoutingTable.primaryShard().currentNodeId());
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build();
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
logger.info("make sure all the primary shards are active");
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().active(), equalTo(true));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java
index d76b666549..873c71f19b 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ExpectedShardSizeAllocationTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterInfo;
import org.elasticsearch.cluster.ClusterInfoService;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -35,10 +36,10 @@ import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
/**
*/
@@ -81,23 +82,20 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
logger.info("Adding one node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertEquals(1, clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.INITIALIZING));
assertEquals(byteSize, clusterState.getRoutingTable().shardsWithState(ShardRoutingState.INITIALIZING).get(0).getExpectedShardSize());
logger.info("Start the primary shard");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
assertEquals(1, clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.STARTED));
assertEquals(1, clusterState.getRoutingNodes().unassigned().size());
logger.info("Add another one node and reroute");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertEquals(1, clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.INITIALIZING));
assertEquals(byteSize, clusterState.getRoutingTable().shardsWithState(ShardRoutingState.INITIALIZING).get(0).getExpectedShardSize());
@@ -134,12 +132,10 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
logger.info("adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
logger.info("start primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("move the shard");
String existingNodeId = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
@@ -149,9 +145,10 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
} else {
toNodeId = "node1";
}
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ AllocationService.CommandsResult commandsResult =
+ allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, existingNodeId, toNodeId)), false, false);
+ assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
+ clusterState = commandsResult.getClusterState();
assertEquals(clusterState.getRoutingNodes().node(existingNodeId).iterator().next().state(), ShardRoutingState.RELOCATING);
assertEquals(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(),ShardRoutingState.INITIALIZING);
@@ -159,8 +156,7 @@ public class ExpectedShardSizeAllocationTests extends ESAllocationTestCase {
assertEquals(clusterState.getRoutingNodes().node(toNodeId).iterator().next().getExpectedShardSize(), byteSize);
logger.info("finish moving the shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node(existingNodeId).isEmpty(), equalTo(true));
assertThat(clusterState.getRoutingNodes().node(toNodeId).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java
index 6dd5c3a7b3..61a28897d5 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedNodeRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
@@ -58,19 +58,16 @@ public class FailedNodeRoutingTests extends ESAllocationTestCase {
logger.info("start 4 nodes");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("start all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
logger.info("start the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(1));
@@ -86,8 +83,7 @@ public class FailedNodeRoutingTests extends ESAllocationTestCase {
.remove(clusterState.routingTable().index("test2").shard(0).primaryShard().currentNodeId())
)
.build();
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
routingNodes = clusterState.getRoutingNodes();
for (RoutingNode routingNode : routingNodes) {
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java
index 852fbd1944..da6f103f51 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FailedShardsRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -33,7 +34,6 @@ import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationComman
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.ArrayList;
import java.util.Collections;
@@ -77,15 +77,12 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
.add(newNode("node2"))
).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
// starting primaries
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// starting replicas
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> verifying all is allocated");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
@@ -97,8 +94,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3"))
).build();
- rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node1").iterator().next().state(), equalTo(STARTED));
@@ -110,33 +106,31 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
String origReplicaNodeId = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
logger.info("--> moving primary shard to node3");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
+ AllocationService.CommandsResult commandsResult = allocation.reroute(clusterState, new AllocationCommands(
new MoveAllocationCommand("test", 0, clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
+ clusterState = commandsResult.getClusterState();
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
logger.info("--> fail primary shard recovering instance on node3 being initialized");
- rerouteResult = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node("node3").iterator().next());
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node("node3").iterator().next());
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(STARTED));
assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
logger.info("--> moving primary shard to node3");
- rerouteResult = allocation.reroute(clusterState, new AllocationCommands(
+ commandsResult = allocation.reroute(clusterState, new AllocationCommands(
new MoveAllocationCommand("test", 0, clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), "node3")),
false, false);
- assertThat(rerouteResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingTable(rerouteResult.routingTable()).build();
+ assertThat(commandsResult.getClusterState(), not(equalTo(clusterState)));
+ clusterState = commandsResult.getClusterState();
assertThat(clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next().state(), equalTo(RELOCATING));
assertThat(clusterState.getRoutingNodes().node("node3").iterator().next().state(), equalTo(INITIALIZING));
logger.info("--> fail primary shard recovering instance on node1 being relocated");
- rerouteResult = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next());
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyFailedShard(clusterState, clusterState.getRoutingNodes().node(origPrimaryNodeId).iterator().next());
// check promotion of replica to primary
assertThat(clusterState.getRoutingNodes().node(origReplicaNodeId).iterator().next().state(), equalTo(STARTED));
@@ -164,16 +158,16 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the shards (primaries)");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- assertTrue(routingResult.changed());
+ ClusterState newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -187,10 +181,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Start the shards (backups)");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -204,11 +198,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("fail the primary shard, will have no place to be rerouted to (single node), so stays unassigned");
ShardRouting shardToFail = clusterState.routingTable().index("test").shard(0).primaryShard();
- routingResult = strategy.applyFailedShard(clusterState, shardToFail);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- routingNodes = clusterState.getRoutingNodes();
+ newState = strategy.applyFailedShard(clusterState, shardToFail);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(), not(equalTo(shardToFail.currentNodeId())));
@@ -238,10 +231,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Adding single node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -254,10 +247,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("fail the first shard, will have no place to be rerouted to (single node), so stays unassigned");
ShardRouting firstShard = clusterState.getRoutingNodes().node("node1").iterator().next();
- routingResult = strategy.applyFailedShard(clusterState, firstShard);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyFailedShard(clusterState, firstShard);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -295,13 +288,9 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(nodeBuilder).build();
while (!clusterState.routingTable().shardsWithState(UNASSIGNED).isEmpty()) {
// start all initializing
- clusterState = ClusterState.builder(clusterState)
- .routingResult(strategy
- .applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING))
- )
- .build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
// and assign more unassigned
- clusterState = ClusterState.builder(clusterState).routingResult(strategy.reroute(clusterState, "reroute")).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
}
int shardsToFail = randomIntBetween(1, numberOfReplicas);
@@ -320,9 +309,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
}
}
- RoutingAllocation.Result routingResult = strategy.applyFailedShards(clusterState, failedShards);
-
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyFailedShards(clusterState, failedShards);
routingNodes = clusterState.getRoutingNodes();
for (FailedRerouteAllocation.FailedShard failedShard : failedShards) {
if (routingNodes.getByAllocationId(failedShard.routingEntry.shardId(), failedShard.routingEntry.allocationId().getId()) != null) {
@@ -357,11 +344,11 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(clusterState));
+ clusterState = newState;
final String nodeHoldingPrimary = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -374,9 +361,9 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("fail the first shard, will start INITIALIZING on the second node");
final ShardRouting firstShard = clusterState.getRoutingNodes().node(nodeHoldingPrimary).iterator().next();
- routingResult = strategy.applyFailedShard(clusterState, firstShard);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- assertTrue(routingResult.changed());
+ newState = strategy.applyFailedShard(clusterState, firstShard);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
final String nodeHoldingPrimary2 = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
assertThat(nodeHoldingPrimary2, not(equalTo(nodeHoldingPrimary)));
@@ -412,15 +399,14 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the shards (primaries)");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -434,10 +420,10 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Start the shards (backups)");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -451,11 +437,11 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Adding third node and reroute");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED, RELOCATING), equalTo(2));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), lessThan(3));
@@ -466,12 +452,11 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
logger.info("Fail the shards on node 3");
ShardRouting shardToFail = routingNodes.node("node3").iterator().next();
- routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyFailedShard(clusterState, shardToFail);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyFailedShard(clusterState, shardToFail);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED, RELOCATING), equalTo(2));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), lessThan(3));
@@ -502,15 +487,15 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(2));
// start primary shards
- clusterState = ClusterState.builder(clusterState).routingTable(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING)).routingTable()).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
// fail the primary shard, check replicas get removed as well...
ShardRouting primaryShardToFail = clusterState.routingTable().index("test").shard(0).primaryShard();
- RoutingAllocation.Result routingResult = allocation.applyFailedShard(clusterState, primaryShardToFail);
- assertThat(routingResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = allocation.applyFailedShard(clusterState, primaryShardToFail);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
// the primary gets allocated on another node, replicas are unassigned
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(2));
@@ -519,7 +504,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
// start the primary shard
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
}
@@ -540,24 +525,24 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
// add 4 nodes
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4"))).build();
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.reroute(clusterState, "reroute")).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(UNASSIGNED).size(), equalTo(2));
// start primary shards
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING))).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
// start another replica shard, while keep one initializing
- clusterState = ClusterState.builder(clusterState).routingResult(allocation.applyStartedShards(clusterState, Collections.singletonList(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0)))).build();
+ clusterState = allocation.applyStartedShards(clusterState, Collections.singletonList(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).get(0)));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
// fail the primary shard, check one replica gets elected to primary, others become INITIALIZING (from it)
ShardRouting primaryShardToFail = clusterState.routingTable().index("test").shard(0).primaryShard();
- RoutingAllocation.Result routingResult = allocation.applyFailedShard(clusterState, primaryShardToFail);
- assertThat(routingResult.changed(), equalTo(true));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = allocation.applyFailedShard(clusterState, primaryShardToFail);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java
index 0d067830d7..cfd4a25e0d 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterAllocationDeciderTests.java
@@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.EmptyClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.Decision;
import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import java.util.Collections;
@@ -71,12 +71,12 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
,allocation), Decision.NO);
// after failing the shard we are unassigned since the node is blacklisted and we can't initialize on the other node
- state = stateFromResult(state, service.reroute(state, "try allocate again"));
+ state = service.reroute(state, "try allocate again");
routingTable = state.routingTable();
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).currentNodeId(), "node2");
- state = stateFromResult(state, service.applyStartedShards(state, routingTable.index("idx").shard(0).shards()));
+ state = service.applyStartedShards(state, routingTable.index("idx").shard(0).shards());
routingTable = state.routingTable();
// ok now we are started and can be allocated anywhere!! lets see...
@@ -84,7 +84,7 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
assertEquals(routingTable.index("idx").shard(0).shards().get(0).currentNodeId(), "node2");
// we fail it again to check if we are initializing immediately on the other node
- state = stateFromResult(state, service.applyFailedShard(state, routingTable.index("idx").shard(0).shards().get(0)));
+ state = service.applyFailedShard(state, routingTable.index("idx").shard(0).shards().get(0));
routingTable = state.routingTable();
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).currentNodeId(), "node1");
@@ -99,10 +99,6 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
,allocation), Decision.YES);
}
- private ClusterState stateFromResult(ClusterState previousState, RoutingAllocation.Result result) {
- return ClusterState.builder(previousState).routingTable(result.routingTable()).metaData(result.metaData()).build();
- }
-
private ClusterState createInitialClusterState(AllocationService service, Settings settings) {
MetaData.Builder metaBuilder = MetaData.builder();
metaBuilder.put(IndexMetaData.builder("idx").settings(settings(Version.CURRENT).put(settings))
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java
index 6d0542b95c..430809e672 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/FilterRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -31,7 +32,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.hamcrest.Matchers;
import java.util.List;
@@ -71,17 +71,14 @@ public class FilterRoutingTests extends ESAllocationTestCase {
.add(newNode("node3", singletonMap("tag1", "value3")))
.add(newNode("node4", singletonMap("tag1", "value4")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> make sure shards are only allocated on tag1 with value1 and value2");
List<ShardRouting> startedShards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED);
@@ -119,17 +116,14 @@ public class FilterRoutingTests extends ESAllocationTestCase {
.add(newNode("node3", singletonMap("tag1", "value3")))
.add(newNode("node4", singletonMap("tag1", "value4")))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> make sure shards are only allocated on tag1 with value1 and value2");
List<ShardRouting> startedShards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED);
@@ -148,15 +142,13 @@ public class FilterRoutingTests extends ESAllocationTestCase {
.build()))
.build();
clusterState = ClusterState.builder(clusterState).metaData(updatedMetaData).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED).size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(2));
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(2));
logger.info("--> finish relocation");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
startedShards = clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.STARTED);
assertThat(startedShards.size(), equalTo(4));
@@ -185,14 +177,12 @@ public class FilterRoutingTests extends ESAllocationTestCase {
DiscoveryNode node1 = newNode("node1", singletonMap("tag1", "value1"));
DiscoveryNode node2 = newNode("node2", singletonMap("tag1", "value2"));
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(node1).add(node2)).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node(node1.getId()).numberOfShardsWithState(INITIALIZING), equalTo(2));
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(2));
logger.info("--> start the shards (only primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> make sure all shards are started");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
@@ -204,29 +194,24 @@ public class FilterRoutingTests extends ESAllocationTestCase {
.build());
logger.info("--> move shards from node1 to node2");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("--> check that concurrent recoveries only allows 1 shard to move");
assertThat(clusterState.getRoutingNodes().node(node1.getId()).numberOfShardsWithState(STARTED), equalTo(1));
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(1));
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(2));
logger.info("--> start the shards (only primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> move second shard from node1 to node2");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(INITIALIZING), equalTo(1));
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(3));
logger.info("--> start the shards (only primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node(node2.getId()).numberOfShardsWithState(STARTED), equalTo(4));
}
}
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/InSyncAllocationIdTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/InSyncAllocationIdTests.java
index f27b7e7889..6c1813de08 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/InSyncAllocationIdTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/InSyncAllocationIdTests.java
@@ -78,15 +78,13 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
logger.info("adding three nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(
newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(0));
assertThat(clusterState.metaData().index("test-old").inSyncAllocationIds(0), equalTo(new HashSet<>(Arrays.asList("x", "y"))));
logger.info("start primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
@@ -95,8 +93,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
assertThat(clusterState.metaData().index("test-old").inSyncAllocationIds(0), equalTo(new HashSet<>(Arrays.asList("x", "y"))));
logger.info("start replica shards");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(3));
@@ -104,8 +101,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.remove("node1"))
.build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
// in-sync allocation ids should not be updated
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(3));
@@ -114,8 +110,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.remove("node2").remove("node3"))
.build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
// in-sync allocation ids should not be updated
assertThat(clusterState.getRoutingTable().shardsWithState(UNASSIGNED).size(), equalTo(3));
@@ -125,24 +120,22 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node1")))
.build();
- rerouteResult = allocation.reroute(clusterState,
- new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState,
+ new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false)
+ .getClusterState();
// check that in-sync allocation ids are reset by forcing an empty primary
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(0));
logger.info("start primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
logger.info("fail primary shard");
ShardRouting startedPrimary = clusterState.getRoutingNodes().shardsWithState(STARTED).get(0);
- rerouteResult = allocation.applyFailedShard(clusterState, startedPrimary);
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyFailedShard(clusterState, startedPrimary);
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(0));
assertEquals(Collections.singleton(startedPrimary.allocationId().getId()),
@@ -165,8 +158,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.remove(replicaShard.currentNodeId()))
.build();
- RoutingAllocation.Result rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(2));
logger.info("fail replica (for which there is no shard routing in the CS anymore)");
@@ -236,8 +228,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.remove(replicaShard.currentNodeId()))
.build();
- RoutingAllocation.Result rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
// in-sync allocation ids should not be updated
assertEquals(inSyncSet, clusterState.metaData().index("test").inSyncAllocationIds(0));
@@ -248,20 +239,17 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode(replicaShard.currentNodeId())))
.build();
- rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
logger.info("start replica shards");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("remove the node");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.remove(replicaShard.currentNodeId()))
.build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
- }
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
+ }
// in-sync allocation set is bounded
Set<String> newInSyncSet = clusterState.metaData().index("test").inSyncAllocationIds(0);
@@ -285,14 +273,12 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
logger.info("adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(
newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(0));
logger.info("start primary shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingTable().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(1));
@@ -300,8 +286,7 @@ public class InSyncAllocationIdTests extends ESAllocationTestCase {
equalTo(clusterState.metaData().index("test").inSyncAllocationIds(0).iterator().next()));
logger.info("start replica shard");
- rerouteResult = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.metaData().index("test").inSyncAllocationIds(0).size(), equalTo(2));
return clusterState;
}
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java
index cd35669f04..986d08843a 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/IndexBalanceTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -30,12 +31,12 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
/**
@@ -84,10 +85,10 @@ public class IndexBalanceTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -100,16 +101,13 @@ public class IndexBalanceTests extends ESAllocationTestCase {
logger.info("Another round of rebalancing");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -123,16 +121,16 @@ public class IndexBalanceTests extends ESAllocationTestCase {
}
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the more shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -202,10 +200,9 @@ public class IndexBalanceTests extends ESAllocationTestCase {
logger.info("Adding one node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -219,17 +216,15 @@ public class IndexBalanceTests extends ESAllocationTestCase {
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
- assertFalse(routingResult.changed());
logger.info("Start the primary shard");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -243,17 +238,17 @@ public class IndexBalanceTests extends ESAllocationTestCase {
}
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the backup shard");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
- assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
+ assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
@@ -273,30 +268,29 @@ public class IndexBalanceTests extends ESAllocationTestCase {
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the backup shard");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
- assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
+ assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
- assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
+ assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(4));
assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(4));
@@ -340,10 +334,9 @@ public class IndexBalanceTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -356,16 +349,14 @@ public class IndexBalanceTests extends ESAllocationTestCase {
logger.info("Another round of rebalancing");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
- assertFalse(routingResult.changed());
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -379,15 +370,15 @@ public class IndexBalanceTests extends ESAllocationTestCase {
}
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the more shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -419,10 +410,9 @@ public class IndexBalanceTests extends ESAllocationTestCase {
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
@@ -435,16 +425,14 @@ public class IndexBalanceTests extends ESAllocationTestCase {
logger.info("Another round of rebalancing");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
- assertFalse(routingResult.changed());
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertTrue(routingResult.changed());
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
@@ -458,15 +446,15 @@ public class IndexBalanceTests extends ESAllocationTestCase {
}
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the more shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
for (int i = 0; i < clusterState.routingTable().index("test1").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test1").shard(i).size(), equalTo(2));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java
index d84afc7f0b..fe131e924c 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/MaxRetryAllocationDeciderTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.EmptyClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
import org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import java.util.Collections;
@@ -43,6 +43,8 @@ import java.util.List;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
@@ -89,10 +91,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i,
new UnsupportedOperationException()));
- RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+ ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), INITIALIZING);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), i+1);
@@ -102,18 +104,21 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom",
new UnsupportedOperationException()));
- RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+ ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), retries);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), UNASSIGNED);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getMessage(), "boom");
- result = strategy.reroute(clusterState, new AllocationCommands(), false, true); // manual reroute should retry once
- assertTrue(result.changed());
- routingTable = result.routingTable();
+ // manual reroute should retry once
+ newState = strategy.reroute(clusterState, new AllocationCommands(), false, true).getClusterState();
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
+
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
assertEquals(routingTable.index("idx").shards().size(), 1);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), retries);
@@ -124,10 +129,11 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom",
new UnsupportedOperationException()));
- result = strategy.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+
+ newState = strategy.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).unassignedInfo().getNumFailedAllocations(), retries+1);
assertEquals(routingTable.index("idx").shard(0).shards().get(0).state(), UNASSIGNED);
@@ -144,10 +150,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom" + i,
new UnsupportedOperationException()));
- RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+ ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
assertEquals(unassignedPrimary.state(), INITIALIZING);
@@ -162,10 +168,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "boom",
new UnsupportedOperationException()));
- RoutingAllocation.Result result = strategy.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+ ClusterState newState = strategy.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), retries);
@@ -183,10 +189,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
Settings.builder().put(clusterState.metaData().index("idx").getSettings()).put("index.allocation.max_retries",
retries+1).build()
).build(), true).build()).build();
- RoutingAllocation.Result result = strategy.reroute(clusterState, "settings changed", false);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+ ClusterState newState = strategy.reroute(clusterState, "settings changed", false);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
// good we are initializing and we are maintaining failure information
assertEquals(routingTable.index("idx").shards().size(), 1);
ShardRouting unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
@@ -211,10 +217,10 @@ public class MaxRetryAllocationDeciderTests extends ESAllocationTestCase {
List<FailedRerouteAllocation.FailedShard> failedShards = Collections.singletonList(
new FailedRerouteAllocation.FailedShard(routingTable.index("idx").shard(0).shards().get(0), "ZOOOMG",
new UnsupportedOperationException()));
- result = strategy.applyFailedShards(clusterState, failedShards);
- assertTrue(result.changed());
- routingTable = result.routingTable();
- clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
+ newState = strategy.applyFailedShards(clusterState, failedShards);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+ routingTable = newState.routingTable();
assertEquals(routingTable.index("idx").shards().size(), 1);
unassignedPrimary = routingTable.index("idx").shard(0).shards().get(0);
assertEquals(unassignedPrimary.unassignedInfo().getNumFailedAllocations(), 1);
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java
index eab7d469da..ab7e31ba43 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/NodeVersionAllocationDeciderTests.java
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.EmptyClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -39,7 +40,6 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands;
-import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.NodeVersionAllocationDecider;
@@ -52,7 +52,6 @@ import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.snapshots.Snapshot;
import org.elasticsearch.snapshots.SnapshotId;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
@@ -68,7 +67,6 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@@ -110,8 +108,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
logger.info("start two nodes and fully start the shards");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
@@ -122,9 +119,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
logger.info("start all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- routingNodes = clusterState.getRoutingNodes();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
@@ -134,9 +129,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
}
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- routingNodes = clusterState.getRoutingNodes();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
@@ -148,9 +141,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3", VersionUtils.getPreviousVersion())))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- routingNodes = clusterState.getRoutingNodes();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
@@ -163,8 +154,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
@@ -174,8 +164,7 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
}
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(3));
@@ -338,11 +327,10 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
AllocationService strategy = new MockAllocationService(Settings.EMPTY,
allocationDeciders,
NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
- RoutingAllocation.Result result = strategy.reroute(state, new AllocationCommands(), true, false);
+ state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
// the two indices must stay as is, the replicas cannot move to oldNode2 because versions don't match
- state = ClusterState.builder(state).routingResult(result).build();
- assertThat(result.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
- assertThat(result.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
+ assertThat(state.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
+ assertThat(state.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
}
public void testRestoreDoesNotAllocateSnapshotOnOlderNodes() {
@@ -371,35 +359,31 @@ public class NodeVersionAllocationDeciderTests extends ESAllocationTestCase {
AllocationService strategy = new MockAllocationService(Settings.EMPTY,
allocationDeciders,
NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
- RoutingAllocation.Result result = strategy.reroute(state, new AllocationCommands(), true, false);
+ state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
// Make sure that primary shards are only allocated on the new node
for (int i = 0; i < numberOfShards; i++) {
- assertEquals("newNode", result.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
+ assertEquals("newNode", state.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
}
}
private ClusterState stabilize(ClusterState clusterState, AllocationService service) {
logger.trace("RoutingNodes: {}", clusterState.getRoutingNodes().prettyPrint());
- RoutingAllocation.Result routingResult = service.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = service.deassociateDeadNodes(clusterState, true, "reroute");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
assertRecoveryNodeVersions(routingNodes);
logger.info("complete rebalancing");
- for (int i = 0; i < 1000; i++) { // at most 200 iters - this should be enough for all tests
+ boolean changed;
+ do {
logger.trace("RoutingNodes: {}", clusterState.getRoutingNodes().prettyPrint());
- routingResult = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = service.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ changed = newState.equals(clusterState) == false;
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- if (routingResult.changed() == false) {
- break;
- }
assertRecoveryNodeVersions(routingNodes);
- }
- logger.info("stabilized success [{}]", routingResult.changed() == false);
- assertFalse(routingResult.changed());
+ } while (changed);
return clusterState;
}
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java
index 838cd5777e..10f1cf6935 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferLocalPrimariesToRelocatingPrimariesTests.java
@@ -20,13 +20,13 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -69,12 +69,11 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation
.add(newNode("node1", singletonMap("tag1", "value1")))
.add(newNode("node2", singletonMap("tag1", "value2")))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
+
while (!clusterState.getRoutingNodes().shardsWithState(INITIALIZING).isEmpty()) {
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
}
logger.info("remove one of the nodes and apply filter to move everything from another node");
@@ -92,8 +91,7 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation
.build()))
.build();
clusterState = ClusterState.builder(clusterState).metaData(metaData).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node1")).build();
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
logger.info("[{}] primaries should be still started but [{}] other primaries should be unassigned", numberOfShards, numberOfShards);
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(numberOfShards));
@@ -103,8 +101,7 @@ public class PreferLocalPrimariesToRelocatingPrimariesTests extends ESAllocation
logger.info("start node back up");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node1", singletonMap("tag1", "value1")))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
while (clusterState.getRoutingNodes().shardsWithState(STARTED).size() < totalNumberOfShards) {
int localInitializations = 0;
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java
index 7badada5d5..1c209157b1 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PreferPrimaryAllocationTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.hamcrest.Matchers.equalTo;
@@ -63,12 +63,10 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase {
logger.info("adding two nodes and performing rerouting till all are allocated");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
while (!clusterState.getRoutingNodes().shardsWithState(INITIALIZING).isEmpty()) {
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
}
logger.info("increasing the number of replicas to 1, and perform a reroute (to get the replicas allocation going)");
@@ -76,8 +74,7 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase {
metaData = MetaData.builder(clusterState.metaData()).updateNumberOfReplicas(1).build();
clusterState = ClusterState.builder(clusterState).routingTable(updatedRoutingTable).metaData(metaData).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("2 replicas should be initializing now for the existing indices (we throttle to 1)");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
@@ -94,8 +91,7 @@ public class PreferPrimaryAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).metaData(metaData).routingTable(updatedRoutingTable).build();
logger.info("reroute, verify that primaries for the new index primary shards are allocated");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().index("new_index").shardsWithState(INITIALIZING).size(), equalTo(2));
}
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java
index ccdc4deb02..ca9d61997b 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
@@ -59,28 +59,23 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase {
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result result = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- result = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the primary shard (on node1)");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- result = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
logger.info("Start the backup shard (on node2)");
routingNodes = clusterState.getRoutingNodes();
- result = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
logger.info("Adding third node and reroute and kill first node");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3")).remove("node1")).build();
RoutingTable prevRoutingTable = clusterState.routingTable();
- result = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(result).build();
+ clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
routingNodes = clusterState.getRoutingNodes();
routingTable = clusterState.routingTable();
@@ -112,13 +107,11 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase {
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.reroute(clusterState, "reroute");
logger.info("Start the primary shards");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- rerouteResult = allocation.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = allocation.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.shardsWithState(STARTED).size(), equalTo(2));
@@ -130,11 +123,8 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase {
logger.info("--> fail node with primary");
String nodeIdToFail = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
String nodeIdRemaining = nodeIdToFail.equals("node1") ? "node2" : "node1";
- clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
- .add(newNode(nodeIdRemaining))
- ).build();
- rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode(nodeIdRemaining))).build();
+ clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.shardsWithState(STARTED).size(), equalTo(1));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java
index c1d4a168e8..f2673805fa 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryNotRelocatedWhileBeingRecoveredTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
@@ -62,28 +62,24 @@ public class PrimaryNotRelocatedWhileBeingRecoveredTests extends ESAllocationTes
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the primary shard (on node1)");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
logger.info("start another node, replica will start recovering form primary");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));
logger.info("start another node, make sure the primary is not relocated");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java
index ea618bb8b6..53d54c1835 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RandomAllocationDeciderTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.EmptyClusterInfoService;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -37,7 +38,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.Decision;
import org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationDecider;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import org.hamcrest.Matchers;
@@ -83,7 +83,7 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
int nodeIdCounter = 0;
int atMostNodes = scaledRandomIntBetween(Math.max(1, maxNumReplicas), 15);
final boolean frequentNodes = randomBoolean();
- RoutingAllocation.Result routingResult;
+ AllocationService.CommandsResult routingResult;
for (int i = 0; i < numIters; i++) {
logger.info("Start iteration [{}]", i);
ClusterState.Builder stateBuilder = ClusterState.builder(clusterState);
@@ -109,14 +109,12 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
stateBuilder.nodes(newNodesBuilder.build());
clusterState = stateBuilder.build();
if (nodesRemoved) {
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
+ clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
} else {
- routingResult = strategy.reroute(clusterState, "reroute");
+ clusterState = strategy.reroute(clusterState, "reroute");
}
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
if (clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size() > 0) {
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
}
}
logger.info("Fill up nodes such that every shard can be allocated");
@@ -137,11 +135,9 @@ public class RandomAllocationDeciderTests extends ESAllocationTestCase {
int iterations = 0;
do {
iterations++;
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
if (clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size() > 0) {
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
}
} while (clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size() != 0 ||
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java
index a6929b651e..ff2020d684 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RebalanceAfterActiveTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterInfo;
import org.elasticsearch.cluster.ClusterInfoService;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
@@ -100,8 +100,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
logger.info("start two nodes and fully start the shards");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).shards().size(), equalTo(2));
@@ -111,8 +110,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
logger.info("start all the primary shards, replicas will start initializing");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
@@ -126,8 +124,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3")).add(newNode("node4")).add(newNode("node5")).add(newNode("node6")).add(newNode("node7")).add(newNode("node8")).add(newNode("node9")).add(newNode("node10")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
@@ -140,8 +137,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
logger.info("start the replica shards, rebalancing should start");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
// we only allow one relocation at a time
@@ -160,8 +156,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
logger.info("complete relocation, other half of relocation should happen");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
// we now only relocate 3, since 2 remain where they are!
@@ -178,8 +173,7 @@ public class RebalanceAfterActiveTests extends ESAllocationTestCase {
logger.info("complete relocation, that's it!");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(10));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java
index c5998b0b73..6c837ed2b2 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/RoutingNodesIntegrityTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -32,11 +33,11 @@ import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllo
import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
/**
*
@@ -71,8 +72,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
assertThat(routingNodes.hasInactivePrimaries(), equalTo(false));
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(true));
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -82,21 +82,18 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("Another round of rebalancing");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the more shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -104,8 +101,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
assertThat(routingNodes.hasInactivePrimaries(), equalTo(false));
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(false));
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
}
@@ -128,57 +124,51 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("Adding one node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the primary shard");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the backup shard");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the backup shard");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(3));
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(4));
@@ -220,8 +210,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
assertThat(routingNodes.hasInactivePrimaries(), equalTo(false));
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(true));
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -231,18 +220,15 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("Another round of rebalancing");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertFalse(routingResult.changed());
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
routingNodes = clusterState.getRoutingNodes();
assertThat(routingNodes.node("node1").numberOfShardsWithState(INITIALIZING), equalTo(1));
assertThat(routingNodes.node("node2").numberOfShardsWithState(INITIALIZING), equalTo(1));
assertThat(routingNodes.node("node3").numberOfShardsWithState(INITIALIZING), equalTo(1));
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -254,13 +240,12 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
assertThat(routingNodes.node("node3").numberOfShardsWithState(STARTED), equalTo(1));
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the more shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -297,13 +282,12 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
assertThat(clusterState.routingTable().index("test1").shards().size(), equalTo(3));
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Reroute, assign");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -311,12 +295,10 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
assertThat(routingNodes.hasInactivePrimaries(), equalTo(true));
assertThat(routingNodes.hasUnassignedPrimaries(), equalTo(false));
- assertFalse(routingResult.changed());
logger.info("Reroute, start the primaries");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -326,8 +308,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("Reroute, start the replicas");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -347,8 +328,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("kill one node");
IndexShardRoutingTable indexShardRoutingTable = clusterState.routingTable().index("test").shard(0);
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build();
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -359,8 +339,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("Start Recovering shards round 1");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
@@ -370,8 +349,7 @@ public class RoutingNodesIntegrityTests extends ESAllocationTestCase {
logger.info("Start Recovering shards round 2");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
routingNodes = clusterState.getRoutingNodes();
assertThat(assertShardStats(routingNodes), equalTo(true));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java
index 69c2efe9b0..66fe40793d 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -34,7 +35,6 @@ import org.elasticsearch.cluster.routing.allocation.decider.SameShardAllocationD
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.LocalTransportAddress;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static java.util.Collections.emptyMap;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
@@ -67,14 +67,12 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
MASTER_DATA_ROLES, Version.CURRENT))
.add(new DiscoveryNode("node2", "node2", "node2", "test1", "test1", LocalTransportAddress.buildUnique(), emptyMap(),
MASTER_DATA_ROLES, Version.CURRENT))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.INITIALIZING), equalTo(2));
logger.info("--> start all primary shards, no replica will be started since its on the same host");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.STARTED), equalTo(2));
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.INITIALIZING), equalTo(0));
@@ -83,8 +81,7 @@ public class SameShardRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(new DiscoveryNode("node3", "node3", "node3", "test2", "test2", LocalTransportAddress.buildUnique(), emptyMap(),
MASTER_DATA_ROLES, Version.CURRENT))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.STARTED), equalTo(2));
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), ShardRoutingState.INITIALIZING), equalTo(2));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java
index 930c099f95..85948f3c52 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardsLimitAllocationTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -32,7 +33,6 @@ import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.allocation.decider.ShardsLimitAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
@@ -64,16 +64,14 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(2));
assertThat(clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(2));
logger.info("Start the primary shards");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.STARTED), equalTo(2));
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(0));
@@ -83,8 +81,7 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
logger.info("Do another reroute, make sure its still not allocated");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
}
public void testClusterLevelShardsLimitAllocate() {
@@ -108,16 +105,14 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(1));
logger.info("Start the primary shards");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.STARTED), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.STARTED), equalTo(1));
@@ -130,15 +125,13 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
.build());
logger.info("Do another reroute, make sure shards are now allocated");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(1));
assertThat(clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.INITIALIZING), equalTo(1));
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(ShardRoutingState.STARTED), equalTo(2));
assertThat(clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(ShardRoutingState.STARTED), equalTo(2));
@@ -171,13 +164,11 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();
logger.info("Adding one node and reroute");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start the primary shards");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), STARTED), equalTo(5));
@@ -196,12 +187,10 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
logger.info("Add another one node and reroute");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
assertThat(numberOfShardsOfType(clusterState.getRoutingNodes(), STARTED), equalTo(10));
@@ -225,8 +214,7 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).metaData(metaData).build();
logger.info("reroute after setting");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(STARTED), equalTo(3));
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(RELOCATING), equalTo(2));
@@ -235,8 +223,7 @@ public class ShardsLimitAllocationTests extends ESAllocationTestCase {
// the first move will destroy the balance and the balancer will move 2 shards from node2 to node one right after
// moving the nodes to node2 since we consider INITIALIZING nodes during rebalance
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
// now we are done compared to EvenShardCountAllocator since the Balancer is not soely based on the average
assertThat(clusterState.getRoutingNodes().node("node1").numberOfShardsWithState(STARTED), equalTo(5));
assertThat(clusterState.getRoutingNodes().node("node2").numberOfShardsWithState(STARTED), equalTo(5));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java
index c30ceef08b..33088bcce9 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardNoReplicasRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
@@ -33,7 +34,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.ArrayList;
import java.util.HashSet;
@@ -79,8 +79,7 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Adding one node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
@@ -90,16 +89,16 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Rerouting again, nothing should change");
clusterState = ClusterState.builder(clusterState).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- assertThat(routingResult.changed(), equalTo(false));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
+ clusterState = newState;
logger.info("Marking the shard as started");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(1));
@@ -108,10 +107,10 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Starting another node and making sure nothing changed");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(false));
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(1));
@@ -121,10 +120,10 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Killing node1 where the shard is, checking the shard is relocated");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node1")).build();
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(1));
@@ -133,16 +132,15 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Start another node, make sure that things remain the same (shard is in node2 and initializing)");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- assertThat(routingResult.changed(), equalTo(false));
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the shard on node 2");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(1));
@@ -172,10 +170,10 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Adding one node and rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(1));
@@ -185,10 +183,10 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
logger.info("Marking the shard as failed");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyFailedShard(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING).get(0));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyFailedShard(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING).get(0));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(1));
@@ -234,10 +232,10 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
nodesBuilder.add(newNode("node" + i));
}
clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
for (int i = 0; i < numberOfIndices; i++) {
assertThat(clusterState.routingTable().index("test" + i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test" + i).shard(0).size(), equalTo(1));
@@ -271,16 +269,14 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
nodesBuilder.add(newNode("node" + i));
}
clusterState = ClusterState.builder(clusterState).nodes(nodesBuilder).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertThat(routingResult.changed(), equalTo(false));
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Marking the shard as started");
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
- assertThat(routingResult.changed(), equalTo(true));
+ clusterState = newState;
int numberOfRelocatingShards = 0;
int numberOfStartedShards = 0;
for (int i = 0; i < numberOfIndices; i++) {
@@ -333,10 +329,10 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")))
.build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
for (int i = 0; i < numberOfIndices; i++) {
assertThat(clusterState.routingTable().index("test" + i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test" + i).shard(0).size(), equalTo(1));
@@ -353,15 +349,15 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState)
.nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node4")).add(newNode("node5")))
.build();
- routingResult = strategy.reroute(clusterState, "reroute");
-
- assertThat(routingResult.changed(), equalTo(false));
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
for (int i = 0; i < numberOfIndices; i++) {
assertThat(clusterState.routingTable().index("test" + i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test" + i).shard(0).size(), equalTo(1));
@@ -373,11 +369,11 @@ public class SingleShardNoReplicasRoutingTests extends ESAllocationTestCase {
assertThat("4 target shard routing are initializing", numberOfShardsOfType(routingNodes, INITIALIZING), equalTo(4));
logger.info("Now, mark the relocated as started");
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
// routingTable = strategy.reroute(new RoutingStrategyInfo(metaData, routingTable), nodes);
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertThat(routingResult.changed(), equalTo(true));
for (int i = 0; i < numberOfIndices; i++) {
assertThat(clusterState.routingTable().index("test" + i).shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test" + i).shard(0).size(), equalTo(1));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java
index cad5654eaa..0990850aca 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/SingleShardOneReplicaRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -29,12 +30,12 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
/**
@@ -69,10 +70,10 @@ public class SingleShardOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Adding one node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(2));
@@ -84,17 +85,15 @@ public class SingleShardOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Add another node and perform rerouting, nothing will happen since primary shards not started");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the primary shard (on node1)");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(2));
@@ -107,15 +106,15 @@ public class SingleShardOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the backup shard");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(2));
@@ -128,10 +127,10 @@ public class SingleShardOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Kill node1, backup shard should become primary");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove("node1")).build();
- routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.deassociateDeadNodes(clusterState, true, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(2));
@@ -145,10 +144,10 @@ public class SingleShardOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Start another node, backup shard should start initializing");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(2));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java
index 76db92435f..d8d00e3915 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/StartedShardsRoutingTests.java
@@ -21,6 +21,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -34,12 +35,12 @@ import org.elasticsearch.cluster.routing.TestShardRouting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
public class StartedShardsRoutingTests extends ESAllocationTestCase {
@@ -68,16 +69,17 @@ public class StartedShardsRoutingTests extends ESAllocationTestCase {
logger.info("--> test starting of shard");
- RoutingAllocation.Result result = allocation.applyStartedShards(state, Arrays.asList(initShard), false);
- assertTrue("failed to start " + initShard + "\ncurrent routing table:" + result.routingTable().prettyPrint(), result.changed());
- assertTrue(initShard + "isn't started \ncurrent routing table:" + result.routingTable().prettyPrint(),
- result.routingTable().index("test").shard(initShard.id()).allShardsStarted());
-
+ ClusterState newState = allocation.applyStartedShards(state, Arrays.asList(initShard), false);
+ assertThat("failed to start " + initShard + "\ncurrent routing table:" + newState.routingTable().prettyPrint(),
+ newState, not(equalTo(state)));
+ assertTrue(initShard + "isn't started \ncurrent routing table:" + newState.routingTable().prettyPrint(),
+ newState.routingTable().index("test").shard(initShard.id()).allShardsStarted());
logger.info("--> testing starting of relocating shards");
- result = allocation.applyStartedShards(state, Arrays.asList(relocatingShard.getTargetRelocatingShard()), false);
- assertTrue("failed to start " + relocatingShard + "\ncurrent routing table:" + result.routingTable().prettyPrint(), result.changed());
- ShardRouting shardRouting = result.routingTable().index("test").shard(relocatingShard.id()).getShards().get(0);
+ newState = allocation.applyStartedShards(state, Arrays.asList(relocatingShard.getTargetRelocatingShard()), false);
+ assertThat("failed to start " + relocatingShard + "\ncurrent routing table:" + newState.routingTable().prettyPrint(),
+ newState, not(equalTo(state)));
+ ShardRouting shardRouting = newState.routingTable().index("test").shard(relocatingShard.id()).getShards().get(0);
assertThat(shardRouting.state(), equalTo(ShardRoutingState.STARTED));
assertThat(shardRouting.currentNodeId(), equalTo("node2"));
assertThat(shardRouting.relocatingNodeId(), nullValue());
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java
index a6a7e6c065..5907232b5f 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/TenShardsOneReplicaRoutingTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -30,7 +31,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
@@ -38,6 +38,7 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.lessThan;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
/**
@@ -82,10 +83,10 @@ public class TenShardsOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Adding one node and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(10));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -99,17 +100,15 @@ public class TenShardsOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Add another node and perform rerouting, nothing will happen since primary not started");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the primary shard (on node1)");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(10));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -123,16 +122,16 @@ public class TenShardsOneReplicaRoutingTests extends ESAllocationTestCase {
}
logger.info("Reroute, nothing should change");
- routingResult = strategy.reroute(clusterState, "reroute");
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
logger.info("Start the backup shard");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(10));
for (int i = 0; i < clusterState.routingTable().index("test").shards().size(); i++) {
assertThat(clusterState.routingTable().index("test").shard(i).size(), equalTo(2));
@@ -148,11 +147,11 @@ public class TenShardsOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Add another node and perform rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(10));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED, RELOCATING), equalTo(10));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), lessThan(10));
@@ -162,11 +161,11 @@ public class TenShardsOneReplicaRoutingTests extends ESAllocationTestCase {
logger.info("Start the shards on node 3");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.node("node3").shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.node("node3").shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
routingNodes = clusterState.getRoutingNodes();
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(10));
assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(7));
assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(7));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java
index 9083085b5c..d6aafbda34 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ThrottlingAllocationTests.java
@@ -23,6 +23,7 @@ import com.carrotsearch.hppc.IntHashSet;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -35,7 +36,6 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.snapshots.Snapshot;
import org.elasticsearch.snapshots.SnapshotId;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
@@ -67,40 +67,35 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one node, do reroute, only 3 should initialize");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(17));
logger.info("start initializing, another 3 should initialize");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(14));
logger.info("start initializing, another 3 should initialize");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(6));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(11));
logger.info("start initializing, another 1 should initialize");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(9));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(10));
logger.info("start initializing, all primaries should be started");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(10));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -126,24 +121,21 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one node, do reroute, only 3 should initialize");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(7));
logger.info("start initializing, another 2 should initialize");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(2));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(5));
logger.info("start initializing, all primaries should be started");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -151,24 +143,21 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start another node, replicas should start being allocated");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(3));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(2));
logger.info("start initializing replicas");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(8));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(2));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(0));
logger.info("start initializing replicas, all should be started");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(10));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -194,28 +183,24 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one node, do reroute, only 5 should initialize");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(5));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(4));
assertEquals(clusterState.getRoutingNodes().getIncomingRecoveries("node1"), 5);
logger.info("start initializing, all primaries should be started");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(5));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(4));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(0));
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
logger.info("start another 2 nodes, 5 shards should be relocating - at most 5 are allowed per node");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2")).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(4));
assertThat(clusterState.routingTable().shardsWithState(RELOCATING).size(), equalTo(5));
@@ -226,8 +211,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
assertEquals(clusterState.getRoutingNodes().getIncomingRecoveries("node1"), 0);
assertEquals(clusterState.getRoutingNodes().getOutgoingRecoveries("node1"), 5);
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
logger.info("start the relocating shards, one more shard should relocate away from node1");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(8));
@@ -257,16 +241,14 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one node, do reroute, only 1 should initialize");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(0));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(1));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(2));
logger.info("start initializing");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -274,8 +256,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one more node, first non-primary should start being allocated");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(1));
@@ -283,8 +264,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
assertEquals(clusterState.getRoutingNodes().getOutgoingRecoveries("node1"), 1);
logger.info("start initializing non-primary");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.routingTable().shardsWithState(INITIALIZING));
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(2));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(0));
assertThat(clusterState.routingTable().shardsWithState(UNASSIGNED).size(), equalTo(1));
@@ -292,8 +272,7 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one more node, initializing second non-primary");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(2));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(1));
@@ -302,19 +281,18 @@ public class ThrottlingAllocationTests extends ESAllocationTestCase {
logger.info("start one more node");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node4"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertEquals(clusterState.getRoutingNodes().getOutgoingRecoveries("node1"), 1);
logger.info("move started non-primary to new node");
- RoutingAllocation.Result reroute = strategy.reroute(clusterState, new AllocationCommands(
+ AllocationService.CommandsResult commandsResult = strategy.reroute(clusterState, new AllocationCommands(
new MoveAllocationCommand("test", 0, "node2", "node4")), true, false);
- assertEquals(reroute.explanations().explanations().size(), 1);
- assertEquals(reroute.explanations().explanations().get(0).decisions().type(), Decision.Type.THROTTLE);
+ assertEquals(commandsResult.explanations().explanations().size(), 1);
+ assertEquals(commandsResult.explanations().explanations().get(0).decisions().type(), Decision.Type.THROTTLE);
// even though it is throttled, move command still forces allocation
- clusterState = ClusterState.builder(clusterState).routingResult(reroute).build();
+ clusterState = commandsResult.getClusterState();
assertThat(clusterState.routingTable().shardsWithState(STARTED).size(), equalTo(1));
assertThat(clusterState.routingTable().shardsWithState(RELOCATING).size(), equalTo(1));
assertThat(clusterState.routingTable().shardsWithState(INITIALIZING).size(), equalTo(2));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java
index 4857086e24..e711354b18 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/UpdateNumberOfReplicasTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -29,7 +30,6 @@ import org.elasticsearch.cluster.routing.RoutingNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING;
import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
@@ -72,22 +72,21 @@ public class UpdateNumberOfReplicasTests extends ESAllocationTestCase {
logger.info("Adding two nodes and performing rerouting");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logger.info("Start all the primary shards");
RoutingNodes routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
logger.info("Start all the replica shards");
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ ClusterState newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
+
final String nodeHoldingPrimary = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId();
final String nodeHoldingReplica = clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId();
assertThat(nodeHoldingPrimary, not(equalTo(nodeHoldingReplica)));
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).shards().size(), equalTo(2));
@@ -117,10 +116,10 @@ public class UpdateNumberOfReplicasTests extends ESAllocationTestCase {
logger.info("Add another node and start the added replica");
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(3));
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().state(), equalTo(STARTED));
@@ -132,10 +131,10 @@ public class UpdateNumberOfReplicasTests extends ESAllocationTestCase {
assertThat(clusterState.routingTable().index("test").shard(0).replicaShardsWithState(INITIALIZING).get(0).currentNodeId(), equalTo("node3"));
routingNodes = clusterState.getRoutingNodes();
- routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ newState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING));
+ assertThat(newState, not(equalTo(clusterState)));
+ clusterState = newState;
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(3));
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().state(), equalTo(STARTED));
@@ -153,7 +152,6 @@ public class UpdateNumberOfReplicasTests extends ESAllocationTestCase {
assertThat(clusterState.metaData().index("test").getNumberOfReplicas(), equalTo(1));
- assertTrue(routingResult.changed());
assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(1));
assertThat(clusterState.routingTable().index("test").shard(0).size(), equalTo(2));
assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().state(), equalTo(STARTED));
@@ -163,9 +161,7 @@ public class UpdateNumberOfReplicasTests extends ESAllocationTestCase {
assertThat(clusterState.routingTable().index("test").shard(0).replicaShards().get(0).currentNodeId(), anyOf(equalTo(nodeHoldingReplica), equalTo("node3")));
logger.info("do a reroute, should remain the same");
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
-
- assertFalse(routingResult.changed());
+ newState = strategy.reroute(clusterState, "reroute");
+ assertThat(newState, equalTo(clusterState));
}
}
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java
index 98268e409f..65fb1ac002 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.cluster.ClusterInfoService;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.DiskUsage;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.MockInternalClusterInfoService.DevNullClusterInfo;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -49,14 +50,12 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.LocalTransportAddress;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.test.gateway.NoopGatewayAllocator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
@@ -66,11 +65,10 @@ import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED;
import static org.elasticsearch.cluster.routing.ShardRoutingState.UNASSIGNED;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
public class DiskThresholdDeciderTests extends ESAllocationTestCase {
-
+
DiskThresholdDecider makeDecider(Settings settings) {
return new DiskThresholdDecider(settings, new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
}
@@ -133,16 +131,14 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.add(newNode("node1"))
.add(newNode("node2"))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Primary shard should be initializing, replica should not
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// Assert that we're able to start the primary
@@ -151,8 +147,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// Assert that the replica couldn't be started since node1 doesn't have enough space
@@ -163,8 +158,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Assert that the replica is initialized now that node3 is available with enough space
@@ -172,8 +166,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// Assert that the replica couldn't be started since node1 doesn't have enough space
@@ -203,8 +196,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started
@@ -234,8 +226,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started
@@ -250,8 +241,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started
@@ -259,8 +249,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> apply INITIALIZING shards");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
@@ -331,8 +320,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.add(newNode("node2"))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Primary should initialize, even though both nodes are over the limit initialize
@@ -372,16 +360,14 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Now the replica should be able to initialize
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(2));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// Assert that we're able to start the primary and replica, since they were both initializing
@@ -399,8 +385,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node3"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Assert that the replica is initialized now that node3 is available with enough space
@@ -408,8 +393,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(ShardRoutingState.INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// Assert that all replicas could be started
@@ -439,8 +423,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started
@@ -470,8 +453,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started
@@ -486,8 +468,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node4"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started
@@ -497,8 +478,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> apply INITIALIZING shards");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// primary shard already has been relocated away
@@ -513,8 +493,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes())
.add(newNode("node5"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// Shards remain started on node3 and node4
@@ -525,8 +504,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> apply INITIALIZING shards");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> final cluster state:");
logShardStates(clusterState);
@@ -771,16 +749,14 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.add(newNode("node1"))
.add(newNode("node2"))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
logShardStates(clusterState);
// shards should be initializing
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(4));
logger.info("--> start the shards");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logShardStates(clusterState);
// Assert that we're able to start the primary and replicas
@@ -794,8 +770,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
AllocationCommand relocate1 = new MoveAllocationCommand("test", 0, "node2", "node3");
AllocationCommands cmds = new AllocationCommands(relocate1);
- routingResult = strategy.reroute(clusterState, cmds, false, false);
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, cmds, false, false).getClusterState();
logShardStates(clusterState);
AllocationCommand relocate2 = new MoveAllocationCommand("test2", 0, "node2", "node3");
@@ -806,7 +781,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
// node3, which will put it over the low watermark when it
// completes, with shard relocations taken into account this should
// throw an exception about not being able to complete
- strategy.reroute(clusterState, cmds, false, false).routingTable();
+ strategy.reroute(clusterState, cmds, false, false);
fail("should not have been able to reroute the shard");
} catch (IllegalArgumentException e) {
assertThat("can't allocated because there isn't enough room: " + e.getMessage(),
@@ -928,8 +903,8 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
// Ensure that the reroute call doesn't alter the routing table, since the first primary is relocating away
// and therefor we will have sufficient disk space on node1.
- RoutingAllocation.Result result = strategy.reroute(clusterState, "reroute");
- assertThat(result.changed(), is(false));
+ ClusterState result = strategy.reroute(clusterState, "reroute");
+ assertThat(result, equalTo(clusterState));
assertThat(result.routingTable().index("test").getShards().get(0).primaryShard().state(), equalTo(STARTED));
assertThat(result.routingTable().index("test").getShards().get(0).primaryShard().currentNodeId(), equalTo("node1"));
assertThat(result.routingTable().index("test").getShards().get(0).primaryShard().relocatingNodeId(), nullValue());
@@ -1024,7 +999,7 @@ public class DiskThresholdDeciderTests extends ESAllocationTestCase {
.put("cluster.routing.allocation.cluster_concurrent_rebalance", -1)
.build(), deciders, NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(Settings.EMPTY), cis);
- RoutingAllocation.Result result = strategy.reroute(clusterState, "reroute");
+ ClusterState result = strategy.reroute(clusterState, "reroute");
assertThat(result.routingTable().index("test").getShards().get(0).primaryShard().state(), equalTo(STARTED));
assertThat(result.routingTable().index("test").getShards().get(0).primaryShard().currentNodeId(), equalTo("node2"));
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java
index 4649bfb42c..5e8f341527 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderUnitTests.java
@@ -23,6 +23,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterInfo;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.DiskUsage;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.MockInternalClusterInfoService.DevNullClusterInfo;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@@ -45,7 +46,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.LocalTransportAddress;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.Arrays;
import java.util.Collections;
@@ -279,12 +279,10 @@ public class DiskThresholdDeciderUnitTests extends ESAllocationTestCase {
AllocationService allocationService = createAllocationService();
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")))
.build();
- RoutingAllocation.Result result = allocationService.reroute(clusterState, "foo");
- clusterState = ClusterState.builder(clusterState).routingTable(result.routingTable()).build();
+ clusterState = allocationService.reroute(clusterState, "foo");
- result = allocationService.applyStartedShards(clusterState,
+ clusterState = allocationService.applyStartedShards(clusterState,
clusterState.getRoutingTable().index("test").shardsWithState(ShardRoutingState.UNASSIGNED));
- clusterState = ClusterState.builder(clusterState).routingTable(result.routingTable()).build();
RoutingAllocation allocation = new RoutingAllocation(null, clusterState.getRoutingNodes(), clusterState, info, 0, false);
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java
index a9c15de61d..4230504f53 100644
--- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/EnableAllocationTests.java
@@ -23,19 +23,18 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.Allocation;
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider.Rebalance;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.EnumSet;
import java.util.List;
@@ -138,15 +137,12 @@ public class EnableAllocationTests extends ESAllocationTestCase {
.add(newNode("node1"))
.add(newNode("node2"))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(1));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> start the shards (replicas)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
logger.info("--> verify only enabled index has been routed");
assertThat(clusterState.getRoutingNodes().shardsWithState("enabled", STARTED).size(), equalTo(2));
@@ -183,17 +179,14 @@ public class EnableAllocationTests extends ESAllocationTestCase {
.add(newNode("node1"))
.add(newNode("node2"))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(4));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(4));
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(8));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -203,8 +196,7 @@ public class EnableAllocationTests extends ESAllocationTestCase {
.add(newNode("node2"))
.add(newNode("node3"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(8));
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(0));
@@ -221,8 +213,7 @@ public class EnableAllocationTests extends ESAllocationTestCase {
}
clusterSettings.applySettings(clusterState.metaData().settings());
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat("expected 6 shards to be started 2 to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
assertThat("expected 2 shards to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(2));
List<ShardRouting> mutableShardRoutings = clusterState.getRoutingNodes().shardsWithState(RELOCATING);
@@ -247,8 +238,7 @@ public class EnableAllocationTests extends ESAllocationTestCase {
default:
fail("only replicas, primaries or all are allowed");
}
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(8));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -280,12 +270,10 @@ public class EnableAllocationTests extends ESAllocationTestCase {
.add(newNode("node1"))
.add(newNode("node2"))
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(6));
logger.info("--> start the shards (primaries)");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
@@ -295,8 +283,7 @@ public class EnableAllocationTests extends ESAllocationTestCase {
.add(newNode("node2"))
.add(newNode("node3"))
).build();
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(0));
metaData = clusterState.metaData();
@@ -310,8 +297,7 @@ public class EnableAllocationTests extends ESAllocationTestCase {
.put(IndexMetaData.builder(meta).settings(Settings.builder().put(meta.getSettings()).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL).build()))).build();
}
clusterSettings.applySettings(clusterState.metaData().settings());
- routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
assertThat("expected 4 primaries to be started and 2 to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
assertThat("expected 2 primaries to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(2));
diff --git a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java
index 8ebf2c3eb9..0aad8669cb 100644
--- a/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java
+++ b/core/src/test/java/org/elasticsearch/cluster/structure/RoutingIteratorTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.cluster.structure;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
+import org.elasticsearch.cluster.ESAllocationTestCase;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNodes;
@@ -35,12 +36,10 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.ShardShuffler;
import org.elasticsearch.cluster.routing.ShardsIterator;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.shard.ShardId;
-import org.elasticsearch.cluster.ESAllocationTestCase;
import java.util.Collections;
import java.util.HashMap;
@@ -251,14 +250,11 @@ public class RoutingIteratorTests extends ESAllocationTestCase {
.add(newNode("node2", unmodifiableMap(node2Attributes)))
.localNodeId("node1")
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// after all are started, check routing iteration
ShardIterator shardIterator = clusterState.routingTable().index("test").shard(0).preferAttributesActiveInitializingShardsIt(new String[]{"rack_id"}, clusterState.nodes());
@@ -300,11 +296,9 @@ public class RoutingIteratorTests extends ESAllocationTestCase {
.localNodeId("node1")
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
ShardsIterator shardsIterator = clusterState.routingTable().index("test").shard(0).onlyNodeSelectorActiveInitializingShardsIt("disk:ebs",clusterState.nodes());
assertThat(shardsIterator.size(), equalTo(1));
@@ -373,14 +367,11 @@ public class RoutingIteratorTests extends ESAllocationTestCase {
.add(newNode("node2"))
.localNodeId("node1")
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY,
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
@@ -447,11 +438,9 @@ public class RoutingIteratorTests extends ESAllocationTestCase {
.add(newNode("node3"))
.localNodeId("node1")
).build();
- RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute");
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.reroute(clusterState, "reroute");
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
// When replicas haven't initialized, it comes back with the primary first, then initializing replicas
GroupShardsIterator shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica_first");
@@ -472,11 +461,9 @@ public class RoutingIteratorTests extends ESAllocationTestCase {
assertFalse(routing.primary());
assertTrue(routing.initializing());
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- routingResult = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
+ clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
shardIterators = operationRouting.searchShards(clusterState, new String[]{"test"}, null, "_replica");
diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/NodeRemovalClusterStateTaskExecutorTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/NodeRemovalClusterStateTaskExecutorTests.java
index 1e8954330c..4492cdb52e 100644
--- a/core/src/test/java/org/elasticsearch/discovery/zen/NodeRemovalClusterStateTaskExecutorTests.java
+++ b/core/src/test/java/org/elasticsearch/discovery/zen/NodeRemovalClusterStateTaskExecutorTests.java
@@ -26,7 +26,6 @@ import org.elasticsearch.cluster.ClusterStateTaskExecutor;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.common.transport.LocalTransportAddress;
import org.elasticsearch.test.ESTestCase;
@@ -133,7 +132,7 @@ public class NodeRemovalClusterStateTaskExecutorTests extends ESTestCase {
final AllocationService allocationService = mock(AllocationService.class);
when(allocationService.deassociateDeadNodes(any(ClusterState.class), eq(true), any(String.class)))
- .thenReturn(mock(RoutingAllocation.Result.class));
+ .thenAnswer(im -> im.getArguments()[0]);
final BiFunction<ClusterState, String, ClusterState> rejoin = (cs, r) -> {
fail("rejoin should not be invoked");
diff --git a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java
index 7adddd6ee0..2ac204a218 100644
--- a/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java
+++ b/core/src/test/java/org/elasticsearch/indices/cluster/ClusterStateChanges.java
@@ -55,7 +55,6 @@ import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.FailedRerouteAllocation;
import org.elasticsearch.cluster.routing.allocation.RandomAllocationDeciderTests;
-import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
import org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator;
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
import org.elasticsearch.cluster.routing.allocation.decider.ReplicaAfterPrimaryActiveAllocationDecider;
@@ -208,8 +207,7 @@ public class ClusterStateChanges extends AbstractComponent {
}
public ClusterState deassociateDeadNodes(ClusterState clusterState, boolean reroute, String reason) {
- RoutingAllocation.Result rerouteResult = allocationService.deassociateDeadNodes(clusterState, reroute, reason);
- return ClusterState.builder(clusterState).routingResult(rerouteResult).build();
+ return allocationService.deassociateDeadNodes(clusterState, reroute, reason);
}
public ClusterState applyFailedShards(ClusterState clusterState, List<FailedRerouteAllocation.FailedShard> failedShards) {
diff --git a/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java b/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java
index 4964defc62..2ca8947cbf 100644
--- a/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java
+++ b/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java
@@ -37,7 +37,6 @@ import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.allocation.AllocationService;
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
-import org.elasticsearch.cluster.routing.allocation.decider.AllocationDecider;
import org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.collect.ImmutableOpenMap;
@@ -140,8 +139,7 @@ public class RareClusterStateIT extends ESIntegTestCase {
routingTable.addAsRecovery(updatedState.metaData().index(index));
updatedState = ClusterState.builder(updatedState).routingTable(routingTable.build()).build();
- RoutingAllocation.Result result = allocationService.reroute(updatedState, "reroute");
- return ClusterState.builder(updatedState).routingResult(result).build();
+ return allocationService.reroute(updatedState, "reroute");
}
@@ -159,8 +157,7 @@ public class RareClusterStateIT extends ESIntegTestCase {
builder.nodes(DiscoveryNodes.builder(currentState.nodes()).remove("_non_existent"));
currentState = builder.build();
- RoutingAllocation.Result result = allocationService.deassociateDeadNodes(currentState, true, "reroute");
- return ClusterState.builder(currentState).routingResult(result).build();
+ return allocationService.deassociateDeadNodes(currentState, true, "reroute");
}
diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java
index f6b9a0a19e..bddda142f0 100644
--- a/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java
+++ b/test/framework/src/main/java/org/elasticsearch/cluster/ESAllocationTestCase.java
@@ -126,9 +126,8 @@ public abstract class ESAllocationTestCase extends ESTestCase {
if (initializingShards.isEmpty()) {
return clusterState;
}
- RoutingAllocation.Result routingResult = strategy.applyStartedShards(clusterState,
+ return strategy.applyStartedShards(clusterState,
arrayAsArrayList(initializingShards.get(randomInt(initializingShards.size() - 1))));
- return ClusterState.builder(clusterState).routingResult(routingResult).build();
}
protected static AllocationDeciders yesAllocationDeciders() {
@@ -148,12 +147,12 @@ public abstract class ESAllocationTestCase extends ESTestCase {
}
protected ClusterState applyStartedShardsUntilNoChange(ClusterState clusterState, AllocationService service) {
- RoutingAllocation.Result routingResult;
+ ClusterState lastClusterState;
do {
+ lastClusterState = clusterState;
logger.debug("ClusterState: {}", clusterState.getRoutingNodes().prettyPrint());
- routingResult = service.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
- clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build();
- } while (routingResult.changed());
+ clusterState = service.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
+ } while (lastClusterState.equals(clusterState) == false);
return clusterState;
}