swamirishi commented on code in PR #9210:
URL: https://github.com/apache/ozone/pull/9210#discussion_r2472646126


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java:
##########
@@ -288,14 +288,26 @@ public void release(UUID key) {
    */
   public UncheckedAutoCloseableSupplier<OMLockDetails> lock() {
     return lock(() -> lock.acquireResourceWriteLock(SNAPSHOT_DB_LOCK),
-        () -> lock.releaseResourceWriteLock(SNAPSHOT_DB_LOCK));
+        () -> lock.releaseResourceWriteLock(SNAPSHOT_DB_LOCK), () -> 
cleanup(true));
   }
 
-  private UncheckedAutoCloseableSupplier<OMLockDetails> lock(
-      Supplier<OMLockDetails> lockFunction, Supplier<OMLockDetails> 
unlockFunction) {
+  /**
+   * Acquires a write lock on a specific snapshot database and returns an 
auto-closeable supplier for lock details.
+   * The lock ensures that the operations accessing the snapshot database are 
performed in a thread safe manner. The
+   * returned supplier automatically releases the lock acquired when closed, 
preventing potential resource
+   * contention or deadlocks.
+   */
+  public UncheckedAutoCloseableSupplier<OMLockDetails> lock(UUID snapshotId) {
+    return lock(() -> lock.acquireWriteLock(SNAPSHOT_DB_LOCK, 
snapshotId.toString()),
+        () -> lock.releaseWriteLock(SNAPSHOT_DB_LOCK, snapshotId.toString()),
+        () -> cleanup(snapshotId));
+  }
+
+  private UncheckedAutoCloseableSupplier<OMLockDetails> 
lock(Supplier<OMLockDetails> lockFunction,
+      Supplier<OMLockDetails> unlockFunction, Supplier<Void> cleanupFunction) {
     AtomicReference<OMLockDetails> lockDetails = new 
AtomicReference<>(lockFunction.get());
     if (lockDetails.get().isLockAcquired()) {
-      cleanup(true);
+      cleanupFunction.get();

Review Comment:
   We don't want a rocksdb open in the cache once a write lock has been acquired



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