public int compactPartition(String partitionPath) throws CloudStorageException {
    if (isShuttingDown()) {
      logger.info("Skipping compaction of {} due to shut down.", partitionPath);
      return 0;
    }

    Map<String, Long> checkpoints = getCompactionProgress(partitionPath);

    long now = System.currentTimeMillis();
    long queryEndTime = now - retentionPeriodMs;
    long queryStartTime = now - TimeUnit.DAYS.toMillis(lookbackDays);
    int totalBlobsPurged = 0;

    // TODO (optimization): start with field with bigger backlog
    for (String fieldName : compactionFields) {
      try {
        long optimizedStartTime = Math.max(queryStartTime, checkpoints.get(fieldName));
        int numPurged = compactPartition(partitionPath, fieldName, optimizedStartTime, queryEndTime);
        logger.info("Purged {} blobs in partition {} based on {}", numPurged, partitionPath, fieldName);
        totalBlobsPurged += numPurged;
      } catch (CloudStorageException ex) {
        logger.error("Compaction failed for partition {} based on {}", partitionPath, fieldName, ex);
        vcrMetrics.compactionFailureCount.inc();
      }
    }
    if (isShuttingDown()) {
      logger.info("Compaction terminated due to shut down.");
    }
    return totalBlobsPurged;
  }
Purge the inactive blobs in the specified partition.
@return the total number of blobs purged.
@throws CloudStorageException if the compaction fails.
ambry-cloud/src/main/java/com/github/ambry/cloud/azure/AzureStorageCompactor.java