You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2020/02/13 14:58:00 UTC
[couchdb] 16/20: basic loading of conflicts for docs
This is an automated email from the ASF dual-hosted git repository.
garren pushed a commit to branch fdb-mango-indexes
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 3feb788a7b40c58e95dac4725e453f5545554976
Author: Garren Smith <ga...@gmail.com>
AuthorDate: Tue Feb 11 14:33:32 2020 +0200
basic loading of conflicts for docs
---
src/fabric/src/fabric2_db.erl | 1 +
src/fabric/src/fabric2_fdb.erl | 23 ++++++++++++++++++++++-
src/mango/test/19-find-conflicts.py | 2 +-
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index a6c7a97..d03c78e 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -71,6 +71,7 @@
open_doc/2,
open_doc/3,
open_doc_revs/4,
+ apply_open_doc_opts/3,
%% open_doc_int/3,
get_doc_info/2,
get_full_doc_info/2,
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 6d21ba1..7b7ddba 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -723,11 +723,32 @@ write_doc(#{} = Db0, Doc, NewWinner0, OldWinner, ToUpdate, ToRemove) ->
incr_stat(Db, <<"doc_del_count">>, 1),
mango_indexer:delete_doc(Db, PrevDoc);
updated ->
- mango_indexer:update_doc(Db, Doc, PrevDoc)
+ DocRev = extract_rev(Doc#doc.revs),
+ {WinnerRevPos, _} = WinnerRevId = maps:get(rev_id, NewWinner),
+ {WinnerDoc, OldWinnerDoc} = case WinnerRevId == DocRev of
+ true -> {Doc, PrevDoc};
+ false -> {PrevDoc, PrevDoc}
+ end,
+
+ RevConflicts = lists:foldl(fun (UpdateRev, Acc) ->
+ {RevPos, _} = maps:get(rev_id, UpdateRev),
+ case RevPos == WinnerRevPos of
+ true ->
+ Acc ++ [UpdateRev#{winner := false}];
+ false ->
+ Acc
+ end
+ end, [], ToUpdate),
+
+ {ok, WinnerDoc1} = fabric2_db:apply_open_doc_opts(WinnerDoc, RevConflicts, [conflicts]),
+ mango_indexer:update_doc(Db, WinnerDoc1, OldWinnerDoc)
end,
ok.
+extract_rev({RevPos, [Rev | _]}) ->
+ {RevPos, Rev}.
+
write_local_doc(#{} = Db0, Doc) ->
#{
diff --git a/src/mango/test/19-find-conflicts.py b/src/mango/test/19-find-conflicts.py
index 45a1e31..bf865d6 100644
--- a/src/mango/test/19-find-conflicts.py
+++ b/src/mango/test/19-find-conflicts.py
@@ -25,7 +25,7 @@ class ChooseCorrectIndexForDocs(mango.DbPerClass):
self.db.save_docs_with_conflicts(copy.deepcopy(CONFLICT))
def test_retrieve_conflicts(self):
- self.db.create_index(["_conflicts"], wait_for_built_index=False)
+ self.db.create_index(["_conflicts"])
result = self.db.find({"_conflicts": {"$exists": True}}, conflicts=True)
self.assertEqual(
result[0]["_conflicts"][0], "1-23202479633c2b380f79507a776743d5"