Skip to content

Persistence: DynamoDB (atomic) entity writes, CAS and name uniqueness - #5892

Merged
flyrain merged 5 commits into
apache:mainfrom
ZephyrYWZhou:dynamodb-atomic-persistence
Nov 7, 2026
Merged

flyrain merged 5 commits into
apache:mainfrom
ZephyrYWZhou:dynamodb-atomic-persistence

Conversation

@ZephyrYWZhou

@ZephyrYWZhou ZephyrYWZhou commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Next step of the optional DynamoDB persistence backend (#5615), building on the skeleton (#5622), the single-table data model (#5707) and the schema + test harness (#5830). This PR adds the first BasePersistence implementation: entity writes, per-entity compare-and-set, and name uniqueness, plus the by-id and by-name lookups.

Still no runtime wiring, so the backend cannot be selected yet. Operations not covered here throw UnsupportedOperationException and land in follow-ups.

Design

DynamoDbBasePersistence runs under the existing AtomicOperationMetaStoreManager. Every correctness decision rides a strongly consistent single-item read or a conditional write:

  • Create — one TransactWriteItems puts the entity item and its name sentinel, both attribute_not_exists, so ids and names stay unique.
  • Update — conditional PutItem, CAS on both entityVersion and grantRecordsVersion (grant changes bump only the latter, same as JDBC).
  • Rename / re-parent — one transaction: CAS the entity, delete the old sentinel, claim the new one.
  • Delete — one transaction: delete the entity (version-checked) and its sentinel.
  • Lookups — strongly consistent GetItem / BatchGetItem; by-name goes through the sentinel, never the GSI.

Failures map to the exceptions the manager already handles:

  • sentinel condition failed → EntityAlreadyExistsException (name collision)
  • entity-id condition failed → EntityAlreadyExistsException with the same id (idempotent create retry)
  • version condition failed → RetryOnConcurrencyException
  • any other cancellation reason (validation, size, throttling) is rethrown as is, not reported as a conflict

A few edge cases are handled explicitly:

  • The manager passes nameOrParentChanged=true on some updates where the name is unchanged; that stays a plain update rather than deleting and re-putting the same sentinel.
  • A sentinel is only deleted if it still points at this entity, so a delete with a stale copy cannot remove a name another entity now owns.
  • Lookups filter on catalog id and type code, matching JDBC.

Changes

  • DynamoDbBasePersistence — entity writes and lookups as above.
  • IdGenerator — positive 63-bit random ids, same as the relational-jdbc generator.
  • TransactionFailures — reads per-action cancellation reasons of a TransactWriteItems, and tells conflicts apart from other failures.
  • DynamoDbBasePersistenceIT — create/read, stale-version rejection, duplicate name, idempotent create, rename and re-parent, rename onto a taken name, delete, the stale-delete case, and batch lookups across chunks with repeated and missing ids, against the Floci harness.
  • TransactionFailuresTest — unit tests for the cancellation-reason mapping.
  • build.gradle.kts — compileOnly(libs.jspecify), as in relational-jdbc.
  • package-info.java — drop the outdated "skeleton only" note.

Testing

./gradlew :polaris-persistence-dynamodb-atomic:spotlessCheck checkstyleMain checkstyleTest checkstyleIntTest compileIntTestJava test javadoc passes. DynamoDbBasePersistenceIT needs Docker and runs in CI (Other Integration Tests), where it passes.

Scope / follow-ups

Next: listEntities / hasChildren (by-name GSI + page token), then writeEntities, then grant records with the by-grantee GSI, then principal secrets, policy mappings and the shared BasePolarisMetaStoreManagerTest, and finally the factory / CDI / config wiring.

Checklist

@ZephyrYWZhou
ZephyrYWZhou marked this pull request as ready for review November 1, 2026 00:35

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, careful first cut. The sentinel-ownership check on delete and the rethrow of non-conflict cancels are both good calls. The main thing to settle is how two failure paths land in AtomicOperationMetaStoreManager: the version-checked delete, and the create 'retry' fallbacks. Details are inline.

Tests: can we add an IT where the entity gets updated between the caller's read and deleteEntity, plus one for an id clash with a different name? A single test through createEntityIfNotExists / dropEntityIfExists would also catch mapping drift before the shared BasePolarisMetaStoreManagerTest arrives.

No CHANGELOG entry is needed while the backend isn't wired. Realm prefixing and the catalog/type filtering on lookups match JDBC.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

@ZephyrYWZhou

Copy link
Copy Markdown
Contributor Author

Finished incorporating ORCA's feedback and polishing the changes. Tagging @flyrain for the next round of review!

@flyrain flyrain 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.

Thanks for the working on it, @ZephyrYWZhou ! Left some comments.

@flyrain flyrain 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 Thanks @ZephyrYWZhou for working on it!

@ZephyrYWZhou

ZephyrYWZhou commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Absolutely @flyrain, thanks for the review and approval! I have opened the issue here - #5985 - and will start working on this before opening next DDB backend PR. Feel free to merge this current PR as well🚀.

@flyrain
flyrain merged commit 18cec3d into apache:main Nov 7, 2026
26 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Nov 7, 2026
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.

3 participants