From f9597bb2474587cb21c128db67a3d400fcacc742 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 29 Mar 2022 15:15:11 -0300 Subject: [PATCH 1/4] fix: set default db backend in etc/emqx_conf.conf --- apps/emqx_conf/etc/emqx_conf.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/emqx_conf/etc/emqx_conf.conf b/apps/emqx_conf/etc/emqx_conf.conf index c6bf76901..4869c2297 100644 --- a/apps/emqx_conf/etc/emqx_conf.conf +++ b/apps/emqx_conf/etc/emqx_conf.conf @@ -319,8 +319,8 @@ db { ## ## @doc db.backend ## ValueType: mnesia | rlog - ## Default: mnesia - backend = mnesia + ## Default: rlog + backend = rlog ## RLOG role ## From 187079859b6db569eab33d1c6ade4cb32894d571 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 29 Mar 2022 15:17:49 -0300 Subject: [PATCH 2/4] chore: bump hocon -> 0.26.6 --- apps/emqx/rebar.config | 2 +- apps/emqx_prometheus/rebar.config | 2 +- mix.exs | 2 +- rebar.config | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/emqx/rebar.config b/apps/emqx/rebar.config index aea67376c..ef91981c5 100644 --- a/apps/emqx/rebar.config +++ b/apps/emqx/rebar.config @@ -30,7 +30,7 @@ {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.1"}}}, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.12.3"}}}, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.8.1"}}}, - {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.26.4"}}}, + {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.26.6"}}}, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}, {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.18.0"}}} diff --git a/apps/emqx_prometheus/rebar.config b/apps/emqx_prometheus/rebar.config index 42212df9f..b05091515 100644 --- a/apps/emqx_prometheus/rebar.config +++ b/apps/emqx_prometheus/rebar.config @@ -4,7 +4,7 @@ [ {emqx, {path, "../emqx"}}, %% FIXME: tag this as v3.1.3 {prometheus, {git, "https://github.com/deadtrickster/prometheus.erl", {tag, "v4.8.1"}}}, - {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.26.4"}}} + {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.26.6"}}} ]}. {edoc_opts, [{preprocess, true}]}. diff --git a/mix.exs b/mix.exs index d7d05e979..d87a4366b 100644 --- a/mix.exs +++ b/mix.exs @@ -68,7 +68,7 @@ defmodule EMQXUmbrella.MixProject do # in conflict by emqtt and hocon {:getopt, "1.0.2", override: true}, {:snabbkaffe, github: "kafka4beam/snabbkaffe", tag: "0.18.0", override: true}, - {:hocon, github: "emqx/hocon", tag: "0.26.4", override: true}, + {:hocon, github: "emqx/hocon", tag: "0.26.6", override: true}, {:emqx_http_lib, github: "emqx/emqx_http_lib", tag: "0.4.1", override: true}, {:esasl, github: "emqx/esasl", tag: "0.2.0"}, {:jose, github: "potatosalad/erlang-jose", tag: "1.11.2"}, diff --git a/rebar.config b/rebar.config index 2e3544309..e62810ece 100644 --- a/rebar.config +++ b/rebar.config @@ -66,7 +66,7 @@ , {system_monitor, {git, "https://github.com/ieQu1/system_monitor", {tag, "3.0.2"}}} , {getopt, "1.0.2"} , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.18.0"}}} - , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.26.4"}}} + , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.26.6"}}} , {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.4.1"}}} , {esasl, {git, "https://github.com/emqx/esasl", {tag, "0.2.0"}}} , {jose, {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.11.2"}}} From 2a48f143bd17063b60522f9c0290e2fb92c57c3c Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 29 Mar 2022 16:55:21 -0300 Subject: [PATCH 3/4] style: please elvis checks --- apps/emqx_machine/src/emqx_machine.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/emqx_machine/src/emqx_machine.erl b/apps/emqx_machine/src/emqx_machine.erl index 27a720a8d..85b645d1b 100644 --- a/apps/emqx_machine/src/emqx_machine.erl +++ b/apps/emqx_machine/src/emqx_machine.erl @@ -30,7 +30,7 @@ start() -> case os:type() of {win32, nt} -> ok; - _nix -> + _Nix -> os:set_signal(sighup, ignore), os:set_signal(sigterm, handle) %% default is handle end, @@ -64,7 +64,7 @@ start_sysmon() -> application:set_env(system_monitor, node_status_fun, {?MODULE, node_status}), application:set_env(system_monitor, status_checks, [{?MODULE, update_vips, false, 10}]), case application:get_env(system_monitor, db_hostname) of - {ok, [_|_]} -> + {ok, [_ | _]} -> application:set_env(system_monitor, callback_mod, system_monitor_pg), _ = application:ensure_all_started(system_monitor, temporary), ok; From 5748b9b492d8080c283580d7c1158e48630ca227 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Tue, 29 Mar 2022 15:43:59 -0300 Subject: [PATCH 4/4] feat: allow customizing per-shard transaction log transport --- apps/emqx_conf/src/emqx_conf_schema.erl | 22 +++++++++++++ apps/emqx_machine/src/emqx_machine.erl | 10 ++++++ apps/emqx_machine/test/emqx_machine_SUITE.erl | 33 ++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index 6830eda00..c616ad148 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -489,6 +489,28 @@ In sync mode the core node waits for an ack from the replicant nodes before send transaction log entry. """ })} + , {"default_shard_transport", + sc(hoconsc:enum([gen_rpc, distr]), + #{ mapping => "mria.shard_transport" + , default => gen_rpc + , desc => + "Defines the default transport for pushing transaction logs.
" + "This may be overridden on a per-shard basis in db.shard_transports." + "gen_rpc uses the gen_rpc library, " + "distr uses the Erlang distribution.
" + })} + , {"shard_transports", + sc(map(shard, hoconsc:enum([gen_rpc, distr])), + #{ desc => + "Allows to tune the transport method used for transaction log replication, " + "on a per-shard basis.
" + "gen_rpc uses the gen_rpc library, " + "distr uses the Erlang distribution.
" + "If not specified, the default is to use the value " + "set in db.default_shard_transport." + , mapping => "emqx_machine.custom_shard_transports" + , default => #{} + })} ]; fields("cluster_call") -> diff --git a/apps/emqx_machine/src/emqx_machine.erl b/apps/emqx_machine/src/emqx_machine.erl index 85b645d1b..0285e5141 100644 --- a/apps/emqx_machine/src/emqx_machine.erl +++ b/apps/emqx_machine/src/emqx_machine.erl @@ -36,6 +36,7 @@ start() -> end, ok = set_backtrace_depth(), start_sysmon(), + configure_shard_transports(), ekka:start(), ok = print_otp_version_warning(). @@ -81,3 +82,12 @@ node_status() -> update_vips() -> system_monitor:add_vip(mria_status:shards_up()). + +configure_shard_transports() -> + ShardTransports = application:get_env(emqx_machine, custom_shard_transports, #{}), + maps:foreach( + fun(ShardBin, Transport) -> + ShardName = binary_to_existing_atom(ShardBin), + mria_config:set_shard_transport(ShardName, Transport) + end, + ShardTransports). diff --git a/apps/emqx_machine/test/emqx_machine_SUITE.erl b/apps/emqx_machine/test/emqx_machine_SUITE.erl index 800aa221b..01b2d59fc 100644 --- a/apps/emqx_machine/test/emqx_machine_SUITE.erl +++ b/apps/emqx_machine/test/emqx_machine_SUITE.erl @@ -34,7 +34,7 @@ init_per_suite(Config) -> %% emqx_machine_SUITE.erl %% %% Reason: - %% the `emqx_machine_boot:ensure_apps_started()` will crashed + %% the `emqx_machine_boot:ensure_apps_started()` will crash %% on starting `emqx_authz` with dirty confs, which caused the file %% `.._build/test/lib/emqx_conf/etc/acl.conf` could not be found %% @@ -65,6 +65,25 @@ init_per_suite(Config) -> end_per_suite(_Config) -> emqx_common_test_helpers:stop_apps([]). +init_per_testcase(t_custom_shard_transports, Config) -> + OldConfig = application:get_env(emqx_machine, custom_shard_transports), + [{old_config, OldConfig} | Config]; +init_per_testcase(_TestCase, Config) -> + Config. + +end_per_testcase(t_custom_shard_transports, Config) -> + OldConfig0 = ?config(old_config, Config), + application:stop(ekka), + case OldConfig0 of + {ok, OldConfig} -> + application:set_env(emqx_machine, custom_shard_transports, OldConfig); + undefined -> + application:unset_env(emqx_machine, custom_shard_transports) + end, + ok; +end_per_testcase(_TestCase, _Config) -> + ok. + t_shutdown_reboot(_Config) -> emqx_machine_boot:stop_apps(), false = emqx:is_running(node()), @@ -72,3 +91,15 @@ t_shutdown_reboot(_Config) -> true = emqx:is_running(node()), ok = emqx_machine_boot:stop_apps(), false = emqx:is_running(node()). + +t_custom_shard_transports(_Config) -> + %% used to ensure the atom exists + Shard = test_shard, + %% the config keys are binaries + ShardBin = atom_to_binary(Shard), + DefaultTransport = gen_rpc, + ?assertEqual(DefaultTransport, mria_config:shard_transport(Shard)), + application:set_env(emqx_machine, custom_shard_transports, #{ShardBin => distr}), + emqx_machine:start(), + ?assertEqual(distr, mria_config:shard_transport(Shard)), + ok.