private void addDatasetVersion(BlobProperties blobProperties, RestRequest restRequest) throws RestServiceException {
      long startAddDatasetVersionTime = System.currentTimeMillis();
      String accountName = null;
      String containerName = null;
      String datasetName = null;
      String version = null;
      try {
        Dataset dataset = (Dataset) restRequest.getArgs().get(RestUtils.InternalKeys.TARGET_DATASET);
        accountName = dataset.getAccountName();
        containerName = dataset.getContainerName();
        datasetName = dataset.getDatasetName();
        version = (String) restRequest.getArgs().get(RestUtils.InternalKeys.TARGET_DATASET_VERSION);
        boolean datasetVersionTtlEnabled =
            RestUtils.getBooleanHeader(restRequest.getArgs(), RestUtils.Headers.DATASET_VERSION_TTL_ENABLED, false);
        long expirationTimeMs =
            Utils.addSecondsToEpochTime(blobProperties.getCreationTimeInMs(), blobProperties.getTimeToLiveInSeconds());
        DatasetVersionRecord datasetVersionRecord =
            accountService.addDatasetVersion(accountName, containerName, datasetName, version,
                blobProperties.getTimeToLiveInSeconds(), blobProperties.getCreationTimeInMs(), datasetVersionTtlEnabled,
                DatasetVersionState.IN_PROGRESS);
        FrontendUtils.replaceRequestPathWithNewOperationOrBlobIdIfNeeded(restRequest, datasetVersionRecord, version);
        restResponseChannel.setHeader(RestUtils.Headers.TARGET_ACCOUNT_NAME, accountName);
        restResponseChannel.setHeader(RestUtils.Headers.TARGET_CONTAINER_NAME, containerName);
        restResponseChannel.setHeader(RestUtils.Headers.TARGET_DATASET_NAME, datasetName);
        restResponseChannel.setHeader(RestUtils.Headers.TARGET_DATASET_VERSION, datasetVersionRecord.getVersion());
        if (datasetVersionRecord.getExpirationTimeMs() != Utils.Infinite_Time) {
          restResponseChannel.setHeader(RestUtils.Headers.DATASET_EXPIRATION_TIME,
              new Date(datasetVersionRecord.getExpirationTimeMs()));
        }
        long newExpirationTimeMs = datasetVersionRecord.getExpirationTimeMs();
        // expirationTimeMs = ttl + creationTime. If dataset version inherit the retentionTimeInSeconds from dataset level
        // the ttl should be updated.
        if (expirationTimeMs != newExpirationTimeMs) {
          blobProperties.setTimeToLiveInSeconds(
              Utils.getTtlInSecsFromExpiryMs(newExpirationTimeMs, blobProperties.getCreationTimeInMs()));
        }
        frontendMetrics.addDatasetVersionProcessingTimeInMs.update(
            System.currentTimeMillis() - startAddDatasetVersionTime);
      } catch (AccountServiceException ex) {
        LOGGER.error(
            "Dataset version create failed for accountName: " + accountName + " containerName: " + containerName
                + " datasetName: " + datasetName + " version: " + version);
        frontendMetrics.addDatasetVersionError.inc();
        throw new RestServiceException(ex.getMessage(),
            RestServiceErrorCode.getRestServiceErrorCode(ex.getErrorCode()));
      }
    }
Support add dataset version queries after before the named blob.
@param blobProperties The {@link BlobProperties} of this blob.
@param restRequest {@link RestRequest} representing the request.
@return the {@link Dataset}
@throws RestServiceException
ambry-frontend/src/main/java/com/github/ambry/frontend/NamedBlobPutHandler.java