Change CanonicalState sharing model.#5437
Closed
deuszx wants to merge 4 commits intotestnet_conwayfrom
Closed
Conversation
…flush Replace clone_unchecked() sharing with a single CanonicalState behind Arc<tokio::sync::RwLock>. Both the block processor and exporter now use the same LogView, so stored_count stays consistent after flush + post_save and the buffer can be safely drained.
Contributor
Author
|
Superseeded by #5449 |
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.
Motivation
The exporter's
CanonicalStateis cloned viaclone_unchecked(), giving the exporter aLogViewwith a frozenstored_count. After flush persists entries to DB, the exporter'sLogViewstill can't read them –LogView::get()routesindex >= stored_counttonew_values(empty in the clone), never hitting the DB. This means the in-memory buffer can never be cleared and grows without bound.Proposal
Share a single
CanonicalStatebehindArc<tokio::sync::RwLock>instead of cloning it. Both the block processor and exporter use the sameLogView, sostored_countstays consistent. After flush +post_save(), the buffer is safely drained — subsequent reads fall through to theLogViewwhich has the correctstored_count.CanonicalStateflushed_countfield (flush now drains the entire buffer)Arc<papaya::HashMap<usize, CanonicalBlock>>withVec<CanonicalBlock>(RwLockprovides concurrency; entries are sequential)clone()(no moreclone_unchecked()) andnext_index()flush()now usesbuffer.drain(..)instead of iteratingflushed_count..countSharedStorageshared_canonical_statefield is nowArc<tokio::sync::RwLock<CanonicalState<C>>>clone()is infallible (Arc clone) — keptResultreturn type to avoid touching 13+ call sitespush_block()is now async (acquires write lock)ExporterStorage/BlockProcessorStorageget_block_with_blob_ids,get_block_with_blobs,get_latest_index) acquire a read lockpush_block,save) acquire a write lockclone()takes&selfinstead of&mut selfTest Plan
cargo build -p linera-service— compiles with no errorscargo test -p linera-service --bin linera-exporter— all existing tests pass (includingtest_committee_destination)Release Plan
main.Links