You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: free removed versions after releasing the keyspaces lock - #352
When a keyspace rotates its memtable, inner_rotate_memtable runs version history GC for every keyspace while it holds the keyspaces read lock. The GC can drop the last reference to a flushed memtable, so a full memtable gets freed under that lock (and, inside lsm-tree, under the version history write lock, which every insert reads).
This PR collects what maintenance returns and drops it after the loop, when the keyspaces guard is gone. It depends on fjall-rs/lsm-tree#328, which makes maintenance return the removed versions. Against the released lsm-tree 3.1.10 the call returns (), so this still compiles and behaves as before until that change is released.
Repro, with fjall as the only dependency: four keyspaces with 32 MiB memtables and one writer doing 100 synced commits a second of 1,000 small entries each, for 60 seconds. The write buffer limit is raised so write stalls do not hide the effect.
Three runs each on aarch64 Linux with the default allocator. "Before" is fjall main with lsm-tree main, "after" is both branches together:
p99
max
commits over 50 ms
before
6.6 / 5.7 / 6.4 ms
191 / 141 / 176 ms
7 / 9 / 7
after
7.6 / 6.8 / 8.3 ms
93 / 93 / 87 ms
5 / 4 / 7
The worst commit goes from between 141 and 191 ms to between 87 and 93 ms. p99 and the number of slow commits do not improve. As a check I leaked the removed versions instead of dropping them, and the max fell to between 47 and 60 ms with 0 to 3 slow commits, so what is left looks like the free itself competing with the writer in the allocator. I have not looked further into that.
The test suite passes with the lsm-tree change (on main) and without it (on 3.1.13).
Summary by CodeRabbit
Bug Fixes
Version-history maintenance results are now released after keyspace iteration, helping prevent resource cleanup from occurring while keyspaces are being read.
No actionable comments were generated in the recent review.
Walkthrough
During memtable rotation, successful version-history maintenance results are collected and dropped after the keyspaces read lock is released. Errors continue to be logged without stopping processing of other keyspaces.
Successful maintenance results are retained in a vector and dropped after keyspace iteration releases the read lock. Errors are logged, and processing continues for other keyspaces.
This change defers freeing removed versions until the keyspaces lock is released, which reduces the maximum commit latency. No merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "fix: free removed versions after releasing the keyspaces lock" matches the main change. The summary shows that maintenance results are now collected and dropped after the keyspaces read loc…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "fix: free removed versions after releasing the keyspaces lock" matches the main change. The summary shows that maintenance results are now collected and dropped after the keyspaces read lock is released. The title is concise, specific, and names the lock-ordering reason for the change.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: eb2cf6c6-6095-44d9-96e0-32efa849017f
Commits
Reviewing files that changed from the base of the PR and between 8700604 and 9574c83.
Files selected for processing: 1
src/keyspace/mod.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
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
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.
When a keyspace rotates its memtable,
inner_rotate_memtableruns version history GC for every keyspace while it holds thekeyspacesread lock. The GC can drop the last reference to a flushed memtable, so a full memtable gets freed under that lock (and, inside lsm-tree, under the version history write lock, which every insert reads).This PR collects what
maintenancereturns and drops it after the loop, when thekeyspacesguard is gone. It depends on fjall-rs/lsm-tree#328, which makesmaintenancereturn the removed versions. Against the released lsm-tree 3.1.10 the call returns(), so this still compiles and behaves as before until that change is released.Repro, with fjall as the only dependency: four keyspaces with 32 MiB memtables and one writer doing 100 synced commits a second of 1,000 small entries each, for 60 seconds. The write buffer limit is raised so write stalls do not hide the effect.
main.rs
Three runs each on aarch64 Linux with the default allocator. "Before" is fjall
mainwith lsm-treemain, "after" is both branches together:The worst commit goes from between 141 and 191 ms to between 87 and 93 ms. p99 and the number of slow commits do not improve. As a check I leaked the removed versions instead of dropping them, and the max fell to between 47 and 60 ms with 0 to 3 slow commits, so what is left looks like the free itself competing with the writer in the allocator. I have not looked further into that.
The test suite passes with the lsm-tree change (on
main) and without it (on 3.1.13).Summary by CodeRabbit