Skip to content

Commit

Permalink
HDDS-10262. Encapsulate SnapshotCache inside OmSnapshotManager (apach…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyrill authored Feb 9, 2024
1 parent d3e2e59 commit 2f2234c
Show file tree
Hide file tree
Showing 30 changed files with 304 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.hadoop.ozone.client.OzoneBucket;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneVolume;
import org.apache.hadoop.ozone.om.IOmMetadataReader;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.OMMetadataManager;
import org.apache.hadoop.ozone.om.OmSnapshot;
Expand All @@ -39,7 +38,6 @@
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.snapshot.ReferenceCounted;
import org.apache.hadoop.ozone.om.snapshot.SnapshotCache;
import org.apache.ozone.rocksdiff.DifferSnapshotInfo;
import org.apache.ozone.rocksdiff.RocksDBCheckpointDiffer;
import org.apache.ozone.test.GenericTestUtils;
Expand Down Expand Up @@ -215,20 +213,16 @@ public void testDAGReconstruction()
OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
RDBStore rdbStore = (RDBStore) omMetadataManager.getStore();
RocksDBCheckpointDiffer differ = rdbStore.getRocksDBCheckpointDiffer();
ReferenceCounted<IOmMetadataReader, SnapshotCache>
snapDB1 = ozoneManager.getOmSnapshotManager()
.getSnapshotCache().get(
SnapshotInfo.getTableKey(volumeName, bucketName, "snap1"));
ReferenceCounted<IOmMetadataReader, SnapshotCache>
snapDB2 = ozoneManager.getOmSnapshotManager()
.getSnapshotCache().get(
SnapshotInfo.getTableKey(volumeName, bucketName, "snap2"));
ReferenceCounted<OmSnapshot> snapDB1 = ozoneManager.getOmSnapshotManager()
.getActiveSnapshot(volumeName, bucketName, "snap1");
ReferenceCounted<OmSnapshot> snapDB2 = ozoneManager.getOmSnapshotManager()
.getActiveSnapshot(volumeName, bucketName, "snap2");
DifferSnapshotInfo snap1 = getDifferSnapshotInfo(omMetadataManager,
volumeName, bucketName, "snap1",
((RDBStore)((OmSnapshot)snapDB1.get())
((RDBStore) snapDB1.get()
.getMetadataManager().getStore()).getDb().getManagedRocksDb());
DifferSnapshotInfo snap2 = getDifferSnapshotInfo(omMetadataManager,
volumeName, bucketName, "snap2", ((RDBStore)((OmSnapshot)snapDB2.get())
volumeName, bucketName, "snap2", ((RDBStore) snapDB2.get()
.getMetadataManager().getStore()).getDb().getManagedRocksDb());

// RocksDB does checkpointing in a separate thread, wait for it
Expand All @@ -247,13 +241,11 @@ public void testDAGReconstruction()

resp = store.createSnapshot(volumeName, bucketName, "snap3");
LOG.debug("Snapshot created: {}", resp);
ReferenceCounted<IOmMetadataReader, SnapshotCache>
snapDB3 = ozoneManager.getOmSnapshotManager()
.getSnapshotCache().get(
SnapshotInfo.getTableKey(volumeName, bucketName, "snap3"));
ReferenceCounted<OmSnapshot> snapDB3 = ozoneManager.getOmSnapshotManager()
.getActiveSnapshot(volumeName, bucketName, "snap3");
DifferSnapshotInfo snap3 = getDifferSnapshotInfo(omMetadataManager,
volumeName, bucketName, "snap3",
((RDBStore)((OmSnapshot)snapDB3.get())
((RDBStore) snapDB3.get()
.getMetadataManager().getStore()).getDb().getManagedRocksDb());
final File checkpointSnap3 = new File(snap3.getDbPath());
GenericTestUtils.waitFor(checkpointSnap3::exists, 2000, 20000);
Expand All @@ -274,24 +266,21 @@ public void testDAGReconstruction()
ozoneManager = cluster.getOzoneManager();
omMetadataManager = ozoneManager.getMetadataManager();
snapDB1 = ozoneManager.getOmSnapshotManager()
.getSnapshotCache().get(
SnapshotInfo.getTableKey(volumeName, bucketName, "snap1"));
.getActiveSnapshot(volumeName, bucketName, "snap1");
snapDB2 = ozoneManager.getOmSnapshotManager()
.getSnapshotCache().get(
SnapshotInfo.getTableKey(volumeName, bucketName, "snap2"));
.getActiveSnapshot(volumeName, bucketName, "snap2");
snap1 = getDifferSnapshotInfo(omMetadataManager,
volumeName, bucketName, "snap1",
((RDBStore)((OmSnapshot)snapDB1.get())
((RDBStore) snapDB1.get()
.getMetadataManager().getStore()).getDb().getManagedRocksDb());
snap2 = getDifferSnapshotInfo(omMetadataManager,
volumeName, bucketName, "snap2", ((RDBStore)((OmSnapshot)snapDB2.get())
volumeName, bucketName, "snap2", ((RDBStore) snapDB2.get()
.getMetadataManager().getStore()).getDb().getManagedRocksDb());
snapDB3 = ozoneManager.getOmSnapshotManager()
.getSnapshotCache().get(
SnapshotInfo.getTableKey(volumeName, bucketName, "snap3"));
.getActiveSnapshot(volumeName, bucketName, "snap3");
snap3 = getDifferSnapshotInfo(omMetadataManager,
volumeName, bucketName, "snap3",
((RDBStore)((OmSnapshot)snapDB3.get())
((RDBStore) snapDB3.get()
.getMetadataManager().getStore()).getDb().getManagedRocksDb());
List<String> sstDiffList21Run2 = differ.getSSTDiffList(snap2, snap1);
assertEquals(sstDiffList21, sstDiffList21Run2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServerConfig;
import org.apache.hadoop.ozone.om.snapshot.ReferenceCounted;
import org.apache.hadoop.ozone.om.snapshot.SnapshotCache;
import org.apache.hadoop.ozone.snapshot.SnapshotDiffReportOzone;
import org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse;
import org.apache.ozone.compaction.log.CompactionLogEntry;
Expand Down Expand Up @@ -76,7 +75,6 @@
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_SST_FILTERING_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPath;
import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPrefix;
import static org.apache.hadoop.ozone.om.TestOzoneManagerHAWithStoppedNodes.createKey;
import static org.apache.hadoop.ozone.snapshot.SnapshotDiffResponse.JobStatus.DONE;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -259,12 +257,11 @@ public void testSnapshotAndKeyDeletionBackgroundServices()

// get snapshot c
OmSnapshot snapC;
try (ReferenceCounted<IOmMetadataReader, SnapshotCache> rcC = newLeaderOM
try (ReferenceCounted<OmSnapshot> rcC = newLeaderOM
.getOmSnapshotManager()
.checkForSnapshot(volumeName, bucketName,
getSnapshotPrefix(snapshotInfoC.getName()), true)) {
.getSnapshot(volumeName, bucketName, snapshotInfoC.getName())) {
assertNotNull(rcC);
snapC = (OmSnapshot) rcC.get();
snapC = rcC.get();
}

// assert that key a is in snapshot c's deleted table
Expand All @@ -284,12 +281,11 @@ public void testSnapshotAndKeyDeletionBackgroundServices()

// get snapshot d
OmSnapshot snapD;
try (ReferenceCounted<IOmMetadataReader, SnapshotCache> rcD = newLeaderOM
try (ReferenceCounted<OmSnapshot> rcD = newLeaderOM
.getOmSnapshotManager()
.checkForSnapshot(volumeName, bucketName,
getSnapshotPrefix(snapshotInfoD.getName()), true)) {
.getSnapshot(volumeName, bucketName, snapshotInfoD.getName())) {
assertNotNull(rcD);
snapD = (OmSnapshot) rcD.get();
snapD = rcD.get();
}

// wait until key a appears in deleted table of snapshot d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.apache.hadoop.ozone.om.helpers.SnapshotInfo;
import org.apache.hadoop.ozone.om.service.SnapshotDeletingService;
import org.apache.hadoop.ozone.om.snapshot.ReferenceCounted;
import org.apache.hadoop.ozone.om.snapshot.SnapshotCache;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -58,7 +57,6 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CHUNK_SIZE_KEY;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ACL_ENABLED;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_BLOCK_DELETING_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPrefix;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_INTERVAL;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SNAPSHOT_DELETING_SERVICE_TIMEOUT;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -133,9 +131,8 @@ public void testSnapshotSplitAndMove() throws Exception {
GenericTestUtils.waitFor(() -> snapshotDeletingService
.getSuccessfulRunCount() >= 1, 1000, 10000);

OmSnapshot bucket1snap3 = (OmSnapshot) om.getOmSnapshotManager()
.checkForSnapshot(VOLUME_NAME, BUCKET_NAME_ONE,
getSnapshotPrefix("bucket1snap3"), true).get();
OmSnapshot bucket1snap3 = om.getOmSnapshotManager()
.getSnapshot(VOLUME_NAME, BUCKET_NAME_ONE, "bucket1snap3").get();

// Check bucket1key1 added to next non deleted snapshot db.
List<? extends Table.KeyValue<String, RepeatedOmKeyInfo>> omKeyInfos =
Expand Down Expand Up @@ -190,8 +187,7 @@ public void testMultipleSnapshotKeyReclaim() throws Exception {

// verify the cache of purged snapshot
// /vol1/bucket2/bucket2snap1 has been cleaned up from cache map
SnapshotCache snapshotCache = om.getOmSnapshotManager().getSnapshotCache();
assertEquals(2, snapshotCache.size());
assertEquals(2, om.getOmSnapshotManager().getSnapshotCacheSize());
}

@SuppressWarnings("checkstyle:MethodLength")
Expand Down Expand Up @@ -359,9 +355,8 @@ public void testSnapshotWithFSO() throws Exception {
assertTableRowCount(om.getMetadataManager().getSnapshotInfoTable(), 2);

verifySnapshotChain(deletedSnap, "/vol1/bucket2/snap3");
OmSnapshot snap3 = (OmSnapshot) om.getOmSnapshotManager()
.checkForSnapshot(VOLUME_NAME, BUCKET_NAME_TWO,
getSnapshotPrefix("snap3"), true).get();
OmSnapshot snap3 = om.getOmSnapshotManager()
.getSnapshot(VOLUME_NAME, BUCKET_NAME_TWO, "snap3").get();

Table<String, OmKeyInfo> snapDeletedDirTable =
snap3.getMetadataManager().getDeletedDirTable();
Expand All @@ -388,10 +383,10 @@ public void testSnapshotWithFSO() throws Exception {
assertTableRowCount(renamedTable, 4);
assertTableRowCount(deletedDirTable, 3);

ReferenceCounted<IOmMetadataReader, SnapshotCache> rcSnap1 =
om.getOmSnapshotManager().checkForSnapshot(
VOLUME_NAME, BUCKET_NAME_TWO, getSnapshotPrefix("snap1"), true);
OmSnapshot snap1 = (OmSnapshot) rcSnap1.get();
ReferenceCounted<OmSnapshot> rcSnap1 =
om.getOmSnapshotManager().getSnapshot(
VOLUME_NAME, BUCKET_NAME_TWO, "snap1");
OmSnapshot snap1 = rcSnap1.get();
Table<String, OmKeyInfo> snap1KeyTable =
snap1.getMetadataManager().getFileTable();
try (TableIterator<String, ? extends Table.KeyValue<String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,7 @@ public void testSnapshotOpensWithDisabledAutoCompaction() throws Exception {
String snapPrefix = createSnapshot(volumeName, bucketName);
try (RDBStore snapshotDBStore = (RDBStore)
((OmSnapshot) cluster.getOzoneManager().getOmSnapshotManager()
.checkForSnapshot(volumeName, bucketName, snapPrefix, false).get())
.getActiveFsMetadataOrSnapshot(volumeName, bucketName, snapPrefix).get())
.getMetadataManager().getStore()) {
for (String table : snapshotDBStore.getTableNames().values()) {
assertTrue(snapshotDBStore.getDb().getColumnFamily(table)
Expand Down Expand Up @@ -2161,7 +2161,7 @@ public void testCompactionDagDisableForSnapshotMetadata() throws Exception {

OmSnapshot omSnapshot = (OmSnapshot) cluster.getOzoneManager()
.getOmSnapshotManager()
.checkForSnapshot(volumeName, bucketName, snapshotName, false).get();
.getActiveFsMetadataOrSnapshot(volumeName, bucketName, snapshotName).get();

RDBStore snapshotDbStore =
(RDBStore) omSnapshot.getMetadataManager().getStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
import org.apache.hadoop.ozone.om.request.file.OMFileRequest;
import org.apache.hadoop.ozone.om.request.util.OMMultipartUploadUtils;
import org.apache.hadoop.ozone.om.snapshot.ReferenceCounted;
import org.apache.hadoop.ozone.om.snapshot.SnapshotCache;
import org.apache.hadoop.ozone.om.snapshot.SnapshotUtils;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ExpiredMultipartUploadInfo;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.ExpiredMultipartUploadsBucket;
Expand All @@ -109,7 +108,6 @@
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_FS_SNAPSHOT_MAX_LIMIT_DEFAULT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_CHECKPOINT_DIR_CREATION_POLL_TIMEOUT;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_SNAPSHOT_CHECKPOINT_DIR_CREATION_POLL_TIMEOUT_DEFAULT;
import static org.apache.hadoop.ozone.om.OmSnapshotManager.getSnapshotPrefix;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.FILE_NOT_FOUND;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
Expand Down Expand Up @@ -1555,7 +1553,7 @@ public PendingKeysDeletion getPendingDeletionKeys(final int keyCount,
OmBucketInfo bucketInfo = getBucketTable().get(bucketKey);

// Get the latest snapshot in snapshot path.
try (ReferenceCounted<IOmMetadataReader, SnapshotCache>
try (ReferenceCounted<OmSnapshot>
rcLatestSnapshot = getLatestActiveSnapshot(
keySplit[1], keySplit[2], omSnapshotManager)) {

Expand All @@ -1573,13 +1571,12 @@ public PendingKeysDeletion getPendingDeletionKeys(final int keyCount,

if (rcLatestSnapshot != null) {
Table<String, OmKeyInfo> prevKeyTable =
((OmSnapshot) rcLatestSnapshot.get())
rcLatestSnapshot.get()
.getMetadataManager()
.getKeyTable(bucketInfo.getBucketLayout());

Table<String, RepeatedOmKeyInfo> prevDeletedTable =
((OmSnapshot) rcLatestSnapshot.get())
.getMetadataManager().getDeletedTable();
rcLatestSnapshot.get().getMetadataManager().getDeletedTable();
String prevKeyTableDBKey = getSnapshotRenamedTable()
.get(dbRenameKey);
String prevDelTableDBKey = getOzoneKey(info.getVolumeName(),
Expand Down Expand Up @@ -1665,8 +1662,7 @@ private boolean versionExistsInPreviousSnapshot(OmKeyInfo omKeyInfo,
/**
* Get the latest OmSnapshot for a snapshot path.
*/
public ReferenceCounted<
IOmMetadataReader, SnapshotCache> getLatestActiveSnapshot(
public ReferenceCounted<OmSnapshot> getLatestActiveSnapshot(
String volumeName, String bucketName,
OmSnapshotManager snapshotManager)
throws IOException {
Expand Down Expand Up @@ -1700,13 +1696,12 @@ IOmMetadataReader, SnapshotCache> getLatestActiveSnapshot(
}
}

Optional<ReferenceCounted<IOmMetadataReader, SnapshotCache>> rcOmSnapshot =
Optional<ReferenceCounted<OmSnapshot>> rcOmSnapshot =
snapshotInfo.isPresent() ?
Optional.ofNullable(
snapshotManager.checkForSnapshot(volumeName,
snapshotManager.getSnapshot(volumeName,
bucketName,
getSnapshotPrefix(snapshotInfo.get().getName()),
true)
snapshotInfo.get().getName())
) :
Optional.empty();

Expand Down
Loading

0 comments on commit 2f2234c

Please sign in to comment.