8000 refactor(components): route SpannerStore transactions via Storage and drop SpannerClient by andrzejfudro · Pull Request #1403 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

refactor(components): route SpannerStore transactions via Storage and drop SpannerClient - #1403

Merged
andrzejfudro merged 3 commits into
refactor/cms-storage-component-mutationsfrom
refactor/cms-storage-mutations-and-tx
Oct 29, 2026
Merged

andrzejfudro merged 3 commits into
refactor/cms-storage-component-mutationsfrom
refactor/cms-storage-mutations-and-tx

Conversation

@andrzejfudro
@andrzejfudro andrzejfudro commented Oct 23, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Route every SpannerStore read-only snapshot and read-write transaction through storage.Storage (including commit-timestamp reporting via RunInTransactionWithCommitTime) and drop *spanner.Client exposure from NewSpannerStore, factory.Storage, and ProdServer.

Key Changes

  • Commit-Timestamp Transaction Runner (internal/storage): Add RunInTransactionWithCommitTime to TransactionRunner (returning the Spanner commit timestamp on Spanner, codes.Unimplemented on PostgreSQL, and MockStorage.CommitTime in tests) and WithReadOnlySnapshot to ComponentRepository.
  • Storage-Backed SpannerStore (pkg/components/store/spanner): Switch SpannerStore and ownership fencing onto storage.Storage (RunInTransaction, RunInTransactionWithCommitTime, WithReadOnlySnapshot) and drop the *spanner.Client constructor parameter without post-commit read-backs.
  • Factory & ESS Wiring (internal/storage/factory, cmd/experiment_state_server): Remove SpannerClient from factory.Storage and ProdServer, expose ProdServer.StorageBackend(), and gate NewSpannerStore(st) in initCMS on st != nil && backend == dbconfig.BackendSpanner so non-Spanner backends keep the MemoryStore fallback until PostgreSQL component writes land.

Assumptions

Verification

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

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

@andrzejfudro
andrzejfudro added this pull request to stack #1399 October 23, 2026 12:58
@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 component storage layer by abstracting Spanner-specific mutations out of the generic SpannerStore and into the repository layer, introducing new transaction interfaces and post-commit callbacks. The review feedback highlights several safety issues in the newly added Spanner mutations, including a potential nil pointer dereference on rec.ObservedGeneration, a potential marshaling failure with nil access payloads in UpdateComponentState, and missing map existence checks when retrieving dependency IDs in InsertComponent and UpdateComponentIntent.

@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-mutations-and-tx branch from ea460df to 8e21889 Compare October 23, 2026 13:56
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-mutations-and-tx branch from 8e21889 to 97b4309 Compare October 26, 2026 10:02
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-mutations-and-tx branch 2 times, most recently from 4336cbb to 488ca69 Compare October 28, 2026 12:10
Base automatically changed from refactor/cms-storage-snapshots-and-fence to main October 28, 2026 13:14
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-mutations-and-tx branch 2 times, most recently from 54b5e04 to 8c22527 Compare October 28, 2026 15:32
@andrzejfudro andrzejfudro changed the title refactor(components): migrate component mutations and transactions to storage refactor(components): wire SpannerStore through storage.Storage Oct 28, 2026
@andrzejfudro
andrzejfudro removed this pull request from stack #1399 October 28, 2026 15:46
@andrzejfudro
andrzejfudro changed the base branch from main to refactor/cms-storage-component-mutations October 28, 2026 15:47
@andrzejfudro
andrzejfudro added this pull request to stack #1472 October 28, 2026 15:47
@andrzejfudro andrzejfudro changed the title refactor(components): wire SpannerStore through storage.Storage refactor(components): route SpannerStore transactions via Storage and drop SpannerClient Oct 29, 2026
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-mutations-and-tx branch 2 times, most recently from ae58678 to 0c35d3d Compare October 29, 2026 11:33
… drop SpannerClient

Add RunInTransactionWithCommitTime to storage.TransactionRunner and
WithReadOnlySnapshot to storage.ComponentRepository so SpannerStore and
ownership fencing run all read-only snapshots and read-write transactions
through storage.Storage without post-commit read-backs.

Remove the *spanner.Client parameter from NewSpannerStore, drop SpannerClient
from factory.Storage and ProdServer, and wire initCMS to construct SpannerStore
whenever Storage is initialized.

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-mutations-and-tx branch from 0c35d3d to a7090a4 Compare October 29, 2026 11:50
@andrzejfudro
andrzejfudro marked this pull request as ready for review October 29, 2026 11:52
Comment thread cmd/experiment_state_server/main.go Resolved
Comment thread internal/storage/README.md Resolved
Comment thread internal/storage/postgres/storage.go Resolved
…e contract

Document RunInTransactionWithCommitTime, ComponentRepository.WithReadOnlySnapshot,
and MockStorage.CommitTime in internal/storage/README.md, clarify the
storage.Storage requirements on NewSpannerStore, and align the PostgreSQL
RunInTransactionWithCommitTime stub comment with #1416.

TAG=agy
CONV=5d43b8db-2f9c-4908-a311-376a2b7dfdf0
@andrzejfudro
andrzejfudro enabled stacked auto-merge October 29, 2026 12:40
VLukiantsev
VLukiantsev previously approved these changes Oct 29, 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, approving on the condition that the CMS store-selection thread on cmd/experiment_state_server/main.go is addressed with one of the proposed low-effort options before merge (see discussion_r4412578759). Thanks for the quick doc fixes.

…ndSpanner

Keep MemoryStore fallback for non-Spanner backends in initCMS until
PostgreSQL component writes land (#1418), and add the Postgres fallback
case to TestInitCMS_StoreSelection.

Comment link: #1403 (comment)

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 (24 lines, excluding 43 test file lines) are within the 50-line grace delta.

Preserving prior approval by @VLukiantsev on commit afb984f.

@andrzejfudro
andrzejfudro added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit eafcf5d 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

0