This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch user-partitioned-dbs-6 in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 6f38cb763cb393823023da41e9b42ed7cef527af Author: Robert Newson <[email protected]> AuthorDate: Mon Aug 13 22:34:59 2018 +0100 optimize _all_docs requests that are bounded within a single partition --- src/fabric/src/fabric_view_all_docs.erl | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl index d515ab8..83c3790 100644 --- a/src/fabric/src/fabric_view_all_docs.erl +++ b/src/fabric/src/fabric_view_all_docs.erl @@ -21,7 +21,7 @@ -include_lib("couch_mrview/include/couch_mrview.hrl"). go(DbName, Options, #mrargs{keys=undefined} = QueryArgs, Callback, Acc) -> - Shards = mem3:shards(DbName), + Shards = shards(DbName, QueryArgs), Workers0 = fabric_util:submit_jobs( Shards, fabric_rpc, all_docs, [Options, QueryArgs]), RexiMon = fabric_util:create_monitors(Workers0), @@ -136,6 +136,28 @@ go(DbName, _Options, Workers, QueryArgs, Callback, Acc0) -> {ok, Resp} end. +shards(DbName, Args) -> + case couch_mrview_util:get_extra(Args, partitioned) of + true -> + StartKey = partition(Args#mrargs.start_key), + EndKey = partition(Args#mrargs.end_key), + case {StartKey, EndKey} of + {Same, Same} when Same =/= undefined -> + mem3:shards(DbName, <<Same/binary, ":foo">>); + {_, _} -> + mem3:shards(DbName) + end; + _ -> + mem3:shards(DbName) + end. + +partition(undefined) -> + undefined; +partition(null) -> + null; +partition(Key) when is_binary(Key) -> + hd(binary:split(Key, <<":">>)). + handle_message({rexi_DOWN, _, {_, NodeRef}, _}, _, State) -> fabric_view:check_down_shards(State, NodeRef);
