Skip to content

Commit 668919f

Browse files
authored
Fix relocating shards size calculation (#48421)
In #48392 we added a second computation of the sizes of the relocating shards in `canRemain()` but passed the wrong value for `subtractLeavingShards`. This fixes that. It also removes some unnecessary logging in a test case added in the same commit.
1 parent a14a222 commit 668919f

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
317317
"this shard is not allocated on the most utilized disk and can remain");
318318
}
319319
if (freeBytes < 0L) {
320-
final long sizeOfRelocatingShards = sizeOfRelocatingShards(node, false, usage.getPath(),
320+
final long sizeOfRelocatingShards = sizeOfRelocatingShards(node, true, usage.getPath(),
321321
allocation.clusterInfo(), allocation.metaData(), allocation.routingTable());
322322
logger.debug("fewer free bytes remaining than the size of all incoming shards: " +
323323
"usage {} on node {} including {} bytes of relocations, shard cannot remain",

server/src/test/java/org/elasticsearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,13 @@ public void testShardRelocationsTakenIntoAccount() {
754754
AllocationCommand moveAllocationCommand = new MoveAllocationCommand("test2", 0, "node2", "node3");
755755
AllocationCommands cmds = new AllocationCommands(moveAllocationCommand);
756756

757-
logger.info("--> before starting: {}", clusterState);
758757
clusterState = startInitializingShardsAndReroute(strategy, clusterState);
759-
logger.info("--> after starting: {}", clusterState);
760758
clusterState = strategy.reroute(clusterState, cmds, false, false).getClusterState();
761-
logger.info("--> after running another command: {}", clusterState);
762759
logShardStates(clusterState);
763760

764761
clusterInfoReference.set(overfullClusterInfo);
765762

766-
clusterState = strategy.reroute(clusterState, "foo");
767-
logger.info("--> after another reroute: {}", clusterState);
763+
strategy.reroute(clusterState, "foo"); // ensure reroute doesn't fail even though there is negative free space
768764
}
769765
}
770766

0 commit comments

Comments
 (0)