Skip to content

Commit

Permalink
Do ignore_cancel_check if table lists do not match
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Jan 31, 2024
1 parent c03a014 commit 64e6ecf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions src/cets_discovery.erl
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ handle_info({ping_result, Node, Result}, State) ->
{noreply, handle_ping_result(Node, Result, State)};
handle_info(enter_regular_phase, State) ->
{noreply, State#{phase := regular}};
handle_info({cancel_check, Node}, State) ->
{noreply, handle_cancel_check(Node, State)};
handle_info({cancel_check, Node, Tables}, State) ->
{noreply, handle_cancel_check(Node, Tables, State)};
handle_info(Msg, State) ->
?LOG_ERROR(#{what => unexpected_info, msg => Msg}),
{noreply, State}.
Expand Down Expand Up @@ -348,17 +348,28 @@ handle_check(State = #{backend_module := Mod, backend_state := BackendState}) ->
State#{get_nodes_status := running}.

-spec send_cancel_check_to_other_nodes(state()) -> ok.
send_cancel_check_to_other_nodes(State = #{nodes := Nodes}) ->
send_cancel_check_to_other_nodes(State = #{nodes := Nodes, tables := Tables}) ->
AliveNodes = lists:sort(nodes()),
AliveKnownNodes = ordsets:intersection(Nodes, AliveNodes),
broadcast_to_other_nodes(AliveKnownNodes, {cancel_check, node()}, State).
broadcast_to_other_nodes(AliveKnownNodes, {cancel_check, node(), Tables}, State).

-spec handle_cancel_check(node(), state()) -> state().
handle_cancel_check(_FromNode, State) ->
-spec handle_cancel_check(node(), [cets:table_name()], state()) -> state().
handle_cancel_check(_FromNode, Tables, State = #{tables := Tables}) ->
%% Remote node asked us to skip our check to reduce
%% resource usage and reduce a chance of a race condition.
%% Start a new timeout for the next check.
schedule_check(State).
schedule_check(State);
handle_cancel_check(FromNode, RemoteTables, State = #{tables := Tables}) ->
%% A corner case when some nodes have different table lists,
%% in this case all nodes need to call join for all tables.
?LOG_INFO(#{
what => ignore_cancel_check,
text => <<"Table lists do not match, ignore cancel_check">>,
remote_tables => RemoteTables,
remote_node => FromNode,
tables => Tables
}),
State.

-spec broadcast_to_other_nodes([node()], term(), state()) -> ok.
broadcast_to_other_nodes([_ | _] = Nodes, Msg, #{name := Name}) ->
Expand Down
4 changes: 2 additions & 2 deletions test/cets_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2834,7 +2834,7 @@ cancel_check_is_sent_after_check(Config) ->
#{nodes := [Node1, Node2]} = cets_discovery:system_info(Disco),
%% Force check, so we do not wait for long.
Disco ! check,
receive_message({cancel_check, Node2}).
receive_message({cancel_check, Node2, []}).

cancel_check_resets_check_timeout(Config) ->
DiscoName = disco_name(Config),
Expand All @@ -2851,7 +2851,7 @@ cancel_check_resets_check_timeout(Config) ->
%% Now next check would be not soon.
%% So, we could be sure nobody would change timer_ref, interfering with our code.
#{timer_ref := OldTRef} = cets_discovery:system_info(Disco),
Disco ! {cancel_check, Node1},
Disco ! {cancel_check, Node1, []},
wait_for_different_timer_ref(Disco, OldTRef).

%% Helper functions
Expand Down

0 comments on commit 64e6ecf

Please sign in to comment.