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 2014/08/01 16:29:47 UTC

[07/23] fabric commit: updated refs/heads/windsor-merge to 4ec3f11

Refactor payload to simplify coordinator

Two things we're doing here:

1) We're unwrapping {doc, {error, Reason}} on the RPC side.
2) We're already suppressing the doc field on the RPC side so we don't
have to duplicate the work on the coordinator.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/e0d34fb6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/e0d34fb6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/e0d34fb6

Branch: refs/heads/windsor-merge
Commit: e0d34fb6dfab296a675d85656eef37fe52f8c615
Parents: 6d254d5
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Thu Oct 17 14:03:47 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Fri Aug 1 14:52:36 2014 +0100

----------------------------------------------------------------------
 src/fabric_rpc.erl          | 34 +++++++++-------------------------
 src/fabric_view_changes.erl | 26 ++++++++------------------
 2 files changed, 17 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/e0d34fb6/src/fabric_rpc.erl
----------------------------------------------------------------------
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index c312aa7..cbc913e 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -306,43 +306,27 @@ changes_enumerator(DocInfo, {Db, _Seq, Args, Options}) ->
         filter = Acc
     } = Args,
     Conflicts = proplists:get_value(conflicts, Options, false),
-    #doc_info{high_seq=Seq, revs=[#rev_info{deleted=Del}|_]} = DocInfo,
+    #doc_info{id=Id, high_seq=Seq, revs=[#rev_info{deleted=Del}|_]} = DocInfo,
     case [X || X <- couch_changes:filter(Db, DocInfo, Acc), X /= null] of
     [] ->
         {ok, {Db, Seq, Args, Options}};
     Results ->
         Opts = if Conflicts -> [conflicts]; true -> [] end,
-        ChangesRow = changes_row(Db, DocInfo, Results, Del, IncludeDocs, Opts),
+        ChangesRow = {change, [
+            {seq, {Seq, uuid(Db)}},
+            {id, Id},
+            {changes, Results},
+            {deleted, Del} |
+            if IncludeDocs -> [doc_member(Db, DocInfo, Opts)]; true -> [] end
+        ]},
         Go = rexi:sync_reply(ChangesRow),
         {Go, {Db, Seq, Args, Options}}
     end.
 
-changes_row(Db, #doc_info{id=Id, high_seq=Seq}=DI, Results, Del, true, Opts) ->
-    {change, [
-        {seq, {Seq, uuid(Db)}},
-        {id, Id},
-        {changes, Results},
-        {deleted, Del},
-        {doc, doc_member(Db, DI, Opts)}
-    ]};
-changes_row(Db, #doc_info{id=Id, high_seq=Seq}, Results, true, _, _) ->
-    {change, [
-        {seq, {Seq, uuid(Db)}},
-        {id, Id},
-        {changes, Results},
-        {deleted, true}
-    ]};
-changes_row(Db, #doc_info{id=Id, high_seq=Seq}, Results, _, _, _) ->
-    {change, [
-        {seq, {Seq, uuid(Db)}},
-        {id, Id},
-        {changes, Results}
-    ]}.
-
 doc_member(Shard, DocInfo, Opts) ->
     case couch_db:open_doc(Shard, DocInfo, [deleted | Opts]) of
     {ok, Doc} ->
-        couch_doc:to_json_obj(Doc, []);
+        {doc, couch_doc:to_json_obj(Doc, [])};
     Error ->
         Error
     end.

http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/e0d34fb6/src/fabric_view_changes.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view_changes.erl b/src/fabric_view_changes.erl
index 8e35e64..672ec2d 100644
--- a/src/fabric_view_changes.erl
+++ b/src/fabric_view_changes.erl
@@ -224,7 +224,6 @@ handle_message(#change{} = Row, {Worker, From}, St) ->
 
 handle_message({change, Props}, {Worker, From}, St) ->
     #collector{
-        query_args = #changes_args{include_docs=IncludeDocs},
         callback = Callback,
         counters = S0,
         limit = Limit,
@@ -239,7 +238,7 @@ handle_message({change, Props}, {Worker, From}, St) ->
     true ->
         Props2 = lists:keyreplace(seq, 1, Props, {seq, null})
     end,
-    {Go, Acc} = Callback(changes_row(Props2, IncludeDocs), AccIn),
+    {Go, Acc} = Callback(changes_row(Props2), AccIn),
     rexi:stream_ack(From),
     {Go, St#collector{counters=S1, limit=Limit-1, user_acc=Acc}};
 
@@ -390,25 +389,16 @@ do_unpack_seqs(Opaque, DbName) ->
             Unpacked ++ [{R, 0} || R <- Replacements]
     end.
 
-changes_row(Props0, IncludeDocs) ->
-    Props1 = case {IncludeDocs, couch_util:get_value(doc, Props0)} of
-        {true, {error, Reason}} ->
-            % Transform {doc, {error, Reason}} to {error, Reason} for JSON
-            lists:keyreplace(doc, 1, Props0, {error, Reason});
-        {false, _} ->
-            lists:keydelete(doc, 1, Props0);
-        _ ->
-            Props0
-    end,
-    Props2 = case couch_util:get_value(deleted, Props1) of
+changes_row(Props0) ->
+    Props1 = case couch_util:get_value(deleted, Props0) of
         true ->
-            Props1;
+            Props0;
         _ ->
-            lists:keydelete(deleted, 1, Props1)
+            lists:keydelete(deleted, 1, Props0)
     end,
-    Allowed = [seq, id, changes, deleted, doc],
-    Props3 = lists:filter(fun({K,_V}) -> lists:member(K, Allowed) end, Props2),
-    {change, {Props3}}.
+    Allowed = [seq, id, changes, deleted, doc, error],
+    Props2 = lists:filter(fun({K,_V}) -> lists:member(K, Allowed) end, Props1),
+    {change, {Props2}}.
 
 find_replacement_shards(#shard{range=Range}, AllShards) ->
     % TODO make this moar betta -- we might have split or merged the partition