Skip to content

feat(storage): queue-leading primary keys with row-level cross-queue isolation - #537

Merged
behinddwalls merged 1 commit into
mainfrom
preetam/queue-leading-schema
Aug 6, 2026
Merged

feat(storage): queue-leading primary keys with row-level cross-queue isolation#537
behinddwalls merged 1 commit into
mainfrom
preetam/queue-leading-schema

Conversation

@behinddwalls

@behinddwalls behinddwalls commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Why?

The factory contract made queue-scoped storage instances the only way in, but the schema still let a bound instance reach another queue's rows: request, batch, build, batch_dependent, and request_batch were keyed by bare IDs. Leading every queue-scoped table's primary key with queue makes the binding real at the row level and leaves every table shardable by queue — cheap now (pre-prod, tables recreated), expensive to retrofit later.

What?

request and batch move to (queue, id), build to (queue, id) with a new queue column, batch_dependent to (queue, batch_id), and request_batch to (queue, request_id, batch_id); change, queue_batch_state, and request_summary_by_queue were already queue-leading, and the global read-model tables stay queue-free. The bound MySQL stores now stamp their queue into every write and prefix every read with it, so a wrong-queue read misses (ErrNotFound / empty) instead of leaking. The build key change also removes a latent cross-queue uniqueness assumption on runner-minted build IDs — two queues sharing one CI pipeline may now mint the same identifier. The storage contract suite gains a queue-isolation test covering all five re-keyed stores, and the e2e harness resolves its white-box request reads per queue.

Test Plan

go test ./... ✅ storage integration contract suite via bazel, including the new cross-queue isolation cases ✅ make fmtmake lintmake check-tidymake check-gazelle. Schemas are pre-production: tables are recreated, no data migration.

@behinddwalls
behinddwalls marked this pull request as ready for review August 6, 2026 17:01
@behinddwalls
behinddwalls requested review from a team and sbalabanov as code owners August 6, 2026 17:01
@behinddwalls
behinddwalls force-pushed the preetam/storage-factory branch from e0c1223 to d342ed4 Compare August 6, 2026 20:46
…isolation

## Summary

### Why?

The factory contract made queue-scoped storage instances the only way in, but the schema still let a bound instance reach another queue's rows: `request`, `batch`, `build`, `batch_dependent`, and `request_batch` were keyed by bare IDs. Leading every queue-scoped table's primary key with `queue` makes the binding real at the row level and leaves every table shardable by queue — cheap now (pre-prod, tables recreated), expensive to retrofit later.

### What?

`request` and `batch` move to `(queue, id)`, `build` to `(queue, id)` with a new `queue` column, `batch_dependent` to `(queue, batch_id)`, and `request_batch` to `(queue, request_id, batch_id)`; `change`, `queue_batch_state`, and `request_summary_by_queue` were already queue-leading, and the global read-model tables stay queue-free. The bound MySQL stores now stamp their queue into every write and prefix every read with it, so a wrong-queue read misses (`ErrNotFound` / empty) instead of leaking. The `build` key change also removes a latent cross-queue uniqueness assumption on runner-minted build IDs — two queues sharing one CI pipeline may now mint the same identifier. The storage contract suite gains a queue-isolation test covering all five re-keyed stores, and the e2e harness resolves its white-box request reads per queue.

## Test Plan

✅ `go test ./...` ✅ storage integration contract suite via bazel, including the new cross-queue isolation cases ✅ `make fmt` ✅ `make lint` ✅ `make check-tidy` ✅ `make check-gazelle`. Schemas are pre-production: tables are recreated, no data migration.
@behinddwalls
behinddwalls force-pushed the preetam/queue-leading-schema branch from 22d8314 to ecfcd55 Compare August 6, 2026 20:47
@behinddwalls
behinddwalls changed the base branch from preetam/storage-factory to main August 6, 2026 20:48
@behinddwalls
behinddwalls merged commit 951a246 into main Aug 6, 2026
3 checks passed
@behinddwalls
behinddwalls deleted the preetam/queue-leading-schema branch August 6, 2026 20:50
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