Repository navigation
refactor(components): move component marshaling and mutations to storage - #1471
Conversation
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
There was a problem hiding this comment.
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.
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
… 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
|
PR description: Assumptions disclosure ( The Assumptions section says "None", but the PR makes a few deliberate choices that should be listed there:
Could you list these as |
…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
left a comment
There was a problem hiding this comment.
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.
Summary
Move component write payload marshaling, Spanner mutation builders, and transactional component write methods into
internal/storageand switchSpannerStoreto call them directly, deleting inlineproto.Marshaland mutation construction frompkg/components/store/spanner.Key Changes
internal/storage/data): MoveMarshalComponentPayloads,MarshalAccessStatus, andDetermineComponentClassintointernal/storage/datawithout adding a dependency onpkg/components/store.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.ComponentTxRepositoryWrite Contract: AddInsertComponent,UpdateComponentIntent,UpdateComponentState,UpdateComponentObservation,SoftDeleteComponent, andWriteComponentOwnertostorage.ComponentTxRepository, implement them on SpannerTxRepository(stubbed on PostgreSQL), and switchSpannerStoreto use them.Assumptions
codes.Unimplementedin this PR — PostgreSQL component persistence lands in follow-up stack PRs whileexperiment_state_serverkeeps CMS on Spanner orMemoryStore— wiring CMS to PostgreSQL before those PRs land would fail component writes withUnimplemented.InsertComponentandUpdateComponentIntentrequire callers to pre-resolvedepIDs(returningFailedPreconditionon missing keys instead of writing0) —SpannerStorealways runsdependency.ValidateIntentDependenciesfirst — any new caller passing an incompletedepIDsmap will fail withFailedPrecondition.ComponentTxRepositorywrites stamp commit-time columns and clear nullable columns (AccessPayload,ObservedGeneration) toNULLwhen their pointer fields arenil— 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