Skip to content

Commit

Permalink
Switch LedgerStateSnapshot to using LM's snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Dec 20, 2024
1 parent 50f7d59 commit 21f2b39
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class LedgerManager
virtual LedgerHeaderHistoryEntry const&
getLastClosedLedgerHeader() const = 0;

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

// return the HAS that corresponds to the last closed ledger as persisted in
// the database
virtual HistoryArchiveState getLastClosedLedgerHAS() = 0;
Expand Down
13 changes: 13 additions & 0 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,19 @@ LedgerManagerImpl::maybeResetLedgerCloseMetaDebugStream(uint32_t ledgerSeq)
}
}

std::shared_ptr<SearchableLiveBucketListSnapshot>
LedgerManagerImpl::getCurrentLedgerStateSnaphot()
{
if (!mReadOnlyLedgerStateSnapshot)
{
mReadOnlyLedgerStateSnapshot =
mApp.getBucketManager()
.getBucketSnapshotManager()
.copySearchableLiveBucketListSnapshot();
}
return mReadOnlyLedgerStateSnapshot;
}

void
LedgerManagerImpl::advanceLedgerPointers(LedgerHeader const& header,
bool debugLog)
Expand Down
5 changes: 5 additions & 0 deletions src/ledger/LedgerManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class LedgerManagerImpl : public LedgerManager
medida::Timer& mMetaStreamWriteTime;
VirtualClock::time_point mLastClose;
bool mRebuildInMemoryState{false};
std::shared_ptr<SearchableLiveBucketListSnapshot>
mReadOnlyLedgerStateSnapshot;

std::unique_ptr<VirtualClock::time_point> mStartCatchup;
medida::Timer& mCatchupDuration;
Expand Down Expand Up @@ -202,5 +204,8 @@ class LedgerManagerImpl : public LedgerManager
void maybeResetLedgerCloseMetaDebugStream(uint32_t ledgerSeq);

SorobanMetrics& getSorobanMetrics() override;

std::shared_ptr<SearchableLiveBucketListSnapshot>
getCurrentLedgerStateSnaphot() override;
};
}
5 changes: 3 additions & 2 deletions src/ledger/LedgerStateSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "ledger/LedgerStateSnapshot.h"
#include "bucket/BucketManager.h"
#include "bucket/BucketSnapshotManager.h"
#include "ledger/LedgerManager.h"
#include "ledger/LedgerTxn.h"
#include "main/Application.h"
#include "transactions/TransactionFrame.h"
Expand Down Expand Up @@ -248,7 +248,8 @@ LedgerSnapshot::LedgerSnapshot(Application& app)
}
else
#endif
mGetter = std::make_unique<BucketSnapshotState>(app.getBucketManager());
mGetter = std::make_unique<BucketSnapshotState>(
app.getLedgerManager().getCurrentLedgerStateSnaphot());
}

LedgerHeaderWrapper
Expand Down
3 changes: 2 additions & 1 deletion src/ledger/LedgerStateSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class BucketSnapshotState : public AbstractLedgerStateSnapshot
LastClosedLedger const mLastClosedLedger;

public:
BucketSnapshotState(BucketManager& bm);
BucketSnapshotState(
std::shared_ptr<SearchableLiveBucketListSnapshot> snapshot);
~BucketSnapshotState() override;

LastClosedLedger const& getLastClosedLedger() const override;
Expand Down

0 comments on commit 21f2b39

Please sign in to comment.