Skip to content

Commit

Permalink
Make background eviction mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Nov 14, 2024
1 parent b820547 commit f333440
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 782 deletions.
5 changes: 0 additions & 5 deletions docs/stellar-core_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ BUCKETLIST_DB_INDEX_CUTOFF = 20
# this value is ingnored and indexes are never persisted.
BUCKETLIST_DB_PERSIST_INDEX = true

# BACKGROUND_EVICTION_SCAN (bool) default true
# Determines whether eviction scans occur in the background thread. Requires
# that DEPRECATED_SQL_LEDGER_STATE is set to false.
BACKGROUND_EVICTION_SCAN = true

# EXPERIMENTAL_BACKGROUND_OVERLAY_PROCESSING (bool) default false
# Determines whether some of overlay processing occurs in the background
# thread.
Expand Down
10 changes: 0 additions & 10 deletions src/bucket/BucketManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,16 +1067,6 @@ BucketManager::maybeSetIndex(std::shared_ptr<BucketBase> b,
}
}

void
BucketManager::scanForEvictionLegacy(AbstractLedgerTxn& ltx, uint32_t ledgerSeq)
{
ZoneScoped;
releaseAssert(protocolVersionStartsFrom(ltx.getHeader().ledgerVersion,
SOROBAN_PROTOCOL_VERSION));
mLiveBucketList->scanForEvictionLegacy(
mApp, ltx, ledgerSeq, mBucketListEvictionCounters, mEvictionStatistics);
}

void
BucketManager::startBackgroundEvictionScan(uint32_t ledgerSeq)
{
Expand Down
2 changes: 0 additions & 2 deletions src/bucket/BucketManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ class BucketManager : NonMovableOrCopyable
// Scans BucketList for non-live entries to evict starting at the entry
// pointed to by EvictionIterator. Scans until `maxEntriesToEvict` entries
// have been evicted or maxEvictionScanSize bytes have been scanned.
void scanForEvictionLegacy(AbstractLedgerTxn& ltx, uint32_t ledgerSeq);

void startBackgroundEvictionScan(uint32_t ledgerSeq);
void resolveBackgroundEvictionScan(AbstractLedgerTxn& ltx,
uint32_t ledgerSeq,
Expand Down
91 changes: 0 additions & 91 deletions src/bucket/LiveBucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,97 +419,6 @@ LiveBucket::checkProtocolLegality(BucketEntry const& entry,
}
}

Loop
LiveBucket::scanForEvictionLegacy(
AbstractLedgerTxn& ltx, EvictionIterator& iter, uint32_t& bytesToScan,
uint32_t& remainingEntriesToEvict, uint32_t ledgerSeq,
medida::Counter& entriesEvictedCounter,
medida::Counter& bytesScannedForEvictionCounter,
std::shared_ptr<EvictionStatistics> stats) const
{
ZoneScoped;
releaseAssert(stats);

if (isEmpty() ||
protocolVersionIsBefore(getBucketVersion(), SOROBAN_PROTOCOL_VERSION))
{
// EOF, need to continue reading next bucket
return Loop::INCOMPLETE;
}

if (remainingEntriesToEvict == 0 || bytesToScan == 0)
{
// Reached end of scan region
return Loop::COMPLETE;
}

XDRInputFileStream stream{};
stream.open(mFilename.string());
stream.seek(iter.bucketFileOffset);

BucketEntry be;
while (stream.readOne(be))
{
if (be.type() == INITENTRY || be.type() == LIVEENTRY)
{
auto const& le = be.liveEntry();
if (isTemporaryEntry(le.data))
{
ZoneNamedN(maybeEvict, "maybe evict entry", true);

auto ttlKey = getTTLKey(le);
uint32_t liveUntilLedger = 0;
auto shouldEvict = [&] {
auto ttlLtxe = ltx.loadWithoutRecord(ttlKey);
if (!ttlLtxe)
{
// Entry was already deleted either manually or by an
// earlier eviction scan, do nothing
return false;
}

releaseAssert(ttlLtxe);
liveUntilLedger =
ttlLtxe.current().data.ttl().liveUntilLedgerSeq;
return !isLive(ttlLtxe.current(), ledgerSeq);
};

if (shouldEvict())
{
ZoneNamedN(evict, "evict entry", true);
auto age = ledgerSeq - liveUntilLedger;
stats->recordEvictedEntry(age);

ltx.erase(ttlKey);
ltx.erase(LedgerEntryKey(le));
entriesEvictedCounter.inc();
--remainingEntriesToEvict;
}
}
}

auto newPos = stream.pos();
auto bytesRead = newPos - iter.bucketFileOffset;
iter.bucketFileOffset = newPos;
bytesScannedForEvictionCounter.inc(bytesRead);
if (bytesRead >= bytesToScan)
{
// Reached end of scan region
bytesToScan = 0;
return Loop::COMPLETE;
}
else if (remainingEntriesToEvict == 0)
{
return Loop::COMPLETE;
}

bytesToScan -= bytesRead;
}

// Hit eof
return Loop::INCOMPLETE;
}

LiveBucket::LiveBucket(std::string const& filename, Hash const& hash,
std::unique_ptr<BucketIndex const>&& index)
: BucketBase(filename, hash, std::move(index))
Expand Down
13 changes: 0 additions & 13 deletions src/bucket/LiveBucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,6 @@ class LiveBucket : public BucketBase,
void apply(Application& app) const;
#endif

// Returns Loop::INCOMPLETE if eof reached, Loop::COMPLETE otherwise.
// Modifies iter as the bucket is scanned. Also modifies bytesToScan and
// maxEntriesToEvict such that after this function returns:
// bytesToScan -= amount_bytes_scanned
// maxEntriesToEvict -= entries_evicted
Loop scanForEvictionLegacy(AbstractLedgerTxn& ltx, EvictionIterator& iter,
uint32_t& bytesToScan,
uint32_t& remainingEntriesToEvict,
uint32_t ledgerSeq,
medida::Counter& entriesEvictedCounter,
medida::Counter& bytesScannedForEvictionCounter,
std::shared_ptr<EvictionStatistics> stats) const;

// Create a fresh bucket from given vectors of init (created) and live
// (updated) LedgerEntries, and dead LedgerEntryKeys. The bucket will
// be sorted, hashed, and adopted in the provided BucketManager.
Expand Down
54 changes: 0 additions & 54 deletions src/bucket/LiveBucketList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "bucket/LiveBucketList.h"
#include "bucket/BucketListBase.h"
#include "ledger/LedgerManager.h"

#include <medida/counter.h>

Expand Down Expand Up @@ -145,57 +144,4 @@ LiveBucketList::checkIfEvictionScanIsStuck(EvictionIterator const& evictionIter,
counters.incompleteBucketScan.inc();
}
}

// To avoid noisy data, only count metrics that encompass a complete
// eviction cycle. If a node joins the network mid cycle, metrics will be
// nullopt and be initialized at the start of the next cycle.
void
LiveBucketList::scanForEvictionLegacy(Application& app, AbstractLedgerTxn& ltx,
uint32_t ledgerSeq,
EvictionCounters& counters,
std::shared_ptr<EvictionStatistics> stats)
{
releaseAssert(stats);

auto getBucketFromIter = [&levels = mLevels](EvictionIterator const& iter) {
auto& level = levels.at(iter.bucketListLevel);
return iter.isCurrBucket ? level.getCurr() : level.getSnap();
};

auto const& networkConfig =
app.getLedgerManager().getSorobanNetworkConfig();
auto const firstScanLevel =
networkConfig.stateArchivalSettings().startingEvictionScanLevel;
auto evictionIter = networkConfig.evictionIterator();
auto scanSize = networkConfig.stateArchivalSettings().evictionScanSize;
auto maxEntriesToEvict =
networkConfig.stateArchivalSettings().maxEntriesToArchive;

updateStartingEvictionIterator(evictionIter, firstScanLevel, ledgerSeq);

auto startIter = evictionIter;
auto b = getBucketFromIter(evictionIter);

while (b->scanForEvictionLegacy(
ltx, evictionIter, scanSize, maxEntriesToEvict, ledgerSeq,
counters.entriesEvicted, counters.bytesScannedForEviction,
stats) == Loop::INCOMPLETE)
{

if (updateEvictionIterAndRecordStats(evictionIter, startIter,
firstScanLevel, ledgerSeq, stats,
counters))
{
break;
}

b = getBucketFromIter(evictionIter);
checkIfEvictionScanIsStuck(
evictionIter,
networkConfig.stateArchivalSettings().evictionScanSize, b,
counters);
}

networkConfig.updateEvictionIterator(ltx, evictionIter);
}
}
4 changes: 0 additions & 4 deletions src/bucket/LiveBucketList.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ class LiveBucketList : public BucketListBase<LiveBucket>
std::shared_ptr<LiveBucket const> b,
EvictionCounters& counters);

void scanForEvictionLegacy(Application& app, AbstractLedgerTxn& ltx,
uint32_t ledgerSeq, EvictionCounters& counters,
std::shared_ptr<EvictionStatistics> stats);

// Add a batch of initial (created), live (updated) and dead entries to the
// bucketlist, representing the entries effected by closing
// `currLedger`. The bucketlist will incorporate these into the smallest
Expand Down
Loading

0 comments on commit f333440

Please sign in to comment.