@@ -141,11 +141,12 @@ public static long sizeOfRelocatingShards(RoutingNode node, boolean subtractShar
141141        return  totalSize ;
142142    }
143143
144+     private  static  final  Decision  YES_UNALLOCATED_PRIMARY_BETWEEN_WATERMARKS  = Decision .single (Decision .Type .YES , NAME , "the node "  +
145+             "is above the low watermark, but less than the high watermark, and this primary shard has never been allocated before" );
144146
145147    @ Override 
146148    public  Decision  canAllocate (ShardRouting  shardRouting , RoutingNode  node , RoutingAllocation  allocation ) {
147-         ClusterInfo  clusterInfo  = allocation .clusterInfo ();
148-         ImmutableOpenMap <String , DiskUsage > usages  = clusterInfo .getNodeMostAvailableDiskUsages ();
149+         ImmutableOpenMap <String , DiskUsage > usages  = allocation .clusterInfo ().getNodeMostAvailableDiskUsages ();
149150        final  Decision  decision  = earlyTerminate (allocation , usages );
150151        if  (decision  != null ) {
151152            return  decision ;
@@ -206,9 +207,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
206207                                    "but allowing allocation because primary has never been allocated" ,
207208                            diskThresholdSettings .getFreeBytesThresholdLow (), freeBytesValue , node .nodeId ());
208209                }
209-                 return  allocation .decision (Decision .YES , NAME ,
210-                         "the node is above the low watermark, but less than the high watermark, and this primary shard has "  +
211-                         "never been allocated before" );
210+                 return  YES_UNALLOCATED_PRIMARY_BETWEEN_WATERMARKS ;
212211            } else  {
213212                // Even though the primary has never been allocated, the node is 
214213                // above the high watermark, so don't allow allocating the shard 
@@ -249,9 +248,7 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
249248                            Strings .format1Decimals (usedDiskThresholdLow , "%" ),
250249                            Strings .format1Decimals (usedDiskPercentage , "%" ), node .nodeId ());
251250                }
252-                 return  allocation .decision (Decision .YES , NAME ,
253-                     "the node is above the low watermark, but less than the high watermark, and this primary shard has "  +
254-                     "never been allocated before" );
251+                 return  YES_UNALLOCATED_PRIMARY_BETWEEN_WATERMARKS ;
255252            } else  {
256253                // Even though the primary has never been allocated, the node is 
257254                // above the high watermark, so don't allow allocating the shard 
@@ -307,6 +304,9 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingNode node, Routing
307304                new  ByteSizeValue (freeBytesAfterShard ));
308305    }
309306
307+     private  static  final  Decision  YES_NOT_MOST_UTILIZED_DISK  = Decision .single (Decision .Type .YES , NAME ,
308+             "this shard is not allocated on the most utilized disk and can remain" );
309+ 
310310    @ Override 
311311    public  Decision  canRemain (ShardRouting  shardRouting , RoutingNode  node , RoutingAllocation  allocation ) {
312312        if  (shardRouting .currentNodeId ().equals (node .nodeId ()) == false ) {
@@ -330,8 +330,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
330330            logger .trace ("node [{}] has {}% free disk ({} bytes)" , node .nodeId (), freeDiskPercentage , freeBytes );
331331        }
332332        if  (dataPath  == null  || usage .getPath ().equals (dataPath ) == false ) {
333-             return  allocation .decision (Decision .YES , NAME ,
334-                     "this shard is not allocated on the most utilized disk and can remain" );
333+             return  YES_NOT_MOST_UTILIZED_DISK ;
335334        }
336335        if  (freeBytes  < 0L ) {
337336            final  long  sizeOfRelocatingShards  = sizeOfRelocatingShards (node , true , usage .getPath (),
@@ -425,35 +424,29 @@ DiskUsage averageUsage(RoutingNode node, ImmutableOpenMap<String, DiskUsage> usa
425424        return  newUsage .getFreeDiskAsPercentage ();
426425    }
427426
427+     private  static  final  Decision  YES_DISABLED  = Decision .single (Decision .Type .YES , NAME , "the disk threshold decider is disabled" );
428+ 
429+     private  static  final  Decision  YES_SINGLE_DATA_NODE  =
430+             Decision .single (Decision .Type .YES , NAME , "there is only a single data node present" );
431+ 
432+     private  static  final  Decision  YES_USAGES_UNAVAILABLE  = Decision .single (Decision .Type .YES , NAME , "disk usages are unavailable" );
433+ 
428434    private  Decision  earlyTerminate (RoutingAllocation  allocation , ImmutableOpenMap <String , DiskUsage > usages ) {
429435        // Always allow allocation if the decider is disabled 
430436        if  (diskThresholdSettings .isEnabled () == false ) {
431-             return  allocation . decision ( Decision . YES ,  NAME ,  "the disk threshold decider is disabled" ) ;
437+             return  YES_DISABLED ;
432438        }
433439
434440        // Allow allocation regardless if only a single data node is available 
435441        if  (enableForSingleDataNode  == false  && allocation .nodes ().getDataNodes ().size () <= 1 ) {
436-             if  (logger .isTraceEnabled ()) {
437-                 logger .trace ("only a single data node is present, allowing allocation" );
438-             }
439-             return  allocation .decision (Decision .YES , NAME , "there is only a single data node present" );
440-         }
441- 
442-         // Fail open there is no info available 
443-         final  ClusterInfo  clusterInfo  = allocation .clusterInfo ();
444-         if  (clusterInfo  == null ) {
445-             if  (logger .isTraceEnabled ()) {
446-                 logger .trace ("cluster info unavailable for disk threshold decider, allowing allocation." );
447-             }
448-             return  allocation .decision (Decision .YES , NAME , "the cluster info is unavailable" );
442+             logger .trace ("only a single data node is present, allowing allocation" );
443+             return  YES_SINGLE_DATA_NODE ;
449444        }
450445
451446        // Fail open if there are no disk usages available 
452447        if  (usages .isEmpty ()) {
453-             if  (logger .isTraceEnabled ()) {
454-                 logger .trace ("unable to determine disk usages for disk-aware allocation, allowing allocation" );
455-             }
456-             return  allocation .decision (Decision .YES , NAME , "disk usages are unavailable" );
448+             logger .trace ("unable to determine disk usages for disk-aware allocation, allowing allocation" );
449+             return  YES_USAGES_UNAVAILABLE ;
457450        }
458451        return  null ;
459452    }
0 commit comments