https://slatedb.io logo
After few minutes, everything hangs and I cannot i...
# general
p
After few minutes, everything hangs and I cannot insert anything to the database without restarting the app. I can observe that slatedb is pulling gigabytes from the storage at a high rate, but said operation never seems to complete, here is logs from around five minutes ago:
Copy code
2025-06-04T12:02:57.997368Z  INFO slatedb::compactor: in-flight compaction: ["l0", "l0", "l0", "l0"] -> 4: Submitted
2025-06-04T12:03:02.917017Z  INFO slatedb::compactor_state: finished compaction: Compaction { status: Submitted, sources: [Sst(Ulid(2114457894177155911273022169136335100)), Sst(Ulid(2114457856681437821622624016127345985)), Sst(Ulid(2114457821826831050638563372430378359)), Sst(Ulid(2114457714488333396781744498431174136))], destination: 4 }
2025-06-04T12:03:02.939930Z  INFO slatedb::compactor_state: accepted submitted compaction: Compaction { status: Submitted, sources: [SortedRun(4), SortedRun(3), SortedRun(2), SortedRun(1)], destination: 1 }
2025-06-04T12:03:02.939938Z  INFO slatedb::compactor: in-flight compaction: ["4", "3", "2", "1"] -> 1: Submitted
2025-06-04T12:03:03.197036Z  INFO slatedb::compactor: in-flight compaction: ["4", "3", "2", "1"] -> 1: Submitted
2025-06-04T12:03:13.197099Z  INFO slatedb::compactor: in-flight compaction: ["4", "3", "2", "1"] -> 1: Submitted
2025-06-04T12:03:23.197157Z  INFO slatedb::compactor: in-flight compaction: ["4", "3", "2", "1"] -> 1: Submitted
2025-06-04T12:03:33.197216Z  INFO slatedb::compactor: in-flight compaction: ["4", "3", "2", "1"] -> 1: Submitted
2025-06-04T12:03:40.136727Z  INFO slatedb::compactor_state: finished compaction: Compaction { status: Submitted, sources: [SortedRun(4), SortedRun(3), SortedRun(2), SortedRun(1)], destination: 1 }
Here is the network activity from slatedb at this point:
From monitoring, it seems that when a compaction is started, the memory usage increases
But never decreases from there, and keeps increasing with further compactions
When the network usage is what I reported, and everything hangs, here is the debugging output
It looks like we are stuck in a loop
Hmm enabling the block cache and object storage cache seem to have improved the situation a lot
Yeah, we are still hanging, but this is better
Copy code
I0604 16:06:11.248762   11025 replicate.go:135] Replicated 8300/16842185791 entries
I0604 16:06:11.256100   11025 replicate.go:135] Replicated 8400/16842185791 entries
I0604 16:06:11.258953   11025 replicate.go:135] Replicated 8500/16842185791 entries
E0604 16:06:14.298096   11025 replicate.go:127] Worker 87: Failed to replicate entry at index 21908677: failed to add X.509 chain: got HTTP status "502 Bad Gateway" (HTTP 502: Cloudflare encountered an error processing this request: Bad Gateway)
I0604 16:06:14.832582   11025 replicate.go:135] Replicated 8600/16842185791 entries
I0604 16:06:14.846067   11025 replicate.go:135] Replicated 8700/16842185791 entries
I0604 16:06:14.848606   11025 replicate.go:135] Replicated 8800/16842185791 entries
I0604 16:06:14.851006   11025 replicate.go:135] Replicated 8900/16842185791 entries
I0604 16:06:14.889160   11025 replicate.go:135] Replicated 9000/16842185791 entries
Note the > E0604 16:06:14.298096 11025 replicate.go:127] Worker 87: Failed to replicate entry at index 21908677: failed to add X.509 chain: got HTTP status "502 Bad Gateway" (HTTP 502: Cloudflare encountered an error processing this request: Bad Gateway)
c
Just catching up
@Pierre this started happening when you enabled checkpoints?
p
No, it happened since I stopped manually flushing and using await_durable: true
c
Hmm
K.. I've got to get kids to school and whatnot, but I can poke around a bit in a few hours.
Can you share your DbBuilder/DbOptions stuff that you're using?
With 512GB local cache, and a nfs share for storage ("local" storage in the context of object_storage)
That's very kind, thank you
Wait, I was doing something extremely stupid
I will monitor to see how it goes now
Probably that the memory usage was due to a huge amount of http related futures then
Yeah, seems like it's fine now
Copy code
# tail -F syslog|pv --line-mode --rate>/dev/null
[ 902 /s]
They are each a POST create that creates a bunch of keys in slatedb.
That looks better memory-wise too
That looks nice 😄
c
😅
So things are ok?
p
Yeah, indeed, sorry for the noise!
But from reading more doc strings, it may just be because readers cannot see the wal?
(I don't need that anyway, I just want to make sure that nothing is broken)
c
This is where I miss Java’s visualvm stuff
p
Did you see that?
I forgot to use it btw to debug this
But it's great...
c
🤯
p
Yeah, that was my reaction too when I first saw this, how come I forgot that @criccomini
Looks like a cheat code right?
🥲
c
I can’t quite recall whether readers see WAL data… I’d have to double check.
Ok, so looks like:
Copy code
manifest_poll_interval: Duration::from_secs(10),
            checkpoint_lifetime: Duration::from_secs(10 * 60),
The default manifest refresh in the DbReader is 10s and the default checkpoint lifetime is 5 minutes.
Sorry, 10 minutes
Notably:
> If the reader is > /// using an explicit checkpoint, then the manifest will not be polled.
Are you managing the checkpoint yourself or simply letting the reader handle it?
Copy code
fn spawn_manifest_poller(self: &Arc<Self>) -> Result<ManifestPoller, SlateDBError> {
        let this = Arc::clone(self);
        async fn core_poll_loop(
            this: Arc<DbReaderInner>,
            thread_rx: &mut UnboundedReceiver<ManifestPollerMsg>,
        ) -> Result<(), SlateDBError> {
            let mut ticker = tokio::time::interval(this.options.manifest_poll_interval);
            loop {
                select! {
                    _ = ticker.tick() => {
                        let mut manifest = StoredManifest::load(
                            Arc::clone(&this.manifest_store),
                        ).await?;

                        let latest_manifest = manifest.manifest();
                        if this.should_reestablish_checkpoint(&latest_manifest.core) {
                            let checkpoint = this.replace_checkpoint(&mut manifest).await?;
                            this.reestablish_checkpoint(checkpoint).await?;
                        } else  {
                            this.maybe_replay_new_wals().await?;
                        }

                        this.maybe_refresh_checkpoint(&mut manifest).await?;
                    },
However, it appears we only replay new wals if we aren't reestablishing a new checkpoint... I'm not sure that's right. I need to ask @jason
Lemme open a GH issue on this to nudge the Responsive folks.
Ah, wait. I see that
build_checkpoint_state
calls
rebuild_checkpoint_state
which calls
build_checkpoint_state
which calls
replay_wal_into
which calls. tl;ldr the WAL is replayed.
p
Hmm, so I wonder why I'm seeing "stale" data in my checkpoints
c
Are you passing a checkpoint UUID when opening the reader?
I cannot see data < 60 secs
c
cc @dmvk
^ He's trying to get DbReader working with checkpoints. He's creating his own checkpoint, then passing the UUID to DbReader.
He's not seeing data that he's inserted <60s
The DbReader does not manage refreshing the checkpoint if you pass in your own UUID (according to the docs), but I don't think that's totally true.
Here's some info
p
Thank you @criccomini the good thing is that I don't really need that
So it's not super critical either 🙂
c
Still would be good to get to the bottom of it 🙂
Don't want an unstable 0.7
d
is tldr that DbReader reading from checkpoint doesn't see data from WAL?
p
Things are kind of beautiful now
Copy code
2025-06-04T20:19:15.529851Z  INFO compactlog::storage: Batch stats: 4 batches flushed (avg size: 474, avg time: 1101ms), throughput: 379 entries/sec, queue: 230/2000
2025-06-04T20:19:20.528499Z  INFO slatedb::compactor: in-flight compaction: ["6", "5", "4", "3"] -> 3: Submitted
2025-06-04T20:19:20.530382Z  INFO compactlog::storage: Batch stats: 5 batches flushed (avg size: 546, avg time: 951ms), throughput: 546 entries/sec, queue: 2/2000
2025-06-04T20:19:25.529585Z  INFO compactlog::storage: Batch stats: 4 batches flushed (avg size: 588, avg time: 1096ms), throughput: 470 entries/sec, queue: 38/2000
2025-06-04T20:19:30.528556Z  INFO slatedb::compactor: in-flight compaction: ["6", "5", "4", "3"] -> 3: Submitted
2025-06-04T20:19:30.530119Z  INFO compactlog::storage: Batch stats: 6 batches flushed (avg size: 537, avg time: 346ms), throughput: 645 entries/sec, queue: 620/2000
I got to the bottom of why it was hanging
The nfs storage was pretty garbage, that's it
c
Have you figured out why your DbReader can't see recent WALs?
Refresh multiple times
tree_size should grow with ingestion
But even with checkpoint interval at 2-3 seconds, I'd need to wait 60 secs to get a new size
c
I don't follow
d
same
do you mean that DbReader (~= read only replica) has delays?
that's expected, you need to wait until it refreshes manifest, or am I missing something?
p
I'd expect that taking a checkpoint, using that checkpoint id to open a db reader, I'd have the same state as available in the writer at the time of the checkpoint
Is my understanding wrong?
d
are you opening new DbReader on every request?
d
dumb question, have you tried logging the checkpoint id during reader initialization? just double-checking we're not chasing ghosts
p
I did that! 🙂
I logged the id at creating the checkpoint, and logged which id I'd get in my handler
They match
c
(I noticed that DbReader does not seem to replay the WAL in ::new when a UUId is provided. I mentioned that in the GH issue)
p
BTW, is it stupid to create a new DbReader per request?
d
depends on the use case I guess, it's definitely pretty expensive
p
Ok, I didn't think of that, my app is supposed to be kind of high througput
I except around 10k requests per second on the read handlers in production
d
ok, that will be super expensive just from S3 PoV (# requests you have to pay for)
p
I see
TBH, I think I'll go local nvme
d
with every rebuild, you need to at least: - Read manifest - Replay all WALs - If data are not in WAL, search through L0 ... you don't have shared block cache, so you can't really reuse anything
is there any business need for reading from exact checkpoint with every request?
or do you only care about data freshness - "data not being older than X"
p
No, the only requirement is to not have requests in the past, but that's easily handled
Otherwise, things will not be cryptographically sound anymore
I mean, requests that still uses checkpoints in the past
Once a new checkpoint have been published
d
you could probably just do something along the lines of what Neo4j called "causual consitency"
meaning, you can reuse DbReader, but in order to serve request it must have manifest version > manifest at checkpoint X
p
Yes, that makes sense, in my case I am also saving in a struct at what time I too the checkpoint
So with a little dance, I could do the same with that
d
btw, does reader (DbReader) and writer (Db) live in the same process? I've seen that you're sharing checkpointId through mutex
p
It should be
Not the same thread though
d
then there should be no reason to use DbReader at all
p
Just using the normal tokio scheduler here
d
SlateDB is thread safe
p
The idea was to separate the read and the write path
Because
Db
is not clonable?
And
pub fn put<K, V>(&mut self, key: K, value: V)
takes
&mut self
Maybe I am missing something obvious?
d
p
Ah, that’s cool then
I will see how I can refactor all that, I didn’t see it that way
d
Copy code
pub async fn put<K, V>(&self, key: K, value: V) -> Result<(), SlateDBError>
    where
        K: AsRef<[u8]>,
        V: AsRef<[u8]>,
    {
        let mut batch = WriteBatch::new();
        batch.put(key, value);
        self.write(batch).await
    }
Wasn't the
&mut self
thingy on WriteBatch? There it makes sense - one batch per thread
but db#put should be fine
p
I will check that tomorrow and report back, thank you
(Western europe here… :))
d
Same, I'm in Czech Republic
so feel free to ping me during your workday 😄
p
I hope I am not bothersome with all my questions lol
d
no worries, this should solve all the freshness problems
we'll still investigate DbReader not replaying WAL in some cases, but maybe with less rush
p
When I was doing that even with batch put, I was getting in a kind of inconsistent state, that’s weird
I will implement that back tomorrow without all the locking first
Like, a request would query the tree, but get an intermediate tree structure (like seeing past and new data in subsequent reads, even though I locked there)
Hence the checkpoints, initially
I will see how it goes, I changed a bunch of things in the crypto code since then so who knows
Maybe I was messing something else up
If slatedb guarantees read-after-write after a batch put, that definitely shouldn’t be a thing anyway
So it was probably my fault
Hmmm now that I think deeper I don’t think I’ll be able to do this without further locks: a new hash is submitted, nodes in the tree gets updated, at the same time, a user query something in the tree, we read in a for loop node by node, in between we get a flush, we’d get a broken tree in between two states
Essentially For key in slatedb_get() compute(key) As there’s no isolation yet that’d break without locks
d
@criccomini it should be possible to do multiple gets against the same snapshot (DbStateSnapshot) right?
not sure if we have user facing API for that though
~ basically pinning reads to the same seq id; maybe somehow through transaction API?
c
Absolutely.
But to clarify...
Snapshot != checkpoint. With snapshot, we're talking about @flaneur233 's seqnum stuff, which isn't fully exposed yet.
So.. you're correct, we don't have a user-facing API yet 😅
p
This would be pretty cool
c
We're getting close.. 🙂
p
In the meantime I’ll just add a lock which should do the thing
c
Annoying, but should certainly work
p
Yeah, anyway I am only looking to insert max 1-2k batches per second, so I shouldn’t get crazy contention either with a r/w lock
But then, I wonder if the current approach with checkpoints is not better then 🤷‍♂️
Otherwise, what would work is a get_many method similar to the write batch thing
But not sure how involved that’d be
f
yeah, a snapshot is very lightweight as all it needs is to save a seqnum. right now, the preconditions for snapshots are almost ready imo. all we need is to expose a Snapshot interface to the public. it can offer a consistent view for further reads at the time the snapshot is created (though a snapshot may have an hours-level timeout). on the other hand, a checkpoint is more long-lived. Its lifecycle is managed in the db manifest and it can live much longer than snapshots, and it's considered a bit heavier than creating a Snapshot. it's useful for creating backups for data syncs or migrations imo.
c
Just starting to look at your PR now 😅
f
after this pr, i'll continue work on exposing the snapshot api 😁 (help from community will be appreciated though, i think it should be a good first issue)
p
With snapshots, wouldn’t an api that allows to retrieve multiple keys atomically, then delete the snapshot be easy to implement?
c
Yup!
p
Conceptually, I am a little confused why checkpoints would be useful at all once this lands
This looks like checkpoints, but with a more efficient impl?
r
Checkpoints are a way of "freezing" the database at a point in time. The garbage collector will retain the SSTs referenced by the checkpoint so you can continue to read it even after the compactor has compacted away its contents due to later updates/deletes. You can also use it to create a clone database that references all the checkpoints SSTs.
p
Got it @Rohan
Thank you