Skip to content

Commit c166008

Browse files
committed
[ALLOCATION] Speed-up disk-threshold decider
Instead of iterating all shards of all indices to get all relocating shards for a given node we can just use the RoutingNode#shardsWithState method and fetch all INITIALIZING / RELOCATING shards and check if they are relocating. This operation is much faster and uses pre-build data-structures. Relates to #6372
1 parent c98b8f3 commit c166008

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDecider.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,12 @@ public DiskThresholdDecider(Settings settings, NodeSettingsService nodeSettingsS
227227
* If subtractShardsMovingAway is set then the size of shards moving away is subtracted from the total size
228228
* of all shards
229229
*/
230-
public long sizeOfRelocatingShards(RoutingNode node, RoutingAllocation allocation, Map<String, Long> shardSizes, boolean subtractShardsMovingAway) {
231-
List<ShardRouting> relocatingShards = allocation.routingTable().shardsWithState(ShardRoutingState.RELOCATING);
230+
public long sizeOfRelocatingShards(RoutingNode node, Map<String, Long> shardSizes, boolean subtractShardsMovingAway) {
232231
long totalSize = 0;
233-
for (ShardRouting routing : relocatingShards) {
234-
if (routing.relocatingNodeId().equals(node.nodeId())) {
232+
for (ShardRouting routing : node.shardsWithState(ShardRoutingState.RELOCATING, ShardRoutingState.INITIALIZING)) {
233+
if (routing.initializing() && routing.relocatingNodeId() != null) {
235234
totalSize += getShardSize(routing, shardSizes);
236-
} else if (subtractShardsMovingAway && routing.currentNodeId().equals(node.nodeId())) {
235+
} else if (subtractShardsMovingAway && routing.relocating()) {
237236
totalSize -= getShardSize(routing, shardSizes);
238237
}
239238
}
@@ -291,7 +290,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
291290
}
292291

293292
if (includeRelocations) {
294-
long relocatingShardsSize = sizeOfRelocatingShards(node, allocation, shardSizes, false);
293+
long relocatingShardsSize = sizeOfRelocatingShards(node, shardSizes, false);
295294
DiskUsage usageIncludingRelocations = new DiskUsage(node.nodeId(), node.node().name(),
296295
usage.getTotalBytes(), usage.getFreeBytes() - relocatingShardsSize);
297296
if (logger.isTraceEnabled()) {
@@ -437,7 +436,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
437436

438437
if (includeRelocations) {
439438
Map<String, Long> shardSizes = clusterInfo.getShardSizes();
440-
long relocatingShardsSize = sizeOfRelocatingShards(node, allocation, shardSizes, true);
439+
long relocatingShardsSize = sizeOfRelocatingShards(node, shardSizes, true);
441440
DiskUsage usageIncludingRelocations = new DiskUsage(node.nodeId(), node.node().name(),
442441
usage.getTotalBytes(), usage.getFreeBytes() - relocatingShardsSize);
443442
if (logger.isTraceEnabled()) {

0 commit comments

Comments
 (0)