Bucket query asserts and perf fix#5323
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4bdff954c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR improves BucketList snapshot safety and performance by (1) adding a test-build thread-ownership invariant to detect illegal cross-thread reuse of a single snapshot instance (per #5067), and (2) reducing snapshot/view construction overhead by sharing pre-resolved metric handles across views over the same immutable ledger state.
Changes:
- Add a
threadInvariant()assertion path (BUILD_TESTS) toSearchableBucketListSnapshotquery entry points to catch cross-thread snapshot reuse. - Introduce
BucketSnapshotMetricsand store shared metric references inImmutableLedgerDataso per-view snapshot construction avoids repeatedly taking the global metrics registry lock. - Thread metrics registry through
ImmutableLedgerDataconstruction fromLedgerManagerImpl.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ledger/LedgerManagerImpl.cpp | Passes MetricsRegistry into ImmutableLedgerData construction sites. |
| src/ledger/ImmutableLedgerView.h | Extends ImmutableLedgerData to hold shared BucketSnapshotMetrics and updates ctor signature. |
| src/ledger/ImmutableLedgerView.cpp | Constructs shared snapshot metrics once per immutable state and wires them into ImmutableLedgerView snapshots. |
| src/bucket/BucketListSnapshot.h | Adds thread-invariant state (test builds) and introduces BucketSnapshotMetrics shared across snapshots. |
| src/bucket/BucketListSnapshot.cpp | Implements BucketSnapshotMetrics, shares metrics in snapshot ctor, and adds thread-invariant checks on query paths. |
4bdff95 to
a8d0c5f
Compare
Description
The first commit resolves #5067.
The 2nd commit addresses a perf issue we saw with the BucketList refactor. We build snapshot objects in parallel contents. Currently, the constructor gets a fresh set of metric references for each snapshot, acquiring a lock to do so. This changes it such that we use a single shared metrics object across all snapshots. Metrics are thread safe, so there should be no safety issue with this, and it makes the snapshot constructor much cheaper.
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)