Skip to content

kvstore: iter_mut and for tables#265

Draft
nrc wants to merge 9 commits into
mainfrom
nrc/kv-iter-mut
Draft

kvstore: iter_mut and for tables#265
nrc wants to merge 9 commits into
mainfrom
nrc/kv-iter-mut

Conversation

@nrc

@nrc nrc commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This PR replace the old for_each_mut API with mutable iterator API (slightly different for different kinds of tables/accesses). The main difficulty here (as well as some interesting lifetime/borrow checker issues) is that after mutation we have to rebuild indexes. That requires some tracking. I've opted to track individual keys since that will be more efficient if a small minority of values are mutated (which might be the case for indexes in particular). However, if the common case is that a whole table is modified then rebuilding the whole index might be more efficient. The other interesting thing is that for the raw API, we need to do the implicit commit somewhere. I explored having this in the dtor of an iterator, but this ended up needing some complex self-referential stuff, so there is a with_iter_mut function rather than iter_mut. If we really need the latter, we can probably do it, but it will require some unsafe code or pinning or something.

Based on #263
Closes #217

AI decl: used Claude to generate tests and for implementing mutation tracking in TableIteratorMut (following similar code for IndexedIteratorMut). Code has been reviewed and refactored.

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.

KV store: core storage follow-ups

1 participant