Correct the tidyup after startup
Use send_after/3 and unit test to confirm this works as expected
This commit is contained in:
parent
dfa8574695
commit
2f3d2a634c
1 changed files with 46 additions and 15 deletions
|
@ -512,7 +512,7 @@ starting({sst_new,
|
||||||
leveled_log:log_timer("SST08",
|
leveled_log:log_timer("SST08",
|
||||||
[ActualFilename, Level, Summary#summary.max_sqn],
|
[ActualFilename, Level, Summary#summary.max_sqn],
|
||||||
SW),
|
SW),
|
||||||
gen_fsm:send_event(self(), timeout),
|
erlang:send_after(?STARTUP_TIMEOUT, self(), tidyup_after_startup),
|
||||||
% always want to have an opportunity to GC - so force the timeout to
|
% always want to have an opportunity to GC - so force the timeout to
|
||||||
% occur whether or not there is an intervening message
|
% occur whether or not there is an intervening message
|
||||||
{reply,
|
{reply,
|
||||||
|
@ -713,15 +713,7 @@ reader(close, _From, State) ->
|
||||||
|
|
||||||
reader(switch_levels, State) ->
|
reader(switch_levels, State) ->
|
||||||
erlang:garbage_collect(self()),
|
erlang:garbage_collect(self()),
|
||||||
{next_state, reader, State};
|
{next_state, reader, State}.
|
||||||
reader(timeout, State) ->
|
|
||||||
case is_process_alive(State#state.starting_pid) of
|
|
||||||
true ->
|
|
||||||
erlang:garbage_collect(self()),
|
|
||||||
{next_state, reader, State};
|
|
||||||
false ->
|
|
||||||
{stop, normal, State}
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
delete_pending({get_kv, LedgerKey, Hash}, _From, State) ->
|
delete_pending({get_kv, LedgerKey, Hash}, _From, State) ->
|
||||||
|
@ -784,8 +776,14 @@ handle_sync_event(_Msg, _From, StateName, State) ->
|
||||||
handle_event(_Msg, StateName, State) ->
|
handle_event(_Msg, StateName, State) ->
|
||||||
{next_state, StateName, State}.
|
{next_state, StateName, State}.
|
||||||
|
|
||||||
handle_info(_Msg, StateName, State) ->
|
handle_info(tidyup_after_startup, StateName, State) ->
|
||||||
{next_state, StateName, State}.
|
case is_process_alive(State#state.starting_pid) of
|
||||||
|
true ->
|
||||||
|
erlang:garbage_collect(self()),
|
||||||
|
{next_state, StateName, State};
|
||||||
|
false ->
|
||||||
|
{stop, normal, State}
|
||||||
|
end.
|
||||||
|
|
||||||
terminate(normal, delete_pending, _State) ->
|
terminate(normal, delete_pending, _State) ->
|
||||||
ok;
|
ok;
|
||||||
|
@ -3355,9 +3353,6 @@ key_dominates_test() ->
|
||||||
nonsense_coverage_test() ->
|
nonsense_coverage_test() ->
|
||||||
{ok, Pid} = gen_fsm:start_link(?MODULE, [], []),
|
{ok, Pid} = gen_fsm:start_link(?MODULE, [], []),
|
||||||
ok = gen_fsm:send_all_state_event(Pid, nonsense),
|
ok = gen_fsm:send_all_state_event(Pid, nonsense),
|
||||||
?assertMatch({next_state, reader, #state{}}, handle_info(nonsense,
|
|
||||||
reader,
|
|
||||||
#state{})),
|
|
||||||
?assertMatch({ok, reader, #state{}}, code_change(nonsense,
|
?assertMatch({ok, reader, #state{}}, code_change(nonsense,
|
||||||
reader,
|
reader,
|
||||||
#state{},
|
#state{},
|
||||||
|
@ -3435,4 +3430,40 @@ stopstart_test() ->
|
||||||
% fetcher on new level zero files working in a loop
|
% fetcher on new level zero files working in a loop
|
||||||
ok = sst_close(Pid).
|
ok = sst_close(Pid).
|
||||||
|
|
||||||
|
stop_whenstarter_stopped_test_() ->
|
||||||
|
{timeout, 60, fun() -> stop_whenstarter_stopped_testto() end}.
|
||||||
|
|
||||||
|
stop_whenstarter_stopped_testto() ->
|
||||||
|
RP = spawn(fun receive_fun/0),
|
||||||
|
spawn(fun() -> start_sst_fun(RP) end),
|
||||||
|
TestFun =
|
||||||
|
fun(X, Acc) ->
|
||||||
|
case Acc of
|
||||||
|
false -> false;
|
||||||
|
true ->
|
||||||
|
timer:sleep(X),
|
||||||
|
is_process_alive(RP)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
?assertMatch(false, lists:foldl(TestFun, true, [10000, 2000, 2000, 2000])).
|
||||||
|
|
||||||
|
|
||||||
|
receive_fun() ->
|
||||||
|
receive
|
||||||
|
{sst_pid, SST_P} ->
|
||||||
|
timer:sleep(?STARTUP_TIMEOUT + 1000),
|
||||||
|
?assertMatch(false, is_process_alive(SST_P))
|
||||||
|
end.
|
||||||
|
|
||||||
|
start_sst_fun(ProcessToInform) ->
|
||||||
|
N = 3000,
|
||||||
|
KVL1 = lists:ukeysort(1, generate_randomkeys(N + 1, N, 1, 20)),
|
||||||
|
OptsSST =
|
||||||
|
#sst_options{press_method=native,
|
||||||
|
log_options=leveled_log:get_opts()},
|
||||||
|
{ok, P1, {_FK1, _LK1}, _Bloom1} =
|
||||||
|
sst_new("test/test_area/", "level1_src", 1, KVL1, 6000, OptsSST),
|
||||||
|
ProcessToInform ! {sst_pid, P1}.
|
||||||
|
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue