Complete const ledger state refactor#5141
Open
SirTyson wants to merge 5 commits intostellar:masterfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR completes the ledger state refactoring by removing BucketSnapshotManager and centralizing state management in LedgerManager. The refactor introduces LedgerStateSnapshot as a unified, thread-safe snapshot type with copy semantics, preventing accidental sharing across threads.
Changes:
- Removed
BucketSnapshotManagerand moved snapshot management toLedgerManager - Introduced
LedgerStateSnapshot(copyable value type) andApplyLedgerStateSnapshot(strong typedef for apply-time snapshots) - Implemented copy semantics with fresh file stream caches per copy for thread safety
- Fixed snapshot invariant race condition by launching it from apply thread instead of main thread
Reviewed changes
Copilot reviewed 62 out of 62 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/ledger/LedgerStateSnapshot.h/cpp |
New unified snapshot types with copy semantics |
src/ledger/LedgerManagerImpl.h/cpp |
Centralized snapshot management with thread-safe access |
src/bucket/BucketSnapshotManager.h/cpp |
Removed entirely |
src/bucket/BucketListSnapshot.h/cpp |
Added copy constructors for thread-safe copying |
src/transactions/ParallelApplyUtils.h/cpp |
Updated to use ApplyLedgerStateSnapshot |
src/invariant/* |
Updated invariant interfaces to use new snapshot types |
src/main/QueryServer.h/cpp |
Updated to use LedgerManager instead of BucketSnapshotManager |
src/overlay/OverlayManagerImpl.h/cpp |
Updated to use LedgerStateSnapshot value type |
| Test files | Updated to use new snapshot APIs |
cf31391 to
e38ed3f
Compare
e38ed3f to
99bf7d0
Compare
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.
Description
Resolves #5073
This is the 2nd PR in the ledger state factor. Specifically, this PR covers steps 2-4.
The change is a bit larger than I would have liked, but it was difficult to break this down into smaller chunks that were still safe for master. While the diff is large, I've tried to make the commits easy to follow along. The commits are as follows:
3476e384cRemove LedgerHeader from BucketListSnapshotDataThis reduces the duplication of
LedgerHeaderby removing it from the immutableBucketListSnapshotDatastruct. The header is moved to a centralized location inBucketSnapshotManagerto prepare for a future commit, which will centralize the header to justCompleteConstLedgerState9bec0791fConsolidated state access to LedgerStateSnapshotThis introduces
LedgerStateSnapshotas the unified, searchable ledger state snapshot struct. This is a lightweight wrapper over a centralizedCompleteConstLedgerState, which provides BucketList search functionality via local file streams.BucketSnapshotManagerhas not yet been removed yet, but basically is just a wrapper around theLedgerManagerto serveLedgerStateSnapshot.2b1957028Make LedgerStateSnapshot threadsafeImplements copy semantics for
LedgerStateSnapshotand makes the default interface a value type. This removes footguns where two threads would have a pointer to the same snapshot, resulting in race conditions.b77fb68feRemove BucketSnapshotManager and manage snapshot from LedgerManagerBucketSnapshotManageris removed entirely, and theLedgerManagermaintains the canonical lcl ledger state snapshot, as well as provides getters for that snapshot. This hardens the distinction between the "apply state" snapshot (used only during ledger apply) and the ledger snapshot published and maintained by the main thread. The apply state, and all apply time functions, must use the 'apply state" snapshot, since this may be ahead of the main thread's snapshot. The main thread snapshot is what is copied by other non-apply threads, such as the query server and overlay thread.d143cc7f3Fix minor race condition in invariant checkThis has various small cleanups. It fixes a few dangling reference issues (that I introduced by removing a couple asserts) and adds a check back to a unit test I forgot I removed during development. Finally, this launches the snapshot invariant thread from the apply thread, not the main thread. This ensures that we always have consistent state between the in-memory state and the ledger state snapshot used for the invariant.
There are still some outstanding cleanups. For example, I still want to get rid of the weird mutable header copy in
BucketSnapshotState(and maybe get rid of that class entirely). I also want to move historical snapshots outside ofCompleteConstLedgerStateand have the query server manage those directly, since it's the only subsystem that cares about it.Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)