5151 worker_module :: module (),
5252 client :: client ()}).
5353
54- -type conn () :: # conn {}.
54+ -opaque conn () :: # conn {}.
55+
56+ -export_type ([conn / 0 ]).
5557
5658-record (pool_st ,
5759 {cluster ,
@@ -115,21 +117,20 @@ checkout(PoolName, TimeLimit) ->
115117 end .
116118
117119% % @doc Return a connection to specified pool updating its timestamp
118- -spec checkin (Connection :: conn ()) -> ok .
120+ -spec checkin (conn ()) -> ok .
119121checkin (# conn {pool = PoolName } = Connection ) ->
120122 safe_send (PoolName , {checkin , self (), Connection # conn {updated = os :timestamp ()}}),
121123 ok .
122124
123125% % @doc Return a connection that has been closed.
124- -spec checkin_closed (Connection :: conn ()) -> ok .
126+ -spec checkin_closed (conn ()) -> ok .
125127checkin_closed (# conn {pool = PoolName }) ->
126128 safe_send (PoolName , {checkin_closed , self ()}),
127129 ok .
128130
129131% % @doc Executes an operation
130132
131- -spec transaction (Connection :: conn (), atom (), list ()) ->
132- {NewConnection :: conn (), {ok , any ()}} | {error , any ()}.
133+ -spec transaction (conn (), atom (), list ()) -> {conn (), {ok , any ()}} | {error , any ()}.
133134transaction (# conn {worker_module = WorkerModule , client = Client } = Conn ,
134135 Function ,
135136 Args ) ->
@@ -140,6 +141,7 @@ transaction(#conn{worker_module = WorkerModule, client = Client} = Conn,
140141 {Conn # conn {client = NClient }, Res }
141142 end .
142143
144+ -spec close (conn (), term ()) -> _ .
143145close (# conn {worker_module = WorkerModule , client = Client }, Reason ) ->
144146 WorkerModule :close (Client , Reason ).
145147
@@ -163,10 +165,10 @@ init(Parent, ClusterName, Host, Port, PoolName, WrkModule) ->
163165 process_flag (trap_exit , true ),
164166 Deb = sys :debug_options ([]),
165167 {Module , Function } = mero_conf :stat_callback (),
166- CallBackInfo =
168+ CallbackInfo =
167169 {Module , Function , [{cluster_name , ClusterName }, {host , Host }, {port , Port }]},
168170 Initial = mero_conf :pool_initial_connections (ClusterName ),
169- spawn_connections (ClusterName , PoolName , WrkModule , Host , Port , CallBackInfo , Initial ),
171+ spawn_connections (ClusterName , PoolName , WrkModule , Host , Port , CallbackInfo , Initial ),
170172 proc_lib :init_ack (Parent , {ok , self ()}),
171173 State =
172174 # pool_st {cluster = ClusterName ,
@@ -183,7 +185,7 @@ init(Parent, ClusterName, Host, Port, PoolName, WrkModule) ->
183185 % % If a connection attempt fails, or a connection is broken
184186 reconnect_wait_time = 200 ,
185187 pool = PoolName ,
186- callback_info = CallBackInfo ,
188+ callback_info = CallbackInfo ,
187189 worker_module = WrkModule ,
188190 last_connection_attempt = 0 },
189191 timer :send_interval (5000 , reload_pool_min_max_settings ),
@@ -297,18 +299,18 @@ maybe_spawn_connect(#pool_st{free = Free,
297299% % - There is minimum interval between connections, and that hasn't elapsed yet since the last
298300% % connection
299301% % - There are in-flight connection attempts
300- maybe_spawn_connect (State =
301- # pool_st { min_connection_interval_ms = Min ,
302- last_connection_attempt = Last ,
303- num_connecting = Connecting } ,
302+ maybe_spawn_connect (# pool_st { min_connection_interval_ms = Min ,
303+ last_connection_attempt = Last ,
304+ num_connecting = Connecting } =
305+ State ,
304306 Needed ,
305307 Now )
306308 when Min /= undefined , Now - Last < Min ; Connecting > 0 ; Needed == 0 ->
307309 State ;
308- maybe_spawn_connect (State =
309- # pool_st { num_failed_connecting = NumFailed ,
310- reconnect_wait_time = WaitTime ,
311- num_connecting = Connecting } ,
310+ maybe_spawn_connect (# pool_st { num_failed_connecting = NumFailed ,
311+ reconnect_wait_time = WaitTime ,
312+ num_connecting = Connecting } =
313+ State ,
312314 _Needed ,
313315 _Now )
314316 when NumFailed > 0 ->
@@ -317,14 +319,14 @@ maybe_spawn_connect(State =
317319 % % one connection until an attempt has succeeded again.
318320 erlang :send_after (WaitTime , self (), connect ),
319321 State # pool_st {num_connecting = Connecting + 1 };
320- maybe_spawn_connect (State =
321- # pool_st { num_connecting = Connecting ,
322- pool = Pool ,
323- worker_module = WrkModule ,
324- cluster = ClusterName ,
325- host = Host ,
326- port = Port ,
327- callback_info = CallbackInfo } ,
322+ maybe_spawn_connect (# pool_st { num_connecting = Connecting ,
323+ pool = Pool ,
324+ worker_module = WrkModule ,
325+ cluster = ClusterName ,
326+ host = Host ,
327+ port = Port ,
328+ callback_info = CallbackInfo } =
329+ State ,
328330 Needed ,
329331 Now ) ->
330332 spawn_connections (ClusterName , Pool , WrkModule , Host , Port , CallbackInfo , Needed ),
@@ -453,7 +455,7 @@ conn_time_to_live(ClusterName) ->
453455 Milliseconds * 1000
454456 end .
455457
456- schedule_expiration (State = # pool_st {cluster = ClusterName }) ->
458+ schedule_expiration (# pool_st {cluster = ClusterName } = State ) ->
457459 erlang :send_after (
458460 mero_conf :pool_expiration_interval (ClusterName ), self (), expire ),
459461 State .
@@ -500,7 +502,7 @@ filter_expired(#conn{updated = Updated} = Conn, {Now, TTL, ExpConns, ActConns})
500502% % If current # of connections > new max_connections, no action is taken to
501503% % close the exceeding ones. Instead, they won't be re-created once they
502504% % terminate by themselves (because of timeouts, errors, inactivity, etc)
503- reload_pool_min_max_settings (State = # pool_st {cluster = ClusterName }) ->
505+ reload_pool_min_max_settings (# pool_st {cluster = ClusterName } = State ) ->
504506 State # pool_st {min_connections = mero_conf :pool_min_free_connections (ClusterName ),
505507 max_connections = mero_conf :pool_max_connections (ClusterName ),
506508 min_connection_interval_ms = mero_conf :pool_min_connection_interval (ClusterName )}.
0 commit comments