private int bulkDeleteMetadata(List<CloudBlobMetadata> blobMetadataList) throws CosmosException {
    String partitionPath = blobMetadataList.get(0).getPartitionId();

    // stored proc link provided in config.  Test for it at startup and use if available.
    String quotedBlobIds =
        blobMetadataList.stream().map(metadata -> '"' + metadata.getId() + '"').collect(Collectors.joining(","));
    String query = String.format(BULK_DELETE_QUERY, quotedBlobIds);
    boolean more = true;
    int deleteCount = 0;
    double requestCharge = 0;

    CosmosStoredProcedureRequestOptions cosmosStoredProcedureRequestOptions = new CosmosStoredProcedureRequestOptions();
    cosmosStoredProcedureRequestOptions.setPartitionKey(new PartitionKey(partitionPath));

    try {
      while (more) {
        CosmosStoredProcedureResponse cosmosStoredProcedureResponse = cosmosAsyncContainer.getScripts()
            .getStoredProcedure(BULK_DELETE_SPROC_ID)
            .execute(Collections.singletonList(query), cosmosStoredProcedureRequestOptions)
            .block();
        Document document;
        if (cosmosStoredProcedureResponse != null) {
          document = new Document(cosmosStoredProcedureResponse.getResponseAsString());
          more = document.getBoolean(PROPERTY_CONTINUATION);
          deleteCount += document.getInt(PROPERTY_DELETED);
          requestCharge += cosmosStoredProcedureResponse.getRequestCharge();
        } else {
          more = false;
        }
      }
      if (requestCharge >= requestChargeThreshold) {
        logger.info("Bulk delete partition {} request charge {} for {} records", partitionPath, requestCharge,
            deleteCount);
      }
      return deleteCount;
    } catch (Exception ex) {
      if (ex instanceof CosmosException) {
        throw (CosmosException) ex;
      }
      throw ex;
    }
  }
Delete the blob metadata documents from CosmosDB using the BulkDelete stored procedure.
@param blobMetadataList the list of blob metadata documents to delete.
@return the number of documents deleted.
@throws CosmosException if the operation failed.
ambry-cloud/src/main/java/com/github/ambry/cloud/azure/CosmosDataAccessor.java