https://slatedb.io logo
Would the compacted output SortedRuns
# general
s
Would the compacted output SortedRuns only have the most recent sequence no. associated key? (no entries for the same key with previous sequence numbers)
c
No, it can have older sequence numbers, too.
@flaneur233 is working on this right now. There are a few scenarios: 1. There are active (transaction) snapshots in the writer process that are referencing older versions of a key. 2. The user has configured a time travel window where they would like to be able to read data as though it were any point in the last N hours. (1) is https://github.com/slatedb/slatedb/pull/688 (2) is discussed a bit here https://github.com/slatedb/slatedb/pull/638 and a bit here https://github.com/slatedb/slatedb/issues/635
p
This is awesome
Is the
DbSnapshot
persisted, or is it an in-memory thing?
c
DbSnapsnot is in memory for the writer process. We are planning to store the "minimum active snapshot sequence number" in the manifest so the compactor won't drop KV pairs that are still in use (even if they're not the most up to date version of the key). We then plan to add time travel so users can specify "keep all data for the last N hours/days/whatever". They'll then be able to do reads "as of" a sequence number. And we'll store a time -> seqnum mapping in the manifest; this part is less fleshed out and is likely to not be exact (i.e. you say "as of a hour ago", you might see data that's as of the nearest timestamp->seqnum we have).
s
I would need to consider these scenarios in the compaction resuming workflow because based on the current logic it seems we are not storing older versions.
c
Correct, current logic doesn't store older versions. The work for this is still in RFCs/PRs.
s
How would the keyspace be partitioned across SSTs of an SR in a non-overlapping manner when MVCC changes are added?
c
SSTs continue to be sorted by key, then seqnum.
On iteration, most recent seqnum key is used and others are skipped (unless a max seqnum is supplied, in which case, keys above that seqnum are skipped as well).
s
I mean what if the SST grows beyond 256mb and the max seqnum is quite high, so there could be a scenario wherein a particular key spans across multiple SSTs with different seqnum?
c
I don't believe that's allowed. IIRC, @flaneur233 forced all seqnum for a single key in one SST (even if it grows past the max size). I'd need to double check, though
@flaneur233 do you recall what you did here?
Thinking on this more.. I think they do get split 😬 I don’t think the compactor executor does anything special
Ya, it looks like we split keys (and seqnums) across SST boundaries during compaction:
Copy code
if let Some(block_size) = current_writer.add(kv).await? {
    bytes_written += block_size;
}

if bytes_written > self.options.max_sst_size {
    let finished_writer = mem::replace(
        &mut current_writer,
        self.table_store.table_writer(SsTableId::Compacted(
            self.rand.rng().gen_ulid(self.clock.as_ref()),
        )),
    );
    let sst = finished_writer.close().await?;

    self.stats.bytes_compacted.add(sst.info.filter_offset);
    output_ssts.push(sst);
    bytes_written = 0;
}
I think it should be Ok as long as we persist the last successfully written seqnum in the compactor file right?
Then we can resume from exactly the next seqnum when we start the next SST on resume
f
oh i had some memories about this, when flushing ssts, RetentionFilter did not let one key's multiple versions to be put in two flushes.. in an extreme case like if a key has 1billion versions, this behaviour should has issues 😯
oh my memory was wrong... yes, this code snippet located in compactor_executor.rs, and this iter should allow multiple versions to be spanned across different ssts...
c
@flaneur233 I had the same memory haha..
s
> I think it should be Ok as long as we persist the last successfully written seqnum in the compactor file right? Then we can resume from exactly the next seqnum when we start the next SST on resume With the ranges overlapping, binary searching the SST partition of a SR and then iterating the SST wouldn't work to find the correct position of the next iterator to start a resume in it's current form. We might need to have the first and lastKey present on a SST to efficiently binary search a sorted Run.
c
We already have first key (see sst.fbs). IIRC, someone else was asking for last_key to be present as well. Seems reasonable to store it in the fbs/meta.
Might also want to store first/last seqnum as well..
s
> Might also want to store first/last seqnum as well.. Across the SST or for a key?
c
Just first/last seqnum in the SST header
s
Yes, we can do that. What is the use-case that you see for it?
c
It would allow us to see the last persisted seqnum for a compaction job, and seek to that spot in the merge iterator without the need to think about keys.
(i think.. haven't really thought about this more than a minute πŸ˜› )
s
Hehe..But won't we first be searching the key and sequence_no would be as low watermark when merging into a destination SR?
c
Not sure.. either way, not a big deal πŸ™‚ Better to keep the header slim until we find legit reasons
s
ok