https://slatedb.io logo
Been pulling at the errors.rs thread a
# general
c
Been pulling at the errors.rs thread a bit over the weekend. Some random thoughts/observations: 1. It seems idiomatic in Rust to have a ton of error types (especially for our internal errors). So I guess I'm OK with the 40+ types we have. 2. I'm struggling with where to put the transient/retry concept. I feel like it's a property of an error rather than a top-level error type itself. Then the question is: should the retry property be exposed to end-users, be used only for internal (SlateDBError) errors, or both? 3. Background tasks kind of act like users: for retriable errors, they should retry rather than set
state.error
, which basically totally halts the DB. 4. We handle backpressure internally right now by blocking the put() calls and waiting internally (maybe_apply_backpressure). This feels right to me (from a user perspective), but it further muddies the retry concept since one could imagine throwing a "Backoff" error that is retryable (transient). The ergonomics around that are uglier, though. Or perhaps we want to support both? 🤔 5. I'm starting to think we should use the
state.error
variable only for permanent errors (i.e. those that require the DB to be closed, data to be repaired, etc). This raises the question about how we get non-fatal errors to users. We probably just want to throw the error once (i.e. mutable take it out of the variable). 6.
Clone
on the SlateDBError is really annoying (it makes the code more complex). But since we are currently returning the
state.error
on every user-facing API call, it has to be clone. I am thinking we might be able to get around this somehow, but not sure the best approach . (this feels like it ties in with 5)
p
2. Is a bit annoying because it would mean that users have to handle some amount of idempotency themselves
c
Yea, so you're saying you'd prefer for us to keep all transient/retry errors internal, right?
p
IHMO retries should be low level, akin to how TCP handles it
c
If we modeled it like TCP, then, we'd return a Timeout to the user if we couldn't retry after some period of time.
Does that sound reasonable?
p
Yes but jt could be configurable, timeout: None, timeout: Some(Duration…
When timeout comes, it shouldn’t completely kill the db, it should be up to the user to decide what to do. Akin to you don’t recreate a reqwest or aws client instance when you get a timeout
1. I think it’s fine and I do like it that way, if you feel a bit in between you can have upper level categories that contains the underlying error
c
We already have that with Error (user-facing) vs. SlateDBError (internal)
Yea I think we definitely need a more nuanced approach to killing the DB. That should really only happen when we have fatal errors.
p
What do you think should be an actual fatal error? On top of my head I think of 404s, corruption (but probably will just panic)
c
Ah, yes, panic is another thing to add to the list of questions. Perhaps as you said, we should eliminate fatal errors and simply panic.
Corruption is the main one. Or invariant violations (e.g. field x must never be empty, but it is)
I wonder what the idiomatic way to handle this kind of stuff is..
p
But panicking on 404 feels off
c
Same
Retry forever on 404 also feels off
But with Timeout.. that sounds reaosnable maybe
p
Perhaps cleanest is to assume a working state, and not assume anything
c
Treat 404 as retriable and then timeout
p
In the end, even a 404 can be transient
c
yup
not sure what you mean here
p
There is a edge case with with auth, maybe
That it’s the user problem if they provide a broken or barely working object storage, that slatedb keeps retrying without too many smarts
c
Yea, that's what I was thinking. If we have a timeout, it should be fine
And for users that set to no time.. that's on them
p
It’s probably a pretty good default anyway
What else useful to do?
And even if they use None, they can still wrap their calls in Abortable, which is pretty common
c
This could be quite clean
I wonder how idiomatic it is in Rust to panic vs. return fatal errors...
p
I think panicking on actually supposed to be unreachable state is fine
Even Postgres does it
(Had Postgres abort on weird things due to physical memory issues)
c
Yea.. for invariant violations I think panic is fine. But for corruption.. 🤔
p
I would say that it’s fine, it signals that something catastrophic happened, and in practice unless someone uses a terrible provider or messes up with the objects it will not happen unless there is a bug somewhere
It’s pretty much undefined behavior
c
K, lemme experiment with this. I think it makes sense
p
If someone absolutely wants no panics they can still use catch_unwind https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
r
i think the main problem with Error is that it is too generic, and i'd argue there probably isn't really a way to make a generic error type that works for everyone, there's always the possibility of someone being interested in handling one specific error condition for one reason or another. given its possible to match on an error for the types you're interested in and wildcard the rest having all of them exposed doesn't seem too bad to me. i think it'd be a lot more useful to have boolean methods to check certain properties of the error, ie
is_transient
(just an example for the sake of the argument, i also agree those should probably be handled internally)
you also don't lose anything in terms of ergonomics vs a set of generic error kinds, since you could just have something like
Copy code
rs
match error {
  SlateDBError::Fenced => {}
  e if e.is_transient() => {}
  _ => {}
}
c
@raftario thx this is helpful feedback. I actually experimented with the is_transient stuff. I much prefer that to
Transient
error, whcih is what we have now. That led me down the "should this even be exposed?" rabbit hole, though. I think we're converging in keeping the transient stuff internal, which should get rid of some stuff. 😄
I'm going to experiment this afternoon to see what I can come up with. I'm shooting for a draft PR and an RFC update.
@Pierre panic on invalid configurations too?
p
I think this make sense but then perhaps we should have builder types on things in settings that can be misconfigured
It would be more idiomatic to me
c
Lil tricky since we support serde from json/yaml/etc
Regarding the TCP analogy: for background tasks (e.g. memtable flusher), not sure what the right behavior is if a "timeout" occurs (i.e. we've retried until the max timeout setting).. I guess panic...
p
This is not really an issue that time
Can easily do it with newtypes
Then the config parser returns a result
What about actually returning a timeout error?
Then the client can decide to do whatever
c
It's a BG process. For memtable you can tie the response to a write if the put() call is awaiting for durability. But for compactor/GC/etc, there is not necessarily a user operation that triggered the timeout. It was a ticker
What we do right now is set the error state for the DB and any user-facing calls will return that error going forward. But for a Timeout, we don't want to block all future operations...
I'm also struggling a bit with the panic analogy with PG. Since SlateDB is a library, not a daemon/app/process, one could argue it's heavy handed to panic the whole process. I am looking at how std::fs works...
Yea.. std::fs almost never panics. It mostly uses Error returns...
Wonder what rocksdb/sled do for this..
Wow the RocksDB one looks strikingly similar to ours
This is really nice..
Some observations on RocksDB's error handling: 1. They allow a
.resume()
that will restart dead bg tasks 2. The allow users to clear bg error states 3. They auto retry for network and retryable IO errors 4. They have tiered error severities (soft, hard, fatal, unrecoverable) 5. They flip the DB to read-only when in error states
r
> What we do right now is set the error state for the DB and any user-facing calls will return that error going forward. But for a Timeout, we don't want to block all future operations... I think for bg processes we should have them try really hard to stay alive and o nly exit on some sort of unrecoverable error, and then only put the db into a terminal error state if a background process exits. I can't think of any other reason to put the db in an error state than a background process exiting. > In the end, even a 404 can be transient If we assume strong read-after-write consistency from the object store why would we see transient 404s? > They allow a .resume() that will restart dead bg tasks What's the benefit over closing and restarting the db? Seems easier to ensure clean state that way. Ditto for point 2.
p
Eg. A temporarily misconfigured proxy that returns 404 on the object store endpoint or a on premises deployment where the proxy returns 404s when the object store is not yet ready, this kind of things
r
makes sense. I feel like ideally that would be handled very close to - really ideally behind - the object store api and the db can just assume a 404 means the object doesn't exist
c
Yea I suppose we can retry on 404s a few times before throwing it up
> I think for bg processes we should have them try really hard to stay alive and o > nly exit on some sort of unrecoverable error, and then only put the db into a terminal error state if a background process exits. I can't think of any other reason to put the db in an error state than a background process exiting. Awesome. I think we're all aligning on this.
I'm thinking of mirroring RocksDB's setup, but simplifying it a bit (no resume, only fatal/unrecoverable errors are set, etc)
> What's the benefit over closing and restarting the db? Seems easier to ensure clean state that way. Ditto for point 2. Honestly, not sure. Only thing I can think of is keeping the in-memory cache?
I'm sure there's some exotic FB-specific reason 😛
p
Did you look what they consider unrecoverable?
c
Yea. They have different tiers, but fully unrecoverable is stuff like corruption.
They map stuff like compactor bg task failure to a "soft" error, which allows the app to call .resume() to restart it. As @Rohan said, though, there's not much diff between calling resume() and just re-opening.