8000 feat(rod): read jobs and allocations from one read-only snapshot by janzak-dev · Pull Request #1598 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

feat(rod): read jobs and allocations from one read-only snapshot - #1598

Draft
janzak-dev wants to merge 3 commits into
feat/rod-user-alloc-backend-storagefrom
feat/rod-user-alloc-backend-snapshot
Draft

janzak-dev wants to merge 3 commits into
feat/rod-user-alloc-backend-storagefrom
feat/rod-user-alloc-backend-snapshot

Conversation

@janzak-dev
@janzak-dev janzak-dev commented Nov 6, 2026 •
Copy link
Copy Markdown
Collaborator

Note

Stacked PR (part of #1515): per-user "dominant resource" allocation on /resources. Every layer has a production caller and tests. Unfinished backend pieces return empty data, never placeholder values.

Backend: endpoint and RPC presenting correct information

  1. feat(rod): add per-user allocations to GetRunningAndPendingJobs #1595 Proto user_allocations + handler mapping from the per-author storage contract. The handler is the producer; storage returns no rows yet, so the field is empty.
  2. feat(storage): aggregate active resources per author in Spanner and Postgres #1597 Spanner + Postgres aggregation. The field is populated from here on.
  3. feat(rod): read jobs and allocations from one read-only snapshot #1598 Jobs page and aggregation read from one read-only snapshot.

Frontend: UI presents correct data
4. #1599 Per-user allocation bar on /resources (the consumer of userAllocations).

Summary

GetRunningAndPendingJobs now reads the jobs page and the per-author aggregation from one read-only snapshot, so user_allocations and the jobs page always describe the same queue state. After this PR the RPC returns correct, consistent data.

Motivation & Context

The final backend layer. In the previous PR the two reads use separate transactions, so a job changing state between them could make the allocations disagree with the jobs page.

Key Changes

  • internal/storage/storage.go: WorkUnitSnapshotRepository (FetchActiveWorkUnitsByQueues and AggregateActiveResourcesByAuthor) plus WorkUnitStore.WithReadOnlyWorkUnitSnapshot. The repository-level aggregation moves into the snapshot repository.
  • Spanner: a ReadOnlyTransaction-bound snapshot repository. FetchActiveWorkUnitsByQueues delegates to it; existing comments are kept.
  • Postgres: pgdb.RunInReadOnlyTx (REPEATABLE READ READ ONLY) hands fn the existing TxRepository (via WithTx), which gains the two read methods; FetchActiveWorkUnitsByQueues delegates to it.
  • jobs.go: fetchJobsAndAllocations runs both reads inside WithReadOnlyWorkUnitSnapshot. WorkUnitFetcher narrows to WithReadOnlyWorkUnitSnapshot, and MockStorage passes itself as the snapshot repository.
  • Docs: section 5 notes the single snapshot.

Assumptions

None — requirements were fully specified (caller-managed read-only transaction per internal/storage/AGENTS.md).

Verification & Testing

  • Spanner emulator and Postgres tests share storagetest.VerifyActiveResourcesSnapshot: the first jobs page (2 of 6 active work units) and the aggregation come from the same snapshot. Existing FetchActiveWorkUnitsByQueues pagination and ordering tests still pass, and a handler test checks there is exactly one snapshot per request.
  • bazel test //internal/storage/... //cmd/rod_data_provider/...: all pass. ./.githooks/pre-commit passes.
  • Live GKE development environment (dev deployment script), read-only gRPC check of every cluster queue: user_allocations equals the per-user sum of requested units over all pages of jobs. For example, a 14-job CPU queue returned cpu 0 running + 1002 pending and memory 0 + 7 GiB, and with page_size=5 every page returned the same totals.

Related Issues / Bugs

Part of #1515

TAG=agy
CONV=4ed50232-a6f2-4c76-aa6f-ef1c3833a550

@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 to ensure that active work unit fetching and resource aggregation are executed within a single, consistent read-only snapshot. It introduces the WithReadOnlyWorkUnitSnapshot method to the WorkUnitStore interface and implements it for both PostgreSQL and Spanner backends, replacing the separate AggregateActiveResourcesByAuthor method. Corresponding updates have been made to the data provider server, mock implementations, unit tests, and documentation. I have no feedback to provide as there are no review comments.

@janzak-dev
janzak-dev force-pushed the feat/rod-user-alloc-backend-snapshot branch from af6d17b to 6f28728 Compare November 6, 2026 13:10
@janzak-dev
janzak-dev removed this pull request from stack #1600 November 6, 2026 13:49
@janzak-dev
janzak-dev force-pushed the feat/rod-user-alloc-backend-snapshot branch from 6f28728 to b3804ed Compare November 6, 2026 13:55
@janzak-dev
janzak-dev added this pull request to stack #1607 November 6, 2026 13:55
@janzak-dev
janzak-dev force-pushed the feat/rod-user-alloc-backend-snapshot branch from b3804ed to 53276a3 Compare November 6, 2026 14:36
Add WorkUnitStore.WithReadOnlyWorkUnitSnapshot and the
WorkUnitSnapshotRepository it hands to callers, implemented with a
Spanner ReadOnlyTransaction and a Postgres REPEATABLE READ READ ONLY
transaction. GetRunningAndPendingJobs now reads the jobs page and the
per-author aggregation from the same snapshot, so user_allocations and
the jobs page always describe the same queue state.
FetchActiveWorkUnitsByQueues delegates to the snapshot, and the
standalone repository-level aggregation is folded into it.

Bug: 582253355
TAG=agy
CONV=4ed50232-a6f2-4c76-aa6f-ef1c3833a550
…ository

The Postgres snapshot now hands fn the existing TxRepository (via WithTx)
instead of a second transaction-bound wrapper. The Spanner and Postgres
snapshot tests share storagetest.ReadActiveResourcesSnapshot and its
verify helpers instead of duplicated snapshot plumbing, and drop guard
assertions already covered by FetchActiveWorkUnitsByQueues, which runs
through the same snapshot.

Bug: 582253355
TAG=agy
CONV=4ed50232-a6f2-4c76-aa6f-ef1c3833a550
- WorkUnitFetcher only needs WithReadOnlyWorkUnitSnapshot now that the
  handler reads the jobs page through the snapshot repository.
- Unexport readActiveResourcesSnapshot, which only the storagetest
  verify helpers use, and drop a compile-time assertion the snapshot
  call site already enforces.

Bug: 582253355
TAG=agy
CONV=4ed50232-a6f2-4c76-aa6f-ef1c3833a550
@janzak-dev
janzak-dev force-pushed the feat/rod-user-alloc-backend-snapshot branch from 53276a3 to 6ca8a84 Compare November 6, 2026 15:17

This branch has not been deployed

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

1 participant

0