https://slatedb.io logo
Hmm, any thoughts about how we could split synchro...
# general
d
Hmm, any thoughts about how we could split synchronous and asynchronous part of the checkpoint? - The idea is, when you trigger db.create_checkpoint(flush = true), you want to checkpoint exact state of the database at that particular point in time - Currently this requires locking the database until the returned future completes, otherwise you risk mixing additional data into the checkpoint. This adds significant latency into the system. Can we tweak the checkpoint logic to support this? I'm thinking something along the lines of creating a snapshot in the synchronous phase (before waiting for future)
c
I need to refresh my memory of checkpointing a little bit.
Are you talking about All vs. Durable for CheckpointScope?
And I'm assuming you mean you want "All", but don't want to have to wait for all the flushes to happen?
d
Yes, you sort of want to create a synchronous snapshot immediately and make it durable asynchromously
c
So the first part (flush_wals/flush_memtables) you want async, but the second part you want to happen right away, right?
Copy code
rust
pub async fn create_checkpoint(
    &self,
    scope: CheckpointScope,
    options: &CheckpointOptions,
) -> Result<CheckpointCreateResult, SlateDBError> {
    // flush all the data into SSTs
    if let CheckpointScope::All = scope {
        if self.inner.wal_enabled {
            self.inner.flush_wals().await?;
        }
        self.inner.flush_memtables().await?;
    }

    let (tx, rx) = tokio::sync::oneshot::channel();
    self.inner.memtable_flush_notifier.send_safely(
        self.inner.state.read().error_reader(),
        MemtableFlushMsg::CreateCheckpoint {
            options: options.clone(),
            sender: tx,
        },
    )?;

    rx.await?
}
Issue is, you won't know what the metadata looks like until you've flushed
d
Sort of, I need to continue writing into the database without affecting state of the checkpoint
c
yea
Random thought: IIRC, we're adding seqnum into the manifest already
Wonder if we can use that...
There's some discussion on this starting with this comment: https://github.com/slatedb/slatedb/pull/638#issuecomment-3058808408
Hmm I don't think that will help, though, since it would be the seqnum of the min open snapshot
Thinking on this a bit more.. if you create the checkpoint, but haven't yet flushed the WAL and memtables, the manifest that you checkpoint won't have the SSTs for that data yet...
That's effectively what the "Durable" scope is...
🤔 this is tricky
How long of a time is acceptable for creating the checkpoint?
The WAL flush and memtable flushes shouldn't take that long... Unless you've increased the l0 max SST size quite a bit or aren't flushing the WAL regularly..
r
I think there's a couple ways to do this: With the new WAL architecture we can do this by augmenting the memtable flushing path. Basically we need some way to tie checkpoints to frozen memtables, and then create those checkpoints as part of flushing the memtable. So the mechanism in the db would look something like: 1. extend the frozen memtable type to include a list of pending checkpoints it should create for that memtable 2. as part of memtable flush, create any checkpoints tied to a frozen memtable after flushing that memtable 3. as part of the checkpoint api, freeze the memtable and include the desired checkpoint in the frozen memtable's list of checkpoints, and return some latch that can be used to block on the checkpoint being created. Then the caller knows that the checkpoint it requesed will contain all the data up to the checkpoint call, even though it doesn't exist yet. It can then block on the latch if it wants to get to the created checkpoint. The checkpoint call itself should be super fast since it just requires freezing the memtable Alternatively, we could try to associate a checkpoint with a sequence number, and then eat some cost when cloning it by forcing the db to undo any writes with larger sequence number. For pure readers they can just align reads to the snapshot.
c
I like your first proposal @Rohan. I had been thinking the inverse: assigning a ULID to frozen memtables that aren't yet flushed and including that somehow in the manifest/checkpoint. But your approach is much cleaner.
@dmvk would Rohan's approach work for you guys?