Commits

Anonymous committed 96e371d

Adding fixes to start_client script to make it easier to stress test;Adding reload_js command to riak-admin to allow users to reload JS running inside Riak

Comments (0)

Files changed (4)

apps/js_data/start_client

 #!/bin/bash
-
+./rebar compile;
 erl -name 'client@127.0.0.1' -setcookie riak -pa ../riak/ebin -pa ebin
 

apps/riak/src/riak_js_manager.erl

 -behaviour(gen_server).
 
 %% API
--export([start_link/1, dispatch/1, blocking_dispatch/1, add_to_manager/0]).
+-export([start_link/1, dispatch/1, blocking_dispatch/1, add_to_manager/0, reload/1, reload/0]).
 
 %% gen_server callbacks
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
             riak_js_vm:blocking_dispatch(Target, JobId, JSCall)
     end.
 
+%% Hack to allow riak-admin to trigger a reload
+reload([]) ->
+    reload().
+
+reload() ->
+    gen_server:call(?MODULE, reload_all_vm).
+
 add_to_manager() ->
     gen_server:cast(?MODULE, {add_child, self()}).
 
     start_children(ChildCount),
     {ok, #state{}}.
 
+handle_call(reload_all_vm, _From, #state{children=Children}=State) ->
+    lists:foreach(fun(Child) -> riak_js_vm:stop(Child) end, Children),
+    {reply, ok, State};
+
 handle_call(_Request, _From, State) ->
     {reply, ignore, State}.
 

apps/riak/src/riak_js_vm.erl

 -behaviour(gen_server).
 
 %% API
--export([start_link/1, dispatch/4, blocking_dispatch/3]).
+-export([start_link/1, dispatch/4, blocking_dispatch/3, stop/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).
+
 init([Manager]) ->
     pg2:create({node(), js_vm}),
     pg2:join({node(), js_vm}, self()),
 handle_call(_Request, _From, State) ->
     {reply, ignore, State}.
 
+handle_cast(stop, State) ->
+    {stop, normal, State};
+
 handle_cast({dispatch, Requestor, _JobId, {FsmPid, {map, {jsanon, JS}, Arg, _Acc},
                                             Value,
                                             KeyData}}, #state{ctx=Ctx}=State) ->
 
 terminate(_Reason, #state{ctx=Ctx}) ->
     js_driver:destroy(Ctx),
+    error_logger:info_msg("Spidermonkey VM host stopping (~p)~n", [self()]),
     ok.
 
 code_change(_OldVsn, State, _Extra) ->

rel/overlay/bin/riak-admin

             exit 1
         fi
         shift
-        
+
         $NODETOOL rpc riak_console status $@
         ;;
 
+    js_reload)
+	# Reload all Javascript VMs
+	RES=`$NODETOOL ping`
+	if [ "$RES" != "pong" ]; then
+	    echo "Node is not running!"
+	    exit 1
+	fi
+
+	$NODETOOL rpc riak_js_manager reload
+	;;
 
     reip)
         ACTION=$1
 
         $ERTS_PATH/erl -noshell $NAME_PARAM riak_backup$NAME_HOST -setcookie $COOKIE \
                        -eval "riak_backup:$ACTION('$NODE', \"$FILENAME\")" -s init stop
-        ;;        
+        ;;
 
     backup)
         ACTION=$1
 
         if [ $# -lt 2 ]; then
             echo "Usage:"
-            echo "    Log to console: $SCRIPT logger <node> <cookie>"  
-            echo "    Log to file:    $SCRIPT logger <node> <cookie> <filename>"  
+            echo "    Log to console: $SCRIPT logger <node> <cookie>"
+            echo "    Log to file:    $SCRIPT logger <node> <cookie> <filename>"
             exit 1
         fi
 
         FILENAME=$3
 
         $ERTS_PATH/erl -noshell $NAME_PARAM riak_logger$NAME_HOST -setcookie $COOKIE \
-                       -eval "riak_event_logger:start('$NODE', \"$FILENAME\")."            
+                       -eval "riak_event_logger:start('$NODE', \"$FILENAME\")."
         ;;
 
     test)
         exit 1
         ;;
 esac
-