Skip to content

Use link/unlink for hidden nodes #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions src/ioq_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ init([]) ->
histos = ets:new(ioq_histos, [named_table, ordered_set])
},
erlang:send_after(get_interval(), self(), dump_table),
process_flag(trap_exit, true),
{ok, update_config(State)}.

handle_call({set_priority, Pri}, _From, State) ->
Expand Down Expand Up @@ -146,7 +147,7 @@ handle_info({Ref, Reply}, #state{reqs = Reqs} = State) ->
case lists:keytake(Ref, #request.ref, Reqs) of
{value, #request{from=From} = Req, Reqs2} ->
TResponse = erlang:monotonic_time(),
erlang:demonitor(Ref, [flush]),
demonitor_(Ref, Req#request.fd),
reply_to_all(From, Reply),
update_histograms(ioq_histos, Req, TResponse),
{noreply, State#state{reqs = Reqs2}, 0};
Expand All @@ -163,6 +164,12 @@ handle_info({'DOWN', Ref, _, _, Reason}, #state{reqs = Reqs} = State) ->
{noreply, State, 0}
end;

handle_info({'EXIT', Pid, Reason}, #state{reqs = Reqs} = State) ->
{L1, L2} = lists:splitwith(fun(R) -> Pid == R#request.fd end, Reqs),
lists:foreach(
fun(R) -> reply_to_all(R#request.from, {'EXIT', Reason}) end, L1),
{noreply, State#state{reqs = L2}, 0};

handle_info(dump_table, State) ->
erlang:send_after(get_interval(), self(), dump_table),
{noreply, dump_table(State), 0};
Expand Down Expand Up @@ -414,7 +421,7 @@ submit_request(Request, State) ->
#state{reqs = Reqs, counters = Counters} = State,

% make the request
Ref = erlang:monitor(process, Fd),
Ref = monitor_(Fd),
Fd ! {'$gen_call', {self(), Ref}, Call},

% record some stats
Expand Down Expand Up @@ -598,6 +605,50 @@ rw({append_bin, _}) ->
rw(_) ->
unknown.


monitor_(Pid) when is_pid(Pid) ->
case is_hidden(Pid) of
true ->
link(Pid),
make_ref();
false ->
erlang:monitor(process, Pid)
end;

monitor_({Name, Node}) when is_atom(Name), is_atom(Node) ->
case is_hidden(Node) of
true ->
make_ref();
false ->
erlang:monitor(process, {Name, Node})
end.


demonitor_(Ref, Pid) when is_reference(Ref), is_pid(Pid) ->
case is_hidden(Pid) of
true ->
unlink(Pid);
false ->
erlang:demonitor(Ref, [flush])
end;

demonitor_(Ref, {Name, Node})
when is_reference(Ref), is_atom(Name), is_atom(Node) ->
case is_hidden(Node) of
true ->
ok;
false ->
erlang:demonitor(Ref, [flush])
end.


is_hidden(Pid) when is_pid(Pid) ->
is_hidden(node(Pid));

is_hidden(Node) when is_atom(Node) ->
lists:member(Node, nodes(hidden)).


-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

Expand Down