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
Every program I've written using changefeeds has had boilerplate akin to the following in it:
if(change.new_val!=null&&change.old_val==null){change.type='added'}elseif(change.new_val==null&&change.old_val!=null){change.type='removed'}elseif(change.new_val!=null&&change.old_val!=null){change.type='changed'// And the new guys:}elseif(change.new_val!=undefined&&change.old_val==undefined){change.type='initial'}elseif(change.new_val==undefined&&change.old_val!=undefined){change.type='uninitial'}
This is pretty mind-numbing, and I would guess almost always necessary ( @segphault and @dalanmiller have written way more apps than me and could comment). In addition, it's also error prone. (There are two errors I made in the example above, can you spot them?) The drivers can provide convenience wrappers, but I think we should just make the changefeeds themselves more user friendly.
I propose we add a type field to changefeed entries, and just put the type in as a string. This would also be a natural place to put type: "error" (see #5041).
Cons:
slightly more cluttered
slightly more bandwidth
sometimes you can just delete old_val, add the new_val and you don't need to exactly classify the type. Even in this case, you can just ignore the type field.
Pros:
Obviously what everyone really wants
Come on
(I would also extend this behavior to the results from return_changes but I would guess the code is shared and so this would just happen as a side-effect)
This is almost the same as #4194, except that the field name and string values are different:
The proposal is to encode this information explicitly by adding an additional field. For example action: 'delete' action: 'insert' action: 'replace' action: 'initial'
I'm going to close the other one, because this one has the nicer write up.
Another "Pro" from the other issue:
The lack of a type/action field sometimes actually makes it impossible to know what happened.
a) Setting the value of a changefeed item to the value null and
b) deleting a changefeed value
are currently undistinguishable.
Oh, sorry, #5041 has the concept of "error" changes, which I suggest become {type: "error"}.
I don't think this is "urgent" since there's a workaround everyone is already doing (barring the edge case correctness issues). But it would be a huge interface improvement for (what I would guess) is not a lot of effort
I like this, for readability/maintainability's sake.
There's not a lot of difference, but I prefer @deontologician's "type" values in the OP ("added" etc), because they more clearly imply that this is an event stream, as opposed to the "action" values like "insert" a la #4194 which could be construed as commands (these objects are not always going to be used that way.)
As secondary benefit, languages like Go have very verbose "exists in a map" syntax (it requires multiple statements), so the new_val/old_val if-else chains are even worse there, and Go has switch on strings, which would be very clean.
In addition we should have type: "state" (for includeStates).
I'm not sure how type: "error" would work. Are you suggesting that we emit an event on the changefeed if someone tries to perform a write, but the write fails? I assumed #5041 was only about the returnChanges result, not for changefeeds. I don't see a reason for why we shouldn't be able to do the same for changefeeds though, if it's desired.
I don't see a reason for why we shouldn't be able to do the same for changefeeds though, if it's desired.
Usually a write fails if not enough replicas are available, or the primary isn't reachable, right? Neither case would allow us to generate corresponding changefeed events with our current architecture.
If the primary isn't available, we can't generate an event because the changefeed events are generated on the primary.
If not enough replicas are available, we only realize that after we've already emitted the change event from the primary, the way things currently work.
I was originally thinking of unchanged writes, that leave a document at the same value. Emitting an event for those might be possible.
I agree the present tense names sound better. It does seem weird to use command names like insert and delete and then call it change instead of update or replace.
It would also be pretty easy to change the default to on if it turns out literally everybody is always turning them on. (Whereas if the default is on it would be break a lot of code to change the default to off.)
It won't be terrible to add an option, and it's certainly better than not
getting the tags at all. I'm fine with 5/off if that's the consensus
otherwise
It would also be pretty easy to change the default to on if it turns out
literally everybody is always turning them on. (Whereas if the default is
on it would be break a lot of code to change the default to off.)
—
Reply to this email directly or view it on GitHub #5188 (comment)
.
A bunch of little things (incremental API improvements, implying use of old_val/new_val null-ness is better if useful, and consistency with the other options being default-off optargs) now add up to me now preferring 5/off for this. As @mlucy said, moving to 5/on later (my second preference) is an easy, compatible change to make.
Activity
danielmewes commentedon Dec 10, 2015
This is almost the same as #4194, except that the field name and string values are different:
I'm going to close the other one, because this one has the nicer write up.
Another "Pro" from the other issue:
The lack of a
type/actionfield sometimes actually makes it impossible to know what happened.a) Setting the value of a changefeed item to the value
nullandb) deleting a changefeed value
are currently undistinguishable.
deontologician commentedon Dec 10, 2015
Would this be a lot extra to implement on top of #5041? I.e. could we do it in 2.3?
danielmewes commentedon Dec 10, 2015
@deontologician Did you mean a different issue? I'm not sure how this is related to #5041.
Would this help with Fusion? I'm not opposed to bumping this into 2.3. Just want to understand how urgently we need this.
deontologician commentedon Dec 10, 2015
Oh, sorry, #5041 has the concept of "error" changes, which I suggest become
{type: "error"}.I don't think this is "urgent" since there's a workaround everyone is already doing (barring the edge case correctness issues). But it would be a huge interface improvement for (what I would guess) is not a lot of effort
danielmewes commentedon Dec 10, 2015
@deontologician That's true. Let me sneak this in.
encryptio commentedon Dec 10, 2015
I like this, for readability/maintainability's sake.
There's not a lot of difference, but I prefer @deontologician's
"type"values in the OP ("added"etc), because they more clearly imply that this is an event stream, as opposed to the"action"values like"insert"a la #4194 which could be construed as commands (these objects are not always going to be used that way.)As secondary benefit, languages like Go have very verbose "exists in a map" syntax (it requires multiple statements), so the
new_val/old_valif-else chains are even worse there, and Go hasswitchon strings, which would be very clean.danielmewes commentedon Dec 10, 2015
I like the
typevalues @deontologician listed above as well.danielmewes commentedon Dec 10, 2015
In addition we should have
type: "state"(forincludeStates).I'm not sure how
type: "error"would work. Are you suggesting that we emit an event on the changefeed if someone tries to perform a write, but the write fails? I assumed #5041 was only about thereturnChangesresult, not for changefeeds. I don't see a reason for why we shouldn't be able to do the same for changefeeds though, if it's desired.danielmewes commentedon Dec 10, 2015
Actually I take that back:
Usually a write fails if not enough replicas are available, or the primary isn't reachable, right? Neither case would allow us to generate corresponding changefeed events with our current architecture.
If the primary isn't available, we can't generate an event because the changefeed events are generated on the primary.
If not enough replicas are available, we only realize that after we've already emitted the change event from the primary, the way things currently work.
I was originally thinking of
unchangedwrites, that leave a document at the same value. Emitting an event for those might be possible.mlucy commentedon Dec 10, 2015
I think this would be OK. Two things:
{type: 'insert'}or{type: 'add'}{type: 'delete'}or{type: 'remove'}{type: 'change}{type: initial}{type: uninitial}.deontologician commentedon Dec 11, 2015
I agree the present tense names sound better. It does seem weird to use command names like
insertanddeleteand then call itchangeinstead ofupdateorreplace.30 remaining items
mlucy commentedon Dec 18, 2015
It would also be pretty easy to change the default to
onif it turns out literally everybody is always turning them on. (Whereas if the default isonit would be break a lot of code to change the default tooff.)deontologician commentedon Dec 18, 2015
It won't be terrible to add an option, and it's certainly better than not
getting the tags at all. I'm fine with 5/off if that's the consensus
otherwise
On Fri, Dec 18, 2015, 16:11 Michael Lucy [email protected] wrote:
encryptio commentedon Dec 21, 2015
A bunch of little things (incremental API improvements, implying use of
old_val/new_valnull-ness is better if useful, and consistency with the other options being default-off optargs) now add up to me now preferring 5/off for this. As @mlucy said, moving to 5/on later (my second preference) is an easy, compatible change to make.danielmewes commentedon Dec 21, 2015
I think there's a majority for off by default.
Marking as settled for 6/off (the 5 ones listed above in present tense +
"state").nighelles commentedon Mar 11, 2016
This is in review #3525.
Implemented in nighelles/5188
nighelles commentedon Mar 25, 2016
This is in next.
Change<T>.Type Support for: rethinkdb/rethinkdb#5188