Skip to content

Allow correlating writes with feed notifications #4629

Open

Description

@coffeemug

I talked to @Slava today about missing RethinkDB features that would make a Meteor integration much simpler. He said he only needs #3579, and ability to correlate writes with feed notifications. This issue is for the latter feature.

Imagine you have a chat application; when the user sends a message you want to show it on the client right away (possibly greyed out) to compensate for latency (which results in a much better user experience). When the notification later shows up in the feed, you then want to update the color to indicate that the message has been broadcast to everyone. In order to do that well, we need monotonically increasing write ids on per-connection basis.

Here is an example:

> r.table('foo').insert({name: 'Slava'}).run()
{
    inserted: 1,
    write_id: [conn_id, timestamp],
    // ...
}

Then on the feed:

> r.table('foo').changes()
{
    new_val: ...,
    old_val: ...,
    write_id: [conn_id, timestamp]
}

This way the client can correlate the write with the feed notification and do latency compensation.

There are a few outstanding questions:

  • How do we return write ids when the user does a batch write?
  • Does it always make sense to return it on a feed (e.g. what about complex feeds like orderBy.limit, etc.)? Will there ever be a case when we can't return a write id on the feed?

Also, ideally the timestamp would be user readable -- e.g. time-since-epoch_integer (the integer is there to dedup two writes with the same timestamp).

Putting in 2.2.

/cc @mlucy @danielmewes

Activity

  1. added this to the 2.2 milestone on Aug 4, 2015
  2. timmaxw commented on Aug 5, 2015

    @timmaxw
    Member

    Instead of [conn_id, timestamp] it might be better to use [branch_id, counter]. We already internally assign one of those to every write.

    Another advantage is that it might allow some kind of eventual integration with resuming changefeeds using B-tree timestamps. For example, we could put a single set of tokens on the changefeed and use them both for correlating writes and for resuming the feed.

  3. mlucy commented on Aug 5, 2015

    @mlucy
    Member

    The advantage of [branch_id, counter] would be that for squashing changefeeds where 5 changes to the same document are squashed together we could just take the latest stamp and count that as the stamp for the squashed change. The disadvantage of that is that the client would have to know how the branches relate to each other in order to figure out whether [A, 1] is before or after [B, 1] (e.g. they issue a write on a document and get back a stamp [A, 1], then they receive a change for that document with stamp [B, 1], and they don't know whether that squashed change includes their write or not unless they know how branch A relates to branch B).

    I think maybe the way we should do this is a map from machine IDs to timestamps. The stamp for a single unsquashed change would just be the machine ID and the timestamp, the stamp for a squashed change that includes two changes from the same machine would be that machine's ID and the latest timestamp, and the stamp for a squashed change that includes two changes from two different machines would be a map with two entries. (I think machine IDs are probably better than connection IDs.)

  4. mlucy commented on Aug 5, 2015

    @mlucy
    Member

    We could also just not worry about squashing changefeeds for the first version, but I vaguely recall that Meteor wanted that feature.

  5. danielmewes commented on Aug 5, 2015

    @danielmewes
    Member

    Independently of relating different branches for the same region to each other, [branch_id, counter] has the general problem of not being monotonically increasing per connection. If different writes hit different shards, they will have different branch_ids with no useful relation to each other.

    @Slava what are the guarantees that you actually need with respect to the IDs being monotonically increasing? Does this have to hold on a per-primary-key basis or on a per-connection basis? E.g. if you write to two different documents A and B, is it important that you can figure out from the returned IDs which one was sent first? Or is it enough to have that guarantee if you submit two writes to the same document?

  6. mlucy commented on Aug 5, 2015

    @mlucy
    Member

    I was imagining that monotonically increasing IDs were important for squashing, and more generally so that if machine A sends n writes and tells machine B to wait for them it doesn't have to send O(n) stamps to B (monotonically increasing per-machine IDs work for this because you just have to send O(machine) stamps to B and your cluster probably isn't that big).

  7. danielmewes commented on Aug 5, 2015

    @danielmewes
    Member

    How do we return write ids when the user does a batch write?

    If we use [client_id, counter], we could use the same id for all writes in the batched write.
    We could assign the counter on a per-query basis on the parsing node. All write_ts generated from that query will have the client_id/counter pair, and the changefeeds will submit that with their notifications when the writes are executed.
    One problem with this is that it's not clear when the whole query has completed.

  8. danielmewes commented on Aug 5, 2015

    @danielmewes
    Member

    Actually thinking about this more I'm still a bit fuzzy on the use case for this feature.

    Specifically: The way I understand this, the idea is to know when a given write has been reflected in the database and has started to be broadcasted to all subscribed users.

    In the original proposal the idea was to accomplish this by getting some sort of ID for a given write, and then waiting for that ID to show up on the changefeed. However in that case, one could just as well simply wait on the write to be acknowledged, which has about the same effect.

    Is there more to this? @Slava would you mind clarifying?

  9. mlucy commented on Aug 5, 2015

    @mlucy
    Member

    One problem with this is that it's not clear when the whole query has completed.

    I think that sort of sinks the idea. I think the primary use case here would be issues a batch of writes on A, sending a small amount of data to B (which has an open changefeed), and then being able to know when B has received the entire batch of writes.

  10. timmaxw commented on Aug 5, 2015

    @timmaxw
    Member

    Another option would be a command called table.flush(arbitrary_token), which causes a special message containing arbitrary_token to be inserted into every changefeed on table, with the guarantee that the extra message would come after every write that had been completed before r.flush() started.

  11. coffeemug commented on Aug 5, 2015

    @coffeemug
    ContributorAuthor

    E.g. if you write to two different documents A and B, is it important that you can figure out from the returned IDs which one was sent first?

    From my conversation with Slava, if you send a write A and get a timestamp Ta, then send a write B and get a timestamp Tb, and then see Tb on a feed, we must guarantee that Ta should also have been reflected in that feed. (Which I think is equivalent to being able to figure out which one was sent first).

  12. danielmewes commented on Aug 5, 2015

    @danielmewes
    Member

    Which I think is equivalent to being able to figure out which one was sent first.

    That's possibly true if the client has only one outstanding write at a time. In general that's not true in the current implementation, because different shards will have their own ordering for writes that is independent of the order in which the writes were submitted by a client.

    I imagine we could modify changefeeds to adhere to the client sequence ordering if this is really necessary.

  13. Slava commented on Aug 5, 2015

    @Slava

    I was imagining that monotonically increasing IDs were important for squashing, and more generally so that if machine A sends n writes and tells machine B to wait for them it doesn't have to send O(n) stamps to B (monotonically increasing per-machine IDs work for this because you just have to send O(machine) stamps to B and your cluster probably isn't that big).

    Yes, I think this is exactly my understanding. The monotonically increasing IDs help to see a squashed change and compare it to the ones application is waiting for.

    Specifically: The way I understand this, the idea is to know when a given write has been reflected in the database and has started to be broadcasted to all subscribed users.

    In the original proposal the idea was to accomplish this by getting some sort of ID for a given write, and then waiting for that ID to show up on the changefeed. However in that case, one could just as well simply wait on the write to be acknowledged, which has about the same effect.

    This is not exactly what I've proposed to @coffeemug. We don't care about DB acknowledging the write (we get it already in the current driver). We care to see when a write appears in the changefeed observed by application.

  14. danielmewes commented on Aug 5, 2015

    @danielmewes
    Member

    Thanks @Slava for chiming in.

    Yes, I think this is exactly my understanding. The monotonically increasing IDs help to see a squashed change and compare it to the ones application is waiting for.

    Ok that makes sense. That sounds like the IDs need to be monotonically increasing per primary key then, which suggests that we could indeed use the replication counter assigned by the shard's primary (possibly together with the branch ID).

  15. 58 remaining items

  16. modified the milestones: subsequent, 2.4 on Apr 28, 2016
  17. ColonelBundy commented on Aug 6, 2016

    @ColonelBundy

    Its been a year, any updates?

  18. danielmewes commented on Aug 9, 2016

    @danielmewes
    Member

    @makkesk8 The status is still what's written in this comment: #4629 (comment)

    Basically: We have an implementation which needs some final touches, and will try very hard to ship it in RethinkDB 2.4.

  19. ColonelBundy commented on Aug 9, 2016

    @ColonelBundy

    @danielmewes Alright, thanks.

  20. aogaili commented on Aug 29, 2016

    @aogaili

    Hello folks - coming from the Meteor camp this seems like a much needed feature to have a working integration. Going through the comments it seems that the implementation is almost complete but it requires more testing. I personally think this feature should get a higher priority since it's a clear win-win situation. Meteor has a considerable community size and this will definitely gives RethinkDB more visibility (that is how I came to know it) and on the other hand Meteor seems to have scaling issues that RethinkDB should be able to solve. There is a bit of churn in the Meteor community and I think this is the right time to get this moving and if there is anyway I can help I'd love to.

  21. modified the milestones: 2.4, 2.4-polish on Oct 14, 2016
  22. gustojs commented on Mar 3, 2017

    @gustojs

    Sorry for pinging that, but I saw that the list of commits for 2.4 was closed already, so I wanted to ask if this made it to the list or was it pushed back again to 2.5.

    Quoting MDG member comment from 25 days ago - "If that's resolved, I think it will be easy to integrate Rethink"

  23. AtnNn commented on Mar 12, 2017

    @AtnNn
    Member

    This issue hasn't made the list. I believe the implementation is still incomplete.

  24. Extarys commented on Jun 27, 2017

    @Extarys

    Sad, some guys still wait on this to include it in meteor

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions