Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bz982 - js_reload not working #30

Merged
2 commits merged into from

2 participants

@beerriot

This patch fixes problems with js_reload, caused by the split of JS VMs into multiple pools in 0.14 instead of one big pool in 0.13. All VMs in all pools are reset if none is specified (as with default 'riak-admin js_reload' behavior).

@beerriot beerriot make js_reload hit all JS pools (bz://982)
Each manager must be told to reload the VMs in its pool.  This patch
supports passing a list of managers to reset, if resetting the entire
list is not desired.

Also, if this is the map pool, purge the map cache.

Also removed the unused reload/2.
2455dde
@dizzyd

The logic associated with the reload/1 converting to/from atoms (as a result of being invoked directly from console) took me a bit to grok. Either this needs a comment explaining how we expect the code to be invoked, a spec for the arguments or it should be a recursive function that use a when clause to figure out when to convert between list/atom.

@beerriot beerriot better doc of what riak_kv_js_manager:reload expects
and hopefully clearer code about mangling to the needed format
681fc14
@dizzyd

+1. Thanks for the nice explanations. :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 26, 2011
  1. @beerriot

    make js_reload hit all JS pools (bz://982)

    beerriot authored
    Each manager must be told to reload the VMs in its pool.  This patch
    supports passing a list of managers to reset, if resetting the entire
    list is not desired.
    
    Also, if this is the map pool, purge the map cache.
    
    Also removed the unused reload/2.
Commits on Jan 28, 2011
  1. @beerriot

    better doc of what riak_kv_js_manager:reload expects

    beerriot authored
    and hopefully clearer code about mangling to the needed format
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 6 deletions.
  1. +7 −0 include/riak_kv_js_pools.hrl
  2. +30 −6 src/riak_kv_js_manager.erl
View
7 include/riak_kv_js_pools.hrl
@@ -1,3 +1,10 @@
-define(JSPOOL_HOOK, riak_kv_js_hook).
-define(JSPOOL_MAP, riak_kv_js_map).
-define(JSPOOL_REDUCE, riak_kv_js_reduce).
+
+%% this list is used to inform the js_reload command of all JS VM
+%% managers that need to reload
+-define(JSPOOL_LIST, [?JSPOOL_HOOK,
+ ?JSPOOL_MAP,
+ ?JSPOOL_REDUCE]).
+
View
36 src/riak_kv_js_manager.erl
@@ -31,7 +31,6 @@
-export([start_link/2,
add_vm/1,
reload/1,
- reload/2,
mark_idle/1,
reserve_vm/1,
reserve_batch_vm/2,
@@ -47,6 +46,8 @@
terminate/2,
code_change/3]).
+-include("riak_kv_js_pools.hrl").
+
-record('DOWN', {ref, type, pid, info}).
-record(vm_state, {pid, needs_reload=false}).
-record(state, {name, master, idle, reserve}).
@@ -54,10 +55,29 @@
start_link(Name, ChildCount) ->
gen_server:start_link({local, Name}, ?MODULE, [Name, ChildCount], []).
-reload(Name, []) ->
- reload(Name).
-reload(Name) ->
- gen_server:call(Name, reload_vms, infinity).
+%% @spec reload([string()|atom()]) -> ok
+%% @doc Reload the Javascript VMs in the named pools. If no pool
+%% names are given, all pools in the JSPOOL_LIST (defined in
+%% riak_kv_js_pools.hrl) are reloaded. Pool names may be given
+%% as either list-strings (as they will be when this function is
+%% invoked via 'riak-admin js_reload') or as atoms (as they are
+%% defined in riak_kv_js_pools.hrl).
+reload([]) ->
+ %% no names == reload all vms
+ reload(?JSPOOL_LIST);
+reload(Names) ->
+ reload_internal(Names).
+
+%% @spec reload_internal([string()|atom()]) -> ok
+%% @doc Recursive implementation of reload/1.
+reload_internal([Name|Rest]) when is_atom(Name) ->
+ gen_server:call(Name, reload_vms, infinity),
+ reload_internal(Rest);
+reload_internal([Name|Rest]) when is_list(Name) ->
+ %% convert riak-admin string argument to atom gen_server name
+ reload_internal([list_to_existing_atom(Name)|Rest]);
+reload_internal([]) ->
+ ok.
add_vm(Name) ->
gen_server:cast(Name, {add_vm, self()}).
@@ -101,7 +121,11 @@ handle_call({mark_idle, VM}, _From, #state{master=Master,
handle_call(reload_vms, _From, #state{master=Master, idle=Idle}=State) ->
reload_idle_vms(Idle),
mark_pending_reloads(Master, Idle),
- riak_kv_vnode:purge_mapcaches(),
+ if State#state.name == ?JSPOOL_MAP ->
+ riak_kv_mapred_cache:clear();
+ true ->
+ ok
+ end,
{reply, ok, State};
handle_call(reserve_batch_vm, _From, State) ->
Something went wrong with that request. Please try again.