Repository navigation
Core: Report a rename that loses the race for its name as ENTITY_ALREADY_EXISTS - #5986
Conversation
orca-review-bot
left a comment
There was a problem hiding this comment.
Nice small fix. The rename now reports ENTITY_ALREADY_EXISTS the same way create does, and the mapping lives at the right layers: JDBC turns the SQL error into a domain exception, and core turns that into a status. I checked that lookupEntityByName uses its own connection (executeSelect without the caller's connection), so it's safe after Postgres aborts the failed UPDATE, same as on the create path.
One test gap: nothing covers the new update-path RetryOnConcurrencyException branch (JdbcBasePersistenceImpl.java:277). Can we parameterize writeEntity_uniquenessViolationWithInvisibleConflict_throwsRetryOnConcurrencyException over insert vs. update so that branch gets hit too?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| originalEntity.getGrantRecordsVersion()); | ||
| } | ||
| } catch (SQLException e) { | ||
| if (datasourceOperations.isUniquenessConstraintViolation(e)) { |
There was a problem hiding this comment.
This block is nearly the same as the insert-path handler a few lines up. The only difference is the extra getId() != entity.getId() check. The visibility handling already changed once (#5094), and next time it'd be easy to update only one copy. Can we pull it into a small private helper that both branches call?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
There was a problem hiding this comment.
Good call on that, let me create a shared helper method for it.
…t the update path
flyrain
left a comment
There was a problem hiding this comment.
+1 Thanks @ZephyrYWZhou !
jbonofre
left a comment
There was a problem hiding this comment.
Thanks for the fix! The change is well scoped and an improvement: a rename that loses the race for its destination name now return ENTITY_ALREADY_EXISTS, the same as the create path, instead of failing with a generic error.
Summary
AtomicOperationMetaStoreManager.renameEntity()checks that the destination name is free, then writes the renamed entity. If another writer claims that name in between, the write fails on the name constraint.renameEntity()only caughtRetryOnConcurrencyException, so this race surfaced as an unhandled error instead ofENTITY_ALREADY_EXISTS. A create in the same situation already returnsENTITY_ALREADY_EXISTS.Raised by @flyrain in #5892.
Changes
AtomicOperationMetaStoreManager.renameEntity(): mapEntityAlreadyExistsExceptiontoENTITY_ALREADY_EXISTS, aspersistNewEntitydoes.JdbcBasePersistenceImpl.writeEntity(): on the update path, translate a uniqueness violation intoEntityAlreadyExistsException, matching the create path. Before this, it was wrapped into a genericRuntimeException. If the conflicting entity is not visible in the snapshot, it raisesRetryOnConcurrencyException, same as the create path.Testing
JdbcBasePersistenceImplTest.writeEntity_renameOntoTakenName_throwsEntityAlreadyExistsException(H2): renaming onto a taken name throwsEntityAlreadyExistsExceptionand leaves the entity unchanged. It fails without the JDBC change.AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.renameThatLosesTheRaceForItsNameReportsAlreadyExists: hides the taken name from the pre-check, as if another writer claimed it right after, and checks thatrenameEntity()returnsENTITY_ALREADY_EXISTS. Runs in the Postgres IT../gradlew :polaris-core:test :polaris-relational-jdbc:testplus spotless and checkstyle pass locally. The Postgres IT needs Docker and is expected to run in CI.Checklist