This is an automated email from the ASF dual-hosted git repository.
hemant 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 c35e99f04b HDDS-10250. Use SnapshotId as key in SnapshotCache (#6139)
c35e99f04b is described below
commit c35e99f04b9662061a8aac0429033959abf83707
Author: Hemant Kumar <[email protected]>
AuthorDate: Sat Feb 10 14:14:18 2024 -0800
HDDS-10250. Use SnapshotId as key in SnapshotCache (#6139)
---
.../apache/hadoop/ozone/om/OmSnapshotManager.java | 42 +++++++-----
.../request/snapshot/OMSnapshotPurgeRequest.java | 2 +-
.../hadoop/ozone/om/snapshot/SnapshotCache.java | 67 ++++++++-----------
.../hadoop/ozone/om/TestOmSnapshotManager.java | 7 ++
.../ozone/om/snapshot/TestSnapshotCache.java | 76 +++++++++-------------
.../ozone/om/snapshot/TestSnapshotDiffManager.java | 33 ++++++----
6 files changed, 113 insertions(+), 114 deletions(-)
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
index e22d6b3097..eb37e399df 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotManager.java
@@ -35,6 +35,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import java.util.UUID;
import com.google.common.cache.RemovalListener;
import org.apache.hadoop.hdds.StringUtils;
@@ -244,7 +245,7 @@ public final class OmSnapshotManager implements
AutoCloseable {
OZONE_OM_SNAPSHOT_CACHE_MAX_SIZE,
OZONE_OM_SNAPSHOT_CACHE_MAX_SIZE_DEFAULT);
- CacheLoader<String, OmSnapshot> loader = createCacheLoader();
+ CacheLoader<UUID, OmSnapshot> loader = createCacheLoader();
// TODO: [SNAPSHOT] Remove this if not going to make SnapshotCache impl
// pluggable.
@@ -325,19 +326,25 @@ public final class OmSnapshotManager implements
AutoCloseable {
return isSnapshotInfoTableEmpty;
}
- private CacheLoader<String, OmSnapshot> createCacheLoader() {
- return new CacheLoader<String, OmSnapshot>() {
+ private CacheLoader<UUID, OmSnapshot> createCacheLoader() {
+ return new CacheLoader<UUID, OmSnapshot>() {
@Nonnull
@Override
- public OmSnapshot load(@Nonnull String snapshotTableKey)
- throws IOException {
- // Check if the snapshot exists
- final SnapshotInfo snapshotInfo = getSnapshotInfo(snapshotTableKey);
+ public OmSnapshot load(@Nonnull UUID snapshotId) throws IOException {
+ String snapshotTableKey = ((OmMetadataManagerImpl)
ozoneManager.getMetadataManager())
+ .getSnapshotChainManager()
+ .getTableKey(snapshotId);
+
+ // SnapshotChain maintains in-memory reverse mapping of snapshotId to
snapshotName based on snapshotInfoTable.
+ // So it should not happen ideally.
+ // If it happens, then either snapshot has been purged in between or
SnapshotChain is corrupted
+ // and missing some entries which needs investigation.
+ if (snapshotTableKey == null) {
+ throw new IOException("No snapshot exist with snapshotId: " +
snapshotId);
+ }
- // Block snapshot from loading when it is no longer active e.g.
DELETED,
- // unless this is called from SnapshotDeletingService.
- checkSnapshotActive(snapshotInfo, true);
+ final SnapshotInfo snapshotInfo = getSnapshotInfo(snapshotTableKey);
CacheValue<SnapshotInfo> cacheValue = ozoneManager.getMetadataManager()
.getSnapshotInfoTable()
@@ -417,9 +424,9 @@ public final class OmSnapshotManager implements
AutoCloseable {
/**
* Immediately invalidate an entry.
*
- * @param key DB snapshot table key
+ * @param key SnapshotId.
*/
- public void invalidateCacheEntry(String key) throws IOException {
+ public void invalidateCacheEntry(UUID key) throws IOException {
if (snapshotCache != null) {
snapshotCache.invalidate(key);
}
@@ -663,17 +670,16 @@ public final class OmSnapshotManager implements
AutoCloseable {
return getSnapshot(snapshotTableKey, skipActiveCheck);
}
- private ReferenceCounted<OmSnapshot> getSnapshot(
- String snapshotTableKey,
- boolean skipActiveCheck) throws IOException {
-
+ private ReferenceCounted<OmSnapshot> getSnapshot(String snapshotTableKey,
boolean skipActiveCheck)
+ throws IOException {
+ SnapshotInfo snapshotInfo = SnapshotUtils.getSnapshotInfo(ozoneManager,
snapshotTableKey);
// Block FS API reads when snapshot is not active.
if (!skipActiveCheck) {
- checkSnapshotActive(ozoneManager, snapshotTableKey);
+ checkSnapshotActive(snapshotInfo, false);
}
// retrieve the snapshot from the cache
- return snapshotCache.get(snapshotTableKey);
+ return snapshotCache.get(snapshotInfo.getSnapshotId());
}
/**
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotPurgeRequest.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotPurgeRequest.java
index 1533ceebe3..0fa9087e25 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotPurgeRequest.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotPurgeRequest.java
@@ -91,7 +91,7 @@ public class OMSnapshotPurgeRequest extends OMClientRequest {
trxnLogIndex, updatedSnapInfos);
updateSnapshotChainAndCache(omMetadataManager, fromSnapshot,
trxnLogIndex, updatedPathPreviousAndGlobalSnapshots);
- ozoneManager.getOmSnapshotManager().invalidateCacheEntry(snapTableKey);
+
ozoneManager.getOmSnapshotManager().invalidateCacheEntry(fromSnapshot.getSnapshotId());
}
omClientResponse = new OMSnapshotPurgeResponse(omResponse.build(),
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 e776968fca..0b64d6d069 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
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import static
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
@@ -39,26 +40,25 @@ public class SnapshotCache {
static final Logger LOG = LoggerFactory.getLogger(SnapshotCache.class);
// Snapshot cache internal hash map.
- // Key: DB snapshot table key
+ // Key: SnapshotId
// Value: OmSnapshot instance, each holds a DB instance handle inside
// TODO: [SNAPSHOT] Consider wrapping SoftReference<> around
IOmMetadataReader
- private final ConcurrentHashMap<String, ReferenceCounted<OmSnapshot>> dbMap;
+ private final ConcurrentHashMap<UUID, ReferenceCounted<OmSnapshot>> dbMap;
+
+ private final CacheLoader<UUID, OmSnapshot> cacheLoader;
- private final CacheLoader<String, OmSnapshot> cacheLoader;
// Soft-limit of the total number of snapshot DB instances allowed to be
// opened on the OM.
private final int cacheSizeLimit;
- public SnapshotCache(
- CacheLoader<String, OmSnapshot> cacheLoader,
- int cacheSizeLimit) {
+ public SnapshotCache(CacheLoader<UUID, OmSnapshot> cacheLoader, int
cacheSizeLimit) {
this.dbMap = new ConcurrentHashMap<>();
this.cacheLoader = cacheLoader;
this.cacheSizeLimit = cacheSizeLimit;
}
@VisibleForTesting
- ConcurrentHashMap<String, ReferenceCounted<OmSnapshot>> getDbMap() {
+ ConcurrentHashMap<UUID, ReferenceCounted<OmSnapshot>> getDbMap() {
return dbMap;
}
@@ -71,17 +71,17 @@ public class SnapshotCache {
/**
* Immediately invalidate an entry.
- * @param key DB snapshot table key
+ * @param key SnapshotId
*/
- public void invalidate(String key) throws IOException {
+ public void invalidate(UUID key) throws IOException {
dbMap.compute(key, (k, v) -> {
if (v == null) {
- LOG.warn("Key: '{}' does not exist in cache.", k);
+ LOG.warn("SnapshotId: '{}' does not exist in snapshot cache.", k);
} else {
try {
v.get().close();
} catch (IOException e) {
- throw new IllegalStateException("Failed to close snapshot: " + key,
e);
+ throw new IllegalStateException("Failed to close snapshotId: " +
key, e);
}
}
return null;
@@ -92,11 +92,10 @@ public class SnapshotCache {
* Immediately invalidate all entries and close their DB instances in cache.
*/
public void invalidateAll() {
- Iterator<Map.Entry<String, ReferenceCounted<OmSnapshot>>>
- it = dbMap.entrySet().iterator();
+ Iterator<Map.Entry<UUID, ReferenceCounted<OmSnapshot>>> it =
dbMap.entrySet().iterator();
while (it.hasNext()) {
- Map.Entry<String, ReferenceCounted<OmSnapshot>> entry = it.next();
+ Map.Entry<UUID, ReferenceCounted<OmSnapshot>> entry = it.next();
OmSnapshot omSnapshot = entry.getValue().get();
try {
// TODO: If wrapped with SoftReference<>, omSnapshot could be null?
@@ -114,7 +113,7 @@ public class SnapshotCache {
*/
public enum Reason {
FS_API_READ,
- SNAPDIFF_READ,
+ SNAP_DIFF_READ,
DEEP_CLEAN_WRITE,
GARBAGE_COLLECTION_WRITE
}
@@ -122,11 +121,10 @@ public class SnapshotCache {
/**
* Get or load OmSnapshot. Shall be close()d after use.
* TODO: [SNAPSHOT] Can add reason enum to param list later.
- * @param key snapshot table key
+ * @param key SnapshotId
* @return an OmSnapshot instance, or null on error
*/
- public ReferenceCounted<OmSnapshot> get(String key)
- throws IOException {
+ public ReferenceCounted<OmSnapshot> get(UUID key) throws IOException {
// Warn if actual cache size exceeds the soft limit already.
if (size() > cacheSizeLimit) {
LOG.warn("Snapshot cache size ({}) exceeds configured soft-limit ({}).",
@@ -137,9 +135,9 @@ public class SnapshotCache {
ReferenceCounted<OmSnapshot> rcOmSnapshot =
dbMap.compute(key, (k, v) -> {
if (v == null) {
- LOG.info("Loading snapshot. Table key: {}", k);
+ LOG.info("Loading SnapshotId: '{}'", k);
try {
- v = new ReferenceCounted<>(cacheLoader.load(k), false, this);
+ v = new ReferenceCounted<>(cacheLoader.load(key), false, this);
} catch (OMException omEx) {
// Return null if the snapshot is no longer active
if (!omEx.getResult().equals(FILE_NOT_FOUND)) {
@@ -163,8 +161,7 @@ public class SnapshotCache {
if (rcOmSnapshot == null) {
// The only exception that would fall through the loader logic above
// is OMException with FILE_NOT_FOUND.
- throw new OMException("Snapshot table key '" + key + "' not found, "
- + "or the snapshot is no longer active",
+ throw new OMException("SnapshotId: '" + key + "' not found, or the
snapshot is no longer active.",
OMException.ResultCodes.FILE_NOT_FOUND);
}
@@ -179,12 +176,12 @@ public class SnapshotCache {
/**
* Release the reference count on the OmSnapshot instance.
- * @param key snapshot table key
+ * @param key SnapshotId
*/
- public void release(String key) {
+ public void release(UUID key) {
dbMap.compute(key, (k, v) -> {
if (v == null) {
- throw new IllegalArgumentException("Key '" + key + "' does not exist
in cache.");
+ throw new IllegalArgumentException("SnapshotId '" + key + "' does not
exist in cache.");
} else {
v.decrementRefCount();
}
@@ -196,15 +193,6 @@ public class SnapshotCache {
cleanup();
}
- /**
- * Alternatively, can release with OmSnapshot instance directly.
- * @param omSnapshot OmSnapshot
- */
- public void release(OmSnapshot omSnapshot) {
- final String snapshotTableKey = omSnapshot.getSnapshotTableKey();
- release(snapshotTableKey);
- }
-
/**
* Wrapper for cleanupInternal() that is synchronized to prevent multiple
* threads from interleaving into the cleanup method.
@@ -221,24 +209,23 @@ public class SnapshotCache {
* TODO: [SNAPSHOT] Add new ozone debug CLI command to trigger this directly.
*/
private void cleanupInternal() {
- for (Map.Entry<String, ReferenceCounted<OmSnapshot>> entry :
dbMap.entrySet()) {
+ for (Map.Entry<UUID, ReferenceCounted<OmSnapshot>> entry :
dbMap.entrySet()) {
dbMap.compute(entry.getKey(), (k, v) -> {
if (v == null) {
- throw new IllegalStateException("Key '" + k + "' does not exist in
cache. The RocksDB " +
+ throw new IllegalStateException("SnapshotId '" + k + "' does not
exist in cache. The RocksDB " +
"instance of the Snapshot may not be closed properly.");
}
if (v.getTotalRefCount() > 0) {
- LOG.debug("Snapshot {} is still being referenced ({}), skipping its
clean up",
- k, v.getTotalRefCount());
+ LOG.debug("SnapshotId {} is still being referenced ({}), skipping
its clean up.", k, v.getTotalRefCount());
return v;
} else {
- LOG.debug("Closing Snapshot {}. It is not being referenced
anymore.", k);
+ LOG.debug("Closing SnapshotId {}. It is not being referenced
anymore.", k);
// Close the instance, which also closes its DB handle.
try {
v.get().close();
} catch (IOException ex) {
- throw new IllegalStateException("Error while closing snapshot DB",
ex);
+ throw new IllegalStateException("Error while closing snapshot
DB.", ex);
}
return null;
}
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotManager.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotManager.java
index 9cc79012dc..c865cb7814 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotManager.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmSnapshotManager.java
@@ -166,9 +166,16 @@ class TestOmSnapshotManager {
SnapshotInfo first = createSnapshotInfo(volumeName, bucketName);
SnapshotInfo second = createSnapshotInfo(volumeName, bucketName);
+ first.setGlobalPreviousSnapshotId(null);
+ first.setPathPreviousSnapshotId(null);
+ second.setGlobalPreviousSnapshotId(first.getSnapshotId());
+ second.setPathPreviousSnapshotId(first.getSnapshotId());
+
when(snapshotInfoTable.get(first.getTableKey())).thenReturn(first);
when(snapshotInfoTable.get(second.getTableKey())).thenReturn(second);
+ ((OmMetadataManagerImpl)
om.getMetadataManager()).getSnapshotChainManager().addSnapshot(first);
+ ((OmMetadataManagerImpl)
om.getMetadataManager()).getSnapshotChainManager().addSnapshot(second);
// create the first snapshot checkpoint
OmSnapshotManager.createOmSnapshotCheckpoint(om.getMetadataManager(),
first);
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 2a70a1f09a..21b795216d 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
@@ -31,6 +31,7 @@ import org.mockito.stubbing.Answer;
import org.slf4j.event.Level;
import java.io.IOException;
+import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -48,7 +49,7 @@ import static org.mockito.Mockito.when;
class TestSnapshotCache {
private static final int CACHE_SIZE_LIMIT = 3;
- private static CacheLoader<String, OmSnapshot> cacheLoader;
+ private static CacheLoader<UUID, OmSnapshot> cacheLoader;
private SnapshotCache snapshotCache;
@BeforeAll
@@ -59,8 +60,8 @@ class TestSnapshotCache {
(Answer<OmSnapshot>) invocation -> {
final OmSnapshot omSnapshot = mock(OmSnapshot.class);
// Mock the snapshotTable return value for the lookup inside
release()
- final String dbKey = (String) invocation.getArguments()[0];
- when(omSnapshot.getSnapshotTableKey()).thenReturn(dbKey);
+ final UUID snapshotID = (UUID) invocation.getArguments()[0];
+
when(omSnapshot.getSnapshotTableKey()).thenReturn(snapshotID.toString());
return omSnapshot;
}
@@ -83,9 +84,9 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("01. get()")
+ @DisplayName("get()")
void testGet() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot = snapshotCache.get(dbKey1);
assertNotNull(omSnapshot);
assertNotNull(omSnapshot.get());
@@ -94,9 +95,9 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("02. get() same entry twice yields one cache entry only")
+ @DisplayName("get() same entry twice yields one cache entry only")
void testGetTwice() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot1 = snapshotCache.get(dbKey1);
assertNotNull(omSnapshot1);
assertEquals(1, snapshotCache.size());
@@ -109,9 +110,9 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("03. release(String)")
+ @DisplayName("release(String)")
void testReleaseByDbKey() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot1 = snapshotCache.get(dbKey1);
assertNotNull(omSnapshot1);
assertNotNull(omSnapshot1.get());
@@ -123,22 +124,9 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("04. release(OmSnapshot)")
- void testReleaseByOmSnapshotInstance() throws IOException {
- final String dbKey1 = "dbKey1";
- ReferenceCounted<OmSnapshot> omSnapshot1 = snapshotCache.get(dbKey1);
- assertNotNull(omSnapshot1);
- assertEquals(1, snapshotCache.size());
-
- snapshotCache.release(omSnapshot1.get());
- // Entry will not be immediately evicted
- assertEquals(1, snapshotCache.size());
- }
-
- @Test
- @DisplayName("05. invalidate()")
+ @DisplayName("invalidate()")
void testInvalidate() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot = snapshotCache.get(dbKey1);
assertNotNull(omSnapshot);
assertEquals(1, snapshotCache.size());
@@ -152,21 +140,21 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("06. invalidateAll()")
+ @DisplayName("invalidateAll()")
void testInvalidateAll() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot1 = snapshotCache.get(dbKey1);
assertNotNull(omSnapshot1);
assertEquals(1, snapshotCache.size());
- final String dbKey2 = "dbKey2";
+ final UUID dbKey2 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot2 = snapshotCache.get(dbKey2);
assertNotNull(omSnapshot2);
assertEquals(2, snapshotCache.size());
// Should be difference omSnapshot instances
assertNotEquals(omSnapshot1, omSnapshot2);
- final String dbKey3 = "dbKey3";
+ final UUID dbKey3 = UUID.randomUUID();
ReferenceCounted<OmSnapshot> omSnapshot3 = snapshotCache.get(dbKey3);
assertNotNull(omSnapshot3);
assertEquals(3, snapshotCache.size());
@@ -182,7 +170,7 @@ class TestSnapshotCache {
assertEquals(0, snapshotCache.size());
}
- private void assertEntryExistence(String key, boolean shouldExist) {
+ private void assertEntryExistence(UUID key, boolean shouldExist) {
if (shouldExist) {
snapshotCache.getDbMap().computeIfAbsent(key, k -> {
fail(k + " should not have been evicted");
@@ -197,28 +185,28 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("07. Basic cache eviction")
+ @DisplayName("Basic cache eviction")
void testEviction1() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
snapshotCache.get(dbKey1);
assertEquals(1, snapshotCache.size());
snapshotCache.release(dbKey1);
assertEquals(1, snapshotCache.size());
- final String dbKey2 = "dbKey2";
+ final UUID dbKey2 = UUID.randomUUID();
snapshotCache.get(dbKey2);
assertEquals(2, snapshotCache.size());
snapshotCache.release(dbKey2);
assertEquals(2, snapshotCache.size());
- final String dbKey3 = "dbKey3";
+ final UUID dbKey3 = UUID.randomUUID();
snapshotCache.get(dbKey3);
assertEquals(3, snapshotCache.size());
snapshotCache.release(dbKey3);
assertEquals(3, snapshotCache.size());
- final String dbKey4 = "dbKey4";
+ final UUID dbKey4 = UUID.randomUUID();
snapshotCache.get(dbKey4);
// dbKey1, dbKey2 and dbKey3 would have been evicted by the end of the
last get() because
// those were release()d.
@@ -227,22 +215,22 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("08. Cache eviction while exceeding soft limit")
+ @DisplayName("Cache eviction while exceeding soft limit")
void testEviction2() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
snapshotCache.get(dbKey1);
assertEquals(1, snapshotCache.size());
- final String dbKey2 = "dbKey2";
+ final UUID dbKey2 = UUID.randomUUID();
snapshotCache.get(dbKey2);
assertEquals(2, snapshotCache.size());
- final String dbKey3 = "dbKey3";
+ final UUID dbKey3 = UUID.randomUUID();
snapshotCache.get(dbKey3);
assertEquals(3, snapshotCache.size());
- final String dbKey4 = "dbKey4";
+ final UUID dbKey4 = UUID.randomUUID();
snapshotCache.get(dbKey4);
// dbKey1 would not have been evicted because it is not release()d
assertEquals(4, snapshotCache.size());
@@ -257,10 +245,10 @@ class TestSnapshotCache {
}
@Test
- @DisplayName("09. Cache eviction with try-with-resources")
+ @DisplayName("Cache eviction with try-with-resources")
void testEviction3WithClose() throws IOException {
- final String dbKey1 = "dbKey1";
+ final UUID dbKey1 = UUID.randomUUID();
try (ReferenceCounted<OmSnapshot> rcOmSnapshot =
snapshotCache.get(dbKey1)) {
assertEquals(1L, rcOmSnapshot.getTotalRefCount());
assertEquals(1, snapshotCache.size());
@@ -270,7 +258,7 @@ class TestSnapshotCache {
assertEquals(0L, snapshotCache.getDbMap().get(dbKey1).getTotalRefCount());
assertEquals(1, snapshotCache.size());
- final String dbKey2 = "dbKey2";
+ final UUID dbKey2 = UUID.randomUUID();
try (ReferenceCounted<OmSnapshot> rcOmSnapshot =
snapshotCache.get(dbKey2)) {
assertEquals(1L, rcOmSnapshot.getTotalRefCount());
assertEquals(2, snapshotCache.size());
@@ -285,7 +273,7 @@ class TestSnapshotCache {
assertEquals(0L, snapshotCache.getDbMap().get(dbKey2).getTotalRefCount());
assertEquals(2, snapshotCache.size());
- final String dbKey3 = "dbKey3";
+ final UUID dbKey3 = UUID.randomUUID();
try (ReferenceCounted<OmSnapshot> rcOmSnapshot =
snapshotCache.get(dbKey3)) {
assertEquals(1L, rcOmSnapshot.getTotalRefCount());
assertEquals(3, snapshotCache.size());
@@ -293,7 +281,7 @@ class TestSnapshotCache {
assertEquals(0L, snapshotCache.getDbMap().get(dbKey3).getTotalRefCount());
assertEquals(3, snapshotCache.size());
- final String dbKey4 = "dbKey4";
+ final UUID dbKey4 = UUID.randomUUID();
try (ReferenceCounted<OmSnapshot> rcOmSnapshot =
snapshotCache.get(dbKey4)) {
assertEquals(1L, rcOmSnapshot.getTotalRefCount());
assertEquals(1, snapshotCache.size());
diff --git
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
index a6461182f2..3f9a1b3ae5 100644
---
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
+++
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/snapshot/TestSnapshotDiffManager.java
@@ -324,8 +324,8 @@ public class TestSnapshotDiffManager {
OZONE_OM_SNAPSHOT_DIFF_JOB_DEFAULT_WAIT_TIME_DEFAULT,
TimeUnit.MILLISECONDS))
.thenReturn(OZONE_OM_SNAPSHOT_DIFF_JOB_DEFAULT_WAIT_TIME_DEFAULT);
- when(configuration
- .getBoolean(OZONE_OM_SNAPSHOT_FORCE_FULL_DIFF,
+ when(configuration.
+ getBoolean(OZONE_OM_SNAPSHOT_FORCE_FULL_DIFF,
OZONE_OM_SNAPSHOT_FORCE_FULL_DIFF_DEFAULT))
.thenReturn(OZONE_OM_SNAPSHOT_FORCE_FULL_DIFF_DEFAULT);
when(configuration
@@ -379,26 +379,25 @@ public class TestSnapshotDiffManager {
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
omSnapshotManager = mock(OmSnapshotManager.class);
- when(omSnapshotManager.isSnapshotStatus(
- any(), any())).thenReturn(true);
+ when(omSnapshotManager.isSnapshotStatus(any(), any())).thenReturn(true);
SnapshotCache snapshotCache = new SnapshotCache(mockCacheLoader(), 10);
when(omSnapshotManager.getActiveSnapshot(anyString(), anyString(),
anyString()))
.thenAnswer(invocationOnMock -> {
- String snapshotTableKey =
SnapshotInfo.getTableKey(invocationOnMock.getArgument(0),
+ SnapshotInfo snapInfo = SnapshotUtils.getSnapshotInfo(ozoneManager,
invocationOnMock.getArgument(0),
invocationOnMock.getArgument(1),
invocationOnMock.getArgument(2));
- return snapshotCache.get(snapshotTableKey);
+ return snapshotCache.get(snapInfo.getSnapshotId());
});
when(ozoneManager.getOmSnapshotManager()).thenReturn(omSnapshotManager);
snapshotDiffManager = new SnapshotDiffManager(db, differ, ozoneManager,
snapDiffJobTable, snapDiffReportTable, columnFamilyOptions,
codecRegistry);
}
- private CacheLoader<String, OmSnapshot> mockCacheLoader() {
- return new CacheLoader<String, OmSnapshot>() {
+ private CacheLoader<UUID, OmSnapshot> mockCacheLoader() {
+ return new CacheLoader<UUID, OmSnapshot>() {
@Nonnull
@Override
- public OmSnapshot load(@Nonnull String key) {
+ public OmSnapshot load(@Nonnull UUID key) {
return getMockedOmSnapshot(key);
}
};
@@ -416,9 +415,9 @@ public class TestSnapshotDiffManager {
IOUtils.closeQuietly(snapshotDiffManager);
}
- private OmSnapshot getMockedOmSnapshot(String snapshot) {
+ private OmSnapshot getMockedOmSnapshot(UUID snapshotId) {
OmSnapshot omSnapshot = mock(OmSnapshot.class);
- when(omSnapshot.getName()).thenReturn(snapshot);
+ when(omSnapshot.getName()).thenReturn(snapshotId.toString());
when(omSnapshot.getMetadataManager()).thenReturn(omMetadataManager);
when(omMetadataManager.getStore()).thenReturn(dbStore);
return omSnapshot;
@@ -435,6 +434,10 @@ public class TestSnapshotDiffManager {
public void testGetDeltaFilesWithDag(int numberOfFiles) throws IOException {
UUID snap1 = UUID.randomUUID();
UUID snap2 = UUID.randomUUID();
+ when(snapshotInfoTable.get(SnapshotInfo.getTableKey(VOLUME_NAME,
BUCKET_NAME, snap1.toString())))
+ .thenReturn(getSnapshotInfoInstance(VOLUME_NAME, BUCKET_NAME,
snap1.toString(), snap2));
+ when(snapshotInfoTable.get(SnapshotInfo.getTableKey(VOLUME_NAME,
BUCKET_NAME, snap2.toString())))
+ .thenReturn(getSnapshotInfoInstance(VOLUME_NAME, BUCKET_NAME,
snap2.toString(), snap2));
String diffDir = snapDiffDir.getAbsolutePath();
Set<String> randomStrings = IntStream.range(0, numberOfFiles)
@@ -504,6 +507,10 @@ public class TestSnapshotDiffManager {
});
UUID snap1 = UUID.randomUUID();
UUID snap2 = UUID.randomUUID();
+ when(snapshotInfoTable.get(SnapshotInfo.getTableKey(VOLUME_NAME,
BUCKET_NAME, snap1.toString())))
+ .thenReturn(getSnapshotInfoInstance(VOLUME_NAME, BUCKET_NAME,
snap1.toString(), snap2));
+ when(snapshotInfoTable.get(SnapshotInfo.getTableKey(VOLUME_NAME,
BUCKET_NAME, snap2.toString())))
+ .thenReturn(getSnapshotInfoInstance(VOLUME_NAME, BUCKET_NAME,
snap2.toString(), snap2));
if (!useFullDiff) {
when(differ.getSSTDiffListWithFullPath(
any(DifferSnapshotInfo.class),
@@ -567,6 +574,10 @@ public class TestSnapshotDiffManager {
});
UUID snap1 = UUID.randomUUID();
UUID snap2 = UUID.randomUUID();
+ when(snapshotInfoTable.get(SnapshotInfo.getTableKey(VOLUME_NAME,
BUCKET_NAME, snap1.toString())))
+ .thenReturn(getSnapshotInfoInstance(VOLUME_NAME, BUCKET_NAME,
snap1.toString(), snap1));
+ when(snapshotInfoTable.get(SnapshotInfo.getTableKey(VOLUME_NAME,
BUCKET_NAME, snap2.toString())))
+ .thenReturn(getSnapshotInfoInstance(VOLUME_NAME, BUCKET_NAME,
snap2.toString(), snap2));
doThrow(new FileNotFoundException("File not found exception."))
.when(differ)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]