Skip to content

Commit

Permalink
Log warning if same node reconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Nov 16, 2023
1 parent 425c923 commit 7897c6c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/cets_discovery.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
dns_status := dns_status(),
nodeup_timestamps := #{node() => milliseconds()},
nodedown_timestamps := #{node() => milliseconds()},
node_start_timestamps := #{node() => milliseconds()},
start_time := milliseconds()
}.
-type dns_status() :: ready | waiting.
Expand Down Expand Up @@ -188,6 +189,7 @@ init(Opts) ->
pending_wait_for_ready => [],
dns_status => DNSStatus,
nodeup_timestamps => #{},
node_start_timestamps => #{},
nodedown_timestamps => #{},
start_time => StartTime
},
Expand Down Expand Up @@ -258,9 +260,12 @@ handle_info({nodedown, Node}, State) ->
time_since_startup_in_milliseconds => time_since_startup_in_milliseconds(State)
})
),
send_start_time_to(Node, State),
%% Do another check to update unavailable_nodes list
self() ! check,
{noreply, State2};
handle_info({start_time, Node, StartTime}, State) ->
{noreply, handle_receive_start_time(Node, StartTime, State)};
handle_info({joining_finished, Results}, State) ->
{noreply, handle_joining_finished(Results, State)};
handle_info({ping_result, Node, Result}, State) ->
Expand Down Expand Up @@ -600,3 +605,28 @@ time_since_startup_in_milliseconds(#{start_time := StartTime}) ->

time_since(StartTime) ->
erlang:system_time(millisecond) - StartTime.

send_start_time_to(Node, #{start_time := StartTime}) ->
case erlang:process_info(self(), registered_name) of
{registered_name, Name} ->
erlang:send({Name, Node}, {start_time, node(), StartTime});
_ ->
ok
end.

handle_receive_start_time(Node, StartTime, State = #{node_start_timestamps := Map}) ->
case maps:get(Node, Map, undefined) of
undefined ->
ok;
StartTime ->
?LOG_WARNING(#{
what => node_reconnects,
remote_node => Node,
start_time => StartTime,
text => <<"Netsplit recovery. The remote node has been connected to us before.">>
});
_ ->
%% Restarted node reconnected, this is fine during the rolling updates
ok
end,
State#{node_start_timestamps := maps:put(Node, StartTime, Map)}.

0 comments on commit 7897c6c

Please sign in to comment.