Skip to content
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

feat: add API to disable/enable core node discovery #177

Merged
Show file tree
Hide file tree
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
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 @@ -247,6 +250,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 @@ -314,11 +314,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