Repository navigation
Do not hang in MemTable destructor on corrupted keys - #232
Merged
Merged
Conversation
* `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.
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.