smengcl commented on code in PR #4015:
URL: https://github.com/apache/ozone/pull/4015#discussion_r1041500197


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/bucket/OMBucketDeleteRequest.java:
##########
@@ -198,6 +215,35 @@ public OMClientResponse 
validateAndUpdateCache(OzoneManager ozoneManager,
     }
   }
 
+  private boolean bucketContainSnapshot(OMMetadataManager omMetadataManager,
+      String snapshotBucketKey) throws IOException {
+    // check both in cache and table
+    Iterator<Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>>> cacheIter =
+        omMetadataManager.getSnapshotInfoTable().cacheIterator();
+    while (cacheIter.hasNext()) {
+      Map.Entry<CacheKey<String>, CacheValue<SnapshotInfo>> cacheKeyValue =
+          cacheIter.next();
+      String key = cacheKeyValue.getKey().getCacheKey();
+      if (key.startsWith(snapshotBucketKey)) {
+        return true;
+      }
+    }
+    try (TableIterator<String, ? extends Table.KeyValue<String, SnapshotInfo>>
+        snapshotIterator = omMetadataManager
+            .getSnapshotInfoTable().iterator()) {
+      snapshotIterator.seek(snapshotBucketKey);
+      if (snapshotIterator.hasNext()) {
+        Table.KeyValue<String, SnapshotInfo> dbKeyValue =
+            snapshotIterator.next();
+        String dbKey = dbKeyValue.getKey();
+        if (dbKey.startsWith(snapshotBucketKey)) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }

Review Comment:
   This should do it atm. Though I wonder if we should have a more efficient 
way of checking whether a bucket has snapshots (and how many snapshots the 
bucket has -- which can be utilized by Recon) later.



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