https://slatedb.io logo
Happy Monday! I'd like to pick up some
# general
a
Happy Monday! I'd like to pick up some of the merge operator work since we'll definitely need it for what we're building. I played around a bit with some prototyping yesterday and I think one thing we'll need to do is to make the reader (
LevelGet
) work with iterators instead of just returning the first value it finds. I have a working patch for it but then I thought about leveraging the work done to make range scans (
DbIterator
) and wanted your takes on whether you thought it makes sense to keep them separate or merge (no pun intended) the two code paths. The downside of merging them is that we're going to need a lot of special casing for the case where the Range covers only a single key (that way we can, for example, leverage bloom filters to skip SSTs/SRs). cc @criccomini @Rohan
also cc @flaneur233 since you've been touching this code for the txn work
r
Its not obvious to me that we should share it or not share it. get in a world with no merges is different enough from scanning to merit its own impl. It's going to be more efficient to probe the levels one at a time vs scan which should just load the ssts as fast as it can. With merge we probably want to do something in between where we load some of the levels but not all at first. But even in that world we should probably try make it possible to retain the existing behaviour for get. Seems like it'll be easier to keep separate from the iterator used by scan
a
that makes sense to me, I wonder in practice how often most of the dataset is cached locally so "prefetching" doesn't have much of a cost associated to it but actually loading it from disk/iterating it is a cost. FWIW, the
DbIterator
already has an option for how much you want to prefetch and it defaults to 1 (no prefetching). I'm already going down the path of prototyping the shared approach so I'll see how it plays out and how much "special casing" we need to do for the get to behave basically the same way it does today
the other benefit of merging the two is that it makes using range(key..key) feasible (for use cases where you programatically generate the range and it may often be the same)
r
sounds good > I wonder in practice how often most of the dataset is cached locally so "prefetching" doesn't have much of a cost associated to it but actually loading it from disk/iterating it is a cost. I think even if its cached most of it will be on local disk so its still kind of expensive to get to. We probably also don't want to pollute the cache by prefetching stuff we dont need
a
the other benefit of consolidating is that we won't have bugs where one supports on type of thing and the other doesn't ๐Ÿ˜† looks like there are some bugs with reading committed in range scans and maybe even some TTL issues (I assume the former is being worked on actively)
๐Ÿ˜ตโ€๐Ÿ’ซ found the other ttl related bug: https://github.com/slatedb/slatedb/pull/938
this makes me think it's worth unifying the two code paths
especially when we do merge + range scans, then it'll get even more complicated
c
(catching up on this thread now)
This was my thought as well.
I tend to feel this way as well, but it'd be nice to see how ugly the unification looks
If unification makes bugs more error prone becuase it's complex, then it's probably not worth it ๐Ÿ˜›
@almog LMK when #936 is ready for ๐Ÿ‘€
a
I'm plugging away at a prototype for unification. In order to avoid hacks it's looking like it's going to be a pretty meaty change so whenever there's individual things to split out I'm submitting them as I go. I think I've also come across these bit of slightly more "dicey" changes required for unification: 1. the iterators all have heavyweight initialization in
new
meaning there's no way to avoid doing things like fetching blocks from S3 until the first
next_entry
which is a no-go for a basic get since you probably won't need most SSTs. I'm planning on splitting out an
init
method into the iterators so that we can defer the initialization of iterators OR call it eagerly when we want to prefetch/initialize iterators for range scans. 2. the bloom filter stuff is a little tricky because we need to record false positive rate so I'm thinking of having a special
SingleKeySstIter
that wraps the
SstIterator
and handles the bloom filter checking and stat recording. The get code would instantiate that iterator (which would also work for cases where you have merge operands for the same key). 3. I need to either change the
MergeIterator
to have a concept of "priority" based on the iterator level (WB/MEM/L0/SR) that allows it to work well with lazy init or create a new iterator that behaves the same way
LevelGet
does today. I'm leaning toward the latter but that'll cause another point of diversion between the two paths though only at the top level.
c
WDYT about doing the "easy" thing now and opening a GH issue with all this for future work?
I do like the iterator work..
that seems worth doing anyway
I just don't want you to get too in the weeds if the immediate goal is merge op
a
that's what I was leaning toward, I'm worried that introducing merge operator before doing this will make it even harder
c
hmm
a
the iterator work is also a good learning opportunity for me, lots of chance to dig into the code ๐Ÿ™‚
c
K. LMK if you need anything. I'm plugging away on some messagedispatcher/error-related stuff.
a
I'll try to get my prototype rough draft out there soon so we can look at it holistically and decide if it's worth it or not before I invest too much time with the nastier changes (like lazy init)
Separate (but related) is it possible for an L0 SST with a higher ID to have a lower sequence number when compared to an SST with a smaller ID? Basically I'm wondering if iterating in order of
db_state.core().l0
is always safe to return the first value found if you discount merges.
r
No thatโ€™s should not be possible. The L0s are always in seq num order. In the current impl thatโ€™s actually true for all sorted runs but we could relax that
c
yep. Regarding sorted runs, I recall having some discussion with @Sujeet about this when he was working on compaction job validation.
IIRC, we would need to update the read path code if we change how SRs are ordered
r
yeah the seq nums give us enough information to do this now
a
https://github.com/slatedb/slatedb/pull/941 this turned out to be a little easier than I thought it would be and I think it's a worthwhile change anyway
c
Nice!
Will try and have a look today/tomorrow.
Unless someone beats me to it ๐Ÿ˜€
(haven't forgotten this.. just trying to get my own PR out the door before reviewing)
a
Let me know when it's out and we can trade reviews ๐Ÿ™‚ I've got another one backed up after 941 and then I'm almost done with the unification one backed up after that (thanks for all the reviews!)
c
aw.. Rohan beat me to it ๐Ÿ˜ฎ
a
hehe don't worry, there's more coming!