Skip to content

Commit

Permalink
keep pools count in riak_sup protected ets table
Browse files Browse the repository at this point in the history
  • Loading branch information
michalwski committed Apr 13, 2015
1 parent 7d2d1f0 commit ba11c9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 0 additions & 3 deletions apps/ejabberd/src/ejabberd_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,6 @@ handle_local_config_add({Key, _Data} = El) ->
handle_local_config_del(#local_config{key = node_start}) ->
%% do nothing with it
ok;
handle_local_config_del(#local_config{key = riak_pools_count}) ->
%% do nothing with it
ok;
handle_local_config_del({Key, _Data} = El) ->
case can_be_ignored(Key) of
true ->
Expand Down
2 changes: 1 addition & 1 deletion apps/ejabberd/src/mongoose_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ update_map(Map, Ops) ->

-spec get_worker() -> pid() | undefined.
get_worker() ->
Pool = pick_pool(ejabberd_config:get_local_option(riak_pools_count)),
Pool = pick_pool(mongoose_riak_sup:get_riak_pools_count()),
case catch cuesport:get_worker(Pool) of
Pid when is_pid(Pid) ->
Pid;
Expand Down
13 changes: 12 additions & 1 deletion apps/ejabberd/src/mongoose_riak_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-export([start/2]).
-export([start_link/2]).
-export([stop/0]).
-export([get_riak_pools_count/0]).

%% Supervisor callbacks
-export([init/1]).
Expand Down Expand Up @@ -48,10 +49,19 @@ start(Workers, PoolsSpec) ->
start_link(Workers, PoolSpec) ->
supervisor:start_link({local, ?SERVER}, ?MODULE, [Workers, PoolSpec]).

-spec stop() -> no_return().
stop() ->
supervisor:terminate_child(ejabberd_sup, riak_pools_sup),
supervisor:delete_child(ejabberd_sup, riak_pools_sup).

-spec get_riak_pools_count() -> integer() | undefined.
get_riak_pools_count() ->
case catch ets:lookup(riak_pools, pools_count) of
[{pools_count, I}] ->
I;
_ ->
undefined
end.
%%%===================================================================
%%% Supervisor callbacks
%%%===================================================================
Expand Down Expand Up @@ -81,7 +91,8 @@ init([Workers, Pools]) ->
SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},

RiakPoolsCount = length(Pools),
ejabberd_config:add_local_option(riak_pools_count, RiakPoolsCount),
ets:new(riak_pools, [named_table, protected, {read_concurrency, true}]),
ets:insert(riak_pools, {pools_count, RiakPoolsCount}),
IdsPools = lists:zip(lists:seq(1, RiakPoolsCount), Pools),

Children = [child_spec(Workers, Id, RiakOpts) || {Id, RiakOpts} <- IdsPools],
Expand Down

0 comments on commit ba11c9a

Please sign in to comment.