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
{{ message }}
Repository navigation
Allow correlating writes with feed notifications #4629
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.
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).
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.
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.)
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?
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).
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.
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?
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.
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.
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).
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.
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.
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).
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.
Reacted by Leander Melms, paranoico, László Király, Benjamin RICHARD and Mislav Paparella
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"
Activity
timmaxw commentedon Aug 5, 2015
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.
mlucy commentedon Aug 5, 2015
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 branchArelates to branchB).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.)
mlucy commentedon Aug 5, 2015
We could also just not worry about squashing changefeeds for the first version, but I vaguely recall that Meteor wanted that feature.
danielmewes commentedon Aug 5, 2015
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 differentbranch_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?
mlucy commentedon Aug 5, 2015
I was imagining that monotonically increasing IDs were important for squashing, and more generally so that if machine A sends
nwrites and tells machine B to wait for them it doesn't have to send O(n) stamps toB(monotonically increasing per-machine IDs work for this because you just have to send O(machine) stamps toBand your cluster probably isn't that big).danielmewes commentedon Aug 5, 2015
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 theclient_id/counterpair, 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.
danielmewes commentedon Aug 5, 2015
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?
mlucy commentedon Aug 5, 2015
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 toB(which has an open changefeed), and then being able to know whenBhas received the entire batch of writes.timmaxw commentedon Aug 5, 2015
Another option would be a command called
table.flush(arbitrary_token), which causes a special message containingarbitrary_tokento be inserted into every changefeed ontable, with the guarantee that the extra message would come after every write that had been completed beforer.flush()started.coffeemug commentedon Aug 5, 2015
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).
danielmewes commentedon Aug 5, 2015
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.
Slava commentedon Aug 5, 2015
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.
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.
danielmewes commentedon Aug 5, 2015
Thanks @Slava for chiming in.
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
counterassigned by the shard's primary (possibly together with the branch ID).58 remaining items
ColonelBundy commentedon Aug 6, 2016
Its been a year, any updates?
danielmewes commentedon Aug 9, 2016
@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.
ColonelBundy commentedon Aug 9, 2016
@danielmewes Alright, thanks.
aogaili commentedon Aug 29, 2016
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.
gustojs commentedon Mar 3, 2017
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"
AtnNn commentedon Mar 12, 2017
This issue hasn't made the list. I believe the implementation is still incomplete.
Extarys commentedon Jun 27, 2017
Sad, some guys still wait on this to include it in meteor