public DatasetVersionRecord addDatasetVersions(int accountId, int containerId, String accountName,
      String containerName, String datasetName, String version, long timeToLiveInSeconds, long creationTimeInMs,
      boolean datasetVersionTtlEnabled, DatasetVersionState datasetVersionState)
      throws SQLException, AccountServiceException {
    long startTimeMs = System.currentTimeMillis();
    long versionNumber = 0;
    Dataset dataset = null;
    DatasetVersionRecord datasetVersionRecord;
    try {
      dataset = getDatasetHelper(accountId, containerId, accountName, containerName, datasetName, true);
      if (isAutoCreatedVersionForUpload(version)) {
        datasetVersionRecord =
            retryWithLatestAutoIncrementedVersion(accountId, containerId, dataset, version, timeToLiveInSeconds,
                creationTimeInMs, datasetVersionTtlEnabled, datasetVersionState);
      } else {
        versionNumber = getVersionBasedOnSchema(version, dataset.getVersionSchema());
        datasetVersionRecord =
            addDatasetVersionHelper(accountId, containerId, dataset, version, timeToLiveInSeconds, creationTimeInMs,
                datasetVersionTtlEnabled, versionNumber, datasetVersionState);
      }
      dataAccessor.onSuccess(Write, System.currentTimeMillis() - startTimeMs);
      return datasetVersionRecord;
    } catch (SQLException | AccountServiceException e) {
      if (e instanceof SQLIntegrityConstraintViolationException) {
        try {
          datasetVersionRecord =
              updateDatasetVersionHelper(accountId, containerId, dataset, version, timeToLiveInSeconds,
                  creationTimeInMs, datasetVersionTtlEnabled, versionNumber, datasetVersionState);
          dataAccessor.onSuccess(Write, System.currentTimeMillis() - startTimeMs);
          return datasetVersionRecord;
        } catch (SQLException | AccountServiceException ex) {
          dataAccessor.onException(ex, Write);
          throw ex;
        }
      }
      dataAccessor.onException(e, Write);
      throw e;
    }
  }
Add a version of {@link Dataset} based on the supplied properties.
@param accountId the id for the parent account.
@param containerId the id of the container.
@param accountName the name for the parent account.
@param containerName the name for the container.
@param datasetName the name of the dataset.
@param version the version of the dataset.
@param timeToLiveInSeconds The dataset version level ttl.
@param creationTimeInMs the creation time of the dataset.
@param datasetVersionTtlEnabled set to true if dataset version ttl want to override the dataset level default ttl.
@param datasetVersionState the {@link DatasetVersionState}
@return the {@link DatasetVersionRecord}.
@throws SQLException
ambry-account/src/main/java/com/github/ambry/account/mysql/DatasetDao.java