Skip to content
Merged
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,7 +227,9 @@ private SnapshotInfo getUpdatedSnapshotInfo(String snapshotTableKey, OMMetadataM

if (snapshotInfo == null) {
snapshotInfo = omMetadataManager.getSnapshotInfoTable().get(snapshotTableKey);
updatedSnapshotInfos.put(snapshotTableKey, snapshotInfo);
if (snapshotInfo != null) {
updatedSnapshotInfos.put(snapshotTableKey, snapshotInfo);
}
}
return snapshotInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.hadoop.ozone.om.response.snapshot;

import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.io.FileUtils;
import org.apache.hadoop.hdds.utils.db.BatchOperation;
import org.apache.hadoop.ozone.om.OMMetadataManager;
Expand Down Expand Up @@ -138,4 +139,9 @@ private void deleteCheckpointDirectory(OMMetadataManager omMetadataManager,
}
}
}

@VisibleForTesting
public Map<String, SnapshotInfo> getUpdatedSnapInfos() {
return updatedSnapInfos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
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.Mockito.anyString;
Expand Down Expand Up @@ -186,6 +187,42 @@ public void testValidateAndUpdateCache() throws Exception {
assertEquals(initialSnapshotPurgeFailCount, getOmMetrics().getNumSnapshotPurgeFails());
}

@Test
public void testDuplicateSnapshotPurge() throws Exception {
List<String> snapshotDbKeysToPurge = createSnapshots(1);
assertFalse(getOmMetadataManager().getSnapshotInfoTable().isEmpty());
OMRequest snapshotPurgeRequest = createPurgeKeysRequest(
snapshotDbKeysToPurge);

OMSnapshotPurgeRequest omSnapshotPurgeRequest = preExecute(snapshotPurgeRequest);

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

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

// Check if the entries are deleted.
assertTrue(getOmMetadataManager().getSnapshotInfoTable().isEmpty());

OMSnapshotPurgeResponse omSnapshotPurgeResponse1 = (OMSnapshotPurgeResponse)
omSnapshotPurgeRequest.validateAndUpdateCache(getOzoneManager(), 201L);

for (Map.Entry<String, SnapshotInfo> purgedSnapshot : omSnapshotPurgeResponse1.getUpdatedSnapInfos().entrySet()) {
assertNotNull(purgedSnapshot.getValue());
}
for (String snapshotTableKey: snapshotDbKeysToPurge) {
assertNull(getOmMetadataManager().getSnapshotInfoTable().get(snapshotTableKey));
}

try (BatchOperation batchOperation = getOmMetadataManager().getStore().initBatchOperation()) {
omSnapshotPurgeResponse1.checkAndUpdateDB(getOmMetadataManager(), batchOperation);
getOmMetadataManager().getStore().commitBatchOperation(batchOperation);
}
}

/**
* This test is mainly to validate metrics and error code.
*/
Expand Down
Loading