2013-02-07 16:45:55 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2012 Basho Technologies, Inc.
|
|
|
|
%%
|
|
|
|
%% This file is provided to you under the Apache License,
|
|
|
|
%% Version 2.0 (the "License"); you may not use this file
|
|
|
|
%% except in compliance with the License. You may obtain
|
|
|
|
%% a copy of the License at
|
|
|
|
%%
|
|
|
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
%%
|
|
|
|
%% Unless required by applicable law or agreed to in writing,
|
|
|
|
%% software distributed under the License is distributed on an
|
|
|
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
%% KIND, either express or implied. See the License for the
|
|
|
|
%% specific language governing permissions and limitations
|
|
|
|
%% under the License.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
2013-02-07 18:25:58 +00:00
|
|
|
-module(loaded_upgrade_worker_sup).
|
2013-01-29 21:54:23 +00:00
|
|
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
2013-01-31 00:30:15 +00:00
|
|
|
-include_lib("riakc/include/riakc.hrl").
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2013-02-07 18:10:46 +00:00
|
|
|
-behavior(supervisor).
|
2013-01-29 21:54:23 +00:00
|
|
|
|
|
|
|
%% API
|
2013-02-07 18:10:46 +00:00
|
|
|
-export([assert_equal/2]).
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
-export([list_keys_tester/5, kv_tester/5, mapred_tester/5,
|
|
|
|
twoi_tester/5, search_tester/5, tester_start_link/4]).
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2013-02-07 18:10:46 +00:00
|
|
|
-export([init/1]).
|
2014-01-07 22:56:20 +00:00
|
|
|
-export([start_link/5]).
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2013-02-07 18:10:46 +00:00
|
|
|
%% Helper macro for declaring children of supervisor
|
2014-01-07 22:56:20 +00:00
|
|
|
-define(CHILD(Name, FunName, Node, Vsn, ReportPid), {
|
2013-02-07 18:10:46 +00:00
|
|
|
list_to_atom(atom_to_list(Name) ++ "_" ++ atom_to_list(FunName)),
|
2014-01-07 22:56:20 +00:00
|
|
|
{ ?MODULE,
|
|
|
|
tester_start_link,
|
|
|
|
[FunName, Node, Vsn, ReportPid]},
|
2013-02-07 18:10:46 +00:00
|
|
|
permanent, 5000, worker, [?MODULE]}).
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
start_link(Name, Node, Backend, Vsn, ReportPid) ->
|
|
|
|
supervisor:start_link(?MODULE, [Name, Node, Backend, Vsn, ReportPid]).
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
init([Name, Node, Backend, Vsn, ReportPid]) ->
|
2013-02-06 17:20:38 +00:00
|
|
|
rt:wait_for_service(Node, [riak_search,riak_kv,riak_pipe]),
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
ChildSpecs1 = [
|
|
|
|
?CHILD(Name, FunName, Node, Vsn, ReportPid)
|
|
|
|
|| FunName <- [list_keys_tester, kv_tester, search_tester]],
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2013-02-07 18:10:46 +00:00
|
|
|
ChildSpecs = case Backend of
|
2013-01-31 00:30:15 +00:00
|
|
|
eleveldb ->
|
2014-01-07 22:56:20 +00:00
|
|
|
[?CHILD(Name, twoi_tester, Node, Vsn, ReportPid) | ChildSpecs1];
|
2013-02-07 18:10:46 +00:00
|
|
|
_ -> ChildSpecs1
|
2013-01-31 00:30:15 +00:00
|
|
|
end,
|
2013-02-07 18:10:46 +00:00
|
|
|
{ok, {{one_for_one, 1000, 60}, ChildSpecs}}.
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2013-01-29 21:54:23 +00:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
tester_start_link(Function, Node, Vsn, ReportPid) ->
|
|
|
|
{ok, spawn_link(?MODULE, Function, [Node, 0, undefined, Vsn, ReportPid])}.
|
2013-02-07 18:10:46 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
list_keys_tester(Node, Count, Pid, Vsn, ReportPid) ->
|
2013-02-05 19:28:30 +00:00
|
|
|
PBC = pb_pid_recycler(Pid, Node),
|
2013-01-31 17:11:02 +00:00
|
|
|
case riakc_pb_socket:list_keys(PBC, <<"objects">>) of
|
|
|
|
{ok, Keys} ->
|
|
|
|
ActualKeys = lists:usort(Keys),
|
2013-02-05 19:29:25 +00:00
|
|
|
ExpectedKeys = lists:usort([loaded_upgrade:int_to_key(K) || K <- lists:seq(0, 100)]),
|
2013-02-07 18:10:46 +00:00
|
|
|
case assert_equal(ExpectedKeys, ActualKeys) of
|
2013-02-01 22:08:03 +00:00
|
|
|
true -> cool;
|
2014-01-07 22:56:20 +00:00
|
|
|
_ -> ReportPid ! {listkeys, Node, not_equal}
|
2013-02-05 19:28:30 +00:00
|
|
|
end;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, timeout} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {listkeys, Node, timeout};
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, {timeout, _}} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {listkeys, Node, timeout};
|
2013-02-05 19:28:30 +00:00
|
|
|
Unexpected ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {listkeys, Node, Unexpected}
|
2013-02-05 19:28:30 +00:00
|
|
|
end,
|
2014-01-07 22:56:20 +00:00
|
|
|
list_keys_tester(Node, Count + 1, PBC, Vsn, ReportPid).
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
kv_tester(Node, Count, Pid, Vsn, ReportPid) ->
|
2013-02-05 19:28:30 +00:00
|
|
|
PBC = pb_pid_recycler(Pid, Node),
|
2013-01-31 00:30:15 +00:00
|
|
|
Key = Count rem 8000,
|
2013-02-05 19:29:25 +00:00
|
|
|
case riakc_pb_socket:get(PBC, loaded_upgrade:bucket(kv), loaded_upgrade:int_to_key(Key)) of
|
2013-01-31 17:11:02 +00:00
|
|
|
{ok, Val} ->
|
2013-02-05 19:29:25 +00:00
|
|
|
case loaded_upgrade:kv_valgen(Key) == riakc_obj:get_value(Val) of
|
2013-02-01 22:08:03 +00:00
|
|
|
true -> cool;
|
2014-01-07 22:56:20 +00:00
|
|
|
_ -> ReportPid ! {kv, Node, not_equal}
|
2013-02-05 19:28:30 +00:00
|
|
|
end;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, disconnected} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-13 00:56:29 +00:00
|
|
|
{error, notfound} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {kv, Node, {notfound, Key}};
|
2013-02-05 19:28:30 +00:00
|
|
|
Unexpected ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {kv, Node, Unexpected}
|
2013-02-05 19:28:30 +00:00
|
|
|
end,
|
2014-01-07 22:56:20 +00:00
|
|
|
kv_tester(Node, Count + 1, PBC, Vsn, ReportPid).
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
mapred_tester(Node, Count, Pid, Vsn, ReportPid) ->
|
2013-02-05 19:28:30 +00:00
|
|
|
PBC = pb_pid_recycler(Pid, Node),
|
2013-02-05 19:29:25 +00:00
|
|
|
case riakc_pb_socket:mapred(PBC, loaded_upgrade:bucket(mapred), loaded_upgrade:erlang_mr()) of
|
2013-01-31 00:30:15 +00:00
|
|
|
{ok, [{1, [10000]}]} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2014-01-07 22:56:20 +00:00
|
|
|
{ok, R} ->
|
|
|
|
lager:warning("Bad MR result: ~p", [R]),
|
|
|
|
ReportPid ! {mapred, Node, bad_result};
|
2013-01-31 17:11:02 +00:00
|
|
|
{error, disconnected} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
%% Finkmaster Flex says timeouts are ok
|
|
|
|
{error, timeout} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-01-31 17:11:02 +00:00
|
|
|
{error, {timeout, _}} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":\"listkeys\",\"error\":\"{badmatch,{'EXIT',noproc}}", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
|
|
|
{error, <<"{\"phase\":\"listkeys\",\"error\":\"{badmatch,{'EXIT',timeout}}", _/binary>>} ->
|
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":0,\"error\":\"badarg", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":0,\"error\":\"[preflist_exhausted]", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":0,\"error\":\"{badmatch,{'EXIT',timeout}}", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":\"listkeys\",\"error\":\"function_clause\",\"input\":\"{cover,", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":\"listkeys\",\"error\":\"badarg\",\"input\":\"{cover,", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"Error processing stream message: exit:{ucs,{bad_utf8_character_code}}:[{xmerl_ucs,", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":0,\"error\":\"[{vnode_down,{shutdown,{gen_fsm,sync_send_event,", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, <<"{\"phase\":0,\"error\":\"[{vnode_down,noproc}]", _/binary>>} ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
|
|
|
Unexpected ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {mapred, Node, Unexpected}
|
2013-02-05 19:28:30 +00:00
|
|
|
end,
|
2014-01-07 22:56:20 +00:00
|
|
|
mapred_tester(Node, Count + 1, PBC, Vsn, ReportPid).
|
2013-01-31 00:30:15 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
twoi_tester(Node, 0, undefined, legacy, ReportPid) ->
|
2013-02-13 21:30:14 +00:00
|
|
|
lager:warning("Legacy nodes do not have 2i load applied"),
|
2014-01-07 22:56:20 +00:00
|
|
|
twoi_tester(Node, 1, undefined, legacy, ReportPid);
|
|
|
|
twoi_tester(Node, Count, Pid, legacy, ReportPid) ->
|
|
|
|
twoi_tester(Node, Count + 1, Pid, legacy, ReportPid);
|
|
|
|
twoi_tester(Node, Count, Pid, Vsn, ReportPid) ->
|
2013-02-05 19:28:30 +00:00
|
|
|
PBC = pb_pid_recycler(Pid, Node),
|
2013-01-31 00:30:15 +00:00
|
|
|
Key = Count rem 8000,
|
2013-02-05 19:29:25 +00:00
|
|
|
ExpectedKeys = [loaded_upgrade:int_to_key(Key)],
|
2013-01-31 17:11:02 +00:00
|
|
|
case {
|
|
|
|
riakc_pb_socket:get_index(
|
2013-02-05 19:28:30 +00:00
|
|
|
PBC,
|
2013-02-05 19:29:25 +00:00
|
|
|
loaded_upgrade:bucket(twoi),
|
2013-02-05 19:28:30 +00:00
|
|
|
{binary_index, "plustwo"},
|
2013-02-05 19:29:25 +00:00
|
|
|
loaded_upgrade:int_to_key(Key + 2)),
|
2013-01-31 17:11:02 +00:00
|
|
|
riakc_pb_socket:get_index(
|
2014-01-07 22:56:20 +00:00
|
|
|
PBC,
|
2013-02-05 19:29:25 +00:00
|
|
|
loaded_upgrade:bucket(twoi),
|
2013-02-05 19:28:30 +00:00
|
|
|
{integer_index, "plusone"},
|
2013-01-31 17:11:02 +00:00
|
|
|
Key + 1)
|
2014-01-07 22:56:20 +00:00
|
|
|
} of
|
2013-07-16 20:20:49 +00:00
|
|
|
{{ok, ?INDEX_RESULTS{keys=BinKeys}}, {ok, ?INDEX_RESULTS{keys=IntKeys}}} ->
|
2013-02-07 18:10:46 +00:00
|
|
|
case {assert_equal(ExpectedKeys, BinKeys), assert_equal(ExpectedKeys, IntKeys)} of
|
2013-02-01 22:08:03 +00:00
|
|
|
{true, true} -> cool;
|
|
|
|
{false, false} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {twoi, Node, bolth_no_match};
|
2013-02-01 22:08:03 +00:00
|
|
|
{false, true} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {twoi, Node, bin_no_match};
|
2013-02-01 22:08:03 +00:00
|
|
|
{true, false} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {twoi, Node, int_no_match}
|
2013-02-05 19:28:30 +00:00
|
|
|
end;
|
2013-01-31 17:11:02 +00:00
|
|
|
{{error, Reason}, _} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {twoi, Node, {error, Reason}};
|
2013-01-31 17:11:02 +00:00
|
|
|
{_, {error, Reason}} ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {twoi, Node, {error, Reason}};
|
2013-02-05 19:28:30 +00:00
|
|
|
Unexpected ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {twoi, Node, Unexpected}
|
2013-02-05 19:28:30 +00:00
|
|
|
end,
|
2014-01-07 22:56:20 +00:00
|
|
|
twoi_tester(Node, Count + 1, PBC, Vsn, ReportPid).
|
2013-01-31 17:11:02 +00:00
|
|
|
|
2014-01-07 22:56:20 +00:00
|
|
|
search_tester(Node, Count, Pid, Vsn, ReportPid) ->
|
2013-02-05 19:28:30 +00:00
|
|
|
PBC = pb_pid_recycler(Pid, Node),
|
2013-01-31 17:11:02 +00:00
|
|
|
{Term, Size} = search_check(Count),
|
2013-02-05 19:29:25 +00:00
|
|
|
case riakc_pb_socket:search(PBC, loaded_upgrade:bucket(search), Term) of
|
2013-01-31 17:11:02 +00:00
|
|
|
{ok, Result} ->
|
2013-02-08 16:24:35 +00:00
|
|
|
case Size == Result#search_results.num_found of
|
|
|
|
true -> ok;
|
2014-01-07 22:56:20 +00:00
|
|
|
_ ->
|
|
|
|
lager:warning("Bad search result: ~p Expected: ~p", [Result#search_results.num_found, Size]),
|
|
|
|
ReportPid ! {search, Node, bad_result}
|
2013-02-08 16:24:35 +00:00
|
|
|
end;
|
2013-02-01 22:08:03 +00:00
|
|
|
{error, disconnected} ->
|
|
|
|
%% oh well, reconnect
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
|
|
|
|
|
|
|
{error, <<"Error processing incoming message: throw:{timeout,range_loop}:[{riak_search_backend", _/binary>>} ->
|
|
|
|
case rt:is_mixed_cluster(Node) of
|
2014-01-07 22:56:20 +00:00
|
|
|
true ->
|
2013-02-05 19:28:30 +00:00
|
|
|
ok;
|
|
|
|
_ ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {search, Node, {timeout, range_loop}}
|
2013-02-05 19:28:30 +00:00
|
|
|
end;
|
|
|
|
|
2013-02-06 17:20:38 +00:00
|
|
|
{error,<<"Error processing incoming message: error:{case_clause,", _/binary>>} ->
|
|
|
|
%% although it doesn't say so, this is the infamous badfun
|
|
|
|
case rt:is_mixed_cluster(Node) of
|
2014-01-07 22:56:20 +00:00
|
|
|
true ->
|
2013-02-06 17:20:38 +00:00
|
|
|
ok;
|
|
|
|
_ ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {search, Node, {error, badfun}}
|
2013-02-06 17:20:38 +00:00
|
|
|
end;
|
2013-02-05 19:28:30 +00:00
|
|
|
Unexpected ->
|
2014-01-07 22:56:20 +00:00
|
|
|
ReportPid ! {search, Node, Unexpected}
|
2013-02-05 19:28:30 +00:00
|
|
|
end,
|
2014-01-07 22:56:20 +00:00
|
|
|
search_tester(Node, Count + 1, PBC, Vsn, ReportPid).
|
2013-01-31 17:11:02 +00:00
|
|
|
|
|
|
|
search_check(Count) ->
|
|
|
|
case Count rem 6 of
|
|
|
|
0 -> { <<"mx.example.net">>, 187};
|
|
|
|
1 -> { <<"ZiaSun">>, 1};
|
|
|
|
2 -> { <<"headaches">>, 4};
|
|
|
|
3 -> { <<"YALSP">>, 3};
|
|
|
|
4 -> { <<"mister">>, 0};
|
|
|
|
5 -> { <<"prohibiting">>, 5}
|
|
|
|
end.
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2013-02-07 18:10:46 +00:00
|
|
|
assert_equal(Expected, Actual) ->
|
2014-01-07 22:56:20 +00:00
|
|
|
case Expected -- Actual of
|
2013-01-29 21:54:23 +00:00
|
|
|
[] -> ok;
|
2013-02-07 18:10:46 +00:00
|
|
|
Diff -> lager:info("Expected -- Actual: ~p", [Diff])
|
2013-01-29 21:54:23 +00:00
|
|
|
end,
|
2013-02-01 22:08:03 +00:00
|
|
|
Actual == Expected.
|
2013-01-29 21:54:23 +00:00
|
|
|
|
2013-02-05 19:28:30 +00:00
|
|
|
pb_pid_recycler(undefined, Node) ->
|
|
|
|
rt:pbc(Node);
|
2013-02-01 22:08:03 +00:00
|
|
|
pb_pid_recycler(Pid, Node) ->
|
|
|
|
case riakc_pb_socket:is_connected(Pid) of
|
|
|
|
true ->
|
|
|
|
Pid;
|
|
|
|
_ ->
|
2013-02-13 00:56:29 +00:00
|
|
|
riakc_pb_socket:stop(Pid),
|
2013-02-01 22:08:03 +00:00
|
|
|
rt:pbc(Node)
|
|
|
|
end.
|