Skip to content

Commit

Permalink
Remove ring id optimization in riak_kv_ensembles
Browse files Browse the repository at this point in the history
Since the ring does not change when bucket types are activated we remove
the check for a changing ring id that was supposed to prevent
unnecessary work. Leaving the optimization in would require changing
riak_core to trigger on cluster metadata changes in addition to ring
changes. This change thus prevents us from having to change riak_core
at the expense of some extra work to check if the ensembles have changed
when they probably haven't.
  • Loading branch information
andrewjstone committed Aug 6, 2014
1 parent 71016f2 commit 59883e4
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions src/riak_kv_ensembles.erl
Expand Up @@ -28,8 +28,7 @@
-behaviour(gen_server).

%% API
-export([start_link/0,
possible_change/0]).
-export([start_link/0]).

%% Support API
-export([ensembles/0,
Expand All @@ -47,7 +46,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-record(state, {last_ring_id :: term()}).
-record(state, {}).

%%%===================================================================
%%% API
Expand All @@ -56,9 +55,6 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

possible_change() ->
?MODULE ! reset_ring_id.

local_ensembles() ->
Node = node(),
lists:foldl(fun(Ensemble, Acc) ->
Expand Down Expand Up @@ -102,7 +98,7 @@ check_membership(Ensemble, CHBin) ->

init([]) ->
schedule_tick(),
{ok, #state{last_ring_id = undefined}}.
{ok, #state{}}.

handle_call(_Request, _From, State) ->
{reply, ok, State}.
Expand All @@ -111,13 +107,9 @@ handle_cast(_Msg, State) ->
{noreply, State}.

handle_info(tick, State) ->
State2 = tick(State),
_ = tick(State),
schedule_tick(),
{noreply, State2};

handle_info(reset_ring_id, State) ->
State2 = State#state{last_ring_id=undefined},
{noreply, State2};
{noreply, State};

handle_info(_Info, State) ->
{noreply, State}.
Expand All @@ -135,17 +127,9 @@ code_change(_OldVsn, State, _Extra) ->
schedule_tick() ->
erlang:send_after(10000, self(), tick).

reset_ring_id() ->
self() ! reset_ring_id.

tick(State=#state{last_ring_id=LastID}) ->
case riak_core_ring_manager:get_ring_id() of
LastID ->
State;
RingID ->
maybe_bootstrap_ensembles(),
State#state{last_ring_id=RingID}
end.
tick(State) ->
maybe_bootstrap_ensembles(),
State.

maybe_bootstrap_ensembles() ->
case riak_ensemble_manager:enabled() of
Expand Down Expand Up @@ -183,14 +167,11 @@ bootstrap_preflists(Ring, CHBin) ->
end,
Known = orddict:fetch_keys(Ensembles),
Need = Required -- Known,
L = [begin
_ = [begin
Peers = required_members(Ensemble, CHBin),
riak_ensemble_manager:create_ensemble(Ensemble, undefined, Peers,
riak_kv_ensemble_backend, [])
end || Ensemble <- Need],
Failed = [Result || Result <- L,
Result =/= ok],
(Failed =:= []) orelse reset_ring_id(),
ok.

required_ensembles(Ring) ->
Expand Down

5 comments on commit 59883e4

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jtuple
at 59883e4

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging basho/riak_kv/bugfix/ensemble-creation-on-bucket-type-activate = 59883e4 into borshop-integration-1008-bugfix/ensemble-creation-on-bucket-type-activate

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basho/riak_kv/bugfix/ensemble-creation-on-bucket-type-activate = 59883e4 merged ok, testing candidate = 3489f5b

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding develop to borshop-integration-1008-bugfix/ensemble-creation-on-bucket-type-activate = 3489f5b

Please sign in to comment.