Skip to content

Commit

Permalink
Remove AllocationService.reroute(ClusterState, String, boolean) (#44629)
Browse files Browse the repository at this point in the history
This commit removes the method AllocationService.reroute(ClusterState, String, boolean) 
in favor of AllocationService.reroute(ClusterState, String).

Motivations are:
    there are already 3 other reroute methods in this class
    this method is always called with the debug parameter set to false
    almost all tests use the method reroute(ClusterState, String)
  • Loading branch information
tlrx authored Jul 22, 2019
1 parent a9cc0e1 commit 67e5ad2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,30 +354,19 @@ public CommandsResult reroute(final ClusterState clusterState, AllocationCommand
return new CommandsResult(explanations, buildResultAndLogHealthChange(clusterState, allocation, "reroute commands"));
}


/**
* Reroutes the routing table based on the live nodes.
* <p>
* If the same instance of ClusterState is returned, then no change has been made.
*/
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 ClusterState is returned, then no change has been made.
*/
protected ClusterState reroute(ClusterState clusterState, String reason, boolean debug) {
ClusterState fixedClusterState = adaptAutoExpandReplicas(clusterState);

RoutingNodes routingNodes = getMutableRoutingNodes(fixedClusterState);
// shuffle the unassigned nodes, just so we won't have things like poison failed shards
routingNodes.unassigned().shuffle();
RoutingAllocation allocation = new RoutingAllocation(allocationDeciders, routingNodes, fixedClusterState,
clusterInfoService.getClusterInfo(), currentNanoTime());
allocation.debugDecision(debug);
reroute(allocation);
if (fixedClusterState == clusterState && allocation.routingNodesChanged() == false) {
return clusterState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private ClusterState createInitialClusterState() {
clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")))
.build();
RoutingTable prevRoutingTable = routingTable;
routingTable = strategy.reroute(clusterState, "reroute", false).routingTable();
routingTable = strategy.reroute(clusterState, "reroute").routingTable();
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();

assertEquals(prevRoutingTable.index("idx").shards().size(), 1);
Expand Down Expand Up @@ -204,7 +204,7 @@ public void testFailedAllocation() {
Settings.builder().put(clusterState.metaData().index("idx").getSettings()).put("index.allocation.max_retries",
retries+1).build()
).build(), true).build()).build();
ClusterState newState = strategy.reroute(clusterState, "settings changed", false);
ClusterState newState = strategy.reroute(clusterState, "settings changed");
assertThat(newState, not(equalTo(clusterState)));
clusterState = newState;
routingTable = newState.routingTable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private ClusterState createInitialClusterState(boolean startShards) {
("node2", Version.CURRENT)))
.build();
RoutingTable prevRoutingTable = routingTable;
routingTable = strategy.reroute(clusterState, "reroute", false).routingTable();
routingTable = strategy.reroute(clusterState, "reroute").routingTable();
clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();

assertEquals(prevRoutingTable.index("source").shards().size(), 2);
Expand Down

0 comments on commit 67e5ad2

Please sign in to comment.