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


##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -49,10 +49,12 @@
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import javax.management.ObjectName;
+import org.apache.hadoop.conf.StorageUnit;

Review Comment:
   Only if the patch is updated for any other reason: please use 
`org.apache.hadoop.hdds.conf.StorageUnit`.



##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/SCMNodeManager.java:
##########
@@ -1360,6 +1369,57 @@ private void nodeSpaceStatistics(Map<String, String> 
nodeStatics) {
     nodeStatics.put(SpaceStatistics.NON_SCM_USED.getLabel(), nonScmUsed);
   }
 
+  private void nodeReadOnlyStatistics(Map<String, String> nodeStatics) {
+    List<DatanodeInfo> allNodes = getAllNodes();
+    long blockSize = (long) conf.getStorageSize(
+        OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE,
+        OzoneConfigKeys.OZONE_SCM_BLOCK_SIZE_DEFAULT,
+        StorageUnit.BYTES);
+    long minRatisVolumeSizeBytes = (long) conf.getStorageSize(
+        ScmConfigKeys.OZONE_DATANODE_RATIS_VOLUME_FREE_SPACE_MIN,
+        ScmConfigKeys.OZONE_DATANODE_RATIS_VOLUME_FREE_SPACE_MIN_DEFAULT,
+        StorageUnit.BYTES);
+    long containerSize = (long) conf.getStorageSize(
+        ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE,
+        ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT,
+        StorageUnit.BYTES);
+
+    int readOnlyCount = (int) allNodes.parallelStream()
+        .filter(dnInfo -> {
+          boolean hasWritableContainer = hasContainerWithSpace(dnInfo, 
blockSize, containerSize);
+          if (hasWritableContainer) {
+            return false;
+          }
+
+          boolean canAllocateNewContainers = 
SCMCommonPlacementPolicy.hasEnoughSpace(
+              dnInfo, minRatisVolumeSizeBytes, containerSize, conf);
+          return !canAllocateNewContainers;
+        })

Review Comment:
   Would it make sense to check `hasEnoughSpace` first?  
`hasContainerWithSpace` seems to be the more expensive operation.
   
   Also, I think this would be more easier to understand as:
   
   ```java
     .filter(dn -> !hasEnoughSpace(dn, minRatisVolumeSizeBytes, containerSize, 
conf)
         && !hasContainerWithSpace(dn, blockSize, containerSize))
   ```



-- 
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