docs: add safety documentation and tests for manual bucket release#387
docs: add safety documentation and tests for manual bucket release#387
Conversation
|
|
|
|
|
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds safety documentation and tests for manual bucket release functionality to prevent use-after-release corruption and enable efficient bucket reuse during data structure migrations. The PR establishes a critical safety pattern where Rust objects must be dropped before releasing their buckets to prevent data corruption.
Key changes:
- Adds comprehensive test suite for Vec bucket release scenarios including corruption demonstrations
- Updates existing BTreeMap tests to follow the safe drop-before-release pattern
- Enhances MemoryManager documentation with critical safety requirements and usage patterns
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/memory_manager/bucket_release_vec_tests.rs | New comprehensive test suite demonstrating Vec bucket release patterns, corruption scenarios, and safe usage |
| src/memory_manager/bucket_release_core_tests.rs | Updates core tests to use proper drop pattern instead of clear_new() |
| src/memory_manager/bucket_release_btreemap_tests.rs | Enhances BTreeMap tests with corruption demonstrations and safe usage patterns |
| src/memory_manager.rs | Adds critical safety documentation for bucket release operations and usage patterns |
| src/btreeset.rs | Adds safety documentation to clear() method regarding bucket release |
| src/btreemap.rs | Adds safety documentation to clear_new() method regarding bucket release |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This PR reverts adding `reclaim_memory` method. Reverts several recent commits in a single change: - `6e397bd` fix: use conservative bucket reuse that survives reload #394 - `00468e1` docs: update memory reclamation examples in the docs #392 - `b911479` docs: cleanup documentation #391 - `d1fde89` docs: use reclaim_memory() name and update docs accordingly #388 - `a18917b` docs: add safety documentation and tests for manual bucket release #387 - `73e96e8` feat: add manual bucket release to prevent memory waste #386 This PR restores the codebase to the state before these commits. Done with `git revert -n 6e397bd 00468e1 b911479 d1fde89 a18917b 73e96e8` The reason for reverting this approach was that it can reclaim unused memory in theory but provides little benefit in real-world migrations. All due to the requirement to keep buckets in ascending order in each VM. Example 1: Reuse works ``` A allocates: [0, 4, 5] B allocates: [1, 2, 3] A frees: [0, 4, 5] B grows: can reuse bucket 4 (since 4 > max(B) = 3) B after grow: [1, 2, 3, 4] ``` Example 2: Reuse fails ``` A allocates: [0, 1, 2] B allocates: [4, 5, 6] A frees: [0, 1, 2] B grows: cannot reuse any freed bucket (all < max(B) = 6), so allocates new bucket 7 B after grow: [4, 5, 6, 7] ``` In real life when migrating state A to state B, state B created after state A grown, so it's first bucket ID is already higher than any free bucket in state A virtual memory, therefore can not be reused.
This PR clarifies and strongly recommends a safe workflow for manual bucket release to prevent use-after-release corruption and enable efficient bucket reuse during migrations.
Safe pattern:
MemoryId.It also adds corresponding tests for
Vecand consolidates them with existingBTreeMaptests for coherence.