diff --git a/src/bucket/BucketListSnapshotBase.cpp b/src/bucket/BucketListSnapshotBase.cpp index 6e56b6dce0..ee570f9733 100644 --- a/src/bucket/BucketListSnapshotBase.cpp +++ b/src/bucket/BucketListSnapshotBase.cpp @@ -59,13 +59,9 @@ SearchableBucketListSnapshotBase::getLedgerHeader() const template LastClosedLedger const& -SearchableBucketListSnapshotBase::getLastClosedLedger() +SearchableBucketListSnapshotBase::getLastClosedLedger() const { releaseAssert(mSnapshot); - if (mAutoUpdate) - { - mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots); - } return mSnapshot->getLastClosedLedger(); } @@ -152,10 +148,9 @@ BucketLevelSnapshot::BucketLevelSnapshot( template SearchableBucketListSnapshotBase::SearchableBucketListSnapshotBase( - BucketSnapshotManager const& snapshotManager, bool autoUpdate) + BucketSnapshotManager const& snapshotManager) : mSnapshotManager(snapshotManager) , mHistoricalSnapshots() - , mAutoUpdate(autoUpdate) { mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots); } diff --git a/src/bucket/BucketListSnapshotBase.h b/src/bucket/BucketListSnapshotBase.h index 4d02bc0435..9285399d97 100644 --- a/src/bucket/BucketListSnapshotBase.h +++ b/src/bucket/BucketListSnapshotBase.h @@ -159,7 +159,6 @@ class SearchableBucketListSnapshotBase : public NonMovableOrCopyable // Snapshot managed by SnapshotManager SnapshotPtrT mSnapshot{}; std::map> mHistoricalSnapshots; - bool const mAutoUpdate; // Loops through all buckets, starting with curr at level 0, then snap at // level 0, etc. Calls f on each bucket. Exits early if function @@ -167,12 +166,8 @@ class SearchableBucketListSnapshotBase : public NonMovableOrCopyable void loopAllBuckets(std::function f, BucketListSnapshot const& snapshot) const; - // If `autoUpdate` is true, the snapshot will keep itself consistent with - // LCL automatically. If not, callers are expected to refresh the snapshot - // manually (this is useful to use cases that a consistent view of the state - // for some arbitrary time) SearchableBucketListSnapshotBase( - BucketSnapshotManager const& snapshotManager, bool autoUpdate); + BucketSnapshotManager const& snapshotManager); std::optional> loadKeysInternal(std::set const& inKeys, @@ -187,6 +182,7 @@ class SearchableBucketListSnapshotBase : public NonMovableOrCopyable } LedgerHeader const& getLedgerHeader() const; + LastClosedLedger const& getLastClosedLedger() const; // Loads inKeys from the specified historical snapshot. Returns // load_result_vec if the snapshot for the given ledger is diff --git a/src/bucket/BucketManager.cpp b/src/bucket/BucketManager.cpp index 10005a974d..60d4b3be12 100644 --- a/src/bucket/BucketManager.cpp +++ b/src/bucket/BucketManager.cpp @@ -1054,8 +1054,7 @@ BucketManager::startBackgroundEvictionScan(uint32_t ledgerSeq) releaseAssert(!mEvictionFuture.valid()); releaseAssert(mEvictionStatistics); - auto searchableBL = mSnapshotManager->copySearchableLiveBucketListSnapshot( - /* autoUpdate */ true); + auto searchableBL = mSnapshotManager->copySearchableLiveBucketListSnapshot(); auto const& cfg = mApp.getLedgerManager().getSorobanNetworkConfig(); auto const& sas = cfg.stateArchivalSettings(); diff --git a/src/bucket/BucketSnapshotManager.cpp b/src/bucket/BucketSnapshotManager.cpp index 545ea38ac3..f8086a5a1a 100644 --- a/src/bucket/BucketSnapshotManager.cpp +++ b/src/bucket/BucketSnapshotManager.cpp @@ -57,7 +57,7 @@ BucketSnapshotManager::copySearchableLiveBucketListSnapshot() const { // Can't use std::make_shared due to private constructor return std::shared_ptr( - new SearchableLiveBucketListSnapshot(*this, autoUpdate)); + new SearchableLiveBucketListSnapshot(*this)); } std::shared_ptr diff --git a/src/bucket/SearchableBucketList.cpp b/src/bucket/SearchableBucketList.cpp index 8361453928..e87eca5cdb 100644 --- a/src/bucket/SearchableBucketList.cpp +++ b/src/bucket/SearchableBucketList.cpp @@ -61,12 +61,6 @@ SearchableLiveBucketListSnapshot::scanForEviction( return result; } -void -SearchableLiveBucketListSnapshot::updateSnapshotToLatest() -{ - mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots, true); -} - template std::optional> SearchableBucketListSnapshotBase::loadKeysInternal( @@ -263,15 +257,14 @@ SearchableLiveBucketListSnapshot::loadKeysWithLimits( } SearchableLiveBucketListSnapshot::SearchableLiveBucketListSnapshot( - BucketSnapshotManager const& snapshotManager, bool autoUpdate) - : SearchableBucketListSnapshotBase(snapshotManager, autoUpdate) + BucketSnapshotManager const& snapshotManager) + : SearchableBucketListSnapshotBase(snapshotManager) { } SearchableHotArchiveBucketListSnapshot::SearchableHotArchiveBucketListSnapshot( BucketSnapshotManager const& snapshotManager) - : SearchableBucketListSnapshotBase(snapshotManager, - /* autoUpdate */ true) + : SearchableBucketListSnapshotBase(snapshotManager) { } diff --git a/src/bucket/SearchableBucketList.h b/src/bucket/SearchableBucketList.h index e9e2cbb9ef..9ce2fef018 100644 --- a/src/bucket/SearchableBucketList.h +++ b/src/bucket/SearchableBucketList.h @@ -14,7 +14,7 @@ class SearchableLiveBucketListSnapshot : public SearchableBucketListSnapshotBase { SearchableLiveBucketListSnapshot( - BucketSnapshotManager const& snapshotManager, bool autoUpdate); + BucketSnapshotManager const& snapshotManager); public: std::vector diff --git a/src/bucket/test/BucketIndexTests.cpp b/src/bucket/test/BucketIndexTests.cpp index 0246789149..fc8b46b63a 100644 --- a/src/bucket/test/BucketIndexTests.cpp +++ b/src/bucket/test/BucketIndexTests.cpp @@ -133,7 +133,7 @@ class BucketIndexTest auto searchableBL = getBM() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(true); + .copySearchableLiveBucketListSnapshot(); auto lk = LedgerEntryKey(canonicalEntry); auto currentLoadedEntry = searchableBL->load(lk); @@ -252,7 +252,7 @@ class BucketIndexTest { auto searchableBL = getBM() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(true); + .copySearchableLiveBucketListSnapshot(); // Test bulk load lookup auto loadResult = @@ -279,7 +279,7 @@ class BucketIndexTest { auto searchableBL = getBM() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(true); + .copySearchableLiveBucketListSnapshot(); for (size_t i = 0; i < n; ++i) { LedgerKeySet searchSubset; @@ -319,7 +319,7 @@ class BucketIndexTest { auto searchableBL = getBM() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(true); + .copySearchableLiveBucketListSnapshot(); // Load should return empty vector for keys not in bucket list auto keysNotInBL = @@ -496,7 +496,7 @@ class BucketIndexPoolShareTest : public BucketIndexTest { auto searchableBL = getBM() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(true); + .copySearchableLiveBucketListSnapshot(); auto loadResult = searchableBL->loadPoolShareTrustLinesByAccountAndAsset( mAccountToSearch.accountID, mAssetToSearch); diff --git a/src/ledger/LedgerManager.h b/src/ledger/LedgerManager.h index bff644a201..7a9644731d 100644 --- a/src/ledger/LedgerManager.h +++ b/src/ledger/LedgerManager.h @@ -97,7 +97,7 @@ class LedgerManager getLastClosedLedgerHeader() const = 0; // Get bucketlist snapshot - virtual std::shared_ptr + virtual std::shared_ptr getCurrentLedgerStateSnaphot() = 0; // return the HAS that corresponds to the last closed ledger as persisted in diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index e4a510ab6a..0464b6693a 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -1252,17 +1252,15 @@ LedgerManagerImpl::maybeResetLedgerCloseMetaDebugStream(uint32_t ledgerSeq) } } -std::shared_ptr +std::shared_ptr LedgerManagerImpl::getCurrentLedgerStateSnaphot() { if (!mReadOnlyLedgerStateSnapshot) { - // Set autoUpdate to false to "freeze" the snapshot - // Update manually at the end of ledger close mReadOnlyLedgerStateSnapshot = mApp.getBucketManager() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(/* autoUpdate */ false); + .copySearchableLiveBucketListSnapshot(); } return mReadOnlyLedgerStateSnapshot; } @@ -1294,7 +1292,7 @@ LedgerManagerImpl::advanceReadOnlyLedgerState(LedgerHeader const& header, bm.getHotArchiveBucketList(), lcl); bm.getBucketSnapshotManager().updateCurrentSnapshot( std::move(liveSnapshot), std::move(hotArchiveSnapshot)); - getCurrentLedgerStateSnaphot()->updateSnapshotToLatest(); + mReadOnlyLedgerStateSnapshot = bm.getBucketSnapshotManager().copySearchableLiveBucketListSnapshot(); } void diff --git a/src/ledger/LedgerManagerImpl.h b/src/ledger/LedgerManagerImpl.h index e76db54ffd..a4a9060f00 100644 --- a/src/ledger/LedgerManagerImpl.h +++ b/src/ledger/LedgerManagerImpl.h @@ -67,7 +67,7 @@ class LedgerManagerImpl : public LedgerManager medida::Timer& mMetaStreamWriteTime; VirtualClock::time_point mLastClose; bool mRebuildInMemoryState{false}; - std::shared_ptr + std::shared_ptr mReadOnlyLedgerStateSnapshot; std::unique_ptr mStartCatchup; @@ -202,7 +202,7 @@ class LedgerManagerImpl : public LedgerManager SorobanMetrics& getSorobanMetrics() override; - std::shared_ptr + std::shared_ptr getCurrentLedgerStateSnaphot() override; }; } diff --git a/src/ledger/LedgerStateSnapshot.cpp b/src/ledger/LedgerStateSnapshot.cpp index 78be141754..97a427dcc5 100644 --- a/src/ledger/LedgerStateSnapshot.cpp +++ b/src/ledger/LedgerStateSnapshot.cpp @@ -169,9 +169,9 @@ LedgerTxnReadOnly::executeWithMaybeInnerSnapshot( return f(lsg); } -BucketSnapshotState::BucketSnapshotState(BucketManager& bm) - : mSnapshot( - bm.getBucketSnapshotManager().copySearchableLiveBucketListSnapshot()) +BucketSnapshotState::BucketSnapshotState( + std::shared_ptr snapshot) + : mSnapshot(snapshot) , mLedgerHeader(LedgerHeaderWrapper( std::make_shared(snapshot->getLedgerHeader()))) { diff --git a/src/ledger/LedgerStateSnapshot.h b/src/ledger/LedgerStateSnapshot.h index 0fc5f03d5a..6dd0ae8abb 100644 --- a/src/ledger/LedgerStateSnapshot.h +++ b/src/ledger/LedgerStateSnapshot.h @@ -116,7 +116,7 @@ class BucketSnapshotState : public AbstractLedgerStateSnapshot public: BucketSnapshotState( - std::shared_ptr snapshot); + std::shared_ptr snapshot); ~BucketSnapshotState() override; LastClosedLedger const& getLastClosedLedger() const override; diff --git a/src/ledger/LedgerTxn.cpp b/src/ledger/LedgerTxn.cpp index ae1994a5ad..500bea8f27 100644 --- a/src/ledger/LedgerTxn.cpp +++ b/src/ledger/LedgerTxn.cpp @@ -3065,7 +3065,7 @@ LedgerTxnRoot::Impl::getSearchableLiveBucketListSnapshot() const mSearchableBucketListSnapshot = mApp.getBucketManager() .getBucketSnapshotManager() - .copySearchableLiveBucketListSnapshot(/* autoUpdate */ true); + .copySearchableLiveBucketListSnapshot(); } return *mSearchableBucketListSnapshot; diff --git a/src/main/QueryServer.cpp b/src/main/QueryServer.cpp index 7c190666db..1830727ce6 100644 --- a/src/main/QueryServer.cpp +++ b/src/main/QueryServer.cpp @@ -68,8 +68,7 @@ QueryServer::QueryServer(const std::string& address, unsigned short port, for (auto pid : workerPids) { mBucketListSnapshots[pid] = std::move( - bucketSnapshotManager.copySearchableLiveBucketListSnapshot( - /* autoUpdate */ true)); + bucketSnapshotManager.copySearchableLiveBucketListSnapshot()); } }