Skip to content
Snippets Groups Projects
Commit dd4cf492 authored by Ayushi Srivastava's avatar Ayushi Srivastava
Browse files

Catch 404 from BlobStore during Versions Purge

parent 331fa62d
No related branches found
No related tags found
1 merge request!1010Catch 404 from BlobStore during Versions Purge
Pipeline #314932 failed
......@@ -206,8 +206,21 @@ public class CloudStorageImpl implements ICloudStorage {
@Override
public void deleteVersions(List<String> versionPaths) {
versionPaths.stream().forEach(versionPath ->
blobStore.deleteFromStorageContainer(headers.getPartitionId(), versionPath, containerName));
versionPaths.stream().forEach(versionPath -> {
try {
blobStore.deleteFromStorageContainer(headers.getPartitionId(), versionPath, containerName);
} catch (AppException ex) {
// It is possible that the record may have a version instance that is present in the metadata store and absent from the the blob store.
// This is a known inconsistency caused when we fail to successfully add the version instance to the blob store.
// To handle it we should ignore deletions from the blob store that result in a 404 (not found) error.
if (ex.getError().getCode() == 404) {
this.logger.warning(String.format("Deletion Failed. Tried to delete non-existent version in storage account: %s", versionPath));
}
else {
throw ex;
}
}
});
}
@Override
......
......@@ -416,7 +416,6 @@ class CloudStorageImplTest {
@Test
void shouldDeleteVersionsSuccessfully() {
List<String> versionPaths = Arrays.asList("versionPath1", "versionPath2");
when(headers.getPartitionId()).thenReturn(DATA_PARTITION);
......@@ -424,7 +423,41 @@ class CloudStorageImplTest {
versionPaths.forEach(versionPath ->
verify(blobStore, times(1)).deleteFromStorageContainer(DATA_PARTITION, versionPath, CONTAINER));
}
@Test
void deleteAllVersionsSuccessfully_when_blobThrowsNotFound() {
List<String> versionPaths = Arrays.asList("versionPath1", "versionPath2", "versionPath3");
when(headers.getPartitionId()).thenReturn(DATA_PARTITION);
when(blobStore.deleteFromStorageContainer(DATA_PARTITION, "versionPath1", CONTAINER)).thenThrow(new AppException(404, "BlobNotFound", "404"));
when(blobStore.deleteFromStorageContainer(DATA_PARTITION, "versionPath2", CONTAINER)).thenReturn(true);
when(blobStore.deleteFromStorageContainer(DATA_PARTITION, "versionPath3", CONTAINER)).thenReturn(true);
cloudStorage.deleteVersions(versionPaths);
// All versions should continue to be deleted after a 404 from blob store is eaten successfully.
versionPaths.forEach(versionPath ->
verify(blobStore, times(1)).deleteFromStorageContainer(DATA_PARTITION, versionPath, CONTAINER));
}
@Test
void deleteAllVersionsFails_when_blobThrowsRandomException() {
List<String> versionPaths = Arrays.asList("versionPath1", "versionPath2", "versionPath3");
when(headers.getPartitionId()).thenReturn(DATA_PARTITION);
when(blobStore.deleteFromStorageContainer(DATA_PARTITION, "versionPath1", CONTAINER)).thenReturn(true);
when(blobStore.deleteFromStorageContainer(DATA_PARTITION, "versionPath2", CONTAINER)).thenThrow(new AppException(500, "Random error", "500"));
assertThrows(AppException.class, () -> cloudStorage.deleteVersions(versionPaths));
// versionPath1 deletes successfully.
verify(blobStore, times(1)).deleteFromStorageContainer(DATA_PARTITION, "versionPath1", CONTAINER);
// versionPath2 delete is called but fails.
verify(blobStore, times(1)).deleteFromStorageContainer(DATA_PARTITION, "versionPath2", CONTAINER);
// Other than 404 by blob store, no exception should be eaten.
// Delete for versionPath3 is never called, as it failed at versionPath2.
verify(blobStore, times(0)).deleteFromStorageContainer(DATA_PARTITION, "versionPath3", CONTAINER);
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment