Skip to content

Commit

Permalink
Refactor, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
loucash committed Mar 20, 2015
1 parent 0678daa commit 06568af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
@darach

riak_governor is an extension to riak_core that provides a simple api to check a
leader of the unique set of preflist owning nodes. It uses rafter underneath
for leader election.
leader of the unique set of preflist owning nodes. It uses rafter or
riak_ensemble underneath for leader election. This work is **experimental**.

When application starts and on each ring change event riak_governor determines the set of
ensembles. There is one ensemble of each unique set of proflist owning nodes.
Expand Down Expand Up @@ -61,6 +61,8 @@ or pull request. Thank you!

## Authors

- Lukasz Biedrycki / @loucash: current implementation
- Lukasz Biedrycki / @loucash: initial implementation
- Darach Ennis / @darach: came up with the name, implementation of pluggable
consensus providers
- Konrad Sosnowski / @konrads: working hard to make riak_ensemble plugin working
- Heinz N. Gies / @Licenser: riak_governor [tests](https://github.com/Licenser/governor_test)
33 changes: 17 additions & 16 deletions src/riak_governor_ensemble_master.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ init([]) ->
EnsembleSize = riak_governor_util:get_ensemble_size(),
RingHash = get_ring_hash(),
_ = ets:new(?MODULE, [named_table, public]),
timer:apply_after(?RETRY_DELAY_MIN, gen_server, cast, [?MODULE, ensure_ensembles]),
RetryDelayMin = application:get_env(riak_governor, ensemble_creation_retry_delay_min, ?RETRY_DELAY_MIN),
RetryDelayMax = application:get_env(riak_governor, ensemble_creation_retry_delay_max, ?RETRY_DELAY_MAX),
timer:apply_after(?RETRY_DELAY_MIN, ?MODULE, ensure_ensembles, []),
RetryDelayMin = riak_governor:get_env(ensemble_creation_retry_delay_min, ?RETRY_DELAY_MIN),
RetryDelayMax = riak_governor:get_env(ensemble_creation_retry_delay_max, ?RETRY_DELAY_MAX),
{ok, #state{ensemble_size=EnsembleSize,
ringhash=RingHash,
retry_backoff=backoff:init(RetryDelayMin, RetryDelayMax)}}.
Expand Down Expand Up @@ -99,9 +99,12 @@ ensure_ensembles_started(#state{ensemble_size=EnsembleSize}) ->
Ensembles0 = all_ensembles(EnsembleSize),
ClusterNodes = riak_governor_util:get_cluster_nodes(),
Ensembles = [ClusterNodes|Ensembles0],
Res = [ensure_ensemble_started(Nodes) || Nodes <- Ensembles],
Res = [ensure_ensemble_started(Nodes) || Nodes <- Ensembles,
is_local_ensemble(Nodes),
not ensemble_started(Nodes)],
% validate all results are ok
case lists:usort(Res) of
[] -> ok;
[ok] -> ok;
_ -> {error, {unexpected_ensemble_start_results, Res}}
end.
Expand All @@ -110,17 +113,11 @@ ensure_ensemble_started([_]) ->
% do not create an ensemble for group of one
ok;
ensure_ensemble_started(Nodes) ->
ShouldStart = ordsets:is_element(node(), Nodes),
AlreadyStarted = ensemble_started(Nodes),
case ShouldStart andalso not AlreadyStarted of
true ->
case start_ensemble(Nodes) of
ok ->
add_ensemble_to_index(Nodes),
ok;
Other -> Other
end;
false -> ok
case start_ensemble(Nodes) of
ok ->
add_ensemble_to_index(Nodes);
Other ->
Other
end.

%% Determine the set of ensembles. Currently, there is one ensemble of each
Expand All @@ -137,11 +134,15 @@ all_ensembles(Size) ->
sets:to_list(PrefGroups).

add_ensemble_to_index(Nodes) ->
ets:insert(?MODULE, {Nodes, riak_governor_util:ensemble_name(Nodes)}).
true = ets:insert(?MODULE, {Nodes, riak_governor_util:ensemble_name(Nodes)}),
ok.

ensemble_started(Nodes) ->
ets:lookup(?MODULE, Nodes) =/= [].

is_local_ensemble(Nodes) ->
ordsets:is_element(node(), Nodes).

start_ensemble(Nodes) ->
EnsembleName = riak_governor_util:ensemble_name(Nodes),
Peers = lists:map(fun(Node) -> {EnsembleName, Node} end, Nodes),
Expand Down

0 comments on commit 06568af

Please sign in to comment.