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

fix: sync data's authz and certs #8369

Merged
merged 7 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/emqx_conf/src/emqx_conf_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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
%% ------------------------------------------------------------------------------
Expand Down Expand Up @@ -150,6 +157,7 @@ copy_override_conf_from_core_node() ->
RawOverrideConf,
#{override_to => cluster}
),
ok = sync_data_from_node(Node),
{ok, TnxId}
end
end.
Expand All @@ -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.
7 changes: 6 additions & 1 deletion apps/emqx_conf/src/proto/emqx_conf_proto_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down Expand Up @@ -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).