You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2018/03/26 20:55:31 UTC

[couchdb] branch COUCHDB-3326-clustered-purge-davisp-refactor updated (dd4546a -> 11eaffb)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    from dd4546a  WIP - chttpd_db HTTP endpoint
     new bcb0155  WIP couch_db.erl
     new 14a1ad3  WIP - couch_db_updater.erl
     new bf22bb1  WIP - chttpd_db.erl
     new cb0ef63  WIP - couch_db.erl
     new 4e8ab64  WIP - couch_bt_engine stuff
     new cd6452a  WIP - test suite upgrades
     new 5c4a041  WIP - couch_db_engine.erl
     new e5bb653  WIP - couch_db_updater.erl
     new 0486f0a  WIP - couch_httpd_db.erl
     new af2076b  WIP - read repair fabric_doc_open.erl
     new ca898e9  WIP - chttpd_db.erl
     new ce79373  WIP - chttpd_purge_tests.erl
     new fac4239  WIP - bt engine
     new 53b7b88  WIP - couch_db.erl
     new 49ebf8e  WIP - couch_db_engine.erl
     new b72bc0c  WIP - couch_db_updater.erl
     new 6b62e0e  WIP - read repair fabric_doc_open_revs
     new 922fce7  WIP - read repair - fabric_rpc.erl
     new e077e92  WIP - fabric API - fabric_rpc.erl
     new e590bdf  WIP - internal replication
     new 17fadec  WIP - test suite
     new 46be71e  WIP - fabric API
     new ca347ee  WIP - couch_mrview_purge_docs_tests.erl
     new 5b14d1b  WIP - add test suite
     new a5083e3  WIP - couch_index_updater.erl
     new abac0e0  WIP - update couch_mrview
     new 537130e  WIP - clustered API fabric
     new 8db8ebd  WIP - chttpd_db.erl
     new f6d6bb5  WIP - fabric clustered API
     new 412755b  WIP - test engine suite
     new 1120c05  WIP - add test engine suite
     new 8f795ed  WIP - test suite couch_db_purge_docs_tests.erl
     new 11eaffb  Update index/mrview

The 33 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/chttpd/src/chttpd_db.erl                       | 14 ++--
 src/chttpd/test/chttpd_purge_tests.erl             | 43 ++++++------
 src/couch/src/couch_bt_engine.erl                  | 31 ++++-----
 src/couch/src/couch_bt_engine_compactor.erl        | 17 +++--
 src/couch/src/couch_bt_engine_header.erl           |  2 +-
 src/couch/src/couch_db.erl                         | 76 ++++++++++++----------
 src/couch/src/couch_db_engine.erl                  |  8 +--
 src/couch/src/couch_db_updater.erl                 | 39 ++++++-----
 src/couch/src/couch_httpd_db.erl                   |  6 +-
 src/couch/src/test_engine_compaction.erl           | 28 +++-----
 ...d_docs.erl => test_engine_fold_purge_infos.erl} | 16 ++---
 src/couch/src/test_engine_get_set_props.erl        |  4 +-
 src/couch/src/test_engine_purge_docs.erl           | 20 +++---
 src/couch/src/test_engine_util.erl                 | 46 +++++--------
 src/couch/test/couch_db_purge_docs_tests.erl       | 16 ++---
 src/couch_index/src/couch_index_updater.erl        |  5 +-
 src/couch_mrview/src/couch_mrview_index.erl        | 30 +++------
 .../test/couch_mrview_purge_docs_tests.erl         |  8 +--
 src/fabric/rebar.config                            |  4 +-
 src/fabric/src/fabric.erl                          | 16 ++---
 src/fabric/src/fabric_db_meta.erl                  |  6 +-
 src/fabric/src/fabric_doc_open.erl                 | 24 +++----
 src/fabric/src/fabric_doc_open_revs.erl            |  6 +-
 src/fabric/src/fabric_doc_purge.erl                | 37 +++++------
 src/fabric/src/fabric_rpc.erl                      | 37 +++++------
 src/mem3/src/mem3_rep.erl                          | 35 ++++++----
 src/mem3/src/mem3_rpc.erl                          |  4 +-
 27 files changed, 281 insertions(+), 297 deletions(-)
 rename src/couch/src/{test_engine_fold_purged_docs.erl => test_engine_fold_purge_infos.erl} (90%)

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 33/33: Update index/mrview

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 11eaffb3caa67562167b083f5864e342d54e6fb5
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 15:34:27 2018 -0500

    Update index/mrview
---
 src/couch_index/src/couch_index_updater.erl             | 3 +--
 src/couch_mrview/test/couch_mrview_purge_docs_tests.erl | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/couch_index/src/couch_index_updater.erl b/src/couch_index/src/couch_index_updater.erl
index 14f2c08..4856c1d 100644
--- a/src/couch_index/src/couch_index_updater.erl
+++ b/src/couch_index/src/couch_index_updater.erl
@@ -216,8 +216,7 @@ purge_index(Db, Mod, IdxState) ->
             {ok, IdxState};
         true ->
             FoldFun = fun({PurgeSeq, _UUId, Id, Revs}, Acc) ->
-                {ok, StateAcc} = Mod:purge(Db, PurgeSeq, [{Id, Revs}], Acc),
-                StateAcc
+                Mod:purge(Db, PurgeSeq, [{Id, Revs}], Acc)
             end,
             {ok, NewStateAcc} = couch_db:fold_purge_infos(
                 Db,
diff --git a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
index b4af2c5..643789c 100644
--- a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
+++ b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
@@ -264,7 +264,7 @@ is_compaction_running(DbName) ->
     couch_util:get_value(compact_running, DbInfo).
 
 fold_fun({_PSeq, _UUID, Id, Revs}, Acc) ->
-    [{Id, Revs} | Acc].
+    {ok, [{Id, Revs} | Acc]}.
 
 docid(I) ->
     list_to_binary(integer_to_list(I)).

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 14/33: WIP - couch_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 53b7b88e117cb1b387772713848e864293b94f63
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:05:40 2018 -0500

    WIP - couch_db.erl
---
 src/couch/src/couch_db.erl | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 2a9e56d..cf7cd8f 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -399,32 +399,36 @@ get_purge_infos(Db, UUIDs) ->
 
 
 get_minimum_purge_seq(#db{} = Db) ->
-    PurgeSeq = couch_db:get_purge_seq(Db),
-    OldestPurgeSeq = couch_db:get_oldest_purge_seq(Db),
-    PurgeInfosLimit = couch_db:get_purge_infos_limit(Db),
+    PurgeSeq = couch_db_engine:get_purge_seq(Db),
+    OldestPurgeSeq = couch_db_engine:get_oldest_purge_seq(Db),
+    PurgeInfosLimit = couch_db_engine:get_purge_infos_limit(Db),
 
     FoldFun = fun(#doc{id = DocId, body = {Props}}, SeqAcc) ->
-        ClientSeq = couch_util:get_value(<<"purge_seq">>, Props),
-        case ClientSeq of
-            CS when is_integer(CS), CS >= PurgeSeq - PurgeInfosLimit ->
-                {ok, SeqAcc};
-            CS when is_integer(CS) ->
-                case purge_client_exists(Db, DocId, Props) of
-                    true -> {ok, erlang:min(CS, SeqAcc)};
-                    false -> {ok, SeqAcc}
+        case DocId of
+            <<"_local/purge-", _/binary>> ->
+                ClientSeq = couch_util:get_value(<<"purge_seq">>, Props),
+                case ClientSeq of
+                    CS when is_integer(CS), CS >= PurgeSeq - PurgeInfosLimit ->
+                        {ok, SeqAcc};
+                    CS when is_integer(CS) ->
+                        case purge_client_exists(Db, DocId, Props) of
+                            true -> {ok, erlang:min(CS, SeqAcc)};
+                            false -> {ok, SeqAcc}
+                        end;
+                    _ ->
+                        % If there's a broken doc we have to keep every
+                        % purge info until the doc is fixed or removed.
+                        Fmt = "Invalid purge doc '~s' with purge_seq '~w'",
+                        couch_log:error(Fmt, [DocId, ClientSeq]),
+                        {ok, erlang:min(OldestPurgeSeq, SeqAcc)}
                 end;
             _ ->
-                % If there's a broken doc we have to keep every
-                % purge info until the doc is fixed or removed.
-                Fmt = "Invalid purge doc '~s' with purge_seq '~w'",
-                couch_log:error(Fmt, [DocId, ClientSeq]),
-                {ok, erlang:min(OldestPurgeSeq, SeqAcc)}
+                {stop, SeqAcc}
         end
     end,
     InitMinSeq = PurgeSeq - PurgeInfosLimit,
     Opts = [
-        {start_key, list_to_binary(?LOCAL_DOC_PREFIX + "purge-")},
-        {end_key_gt, list_to_binary(?LOCAL_DOC_PREFIX + "purge.")}
+        {start_key, list_to_binary(?LOCAL_DOC_PREFIX ++ "purge-")}
     ],
     {ok, MinIdxSeq} = couch_db:fold_local_docs(Db, FoldFun, InitMinSeq, Opts),
     FinalSeq = case MinIdxSeq < PurgeSeq - PurgeInfosLimit of
@@ -433,7 +437,7 @@ get_minimum_purge_seq(#db{} = Db) ->
     end,
     % Log a warning if we've got a purge sequence exceeding the
     % configured threshold.
-    if FinalSeq < (PurgeSeq - PurgeInfosLimit) ->
+    if FinalSeq >= (PurgeSeq - PurgeInfosLimit) -> ok; true ->
         Fmt = "The purge sequence for '~s' exceeds configured threshold",
         couch_log:warning(Fmt, [couch_db:name(Db)])
     end,

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 18/33: WIP - read repair - fabric_rpc.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 922fce71f90ced2b7f9616cf26628bb541421597
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:07:04 2018 -0500

    WIP - read repair - fabric_rpc.erl
---
 src/fabric/src/fabric_rpc.erl | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index d1d33e9..d493da7 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -321,12 +321,12 @@ with_db(DbName, Options, {M,F,A}) ->
     end.
 
 
-read_repair_filter_docs(DbName, NodeIdRevs, Docs, Options) ->
+read_repair_filter(DbName, NodeIdRevs, Docs, Options) ->
     set_io_priority(DbName, Options),
     case get_or_create_db(DbName, Options) of
         {ok, Db} ->
             try
-                filter_purged_revs(Db, DocsByNode, Docs)
+                filter_purged_revs(Db, NodeIdRevs, Docs)
             after
                 couch_db:close(Db)
             end;
@@ -362,7 +362,7 @@ filter_purged_revs(Db, NodeIdRevs, Docs) ->
         case Id of
             <<?LOCAL_DOC_PREFIX, "/purge-mem3-", _/binary>> ->
                 TargetNodeBin = couch_util:get_value(<<"target_node">>, Props),
-                PurgeSeq = couch_util:get_value(<<"purge_seq">>, Props)
+                PurgeSeq = couch_util:get_value(<<"purge_seq">>, Props),
                 NewAcc = try
                     TargetNode = binary_to_existing_atom(TargetNodeBin, latin1),
                     case lists:member(TargetNode, Nodes) of
@@ -375,7 +375,8 @@ filter_purged_revs(Db, NodeIdRevs, Docs) ->
                     % A really old doc referring to a node that's
                     % no longer in the cluster
                     {ok, Acc}
-                end
+                end,
+                {ok, NewAcc};
             _ ->
                 % We've processed all _local mem3 purge docs
                 {stop, Acc}
@@ -386,8 +387,7 @@ filter_purged_revs(Db, NodeIdRevs, Docs) ->
     {ok, DbPSeq} = couch_db:get_purge_seq(Db),
     Lag = config:get_integer("couchdb", "read_repair_lag", 100),
 
-    {TotesGood, NeedChecking} =
-            lists:foldl(fun({Node, IdRevs}, {GoodToGo, MaybeGood}) ->
+    CheckSeqFun = fun({Node, IdRevs}, {GoodToGo, MaybeGood}) ->
         NodeSeq = case lists:keyfind(Node, 1, NodeSeqs) of
             {Node, PS} -> PS;
             false -> 0
@@ -398,27 +398,32 @@ filter_purged_revs(Db, NodeIdRevs, Docs) ->
                 NewGTG = [{DocId, Rev} || Rev <- Revs] ++ GoodToGo,
                 {NewGTG, MaybeGood};
             _ when NodeSeq >= DbPSeq - Lag ->
-                {GoodToGo, [{NodeSeq, IdRevs} | MaybGood]};
+                {GoodToGo, [{NodeSeq, IdRevs} | MaybeGood]};
             _ ->
                 % The remote node `Node` is so far out of date
                 % we'll just ignore its read-repair updates rather
                 % than scan an unbounded number of purge infos
                 {GoodToGo, MaybeGood}
         end
-    end, {[], []}, NodeIdRevs),
+    end,
+    {TotesGood, NeedChecking} = lists:foldl(CheckSeqFun, {[], []}, NodeIdRevs),
 
     % For any node that's not up to date with internal
     % replication we have to check if any of the revisions
     % have been purged before running our updates
     RestGood = if NeedChecking == [] -> []; true ->
-        StartSeq = lists:min([S || {S, _, _} <- ExpandedChecks]),
         CheckFoldFun = fun({PSeq, _UUID, DocId, Revs}, Acc) ->
             FilterFun = fun({NS, FiltDocId, FiltRev}) ->
+                % The `NS =< PSeq` portion of this translates to the
+                % fact that we haven't yet replicated PSeq to the
+                % target node, hence we would need to filter this read
+                % repair update or risk undoing a purge operation.
                 NS =< PSeq andalso FiltDocId == DocId
                         andalso lists:member(FiltRev, Revs)
             end,
             {ok, lists:filter(FilterFun, Acc)}
         end,
+        StartSeq = lists:min([S || {S, _} <- NeedChecking]),
         InitAcc = lists:flatmap(fun({NodeSeq, {DocId, Revs}}) ->
             [{NodeSeq, DocId, Rev} || Rev <- Revs]
         end, NeedChecking),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 07/33: WIP - couch_db_engine.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5c4a041e0ce736a417a1fa54ef26eb7960fcd7b3
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 10:26:02 2018 -0500

    WIP - couch_db_engine.erl
---
 src/couch/src/couch_db_engine.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index b19514b..8199118 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -673,7 +673,7 @@
 
     set_revs_limit/2,
     set_security/2,
-    set_purge_docs_limit/2,
+    set_purge_infos_limit/2,
 
     open_docs/2,
     open_local_docs/2,

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 32/33: WIP - test suite couch_db_purge_docs_tests.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8f795ed184c00c397565f3c75230d1c7f759737a
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 15:34:12 2018 -0500

    WIP - test suite couch_db_purge_docs_tests.erl
---
 src/couch/test/couch_db_purge_docs_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/test/couch_db_purge_docs_tests.erl b/src/couch/test/couch_db_purge_docs_tests.erl
index 070fb24..7d93662 100644
--- a/src/couch/test/couch_db_purge_docs_tests.erl
+++ b/src/couch/test/couch_db_purge_docs_tests.erl
@@ -357,4 +357,4 @@ save_doc(Db, Json) ->
     couch_db:update_doc(Db, Doc, []).
 
 fold_fun({_PSeq, _UUID, Id, Revs}, Acc) ->
-    [{Id, Revs} | Acc].
\ No newline at end of file
+    {ok, [{Id, Revs} | Acc]}.
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 01/33: WIP couch_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bcb01553d7250498e937db225b641b1d760c3e19
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 09:11:40 2018 -0500

    WIP couch_db.erl
---
 src/couch/src/couch_db.erl | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 2a2095c..b0b5d9f 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -374,16 +374,19 @@ get_full_doc_info(Db, Id) ->
 get_full_doc_infos(Db, Ids) ->
     couch_db_engine:open_docs(Db, Ids).
 
+purge_docs(Db, IdRevs) ->
+    purge_docs(Db, IdRevs, []).
 
--spec purge_docs(#db{}, [{UUId, Id, [Rev]}]) ->
+-spec purge_docs(#db{}, [{UUId, Id, [Rev]}], [PurgeOption]) ->
     {ok, [Reply]} when
     UUId :: binary(),
     Id :: binary(),
     Rev :: {non_neg_integer(), binary()},
+    PurgeOption :: interactive_edit | replicated_changes,
     Reply :: {ok, []} | {ok, [Rev]}.
-purge_docs(#db{main_pid = Pid}, UUIdsIdsRevs) ->
+purge_docs(#db{main_pid = Pid}, UUIdsIdsRevs, Options) ->
     increment_stat(Db, [couchdb, database_purges]),
-    gen_server:call(Pid, {purge_docs, UUIdsIdsRevs});
+    gen_server:call(Pid, {purge_docs, UUIdsIdsRevs, Options});
 
 -spec get_purge_infos(#db{}, [UUId]) -> [PurgeInfo] when
     UUId :: binary(),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 05/33: WIP - couch_bt_engine stuff

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 4e8ab6420f0f8db818fab809fdfecebb1af78259
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 10:25:34 2018 -0500

    WIP - couch_bt_engine stuff
---
 src/couch/src/couch_bt_engine.erl           | 29 +++++++++++++++--------------
 src/couch/src/couch_bt_engine_compactor.erl | 17 ++++++++---------
 src/couch/src/couch_bt_engine_header.erl    |  2 +-
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 485d21d..899a915 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -47,7 +47,6 @@
     set_revs_limit/2,
     set_purge_infos_limit/2,
     set_security/2,
-    set_purged_docs_limit/2,
 
     open_docs/2,
     open_local_docs/2,
@@ -348,7 +347,7 @@ read_doc_body(#st{} = St, #doc{} = Doc) ->
 
 
 load_purge_infos(St, UUIDs) ->
-    Results = couch_btree:lookup(St#st.upurge_tree, UUIDs),
+    Results = couch_btree:lookup(St#st.purge_tree, UUIDs),
     lists:map(fun
         ({ok, Info}) -> Info;
         (not_found) -> not_found
@@ -444,10 +443,10 @@ purge_docs(#st{} = St, Pairs, PurgeInfos) ->
         id_tree = IdTree,
         seq_tree = SeqTree,
         purge_tree = PurgeTree,
-        upurge_tree = UPurgeTree
+        purge_seq_tree = PurgeSeqTree
     } = St,
 
-    RemDocIds = [Old#full_doc_info.doc_id || {Old, not_found} <- Pairs],
+    RemDocIds = [Old#full_doc_info.id || {Old, not_found} <- Pairs],
     RemSeqs = [Old#full_doc_info.update_seq || {Old, _} <- Pairs],
     DocsToAdd = [New || {_, New} <- Pairs, New /= not_found],
     CurrSeq = couch_bt_engine_header:get(St#st.header, update_seq),
@@ -458,8 +457,8 @@ purge_docs(#st{} = St, Pairs, PurgeInfos) ->
     % indexers see that they need to process the new purge
     % information.
     UpdateSeq = case NewSeq == CurrSeq of
-        true -> InitUpdateSeq + 1;
-        false -> NewUpdateSeq
+        true -> CurrSeq + 1;
+        false -> NewSeq
     end,
     Header = couch_bt_engine_header:set(St#st.header, [
         {update_seq, UpdateSeq}
@@ -470,7 +469,7 @@ purge_docs(#st{} = St, Pairs, PurgeInfos) ->
     {ok, PurgeTree2} = couch_btree:add(PurgeTree, PurgeInfos),
     {ok, PurgeSeqTree2} = couch_btree:add(PurgeSeqTree, PurgeInfos),
     {ok, St#st{
-        header = Header2,
+        header = Header,
         id_tree = IdTree2,
         seq_tree = SeqTree2,
         purge_tree = PurgeTree2,
@@ -544,7 +543,7 @@ fold_changes(St, SinceSeq, UserFun, UserAcc, Options) ->
 fold_purge_infos(St, StartSeq0, UserFun, UserAcc, Options) ->
     PurgeSeqTree = St#st.purge_seq_tree,
     StartSeq = StartSeq0 + 1,
-    MinSeq = load_oldest_purge_seq(PurgeSeqTree),
+    MinSeq = get_oldest_purge_seq(St),
     if MinSeq =< StartSeq -> ok; true ->
         throw({invalid_start_purge_seq, StartSeq0})
     end,
@@ -553,7 +552,7 @@ fold_purge_infos(St, StartSeq0, UserFun, UserAcc, Options) ->
     end,
     Opts = [{start_key, StartSeq}] ++ Options,
     {ok, _, OutAcc} = couch_btree:fold(PurgeSeqTree, Wrapper, UserAcc, Opts),
-    {ok, OutAcc};
+    {ok, OutAcc}.
 
 
 count_changes_since(St, SinceSeq) ->
@@ -714,7 +713,7 @@ purge_tree_split({PurgeSeq, UUID, DocId, Revs}) ->
     {UUID, {PurgeSeq, DocId, Revs}}.
 
 
-purge_tree_join({UUID, {PurgeSeq, DocId, Revs}}) ->
+purge_tree_join(UUID, {PurgeSeq, DocId, Revs}) ->
     {PurgeSeq, UUID, DocId, Revs}.
 
 
@@ -722,7 +721,7 @@ purge_seq_tree_split({PurgeSeq, UUID, DocId, Revs}) ->
     {PurgeSeq, {UUID, DocId, Revs}}.
 
 
-purge_seq_tree_join({PurgeSeq, {UUID, DocId, Revs}}) ->
+purge_seq_tree_join(PurgeSeq, {UUID, DocId, Revs}) ->
     {PurgeSeq, UUID, DocId, Revs}.
 
 
@@ -897,6 +896,8 @@ upgrade_purge_info(Fd, Header) ->
         Ptr when is_tuple(Ptr) ->
             Header;
         PurgeSeq when is_integer(PurgeSeq)->
+            % Pointer to old purged ids/revs is in purge_seq_tree_state
+            Ptr = couch_bt_engine_header:get(Header, purge_seq_tree_state),
             {ok, PurgedIdsRevs} = couch_file:pread_term(Fd, Ptr),
 
             {Infos, NewSeq} = lists:foldl(fun({Id, Revs}, {InfoAcc, PSeq}) ->
@@ -921,8 +922,8 @@ upgrade_purge_info(Fd, Header) ->
             {ok, PurgeSeqTreeSt} = couch_btree:get_state(PurgeSeqTree2),
 
             couch_bt_engine_header:set(Header, [
-                {purge_tree_state, PTreeState},
-                {purge_seq_tree_state, UPTreeState}
+                {purge_tree_state, PurgeTreeSt},
+                {purge_seq_tree_state, PurgeSeqTreeSt}
             ])
     end.
 
@@ -1098,7 +1099,7 @@ finish_compaction_int(#st{} = OldSt, #st{} = NewSt1) ->
         header = couch_bt_engine_header:set(Header, [
             {compacted_seq, get_update_seq(OldSt)},
             {revs_limit, get_revs_limit(OldSt)},
-            {purge_infos_limit, get_purged_docs_limit(OldSt)}
+            {purge_infos_limit, get_purge_infos_limit(OldSt)}
         ]),
         local_tree = NewLocal2
     }),
diff --git a/src/couch/src/couch_bt_engine_compactor.erl b/src/couch/src/couch_bt_engine_compactor.erl
index f6e79b4..884f0fa 100644
--- a/src/couch/src/couch_bt_engine_compactor.erl
+++ b/src/couch/src/couch_bt_engine_compactor.erl
@@ -107,7 +107,6 @@ copy_purge_info(DbName, OldSt, NewSt, Retry) ->
     MinPurgeSeq = couch_util:with_db(DbName, fun(Db) ->
         couch_db:get_minimum_purge_seq(Db)
     end),
-    OldIdTree = OldSt#st.id_tree,
     OldPSTree = OldSt#st.purge_seq_tree,
     StartSeq = couch_bt_engine:get_purge_seq(NewSt) + 1,
     BufferSize = config:get_integer(
@@ -115,7 +114,7 @@ copy_purge_info(DbName, OldSt, NewSt, Retry) ->
     CheckpointAfter = config:get(
             "database_compaction", "checkpoint_after", BufferSize * 10),
 
-    EnumFun = fun(Info, _Reds, {StAcc, InfosAcc0, InfosSize, CopiedSize}) ->
+    EnumFun = fun(Info, _Reds, {StAcc0, InfosAcc, InfosSize, CopiedSize}) ->
         NewInfosSize = InfosSize + ?term_size(Info),
         if NewInfosSize >= BufferSize ->
             StAcc1 = copy_purge_infos(
@@ -125,11 +124,11 @@ copy_purge_info(DbName, OldSt, NewSt, Retry) ->
                 StAcc2 = commit_compaction_data(StAcc1),
                 {ok, {StAcc2, [], 0, 0}};
             true ->
-                {ok, {StAcc2, [], 0, NewCopiedSize}}
+                {ok, {StAcc1, [], 0, NewCopiedSize}}
             end;
         true ->
-            NewInfosAcc = [Info | InfosAcc]
-            {ok, {StAcc, NewInfosAcc, NewInfosSize, CopiedSize}}
+            NewInfosAcc = [Info | InfosAcc],
+            {ok, {StAcc0, NewInfosAcc, NewInfosSize, CopiedSize}}
         end
     end,
 
@@ -140,7 +139,7 @@ copy_purge_info(DbName, OldSt, NewSt, Retry) ->
     copy_purge_infos(OldSt, NewStAcc, Infos, MinPurgeSeq, Retry).
 
 
-copy_purge_docs(OldSt, NewSt, Infos, MinPurgeSeq, Retry) ->
+copy_purge_infos(OldSt, NewSt, Infos, MinPurgeSeq, Retry) ->
     #st{
         id_tree = OldIdTree
     } = OldSt,
@@ -170,13 +169,13 @@ copy_purge_docs(OldSt, NewSt, Infos, MinPurgeSeq, Retry) ->
         AllDocIds = [DocId || {_PurgeSeq, _UUID, DocId, _Revs} <- Infos],
         UniqDocIds = lists:usort(AllDocIds),
         {ok, OldIdResults} = couch_btree:lookup(OldIdTree, UniqDocIds),
-        OldZipped = lists:zip(UniqDocIds, Results),
+        OldZipped = lists:zip(UniqDocIds, OldIdResults),
 
         % The list of non-existant docs in the database being compacted
-        MaybeRemDocIds = [DocId || {DocId, not_found} <- Zipped],
+        MaybeRemDocIds = [DocId || {DocId, not_found} <- OldZipped],
 
         % Removing anything that exists in the partially compacted database
-        {ok, NewIdResults} = couch_btree:lookup(NewIdTree, MaybeRemDocIds),
+        {ok, NewIdResults} = couch_btree:lookup(NewIdTree0, MaybeRemDocIds),
         ToRemove = [Doc || Doc <- NewIdResults, Doc /= not_found],
 
         {RemIds, RemSeqs} = lists:unzip(lists:map(fun(FDI) ->
diff --git a/src/couch/src/couch_bt_engine_header.erl b/src/couch/src/couch_bt_engine_header.erl
index 55246ac..467bb2f 100644
--- a/src/couch/src/couch_bt_engine_header.erl
+++ b/src/couch/src/couch_bt_engine_header.erl
@@ -33,7 +33,7 @@
     local_tree_state/1,
     purge_tree_state/1,
     purge_seq_tree_state/1,
-    purged_docs_limit/1,
+    purge_infos_limit/1,
     security_ptr/1,
     revs_limit/1,
     uuid/1,

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 22/33: WIP - fabric API

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 46be71e4d4c2b3f3bacce8e9ff01a1a78d64968d
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:08:47 2018 -0500

    WIP - fabric API
---
 src/fabric/src/fabric.erl           |  2 +-
 src/fabric/src/fabric_doc_purge.erl | 37 +++++++++++++++++--------------------
 2 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index 7532d9d..1900f79 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -284,7 +284,7 @@ update_docs(DbName, Docs, Options) ->
 %% @doc purge revisions for a list '{Id, Revs}'
 %%      returns {ok, {PurgeSeq, Results}}
 -spec purge_docs(dbname(), [{docid(), [revision()]}], [option()]) ->
-    {ok, [{Health, [revision()]}] | {error, any()}}} when
+    {ok, [{Health, [revision()]}] | {error, any()}} when
     Health :: ok | accepted.
 purge_docs(DbName, IdsRevs, Options) when is_list(IdsRevs) ->
     IdsRevs2 = [idrevs(IdRs) || IdRs <- IdsRevs],
diff --git a/src/fabric/src/fabric_doc_purge.erl b/src/fabric/src/fabric_doc_purge.erl
index c11f533..b51f28e 100644
--- a/src/fabric/src/fabric_doc_purge.erl
+++ b/src/fabric/src/fabric_doc_purge.erl
@@ -38,20 +38,19 @@ go(DbName, IdsRevs, Options) ->
 
     % Fire off rexi workers for each shard.
     {Workers, WorkerUUIDs} = dict:fold(fun(Shard, ShardReqs, {Ws, WUUIDs}) ->
-        UUIDs = [UUID || {UUID, _Id, _Revs} <- ShardReqs],
-        #shard{name = Name, node = Node} = Shard,
-        Args = [ShardDbName, Reqs, Options]
+        #shard{name = ShardDbName, node = Node} = Shard,
+        Args = [ShardDbName, ShardReqs, Options],
         Ref = rexi:cast(Node, {fabric_rpc, purge_docs, Args}),
         Worker = Shard#shard{ref=Ref},
-        {[Worker | Ws], [{Worker, UUIDs} | WUUIDs]}
+        ShardUUIDs = [UUID || {UUID, _Id, _Revs} <- ShardReqs],
+        {[Worker | Ws], [{Worker, ShardUUIDs} | WUUIDs]}
     end, {[], []}, group_reqs_by_shard(DbName, Reqs)),
 
     RexiMon = fabric_util:create_monitors(Workers),
     Timeout = fabric_util:request_timeout(),
     Acc0 = #acc{
-        workers = Workers,
+        worker_uuids = WorkerUUIDs,
         req_count = Count,
-        ref_uuids = RefUUIDs,
         resps = dict:from_list([{UUID, []} || UUID <- UUIDs]),
         w = w(DbName, Options)
     },
@@ -63,11 +62,11 @@ go(DbName, IdsRevs, Options) ->
             #acc{
                 worker_uuids = WorkerUUIDs,
                 resps = Resps
-            } = Acc1
-            DefunctWorkers = [Worker || {Worker, _} <- WorkerUUIDs]
+            } = Acc1,
+            DefunctWorkers = [Worker || {Worker, _} <- WorkerUUIDs],
             fabric_util:log_timeout(DefunctWorkers, "purge_docs"),
             NewResps = append_errors(timeout, WorkerUUIDs, Resps),
-            Acc1#acc{worker_uuids = [], resps = NewResps}
+            Acc1#acc{worker_uuids = [], resps = NewResps};
         Else ->
             Else
     after
@@ -83,7 +82,7 @@ handle_message({rexi_DOWN, _, {_, Node}, _}, _Worker, Acc) ->
         resps = Resps
     } = Acc,
     Pred = fun({#shard{node = N}, _}) -> N == Node end,
-    {Failed, Rest} = lists:partition(Pred, WorkerUUIDs)
+    {Failed, Rest} = lists:partition(Pred, WorkerUUIDs),
     NewResps = append_errors(internal_server_error, Failed, Resps),
     maybe_stop(Acc#acc{worker_uuids = Rest, resps = NewResps});
 
@@ -94,7 +93,7 @@ handle_message({rexi_EXIT, _}, Worker, Acc) ->
     } = Acc,
     {value, WorkerPair, Rest} = lists:keytake(Worker, 1, WorkerUUIDs),
     NewResps = append_errors(internal_server_error, [WorkerPair], Resps),
-    maybe_stop(Acc#acc{worker_uuids = Rest, resps = NewResps})
+    maybe_stop(Acc#acc{worker_uuids = Rest, resps = NewResps});
 
 handle_message({ok, Replies}, Worker, Acc) ->
     #acc{
@@ -102,6 +101,7 @@ handle_message({ok, Replies}, Worker, Acc) ->
         resps = Resps
     } = Acc,
     {value, {_W, UUIDs}, Rest} = lists:keytake(Worker, 1, WorkerUUIDs),
+    couch_log:error("XKCD: ~p ~p :: ~p ~p", [length(UUIDs), length(Replies), UUIDs, Replies]),
     NewResps = append_resps(UUIDs, Replies, Resps),
     maybe_stop(Acc#acc{worker_uuids = Rest, resps = NewResps});
 
@@ -114,7 +114,7 @@ create_reqs([], UUIDs, Reqs, Count) ->
 
 create_reqs([{Id, Revs} | RestIdsRevs], UUIDs, Reqs, Count) ->
     UUID = couch_uuids:new(),
-    NewUUIDS = [UUID | UUIDs],
+    NewUUIDs = [UUID | UUIDs],
     NewReqs = [{UUID, Id, Revs} | Reqs],
     create_reqs(RestIdsRevs, NewUUIDs, NewReqs, Count + 1).
 
@@ -124,7 +124,7 @@ group_reqs_by_shard(DbName, Reqs) ->
         lists:foldl(fun(Shard, D1) ->
             dict:append(Shard, Req, D1)
         end, D0, mem3:shards(DbName, Id))
-    end, dict:new(), UUIDsIdsRevs).
+    end, dict:new(), Reqs).
 
 
 w(DbName, Options) ->
@@ -153,12 +153,13 @@ maybe_stop(#acc{worker_uuids = []} = Acc) ->
     {stop, Acc};
 maybe_stop(#acc{resps = Resps, w = W} = Acc) ->
     try
-        dict:fold(fun(UUID, UUIDResps, _) ->
+        dict:fold(fun(_UUID, UUIDResps, _) ->
+            couch_log:error("XKCD: ~p ~p", [UUIDResps, W]),
             case has_quorum(UUIDResps, W) of
                 true -> ok;
                 false -> throw(keep_going)
             end
-        end, nil, Resps)
+        end, nil, Resps),
         {stop, Acc}
     catch throw:keep_going ->
         {ok, Acc}
@@ -177,7 +178,7 @@ format_resps(UUIDs, #acc{} = Acc) ->
                 [Error | _] = lists:usort(Replies),
                 [{UUID, Error} | ReplyAcc];
             _ ->
-                AllRevs = lists:usort(lists:flatten(OkReplies)).
+                AllRevs = lists:usort(lists:flatten(OkReplies)),
                 Health = if length(OkReplies) >= W -> ok; true -> accepted end,
                 [{UUID, {Health, AllRevs}} | ReplyAcc]
         end
@@ -197,10 +198,6 @@ has_quorum([{ok, _} | Rest], W) when W > 0 ->
     has_quorum(Rest, W - 1).
 
 
-update_health(ok, Health) -> Health;
-update_health(accepted, _) -> accepted.
-
-
 %% % eunits
 %% doc_purge_ok_test() ->
 %%     meck:new(couch_log),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 20/33: WIP - internal replication

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e590bdf407eb2952af7b357615e93910e676781b
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:07:57 2018 -0500

    WIP - internal replication
---
 src/mem3/src/mem3_rep.erl | 35 ++++++++++++++++++++++-------------
 src/mem3/src/mem3_rpc.erl |  4 ++--
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/mem3/src/mem3_rep.erl b/src/mem3/src/mem3_rep.erl
index 338d20e..edac76d 100644
--- a/src/mem3/src/mem3_rep.erl
+++ b/src/mem3/src/mem3_rep.erl
@@ -76,7 +76,7 @@ go(#shard{} = Source, #shard{} = Target, Opts) ->
     go(Acc).
 
 
-go(#acc{source=Source, batch_count=BC}=Acc0) ->
+go(#acc{source=Source, batch_count=BC}=Acc) ->
     case couch_db:open(Source#shard.name, [?ADMIN_CTX]) of
     {ok, Db} ->
         Resp = try
@@ -200,9 +200,9 @@ find_source_seq_int(#doc{body={Props}}, SrcNode0, TgtNode0, TgtUUID, TgtSeq) ->
     end.
 
 
-repl(Acc0#acc{db = Db0}) ->
+repl(#acc{db = Db0} = Acc0) ->
     erlang:put(io_priority, {internal_repl, couch_db:name(Db0)}),
-    #acc{seq = Seq} = Acc1 = calculate_start_seq(Acc0),
+    Acc1 = calculate_start_seq(Acc0),
     try
         Acc3 = case config:get_boolean("mem3", "replicate_purges", false) of
             true ->
@@ -229,10 +229,10 @@ pull_purges(#acc{} = Acc0) ->
         name = TgtDbName
     } = Target,
 
-    {Acc2, RemToPull} = with_src_db(Acc0, fun(Db) ->
+    with_src_db(Acc0, fun(Db) ->
         SrcUUID = couch_db:get_uuid(Db),
         {ok, LocalPurgeId, Infos, ThroughSeq, Remaining} =
-                mem3_rpc:load_purge_infos(TNode, DbName, SrcUUID, Count),
+                mem3_rpc:load_purge_infos(TgtNode, TgtDbName, SrcUUID, Count),
 
         if Infos == [] -> ok; true ->
             {ok, _} = couch_db:purge_docs(Db, Infos, [replicated_edits]),
@@ -246,7 +246,7 @@ pull_purges(#acc{} = Acc0) ->
             PurgesToPush = couch_db:get_purge_seq(Db) - OldestPurgeSeq,
             Changes = couch_db:count_changes_since(Db, UpdateSeq),
             throw({finished, Remaining + PurgesToPush + Changes})
-        end
+        end,
 
         Acc0#acc{purgeid = LocalPurgeId}
     end).
@@ -265,13 +265,21 @@ push_purges(#acc{} = Acc0) ->
     } = Target,
 
     with_src_db(Acc0, fun(Db) ->
+        StartSeq = case couch_db:open_doc(Db, LocalPurgeId, []) of
+            {ok, #doc{body = {Props}}} ->
+                couch_util:get_value(<<"purge_seq">>, Props);
+            {not_found, _} ->
+                {ok, Oldest} = couch_db:get_oldest_purge_seq(Db),
+                Oldest
+        end,
+
         FoldFun = fun({PSeq, UUID, Id, Revs}, {Count, Infos, _}) ->
             NewCount = Count + length(Revs),
             NewInfos = [{UUID, Id, Revs} | Infos],
             Status = if NewCount < BatchSize -> ok; true -> stop end,
             {Status, {NewCount, NewInfos, PSeq}}
         end,
-        InitAcc = {0, [], StartSeq}
+        InitAcc = {0, [], StartSeq},
         {ok, {_, Infos, ThroughSeq}} =
             couch_db:fold_purge_infos(Db, StartSeq, FoldFun, InitAcc),
 
@@ -303,12 +311,13 @@ push_changes(#acc{} = Acc0) ->
 
     % Avoid needless rewriting the internal replication
     % checkpoint document if nothing is replicated.
-    if Seq < couch_db:get_update_seq(Db0) -> ok; true ->
+    UpdateSeq = couch_db:get_update_seq(Db0),
+    if Seq < UpdateSeq -> ok; true ->
         throw({finished, 0})
-    end
+    end,
 
     with_src_db(Acc0, fun(Db) ->
-        Acc1 = Acc#acc{db = Db},
+        Acc1 = Acc0#acc{db = Db},
         Fun = fun ?MODULE:changes_enumerator/2,
         {ok, Acc2} = couch_db:fold_changes(Db, Seq, Fun, Acc1),
         {ok, #acc{seq = LastSeq}} = replicate_batch(Acc2),
@@ -485,15 +494,15 @@ purge_cp_body(#acc{} = Acc, PurgeSeq) ->
     } = Acc,
     {Mega, Secs, _} = os:timestamp(),
     NowSecs = Mega * 1000000 + Secs,
-    Body = {[
+    {[
         {<<"type">>, <<"internal_replication">>},
         {<<"updated_on">>, NowSecs},
         {<<"purge_seq">>, PurgeSeq},
         {<<"verify_module">>, <<"mem3_rep">>},
         {<<"verify_function">>, <<"verify_purge_checkpoint">>},
         {<<"dbname">>, Source#shard.dbname},
-        {<<"source">>, atom_to_binary(Source#shard.node)},
-        {<<"target">>, atom_to_binary(Target#shard.node)},
+        {<<"source">>, atom_to_binary(Source#shard.node, latin1)},
+        {<<"target">>, atom_to_binary(Target#shard.node, latin1)},
         {<<"range">>, Source#shard.range}
     ]}.
 
diff --git a/src/mem3/src/mem3_rpc.erl b/src/mem3/src/mem3_rpc.erl
index ab293d7..b0b0098 100644
--- a/src/mem3/src/mem3_rpc.erl
+++ b/src/mem3/src/mem3_rpc.erl
@@ -156,7 +156,7 @@ load_purge_infos_rpc(DbName, SrcUUID, BatchSize) ->
             TgtUUID = couch_db:get_uuid(Db),
             PurgeDocId = mem3_rep:make_purge_id(SrcUUID, TgtUUID),
             StartSeq = case couch_db:open_doc(Db, PurgeDocId, []) of
-                {ok, #doc{props = {Props}}} ->
+                {ok, #doc{body = {Props}}} ->
                     couch_util:get_value(<<"purge_seq">>, Props);
                 {not_found, _} ->
                     {ok, Oldest} = couch_db:get_oldest_purge_seq(Db),
@@ -173,7 +173,7 @@ load_purge_infos_rpc(DbName, SrcUUID, BatchSize) ->
                     couch_db:fold_purge_infos(Db, StartSeq, FoldFun, InitAcc),
             {ok, PurgeSeq} = couch_db:get_purge_seq(Db),
             Remaining = PurgeSeq - ThroughSeq,
-            rexi:reply({ok, PurgeDocId, PurgeInfos, ThroughSeq, Remainin})
+            rexi:reply({ok, PurgeDocId, PurgeInfos, ThroughSeq, Remaining});
         Else ->
             rexi:reply(Else)
     end.

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 24/33: WIP - add test suite

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5b14d1bb319e3da93bcdb0334b5206610ba92c05
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:21:43 2018 -0500

    WIP - add test suite
---
 src/couch/src/test_engine_compaction.erl               |  8 ++++----
 ...urged_docs.erl => test_engine_fold_purge_infos.erl} | 14 +++++++-------
 src/couch/src/test_engine_purge_docs.erl               | 18 +++++++++---------
 src/couch/src/test_engine_util.erl                     |  8 ++++----
 src/couch/test/couch_db_purge_docs_tests.erl           | 14 +++++++-------
 5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/src/couch/src/test_engine_compaction.erl b/src/couch/src/test_engine_compaction.erl
index 665b7d8..18bf938 100644
--- a/src/couch/src/test_engine_compaction.erl
+++ b/src/couch/src/test_engine_compaction.erl
@@ -95,7 +95,7 @@ cet_compact_with_everything() ->
         {<<"foo">>, [FooRev#rev_info.rev]}
     ],
 
-    {ok, PIdRevs6} = Engine:fold_purged_docs(St6, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs6} = Engine:fold_purge_infos(St6, 0, fun fold_fun/2, [], []),
     ?assertEqual(PurgedIdRevs, PIdRevs6),
 
     {ok, St7} = try
@@ -130,7 +130,7 @@ cet_compact_with_everything() ->
     end),
 
     {ok, St10, undefined} = Engine:finish_compaction(St9, DbName, [], Term),
-    {ok, PIdRevs11} = Engine:fold_purged_docs(St10, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs11} = Engine:fold_purge_infos(St10, 0, fun fold_fun/2, [], []),
     ?assertEqual(PurgedIdRevs, PIdRevs11),
 
     Db2 = test_engine_util:db_as_term(Engine, St10),
@@ -248,7 +248,7 @@ ignore_cet_compact_purged_docs_limit() ->
     % check that before compaction all NumDocs of purge_requests
     % are in purge_tree,
     % even if NumDocs=1200 is greater than purged_docs_limit=1000
-    {ok, PurgedIdRevs} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PurgedIdRevs} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
     ?assertEqual(1, Engine:get_oldest_purge_seq(St3)),
     ?assertEqual(NumDocs, length(PurgedIdRevs)),
 
@@ -260,7 +260,7 @@ ignore_cet_compact_purged_docs_limit() ->
     % are in purge_tree
     PurgedDocsLimit = Engine:get_purged_docs_limit(St5),
     OldestPSeq = Engine:get_oldest_purge_seq(St5),
-    {ok, PurgedIdRevs2} = Engine:fold_purged_docs(
+    {ok, PurgedIdRevs2} = Engine:fold_purge_infos(
         St5, OldestPSeq - 1, fun fold_fun/2, [], []),
     ExpectedOldestPSeq = NumDocs - PurgedDocsLimit + 1,
     ?assertEqual(ExpectedOldestPSeq, OldestPSeq),
diff --git a/src/couch/src/test_engine_fold_purged_docs.erl b/src/couch/src/test_engine_fold_purge_infos.erl
similarity index 91%
rename from src/couch/src/test_engine_fold_purged_docs.erl
rename to src/couch/src/test_engine_fold_purge_infos.erl
index 1dc0885..07131e4 100644
--- a/src/couch/src/test_engine_fold_purged_docs.erl
+++ b/src/couch/src/test_engine_fold_purge_infos.erl
@@ -10,7 +10,7 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
--module(test_engine_fold_purged_docs).
+-module(test_engine_fold_purge_infos).
 -compile(export_all).
 
 
@@ -23,7 +23,7 @@
 
 cet_empty_purged_docs() ->
     {ok, Engine, St} = test_engine_util:init_engine(),
-    ?assertEqual({ok, []}, Engine:fold_purged_docs(St, 0, fun fold_fun/2, [], [])).
+    ?assertEqual({ok, []}, Engine:fold_purge_infos(St, 0, fun fold_fun/2, [], [])).
 
 
 cet_all_purged_docs() ->
@@ -49,7 +49,7 @@ cet_all_purged_docs() ->
     {Actions2, IdsRevs} = {lists:reverse(RevActions2), lists:reverse(RevIdRevs)},
 
     {ok, St3} = test_engine_util:apply_actions(Engine, St2, Actions2),
-    {ok, PurgedIdRevs} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PurgedIdRevs} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
     ?assertEqual(IdsRevs, lists:reverse(PurgedIdRevs)).
 
 
@@ -77,7 +77,7 @@ cet_start_seq() ->
 
     StartSeq = 3,
     StartSeqIdRevs = lists:nthtail(StartSeq, lists:reverse(RIdRevs)),
-    {ok, PurgedIdRevs} = Engine:fold_purged_docs(St3, StartSeq, fun fold_fun/2, [], []),
+    {ok, PurgedIdRevs} = Engine:fold_purge_infos(St3, StartSeq, fun fold_fun/2, [], []),
     ?assertEqual(StartSeqIdRevs, lists:reverse(PurgedIdRevs)).
 
 
@@ -98,13 +98,13 @@ cet_id_rev_repeated() ->
     ],
     {ok, St3} = test_engine_util:apply_actions(Engine, St2, Actions2),
     PurgedIdRevs0 = [{<<"foo">>, [Rev1]}],
-    {ok, PurgedIdRevs1} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PurgedIdRevs1} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
     ?assertEqual(PurgedIdRevs0, PurgedIdRevs1),
     ?assertEqual(1, Engine:get_purge_seq(St3)),
 
     % purge the same Id,Rev when the doc still exists
     {ok, St4} = test_engine_util:apply_actions(Engine, St3, Actions2),
-    {ok, PurgedIdRevs2} = Engine:fold_purged_docs(St4, 0, fun fold_fun/2, [], []),
+    {ok, PurgedIdRevs2} = Engine:fold_purge_infos(St4, 0, fun fold_fun/2, [], []),
     ?assertEqual(PurgedIdRevs0, PurgedIdRevs2),
     ?assertEqual(1, Engine:get_purge_seq(St4)),
 
@@ -119,7 +119,7 @@ cet_id_rev_repeated() ->
 
     % purge the same Id,Rev when the doc was completely purged
     {ok, St6} = test_engine_util:apply_actions(Engine, St5, Actions3),
-    {ok, PurgedIdRevs3} = Engine:fold_purged_docs(St6, 0, fun fold_fun/2, [], []),
+    {ok, PurgedIdRevs3} = Engine:fold_purge_infos(St6, 0, fun fold_fun/2, [], []),
     ?assertEqual(PurgedIdRevs00, lists:reverse(PurgedIdRevs3)),
     ?assertEqual(2, Engine:get_purge_seq(St6)).
 
diff --git a/src/couch/src/test_engine_purge_docs.erl b/src/couch/src/test_engine_purge_docs.erl
index a1dbae7..268011b 100644
--- a/src/couch/src/test_engine_purge_docs.erl
+++ b/src/couch/src/test_engine_purge_docs.erl
@@ -25,7 +25,7 @@ cet_purge_simple() ->
         {create, {<<"foo">>, [{<<"vsn">>, 1}]}}
     ],
     {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions1),
-    {ok, PIdRevs2} = Engine:fold_purged_docs(St2, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs2} = Engine:fold_purge_infos(St2, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(1, Engine:get_doc_count(St2)),
     ?assertEqual(0, Engine:get_del_doc_count(St2)),
@@ -41,7 +41,7 @@ cet_purge_simple() ->
         {purge, {<<"foo">>, Rev}}
     ],
     {ok, St3} = test_engine_util:apply_actions(Engine, St2, Actions2),
-    {ok, PIdRevs3} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs3} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(0, Engine:get_doc_count(St3)),
     ?assertEqual(0, Engine:get_del_doc_count(St3)),
@@ -58,7 +58,7 @@ cet_purge_conflicts() ->
         {conflict, {<<"foo">>, [{<<"vsn">>, 2}]}}
     ],
     {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions1),
-    {ok, PIdRevs2} = Engine:fold_purged_docs(St2, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs2} = Engine:fold_purge_infos(St2, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(1, Engine:get_doc_count(St2)),
     ?assertEqual(0, Engine:get_del_doc_count(St2)),
@@ -74,7 +74,7 @@ cet_purge_conflicts() ->
         {purge, {<<"foo">>, Rev1}}
     ],
     {ok, St3} = test_engine_util:apply_actions(Engine, St2, Actions2),
-    {ok, PIdRevs3} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs3} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(1, Engine:get_doc_count(St3)),
     ?assertEqual(0, Engine:get_del_doc_count(St3)),
@@ -90,7 +90,7 @@ cet_purge_conflicts() ->
         {purge, {<<"foo">>, Rev2}}
     ],
     {ok, St4} = test_engine_util:apply_actions(Engine, St3, Actions3),
-    {ok, PIdRevs4} = Engine:fold_purged_docs(St4, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs4} = Engine:fold_purge_infos(St4, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(0, Engine:get_doc_count(St4)),
     ?assertEqual(0, Engine:get_del_doc_count(St4)),
@@ -108,7 +108,7 @@ cet_add_delete_purge() ->
     ],
 
     {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions1),
-    {ok, PIdRevs2} = Engine:fold_purged_docs(St2, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs2} = Engine:fold_purge_infos(St2, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(0, Engine:get_doc_count(St2)),
     ?assertEqual(1, Engine:get_del_doc_count(St2)),
@@ -124,7 +124,7 @@ cet_add_delete_purge() ->
         {purge, {<<"foo">>, Rev}}
     ],
     {ok, St3} = test_engine_util:apply_actions(Engine, St2, Actions2),
-    {ok, PIdRevs3} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs3} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(0, Engine:get_doc_count(St3)),
     ?assertEqual(0, Engine:get_del_doc_count(St3)),
@@ -142,7 +142,7 @@ cet_add_two_purge_one() ->
     ],
 
     {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions1),
-    {ok, PIdRevs2} = Engine:fold_purged_docs(St2, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs2} = Engine:fold_purge_infos(St2, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(2, Engine:get_doc_count(St2)),
     ?assertEqual(0, Engine:get_del_doc_count(St2)),
@@ -158,7 +158,7 @@ cet_add_two_purge_one() ->
         {purge, {<<"foo">>, Rev}}
     ],
     {ok, St3} = test_engine_util:apply_actions(Engine, St2, Actions2),
-    {ok, PIdRevs3} = Engine:fold_purged_docs(St3, 0, fun fold_fun/2, [], []),
+    {ok, PIdRevs3} = Engine:fold_purge_infos(St3, 0, fun fold_fun/2, [], []),
 
     ?assertEqual(1, Engine:get_doc_count(St3)),
     ?assertEqual(0, Engine:get_del_doc_count(St3)),
diff --git a/src/couch/src/test_engine_util.erl b/src/couch/src/test_engine_util.erl
index 745e00f..3e6d2d6 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -24,7 +24,7 @@
     test_engine_attachments,
     test_engine_fold_docs,
     test_engine_fold_changes,
-    test_engine_fold_purged_docs,
+    test_engine_fold_purge_infos,
     test_engine_purge_docs,
     test_engine_compaction,
     test_engine_ref_counting
@@ -238,7 +238,7 @@ gen_write(Engine, St, {purge, {DocId, PrevRevs0, _}}, UpdateSeq) ->
                 _ -> false
             end
         end,
-        {ok, IsPurgedBefore} = Engine:fold_purged_docs(
+        {ok, IsPurgedBefore} = Engine:fold_purge_infos(
             St, 0, FoldFun, false, []),
         case IsPurgedBefore of
             true -> {{}, UpdateSeq, purged_before};
@@ -263,7 +263,7 @@ gen_write(Engine, St, {purge, {DocId, PrevRevs0, _}}, UpdateSeq) ->
                     _ -> Acc
                 end
             end,
-            {ok, PurgedRevs} = Engine:fold_purged_docs(St, 0, FoldFun, [], []),
+            {ok, PurgedRevs} = Engine:fold_purge_infos(St, 0, FoldFun, [], []),
             case lists:subtract(PrevRevs, PurgedRevs) of [] -> ok; _ ->
                 % If we didn't purge all the requested revisions
                 % and they haven't been purged before
@@ -498,7 +498,7 @@ db_purged_docs_as_term(Engine, St) ->
     FoldFun = fun({PSeq, UUID, Id, Revs}, Acc) ->
         [{PSeq, UUID, Id, Revs} | Acc]
     end,
-    {ok, PDocs} = Engine:fold_purged_docs(St, StartPSeq, FoldFun, [], []),
+    {ok, PDocs} = Engine:fold_purge_infos(St, StartPSeq, FoldFun, [], []),
     lists:reverse(PDocs).
 
 
diff --git a/src/couch/test/couch_db_purge_docs_tests.erl b/src/couch/test/couch_db_purge_docs_tests.erl
index 1608957..070fb24 100644
--- a/src/couch/test/couch_db_purge_docs_tests.erl
+++ b/src/couch/test/couch_db_purge_docs_tests.erl
@@ -81,7 +81,7 @@ purge_simple(DbName) ->
             ?assertEqual([Rev2], PRevs2),
 
             {ok, Db3} = couch_db:reopen(Db2),
-            {ok, PIdsRevs} = couch_db:fold_purged_docs(
+            {ok, PIdsRevs} = couch_db:fold_purge_infos(
                 Db3, 0, fun fold_fun/2, [], []),
             ?assertEqual(0, couch_db_engine:get_doc_count(Db3)),
             ?assertEqual(0, couch_db_engine:get_del_doc_count(Db3)),
@@ -109,7 +109,7 @@ add_delete_purge(DbName) ->
             couch_db:ensure_full_commit(Db1),
 
             {ok, Db2} = couch_db:reopen(Db1),
-            {ok, PIdsRevs1} = couch_db:fold_purged_docs(
+            {ok, PIdsRevs1} = couch_db:fold_purge_infos(
                 Db2, 0, fun fold_fun/2, [], []),
             ?assertEqual(0, couch_db_engine:get_doc_count(Db2)),
             ?assertEqual(1, couch_db_engine:get_del_doc_count(Db2)),
@@ -123,7 +123,7 @@ add_delete_purge(DbName) ->
             ?assertEqual([Rev2], PRevs),
 
             {ok, Db3} = couch_db:reopen(Db2),
-            {ok, PIdsRevs2} = couch_db:fold_purged_docs(
+            {ok, PIdsRevs2} = couch_db:fold_purge_infos(
                 Db3, 0, fun fold_fun/2, [], []),
             ?assertEqual(0, couch_db_engine:get_doc_count(Db3)),
             ?assertEqual(0, couch_db_engine:get_del_doc_count(Db3)),
@@ -155,7 +155,7 @@ add_two_purge_one(DbName) ->
             ?assertEqual([Rev], PRevs),
 
             {ok, Db3} = couch_db:reopen(Db2),
-            {ok, PIdsRevs} = couch_db:fold_purged_docs(
+            {ok, PIdsRevs} = couch_db:fold_purge_infos(
                 Db3, 0, fun fold_fun/2, [], []),
             ?assertEqual(1, couch_db_engine:get_doc_count(Db3)),
             ?assertEqual(0, couch_db_engine:get_del_doc_count(Db3)),
@@ -175,7 +175,7 @@ purge_id_not_exist(DbName) ->
             ?assertEqual([], PRevs),
 
             {ok, Db2} = couch_db:reopen(Db),
-            {ok, PIdsRevs} = couch_db:fold_purged_docs(
+            {ok, PIdsRevs} = couch_db:fold_purge_infos(
                 Db2, 0, fun fold_fun/2, [], []),
             ?assertEqual(0, couch_db_engine:get_doc_count(Db2)),
             ?assertEqual(0, couch_db_engine:get_del_doc_count(Db2)),
@@ -208,7 +208,7 @@ purge_non_leaf_rev(DbName) ->
             ?assertEqual([], PRevs),
 
             {ok, Db4} = couch_db:reopen(Db3),
-            {ok, PIdsRevs} = couch_db:fold_purged_docs(Db4, 0, fun fold_fun/2, [], []),
+            {ok, PIdsRevs} = couch_db:fold_purge_infos(Db4, 0, fun fold_fun/2, [], []),
             ?assertEqual(1, couch_db_engine:get_doc_count(Db4)),
             ?assertEqual(2, couch_db_engine:get_update_seq(Db4)),
             ?assertEqual(0, couch_db_engine:get_purge_seq(Db4)),
@@ -241,7 +241,7 @@ purge_conflicts(DbName) ->
             ?assertEqual([Rev], PRevs),
 
             {ok, Db4} = couch_db:reopen(Db3),
-            {ok, PIdsRevs} = couch_db:fold_purged_docs(
+            {ok, PIdsRevs} = couch_db:fold_purge_infos(
                 Db4, 0, fun fold_fun/2, [], []),
             % still has one doc
             ?assertEqual(1, couch_db_engine:get_doc_count(Db4)),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 09/33: WIP - couch_httpd_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 0486f0a8577178a60869ae7e635f3d95baf5ca75
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 10:26:27 2018 -0500

    WIP - couch_httpd_db.erl
---
 src/couch/src/couch_httpd_db.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/couch/src/couch_httpd_db.erl b/src/couch/src/couch_httpd_db.erl
index b407c02..27f7d70 100644
--- a/src/couch/src/couch_httpd_db.erl
+++ b/src/couch/src/couch_httpd_db.erl
@@ -379,15 +379,15 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_purge">>]}=Req, Db) ->
     couch_stats:increment_counter([couchdb, httpd, purge_requests]),
     couch_httpd:validate_ctype(Req, "application/json"),
     {IdRevs} = couch_httpd:json_body_obj(Req),
-    PurgeReqs = lists:map(fun({Id, JsonRevs} ->
-        {couch_uuids:new(), Id, couch_doc:parse_revs(Revs)}
+    PurgeReqs = lists:map(fun({Id, JsonRevs}) ->
+        {couch_uuids:new(), Id, couch_doc:parse_revs(JsonRevs)}
     end, IdRevs),
 
     {ok, Replies} = couch_db:purge_docs(Db, PurgeReqs),
 
     Results = lists:zipwith(fun({{Id, _}, Reply}) ->
         {Id, couch_doc:revs_to_strs(Reply)}
-    end, IdRevs, PurgeReqs),
+    end, IdRevs, Replies),
 
     {ok, Db2} = couch_db:reopen(Db),
     {ok, PurgeSeq} = couch_db:get_purge_seq(Db2),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 25/33: WIP - couch_index_updater.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit a5083e3fad157571b28e7863b803f5d4fdcd0127
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:24:16 2018 -0500

    WIP - couch_index_updater.erl
---
 src/couch_index/src/couch_index_updater.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch_index/src/couch_index_updater.erl b/src/couch_index/src/couch_index_updater.erl
index 6dc587d..14f2c08 100644
--- a/src/couch_index/src/couch_index_updater.erl
+++ b/src/couch_index/src/couch_index_updater.erl
@@ -219,7 +219,7 @@ purge_index(Db, Mod, IdxState) ->
                 {ok, StateAcc} = Mod:purge(Db, PurgeSeq, [{Id, Revs}], Acc),
                 StateAcc
             end,
-            {ok, NewStateAcc} = couch_db:fold_purged_docs(
+            {ok, NewStateAcc} = couch_db:fold_purge_infos(
                 Db,
                 IdxPurgeSeq,
                 FoldFun,

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 13/33: WIP - bt engine

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit fac4239d95a96b815161be768df4fb05a0cd2e0a
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:03:59 2018 -0500

    WIP - bt engine
---
 src/couch/src/couch_bt_engine.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 899a915..bbb20d9 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -820,7 +820,7 @@ init_state(FilePath, Fd, Header0, Options) ->
         {reduce, fun ?MODULE:purge_tree_reduce/2}
     ]),
 
-    PurgeSeqTreeState = couch_bt_engine_header:upurge_tree_state(Header),
+    PurgeSeqTreeState = couch_bt_engine_header:purge_seq_tree_state(Header),
     {ok, PurgeSeqTree} = couch_btree:open(PurgeSeqTreeState, Fd, [
         {split, fun ?MODULE:purge_seq_tree_split/1},
         {join, fun ?MODULE:purge_seq_tree_join/2},

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 15/33: WIP - couch_db_engine.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 49ebf8e29a93958c50d5b071df791b0a82c97efb
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:05:51 2018 -0500

    WIP - couch_db_engine.erl
---
 src/couch/src/couch_db_engine.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index 8199118..5ac9865 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -683,7 +683,7 @@
     serialize_doc/2,
     write_doc_body/2,
     write_doc_infos/3,
-    purge_doc_revs/3,
+    purge_docs/3,
     commit_data/1,
 
     open_write_stream/2,
@@ -900,9 +900,9 @@ write_doc_infos(#db{} = Db, DocUpdates, LocalDocs) ->
     {ok, Db#db{engine = {Engine, NewSt}}}.
 
 
-purge_doc_revs(#db{} = Db, DocUpdates, Purges) ->
+purge_docs(#db{} = Db, DocUpdates, Purges) ->
     #db{engine = {Engine, EngineState}} = Db,
-    {ok, NewSt} = Engine:purge_doc_revs(
+    {ok, NewSt} = Engine:purge_docs(
         EngineState, DocUpdates, Purges),
     {ok, Db#db{engine = {Engine, NewSt}}}.
 

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 03/33: WIP - chttpd_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bf22bb1ca5ade221bdf97bdee502fea7ab9966a1
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 09:51:46 2018 -0500

    WIP - chttpd_db.erl
---
 src/chttpd/src/chttpd_db.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 7be5513..e2e920f 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -968,7 +968,7 @@ update_doc_result_to_json(DocId, Error) ->
 purge_results_to_json([], []) ->
     {201, []};
 purge_results_to_json([{DocId, _Revs} | RIn], [{ok, PRevs} | ROut]) ->
-    {Code, Results} = purge_results_to_json(RestIn, RestOut),
+    {Code, Results} = purge_results_to_json(RIn, ROut),
     {Code, [{DocId, couch_doc:revs_to_strs(PRevs)} | Results]};
 purge_results_to_json([{DocId, _Revs} | RIn], [{accepted, PRevs} | ROut]) ->
     {Code, Results} = purge_results_to_json(RIn, ROut),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 30/33: WIP - test engine suite

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 412755bffdae1a2a42973b06edd6f81c7405c3f6
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 15:02:06 2018 -0500

    WIP - test engine suite
---
 src/couch/src/test_engine_compaction.erl    | 2 +-
 src/couch/src/test_engine_get_set_props.erl | 4 ++--
 src/couch/src/test_engine_util.erl          | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/couch/src/test_engine_compaction.erl b/src/couch/src/test_engine_compaction.erl
index 18bf938..4656084 100644
--- a/src/couch/src/test_engine_compaction.erl
+++ b/src/couch/src/test_engine_compaction.erl
@@ -258,7 +258,7 @@ ignore_cet_compact_purged_docs_limit() ->
 
     % check that after compaction only purged_docs_limit purge_requests
     % are in purge_tree
-    PurgedDocsLimit = Engine:get_purged_docs_limit(St5),
+    PurgedDocsLimit = Engine:get_purge_infos_limit(St5),
     OldestPSeq = Engine:get_oldest_purge_seq(St5),
     {ok, PurgedIdRevs2} = Engine:fold_purge_infos(
         St5, OldestPSeq - 1, fun fold_fun/2, [], []),
diff --git a/src/couch/src/test_engine_get_set_props.erl b/src/couch/src/test_engine_get_set_props.erl
index ac6aca8..74cbd44 100644
--- a/src/couch/src/test_engine_get_set_props.erl
+++ b/src/couch/src/test_engine_get_set_props.erl
@@ -34,8 +34,8 @@ cet_default_props() ->
     ?assertEqual(true, is_integer(Engine:get_disk_version(St))),
     ?assertEqual(0, Engine:get_update_seq(St)),
     ?assertEqual(0, Engine:get_purge_seq(St)),
-    ?assertEqual(true, is_integer(Engine:get_purged_docs_limit(St))),
-    ?assertEqual(true, Engine:get_purged_docs_limit(St) > 0),
+    ?assertEqual(true, is_integer(Engine:get_purge_infos_limit(St))),
+    ?assertEqual(true, Engine:get_purge_infos_limit(St) > 0),
     ?assertEqual(dso, Engine:get_security(St)),
     ?assertEqual(1000, Engine:get_revs_limit(St)),
     ?assertMatch(<<_:32/binary>>, Engine:get_uuid(St)),
diff --git a/src/couch/src/test_engine_util.erl b/src/couch/src/test_engine_util.erl
index 3e6d2d6..7ff8537 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -460,7 +460,7 @@ db_props_as_term(Engine, St) ->
         get_disk_version,
         get_update_seq,
         get_purge_seq,
-        get_purged_docs_limit,
+        get_purge_infos_limit,
         get_security,
         get_revs_limit,
         get_uuid,

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 23/33: WIP - couch_mrview_purge_docs_tests.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ca347eeb27a360f3dd087e82d11425e94113da13
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:16:57 2018 -0500

    WIP - couch_mrview_purge_docs_tests.erl
---
 src/couch_mrview/test/couch_mrview_purge_docs_tests.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
index 5ab4f21..b4af2c5 100644
--- a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
+++ b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
@@ -140,7 +140,7 @@ test_purge_with_compact1(Db) ->
 
         {ok, Db2} = couch_db:reopen(Db1),
         _Result1 = run_query(Db2, []),
-        {ok, PurgedIdRevs} = couch_db:fold_purged_docs(
+        {ok, PurgedIdRevs} = couch_db:fold_purge_infos(
             Db2,
             0,
             fun fold_fun/2,
@@ -188,7 +188,7 @@ test_purge_with_compact2(Db) ->
         % to mrview
         {ok, Db2} = couch_db:reopen(Db1),
         _Result1 = run_query(Db2, []),
-        {ok, PurgedIdRevs} = couch_db:fold_purged_docs(
+        {ok, PurgedIdRevs} = couch_db:fold_purge_infos(
             Db2,
             0,
             fun fold_fun/2,
@@ -206,7 +206,7 @@ test_purge_with_compact2(Db) ->
         % check the remaining purge requests in purge tree
         {ok, Db4} = couch_db:reopen(Db3),
         {ok, OldestPSeq} = couch_db:get_oldest_purge_seq(Db4),
-        {ok, PurgedIdRevs2} = couch_db:fold_purged_docs(
+        {ok, PurgedIdRevs2} = couch_db:fold_purge_infos(
             Db4,
             OldestPSeq - 1,
             fun fold_fun/2,

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 19/33: WIP - fabric API - fabric_rpc.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e077e92b7d6619651c3dbf182413548f4ae5ace2
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:07:19 2018 -0500

    WIP - fabric API - fabric_rpc.erl
---
 src/fabric/src/fabric_rpc.erl | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index d493da7..462996a 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -259,13 +259,7 @@ get_purge_seq(DbName, Options) ->
     with_db(DbName, Options, {couch_db, get_purge_seq, []}).
 
 purge_docs(DbName, UUIdsIdsRevs, Options) ->
-    case proplists:get_value(replicated_changes, Options) of
-        true ->
-            X = replicated_changes;
-        _ ->
-            X = interactive_edit
-    end,
-    with_db(DbName, Options, {couch_db, purge_docs, [UUIdsIdsRevs, X]}).
+    with_db(DbName, Options, {couch_db, purge_docs, [UUIdsIdsRevs, Options]}).
 
 %% @equiv group_info(DbName, DDocId, [])
 group_info(DbName, DDocId) ->

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 04/33: WIP - couch_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit cb0ef63ef7d5330750a7aeba17386ccb4bd46206
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 09:51:54 2018 -0500

    WIP - couch_db.erl
---
 src/couch/src/couch_db.erl | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index b0b5d9f..2a9e56d 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -384,13 +384,14 @@ purge_docs(Db, IdRevs) ->
     Rev :: {non_neg_integer(), binary()},
     PurgeOption :: interactive_edit | replicated_changes,
     Reply :: {ok, []} | {ok, [Rev]}.
-purge_docs(#db{main_pid = Pid}, UUIdsIdsRevs, Options) ->
+purge_docs(#db{main_pid = Pid} = Db, UUIdsIdsRevs, Options) ->
     increment_stat(Db, [couchdb, database_purges]),
-    gen_server:call(Pid, {purge_docs, UUIdsIdsRevs, Options});
+    gen_server:call(Pid, {purge_docs, UUIdsIdsRevs, Options}).
 
 -spec get_purge_infos(#db{}, [UUId]) -> [PurgeInfo] when
     UUId :: binary(),
     PurgeInfo :: {PurgeSeq, UUId, Id, [Rev]} | not_found,
+    PurgeSeq :: non_neg_integer(),
     Id :: binary(),
     Rev :: {non_neg_integer(), binary()}.
 get_purge_infos(Db, UUIDs) ->
@@ -425,7 +426,7 @@ get_minimum_purge_seq(#db{} = Db) ->
         {start_key, list_to_binary(?LOCAL_DOC_PREFIX + "purge-")},
         {end_key_gt, list_to_binary(?LOCAL_DOC_PREFIX + "purge.")}
     ],
-    {ok, MinIdxSeq} = couch_db:fold_local_docs(Db, FoldFun, InitSeq, Opts),
+    {ok, MinIdxSeq} = couch_db:fold_local_docs(Db, FoldFun, InitMinSeq, Opts),
     FinalSeq = case MinIdxSeq < PurgeSeq - PurgeInfosLimit of
         true -> MinIdxSeq;
         false -> erlang:max(0, PurgeSeq - PurgeInfosLimit)
@@ -439,7 +440,7 @@ get_minimum_purge_seq(#db{} = Db) ->
     FinalSeq.
 
 
-purge_client_exists(DbName, DocID, Props) ->
+purge_client_exists(DbName, DocId, Props) ->
     % Warn about clients that have not updated their purge
     % checkpoints in the last "index_lag_warn_seconds"
     LagWindow = config:get_integer(
@@ -450,14 +451,14 @@ purge_client_exists(DbName, DocID, Props) ->
     LagThreshold = NowSecs - LagWindow,
 
     try
-        CheckFun = get_purge_client_fun(Props),
+        CheckFun = get_purge_client_fun(DocId, Props),
         Exists = CheckFun(DbName, DocId, Props),
         if not Exists -> ok; true ->
             Updated = couch_util:get_value(<<"updated_on">>, Props),
             if is_integer(Updated) and Updated > LagThreshold -> ok; true ->
-                Diff = NowSecs - LU,
+                Diff = NowSecs - Updated,
                 Fmt = "Purge checkpint '~s' not updated in ~p seconds",
-                couch_log:error(Fmt, [DocId, NowSecs - LU])
+                couch_log:error(Fmt, [DocId, Diff])
             end
         end,
         Exists
@@ -468,13 +469,13 @@ purge_client_exists(DbName, DocID, Props) ->
     end.
 
 
-get_purge_client_fun(DocId, Props) -
+get_purge_client_fun(DocId, Props) ->
     M0 = couch_util:get_value(<<"verify_module">>, Props),
-    try
-        M = binary_to_existing_atom(M0, latin1)
+    M = try
+        binary_to_existing_atom(M0, latin1)
     catch error:badarg ->
-        Fmt = "Missing index module '~s' for purge checkpoint '~s'",
-        couch_log:error(Fmt, [M0, DocId]),
+        Fmt1 = "Missing index module '~s' for purge checkpoint '~s'",
+        couch_log:error(Fmt1, [M0, DocId]),
         throw(failed)
     end,
 
@@ -483,8 +484,8 @@ get_purge_client_fun(DocId, Props) -
         F = binary_to_existing_atom(F0, latin1),
         fun M:F/2
     catch error:badarg ->
-        Fmt = "Missing function '~s' in '~s' for purge checkpoint '~s'",
-        couch_log:error(Fmt, [F0, M0, DocId]),
+        Fmt2 = "Missing function '~s' in '~s' for purge checkpoint '~s'",
+        couch_log:error(Fmt2, [F0, M0, DocId]),
         throw(failed)
     end.
 

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 29/33: WIP - fabric clustered API

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f6d6bb5a0128c58a61701675b5c6b68a40290529
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:41:59 2018 -0500

    WIP - fabric clustered API
---
 src/fabric/src/fabric.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index 40d729c..b2e71dc 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -139,7 +139,7 @@ set_security(DbName, SecObj, Options) ->
     fabric_db_meta:set_security(dbname(DbName), SecObj, opts(Options)).
 
 %% @doc sets the upper bound for the number of stored purge requests
--spec set_purged_docs_limit(dbname(), pos_integer(), [option()]) -> ok.
+-spec set_purge_infos_limit(dbname(), pos_integer(), [option()]) -> ok.
 set_purge_infos_limit(DbName, Limit, Options)
         when is_integer(Limit), Limit > 0 ->
     fabric_db_meta:set_purge_infos_limit(dbname(DbName), Limit, opts(Options)).

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 02/33: WIP - couch_db_updater.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 14a1ad3dbdc6ac60ae6575ed1fad40e8aeba9bd2
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 09:11:56 2018 -0500

    WIP - couch_db_updater.erl
---
 src/couch/src/couch_db_updater.erl | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index b2bcf1e..23a77fb 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -98,17 +98,19 @@ handle_call({set_purge_infos_limit, Limit}, _From, Db) ->
     ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
     {reply, ok, Db2};
 
-handle_call({purge_docs, PurgeReqs0}, _From, Db) ->
-    % First filter out any purge requests we've already
-    % processed.
-    UUIDs = [UUID || {UUID, _Id, _Revs} <- PurgeReqs0],
-    {ok, PurgeInfos} = couch_db:load_purge_infos(Db, UUIDs),
-    PurgeReqs = lists:foldr(fun
-        ({not_found, PReq}, Acc) -> [PReq | Acc];
-        ({{_, _, _, _}, _}, Acc) -> Acc
-    end, lists:zip(PurgeInfos, PurgeReqs0)),
-
-    % Processing any remaining purge requests
+handle_call({purge_docs, PurgeReqs0, Options}, _From, Db) ->
+    % Filter out any previously applied updates during
+    % internal replication
+    IsRepl = lists:member(replicated_changes, Options),
+    PurgeReqs = if not IsRepl -> PurgeReqs0; true ->
+        UUIDs = [UUID || {UUID, _Id, _Revs} <- PurgeReqs0],
+        {ok, PurgeInfos} = couch_db:load_purge_infos(Db, UUIDs),
+        lists:flatmap(fun
+            ({not_found, PReq}) -> [PReq];
+            ({{_, _, _, _}, _}) -> []
+        end, lists:zip(PurgeInfos, PurgeReqs0))
+    end,
+
     Ids = [Id || {_UUID, Id, _Revs} <- PurgeReqs],
     DocInfos = couch_db_engine:open_docs(Db, Ids),
     UpdateSeq = couch_db_engine:get_update_seq(Db),
@@ -689,7 +691,7 @@ purge_docs([Req | RestReqs], [FDI | RestInfos], USeq, PSeq, Acc) ->
     {Pairs, PInfos, Replies} = Acc,
     NewAcc = {
         [Pair | Pairs],
-        [{PSeq, UUID, DocId, Revs} | PInfos],
+        [{PSeq + 1, UUID, DocId, Revs} | PInfos],
         [{ok, RemovedRevs} | Replies]
     },
     purge_docs(RestReqs, RestInfos, NewUSeq, PSeq + 1, NewAcc).

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 17/33: WIP - read repair fabric_doc_open_revs

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6b62e0ebd4434d3c6b4d6d9f95ad4f1e2689c6b5
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:06:32 2018 -0500

    WIP - read repair fabric_doc_open_revs
---
 src/fabric/src/fabric_doc_open_revs.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/fabric/src/fabric_doc_open_revs.erl b/src/fabric/src/fabric_doc_open_revs.erl
index a020ba6..bb93568 100644
--- a/src/fabric/src/fabric_doc_open_revs.erl
+++ b/src/fabric/src/fabric_doc_open_revs.erl
@@ -30,7 +30,7 @@
     latest,
     replies = [],
     node_id_revs = [],
-    repair = false,
+    repair = false
 }).
 
 go(DbName, Id, Revs, Options) ->
@@ -109,14 +109,14 @@ handle_message({ok, RawReplies}, Worker, State) ->
             {NewReplies0, MinCount} = dict_replies(PrevReplies, RawReplies),
             {NewReplies0, MinCount >= R, false}
     end,
-    NewNodeIdRevs = if Woker == nil -> PrevNodeIdRevs; true ->
+    NewNodeIdRevs = if Worker == nil -> PrevNodeIdRevs; true ->
         IdRevs = lists:foldl(fun
             ({ok, #doc{id = Id, revs = {Pos, [Rev | _]}}}, Acc) ->
                 [{Id, {Pos, Rev}} | Acc];
             (_, Acc) ->
                 Acc
         end, [], RawReplies),
-        [{Worker#worker.shard, IdRevs} | PrevNodeIdRevs]
+        [{Worker#shard.node, IdRevs} | PrevNodeIdRevs]
     end,
 
     Complete = (ReplyCount =:= (WorkerCount - 1)),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 10/33: WIP - read repair fabric_doc_open.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit af2076bdd60bb01f0e4e0a7ef2cf493005187565
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 10:30:25 2018 -0500

    WIP - read repair fabric_doc_open.erl
---
 src/fabric/src/fabric_doc_open.erl | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/fabric/src/fabric_doc_open.erl b/src/fabric/src/fabric_doc_open.erl
index 445cfbb..bf17528 100644
--- a/src/fabric/src/fabric_doc_open.erl
+++ b/src/fabric/src/fabric_doc_open.erl
@@ -85,8 +85,8 @@ handle_message({rexi_EXIT, _Reason}, Worker, Acc) ->
 handle_message(Reply, Worker, Acc) ->
     NewReplies = fabric_util:update_counter(Reply, 1, Acc#acc.replies),
     NewNodeIdRevs = case Reply of
-        {ok #doc{id = Id, revs = {Pos, [Rev | _]}} ->
-            [{Worker#shard.node {Id, [{Pos, Rev}]}} | Acc#acc.node_id_revs];
+        {ok, #doc{id = Id, revs = {Pos, [Rev | _]}}} ->
+            [{Worker#shard.node, {Id, [{Pos, Rev}]}} | Acc#acc.node_id_revs];
         _ ->
             Acc#acc.node_id_revs
     end,
@@ -327,7 +327,7 @@ handle_message_reply_test() ->
         {ok, Acc0#acc{
             workers=[Worker0, Worker1],
             replies=[fabric_util:kv(foo,1)],
-            replies_by_node=[{undefined, foo}]
+            node_id_revs=[{undefined, foo}]
         }},
         handle_message(foo, Worker2, Acc0)
     ),
@@ -336,7 +336,7 @@ handle_message_reply_test() ->
         {ok, Acc0#acc{
             workers=[Worker0, Worker1],
             replies=[fabric_util:kv(bar,1), fabric_util:kv(foo,1)],
-            replies_by_node=[{undefined, bar}]
+            node_id_revs=[{undefined, bar}]
         }},
         handle_message(bar, Worker2, Acc0#acc{
             replies=[fabric_util:kv(foo,1)]
@@ -349,7 +349,7 @@ handle_message_reply_test() ->
 
     ?assertEqual(
         {stop, Acc0#acc{workers=[],replies=[fabric_util:kv(foo,1)],
-            replies_by_node=[{undefined, foo}]}},
+            node_id_revs=[{undefined, foo}]}},
         handle_message(foo, Worker0, Acc0#acc{workers=[Worker0]})
     ),
 
@@ -357,12 +357,12 @@ handle_message_reply_test() ->
         {stop, Acc0#acc{
             workers=[],
             replies=[fabric_util:kv(bar,1), fabric_util:kv(foo,1)],
-            replies_by_node =[{undefined, bar}, {undefined, foo}]
+            node_id_revs =[{undefined, bar}, {undefined, foo}]
         }},
         handle_message(bar, Worker0, Acc0#acc{
             workers=[Worker0],
             replies=[fabric_util:kv(foo,1)],
-            replies_by_node=[{undefined, foo}]
+            node_id_revs=[{undefined, foo}]
         })
     ),
 
@@ -375,12 +375,12 @@ handle_message_reply_test() ->
             replies=[fabric_util:kv(foo,2)],
             state=r_met,
             q_reply=foo,
-            replies_by_node =[{undefined, foo}, {undefined, foo}]
+            node_id_revs =[{undefined, foo}, {undefined, foo}]
         }},
         handle_message(foo, Worker1, Acc0#acc{
             workers=[Worker0, Worker1],
             replies=[fabric_util:kv(foo,1)],
-            replies_by_node =[{undefined, foo}]
+            node_id_revs =[{undefined, foo}]
         })
     ),
 
@@ -391,7 +391,7 @@ handle_message_reply_test() ->
             replies=[fabric_util:kv(foo,1)],
             state=r_met,
             q_reply=foo,
-            replies_by_node =[{undefined, foo}]
+            node_id_revs =[{undefined, foo}]
         }},
         handle_message(foo, Worker0, Acc0#acc{r=1})
     ),
@@ -402,13 +402,13 @@ handle_message_reply_test() ->
             replies=[fabric_util:kv(bar,1), fabric_util:kv(foo,2)],
             state=r_met,
             q_reply=foo,
-            replies_by_node =[{undefined, foo}, {undefined, foo},
+            node_id_revs =[{undefined, foo}, {undefined, foo},
                 {undefined, bar}]
         }},
         handle_message(foo, Worker0, Acc0#acc{
             workers=[Worker0],
             replies=[fabric_util:kv(bar,1), fabric_util:kv(foo,1)],
-            replies_by_node =[{undefined, foo}, {undefined, bar}]
+            node_id_revs =[{undefined, foo}, {undefined, bar}]
         })
     ),
 

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 08/33: WIP - couch_db_updater.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e5bb653e60a3b6e947012d8872c570af82e7baa0
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 10:26:16 2018 -0500

    WIP - couch_db_updater.erl
---
 src/couch/src/couch_db_updater.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index 23a77fb..7ba3ce8 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -118,7 +118,7 @@ handle_call({purge_docs, PurgeReqs0, Options}, _From, Db) ->
 
     InitAcc = {[], [], []},
     {Pairs, PInfos, Replies} = purge_docs(
-            Db, PurgeReqs, DocInfos, UpdateSeq, PurgeSeq, InitAcc),
+            PurgeReqs, DocInfos, UpdateSeq, PurgeSeq, InitAcc),
 
     Db2 = if Pairs == [] -> Db; true ->
         {ok, Db1} = couch_db_engine:purge_docs(Db, Pairs, PInfos),

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 21/33: WIP - test suite

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 17fadec669dd82af6782f15af6927169735fc690
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:08:18 2018 -0500

    WIP - test suite
---
 src/couch/src/test_engine_util.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/test_engine_util.erl b/src/couch/src/test_engine_util.erl
index 68e83b1..745e00f 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -140,7 +140,7 @@ apply_batch(Engine, St, [{purge, {Id, Revs}}]) ->
             St;
         {Pair, _, {Id, PRevs}} ->
             UUID = couch_uuids:new(),
-            {ok, NewSt} = Engine:purge_doc_revs(
+            {ok, NewSt} = Engine:purge_docs(
                 St, [Pair], [{UUID, Id, PRevs}]),
             NewSt
     end;

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 06/33: WIP - test suite upgrades

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit cd6452aa95f6ed407c5d920a9ff83f7cf463910b
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 10:25:49 2018 -0500

    WIP - test suite upgrades
---
 src/couch/src/test_engine_compaction.erl | 16 +++-------------
 src/couch/src/test_engine_util.erl       | 24 ++++--------------------
 2 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/src/couch/src/test_engine_compaction.erl b/src/couch/src/test_engine_compaction.erl
index 51970ee..665b7d8 100644
--- a/src/couch/src/test_engine_compaction.erl
+++ b/src/couch/src/test_engine_compaction.erl
@@ -209,19 +209,9 @@ cet_recompact_purge() ->
         {'$gen_cast', {compact_done, Engine, Term0}} ->
             Term0;
         {'DOWN', Ref, _, _, Reason} ->
-            erlang:error({compactor_died, Reason});
-        {'$gen_call', {NewPid, Ref2}, get_disposable_purge_seq} ->
-            NewPid!{Ref2, {ok, 0}},
-            receive
-                {'$gen_cast', {compact_done, Engine, Term0}} ->
-                    Term0;
-                {'DOWN', Ref, _, _, Reason} ->
-                    erlang:error({compactor_died, Reason})
-                after 10000 ->
-                    erlang:error(compactor_timed_out)
-            end
-        after 10000 ->
-            erlang:error(compactor_timed_out)
+            erlang:error({compactor_died, Reason})
+    after 10000 ->
+        erlang:error(compactor_timed_out)
     end,
 
     {ok, St6, undefined} = Engine:finish_compaction(St5, DbName, [], NewTerm),
diff --git a/src/couch/src/test_engine_util.erl b/src/couch/src/test_engine_util.erl
index bd49969..68e83b1 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -627,26 +627,10 @@ compact(Engine, St1, DbPath) ->
     Term = receive
         {'$gen_cast', {compact_done, Engine, Term0}} ->
             Term0;
-            erlang:error({compactor_died, Reason});
-        {'$gen_call', {Pid, Ref2}, get_disposable_purge_seq} ->
-            % assuming no client exists (no internal replications or indexes)
-            PSeq = Engine:get_purge_seq(St2),
-            OldestPSeq = Engine:get_oldest_purge_seq(St2),
-            PDocsLimit = Engine:get_purged_docs_limit(St2),
-            ExpectedDispPSeq = PSeq - PDocsLimit,
-            DisposablePSeq = if ExpectedDispPSeq > 0 -> ExpectedDispPSeq;
-                    true -> OldestPSeq - 1 end,
-            Pid!{Ref2, {ok, DisposablePSeq}},
-            receive
-                {'$gen_cast', {compact_done, Engine, Term0}} ->
-                    Term0;
-                {'DOWN', Ref, _, _, Reason} ->
-                    erlang:error({compactor_died, Reason})
-                after 10000 ->
-                    erlang:error(compactor_timed_out)
-            end
-        after ?COMPACTOR_TIMEOUT ->
-            erlang:error(compactor_timed_out)
+        {'DOWN', Ref, _, _, Reason} ->
+            erlang:error({compactor_died, Reason})
+    after ?COMPACTOR_TIMEOUT ->
+        erlang:error(compactor_timed_out)
     end,
 
     {ok, St2, DbName, Pid, Term}.

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 26/33: WIP - update couch_mrview

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit abac0e04805ce57e62c188de3f63f0a7d42540b3
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:28:46 2018 -0500

    WIP - update couch_mrview
---
 src/couch_mrview/src/couch_mrview_index.erl | 30 ++++++++---------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index 3f04f8f..1b0adf0 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -299,21 +299,7 @@ maybe_create_local_purge_doc(DbName, #doc{}=DDoc) ->
 
 
 update_local_purge_doc(Db, State) ->
-    Sig = couch_index_util:hexsig(get(signature, State)),
-    Doc = couch_doc:from_json_obj({[
-        {<<"_id">>, couch_mrview_util:get_local_purge_doc_id(Sig)},
-        {<<"purge_seq">>, get(purge_seq, State)},
-        {<<"timestamp_utc">>, couch_util:utc_string()},
-        {<<"verify_module">>, <<"couch_mrview_index">>},
-        {<<"verify_function">>, <<"verify_index_exists">>},
-        {<<"verify_options">>, {[
-            {<<"dbname">>, get(db_name, State)},
-            {<<"ddoc_id">>, get(idx_name, State)},
-            {<<"signature">>, Sig}
-        ]}},
-        {<<"type">>, <<"mrview">>}
-    ]}),
-    couch_db:update_doc(Db, Doc, []).
+    update_local_purge_doc(Db, State, get(purge_seq, State)).
 
 
 update_local_purge_doc(Db, State, PSeq) ->
@@ -321,18 +307,18 @@ update_local_purge_doc(Db, State, PSeq) ->
     DocId = couch_mrview_util:get_local_purge_doc_id(Sig),
     case couch_db:open_doc(Db, DocId, []) of
         {not_found, _Reason} ->
+            {Mega, Secs, _} = os:timestamp(),
+            NowSecs = Mega * 1000000 + Secs,
             Doc = couch_doc:from_json_obj({[
                 {<<"_id">>, DocId},
+                {<<"type">>, <<"mrview">>},
                 {<<"purge_seq">>, PSeq},
-                {<<"timestamp_utc">>, couch_util:utc_string()},
+                {<<"updated_on">>, NowSecs},
                 {<<"verify_module">>, <<"couch_mrview_index">>},
                 {<<"verify_function">>, <<"verify_index_exists">>},
-                {<<"verify_options">>, {[
-                    {<<"dbname">>, State#mrst.db_name},
-                    {<<"ddoc_id">>, State#mrst.idx_name},
-                    {<<"signature">>, Sig}
-                ]}},
-                {<<"type">>, <<"mrview">>}
+                {<<"dbname">>, State#mrst.db_name},
+                {<<"ddoc_id">>, State#mrst.idx_name},
+                {<<"signature">>, Sig}
             ]}),
             couch_db:update_doc(Db, Doc, []);
         {ok, _LocalPurgeDoc} ->

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 28/33: WIP - chttpd_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 8db8ebdffc17190d02cc8ab35f56b93662cfe150
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:32:27 2018 -0500

    WIP - chttpd_db.erl
---
 src/chttpd/src/chttpd_db.erl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index befcc12..65cd09e 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -604,19 +604,19 @@ db_req(#httpd{method='GET',path_parts=[_,<<"_revs_limit">>]}=Req, Db) ->
 db_req(#httpd{path_parts=[_,<<"_revs_limit">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "PUT,GET");
 
-db_req(#httpd{method='PUT',path_parts=[_,<<"_purged_docs_limit">>]}=Req, Db) ->
+db_req(#httpd{method='PUT',path_parts=[_,<<"_purge_infos_limit">>]}=Req, Db) ->
     Limit = chttpd:json_body(Req),
     Options = [{user_ctx, Req#httpd.user_ctx}],
     case chttpd:json_body(Req) of
         Limit when is_integer(Limit), Limit > 0 ->
-            ok = fabric:set_purged_docs_limit(Db, Limit, Options),
+            ok = fabric:set_purge_infos_limit(Db, Limit, Options),
             send_json(Req, {[{<<"ok">>, true}]});
         _->
             throw({bad_request, "`purged_docs_limit` must be positive integer"})
     end;
 
-db_req(#httpd{method='GET',path_parts=[_,<<"_purged_docs_limit">>]}=Req, Db) ->
-    send_json(Req, fabric:get_purged_docs_limit(Db));
+db_req(#httpd{method='GET',path_parts=[_,<<"_purged_infos_limit">>]}=Req, Db) ->
+    send_json(Req, fabric:get_purge_infos_limit(Db));
 
 % Special case to enable using an unencoded slash in the URL of design docs,
 % as slashes in document IDs must otherwise be URL encoded.

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 11/33: WIP - chttpd_db.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ca898e9f1d77500450dfe66cf5810c2d0c12b480
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:03:17 2018 -0500

    WIP - chttpd_db.erl
---
 src/chttpd/src/chttpd_db.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index e2e920f..befcc12 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -503,8 +503,8 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_purge">>]}=Req, Db) ->
     {IdsRevs} = chttpd:json_body_obj(Req),
     IdsRevs2 = [{Id, couch_doc:parse_revs(Revs)} || {Id, Revs} <- IdsRevs],
     {ok, Results} = fabric:purge_docs(Db, IdsRevs2, Options),
-    {Code, JSON} = purge_results_to_json(IdsRevs2, Results),
-    send_json(Req, Code, {[{<<"purge_seq">>, null}, {<<"purged">>, JSON}]});
+    {Code, Json} = purge_results_to_json(IdsRevs2, Results),
+    send_json(Req, Code, {[{<<"purge_seq">>, null}, {<<"purged">>, {Json}}]});
 
 db_req(#httpd{path_parts=[_,<<"_purge">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "POST");

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 31/33: WIP - add test engine suite

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1120c05bd29d64c81f29f6fc9f84bc79075ed0dd
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 15:33:48 2018 -0500

    WIP - add test engine suite
---
 src/couch/src/test_engine_compaction.erl       |  2 +-
 src/couch/src/test_engine_fold_purge_infos.erl |  2 +-
 src/couch/src/test_engine_purge_docs.erl       |  2 +-
 src/couch/src/test_engine_util.erl             | 10 +++++-----
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/couch/src/test_engine_compaction.erl b/src/couch/src/test_engine_compaction.erl
index 4656084..727e188 100644
--- a/src/couch/src/test_engine_compaction.erl
+++ b/src/couch/src/test_engine_compaction.erl
@@ -278,4 +278,4 @@ local_docid(I) ->
 
 
 fold_fun({_PSeq, _UUID, Id, Revs}, Acc) ->
-    [{Id, Revs} | Acc].
+    {ok, [{Id, Revs} | Acc]}.
diff --git a/src/couch/src/test_engine_fold_purge_infos.erl b/src/couch/src/test_engine_fold_purge_infos.erl
index 07131e4..74556c2 100644
--- a/src/couch/src/test_engine_fold_purge_infos.erl
+++ b/src/couch/src/test_engine_fold_purge_infos.erl
@@ -125,7 +125,7 @@ cet_id_rev_repeated() ->
 
 
 fold_fun({_PSeq, _UUID, Id, Revs}, Acc) ->
-    [{Id, Revs} | Acc].
+    {ok, [{Id, Revs} | Acc]}.
 
 
 docid(I) ->
diff --git a/src/couch/src/test_engine_purge_docs.erl b/src/couch/src/test_engine_purge_docs.erl
index 268011b..21e2051 100644
--- a/src/couch/src/test_engine_purge_docs.erl
+++ b/src/couch/src/test_engine_purge_docs.erl
@@ -168,4 +168,4 @@ cet_add_two_purge_one() ->
 
 
 fold_fun({_Pseq, _UUID, Id, Revs}, Acc) ->
-    [{Id, Revs} | Acc].
\ No newline at end of file
+    {ok, [{Id, Revs} | Acc]}.
\ No newline at end of file
diff --git a/src/couch/src/test_engine_util.erl b/src/couch/src/test_engine_util.erl
index 7ff8537..c7edcbe 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -234,8 +234,8 @@ gen_write(Engine, St, {purge, {DocId, PrevRevs0, _}}, UpdateSeq) ->
         % Check if this doc has been purged before
         FoldFun = fun({_PSeq, _UUID, Id, _Revs}, _Acc) ->
             case Id of
-                DocId -> true;
-                _ -> false
+                DocId -> {stop, true};
+                _ -> {ok, false}
             end
         end,
         {ok, IsPurgedBefore} = Engine:fold_purge_infos(
@@ -259,8 +259,8 @@ gen_write(Engine, St, {purge, {DocId, PrevRevs0, _}}, UpdateSeq) ->
             % Check if these Revs have been purged before
             FoldFun = fun({_Pseq, _UUID, Id, Revs}, Acc) ->
                 case Id of
-                    DocId -> Acc ++ Revs;
-                    _ -> Acc
+                    DocId -> {ok, Acc ++ Revs};
+                    _ -> {ok, Acc}
                 end
             end,
             {ok, PurgedRevs} = Engine:fold_purge_infos(St, 0, FoldFun, [], []),
@@ -496,7 +496,7 @@ db_changes_as_term(Engine, St) ->
 db_purged_docs_as_term(Engine, St) ->
     StartPSeq = Engine:get_oldest_purge_seq(St) - 1,
     FoldFun = fun({PSeq, UUID, Id, Revs}, Acc) ->
-        [{PSeq, UUID, Id, Revs} | Acc]
+        {ok, [{PSeq, UUID, Id, Revs} | Acc]}
     end,
     {ok, PDocs} = Engine:fold_purge_infos(St, StartPSeq, FoldFun, [], []),
     lists:reverse(PDocs).

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 16/33: WIP - couch_db_updater.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit b72bc0c01df5bab8d4071fc0d3ec0f65a16ce8bf
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:06:09 2018 -0500

    WIP - couch_db_updater.erl
---
 src/couch/src/couch_db_updater.erl | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index 7ba3ce8..af935c7 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -661,7 +661,7 @@ purge_docs([Req | RestReqs], [FDI | RestInfos], USeq, PSeq, Acc) ->
             case couch_key_tree:remove_leafs(Tree, Revs) of
                 {_, []} ->
                     % No change
-                    {{not_found, not_found}, [], USeq};
+                    {no_change, [], USeq};
                 {[], Removed} ->
                     % Completely purged
                     {{FDI, not_found}, Removed, USeq};
@@ -686,11 +686,16 @@ purge_docs([Req | RestReqs], [FDI | RestInfos], USeq, PSeq, Acc) ->
                     {{FDI, NewFDI}, Removed, NewUpdateSeq}
             end;
         not_found ->
-            {{not_found, not_found}, [], USeq}
+            % Not found means nothing to change
+            {no_change, [], USeq}
     end,
     {Pairs, PInfos, Replies} = Acc,
+    NewPairs = case Pair of
+        no_change -> Pairs;
+        _ -> [Pair | Pairs]
+    end,
     NewAcc = {
-        [Pair | Pairs],
+        NewPairs,
         [{PSeq + 1, UUID, DocId, Revs} | PInfos],
         [{ok, RemovedRevs} | Replies]
     },

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 12/33: WIP - chttpd_purge_tests.erl

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ce7937392b0eb15549eae1b9e4f1d453443bb514
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:03:35 2018 -0500

    WIP - chttpd_purge_tests.erl
---
 src/chttpd/test/chttpd_purge_tests.erl | 43 +++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/chttpd/test/chttpd_purge_tests.erl b/src/chttpd/test/chttpd_purge_tests.erl
index 7900090..74055db 100644
--- a/src/chttpd/test/chttpd_purge_tests.erl
+++ b/src/chttpd/test/chttpd_purge_tests.erl
@@ -80,7 +80,13 @@ test_empty_purge_request(Url) ->
             [?CONTENT_JSON, ?AUTH], IdsRevs),
         ResultJson = ?JSON_DECODE(ResultBody),
         ?assert(Status =:= 201 orelse Status =:= 202),
-        ?assertEqual({[{<<"purged">>,{[]}}]}, ResultJson)
+        ?assertEqual(
+                {[
+                    {<<"purge_seq">>, null},
+                    {<<"purged">>,{[]}}
+                ]},
+                ResultJson
+            )
     end).
 
 
@@ -95,30 +101,29 @@ test_ok_purge_request(Url) ->
         {ok, _, _, Body3} = create_doc(Url, "doc3"),
         {Json3} = ?JSON_DECODE(Body3),
         Rev3 = couch_util:get_value(<<"rev">>, Json3, undefined),
-        IdsRevs = "{\"doc1\": [\"" ++ ?b2l(Rev1) ++ "\"], \"doc2\": [\"" ++
-            ?b2l(Rev2) ++ "\"], \"doc3\": [\"" ++ ?b2l(Rev3) ++ "\"] }",
+
+        IdsRevsEJson = {[
+            {<<"doc1">>, [Rev1]},
+            {<<"doc2">>, [Rev2]},
+            {<<"doc3">>, [Rev3]}
+        ]},
+        IdsRevs = binary_to_list(?JSON_ENCODE(IdsRevsEJson)),
 
         {ok, Status, _, ResultBody} = test_request:post(Url ++ "/_purge/",
             [?CONTENT_JSON, ?AUTH], IdsRevs),
         ResultJson = ?JSON_DECODE(ResultBody),
         ?assert(Status =:= 201 orelse Status =:= 202),
         ?assertEqual(
-            {[{<<"purged">>, {[
-                {<<"doc1">>, {[
-                    {<<"purged">>,[Rev1]},
-                    {<<"ok">>,true}
-                ]}},
-                {<<"doc2">>, {[
-                    {<<"purged">>,[Rev2]},
-                    {<<"ok">>,true}
-                ]}},
-                {<<"doc3">>, {[
-                    {<<"purged">>,[Rev3]},
-                    {<<"ok">>,true}
-                ]}}
-            ]}}]},
-            ResultJson
-        )
+                {[
+                    {<<"purge_seq">>, null},
+                    {<<"purged">>, {[
+                        {<<"doc1">>, [Rev1]},
+                        {<<"doc2">>, [Rev2]},
+                        {<<"doc3">>, [Rev3]}
+                    ]}}
+                ]},
+                ResultJson
+            )
     end).
 
 

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.

[couchdb] 27/33: WIP - clustered API fabric

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 537130ec798a7f479df2d1f8fe179b9d862dff6f
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Mar 26 13:32:18 2018 -0500

    WIP - clustered API fabric
---
 src/fabric/rebar.config           |  4 ++--
 src/fabric/src/fabric.erl         | 12 ++++++------
 src/fabric/src/fabric_db_meta.erl |  6 +++---
 src/fabric/src/fabric_rpc.erl     |  6 +++---
 4 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/fabric/rebar.config b/src/fabric/rebar.config
index 362c878..3f51af3 100644
--- a/src/fabric/rebar.config
+++ b/src/fabric/rebar.config
@@ -10,5 +10,5 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
-{cover_enabled, true}.
-{cover_print_enabled, true}.
+%{cover_enabled, true}.
+%{cover_print_enabled, true}.
diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index 1900f79..40d729c 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -21,7 +21,7 @@
     delete_db/2, get_db_info/1, get_doc_count/1, set_revs_limit/3,
     set_security/2, set_security/3, get_revs_limit/1, get_security/1,
     get_security/2, get_all_security/1, get_all_security/2,
-    get_purged_docs_limit/1, set_purged_docs_limit/3,
+    get_purge_infos_limit/1, set_purge_infos_limit/3,
     compact/1, compact/2]).
 
 % Documents
@@ -140,15 +140,15 @@ set_security(DbName, SecObj, Options) ->
 
 %% @doc sets the upper bound for the number of stored purge requests
 -spec set_purged_docs_limit(dbname(), pos_integer(), [option()]) -> ok.
-set_purged_docs_limit(DbName, Limit, Options)
+set_purge_infos_limit(DbName, Limit, Options)
         when is_integer(Limit), Limit > 0 ->
-    fabric_db_meta:set_purged_docs_limit(dbname(DbName), Limit, opts(Options)).
+    fabric_db_meta:set_purge_infos_limit(dbname(DbName), Limit, opts(Options)).
 
 %% @doc retrieves the upper bound for the number of stored purge requests
--spec get_purged_docs_limit(dbname()) -> pos_integer() | no_return().
-get_purged_docs_limit(DbName) ->
+-spec get_purge_infos_limit(dbname()) -> pos_integer() | no_return().
+get_purge_infos_limit(DbName) ->
     {ok, Db} = fabric_util:get_db(dbname(DbName), [?ADMIN_CTX]),
-    try couch_db:get_purged_docs_limit(Db) after catch couch_db:close(Db) end.
+    try couch_db:get_purge_infos_limit(Db) after catch couch_db:close(Db) end.
 
 get_security(DbName) ->
     get_security(DbName, [?ADMIN_CTX]).
diff --git a/src/fabric/src/fabric_db_meta.erl b/src/fabric/src/fabric_db_meta.erl
index 4fd9365..26e1b37 100644
--- a/src/fabric/src/fabric_db_meta.erl
+++ b/src/fabric/src/fabric_db_meta.erl
@@ -13,7 +13,7 @@
 -module(fabric_db_meta).
 
 -export([set_revs_limit/3, set_security/3, get_all_security/2,
-    set_purged_docs_limit/3]).
+    set_purge_infos_limit/3]).
 
 -include_lib("fabric/include/fabric.hrl").
 -include_lib("mem3/include/mem3.hrl").
@@ -49,9 +49,9 @@ handle_revs_message(Error, _, _Acc) ->
     {error, Error}.
 
 
-set_purged_docs_limit(DbName, Limit, Options) ->
+set_purge_infos_limit(DbName, Limit, Options) ->
     Shards = mem3:shards(DbName),
-    Workers = fabric_util:submit_jobs(Shards, set_purged_docs_limit, [Limit, Options]),
+    Workers = fabric_util:submit_jobs(Shards, set_purge_infos_limit, [Limit, Options]),
     Handler = fun handle_purge_message/3,
     Acc0 = {Workers, length(Workers) - 1},
     case fabric_util:recv(Workers, #shard.ref, Handler, Acc0) of
diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index 462996a..783764e 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -21,7 +21,7 @@
     delete_shard_db_doc/2]).
 -export([get_all_security/2, open_shard/2]).
 -export([compact/1, compact/2]).
--export([get_purge_seq/2, purge_docs/3, set_purged_docs_limit/3]).
+-export([get_purge_seq/2, purge_docs/3, set_purge_infos_limit/3]).
 
 -export([get_db_info/2, get_doc_count/2, get_update_seq/2,
          changes/4, map_view/5, reduce_view/5, group_info/3, update_mrview/4]).
@@ -202,8 +202,8 @@ get_all_security(DbName, Options) ->
 set_revs_limit(DbName, Limit, Options) ->
     with_db(DbName, Options, {couch_db, set_revs_limit, [Limit]}).
 
-set_purged_docs_limit(DbName, Limit, Options) ->
-    with_db(DbName, Options, {couch_db, set_purged_docs_limit, [Limit]}).
+set_purge_infos_limit(DbName, Limit, Options) ->
+    with_db(DbName, Options, {couch_db, set_purge_infos_limit, [Limit]}).
 
 open_doc(DbName, DocId, Options) ->
     with_db(DbName, Options, {couch_db, open_doc, [DocId, Options]}).

-- 
To stop receiving notification emails like this one, please contact
davisp@apache.org.