Skip to content

fix(posting): mark removed split parts for reclamation - #9825

Open
KeisukeYamashita wants to merge 1 commit into
dgraph-io:mainfrom
KeisukeYamashita:codex/fix-orphan-split-cleanup-9824
Open

KeisukeYamashita wants to merge 1 commit into
dgraph-io:mainfrom
KeisukeYamashita:codex/fix-orphan-split-cleanup-9824

Conversation

@KeisukeYamashita

@KeisukeYamashita KeisukeYamashita commented Sep 4, 2026

Copy link
Copy Markdown

Refs #9824

Description

Write BitEmptyPosting records for split parts removed during rollup, allowing Badger compaction to reclaim their old payloads.

Use the replacement parent's timestamp, including the +1 for finite read timestamps, to preserve historical reads.

Add regression tests covering:

  • Partial and whole-list deletion for data, reverse, and index keys.
  • Splits created through normal mutations and rollup.
  • Historical reads, timestamp boundaries, reinsertion, delayed rollup writes, database reopen, and backup conversion.

Validation: the posting test suite, targeted race tests (three runs), targeted debug tests, and Dgraph build pass. Trunk has not yet been run.

This change does not remove empty-key metadata or retroactively clean up already-orphaned parts.

Checklist

  • The PR title follows the Conventional Commits syntax.
  • Code compiles correctly and linting (via trunk) passes locally.
  • Regression tests added for the bug fix.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Improved posting list rollups so reads referencing older split parts continue to work after compaction.
    • Preserved access to historical data during rollups, deletions, concurrent reads, and backup operations.
    • Reclaimed unreferenced split data after compaction while maintaining valid reads.
  • Tests

    • Added comprehensive coverage for split creation, cleanup, deletion modes, key types, timestamp boundaries, and historical reads.

@KeisukeYamashita
KeisukeYamashita requested a review from a team as a code owner September 4, 2026 08:30
@shiva-istari
shiva-istari force-pushed the codex/fix-orphan-split-cleanup-9824 branch 2 times, most recently from d5295a5 to 5e99229 Compare September 10, 2026 12:35
@matthewmcneely
matthewmcneely force-pushed the codex/fix-orphan-split-cleanup-9824 branch from 5e99229 to 5475bc3 Compare September 10, 2026 20:51
@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1fd05336-788b-4489-8082-d700cd9ba525

📥 Commits

Reviewing files that changed from the base of the PR and between 3656273 and 5475bc3.

📒 Files selected for processing (2)
  • posting/list.go
  • posting/split_cleanup_test.go

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

List.Rollup now writes empty, versioned parts for removed splits. New tests cover split creation, historical reads, reinsertion, timestamp boundaries, backup conversion, and reclamation across key kinds and deletion modes.

Changes

Posting split cleanup

Layer / File(s) Summary
Rollup removed-part preservation
posting/list.go
List.Rollup emits empty posting-list parts for removed splits using the main KV version.
Native split cleanup and historical reads
posting/split_cleanup_test.go
Tests validate native split cleanup, historical parent reads, concurrent reads, reinsertion, backups, and facet preservation.
Timestamp and key-kind coverage
posting/split_cleanup_test.go
Fixtures and tests cover data, reverse, and index keys, deletion modes, timestamp boundaries, and compaction reclamation.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: matthewmcneely, gooohgb

Merge Risk: 🟡 Moderate · up to 5475b

Posting rollups now write empty records for removed splits to enable reclamation. If split validation rejects this representation, deletion rollups could fail; the invariant should be confirmed before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: marking removed posting split parts for reclamation during rollup.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread posting/list.go

// Retire removed parts at the parent's timestamp (+1 for finite readTs)
// so compaction preserves reads using the old parent.
for _, startUid := range l.plist.Splits {

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.

The crash-safety of this depends on a write-ordering invariant that's currently implicit. If one of these tombstones ever became durable before the new parent KV and the process died in between, the old parent would still be the latest visible version and would reference a part that now reads as empty. Worse, the next rollup would read that part as empty and persist the loss.

Today the ordering holds: the sort below puts the main key first (DefaultPrefix 0x00 sorts before ByteSplit 0x04), TxnWriter submits commits in call order, and badger's WAL replays a strict prefix, so a tombstone can't survive a crash without its parent. But nothing in the code says that order is load-bearing (the sort comment only mentions readability). Could you add a short comment here or on the sort noting that the main-list KV must be written before these tombstones?

Comment thread posting/list.go
if err != nil {
return nil, errors.Wrapf(err, "cannot marshal removed posting list part")
}
part.Version = kv.Version

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.

This works only because the retained-parts loop above shadows kv in its own scope, so the outer kv here is still the main-list KV with the +1 applied. That's fragile: a refactor of that loop could silently change which version these tombstones get. Suggest capturing parentVersion := kv.Version right after it's computed and using it here.

While you're at it, a line on why removed parts get the parent's +1 version while retained parts stay at out.newMinTs would help future readers: a reader at exactly newMinTs still resolves the old parent, which must still see the removed part's data.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants