Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/bucket/BucketOutputIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ template <typename BucketT>
std::shared_ptr<BucketT>
BucketOutputIterator<BucketT>::getBucket(
BucketManager& bucketManager, MergeKey* mergeKey,
std::unique_ptr<std::vector<typename BucketT::EntryT>> inMemoryState)
std::unique_ptr<std::vector<typename BucketT::EntryT>> inMemoryState,
std::shared_ptr<typename BucketT::IndexT const> preBuiltIndex)
{
ZoneScoped;
if (mBuf)
Expand Down Expand Up @@ -219,7 +220,11 @@ BucketOutputIterator<BucketT>::getBucket(

if (!index)
{
if constexpr (std::is_same_v<BucketT, LiveBucket>)
if (preBuiltIndex)
{
index = std::move(preBuiltIndex);
}
else if constexpr (std::is_same_v<BucketT, LiveBucket>)
{
if (inMemoryState)
{
Expand Down
2 changes: 2 additions & 0 deletions src/bucket/BucketOutputIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ template <typename BucketT> class BucketOutputIterator
std::shared_ptr<BucketT> getBucket(
BucketManager& bucketManager, MergeKey* mergeKey = nullptr,
std::unique_ptr<std::vector<typename BucketT::EntryT>> inMemoryState =
nullptr,
std::shared_ptr<typename BucketT::IndexT const> preBuiltIndex =
nullptr);
};
}
14 changes: 13 additions & 1 deletion src/bucket/LiveBucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "bucket/BucketOutputIterator.h"
#include "bucket/BucketUtils.h"
#include "bucket/LedgerCmp.h"
#include <future>
#include <medida/counter.h>

namespace stellar
Expand Down Expand Up @@ -595,6 +596,14 @@ LiveBucket::mergeInMemory(BucketManager& bucketManager,
bucketManager.incrMergeCounters<LiveBucket>(mc);
}

// Start index construction on a worker thread, the inputs are all
// read-only from that point on.
auto indexFuture = std::async(
std::launch::async, [&bucketManager, &mergedEntries, &meta]() {
return std::make_shared<LiveBucketIndex const>(bucketManager,
mergedEntries, meta);
});
Comment thread
dmkozh marked this conversation as resolved.

// Write merge output to a bucket and save to disk
LiveBucketOutputIterator out(bucketManager.getTmpDir(),
/*keepTombstoneEntries=*/true, meta, mc, ctx,
Expand All @@ -605,11 +614,14 @@ LiveBucket::mergeInMemory(BucketManager& bucketManager,
out.put(e);
}

auto preBuiltIndex = indexFuture.get();

// Store the merged entries in memory in the new bucket in case this
// bucket sees another incoming merge as level 0 curr.
return out.getBucket(
bucketManager, nullptr,
std::make_unique<std::vector<BucketEntry>>(std::move(mergedEntries)));
std::make_unique<std::vector<BucketEntry>>(std::move(mergedEntries)),
std::move(preBuiltIndex));
}

BucketEntryCounters const&
Expand Down
Loading