Permalink
Browse files

Merge pull request #223 from basho/jdb-timers

Change ticks from timer to more efficient erlang:send_after
  • Loading branch information...
2 parents 6213954 + 8313087 commit fc8a51f5190da59040d2a13c81b00d5b022ed2d0 Jared Morrow committed Sep 13, 2012
Showing with 28 additions and 26 deletions.
  1. +6 −3 src/riak_core_capability.erl
  2. +7 −8 src/riak_core_gossip.erl
  3. +15 −15 src/riak_core_vnode_manager.erl
@@ -216,14 +216,17 @@ handle_call({ring_changed, Ring}, _From, State) ->
State2 = update_supported(Ring, State),
{reply, ok, State2}.
-handle_cast(tick, State) ->
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(tick, State) ->
schedule_tick(),
State2 =
lists:foldl(fun(Node, StateAcc) ->
add_node(Node, [], StateAcc)
end, State, State#state.unknown),
State3 = renegotiate_capabilities(State2),
- {noreply, State3}.
+ {noreply, State3};
handle_info(_Info, State) ->
{noreply, State}.
@@ -245,7 +248,7 @@ schedule_tick() ->
Tick = app_helper:get_env(riak_core,
capability_tick,
10000),
- timer:apply_after(Tick, gen_server, cast, [?MODULE, tick]).
+ erlang:send_after(Tick, ?MODULE, tick).
%% Capabilities are re-initialized if riak_core_capability server crashes
reload(State=#state{registered=[]}) ->
@@ -301,12 +301,6 @@ handle_cast({reconcile_ring, RingIn}, State) ->
{noreply, State2}
end;
-handle_cast(reset_tokens, State) ->
- schedule_next_reset(),
- gen_server:cast(?MODULE, gossip_ring),
- {Tokens, _} = app_helper:get_env(riak_core, gossip_limit, ?DEFAULT_LIMIT),
- {noreply, State#state{gossip_tokens=Tokens}};
-
handle_cast(gossip_ring, State) ->
% Gossip the ring to some random other node...
{ok, MyRing} = riak_core_ring_manager:get_raw_ring(),
@@ -332,7 +326,12 @@ handle_cast({rejoin, RingIn}, State) ->
handle_cast(_, State) ->
{noreply, State}.
-%% @private
+handle_info(reset_tokens, State) ->
+ schedule_next_reset(),
+ gen_server:cast(?MODULE, gossip_ring),
+ {Tokens, _} = app_helper:get_env(riak_core, gossip_limit, ?DEFAULT_LIMIT),
+ {noreply, State#state{gossip_tokens=Tokens}};
+
handle_info(_Info, State) -> {noreply, State}.
%% @private
@@ -350,7 +349,7 @@ code_change(_OldVsn, State, _Extra) ->
schedule_next_reset() ->
{_, Reset} = app_helper:get_env(riak_core, gossip_limit, ?DEFAULT_LIMIT),
- timer:apply_after(Reset, gen_server, cast, [?MODULE, reset_tokens]).
+ erlang:send_after(Reset, ?MODULE, reset_tokens).
reconcile(Ring0, [OtherRing0]) ->
%% Due to rolling upgrades and legacy gossip, a ring's cluster name
@@ -359,7 +359,20 @@ handle_cast({ring_changed, Ring}, State) ->
{noreply, State3};
-handle_cast(management_tick, State) ->
+handle_cast(maybe_start_vnodes, State) ->
+ {ok, Ring} = riak_core_ring_manager:get_raw_ring(),
+ State2 = maybe_start_vnodes(Ring, State),
+ {noreply, State2};
+
+handle_cast({kill_repairs, Reason}, State) ->
+ lager:warning("Killing all repairs: ~p", [Reason]),
+ kill_repairs(State#state.repairs, Reason),
+ {noreply, State#state{repairs=[]}};
+
+handle_cast(_, State) ->
+ {noreply, State}.
+
+handle_info(management_tick, State) ->
schedule_management_timer(),
{ok, Ring} = riak_core_ring_manager:get_raw_ring(),
Mods = [Mod || {_, Mod} <- riak_core:vnode_modules()],
@@ -386,19 +399,6 @@ handle_cast(management_tick, State) ->
Repairs2 = check_repairs(State4#state.repairs),
{noreply, State5#state{repairs=Repairs2}};
-handle_cast(maybe_start_vnodes, State) ->
- {ok, Ring} = riak_core_ring_manager:get_raw_ring(),
- State2 = maybe_start_vnodes(Ring, State),
- {noreply, State2};
-
-handle_cast({kill_repairs, Reason}, State) ->
- lager:warning("Killing all repairs: ~p", [Reason]),
- kill_repairs(State#state.repairs, Reason),
- {noreply, State#state{repairs=[]}};
-
-handle_cast(_, State) ->
- {noreply, State}.
-
handle_info({'DOWN', MonRef, process, _P, _I}, State) ->
delmon(MonRef, State),
{noreply, State}.
@@ -433,7 +433,7 @@ schedule_management_timer() ->
ManagementTick = app_helper:get_env(riak_core,
vnode_management_timer,
10000),
- timer:apply_after(ManagementTick, gen_server, cast, [?MODULE, management_tick]).
+ erlang:send_after(ManagementTick, ?MODULE, management_tick).
trigger_ownership_handoff(Transfers, Mods, State) ->
Limit = app_helper:get_env(riak_core,

0 comments on commit fc8a51f

Please sign in to comment.