From aca809aa90014fc4cb0ae8b833dada2238a3da6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8e=20S=C3=B8rensen?= Date: Thu, 5 Jan 2012 17:50:18 +0100 Subject: [PATCH] level: Handle failure of merger process. Remove EXIT messages from inbox. --- src/fractal_btree_level.erl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/fractal_btree_level.erl b/src/fractal_btree_level.erl index 6e87923..28c279a 100644 --- a/src/fractal_btree_level.erl +++ b/src/fractal_btree_level.erl @@ -211,9 +211,14 @@ main_loop(State = #state{ next=Next }) -> {system, From, Req} -> plain_fsm:handle_system_msg( From, Req, State, fun(S1) -> main_loop(S1) end); - {'EXIT', Parent, Reason} -> - plain_fsm:parent_EXIT(Reason, State) + {'EXIT', Parent, Reason} -> + plain_fsm:parent_EXIT(Reason, State); + {'EXIT', _, normal} -> + %% Probably from a merger_pid - which we may have forgotten in the meantime. + main_loop(State); + {'EXIT', Pid, Reason} when Pid == State#state.merge_pid -> + restart_merge_then_loop(State#state{merge_pid=undefined}, Reason) end. do_lookup(_Key, []) -> @@ -236,6 +241,13 @@ stop_if_defined(undefined) -> ok; stop_if_defined(MergePid) when is_pid(MergePid) -> erlang:exit(MergePid, shutdown). + +restart_merge_then_loop(State, Reason) -> + XFileName = filename("X",State), + error_logger:warning_msg("Merger appears to have failed (reason: ~p). Removing outfile ~s\n", [Reason, XFileName]), + file:delete(XFileName), + check_begin_merge_then_loop(State). + begin_merge(State) -> AFileName = filename("A",State), BFileName = filename("B",State),