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 already return a summary object from rdb_replace_and_return_superblock, which contains things like :replaced => 1. That function has two variables new_val and old_val which contain the data we want. If the optarg is set, we simply include :vals => [{:old => old_val, :new => new_val}] in the summary object. The algorithm we use to combine summary objects concatenates arrays, so we'll end up with an array of all the replaced vals.
If you're updating a whole table that way, yeah. I don't think we need to support atomic set-and-get for large range updates. (Honestly, we could probably get away with just offering this for point updates.)
We should probably consider just doing point updates. I suppose we should wait on discussing further but I think it's important for those thinking about this issue to know about the constraints of the API when considering it. So I wanted to make sure this was noted before discussion began.
I don't really know how hard it is to do an atomic get/set for a range of documents, but I also tend to think that offering this feature for point updates is enough.
The main use case is when an user update its own settings. I can't really think of a frequent use case where someone would have to do a range update and retrieve all the updated results.
Also, if I'm not mistaken, mongo's findAndModify doesn't exists for range updates.
So I'm about to get radical on y'all since this is the time for such ideas.
What if we rethink(tm) this whole write reporting business and return the updated value by default? The current write summarizing behavior could then be provided by a new summarize or report command.
The main issue with this idea is how we deal with lazy streams of updated values, especially when the user doesn't actually want to read the values. Maybe we only do it for point updates and replaces, as if range updates have .report() tacked on by default.
This is probably not the way forward but I would at least like to explore alternatives to the initial proposal. A weird optional argument plus an even weirder output object are just too much for me.
I'm strongly opposed to returning the results by default because most of the time users don't actually care about getting back the values -- they already know what they are and are just setting them. The case where they want to get the values back (e.g. increment and read) is very important but is fairly rare.
An interesting proposal, but it looks like it may have some problems. Off the top of my head:
If we return a stream from a range update, how do we report errors? Do we change to aborting halfway through rather than continuing like we do now?
We'd be moving back to having different error behavior for point updates and range updates, which kinda sucks.
The do and map examples don't actually work because we'll see the row that we read on the machine serving the query rather than the row that the update function is run on (these may be different if the user is doing something racy). We need a way to get the old row back from the shard after the update if we want to have atomic updates.
Also, right now once you store a single row selection in a variable it turns into an object, to prevent the problem I mentioned above where you do a read and a write on it and expect them both to see the same thing.
Streams of the values from range updates is just never going to work. You either need to store all of the values in memory or have incredibly strange lazy evaluation semantics for the write.
I'll probably just do it for all the write ops because it's easy. It's useful for insert if you're doing an upsert, and it's useful for delete (maybe).
I thought about making the optarg take :old, :new, or :all, but this seemed simpler. Assuming that they aren't drastically changing the size of the row, it's only a factor of 2 performance hit in the worst worst worst case, which didn't seem like a big enough deal to complicate the interface.
Alright, this is settled with old_val and new_val both being included. If people complain it will be easy to update return_vals to take :old and :new as well as true.
Activity
jdoliner commentedon Jun 10, 2013
Could you clarify with this proposal how an implementation might work? Or at least make an argument that this API is possible to implement.
mlucy commentedon Jun 10, 2013
We already return a summary object from
rdb_replace_and_return_superblock, which contains things like:replaced => 1. That function has two variablesnew_valandold_valwhich contain the data we want. If the optarg is set, we simply include:vals => [{:old => old_val, :new => new_val}]in the summary object. The algorithm we use to combine summary objects concatenates arrays, so we'll end up with an array of all the replaced vals.jdoliner commentedon Jun 10, 2013
But won't you now have an array in memory twice the size of the table?
mlucy commentedon Jun 10, 2013
If you're updating a whole table that way, yeah. I don't think we need to support atomic set-and-get for large range updates. (Honestly, we could probably get away with just offering this for point updates.)
jdoliner commentedon Jun 10, 2013
We should probably consider just doing point updates. I suppose we should wait on discussing further but I think it's important for those thinking about this issue to know about the constraints of the API when considering it. So I wanted to make sure this was noted before discussion began.
neumino commentedon Jun 10, 2013
I don't really know how hard it is to do an atomic get/set for a range of documents, but I also tend to think that offering this feature for point updates is enough.
The main use case is when an user update its own settings. I can't really think of a frequent use case where someone would have to do a range update and retrieve all the updated results.
Also, if I'm not mistaken, mongo's findAndModify doesn't exists for range updates.
mlucy commentedon Jun 10, 2013
Also, if people want to do this for range updates they could always force it by doing:
mlucy commentedon Jun 10, 2013
But anyway, I agree with @jdoliner, let's put off discussing this further until the 3-day period at the start of 1.7.
jdoliner commentedon Jun 10, 2013
Yeah, I sort of like that idea. I'm a bit uneasy about having something work with ranges but blow up if the ranges are too big.
wmrowan commentedon Jun 11, 2013
So I'm about to get radical on y'all since this is the time for such ideas.
What if we rethink(tm) this whole write reporting business and return the updated value by default? The current write summarizing behavior could then be provided by a new
summarizeorreportcommand.Here's something like what I'm imagining:
table.get(key).update(...).run() => new_valtable.get(non_existant).update(...).run() => errortable.update(...).run(...) => stream_of_new_valstable.get(key).update(...).report() => {'updated': 1}table.get(non_existant).update(...).report() => {'error': 1}table.update(...).report() => {'updated': >1, 'errors': >1}table.get(key).do({'old': r.row, 'new': r.row.update(...)}) => ...table.map({'old': r.row, 'new': r.row.update(...)}) => ...The main issue with this idea is how we deal with lazy streams of updated values, especially when the user doesn't actually want to read the values. Maybe we only do it for point updates and replaces, as if range updates have
.report()tacked on by default.This is probably not the way forward but I would at least like to explore alternatives to the initial proposal. A weird optional argument plus an even weirder output object are just too much for me.
coffeemug commentedon Jun 11, 2013
I'm strongly opposed to returning the results by default because most of the time users don't actually care about getting back the values -- they already know what they are and are just setting them. The case where they want to get the values back (e.g. increment and read) is very important but is fairly rare.
mlucy commentedon Jun 12, 2013
An interesting proposal, but it looks like it may have some problems. Off the top of my head:
doandmapexamples don't actually work because we'll see the row that we read on the machine serving the query rather than the row that the update function is run on (these may be different if the user is doing something racy). We need a way to get the old row back from the shard after the update if we want to have atomic updates.mlucy commentedon Jun 12, 2013
Also, right now once you store a single row selection in a variable it turns into an object, to prevent the problem I mentioned above where you do a read and a write on it and expect them both to see the same thing.
jdoliner commentedon Jun 12, 2013
Streams of the values from range updates is just never going to work. You either need to store all of the values in memory or have incredibly strange lazy evaluation semantics for the write.
mlucy commentedon Jun 18, 2013
Alright, here's what I think we should do here:
return_valstoupdatethat defaults to false.return_valsis set totruefor a point update, we return a summary object that looks like:return_valsis set totruefor a range update, we error.coffeemug commentedon Jun 18, 2013
This wouldn't just be
updatebutreplaceas well, correct? (is there another command I'm missing?)mlucy commentedon Jun 18, 2013
I'll probably just do it for all the write ops because it's easy. It's useful for
insertif you're doing an upsert, and it's useful fordelete(maybe).mlucy commentedon Jun 18, 2013
(but, yes, we should certainly do it for
replace)srh commentedon Jun 18, 2013
We don't need to return new_val, do we? Most people just want old_val. Or they want just new_val. Maybe they should be separate options.
mlucy commentedon Jun 18, 2013
I thought about making the optarg take
:old,:new, or:all, but this seemed simpler. Assuming that they aren't drastically changing the size of the row, it's only a factor of 2 performance hit in the worst worst worst case, which didn't seem like a big enough deal to complicate the interface.jdoliner commentedon Jun 19, 2013
And if people are really worried about the performance they can always tack a
pluckon the end of it.mlucy commentedon Jun 21, 2013
Alright, this is settled with
old_valandnew_valboth being included. If people complain it will be easy to updatereturn_valsto take:oldand:newas well astrue.mlucy commentedon Jun 26, 2013
This is in review 670 by @jdoliner .
mlucy commentedon Jun 27, 2013
This is in next.