Skip to content

DynamoDB (atomic): keep a strongly consistent child record in the base table for listing #6119

Closed

Description

@ZephyrYWZhou

Background

The DynamoDB (atomic) backend (#5615) lists a parent's children through the gsi1 global secondary index (gsi1pk = realmId#catalogId#parentId#typeCode, gsi1sk = the padded entity id, from #6006). A GSI is eventually consistent, and DynamoDB does not allow a strongly consistent read on one.

The problem

Some listings drive a correctness decision, not just discovery:

  • a namespace drop checks whether the namespace is empty;
  • location-overlap validation checks for a sibling.

Because gsi1 can lag, a create that already completed may be missing from the index for a moment. So a drop can wrongly treat a non-empty namespace as empty, and overlap validation can miss a newly created sibling. This happens even for sequential requests, so it is not covered by the existing concurrency TODO. (Raised by @flyrain on #6016.)

Proposed fix

Keep a strongly consistent child record in the base table, so listing can read children with ConsistentRead=true instead of the lagging index.

  • A child record keyed by the parent's coordinates (realmId#catalogId#parentId#typeCode) with the child id in the sort key (CHILD#<padded-id>), payload is the child id.
  • Written in the same TransactWriteItems as the entity: added on create, moved on re-parent, removed on delete. A pure rename leaves it in place, since it is keyed by parent and id, not name.

This PR is the write side only. gsi1 and listing are unchanged here; a follow-up (reworking #6016) switches listEntities/hasChildren to a base-table Query with ConsistentRead=true and removes gsi1. The child record has to exist before listing can read it, hence the split.

Acceptance Criteria

  1. A create writes a child record in the base table, in the same transaction as the entity.
  2. A re-parent moves the child record; a pure rename leaves it in place.
  3. A delete removes the child record.
  4. gsi1 and the listing paths are unchanged in this PR.

Related: #5615, #6016, #6006

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions