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 2015/04/04 12:05:06 UTC
fabric commit: updated refs/heads/2655-r-met2 to e31a50c
Repository: couchdb-fabric
Updated Branches:
refs/heads/2655-r-met2 [created] e31a50cbc
Indicate consistency of read
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/e31a50cb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/e31a50cb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/e31a50cb
Branch: refs/heads/2655-r-met2
Commit: e31a50cbc408a62872c1f17276cf8fb92f04a689
Parents: 985f136
Author: Robert Newson <rn...@apache.org>
Authored: Sat Apr 4 11:04:45 2015 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Sat Apr 4 11:04:45 2015 +0100
----------------------------------------------------------------------
src/fabric_doc_open.erl | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/e31a50cb/src/fabric_doc_open.erl
----------------------------------------------------------------------
diff --git a/src/fabric_doc_open.erl b/src/fabric_doc_open.erl
index c7d90a4..0a235ac 100644
--- a/src/fabric_doc_open.erl
+++ b/src/fabric_doc_open.erl
@@ -45,8 +45,8 @@ go(DbName, Id, Options) ->
RexiMon = fabric_util:create_monitors(Workers),
try fabric_util:recv(Workers, #shard.ref, fun handle_message/3, Acc0) of
{ok, #acc{}=Acc} ->
- Reply = handle_response(Acc),
- format_reply(Reply, SuppressDeletedDoc);
+ {Reply, Consistency} = handle_response(Acc),
+ format_reply(Reply, SuppressDeletedDoc, Consistency, Options);
{timeout, #acc{workers=DefunctWorkers}} ->
fabric_util:log_timeout(DefunctWorkers, "open_doc"),
{error, timeout};
@@ -90,18 +90,18 @@ handle_response(#acc{state=r_met, replies=Replies, q_reply=QuorumReply}=Acc) ->
case {Replies, fabric_util:remove_ancestors(Replies, [])} of
{[_], [_]} ->
% Complete agreement amongst all copies
- QuorumReply;
+ {QuorumReply, consistent};
{[_|_], [{_, {QuorumReply, _}}]} ->
% Any divergent replies are ancestors of the QuorumReply,
% repair the document asynchronously
spawn(fun() -> read_repair(Acc) end),
- QuorumReply;
+ {QuorumReply, divergent};
_Else ->
% real disagreement amongst the workers, block for the repair
- read_repair(Acc)
+ {read_repair(Acc), disagreement}
end;
handle_response(Acc) ->
- read_repair(Acc).
+ {read_repair(Acc), disagreement}.
is_r_met(Workers, Replies, R) ->
case lists:dropwhile(fun({_,{_, Count}}) -> Count < R end, Replies) of
@@ -156,9 +156,15 @@ choose_reply(Docs) ->
end, Docs),
{ok, Winner}.
-format_reply({ok, #doc{deleted=true}}, true) ->
+format_reply({ok, #doc{deleted=true}}, true, _, _) ->
{not_found, deleted};
-format_reply(Else, _) ->
+format_reply({ok, #doc{}=Doc}, _, Consistency, Options) ->
+ Meta = case lists:member(is_r_met, Options) of
+ true -> [{r_met, Consistency} | Doc#doc.meta];
+ false -> Doc#doc.meta
+ end,
+ {ok, Doc#doc{meta=Meta}};
+format_reply(Else, _, _, _) ->
Else.