Skip to content

Commit

Permalink
[AUTO] [ RTI-14085 ] Update Dependencies (#112)
Browse files Browse the repository at this point in the history
* Update dependencies

* [update-deps] Thank you, Elvis!

---------

Co-authored-by: Brujo Benavides Rodriguez <[email protected]>
  • Loading branch information
adroll-rtb-ci and elbrujohalcon authored Mar 6, 2023
1 parent 33808a9 commit 278d09c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 45 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
{project_plugins,
[{rebar3_hex, "~> 7.0.4"},
{rebar3_format, "~> 1.2.1"},
{rebar3_lint, "~> 2.0.1"},
{rebar3_lint, "~> 3.0.0"},
{rebar3_hank, "~> 1.3.0"}]}.
24 changes: 13 additions & 11 deletions src/mero_conf.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@

-type per_pool_config_value(Type) ::
{by_pool, Default :: Type, [{Pool :: atom(), Value :: Type}]}.
-type mero_conf_value(Type) :: Type | per_pool_config_value(Type).
-type value(Type) :: Type | per_pool_config_value(Type).

-export_type([value/1]).

%%%=============================================================================
%%% External functions
Expand Down Expand Up @@ -88,7 +90,7 @@ cluster_config(ClusterConfig) ->
pool_initial_connections(Pool) ->
get_env_per_pool(initial_connections_per_pool, Pool).

-spec initial_connections_per_pool(Initial :: mero_conf_value(integer())) -> ok.
-spec initial_connections_per_pool(Initial :: value(integer())) -> ok.
initial_connections_per_pool(Initial) ->
application:set_env(mero, initial_connections_per_pool, Initial).

Expand All @@ -99,7 +101,7 @@ initial_connections_per_pool(Initial) ->
pool_min_free_connections(Pool) ->
get_env_per_pool(min_free_connections_per_pool, Pool).

-spec min_free_connections_per_pool(MinFree :: mero_conf_value(integer())) -> ok.
-spec min_free_connections_per_pool(MinFree :: value(integer())) -> ok.
min_free_connections_per_pool(MinFree) ->
application:set_env(mero, min_free_connections_per_pool, MinFree).

Expand All @@ -108,7 +110,7 @@ min_free_connections_per_pool(MinFree) ->
pool_max_connections(Pool) ->
get_env_per_pool(max_connections_per_pool, Pool).

-spec max_connections_per_pool(Max :: mero_conf_value(integer())) -> ok.
-spec max_connections_per_pool(Max :: value(integer())) -> ok.
max_connections_per_pool(Max) ->
application:set_env(mero, max_connections_per_pool, Max).

Expand All @@ -117,7 +119,7 @@ max_connections_per_pool(Max) ->
pool_timeout_read(Pool) ->
get_env_per_pool(timeout_read, Pool).

-spec timeout_read(Timeout :: mero_conf_value(integer())) -> ok.
-spec timeout_read(Timeout :: value(integer())) -> ok.
timeout_read(Timeout) ->
application:set_env(mero, timeout_read, Timeout).

Expand All @@ -126,7 +128,7 @@ timeout_read(Timeout) ->
pool_timeout_write(Pool) ->
get_env_per_pool(timeout_write, Pool).

-spec timeout_write(Timeout :: mero_conf_value(integer())) -> ok.
-spec timeout_write(Timeout :: value(integer())) -> ok.
timeout_write(Timeout) ->
application:set_env(mero, timeout_write, Timeout).

Expand All @@ -135,7 +137,7 @@ timeout_write(Timeout) ->
pool_write_retries(Pool) ->
get_env_per_pool(write_retries, Pool).

-spec write_retries(Timeout :: mero_conf_value(integer())) -> ok.
-spec write_retries(Timeout :: value(integer())) -> ok.
write_retries(Timeout) ->
application:set_env(mero, write_retries, Timeout).

Expand All @@ -144,7 +146,7 @@ write_retries(Timeout) ->
pool_key_expiration_time(Pool) ->
get_env_per_pool(expiration_time, Pool).

-spec key_expiration_time(Time :: mero_conf_value(integer())) -> ok.
-spec key_expiration_time(Time :: value(integer())) -> ok.
key_expiration_time(Time) ->
application:set_env(mero, expiration_time, Time).

Expand All @@ -153,7 +155,7 @@ key_expiration_time(Time) ->
pool_expiration_interval(Pool) ->
get_env_per_pool(expiration_interval, Pool).

-spec expiration_interval(mero_conf_value(integer())) -> ok.
-spec expiration_interval(value(integer())) -> ok.
expiration_interval(Val) ->
application:set_env(mero, expiration_interval, Val).

Expand All @@ -162,7 +164,7 @@ expiration_interval(Val) ->
pool_connection_unused_max_time(Pool) ->
get_env_per_pool(connection_unused_max_time, Pool).

-spec connection_unused_max_time(mero_conf_value(integer())) -> ok.
-spec connection_unused_max_time(value(integer())) -> ok.
connection_unused_max_time(Val) ->
application:set_env(mero, connection_unused_max_time, Val).

Expand All @@ -182,7 +184,7 @@ pool_min_connection_interval(Pool) ->
undefined
end.

-spec max_connection_delay_time(mero_conf_value(integer())) -> ok.
-spec max_connection_delay_time(value(integer())) -> ok.
max_connection_delay_time(Val) ->
application:set_env(mero, max_connection_delay_time, Val).

Expand Down
12 changes: 7 additions & 5 deletions src/mero_conf_monitor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@
%%
-module(mero_conf_monitor).

%% @todo Remove once https://github.com/inaka/elvis_core/issues/308 is dealt with
-elvis([{elvis_style, export_used_types, disable}]).

-behaviour(gen_server).

-export([start_link/1, init/1, handle_call/3, handle_cast/2, handle_info/2,
handle_continue/2]).

-record(state,
{orig_config :: cluster_config(),
processed_config :: cluster_config(),
{orig_config :: mero:cluster_config(),
processed_config :: mero:cluster_config(),
cluster_version :: undefined | pos_integer()}).

-type state() :: #state{}.
-type cluster_config() :: mero:cluster_config().
-type init_args() :: #{orig_config := cluster_config()}.
-type init_args() :: #{orig_config := mero:cluster_config()}.

%%%-----------------------------------------------------------------------------
%%% API
%%%-----------------------------------------------------------------------------
-spec start_link(cluster_config()) -> {ok, pid()} | ignore | {error, term()}.
-spec start_link(mero:cluster_config()) -> {ok, pid()} | ignore | {error, term()}.
start_link(OrigConfig) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, #{orig_config => OrigConfig}, []).

Expand Down
54 changes: 28 additions & 26 deletions src/mero_pool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
worker_module :: module(),
client :: client()}).

-type conn() :: #conn{}.
-opaque conn() :: #conn{}.

-export_type([conn/0]).

-record(pool_st,
{cluster,
Expand Down Expand Up @@ -115,21 +117,20 @@ checkout(PoolName, TimeLimit) ->
end.

%% @doc Return a connection to specified pool updating its timestamp
-spec checkin(Connection :: conn()) -> ok.
-spec checkin(conn()) -> ok.
checkin(#conn{pool = PoolName} = Connection) ->
safe_send(PoolName, {checkin, self(), Connection#conn{updated = os:timestamp()}}),
ok.

%% @doc Return a connection that has been closed.
-spec checkin_closed(Connection :: conn()) -> ok.
-spec checkin_closed(conn()) -> ok.
checkin_closed(#conn{pool = PoolName}) ->
safe_send(PoolName, {checkin_closed, self()}),
ok.

%% @doc Executes an operation

-spec transaction(Connection :: conn(), atom(), list()) ->
{NewConnection :: conn(), {ok, any()}} | {error, any()}.
-spec transaction(conn(), atom(), list()) -> {conn(), {ok, any()}} | {error, any()}.
transaction(#conn{worker_module = WorkerModule, client = Client} = Conn,
Function,
Args) ->
Expand All @@ -140,6 +141,7 @@ transaction(#conn{worker_module = WorkerModule, client = Client} = Conn,
{Conn#conn{client = NClient}, Res}
end.

-spec close(conn(), term()) -> _.
close(#conn{worker_module = WorkerModule, client = Client}, Reason) ->
WorkerModule:close(Client, Reason).

Expand All @@ -163,10 +165,10 @@ init(Parent, ClusterName, Host, Port, PoolName, WrkModule) ->
process_flag(trap_exit, true),
Deb = sys:debug_options([]),
{Module, Function} = mero_conf:stat_callback(),
CallBackInfo =
CallbackInfo =
{Module, Function, [{cluster_name, ClusterName}, {host, Host}, {port, Port}]},
Initial = mero_conf:pool_initial_connections(ClusterName),
spawn_connections(ClusterName, PoolName, WrkModule, Host, Port, CallBackInfo, Initial),
spawn_connections(ClusterName, PoolName, WrkModule, Host, Port, CallbackInfo, Initial),
proc_lib:init_ack(Parent, {ok, self()}),
State =
#pool_st{cluster = ClusterName,
Expand All @@ -183,7 +185,7 @@ init(Parent, ClusterName, Host, Port, PoolName, WrkModule) ->
%% If a connection attempt fails, or a connection is broken
reconnect_wait_time = 200,
pool = PoolName,
callback_info = CallBackInfo,
callback_info = CallbackInfo,
worker_module = WrkModule,
last_connection_attempt = 0},
timer:send_interval(5000, reload_pool_min_max_settings),
Expand Down Expand Up @@ -297,18 +299,18 @@ maybe_spawn_connect(#pool_st{free = Free,
%% - There is minimum interval between connections, and that hasn't elapsed yet since the last
%% connection
%% - There are in-flight connection attempts
maybe_spawn_connect(State =
#pool_st{min_connection_interval_ms = Min,
last_connection_attempt = Last,
num_connecting = Connecting},
maybe_spawn_connect(#pool_st{min_connection_interval_ms = Min,
last_connection_attempt = Last,
num_connecting = Connecting} =
State,
Needed,
Now)
when Min /= undefined, Now - Last < Min; Connecting > 0; Needed == 0 ->
State;
maybe_spawn_connect(State =
#pool_st{num_failed_connecting = NumFailed,
reconnect_wait_time = WaitTime,
num_connecting = Connecting},
maybe_spawn_connect(#pool_st{num_failed_connecting = NumFailed,
reconnect_wait_time = WaitTime,
num_connecting = Connecting} =
State,
_Needed,
_Now)
when NumFailed > 0 ->
Expand All @@ -317,14 +319,14 @@ maybe_spawn_connect(State =
%% one connection until an attempt has succeeded again.
erlang:send_after(WaitTime, self(), connect),
State#pool_st{num_connecting = Connecting + 1};
maybe_spawn_connect(State =
#pool_st{num_connecting = Connecting,
pool = Pool,
worker_module = WrkModule,
cluster = ClusterName,
host = Host,
port = Port,
callback_info = CallbackInfo},
maybe_spawn_connect(#pool_st{num_connecting = Connecting,
pool = Pool,
worker_module = WrkModule,
cluster = ClusterName,
host = Host,
port = Port,
callback_info = CallbackInfo} =
State,
Needed,
Now) ->
spawn_connections(ClusterName, Pool, WrkModule, Host, Port, CallbackInfo, Needed),
Expand Down Expand Up @@ -453,7 +455,7 @@ conn_time_to_live(ClusterName) ->
Milliseconds * 1000
end.

schedule_expiration(State = #pool_st{cluster = ClusterName}) ->
schedule_expiration(#pool_st{cluster = ClusterName} = State) ->
erlang:send_after(
mero_conf:pool_expiration_interval(ClusterName), self(), expire),
State.
Expand Down Expand Up @@ -500,7 +502,7 @@ filter_expired(#conn{updated = Updated} = Conn, {Now, TTL, ExpConns, ActConns})
%% If current # of connections > new max_connections, no action is taken to
%% close the exceeding ones. Instead, they won't be re-created once they
%% terminate by themselves (because of timeouts, errors, inactivity, etc)
reload_pool_min_max_settings(State = #pool_st{cluster = ClusterName}) ->
reload_pool_min_max_settings(#pool_st{cluster = ClusterName} = State) ->
State#pool_st{min_connections = mero_conf:pool_min_free_connections(ClusterName),
max_connections = mero_conf:pool_max_connections(ClusterName),
min_connection_interval_ms = mero_conf:pool_min_connection_interval(ClusterName)}.
Expand Down
3 changes: 3 additions & 0 deletions test/mero_dummy_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
%%
-module(mero_dummy_server).

%% @todo Remove once https://github.com/inaka/elvis_core/issues/308 is dealt with
-elvis([{elvis_style, export_used_types, disable}]).

-include_lib("mero/include/mero.hrl").

-behaviour(gen_server).
Expand Down
4 changes: 2 additions & 2 deletions test/mero_test_with_local_memcached_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ mget(Cluster, ClusterAlt, Keys) ->
end,
Keys).

mincrement(Cluster = cluster_txt, Keys) ->
mincrement(cluster_txt = Cluster, Keys) ->
{error, not_supportable} = mero:mincrement_counter(Cluster, Keys);
mincrement(Cluster = cluster_binary, Keys) ->
mincrement(cluster_binary = Cluster, Keys) ->
ok = mero:mincrement_counter(Cluster, Keys),
MGetRet =
lists:sort(
Expand Down

0 comments on commit 278d09c

Please sign in to comment.