Skip to content

Feat: Align resource state versions with the writing batch index#89

Open
hmoog wants to merge 1 commit into
masterfrom
feat/state-version-batch-index
Open

Feat: Align resource state versions with the writing batch index#89
hmoog wants to merge 1 commit into
masterfrom
feat/state-version-batch-index

Conversation

@hmoog

@hmoog hmoog commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

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 StatePtrLatest entry 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 StatePtrLatest stub 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_data stamp 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 the written.version > read.version change guard stays accurate (batch indices are monotonic).
  • StateVersion persistence treats empty data as absent, consistently across the three persist methods: write_data skips the row, write_latest_ptr deletes the latest pointer, and write_rollback_ptr records 0 so a rollback restores the resource to absent rather than to a stub.
  • Scheduler: the executing batch's index is threaded through AccessHandle into the state-version mutators.

Tests

  • The assert_written_state helpers assert the stored data only; the version is now the batch index, not a writer count.
  • The test processor gains a CLEAR_DATA sentinel transaction id whose write empties a resource.
  • New coverage: removal drops the latest pointer; recreate after removal takes the new batch-index version without colliding with retained history; rolling back a removal restores the prior version; rolling back a recreate leaves the resource absent; after pruning past a removal the resource has zero on-disk footprint.

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 StatePtrRollback is representation-agnostic (it restores whatever version the pointer recorded).

@hmoog hmoog marked this pull request as ready for review June 23, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant