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/07/10 10:50:49 UTC
[couchdb] 02/02: unpartition key in view responses
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch user-partitioned-dbs-wip
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 03f2cc3382f1f819b2a615c9123cb126ee618713
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Jul 10 11:50:37 2018 +0100
unpartition key in view responses
---
src/fabric/include/fabric.hrl | 3 ++-
src/fabric/src/fabric_view.erl | 12 ++++++++++--
src/fabric/src/fabric_view_map.erl | 3 ++-
src/fabric/src/fabric_view_reduce.erl | 3 ++-
4 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/fabric/include/fabric.hrl b/src/fabric/include/fabric.hrl
index be1d639..8ceab22 100644
--- a/src/fabric/include/fabric.hrl
+++ b/src/fabric/include/fabric.hrl
@@ -31,7 +31,8 @@
lang,
sorted,
user_acc,
- update_seq
+ update_seq,
+ partitioned=false
}).
-record(stream_acc, {
diff --git a/src/fabric/src/fabric_view.erl b/src/fabric/src/fabric_view.erl
index 69f4290..bf4d64e 100644
--- a/src/fabric/src/fabric_view.erl
+++ b/src/fabric/src/fabric_view.erl
@@ -128,8 +128,11 @@ maybe_send_row(State) ->
try get_next_row(State) of
{_, NewState} when Skip > 0 ->
maybe_send_row(NewState#collector{skip=Skip-1});
- {Row, NewState} ->
- case Callback(transform_row(possibly_embed_doc(NewState,Row)), AccIn) of
+ {Row0, NewState} ->
+ Row1 = possibly_embed_doc(NewState, Row0),
+ Row2 = unpartition_row(NewState, Row1),
+ Row3 = transform_row(Row2),
+ case Callback(Row3, AccIn) of
{stop, Acc} ->
{stop, NewState#collector{user_acc=Acc, limit=Limit-1}};
{ok, Acc} ->
@@ -272,6 +275,11 @@ transform_row(#view_row{key=Key, id=_Id, value=_Value, doc={error,Reason}}) ->
transform_row(#view_row{key=Key, id=Id, value=Value, doc=Doc}) ->
{row, [{id,Id}, {key,Key}, {value,Value}, {doc,Doc}]}.
+unpartition_row(#collector{partitioned=true}, #view_row{key=[_Partition, Key]} = Row) ->
+ Row#view_row{key = Key};
+unpartition_row(#collector{partitioned=false}, Row) ->
+ Row.
+
compare(_, _, A, A) -> true;
compare(fwd, <<"raw">>, A, B) -> A < B;
compare(rev, <<"raw">>, A, B) -> B < A;
diff --git a/src/fabric/src/fabric_view_map.erl b/src/fabric/src/fabric_view_map.erl
index b6a3d6f..75b71f1 100644
--- a/src/fabric/src/fabric_view_map.erl
+++ b/src/fabric/src/fabric_view_map.erl
@@ -76,7 +76,8 @@ go(DbName, Workers, {map, View, _}, Args, Callback, Acc0) ->
sorted = Args#mrargs.sorted,
collation = Collation,
user_acc = Acc0,
- update_seq = case UpdateSeq of true -> []; false -> nil end
+ update_seq = case UpdateSeq of true -> []; false -> nil end,
+ partitioned = Args#mrargs.partitioned
},
case rexi_utils:recv(Workers, #shard.ref, fun handle_message/3,
State, infinity, 1000 * 60 * 60) of
diff --git a/src/fabric/src/fabric_view_reduce.erl b/src/fabric/src/fabric_view_reduce.erl
index a74be10..c58d3aa 100644
--- a/src/fabric/src/fabric_view_reduce.erl
+++ b/src/fabric/src/fabric_view_reduce.erl
@@ -82,7 +82,8 @@ go2(DbName, Workers, {red, {_, Lang, View}, _}=VInfo, Args, Callback, Acc0) ->
collation = couch_util:get_value(<<"collation">>, View#mrview.options),
rows = dict:new(),
user_acc = Acc0,
- update_seq = case UpdateSeq of true -> []; false -> nil end
+ update_seq = case UpdateSeq of true -> []; false -> nil end,
+ partitioned = Args#mrargs.partitioned
},
try rexi_utils:recv(Workers, #shard.ref, fun handle_message/3,
State, infinity, 1000 * 60 * 60) of