sadanand48 commented on code in PR #3973:
URL: https://github.com/apache/ozone/pull/3973#discussion_r1027700809


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMDirectoriesPurgeRequestWithFSO.java:
##########
@@ -48,12 +59,72 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager,
     List<OzoneManagerProtocolProtos.PurgePathRequest> purgeRequests =
             purgeDirsRequest.getDeletedPathList();
 
+    Set<Pair<String, String>> lockSet = new HashSet<>();
+    Map<Pair<String, String>, OmBucketInfo> volBucketInfoMap = new HashMap<>();
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    try {
+      for (OzoneManagerProtocolProtos.PurgePathRequest path : purgeRequests) {
+        for (OzoneManagerProtocolProtos.KeyInfo key :
+            path.getMarkDeletedSubDirsList()) {
+          OmKeyInfo keyInfo = OmKeyInfo.getFromProtobuf(key);
+          String volumeName = keyInfo.getVolumeName();
+          String bucketName = keyInfo.getBucketName();
+          Pair<String, String> volBucketPair = Pair.of(volumeName, bucketName);
+          if (!lockSet.contains(volBucketPair)) {
+            omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+                volumeName, bucketName);
+            lockSet.add(volBucketPair);
+          }
+          OmBucketInfo omBucketInfo = getBucketInfo(omMetadataManager,
+              volumeName, bucketName);
+          // bucketInfo can be null in case of delete volume or bucket
+          if (null != omBucketInfo) {
+            omBucketInfo.incrUsedNamespace(-1L);
+            volBucketInfoMap.putIfAbsent(volBucketPair, omBucketInfo);
+          }
+        }
+
+        for (OzoneManagerProtocolProtos.KeyInfo key :
+            path.getDeletedSubFilesList()) {
+          OmKeyInfo keyInfo = OmKeyInfo.getFromProtobuf(key);
+          String volumeName = keyInfo.getVolumeName();
+          String bucketName = keyInfo.getBucketName();
+          Pair<String, String> volBucketPair = Pair.of(volumeName, bucketName);
+          if (!lockSet.contains(volBucketPair)) {
+            omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+                volumeName, bucketName);
+            lockSet.add(volBucketPair);
+          }
+          OmBucketInfo omBucketInfo = getBucketInfo(omMetadataManager,
+              volumeName, bucketName);
+          // bucketInfo can be null in case of delete volume or bucket
+          if (null != omBucketInfo) {
+            omBucketInfo.incrUsedBytes(-sumBlockLengths(keyInfo));
+            omBucketInfo.incrUsedNamespace(-1L);
+            volBucketInfoMap.putIfAbsent(volBucketPair, omBucketInfo);
+          }
+        }
+      }
+    } catch (IOException ex) {
+      // Case of IOException for fromProtobuf will not hanppen
+      // as this is created and send within OM
+      // only case of upgrade where compatibility is broken can have
+      throw new IllegalStateException(ex);
+    } finally {
+      lockSet.stream().forEach(e -> omMetadataManager.getLock()
+          .releaseWriteLock(BUCKET_LOCK, e.getKey(),

Review Comment:
   We are acquiring multiple bucket locks and releasing only when all keys are 
processed. If the number of keys is large, this can block many reads for a long 
time . Is there a size limit for number of keys  in 
`purgeDirsRequest.getDeletedPathList()`. I think we should have a size limit.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMDirectoriesPurgeRequestWithFSO.java:
##########
@@ -48,12 +59,72 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager,
     List<OzoneManagerProtocolProtos.PurgePathRequest> purgeRequests =
             purgeDirsRequest.getDeletedPathList();
 
+    Set<Pair<String, String>> lockSet = new HashSet<>();
+    Map<Pair<String, String>, OmBucketInfo> volBucketInfoMap = new HashMap<>();

Review Comment:
   Can we live without `Pair<String,String>` in `Map<Pair<String, String>, 
OmBucketInfo> volBucketInfoMap`. `OmBucketInfo `already has the `volumeName` 
and `bucketName `as  a field. Instead we can only have a list of OmBucketInfo.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMDirectoriesPurgeRequestWithFSO.java:
##########
@@ -48,12 +59,72 @@ public OMClientResponse validateAndUpdateCache(OzoneManager 
ozoneManager,
     List<OzoneManagerProtocolProtos.PurgePathRequest> purgeRequests =
             purgeDirsRequest.getDeletedPathList();
 
+    Set<Pair<String, String>> lockSet = new HashSet<>();
+    Map<Pair<String, String>, OmBucketInfo> volBucketInfoMap = new HashMap<>();
+    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
+    try {
+      for (OzoneManagerProtocolProtos.PurgePathRequest path : purgeRequests) {
+        for (OzoneManagerProtocolProtos.KeyInfo key :
+            path.getMarkDeletedSubDirsList()) {
+          OmKeyInfo keyInfo = OmKeyInfo.getFromProtobuf(key);
+          String volumeName = keyInfo.getVolumeName();
+          String bucketName = keyInfo.getBucketName();
+          Pair<String, String> volBucketPair = Pair.of(volumeName, bucketName);
+          if (!lockSet.contains(volBucketPair)) {
+            omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+                volumeName, bucketName);
+            lockSet.add(volBucketPair);
+          }
+          OmBucketInfo omBucketInfo = getBucketInfo(omMetadataManager,
+              volumeName, bucketName);
+          // bucketInfo can be null in case of delete volume or bucket
+          if (null != omBucketInfo) {
+            omBucketInfo.incrUsedNamespace(-1L);
+            volBucketInfoMap.putIfAbsent(volBucketPair, omBucketInfo);
+          }
+        }
+
+        for (OzoneManagerProtocolProtos.KeyInfo key :
+            path.getDeletedSubFilesList()) {
+          OmKeyInfo keyInfo = OmKeyInfo.getFromProtobuf(key);
+          String volumeName = keyInfo.getVolumeName();
+          String bucketName = keyInfo.getBucketName();
+          Pair<String, String> volBucketPair = Pair.of(volumeName, bucketName);
+          if (!lockSet.contains(volBucketPair)) {
+            omMetadataManager.getLock().acquireWriteLock(BUCKET_LOCK,
+                volumeName, bucketName);
+            lockSet.add(volBucketPair);
+          }
+          OmBucketInfo omBucketInfo = getBucketInfo(omMetadataManager,
+              volumeName, bucketName);
+          // bucketInfo can be null in case of delete volume or bucket
+          if (null != omBucketInfo) {
+            omBucketInfo.incrUsedBytes(-sumBlockLengths(keyInfo));
+            omBucketInfo.incrUsedNamespace(-1L);
+            volBucketInfoMap.putIfAbsent(volBucketPair, omBucketInfo);
+          }
+        }
+      }
+    } catch (IOException ex) {
+      // Case of IOException for fromProtobuf will not hanppen
+      // as this is created and send within OM
+      // only case of upgrade where compatibility is broken can have
+      throw new IllegalStateException(ex);
+    } finally {
+      lockSet.stream().forEach(e -> omMetadataManager.getLock()
+          .releaseWriteLock(BUCKET_LOCK, e.getKey(),
+              e.getValue()));
+      for (Map.Entry<Pair<String, String>, OmBucketInfo> entry :
+          volBucketInfoMap.entrySet()) {
+        entry.setValue(entry.getValue().copyObject());

Review Comment:
   Not sure I understood this correctly, Why are  we copying object here?



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