7
7
#include " bucket/BucketInputIterator.h"
8
8
#include " bucket/BucketList.h"
9
9
#include " bucket/BucketOutputIterator.h"
10
- #include " bucket/SearcahbleBucketListSnapshot .h"
10
+ #include " bucket/SearchableBucketListSnapshot .h"
11
11
#include " crypto/Hex.h"
12
12
#include " history/HistoryManager.h"
13
13
#include " historywork/VerifyBucketWork.h"
@@ -180,7 +180,7 @@ std::string const&
180
180
BucketManagerImpl::getTmpDir ()
181
181
{
182
182
ZoneScoped;
183
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
183
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
184
184
if (!mWorkDir )
185
185
{
186
186
TmpDir t = mTmpDirManager ->tmpDir (" bucket" );
@@ -269,7 +269,7 @@ BucketManagerImpl::getMergeTimer()
269
269
MergeCounters
270
270
BucketManagerImpl::readMergeCounters ()
271
271
{
272
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
272
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
273
273
return mMergeCounters ;
274
274
}
275
275
@@ -359,7 +359,7 @@ MergeCounters::operator==(MergeCounters const& other) const
359
359
void
360
360
BucketManagerImpl::incrMergeCounters (MergeCounters const & delta)
361
361
{
362
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
362
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
363
363
mMergeCounters += delta;
364
364
}
365
365
@@ -385,7 +385,7 @@ BucketManagerImpl::adoptFileAsBucket(std::string const& filename,
385
385
{
386
386
ZoneScoped;
387
387
releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
388
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
388
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
389
389
390
390
if (mergeKey)
391
391
{
@@ -469,7 +469,7 @@ BucketManagerImpl::noteEmptyMergeOutput(MergeKey const& mergeKey)
469
469
// because it'd over-identify multiple individual inputs with the empty
470
470
// output, potentially retaining far too many inputs, as lots of different
471
471
// mergeKeys result in an empty output.
472
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
472
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
473
473
CLOG_TRACE (Bucket, " BucketManager::noteEmptyMergeOutput({})" , mergeKey);
474
474
mLiveFutures .erase (mergeKey);
475
475
}
@@ -478,7 +478,7 @@ std::shared_ptr<Bucket>
478
478
BucketManagerImpl::getBucketIfExists (uint256 const & hash)
479
479
{
480
480
ZoneScoped;
481
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
481
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
482
482
auto i = mSharedBuckets .find (hash);
483
483
if (i != mSharedBuckets .end ())
484
484
{
@@ -495,7 +495,7 @@ std::shared_ptr<Bucket>
495
495
BucketManagerImpl::getBucketByHash (uint256 const & hash)
496
496
{
497
497
ZoneScoped;
498
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
498
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
499
499
if (isZero (hash))
500
500
{
501
501
return std::make_shared<Bucket>();
@@ -528,7 +528,7 @@ std::shared_future<std::shared_ptr<Bucket>>
528
528
BucketManagerImpl::getMergeFuture (MergeKey const & key)
529
529
{
530
530
ZoneScoped;
531
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
531
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
532
532
MergeCounters mc;
533
533
auto i = mLiveFutures .find (key);
534
534
if (i == mLiveFutures .end ())
@@ -574,7 +574,7 @@ BucketManagerImpl::putMergeFuture(
574
574
{
575
575
ZoneScoped;
576
576
releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
577
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
577
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
578
578
CLOG_TRACE (
579
579
Bucket,
580
580
" BucketManager::putMergeFuture storing future for running merge {}" ,
@@ -586,7 +586,7 @@ BucketManagerImpl::putMergeFuture(
586
586
void
587
587
BucketManagerImpl::clearMergeFuturesForTesting ()
588
588
{
589
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
589
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
590
590
mLiveFutures .clear ();
591
591
}
592
592
#endif
@@ -685,7 +685,7 @@ BucketManagerImpl::cleanupStaleFiles()
685
685
return ;
686
686
}
687
687
688
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
688
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
689
689
auto referenced = getAllReferencedBuckets ();
690
690
std::transform (std::begin (mSharedBuckets ), std::end (mSharedBuckets ),
691
691
std::inserter (referenced, std::end (referenced)),
715
715
BucketManagerImpl::forgetUnreferencedBuckets ()
716
716
{
717
717
ZoneScoped;
718
- std::lock_guard<std::recursive_mutex> lock (mBucketMutex );
718
+ std::lock_guard<std::recursive_mutex> lock (mBucketFileMutex );
719
719
auto referenced = getAllReferencedBuckets ();
720
720
auto blReferenced = getBucketListReferencedBuckets ();
721
721
@@ -822,8 +822,11 @@ BucketManagerImpl::addBatch(Application& app, uint32_t currLedger,
822
822
auto timer = mBucketAddBatch .TimeScope ();
823
823
mBucketObjectInsertBatch .Mark (initEntries.size () + liveEntries.size () +
824
824
deadEntries.size ());
825
- mBucketList ->addBatch (app, currLedger, currLedgerProtocol, initEntries,
826
- liveEntries, deadEntries);
825
+ {
826
+ std::lock_guard<std::recursive_mutex> lock (mBucketSnapshotMutex );
827
+ mBucketList ->addBatch (app, currLedger, currLedgerProtocol, initEntries,
828
+ liveEntries, deadEntries);
829
+ }
827
830
mBucketListSizeCounter .set_count (mBucketList ->getSize ());
828
831
}
829
832
@@ -905,11 +908,15 @@ BucketManagerImpl::scanForEvictionLegacySQL(AbstractLedgerTxn& ltx,
905
908
}
906
909
907
910
std::unique_ptr<SearchableBucketListSnapshot const >
908
- BucketManagerImpl::getSearchableBucketListSnapshot (bool isMainThread ) const
911
+ BucketManagerImpl::getSearchableBucketListSnapshot () const
909
912
{
910
- // TODO: Lock this
911
913
releaseAssertOrThrow (mApp .getConfig ().isUsingBucketListDB () && mBucketList );
912
- return std::make_unique<SearchableBucketListSnapshot>(mApp , *mBucketList );
914
+
915
+ std::lock_guard<std::recursive_mutex> lock (mBucketSnapshotMutex );
916
+
917
+ // Note: cannot use make_unique due to private constructor
918
+ return std::unique_ptr<SearchableBucketListSnapshot>(
919
+ new SearchableBucketListSnapshot (mApp , *mBucketList ));
913
920
}
914
921
915
922
medida::Meter&
@@ -972,47 +979,55 @@ BucketManagerImpl::assumeState(HistoryArchiveState const& has,
972
979
ZoneScoped;
973
980
releaseAssertOrThrow (mApp .getConfig ().MODE_ENABLES_BUCKETLIST );
974
981
975
- for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
976
982
{
977
- auto curr = getBucketByHash (hexToBin256 (has.currentBuckets .at (i).curr ));
978
- auto snap = getBucketByHash (hexToBin256 (has.currentBuckets .at (i).snap ));
979
- if (!(curr && snap))
983
+ std::lock_guard<std::recursive_mutex> lock (mBucketSnapshotMutex );
984
+ for (uint32_t i = 0 ; i < BucketList::kNumLevels ; ++i)
980
985
{
981
- throw std::runtime_error (
982
- " Missing bucket files while assuming saved BucketList state" );
983
- }
986
+ auto curr =
987
+ getBucketByHash (hexToBin256 (has.currentBuckets .at (i).curr ));
988
+ auto snap =
989
+ getBucketByHash (hexToBin256 (has.currentBuckets .at (i).snap ));
990
+ if (!(curr && snap))
991
+ {
992
+ throw std::runtime_error (" Missing bucket files while assuming "
993
+ " saved BucketList state" );
994
+ }
984
995
985
- auto const & nextFuture = has.currentBuckets .at (i).next ;
986
- std::shared_ptr<Bucket> nextBucket = nullptr ;
987
- if (nextFuture.hasOutputHash ())
988
- {
989
- nextBucket =
990
- getBucketByHash (hexToBin256 (nextFuture.getOutputHash ()));
991
- if (!nextBucket)
996
+ auto const & nextFuture = has.currentBuckets .at (i).next ;
997
+ std::shared_ptr<Bucket> nextBucket = nullptr ;
998
+ if (nextFuture.hasOutputHash ())
992
999
{
993
- throw std::runtime_error (" Missing future bucket files while "
994
- " assuming saved BucketList state" );
1000
+ nextBucket =
1001
+ getBucketByHash (hexToBin256 (nextFuture.getOutputHash ()));
1002
+ if (!nextBucket)
1003
+ {
1004
+ throw std::runtime_error (
1005
+ " Missing future bucket files while "
1006
+ " assuming saved BucketList state" );
1007
+ }
995
1008
}
996
- }
997
1009
998
- // Buckets on the BucketList should always be indexed when BucketListDB
999
- // enabled
1000
- if (mApp .getConfig ().isUsingBucketListDB ())
1001
- {
1002
- releaseAssert (curr->isEmpty () || curr->isIndexed ());
1003
- releaseAssert (snap->isEmpty () || snap->isIndexed ());
1004
- if (nextBucket)
1010
+ // Buckets on the BucketList should always be indexed when
1011
+ // BucketListDB enabled
1012
+ if (mApp .getConfig ().isUsingBucketListDB ())
1005
1013
{
1006
- releaseAssert (nextBucket->isEmpty () || nextBucket->isIndexed ());
1014
+ releaseAssert (curr->isEmpty () || curr->isIndexed ());
1015
+ releaseAssert (snap->isEmpty () || snap->isIndexed ());
1016
+ if (nextBucket)
1017
+ {
1018
+ releaseAssert (nextBucket->isEmpty () ||
1019
+ nextBucket->isIndexed ());
1020
+ }
1007
1021
}
1022
+
1023
+ mBucketList ->getLevel (i).setCurr (curr);
1024
+ mBucketList ->getLevel (i).setSnap (snap);
1025
+ mBucketList ->getLevel (i).setNext (nextFuture);
1008
1026
}
1009
1027
1010
- mBucketList ->getLevel (i).setCurr (curr);
1011
- mBucketList ->getLevel (i).setSnap (snap);
1012
- mBucketList ->getLevel (i).setNext (nextFuture);
1028
+ mBucketList ->restartMerges (mApp , maxProtocolVersion, has.currentLedger );
1013
1029
}
1014
1030
1015
- mBucketList ->restartMerges (mApp , maxProtocolVersion, has.currentLedger );
1016
1031
cleanupStaleFiles ();
1017
1032
}
1018
1033
0 commit comments