You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2018/08/20 11:54:37 UTC
[couchdb] 02/02: explicit term shape for partitioned rows
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 807c9227d5c41db888bd8e9a097387562745b444
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Aug 14 18:58:30 2018 +0100
explicit term shape for partitioned rows
---
src/couch/src/couch_btree.erl | 14 ++++++++++++++
src/couch/src/couch_ejson_compare.erl | 4 ++++
src/couch_mrview/src/couch_mrview.erl | 2 ++
src/couch_mrview/src/couch_mrview_updater.erl | 2 +-
src/couch_mrview/src/couch_mrview_util.erl | 14 +++++++-------
src/fabric/src/fabric_view.erl | 4 +---
6 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/src/couch/src/couch_btree.erl b/src/couch/src/couch_btree.erl
index ea224b1..d11d7e6 100644
--- a/src/couch/src/couch_btree.erl
+++ b/src/couch/src/couch_btree.erl
@@ -133,6 +133,20 @@ make_group_fun(Bt, exact) ->
end;
make_group_fun(Bt, GroupLevel) when is_integer(GroupLevel), GroupLevel > 0 ->
fun
+ ({{p, _Partition, Key1}, _}, {{p, _Partition, Key2}, _}) ->
+ SL1 = lists:sublist(Key1, GroupLevel),
+ SL2 = lists:sublist(Key2, GroupLevel),
+ case less(Bt, {SL1, nil}, {SL2, nil}) of
+ false ->
+ case less(Bt, {SL2, nil}, {SL1, nil}) of
+ false ->
+ true;
+ _ ->
+ false
+ end;
+ _ ->
+ false
+ end;
({[_|_] = Key1, _}, {[_|_] = Key2, _}) ->
SL1 = lists:sublist(Key1, GroupLevel),
SL2 = lists:sublist(Key2, GroupLevel),
diff --git a/src/couch/src/couch_ejson_compare.erl b/src/couch/src/couch_ejson_compare.erl
index 81adbb8..ca36c86 100644
--- a/src/couch/src/couch_ejson_compare.erl
+++ b/src/couch/src/couch_ejson_compare.erl
@@ -22,6 +22,10 @@ init() ->
Dir = code:priv_dir(couch),
ok = erlang:load_nif(filename:join(Dir, ?MODULE), NumScheds).
+% partitioned row comparison
+less({p, PA, A}, {p, PB, B}) ->
+ less([PA, A], [PB, B]);
+
less(A, B) ->
try
less_nif(A, B)
diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index e1db906..f5963e7 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -615,6 +615,8 @@ red_fold(Db, {NthRed, _Lang, View}=RedView, Args, Callback, UAcc) ->
end, Acc, OptList),
finish_fold(Acc2, []).
+red_fold({p, _Partition, Key}, Red, Acc) ->
+ red_fold(Key, Red, Acc);
red_fold(_Key, _Red, #mracc{skip=N}=Acc) when N > 0 ->
{ok, Acc#mracc{skip=N-1, last_go=ok}};
red_fold(Key, Red, #mracc{meta_sent=false}=Acc) ->
diff --git a/src/couch_mrview/src/couch_mrview_updater.erl b/src/couch_mrview/src/couch_mrview_updater.erl
index a922eb5..0c1a17c 100644
--- a/src/couch_mrview/src/couch_mrview_updater.erl
+++ b/src/couch_mrview/src/couch_mrview_updater.erl
@@ -384,7 +384,7 @@ write_kvs(State, UpdateSeq, ViewKVs, DocIdKeys, Seqs, Log0) ->
}.
inject_partition(KVs) ->
- [{{[partition(DocId), Key], DocId}, Value} || {{Key, DocId}, Value} <- KVs].
+ [{{{p, partition(DocId), Key}, DocId}, Value} || {{Key, DocId}, Value} <- KVs].
partition(DocId) ->
[Partition, _Rest] = binary:split(DocId, <<":">>),
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index 8b66755..acfb282 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -649,25 +649,25 @@ apply_partition(#mrargs{} = Args0, Style) ->
end;
apply_partition(Partition, #mrargs{direction=fwd, start_key=undefined, end_key=undefined} = Args) ->
- Args#mrargs{start_key=[Partition, ?LOWEST_KEY], end_key=[Partition, ?HIGHEST_KEY]};
+ Args#mrargs{start_key={p, Partition, ?LOWEST_KEY}, end_key={p, Partition, ?HIGHEST_KEY}};
apply_partition(Partition, #mrargs{direction=rev, start_key=undefined, end_key=undefined} = Args) ->
- Args#mrargs{start_key=[Partition, ?HIGHEST_KEY], end_key=[Partition, ?LOWEST_KEY]};
+ Args#mrargs{start_key={p, Partition, ?HIGHEST_KEY}, end_key={p, Partition, ?LOWEST_KEY}};
apply_partition(Partition, #mrargs{direction=fwd, start_key=SK0, end_key=undefined} = Args) ->
- Args#mrargs{start_key=[Partition, SK0], end_key=[Partition, ?HIGHEST_KEY]};
+ Args#mrargs{start_key={p, Partition, SK0}, end_key={p, Partition, ?HIGHEST_KEY}};
apply_partition(Partition, #mrargs{direction=rev, start_key=SK0, end_key=undefined} = Args) ->
- Args#mrargs{start_key=[Partition, SK0], end_key=[Partition, ?LOWEST_KEY]};
+ Args#mrargs{start_key={p, Partition, SK0}, end_key={p, Partition, ?LOWEST_KEY}};
apply_partition(Partition, #mrargs{direction=fwd, start_key=undefined, end_key=EK0} = Args) ->
- Args#mrargs{start_key=[Partition, ?LOWEST_KEY], end_key=[Partition, EK0]};
+ Args#mrargs{start_key={p, Partition, ?LOWEST_KEY}, end_key={p, Partition, EK0}};
apply_partition(Partition, #mrargs{direction=rev, start_key=undefined, end_key=EK0} = Args) ->
- Args#mrargs{start_key=[Partition, ?HIGHEST_KEY], end_key=[Partition, EK0]};
+ Args#mrargs{start_key={p, Partition, ?HIGHEST_KEY}, end_key={p, Partition, EK0}};
apply_partition(Partition, #mrargs{start_key=SK0, end_key=EK0} = Args) ->
- Args#mrargs{start_key=[Partition, SK0], end_key=[Partition, EK0]}.
+ Args#mrargs{start_key={p, Partition, SK0}, end_key={p, Partition, EK0}}.
%% all_docs is special as it's not really a view and is already
diff --git a/src/fabric/src/fabric_view.erl b/src/fabric/src/fabric_view.erl
index 9224132..1b01e83 100644
--- a/src/fabric/src/fabric_view.erl
+++ b/src/fabric/src/fabric_view.erl
@@ -202,10 +202,8 @@ possibly_embed_doc(#collector{db_name=DbName, query_args=Args},
_ -> Row
end.
-detach_partition(#view_row{key=[_Partition, Key]} = Row) ->
+detach_partition(#view_row{key={p, _Partition, Key}} = Row) ->
Row#view_row{key = Key};
-detach_partition(#view_row{key=null} = Row) ->
- Row#view_row{key = null};
detach_partition(#view_row{} = Row) ->
Row.