Skip to content

refactor(storage): add component read repository and wire into SpannerStore - #1393

Merged
andrzejfudro merged 5 commits into
mainfrom
refactor/extract-cms-spanner-repository
Oct 28, 2026
Merged

andrzejfudro merged 5 commits into
mainfrom
refactor/extract-cms-spanner-repository

Conversation

@andrzejfudro

@andrzejfudro andrzejfudro commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Defines ComponentRepository, ComponentTxRepository, and ComponentStore in internal/storage (storage.Storage and storage.Transaction), wired into internal/storage/spanner, internal/storage/postgres (Unimplemented stub), and storage.MockStorage.
  • Moves the Spanner single-component read SQL queries (GetActiveComponent, GetComponentByID) and row/proto decoding helpers (RowToComponentRecord, UnmarshalConfigProto, UnmarshalAccessStatus) out of pkg/components/store/spanner/spanner_store.go into internal/storage/spanner/component.
  • Updates SpannerStore in pkg/components/store/spanner to delegate GetComponent, 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:

  1. Move Spanner persistence to internal/storage repositories: extract component reads, catalog listing, snapshots, ownership fences, and mutations until the store has no Spanner dependency.
  2. Promote to a database-agnostic store: rename pkg/components/store/spanner to pkg/components/store/dbstore and run the test suite against any backend.
  3. Add PostgreSQL support: prepare internal/storage for PostgreSQL component transactions, then implement PostgreSQL reads and writes with concurrency tests.

Assumptions

  • The repository interfaces use the existing pkg/components/store types (store.ComponentRecord, store.ErrComponentNotFound), so internal/storage now depends on //pkg/components/store — this avoids a parallel set of storage-only component types and conversions — if reviewers prefer internal/storage not to import pkg/, those types have to move into internal/storage/data first.
  • The PostgreSQL component repository returns codes.Unimplemented in 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) — the storage.Storage.Components() and Transaction.Components wiring has no production caller on either backend yet, because SpannerStore still uses the concrete Spanner repository (marked with a TODO) until it moves onto storage.Storage later in this stack, so there is no behavior change.

Testing

  • bazel test //internal/storage/... //pkg/components/...

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

Comment thread pkg/components/store/dbstore/dbstore.go Resolved
Comment thread pkg/components/store/dbstore/dbstore.go Resolved
@andrzejfudro
andrzejfudro force-pushed the refactor/extract-cms-spanner-repository branch from f397398 to 8598d3b Compare October 23, 2026 09:35
@andrzejfudro andrzejfudro changed the title refactor(components): split Spanner persistence out of the CMS component store refactor(cms): move component store reads into a backend-agnostic dbstore Oct 23, 2026
@andrzejfudro
andrzejfudro force-pushed the refactor/extract-cms-spanner-repository branch from 8598d3b to 4852b5b Compare October 23, 2026 10:09
…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
@andrzejfudro
andrzejfudro force-pushed the refactor/extract-cms-spanner-repository branch from 4852b5b to 59afd33 Compare October 23, 2026 11:17
@andrzejfudro andrzejfudro changed the title refactor(cms): move component store reads into a backend-agnostic dbstore refactor(storage): add component read repository and wire into SpannerStore Oct 23, 2026
TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
@andrzejfudro
andrzejfudro added this pull request to stack #1399 October 23, 2026 11:42
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
@andrzejfudro
andrzejfudro marked this pull request as ready for review October 27, 2026 11:38
@andrzejfudro
andrzejfudro marked this pull request as draft October 27, 2026 11:45
@andrzejfudro
andrzejfudro requested review from VLukiantsev and removed request for VLukiantsev October 27, 2026 11:45
@andrzejfudro
andrzejfudro marked this pull request as ready for review October 27, 2026 11:51
Comment thread internal/storage/storage.go Resolved
@andrzejfudro
andrzejfudro force-pushed the refactor/extract-cms-spanner-repository branch from e0b245a to 96f9b57 Compare October 27, 2026 16:32
- 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
@andrzejfudro
andrzejfudro force-pushed the refactor/extract-cms-spanner-repository branch from 96f9b57 to e0a0354 Compare October 27, 2026 16:46
@VLukiantsev

Copy link
Copy Markdown
Collaborator

One small out-of-diff observation (not postable inline since the line is unchanged):

  • pkg/components/store/spanner/spanner_store.go L88: spannerQueryable now duplicates the newly exported component.Queryable (internal/storage/spanner/component/repository.go). Not worth changing in this PR. It should disappear along with the TODO on SpannerStore.repo once the remaining Spanner reads move out of the store, but please fold it into that follow-up rather than leaving two identical interfaces.

VLukiantsev
VLukiantsev previously approved these changes Oct 28, 2026

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

@github-actions github-actions 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.

🤖 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.

@andrzejfudro
andrzejfudro enabled stacked auto-merge October 28, 2026 09:28
@andrzejfudro
andrzejfudro added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 3b13e54 Oct 28, 2026
14 checks passed
andrzejfudro added a commit that referenced this pull request Oct 28, 2026
…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
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