Skip to content

Commit

Permalink
When rename a deleted dataset version, return not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Guo committed Jan 14, 2025
1 parent 6683f02 commit c14cbba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,17 @@ public void testRenameDatasetVersion() throws Exception {
mySqlAccountStore.getDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
testContainer.getName(), DATASET_NAME_RENAME, sourceVersion);
assertNull("Rename from should be null", datasetVersionRecord.getRenameFrom());

//rename a deleted version should return not found
mySqlAccountStore.deleteDatasetVersion(testAccount.getId(), testContainer.getId(), DATASET_NAME_RENAME, sourceVersion);
targetVersion = "5.5.5.5";
try {
mySqlAccountStore.renameDatasetVersion(testAccount.getId(), testContainer.getId(), testAccount.getName(),
testContainer.getName(), DATASET_NAME_RENAME, renamedSourceVersion, targetVersion);
fail();
} catch (AccountServiceException e) {
assertEquals("Mismatch on error code", AccountServiceErrorCode.NotFound, e.getErrorCode());
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ public DatasetDao(MySqlDataAccessor dataAccessor, MySqlAccountServiceConfig mySq
//copy a dataset version from a source version.
//We need to update the modify time so counter based purge policy won't delete it.
copyToNewDatasetVersionSql = String.format(
"INSERT INTO %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s) SELECT %2$s, %3$s, %4$s, ?, "
+ "%6$s, NOW(3), %8$s, %9$s, ? FROM %1$s WHERE %2$s = ? AND %3$s = ? AND %4$s = ? AND %5$s = ? AND %9$s = ?",
"INSERT INTO %1$s (%2$s, %3$s, %4$s, %5$s, %6$s, %7$s, %8$s, %9$s, %10$s) "
+ "SELECT %2$s, %3$s, %4$s, ?, %6$s, NOW(3), %8$s, %9$s, ? "
+ "FROM %1$s WHERE %2$s = ? AND %3$s = ? AND %4$s = ? AND %5$s = ? AND %9$s = ? "
+ "AND (%8$s IS NULL OR %8$s > NOW(3))",
DATASET_VERSION_TABLE, ACCOUNT_ID, CONTAINER_ID, DATASET_NAME, VERSION, CREATION_TIME, LAST_MODIFIED_TIME,
DELETED_TS, DATASET_VERSION_STATE, RENAME_FROM);
//dataset version has in_progress and ready states.
Expand Down

0 comments on commit c14cbba

Please sign in to comment.