Skip to content

Add atomic multi-entity and grant-record commit SPI#5035

Open
iprithv wants to merge 3 commits into
apache:mainfrom
iprithv:fix/atomic-entity-grant-commit-spi
Open

Add atomic multi-entity and grant-record commit SPI#5035
iprithv wants to merge 3 commits into
apache:mainfrom
iprithv:fix/atomic-entity-grant-commit-spi

Conversation

@iprithv

@iprithv iprithv commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

AtomicOperationMetaStoreManager grant, revoke, createCatalog, and dropEntity previously performed multiple independent writeEntity / writeToGrantRecords / deleteEntity calls. For JDBC, each call was its own transaction, so a failure mid-sequence could leave partial state (entity without grants, grant without version bumps, catalog without admin role, etc.).

@flyingImer flyingImer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Direction looks right to me. One thing: writeEntitiesAndGrantRecords is new and abstract, but nothing tests that it's actually atomic. Also, I'm thinking writeEntities could just merge into it as a default method, WDYT?

@iprithv
iprithv requested a review from flyingImer July 13, 2026 17:31
iprithv added a commit to iprithv/polaris that referenced this pull request Jul 13, 2026
…I change

As per review feedback, this replaces the broad BasePersistence SPI change
(writeEntitiesAndGrantRecords) with a narrower JDBC-internal fix:

- Remove writeEntitiesAndGrantRecords from BasePersistence (revert SPI change)
- Add BasePersistence.flush() as a default no-op method
- In JdbcBasePersistenceImpl, batch consecutive write operations in a
  ThreadLocal transaction; read operations and flush() commit it
- AtomicOperationMetaStoreManager calls ms.flush() after sequences of
  writes that should be atomic (grant/revoke, createCatalog, dropEntity)

This achieves the same atomicity for JDBC without adding RBAC-specific
methods to the generic persistence SPI. NoSQL/transactional backends
are unaffected since flush() is a no-op for them.

Fixes apache#5035
@iprithv
iprithv force-pushed the fix/atomic-entity-grant-commit-spi branch from 0e34b06 to 0a79a4c Compare July 13, 2026 21:38
@iprithv

iprithv commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@flyingImer thanks for checking, but I've reworked per community feedback...apologies, writeEntities default-method suggestion is no longer needed since that method is gone..

FYI : https://lists.apache.org/thread/hp0y4j30ooztc01n3qz4rm7roczozror from @snazy

* <p>Callers that perform a sequence of write operations that should be atomic should invoke this
* method after the last write in the sequence.
*/
default void flush() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documented contract of BasePersistence says:
Each method in this interface must be atomic, meaning that write operations must either fully succeed with all changes applied, or fail entirely without partial updates.

With that, there must be no "pending changes" left, and no need for some "commit" or "flush."

@iprithv iprithv Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snazy ahh..I get it! flush() was a mistake.. i've reworked to remove flush() and instead add commitChangeSet() to BasePersistence. this new method groups all mutations (entity creates/updates/deletes + grant creates/deletes) into a single atomic call, so each SPI method remains self-contained and atomic. default throws UnsupportedOperationException, so existing backends are unaffected..

Grant operations in AtomicOperationMetaStoreManager now build a ChangeSet internally and use commitChangeSet() when the backend supports it (JDBC), falling back to individual operations otherwise. no more ThreadLocal, no more flush :) thank you for checking this!

@dimas-b

dimas-b commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for looking into this area of the codebase, @iprithv !

From my POV we need a more holistic change to the Persistence SPI and that will probably need a dev discussion before we review specific class changes.

Starting with individual PRs seems like introducing more complexity by trying to address the multi-object change project in narrow areas of the SPI surface. I believe we need to simplity the Persistence SPI by reducing the interface surface and introducing higher level concepts for grouping multiple objects into the same atomic change.

Cf. #4939 (comment)

iprithv added 2 commits July 15, 2026 04:00
…commits

This redesigns the approach to making grant/catalog operations atomic:

- Removed BasePersistence.flush() which violated the per-call atomicity contract
- Added BasePersistence.commitChangeSet() for atomic mixed entity+grant commits
- Added MetaStoreChangeSet, EntityMutation, GrantMutation records
- Added PolarisMetaStoreManager.commitTransactionBatch() as primary mutation path
- Refactored AtomicOperationMetaStoreManager grant ops to use commitChangeSet
- Removed ThreadLocal<Connection> hack from JdbcBasePersistenceImpl
- Each BasePersistence call is now self-contained and atomic
@iprithv

iprithv commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@dimas-b Thanks, I think this revised version aligns with what you were asking for.
Instead of the narrow flush() fix, I've implemented the core of the "ChangeSet-first" direction you outlined in PR #4939 and https://lists.apache.org/thread/rf5orxs815zs4h64p4rwp03q3pbgxb5r

this is still like first step... it doesn't yet refactor all single-entity methods to ride on commitTransactionBatch, and it doesn't unify AtomicOperationMetaStoreManager with TransactionalMetaStoreManagerImpl. but it establishes the API foundation and makes grant operations atomic on JDBC without adding RBAC-specific methods to the SPI.

I also posted a design mail to dev@ to gather broader feedback: https://lists.apache.org/thread/mslr6n7194qsotrlv26wqooo2wggxc8n

WDYT, does this direction work?

@iprithv
iprithv requested a review from snazy July 14, 2026 22:40
@dimas-b

dimas-b commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for pushing Polaris in this direction, @iprithv ! I support the general idea behind this change. However, I think it might be time to have a discussion about this kind of change on dev and work towards a broader consensus. Please give me a bit of time. I hope to be able to send a dev email soon... If this gets delayed, pls ping me 😅

How critical is this change for your use cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants