Skip to content

Replace transaction metastore wrapper with explicit buffering - #5088

Open
flyrain wants to merge 2 commits into
apache:mainfrom
flyrain:refactor/explicit-transaction-update-buffer
Open

flyrain wants to merge 2 commits into
apache:mainfrom
flyrain:refactor/explicit-transaction-update-buffer

Conversation

@flyrain

@flyrain flyrain commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Why

TransactionWorkspaceMetaStoreManager implemented the entire metastore interface even though it only buffered one write operation. Nearly every other method threw, and its delegate was unused. This made a catalog-specific transaction detail look like a general persistence implementation and coupled it to every change in PolarisMetaStoreManager.

The new TableCommitActions abstraction represents only the side effects produced by a table commit: table-entity updates and metadata-file cleanup. Its direct implementation applies those actions immediately, while its buffered implementation collects them for an atomic multi-table commit.

What changed

  • Replaced TransactionWorkspaceMetaStoreManager with package-private TableCommitActions, using direct and buffered implementations for normal and multi-table commits.
  • Kept the real PolarisMetaStoreManager immutable and removed transaction-mode branches from the entity-update and metadata-cleanup call sites.
  • Preserved the existing rejection behavior for location-overlap validation during a buffered multi-table commit.
  • Added coverage for buffered entity updates, deferred metadata cleanup, and the preserved overlap-validation failure.

Checklist

  • 🛡️ Don't disclose security issues! (contact [email protected])
  • 🔗 Clearly explained why the changes are needed, or linked related issues: no related issue
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (not needed; no intended user-visible behavior change)
  • 📚 Updated documentation in site/content/in-dev/unreleased (not needed; no API or configuration change)

@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jul 17, 2026
@flyrain
flyrain marked this pull request as ready for review July 17, 2026 22:05
Copilot AI review requested due to automatic review settings July 17, 2026 22:05
@flyrain
flyrain requested review from dimas-b and singhpk234 July 17, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Iceberg multi-table transaction handling by removing the broad TransactionWorkspaceMetaStoreManager wrapper and replacing it with an explicit, Iceberg-scoped buffering object (PendingTableCommit) to collect deferred entity updates and metadata-file cleanups during commitTransaction.

Changes:

  • Introduces PendingTableCommit to buffer table-commit side effects (entity updates + metadata cleanups) until validations succeed.
  • Updates LocalIcebergCatalog and IcebergCatalogHandler.commitTransaction to use explicit buffering instead of swapping the metastore manager.
  • Updates/extends tests to validate deferred cleanup behavior and preserved location-overlap rejection behavior during a pending commit.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/PendingTableCommit.java Adds a package-private collector for buffered entity updates and deferred metadata cleanups.
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/LocalIcebergCatalog.java Buffers entity updates and metadata cleanup when a pending commit is set; preserves overlap-validation rejection behavior.
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java Uses PendingTableCommit in commitTransaction and replays buffered persistence + cleanup after validation.
runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractLocalIcebergCatalogTest.java Updates tests to assert buffering/replay behavior via PendingTableCommit.
runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractLocalIcebergCatalogOverlapTest.java Adds coverage that overlap-check failure behavior is preserved under a pending commit.
polaris-core/src/main/java/org/apache/polaris/core/persistence/TransactionWorkspaceMetaStoreManager.java Removes the metastore-wrapper implementation in favor of explicit buffering at the call sites.

Comment on lines +1445 to 1449
// Buffer the entity updates and metadata-file cleanups produced by each table commit. The
// entity updates are persisted as a single atomic unit after all validations succeed.
PendingTableCommit pendingTableCommit = new PendingTableCommit();
((LocalIcebergCatalog) baseCatalog).setPendingTableCommit(pendingTableCommit);

@dimas-b dimas-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like a reasonable refactoring to me. Thanks, @flyrain !

deleteRemovedMetadataFiles.accept(new MetadataFileCleanup(io(), base, metadata));
MetadataFileCleanup cleanup = new MetadataFileCleanup(io(), base, metadata);
if (pendingTableCommit != null) {
pendingTableCommit.addPendingMetadataFileCleanup(cleanup);

@dimas-b dimas-b Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This and similar (new) if/else blocks complicate the processing logic. How about renaming PendingTableCommit to CatalogEntityUpdater and making two implementations:

  1. calling through to metaStoreManager for single entity changes.
  2. collecting updates and metadata cleanup for multi-table commits.

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.

Hi @dimas-b, that's a good point. The conditional block isn't that elegant. What you suggest also makes sense. That's actually my first version. But I intentionally switch it to back to this version due to at least one or two additional classes/interfaces added. I thought maybe this is maybe simpler, given there are only two places needing it. And we can always abstract later by introducing the interface, etc. WDYT?

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.

Made this change by introducing a new interface and two impl. for different behaviors. I'm OK with both. I think the first version is actually a bit simpler. Let me know if you strongly prefer one over another.

@dimas-b dimas-b left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 to introducing TableCommitActions

this.deleteRemovedMetadataFiles =
deleteLogic != null ? deleteLogic : LocalIcebergCatalog::defaultDeleteRemovedMetadataFiles;
/** Restores immediate persistence and metadata-file cleanup for table commits. */
void resetTableCommitActions() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this method is rather confusing. The local catalog object should not be shared between operations that have different "table commit" semantics.

Currently it's called only from test code, but those tests also pass without this method, I believe.

realmConfig.getConfig(FeatureConfiguration.OPTIMIZED_SIBLING_CHECK);
if (tableCommitActions instanceof BufferedTableCommitActions) {
String methodName = useOptimizedSiblingCheck ? "hasOverlappingSiblings" : "listEntities";
throw diagnostics.fail("illegal_method_in_transaction_workspace", methodName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This logic looks odd in the current codebase 🤔 Why do we need this?

}

@Test
public void testBufferedTableCommitActionsPreserveOptimizedLocationOverlapFailure() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what this test validates? Does it mean that IcebergCatalogHandler.commitTransaction() never called this method?

}

List<MetadataFileCleanup> pendingMetadataFileCleanups() {
return List.copyOf(pendingMetadataFileCleanups);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps we should move the batched call to CatalogUtil.deleteRemovedMetadataFiles() here to be symmetric with DirectTableCommitActions? WDYT?

}

List<EntityWithPath> pendingUpdates() {
return List.copyOf(pendingUpdates);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also maybe move updateEntitiesPropertiesIfNotChanged() calls and matching "clean up" call here too?

this.storageAccessConfigProvider = storageAccessConfigProvider;
this.fileIOFactory = fileIOFactory;
this.metaStoreManager = metaStoreManager;
this.directTableCommitActions = new DirectTableCommitActions(metaStoreManager);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A fresh LocalIcebergCatalog is created for each REST API call, including IcebergCatalogHandler.commitTransaction().

Ideally, the type of tableCommitActions to use should trickle down through the call chain as it is specific to overarching operation as a whole.

If you agree, this can be deferred to keep this PR's diff smaller.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the stale label Aug 20, 2026
@github-actions github-actions Bot closed this Aug 25, 2026
@github-project-automation github-project-automation Bot moved this from PRs In Progress to Done in Basic Kanban Board Aug 25, 2026
@flyrain flyrain reopened this Aug 25, 2026
@github-project-automation github-project-automation Bot moved this from Done to PRs In Progress in Basic Kanban Board Aug 25, 2026
@github-actions github-actions Bot removed the stale label Aug 28, 2026
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants