Skip to content

Commit 7559e1f

Browse files
authored
HDDS-10524. [Snapshot] Invalidate the cache entry from snapshotInfoTable cache in OMSnapshotPurgeRequest (#6443)
1 parent e68183e commit 7559e1f

4 files changed

Lines changed: 31 additions & 14 deletions

File tree

hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/SnapshotInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ public SnapshotInfo copyObject() {
718718
@Override
719719
public String toString() {
720720
return "SnapshotInfo{" +
721-
", snapshotId: '" + snapshotId + '\'' +
721+
"snapshotId: '" + snapshotId + '\'' +
722722
", name: '" + name + "'," +
723723
", volumeName: '" + volumeName + '\'' +
724724
", bucketName: '" + bucketName + '\'' +

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/snapshot/OMSnapshotPurgeRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
102102
trxnLogIndex, updatedSnapInfos);
103103
updateSnapshotChainAndCache(omMetadataManager, fromSnapshot,
104104
trxnLogIndex, updatedPathPreviousAndGlobalSnapshots);
105+
// Remove and close snapshot's RocksDB instance from SnapshotCache.
105106
ozoneManager.getOmSnapshotManager().invalidateCacheEntry(fromSnapshot.getSnapshotId());
107+
// Update SnapshotInfoTable cache.
108+
ozoneManager.getMetadataManager().getSnapshotInfoTable()
109+
.addCacheEntry(new CacheKey<>(fromSnapshot.getTableKey()), CacheValue.get(trxnLogIndex));
106110
}
107111

108112
omClientResponse = new OMSnapshotPurgeResponse(omResponse.build(),

hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/snapshot/OMSnapshotPurgeResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ protected void addToDBBatch(OMMetadataManager omMetadataManager,
8484
updateSnapInfo(metadataManager, batchOperation,
8585
updatedPreviousAndGlobalSnapInfos);
8686
for (String dbKey: snapshotDbKeys) {
87+
// Skip the cache here because snapshot is purged from cache in OMSnapshotPurgeRequest.
8788
SnapshotInfo snapshotInfo = omMetadataManager
88-
.getSnapshotInfoTable().get(dbKey);
89+
.getSnapshotInfoTable().getSkipCache(dbKey);
8990
// Even though snapshot existed when SnapshotDeletingService
9091
// was running. It might be deleted in the previous run and
9192
// the DB might not have been updated yet. So snapshotInfo
@@ -96,8 +97,7 @@ protected void addToDBBatch(OMMetadataManager omMetadataManager,
9697

9798
// Delete Snapshot checkpoint directory.
9899
deleteCheckpointDirectory(omMetadataManager, snapshotInfo);
99-
omMetadataManager.getSnapshotInfoTable().deleteWithBatch(batchOperation,
100-
dbKey);
100+
omMetadataManager.getSnapshotInfoTable().deleteWithBatch(batchOperation, dbKey);
101101
}
102102
}
103103

hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/request/snapshot/TestOMSnapshotPurgeRequestAndResponse.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import static org.junit.jupiter.api.Assertions.assertFalse;
6868
import static org.junit.jupiter.api.Assertions.assertNotEquals;
6969
import static org.junit.jupiter.api.Assertions.assertNotNull;
70+
import static org.junit.jupiter.api.Assertions.assertNull;
7071
import static org.junit.jupiter.api.Assertions.assertTrue;
7172
import static org.mockito.Mockito.any;
7273
import static org.mockito.Mockito.anyString;
@@ -77,8 +78,6 @@
7778
* Tests OMSnapshotPurgeRequest class.
7879
*/
7980
public class TestOMSnapshotPurgeRequestAndResponse {
80-
81-
private BatchOperation batchOperation;
8281
private List<Path> checkpointPaths = new ArrayList<>();
8382

8483
private OzoneManager ozoneManager;
@@ -177,7 +176,6 @@ private void createSnapshotCheckpoint(String snapshotName) throws Exception {
177176
private void createSnapshotCheckpoint(String volume,
178177
String bucket,
179178
String snapshotName) throws Exception {
180-
batchOperation = omMetadataManager.getStore().initBatchOperation();
181179
OMRequest omRequest = OMRequestTestUtils
182180
.createSnapshotRequest(volume, bucket, snapshotName);
183181
// Pre-Execute OMSnapshotCreateRequest.
@@ -188,9 +186,10 @@ private void createSnapshotCheckpoint(String volume,
188186
OMSnapshotCreateResponse omClientResponse = (OMSnapshotCreateResponse)
189187
omSnapshotCreateRequest.validateAndUpdateCache(ozoneManager, 1);
190188
// Add to batch and commit to DB.
191-
omClientResponse.addToDBBatch(omMetadataManager, batchOperation);
192-
omMetadataManager.getStore().commitBatchOperation(batchOperation);
193-
batchOperation.close();
189+
try (BatchOperation batchOperation = omMetadataManager.getStore().initBatchOperation()) {
190+
omClientResponse.addToDBBatch(omMetadataManager, batchOperation);
191+
omMetadataManager.getStore().commitBatchOperation(batchOperation);
192+
}
194193

195194
String key = SnapshotInfo.getTableKey(volume, bucket, snapshotName);
196195
SnapshotInfo snapshotInfo =
@@ -226,9 +225,10 @@ private void purgeSnapshots(OMRequest snapshotPurgeRequest)
226225
omSnapshotPurgeRequest.validateAndUpdateCache(ozoneManager, 200L);
227226

228227
// Commit to DB.
229-
batchOperation = omMetadataManager.getStore().initBatchOperation();
230-
omSnapshotPurgeResponse.checkAndUpdateDB(omMetadataManager, batchOperation);
231-
omMetadataManager.getStore().commitBatchOperation(batchOperation);
228+
try (BatchOperation batchOperation = omMetadataManager.getStore().initBatchOperation()) {
229+
omSnapshotPurgeResponse.checkAndUpdateDB(omMetadataManager, batchOperation);
230+
omMetadataManager.getStore().commitBatchOperation(batchOperation);
231+
}
232232
}
233233

234234
@Test
@@ -238,7 +238,20 @@ public void testValidateAndUpdateCache() throws Exception {
238238
assertFalse(omMetadataManager.getSnapshotInfoTable().isEmpty());
239239
OMRequest snapshotPurgeRequest = createPurgeKeysRequest(
240240
snapshotDbKeysToPurge);
241-
purgeSnapshots(snapshotPurgeRequest);
241+
242+
OMSnapshotPurgeRequest omSnapshotPurgeRequest = preExecute(snapshotPurgeRequest);
243+
244+
OMSnapshotPurgeResponse omSnapshotPurgeResponse = (OMSnapshotPurgeResponse)
245+
omSnapshotPurgeRequest.validateAndUpdateCache(ozoneManager, 200L);
246+
247+
for (String snapshotTableKey: snapshotDbKeysToPurge) {
248+
assertNull(omMetadataManager.getSnapshotInfoTable().get(snapshotTableKey));
249+
}
250+
251+
try (BatchOperation batchOperation = omMetadataManager.getStore().initBatchOperation()) {
252+
omSnapshotPurgeResponse.checkAndUpdateDB(omMetadataManager, batchOperation);
253+
omMetadataManager.getStore().commitBatchOperation(batchOperation);
254+
}
242255

243256
// Check if the entries are deleted.
244257
assertTrue(omMetadataManager.getSnapshotInfoTable().isEmpty());

0 commit comments

Comments
 (0)