I'm leaning toward the solution to keep writeEntities() all-or-nothing. This gives us two options. 1. Introduce a new writeEntities-like method that doesn't enforce all-or-nothing, so that createEntitiesIfNotExist() can use it. 2. Changing the behavior of "createEntitiesIfNotExist" so that it also enforces all-or-nothing.
I'm slightly leaning toward option 2, given that only tasking creation calls `createEntitiesIfNotExist`, which is easier to modify. Option 1 requires changes from all persistence backends. Yufei On Mon, Nov 30, 2026 at 11:39 AM Serhii Svynarchuk <[email protected]> wrote: > Hi Yufei, > > Thanks for clarifying. I checked the Polaris code and can confirm that > Iceberg’s REST multi-table commit uses > updateEntitiesPropertiesIfNotChanged(). The only production caller of > createEntitiesIfNotExist() I found is the table cleanup handler > < > https://github.com/apache/polaris/blob/6800f2dbab6a2741c84f2702b5b4d25e9751380f/runtime/service/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java#L140-L164 > >. > It dispatches the returned child tasks before deleting the table metadata, > and a retry rebuilds the batch with fresh IDs and names. > > For #6194 <https://github.com/apache/polaris/issues/6194>, would it make > sense to keep writeEntities() all-or-nothing and give > createEntitiesIfNotExist() a separate operation that reuses same-ID > entities and atomically creates all missing ones? That would preserve the > documented behavior across backends and give cleanup a clear guarantee that > every child task is persisted when the call succeeds. > > Thanks, > Serhii Svynarchuk > > On Mon, Nov 30, 2026 at 8:29 PM Yufei Gu <[email protected]> wrote: > > > Thanks for bringing this to the dev mailing list. Copied my response from > > the issue: > > > > I think there are mismatches between writeEntities() > > < > > > https://github.com/apache/polaris/blob/dc8eb486d0c983067369cae2fabf4c38a2af1f59/polaris-core/src/main/java/org/apache/polaris/core/persistence/BasePersistence.java#L97-L132 > > > > > and createEntitiesIfNotExist(). writeEntities() promises an all or > nothing > > commit. The contract for createEntitiesIfNotExist() > > < > > > https://github.com/apache/polaris/blob/dc8eb486d0c983067369cae2fabf4c38a2af1f59/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java#L261-L282 > > > > > allows existing entities with the requested IDs to be reused. For > example, > > if A and B already exist and we request [A, B, C], the documented > behavior > > is to reuse A and B and create C. > > > > Today, both createEntitiesIfNotExist() > > < > > > https://github.com/apache/polaris/blob/dc8eb486d0c983067369cae2fabf4c38a2af1f59/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java#L899-L913 > > > > > and updateEntitiesPropertiesIfNotChanged() > > < > > > https://github.com/apache/polaris/blob/dc8eb486d0c983067369cae2fabf4c38a2af1f59/polaris-core/src/main/java/org/apache/polaris/core/persistence/AtomicOperationMetaStoreManager.java#L966-L995 > > > > > call writeEntities(). updateEntitiesPropertiesIfNotChanged() needs a > > transactional method, which is the right thing here. If we want to > preserve > > the documented behavior of createEntitiesIfNotExist(), it should use a > > separate persistence operation to preserve its documented behavior. We > may > > introduce a nontransactional batch API for that. > > > > As far as I can tell, no REST endpoint calls createEntitiesIfNotExist(). > In > > particular, the Iceberg commitTransaction() handler rejects staged > creates > > < > > > https://github.com/apache/polaris/blob/dc8eb486d0c983067369cae2fabf4c38a2af1f59/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java#L1535-L1541 > > > > > before loading any tables, then commits the pending updates > > < > > > https://github.com/apache/polaris/blob/dc8eb486d0c983067369cae2fabf4c38a2af1f59/runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java#L1604-L1608 > > > > > through updateEntitiesPropertiesIfNotChanged(). The create behavior > > discussed in #6194 <https://github.com/apache/polaris/issues/6194> > > therefore does not affect that endpoint. > > > > > > Yufei > > > > > > On Mon, Nov 30, 2026 at 9:32 AM Serhii Svynarchuk <[email protected]> > > wrote: > > > > > Hi all, > > > > > > While working on issue #6194 < > > > https://github.com/apache/polaris/issues/6194>, > > > I noticed that JDBC and DynamoDB handle createEntitiesIfNotExist > > > differently when only some of the requested entities already exist. > > > > > > Suppose A and B already exist with the requested IDs, C is new, and we > > > call createEntitiesIfNotExist([A, > > > B, C]). > > > > > > - *JDBC* succeeds, reuses A and B, and creates C in one transaction. > > > This matches the current Javadoc and the shared test > > > testCreateEntitiesAlreadyExisting. Javadoc > > > < > > > > > > https://github.com/apache/polaris/blob/main/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManager.java#L261-L278 > > > > > > > - *DynamoDB* returns ENTITY_ALREADY_EXISTS and leaves C absent. > > DynamoDB > > > PR #6144 <https://github.com/apache/polaris/pull/6144> > > > > > > Which behavior should all persistence backends implement? Should the > call > > > succeed by reusing entities with matching IDs and atomically creating > the > > > missing ones, or should it return a conflict and create nothing when > only > > > some of the requested IDs already exist? > > > > > > Thanks, > > > Serhii > > > > > >
