Repository navigation
T11d: RequestId, LL-Request-Id, and deduplication #9
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e6f81a1
Add RequestId, sent as LL-Request-Id, with deduplication
kirre-bylund 5c1327a
Remove request deduplication entirely
kirre-bylund 69bcb61
Drop the idempotent flag, and put the request id on failures
kirre-bylund 4dd8226
Fix four review findings, and make the id counter's invariant local
kirre-bylund 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
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,63 @@ | ||
| #pragma once | ||
|
|
||
| // The id every async call returns (D25). | ||
| // | ||
| // A value type wrapping a `uint64`, not a string: a string id would allocate on every call, | ||
| // which is exactly the kind of thing a game SDK should not do on a hot path. It is the same | ||
| // id the queue uses internally and the same id sent as `LL-Request-Id`, so a support ticket | ||
| // can be matched to a server log line. | ||
| // | ||
| // It is also what `Cancel(RequestId)` will take when cancellation lands, so the return type | ||
| // does not have to change for that. | ||
| // | ||
| // **The counter is process-wide, not per-client.** Two clients in one process are legal | ||
| // (D20), and a per-client counter would let both mint id 5 - so a support ticket quoting | ||
| // "request 5" would be ambiguous. Minting from one static counter makes the id unique | ||
| // across the process, which is the whole point of a correlation id. | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
|
|
||
| namespace lootlocker { | ||
|
|
||
| class RequestId { | ||
| public: | ||
| // Invalid. `IsValid()` is false, and it is what a rejected submission returns. | ||
| RequestId() = default; | ||
|
|
||
| explicit RequestId(std::uint64_t value) : m_value(value) {} | ||
|
|
||
| // Mint the next id. Process-wide and monotonic, so ids are unique across every client | ||
| // in the process and increasing in submission order. | ||
| // | ||
| // Never returns an invalid id: 0 is skipped, so a wrap cannot produce one. The wrap is | ||
| // unreachable in practice - a `uint64` at a million requests a second lasts longer than | ||
| // the hardware - but skipping 0 costs one comparison and removes the edge case | ||
| // entirely. | ||
| static RequestId Next(); | ||
|
|
||
| std::uint64_t Value() const { return m_value; } | ||
|
|
||
| // False for the default-constructed id, which is what a rejected submission returns. | ||
| // Ids start at 1, so 0 is unambiguous. | ||
| bool IsValid() const { return m_value != 0; } | ||
|
|
||
| // For logs and for the `LL-Request-Id` header. Allocates, so not on a hot path. | ||
| std::string ToString() const; | ||
|
|
||
| bool operator==(const RequestId& other) const { return m_value == other.m_value; } | ||
| bool operator!=(const RequestId& other) const { return m_value != other.m_value; } | ||
|
|
||
| // Ordering exists so the queue can keep FIFO order among requests that are equally | ||
| // ready, and so an id can be a map key. Because ids are minted monotonically, this is | ||
| // also submission order within one client. | ||
| // | ||
| // It is deliberately not a documented guarantee: the other SDKs mint a GUID and have no | ||
| // ordering at all, and nothing in the public surface should come to depend on it. | ||
| bool operator<(const RequestId& other) const { return m_value < other.m_value; } | ||
|
|
||
| private: | ||
| std::uint64_t m_value = 0; | ||
| }; | ||
|
|
||
| } // namespace lootlocker |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.