2012-11-13 21:19:50 +00:00
|
|
|
-module(riak_kv_vnode_intercepts).
|
|
|
|
-compile(export_all).
|
|
|
|
-include("intercept.hrl").
|
|
|
|
|
|
|
|
-define(M, riak_kv_vnode_orig).
|
|
|
|
|
|
|
|
%% @doc Simulate dropped puts by truncating the preflist for every kv
|
|
|
|
%% vnode put. This is useful for testing read-repair, AAE, etc.
|
|
|
|
dropped_put(Preflist, BKey, Obj, ReqId, StartTime, Options, Sender) ->
|
|
|
|
NewPreflist = lists:sublist(Preflist, length(Preflist) - 1),
|
|
|
|
%% Uncomment to see modification in logs, too spammy to have on by default
|
|
|
|
%% ?I_INFO("Preflist modified from ~p to ~p", [Preflist, NewPreflist]),
|
|
|
|
?M:put_orig(NewPreflist, BKey, Obj, ReqId, StartTime, Options, Sender).
|
|
|
|
|
|
|
|
%% @doc Make all KV vnode commands take abnormally long.
|
|
|
|
slow_handle_command(Req, Sender, State) ->
|
|
|
|
timer:sleep(500),
|
|
|
|
?M:handle_command_orig(Req, Sender, State).
|
2013-02-23 05:25:08 +00:00
|
|
|
|
2013-12-18 04:21:29 +00:00
|
|
|
%% @doc Return wrong_node error because ownership transfer is happening
|
|
|
|
%% when trying to get the hashtree pid for a partition.
|
|
|
|
wrong_node(_Partition) ->
|
|
|
|
{error, wrong_node}.
|
|
|
|
|
2013-04-18 22:52:04 +00:00
|
|
|
%% @doc Make all KV vnode coverage commands take abnormally long.
|
|
|
|
slow_handle_coverage(Req, Filter, Sender, State) ->
|
|
|
|
random:seed(erlang:now()),
|
|
|
|
Rand = random:uniform(5000),
|
|
|
|
error_logger:info_msg("coverage sleeping ~p", [Rand]),
|
|
|
|
timer:sleep(Rand),
|
|
|
|
?M:handle_coverage_orig(Req, Filter, Sender, State).
|
|
|
|
|
2013-02-23 05:25:08 +00:00
|
|
|
%% @doc Simulate dropped gets/network partitions byresponding with
|
|
|
|
%% noreply during get requests.
|
2013-02-28 15:03:24 +00:00
|
|
|
drop_do_get(Sender, BKey, ReqId, State) ->
|
|
|
|
Partition = element(2,State),
|
2013-02-23 05:25:08 +00:00
|
|
|
case ets:lookup(intercepts_tab, drop_do_get_partitions) of
|
|
|
|
[] ->
|
2013-02-28 15:03:24 +00:00
|
|
|
?M:do_get_orig(Sender, BKey, ReqId, State);
|
2013-02-25 18:52:47 +00:00
|
|
|
[{drop_do_get_partitions, Partitions}] ->
|
2013-02-28 15:03:24 +00:00
|
|
|
case lists:member(Partition, Partitions) of
|
2013-02-23 05:25:08 +00:00
|
|
|
true ->
|
2013-02-28 15:03:24 +00:00
|
|
|
%% ?I_INFO("Dropping get for ~p on ~p", [BKey, Partition]),
|
2013-02-25 18:52:47 +00:00
|
|
|
lager:log(info, self(), "dropping get request for ~p",
|
2013-02-28 15:03:24 +00:00
|
|
|
[Partition]),
|
2013-02-23 05:25:08 +00:00
|
|
|
{noreply, State};
|
|
|
|
false ->
|
2013-02-28 15:03:24 +00:00
|
|
|
?M:do_get_orig(Sender, BKey, ReqId, State)
|
2013-02-23 05:25:08 +00:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
%% @doc Simulate dropped puts/network partitions byresponding with
|
|
|
|
%% noreply during put requests.
|
2013-02-28 15:03:24 +00:00
|
|
|
drop_do_put(Sender, BKey, RObj, ReqId, StartTime, Options, State) ->
|
|
|
|
Partition = element(2,State),
|
2013-02-25 18:52:47 +00:00
|
|
|
case ets:lookup(intercepts_tab, drop_do_put_partitions) of
|
2013-02-23 05:25:08 +00:00
|
|
|
[] ->
|
2013-02-28 15:03:24 +00:00
|
|
|
?M:do_put_orig(Sender, BKey, RObj, ReqId, StartTime, Options, State);
|
2013-02-25 18:52:47 +00:00
|
|
|
[{drop_do_put_partitions, Partitions}] ->
|
2013-02-28 15:03:24 +00:00
|
|
|
case lists:member(Partition, Partitions) of
|
2013-02-23 05:25:08 +00:00
|
|
|
true ->
|
2013-02-25 18:52:47 +00:00
|
|
|
lager:log(info, self(), "dropping put request for ~p",
|
2013-02-28 15:03:24 +00:00
|
|
|
[Partition]),
|
|
|
|
%% ?I_INFO("Dropping put for ~p on ~p", [BKey, Partition]),
|
2013-02-25 18:52:47 +00:00
|
|
|
State;
|
2013-02-23 05:25:08 +00:00
|
|
|
false ->
|
2013-02-28 15:03:24 +00:00
|
|
|
?M:do_put_orig(Sender, BKey, RObj, ReqId, StartTime, Options, State)
|
2013-02-23 05:25:08 +00:00
|
|
|
end
|
|
|
|
end.
|
2013-02-27 23:03:00 +00:00
|
|
|
|
|
|
|
%% @doc Simulate put failures by responding with failure messages.
|
2013-02-28 15:03:24 +00:00
|
|
|
error_do_put(Sender, BKey, RObj, ReqId, StartTime, Options, State) ->
|
|
|
|
Partition = element(2,State),
|
2013-02-27 23:03:00 +00:00
|
|
|
case ets:lookup(intercepts_tab, drop_do_put_partitions) of
|
|
|
|
[] ->
|
2013-02-28 15:03:24 +00:00
|
|
|
?M:do_put_orig(Sender, BKey, RObj, ReqId, StartTime, Options, State);
|
2013-02-27 23:03:00 +00:00
|
|
|
[{drop_do_put_partitions, Partitions}] ->
|
2013-02-28 15:03:24 +00:00
|
|
|
case lists:member(Partition, Partitions) of
|
2013-02-27 23:03:00 +00:00
|
|
|
true ->
|
|
|
|
lager:log(info, self(), "failing put request for ~p",
|
2013-02-28 15:03:24 +00:00
|
|
|
[Partition]),
|
|
|
|
%% ?I_INFO("Failing put for ~p on ~p", [BKey, Partition]),
|
2013-02-27 23:03:00 +00:00
|
|
|
|
|
|
|
%% sleep for a while, so the vnode response order is
|
|
|
|
%% deterministic
|
|
|
|
timer:sleep(1000),
|
2013-02-28 15:03:24 +00:00
|
|
|
riak_core_vnode:reply(Sender, {fail, Partition, ReqId}),
|
2013-02-27 23:03:00 +00:00
|
|
|
State;
|
|
|
|
false ->
|
2013-02-28 15:03:24 +00:00
|
|
|
?M:do_put_orig(Sender, BKey, RObj, ReqId, StartTime, Options, State)
|
2013-02-27 23:03:00 +00:00
|
|
|
end
|
|
|
|
end.
|
2013-08-16 00:37:02 +00:00
|
|
|
|
|
|
|
corrupting_handle_handoff_data(BinObj0, State) ->
|
|
|
|
BinObj =
|
|
|
|
case random:uniform(20) of
|
|
|
|
10 ->
|
|
|
|
corrupt_binary(BinObj0);
|
|
|
|
_ -> BinObj0
|
|
|
|
end,
|
|
|
|
?M:handle_handoff_data_orig(BinObj, State).
|
|
|
|
|
|
|
|
corrupt_binary(O) ->
|
|
|
|
crypto:rand_bytes(byte_size(O)).
|