cassandra/test
Dmitry Konstantinov 7dcfc6f343 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-06-25 22:26:17 +01:00
..
anttasks/org/apache/cassandra/anttasks Organize imports and standartize import order across entire codebase 2025-12-30 22:34:14 +01:00
bin Add cursor based optimized compaction path 2025-12-19 12:45:25 -05:00
burn/org/apache/cassandra Avoid ByteBuffer wrapping in cql3.selection.Selector.InputRow to reduce memory allocation rate 2026-06-04 19:19:36 +01:00
conf Merge branch 'cassandra-5.0' into cassandra-6.0 2026-06-21 22:05:32 +01:00
data Remove 4.0 upgrade paths and related 4.0 tests 2026-06-02 23:54:38 +02:00
distributed/org/apache/cassandra Merge branch 'cassandra-6.0' into trunk 2026-06-21 22:23:43 +01:00
harry/main/org/apache/cassandra Accord: Deterministic time integration 2026-05-18 13:19:25 +01:00
long/org/apache/cassandra Implement custom CassandraThread to keep direct references to frequently used thread local objects 2026-06-02 13:56:59 +01:00
memory/org/apache/cassandra/db/compaction Organize imports and standartize import order across entire codebase 2025-12-30 22:34:14 +01:00
microbench/org/apache/cassandra/test/microbench Merge branch 'cassandra-5.0' into cassandra-6.0 2026-06-14 16:50:17 +02:00
resources Merge branch 'cassandra-6.0' into trunk 2026-05-15 14:49:01 +01:00
simulator Introduce AccordExecutorSignalLoop that aims to reduce lock contention: 2026-05-16 21:12:49 +01:00
unit Fix memtable on-heap accounting drift in BTree.update and BTreeRow.merge 2026-06-25 22:26:17 +01:00