The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
API to manage pools of persistent connections to external resources. More...
#include <freeradius-devel/server/stats.h>
Go to the source code of this file.
Data Structures | |
struct | fr_pool_state_s |
Typedefs | |
typedef int(* | fr_pool_connection_alive_t) (void *opaque, void *connection) |
Check a connection handle is still viable. More... | |
typedef void *(* | fr_pool_connection_create_t) (TALLOC_CTX *ctx, void *opaque, fr_time_delta_t timeout) |
Create a new connection handle. More... | |
typedef void(* | fr_pool_reconnect_t) (fr_pool_t *pool, void *opaque) |
Alter the opaque data of a connection pool during reconnection event. More... | |
typedef struct fr_pool_state_s | fr_pool_state_t |
typedef struct fr_pool_s | fr_pool_t |
Functions | |
int | fr_pool_connection_close (fr_pool_t *pool, request_t *request, CC_RELEASE_HANDLE("conn_pool_handle") void *conn) |
void * | fr_pool_connection_get (fr_pool_t *pool, request_t *request) |
Reserve a connection in the connection pool. More... | |
void * | fr_pool_connection_reconnect (fr_pool_t *pool, request_t *request, CC_RELEASE_HANDLE("conn_pool_handle") void *conn) |
void | fr_pool_connection_release (fr_pool_t *pool, request_t *request, CC_RELEASE_HANDLE("conn_pool_handle") void *conn) |
fr_pool_t * | fr_pool_copy (TALLOC_CTX *ctx, fr_pool_t *pool, void *opaque) |
Allocate a new pool using an existing one as a template. More... | |
void | fr_pool_enable_triggers (fr_pool_t *pool, char const *trigger_prefix, fr_pair_list_t *trigger_args) |
Enable triggers for a connection pool. More... | |
void | fr_pool_free (fr_pool_t *pool) |
Delete a connection pool. More... | |
fr_pool_t * | fr_pool_init (TALLOC_CTX *ctx, CONF_SECTION const *cs, void *opaque, fr_pool_connection_create_t c, fr_pool_connection_alive_t a, char const *log_prefix) |
Create a new connection pool. More... | |
void const * | fr_pool_opaque (fr_pool_t *pool) |
Return the opaque data associated with a connection pool. More... | |
int | fr_pool_reconnect (fr_pool_t *pool, request_t *request) |
Mark connections for reconnection, and spawn at least 'start' connections. More... | |
void | fr_pool_reconnect_func (fr_pool_t *pool, fr_pool_reconnect_t reconnect) |
Set a reconnection callback for the connection pool. More... | |
void | fr_pool_ref (fr_pool_t *pool) |
Increment pool reference by one. More... | |
int | fr_pool_start (fr_pool_t *pool) |
int | fr_pool_start_num (fr_pool_t *pool) |
Connection pool get start. More... | |
fr_pool_state_t const * | fr_pool_state (fr_pool_t *pool) |
Get the number of connections currently in the pool. More... | |
fr_time_delta_t | fr_pool_timeout (fr_pool_t *pool) |
Connection pool get timeout. More... | |
API to manage pools of persistent connections to external resources.
Definition in file pool.h.
struct fr_pool_state_s |
Data Fields | ||
---|---|---|
uint32_t | active | Number of currently reserved connections. |
uint64_t | count | Number of connections spawned over the lifetime of the pool. |
fr_time_t | last_at_max | Last time we hit the maximum number of allowed connections. |
fr_time_t | last_checked | Last time we pruned the connection pool. |
fr_time_t | last_closed | Last time a connection was closed. |
fr_time_t | last_failed | Last time we tried to spawn a connection but failed. |
fr_time_t | last_held_max | Last time we warned about a high latency event. |
fr_time_t | last_held_min | Last time we warned about a low latency event. |
fr_time_t | last_released | Last time a connection was released. |
fr_time_t | last_spawned | Last time we spawned a connection. |
fr_time_t | last_throttled | Last time we refused to spawn a connection because the last connection failed, or we were already spawning a connection. |
fr_time_delta_t | next_delay |
The next delay time. cleanup. Initialized to cleanup_interval, and decays from there. |
uint32_t | num | Number of connections in the pool. |
uint32_t | pending | Number of pending open connections. |
bool | reconnecting | We are currently reconnecting the pool. |
typedef int(* fr_pool_connection_alive_t) (void *opaque, void *connection) |
Check a connection handle is still viable.
Should check the state of a connection handle.
[in] | opaque | pointer passed to fr_pool_init. |
[in] | connection | handle returned by fr_pool_connection_create_t. |
typedef void*(* fr_pool_connection_create_t) (TALLOC_CTX *ctx, void *opaque, fr_time_delta_t timeout) |
Create a new connection handle.
This function will be called whenever the connection pool manager needs to spawn a new connection, and on reconnect.
Memory should be talloced in the provided context to hold the module's connection structure. The context is allocated in the NULL context, but will be freed when fr_pool_t is freed via some internal magic.
There is no delete callback, so operations such as closing sockets and freeing library connection handles should be done by a destructor attached to memory allocated beneath the provided ctx.
[in,out] | ctx | to allocate memory in. |
[in] | opaque | pointer passed to fr_pool_init. |
[in] | timeout | The maximum time in ms the function has to complete the connection. Should be enforced by the function. |
typedef void(* fr_pool_reconnect_t) (fr_pool_t *pool, void *opaque) |
Alter the opaque data of a connection pool during reconnection event.
This function will be called whenever we have been signalled to reconnect all the connections in a pool.
It is called at a point where we have determined that no connection spawning is in progress, so it is safe to modify any pointers or memory associated with the opaque data.
[in] | pool | being reconnected. |
[in] | opaque | pointer passed to fr_pool_init. |
typedef struct fr_pool_state_s fr_pool_state_t |
int fr_pool_connection_close | ( | fr_pool_t * | pool, |
request_t * | request, | ||
CC_RELEASE_HANDLE("conn_pool_handle") void * | conn | ||
) |
Reserve a connection in the connection pool.
Will attempt to find an unused connection in the connection pool, if one is found, will mark it as in in use increment the number of active connections and return the connection handle.
If no free connections are found will attempt to spawn a new one, conditional on a connection spawning not already being in progress, and not being at the 'max' connection limit.
[in] | pool | to reserve the connection from. |
[in] | request | The current request. |
Definition at line 1392 of file pool.c.
void* fr_pool_connection_reconnect | ( | fr_pool_t * | pool, |
request_t * | request, | ||
CC_RELEASE_HANDLE("conn_pool_handle") void * | conn | ||
) |
void fr_pool_connection_release | ( | fr_pool_t * | pool, |
request_t * | request, | ||
CC_RELEASE_HANDLE("conn_pool_handle") void * | conn | ||
) |
void fr_pool_enable_triggers | ( | fr_pool_t * | pool, |
char const * | trigger_prefix, | ||
fr_pair_list_t * | trigger_args | ||
) |
Enable triggers for a connection pool.
[in] | pool | to enable triggers for. |
[in] | trigger_prefix | prefix to prepend to all trigger names. Usually a path to the module's trigger configuration .e.g. modules.<name>.pool <trigger name>is appended to form the complete path. |
[in] | trigger_args | to make available in any triggers executed by the connection pool. These will usually be fr_pair_t (s) describing the host associated with the pool. Trigger args will be copied, input trigger_args should be freed if necessary. |
Definition at line 933 of file pool.c.
void fr_pool_free | ( | fr_pool_t * | pool | ) |
Delete a connection pool.
Closes, unlinks and frees all connections in the connection pool, then frees all memory used by the connection pool.
[in,out] | pool | to delete. |
Definition at line 1329 of file pool.c.
fr_pool_t* fr_pool_init | ( | TALLOC_CTX * | ctx, |
CONF_SECTION const * | cs, | ||
void * | opaque, | ||
fr_pool_connection_create_t | c, | ||
fr_pool_connection_alive_t | a, | ||
char const * | log_prefix | ||
) |
Create a new connection pool.
Allocates structures used by the connection pool, initialises the various configuration options and counters, and sets the callback functions.
Will also spawn the number of connections specified by the 'start' configuration option.
[in] | ctx | Context to link pool's destruction to. |
[in] | cs | pool section. |
[in] | opaque | data pointer to pass to callbacks. |
[in] | c | Callback to create new connections. |
[in] | a | Callback to check the status of connections. |
[in] | log_prefix | prefix to prepend to all log messages. |
Definition at line 967 of file pool.c.
void const* fr_pool_opaque | ( | fr_pool_t * | pool | ) |
Mark connections for reconnection, and spawn at least 'start' connections.
This intended to be called on a connection pool that's in use, to have it reflect a configuration change, or because the administrator knows that all connections in the pool are inviable and need to be reconnected.
[in] | pool | to reconnect. |
[in] | request | The current request. |
Definition at line 1244 of file pool.c.
void fr_pool_reconnect_func | ( | fr_pool_t * | pool, |
fr_pool_reconnect_t | reconnect | ||
) |
Set a reconnection callback for the connection pool.
This can be called at any time during the pool's lifecycle.
[in] | pool | to set reconnect callback for. |
reconnect | callback to call when reconnecting pool's connections. |
Definition at line 1224 of file pool.c.
void fr_pool_ref | ( | fr_pool_t * | pool | ) |
int fr_pool_start | ( | fr_pool_t * | pool | ) |
int fr_pool_start_num | ( | fr_pool_t * | pool | ) |
fr_pool_state_t const* fr_pool_state | ( | fr_pool_t * | pool | ) |
fr_time_delta_t fr_pool_timeout | ( | fr_pool_t * | pool | ) |