fix: sync data's authz and certs

This commit is contained in:
Zhongwen Deng 2022-07-01 11:44:29 +08:00
parent b134c3562a
commit 740ff3587c
2 changed files with 25 additions and 1 deletions

View File

@ -20,6 +20,7 @@
-export([start/2, stop/1]).
-export([get_override_config_file/0]).
-export([sync_data_from_node/0]).
-include_lib("emqx/include/logger.hrl").
-include("emqx_conf.hrl").
@ -56,6 +57,12 @@ get_override_config_file() ->
end
end.
sync_data_from_node() ->
Dir = emqx:data_dir(),
{ok, Zip} = zip:zip(atom_to_list(node()) ++ "_data.zip", ["authz", "certs"], [{cwd, Dir}]),
Res = {ok, _Bin} = file:read_file(Zip),
Res.
%% ------------------------------------------------------------------------------
%% Internal functions
%% ------------------------------------------------------------------------------
@ -150,6 +157,7 @@ copy_override_conf_from_core_node() ->
RawOverrideConf,
#{override_to => cluster}
),
ok = sync_data_from_node(Node),
{ok, TnxId}
end
end.
@ -173,3 +181,14 @@ conf_sort({ok, #{tnx_id := Id, wall_clock := W1}}, {ok, #{tnx_id := Id, wall_clo
W1 > W2;
conf_sort({ok, _}, {ok, _}) ->
false.
sync_data_from_node(Node) ->
case emqx_conf_proto_v1:sync_data_from_node(Node) of
{ok, DataBin} ->
{ok, Files} = zip:unzip(DataBin, [{cwd, emqx:data_dir()}]),
?SLOG(debug, #{node => Node, msg => "sync_data_from_node_ok", files => Files}),
ok;
Error ->
?SLOG(emergency, #{node => Node, msg => "sync_data_from_node_failed", reason => Error}),
error(Error)
end.

View File

@ -33,7 +33,8 @@
reset/2,
reset/3,
get_override_config_file/1
get_override_config_file/1,
sync_data_from_node/1
]).
-include_lib("emqx/include/bpapi.hrl").
@ -104,3 +105,7 @@ reset(Node, KeyPath, Opts) ->
-spec get_override_config_file([node()]) -> emqx_rpc:multicall_result().
get_override_config_file(Nodes) ->
rpc:multicall(Nodes, emqx_conf_app, get_override_config_file, [], 20000).
-spec sync_data_from_node(node()) -> {ok, binary()} | emqx_rpc:badrpc().
sync_data_from_node(Node) ->
rpc:call(Node, emqx_conf_app, sync_data_from_node, [], 20000).