From 52e6c88941c6899f40b1b1080199a10d62524bf3 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Thu, 13 Jun 2024 16:57:46 -0300 Subject: [PATCH] feat: enforce singleton discovery strategy when using DS `builtin_local` backend Fixes https://emqx.atlassian.net/browse/EMQX-12493 --- apps/emqx_conf/src/emqx_conf_schema.erl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index 2c0de10aa..dc85cbf3c 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -134,10 +134,27 @@ roots() -> lists:flatmap(fun roots/1, common_apps()). validations() -> - [{check_node_name_and_discovery_strategy, fun validate_cluster_strategy/1}] ++ + [ + {check_node_name_and_discovery_strategy, fun validate_cluster_strategy/1}, + {validate_durable_sessions_strategy, fun validate_durable_sessions_strategy/1} + ] ++ hocon_schema:validations(emqx_schema) ++ lists:flatmap(fun hocon_schema:validations/1, common_apps()). +validate_durable_sessions_strategy(Conf) -> + DSEnabled = hocon_maps:get("durable_sessions.enable", Conf), + DiscoveryStrategy = hocon_maps:get("cluster.discovery_strategy", Conf), + DSBackend = hocon_maps:get("durable_storage.messages.backend", Conf), + case {DSEnabled, DSBackend} of + {true, builtin_local} when DiscoveryStrategy =/= singleton -> + {error, << + "cluster discovery strategy must be 'singleton' when" + " durable storage backend is builtin_local" + >>}; + _ -> + ok + end. + common_apps() -> Edition = emqx_release:edition(), lists:filtermap( @@ -166,7 +183,7 @@ fields("cluster") -> )}, {"discovery_strategy", sc( - hoconsc:enum([manual, static, dns, etcd, k8s]), + hoconsc:enum([manual, static, singleton, dns, etcd, k8s]), #{ default => manual, desc => ?DESC(cluster_discovery_strategy),