private void updateVersionStateAndDeleteDatasetVersionOutOfRetentionCount(Callback<Void> callback)
        throws RestServiceException {
      Dataset dataset = (Dataset) restRequest.getArgs().get(RestUtils.InternalKeys.TARGET_DATASET);
      String accountName = dataset.getAccountName();
      String containerName = dataset.getContainerName();
      String datasetName = dataset.getDatasetName();
      String targetVersion = (String) restResponseChannel.getHeader(Headers.TARGET_DATASET_VERSION);
      try {
        accountService.updateDatasetVersionState(accountName, containerName, datasetName, targetVersion,
            DatasetVersionState.READY);
      } catch (AccountServiceException ex) {
        LOGGER.error(
            "Dataset version update failed for accountName: " + accountName + " containerName: " + containerName
                + " datasetName: " + datasetName + " version: " + targetVersion, ex);
        throw new RestServiceException(ex.getMessage(),
            RestServiceErrorCode.getRestServiceErrorCode(ex.getErrorCode()));
      }
      try {
        List<DatasetVersionRecord> datasetVersionRecordList =
            accountService.getAllValidVersionsOutOfRetentionCount(accountName, containerName, datasetName);
        if (datasetVersionRecordList.size() > 0) {
          WrappedRestRequest wrappedRestRequest = new WrappedRestRequest(restRequest);
          LOGGER.info(
              "Number of records need to be deleted due to out of retention count: " + datasetVersionRecordList.size()
                  + " for accountName: " + accountName + " containerName: " + containerName + " datasetName: "
                  + datasetName);
          recursiveDeleteDatasetVersions(wrappedRestRequest, datasetVersionRecordList, 0, callback);
        } else {
          callback.onCompletion(null, null);
        }
      } catch (Exception e) {
        frontendMetrics.deleteDatasetVersionOutOfRetentionError.inc();
        LOGGER.error("Failed to delete dataset version out of retention count for this dataset: " + dataset, e);
        //We don't want the exception to be submitted to response.
        callback.onCompletion(null, null);
      }
    }
Support delete the dataset version out of retentionCount
ambry-frontend/src/main/java/com/github/ambry/frontend/NamedBlobPutHandler.java