fix: add actual transaction data to RWDB memory usage calculations

The existing memory usage functions only counted structural overhead
(sizeof of containers and pointers) but missed the actual transaction
and metadata blob sizes. This caused severe underreporting - showing
KBs when actually using MBs or GBs.

Changes:
- Keep existing structural overhead calculations
- Add actual transaction/metadata serialized data sizes
- Use transactionMap_ as single source to avoid double-counting
- Add MAP_NODE_OVERHEAD constant for red-black tree nodes (~40 bytes each)
- Use vector::capacity() instead of size() for actual allocated memory
- Include ledger's transaction map node overhead in ledger calculations
- Change internal calculation to uint64_t to prevent overflow
- Add clear comments explaining what each section measures

These improvements provide much more accurate memory reporting for
monitoring and diagnostic purposes.
This commit is contained in:
Nicholas Dudfield
2025-08-20 08:17:17 +07:00
parent 23c7cd25a7
commit 1703574d50
2 changed files with 88 additions and 35 deletions

View File

@@ -542,9 +542,9 @@ public:
auto newLedgerKB = sqliteDb->getKBUsedLedger();
auto newTxKB = sqliteDb->getKBUsedTransaction();
BEAST_EXPECT(newAllKB == 1);
BEAST_EXPECT(newAllKB == 2);
BEAST_EXPECT(newLedgerKB == 0);
BEAST_EXPECT(newTxKB == 0);
BEAST_EXPECT(newTxKB == 1);
// Test database closure operations (should not throw)
try