Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cets/prevent crash on upgrade #4256

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}.

Check warning on line 32 in src/mongoose_cets_discovery_rdbms.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cets_discovery_rdbms.erl#L30-L32

Added lines #L30 - L32 were not covered by tests

cluster_name_with_vsn(ClusterName) ->
{ok, CetsVsn} = application:get_key(cets, vsn),
[MajorVsn, MinorVsn | _] = string:tokens(CetsVsn, "."),
iolist_to_binary([ClusterName, $-, MajorVsn, $., MinorVsn]).

Check warning on line 37 in src/mongoose_cets_discovery_rdbms.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cets_discovery_rdbms.erl#L35-L37

Added lines #L35 - L37 were not covered by tests

defaults() ->
#{expire_time => 60 * 60 * 1, %% 1 hour in seconds
Expand Down