Make entity drop and cleanup task creation atomic#5095
Conversation
There was a problem hiding this comment.
Pull request overview
Implements an atomic persistence operation to drop an entity and create associated cleanup task entities in a single commit/rollback unit, addressing the crash window between “drop” and “schedule cleanup”.
Changes:
- Add
BasePersistence.deleteEntityAndCreateEntities(...)and implement it for transactional persistence and JDBC persistence. - Update
AtomicOperationMetaStoreManagerto use the new atomic operation when scheduling entity cleanup tasks during drops. - Add rollback tests (TreeMap + JDBC) to verify that cleanup task creation failures do not leave the entity dropped or create partial tasks.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| polaris-core/src/testFixtures/java/org/apache/polaris/core/persistence/BasePolarisMetaStoreManagerTest.java | Adds shared assertion verifying rollback behavior when cleanup-task creation fails. |
| polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapAtomicOperationMetaStoreManagerTest.java | Wires the new rollback assertion into the TreeMap atomic metastore test suite. |
| polaris-core/src/main/java/org/apache/polaris/core/persistence/transactional/AbstractTransactionalPersistence.java | Implements deleteEntityAndCreateEntities using a single transactional action. |
| polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java | Introduces the new atomic delete+create persistence API and documents its semantics. |
| polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java | Uses the new atomic operation to make drop + cleanup task scheduling transactional for atomic-operation persistence. |
| persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/AtomicMetastoreManagerWithJdbcBasePersistenceImplTest.java | Wires the new rollback assertion into the JDBC atomic metastore test suite. |
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java | Adds JDBC implementation of the new atomic delete+create API. |
| persistence/nosql/persistence/metastore/src/main/java/org/apache/polaris/persistence/nosql/metastore/NonFunctionalBasePersistence.java | Adds the new method to the non-functional implementation with the existing “use metastore manager” exception behavior. |
006a3f2 to
f74982f
Compare
jbonofre
left a comment
There was a problem hiding this comment.
This is a good PR that fixes correctness.
I would appreciate your thoughts on my comment regarding DropEntityResult.
| for (PolarisBaseEntity entityToCreate : entitiesToCreate) { | ||
| try { | ||
| this.checkConditionsForWriteEntityInCurrentTxn(callCtx, entityToCreate, null); | ||
| } catch (EntityAlreadyExistsException e) { |
There was a problem hiding this comment.
This is a behavior change here, as it can now escape dropEntityIfExists.
Previously, the code ignored the result of createEntityIfNotExists, so a name collision on the cleanup task silently "succeeded".
Now, EntityAlreadyExistsException propagates.
I think it's more "correct", but:
- It's inconsistent with this class's convention of translating
EntityAlreadyExistsExceptioninto a result status. We should consider returning aDropEntityResulterror status instead of throwing a raw persistence exception through the manager API. - The realistic trigger is a concurrent double-drop of the same entity (two cleanup tasks named
entityCleanup_<sameId>with different task ids). The earlier existence check narrows this window but doesn't fully close it. It's worth confirming the REST/service layer degrades gracefully (maps to 409, not 500) rather than leaking a stack trace.
Summary
Implement the
Entity cleanup currently requires two persistence operations:
A crash between these operations can leave a dropped resource without a cleanup task. This change introduces
BasePersistence.deleteEntityAndCreateEntities(...)so both changes are committed or rolled back together.Changes
Atomically drop entities and create cleanup tasks across TreeMap and JDBC, while preserving idempotency. Add rollback tests verifying that task creation failures leave the original entity intact and create no new tasks.
Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)