1+ % % -------------------------------------------------------------------
2+ % %
3+ % % Copyright (c) 2015 Basho Technologies, Inc.
4+ % %
5+ % % This file is provided to you under the Apache License,
6+ % % Version 2.0 (the "License"); you may not use this file
7+ % % except in compliance with the License. You may obtain
8+ % % a copy of the License at
9+ % %
10+ % % http://www.apache.org/licenses/LICENSE-2.0
11+ % %
12+ % % Unless required by applicable law or agreed to in writing,
13+ % % software distributed under the License is distributed on an
14+ % % "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ % % KIND, either express or implied. See the License for the
16+ % % specific language governing permissions and limitations
17+ % % under the License.
18+ % %
19+ % %-------------------------------------------------------------------
20+
21+ -module (riak_core_vnode_manager_intercepts ).
22+ -include (" intercept.hrl" ).
23+ % % API
24+ -compile (export_all ).
25+ -define (M , riak_core_vnode_manager_orig ).
26+
27+ return_dead_process_pid_from_get_vnode_pid (Index , VNodeMod = riak_pipe_vnode ) ->
28+ % % ?I_INFO("Intercepting riak_core_vnode_master:get_vnode_pid"),
29+ random :seed (os :timestamp ()),
30+ case random :uniform (100 ) of
31+ 7 ->
32+ % % Simulate what happens when a VNode completes handoff between get_vnode_pid
33+ % % and the fold attempting to start - other attempts to intercept and slow
34+ % % certain parts of Riak to invoke the particular race condition were unsuccessful
35+ ? I_INFO (" Replaced VNode with spawned function in get_vnode_pid" ),
36+ VNodePid = spawn (fun () ->
37+ ok
38+ end ),
39+ MonRef = erlang :monitor (process , VNodePid ),
40+ receive
41+ {'DOWN' , MonRef , process , VNodePid , _Reason } -> ok
42+ end ,
43+ {ok , VNodePid };
44+ _ ->
45+ ? M :get_vnode_pid_orig (Index , VNodeMod )
46+ end ;
47+ return_dead_process_pid_from_get_vnode_pid (Index , VNodeMod ) ->
48+ ? M :get_vnode_pid_orig (Index , VNodeMod ).
0 commit comments