CosmosContainerDeletionEntry updateContainerDeletionEntry(short containerId, short accountId,
      BiConsumer<CosmosContainerDeletionEntry, AtomicBoolean> updateFields) throws CosmosException {

    CosmosAsyncContainer cosmosContainerForDeletedCollection =
        cosmosAsyncDatabase.getContainer(cosmosDeletedContainerCollection);
    CosmosContainerResponse cosmosContainerResponse = cosmosContainerForDeletedCollection.read().block();
    if (cosmosContainerResponse == null) {
      throw new IllegalStateException(
          "CosmosDB container for storing deprecated Ambry containers not found: " + cosmosDeletedContainerCollection);
    }

    // Read the existing record
    String id = CosmosContainerDeletionEntry.generateContainerDeletionEntryId(accountId, containerId);
    CosmosItemResponse<CosmosContainerDeletionEntry> cosmosItemResponse = executeCosmosAction(
        () -> cosmosContainerForDeletedCollection.readItem(id, new PartitionKey(id), CosmosContainerDeletionEntry.class)
            .block(), azureMetrics.continerDeletionEntryReadTime);
    CosmosContainerDeletionEntry containerDeletionEntry = cosmosItemResponse.getItem();

    // Update the record
    AtomicBoolean fieldsChanged = new AtomicBoolean(false);
    updateFields.accept(containerDeletionEntry, fieldsChanged);
    if (!fieldsChanged.get()) {
      logger.debug("No change in value for container deletion entry {}", containerDeletionEntry.toJson());
      return null;
    }

    // For testing conflict handling
    if (updateCallback != null) {
      try {
        updateCallback.call();
      } catch (Exception ex) {
        logger.error("Error in update callback", ex);
      }
    }

    // Set condition to ensure we don't clobber a concurrent update and replace the record.
    CosmosItemRequestOptions requestOptions = new CosmosItemRequestOptions();
    requestOptions.setIfMatchETag(cosmosItemResponse.getETag());
    try {
      return executeCosmosAction(
          () -> cosmosContainerForDeletedCollection.replaceItem(containerDeletionEntry, id, new PartitionKey(id),
              requestOptions).block(), azureMetrics.documentUpdateTime).getItem();
    } catch (CosmosException cex) {
      if (cex.getStatusCode() == HttpConstants.StatusCodes.PRECONDITION_FAILED) {
        // Keep track of failures due to conflicts.
        azureMetrics.blobUpdateConflictCount.inc();
      }
      throw cex;
    }
  }
Update the container deletion entry document in the CosmosDB collection.
@param containerId the container id for which document is replaced.
@param accountId the account id for which document is replaced.
@param updateFields {@link BiConsumer} object to use as callback to update the required fields.
@return the {@link CosmosContainerDeletionEntry} entry if successful.
Returns {@Null} if the field already has the specified value.
@throws CosmosException if the record was not found or if the operation failed.
ambry-cloud/src/main/java/com/github/ambry/cloud/azure/CosmosDataAccessor.java