refactor: keep each call's state in one atomic record (WT-1138) - #364
Merged
Conversation
The tracker used to spread one call's state across eight separate collections; each was safe on its own, but a transition touched several of them one after another, so a reader could in principle catch a call halfway through a change. All facts about a call now live in a single immutable record, and every transition replaces that record in one atomic step, so any reader always sees a consistent picture. Behaviour is intentionally unchanged: the full test suite, including the recently added pinning tests for the layer's subtle semantics, passes without modifying a single test.
The record describing one call's complete state now lives beside the other core-layer classes instead of being nested inside the tracker, so its documentation stands on its own and the tracker file stays focused on the transitions. Only the tracker can still create or store records.
The layer document still described the eight separate collections this change replaces. It now describes the single per-call record, the atomic transitions, and what deliberately remains non-atomic, and its test-coverage section reflects the pinning tests that now guard the layer - so the document and the code ship in the same change and never disagree on develop.
Four areas of the call-state layer had no direct coverage: the window where a call the app already knows is registered a second time by the push path, the dispatch guards that survive a call's termination, the mid-call metadata merge, and - the point of the record rework itself - that a reader can no longer catch a call halfway through a transition. Ten tests pin them now, each proven to fail when the behaviour it guards is broken; the concurrency one also fails against the previous implementation, demonstrating the race the rework closed. The re-registration tests double as a tripwire for the planned tightening of that window: changing it will turn them red on purpose.
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.
Overview
The main-process call-state tracker kept the facts about one call spread across eight separate collections. Each collection was thread-safe on its own, but a lifecycle transition updated several of them one after another, so a reader could in principle observe a call halfway through a change - for example, a call being resurrected after a transfer-back briefly looked terminated. Nothing hits this today because all writes are serialized, but it was a standing trap for any future code that reads from another thread.
All per-call state now lives in a single immutable record, and every transition replaces that record in one atomic step: a reader always sees a consistent snapshot, and different calls never block each other. Behaviour is deliberately unchanged - the record's fields mirror exactly the facts the old collections kept, including the deliberately sticky ghost-call guard and the ability of a call to be registered and pending at the same time during a push-path re-registration.
Verification: the full native suite, including the recently added pinning tests for this layer's subtle semantics, passes without a single test being modified; each pinning test was also re-proven to fail against this implementation when the line it guards is broken.