iilyak commented on a change in pull request #3766:
URL: https://github.com/apache/couchdb/pull/3766#discussion_r774761365
##########
File path: src/smoosh/src/smoosh_channel.erl
##########
@@ -194,21 +215,128 @@ 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) ->
+terminate(_Reason, #state{name = Name, waiting = Q}) ->
+ file:delete(active_file_name(Name)),
Review comment:
It looks like we should distinguish the case of a node restart from a
smoosh_channel restart. I suggest investigating the inclusion of node start
timestamp into filename. If timestamp is the same we restore the `waiting`
otherwise we use enqueue. In any case this logic would need to go into recover.
```
NodeStartTime = erlang:convert_time_unit(erlang:time_offset() +
erlang:system_info(start_time), native, millisecond).
```
--
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]