fix(cluster_rpc): clean self-data by mria stop callback

This commit is contained in:
firest 2023-06-28 10:38:36 +00:00
parent 8e68af14ef
commit 71d34504bf
2 changed files with 7 additions and 4 deletions

View File

@ -29,7 +29,7 @@
status/0,
skip_failed_commit/1,
fast_forward_to_commit/2,
on_leave/0
on_mria_stop/1
]).
-export([
commit/2,
@ -271,14 +271,18 @@ fast_forward_to_commit(Node, ToTnxId) ->
gen_server:call({?MODULE, Node}, {fast_forward_to_commit, ToTnxId}).
%% It is necessary to clean this node commit record in the cluster
on_leave() ->
gen_server:call(?MODULE, on_leave).
on_mria_stop(leave) ->
gen_server:call(?MODULE, on_leave);
on_mria_stop(_) ->
ok.
%%%===================================================================
%%% gen_server callbacks
%%%===================================================================
%% @private
init([Node, RetryMs]) ->
mria:register_callback(stop, fun ?MODULE:on_mria_stop/1),
{ok, _} = mnesia:subscribe({table, ?CLUSTER_MFA, simple}),
State = #{node => Node, retry_interval => RetryMs, is_leaving => false},
%% The init transaction ID is set in emqx_conf_app after

View File

@ -120,7 +120,6 @@ cluster(["join", SNode]) ->
emqx_ctl:print("Failed to join the cluster: ~0p~n", [Error])
end;
cluster(["leave"]) ->
emqx_cluster_rpc:on_leave(),
case ekka:leave() of
ok ->
emqx_ctl:print("Leave the cluster successfully.~n"),