private DatasetVersionRecord retryWithLatestAutoIncrementedVersion(int accountId, int containerId, Dataset dataset,
      String version, long timeToLiveInSeconds, long creationTimeInMs, boolean datasetVersionTtlEnabled,
      DatasetVersionState datasetVersionState)
      throws AccountServiceException, SQLException {
    long versionNumber;
    while (true) {
      try {
        versionNumber =
            getAutoIncrementedVersionBasedOnLatestAvailableVersionHelper(accountId, containerId, dataset.getVersionSchema(),
                dataset.getDatasetName(), version);
        version = convertVersionValueToVersion(versionNumber, dataset.getVersionSchema());
        //always retry with the latest version + 1 until it has been successfully uploading without conflict or failed with exception.
        return addDatasetVersions(accountId, containerId, dataset.getAccountName(), dataset.getContainerName(),
            dataset.getDatasetName(), version, timeToLiveInSeconds, creationTimeInMs, datasetVersionTtlEnabled,
            datasetVersionState);
      } catch (SQLException | AccountServiceException ex) {
        // if the version already exist in database, retry with the new latest version +1.
        if (!(ex instanceof SQLIntegrityConstraintViolationException)) {
          throw ex;
        }
      }
    }
  }
Retry and add the latest auto incremented dataset version
@param accountId the id for the parent account.
@param containerId the id of the container.
@param dataset the {@link 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} with the latest auto incremented dataset version
@throws AccountServiceException
@throws SQLException
ambry-account/src/main/java/com/github/ambry/account/mysql/DatasetDao.java