Fix silly nodes report bug

This commit is contained in:
2025-10-29 15:35:05 +09:00
parent 7252ecd40b
commit c5349f5736
4 changed files with 1403 additions and 38 deletions
+18 -9
View File
@@ -40,11 +40,11 @@
req = none :: none | binary()}).
-record(s,
{tls = false :: boolean(),
chain_nodes = {[], []} :: {[hz:chain_node()], [hz:chain_node()]},
sticky = none :: none | hz:chain_node(),
fetchers = [] :: [#fetcher{}],
timeout = 5000 :: pos_integer()}).
{tls = false :: boolean(),
chain_nodes = {[], []} :: {[hz:chain_node()], [hz:chain_node()]},
sticky = none :: none | hz:chain_node(),
fetchers = [] :: [#fetcher{}],
timeout = 5000 :: pos_integer()}).
-type state() :: #s{}.
@@ -169,8 +169,8 @@ handle_call({request_sticky, Request}, From, State) ->
{noreply, NewState};
handle_call(tls, _, State = #s{tls = TLS}) ->
{reply, TLS, State};
handle_call(chain_nodes, _, State = #s{chain_nodes = {Wait, Used}}) ->
Nodes = lists:append(Wait, Used),
handle_call(chain_nodes, _, State) ->
Nodes = do_chain_nodes(State),
{reply, Nodes, State};
handle_call(timeout, _, State = #s{timeout = Value}) ->
{reply, Value, State};
@@ -239,6 +239,15 @@ terminate(_, _) ->
%%% Doer Functions
do_chain_nodes(#s{sticky = none, chain_nodes = {Wait, Used}}) ->
lists:append(Wait, Used);
do_chain_nodes(#s{sticky = Sticky, chain_nodes = {Wait, Used}}) ->
case lists:append(Wait, Used) of
[Sticky] -> [Sticky];
Nodes -> [Sticky | Nodes]
end.
do_chain_nodes([], State) ->
State#s{sticky = none, chain_nodes = {[], []}};
do_chain_nodes(List = [Sticky], State) ->
@@ -268,7 +277,7 @@ do_request_sticky(Request,
Now = erlang:system_time(nanosecond),
Fetcher =
case TLS of
true -> fun() -> hz_fetcher:slowly_connect(Node, Request, From, Timeout) end;
true -> fun() -> hz_fetcher:connect_slowly(Node, Request, From, Timeout) end;
false -> fun() -> hz_fetcher:connect(Node, Request, From, Timeout) end
end,
{PID, Mon} = spawn_monitor(Fetcher),
@@ -293,7 +302,7 @@ do_request(Request,
Now = erlang:system_time(nanosecond),
Fetcher =
case TLS of
true -> fun() -> hz_fetcher:slowly_connect(Node, Request, From, Timeout) end;
true -> fun() -> hz_fetcher:connect_slowly(Node, Request, From, Timeout) end;
false -> fun() -> hz_fetcher:connect(Node, Request, From, Timeout) end
end,
{PID, Mon} = spawn_monitor(Fetcher),