Skip to content

Commit

Permalink
Merge pull request #4329 from graydon/bug-4324-io-context-race-in-buc…
Browse files Browse the repository at this point in the history
…ket-merge

Fix #4324 by switching io_context in merge, also reduce contact with app

Reviewed-by: marta-lokhova
  • Loading branch information
latobarita authored May 22, 2024
2 parents 1bc57e7 + 2abb588 commit 0f35905
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/bucket/FutureBucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,14 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
checkState();
return;
}
asio::io_context& ctx = app.getWorkerIOContext();
bool doFsync = !app.getConfig().DISABLE_XDR_FSYNC;
std::chrono::seconds availableTime = getAvailableTimeForMerge(app, level);

using task_t = std::packaged_task<std::shared_ptr<Bucket>()>;
std::shared_ptr<task_t> task = std::make_shared<task_t>(
[curr, snap, &bm, shadows, maxProtocolVersion, countMergeEvents, level,
&timer, &app]() mutable {
&timer, &ctx, doFsync, availableTime]() mutable {
auto timeScope = timer.TimeScope();
CLOG_TRACE(Bucket, "Worker merging curr={} with snap={}",
hexAbbrev(curr->getHash()), hexAbbrev(snap->getHash()));
Expand All @@ -358,11 +362,10 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
ZoneNamedN(mergeZone, "Merge task", true);
ZoneValueV(mergeZone, static_cast<int64_t>(level));

auto res = Bucket::merge(
bm, maxProtocolVersion, curr, snap, shadows,
BucketList::keepDeadEntries(level), countMergeEvents,
app.getClock().getIOContext(),
!app.getConfig().DISABLE_XDR_FSYNC);
auto res =
Bucket::merge(bm, maxProtocolVersion, curr, snap, shadows,
BucketList::keepDeadEntries(level),
countMergeEvents, ctx, doFsync);

if (res)
{
Expand All @@ -371,9 +374,7 @@ FutureBucket::startMerge(Application& app, uint32_t maxProtocolVersion,
hexAbbrev(curr->getHash()), hexAbbrev(snap->getHash()));

std::chrono::duration<double> time(timeScope.Stop());
double timePct =
time.count() /
getAvailableTimeForMerge(app, level).count() * 100;
double timePct = time.count() / availableTime.count() * 100;
CLOG_DEBUG(
Perf,
"Bucket merge on level {} finished in {} seconds "
Expand Down

0 comments on commit 0f35905

Please sign in to comment.