couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject [29/43] couch-mrview commit: updated refs/heads/2971-count-distinct to f7c3c24
Date Wed, 01 Mar 2017 16:38:03 GMT
Update with couch_index_updater:update/3

Handle '$gen_cast' messages in receive


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/0d382f5f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/0d382f5f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/0d382f5f

Branch: refs/heads/2971-count-distinct
Commit: 0d382f5fd210b3413b3e4c07ad65458004821bf6
Parents: 1d5c6a5
Author: Jay Doane <jay.s.doane@gmail.com>
Authored: Mon Oct 10 13:19:56 2016 -0700
Committer: Jay Doane <jay.s.doane@gmail.com>
Committed: Mon Oct 10 13:19:56 2016 -0700

----------------------------------------------------------------------
 src/couch_mrview_compactor.erl | 47 ++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/0d382f5f/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index d5ea763..50e7eae 100644
--- a/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview_compactor.erl
@@ -149,32 +149,41 @@ compact(State) ->
 
 
 recompact(State) ->
-    RetryCount = config:get_integer("view_compaction", "recompact_retry_count",
-        ?DEFAULT_RECOMPACT_RETRY_COUNT),
-    recompact(State, RetryCount).
-
-recompact(State, 0) ->
-    couch_log:error("couch_mrview_compactor:recompact max retries exceeded ~p",
-        [State]),
-    {ok, State};
-recompact(State, Attempt) ->
+    recompact(State, recompact_retry_count()).
+
+recompact(_State, 0) ->
+    erlang:error(exceeded_recompact_retry_count);
+
+recompact(State, RetryCount) ->
+    Self = self(),
     link(State#mrst.fd),
     {Pid, Ref} = erlang:spawn_monitor(fun() ->
-        couch_index_updater:update(couch_mrview_index, State)
+        couch_index_updater:update(Self, couch_mrview_index, State)
     end),
+    recompact_loop(Pid, Ref, State, RetryCount).
+
+recompact_loop(Pid, Ref, State, RetryCount) ->
     receive
-        {'DOWN', Ref, _, _, Result} ->
+        {'$gen_cast', {new_state, State2}} ->
+            % We've made progress so reset RetryCount
+            recompact_loop(Pid, Ref, State2, recompact_retry_count());
+        {'DOWN', Ref, _, _, {updated, Pid, State2}} ->
             unlink(State#mrst.fd),
-            case Result of
-                {updated, Pid, State2} ->
-                    {ok, State2};
-                Error ->
-                    couch_log:info("couch_mrview_compactor:recompact error ~p",
-                        [Error]),
-                    recompact(State, Attempt - 1)
-            end
+            {ok, State2};
+        {'DOWN', Ref, _, _, Reason} ->
+            unlink(State#mrst.fd),
+            couch_log:warning("Error during recompaction: ~r", [Reason]),
+            recompact(State, RetryCount - 1)
     end.
 
+recompact_retry_count() ->
+    config:get_integer(
+        "view_compaction",
+        "recompact_retry_count",
+        ?DEFAULT_RECOMPACT_RETRY_COUNT
+    ).
+
+
 compact_log(LogBtree, BufferSize, Acc0) ->
     FoldFun = fun(KV, Acc) ->
         #acc{btree = Bt, kvs = Kvs, kvs_size = KvsSize} = Acc,


Mime
View raw message