-
Notifications
You must be signed in to change notification settings - Fork 12
docs: define scoped sequential resource IDs #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+75
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Scoped Sequential Resource IDs | ||
|
|
||
| ## Status | ||
|
|
||
| Proposed. | ||
|
|
||
| ## Decision | ||
|
|
||
| A generated resource ID is the canonical decimal string for a positive value returned by a durable counter scoped to `(owner domain, queue, resource kind)`. | ||
|
|
||
| | Resource | Current ID | Proposed ID | Complete identity | | ||
| |---|---:|---:|---| | ||
| | SubmitQueue request | `demo-queue/42` | `"42"` | `(submitqueue, demo-queue, request, "42")` | | ||
| | SubmitQueue batch | `demo-queue/batch/7` | `"7"` | `(submitqueue, demo-queue, batch, "7")` | | ||
| | Stovepipe request | `request/monorepo/main/42` | `"42"` | `(stovepipe, monorepo/main, request, "42")` | | ||
|
|
||
| The decimal ID is unique only within its scope. The same value may appear in another queue, resource kind, or domain. APIs and messages therefore carry the queue separately; their typed field or message type supplies the resource kind. | ||
|
|
||
| Do not embed scope into the ID. Forms such as `demo-queue/42`, `demo-queue/batch/7`, `request.42`, and ARN-like resource names are not stored or accepted as IDs. | ||
|
|
||
| ## Counter | ||
|
|
||
| The counter backend persists one high-water mark per `(owner domain, queue, resource kind)`. For example: | ||
|
|
||
| ```text | ||
| (submitqueue, demo-queue, request) -> 42 | ||
| (submitqueue, demo-queue, batch) -> 7 | ||
| (stovepipe, demo-queue, request) -> 11 | ||
| ``` | ||
|
|
||
| Controllers allocate an ID before creating the resource; stores accept the caller-supplied ID and never generate one. | ||
|
|
||
| - The first ID is `1`; `0` is the unset value. | ||
| - Allocation is atomic across replicas and durable across restarts. | ||
| - Allocated values are never reused. Failed writes may leave gaps. | ||
| - Overflow fails instead of wrapping. | ||
| - Numeric order is allocation order only within the same scope. | ||
|
|
||
| The counter contract requires an atomic durable increment, not MySQL specifically. MySQL remains the initial implementation. | ||
|
|
||
| ## Storage and contracts | ||
|
|
||
| Resource tables keep IDs as strings. Queue remains the leading key: | ||
|
|
||
| ```text | ||
| request(queue, id VARCHAR(...), ...) PRIMARY KEY (queue, id) | ||
| batch(queue, id VARCHAR(...), ...) PRIMARY KEY (queue, id) | ||
| ``` | ||
|
|
||
| Reference columns use the same string type. Domain entities may use distinct named string types such as `RequestID` and `BatchID`; protobuf resource fields remain `string`. The counter backend may store its high-water marks as integers, and controllers convert allocated values to canonical decimal strings before creating resources. | ||
|
|
||
| This proposal applies only to counter-generated resources. Provider build IDs, message and hook IDs, change URIs, and content hashes keep their existing contracts. | ||
|
|
||
| ## URLs and display | ||
|
|
||
| The decimal ID is used directly as one path segment: | ||
|
|
||
| ```text | ||
| /requests/42 | ||
| /batches/7 | ||
| ``` | ||
|
|
||
| The route supplies the resource kind; the request context supplies the queue. Queue URL design is separate. | ||
|
|
||
| A UI may display `request.42`, `batch.7`, or `#42`, but those are derived labels, not identities. | ||
|
|
||
| ## Rejected alternatives | ||
|
|
||
| - **Queue or kind prefixes:** duplicate explicit context, lengthen keys, require parsing, and introduce URL separators. | ||
| - **ARN-like names:** solve global lookup, which current APIs neither provide nor require. | ||
| - **UUIDs or a global counter:** provide global uniqueness at the cost of unnecessary encoding or coordination. | ||
| - **Integer resource fields:** couple the persisted and wire contracts to the current counter representation without adding identity semantics. | ||
| - **SQL auto-increment or `MAX(id) + 1`:** move allocation into one storage implementation or fail under concurrency. | ||
| - **Process-local counters:** reuse IDs after restart and collide across replicas. | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we expect any entity type to be covered here? For example, we have BuildID (
submitqueue/stovepipe/entity/build.go
Line 77 in 128e8a3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BuildIDs are always runner minted so we are just gonna treat them as is...