Skip to content

Make table.filter.update atomic #3992

Open

Description

@AtnNn

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.

Activity

  1. added this to the 2.1 milestone on Mar 30, 2015
  2. mlucy commented on Mar 30, 2015

    @mlucy
    Member

    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.

  3. mlucy commented on Mar 30, 2015

    @mlucy
    Member

    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.

  4. AtnNn commented on Mar 31, 2015

    @AtnNn
    MemberAuthor

    @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?

  5. modified the milestones: , 2.1 on Mar 31, 2015
  6. mlucy commented on Mar 31, 2015

    @mlucy
    Member

    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.

  7. modified the milestones: , subsequent on Apr 20, 2015
  8. modified the milestones: 2.1, subsequent on May 20, 2015
  9. mlucy commented on May 20, 2015

    @mlucy
    Member

    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?)

  10. 23 remaining items

  11. modified the milestones: 2.2, on Aug 4, 2015
  12. mlucy commented on Aug 4, 2015

    @mlucy
    Member

    Bumping this to 2.2 since it was apparently never settled, we should try to settle it during the next discussion period.

  13. zappjones commented on Dec 18, 2015

    @zappjones

    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!

  14. mlucy commented on Dec 18, 2015

    @mlucy
    Member

    @danielmewes -- I made this mistake myself just recently when answering a stackoverflow question. I really think we should try to do something better here.

  15. AtnNn commented on Feb 12, 2016

    @AtnNn
    MemberAuthor

    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?

  16. danielmewes commented on Feb 15, 2016

    @danielmewes
    Member

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions