Anonymous avatar Anonymous committed 68ce417

Fixed craptastic half-assed call to riak_client in mrstress;Wired up vnode mapcache purges when JS VMs are reloaded;Fixed JS VM reload to work when Riak is under load (no more hung queries hopefully)

Comments (0)

Files changed (4)

apps/js_data/src/mrstress.erl

     %M = <<"function(v, _, _) { var value = v[\"values\"][0][\"data\"]; return [parseInt(value)]; }">>,
     R = <<"function(v, _) { var sum = 0; v.forEach(function(x) { sum = sum + x; }); return [sum]; }">>,
     R1 = <<"function(values, _) { return values.map(function(v) { return parseInt(v); }); }">>,
-    %Selected = select_inputs(Inputs, InputSize, []),
-    Selected = <<"stress">>,
+    Selected = select_inputs(Inputs, InputSize, []),
     Start = erlang:now(),
-    case Client:mapred_bucket_stream(Selected, [{map, {jsfun, <<"Riak.mapValues">>}, none, false},
-                                                {reduce, {jsanon, R1}, none, false},
-                                                {reduce, {jsanon, R}, none, true}]) of
-%%     case Client:mapred(Selected, [{map, {jsfun, <<"Riak.mapValues">>}, none, false},
-%%                                   {reduce, {jsanon, R1}, none, false},
-%%                                   {reduce, {jsanon, R}, none, true}]) of
+    case Client:mapred(Selected, [{map, {jsfun, <<"Riak.mapValues">>}, none, false},
+                                  {reduce, {jsanon, R1}, none, false},
+                                  {reduce, {jsanon, R}, none, true}]) of
         {ok, [InputSize]} ->
             End = erlang:now(),
             stress_collector:log(timer:now_diff(End, Start), 0),

apps/riak/src/riak_js_manager.erl

     {ok, #state{}}.
 
 handle_call(reload_all_vm, _From, #state{children=Children}=State) ->
-    lists:foreach(fun(Child) -> riak_js_vm:stop(Child) end, Children),
+    lists:foreach(fun(Child) -> riak_js_vm:reload(Child) end, Children),
+    VNodes = gen_server2:call(riak_vnode_master, all_vnodes),
+    lists:foreach(fun(VNode) -> gen_fsm:send_event(VNode, purge_mapcache) end, VNodes),
     {reply, ok, State};
 
 handle_call(_Request, _From, State) ->

apps/riak/src/riak_js_vm.erl

 -behaviour(gen_server).
 
 %% API
--export([start_link/1, dispatch/4, blocking_dispatch/3, stop/1]).
+-export([start_link/1, dispatch/4, blocking_dispatch/3, reload/1]).
 
 %% gen_server callbacks
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
 blocking_dispatch(VMPid, JobId, JSCall) ->
     gen_server:call(VMPid, {dispatch, JobId, JSCall}, 10000).
 
-stop(VMPid) ->
-    gen_server:cast(VMPid, stop).
+reload(VMPid) ->
+    gen_server:cast(VMPid, reload).
 
 init([Manager]) ->
     pg2:create({node(), js_vm}),
 handle_call(_Request, _From, State) ->
     {reply, ignore, State}.
 
-handle_cast(stop, State) ->
-    {stop, normal, State};
+handle_cast(reload, #state{ctx=Ctx}=State) ->
+    init_context(Ctx),
+    error_logger:info_msg("Spidermonkey VM host reloaded (~p)~n", [self()]),
+    {noreply, State};
 
 handle_cast({dispatch, Requestor, _JobId, {FsmPid, {map, {jsanon, JS}, Arg, _Acc},
                                             Value,

apps/riak/src/riak_vnode.erl

     KeyCache = orddict:store({FunName,Arg,KeyData},MF_Res,KeyCache0),
     {next_state,active,
      StateData#state{mapcache=orddict:store(BKey,KeyCache,Cache)},?TIMEOUT};
+active(purge_mapcache, StateData) ->
+    {next_state, active, StateData#state{mapcache=orddict:new()}};
 active({mapcache, BKey,{M,F,Arg,KeyData},MF_Res},
        StateData=#state{mapcache=Cache}) ->
     KeyCache0 = case orddict:find(BKey, Cache) of
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.