Skip to content

Commit

Permalink
Merge pull request #4256 from esl/cets/prevent-crash-on-upgrade
Browse files Browse the repository at this point in the history
Cets/prevent crash on upgrade
  • Loading branch information
JanuszJakubiec authored Apr 9, 2024
2 parents 5272f6b + 082f1e0 commit e798ab4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 8 additions & 0 deletions big_tests/tests/cets_disco_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/graphql_cets_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<>>,
Expand Down
16 changes: 12 additions & 4 deletions src/mongoose_cets_discovery_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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").

Expand All @@ -25,8 +27,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
Expand Down

0 comments on commit e798ab4

Please sign in to comment.