This is an automated email from the ASF dual-hosted git repository.
chungen0126 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 fef9cde752a HDDS-16686. Leave still-referenced snapshot cache keys
queued during cleanup (#11848)
fef9cde752a is described below
commit fef9cde752aa99cc3c665d05d87b87d47ccbe5f5
Author: Mark Tsai <[email protected]>
AuthorDate: Fri Oct 30 11:38:24 2026 +0800
HDDS-16686. Leave still-referenced snapshot cache keys queued during
cleanup (#11848)
---
.../hadoop/ozone/om/snapshot/SnapshotCache.java | 6 ++++-
.../ozone/om/snapshot/TestSnapshotCache.java | 31 ++++++++++++++++++++++
2 files changed, 36 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 1c7e63159f4..59b4d7b955e 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
@@ -405,9 +405,13 @@ private synchronized Void cleanup(UUID evictionKey,
boolean expectKeyToBePresent
if (v == null) {
LOG.info("SnapshotId '{}' does not exist in cache during cleanup; "
+ "it may have already been invalidated, closed, and removed.", k);
+ pendingEvictionQueue.remove(k);
} else if (v.getTotalRefCount() > 0) {
LOG.debug("SnapshotId {} is still being referenced ({}), skipping its
clean up.", k, v.getTotalRefCount());
result = v;
+ // Deliberately leave the key queued. A concurrent release can drop
the last reference and re-enqueue
+ // the key after the count above was read, and dequeuing it here would
strand an unreferenced entry in
+ // dbMap that is no longer queued, so nothing would ever evict it.
} else {
LOG.debug("Closing SnapshotId {}. It is not being referenced
anymore.", k);
// Close the instance, which also closes its DB handle.
@@ -417,8 +421,8 @@ private synchronized Void cleanup(UUID evictionKey, boolean
expectKeyToBePresent
throw new IllegalStateException("Error while closing snapshot DB for
snapshotId " + k, ex);
}
omMetrics.decNumSnapshotCacheSize();
+ pendingEvictionQueue.remove(k);
}
- pendingEvictionQueue.remove(k);
return result;
});
return null;
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 ff729df43bc..bc874d740a2 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
@@ -649,6 +649,37 @@ void testCloseFailureRetriesSnapshot() throws Exception {
assertEquals(0, omMetrics.getNumSnapshotCacheSize());
}
+ @Test
+ @DisplayName("cleanup() leaves a still-referenced key queued so a concurrent
release is not erased")
+ void testCleanupKeepsQueuedKeyWhenStillReferenced() throws IOException {
+ snapshotCache = new SnapshotCache(cacheLoader, CACHE_SIZE_LIMIT,
omMetrics, 0, true, newAcquiringLock());
+ final UUID snapshotId = UUID.randomUUID();
+
+ // Drop the last reference so the key is enqueued for eviction, then take
a fresh reference. This is the
+ // state a release racing the eviction pass leaves behind: queued, but
referenced again. Reproducing the
+ // race itself needs the release to land inside cleanup()'s dbMap.compute
window, which no production hook
+ // exposes; this pins the dequeue decision that makes the race harmful.
+ snapshotCache.get(snapshotId).close();
+ assertTrue(snapshotCache.getPendingEvictionQueue().contains(snapshotId));
+
+ final UncheckedAutoCloseableSupplier<OmSnapshot> handle =
snapshotCache.get(snapshotId);
+ assertTrue(snapshotCache.getPendingEvictionQueue().contains(snapshotId));
+
+ // The cleanup pass sees a non-zero refcount and must leave the key
queued. Dequeuing it here is what
+ // strands an unreferenced entry in dbMap with nothing left to evict it,
after which lock() never drains.
+ assertThrows(IllegalStateException.class, () -> snapshotCache.lock());
+ assertTrue(snapshotCache.getPendingEvictionQueue().contains(snapshotId));
+ assertTrue(snapshotCache.getDbMap().containsKey(snapshotId));
+
+ // Once the last reference goes away, the next pass evicts it.
+ handle.close();
+ try (UncheckedAutoCloseableSupplier<OMLockDetails> lockDetails =
snapshotCache.lock()) {
+ assertTrue(lockDetails.get().isLockAcquired());
+ }
+ assertFalse(snapshotCache.getDbMap().containsKey(snapshotId));
+ assertFalse(snapshotCache.getPendingEvictionQueue().contains(snapshotId));
+ }
+
@Test
@DisplayName("get() surfaces a retriable load TIMEOUT as OMException, not
IllegalStateException")
void testGetPropagatesLoadTimeout() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]