Repository navigation
refactor(storage): add component read repository and wire into SpannerStore - #1393
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Cloud Spanner component store by separating the backend-agnostic catalog rules and business logic into a new dbstore package, while leaving the database-specific queries and mutations in a Spanner component repository. This improves modularity and allows for potential alternative database backends. The review feedback highlights several critical improvements: correcting a sentinel error check in dbstore.go to use errors.Is, removing a backend-specific hardcoded error message from the generic dbstore package, and properly handling ignored errors from dependency resolution functions during deactivation and deletion operations.
f397398 to
8598d3b
Compare
8598d3b to
4852b5b
Compare
…rStore Define ComponentRepository, ComponentTxRepository, and ComponentStore in internal/storage and wire them into storage.Storage, storage.Transaction, internal/storage/spanner, internal/storage/postgres (Unimplemented stub), and MockStorage. Move the Spanner single-component read queries (GetActiveComponent, GetComponentByID) and row/proto decoding helpers out of pkg/components/store/spanner/spanner_store.go into internal/storage/spanner/component, and update SpannerStore read paths (GetComponent, GetComponentByID, ValidateComponentRequirement, UpdateObservedGeneration, ResolveComponentSnapshot) to delegate to the component repository. TAG=agy CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
4852b5b to
59afd33
Compare
TAG=agy CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
Document that component reads return store.ErrComponentNotFound itself on a miss and return active dependencies sorted by name, so other backends match what the component store relies on. TAG=agy CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
e0b245a to
96f9b57
Compare
- Declare ComponentTxRepository as its own interface with its methods listed explicitly instead of aliasing ComponentRepository. - Split the Spanner component repository into Repository, which reads from a new read-only transaction of its client, and TxRepository, which reads within the transaction bound by WithTx, sharing unexported read functions; a missing client or transaction returns an error instead of a nil dereference. - Split fetchDependencies, scanSourceOwner, decodeComponentPayloads and finalizeComponentRecord out of queryComponentWithDeps and RowToComponentRecord, as on main. - Add unit tests for RowToComponentRecord decoding (legacy ComponentSpec config, corrupt config, empty status, observed generation, owner, deleted rows), reads through a read-only transaction, and the nil client or transaction errors. - Mark the temporary concrete repository dependency of SpannerStore with a TODO. TAG=agy CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
96f9b57 to
e0a0354
Compare
|
One small out-of-diff observation (not postable inline since the line is unchanged):
|
VLukiantsev
left a comment
There was a problem hiding this comment.
LGTM. Verified the follow-ups in e0a0354 (distinct ComponentTxRepository, Repository/TxRepository split with nil guards, restored helpers, RowToComponentRecord unit tests, TODO + reworded Assumptions). The dependency sort-order test nit is optional.
…itory test Add a second active dependency (`auth`, with ComponentId 4 > `db`'s ComponentId 2) to `seedCatalog` so `GetActiveComponent` and `GetComponentByID` exercise `ORDER BY dep.Name ASC`. TAG=agy CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
There was a problem hiding this comment.
🤖 Incremental PR Approval
PR author is a code owner and changes since last approval (0 lines, excluding 5 test file lines) are within the 50-line grace delta.
Preserving prior approval by @VLukiantsev on commit e0a0354.
…eries to storage Move historical snapshot reads (GetSnapshotByID, GetSnapshotByName), fast-path component+fence read (GetComponentWithFence), ownership gauge queries (ReadOwnershipGauges), and transactional ownership fence primitives (ReadFence, WriteFence, ReassignOwnedComponents) out of SpannerStore into internal/storage/spanner/component (with PostgreSQL Unimplemented stubs), deriving snapshot dependencies in SpannerStore outside the storage layer. Follow the Repository/TxRepository split from #1393 and guard ReadFence, WriteFence, and ReassignOwnedComponents against nil read-write transactions. TAG=agy CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
Summary
ComponentRepository,ComponentTxRepository, andComponentStoreininternal/storage(storage.Storageandstorage.Transaction), wired intointernal/storage/spanner,internal/storage/postgres(Unimplementedstub), andstorage.MockStorage.GetActiveComponent,GetComponentByID) and row/proto decoding helpers (RowToComponentRecord,UnmarshalConfigProto,UnmarshalAccessStatus) out ofpkg/components/store/spanner/spanner_store.gointointernal/storage/spanner/component.SpannerStoreinpkg/components/store/spannerto delegateGetComponent,GetComponentByID,ValidateComponentRequirement, and transactional single-component lookups (UpdateObservedGeneration,ResolveComponentSnapshot) to the storage component repository.Overall Stack Plan
This PR starts a stack that decouples the CMS component store from Spanner and adds PostgreSQL support, keeping catalog domain logic shared in one store:
internal/storagerepositories: extract component reads, catalog listing, snapshots, ownership fences, and mutations until the store has no Spanner dependency.pkg/components/store/spannertopkg/components/store/dbstoreand run the test suite against any backend.internal/storagefor PostgreSQL component transactions, then implement PostgreSQL reads and writes with concurrency tests.Assumptions
pkg/components/storetypes (store.ComponentRecord,store.ErrComponentNotFound), sointernal/storagenow depends on//pkg/components/store— this avoids a parallel set of storage-only component types and conversions — if reviewers preferinternal/storagenot to importpkg/, those types have to move intointernal/storage/datafirst.codes.Unimplementedin this PR — it keeps the PR under the size limit; the PostgreSQL reads and writes land later in this stack (feat(storage): implement PostgreSQL component repository reads #1417, feat(storage): implement PostgreSQL component writes and run the dbstore suite on PostgreSQL #1418) — thestorage.Storage.Components()andTransaction.Componentswiring has no production caller on either backend yet, becauseSpannerStorestill uses the concrete Spanner repository (marked with aTODO) until it moves ontostorage.Storagelater in this stack, so there is no behavior change.Testing
bazel test //internal/storage/... //pkg/components/...TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0