GC before transitioning a L0 to reader
The L0 Pid has used a lot of memory in the construction of the file (something like 50MB). This won't be GC'd immediately. This is fine, as this will normally be short-lived. However if the SST file is switched levels ... then this may mean thta we have multiple SST files with memory not being GC'd.
This commit is contained in:
parent
da06ef133c
commit
95c27a835b
2 changed files with 16 additions and 2 deletions
|
@ -186,8 +186,9 @@ merge(SrcLevel, Manifest, RootPath, OptsSST) ->
|
|||
leveled_log:log("PC008", [SrcLevel, Candidates]),
|
||||
case Candidates of
|
||||
0 ->
|
||||
leveled_log:log("PC009",
|
||||
[Src#manifest_entry.filename, SrcLevel + 1]),
|
||||
NewLevel = SrcLevel + 1,
|
||||
leveled_log:log("PC009", [Src#manifest_entry.filename, NewLevel]),
|
||||
leveled_sst:sst_switchlevels(Src#manifest_entry.owner, NewLevel),
|
||||
Man0 = leveled_pmanifest:switch_manifest_entry(Manifest,
|
||||
NewSQN,
|
||||
SrcLevel,
|
||||
|
|
|
@ -121,6 +121,7 @@
|
|||
sst_setfordelete/2,
|
||||
sst_clear/1,
|
||||
sst_checkready/1,
|
||||
sst_switchlevels/2,
|
||||
sst_deleteconfirmed/1,
|
||||
sst_close/1]).
|
||||
|
||||
|
@ -449,6 +450,15 @@ sst_checkready(Pid) ->
|
|||
%% Only used in test
|
||||
gen_fsm:sync_send_event(Pid, background_complete).
|
||||
|
||||
-spec sst_switchlevels(pid(), pos_integer()) -> ok.
|
||||
%% @doc
|
||||
%% Notify the SST file that it is now working at a new level
|
||||
%% This simply prompts a GC on the PID now (as this may now be a long-lived
|
||||
%% file, so don't want all the startup state to be held on memory - want to
|
||||
%% proactively drop it
|
||||
sst_switchlevels(Pid, _NewLevel) ->
|
||||
gen_fsm:send_event(Pid, switch_levels).
|
||||
|
||||
-spec sst_close(pid()) -> ok.
|
||||
%% @doc
|
||||
%% Close the file
|
||||
|
@ -699,6 +709,9 @@ reader(close, _From, State) ->
|
|||
ok = file:close(State#state.handle),
|
||||
{stop, normal, ok, State}.
|
||||
|
||||
reader(switch_levels, State) ->
|
||||
erlang:garbage_collect(self()),
|
||||
{next_state, reader, State};
|
||||
reader(timeout, State) ->
|
||||
case is_process_alive(State#state.starting_pid) of
|
||||
true ->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue