@@ -140,9 +140,8 @@ public static long sizeOfRelocatingShards(
140
140
141
141
// Where reserved space is unavailable (e.g. stats are out-of-sync) compute a conservative estimate for initialising shards
142
142
final List <ShardRouting > initializingShards = node .shardsWithState (ShardRoutingState .INITIALIZING );
143
- initializingShards .removeIf (shardRouting -> reservedSpace .containsShardId (shardRouting .shardId ()));
144
143
for (ShardRouting routing : initializingShards ) {
145
- if (routing .relocatingNodeId () == null ) {
144
+ if (routing .relocatingNodeId () == null || reservedSpace . containsShardId ( routing . shardId ()) ) {
146
145
// in practice the only initializing-but-not-relocating shards with a nonzero expected shard size will be ones created
147
146
// by a resize (shrink/split/clone) operation which we expect to happen using hard links, so they shouldn't be taking
148
147
// any additional space and can be ignored here
@@ -230,7 +229,14 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
230
229
231
230
// subtractLeavingShards is passed as false here, because they still use disk space, and therefore we should be extra careful
232
231
// and take the size into account
233
- final DiskUsageWithRelocations usage = getDiskUsage (node , allocation , usages , false );
232
+ final DiskUsageWithRelocations usage = getDiskUsage (
233
+ node ,
234
+ allocation ,
235
+ usages ,
236
+ clusterInfo .getAvgFreeByte (),
237
+ clusterInfo .getAvgTotalBytes (),
238
+ false
239
+ );
234
240
// First, check that the node currently over the low watermark
235
241
double freeDiskPercentage = usage .getFreeDiskAsPercentage ();
236
242
// Cache the used disk percentage for displaying disk percentages consistent with documentation
@@ -492,7 +498,14 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
492
498
493
499
// subtractLeavingShards is passed as true here, since this is only for shards remaining, we will *eventually* have enough disk
494
500
// since shards are moving away. No new shards will be incoming since in canAllocate we pass false for this check.
495
- final DiskUsageWithRelocations usage = getDiskUsage (node , allocation , usages , true );
501
+ final DiskUsageWithRelocations usage = getDiskUsage (
502
+ node ,
503
+ allocation ,
504
+ usages ,
505
+ clusterInfo .getAvgFreeByte (),
506
+ clusterInfo .getAvgTotalBytes (),
507
+ true
508
+ );
496
509
final String dataPath = clusterInfo .getDataPath (shardRouting );
497
510
// If this node is already above the high threshold, the shard cannot remain (get it off!)
498
511
final double freeDiskPercentage = usage .getFreeDiskAsPercentage ();
@@ -581,13 +594,15 @@ private DiskUsageWithRelocations getDiskUsage(
581
594
RoutingNode node ,
582
595
RoutingAllocation allocation ,
583
596
final Map <String , DiskUsage > usages ,
597
+ final long avgFreeBytes ,
598
+ final long avgTotalBytes ,
584
599
boolean subtractLeavingShards
585
600
) {
586
601
DiskUsage usage = usages .get (node .nodeId ());
587
602
if (usage == null ) {
588
603
// If there is no usage, and we have other nodes in the cluster,
589
604
// use the average usage for all nodes as the usage for this node
590
- usage = averageUsage (node , usages );
605
+ usage = new DiskUsage (node . nodeId (), node . node (). getName (), "_na_" , avgTotalBytes , avgFreeBytes );
591
606
if (logger .isDebugEnabled ()) {
592
607
logger .debug (
593
608
"unable to determine disk usage for {}, defaulting to average across nodes [{} total] [{} free] [{}% free]" ,
@@ -619,26 +634,6 @@ private DiskUsageWithRelocations getDiskUsage(
619
634
return diskUsageWithRelocations ;
620
635
}
621
636
622
- /**
623
- * Returns a {@link DiskUsage} for the {@link RoutingNode} using the
624
- * average usage of other nodes in the disk usage map.
625
- * @param node Node to return an averaged DiskUsage object for
626
- * @param usages Map of nodeId to DiskUsage for all known nodes
627
- * @return DiskUsage representing given node using the average disk usage
628
- */
629
- DiskUsage averageUsage (RoutingNode node , final Map <String , DiskUsage > usages ) {
630
- if (usages .size () == 0 ) {
631
- return new DiskUsage (node .nodeId (), node .node ().getName (), "_na_" , 0 , 0 );
632
- }
633
- long totalBytes = 0 ;
634
- long freeBytes = 0 ;
635
- for (DiskUsage du : usages .values ()) {
636
- totalBytes += du .getTotalBytes ();
637
- freeBytes += du .getFreeBytes ();
638
- }
639
- return new DiskUsage (node .nodeId (), node .node ().getName (), "_na_" , totalBytes / usages .size (), freeBytes / usages .size ());
640
- }
641
-
642
637
/**
643
638
* Given the DiskUsage for a node and the size of the shard, return the
644
639
* percentage of free disk if the shard were to be allocated to the node.
0 commit comments