Repository navigation
feat(orchestrator): keep per-state request membership records for listing a queue's requests by state - #891
Open
roychying wants to merge 1 commit into
Conversation
…o a queue's requests can be listed by state
roychying
added this pull request to stack #892
October 19, 2026 23:13
roychying
requested review from
a team,
behinddwalls and
sbalabanov
as code owners
October 19, 2026 23:13
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Operators need queue depth: how many requests are in each state, and how long the oldest one has been there. Event metrics cannot provide this. It is a property of stored state, and it matters most when a queue is stuck and no events are flowing.
The
requesttable is keyed by(queue, id), so "requests of queue Q in state S" is not a key-based read. Adding a(queue, state)secondary index would makeRequestStoredepend on a query-by-attribute, which the storage contract rules out. The sanctioned shape is a first-class mapping store keyed by the lookup attribute, the same pattern asQueueBatchStateandChangeRecord.This PR adds that mapping for requests. A periodic job can then report per-state request counts and the oldest time-in-state with key-prefix scans only.
What?
entity.QueueRequestState{Queue, State, RequestID, EnteredAtMs}: one record per in-queue request, under its current state.entity.InQueueRequestStates: every non-terminal request state. A test enforces that each valid state is either in this list or terminal.storage.QueueRequestStateStore.List(ctx, state), with its mock.GetQueueRequestStateStore()on the orchestrator storage aggregate.queue_request_state, PK(queue, state, request_id). It leads withqueue, as the queue-shard linter requires, and has no secondary index.Listis a primary-key-prefix scan.CreateandUpdateit deletes the request's record from every other in-queue state andINSERT IGNOREs it under the new one, so a version-only update keepsentered_at_ms. A terminal state leaves no record, so the table only ever holds in-queue requests. A failed CAS or duplicate create rolls back with no record change.mysql.NewStorage(db, scope, WithQueueRequestStateRecords())enables the records. It is off by default, so a deployment that upgrades before creating the table keeps working.Listreturns an error instead of reporting every queue as idle.AGENTS.md, and the store/table map indoc/rfc/service-scoped-extensions.md.Exact records maintained by the store, rather than advisory records maintained in core.**
QueueBatchStaterecords are moved bysubmitqueue/orchestrator/core/batcharound the batch CAS, are advisory, and need repair on redelivery. Here the backend keeps the record in the same transaction as the request write. That way:The cost is that a backend must be able to update the request and its record atomically. A key-value backend without local transactions would need its own write ordering.
Test Plan
TestRequestStore_WritesQueueRequestStateRecordscovers:startedin the same transactionTestQueueRequestStateStore_List: rows, empty, query error, row error.TestDisabledQueueRequestStateStore_ListFails.TestNewStorage_QueueRequestStateRecords: off by default, on with the option.TestInQueueRequestStates: every valid state is either in-queue or terminal.TestStorage_QueueRequestStateRecordsFollowRequestWritescovers:EnteredAtMsRun locally:
Issue