@@ -1163,7 +1163,7 @@ loadEntriesFromBucket(std::shared_ptr<Bucket> b, std::string const& name,
1163
1163
}
1164
1164
1165
1165
static std::vector<std::pair<Hash, std::string>>
1166
- getBucketHashes (HistoryArchiveState const & has)
1166
+ getBucketHashes (HistoryArchiveState const & has, bool inOrder )
1167
1167
{
1168
1168
std::vector<std::pair<Hash, std::string>> hashes;
1169
1169
for (uint32_t i = BucketList::kNumLevels ; i > 0 ; --i)
@@ -1228,8 +1228,9 @@ static void
1228
1228
processArchivalMetrics (
1229
1229
std::shared_ptr<Bucket const > const b,
1230
1230
UnorderedMap<LedgerKey, StateArchivalMetric>& ledgerEntries,
1231
- UnorderedMap<LedgerKey, StateArchivalMetric>& ttls)
1231
+ UnorderedMap<LedgerKey, std::pair< StateArchivalMetric, uint32_t > >& ttls)
1232
1232
{
1233
+ CLOG_FATAL (Bucket, " Size {}" , b->getSize ());
1233
1234
for (BucketInputIterator in (b); in; ++in)
1234
1235
{
1235
1236
auto const & be = *in;
@@ -1242,29 +1243,47 @@ processArchivalMetrics(
1242
1243
continue ;
1243
1244
}
1244
1245
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 ())
1248
1250
{
1251
+ releaseAssert (!isDead);
1249
1252
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
+ }
1254
1267
}
1255
1268
else
1256
1269
{
1257
- iter->second .bytes += xdr::xdr_size (be);
1270
+ iter->second .first . outdatedBytes += xdr::xdr_size (be);
1258
1271
}
1259
- };
1260
-
1261
- if (isTTL)
1262
- {
1263
- proccessEntry (ttls);
1264
1272
}
1265
1273
else
1266
1274
{
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
+ }
1268
1287
}
1269
1288
}
1270
1289
}
@@ -1275,7 +1294,9 @@ BucketManagerImpl::dumpStateArchivalStatistics(HistoryArchiveState const& has)
1275
1294
ZoneScoped;
1276
1295
auto hashes = getBucketHashes (has);
1277
1296
UnorderedMap<LedgerKey, StateArchivalMetric> ledgerEntries;
1278
- UnorderedMap<LedgerKey, StateArchivalMetric> ttls;
1297
+
1298
+ // key -> (metric, liveUntilLedger)
1299
+ UnorderedMap<LedgerKey, std::pair<StateArchivalMetric, uint32_t >> ttls;
1279
1300
float blSize = 0 ;
1280
1301
for (auto const & pair : hashes)
1281
1302
{
@@ -1293,65 +1314,63 @@ BucketManagerImpl::dumpStateArchivalStatistics(HistoryArchiveState const& has)
1293
1314
blSize += b->getSize ();
1294
1315
}
1295
1316
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
1300
1320
// 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"
1306
1326
1307
1327
for (auto const & [k, leMetric] : ledgerEntries)
1308
1328
{
1309
1329
auto ttlIter = ttls.find (getTTLKey (k));
1310
1330
releaseAssertOrThrow (ttlIter != ttls.end ());
1311
- auto const & ttlMetric = ttlIter->second ;
1331
+ auto const & [ ttlMetric, liveUntilLedger] = ttlIter->second ;
1312
1332
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 )
1314
1337
{
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 );
1322
1339
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;
1326
1353
}
1327
1354
else
1328
1355
{
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;
1334
1358
}
1335
1359
}
1336
- else
1337
- {
1338
- releaseAssertOrThrow (!leMetric.le .has_value ());
1339
- evictedBytes += leMetric.bytes + ttlMetric.bytes ;
1340
- }
1341
1360
}
1342
1361
1343
1362
CLOG_INFO (Bucket, " BucketList total bytes: {}" , blSize);
1344
1363
CLOG_INFO (Bucket,
1345
- " Live Temporary Entries: Non-shadows {} bytes ({}%), Shadowed {} "
1364
+ " Live Temporary Entries: Newest {} bytes ({}%), Outdated {} "
1346
1365
" bytes ({}%)" ,
1347
- liveBytesNoShadow , (liveBytesNoShadow / blSize) * 100 ,
1348
- liveBytesShadows , (liveBytesShadows / blSize) * 100 );
1366
+ liveBytesNewest , (liveBytesNewest / blSize) * 100 ,
1367
+ liveBytesOutdated , (liveBytesOutdated / blSize) * 100 );
1349
1368
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 ({}%)" ,
1355
1374
evictedBytes, (evictedBytes / blSize) * 100 );
1356
1375
}
1357
1376
0 commit comments