riak_test/tests/replication_upgrade.erl

69 lines
2.1 KiB
Erlang
Raw Normal View History

2012-11-16 19:49:28 +00:00
-module(replication_upgrade).
2012-12-14 15:50:49 +00:00
-behavior(riak_test).
-export([confirm/0]).
2012-11-16 19:49:28 +00:00
-include_lib("eunit/include/eunit.hrl").
confirm() ->
2013-01-22 18:49:22 +00:00
TestMetaData = riak_test_runner:metadata(),
FromVersion = proplists:get_value(upgrade_version, TestMetaData, previous),
2012-11-16 19:49:28 +00:00
2013-01-22 18:49:22 +00:00
lager:info("Doing rolling replication upgrade test from ~p to ~p",
[FromVersion, "current"]),
2012-11-16 19:49:28 +00:00
2013-01-22 18:49:22 +00:00
NumNodes = rt:config(num_nodes, 6),
2012-11-16 19:49:28 +00:00
2013-01-22 18:49:22 +00:00
UpgradeOrder = rt:config(repl_upgrade_order, "forwards"),
2012-11-16 19:49:28 +00:00
2013-01-22 18:49:22 +00:00
lager:info("Deploy ~p nodes", [NumNodes]),
2012-11-16 19:49:28 +00:00
Conf = [
{riak_repl,
[
{fullsync_on_connect, false},
{fullsync_interval, disabled}
]}
],
NodeConfig = [{FromVersion, Conf} || _ <- lists:seq(1, NumNodes)],
Nodes = rt:deploy_nodes(NodeConfig),
NodeUpgrades = case UpgradeOrder of
"forwards" ->
Nodes;
"backwards" ->
lists:reverse(Nodes);
"alternate" ->
%% eg 1, 4, 2, 5, 3, 6
lists:flatten(lists:foldl(fun(E, [A,B,C]) -> [B, C, A ++ [E]] end,
[[],[],[]], Nodes));
"random" ->
%% halfass randomization
lists:sort(fun(_, _) -> random:uniform(100) < 50 end, Nodes);
Other ->
lager:error("Invalid upgrade ordering ~p", [Other]),
erlang:exit()
end,
lager:info("Upgrading nodes in order: ~p", [NodeUpgrades]),
2013-01-22 18:49:22 +00:00
ClusterASize = rt:config(cluster_a_size, 3),
2012-11-16 19:49:28 +00:00
{ANodes, BNodes} = lists:split(ClusterASize, Nodes),
lager:info("ANodes: ~p", [ANodes]),
lager:info("BNodes: ~p", [BNodes]),
lager:info("Build cluster A"),
replication:make_cluster(ANodes),
lager:info("Build cluster B"),
replication:make_cluster(BNodes),
%% initial replication run, homogeneous cluster
replication:replication(ANodes, BNodes, false),
%% upgrade the nodes, one at a time
lists:foreach(fun(Node) ->
2013-01-23 21:26:54 +00:00
rtdev:upgrade(Node, current),
2012-11-16 19:49:28 +00:00
rt:wait_until_pingable(Node),
timer:sleep(1000),
replication:replication(ANodes, BNodes, true)
end, NodeUpgrades).