-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make view query limits configurable #1804
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly good but there's a few style issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the clause checking for infinity is the main thing. Up to you on whether you want to relax the equality check. Otherwise this all looks good.
|
||
% set the highest limit possible if a user has not | ||
% specified a limit | ||
Args1 = case Args#mrargs.limit =:= ?MAX_VIEW_LIMIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super minor nit but I'd probably use ==
instead of =:=
here. Only because I had to stop and think on whether we needed the stronger =:=
for any reason or not.
% set the highest limit possible if a user has not | ||
% specified a limit | ||
Args1 = case Args#mrargs.limit =:= ?MAX_VIEW_LIMIT | ||
andalso MaxLimit =/= infinity of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this clause checking infinity
anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this line from if Args1#mrargs.limit =:= MaxLimit -> Args1; true ->
to
if Args1#mrargs.limit =< MaxLimit -> Args1; true ->
90be3b0
to
6c2785a
Compare
005b442
to
60bbe3f
Compare
be1fe52
to
31a4a53
Compare
04146c3
to
51a482e
Compare
8cd68be
to
91af772
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks alright but we have to figure out why those tests are failing before this can be merged. Reading through I'm not seeing anything so my best guess is an unrelated test leaves the config in a bad state.
end, | ||
|
||
if Args1#mrargs.limit =< MaxLimit -> Args1; true -> | ||
Fmt = "Limit is too large, must not exceed ~p", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something is wrong here but I'm not immediately seeing why. The view_multi_key_design.js test has failed with this error message on each worker. Perhaps we left a bad config from an unrelated test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the issue. It was because of the fix_skip_and_limit
function https://github.com/apache/couchdb/blob/master/src/fabric/src/fabric_view.erl#L380
We made the max limit greater than the defined max limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the issue there but I'm not seeing what changed to account for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall except for the debug logging.
end, | ||
|
||
if Args1#mrargs.limit =< MaxLimit -> Args1; true -> | ||
Fmt = "Limit is too large, must not exceed ~p", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the issue there but I'm not seeing what changed to account for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two other minor changes to make.
%{:body => body} = resp | ||
|
||
Enum.each(body["all_nodes"], fn node -> | ||
resp = Couch.put("/_node/#{node}/_config/query_server_config/partition_query_limit", body: "\"2000\"") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reading again, and just noticed this. You should use set_config which takes care of removing the config change after the test finishes. There's an example here:
set_config({"couchdb", "max_partition_size", Integer.to_string(@max_size)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And samesies for partition_view_test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now that I've figured out how that interaction with fix_skip_and_limit works I realize that this is wrong. The current version appears to work but only because we're not testing with skip values that are large enough to cause a bad response.
The issue here is that we're calling validate_args on each RPC worker, however, due to clustering when a skip is set, each RPC worker has to return skip+limit rows which the coordinator then does the skip discard and then cuts off the response when limit rows. However, due to how this works we very often might be telling RPC workers to return more than the maximum allowed number of rows which gets flagged as an error.
The fix here is I think simple enough. We should just move the apply_limit code to fabric_util:validate_args which is only ever called from the coordinator layer so we don't have to worry about validating a system modified mrargs record.
Also, to force the bug, the skip would have to be set to That is of course an unlikely scenario and goes against the general recommendation to not use a large skip value but it'd still be an incorrect response if someone did get into that situation where maybe |
Turns out fabric_util was too far up. However we can just move it up one call so the RPC workers don't call it again and that fixes the issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 but be sure and squerge this down into a single commit before merging. I left it unsquerged so you can see the changes I made separate from the rest of the PR.
This allows us to set a maximun allowed number of documents to be returned for a global or a partitioned view query and _all_docs query. Co-authored-by: Paul J. Davis <paul.joseph.davis@gmail.com>
Overview
This allows us to set a maximun allowed number of documents
to be returned for a global or a partitioned query.
Testing recommendations
Set a view limit in the default.ini.
Related Issues or Pull Requests
Checklist