Skip to content

Commit

Permalink
Use cached snapshot provided by BucketManager
Browse files Browse the repository at this point in the history
  • Loading branch information
marta-lokhova committed Sep 12, 2024
1 parent 9b91bcb commit 79b7860
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/bucket/BucketManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,5 +381,9 @@ class BucketManager : NonMovableOrCopyable
scheduleVerifyReferencedBucketsWork() = 0;

virtual Config const& getConfig() const = 0;

// Get bucketlist snapshot
virtual std::shared_ptr<SearchableBucketListSnapshot>
getSearchableBucketListSnapshot() = 0;
};
}
15 changes: 15 additions & 0 deletions src/bucket/BucketManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,4 +1509,19 @@ BucketManagerImpl::getConfig() const
{
return mApp.getConfig();
}

std::shared_ptr<SearchableBucketListSnapshot>
BucketManagerImpl::getSearchableBucketListSnapshot()
{
releaseAssert(mApp.getConfig().isUsingBucketListDB());
// Any other threads must maintain their own snapshot
releaseAssert(threadIsMain());
if (!mSearchableBucketListSnapshot)
{
mSearchableBucketListSnapshot =
mSnapshotManager->copySearchableBucketListSnapshot();
}

return mSearchableBucketListSnapshot;
}
}
5 changes: 5 additions & 0 deletions src/bucket/BucketManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class BucketManagerImpl : public BucketManager
std::unique_ptr<TmpDirManager> mTmpDirManager;
std::unique_ptr<TmpDir> mWorkDir;
std::map<Hash, std::shared_ptr<Bucket>> mSharedBuckets;
std::shared_ptr<SearchableBucketListSnapshot>
mSearchableBucketListSnapshot{};

// Lock for managing raw Bucket files or the bucket directory. This lock is
// only required for file access, but is not required for logical changes to
Expand Down Expand Up @@ -187,6 +189,9 @@ class BucketManagerImpl : public BucketManager
std::shared_ptr<BasicWork> scheduleVerifyReferencedBucketsWork() override;

Config const& getConfig() const override;

std::shared_ptr<SearchableBucketListSnapshot>
getSearchableBucketListSnapshot() override;
};

#define SKIP_1 50
Expand Down
7 changes: 3 additions & 4 deletions src/ledger/LedgerStateSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ LedgerTxnReadOnly::executeWithMaybeInnerSnapshot(
return f(lsg);
}

BucketSnapshotState::BucketSnapshotState(BucketSnapshotManager& bsm)
: mSnapshot(bsm.copySearchableBucketListSnapshot())
BucketSnapshotState::BucketSnapshotState(BucketManager& bm)
: mSnapshot(bm.getSearchableBucketListSnapshot())
, mLedgerHeader(LedgerHeaderWrapper(
std::make_shared<LedgerHeader>(mSnapshot->getLedgerHeader())))
{
Expand Down Expand Up @@ -233,8 +233,7 @@ LedgerSnapshot::LedgerSnapshot(Application& app)
}
else
{
mGetter = std::make_unique<BucketSnapshotState>(
app.getBucketManager().getBucketSnapshotManager());
mGetter = std::make_unique<BucketSnapshotState>(app.getBucketManager());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ledger/LedgerStateSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BucketSnapshotState : public AbstractLedgerStateSnapshot
LedgerHeaderWrapper mLedgerHeader;

public:
BucketSnapshotState(BucketSnapshotManager& bsm);
BucketSnapshotState(BucketManager& bm);
~BucketSnapshotState() override;

LedgerHeaderWrapper getLedgerHeader() const override;
Expand Down

0 comments on commit 79b7860

Please sign in to comment.