From f102499aecc8a6dd4d008d025669543568fab990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Tue, 9 Apr 2024 09:29:40 +0200 Subject: [PATCH 1/3] Put CETS version in cluster name When performing a rolling upgrade e.g. from 6.2.0 to the upcoming 6.2.1, CETS would crash on all nodes due to version incompatibility. This can be prevented by putting cets 'Major.Minor' version in the cluster name, making the two cluster components disjoint during upgrade. The only thing to keep in mind is to bump the Major or Minor version number when there is any incompatibility in the CETS inter-node API. --- src/mongoose_cets_discovery_rdbms.erl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mongoose_cets_discovery_rdbms.erl b/src/mongoose_cets_discovery_rdbms.erl index 3e0042e81d..b6342bd074 100644 --- a/src/mongoose_cets_discovery_rdbms.erl +++ b/src/mongoose_cets_discovery_rdbms.erl @@ -25,8 +25,14 @@ -spec init(opts()) -> state(). init(Opts = #{cluster_name := ClusterName, node_name_to_insert := Node}) when is_binary(ClusterName), is_binary(Node) -> - Keys = [cluster_name, node_name_to_insert, last_query_info, expire_time, node_ip_binary], - maps:with(Keys, maps:merge(defaults(), Opts)). + Keys = [node_name_to_insert, expire_time, last_query_info, node_ip_binary], + StateOpts = maps:merge(defaults(), maps:with(Keys, Opts)), + StateOpts#{cluster_name => cluster_name_with_vsn(ClusterName)}. + +cluster_name_with_vsn(ClusterName) -> + {ok, CetsVsn} = application:get_key(cets, vsn), + [MajorVsn, MinorVsn | _] = string:tokens(CetsVsn, "."), + iolist_to_binary([ClusterName, $-, MajorVsn, $., MinorVsn]). defaults() -> #{expire_time => 60 * 60 * 1, %% 1 hour in seconds From e4ef412a0cb81d8f98e10d95ab542fffca6965c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Tue, 9 Apr 2024 11:55:05 +0200 Subject: [PATCH 2/3] Check that CETS version is added to cluster name --- big_tests/tests/cets_disco_SUITE.erl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/big_tests/tests/cets_disco_SUITE.erl b/big_tests/tests/cets_disco_SUITE.erl index b03dc68cbe..0f233df032 100644 --- a/big_tests/tests/cets_disco_SUITE.erl +++ b/big_tests/tests/cets_disco_SUITE.erl @@ -23,6 +23,7 @@ file_cases() -> rdbms_cases() -> [rdbms_backend, rdbms_backend_supports_cluster_change, + rdbms_backend_cluster_name_contains_cets_version, rdbms_backend_supports_auto_cleaning, rdbms_backend_node_doesnt_remove_itself, rdbms_backend_db_queries, @@ -120,6 +121,13 @@ rdbms_backend_supports_cluster_change(_Config) -> init_and_get_nodes(mim2(), Opts2#{cluster_name := CN2}, [test1]), get_nodes(mim(), NewState1A, [test1, test2]). +rdbms_backend_cluster_name_contains_cets_version(_Config) -> + CN = random_cluster_name(?FUNCTION_NAME), + Opts = #{cluster_name => CN, node_name_to_insert => <<"test1">>}, + #{cluster_name := CNWithVsn} = init_and_get_nodes(mim(), Opts, []), + [<<>>, Vsn] = binary:split(CNWithVsn, CN), + ?assertMatch({match, _}, re:run(Vsn, "-[0-9]+\\.[0-9]+")). + rdbms_backend_supports_auto_cleaning(_Config) -> Timestamp = month_ago(), mock_timestamp(mim(), Timestamp), From 082f1e01c1b925c4d62e3fdbc60d63be63fe49f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chrz=C4=85szcz?= Date: Tue, 9 Apr 2024 12:38:54 +0200 Subject: [PATCH 3/3] Update tests with the new cluster name --- big_tests/tests/graphql_cets_SUITE.erl | 2 +- src/mongoose_cets_discovery_rdbms.erl | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/big_tests/tests/graphql_cets_SUITE.erl b/big_tests/tests/graphql_cets_SUITE.erl index 8017a98361..df68214748 100644 --- a/big_tests/tests/graphql_cets_SUITE.erl +++ b/big_tests/tests/graphql_cets_SUITE.erl @@ -242,7 +242,7 @@ add_bad_node() -> wait_for_has_bad_node(). register_bad_node() -> - ClusterName = <<"mim">>, + ClusterName = rpc(mim(), mongoose_cets_discovery_rdbms, cluster_name_with_vsn, [<<"mim">>]), Node = <<"badnode@localhost">>, Num = 100, Address = <<>>, diff --git a/src/mongoose_cets_discovery_rdbms.erl b/src/mongoose_cets_discovery_rdbms.erl index b6342bd074..39fd7f918b 100644 --- a/src/mongoose_cets_discovery_rdbms.erl +++ b/src/mongoose_cets_discovery_rdbms.erl @@ -4,8 +4,10 @@ -export([init/1, get_nodes/1]). %% these functions are exported for testing purposes only. --export([select/1, insert_new/5, update_existing/3, delete_node_from_db/1]). --ignore_xref([select/1, insert_new/5, update_existing/3, delete_node_from_db/1]). +-export([select/1, insert_new/5, update_existing/3, delete_node_from_db/1, + cluster_name_with_vsn/1]). +-ignore_xref([select/1, insert_new/5, update_existing/3, delete_node_from_db/1, + cluster_name_with_vsn/1]). -include("mongoose_logger.hrl").