cassandra/test
Dmitry Konstantinov ce353ffe9f Fix memtable on-heap accounting drift in BTree.update and BTreeRow.merge
Several paths report on-heap allocation through UpdateFunction.onAllocatedOnHeap in a
way that diverges from the heap actually retained (BTree.sizeOnHeapOf), so the memtable's
owned-heap counter drifts. Five under/over-counting causes are fixed so that reported
allocation matches sizeOnHeapOf:

1) BTree.update over-counts on node split/overflow and never counts branch sizeMaps.
   The Updater's running 'allocated' was not a true net delta: leaf drain() cleared the
   source before subtracting it, the redistribute/overflow paths added new nodes without
   releasing the source they replace, and branch sizeMaps were never counted.
   Fix: account each node net - add every newly retained node's shallow heap (array plus
   sizeMap) and subtract it for every replaced source, releasing before the source is
   cleared; and record the root as the top builder's source so the old root is released too.
   Test: BTreeUpdateHeapAccountingTest (randomized small / contiguous-block / overlapping /
   height-4, coverage verified by JaCoCo).

2) BTreeRow.merge does not release a row's column tree when a row tombstone shadows its
   cells: the retain branch rebuilds it smaller via BTree.transformAndFilter (node accounting
   disabled) but never releases the freed structure. Fix: report sizeOnHeapOf(retained) -
   sizeOnHeapOf(existing) when the filter shrinks the tree, as ColumnData.Reconciler.merge does.

3) BTreeRow.merge does not account the row's LivenessInfo/Deletion change (e.g. a tombstone
   replacing a live row). Fix: account (reconciled liveness+deletion) - (existing liveness+deletion).

4) Allocation and release disagree on the branch sizeMap: allocation used sizeOfStructureOnHeap
   (excludes it), release used sizeOnHeapOf (includes it). Fix: remove sizeOfStructureOnHeap and
   use sizeOnHeapOf everywhere.

5) ColumnData.removeShadowed does not release a shadowed complex (collection) column's own
   structure: it releases the inner cells via recordDeletion.delete but not the column's cell
   tree (which can span multiple nodes) nor, when the column is dropped, its wrapper - both
   counted as owned when written. Fix: report (EMPTY_SIZE + sizeOnHeapOf(tree)) after - before
   (after is 0 when dropped); a no-op on the update side (recordDeletion == noOp), as required
   by CASSANDRA-21469.

Tests for 2-5: PartitionRowAccountingTest.rowTombstoneOverExistingRowDoesNotInflateOwnership and
.rowTombstoneOverExistingCollectionDoesNotInflateOwnership require two logically identical
partitions reached via different merge paths to own exactly the same on-heap (only with all
fixes does it match); SetCellAccountingTest guards that a grow/reset op mix on a set<text>
column never drives the owned heap negative.

patch by Dmitry Konstantinov; reviewed by Caleb Rackliffe for CASSANDRA-21472
2026-07-16 22:38:06 +01:00
..
anttasks/org/apache/cassandra/anttasks JMH improvements - faster build and async profiler 2023-09-25 12:39:36 +02:00
bin JMH improvements - faster build and async profiler 2023-09-25 12:39:36 +02:00
burn/org/apache/cassandra Fix BTree.FastBuilder.reset() and test 2024-09-16 12:24:32 -05:00
conf Use default commitlog settings in test YAMLs 2024-08-15 10:12:39 -05:00
data Fix IndexOutOfBoundsException in sstablemetadata tool when a range tombstone is a max clustering value 2025-08-27 18:54:10 +02:00
distributed/org/apache/cassandra BTree.FastBuilder.reset() fails to clear savedBuffer and savedNextKey, causing ClassCastException and SSTable header corruption during schema disagreement 2026-06-02 10:14:26 +01:00
long/org/apache/cassandra Merge branch 'cassandra-3.11' into cassandra-4.0 2023-01-28 16:54:39 +01:00
memory/org/apache/cassandra/db/compaction Remove OrderedJUnit4ClassRunner 2021-09-20 13:37:32 +02:00
microbench/org/apache/cassandra/test/microbench JMH improvements - faster build and async profiler 2023-09-25 12:39:36 +02:00
resources Remove byteman-related files from production sources 2023-10-10 09:51:11 +02:00
unit/org Fix memtable on-heap accounting drift in BTree.update and BTreeRow.merge 2026-07-16 22:38:06 +01:00