Skip to content

Commit

Permalink
rebase fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Dec 29, 2024
1 parent 50785e6 commit b69ace5
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 47 deletions.
9 changes: 2 additions & 7 deletions src/bucket/BucketListSnapshotBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ SearchableBucketListSnapshotBase<BucketT>::getLedgerHeader() const

template <class BucketT>
LastClosedLedger const&
SearchableBucketListSnapshotBase<BucketT>::getLastClosedLedger()
SearchableBucketListSnapshotBase<BucketT>::getLastClosedLedger() const
{
releaseAssert(mSnapshot);
if (mAutoUpdate)
{
mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots);
}
return mSnapshot->getLastClosedLedger();
}

Expand Down Expand Up @@ -152,10 +148,9 @@ BucketLevelSnapshot<BucketT>::BucketLevelSnapshot(

template <class BucketT>
SearchableBucketListSnapshotBase<BucketT>::SearchableBucketListSnapshotBase(
BucketSnapshotManager const& snapshotManager, bool autoUpdate)
BucketSnapshotManager const& snapshotManager)
: mSnapshotManager(snapshotManager)
, mHistoricalSnapshots()
, mAutoUpdate(autoUpdate)
{
mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots);
}
Expand Down
8 changes: 2 additions & 6 deletions src/bucket/BucketListSnapshotBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,15 @@ class SearchableBucketListSnapshotBase : public NonMovableOrCopyable
// Snapshot managed by SnapshotManager
SnapshotPtrT<BucketT> mSnapshot{};
std::map<uint32_t, SnapshotPtrT<BucketT>> 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
// returns Loop::COMPLETE.
void loopAllBuckets(std::function<Loop(BucketSnapshotT const&)> f,
BucketListSnapshot<BucketT> 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<std::vector<typename BucketT::LoadT>>
loadKeysInternal(std::set<LedgerKey, LedgerEntryIdCmp> const& inKeys,
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/bucket/BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/bucket/BucketSnapshotManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ BucketSnapshotManager::copySearchableLiveBucketListSnapshot() const
{
// Can't use std::make_shared due to private constructor
return std::shared_ptr<SearchableLiveBucketListSnapshot>(
new SearchableLiveBucketListSnapshot(*this, autoUpdate));
new SearchableLiveBucketListSnapshot(*this));
}

std::shared_ptr<SearchableHotArchiveBucketListSnapshot const>
Expand Down
13 changes: 3 additions & 10 deletions src/bucket/SearchableBucketList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ SearchableLiveBucketListSnapshot::scanForEviction(
return result;
}

void
SearchableLiveBucketListSnapshot::updateSnapshotToLatest()
{
mSnapshotManager.maybeUpdateSnapshot(mSnapshot, mHistoricalSnapshots, true);
}

template <class BucketT>
std::optional<std::vector<typename BucketT::LoadT>>
SearchableBucketListSnapshotBase<BucketT>::loadKeysInternal(
Expand Down Expand Up @@ -263,15 +257,14 @@ SearchableLiveBucketListSnapshot::loadKeysWithLimits(
}

SearchableLiveBucketListSnapshot::SearchableLiveBucketListSnapshot(
BucketSnapshotManager const& snapshotManager, bool autoUpdate)
: SearchableBucketListSnapshotBase<LiveBucket>(snapshotManager, autoUpdate)
BucketSnapshotManager const& snapshotManager)
: SearchableBucketListSnapshotBase<LiveBucket>(snapshotManager)
{
}

SearchableHotArchiveBucketListSnapshot::SearchableHotArchiveBucketListSnapshot(
BucketSnapshotManager const& snapshotManager)
: SearchableBucketListSnapshotBase<HotArchiveBucket>(snapshotManager,
/* autoUpdate */ true)
: SearchableBucketListSnapshotBase<HotArchiveBucket>(snapshotManager)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/bucket/SearchableBucketList.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SearchableLiveBucketListSnapshot
: public SearchableBucketListSnapshotBase<LiveBucket>
{
SearchableLiveBucketListSnapshot(
BucketSnapshotManager const& snapshotManager, bool autoUpdate);
BucketSnapshotManager const& snapshotManager);

public:
std::vector<LedgerEntry>
Expand Down
10 changes: 5 additions & 5 deletions src/bucket/test/BucketIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class BucketIndexTest

auto searchableBL = getBM()
.getBucketSnapshotManager()
.copySearchableLiveBucketListSnapshot(true);
.copySearchableLiveBucketListSnapshot();
auto lk = LedgerEntryKey(canonicalEntry);

auto currentLoadedEntry = searchableBL->load(lk);
Expand Down Expand Up @@ -252,7 +252,7 @@ class BucketIndexTest
{
auto searchableBL = getBM()
.getBucketSnapshotManager()
.copySearchableLiveBucketListSnapshot(true);
.copySearchableLiveBucketListSnapshot();

// Test bulk load lookup
auto loadResult =
Expand All @@ -279,7 +279,7 @@ class BucketIndexTest
{
auto searchableBL = getBM()
.getBucketSnapshotManager()
.copySearchableLiveBucketListSnapshot(true);
.copySearchableLiveBucketListSnapshot();
for (size_t i = 0; i < n; ++i)
{
LedgerKeySet searchSubset;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -496,7 +496,7 @@ class BucketIndexPoolShareTest : public BucketIndexTest
{
auto searchableBL = getBM()
.getBucketSnapshotManager()
.copySearchableLiveBucketListSnapshot(true);
.copySearchableLiveBucketListSnapshot();
auto loadResult =
searchableBL->loadPoolShareTrustLinesByAccountAndAsset(
mAccountToSearch.accountID, mAssetToSearch);
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class LedgerManager
getLastClosedLedgerHeader() const = 0;

// Get bucketlist snapshot
virtual std::shared_ptr<SearchableLiveBucketListSnapshot>
virtual std::shared_ptr<SearchableLiveBucketListSnapshot const>
getCurrentLedgerStateSnaphot() = 0;

// return the HAS that corresponds to the last closed ledger as persisted in
Expand Down
8 changes: 3 additions & 5 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,17 +1252,15 @@ LedgerManagerImpl::maybeResetLedgerCloseMetaDebugStream(uint32_t ledgerSeq)
}
}

std::shared_ptr<SearchableLiveBucketListSnapshot>
std::shared_ptr<SearchableLiveBucketListSnapshot const>
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;
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ledger/LedgerManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LedgerManagerImpl : public LedgerManager
medida::Timer& mMetaStreamWriteTime;
VirtualClock::time_point mLastClose;
bool mRebuildInMemoryState{false};
std::shared_ptr<SearchableLiveBucketListSnapshot>
std::shared_ptr<SearchableLiveBucketListSnapshot const>
mReadOnlyLedgerStateSnapshot;

std::unique_ptr<VirtualClock::time_point> mStartCatchup;
Expand Down Expand Up @@ -202,7 +202,7 @@ class LedgerManagerImpl : public LedgerManager

SorobanMetrics& getSorobanMetrics() override;

std::shared_ptr<SearchableLiveBucketListSnapshot>
std::shared_ptr<SearchableLiveBucketListSnapshot const>
getCurrentLedgerStateSnaphot() override;
};
}
6 changes: 3 additions & 3 deletions src/ledger/LedgerStateSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ LedgerTxnReadOnly::executeWithMaybeInnerSnapshot(
return f(lsg);
}

BucketSnapshotState::BucketSnapshotState(BucketManager& bm)
: mSnapshot(
bm.getBucketSnapshotManager().copySearchableLiveBucketListSnapshot())
BucketSnapshotState::BucketSnapshotState(
std::shared_ptr<SearchableLiveBucketListSnapshot const> snapshot)
: mSnapshot(snapshot)
, mLedgerHeader(LedgerHeaderWrapper(
std::make_shared<LedgerHeader>(snapshot->getLedgerHeader())))
{
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/LedgerStateSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BucketSnapshotState : public AbstractLedgerStateSnapshot

public:
BucketSnapshotState(
std::shared_ptr<SearchableLiveBucketListSnapshot> snapshot);
std::shared_ptr<SearchableLiveBucketListSnapshot const> snapshot);
~BucketSnapshotState() override;

LastClosedLedger const& getLastClosedLedger() const override;
Expand Down
2 changes: 1 addition & 1 deletion src/ledger/LedgerTxn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3065,7 +3065,7 @@ LedgerTxnRoot::Impl::getSearchableLiveBucketListSnapshot() const
mSearchableBucketListSnapshot =
mApp.getBucketManager()
.getBucketSnapshotManager()
.copySearchableLiveBucketListSnapshot(/* autoUpdate */ true);
.copySearchableLiveBucketListSnapshot();
}

return *mSearchableBucketListSnapshot;
Expand Down
3 changes: 1 addition & 2 deletions src/main/QueryServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit b69ace5

Please sign in to comment.