Skip to content

Commit 9b5bee7

Browse files
committed
Delay restarting merges in startup path
1 parent e6d4a41 commit 9b5bee7

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

‎src/bucket/BucketManager.cpp‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,17 +1393,26 @@ BucketManager::assumeState(Application& app, HistoryArchiveState const& has,
13931393

13941394
if (restartMerges)
13951395
{
1396-
mLiveBucketList->restartMerges(app, maxProtocolVersion,
1397-
has.currentLedger);
1398-
if (has.hasHotArchiveBuckets())
1399-
{
1400-
mHotArchiveBucketList->restartMerges(app, maxProtocolVersion,
1401-
has.currentLedger);
1402-
}
1396+
this->restartMerges(app, has, maxProtocolVersion);
14031397
}
14041398
cleanupStaleFiles(has);
14051399
}
14061400

1401+
void
1402+
BucketManager::restartMerges(Application& app, HistoryArchiveState const& has,
1403+
uint32_t maxProtocolVersion)
1404+
{
1405+
ZoneScoped;
1406+
releaseAssert(threadIsMain());
1407+
1408+
mLiveBucketList->restartMerges(app, maxProtocolVersion, has.currentLedger);
1409+
if (has.hasHotArchiveBuckets())
1410+
{
1411+
mHotArchiveBucketList->restartMerges(app, maxProtocolVersion,
1412+
has.currentLedger);
1413+
}
1414+
}
1415+
14071416
void
14081417
BucketManager::shutdown()
14091418
{

‎src/bucket/BucketManager.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ class BucketManager : NonMovableOrCopyable
398398
void assumeState(Application& app, HistoryArchiveState const& has,
399399
uint32_t maxProtocolVersion, bool restartMerges);
400400

401+
// Restart any in-progress merges captured in `has`. Safe to call only
402+
// after `assumeState` has populated the BucketList from the same `has`.
403+
void restartMerges(Application& app, HistoryArchiveState const& has,
404+
uint32_t maxProtocolVersion);
405+
401406
void shutdown();
402407

403408
bool isShutdown() const;

‎src/ledger/LedgerManagerImpl.cpp‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,13 +581,11 @@ LedgerManagerImpl::loadLastKnownLedgerInternal(bool skipBuildingFullState)
581581
throw std::runtime_error("Bucket directory is corrupt");
582582
}
583583

584-
// Only restart merges in full startup mode. Many modes in core
585-
// (standalone offline commands, in-memory setup) do not need to
586-
// spin up expensive merge processes.
587584
auto assumeStart = mApp.getClock().now();
585+
// We don't restart merges here so that in-memory state population is
586+
// faster.
588587
auto assumeStateWork = mApp.getWorkScheduler().executeWork<AssumeStateWork>(
589-
has, latestLedgerHeader->ledgerVersion,
590-
/* restartMerges */ !skipBuildingFullState);
588+
has, latestLedgerHeader->ledgerVersion, /* restartMerges */ false);
591589
if (assumeStateWork->getState() == BasicWork::State::WORK_SUCCESS)
592590
{
593591
std::chrono::duration<double> assumeSecs =
@@ -630,6 +628,12 @@ LedgerManagerImpl::loadLastKnownLedgerInternal(bool skipBuildingFullState)
630628

631629
maybeRunSnapshotInvariantFromLedgerState(copyApplyLedgerView(),
632630
/* runInParallel */ false);
631+
632+
// Only restart merges in full startup mode. Many modes in core
633+
// (standalone offline commands, in-memory setup) do not need to spin up
634+
// expensive merge processes.
635+
mApp.getBucketManager().restartMerges(
636+
mApp, has, latestLedgerHeader->ledgerVersion);
633637
}
634638
mApplyState.markEndOfSetupPhase();
635639

0 commit comments

Comments
 (0)