8000 refactor(components): migrate snapshots, fast-path read, and fence queries to storage by andrzejfudro · Pull Request #1402 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

refactor(components): migrate snapshots, fast-path read, and fence queries to storage - #1402

Merged
andrzejfudro merged 2 commits into
mainfrom
refactor/cms-storage-snapshots-and-fence
Oct 28, 2026
Merged

andrzejfudro merged 2 commits into
mainfrom
refactor/cms-storage-snapshots-and-fence

Conversation

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

Summary

  • Moves the single-query component+fence read (GetComponentWithFence) and ownership gauge queries (ReadOwnershipGauges) from SpannerStore into internal/storage/spanner/component.Repository (with codes.Unimplemented stubs in internal/storage/postgres/component.Repository).
  • Extends storage.ComponentTxRepository (internal/storage/spanner/component.TxRepository) with ListActiveComponents, transactional snapshot reads (GetSnapshotByID, GetSnapshotByName), and ownership fence operations (ReadFence, RefreshFence, ReplaceFence, ReassignOwnedComponents), guarding read-write operations against nil transactions with grpcerr.ErrFailedPrecondition.
  • Keeps snapshot dependency derivation (withSnapshotDependencies) in SpannerStore so internal/storage remains independent of pkg/components/store/dependency.

Testing

  • bazel test //internal/storage/spanner/component:component_test //internal/storage/postgres/component:component_test //pkg/components/store/spanner:spanner_test

Assumptions

  • SpannerStore temporarily retains client *spanner.Client and repo *component.Repository (marked with a TODO) to bind TxRepository inside ResolveComponentSnapshot and read-write transactions (DeclareClusterEpoch, SetComponentIntent, PrepareDeactivation, CompleteDeactivation, UpdateObservedGeneration, ExecuteDeletion) until refactor(components): route SpannerStore transactions via Storage and drop SpannerClient #1403 moves component mutations and transactions behind storage.TransactionRunner.

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

@andrzejfudro
andrzejfudro added this pull request to stack #1399 October 23, 2026 12:41
@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 moving Spanner-specific queries and transaction operations—such as ownership fence management, snapshot retrieval, and component reassignment—from the high-level Spanner store into the dedicated component repository. It also updates the storage interfaces and adds corresponding unimplemented stubs to the Postgres repository. The review feedback highlights a critical reliability issue where the newly introduced ReadFence, WriteFence, and ReassignOwnedComponents methods directly access the transaction field r.tx without checking if it is nil, which can lead to nil pointer dereference panics when the repository is bound to a read-only transaction.

@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-snapshots-and-fence branch from ec21b8e to d4a2c17 Compare October 26, 2026 09:54
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-snapshots-and-fence branch from 705569b to 61ef7ca Compare October 28, 2026 08:52
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-snapshots-and-fence branch from 61ef7ca to 75943aa Compare October 28, 2026 09:29
Base automatically changed from refactor/wire-cms-storage-repository to main October 28, 2026 09:41
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-snapshots-and-fence branch from 75943aa to 737d82e Compare October 28, 2026 09:41
@andrzejfudro
Copy link
Copy Markdown
Collaborator Author

/gemini review

@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 storage layer by moving component ownership fence and snapshot operations into the repository layer, specifically updating the ComponentRepository and ComponentTxRepository interfaces. These operations are implemented for the Spanner storage backend, while the Postgres storage backend is updated with unimplemented stubs. Additionally, SpannerStore is refactored to delegate these queries to the updated repository interfaces. I have no feedback to provide on these changes.

@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-snapshots-and-fence branch 2 times, most recently from 00ac183 to 4bf0130 Compare October 28, 2026 10:53
…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
@andrzejfudro
andrzejfudro force-pushed the refactor/cms-storage-snapshots-and-fence branch from 4bf0130 to 2b92d48 Compare October 28, 2026 10:57
@andrzejfudro
andrzejfudro marked this pull request as ready for review October 28, 2026 11:04
Comment thread internal/storage/storage.go Resolved
…torage

- Drop non-transactional GetSnapshotByID and GetSnapshotByName from
  storage.ComponentRepository and Spanner Repository, keeping them only
  on storage.ComponentTxRepository with full contract docs.
- Split WriteFence into RefreshFence(ctx, newName) and ReplaceFence(ctx,
  cluster), moving the rename check into declareClusterEpochTx.
- Clarify ComponentTxRepository doc for read-only bindings and absent
  fence row locking.
- Assert codes.NotFound and grpcerr.ErrFailedPrecondition in repository
  unit tests, and assert StaleOwners, ReassignOwnedComponents count, and
  ReadFence after RefreshFence.

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. Verified all review threads against 1872317: fixes applied cleanly and moved methods preserve their SQL, error, and transaction contracts.

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