Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ 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));
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")
Expand Down