Simplify call sequence for fold
Now hanoi:fold_range/4 creates the fold worker; which makes the callee and not the hanoi main gen_server be ancestor for the worker.
This commit is contained in:
parent
5b88a71e1d
commit
0066b19c80
3 changed files with 11 additions and 12 deletions
|
@ -117,13 +117,14 @@ fold(Ref,Fun,Acc0) ->
|
|||
|
||||
-spec fold_range(hanoi(),kv_fold_fun(),any(),key_range()) -> any().
|
||||
fold_range(Ref,Fun,Acc0,Range) ->
|
||||
{ok, FoldWorkerPID} = hanoi_fold_worker:start(self()),
|
||||
if Range#btree_range.limit < 10 ->
|
||||
{ok, PID} = gen_server:call(Ref, {blocking_range, self(), Range}, infinity);
|
||||
ok = gen_server:call(Ref, {blocking_range, FoldWorkerPID, Range}, infinity);
|
||||
true ->
|
||||
{ok, PID} = gen_server:call(Ref, {snapshot_range, self(), Range}, infinity)
|
||||
ok = gen_server:call(Ref, {snapshot_range, FoldWorkerPID, Range}, infinity)
|
||||
end,
|
||||
MRef = erlang:monitor(process, PID),
|
||||
receive_fold_range(MRef, PID,Fun,Acc0).
|
||||
MRef = erlang:monitor(process, FoldWorkerPID),
|
||||
receive_fold_range(MRef, FoldWorkerPID, Fun, Acc0).
|
||||
|
||||
receive_fold_range(MRef, PID,Fun,Acc0) ->
|
||||
receive
|
||||
|
@ -308,14 +309,12 @@ code_change(_OldVsn, State, _Extra) ->
|
|||
|
||||
|
||||
|
||||
handle_call({snapshot_range, Sender, Range}, _From, State=#state{ top=TopLevel, nursery=Nursery }) ->
|
||||
{ok, FoldWorkerPID} = hanoi_fold_worker:start(Sender),
|
||||
handle_call({snapshot_range, FoldWorkerPID, Range}, _From, State=#state{ top=TopLevel, nursery=Nursery }) ->
|
||||
hanoi_nursery:do_level_fold(Nursery, FoldWorkerPID, Range),
|
||||
Result = hanoi_level:snapshot_range(TopLevel, FoldWorkerPID, Range),
|
||||
{reply, Result, State};
|
||||
|
||||
handle_call({blocking_range, Sender, Range}, _From, State=#state{ top=TopLevel, nursery=Nursery }) ->
|
||||
{ok, FoldWorkerPID} = hanoi_fold_worker:start(Sender),
|
||||
handle_call({blocking_range, FoldWorkerPID, Range}, _From, State=#state{ top=TopLevel, nursery=Nursery }) ->
|
||||
hanoi_nursery:do_level_fold(Nursery, FoldWorkerPID, Range),
|
||||
Result = hanoi_level:blocking_range(TopLevel, FoldWorkerPID, Range),
|
||||
{reply, Result, State};
|
||||
|
|
|
@ -75,7 +75,8 @@ start(SendTo) ->
|
|||
process_flag(trap_exit,true),
|
||||
link(SendTo),
|
||||
try
|
||||
initialize(#state{sendto=SendTo}, [])
|
||||
initialize(#state{sendto=SendTo}, []),
|
||||
unlink(SendTo)
|
||||
catch
|
||||
Class:Ex ->
|
||||
error_logger:error_msg("Unexpected: ~p:~p ~p~n", [Class, Ex, erlang:get_stacktrace()]),
|
||||
|
@ -227,7 +228,6 @@ emit_next(State, [{FirstPID,FirstKV}|Rest]=Values, Queues) ->
|
|||
end.
|
||||
|
||||
end_of_fold(State) ->
|
||||
unlink(State#state.sendto),
|
||||
ok.
|
||||
|
||||
data_vsn() ->
|
||||
|
|
|
@ -128,12 +128,12 @@ destroy(Ref) ->
|
|||
snapshot_range(Ref, FoldWorkerPID, Range) ->
|
||||
{ok, Folders} = plain_rpc:call(Ref, {init_snapshot_range_fold, FoldWorkerPID, Range, []}),
|
||||
FoldWorkerPID ! {initialize, Folders},
|
||||
{ok, FoldWorkerPID}.
|
||||
ok.
|
||||
|
||||
blocking_range(Ref, FoldWorkerPID, Range) ->
|
||||
{ok, Folders} = plain_rpc:call(Ref, {init_blocking_range_fold, FoldWorkerPID, Range, []}),
|
||||
FoldWorkerPID ! {initialize, Folders},
|
||||
{ok, FoldWorkerPID}.
|
||||
ok.
|
||||
|
||||
%%%%% INTERNAL
|
||||
|
||||
|
|
Loading…
Reference in a new issue