Skip to content

refactor(components): move component marshaling and mutations to storage - #1471

Merged
andrzejfudro merged 5 commits into
mainfrom
refactor/cms-storage-component-mutations
Oct 29, 2026
Merged

andrzejfudro merged 5 commits into
mainfrom
refactor/cms-storage-component-mutations

Conversation

@andrzejfudro

@andrzejfudro andrzejfudro commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Move component write payload marshaling, Spanner mutation builders, and transactional component write methods into internal/storage and switch SpannerStore to call them directly, deleting inline proto.Marshal and mutation construction from pkg/components/store/spanner.

Key Changes

  • Payload Marshaling (internal/storage/data): Move MarshalComponentPayloads, MarshalAccessStatus, and DetermineComponentClass into internal/storage/data without adding a dependency on pkg/components/store.
  • Spanner Mutation Builders (internal/storage/spanner/data): Extract component insert, intent update, state update, observation update, soft-delete, and owner update column/mutation builders with unit tests asserting exact column maps.
  • ComponentTxRepository Write Contract: Add InsertComponent, UpdateComponentIntent, UpdateComponentState, UpdateComponentObservation, SoftDeleteComponent, and WriteComponentOwner to storage.ComponentTxRepository, implement them on Spanner TxRepository (stubbed on PostgreSQL), and switch SpannerStore to use them.

Assumptions

  • PostgreSQL component write methods return codes.Unimplemented in this PR — PostgreSQL component persistence lands in follow-up stack PRs while experiment_state_server keeps CMS on Spanner or MemoryStore — wiring CMS to PostgreSQL before those PRs land would fail component writes with Unimplemented.
  • InsertComponent and UpdateComponentIntent require callers to pre-resolve depIDs (returning FailedPrecondition on missing keys instead of writing 0) — SpannerStore always runs dependency.ValidateIntentDependencies first — any new caller passing an incomplete depIDs map will fail with FailedPrecondition.
  • ComponentTxRepository writes stamp commit-time columns and clear nullable columns (AccessPayload, ObservedGeneration) to NULL when their pointer fields are nil — this matches the nullable schema symmetrically — future backend implementations must honor both invariants.

Verification

  • bazel test //internal/storage/... //pkg/components/... (Passed)
  • ./.githooks/pre-commit (Passed)

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0

Extract backend-agnostic component payload marshaling helpers into
internal/storage/data and Spanner component mutation builders into
internal/storage/spanner/data. Extend storage.ComponentRepository with
WithReadOnlySnapshot and storage.ComponentTxRepository with component write
operations (InsertComponent, UpdateComponentIntent, UpdateComponentState,
UpdateComponentObservation, SoftDeleteComponent, WriteComponentOwner),
implemented in internal/storage/spanner/component with PostgreSQL stubs.

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces transactional component catalog operations across storage implementations, adding new interface methods to ComponentRepository and ComponentTxRepository such as WithReadOnlySnapshot, InsertComponent, and UpdateComponentIntent. It implements these operations for Spanner, provides unimplemented stubs for Postgres, and adds helper functions for marshalling and unmarshalling component payloads. The review feedback suggests enhancing robustness by adding defensive nil checks for the ComponentRecord parameter in several unmarshalling and finalization helpers, as well as checking for a nil callback function in WithReadOnlySnapshot before invocation.

Comment thread internal/storage/data/component.go Resolved
Comment thread internal/storage/data/component.go Resolved
Comment thread internal/storage/data/component.go Resolved
@andrzejfudro
andrzejfudro changed the base branch from main to refactor/cms-storage-snapshots-and-fence October 28, 2026 15:38
@andrzejfudro
andrzejfudro changed the base branch from refactor/cms-storage-snapshots-and-fence to main October 28, 2026 15:47
@andrzejfudro
andrzejfudro added this pull request to stack #1472 October 28, 2026 15:47
Add defensive nil checks for ComponentRecord parameters in UnmarshalConfigProto,
UnmarshalAccessStatus, and FinalizeComponentRecord, and validate that the
callback passed to Repository.WithReadOnlySnapshot is non-nil, with unit test
coverage.

Comment link: #1471 (comment)
Comment link: #1471 (comment)
Comment link: #1471 (comment)
Comment link: #1471 (comment)

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
Switch SpannerStore's component write paths (SetComponentIntent,
PrepareDeactivation, CompleteDeactivation, UpdateObservedGeneration, and
ExecuteDeletion) to ComponentTxRepository write methods backed by
internal/storage/data and internal/storage/spanner/data, deleting inline
proto marshaling and Spanner mutation construction from SpannerStore.

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
@andrzejfudro andrzejfudro changed the title refactor(storage): add component catalog mutations and snapshot runner refactor(components): move component marshaling and mutations to storage Oct 29, 2026
… dep from storage/data

Restore finalizeComponentRecord, UnmarshalConfigProto, and UnmarshalAccessStatus
in internal/storage/spanner/component/repository.go so the read path stays untouched,
and pass primitive/proto fields to MarshalComponentPayloads so internal/storage/data
does not depend on pkg/components/store.

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
@andrzejfudro
andrzejfudro marked this pull request as ready for review October 29, 2026 09:03
Comment thread internal/storage/storage.go Resolved
Comment thread internal/storage/storage.go Resolved
@VLukiantsev

Copy link
Copy Markdown
Collaborator

PR description: Assumptions disclosure (github_authoring_and_prs.md §3)

The Assumptions section says "None", but the PR makes a few deliberate choices that should be listed there:

  • PostgreSQL write support is deferred. The six new ComponentTxRepository write methods return codes.Unimplemented in the PostgreSQL repository, so a Postgres-backed CMS would fail every component write.
  • Dependencies must be resolved before writes. InsertComponent / UpdateComponentIntent now return FailedPrecondition when depIDs lacks a dependency; the old store code silently wrote 0. This is safe today only because dependency.ValidateIntentDependencies / ResolveDependencyIDs always run first.
  • New interface-level semantics. ComponentTxRepository now promises that writes stamp commit-time columns, and that nil access, status or observed-generation values clear the stored column. A future backend has to honour both.

Could you list these as <assumption> — <why> — <impact if wrong> entries?

…and expand mutation tests

Document nil-record, missing-dependency, read-only binding, and nil-to-NULL
column semantics across the six ComponentTxRepository write methods.

Extract pure column-map builders in internal/storage/spanner/data so unit tests
assert exact Spanner column maps, and split UpdateComponentIntent,
UpdateComponentObservation, and SoftDeleteComponent into separate transactions
with full record assertions in repository_test.go.

Comment link: #1471 (comment)
Comment link: #1471 (comment)
Comment link: #1471 (comment)
Comment link: #1471 (comment)

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0

@VLukiantsev VLukiantsev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Re-reviewed fbf308e: the ComponentTxRepository write contracts are documented, the mutation builders and repository round-trips are tested at the column and record level, and the Assumptions section is complete. The refactor preserves the existing Spanner write contract.

@andrzejfudro
andrzejfudro enabled stacked auto-merge October 29, 2026 12:40
@andrzejfudro
andrzejfudro added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 9d1bdbb Oct 29, 2026
14 checks passed
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.

2 participants