couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [36/49] fabric commit: updated refs/heads/windsor-merge to b1c0030
Date Fri, 01 Aug 2014 14:34:57 GMT
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/161f0889
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/161f0889
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/161f0889

Branch: refs/heads/windsor-merge
Commit: 161f0889b003a8c72912797491ad3d6cf983519f
Parents: 5e65ee0
Author: Adam Kocoloski <adam@cloudant.com>
Authored: Thu Oct 17 14:03:47 2013 -0400
Committer: Robert Newson <rnewson@apache.org>
Committed: Fri Aug 1 15:33:42 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/161f0889/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/161f0889/src/fabric_view_changes.erl
----------------------------------------------------------------------
diff --git a/src/fabric_view_changes.erl b/src/fabric_view_changes.erl
index ed6dfb2..36cb945 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


Mime
View raw message