iilyak commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r776321278
##########
File path: src/smoosh/src/smoosh_channel.erl
##########
@@ -194,21 +215,109 @@ handle_info(check_window, State0) ->
end,
erlang:send_after(60 * 1000, self(), check_window),
{noreply, FinalState};
+handle_info(persist_queue, State0) ->
+ #state{waiting = Queue} = State0,
+ write_state_to_file(State0),
+ smoosh_priority_queue:write_to_file(Queue),
+ Checkpoint =
+ config:get_integer(
+ "smoosh", "state_checkpoint_interval_in_sec",
?DEFAULT_CHECKPOINT_INTERVAL_IN_SEC
+ ) * 1000,
+ erlang:send_after(Checkpoint, self(), persist_queue),
+ {noreply, State0};
handle_info(pause, State0) ->
- {ok, State} = code_change(nil, State0, nil),
+ State = maybe_open_queue(State0),
{noreply, State#state{paused = true}};
handle_info(unpause, State0) ->
- {ok, State} = code_change(nil, State0, nil),
+ State = maybe_open_queue(State0),
{noreply, maybe_start_compaction(State#state{paused = false})}.
terminate(_Reason, _State) ->
ok.
-code_change(_OldVsn, #state{} = State, _Extra) ->
- {ok, State}.
+maybe_recover_state(#state{name = Name} = State) ->
+ Active = recover(active_file_name(Name)),
+ Starting = recover(starting_file_name(Name)),
Review comment:
The `starting` field contains a list of `[{Ref, Key}]` see
[here](https://github.com/apache/couchdb/pull/3766/files#diff-113cd247cfe56b1aa882a37daa2856fd33bab2e2a6183034eb3a30088960dc13R429).
Where Ref is a `Ref = erlang:monitor(process, DbPid),`. In both scenarios
(node restart or smoosh restart) the monitors are dead. Because the original
smoosh_channel process is dead and now we have a new one.
Therefore for each element in starting we need to
[start_compact](https://github.com/apache/couchdb/pull/3766/files#diff-113cd247cfe56b1aa882a37daa2856fd33bab2e2a6183034eb3a30088960dc13R420).
It might be easier to not recover the starting state at all (assign
`#state{starting = []}`) and just do:
```erlang
maybe_recover_state(#state{name = Name, waiting = Waiting0} = State) ->
%% BTW the Waiting0 is going to be empty with current shape of the code
%% the fun bellow doesn't handle the view compaction terms you will need
to adapt it
Waiting = lists:foldl(fun({_, DbName}, Q) ->
smoosh_priority_queue:in(Key, Priority, Priority, Capacity, Q)
end, Waiting0, Starting).
```
The problem is ^^^ we don't know the Priority.
--
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]