Skip to content

Commit ff4d4e4

Browse files
authored
Merge pull request #1283 from basho/fix-az-make_updowngrade_work_for_any_recent_versions
updowngrade: better prepare riak.conf & caps, make it work for 1.4-1.5 and 1.5-1.6 cycles
2 parents d5c6bd6 + 626c4d5 commit ff4d4e4

4 files changed

+85
-27
lines changed

tests/ts_cluster_updowngrade_group_by_SUITE.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%% -------------------------------------------------------------------
22
%%
3-
%% Copyright (c) 2016 Basho Technologies, Inc.
3+
%% Copyright (c) 2016, 2017 Basho Technologies, Inc.
44
%%
55
%% This file is provided to you under the Apache License,
66
%% Version 2.0 (the "License"); you may not use this file
@@ -40,8 +40,8 @@ make_scenarios() ->
4040
need_query_node_transition = NeedQueryNodeTransition,
4141
need_pre_cluster_mixed = NeedPreClusterMixed,
4242
need_post_cluster_mixed = NeedPostClusterMixed,
43-
ensure_full_caps = [{{riak_kv, sql_select_version}, v3}, {{riak_kv, riak_ql_ddl_rec_version}, v2}, {{riak_kv, decode_query_results_at_vnode}, true}],
44-
ensure_degraded_caps = [{{riak_kv, sql_select_version}, v2}, {{riak_kv, riak_ql_ddl_rec_version}, v1}, {{riak_kv, decode_query_results_at_vnode}, false}],
43+
ensure_full_caps = ts_updown_util:caps_to_ensure(full),
44+
ensure_degraded_caps = ts_updown_util:caps_to_ensure(degraded),
4545
convert_config_to_previous = fun ts_updown_util:convert_riak_conf_to_previous/1}
4646
|| TableNodeVsn <- [previous, current],
4747
QueryNodeVsn <- [previous, current],
@@ -51,6 +51,7 @@ make_scenarios() ->
5151
NeedPostClusterMixed <- [true, false]],
5252
[add_tests(X) || X <- BaseScenarios].
5353

54+
5455
%% This test will not use config invariants
5556
%% see ts_cluster_updowngrade_select_aggregation_SUITE.erl for an example
5657
%% of how to use them

tests/ts_cluster_updowngrade_order_by_SUITE.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%% -------------------------------------------------------------------
22
%%
3-
%% Copyright (c) 2016 Basho Technologies, Inc.
3+
%% Copyright (c) 2016, 2017 Basho Technologies, Inc.
44
%%
55
%% This file is provided to you under the Apache License,
66
%% Version 2.0 (the "License"); you may not use this file
@@ -60,8 +60,8 @@ make_scenarios() ->
6060
need_query_node_transition = NeedQueryNodeTransition,
6161
need_pre_cluster_mixed = NeedPreClusterMixed,
6262
need_post_cluster_mixed = NeedPostClusterMixed,
63-
ensure_full_caps = [{{riak_kv, sql_select_version}, v3}, {{riak_kv, riak_ql_ddl_rec_version}, v2}, {{riak_kv, decode_query_results_at_vnode}, true}],
64-
ensure_degraded_caps = [{{riak_kv, sql_select_version}, v2}, {{riak_kv, riak_ql_ddl_rec_version}, v1}, {{riak_kv, decode_query_results_at_vnode}, false}],
63+
ensure_full_caps = ts_updown_util:caps_to_ensure(full),
64+
ensure_degraded_caps = ts_updown_util:caps_to_ensure(degraded),
6565
convert_config_to_previous = fun ts_updown_util:convert_riak_conf_to_previous/1}
6666
|| TableNodeVsn <- [previous, current],
6767
QueryNodeVsn <- [current],

tests/ts_cluster_updowngrade_select_aggregation_SUITE.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%% -------------------------------------------------------------------
22
%%
3-
%% Copyright (c) 2016 Basho Technologies, Inc.
3+
%% Copyright (c) 2016, 2017 Basho Technologies, Inc.
44
%%
55
%% This file is provided to you under the Apache License,
66
%% Version 2.0 (the "License"); you may not use this file
@@ -35,8 +35,8 @@ make_scenarios() ->
3535
need_query_node_transition = NeedQueryNodeTransition,
3636
need_pre_cluster_mixed = NeedPreClusterMixed,
3737
need_post_cluster_mixed = NeedPostClusterMixed,
38-
ensure_full_caps = [{{riak_kv, sql_select_version}, v3}, {{riak_kv, riak_ql_ddl_rec_version}, v2}, {{riak_kv, decode_query_results_at_vnode}, true}],
39-
ensure_degraded_caps = [{{riak_kv, sql_select_version}, v2}, {{riak_kv, riak_ql_ddl_rec_version}, v1}, {{riak_kv, decode_query_results_at_vnode}, false}],
38+
ensure_full_caps = ts_updown_util:caps_to_ensure(full),
39+
ensure_degraded_caps = ts_updown_util:caps_to_ensure(degraded),
4040
convert_config_to_previous = fun ts_updown_util:convert_riak_conf_to_previous/1}
4141
|| TableNodeVsn <- [previous, current],
4242
QueryNodeVsn <- [previous, current],

tests/ts_updown_util.erl

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%% -------------------------------------------------------------------
22
%%
3-
%% Copyright (c) 2016 Basho Technologies, Inc.
3+
%% Copyright (c) 2016, 2017 Basho Technologies, Inc.
44
%%
55
%% This file is provided to you under the Apache License,
66
%% Version 2.0 (the "License"); you may not use this file
@@ -50,6 +50,7 @@
5050
-module(ts_updown_util).
5151

5252
-export([
53+
caps_to_ensure/1,
5354
convert_riak_conf_to_previous/1,
5455
maybe_shutdown_client_node/1,
5556
setup/1,
@@ -581,31 +582,87 @@ wait_until_active_table(TargetNode, PrevClientNode, Table, N) ->
581582
make_msg(Format, Payload) ->
582583
list_to_binary(fmt(Format, Payload)).
583584

585+
586+
get_riak_release_in_slot(VsnSlot) ->
587+
case rtdev:get_version(VsnSlot) of
588+
unknown ->
589+
ct:fail("Failed to determine riak version in '~s' slot", [VsnSlot]);
590+
Known ->
591+
case re:run(Known, "riak_ts-(\\d+)\\.(\\d+)\\.(\\d+)", [{capture, all_but_first, list}]) of
592+
{match, [V1, V2, V3]} ->
593+
{list_to_integer(V1),
594+
list_to_integer(V2),
595+
list_to_integer(V3)};
596+
nomatch ->
597+
ct:fail("Failed to parse riak version in '~s' slot", [VsnSlot])
598+
end
599+
end.
600+
601+
%% ---------------------------------
602+
603+
%% Dealing with case-by-case upgrade particulars, such as:
604+
%%
605+
%% * newly introduced keys in riak.conf that need to be deleted on
606+
%% downgrade;
607+
%%
608+
%% * capabilities that need to be ensured before running the tests
609+
%% (arguments to `wait_until_capability`).
610+
584611
%% We need to comment out those settings which appear in version
585612
%% 1.x. For version 1.x-1 to work with riak.conf initially created in
586613
%% 1.x, the offending settings need to be deleted. We do it here, by
587614
%% commenting them out.
588615

589-
%% riak.conf created under 1.6 cannot be read by 1.5 because of new keys:
590-
%% riak_kv.query.timeseries.qbuf_inmem_max,
591-
%%
592-
%% riak.conf created under 1.5 cannot be read by 1.4 because of new keys:
593-
%% riak_kv.query.timeseries.max_returned_data_size,
594-
%% riak_kv.query.timeseries.qbuf_soft_watermark,
595-
%% riak_kv.query.timeseries.qbuf_hard_watermark,
596-
%% riak_kv.query.timeseries.qbuf_expire_ms,
597-
%% riak_kv.query.timeseries.qbuf_incomplete_release_ms
598-
%%
599616
convert_riak_conf_to_previous(Config) ->
600617
DatafPath = ?CFG(new_data_dir, Config),
601618
RiakConfPath = filename:join(DatafPath, "../etc/riak.conf"),
602-
{ok, Content0} = file:read_file(RiakConfPath),
603-
Content9 =
604-
re:replace(
605-
Content0,
606-
<<"^riak_kv.query.timeseries.qbuf_inmem_max">>,
607-
<<"#\\1">>, [global, multiline, {return, binary}]),
608-
ok = file:write_file(RiakConfPath, Content9).
619+
{ok, Contents0} = file:read_file(RiakConfPath),
620+
Contents9 =
621+
lists:foldl(
622+
fun(KeyToDelete, Contents) ->
623+
re:replace(Contents, ["^", KeyToDelete], "#\\1",
624+
[global, multiline, {return, list}])
625+
end,
626+
Contents0,
627+
get_riak_conf_new_keys()),
628+
ok = file:write_file(RiakConfPath, Contents9).
629+
630+
%% When a new release is cut, register newly introduced keys here:
631+
get_riak_conf_new_keys() ->
632+
%% the current version may have not been tagged yet, so look at
633+
%% previous version
634+
case get_riak_release_in_slot(previous) of
635+
{1, 5, _} ->
636+
["riak_kv.query.timeseries.qbuf_inmem_max"];
637+
{1, 4, _} ->
638+
["riak_kv.query.timeseries.max_returned_data_size",
639+
"riak_kv.query.timeseries.qbuf_soft_watermark",
640+
"riak_kv.query.timeseries.qbuf_hard_watermark",
641+
"riak_kv.query.timeseries.qbuf_expire_ms",
642+
"riak_kv.query.timeseries.qbuf_incomplete_release_ms"]
643+
end.
644+
645+
%% Wait for these capabilities to settle at these versions at the end
646+
%% of upgrade/downgrade:
647+
caps_to_ensure(full) ->
648+
case get_riak_release_in_slot(previous) of
649+
{1, 5, _} ->
650+
[]; %% no new caps in 1.6 since 1.5
651+
{1, 4, _} ->
652+
[{{riak_kv, sql_select_version}, v3},
653+
{{riak_kv, riak_ql_ddl_rec_version}, v2},
654+
{{riak_kv, decode_query_results_at_vnode}, true}]
655+
end;
656+
caps_to_ensure(degraded) ->
657+
case get_riak_release_in_slot(previous) of
658+
{1, 5, _} ->
659+
[]; %% no new caps in 1.6 since 1.5
660+
{1, 4, _} ->
661+
[{{riak_kv, sql_select_version}, v2},
662+
{{riak_kv, riak_ql_ddl_rec_version}, v1},
663+
{{riak_kv, decode_query_results_at_vnode}, false}]
664+
end.
665+
609666

610667
%% Keep the old convert_riak_conf_to_previous functions around, for
611668
%% reference and occasional test rerun

0 commit comments

Comments
 (0)