https://slatedb.io logo
refactor Iterator class
# general
m
I think it's time to push forward with the iterator refactoring. While implementing MultiGet, I encountered a situation where when the option has a max_seq requirement, you have to repeatedly rebuild SstIterator to construct FilterIterator because FilterIterator lacks a seek function. As I dug deeper, when trying to implement the SeekTo trait for it, I discovered that the KeyValueIterator doesn't have any method to expose the current RowEntry it's pointing to. This makes it impossible to implement SeekTo (since before next_entry, I need to first compare the current key with the target key and then verify its seqNum). This improvement doesn't fit within the current MultiGet PR - it seems we should prioritize our iterator architecture overhaul now.
I believe the generic methods an iterator should include are: current_entry, next, prev_next (for backward iteration), seek, prev_seek (for backward seeking), and is_value (we often use pattern matching with iterator.next_entry to check if the iterator has reached empty - encapsulating this as is_value could reduce repetitive code). These should be split into different traits, with each iterator object constrained to move in a fixed direction (either forward or backward). We also need to consider functional wrappers for iterators, such as FilterIterator (for validating whether an Entry is valid) and ForegroundIterator (for periodically cleaning up invalid memory occupied by iterators - I'm not sure if you've already decided against implementing this, but for now let's assume we might consider it in the future).
@Rohan @criccomini @flaneur233
c
@maomeng8344 Thx, I will take a look.. backed up.. there are a lot of PRs 😅 I'm also working on a book and running a small investment fund .. and a newsletter 😭
Sorry for the delay
> This improvement doesn't fit within the current MultiGet PR - it seems we should prioritize our iterator architecture overhaul now. +1 from me. I would like @flaneur233 / @Rohan to weigh in though as they're more familiar with that stack of code.
My ask is that you do this incrementally. 😅 A GH issue (or issues) describing the work would be helpful, too.
m
I'll first try to modify the VecDeque iterator—it's really quite strange. I think the approach in mini-lsm is much better, but I'm not sure what potential risks it might have. My understanding of Rust is still too limited, so I need you to evaluate it
https://github.com/slatedb/slatedb/pull/543 I'm uncertain about the benefits of this modification, but would like to submit it for technical review - particularly regarding self-referential safety implications
c
Planning to take a look shortly
@jason I want to call your attention to this issue and PR ^
I remember you doing some work on iterators as part of
scan()
/cc @Rohan @almog ^ I think some 👀 on the VecDeq PR is warranted. It's adding a self reference thingamajig that makes MemtableIterator quite usable, but also a bit tricky to understand under the hood.
a
I may be able to squeeze it in tomorrow morning, but I'm going backpacking in Zion/Bryce flying out tomorrow afternoon until Wednesday so don't block on me 😬
c
No pressure 🙂
Enjoy the trip!
m
https://github.com/slatedb/slatedb/pull/550 could any body review it and get some suggestion,this pr is stupid in some place
2 Views