iilyak commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r815864063



##########
File path: src/smoosh/src/smoosh_channel.erl
##########
@@ -194,18 +231,144 @@ handle_info(check_window, State0) ->
         end,
     erlang:send_after(60 * 1000, self(), check_window),
     {noreply, FinalState};
-handle_info(pause, State0) ->
-    {ok, State} = code_change(nil, State0, nil),
+handle_info(start_recovery, #state{name = Name, waiting = Waiting0} = State0) 
->
+    RecActive = recover(active_file_name(Name)),
+    Waiting1 = lists:foldl(
+        fun(DbName, Acc) ->
+            case couch_db:is_compacting(DbName) of
+                true ->
+                    Priority = smoosh_server:get_priority(Name, DbName),
+                    smoosh_priority_queue:in(DbName, Priority, Priority, Acc);
+                false ->
+                    Acc
+            end
+        end,
+        Waiting0,
+        RecActive
+    ),
+    State1 = maybe_start_compaction(State0#state{paused = false, waiting = 
Waiting1}),
+    couch_log:notice(
+        "~p Previously active compaction jobs (if any) have been successfully 
recovered and restarted.",
+        [?MODULE]
+    ),
+    erlang:send_after(?ACTIVATE_DELAY_IN_MSEC, self(), activate),

Review comment:
       We might want to speed up the activation event by checking the state of 
`waiting`. 
   
   ```
   maybe_start_compaction(State) ->
        ....
           length(State#state.active) + length(State#state.starting) < 
Concurrency ->
               case smoosh_priority_queue:out(State#state.waiting) of
                   false ->
                       maybe_activate(State);
   ```
   
   ```
   maybe_activate(state#{activated = true} = State) ->
        State;
   maybe_activate(State) ->
        activate(State).
   
   activate(State) ->
        %% content of the `handle_info(activate, ...` clause
   ```
   
   ```
   handle_info(activate, #state{} = State) ->
        activate(State);
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to