Skip to content

Do not hang in MemTable destructor on corrupted keys - #232

Merged
greensky00 merged 1 commit into
masterfrom
junahn_pr2
Nov 13, 2026
Merged

greensky00 merged 1 commit into
masterfrom
junahn_pr2

Conversation

@greensky00

Copy link
Copy Markdown
Contributor
  • skiplist_erase_node() finds a node by key comparison, so if a key is corrupted (e.g., overwritten by others), erasing its neighbor leaves a dangling pointer, and the next erase loops forever.

  • Add skiplist_destroy_nodes() that detaches and frees all nodes by following the bottom layer pointers only, without key comparison.

  • Use it in ~MemTable() for both key and seq indexes, and log a warning if the number of freed nodes does not match the index size.

  • Add a unit test that corrupts keys and seq numbers in a memtable, and then destroys it.

* `skiplist_erase_node()` finds a node by key comparison, so if a key
  is corrupted (e.g., overwritten by others), erasing its neighbor
  leaves a dangling pointer, and the next erase loops forever.

* Add `skiplist_destroy_nodes()` that detaches and frees all nodes by
  following the bottom layer pointers only, without key comparison.

* Use it in `~MemTable()` for both key and seq indexes, and log a
  warning if the number of freed nodes does not match the index size.

* Add a unit test that corrupts keys and seq numbers in a memtable,
  and then destroys it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change to comparison-free MemTable teardown.

No open issues 🎉

What changed in this PR

This PR prevents MemTable teardown from hanging when corrupted keys or sequence numbers disrupt skiplist ordering. It replaces comparison-based removal with bottom-layer traversal.

Changes:

  • Adds a skiplist teardown API that frees nodes without comparing keys.
  • Uses the API for both MemTable indexes and warns when freed-node counts differ from expected sizes.
  • Adds teardown tests covering corrupted keys and sequence numbers.
File Description
tests/​unit/​memtable_test.cc Adds corruption scenarios to verify MemTable destruction completes.
src/​skiplist.h Declares the teardown API and documents its exclusive-access requirement.
src/​skiplist.cc Implements comparison-free node destruction and resets index state.
src/​memtable.cc Adopts the teardown API for both indexes and adds count-mismatch warnings.

Review effort: Balanced

@greensky00
greensky00 merged commit 46c5ef4 into master Nov 13, 2026
2 checks passed
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