Skip to content

Commit

Permalink
Merge pull request #177 from SergeTupchiy/EMQX-11826-prevent-left-nod…
Browse files Browse the repository at this point in the history
…e-from-rejoining

feat: add API to disable/enable core node discovery
  • Loading branch information
SergeTupchiy authored Mar 28, 2024
2 parents 8e931f0 + 3b45683 commit 401424d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/mria.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
, cluster_nodes/1
, cluster_status/1
, is_node_in_cluster/1
, enable_core_node_discovery/0
, disable_core_node_discovery/0
]).

%% Register callback
Expand Down Expand Up @@ -271,6 +273,14 @@ force_leave(Node) ->
{error, node_not_in_cluster}
end.

-spec enable_core_node_discovery() -> ok.
enable_core_node_discovery() ->
mria_config:set_core_node_discovery(true).

-spec disable_core_node_discovery() -> ok.
disable_core_node_discovery() ->
mria_config:set_core_node_discovery(false).

%%--------------------------------------------------------------------
%% Register callback
%%--------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions src/mria_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
, load_config/0
, erase_all_config/0

, set_core_node_discovery/1
, is_core_node_discovery_enabled/0

%% Shard config:
, set_dirty_shard/2
, dirty_shard/1
Expand Down Expand Up @@ -249,6 +252,22 @@ set_extra_mnesia_diagnostic_checks(Checks) when is_list(Checks) ->
get_extra_mnesia_diagnostic_checks() ->
persistent_term:get(?mria(extra_mnesia_diagnostic_checks), []).

-spec set_core_node_discovery(boolean()) -> ok.
set_core_node_discovery(What) when What =:= true; What =:= false ->
case role() of
core ->
ok;
replicant ->
ok = application:set_env(mria, core_node_discovery, What)
end.

-spec is_core_node_discovery_enabled() -> boolean().
is_core_node_discovery_enabled() ->
case role() of
core -> false;
replicant -> application:get_env(mria, core_node_discovery, true)
end.

%%================================================================================
%% Internal
%%================================================================================
Expand Down
11 changes: 8 additions & 3 deletions src/mria_lb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,16 @@ lb_callback() ->

-spec discover_nodes() -> [node()].
discover_nodes() ->
DiscoveryFun = mria_config:core_node_discovery_callback(),
case manual_seed() of
[] ->
%% Run the discovery algorithm
DiscoveryFun();
case mria_config:is_core_node_discovery_enabled() of
true ->
%% Run the discovery algorithm
DiscoveryFun = mria_config:core_node_discovery_callback(),
DiscoveryFun();
false ->
[]
end;
[Seed] ->
discover_manually(Seed)
end.
Expand Down

0 comments on commit 401424d

Please sign in to comment.