Feat: Align resource state versions with the writing batch index#89
Open
hmoog wants to merge 1 commit into
Open
Feat: Align resource state versions with the writing batch index#89hmoog wants to merge 1 commit into
hmoog wants to merge 1 commit into
Conversation
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.
Summary
Resource state versions are now the index of the batch that wrote them, instead of a per-resource counter that started at 0 and incremented per mutation. With the version sourced from the globally monotonic batch index, an emptied resource drops its
StatePtrLatestentry entirely instead of parking a stub on an empty version.Motivation
The per-resource counter was opaque (it did not say which batch produced a state) and forced an emptied resource to keep a
StatePtrLateststub pointing at a versionless empty row, only to preserve the resource's version high-water mark. Sourcing the version from the batch index makes that high-water mark external and global, so the stub is no longer needed: absent now always means no latest pointer. This also aligns state versions with the SMT, which already keys on the batch index, and is the prerequisite for later keying state by the canonical chain's never-reused batch ids.Changes
StateVersion:data_mut/set_datastamp the writing batch's index as the version. A write that changes a resource advances its version to that index; an untouched resource keeps its prior version, so thewritten.version > read.versionchange guard stays accurate (batch indices are monotonic).StateVersionpersistence treats empty data as absent, consistently across the three persist methods:write_dataskips the row,write_latest_ptrdeletes the latest pointer, andwrite_rollback_ptrrecords0so a rollback restores the resource to absent rather than to a stub.AccessHandleinto the state-version mutators.Tests
assert_written_statehelpers assert the stored data only; the version is now the batch index, not a writer count.CLEAR_DATAsentinel transaction id whose write empties a resource.Run with
cargo test --manifest-path scheduling/Cargo.toml.Notes
Versions are sparse: only the batches that actually wrote a resource appear. Rollback is unchanged, since
StatePtrRollbackis representation-agnostic (it restores whatever version the pointer recorded).