@Test public void testPurgeWithStorageError() throws Exception { BlobStorageException ex = mockStorageException(BlobErrorCode.BLOB_ARCHIVED); BlobBatch mockBatch = mock(BlobBatch.class); Response<Void> mockResponse = mock(Response.class); when(mockResponse.getStatusCode()).thenThrow(ex); when(mockBlobBatchClient.getBlobBatch()).thenReturn(mockBatch); when(mockBatch.deleteBlob(anyString(), anyString())).thenReturn(mockResponse); try { azureStorageCompactor.purgeBlobs(blobMetadataList); fail("Expected CloudStorageException"); } catch (CloudStorageException bex) { } assertEquals(0, azureMetrics.blobDeletedCount.getCount()); assertEquals(numBlobsPerQuery, azureMetrics.blobDeleteErrorCount.getCount()); }
int purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws CloudStorageException { if (blobMetadataList.isEmpty()) { return 0; } azureMetrics.blobDeleteRequestCount.inc(blobMetadataList.size()); long t0 = System.currentTimeMillis(); try { List<CloudBlobMetadata> deletedBlobs = azureBlobDataAccessor.purgeBlobs(blobMetadataList); long t1 = System.currentTimeMillis(); int deletedCount = deletedBlobs.size(); azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size() - deletedCount); if (deletedCount > 0) { azureMetrics.blobDeletionTime.update((t1 - t0) / deletedCount, TimeUnit.MILLISECONDS); } else { return 0; } cosmosDataAccessor.deleteMetadata(deletedBlobs); long t2 = System.currentTimeMillis(); azureMetrics.documentDeleteTime.update((t2 - t1) / deletedCount, TimeUnit.MILLISECONDS); azureMetrics.blobDeletedCount.inc(deletedCount); return deletedCount; } catch (Exception ex) { azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size()); throw AzureCloudDestination.toCloudStorageException("Failed to purge all blobs", ex, azureMetrics); } }
AzureStorageCompactor { int purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws CloudStorageException { if (blobMetadataList.isEmpty()) { return 0; } azureMetrics.blobDeleteRequestCount.inc(blobMetadataList.size()); long t0 = System.currentTimeMillis(); try { List<CloudBlobMetadata> deletedBlobs = azureBlobDataAccessor.purgeBlobs(blobMetadataList); long t1 = System.currentTimeMillis(); int deletedCount = deletedBlobs.size(); azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size() - deletedCount); if (deletedCount > 0) { azureMetrics.blobDeletionTime.update((t1 - t0) / deletedCount, TimeUnit.MILLISECONDS); } else { return 0; } cosmosDataAccessor.deleteMetadata(deletedBlobs); long t2 = System.currentTimeMillis(); azureMetrics.documentDeleteTime.update((t2 - t1) / deletedCount, TimeUnit.MILLISECONDS); azureMetrics.blobDeletedCount.inc(deletedCount); return deletedCount; } catch (Exception ex) { azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size()); throw AzureCloudDestination.toCloudStorageException("Failed to purge all blobs", ex, azureMetrics); } } }
AzureStorageCompactor { int purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws CloudStorageException { if (blobMetadataList.isEmpty()) { return 0; } azureMetrics.blobDeleteRequestCount.inc(blobMetadataList.size()); long t0 = System.currentTimeMillis(); try { List<CloudBlobMetadata> deletedBlobs = azureBlobDataAccessor.purgeBlobs(blobMetadataList); long t1 = System.currentTimeMillis(); int deletedCount = deletedBlobs.size(); azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size() - deletedCount); if (deletedCount > 0) { azureMetrics.blobDeletionTime.update((t1 - t0) / deletedCount, TimeUnit.MILLISECONDS); } else { return 0; } cosmosDataAccessor.deleteMetadata(deletedBlobs); long t2 = System.currentTimeMillis(); azureMetrics.documentDeleteTime.update((t2 - t1) / deletedCount, TimeUnit.MILLISECONDS); azureMetrics.blobDeletedCount.inc(deletedCount); return deletedCount; } catch (Exception ex) { azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size()); throw AzureCloudDestination.toCloudStorageException("Failed to purge all blobs", ex, azureMetrics); } } AzureStorageCompactor(AzureBlobDataAccessor azureBlobDataAccessor, CosmosDataAccessor cosmosDataAccessor,
      CloudConfig cloudConfig, VcrMetrics vcrMetrics, AzureMetrics azureMetrics); }
AzureStorageCompactor { int purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws CloudStorageException { if (blobMetadataList.isEmpty()) { return 0; } azureMetrics.blobDeleteRequestCount.inc(blobMetadataList.size()); long t0 = System.currentTimeMillis(); try { List<CloudBlobMetadata> deletedBlobs = azureBlobDataAccessor.purgeBlobs(blobMetadataList); long t1 = System.currentTimeMillis(); int deletedCount = deletedBlobs.size(); azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size() - deletedCount); if (deletedCount > 0) { azureMetrics.blobDeletionTime.update((t1 - t0) / deletedCount, TimeUnit.MILLISECONDS); } else { return 0; } cosmosDataAccessor.deleteMetadata(deletedBlobs); long t2 = System.currentTimeMillis(); azureMetrics.documentDeleteTime.update((t2 - t1) / deletedCount, TimeUnit.MILLISECONDS); azureMetrics.blobDeletedCount.inc(deletedCount); return deletedCount; } catch (Exception ex) { azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size()); throw AzureCloudDestination.toCloudStorageException("Failed to purge all blobs", ex, azureMetrics); } } AzureStorageCompactor(AzureBlobDataAccessor azureBlobDataAccessor, CosmosDataAccessor cosmosDataAccessor,
      CloudConfig cloudConfig, VcrMetrics vcrMetrics, AzureMetrics azureMetrics); void shutdown(); int compactPartition(String partitionPath); }
AzureStorageCompactor { int purgeBlobs(List<CloudBlobMetadata> blobMetadataList) throws CloudStorageException { if (blobMetadataList.isEmpty()) { return 0; } azureMetrics.blobDeleteRequestCount.inc(blobMetadataList.size()); long t0 = System.currentTimeMillis(); try { List<CloudBlobMetadata> deletedBlobs = azureBlobDataAccessor.purgeBlobs(blobMetadataList); long t1 = System.currentTimeMillis(); int deletedCount = deletedBlobs.size(); azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size() - deletedCount); if (deletedCount > 0) { azureMetrics.blobDeletionTime.update((t1 - t0) / deletedCount, TimeUnit.MILLISECONDS); } else { return 0; } cosmosDataAccessor.deleteMetadata(deletedBlobs); long t2 = System.currentTimeMillis(); azureMetrics.documentDeleteTime.update((t2 - t1) / deletedCount, TimeUnit.MILLISECONDS); azureMetrics.blobDeletedCount.inc(deletedCount); return deletedCount; } catch (Exception ex) { azureMetrics.blobDeleteErrorCount.inc(blobMetadataList.size()); throw AzureCloudDestination.toCloudStorageException("Failed to purge all blobs", ex, azureMetrics); } } AzureStorageCompactor(AzureBlobDataAccessor azureBlobDataAccessor, CosmosDataAccessor cosmosDataAccessor,
      CloudConfig cloudConfig, VcrMetrics vcrMetrics, AzureMetrics azureMetrics); void shutdown(); int compactPartition(String partitionPath);  }