Copilot commented on code in PR #8474:
URL: https://github.com/apache/ozone/pull/8474#discussion_r2114176091


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java:
##########
@@ -370,7 +371,8 @@ public void init() throws RocksDBException, IOException, 
ExecutionException {
 
     omSnapshotManager = mock(OmSnapshotManager.class);
     when(ozoneManager.getOmSnapshotManager()).thenReturn(omSnapshotManager);
-    SnapshotCache snapshotCache = new SnapshotCache(mockCacheLoader(), 10, 
omMetrics, 0);
+    SnapshotCache snapshotCache = new SnapshotCache(mockCacheLoader(), 10, 
omMetrics, 0,
+        new OmReadOnlyLock());

Review Comment:
   Using `OmReadOnlyLock` in this test will cause all `get()` calls to fail 
(lock always not acquired). Consider injecting a lock stub or the real 
`OzoneManagerLock` that grants read locks so the test can exercise cache 
behavior.
   ```suggestion
       OzoneManagerLock mockLock = mock(OzoneManagerLock.class);
       when(mockLock.acquireReadLock(anyString())).thenReturn(true);
       SnapshotCache snapshotCache = new SnapshotCache(mockCacheLoader(), 10, 
omMetrics, 0,
           mockLock);
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java:
##########
@@ -215,14 +229,53 @@ public void release(UUID key) {
     val.decrementRefCount();
   }
 
+  /**
+   * Acquires a write lock on the 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 when closed, preventing potential resource contention or deadlocks.
+   */
+  public UncheckedAutoCloseableSupplier<OMLockDetails> lock() {

Review Comment:
   [nitpick] The method name `lock()` is very generic and may be confused with 
the `lock` field. Consider renaming it to `acquireSnapshotDbWriteLock()` or 
similar for clarity.



-- 
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: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to