Skip to content

CASSANDRA-21390 5.0 Fix negative memtable allocator ownership when an update is shadowed by an existing row deletion#4886

Open
smiklosovic wants to merge 1 commit into
apache:cassandra-5.0from
smiklosovic:CASSANDRA-21390-5.0
Open

CASSANDRA-21390 5.0 Fix negative memtable allocator ownership when an update is shadowed by an existing row deletion#4886
smiklosovic wants to merge 1 commit into
apache:cassandra-5.0from
smiklosovic:CASSANDRA-21390-5.0

Conversation

@smiklosovic

Copy link
Copy Markdown
Contributor

When BTreeRow.merge reconciles an update into a row whose existing deletion shadows the update's cells, it filtered the update (incoming) side of the merge with Reconciler.retain, which records the removal via PostReconciliationFunction.delete. On the memtable write path that subtracts the shadowed cells' on-heap size from the allocator's ownership even though that incoming data was never allocated to the memtable. Under overwrite/delete churn that re-applies cells already covered by a newer row/partition deletion (e.g. repair re-streaming), the allocator's "owns" counter drifts negative and the next flush trips "AssertionError: Negative released" in MemtablePool$SubPool.released via MemtableAllocator$SubAllocator.releaseAll during discard.

Filter the update (incoming) side with a non-recording variant, Reconciler.removeShadowed, and keep retain() for the existing side, whose data the memtable already owns. The filtered result is identical; only the erroneous accounting notification is dropped. This mirrors the already-correct complex-column path in ColumnData.merge.

patch by Stefan Miklosovic; reviewed by Dmitry Konstantinov for CASSANDRA-21390

Assisted-By: Claude Opus 4.8 noreply@anthropic.com

Thanks for sending a pull request! Here are some tips if you're new here:

  • Ensure you have added or run the appropriate tests for your PR.
  • Be sure to keep the PR description updated to reflect all changes.
  • Write your PR title to summarize what this PR proposes.
  • If possible, provide a concise example to reproduce the issue for a faster review.
  • Read our contributor guidelines
  • If you're making a documentation change, see our guide to documentation contribution

Commit messages should follow the following format:

<One sentence description, usually Jira title or CHANGES.txt summary>

<Optional lengthier description (context on patch)>

patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####

Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>

The Cassandra Jira

…by an existing row deletion

When BTreeRow.merge reconciles an update into a row whose existing deletion
shadows the update's cells, it filtered the update (incoming) side of the merge
with Reconciler.retain, which records the removal via
PostReconciliationFunction.delete. On the memtable write path that subtracts the
shadowed cells' on-heap size from the allocator's ownership even though that
incoming data was never allocated to the memtable. Under overwrite/delete churn
that re-applies cells already covered by a newer row/partition deletion (e.g.
repair re-streaming), the allocator's "owns" counter drifts negative and the next
flush trips "AssertionError: Negative released" in MemtablePool$SubPool.released
via MemtableAllocator$SubAllocator.releaseAll during discard.

Filter the update (incoming) side with a non-recording variant,
Reconciler.removeShadowed, and keep retain() for the existing side,
whose data the memtable already owns. The filtered result is identical; only the
erroneous accounting notification is dropped. This mirrors the already-correct
complex-column path in ColumnData.merge.

patch by Stefan Miklosovic; reviewed by Dmitry Konstantinov for CASSANDRA-21390

Assisted-By: Claude Opus 4.8 <noreply@anthropic.com>
import static org.assertj.core.api.Assertions.assertThat;

/**
* CQL-driven regression test for CASSANDRA-21390 ("TrieMemtable MemtableReclaimMemory AssertionError:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it is better to not refer CASSANDRA-21390 here to avoid confusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants