Skip to content

Commit c81eee5

Browse files
Rename decideShardAllocation to reflect allocation explain purpose (#137227)
Renames ShardsAllocator#decideShardAllocation to ShardsAllocator#explainShardAllocation Relates ES-12833
1 parent aa643b1 commit c81eee5

File tree

13 files changed

+29
-34
lines changed

13 files changed

+29
-34
lines changed

server/src/main/java/org/elasticsearch/cluster/routing/allocation/AllocationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ public ShardAllocationDecision explainShardAllocation(ShardRouting shardRouting,
795795
if (allocateDecision.isDecisionTaken()) {
796796
return new ShardAllocationDecision(allocateDecision, MoveDecision.NOT_TAKEN);
797797
} else {
798-
return shardsAllocator.decideShardAllocation(shardRouting, allocation);
798+
return shardsAllocator.explainShardAllocation(shardRouting, allocation);
799799
}
800800
}
801801

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private void collectAndRecordNodeWeightStats(Balancer balancer, BalancingWeights
243243
}
244244

245245
@Override
246-
public ShardAllocationDecision decideShardAllocation(final ShardRouting shard, final RoutingAllocation allocation) {
246+
public ShardAllocationDecision explainShardAllocation(final ShardRouting shard, final RoutingAllocation allocation) {
247247
Balancer balancer = new Balancer(
248248
writeLoadForecaster,
249249
allocation,

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceShardsAllocator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ public String toString() {
246246
}
247247

248248
@Override
249-
public ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
250-
return delegateAllocator.decideShardAllocation(shard, allocation);
249+
public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
250+
return delegateAllocator.explainShardAllocation(shard, allocation);
251251
}
252252

253253
@Override

server/src/main/java/org/elasticsearch/cluster/routing/allocation/allocator/ShardsAllocator.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,8 @@ default RoutingExplanations execute(RoutingAllocation allocation, AllocationComm
7777
* then the {@link AllocateUnassignedDecision} will be non-null. If the shard is not in the unassigned
7878
* state, then the {@link MoveDecision} will be non-null.
7979
*
80-
* This method is primarily used by the cluster allocation explain API to provide detailed explanations
81-
* for the allocation of a single shard. Implementations of the {@link #allocate(RoutingAllocation)} method
82-
* may use the results of this method implementation to decide on allocating shards in the routing table
83-
* to the cluster.
84-
*
8580
* If an implementation of this interface does not support explaining decisions for a single shard through
8681
* the cluster explain API, then this method should throw a {@code UnsupportedOperationException}.
8782
*/
88-
ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation);
83+
ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation);
8984
}

server/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainActionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void allocate(RoutingAllocation allocation) {
8181
}
8282

8383
@Override
84-
public ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
84+
public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
8585
if (shard.initializing() || shard.relocating()) {
8686
return ShardAllocationDecision.NOT_TAKEN;
8787
} else {

server/src/test/java/org/elasticsearch/cluster/ClusterModuleTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void allocate(RoutingAllocation allocation) {
111111
}
112112

113113
@Override
114-
public ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
114+
public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
115115
throw new UnsupportedOperationException("explain API not supported on FakeShardsAllocator");
116116
}
117117
}

server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void allocate(RoutingAllocation allocation) {
148148
}
149149

150150
@Override
151-
public ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
151+
public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
152152
return ShardAllocationDecision.NOT_TAKEN;
153153
}
154154
},

server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationStatsServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public void allocate(RoutingAllocation allocation) {
215215
}
216216

217217
@Override
218-
public ShardAllocationDecision decideShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
218+
public ShardAllocationDecision explainShardAllocation(ShardRouting shard, RoutingAllocation allocation) {
219219
return null;
220220
}
221221
};

server/src/test/java/org/elasticsearch/cluster/routing/allocation/BalancedSingleShardTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testRebalanceNonStartedShardNotAllowed() {
5858
final ProjectId projectId = clusterState.metadata().projects().keySet().iterator().next();
5959

6060
ShardRouting shard = clusterState.globalRoutingTable().routingTable(projectId).index("idx").shard(0).primaryShard();
61-
MoveDecision rebalanceDecision = allocator.decideShardAllocation(
61+
MoveDecision rebalanceDecision = allocator.explainShardAllocation(
6262
shard,
6363
newRoutingAllocation(new AllocationDeciders(Collections.emptyList()), clusterState)
6464
).getMoveDecision();
@@ -75,7 +75,7 @@ public void testRebalanceNotAllowedDuringPendingAsyncFetch() {
7575
ShardRouting shard = clusterState.globalRoutingTable().routingTable(projectId).index("idx").shard(0).primaryShard();
7676
RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(Collections.emptyList()), clusterState);
7777
routingAllocation.setHasPendingAsyncFetch();
78-
MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
78+
MoveDecision rebalanceDecision = allocator.explainShardAllocation(shard, routingAllocation).getMoveDecision();
7979
assertNotNull(rebalanceDecision.getClusterRebalanceDecision());
8080
assertEquals(AllocationDecision.AWAITING_INFO, rebalanceDecision.getAllocationDecision());
8181
assertThat(rebalanceDecision.getExplanation(), equalTo(Explanations.Rebalance.AWAITING_INFO));
@@ -104,7 +104,7 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca
104104
new AllocationDeciders(Collections.singleton(noRebalanceDecider)),
105105
clusterState
106106
);
107-
MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
107+
MoveDecision rebalanceDecision = allocator.explainShardAllocation(shard, routingAllocation).getMoveDecision();
108108
assertEquals(canRebalanceDecision.type(), rebalanceDecision.getClusterRebalanceDecision().type());
109109
assertEquals(AllocationDecision.fromDecisionType(canRebalanceDecision.type()), rebalanceDecision.getAllocationDecision());
110110
assertThat(
@@ -247,7 +247,7 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca
247247
routingAllocation = newRoutingAllocation(new AllocationDeciders(allocationDeciders), clusterState);
248248
routingAllocation.debugDecision(true);
249249
ShardRouting shard = clusterState.getRoutingNodes().activePrimary(shardToRebalance.shardId());
250-
MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
250+
MoveDecision rebalanceDecision = allocator.explainShardAllocation(shard, routingAllocation).getMoveDecision();
251251
assertEquals(shardToRebalance.relocatingNodeId(), rebalanceDecision.getTargetNode().getId());
252252
// make sure all excluded nodes returned a NO decision
253253
for (NodeAllocationResult nodeResult : rebalanceDecision.getNodeDecisions()) {
@@ -345,7 +345,7 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca
345345
assertThat(clusterState.metadata().projects(), aMapWithSize(1));
346346
final ProjectId projectId = clusterState.metadata().projects().keySet().iterator().next();
347347

348-
return allocator.decideShardAllocation(shardRouting, routingAllocation).getMoveDecision();
348+
return allocator.explainShardAllocation(shardRouting, routingAllocation).getMoveDecision();
349349
}
350350

351351
private ClusterState addNodesToClusterState(ClusterState clusterState, int numNodesToAdd) {
@@ -382,7 +382,7 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca
382382

383383
ShardRouting shard = clusterState.routingTable(projectId).index("idx").shard(0).primaryShard();
384384
RoutingAllocation routingAllocation = newRoutingAllocation(new AllocationDeciders(allocationDeciders), clusterState);
385-
MoveDecision rebalanceDecision = allocator.decideShardAllocation(shard, routingAllocation).getMoveDecision();
385+
MoveDecision rebalanceDecision = allocator.explainShardAllocation(shard, routingAllocation).getMoveDecision();
386386

387387
if (rebalanceExpected == false) {
388388
assertAssignedNodeRemainsSame(allocator, routingAllocation, shard);

server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/BalancedShardsAllocatorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class BalancedShardsAllocatorTests extends ESAllocationTestCase {
102102
};
103103
private static final Settings WITH_DISK_BALANCING = Settings.builder().put(DISK_USAGE_BALANCE_FACTOR_SETTING.getKey(), "1e-9").build();
104104

105-
public void testDecideShardAllocation() {
105+
public void testExplainShardAllocation() {
106106
BalancedShardsAllocator allocator = new BalancedShardsAllocator(Settings.EMPTY);
107107
ClusterState clusterState = ClusterStateCreationUtils.state("idx", false, ShardRoutingState.STARTED);
108108
assertEquals(clusterState.nodes().getSize(), 3);
@@ -125,9 +125,9 @@ public void testDecideShardAllocation() {
125125
RoutingAllocation allocation = createRoutingAllocation(clusterState);
126126

127127
allocation.debugDecision(false);
128-
AllocateUnassignedDecision allocateDecision = allocator.decideShardAllocation(shard, allocation).getAllocateDecision();
128+
AllocateUnassignedDecision allocateDecision = allocator.explainShardAllocation(shard, allocation).getAllocateDecision();
129129
allocation.debugDecision(true);
130-
AllocateUnassignedDecision allocateDecisionWithExplain = allocator.decideShardAllocation(shard, allocation).getAllocateDecision();
130+
AllocateUnassignedDecision allocateDecisionWithExplain = allocator.explainShardAllocation(shard, allocation).getAllocateDecision();
131131
// the allocation decision should have same target node no matter the debug is on or off
132132
assertEquals(allocateDecision.getTargetNode().getId(), allocateDecisionWithExplain.getTargetNode().getId());
133133

@@ -138,7 +138,7 @@ public void testDecideShardAllocation() {
138138
assertEquals(allocateDecision.getTargetNode().getId(), assignedShards.get(0).currentNodeId());
139139
}
140140

141-
public void testDecideShardAllocationWhenThereAreMultipleProjects() {
141+
public void testExplainShardAllocationWhenThereAreMultipleProjects() {
142142
final int numberOfNodes = randomIntBetween(3, 8);
143143
final int numberOfProjects = randomIntBetween(3, 8);
144144

@@ -222,7 +222,7 @@ public void testDecideShardAllocationWhenThereAreMultipleProjects() {
222222
.index(indexName)
223223
.shard(0)
224224
.primaryShard();
225-
AllocateUnassignedDecision allocateDecision = allocator.decideShardAllocation(shard, allocation).getAllocateDecision();
225+
AllocateUnassignedDecision allocateDecision = allocator.explainShardAllocation(shard, allocation).getAllocateDecision();
226226
final DiscoveryNode targetNode = allocateDecision.getTargetNode();
227227
assertThat(targetNode, notNullValue());
228228
assertThat(nodes.get(targetNode.getId()), sameInstance(targetNode));

0 commit comments

Comments
 (0)