You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Queries such as r.table(t).filter(f).update(u) seem atomic because there is no error when the non_atomic flag is not set. However it is possible for u to be applied when f doesn't hold (see rethinkdb/docs#679 (comment))
A possible work-around is r.table(t).filter(f).update((row) -> r.branch(f(row), u(row), {}))
This is a proposal for adding support in the server for making entire queries or subqueries atomic, by either guaranteeing to the user that queries like this one are atomic or letting the user specify that they should be without needing to duplicate any logic into the update function.
I think we should rewrite r.table(t).filter(f).update(u) to r.table(t).update(r.branch(f, u, nil)). It will be faster and will provide an atomicity guarantee.
Er, ignore that comment, I forgot for a second that we don't have range writes even for whole tables. I think we should rewrite it to r.table(t).filter(f).update(r.branch(f, u, nil)), which will be slightly slower than r.table(t).filter(f).update(u) but will provide the atomicity guarantee.
@mlucy could we also provide or do we already have an atomicity guarantee for getAll.update, between.update, has_fields.update, get_intersecting.update, filter.replace, filter.delete, other similar commands, and combinations thereof?
has_fields is rewritten to a filter, get_all is rewritten to a between, and replace/update/delete are the same operation underneath. So we'd have to implement it twice; once for ranges and once for predicates. I'm not sure about get_intersecting, that might be a third implementation.
Moving this to 2.1 after talking with @coffeemug about it. He pointed out that this could be perceived as "compare and set" failing, which would be bad to still have in the upcoming release. (@danielmewes, does that seem fine?)
@danielmewes -- I made this mistake myself just recently when answering a stackoverflow question. I really think we should try to do something better here.
I just ran into this again. Could we change non_atomic: true to atomic: false and then have atomic: 'document_update' which would have the current behaviour and atomic: 'document_query'which would fail for all queries that touch anything other than the document id?
@AtnNn I like that proposal.
We do need to figure out what document_query means exactly though (does it only work for filter, or also for predicates such as between, getAll or getIntersecting?).
We also need to be somewhat careful in how we name and describe this, since a document_query query isn't actually atomic at all.
If RethinkDB crashes in the middle of a multi-document update for example, it will have updated some documents but not others.
If you compare the set of documents that are updated by such a query and the set of documents in the table that fulfil the filter predicate at any given time, it's also possible that the updated set is not equal to any of the matching sets that existed in the table during the query execution (it will usually be a subset of some matching set, but not always I think).
We need to make it clear that there's still not going to be any atomicity across documents, and that the only thing it does is that it turns the filter predicate into a CAS update.
Activity
mlucy commentedon Mar 30, 2015
I think we should rewrite
r.table(t).filter(f).update(u)tor.table(t).update(r.branch(f, u, nil)). It will be faster and will provide an atomicity guarantee.mlucy commentedon Mar 30, 2015
Er, ignore that comment, I forgot for a second that we don't have range writes even for whole tables. I think we should rewrite it to
r.table(t).filter(f).update(r.branch(f, u, nil)), which will be slightly slower thanr.table(t).filter(f).update(u)but will provide the atomicity guarantee.AtnNn commentedon Mar 31, 2015
@mlucy could we also provide or do we already have an atomicity guarantee for
getAll.update,between.update,has_fields.update,get_intersecting.update,filter.replace,filter.delete, other similar commands, and combinations thereof?mlucy commentedon Mar 31, 2015
has_fieldsis rewritten to a filter,get_allis rewritten to a between, andreplace/update/deleteare the same operation underneath. So we'd have to implement it twice; once for ranges and once for predicates. I'm not sure aboutget_intersecting, that might be a third implementation.mlucy commentedon May 20, 2015
Moving this to 2.1 after talking with @coffeemug about it. He pointed out that this could be perceived as "compare and set" failing, which would be bad to still have in the upcoming release. (@danielmewes, does that seem fine?)
23 remaining items
mlucy commentedon Aug 4, 2015
Bumping this to 2.2 since it was apparently never settled, we should try to settle it during the next discussion period.
zappjones commentedon Dec 18, 2015
Hi all -
I just saw a link in the consistency documentation (https://www.rethinkdb.com/docs/consistency/) pointing to this thread and was wondering if there was any new information regarding making the filter.update process atomic?
Thanks!
mlucy commentedon Dec 18, 2015
@danielmewes -- I made this mistake myself just recently when answering a stackoverflow question. I really think we should try to do something better here.
AtnNn commentedon Feb 12, 2016
I just ran into this again. Could we change
non_atomic: truetoatomic: falseand then haveatomic: 'document_update'which would have the current behaviour andatomic: 'document_query'which would fail for all queries that touch anything other than the document id?danielmewes commentedon Feb 15, 2016
@AtnNn I like that proposal.
We do need to figure out what
document_querymeans exactly though (does it only work forfilter, or also for predicates such asbetween,getAllorgetIntersecting?).We also need to be somewhat careful in how we name and describe this, since a
document_queryquery isn't actually atomic at all.If RethinkDB crashes in the middle of a multi-document update for example, it will have updated some documents but not others.
If you compare the set of documents that are updated by such a query and the set of documents in the table that fulfil the filter predicate at any given time, it's also possible that the updated set is not equal to any of the matching sets that existed in the table during the query execution (it will usually be a subset of some matching set, but not always I think).
We need to make it clear that there's still not going to be any atomicity across documents, and that the only thing it does is that it turns the filter predicate into a CAS update.