public int compactPartition(String partitionPath, CloudStorageCompactor compactor) throws CloudStorageException {
    Set<Pair<Short, Short>> deletedContainers = getDeletedContainers();
    String containerName = azureBlobLayoutStrategy.getClusterAwareAzureContainerName(partitionPath);
    BlobContainerClient blobContainerClient = createOrGetBlobStore(containerName);
    ListBlobsOptions listBlobsOptions = new ListBlobsOptions().setDetails(new BlobListDetails()
        .setRetrieveMetadata(true)).setMaxResultsPerPage(azureCloudConfig.azureBlobStorageMaxResultsPerPage);
    String continuationToken = null;
    int numBlobsPurged = 0, totalNumBlobs = 0;
    Timer.Context storageTimer = azureMetrics.partitionCompactionLatency.time();
    try {
      logger.info("[COMPACT] Compacting partition {} in Azure blob storage", containerName);
      Supplier<Boolean> stopCompaction = () -> isCompactionStopped(partitionPath, compactor);
      while (!stopCompaction.get()) {
        PagedResponse<BlobItem> blobItemPagedResponse =
            blobContainerClient.listBlobs(listBlobsOptions, null)
                .iterableByPage(continuationToken).iterator().next();
        continuationToken = blobItemPagedResponse.getContinuationToken();
        logger.debug("[COMPACT] Acquired continuation-token {} for partition {}", continuationToken, containerName);
        List<BlobItem> blobItemList = blobItemPagedResponse.getValue();
        totalNumBlobs += blobItemList.size();
        numBlobsPurged += eraseBlobs(blobItemList, blobContainerClient, deletedContainers, stopCompaction);
        if (continuationToken == null) {
          logger.trace("[COMPACT] Reached end-of-partition {} as Azure blob storage continuationToken is null", containerName);
          break;
        }
      }
    } catch (Throwable t) {
      azureMetrics.partitionCompactionErrorCount.inc();
      String error = String.format("[COMPACT] Failed to compact partition %s due to %s", partitionPath, t.getMessage());
      logger.error(error);
      // Swallow error & return partial result. We want to be as close as possible to the real number of blobs deleted.
    } finally {
      storageTimer.stop();
    }
    logger.info("[COMPACT] Erased {} blobs out of {} from partition {} in Azure blob storage",
        numBlobsPurged, totalNumBlobs, partitionPath);
    return numBlobsPurged;
  }
Compacts a partition
@param partitionPath the path of the partitions to compact.
@return the number of blobs erased from cloud
@throws CloudStorageException
ambry-cloud/src/main/java/com/github/ambry/cloud/azure/AzureCloudDestinationSync.java