You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2018/10/16 10:35:24 UTC
[couchdb] 01/03: Mango fixes
This is an automated email from the ASF dual-hosted git repository.
garren pushed a commit to branch partition-review-fixes
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 5593e92b061c8f48eb62c1e92bf703801b887fff
Author: Garren Smith <ga...@gmail.com>
AuthorDate: Tue Oct 16 11:27:42 2018 +0200
Mango fixes
* fix issue with mango all_docs query
* Improve partition validation check
---
src/fabric/src/fabric_view_all_docs.erl | 24 +++++++++++++++---------
src/mango/src/mango_idx.erl | 13 +++++--------
2 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl
index e8868c5..635f2d8 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -138,8 +138,14 @@ go(DbName, _Options, Workers, QueryArgs, Callback, Acc0) ->
end.
shards(DbName, Args) ->
- case couch_mrview_util:get_extra(Args, partitioned) of
- true ->
+ case {couch_mrview_util:get_extra(Args, partitioned, false),
+ couch_mrview_util:get_extra(Args, partition, undefined)} of
+ {false, _} ->
+ mem3:shards(DbName);
+ {true, undefined} ->
+ % This is an added in optimisation. If a user specifies a specific
+ % partition in the startkey and endkey then it is possible to just choose the shards
+ % with that partition in it.
StartKey = partition(Args#mrargs.start_key),
EndKey = partition(Args#mrargs.end_key),
case {StartKey, EndKey} of
@@ -148,16 +154,16 @@ shards(DbName, Args) ->
{_, _} ->
mem3:shards(DbName)
end;
- _ ->
- mem3:shards(DbName)
+ {true, Partition} ->
+ mem3:shards(DbName, <<Partition/binary, ":foo">>)
end.
-partition(undefined) ->
- undefined;
-partition(null) ->
- null;
+
partition(Key) when is_binary(Key) ->
- hd(binary:split(Key, <<":">>)).
+ hd(binary:split(Key, <<":">>));
+partition(_) ->
+ undefined.
+
handle_message({rexi_DOWN, _, {_, NodeRef}, _}, _, State) ->
fabric_view:check_down_shards(State, NodeRef);
diff --git a/src/mango/src/mango_idx.erl b/src/mango/src/mango_idx.erl
index 261e8f0..8c25f4a 100644
--- a/src/mango/src/mango_idx.erl
+++ b/src/mango/src/mango_idx.erl
@@ -79,12 +79,9 @@ get_usable_indexes(Db, Selector, Opts) ->
filter_indexes_by_partitioned(false, Indexes, _PQ) ->
Indexes;
-filter_indexes_by_partitioned(DbPartitioned, Indexes, PQ) ->
+filter_indexes_by_partitioned(true, Indexes, PQ) ->
FilterFun = fun (Idx)->
- PartitionedIdx = case lists:keyfind(partitioned, 1, Idx#idx.design_opts) of
- {partitioned, PI} -> PI;
- false -> DbPartitioned
- end,
+ PartitionedIdx = couch_util:get_value(partitioned, Idx#idx.design_opts, true),
filter_index_by_partitioned(Idx#idx.def, PartitionedIdx, PQ)
end,
lists:filter(FilterFun, Indexes).
@@ -148,9 +145,9 @@ validate_new(Idx, Db) ->
validate_design_opts(Props) ->
- case lists:keyfind(<<"options">>, 1, Props) of
- {<<"options">>, {[{<<"partitioned">>, P}]}}
- when is_boolean(P) ->
+ {Options} = couch_util:get_value(<<"options">>, Props, []),
+ case couch_util:get_value(<<"partitioned">>, Options) of
+ P when is_boolean(P) ->
[{partitioned, P}];
_ ->
[]