summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-06-17 12:34:11 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-06-17 12:34:11 -0400
commitb7d46723fc704eb37555ac5dce96eab1724bdc2e (patch)
tree6daa7069db1512e40e6341fbe49c83af4d190343
parente6fe7126c88893dd39cec32481b05f7c38e97475 (diff)
updates to use 0.11-style missing_revs
-rw-r--r--src/fabric_doc_missing_revs.erl2
-rw-r--r--src/fabric_rpc.erl25
2 files changed, 23 insertions, 4 deletions
diff --git a/src/fabric_doc_missing_revs.erl b/src/fabric_doc_missing_revs.erl
index fe6deac6..8f1f5b4c 100644
--- a/src/fabric_doc_missing_revs.erl
+++ b/src/fabric_doc_missing_revs.erl
@@ -55,7 +55,7 @@ group_idrevs_by_shard(DbName, IdsRevs) ->
end, dict:new(), IdsRevs)).
update_dict(D0, KVs) ->
- lists:foldl(fun({K,V}, D1) -> dict:store(K, V, D1) end, D0, KVs).
+ lists:foldl(fun({K,V,_}, D1) -> dict:store(K, V, D1) end, D0, KVs).
skip_message({1, Dict}) ->
{stop, dict:fold(fun force_reply/3, [], Dict)};
diff --git a/src/fabric_rpc.erl b/src/fabric_rpc.erl
index e9d9eb20..4b6e4e62 100644
--- a/src/fabric_rpc.erl
+++ b/src/fabric_rpc.erl
@@ -162,10 +162,11 @@ get_missing_revs(DbName, IdRevsList) ->
Ids = [Id1 || {Id1, _Revs} <- IdRevsList],
{ok, lists:zipwith(fun({Id, Revs}, FullDocInfoResult) ->
case FullDocInfoResult of
- {ok, #full_doc_info{rev_tree=RevisionTree}} ->
- {Id, couch_key_tree:find_missing(RevisionTree, Revs)};
+ {ok, #full_doc_info{rev_tree=RevisionTree} = FullInfo} ->
+ MissingRevs = couch_key_tree:find_missing(RevisionTree, Revs),
+ {Id, MissingRevs, possible_ancestors(FullInfo, MissingRevs)};
not_found ->
- {Id, Revs}
+ {Id, Revs, []}
end
end, IdRevsList, couch_btree:lookup(Db#db.id_tree, Ids))};
Error ->
@@ -304,3 +305,21 @@ doc_member(Shard, Id, Rev) ->
Error ->
Error
end.
+
+possible_ancestors(_FullInfo, []) ->
+ [];
+possible_ancestors(FullInfo, MissingRevs) ->
+ #doc_info{revs=RevsInfo} = couch_doc:to_doc_info(FullInfo),
+ LeafRevs = [Rev || #rev_info{rev=Rev} <- RevsInfo],
+ % Find the revs that are possible parents of this rev
+ lists:foldl(fun({LeafPos, LeafRevId}, Acc) ->
+ % this leaf is a "possible ancenstor" of the missing
+ % revs if this LeafPos lessthan any of the missing revs
+ case lists:any(fun({MissingPos, _}) ->
+ LeafPos < MissingPos end, MissingRevs) of
+ true ->
+ [{LeafPos, LeafRevId} | Acc];
+ false ->
+ Acc
+ end
+ end, [], LeafRevs).