Skip to content

Polaris persistence mandates the use of transactions & serializable isolation #766

Open

Description

@snazy

Describe the bug

Despite that PolarisMetaStoreSession clearly says that it [is] really easy to back this using [...] simpler KV store. the whole code architecture of everything around persistence in Polaris requires nothing less than (relational) transactions and strong consistency across multiple rows in multiple tables.

For example org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl#writeEntity:

  private void writeEntity(
      @Nonnull PolarisMetaStoreSession ms,
      @Nonnull PolarisBaseEntity entity,
      boolean writeToActive) {
    ms.writeToEntities(entity);
    ms.writeToEntitiesChangeTracking(entity);

    if (writeToActive) {
      ms.writeToEntitiesActive(entity);
    }
  }

works against 2-3 different rows in 2-3 different tables, requiring that all or none of the changes succeed - this is multiplied by the number of entities being written. On top it requires that entities being read before (existing and non-existing) did not change when the tx gets committed.

The "pattern" of having these different tables leaks into a lot of places. It effectively makes it rather impossible to use anything else than a relational database w/ isolation level SERIALIZABLE.

To Reproduce

No response

Actual Behavior

No response

Expected Behavior

No response

Additional context

No response

System information

No response

Activity

  1. added
    bug
    on Jan 15, 2025
  2. dennishuo commented on Jan 23, 2025

    @dennishuo
    Contributor

    The current code structure probably exaggerates the expected transaction semantics needlessly, and a few minor adjustments should be able to significantly lighten the requirements. In particular:

    1. Most of the independent one-shot reads happen to be structured as runInReadTransaction but aren't actually depending on transaction semantics
    2. The writeToEntities, writeToEntitiesChangeTracking, writeToEntitiesActive triplet is actually more for serving the role of secondary indexes than truly being separate tables. There are caveats depending on how we approach vestigial plans for UNDROP functionality, but it's worth discussing whether these make sense to push down to the MetaStoreSession layer and even refactoring the EclipseLink one to better portray these as serving efficient queries on a single table
    3. A few operations actually do uniquely require various flavors of transactions across multiple rows or tables; we should enumerate these separately from the majority of "core" actions. Of particular interest off the top of my head:
      a. CreateCatalog relationship to a "storage integration" object and bootstrapped CatalogRoles
      b. CreatePrincipal with "principal secrets"
      c. Iceberg-level multi-table commit that uses updateEntitiesPropertiesIfNotChanged
      d. DropTable atomically adding a TaskEntity for cleanup (other DropEntity types as well technically, but the main non-trivial case is for file cleanup when PURGE=true)
  3. dennishuo commented on Feb 4, 2025

    @dennishuo
    Contributor

    Wrote up some analysis and tentative proposal for the way forward that should get us pretty far with fairly minimal changes:

    https://docs.google.com/document/d/1U9rprj8w8-Q0SnQvRMvoVlbX996z-89eOkVwWTQaZG0/edit?tab=t.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions