Skip to content

Commit

Permalink
CDPD-67727. HDDS-10524. [Snapshot] Invalidate the cache entry from sn…
Browse files Browse the repository at this point in the history
…apshotInfoTable cache in OMSnapshotPurgeRequest (apache#6443)

Change-Id: I96831f1f18f092950a2fbf257571d7a587e13f8a
  • Loading branch information
hemantk-12 authored and swamirishi committed Apr 9, 2024
1 parent edb045a commit 7098522
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ public SnapshotInfo copyObject() {
@Override
public String toString() {
return "SnapshotInfo{" +
", snapshotId: '" + snapshotId + '\'' +
"snapshotId: '" + snapshotId + '\'' +
", name: '" + name + "'," +
", volumeName: '" + volumeName + '\'' +
", bucketName: '" + bucketName + '\'' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
trxnLogIndex, updatedSnapInfos, true);
updateSnapshotChainAndCache(omMetadataManager, fromSnapshot,
trxnLogIndex, updatedPathPreviousAndGlobalSnapshots);
// Remove and close snapshot's RocksDB instance from SnapshotCache.
ozoneManager.getOmSnapshotManager().getSnapshotCache()
.invalidate(snapTableKey);
// Update SnapshotInfoTable cache.
ozoneManager.getMetadataManager().getSnapshotInfoTable()
.addCacheEntry(new CacheKey<>(fromSnapshot.getTableKey()), CacheValue.get(trxnLogIndex));
}

omClientResponse = new OMSnapshotPurgeResponse(omResponse.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ protected void addToDBBatch(OMMetadataManager omMetadataManager,
updateSnapInfo(metadataManager, batchOperation,
updatedPreviousAndGlobalSnapInfos);
for (String dbKey: snapshotDbKeys) {
// Skip the cache here because snapshot is purged from cache in OMSnapshotPurgeRequest.
SnapshotInfo snapshotInfo = omMetadataManager
.getSnapshotInfoTable().get(dbKey);
.getSnapshotInfoTable().getSkipCache(dbKey);
// Even though snapshot existed when SnapshotDeletingService
// was running. It might be deleted in the previous run and
// the DB might not have been updated yet. So snapshotInfo
Expand All @@ -96,8 +97,7 @@ protected void addToDBBatch(OMMetadataManager omMetadataManager,

// Delete Snapshot checkpoint directory.
deleteCheckpointDirectory(omMetadataManager, snapshotInfo);
omMetadataManager.getSnapshotInfoTable().deleteWithBatch(batchOperation,
dbKey);
omMetadataManager.getSnapshotInfoTable().deleteWithBatch(batchOperation, dbKey);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
Expand All @@ -79,8 +80,6 @@
* Tests OMSnapshotPurgeRequest class.
*/
public class TestOMSnapshotPurgeRequestAndResponse {

private BatchOperation batchOperation;
private List<Path> checkpointPaths = new ArrayList<>();

private OzoneManager ozoneManager;
Expand Down Expand Up @@ -180,7 +179,6 @@ private void createSnapshotCheckpoint(String snapshotName) throws Exception {
private void createSnapshotCheckpoint(String volume,
String bucket,
String snapshotName) throws Exception {
batchOperation = omMetadataManager.getStore().initBatchOperation();
OMRequest omRequest = OMRequestTestUtils
.createSnapshotRequest(volume, bucket, snapshotName);
// Pre-Execute OMSnapshotCreateRequest.
Expand All @@ -191,9 +189,10 @@ private void createSnapshotCheckpoint(String volume,
OMSnapshotCreateResponse omClientResponse = (OMSnapshotCreateResponse)
omSnapshotCreateRequest.validateAndUpdateCache(ozoneManager, 1);
// Add to batch and commit to DB.
omClientResponse.addToDBBatch(omMetadataManager, batchOperation);
omMetadataManager.getStore().commitBatchOperation(batchOperation);
batchOperation.close();
try (BatchOperation batchOperation = omMetadataManager.getStore().initBatchOperation()) {
omClientResponse.addToDBBatch(omMetadataManager, batchOperation);
omMetadataManager.getStore().commitBatchOperation(batchOperation);
}

String key = SnapshotInfo.getTableKey(volume, bucket, snapshotName);
SnapshotInfo snapshotInfo =
Expand Down Expand Up @@ -229,9 +228,10 @@ private void purgeSnapshots(OMRequest snapshotPurgeRequest)
omSnapshotPurgeRequest.validateAndUpdateCache(ozoneManager, 200L);

// Commit to DB.
batchOperation = omMetadataManager.getStore().initBatchOperation();
omSnapshotPurgeResponse.checkAndUpdateDB(omMetadataManager, batchOperation);
omMetadataManager.getStore().commitBatchOperation(batchOperation);
try (BatchOperation batchOperation = omMetadataManager.getStore().initBatchOperation()) {
omSnapshotPurgeResponse.checkAndUpdateDB(omMetadataManager, batchOperation);
omMetadataManager.getStore().commitBatchOperation(batchOperation);
}
}

@Test
Expand All @@ -241,7 +241,20 @@ public void testValidateAndUpdateCache() throws Exception {
assertFalse(omMetadataManager.getSnapshotInfoTable().isEmpty());
OMRequest snapshotPurgeRequest = createPurgeKeysRequest(
snapshotDbKeysToPurge);
purgeSnapshots(snapshotPurgeRequest);

OMSnapshotPurgeRequest omSnapshotPurgeRequest = preExecute(snapshotPurgeRequest);

OMSnapshotPurgeResponse omSnapshotPurgeResponse = (OMSnapshotPurgeResponse)
omSnapshotPurgeRequest.validateAndUpdateCache(ozoneManager, 200L);

for (String snapshotTableKey: snapshotDbKeysToPurge) {
assertNull(omMetadataManager.getSnapshotInfoTable().get(snapshotTableKey));
}

try (BatchOperation batchOperation = omMetadataManager.getStore().initBatchOperation()) {
omSnapshotPurgeResponse.checkAndUpdateDB(omMetadataManager, batchOperation);
omMetadataManager.getStore().commitBatchOperation(batchOperation);
}

// Check if the entries are deleted.
assertTrue(omMetadataManager.getSnapshotInfoTable().isEmpty());
Expand Down

0 comments on commit 7098522

Please sign in to comment.