@@ -251,11 +251,10 @@ RestoredEntries::addLiveBucketlistRestore(LedgerKey const& key,
251251}
252252
253253void
254- RestoredEntries::addRestoresFrom (RestoredEntries const & other,
255- bool allowDuplicates)
254+ RestoredEntries::addRestoresFrom (RestoredEntries const & other)
256255{
257256 ZoneScoped;
258- // This method is called from three different call sites. In 2 of them it is
257+ // This method is called from three different call sites. In all three it is
259258 // correct to assert that each restore is new/disjoint from any existing
260259 // restore:
261260 //
@@ -272,19 +271,19 @@ RestoredEntries::addRestoresFrom(RestoredEntries const& other,
272271 // entry -- it'd be a concurrency bug if not! -- so there should not be
273272 // any other restores of the same entry from other threads.
274273 //
275- // In the third place we're committing from an ltx to its parent, and the
276- // ltx was actually starting with a copy of the restored-maps from the
277- // parent, so there are going to be duplicates. We allow duplicates in that
278- // case .
279- for (auto kvp : other.hotArchive )
274+ // - In the third call site we're committing from a child ltx to its
275+ // parent. Since child LedgerTxns only track their own restores (they
276+ // do not start with a copy of the parent's restored entries), there
277+ // should be no duplicates .
278+ for (auto const & kvp : other.hotArchive )
280279 {
281280 auto [_, inserted] = hotArchive.emplace (kvp.first , kvp.second );
282- releaseAssert (inserted || allowDuplicates );
281+ releaseAssert (inserted);
283282 }
284- for (auto kvp : other.liveBucketList )
283+ for (auto const & kvp : other.liveBucketList )
285284 {
286285 auto [_, inserted] = liveBucketList.emplace (kvp.first , kvp.second );
287- releaseAssert (inserted || allowDuplicates );
286+ releaseAssert (inserted);
288287 }
289288}
290289
@@ -435,15 +434,6 @@ LedgerTxn::Impl::Impl(LedgerTxn& self, AbstractLedgerTxnParent& parent,
435434 , mConsistency (LedgerTxnConsistency::EXACT )
436435 , mActiveThreadId (std::this_thread::get_id())
437436{
438- for (auto const & [key, entry] : mParent .getRestoredHotArchiveKeys ())
439- {
440- mRestoredEntries .hotArchive .emplace (key, entry);
441- }
442- for (auto const & [key, entry] : mParent .getRestoredLiveBucketListKeys ())
443- {
444- mRestoredEntries .liveBucketList .emplace (key, entry);
445- }
446-
447437 mParent .addChild (self, mode);
448438}
449439
@@ -703,10 +693,7 @@ LedgerTxn::Impl::commitChild(EntryIterator iter,
703693 printErrorAndAbort (" unknown fatal error during commit to LedgerTxn" );
704694 }
705695
706- // The child will have started with a copy of the parents mRestoredEntries,
707- // so we can see duplicates here, but duplicate restores would've been
708- // caught during restoration in the restoreFrom* functions.
709- mRestoredEntries .addRestoresFrom (restoredEntries, /* allowDuplicates=*/ true );
696+ mRestoredEntries .addRestoresFrom (restoredEntries);
710697
711698 // std::unique_ptr<...>::swap does not throw
712699 mHeader .swap (childHeader);
@@ -915,6 +902,41 @@ LedgerTxn::Impl::markRestoredFromHotArchive(LedgerEntry const& ledgerEntry,
915902 addKey (ttlEntry);
916903}
917904
905+ void
906+ LedgerTxn::markRestoredFromLiveBucketList (LedgerEntry const & ledgerEntry,
907+ LedgerEntry const & ttlEntry)
908+ {
909+ getImpl ()->markRestoredFromLiveBucketList (ledgerEntry, ttlEntry);
910+ }
911+
912+ void
913+ LedgerTxn::Impl::markRestoredFromLiveBucketList (LedgerEntry const & ledgerEntry,
914+ LedgerEntry const & ttlEntry)
915+ {
916+ abortIfWrongThread (" markRestoredFromLiveBucketList" );
917+ throwIfSealed ();
918+ throwIfChild ();
919+
920+ if (!isPersistentEntry (ledgerEntry.data ))
921+ {
922+ throw std::runtime_error (
923+ " Key type not supported for live BucketList restore" );
924+ }
925+
926+ // Mark the keys as restored
927+ auto addKey = [this ](LedgerEntry const & entry) {
928+ auto [_, inserted] = mRestoredEntries .liveBucketList .emplace (
929+ LedgerEntryKey (entry), entry);
930+ if (!inserted)
931+ {
932+ throw std::runtime_error (
933+ " Key already restored from Live BucketList" );
934+ }
935+ };
936+ addKey (ledgerEntry);
937+ addKey (ttlEntry);
938+ }
939+
918940LedgerTxnEntry
919941LedgerTxn::restoreFromLiveBucketList (LedgerEntry const & entry, uint32_t ttl)
920942{
0 commit comments