@@ -89,9 +89,13 @@ BucketManagerImpl::initialize()
89
89
if (mApp .getConfig ().MODE_ENABLES_BUCKETLIST )
90
90
{
91
91
mBucketList = std::make_unique<BucketList>();
92
- mSnapshotManager = std::make_unique<BucketSnapshotManager>(
93
- mApp .getMetrics (),
94
- std::make_unique<BucketListSnapshot>(*mBucketList , 0 ));
92
+
93
+ if (mApp .getConfig ().isUsingBucketListDB ())
94
+ {
95
+ mSnapshotManager = std::make_unique<BucketSnapshotManager>(
96
+ mApp .getMetrics (),
97
+ std::make_unique<BucketListSnapshot>(*mBucketList , 0 ));
98
+ }
95
99
}
96
100
}
97
101
@@ -185,7 +189,7 @@ std::string const&
185
189
BucketManagerImpl::getTmpDir ()
186
190
{
187
191
ZoneScoped;
188
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
192
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
189
193
if (!mWorkDir )
190
194
{
191
195
TmpDir t = mTmpDirManager ->tmpDir (" bucket" );
@@ -268,7 +272,8 @@ BucketManagerImpl::getBucketList()
268
272
BucketSnapshotManager&
269
273
BucketManagerImpl::getBucketSnapshotManager () const
270
274
{
271
- releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
275
+ releaseAssertOrThrow (mApp .getConfig ().isUsingBucketListDB ());
276
+ releaseAssert (mSnapshotManager );
272
277
return *mSnapshotManager ;
273
278
}
274
279
@@ -281,7 +286,7 @@ BucketManagerImpl::getMergeTimer()
281
286
MergeCounters
282
287
BucketManagerImpl::readMergeCounters ()
283
288
{
284
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
289
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
285
290
return mMergeCounters ;
286
291
}
287
292
@@ -371,7 +376,7 @@ MergeCounters::operator==(MergeCounters const& other) const
371
376
void
372
377
BucketManagerImpl::incrMergeCounters (MergeCounters const & delta)
373
378
{
374
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
379
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
375
380
mMergeCounters += delta;
376
381
}
377
382
@@ -397,7 +402,7 @@ BucketManagerImpl::adoptFileAsBucket(std::string const& filename,
397
402
{
398
403
ZoneScoped;
399
404
releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
400
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
405
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
401
406
402
407
if (mergeKey)
403
408
{
@@ -481,7 +486,7 @@ BucketManagerImpl::noteEmptyMergeOutput(MergeKey const& mergeKey)
481
486
// because it'd over-identify multiple individual inputs with the empty
482
487
// output, potentially retaining far too many inputs, as lots of different
483
488
// mergeKeys result in an empty output.
484
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
489
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
485
490
CLOG_TRACE (Bucket, " BucketManager::noteEmptyMergeOutput({})" , mergeKey);
486
491
mLiveFutures .erase (mergeKey);
487
492
}
@@ -490,7 +495,7 @@ std::shared_ptr<Bucket>
490
495
BucketManagerImpl::getBucketIfExists (uint256 const & hash)
491
496
{
492
497
ZoneScoped;
493
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
498
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
494
499
auto i = mSharedBuckets .find (hash);
495
500
if (i != mSharedBuckets .end ())
496
501
{
@@ -507,7 +512,7 @@ std::shared_ptr<Bucket>
507
512
BucketManagerImpl::getBucketByHash (uint256 const & hash)
508
513
{
509
514
ZoneScoped;
510
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
515
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
511
516
if (isZero (hash))
512
517
{
513
518
return std::make_shared<Bucket>();
@@ -540,7 +545,7 @@ std::shared_future<std::shared_ptr<Bucket>>
540
545
BucketManagerImpl::getMergeFuture (MergeKey const & key)
541
546
{
542
547
ZoneScoped;
543
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
548
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
544
549
MergeCounters mc;
545
550
auto i = mLiveFutures .find (key);
546
551
if (i == mLiveFutures .end ())
@@ -586,7 +591,7 @@ BucketManagerImpl::putMergeFuture(
586
591
{
587
592
ZoneScoped;
588
593
releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
589
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
594
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
590
595
CLOG_TRACE (
591
596
Bucket,
592
597
" BucketManager::putMergeFuture storing future for running merge {}" ,
@@ -598,7 +603,7 @@ BucketManagerImpl::putMergeFuture(
598
603
void
599
604
BucketManagerImpl::clearMergeFuturesForTesting ()
600
605
{
601
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
606
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
602
607
mLiveFutures .clear ();
603
608
}
604
609
#endif
@@ -697,7 +702,7 @@ BucketManagerImpl::cleanupStaleFiles()
697
702
return ;
698
703
}
699
704
700
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
705
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
701
706
auto referenced = getAllReferencedBuckets ();
702
707
std::transform (std::begin (mSharedBuckets ), std::end (mSharedBuckets ),
703
708
std::inserter (referenced, std::end (referenced)),
727
732
BucketManagerImpl::forgetUnreferencedBuckets ()
728
733
{
729
734
ZoneScoped;
730
- std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
735
+ std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
731
736
auto referenced = getAllReferencedBuckets ();
732
737
auto blReferenced = getBucketListReferencedBuckets ();
733
738
@@ -837,8 +842,12 @@ BucketManagerImpl::addBatch(Application& app, uint32_t currLedger,
837
842
mBucketList ->addBatch (app, currLedger, currLedgerProtocol, initEntries,
838
843
liveEntries, deadEntries);
839
844
mBucketListSizeCounter .set_count (mBucketList ->getSize ());
840
- mSnapshotManager ->updateCurrentSnapshot (
841
- std::make_unique<BucketListSnapshot>(*mBucketList , currLedger));
845
+
846
+ if (app.getConfig ().isUsingBucketListDB ())
847
+ {
848
+ mSnapshotManager ->updateCurrentSnapshot (
849
+ std::make_unique<BucketListSnapshot>(*mBucketList , currLedger));
850
+ }
842
851
}
843
852
844
853
#ifdef BUILD_TESTS
@@ -978,60 +987,57 @@ BucketManagerImpl::assumeState(HistoryArchiveState const& has,
978
987
ZoneScoped;
979
988
releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
980
989
990
+ for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
981
991
{
982
- for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
992
+ auto curr = getBucketByHash (hexToBin256 (has.currentBuckets .at (i).curr ));
993
+ auto snap = getBucketByHash (hexToBin256 (has.currentBuckets .at (i).snap ));
994
+ if (!(curr && snap))
983
995
{
984
- auto curr =
985
- getBucketByHash (hexToBin256 (has.currentBuckets .at (i).curr ));
986
- auto snap =
987
- getBucketByHash (hexToBin256 (has.currentBuckets .at (i).snap ));
988
- if (!(curr && snap))
989
- {
990
- throw std::runtime_error (" Missing bucket files while assuming "
991
- " saved BucketList state" );
992
- }
996
+ throw std::runtime_error (" Missing bucket files while assuming "
997
+ " saved BucketList state" );
998
+ }
993
999
994
- auto const & nextFuture = has.currentBuckets .at (i).next ;
995
- std::shared_ptr<Bucket> nextBucket = nullptr ;
996
- if (nextFuture.hasOutputHash ())
1000
+ auto const & nextFuture = has.currentBuckets .at (i).next ;
1001
+ std::shared_ptr<Bucket> nextBucket = nullptr ;
1002
+ if (nextFuture.hasOutputHash ())
1003
+ {
1004
+ nextBucket =
1005
+ getBucketByHash (hexToBin256 (nextFuture.getOutputHash ()));
1006
+ if (!nextBucket)
997
1007
{
998
- nextBucket =
999
- getBucketByHash (hexToBin256 (nextFuture.getOutputHash ()));
1000
- if (!nextBucket)
1001
- {
1002
- throw std::runtime_error (
1003
- " Missing future bucket files while "
1004
- " assuming saved BucketList state" );
1005
- }
1008
+ throw std::runtime_error (" Missing future bucket files while "
1009
+ " assuming saved BucketList state" );
1006
1010
}
1011
+ }
1007
1012
1008
- // Buckets on the BucketList should always be indexed when
1009
- // BucketListDB enabled
1010
- if (mApp .getConfig ().isUsingBucketListDB ())
1013
+ // Buckets on the BucketList should always be indexed when
1014
+ // BucketListDB enabled
1015
+ if (mApp .getConfig ().isUsingBucketListDB ())
1016
+ {
1017
+ releaseAssert (curr->isEmpty () || curr->isIndexed ());
1018
+ releaseAssert (snap->isEmpty () || snap->isIndexed ());
1019
+ if (nextBucket)
1011
1020
{
1012
- releaseAssert (curr->isEmpty () || curr->isIndexed ());
1013
- releaseAssert (snap->isEmpty () || snap->isIndexed ());
1014
- if (nextBucket)
1015
- {
1016
- releaseAssert (nextBucket->isEmpty () ||
1017
- nextBucket->isIndexed ());
1018
- }
1021
+ releaseAssert (nextBucket->isEmpty () || nextBucket->isIndexed ());
1019
1022
}
1020
-
1021
- mBucketList ->getLevel (i).setCurr (curr);
1022
- mBucketList ->getLevel (i).setSnap (snap);
1023
- mBucketList ->getLevel (i).setNext (nextFuture);
1024
1023
}
1025
1024
1026
- if (restartMerges)
1027
- {
1028
- mBucketList ->restartMerges (mApp , maxProtocolVersion,
1029
- has.currentLedger );
1030
- }
1025
+ mBucketList ->getLevel (i).setCurr (curr);
1026
+ mBucketList ->getLevel (i).setSnap (snap);
1027
+ mBucketList ->getLevel (i).setNext (nextFuture);
1028
+ }
1029
+
1030
+ if (restartMerges)
1031
+ {
1032
+ mBucketList ->restartMerges (mApp , maxProtocolVersion, has.currentLedger );
1031
1033
}
1032
1034
1033
- mSnapshotManager ->updateCurrentSnapshot (
1034
- std::make_unique<BucketListSnapshot>(*mBucketList , has.currentLedger ));
1035
+ if (mApp .getConfig ().isUsingBucketListDB ())
1036
+ {
1037
+ mSnapshotManager ->updateCurrentSnapshot (
1038
+ std::make_unique<BucketListSnapshot>(*mBucketList ,
1039
+ has.currentLedger ));
1040
+ }
1035
1041
cleanupStaleFiles ();
1036
1042
}
1037
1043
0 commit comments