|
1 | 1 | %% ------------------------------------------------------------------- |
2 | 2 | %% |
3 | | -%% Copyright (c) 2016 Basho Technologies, Inc. |
| 3 | +%% Copyright (c) 2016, 2017 Basho Technologies, Inc. |
4 | 4 | %% |
5 | 5 | %% This file is provided to you under the Apache License, |
6 | 6 | %% Version 2.0 (the "License"); you may not use this file |
|
50 | 50 | -module(ts_updown_util). |
51 | 51 |
|
52 | 52 | -export([ |
| 53 | + caps_to_ensure/1, |
53 | 54 | convert_riak_conf_to_previous/1, |
54 | 55 | maybe_shutdown_client_node/1, |
55 | 56 | setup/1, |
@@ -581,31 +582,87 @@ wait_until_active_table(TargetNode, PrevClientNode, Table, N) -> |
581 | 582 | make_msg(Format, Payload) -> |
582 | 583 | list_to_binary(fmt(Format, Payload)). |
583 | 584 |
|
| 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 | + |
584 | 611 | %% We need to comment out those settings which appear in version |
585 | 612 | %% 1.x. For version 1.x-1 to work with riak.conf initially created in |
586 | 613 | %% 1.x, the offending settings need to be deleted. We do it here, by |
587 | 614 | %% commenting them out. |
588 | 615 |
|
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 | | -%% |
599 | 616 | convert_riak_conf_to_previous(Config) -> |
600 | 617 | DatafPath = ?CFG(new_data_dir, Config), |
601 | 618 | 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 | + |
609 | 666 |
|
610 | 667 | %% Keep the old convert_riak_conf_to_previous functions around, for |
611 | 668 | %% reference and occasional test rerun |
|
0 commit comments