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
I do understand that the absence of the old_val key indicates that a particular row is part of the initial batch; however, this is not sufficient in telling us which row represents the final one of the initial batch.
Consider the example above. In the case where the scores table contains less than 10 rows to begin with, we are unable to determine the end of the initial batch on the client.
@hpx7 -- there isn't really a good way right now. We went back and forth on this, but decided against complicating the format for the initial release. What sort of interface would you like to see?
Looking at the javascript driver, it seems like the EventEmitter interface could be useful - there could be a loaded event which indicates the end of the initial batch. Not sure how this would be implemented in the other drivers though.
Another option I see is simply adding a field to the rows returned from the changefeed (in addition to new_val/old_val). Perhaps an integer remaining field or simply a boolean lastOfBatch field.
Something like the "remaining" concept could possibly be implemented on the cursor level instead as well.
A pretty reasonable protocol implementation would be to add a field {note: "last_initial_val"} to the last initial document. That would let people who don't care about this information ignore it, and it would be backwards-compatible so it would avoid breaking any code that was written for 1.16 changefeeds.
The first notification object in the changefeed stream will contain the query's initial value in new_val and have no old_val field.
This sounds a little ambiguous in the case of multiple initial documents, but it sounds like one can unambiguously distinguish any query's initial results from its change events by waiting for the first response with an old_val key.
If so, then adding a note key makes sense as we won't have to block on the first change to make that distinction. This conversation is strongly related to the return_initial proposal in #3579.
Maybe this is crazy, it'd probably require redoing the protocol a bit, but what if we returned two cursors, one for the initial value and one for new changes?
Handling the case where a query may return more than one cursor sounds like a lot of complexity; can you envision a use case where you'd both want the initial data set, and want to read new changes before reading said initial data?
The only issue I see with the {note: "last_initial_val"} solution is that it requires the database to know, when publishing a particular row, whether that row is the final one. I can imagine scenarios in which this may not be a desirable property.
One solution that doesn't have this problem is simple adding a {ready: true} message to the protocol, but extending the protocol to support this may break backwards compatibility.
I suppose the {note: "last_initial_val"} option will also not work in the case where a query happens to not return any values initially, which is something you may not be able to predict depending on your current application state.
That's a fair point about not being able to attach the note if there are no initial values. Maybe breaking backwards compatibility is better then. (We could also omit the {ready: true} documents by default and have an optarg to turn them on; that would preserve backwards compatibility while letting people who really need this information get it.)
That seems reasonable. To be clear, its sounds like the resultant usage would be:
Set an optarg, mark_ready or something, on a query with .changes()
Handle documents lacking a ready key as a query result (extracting from new_val key)
Read a document with a ready key, discard
Handle all future documents as a changefeed event (with new_val and old_val keys).
Which does not require the database know which is the final document in a query result, does not block on change events for a client to know the full result set, and also handles the case of no results.
As a bonus, aside from extracting the new_val key in step 2, you can pretty much use identical code to process query results with or without changefeeds.
Is it possible to add the documents to the feed only when their value is added to the initial stream?
The "only" consistency required is that the documents are up to date.
So I'm fine with the following situation:
Ask for a change feed on a range that contains doc1 and doc2.
Update doc1.0 to doc1.1 and doc2.0 do doc2.1
Retrieve doc1.0 and doc2.1 and get only the change for doc1.0 -> doc1.1
If I understand your example correctly, that sounds like it has more to do the MVCC nature of the database than separating initial results from changefeed events.
I don't think adding {ready: true} behaviour would would effect your example in any way.
I would expect: doc1.0, doc2.1, ready, doc1.0 -> doc1.1.
We add an optarg note_states to changes. It defaults to false but can be set to true on any changefeed.
If note_states is true, we will occasionally insert documents of the form {state: X} into the stream of changes.
One value for X will be initializing. We'll send {state: 'initializing'} as the first document of a feed which returns initial values.
Another value for X will be ready. We'll send {state: 'ready'} whenever we're done sending initial values. (So for a changefeed which doesn't return initial values, {state: 'ready'} will be the first document.)
We reserve the right to add more states in the future.
We reserve the write to send changes before {state: 'ready'}, even though we don't do so right now, but if we do so then we'll guarantee that the initial value for a particular primary key is always seen before any changes to that primary key.
I didn't like include_status in this context at first. But I can't tell why and also cannot come up with a better name (I had considered send_status, but don't like that much either).
If some writes happen on the table, I can get changes about the document with id: x only after I receive {new_val: {id: x}}.
If someone insert {id: 4} before ready is sent, will I get {new_val: {id: 4}} then {new_val: {id: 4}, old_val: null}? Or can I get straight {new_val: {id: 4}, old_val: null}? Or just {new_val: {id: 4}}?
Could we have a note to distinguish this feed from other feeds? Such that generic libraries that want to build a higher API (like maintaining a list of changing documents) don't have to wait for the first element to know what they are dealing with (similar to the atom feed)?
One last picky thing. While include_states sounds better than note_states, it doesn't quite describe what the option is for. Shouldn't it be more something like initial_values: true (or something better)?
:+1 overall it looks like a clean API :) I would be happy to add that on thinky :-)
Could we have a note to distinguish this feed from other feeds?
You mean a feed that has include_states enabled? That's a good idea, I think we should do that through our ResponseHints interface (#3715).
Shouldn't it be more something like initial_values: true (or something better)?
That seems like a much worse description of what include_states does to me. I mean you can get the initial values without include_states.
If someone insert {id: 4} before ready is sent, will I get {new_val: {id: 4}} then {new_val: {id: 4}, old_val: null}? Or can I get straight {new_val: {id: 4}, old_val: null}? Or just {new_val: {id: 4}}?
I think you would either get only {new_val: {id: 4}, old_val: null} or only {new_val: {id: 4}}, but not both.
Activity
hpx7 commentedon Jan 31, 2015
I do understand that the absence of the
old_valkey indicates that a particular row is part of the initial batch; however, this is not sufficient in telling us which row represents the final one of the initial batch.Consider the example above. In the case where the
scorestable contains less than 10 rows to begin with, we are unable to determine the end of the initial batch on the client.mlucy commentedon Jan 31, 2015
@hpx7 -- there isn't really a good way right now. We went back and forth on this, but decided against complicating the format for the initial release. What sort of interface would you like to see?
hpx7 commentedon Jan 31, 2015
Looking at the javascript driver, it seems like the
EventEmitterinterface could be useful - there could be aloadedevent which indicates the end of the initial batch. Not sure how this would be implemented in the other drivers though.Another option I see is simply adding a field to the rows returned from the changefeed (in addition to
new_val/old_val). Perhaps an integerremainingfield or simply a booleanlastOfBatchfield.Something like the "remaining" concept could possibly be implemented on the cursor level instead as well.
mlucy commentedon Jan 31, 2015
A pretty reasonable protocol implementation would be to add a field
{note: "last_initial_val"}to the last initial document. That would let people who don't care about this information ignore it, and it would be backwards-compatible so it would avoid breaking any code that was written for 1.16 changefeeds.kofalt commentedon Jan 31, 2015
In general, with the scope of queries that can be watched for changes expanding, it would be nice to have a way to clearly distinguish between:
.changes()From the current documentation:
This sounds a little ambiguous in the case of multiple initial documents, but it sounds like one can unambiguously distinguish any query's initial results from its change events by waiting for the first response with an
old_valkey.If so, then adding a
notekey makes sense as we won't have to block on the first change to make that distinction. This conversation is strongly related to thereturn_initialproposal in #3579.Tryneus commentedon Feb 1, 2015
Maybe this is crazy, it'd probably require redoing the protocol a bit, but what if we returned two cursors, one for the initial value and one for new changes?
kofalt commentedon Feb 1, 2015
Handling the case where a query may return more than one cursor sounds like a lot of complexity; can you envision a use case where you'd both want the initial data set, and want to read new changes before reading said initial data?
hpx7 commentedon Feb 1, 2015
The only issue I see with the
{note: "last_initial_val"}solution is that it requires the database to know, when publishing a particular row, whether that row is the final one. I can imagine scenarios in which this may not be a desirable property.One solution that doesn't have this problem is simple adding a
{ready: true}message to the protocol, but extending the protocol to support this may break backwards compatibility.kofalt commentedon Feb 1, 2015
I suppose the
{note: "last_initial_val"}option will also not work in the case where a query happens to not return any values initially, which is something you may not be able to predict depending on your current application state.mlucy commentedon Feb 1, 2015
That's a fair point about not being able to attach the note if there are no initial values. Maybe breaking backwards compatibility is better then. (We could also omit the
{ready: true}documents by default and have an optarg to turn them on; that would preserve backwards compatibility while letting people who really need this information get it.)kofalt commentedon Feb 3, 2015
That seems reasonable. To be clear, its sounds like the resultant usage would be:
mark_readyor something, on a query with.changes()readykey as a query result (extracting fromnew_valkey)readykey, discardnew_valandold_valkeys).Which does not require the database know which is the final document in a query result, does not block on change events for a client to know the full result set, and also handles the case of no results.
As a bonus, aside from extracting the
new_valkey in step 2, you can pretty much use identical code to process query results with or without changefeeds.neumino commentedon Feb 3, 2015
Is it possible to add the documents to the feed only when their value is added to the initial stream?
The "only" consistency required is that the documents are up to date.
So I'm fine with the following situation:
doc1 and doc2.doc1.0todoc1.1anddoc2.0dodoc2.1doc1.0anddoc2.1and get only the change fordoc1.0->doc1.1kofalt commentedon Feb 3, 2015
If I understand your example correctly, that sounds like it has more to do the MVCC nature of the database than separating initial results from changefeed events.
I don't think adding
{ready: true}behaviour would would effect your example in any way.I would expect:
doc1.0,doc2.1,ready,doc1.0 -> doc1.1.12 remaining items
mlucy commentedon Feb 9, 2015
note_statestochanges. It defaults tofalsebut can be set totrueon any changefeed.note_statesistrue, we will occasionally insert documents of the form{state: X}into the stream of changes.Xwill beinitializing. We'll send{state: 'initializing'}as the first document of a feed which returns initial values.Xwill beready. We'll send{state: 'ready'}whenever we're done sending initial values. (So for a changefeed which doesn't return initial values,{state: 'ready'}will be the first document.){state: 'ready'}, even though we don't do so right now, but if we do so then we'll guarantee that the initial value for a particular primary key is always seen before any changes to that primary key.mglukhovsky commentedon Feb 9, 2015
Is
notebeing used as a verb here? I assumed it was a noun, and got confused. Can we use a clearer verb, likeinclude_states?coffeemug commentedon Feb 10, 2015
👍 for
include_statesAlso, moving to 2.0 after talking to @mlucy (since it's easy to do and pretty important).
danielmewes commentedon Feb 10, 2015
I didn't like
include_statusin this context at first. But I can't tell why and also cannot come up with a better name (I had consideredsend_status, but don't like that much either).Hence
include_statesis good.danielmewes commentedon Feb 10, 2015
Also 👍 on all the other details in #3709 (comment)
I think we can mark this settled.
kofalt commentedon Feb 10, 2015
+1 on @mlucy's proposal and +1 and for
include_states. LGTMdanielmewes commentedon Feb 10, 2015
Thanks @hpx7, @marshall007, @kofalt for all your feedback in this and other threads by the way! Was very helpful.
neumino commentedon Feb 10, 2015
Just to be sure that I understood the proposal. Suppose I have 3 documents in my table.
I'll first get
{state: 'initializing'}, then some changes, and then{state: 'ready'}.Suppose that no writes happen on the table, I'll get
If some writes happen on the table, I can get changes about the document with
id: xonly after I receive{new_val: {id: x}}.If someone insert
{id: 4}beforereadyis sent, will I get{new_val: {id: 4}}then{new_val: {id: 4}, old_val: null}? Or can I get straight{new_val: {id: 4}, old_val: null}? Or just{new_val: {id: 4}}?Could we have a note to distinguish this feed from other feeds? Such that generic libraries that want to build a higher API (like maintaining a list of changing documents) don't have to wait for the first element to know what they are dealing with (similar to the atom feed)?
One last picky thing. While
include_statessounds better thannote_states, it doesn't quite describe what the option is for. Shouldn't it be more something likeinitial_values: true(or something better)?:+1 overall it looks like a clean API :) I would be happy to add that on thinky :-)
danielmewes commentedon Feb 10, 2015
@neumino
You mean a feed that has
include_statesenabled? That's a good idea, I think we should do that through ourResponseHintsinterface (#3715).That seems like a much worse description of what
include_statesdoes to me. I mean you can get the initial values withoutinclude_states.I think you would either get only
{new_val: {id: 4}, old_val: null}or only{new_val: {id: 4}}, but not both.mlucy commentedon Mar 10, 2015
This is in next (CR by Marc).