-spec get_rnd_id() -> pos_integer().
get_rnd_id() ->
- randoms:uniform(2, ejabberd_redis_sup:get_pool_size()).
+ randoms:round_robin(ejabberd_redis_sup:get_pool_size() - 1) + 2.
-spec get_result([{error, atom() | binary()} | {ok, iodata()}]) ->
{ok, [redis_reply()]} | {error, binary()}.
-author('alexey@process-one.net').
-export([start_link/0, init/1, get_pids/0,
- transform_options/1, get_random_pid/0, get_random_pid/1,
+ transform_options/1, get_random_pid/0,
host_up/1, config_reloaded/0, opt_type/1]).
-include("ejabberd.hrl").
[ejabberd_riak:get_proc(I) || I <- lists:seq(1, get_pool_size())].
get_random_pid() ->
- get_random_pid(p1_time_compat:system_time()).
-
-get_random_pid(Term) ->
- I = erlang:phash2(Term, get_pool_size()) + 1,
+ I = randoms:round_robin(get_pool_size()) + 1,
ejabberd_riak:get_proc(I).
transform_options(Opts) ->
get_random_pid(Host) ->
case get_pids(Host) of
[] -> none;
- Pids -> lists:nth(erlang:phash(p1_time_compat:unique_integer(), length(Pids)), Pids)
+ Pids ->
+ I = randoms:round_robin(length(Pids)) + 1,
+ lists:nth(I, Pids)
end.
add_pid(Host, Pid) ->
-author('alexey@process-one.net').
--export([get_string/0, uniform/0, uniform/1, uniform/2, bytes/1]).
+-export([get_string/0, uniform/0, uniform/1, uniform/2, bytes/1,
+ round_robin/1]).
-define(THRESHOLD, 16#10000000000000000).
bytes(N) ->
crypto:rand_bytes(N).
-endif.
+
+-spec round_robin(pos_integer()) -> non_neg_integer().
+round_robin(N) ->
+ erlang:unique_integer([monotonic, positive]) rem N.