https://slatedb.io logo
<@965845316370833408> left some comments on https:...
# general
c
@flaneur233 left some comments on https://github.com/slatedb/slatedb/pull/440. It looks great. Thanks so much for persisting with this. I think if @almog and @Rohan sign off, we're good to go.
a
I'm pretty swamped this week, but will try to find time for another pass. If it gets another +1 definitely feel free to merge without blocking on me
Got my coffee, and sitting down at my desk until I've reviewd this again ๐Ÿซก
c
Love it. Working on mine right now. Tried to do tea but wasn't high enough octane
a
๐Ÿ˜• I'm still confused... I understand the need for
SyncLevel
on the writer side, I don't understand
ReadWatermark
on the reader side. I left a comment on the RFC to that effect. I might just be dense, if everyone else gets it then feel free to move on without me.
c
Probably a signal worth listening to if you're confused ๐Ÿ˜›
The read watermark is simply governing which watermark you're using to read data from. There is a water mark for committed (which need only be in memory), on local disk, or on remote.
So ReadWatermark is telling you about a durability level (since all three watermarks are only seeing committed data)
a
ok, how is that different from the existing DurabilityLevel?
c
durability level is only used on the writer side
a
sorry, I meant "existing" as in the baseline in the RFC ๐Ÿ˜…
c
Ah! Gotcha. It's a bit of a semantic thing: The "existing" DurabilityLevel only says something about durability: when the data is written to a storage system. It doesn't say anything about consistency (when a complete batch write is visible). The ReadWatermark's "Committed" is meant to express that a batch write has been fully written into a memtable and is now consistently visible
From a durability perspective, the two are the same. From a consistency perspective, the two are different.
a
I think that gets to the point of my comment - why have both consistency and durability controlled by a single enum? If we never allow reading dirty, then DurabilityLevel and ReadWatermark are identical right?
Basically I can set
DurabilityLevel::Memory
for all my reads, but if all writers write with
SyncLevel::Remote
i'll never see data until it's remote anyway
If we eventually did allow dirty reads, then would we have six values in
ReadWatermark
?
c
> If we eventually did allow dirty reads, then would we have six values in ReadWatermark? Nah, I think it would only add one more watermark for in-memory dirty reads since all writes to storage are atomic (right now). If we ALSO added fractional writes (i.e. splitting a single batch write/transaction into multiple SSTs), THEN it would explode the ReadWatermarks as you describe.
But, yea, if we commit to just SI or SSI (as we're doing righ tnow), then I think DurabilityLevel and ReadWatermark are the same. Then it's purely a semantic thing, where @flaneur233 was a bit uncomfortable with using a "durability" enum as consistency. But since we dropped dirty reads and have only one level of consistency now, perhaps @flaneur233 you're OK with using DurabilityLevel for both?
a
I think that would make it easier for me to reason about since there's only one concept on read side. > I think it would only add one more watermark for in-memory dirty reads Trying to follow this. In the simplest form it's possible for there to be uncommitted data both in memory and on local (not in S3) even with atomic writes (if writer is writing with
SyncLevel::Remote
) so at a minimum wouldn't I need to make that distinction if I wanted to sepcify "read dirty, but only if its persisted to local disk" (as opposed to, read dirty even if its only in memory)
c
Ah, you're correct.
I forgot about the local disk part
Essentially, you would need commit watermarks for each tier
Which I guess is what you said
I feel like the KISS approach of simply guaranteeing SI or SSI at all levels is the right thing to do.. keeps it simple
a
๐Ÿ’ฏ agreed, I think we shouldn't complciate things unless the need arises
c
Let's see what @flaneur233 thinks
@almog wanna leave a comment ^ on the GH issue? Not sure @flaneur233 is on Discord at the moment..
a
I did ๐Ÿ˜ƒ (updated with a link to this discord thread)
f
sorry for the late response caught a cold yesterday. quq
iiuc, I think the current disagreement might be about the naming of ReadWatermark, as @almog pointed out, "both consistency and durability controlled by a single enum." "Committed" and "LocalPersisted" are indeed different concepts of Consistency and Durability, but i think "LastCommitted" and "LastLocalPersisted" can be explained as two watermark points in a same history of db writes. ๐Ÿ˜ฏ in a mindset of, a db has a history of writes, we can seek back to a point of this history by specifying a watermark. if using
DurabilityLevel
, the mindset will be "read data persisted to Memory," "read data ensured to be persisted to Local," "read data ensured to be Remote." in my understanding, "read data persisted to Memory" doesn't directly imply the meaning of "latest committed"; it requires a mental deduction process.. therefore, I choose the api to be more contextual in the rfc, to specify we are reading at "the last committed point". the semantic interpretation of
DurabilityLevel::Memory
in the read operations is actually the main concern for me... it could be interpereted as "persistence to memory", but "persistence to memory" this sentence is kinda paradox i am afraid, it's intention is more likely to be "no durability requirement"... if we could remove
DurabilityLevel::Memory
, I think it would help reduce my confusion on this aspect, like:
Copy code
enum DurabilityLevel {
  Local,
  Remote
}

struct GetOptions {
  min_durability: Option<DurabilityLevel> // "min_durability" is suggested by claude sonnet 3.7 ๐Ÿ‘€, for it "
makes it clearer that you're specifying the minimum durability level required for the data you're reading"
}

db.get("key", GetOptions::new()::with_min_durability(DurabilityLevel::Remote))
if
with_min_durability
is not specified, it means no min durability about the data is required, we simply read the latest committed data. @almog @criccomini how do you feel about this api?
a
I totally understand that and can get on board - minor suggestion, what do you think about using NONE, LOCAL, REMOTE so we donโ€™t have to use an optional there? So itโ€™s still called with_durability_level but you can pass is NONE (the default)
Also not to beat a dead horse but I slept on the watermark thing a bit more and to your point about that mental model my concern was that itโ€™s tied to the implementation of the database, not concepts. I could have a database that makes uncommitted data durable first optimistically and only commits it later (Kafka does this, for example)
r
Just catching up on the discussion here. I like where we ended up with the separate enums for durability vs respecting the writer's sync level. I do think we might want to expose the latter on the read side of things though, at least for establishing the transaction snapshot. My worry is that if we only support reading committed data, then in the presence of a writer doing synchronous commits, then concurrent transactions are likely to conflict. It seems reasonable to allow concurrent transactions to request the latest committing (rather than committed) data for their snapshot(s).
f
i am afraid it might has confliction between making consistent snapshot and last commiting, the data with LastCommiting is possible to rolled back at any point, and we can not make this snapshot consistent ๐Ÿ˜ฏ. in the rfc, LastCommiting was forbidden inside transactions, a transaction must starts with a committed sequence number.
c
Yea we backed away from last committing .. I'm thinking through @Rohan 's example. If I understand correctly, the concern is if a writer does SyncLevel::Remote, then there is a somewhat long period of time (depending on flush interval) where other writes could happen that don't see the first write. In that case it's possible a conflict could happen and the subsequent writes will need to fail. Is that right?
I suppose that's possible, but shouldn't the writer just set sync level to none in that case? (They can still wait durability if they want)
f
yep, this is also what i thought
r
the issue is more for other transactions. if some writer is doing a synchronous commit, then the other transactions have a relatively higher likelihood of hitting conflicts since there will be a lot of uncommitted data that is awaiting commit e.g. lets say I have the following writes that have been accepted by slatedb seq100 seq101 seq102 seq103 seq100 is done with synchronous commit set to Remote. Then any new transaction could conflict with all 4 of the in-flight writes.
> the data with LastCommiting is possible to rolled back at any point I guess this is part of what I'm not quite following. Under what circumstances would we roll back transactions that have been accepted by the db (meaning they have passed their SI/SSI checks) and are awaiting being written to the db. That's going to be kind of awkward to do. I suppose you could throw away a WAL segment that you know failed to write to the object store IF you know the committed watermark is lower than the lowest seq num in the WAL segment - is that what you had in mind @flaneur233 ?
or do you mean they're rolled back in the sense that if the db crashes the writes are lost?
f
this is a good point, let me think about it. i had never thought LastCommitting to be able to put in Snapshot before...
yes, user rollback() will not rollback these data in LastCommitting state. it's in the flight of commiting, and the in memory WAL will not be truncated unless process exit or crash
LastCommiting is not LastUncommitted, this is an interesting difference... the data in LastCommitting actually had already passed the SI or SSI conflict checks, and user has no chance to cancel it in the process.
with this understanding, i can not find an solid reason to forbid this... (maybe only allow reading committed data is simpler for users?) so the discussion will come back to whether do we keep LastCommitting or not. i am open for both ๐Ÿ˜ฏ ...
(there might be a small implementation detail for LastCommiting needs to be take care about, we should ensure appending in memory WAL entries in atomic for each commit.)
another question is, if we have allow LastCommiting on transactions, do we still require
with_wait_durability
besides
with_sync
? if i remember correctly, the intention of having
with_wait_durable
besides
with_sync
is also to reduce the chance of being blocked by any other having sync commit ๐Ÿค”
r
> (there might be a small implementation detail for LastCommiting needs to be take care about, we should ensure appending in memory WAL entries in atomic for each commit.) yep. FWIW this is the case today already > another question is, if we have allow LastCommiting on transactions, do we still require with_wait_durability besides with_sync ? if i remember correctly, the intention of having with_wait_durable besides with_sync is also to reduce the chance of being blocked by any other having sync commit ๐Ÿค” Yeah I think if we allow
LastCommitting
its not required
f
oh just remembered that there's also requirement about no-WAL mode ๐Ÿ˜ฏ . in the previous discussion, we decided not to support sync commit in no-WAL mode and it feels make a lot of sense. let me try summarize the requirements so far in my understanding: 1. we hope to have a way to allow multiple writers to write to the db, while allow some readers to read latest undurable writes without being blocked by some one is sync committing. 2. in no-WAL mode, all the writes are considered as committed but undurable, and we hope to have way to await it to be persisted. so, finally we'll end up having LastCommitting + with_sync + with_wait_durability, do i understand this right?
c
Iโ€™m confused about the multi-writer comment: SlateDB is single writer only
f
users can write to a single slatedb instance in different threads, but they're all co-located in the same machine
c
Ah gotcha
> so, finally we'll end up having LastCommitting + with_sync + with_wait_durability, do i understand this right? I'm not 100% clear on this comment. LastCommitting would be on teh read side, while with_sync and with_await_durability would be on the write side, right?
f
yes, LastCommitting is read side only, while the
with_sync
and
with_await_durable
are write side apis (I'd hope to find a more concise API design though.. i found rocksdb also has a no-WAL mode while have way to watch the event of write got persisted with a
WriteWithCallback
api, maybe worth as an reference for this.. ). however, to move this RFC forward, I guess it might good to return to the approach of minimizing api changes and only adding capabilities.
c
@almog this make sense to you? If so, @flaneur233 can you update the RFC (๐Ÿ˜…) so we can approve? Will be amazing to get the design nailed down!
a
Whatโ€™s the actual proposal? Iโ€™m a bit lost with the back and forth
My only sticky point is that if we support last committing (which Iโ€™m convinced we need) that it should be separate from the read durability config. If we have that Iโ€™m happy
c
I believe the proposal is to do that, and to drop read durability config.
I could be wrong on that
RFC update ๐Ÿ˜…
f
but adding back
LastCommitting
as @Rohan suggested might conflict with the previous discussion with @almog about removing it, any suggestion about this? ๐Ÿฅน
hope to get some suggestions from @Rohan on this ๐Ÿฅน
r
IIUC @almog is on board with supporting
LastComitting
, he's just saying (and I agree) that it should be a separate config property with its own enum from the durability level since from the user's POV it's expressing two distinct guarantees. We'd almost certainly implement it by taking the two properties and mapping them to some watermark in the log, but theat's an implementation detail.
so there shouldn't be any conflict
f
i'm still confused about the design of having two enums, but after our discussion, it seems like we're reaching a more consistent understanding about the scope of problem.
r
something like:
Copy code
pub enum ReadLevel {
    #[default]
    Committed,
    Committing,
}

pub enum Durability {
    None,
    Local,
    Remote
}

struct ReadOptions {
    read_level: ReadLevel,
    durability: Durability
}
Then the read implementation just picks a watermark that satisfies both requirements. So if a user asks for
read_level: Committing, durability: Remote
it uses the sequence number that corresponds to the latest state persisted remotely. If a user asks for
read_level: Committed, durability: None
it uses the sequence number that corresponds to the latest committed write.
I think this makes sense because the reader can just list the properties they care about for their read and the db chooses how to guarantee that.
f
if your internal design is picking a watermark, why not align these? i kinda hate having combinations in api design, especially when you could enumerate all the expected use cases with clear semantics you expect users to do.
i'm sorry, but I do feel that some aspects of this API design are a bit out of control for me.. let me rest a while from this. ๐Ÿ˜ณ
r
> if your internal design is picking a watermark, why not align these? It just seems easier for a user to understand what it means. I think we all agree that the durability level and the read level (e.g. committing/committed - not sure what to call this - isolation level?) are semantically different concepts. So from the api pov wouldn't it make sense to specify them separately?
f
having a Durability configuration in the
read
side is still very confusing to me. I've tried to Google similar practices about setting
Durability
on
read()
but nothing found. i don't think there's anything called "Durability Gurantee" on the read side, the durability gurantee is guranteed at how
fsync()
is handled on the write, or how many replica have replicated in the
write
. readers just read established data, the readers can have an option choose flash back to specified point as a snapshot. i think having
Durability Guarantee
in
read
is what troubles me most so far.
> the read level (e.g. committing/committed - not sure what to call this - isolation level?) i am neither sure about how to call this in the sense of ACID but i am sure it's not about isolation level.. where isolation level is about SI, SSI on conflict checking in optimistic concurrency control. i tend to be skeptical that we can find proper term from ACID to reflect this, but it might be possible to regard all these flags for reads as variants of Time Travel.. Time Travel is an useful feature that exists in almost all the modern databases but it's surely not considered as one of the terms inside ACID.
r
> i am neither sure about how to call this in the sense of ACID but i am sure it's not about isolation level.. where isolation level is about SI, SSI on conflict checking in optimistic concurrency control yeah I agree. I just thought isolation since it's the closest term I could think of since it specifies what other concurrent operations you want your read to include/exclude. I agree it's not the right term though.
> i think having Durability Guarantee in read is what troubles me most so far. FWIW I think this is orthogonal to whether or not we use a single enum. I just feel like it's useful for slatedb since there is a potentially long period between a sequence number being committed and it being durably applied, and it seems useful to provide a way for a reader to read only durable data.
f
agree, i also think it's useful. i'm wondering if there's a way for us to avoid using terms like 'Durability or Consistency' while still providing the same capabilities we want. the danger with these terms is that they're so fundamental that we'd need to review many textbooks to ensure that our usage of these terms actually matches the simple things we want to do ๐Ÿค”
r
lol I kind of feel like they get overloaded so much already that nobody really knows what they mean anymore anyway. I think one of the biggest aha moments of my learning about databases was understanding the difference between "consistency" in ACID and CAP.
f
yeah, the meaning of Consistency is totally different in each context ๐Ÿฅน. And even worse, a database product is likely to have both ACID and CAP mentioned on their product page...
r
In seriousness though I agree we should strive to use the right terms. I do think durability appropriately describes what we're talking about when we say durability level - it's a description of how durable data should be to qualify as written or to be served by a read. I don't know the right word for committing/committed though.
f
for my proposal, using
ReadLevel::{LastCommitting, LastCommitted, LastLocalPersisted, LastRemotePersisted}
to describe what's the position we hope to read is a way to skip the naming issue.. I am also afraid that these the two aspects aren't completely combinational -
{Committing, Local}
and
{Committing, Remote}
aren't particularly semantically coherent combinations, at least they should be treated as
{Comitted, Local}
and
{Committed, Remote}
underlying.. it also worries me a lot about how should we tell user when to use
{Committing, Local}
in the docs...
a
{Committing, Local}
does make sense to me if the writer writes with
SyncLevel::Remote
- it's saying "I'm OK reading data that is "uncomitted" because it's not in remote yet so long as its persisted locally". It's scenarios like this which make me think tying the API to the implementation is likely going to bite us going forward. I agree that
{Committing, Remote}
is a bit goofy, you may as well specify just
Remote
-- I don't think that's a problem because the user is "allowed" to think in terms of what matter to them: either the durability or the "consistency" guarantees. Since we're sturggling to come up with a solution here I'm wondering if it makes sense to go back to the motivation. Is there really a need to support
SyncLevel::Remote
? It seems like if you have that kind of consistency guarantees SlateDB is not the right fit for you (probably the same with
ReadDurability::Remote
)
f
> it's saying "I'm OK reading data that is "uncomitted" because it's not in remote yet so long as its persisted locally" i guess the understanding of "uncommitted" is not aligned between us. if you want to read data persisted in local, it should always be committed ("committed" means "applied to memtable"). the commitness is not determined by whether it's stored in remote or not.
> Since we're sturggling to come up with a solution here I'm wondering if it makes sense to go back to the motivation. Is there really a need to support SyncLevel::Remote? It seems like if you have that kind of consistency guarantees SlateDB is not the right fit for you (probably the same with ReadDurability::Remote) let's put this aside for now, I don't think it's urgent. sync commit is a small part in the impl of transaction. however I might need to focus on doing some other things in the near future.
a
> i guess the understanding of "uncommitted" is not aligned between us Correct, I guess I meant "unsyced" data (or "comitting")
c
> the commitness is not determined by whether it's stored in remote or not This is a tricky one. @flaneur233 I agree with you, that's how I've been framing it. Given how SlateDB currently works, once data is committed into the memtable, it's "committed" from them on, regardless of whether it goes to local disk or remote disk. But @almog raised a good point earlier, which is: what if we add local disk WAL support and then write partial data to disk before it's fully committed (for example, to increase write performance using pipelined writes, or to handle large multi-write-batch writes). In that case, we could end up with "committing" data that is on disk.
That's a lot of "what if's" though...
> Correct, I guess I meant "unsyced" data (or "comitting") @almog to make sure I understand correctly, you're saying if a writer writes with SyncLevel Remote, a reader should be able to see the data after it's local if it requests local durability and "committing". I think this is what we raised with Rohan earlier: shouldn't the writer set sync level to local in that case? The reader and writer are going to be in the same process and presumably controlled by the same developers.
In that case, the writer can still await_durability=remote...
a
I guess so? My point is that it's easy to understand what
{Committing, Local}
means without making assumptions on how it's used. We could achieve the same behavior by saying "we recommend you set
SyncLevel::Local
and then read with
LastCommitting
if you want that behavior, but also make sure that you are OK reading data that isn't in
Local
if some writers decide to write with `SyncLevel::Memory`". That seems... more difficult to explain
r
> i guess the understanding of "uncommitted" is not aligned between us. if you want to read data persisted in local, it should always be committed ("committed" means "applied to memtable"). the commitness is not determined by whether it's stored in remote or not. wha? Isn't this the whole point of synchronous commit? that we want a way to only consider a write committed when it's written with some level of durability?
c
EDIT: derp, I missed the word "synchronous" in Rohan's comment. Leaving the below stuff here just for references. But yes, for SYNC commit, the point is the durability level. No, they're two different things in ACID. All consistency says is that you'll see no partial txns. This was the point if my foray into PG. In PG, You can set the sync commit semantic to simply be in memory. So data can be lost in a crash but will be seen as committed prior to failure.
Granted, ACID is a disaster with no clear definition.
In DDIA, Kleppmann days consistency doesn't even belong in DB--it's an app thing.
This discussion with Phil Eaton was enlightening: https://bsky.app/profile/chris.blue/post/3lf6pgpg5f22r
All this said, since there's no real formal definition, @flaneur233 did a survey of badger and rocksdb to at least see if we could adopt their style..
That is where all this is coming from--the RFC is largely how RocksDB behaves. Granted, SlateDb has a different writing style with batching (commit groups in RocksDB) and remote writes. So we don't have to copy them...
Ohhhh derp.. I missed the "synchronous" adverb there ๐Ÿ˜‚
Yes, for SYNC commit, it's meant to define how durable the write needs to be before it's considered committed.
f
if you enabled
sync: local
in your write, your write will be considered as committed when it's flushed into local disk & applied to memtable, you do not require to await it to be persisted in remote to be considered as "committed".
oh, this might be the source of all the arguments above. we can focus on this topic in the later discussion
r
> No, they're two different things in ACID. All consistency says is that you'll see no partial txns. I thought that was the A "atomic" in acid. My understanding was consistency was avout db consistency constraints (like foreign key constraints)
f
> My understanding was consistency was avout db consistency constraints (like foreign key constraints) +1
> @almog to make sure I understand correctly, you're saying if a writer writes with SyncLevel Remote, a reader should be able to see the data after it's local if it requests local durability and "committing". it's committing not because it's in local, but because its WAL not flushed to Remote. i've draw some time sequence graph in the rfc on this. before the WAL entry is persisted to the target level (like Remote), it'll not be applied to memtable, and not considered as committed. whether the WAL is flushed on disk or not, does not affect the fact it's commited or committing.
> But @almog raised a good point earlier, which is: what if we add local disk WAL support and then write partial data to disk before it's fully committed (for example, to increase write performance using pipelined writes, or to handle large multi-write-batch writes). In that case, we could end up with "committing" data that is on disk. this not unusual in postgres, the wal is also flushed in local first, and the "commiting" data is simply not committed yet,. if we fail to flush to remote when enabled with
sync_commit: remote
, the commit simply aborted and nothing happens.
c
Yep, thatโ€™s what I expected.
Blah, youโ€™re right. :homer:
God I hate ACIDโ€ฆ
Anyhowโ€ฆ what do we need to do to converge on this? I realized today that the RFC was opened in October ๐Ÿคฏ
Iโ€™m kinda lost on the current state of the convo..
f
iiuc, the current difference on understanding might be whether it's useful to have
Committing + Local
Committing+Remote or not, or what the behaviour it's expected to have if we decides to have these ๐Ÿค”
c
Oof code you re-paste that? Iโ€™m seeing HTML in discord lol
f
i failed to mark the delete line in discord ๐Ÿคฃ just remembered that we all agreed there's no
Committing + Remote
in the options
c
Gotcha
f
having
Committing + Local
seems trick for me
Committing + Memory is kinda straight forward, we can implement this as read an additional WAL table in memory plus reading Memtable
a
I think for me it's less about what we support and what we don't but instead how we communicate the configs. We could throw exceptions on unimplemented combinations of configurations, but I think having two separate configs: one for durability and one for "unsync" reads makes it much easier for me to understand what's going on rather than a watermark that imposes an ordering that's tied to implementation. All in all, though, I agree with Chris. I'd rather make progress here so we can close this out. Don't mean to be keeping it open since October!
That way I can think about durability and "consistency" (for lack of better term) as distinct concepts
f
not expectd to see the world changed a lot after october ๐Ÿฅน
c
This does seem to align with my initial statements around D and C being two different things
I suppose under the hood, the implementation would use the watermarks anywayโ€ฆ just different combinations of C and D would result in different water marks (or exceptions if we donโ€™t support a given combo)
Kinda seems like weโ€™re just talking about API at this pointโ€ฆ which I guess is what Almog meant by how we communicate the configs.
@flaneur233 can you elaborate on this? Whatโ€™s the concern about it being tricky?
f
let me post another proposal: -
with_persisted_only(DurabiltyLevel{ Local, Remote})
or
with_durable_only
-
with_dirty(true / false)
-> use a bool to avoid naming an enum, we all agree that
LastCommitting
is not a good default for normal users, it's an dangerous option, the data is risky to be lost after crash.
with_dirty()
and
with_persisted_only(DurabiltyLevel{ Local, Remote})
can not used together. @almog @criccomini how do you feel about this api? i found what we want is to specify a filter when it comes with durability on read side, it's not about durabilty gurantee.
i haven;t thought thoroughly about how to implement this, it might contain lot of details while the use case might be limitted... to allow reading the committing data, we have to read the in memory WAL, and on the other hand, the durability requirement
Local
requires us to read the data have to be persisted in Local. so what we have to do might be to read the WAL on local disk in stead of the in memory WAL, or have some water marks in the in memory WAL to allow us only read the wal entries that had local persisted, and do we need to skip memtable here? a memtable might partially persisted in local
c
At first blush this seems reasonable. I particularly like the "with_dirty". That feels very intuitive to me. But let me sleep on it and follow up tomorrow. ๐Ÿ™‚
f
have a good night!
c
Thanks! My kids are being a pain in the butt right now.. Middle schoolers (12 year olds) are frustrating!
Yea, I was noodling on the implementation a bit as well. Reading the on-disk WAL could get expensive since it's essentially a ton of little L0 (un partitioned) SSTs... But IMO, we should punt on this and not implement it right now. We don't even have local disk, which, itself, is a big effort.
f
will have a father-son programming team after 3~4 years ๐Ÿ˜†
c
It's possible we could keep a separate in-memory KVTable that mirrors what's on local disk to avoid actually going to disk on reads.
He's big on scratch right now.. it's a pretty interesting little visual programming language. He discovered it even has a debugger!
WDYT about
with_durability
and
with_dirty
?
f
i think the
_only
suffix may help empahsis it's a filter instead of a guarantee, 'durability' describes a property, while 'durable_only' refers to a filter.
c
Yea, I just caught that...
So your proposal is you can set either one or the other but not both
So if a reader wanted to read local + committing... how would they do that with the settings you propose? It seems not possible?
f
yeah, exactly, i think
with_dirty
is an advanced option, user should know what they are doing to use this
yes, i guess @almog will also agree that we can put
local + committing
aside at the moment, just return error on this combination
c
Gotcha. I suppose if we wanted to support local + committing (with_dirty + with_durability), the API would support that. We would just relax the constraint that you can only call one or the other.
So it does give us the flexibility to implemenet it if/when we decide we neeed it..
I'm still stuck on the "only" ๐Ÿ˜ญ WDYT about
with_durability_filter
? ๐Ÿ™‚
f
i like this ๐Ÿซก , all i want is to describe it's a filter in read options while avoid to describe it's a property of the read operation
c
Ya it seems to fit with how you're actually describing it..
Ok, so proposal is now: 1.
with_durability_filter
that determines whether readers see local/remote committed data. 2.
with_dirty
, which determines if users see "committing" data (not yet durably written to the WAL as defined by the SyncLevel on the write-side). 3. Only one or the other can be set.
For (1), would we have just local/remote? Or an "in-memory" (but still committed) as well?
f
i think so, we can treat it as do nothing
c
Ok, I'm feeling pretty good about this. But again, let's sleep on it and let @Rohan and @almog weigh in.
It seems to give us the flexibility we might need in the future while still maintaining the semantics you want.
I thnk we really got wrapped around the axle with this "local" stuff, considering we don't even have it yet ๐Ÿ˜… .
I'm debating if we really need "local" if we split the WAL path as I describe in https://github.com/slatedb/slatedb/issues/504. That would allow S3 Express...
f
adding one degree of freedom increases the complexity exponentially ๐Ÿฅฒ
c
Hahaha yea..
Keeping it locked down to either/or for now lets us keep the initial implementation more straight forward...
One other question: Does this API re-create the issue Rohan raised about transaction conflicts earlier?
f
i am also a bit debating about this, i am not sure whether having local WAL or accelerated WAL storage is a global config instead of per read/write config?
sorry i lost my context about the tx conflicts part ๐Ÿ˜ฏ, can you help guide me a link?
c
Digging it up
f
@criccomini i think this increasing likelyhood of conflicts is inherently with sync=remote, when the commit is slow, this will fail the later updates on the same rows, but this is exactly what we want in the order billing case: it's actually a coordination to avoid this order to be updated by others until this write is persisted / committed.
when we use locks, it also increase the likelyhood of contention on the same objects. it will slow down the others to access this same object. coordination will slow down operations on the same objects.
c
Yea, definitely semantically correct. But I think Rohan's point was that allowing the txn to see dirty writes would reduce the amount of conflicts while not impacting ACID semantics, right?
(nm about phantom reads ๐Ÿ™‚)
f
oh i remembered it, yes, when a batch of commits is on the flight to be persisted. allows readding the Committing data will not violate the transaction isolation in other txns, as Comitting is not Uncommitted, it will not rollback unless the process crashed.
c
Ya! That's a good description
So I think the quesiton is how does the proposed API handle that case?
f
so, i think having
with_dirty
will resolve @Rohan 's requirement here
in the previous discussion, we were planning to forbid all the committing/uncommitted reads, only allow the committed data to be read
c
Fair enough. Since the dirty read data will have to be durably written prior to the subsequent txn's write.
(It would get more complex if we added Local+Committing, but we're tabling that now)
f
yes ๐Ÿ˜
c
Ok!
Ok, tuckin the kids in. Responding to the above message to bump it down here as a tl;dr for Rohan/Almog ๐Ÿ˜…
๐Ÿค—
f
good night ๐Ÿ˜
r
I think this makes sense, but why only allow one or the other to be set?
> i haven;t thought thoroughly about how to implement this, it might contain lot of details while the use case might be limitted... to allow reading the committing data, we have to read the in memory WAL, and on the other hand, the durability requirement Local requires us to read the data have to be persisted in Local. so what we have to do might be to read the WAL on local disk in stead of the in memory WAL, or have some water marks in the in memory WAL to allow us only read the wal entries that had local persisted, and do we need to skip memtable here? a memtable might partially persisted in local I'm not following. What's wrong with the way we're doing things today where every write enters the memtable immediately and its flushed to the WAL in the background? With seq numbers it makes it really straightforward to decide what to include or not to include in a read - you just read the data that's <= the sequence number you care about. So if you want to read committed data only, you just do the read against the seq num that corresponds to whatever was last committed.
f
> you just read the data that's <= the sequence number you care about indeed, but for LastCommitting + DurabilityLevel::Local, which hopes to read the data had flushed in WAL in local but not flushed in Remote and all the data are at least persisted in local when user set
sync: Remote
so it's considered as Committing not Committed, which seq <= we'd depends on for this?
i am curious about when shall we use this combination.
r
in that case you'd just read whatever seq number maps to the latest write that has been persisted locally
the reader doesn't care about reading dirty data, but just wants to make sure the reads are persisted locally
also I'm ok with just not allowing that since it's a weird use case - just it seems straightforward to choose a seq num
f
no seq only works in memtable, i still have to find something in WAL to read these uncommitted data.
r
> no seq only works in memtable, i still have to find something in WAL to read these uncommitted data. not following
f
can you explain, how to use seq to get the uncommitted data but local persisted from WAL + memtable with this seq num?
r
that probably comes to my other comment above - why wait to insert data to the memtable until after its committed? Why not just insert into the memtable after the isolation check has passed, and just read from the memtable using the right seq num
f
it's intended to insert to memtable after the isolation check passed, then (flush the data to persistence as sync level) AND the data inserted in memtable, and this data will be considered as committed.
r
gotcha. so then all the rows we care about are in the memtable, and have an associated sequence number right? so can't we just apply a max seq num constraint to the read from the memtable?
f
let me think about this ๐Ÿค”
this approach is pretty nice for we can remove the code path to access WAL for read ๐Ÿค”
let WAL only for crash recovery.
we can have a last committed seq, last local persisted seq, last remote persisted seq maintained.
r
yeah. that's kind of how it works today, in the sense that we don't ever read the wal ssts directly - just the wal in-memory tables. But we just did it that way because we didn't have sequence numbers
f
if i have a last local persisted seq, is it possible to smaller than last committed seq? if i sync = Remote, the last local persisted seq, might increased, but it still haven't persisted in Remote, so it's not Committed.
so Comitted + Local Persisted = min(Committed, Local Persisted)
r
yeah. it just picks would just pick the tightest constraint from the read options
f
๐Ÿค” make sense to me
i like the idea to remove the read access to WAL. will simplify some data access path & the maintainance of the in memory WAL tables i think.
a
Iโ€™m on board with the API and with the initial constraints proposed since I see a clear way to lift them if we want to. One last thing to confirm, with_dirty does nothing with the default write SyncLevel of MEMORY, right? That means you only need to worry about it with stricter sync configurations. Iโ€™m +1
c
(reading the updated RFC right now)
Ok! Read the diff, this chat, and then the full RFC again.
โœ…
I'm quite excited about the approach we landed on.
It seems very intuitive to me.
a
Got my โœ… as well!
f
> One last thing to confirm, with_dirty does nothing with the default write SyncLevel of MEMORY, right? That means you only need to worry about it with stricter sync configurations. i am afraid there might have related impacts, if the writer has
sync: Off
on the write operation, this write operation may still be blocked by the previous write with
sync: Remote
, so, it'll append the write to the in memory WAL buffer, and not visible to readers which hope to only read the committed data. at this moment, the readers with
dirty: true
can read these writes.
c
I suppose this could lead to an edge case where a writer calls put(sync off), then calls get(dirty: false) and doesnโ€™t see their own write. This could happen if a previous writer did a put(sync remote) and if hasnโ€™t her for to object storage. This is correct behavior but perhaps unintuitive. (Itโ€™s also mentioned in the RFC) I am comfortable with this behavior. It seems like an edge case to mix sync levels within a process.
@flaneur233 is my understanding correct?
f
i think
put(sync off)
will still await the previous commit to be persisted to Remote, because all the commits are ordered, even it's
sync=off
,
commit()
call will still await the commit to be applied, so the next
read()
will keep "read-your-write consistency" ๐Ÿฅน
asked sonnet 3.7: > does commit() returns after the write is successfully applied to memtable in rocksdb? > does a write operation with sync: false in the current thread need to wait for previous write operations with sync: true from other threads to be applied to the memtable before it can succeed? output: > Yes, in RocksDB, the commit() operation (or any write operation that completes a transaction) returns after the write has been successfully applied to the memtable. This is part of RocksDB's design to ensure that once a write operation returns success, the data is at least in memory (memtable) and will be part of any future reads. > However, all writes are processed in sequence through RocksDB's write queue, so a write with sync: false will still wait for all previous writes (including those with sync: true from other threads) to be applied to the memtable before it can proceed.
r
> I suppose this could lead to an edge case where a writer calls put(sync off), then calls get(dirty: false) and doesnโ€™t see their own write. This could happen if a previous writer did a put(sync remote) and if hasnโ€™t her for to object storage. This is correct behavior but perhaps unintuitive. (Itโ€™s also mentioned in the RFC) shouldn't we just block the write in this case? a write should return when it's committed (and if
await_durable
is true, when it's durable).
nvm - just grokked that it's sync off vs sync memory - I think in that case I'm fine with get(dirty: false) not including the write. By definition with sync off you're asking not to wait for the write to be committed, so its correct that a subsequent read that asks for only committed data may not include the write.
f
> By definition with sync off you're asking not to wait for the write to be committed sync off in other systems like rocksdb seems waiting it to be committed. after commit(), even with sync: off, it's returned after it's committed, "commit" impies it "applied the write"
r
that's odd. seems useful to have an option to not wait
f
sync: off only means it not
fsync()
the wal. after a successful
commit()
, the subsequent reads will read its previous writes.
to allow not to wait, it may require an additional api like this in badger: https://pkg.go.dev/github.com/fjl/badger#example-KV.BatchSetAsync set no sync in badger does not means it's async, users can use these async methods to not wait at all.
looks like this:
r
why add a whole new api for just another sync level like "off" vs "memory" or "remote"?
f
it may sounds odd, but
sync: off
does not means it's an async write.
a
commit()
ensures the next reads operations have a "read your writes"
async means we do not care about when the write got applied, make it fire and forget, maybe with a callback to acknowlege the write.
i am afraid of it might have some unknown risks to have some behavior not aligned with rocksdb or other systems on the
commit()
semantic.
in my current understanding, a
commit()
always implies "apply the write".
r
Alternatively we could support something like the following (as an alternative, in addition to just
commit
):
Copy code
// returns err if it fails ssi check
accepted_txn = txn.apply(sync: <whatever>).await?;
// waits for the commit to finish
accepted_txn.await_commit().await;
> i am afraid of it might have some unknown risks to have some behavior not aligned with rocksdb or other systems on the commit() semantic. I'm starting to feel like all the dbs are subtly different anyway. So someone who's already familiar with how they work will know to carefully try to understand what the semantics are in slatedb. And someone who isn't familiar will need to do that anyway.
f
i think this is the same approach the above badger did
r
anyway, this is all outside the scope of rfc-0007 - just thinking out loud about this now
f
they have
sync: true/false
on write operations, and every write operation have an "async" counterparty
r
I maybe misunderstood but it looks like they have a whole parallel api for async txns. It seems simpler to just have it for the commit part.
anyway, I need to head to ๐Ÿ’ค , my brain is shutting down for the day
f
good night!
(just came across pebble's doc, i found myself love their
WriteOptions
a lot: https://pkg.go.dev/github.com/cockroachdb/pebble#WriteOptions
I think it might not be bad to put some constraints on the design space. following common practices may help users reuse common knowledge (sometimes with biases though), and it's often easier for new adapters to understand the system than learning details comprehensively)
sorry the above async* api i post might be a legacy version, the latest v4 version looks like this: https://pkg.go.dev/github.com/dgraph-io/badger/v4#Txn.CommitWith they offered a
CommitWith(cb func(err error))
function to allow users have a no-await commit call.
c
SGTM. I think we'll want the ability to not block on sync writes, but I think that's a straightforward API to add
Seems like last open thing was the implementation detail around memtable vs wal writes that you and @Rohan are discussing
so close