From 278d09ceef05350d797672878976b2ca2de6a14b Mon Sep 17 00:00:00 2001 From: RTB CI Bot <42817598+adroll-rtb-ci@users.noreply.github.com> Date: Mon, 6 Mar 2023 16:33:43 +0100 Subject: [PATCH] [AUTO] [ RTI-14085 ] Update Dependencies (#112) * Update dependencies * [update-deps] Thank you, Elvis! --------- Co-authored-by: Brujo Benavides Rodriguez --- rebar.config | 2 +- src/mero_conf.erl | 24 +++++---- src/mero_conf_monitor.erl | 12 +++-- src/mero_pool.erl | 54 ++++++++++--------- test/mero_dummy_server.erl | 3 ++ test/mero_test_with_local_memcached_SUITE.erl | 4 +- 6 files changed, 54 insertions(+), 45 deletions(-) diff --git a/rebar.config b/rebar.config index dc1f19a..b51910c 100644 --- a/rebar.config +++ b/rebar.config @@ -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"}]}. diff --git a/src/mero_conf.erl b/src/mero_conf.erl index 9c382d3..abc124e 100644 --- a/src/mero_conf.erl +++ b/src/mero_conf.erl @@ -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 @@ -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). @@ -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). @@ -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). @@ -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). @@ -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). @@ -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). @@ -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). @@ -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). @@ -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). @@ -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). diff --git a/src/mero_conf_monitor.erl b/src/mero_conf_monitor.erl index c68875f..1132d90 100644 --- a/src/mero_conf_monitor.erl +++ b/src/mero_conf_monitor.erl @@ -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}, []). diff --git a/src/mero_pool.erl b/src/mero_pool.erl index bbfb13a..b7a7d5f 100644 --- a/src/mero_pool.erl +++ b/src/mero_pool.erl @@ -51,7 +51,9 @@ worker_module :: module(), client :: client()}). --type conn() :: #conn{}. +-opaque conn() :: #conn{}. + +-export_type([conn/0]). -record(pool_st, {cluster, @@ -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) -> @@ -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). @@ -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, @@ -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), @@ -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 -> @@ -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), @@ -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. @@ -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)}. diff --git a/test/mero_dummy_server.erl b/test/mero_dummy_server.erl index e62b048..2bbffd9 100644 --- a/test/mero_dummy_server.erl +++ b/test/mero_dummy_server.erl @@ -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). diff --git a/test/mero_test_with_local_memcached_SUITE.erl b/test/mero_test_with_local_memcached_SUITE.erl index 8117183..0e55154 100644 --- a/test/mero_test_with_local_memcached_SUITE.erl +++ b/test/mero_test_with_local_memcached_SUITE.erl @@ -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(