From 499ab5d9c490e1cca0e7af70ee7633d6fdd4d2f9 Mon Sep 17 00:00:00 2001 From: Shawn <506895667@qq.com> Date: Mon, 12 Jul 2021 18:10:47 +0800 Subject: [PATCH] fix(config): configure a plain map for mqueue_priorities --- apps/emqx/etc/emqx.conf | 22 +++++++++++--------- apps/emqx/include/emqx.hrl | 6 ------ apps/emqx/src/emqx_frame.erl | 2 +- apps/emqx/src/emqx_mqueue.erl | 2 ++ apps/emqx/src/emqx_schema.erl | 2 +- apps/emqx/test/emqx_flapping_SUITE.erl | 12 ++--------- apps/emqx/test/emqx_mqtt_SUITE.erl | 9 ++++++++ apps/emqx_coap/test/emqx_coap_SUITE.erl | 2 +- apps/emqx_sn/test/emqx_sn_protocol_SUITE.erl | 1 - 9 files changed, 28 insertions(+), 30 deletions(-) diff --git a/apps/emqx/etc/emqx.conf b/apps/emqx/etc/emqx.conf index ec2636c40..5c8bd5265 100644 --- a/apps/emqx/etc/emqx.conf +++ b/apps/emqx/etc/emqx.conf @@ -1039,26 +1039,28 @@ zones.default { ## ## There's no priority table by default, hence all messages ## are treated equal. - ## The top topicname in the table has the highest priority, and then - ## the next one has the second highest priority, etc. - ## Messages for topics not in the priority table are treated as + ## + ## Priority number [1-255] + ## + ## NOTE: comma and equal signs are not allowed for priority topic names + ## NOTE: Messages for topics not in the priority table are treated as ## either highest or lowest priority depending on the configured ## value for mqtt.mqueue_default_priority ## ## @doc zones..mqtt.mqueue_priorities - ## ValueType: Array + ## ValueType: Map | disabled ## Examples: - ## To configure "t/1" > "t/2" > "t/3": - ## mqueue_priorities: [t/1,t/2,t/3] - ## Default: [] - mqueue_priorities: [] + ## To configure "topic/1" > "topic/2": + ## mqueue_priorities: {"topic/1": 10, "topic/2": 8} + ## Default: disabled + mqueue_priorities: disabled ## Default to highest priority for topics not matching priority table ## ## @doc zones..mqtt.mqueue_default_priority ## ValueType: highest | lowest - ## Default: highest - mqueue_default_priority: highest + ## Default: lowest + mqueue_default_priority: lowest ## Whether to enqueue QoS0 messages. ## diff --git a/apps/emqx/include/emqx.hrl b/apps/emqx/include/emqx.hrl index a11c30cb4..60dccd9a3 100644 --- a/apps/emqx/include/emqx.hrl +++ b/apps/emqx/include/emqx.hrl @@ -35,12 +35,6 @@ -define(ERTS_MINIMUM_REQUIRED, "10.0"). -%%-------------------------------------------------------------------- -%% Configs -%%-------------------------------------------------------------------- - --define(NO_PRIORITY_TABLE, none). - %%-------------------------------------------------------------------- %% Topics' prefix: $SYS | $queue | $share %%-------------------------------------------------------------------- diff --git a/apps/emqx/src/emqx_frame.erl b/apps/emqx/src/emqx_frame.erl index 1737e8791..0bab10e0c 100644 --- a/apps/emqx/src/emqx_frame.erl +++ b/apps/emqx/src/emqx_frame.erl @@ -646,7 +646,7 @@ serialize_properties(Props) when is_map(Props) -> Bin = << <<(serialize_property(Prop, Val))/binary>> || {Prop, Val} <- maps:to_list(Props) >>, [serialize_variable_byte_integer(byte_size(Bin)), Bin]. -serialize_property(_, undefined) -> +serialize_property(_, Disabled) when Disabled =:= disabled; Disabled =:= undefined -> <<>>; serialize_property('Payload-Format-Indicator', Val) -> <<16#01, Val>>; diff --git a/apps/emqx/src/emqx_mqueue.erl b/apps/emqx/src/emqx_mqueue.erl index d0c6365ff..d625209ca 100644 --- a/apps/emqx/src/emqx_mqueue.erl +++ b/apps/emqx/src/emqx_mqueue.erl @@ -67,6 +67,8 @@ , dropped/1 ]). +-define(NO_PRIORITY_TABLE, disabled). + -export_type([mqueue/0, options/0]). -type(topic() :: emqx_topic:topic()). diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 72fe3832b..738623f72 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -277,7 +277,7 @@ fields("mqtt") -> , {"await_rel_timeout", t(duration_s(), undefined, "300s")} , {"session_expiry_interval", t(duration_s(), undefined, "2h")} , {"max_mqueue_len", maybe_infinity(integer(), 1000)} - , {"mqueue_priorities", t(comma_separated_list(), undefined, "none")} + , {"mqueue_priorities", maybe_disabled(map())} , {"mqueue_default_priority", t(union(highest, lowest), undefined, lowest)} , {"mqueue_store_qos0", t(boolean(), undefined, true)} , {"use_username_as_clientid", t(boolean(), undefined, false)} diff --git a/apps/emqx/test/emqx_flapping_SUITE.erl b/apps/emqx/test/emqx_flapping_SUITE.erl index 8f069b747..79eb64b45 100644 --- a/apps/emqx/test/emqx_flapping_SUITE.erl +++ b/apps/emqx/test/emqx_flapping_SUITE.erl @@ -25,18 +25,10 @@ all() -> emqx_ct:all(?MODULE). init_per_suite(Config) -> emqx_ct_helpers:boot_modules(all), - emqx_ct_helpers:start_apps([], fun set_special_configs/1), + emqx_ct_helpers:start_apps([]), + emqx_config:put_listener_conf(default, mqtt_tcp, [flapping_detect, enable], true), Config. -set_special_configs(emqx) -> - emqx_zone:set_env(external, enable_flapping_detect, true), - application:set_env(emqx, flapping_detect_policy, - #{threshold => 3, - duration => 100, - banned_interval => 2 - }); -set_special_configs(_App) -> ok. - end_per_suite(_Config) -> emqx_ct_helpers:stop_apps([]), ekka_mnesia:delete_schema(), %% Clean emqx_banned table diff --git a/apps/emqx/test/emqx_mqtt_SUITE.erl b/apps/emqx/test/emqx_mqtt_SUITE.erl index c86d6334a..42a4e5780 100644 --- a/apps/emqx/test/emqx_mqtt_SUITE.erl +++ b/apps/emqx/test/emqx_mqtt_SUITE.erl @@ -156,6 +156,15 @@ t_async_set_keepalive('end', _Config) -> ok. t_async_set_keepalive(_) -> + case os:type() of + {unix, darwin} -> + %% Mac OSX don't support the feature + ok; + _ -> + do_async_set_keepalive() + end. + +do_async_set_keepalive() -> ClientID = <<"client-tcp-keepalive">>, {ok, Client} = emqtt:start_link([{host, "localhost"}, {proto_ver,v5}, diff --git a/apps/emqx_coap/test/emqx_coap_SUITE.erl b/apps/emqx_coap/test/emqx_coap_SUITE.erl index 9618425a3..d8670eb5c 100644 --- a/apps/emqx_coap/test/emqx_coap_SUITE.erl +++ b/apps/emqx_coap/test/emqx_coap_SUITE.erl @@ -265,7 +265,7 @@ t_kick_1(_Config) -> end. % mqtt connection kicked by coap with same client id -t_acl(Config) -> +t_acl(_Config) -> OldPath = emqx:get_env(plugins_etc_dir), application:set_env(emqx, plugins_etc_dir, emqx_ct_helpers:deps_path(emqx_authz, "test")), diff --git a/apps/emqx_sn/test/emqx_sn_protocol_SUITE.erl b/apps/emqx_sn/test/emqx_sn_protocol_SUITE.erl index 0947bdaca..1371c5123 100644 --- a/apps/emqx_sn/test/emqx_sn_protocol_SUITE.erl +++ b/apps/emqx_sn/test/emqx_sn_protocol_SUITE.erl @@ -170,7 +170,6 @@ t_subscribe_case02(_) -> ReturnCode = 0, {ok, Socket} = gen_udp:open(0, [binary]), - ClientId = ?CLIENTID, send_connect_msg(Socket, ?CLIENTID), ?assertEqual(<<3, ?SN_CONNACK, 0>>, receive_response(Socket)),