adoroszlai commented on code in PR #9518:
URL: https://github.com/apache/ozone/pull/9518#discussion_r2634323913


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1383,9 +1382,18 @@ private void nodeOutOfSpaceStatistics(Map<String, 
String> nodeStatics) {
         ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT,
         StorageUnit.BYTES);
 
-    int nodeOutOfSpaceCount = (int) allNodes.parallelStream()
-        .filter(dn -> !hasEnoughSpace(dn, minRatisVolumeSizeBytes, 
containerSize, conf)
-            && !hasEnoughCommittedVolumeSpace(dn, blockSize))
+    int nodeOutOfSpaceCount = (int) getAllNodes().parallelStream()
+        .filter(dn -> {
+          try {
+            if (!dn.getNodeStatus().isNodeWritable()) {
+              return true;
+            }
+            return !hasEnoughSpace(dn, minRatisVolumeSizeBytes, containerSize, 
conf)
+                && !hasEnoughCommittedVolumeSpace(dn, blockSize);
+          } catch (Exception e) {
+            throw new RuntimeException(e);
+          }
+        })

Review Comment:
   - `try-catch` is unnecessary
   - How about extracting an inner class for the `Predicate`?
   
   ```java
     private void nodeOutOfSpaceStatistics(Map<String, String> nodeStatics) {
       int nodeOutOfSpaceCount = (int) getAllNodes().parallelStream()
           .filter(new ReadonlyNodeFilter(conf))
           .count();
   
       ...
     }
   
     ...
   
     static class ReadonlyNodeFilter implements Predicate<DatanodeInfo> {
   
       private final long blockSize;
       private final long minRatisVolumeSizeBytes;
       private final long containerSize;
       private final ConfigurationSource conf;
   
       ReadonlyNodeFilter(ConfigurationSource conf) {
         blockSize = (long) conf.getStorageSize(
             OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE,
             OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE_DEFAULT,
             StorageUnit.BYTES);
         minRatisVolumeSizeBytes = (long) conf.getStorageSize(
             ScmConfigKeys.OZONE_DATANODE_RATIS_VOLUME_FREE_SPACE_MIN,
             ScmConfigKeys.OZONE_DATANODE_RATIS_VOLUME_FREE_SPACE_MIN_DEFAULT,
             StorageUnit.BYTES);
         containerSize = (long) conf.getStorageSize(
             ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
             ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT,
             StorageUnit.BYTES);
         this.conf = conf;
       }
   
       @Override
       public boolean test(DatanodeInfo dn) {
         if (!dn.getNodeStatus().isNodeWritable()) {
           return true;
         }
         return !hasEnoughSpace(dn, minRatisVolumeSizeBytes, containerSize, 
conf)
             && !hasEnoughCommittedVolumeSpace(dn, blockSize);
       }
     }
   ```
   
   (Note: needs imports and `hasEnoughCommittedVolumeSpace` needs to be 
`static` (or moved into the new class).)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to