chore: exit with non-zero status if config initialization failed

This commit is contained in:
Zaiming (Stone) Shi 2023-03-30 12:52:51 +02:00
parent 28021c466a
commit 494e4b639a
3 changed files with 11 additions and 1 deletions

View File

@ -72,9 +72,13 @@ set_init_config_load_done() ->
get_init_config_load_done() -> get_init_config_load_done() ->
application:get_env(emqx, init_config_load_done, false). application:get_env(emqx, init_config_load_done, false).
%% @doc Set the transaction id from which this node should start applying after boot.
%% The transaction ID is received from the core node which we just copied the latest
%% config from.
set_init_tnx_id(TnxId) -> set_init_tnx_id(TnxId) ->
application:set_env(emqx, cluster_rpc_init_tnx_id, TnxId). application:set_env(emqx, cluster_rpc_init_tnx_id, TnxId).
%% @doc Get the transaction id from which this node should start applying after boot.
get_init_tnx_id() -> get_init_tnx_id() ->
application:get_env(emqx, cluster_rpc_init_tnx_id, -1). application:get_env(emqx, cluster_rpc_init_tnx_id, -1).

View File

@ -275,8 +275,13 @@ init([Node, RetryMs]) ->
_ = mria:wait_for_tables([?CLUSTER_MFA, ?CLUSTER_COMMIT]), _ = mria:wait_for_tables([?CLUSTER_MFA, ?CLUSTER_COMMIT]),
{ok, _} = mnesia:subscribe({table, ?CLUSTER_MFA, simple}), {ok, _} = mnesia:subscribe({table, ?CLUSTER_MFA, simple}),
State = #{node => Node, retry_interval => RetryMs}, State = #{node => Node, retry_interval => RetryMs},
%% The init transaction ID is set in emqx_conf_app after
%% it has fetched the latest config from one of the core nodes
TnxId = emqx_app:get_init_tnx_id(), TnxId = emqx_app:get_init_tnx_id(),
ok = maybe_init_tnx_id(Node, TnxId), ok = maybe_init_tnx_id(Node, TnxId),
%% Now continue with the normal catch-up process
%% That is: apply the missing transactions after the config
%% was copied until now.
{ok, State, {continue, ?CATCH_UP}}. {ok, State, {continue, ?CATCH_UP}}.
%% @private %% @private
@ -396,6 +401,7 @@ get_cluster_tnx_id() ->
Id -> Id Id -> Id
end. end.
%% The entry point of a config change transaction.
init_mfa(Node, MFA) -> init_mfa(Node, MFA) ->
mnesia:write_lock_table(?CLUSTER_MFA), mnesia:write_lock_table(?CLUSTER_MFA),
LatestId = get_cluster_tnx_id(), LatestId = get_cluster_tnx_id(),

View File

@ -38,7 +38,7 @@ start(_StartType, _StartArgs) ->
reason => E, reason => E,
stacktrace => St stacktrace => St
}), }),
init:stop() init:stop(1)
end, end,
ok = emqx_config_logger:refresh_config(), ok = emqx_config_logger:refresh_config(),
emqx_conf_sup:start_link(). emqx_conf_sup:start_link().