diff --git a/apps/emqx/rebar.config b/apps/emqx/rebar.config index 8b173d493..bfd981854 100644 --- a/apps/emqx/rebar.config +++ b/apps/emqx/rebar.config @@ -28,7 +28,7 @@ {gproc, {git, "https://github.com/emqx/gproc", {tag, "0.9.0.1"}}}, {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.2"}}}, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.11.1"}}}, - {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.18.1"}}}, + {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.18.3"}}}, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.3.1"}}}, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.40.4"}}}, {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.5.3"}}}, diff --git a/apps/emqx_management/src/emqx_mgmt_cluster.erl b/apps/emqx_management/src/emqx_mgmt_cluster.erl index 828567776..be9685f1b 100644 --- a/apps/emqx_management/src/emqx_mgmt_cluster.erl +++ b/apps/emqx_management/src/emqx_mgmt_cluster.erl @@ -69,7 +69,8 @@ handle_call({invite_async, Node, JoinTo}, _From, State) -> undefined -> Caller = self(), Task = spawn_link_invite_worker(Node, JoinTo, Caller), - {reply, ok, State#{Node => Task}}; + State1 = remove_finished_task(Node, State), + {reply, ok, State1#{Node => Task}}; WorkerPid -> {reply, {error, {already_started, WorkerPid}}, State} end; @@ -157,6 +158,11 @@ find_node_name_via_worker_pid(WorkerPid, {Key, Task, I}) -> find_node_name_via_worker_pid(WorkerPid, maps:next(I)) end. +remove_finished_task(Node, State = #{history := History}) -> + State#{history => maps:remove(Node, History)}; +remove_finished_task(_Node, State) -> + State. + state_to_invitation_status(State) -> History = maps:get(history, State, #{}), {Succ, Failed} = lists:foldl( diff --git a/apps/emqx_management/test/emqx_mgmt_api_cluster_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_api_cluster_SUITE.erl index b2658f8fa..d1438b3ee 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_cluster_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_cluster_SUITE.erl @@ -190,7 +190,7 @@ t_cluster_invite_async(Config) -> lists:sort(Core1Resp) ), - %% force leave the core2 and replicant + %% force leave the core2 {204} = rpc:call( Core1, emqx_mgmt_api_cluster, @@ -260,7 +260,41 @@ t_cluster_invite_async(Config) -> } ], lists:sort(Core1Resp3) - ). + ), + + %% force leave the core2 + {204} = rpc:call( + Core1, + emqx_mgmt_api_cluster, + force_leave, + [delete, #{bindings => #{node => atom_to_binary(Core2)}}] + ), + %% invite core2 again + ?assertMatch( + {200}, + Invite(Core2) + ), + + %% assert: core2 is in_progress status + {200, InvitationStatus1} = rpc:call(Core1, emqx_mgmt_api_cluster, get_invitation_status, [ + get, #{} + ]), + ?assertMatch( + #{succeed := [], in_progress := [#{node := Core2}], failed := []}, + InvitationStatus1 + ), + + %% waiting the async invitation_succeed + ?assertMatch({succeed, _}, waiting_the_async_invitation_succeed(Core1, Core2)), + + {200, InvitationStatus2} = rpc:call(Core1, emqx_mgmt_api_cluster, get_invitation_status, [ + get, #{} + ]), + ?assertMatch( + #{succeed := [#{node := Core2}], in_progress := [], failed := []}, + InvitationStatus2 + ), + ok. cluster(Config) -> NodeSpec = #{apps => ?APPS}, diff --git a/mix.exs b/mix.exs index 7389cb0f9..bb79c3204 100644 --- a/mix.exs +++ b/mix.exs @@ -55,7 +55,7 @@ defmodule EMQXUmbrella.MixProject do {:cowboy, github: "emqx/cowboy", tag: "2.9.2", override: true}, {:esockd, github: "emqx/esockd", tag: "5.11.1", override: true}, {:rocksdb, github: "emqx/erlang-rocksdb", tag: "1.8.0-emqx-2", override: true}, - {:ekka, github: "emqx/ekka", tag: "0.18.1", override: true}, + {:ekka, github: "emqx/ekka", tag: "0.18.3", override: true}, {:gen_rpc, github: "emqx/gen_rpc", tag: "3.3.1", override: true}, {:grpc, github: "emqx/grpc-erl", tag: "0.6.12", override: true}, {:minirest, github: "emqx/minirest", tag: "1.3.15", override: true}, diff --git a/rebar.config b/rebar.config index a1f17c321..7a2e7ff8c 100644 --- a/rebar.config +++ b/rebar.config @@ -83,7 +83,7 @@ {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.9.2"}}}, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.11.1"}}}, {rocksdb, {git, "https://github.com/emqx/erlang-rocksdb", {tag, "1.8.0-emqx-2"}}}, - {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.18.1"}}}, + {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.18.3"}}}, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.3.1"}}}, {grpc, {git, "https://github.com/emqx/grpc-erl", {tag, "0.6.12"}}}, {minirest, {git, "https://github.com/emqx/minirest", {tag, "1.3.15"}}},