Skip to content

Comments

apollo_storage: Use watch channels for marker tracking#12690

Open
dean-starkware wants to merge 1 commit intodean/storage-batching-init-fixfrom
dean/storage-batching-channel-markers
Open

apollo_storage: Use watch channels for marker tracking#12690
dean-starkware wants to merge 1 commit intodean/storage-batching-init-fixfrom
dean/storage-batching-channel-markers

Conversation

@dean-starkware
Copy link

@dean-starkware dean-starkware commented Feb 18, 2026

Replace spawn_blocking-based marker reads with tokio::sync::watch channels. This eliminates the MDBX Thread Local Storage issue where uncommitted writes from one thread were not visible to reads from another thread in the blocking pool.


Note

Medium Risk
Changes core sync concurrency/marker propagation and compiled-class download flow; mistakes could stall progress or skip required compiled classes under certain config/compatibility conditions.

Overview
Sync now tracks header/state markers via tokio::sync::watch channels, updating them after each successful write, so block/state streams no longer poll storage each loop (avoids cross-thread MDBX visibility issues with batched/uncommitted writes).

Compiled class syncing is reworked from range-based stream_compiled_classes scanning markers to an event-driven model: after storing a state diff, the sync enqueues per-class CompiledClassRequests and fetches each CASM via get_compiled_class, while switching several validation/lookup reads to use the writer’s RW transaction for consistency. Tests are updated to mock get_compiled_class calls, and storage batching commit logic is slightly adjusted (removes a stray blank line only).

Written by Cursor Bugbot for commit fc546ad. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator

@matanl-starkware matanl-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matanl-starkware reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on dean-starkware).


crates/apollo_central_sync/src/lib.rs line 941 at r1 (raw file):

            // Skip forward through blocks without declared classes.
            while from < state_marker {
                let txn = reader.begin_ro_txn()?;

Here you don't have pending writes...

Code quote:

reader.begin_ro_txn()

@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch 2 times, most recently from 1081b9f to d1ec325 Compare February 19, 2026 11:12
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from a9146ee to 7775b79 Compare February 19, 2026 11:32
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from 7775b79 to 1752bb2 Compare February 19, 2026 11:48
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from 1752bb2 to 4d74a1e Compare February 19, 2026 12:24
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from 1d6cf39 to 57f79bb Compare February 19, 2026 13:01
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch 2 times, most recently from 73c95bd to e15217f Compare February 19, 2026 13:56
@dean-starkware dean-starkware force-pushed the dean/storage-batching-init-fix branch from 54a2710 to d05a88d Compare February 19, 2026 13:58
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from e15217f to a2a3cea Compare February 19, 2026 14:01
@dean-starkware dean-starkware force-pushed the dean/storage-batching-init-fix branch from d05a88d to 4700a60 Compare February 19, 2026 14:09
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from a2a3cea to ad30d3f Compare February 19, 2026 14:11
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from ad30d3f to cf93686 Compare February 22, 2026 11:24
@dean-starkware dean-starkware force-pushed the dean/storage-batching-init-fix branch 3 times, most recently from 09de6c9 to d538938 Compare February 22, 2026 11:56
Copy link
Author

@dean-starkware dean-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dean-starkware made 1 comment.
Reviewable status: 0 of 14 files reviewed, 1 unresolved discussion (waiting on matanl-starkware).


crates/apollo_central_sync/src/lib.rs line 941 at r1 (raw file):

Previously, matanl-starkware (Matan Lior) wrote…

Here you don't have pending writes...

Already fixed.

@dean-starkware dean-starkware changed the title fix(sync): use watch channels for marker tracking to avoid MDBX TLS i… apollo_storage: Use watch channels for marker tracking to avoid MDBX TLS i… Feb 22, 2026
@dean-starkware dean-starkware changed the title apollo_storage: Use watch channels for marker tracking to avoid MDBX TLS i… apollo_storage: Use watch channels for marker tracking Feb 22, 2026
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from cf93686 to a24793b Compare February 22, 2026 12:07
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch 2 times, most recently from 216db74 to 85494d3 Compare February 22, 2026 12:27
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch 4 times, most recently from 06d7ff2 to 92d7bfe Compare February 22, 2026 13:10
…ility bugs

Replace direct DB marker reads in stream generators with tokio::sync::watch
channels, eliminating spawn_blocking and MDBX thread-affinity issues.

Remove spawn_blocking from perform_storage_writes to prevent MDBX TLS
violations that caused State marker mismatches when batching was enabled.

Switch compiler_backward_compatibility_marker and compiled_class_marker
reads from begin_ro_txn to begin_rw_txn so they see uncommitted batched
writes, fixing Class marker mismatches.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dean-starkware dean-starkware force-pushed the dean/storage-batching-channel-markers branch from 92d7bfe to fc546ad Compare February 22, 2026 13:28
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.

3 participants