Use hibernate not garbage_collect

Use hibernation rather than manual garbage_collect calls as per standard recommendation.  Hibernate will be default gabage_collect anyway.  Maybe help with SST files that naturally go quiet.

Plus typos from previous commit in leveled_cdb.
This commit is contained in:
Martin Sumner 2019-07-18 13:21:38 +01:00
parent 5a853ee44d
commit 85bfa7fbb4
2 changed files with 7 additions and 8 deletions

View file

@ -58,7 +58,8 @@
{gen_fsm, sync_send_event, 2}, {gen_fsm, sync_send_event, 2},
{gen_fsm, send_event, 2}, {gen_fsm, send_event, 2},
{gen_fsm, sync_send_all_state_event, 3}, {gen_fsm, sync_send_all_state_event, 3},
{gen_fsm, send_all_state_event, 2}]}). {gen_fsm, send_all_state_event, 2},
{gen_fsm, reply, 2}]}).
-endif. -endif.
-ifdef(slow_test). -ifdef(slow_test).
@ -441,7 +442,7 @@ starting({open_writer, Filename}, _From, State) ->
last_position=LastPosition, last_position=LastPosition,
last_key=LastKey, last_key=LastKey,
filename=Filename, filename=Filename,
hashtree=HashTree} hashtree=HashTree},
{reply, ok, writer, State0, hibernate}; {reply, ok, writer, State0, hibernate};
starting({open_reader, Filename}, _From, State) -> starting({open_reader, Filename}, _From, State) ->
leveled_log:save(State#state.log_options), leveled_log:save(State#state.log_options),
@ -450,7 +451,7 @@ starting({open_reader, Filename}, _From, State) ->
State0 = State#state{handle=Handle, State0 = State#state{handle=Handle,
last_key=LastKey, last_key=LastKey,
filename=Filename, filename=Filename,
hash_index=Index} hash_index=Index},
{reply, ok, reader, State0, hibernate}; {reply, ok, reader, State0, hibernate};
starting({open_reader, Filename, LastKey}, _From, State) -> starting({open_reader, Filename, LastKey}, _From, State) ->
leveled_log:save(State#state.log_options), leveled_log:save(State#state.log_options),
@ -459,7 +460,7 @@ starting({open_reader, Filename, LastKey}, _From, State) ->
State0 = State#state{handle=Handle, State0 = State#state{handle=Handle,
last_key=LastKey, last_key=LastKey,
filename=Filename, filename=Filename,
hash_index=Index} hash_index=Index},
{reply, ok, reader, State0, hibernate}. {reply, ok, reader, State0, hibernate}.
writer({get_kv, Key}, _From, State) -> writer({get_kv, Key}, _From, State) ->

View file

@ -717,8 +717,7 @@ reader(close, _From, State) ->
{stop, normal, ok, State}. {stop, normal, ok, State}.
reader({switch_levels, NewLevel}, State) -> reader({switch_levels, NewLevel}, State) ->
erlang:garbage_collect(self()), {next_state, reader, State#state{level = NewLevel}, hibernate}.
{next_state, reader, State#state{level = NewLevel}}.
delete_pending({get_kv, LedgerKey, Hash}, _From, State) -> delete_pending({get_kv, LedgerKey, Hash}, _From, State) ->
@ -792,8 +791,7 @@ handle_info(tidyup_after_startup, delete_pending, State) ->
handle_info(tidyup_after_startup, StateName, State) -> handle_info(tidyup_after_startup, StateName, State) ->
case is_process_alive(State#state.starting_pid) of case is_process_alive(State#state.starting_pid) of
true -> true ->
erlang:garbage_collect(self()), {next_state, StateName, State, hibernate};
{next_state, StateName, State};
false -> false ->
{stop, normal, State} {stop, normal, State}
end. end.