https://slatedb.io logo
👋 hey folk - I'm implementing the
# general
a
👋 hey folk - I'm implementing the tracker that maps seqnum -> system clock tick and I'm wondering how it should interact with the COW state that we currently have for the manifest. There's potential that this tracker is going to be significantly larger than the other state that we copy-on-write, so I'm a little concerned about adding it directly to the
CoreDbState
. Any thoughts?
I am using gorilla encoding for the serialized format so it stores the data very efficiently once it's serialized (typically only ~12 bits for each timestamp), but in memory it is just an array of i64s. Maybe that's fine to deep clone every time? I'm imagining we'd track up to 4096 seq->timestamp mappings as a default (so 4096 clones).
i'm looking through how often the
CoreDbState
is copied, it looks like only when an imm_memtable is moved to l0 or a WAL is flushed? I may very well be over-thinking this 😅
c
Hmmm
L0 writes happen somewhat infrequently, usually. But WAL writes can happen a lot... And there are some pathological cases where even L0 gets flushed frequently.
If it's 4KiB, though... 🤔
Crazy thought: what if we did seconds for first minute, minutes for first hour, hours for first day, and days forever (rather than locking it in at 4096)?
(this is unrelated to your question 🤣 )
60+60+24+10*365 <- 10 years = 3794 entries
@Pierre how big are your manifest files usually?
@almog I suspect we're over thinking this.. 😛
Since it's just in-memory ops, perhaps KISS for now and if it becomes a problem, we can decouple it in the in memory data structure?
Derp.. 4096 * i64 = 262_144 bytes. Forgot they were each i64's. Also.. should we simply do i32 (or u32?) to store seconds (vs.ms, which gorilla encoding seems to recommend against)
a
(to your aside) I think doing i32 is a good idea, the delta-on-delta would be more consistent in that case
Also what I was thinking of doing is a dynamic tiering where you set the number of mappings you want to track, and then when a tier fills up you double the step and push it to a lower tier. when the lowest tier fills up, you double the step of that tier and bubble up
so you could set a hard limit on the size
it's similar to your exponential decay idea on the GH issue
so you would have (roughly, hard to get the example to line up with numbers there should be no overlap between tiers)
Copy code
tier | seq nums
t0 | 1000, 1016, 1032...
t1 | 512, 544, 576, ...
t2 | 128, 192, 256, ...
t3 | 0, 128, ...
the other nice thing about this is that you don't need to serialize the sequence numbers themselves since they're computable by the
start_seq + index * tier.step
, and then you just binsearch the values to get the timestamp you want
OK thinking about it a bit more I like this... not sure why I've been modeling it as seqnum -> timestamp instead of the other way around.
3794 entires is serialized super tiny, esp if we gorilla encode the seqnums and use the step idea so we don't need to encode timestamps at all
ah actually the problem is that we may not have data coming in for every timestamp interval so we need to store the timestamps themselves if we map from ts -> seq and not the other way around
c
ahh
🤔
Can you fill in any gaps when writing, tho? The seqnum should just say the same if there's no new data coming in
I suppose the manifest updates can be unpredictably timed, though, so we might end up with timestamp gaps anyway if the manifest updates in a 10 minute interval...
So yea perhaps best to stick with seqnum -> timestamp
This does feel a little goofy to me vs. simply keeping
create_time
timestamps in the rows...
We can encode the i64's by row just as cleverly... (similar to what we do for key prefix)
a
I suspect having this mapping will be helpful going forward which is why I'm tempted to keep it global, anecdotadly in Kafka being able to map from offset -> timestamp and vice versa was super helpful we could use this to effectively remove any persisted system clock tick anywhere and just have everything use seq numbers
but it's not a hill I'll die on
c
> I suspect having this mapping will be helpful going forward which is why I'm tempted to keep it global, anecdotadly in Kafka being able to map from offset -> timestamp and vice versa was super helpful How did they do that mapping?
a
it was a best effort mapping since they didn't enforce monotonicity, but I'm not totally sure of the implementation -- I just know they exposed an admin API where you could get it. Let me see if I can quickly dig that up
https://github.com/a0x8o/kafka/blob/master/core/src/main/scala/kafka/log/TimeIndex.scala Looks like they actually keep a
.timeindex
file for every segment if I'm reading this + ChatGPT correctly
also no idea why it pointed to a fork of kafka haha
c
haha
Ah this is interesting
This is actually kinda similar to the delta encoding @flaneur233 was talking about for deletes!
So it appears they don't have a central persisted map
They have sparse per-log (per-SST in our case) indices
this is better to read..
a
Gotta go walk the dog but I'll digest that later, they do have the benefit of being able to binsearch their log by offset which we don't have because we merge seqnums by key, not ordered by seqnum
c
Yea... that's tricky.. we'd have to build something like the retention iterator thingy that @flaneur233 built to buffer stuff.. I'm not even sure that would work for this use case..
I need to think on this a bit, too...
Sparse index in the manifest does seem nice and simple 😅
(comparatively simple 😛 )
Yea.. I'm really coming around to the manifest map..
The lack of sorting by seqnum in the SSTs/SRs makes things rough
I like this
I'm confused about this comment. Aren't the sequence numbers shown in the block diagram above?
Seems RocksDB stores it per-row
I suppose if we stored per-row, it should make timestamp-based reads (both get and iterator) the same logic as filtering by seqnum 🤔
p
Small enough not to matter
Few MBs
a
yeah, the diagram above was representative of the tiering concept but if you think about it all you need to serialize at each tier is:
Copy code
start_seq, step_size, timestamps[] (gorilla)
Then you know that the timestamp at index
i
is for seqnum
start_seq + step_size * i
I'm not opposed to also storing it per row, but we already store the seqnum and the user defined timestamp (which in most cases may actually just be the system time, I wonder if we can indicate that as an optimization somewhere) The map is helpful for situations where you want to get a sequence number for a timestamp (or vice versa) quickly, storing that with each row isn't helpful for that. I feel like this iterator is just one example of where it's useful, but I can't off the top of my head come up with other uses right now
p
Btw, as this keeps coming up (the size thing), it would probably compress pretty well
I don't see any real downside of zstding that thing
a
I don't know if zstd'ing an already compressed gorilla structure would really help - the custom compression is about as good as it gets. I think for a normal workload we can expect ~12bits per 32bit integer
p
Oh, for some reason I thought the manifests were json
a
They're flatbuffer, so it's pretty well compressed 😅
p
Great
No idea why I thought it was JSONs
When you think about it, couldn't manifests be stored in slatedb?
With a "bootstrap" manifest that just references l0s
a
The data model for the manifest is a little different, it's nice to keep it separate from the SSTs IMO