4040#include " swoc/bwf_fwd.h"
4141#include " swoc/TextView.h"
4242#include < tscore/MgmtDefs.h>
43- #include " proxy/http/HttpProxyAPIEnums.h"
44- #include " proxy/Show.h"
43+ #include " iocore/net/SessionSharingAPIEnums.h"
4544
4645/* *
4746 * Singleton class to keep track of the number of outbound connections.
4847 *
4948 * Outbound connections are divided in to equivalence classes (called "groups" here) based on the
5049 * session matching setting. Tracking data is stored for each group.
5150 */
52- class OutboundConnTrack
51+ class ConnectionTracker
5352{
54- using self_type = OutboundConnTrack ; // /< Self reference type.
53+ using self_type = ConnectionTracker ; // /< Self reference type.
5554
5655public:
5756 // Non-copyable.
58- OutboundConnTrack (const self_type &) = delete ;
57+ ConnectionTracker (const self_type &) = delete ;
5958 self_type &operator =(const self_type &) = delete ;
6059
6160 // / Definition of an upstream server group equivalence class.
@@ -71,23 +70,23 @@ class OutboundConnTrack
7170
7271 // / Per transaction configuration values.
7372 struct TxnConfig {
74- int max {0 }; // /< Maximum concurrent connections.
75- int min {0 }; // /< Minimum keepalive connections.
76- MatchType match {MATCH_IP}; // /< Match type.
73+ int server_max {0 }; // /< Maximum concurrent server connections.
74+ int server_min {0 }; // /< Minimum keepalive server connections.
75+ MatchType server_match {MATCH_IP}; // /< Server match type.
7776 };
7877
7978 /* * Static configuration values. */
8079 struct GlobalConfig {
81- std::chrono::seconds alert_delay {60 }; // /< Alert delay in seconds.
80+ std::chrono::seconds server_alert_delay {60 }; // /< Alert delay in seconds.
8281 };
8382
8483 // The names of the configuration values.
8584 // Unfortunately these are not used in RecordsConfig.cc so that must be made consistent by hand.
8685 // Note: These need to be @c constexpr or there are static initialization ordering risks.
87- static constexpr std::string_view CONFIG_VAR_MAX {" proxy.config.http.per_server.connection.max" };
88- static constexpr std::string_view CONFIG_VAR_MIN {" proxy.config.http.per_server.connection.min" };
89- static constexpr std::string_view CONFIG_VAR_MATCH {" proxy.config.http.per_server.connection.match" };
90- static constexpr std::string_view CONFIG_VAR_ALERT_DELAY {" proxy.config.http.per_server.connection.alert_delay" };
86+ static constexpr std::string_view CONFIG_SERVER_VAR_MAX {" proxy.config.http.per_server.connection.max" };
87+ static constexpr std::string_view CONFIG_SERVER_VAR_MIN {" proxy.config.http.per_server.connection.min" };
88+ static constexpr std::string_view CONFIG_SERVER_VAR_MATCH {" proxy.config.http.per_server.connection.match" };
89+ static constexpr std::string_view CONFIG_SERVER_VAR_ALERT_DELAY {" proxy.config.http.per_server.connection.alert_delay" };
9190
9291 // / A record for the outbound connection count.
9392 // / These are stored per outbound session equivalence class, as determined by the session matching.
@@ -118,7 +117,7 @@ class OutboundConnTrack
118117 // Counting data.
119118 std::atomic<int > _count{0 }; // /< Number of outbound connections.
120119 std::atomic<int > _count_max{0 }; // /< largest observed @a count value.
121- std::atomic<int > _blocked{0 }; // /< Number of outbound connections blocked since last alert.
120+ std::atomic<int > _blocked{0 }; // /< Number of connections blocked since last alert.
122121 std::atomic<int > _in_queue{0 }; // /< # of connections queued, waiting for a connection.
123122 std::atomic<Ticker> _last_alert{0 }; // /< Absolute time of the last alert.
124123
@@ -130,6 +129,7 @@ class OutboundConnTrack
130129 * Construct from @c Key because the use cases do a table lookup first so the @c Key is already constructed.
131130 * @param key A populated @c Key structure - values are copied to the @c Group.
132131 * @param fqdn The full FQDN.
132+ * @param min_keep_alive The minimum number of origin keep alive connections to maintain.
133133 */
134134 Group (Key const &key, std::string_view fqdn, int min_keep_alive);
135135 // / Key equality checker.
@@ -182,22 +182,22 @@ class OutboundConnTrack
182182
183183 /* * Generate a Warning that a connection was blocked.
184184 *
185- * @param config Transaction local configuration .
186- * @param sm_id State machine ID to display in Warning.
185+ * @param max_connections The maximum configured number of connections for the group .
186+ * @param sm_id ID to display in Warning.
187187 * @param count Count value to display in Warning.
188188 * @param addr IP address of the upstream.
189189 * @param debug_tag Tag to use for the debug message. If no debug message should be generated set this to @c nullptr.
190190 */
191- void Warn_Blocked (const TxnConfig *config , int64_t sm_id , int count, const sockaddr *addr, const char *debug_tag = nullptr );
191+ void Warn_Blocked (int max_connections , int64_t id , int count, const sockaddr *addr, const char *debug_tag = nullptr );
192192 };
193193
194- /* * Get or create the @c Group for the specified session properties.
194+ /* * Get or create the @c Group for the specified outbound session properties.
195195 * @param txn_cnf The transaction local configuration.
196196 * @param fqdn The fully qualified domain name of the upstream.
197197 * @param addr The IP address of the upstream.
198198 * @return A @c Group for the arguments, existing if possible and created if not.
199199 */
200- static TxnState obtain (TxnConfig const &txn_cnf, std::string_view fqdn, const IpEndpoint &addr);
200+ static TxnState obtain_outbound (TxnConfig const &txn_cnf, std::string_view fqdn, IpEndpoint const &addr);
201201
202202 /* * Get the currently existing groups.
203203 * @param [out] groups parameter - pointers to the groups are pushed in to this container.
@@ -244,9 +244,9 @@ class OutboundConnTrack
244244 static void Warning_Bad_Match_Type (std::string_view tag);
245245
246246 // Converters for overridable values for use in the TS API.
247- static const MgmtConverter MIN_CONV ;
248- static const MgmtConverter MAX_CONV ;
249- static const MgmtConverter MATCH_CONV ;
247+ static const MgmtConverter MIN_SERVER_CONV ;
248+ static const MgmtConverter MAX_SERVER_CONV ;
249+ static const MgmtConverter SERVER_MATCH_CONV ;
250250
251251protected:
252252 static GlobalConfig *_global_config; // /< Global configuration data.
@@ -278,13 +278,13 @@ class OutboundConnTrack
278278 Imp &instance ();
279279};
280280
281- inline OutboundConnTrack ::Imp &
282- OutboundConnTrack ::instance ()
281+ inline ConnectionTracker ::Imp &
282+ ConnectionTracker ::instance ()
283283{
284284 return _imp;
285285}
286286
287- inline OutboundConnTrack ::Group::Group (Key const &key, std::string_view fqdn, int min_keep_alive)
287+ inline ConnectionTracker ::Group::Group (Key const &key, std::string_view fqdn, int min_keep_alive)
288288 : _hash(key._hash), _match_type(key._match_type), min_keep_alive_conns(min_keep_alive), _key{_addr, _hash, _match_type}
289289{
290290 // store the host name if relevant.
@@ -300,7 +300,7 @@ inline OutboundConnTrack::Group::Group(Key const &key, std::string_view fqdn, in
300300}
301301
302302inline uint64_t
303- OutboundConnTrack ::Group::hash (const Key &key)
303+ ConnectionTracker ::Group::hash (const Key &key)
304304{
305305 switch (key._match_type ) {
306306 case MATCH_IP:
@@ -317,43 +317,43 @@ OutboundConnTrack::Group::hash(const Key &key)
317317}
318318
319319inline bool
320- OutboundConnTrack ::TxnState::is_active ()
320+ ConnectionTracker ::TxnState::is_active ()
321321{
322322 return nullptr != _g;
323323}
324324
325325inline int
326- OutboundConnTrack ::TxnState::reserve ()
326+ ConnectionTracker ::TxnState::reserve ()
327327{
328328 _reserved_p = true ;
329329 return ++_g->_count ;
330330}
331331
332332inline void
333- OutboundConnTrack ::TxnState::release ()
333+ ConnectionTracker ::TxnState::release ()
334334{
335335 if (_reserved_p) {
336336 _reserved_p = false ;
337337 --_g->_count ;
338338 }
339339}
340340
341- inline OutboundConnTrack ::Group *
342- OutboundConnTrack ::TxnState::drop ()
341+ inline ConnectionTracker ::Group *
342+ ConnectionTracker ::TxnState::drop ()
343343{
344344 _reserved_p = false ;
345345 return _g;
346346}
347347
348348inline int
349- OutboundConnTrack ::TxnState::enqueue ()
349+ ConnectionTracker ::TxnState::enqueue ()
350350{
351351 _queued_p = true ;
352352 return ++_g->_in_queue ;
353353}
354354
355355inline void
356- OutboundConnTrack ::TxnState::dequeue ()
356+ ConnectionTracker ::TxnState::dequeue ()
357357{
358358 if (_queued_p) {
359359 _queued_p = false ;
@@ -362,7 +362,7 @@ OutboundConnTrack::TxnState::dequeue()
362362}
363363
364364inline void
365- OutboundConnTrack ::TxnState::clear ()
365+ ConnectionTracker ::TxnState::clear ()
366366{
367367 if (_g) {
368368 this ->dequeue ();
@@ -372,7 +372,7 @@ OutboundConnTrack::TxnState::clear()
372372}
373373
374374inline void
375- OutboundConnTrack ::TxnState::update_max_count (int count)
375+ ConnectionTracker ::TxnState::update_max_count (int count)
376376{
377377 auto cmax = _g->_count_max .load ();
378378 if (count > cmax) {
@@ -381,48 +381,46 @@ OutboundConnTrack::TxnState::update_max_count(int count)
381381}
382382
383383inline void
384- OutboundConnTrack ::TxnState::blocked ()
384+ ConnectionTracker ::TxnState::blocked ()
385385{
386386 ++_g->_blocked ;
387387}
388388
389389/* === Linkage === */
390390inline auto
391- OutboundConnTrack ::Linkage::next_ptr (value_type *value) -> value_type *&
391+ ConnectionTracker ::Linkage::next_ptr (value_type *value) -> value_type *&
392392{
393393 return value->_next ;
394394}
395395
396396inline auto
397- OutboundConnTrack ::Linkage::prev_ptr (value_type *value) -> value_type *&
397+ ConnectionTracker ::Linkage::prev_ptr (value_type *value) -> value_type *&
398398{
399399 return value->_prev ;
400400}
401401
402402inline uint64_t
403- OutboundConnTrack ::Linkage::hash_of (key_type key)
403+ ConnectionTracker ::Linkage::hash_of (key_type key)
404404{
405405 return Group::hash (key);
406406}
407407
408408inline auto
409- OutboundConnTrack ::Linkage::key_of (value_type *value) -> key_type
409+ ConnectionTracker ::Linkage::key_of (value_type *value) -> key_type
410410{
411411 return value->_key ;
412412}
413413
414414inline bool
415- OutboundConnTrack ::Linkage::equal (key_type lhs, key_type rhs)
415+ ConnectionTracker ::Linkage::equal (key_type lhs, key_type rhs)
416416{
417417 return Group::equal (lhs, rhs);
418418}
419419/* === */
420420
421- Action *register_ShowConnectionCount (Continuation *, HTTPHdr *);
422-
423421namespace swoc
424422{
425- BufferWriter &bwformat (BufferWriter &w, bwf::Spec const &spec, OutboundConnTrack ::MatchType type);
426- BufferWriter &bwformat (BufferWriter &w, bwf::Spec const &spec, OutboundConnTrack ::Group::Key const &key);
427- BufferWriter &bwformat (BufferWriter &w, bwf::Spec const &spec, OutboundConnTrack ::Group const &g);
423+ BufferWriter &bwformat (BufferWriter &w, bwf::Spec const &spec, ConnectionTracker ::MatchType type);
424+ BufferWriter &bwformat (BufferWriter &w, bwf::Spec const &spec, ConnectionTracker ::Group::Key const &key);
425+ BufferWriter &bwformat (BufferWriter &w, bwf::Spec const &spec, ConnectionTracker ::Group const &g);
428426} // namespace swoc
0 commit comments