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
We never implemented a return_initial optarg. Currently point changefeeds and limit changefeeds always do return_initial, and other feeds never do. I think that's probably the desired default behavior.
It would be too much work to support return_initial on range changefeeds before the release, but we could offer the option to disable it on changefeeds where it's enabled by default. @coffeemug, @danielmewes, do you think this is worth doing?
Agree with @danielmewes. I do think that once 1.16 is out, return_initial and/or persistent/restartable feeds will be the next order of business for changefeeds.
This is in next, but may not make it into 2.1. When we're sure where we're scheduling it we should open a docs issue. (Re-assigning to @danielmewes to handle scheduling.)
Question: would the initial state stream be possible to sort?
In my system I want to return the documents in the same order they arrived, so for the consumer it will be received as if it was live (just faster!).
Currently I do a current-value query (sorted by modify time) and a changes() query in a thread each and serialize the output from those threads so they're emitted externally in "initial-then-changes"-order. This is a somewhat cumbersome solution (and notably slower). Having changes() natively return initial state first is a great win for this use case. However, there is the sorting issue...
@tatsujin1 If you just do an orderBy({index: ...}).changes({includeInitial: true}), changes will not necessarily arrive after all initial results, but you can start seeing some changes before you have received all initial results.
There are two work-arounds:
If you also specify {includeStates: true}, you will receive a special document {state: "ready"} once all initial results (plus possibly a few changes) have been transmitted. If you delay rendering in your application until you see that document, you get essentially the desired behavior where the first view that's rendered represents the initial results at the time of the ready document, and from that point on you receive changes to it. Note that at no point you will see a change for a document that you haven't seen the initial result for yet.
If you attach a limit to the query, i.e. table.orderBy({index: ...}).limit(...), I believe you will get the behavior you describe where all initial results will be transmitted first, followed by any updates.
The reason for why unlimited changefeeds with include_initial can send changes before they've sent all initial results is for memory consumption. If we had to somehow keep track of all changes until we're done sending all initial results, that would mean that we would need to use an unbounded amount of memory (depending on the number of changes happening during the time where we stream the initial results).
That changes arrive amongst initial state documents is not a problem; the two sets are simple to serialize in application code. Hmm... come to think of it, I'm not sure that is strictly required. :) (especially as the initial is sent first, as you mentioned)
Sorting the initial state is something I need, however; the inter-document arrival order has meaning in my case, e.g. A then B means X; B then A means Y.
But hey, I hadn't thought of using an indexed .order_by()! As it is required to be first in the query chain I thought it would be too slow to "sort the entire data set", but I tried it now and it is surprisingly fast! :)
Yeah, I know of the state documents, but since I'm doing the initial+changes queries manually it's not currently used, but they of course will be once this feature is in use. If the initial+changes sets need to be serialized that is...
Activity
danielmewes commentedon Jan 15, 2015
I wouldn't worry about this for 1.16. Moving to subsequent.
coffeemug commentedon Jan 16, 2015
Agree with @danielmewes. I do think that once 1.16 is out,
return_initialand/or persistent/restartable feeds will be the next order of business for changefeeds.Timer commentedon Mar 17, 2015
I would be interested in seeing this implemented.
danielmewes commentedon Mar 18, 2015
@Timer @mlucy is working on the full version of this (including
return_initialfor range changefeeds). Will ship in 2.1 (after 2.0).Timer commentedon Mar 18, 2015
Sounds good, thanks for the update @danielmewes!
mlucy commentedon May 7, 2015
This is in
next, but may not make it into2.1. When we're sure where we're scheduling it we should open a docs issue. (Re-assigning to @danielmewes to handle scheduling.)31 remaining items
jasonkuhrt commentedon Jun 17, 2015
👍
Slava commentedon Jun 30, 2015
commenting to register my interest in this issue publicly, as well as subscribe for further updates
ccorcos commentedon Jul 1, 2015
+1
danielcompton commentedon Aug 11, 2015
When this feature is added, will it dissolve the differences between 'point' changefeeds and other changefeeds?
mlucy commentedon Aug 11, 2015
@danielcompton -- yes, the interface should be the same.
stellanhaglund commentedon Sep 7, 2015
This seems very promising, I guess the 2.2 release is months away?
mlucy commentedon Sep 7, 2015
@stellanhaglund -- we don't have a release date yet, but we just released 2.1 and historically releases have been 1-3 months apart.
neonrust commentedon Oct 19, 2015
Question: would the initial state stream be possible to sort?
In my system I want to return the documents in the same order they arrived, so for the consumer it will be received as if it was live (just faster!).
Currently I do a current-value query (sorted by modify time) and a
changes()query in a thread each and serialize the output from those threads so they're emitted externally in "initial-then-changes"-order. This is a somewhat cumbersome solution (and notably slower). Havingchanges()natively return initial state first is a great win for this use case. However, there is the sorting issue...danielmewes commentedon Oct 19, 2015
@tatsujin1 If you just do an
orderBy({index: ...}).changes({includeInitial: true}), changes will not necessarily arrive after all initial results, but you can start seeing some changes before you have received all initial results.There are two work-arounds:
{includeStates: true}, you will receive a special document{state: "ready"}once all initial results (plus possibly a few changes) have been transmitted. If you delay rendering in your application until you see that document, you get essentially the desired behavior where the first view that's rendered represents the initial results at the time of thereadydocument, and from that point on you receive changes to it. Note that at no point you will see a change for a document that you haven't seen the initial result for yet.limitto the query, i.e.table.orderBy({index: ...}).limit(...), I believe you will get the behavior you describe where all initial results will be transmitted first, followed by any updates.The reason for why unlimited changefeeds with
include_initialcan send changes before they've sent all initial results is for memory consumption. If we had to somehow keep track of all changes until we're done sending all initial results, that would mean that we would need to use an unbounded amount of memory (depending on the number of changes happening during the time where we stream the initial results).neonrust commentedon Oct 20, 2015
Thanks for the thorough response!
That changes arrive amongst initial state documents is not a problem; the two sets are simple to serialize in application code. Hmm... come to think of it, I'm not sure that is strictly required. :) (especially as the initial is sent first, as you mentioned)
Sorting the initial state is something I need, however; the inter-document arrival order has meaning in my case, e.g. A then B means X; B then A means Y.
But hey, I hadn't thought of using an indexed
.order_by()! As it is required to be first in the query chain I thought it would be too slow to "sort the entire data set", but I tried it now and it is surprisingly fast! :)Yeah, I know of the
statedocuments, but since I'm doing the initial+changes queries manually it's not currently used, but they of course will be once this feature is in use. If the initial+changes sets need to be serialized that is...mlucy commentedon Oct 20, 2015
This is in
next, but it still needs more testing (I'll create another issue for that shortly). Should be released in 2.2.