Skip to content

Commit e5ef01a

Browse files
committed
wip
1 parent 3fb3b5b commit e5ef01a

File tree

3 files changed

+85
-63
lines changed

3 files changed

+85
-63
lines changed

src/bucket/BucketManager.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,16 @@ struct BucketListEvictionCounters
9292
// Per-LedgerKey metrics used for dumping archival state
9393
struct StateArchivalMetric
9494
{
95-
// Newest version of LedgerEntry in the BucketList, or nullopt if newest
96-
// version is a DEADENTRY
97-
std::optional<LedgerEntry> le{};
95+
// True if the newest version of the entry is a DEADENTRY
96+
bool isDead{};
9897

99-
// Number of bytes that the given LedgerKey occupies in the BucketList,
100-
// including shadowed entries
101-
uint64_t bytes{};
98+
// Number of bytes that the newest version of the entry occupies in the
99+
// BucketList
100+
uint64_t newestBytes{};
101+
102+
// Number of bytes that all outdated versions of the entry occupy in the
103+
// BucketList
104+
uint64_t outdatedBytes{};
102105
};
103106

104107
/**

src/bucket/BucketManagerImpl.cpp

+75-56
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ loadEntriesFromBucket(std::shared_ptr<Bucket> b, std::string const& name,
11631163
}
11641164

11651165
static std::vector<std::pair<Hash, std::string>>
1166-
getBucketHashes(HistoryArchiveState const& has)
1166+
getBucketHashes(HistoryArchiveState const& has, bool inOrder)
11671167
{
11681168
std::vector<std::pair<Hash, std::string>> hashes;
11691169
for (uint32_t i = BucketList::kNumLevels; i > 0; --i)
@@ -1228,8 +1228,9 @@ static void
12281228
processArchivalMetrics(
12291229
std::shared_ptr<Bucket const> const b,
12301230
UnorderedMap<LedgerKey, StateArchivalMetric>& ledgerEntries,
1231-
UnorderedMap<LedgerKey, StateArchivalMetric>& ttls)
1231+
UnorderedMap<LedgerKey, std::pair<StateArchivalMetric, uint32_t>>& ttls)
12321232
{
1233+
CLOG_FATAL(Bucket, "Size {}", b->getSize());
12331234
for (BucketInputIterator in(b); in; ++in)
12341235
{
12351236
auto const& be = *in;
@@ -1242,29 +1243,47 @@ processArchivalMetrics(
12421243
continue;
12431244
}
12441245

1245-
auto proccessEntry = [&](auto& map) {
1246-
auto iter = map.find(k);
1247-
if (iter == map.end())
1246+
if (isTTL)
1247+
{
1248+
auto iter = ttls.find(k);
1249+
if (iter == ttls.end())
12481250
{
1251+
releaseAssert(!isDead);
12491252
StateArchivalMetric metric;
1250-
metric.le =
1251-
isDead ? std::nullopt : std::make_optional(be.liveEntry());
1252-
metric.bytes = xdr::xdr_size(be);
1253-
map.emplace(k, metric);
1253+
metric.isDead = isDead;
1254+
metric.newestBytes = xdr::xdr_size(be);
1255+
if (isDead)
1256+
{
1257+
releaseAssert(false);
1258+
ttls.emplace(k, std::make_pair(metric, 0));
1259+
}
1260+
else
1261+
{
1262+
ttls.emplace(
1263+
k, std::make_pair(
1264+
metric,
1265+
be.liveEntry().data.ttl().liveUntilLedgerSeq));
1266+
}
12541267
}
12551268
else
12561269
{
1257-
iter->second.bytes += xdr::xdr_size(be);
1270+
iter->second.first.outdatedBytes += xdr::xdr_size(be);
12581271
}
1259-
};
1260-
1261-
if (isTTL)
1262-
{
1263-
proccessEntry(ttls);
12641272
}
12651273
else
12661274
{
1267-
proccessEntry(ledgerEntries);
1275+
auto iter = ledgerEntries.find(k);
1276+
if (iter == ledgerEntries.end())
1277+
{
1278+
StateArchivalMetric metric;
1279+
metric.isDead = isDead;
1280+
metric.newestBytes = xdr::xdr_size(be);
1281+
ledgerEntries.emplace(k, metric);
1282+
}
1283+
else
1284+
{
1285+
iter->second.outdatedBytes += xdr::xdr_size(be);
1286+
}
12681287
}
12691288
}
12701289
}
@@ -1275,7 +1294,9 @@ BucketManagerImpl::dumpStateArchivalStatistics(HistoryArchiveState const& has)
12751294
ZoneScoped;
12761295
auto hashes = getBucketHashes(has);
12771296
UnorderedMap<LedgerKey, StateArchivalMetric> ledgerEntries;
1278-
UnorderedMap<LedgerKey, StateArchivalMetric> ttls;
1297+
1298+
// key -> (metric, liveUntilLedger)
1299+
UnorderedMap<LedgerKey, std::pair<StateArchivalMetric, uint32_t>> ttls;
12791300
float blSize = 0;
12801301
for (auto const& pair : hashes)
12811302
{
@@ -1293,65 +1314,63 @@ BucketManagerImpl::dumpStateArchivalStatistics(HistoryArchiveState const& has)
12931314
blSize += b->getSize();
12941315
}
12951316

1296-
// *BytesNoShadow == bytes consumed only by newest version of BucketEntry
1297-
// *BytesShadows == bytes consumed only by shadows, does not count newest
1298-
// version of BucketEntry
1299-
// live -> liveUntilLedger > ledgerSeq
1317+
// *BytesNewest == bytes consumed only by newest version of BucketEntry
1318+
// *BytesOutdated == bytes consumed only by outdated version of BucketEntry
1319+
// live -> liveUntilLedger >= ledgerSeq
13001320
// expired -> liveUntilLedger < ledgerSeq, but not yet evicted
1301-
uint64_t liveBytesNoShadow{};
1302-
uint64_t liveBytesShadows{};
1303-
uint64_t expiredBytesNoShadow{};
1304-
uint64_t expiredBytesShadows{};
1305-
uint64_t evictedBytes{}; // All evicted bytes considered shadows
1321+
uint64_t liveBytesNewest{};
1322+
uint64_t liveBytesOutdated{};
1323+
uint64_t expiredBytesNewest{};
1324+
uint64_t expiredBytesOutdated{};
1325+
uint64_t evictedBytes{}; // All evicted bytes considered "outdated"
13061326

13071327
for (auto const& [k, leMetric] : ledgerEntries)
13081328
{
13091329
auto ttlIter = ttls.find(getTTLKey(k));
13101330
releaseAssertOrThrow(ttlIter != ttls.end());
1311-
auto const& ttlMetric = ttlIter->second;
1331+
auto const& [ttlMetric, liveUntilLedger] = ttlIter->second;
13121332

1313-
if (ttlMetric.le.has_value())
1333+
auto newestBytes = ttlMetric.newestBytes + leMetric.newestBytes;
1334+
auto outdatedBytes = ttlMetric.outdatedBytes + leMetric.outdatedBytes;
1335+
1336+
if (ttlMetric.isDead)
13141337
{
1315-
releaseAssertOrThrow(leMetric.le.has_value());
1316-
auto ttlSize = xdr::xdr_size(*ttlMetric.le);
1317-
auto leSize = xdr::xdr_size(*leMetric.le);
1318-
if (isLive(*ttlMetric.le,
1319-
mApp.getLedgerManager().getLastClosedLedgerNum()))
1320-
{
1321-
liveBytesNoShadow += ttlSize + leSize;
1338+
releaseAssertOrThrow(leMetric.isDead);
13221339

1323-
// Don't count most recent version in shadow bytes
1324-
liveBytesShadows +=
1325-
(ttlMetric.bytes - ttlSize) + (leMetric.bytes - leSize);
1340+
// All bytes considred outdated for evicted entries
1341+
evictedBytes += newestBytes + outdatedBytes;
1342+
}
1343+
else
1344+
{
1345+
releaseAssertOrThrow(!leMetric.isDead);
1346+
1347+
// If entry is live
1348+
if (liveUntilLedger >=
1349+
mApp.getLedgerManager().getLastClosedLedgerNum())
1350+
{
1351+
liveBytesNewest += newestBytes;
1352+
liveBytesOutdated += outdatedBytes;
13261353
}
13271354
else
13281355
{
1329-
expiredBytesNoShadow += ttlSize + leSize;
1330-
1331-
// Don't count most recent version in shadow bytes
1332-
expiredBytesShadows +=
1333-
(ttlMetric.bytes - ttlSize) + (leMetric.bytes - leSize);
1356+
expiredBytesNewest += newestBytes;
1357+
expiredBytesOutdated += outdatedBytes;
13341358
}
13351359
}
1336-
else
1337-
{
1338-
releaseAssertOrThrow(!leMetric.le.has_value());
1339-
evictedBytes += leMetric.bytes + ttlMetric.bytes;
1340-
}
13411360
}
13421361

13431362
CLOG_INFO(Bucket, "BucketList total bytes: {}", blSize);
13441363
CLOG_INFO(Bucket,
1345-
"Live Temporary Entries: Non-shadows {} bytes ({}%), Shadowed {} "
1364+
"Live Temporary Entries: Newest {} bytes ({}%), Outdated {} "
13461365
"bytes ({}%)",
1347-
liveBytesNoShadow, (liveBytesNoShadow / blSize) * 100,
1348-
liveBytesShadows, (liveBytesShadows / blSize) * 100);
1366+
liveBytesNewest, (liveBytesNewest / blSize) * 100,
1367+
liveBytesOutdated, (liveBytesOutdated / blSize) * 100);
13491368
CLOG_INFO(Bucket,
1350-
"Expired but not evicted Temporary Entries: Non-shadows {} bytes "
1351-
"({}%), Shadowed {} bytes ({}%)",
1352-
expiredBytesNoShadow, (expiredBytesNoShadow / blSize) * 100,
1353-
expiredBytesShadows, (expiredBytesShadows / blSize) * 100);
1354-
CLOG_INFO(Bucket, "Evicted Temporary Entries: Shadowed {} bytes ({}%)",
1369+
"Expired but not evicted Temporary Newest {} bytes "
1370+
"({}%), Outdated {} bytes ({}%)",
1371+
expiredBytesNewest, (expiredBytesNewest / blSize) * 100,
1372+
expiredBytesOutdated, (expiredBytesOutdated / blSize) * 100);
1373+
CLOG_INFO(Bucket, "Evicted Temporary Entries: Outdated {} bytes ({}%)",
13551374
evictedBytes, (evictedBytes / blSize) * 100);
13561375
}
13571376

src/main/ApplicationUtils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ dumpStateArchivalStatistics(Config cfg)
561561
VirtualClock clock;
562562
cfg.setNoListen();
563563
Application::pointer app = Application::create(clock, cfg, false);
564-
app->getLedgerManager().loadLastKnownLedger(nullptr);
564+
app->getLedgerManager().loadLastKnownLedger(false, false);
565565
auto& lm = app->getLedgerManager();
566566
auto& bm = app->getBucketManager();
567567
HistoryArchiveState has = lm.getLastClosedLedgerHAS();

0 commit comments

Comments
 (0)