From 891c7a65b5aae87dba2311ed7e6398f435ac7c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Biedrycki?= Date: Mon, 16 Mar 2015 17:55:51 +0000 Subject: [PATCH] Revert "Refactor few bits" This reverts commit 17e05c0a4b2ddf4f8c47673fdb1a059c079369c6. --- src/riak_governor_ensemble_master.erl | 22 ++++++++++++---------- src/riak_governor_util.erl | 15 --------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/riak_governor_ensemble_master.erl b/src/riak_governor_ensemble_master.erl index 5beb909..c161b48 100644 --- a/src/riak_governor_ensemble_master.erl +++ b/src/riak_governor_ensemble_master.erl @@ -98,13 +98,18 @@ ensure_ensemble_started([_]) -> % do not create an ensemble for group of one ok; ensure_ensemble_started(Nodes) -> - Fns = [ - fun() -> is_local_ensemble(Nodes) end, - fun() -> ensemble_started(Nodes) end, - fun() -> start_ensemble(Nodes) end, - fun() -> add_ensemble_to_index(Nodes) end - ], - riak_governor_util:whileok(Fns). + 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 + end. %% Determine the set of ensembles. Currently, there is one ensemble of each %% unique set of preflist owning nodes. @@ -125,9 +130,6 @@ add_ensemble_to_index(Nodes) -> 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), diff --git a/src/riak_governor_util.erl b/src/riak_governor_util.erl index a895432..f6a256b 100644 --- a/src/riak_governor_util.erl +++ b/src/riak_governor_util.erl @@ -5,7 +5,6 @@ -export([get_ensemble_size/0, get_ensemble_provider/0, ensemble_name/1]). -export([get_primary_apl/1]). -export([get_cluster_nodes/0]). --export([whileok/1]). get_ensemble_size() -> riak_governor:get_env(ensemble_size, ?DEFAULT_ENSEMBLE_SIZE). @@ -26,17 +25,3 @@ get_primary_apl(DocIdx) -> get_cluster_nodes() -> {ok, Ring} = riak_core_ring_manager:get_raw_ring(), lists:usort(riak_core_ring:all_members(Ring)). - -whileok([]) -> - ok; -whileok([Fn|Fns]) -> - case Fn() of - ok -> - whileok(Fns); - true -> - whileok(Fns); - {ok, _} -> - whileok(Fns); - Other -> - Other - end.