This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new a27d1bb91bc HDDS-16694. Count only loaded snapshots in 
NumSnapshotCacheSize (#11400)
a27d1bb91bc is described below

commit a27d1bb91bc200c88a01ed2d4940ca5df8223474
Author: rjgoyln <[email protected]>
AuthorDate: Fri Oct 9 22:15:14 2026 +0800

    HDDS-16694. Count only loaded snapshots in NumSnapshotCacheSize (#11400)
---
 .../org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java |  2 +-
 .../apache/hadoop/ozone/om/snapshot/TestSnapshotCache.java | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java
index 790150e218a..40a92b1ae0e 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotCache.java
@@ -227,6 +227,7 @@ public UncheckedAutoCloseableSupplier<OmSnapshot> get(UUID 
key) throws IOExcepti
           LOG.info("Loading SnapshotId: '{}'", k);
           try {
             v = new ReferenceCounted<>(cacheLoader.load(key), false, this);
+            omMetrics.incNumSnapshotCacheSize();
           } catch (OMException omEx) {
             // Return null if the snapshot is no longer active
             if 
(!omEx.getResult().equals(OMException.ResultCodes.FILE_NOT_FOUND)) {
@@ -239,7 +240,6 @@ public UncheckedAutoCloseableSupplier<OmSnapshot> get(UUID 
key) throws IOExcepti
             // Unexpected and unknown exception thrown from CacheLoader#load
             throw new IllegalStateException(ex);
           }
-          omMetrics.incNumSnapshotCacheSize();
         }
         if (v != null) {
           // When RC OmSnapshot is successfully loaded
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotCache.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotCache.java
index 2c789729c06..756b60f2f39 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotCache.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotCache.java
@@ -170,6 +170,20 @@ public void testGetReleasesReadLockOnLoadFailure() throws 
Exception {
     verify(lock, times(1)).releaseReadLock(eq(SNAPSHOT_DB_LOCK), 
eq(dbKey.toString()));
   }
 
+  @Test
+  @DisplayName("get() of an inactive snapshot does not count towards cache 
size")
+  void testGetInactiveSnapshotDoesNotIncrementCacheSize() throws Exception {
+    final UUID dbKey = UUID.randomUUID();
+    when(cacheLoader.load(eq(dbKey)))
+        .thenThrow(new OMException("Snapshot is no longer active", 
OMException.ResultCodes.FILE_NOT_FOUND));
+    for (int i = 0; i < 3; i++) {
+      OMException ex = assertThrows(OMException.class, () -> 
snapshotCache.get(dbKey));
+      assertEquals(OMException.ResultCodes.FILE_NOT_FOUND, ex.getResult());
+      assertEquals(0, snapshotCache.size());
+      assertEquals(0, omMetrics.getNumSnapshotCacheSize());
+    }
+  }
+
   @ParameterizedTest
   @ValueSource(ints = {0, 1, 5, 10})
   @DisplayName("Tests get() holds a read lock")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to