From 13c6c62d8528872e07fb823522f859e3537db2e5 Mon Sep 17 00:00:00 2001 From: ieQu1 <99872536+ieQu1@users.noreply.github.com> Date: Tue, 26 Mar 2024 13:32:14 +0100 Subject: [PATCH] fix(mria): Strictly check compatibility of the replicant with core --- apps/emqx/rebar.config | 2 +- apps/emqx_machine/src/emqx_machine.erl | 28 ++++++++++++++++++++++++++ changes/ce/fix-12786.en.md | 2 ++ rebar.config | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 changes/ce/fix-12786.en.md diff --git a/apps/emqx/rebar.config b/apps/emqx/rebar.config index 3822078b76..14b041615b 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.19.0"}}}, + {ekka, {git, "https://github.com/emqx/ekka", {branch, "dev/custom-core-compat-cb"}}}, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "3.3.1"}}}, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.42.1"}}}, {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.5.3"}}}, diff --git a/apps/emqx_machine/src/emqx_machine.erl b/apps/emqx_machine/src/emqx_machine.erl index d8858ff16a..e676f16cb2 100644 --- a/apps/emqx_machine/src/emqx_machine.erl +++ b/apps/emqx_machine/src/emqx_machine.erl @@ -51,6 +51,26 @@ start() -> configure_shard_transports(), set_mnesia_extra_diagnostic_checks(), emqx_otel_app:configure_otel_deps(), + %% Register mria callbacks that help to check compatibility of the + %% replicant with the core node. Currently they rely on the exact + %% match of the version of EMQX OTP application: + application:load(mria), + application:load(emqx), + mria_config:register_callback( + lb_custom_info, + fun() -> + get_emqx_vsn() + end + ), + mria_config:register_callback( + lb_custom_info_check, + fun + (undefined) -> + false; + (OtherVsn) -> + get_emqx_vsn() =:= OtherVsn + end + ), ekka:start(), ok. @@ -227,3 +247,11 @@ resolve_dist_address_type() -> _ -> inet end. + +get_emqx_vsn() -> + case application:get_key(emqx, vsn) of + {ok, Vsn} -> + Vsn; + undefined -> + undefined + end. diff --git a/changes/ce/fix-12786.en.md b/changes/ce/fix-12786.en.md new file mode 100644 index 0000000000..49acef7da8 --- /dev/null +++ b/changes/ce/fix-12786.en.md @@ -0,0 +1,2 @@ +Add a strict check that prevents replicant nodes from connecting to the core nodes running with a different version of EMQX application. +Effectively it means that during the rolling upgrades the replicant nodes can only work if there is at least one core node with the matching EMQX release. diff --git a/rebar.config b/rebar.config index 6713b5c9bd..6a9a85ef76 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.19.0"}}}, + {ekka, {git, "https://github.com/emqx/ekka", {branch, "dev/custom-core-compat-cb"}}}, {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.4.0"}}},