Skip to content

Commit 5476dce

Browse files
Gagan6164abhita
authored andcommitted
Add minor fixes in WarmDiskThresholdDecider (opensearch-project#18456)
Signed-off-by: Gagan Singh Saini <[email protected]>
1 parent a1af9eb commit 5476dce

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

server/src/main/java/org/opensearch/cluster/routing/allocation/decider/WarmDiskThresholdDecider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
123123

124124
final long totalAddressableSpace = calculateTotalAddressableSpace(node, allocation);
125125
final long currentNodeRemoteShardSize = calculateCurrentNodeRemoteShardSize(node, allocation, false);
126-
final long freeSpace = totalAddressableSpace - currentNodeRemoteShardSize;
127-
final long freeSpaceAfterAllocation = freeSpace > shardSize ? freeSpace - shardSize : 0;
126+
final long freeSpace = Math.max(totalAddressableSpace - currentNodeRemoteShardSize, 0);
127+
final long freeSpaceAfterAllocation = Math.max(freeSpace - shardSize, 0);
128128
final long freeSpaceLowThreshold = calculateFreeSpaceLowThreshold(diskThresholdSettings, totalAddressableSpace);
129129

130130
final ByteSizeValue freeSpaceLowThresholdInByteSize = new ByteSizeValue(freeSpaceLowThreshold);
@@ -145,7 +145,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
145145
return allocation.decision(
146146
Decision.NO,
147147
NAME,
148-
"allocating the shard to this node will bring the node above the low watermark cluster setting [%s=%s] "
148+
"allocating the shard to this node will bring the node above the low watermark cluster setting [%s] "
149149
+ "and cause it to have less than the minimum required [%s] of addressable remote free space (free: [%s], estimated remote shard size: [%s])",
150150
CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(),
151151
freeSpaceLowThresholdInByteSize,
@@ -183,7 +183,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
183183

184184
final long totalAddressableSpace = calculateTotalAddressableSpace(node, allocation);
185185
final long currentNodeRemoteShardSize = calculateCurrentNodeRemoteShardSize(node, allocation, true);
186-
final long freeSpace = totalAddressableSpace - currentNodeRemoteShardSize;
186+
final long freeSpace = Math.max(totalAddressableSpace - currentNodeRemoteShardSize, 0);
187187

188188
final long freeSpaceHighThreshold = calculateFreeSpaceHighThreshold(diskThresholdSettings, totalAddressableSpace);
189189

@@ -200,8 +200,8 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
200200
return allocation.decision(
201201
Decision.NO,
202202
NAME,
203-
"the shard cannot remain on this node because it is above the high watermark cluster setting [%s=%s] "
204-
+ "and there is less than the required [%s%%] free remote addressable space on node, actual free: [%s%%]",
203+
"the shard cannot remain on this node because it is above the high watermark cluster setting [%s] "
204+
+ "and there is less than the required [%s] free remote addressable space on node, actual free: [%s]",
205205
CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(),
206206
freeSpaceHighThresholdInByteSize,
207207
freeSpaceInByteSize

server/src/test/java/org/opensearch/cluster/routing/allocation/decider/WarmDiskThresholdDeciderTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ public void testCanAllocateInSufficientFreeSpace() {
175175
.build();
176176

177177
final Map<String, Long> shardSizes = new HashMap<>();
178-
shardSizes.put("[test][0][p]", 4000L); // 5000 bytes
179-
shardSizes.put("[test][0][r]", 4000L);
178+
shardSizes.put("[test][0][p]", 5500L); // 5500 bytes shard size and total addressable space - 5000 bytes
179+
shardSizes.put("[test][0][r]", 5500L);
180180
shardSizes.put("[test2][0][p]", 1000L); // 1000 bytes
181181
shardSizes.put("[test2][0][r]", 1000L);
182182

@@ -354,8 +354,8 @@ public void testCanRemainInsufficientSpace() {
354354
WarmDiskThresholdDecider decider = new WarmDiskThresholdDecider(settings, clusterSettings);
355355

356356
final Map<String, Long> shardSizes = new HashMap<>();
357-
shardSizes.put("[test][0][p]", 4000L); // 4000 bytes
358-
shardSizes.put("[test][0][r]", 4000L);
357+
shardSizes.put("[test][0][p]", 5500L); // Shard size more than total addressable space - 5000 bytes
358+
shardSizes.put("[test][0][r]", 5500L);
359359
shardSizes.put("[test2][0][p]", 1000L); // 1000 bytes
360360
shardSizes.put("[test2][0][r]", 1000L);
361361

0 commit comments

Comments
 (0)