The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
trunk.h File Reference
#include <freeradius-devel/server/connection.h>
#include <freeradius-devel/server/request.h>
#include <freeradius-devel/server/cf_parse.h>
+ Include dependency graph for trunk.h:

Go to the source code of this file.

Data Structures

struct  fr_trunk_conf_t
 Common configuration parameters for a trunk. More...
 
struct  fr_trunk_connection_pub_s
 Public fields for the trunk connection. More...
 
struct  fr_trunk_io_funcs_t
 I/O functions to pass to fr_trunk_alloc. More...
 
struct  fr_trunk_pub_s
 Public fields for the trunk. More...
 
struct  fr_trunk_request_pub_s
 Public fields for the trunk request. More...
 

Macros

#define _CONST   const
 
#define FR_TRUNK_CONN_ALL
 All connection states. More...
 
#define FR_TRUNK_CONN_PROCESSING
 States where the connection may be processing requests. More...
 
#define FR_TRUNK_CONN_SERVICEABLE
 States where the connection may potentially be used to send requests. More...
 
#define FR_TRUNK_CONNECTION_VERIFY(_tconn)   fr_trunk_connection_verify(__FILE__, __LINE__, _tconn)
 
#define FR_TRUNK_REQUEST_STATE_ALL
 All request states. More...
 
#define FR_TRUNK_REQUEST_STATE_CANCEL_ALL
 All requests in various cancellation states. More...
 
#define FR_TRUNK_REQUEST_VERIFY(_treq)   fr_trunk_request_verify(__FILE__, __LINE__, _treq)
 
#define FR_TRUNK_VERIFY(_trunk)   fr_trunk_verify(__FILE__, __LINE__, _trunk)
 

Typedefs

typedef fr_connection_t *(* fr_trunk_connection_alloc_t) (fr_trunk_connection_t *tconn, fr_event_list_t *el, fr_connection_conf_t const *conf, char const *log_prefix, void *uctx)
 Allocate a new connection for the trunk. More...
 
typedef void(* fr_trunk_connection_notify_t) (fr_trunk_connection_t *tconn, fr_connection_t *conn, fr_event_list_t *el, fr_trunk_connection_event_t notify_on, void *uctx)
 Inform the trunk API client which I/O events the trunk wants to receive. More...
 
typedef struct fr_trunk_connection_pub_s fr_trunk_connection_t
 
typedef void(* fr_trunk_request_cancel_mux_t) (fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)
 Inform a remote service like a datastore that a request should be cancelled. More...
 
typedef void(* fr_trunk_request_cancel_t) (fr_connection_t *conn, void *preq_to_reset, fr_trunk_cancel_reason_t reason, void *uctx)
 Remove an outstanding "sent" request from a tracking/matching structure. More...
 
typedef void(* fr_trunk_request_complete_t) (request_t *request, void *preq, void *rctx, void *uctx)
 Write a successful result to the rctx so that the trunk API client is aware of the result. More...
 
typedef void(* fr_trunk_request_conn_release_t) (fr_connection_t *conn, void *preq_to_reset, void *uctx)
 Free connection specific resources from a treq, as the treq is being removed from a connection. More...
 
typedef void(* fr_trunk_request_demux_t) (fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)
 Demultiplex on or more responses, reading them from a connection, decoding them, and matching them with their requests. More...
 
typedef void(* fr_trunk_request_fail_t) (request_t *request, void *preq, void *rctx, fr_trunk_request_state_t state, void *uctx)
 Write a failure result to the rctx so that the trunk API client is aware that the request failed. More...
 
typedef void(* fr_trunk_request_free_t) (request_t *request, void *preq_to_free, void *uctx)
 Free resources associated with a trunk request. More...
 
typedef void(* fr_trunk_request_mux_t) (fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)
 Multiplex one or more requests into a single connection. More...
 
typedef struct fr_trunk_request_pub_s fr_trunk_request_t
 
typedef struct fr_trunk_pub_s fr_trunk_t
 
typedef struct fr_trunk_watch_entry_s fr_trunk_watch_entry_t
 
typedef void(* fr_trunk_watch_t) (fr_trunk_t *trunk, fr_trunk_state_t prev, fr_trunk_state_t state, void *uctx)
 Receive a notification when a trunk enters a particular state. More...
 

Enumerations

enum  fr_trunk_cancel_reason_t {
  FR_TRUNK_CANCEL_REASON_NONE = 0 ,
  FR_TRUNK_CANCEL_REASON_SIGNAL ,
  FR_TRUNK_CANCEL_REASON_MOVE ,
  FR_TRUNK_CANCEL_REASON_REQUEUE
}
 Reasons for a request being cancelled. More...
 
enum  fr_trunk_connection_event_t {
  FR_TRUNK_CONN_EVENT_NONE = 0x00 ,
  FR_TRUNK_CONN_EVENT_READ = 0x01 ,
  FR_TRUNK_CONN_EVENT_WRITE = 0x02 ,
  FR_TRUNK_CONN_EVENT_BOTH = 0x03
}
 What type of I/O events the trunk connection is currently interested in receiving. More...
 
enum  fr_trunk_connection_state_t {
  FR_TRUNK_CONN_HALTED = 0x0000 ,
  FR_TRUNK_CONN_INIT = 0x0001 ,
  FR_TRUNK_CONN_CONNECTING = 0x0002 ,
  FR_TRUNK_CONN_ACTIVE = 0x0004 ,
  FR_TRUNK_CONN_CLOSED = 0x0008 ,
  FR_TRUNK_CONN_FULL = 0x0010 ,
  FR_TRUNK_CONN_INACTIVE = 0x0020 ,
  FR_TRUNK_CONN_INACTIVE_DRAINING = 0x0040 ,
  FR_TRUNK_CONN_DRAINING = 0x0080 ,
  FR_TRUNK_CONN_DRAINING_TO_FREE = 0x0100
}
 Used for sanity checks and to track which list the connection is in. More...
 
enum  fr_trunk_enqueue_t {
  FR_TRUNK_ENQUEUE_IN_BACKLOG = 1 ,
  FR_TRUNK_ENQUEUE_OK = 0 ,
  FR_TRUNK_ENQUEUE_NO_CAPACITY = -1 ,
  FR_TRUNK_ENQUEUE_DST_UNAVAILABLE = -2 ,
  FR_TRUNK_ENQUEUE_FAIL = -3
}
 
enum  fr_trunk_request_state_t {
  FR_TRUNK_REQUEST_STATE_INIT = 0x0000 ,
  FR_TRUNK_REQUEST_STATE_UNASSIGNED = 0x0001 ,
  FR_TRUNK_REQUEST_STATE_BACKLOG = 0x0002 ,
  FR_TRUNK_REQUEST_STATE_PENDING = 0x0004 ,
  FR_TRUNK_REQUEST_STATE_PARTIAL = 0x0008 ,
  FR_TRUNK_REQUEST_STATE_SENT = 0x0010 ,
  FR_TRUNK_REQUEST_STATE_COMPLETE = 0x0020 ,
  FR_TRUNK_REQUEST_STATE_FAILED = 0x0040 ,
  FR_TRUNK_REQUEST_STATE_CANCEL = 0x0080 ,
  FR_TRUNK_REQUEST_STATE_CANCEL_SENT = 0x0100 ,
  FR_TRUNK_REQUEST_STATE_CANCEL_PARTIAL = 0x0200 ,
  FR_TRUNK_REQUEST_STATE_CANCEL_COMPLETE = 0x0400
}
 Used for sanity checks and to simplify freeing. More...
 
enum  fr_trunk_state_t {
  FR_TRUNK_STATE_IDLE = 0 ,
  FR_TRUNK_STATE_ACTIVE ,
  FR_TRUNK_STATE_PENDING ,
  FR_TRUNK_STATE_MAX
}
 

Functions

bool fr_trunk_connection_search (fr_trunk_connection_t *tconn, void *ptr)
 
void fr_trunk_connection_verify (char const *file, int line, fr_trunk_connection_t *tconn)
 
bool fr_trunk_request_search (fr_trunk_request_t *treq, void *ptr)
 
void fr_trunk_request_verify (char const *file, int line, fr_trunk_request_t *treq)
 
bool fr_trunk_search (fr_trunk_t *trunk, void *ptr)
 
void fr_trunk_verify (char const *file, int line, fr_trunk_t *trunk)
 Verify a trunk. More...
 

Variables

conf_parser_t const fr_trunk_config []
 Config parser definitions to populate a fr_trunk_conf_t. More...
 

Statistics

uint16_t fr_trunk_connection_count_by_state (fr_trunk_t *trunk, int conn_state)
 Return the count number of connections in the specified states. More...
 
uint32_t fr_trunk_request_count_by_connection (fr_trunk_connection_t const *tconn, int req_state)
 Return the count number of requests associated with a trunk connection. More...
 
uint64_t fr_trunk_request_count_by_state (fr_trunk_t *trunk, int conn_state, int req_state)
 Return a count of requests on a connection in a specific state. More...
 

Request state signalling

void fr_trunk_request_signal_cancel (fr_trunk_request_t *treq)
 Cancel a trunk request. More...
 
void fr_trunk_request_signal_cancel_complete (fr_trunk_request_t *treq)
 Signal that a remote server acked our cancellation. More...
 
void fr_trunk_request_signal_cancel_partial (fr_trunk_request_t *treq)
 Signal a partial cancel write. More...
 
void fr_trunk_request_signal_cancel_sent (fr_trunk_request_t *treq)
 Signal that a remote server has been notified of the cancellation. More...
 
void fr_trunk_request_signal_complete (fr_trunk_request_t *treq)
 Signal that a trunk request is complete. More...
 
void fr_trunk_request_signal_fail (fr_trunk_request_t *treq)
 Signal that a trunk request failed. More...
 
void fr_trunk_request_signal_partial (fr_trunk_request_t *treq)
 Signal a partial write. More...
 
void fr_trunk_request_signal_sent (fr_trunk_request_t *treq)
 Signal that the request was written to a connection successfully. More...
 

(R)enqueue and alloc requests

uint64_t fr_trunk_connection_requests_requeue (fr_trunk_connection_t *tconn, int states, uint64_t max, bool fail_bound)
 Move requests off of a connection and requeue elsewhere. More...
 
fr_trunk_request_tfr_trunk_request_alloc (fr_trunk_t *trunk, request_t *request))
 (Pre-)Allocate a new trunk request More...
 
fr_trunk_enqueue_t fr_trunk_request_enqueue (fr_trunk_request_t **treq, fr_trunk_t *trunk, request_t *request, void *preq, void *rctx))
 Enqueue a request that needs data written to the trunk. More...
 
fr_trunk_enqueue_t fr_trunk_request_enqueue_on_conn (fr_trunk_request_t **treq_out, fr_trunk_connection_t *tconn, request_t *request, void *preq, void *rctx, bool ignore_limits))
 Enqueue additional requests on a specific connection. More...
 
void fr_trunk_request_free (fr_trunk_request_t **treq)
 If the trunk request is freed then update the target requests. More...
 
fr_trunk_enqueue_t fr_trunk_request_requeue (fr_trunk_request_t *treq)
 Re-enqueue a request on the same connection. More...
 
void fr_trunk_request_state_log (fr_log_t const *log, fr_log_type_t log_type, char const *file, int line, fr_trunk_request_t const *treq)
 

Dequeue protocol requests and cancellations

int fr_trunk_connection_pop_cancellation (fr_trunk_request_t **treq_out, fr_trunk_connection_t *tconn)
 Pop a cancellation request off a connection's cancellation queue. More...
 
int fr_trunk_connection_pop_request (fr_trunk_request_t **treq_out, fr_trunk_connection_t *tconn)
 Pop a request off a connection's pending queue. More...
 

Connection state signalling

The following states are signalled from I/O event handlers:

  • writable - The connection is writable (the muxer will be called).
  • readable - The connection is readable (the demuxer will be called).
  • reconnect - The connection is likely bad and should be reconnected. If the code signalling has access to the conn, fr_connection_signal_reconnect can be used instead of fr_trunk_connection_signal_reconnect.

The following states are signalled to control whether a connection may be assigned new requests:

  • inactive - The connection cannot accept any new requests. Either due to congestion or some other administrative reason.
  • active - The connection can, once again, accept new requests.

Note: In normal operation a connection will automatically transition between the active and inactive states if conf->max_req_per_conn is specified and the number of pending requests on that connection are equal to that number. If however, the connection has previously been signalled inactive, it will not automatically be reactivated once the number of requests drops below max_req_per_conn.

For other connection states the trunk API should not be signalled directly. It will be informed by "watch" callbacks inserted into the fr_connection_t as to when the connection changes state.

fr_trunk_connection_signal_active does not need to be called in any of the fr_connection_t state callbacks. It is only used to activate a connection which has been previously marked inactive using fr_trunk_connection_signal_inactive.

If fr_trunk_connection_signal_inactive is being used to remove a congested connection from the active list (i.e. on receipt of an explicit protocol level congestion notification), consider calling fr_trunk_connection_requests_requeue with the FR_TRUNK_REQUEST_STATE_PENDING state to redistribute that connection's backlog to other connections in the trunk.

bool fr_trunk_connection_in_state (fr_trunk_connection_t *tconn, int state)
 Returns true if the trunk connection is in one of the specified states. More...
 
void fr_trunk_connection_signal_active (fr_trunk_connection_t *tconn)
 Signal a trunk connection is no longer full. More...
 
void fr_trunk_connection_signal_inactive (fr_trunk_connection_t *tconn)
 Signal a trunk connection cannot accept more requests. More...
 
void fr_trunk_connection_signal_readable (fr_trunk_connection_t *tconn)
 Signal that a trunk connection is readable. More...
 
void fr_trunk_connection_signal_reconnect (fr_trunk_connection_t *tconn, fr_connection_reason_t reason)
 Signal a trunk connection is no longer viable. More...
 
void fr_trunk_connection_signal_writable (fr_trunk_connection_t *tconn)
 Signal that a trunk connection is writable. More...
 

Connection Callbacks

void fr_trunk_connection_callback_readable (fr_event_list_t *el, int fd, int flags, void *uctx)
 
void fr_trunk_connection_callback_writable (fr_event_list_t *el, int fd, int flags, void *uctx)
 

Connection management

void fr_trunk_reconnect (fr_trunk_t *trunk, int state, fr_connection_reason_t reason)
 Force the trunk to re-establish its connections. More...
 

Trunk allocation

fr_trunk_tfr_trunk_alloc (TALLOC_CTX *ctx, fr_event_list_t *el, fr_trunk_io_funcs_t const *funcs, fr_trunk_conf_t const *conf, char const *log_prefix, void const *uctx, bool delay_start))
 Allocate a new collection of connections. More...
 
int fr_trunk_connection_manage_schedule (fr_trunk_t *trunk)
 Schedule a trunk management event for the next time the event loop is executed. More...
 
void fr_trunk_connection_manage_start (fr_trunk_t *trunk)
 Allow the trunk to open and close connections in response to load. More...
 
void fr_trunk_connection_manage_stop (fr_trunk_t *trunk)
 Stop the trunk from opening and closing connections in response to load. More...
 
int fr_trunk_start (fr_trunk_t *trunk)
 Start the trunk running. More...
 

Watchers

fr_trunk_watch_entry_tfr_trunk_add_watch (fr_trunk_t *trunk, fr_trunk_state_t state, fr_trunk_watch_t watch, bool oneshot, void const *uctx))
 Add a watch entry to the trunk state list. More...
 
int fr_trunk_del_watch (fr_trunk_t *trunk, fr_trunk_state_t state, fr_trunk_watch_t watch)
 Remove a watch function from a trunk state list. More...
 

Data Structure Documentation

◆ fr_trunk_conf_t

struct fr_trunk_conf_t

Common configuration parameters for a trunk.

Definition at line 213 of file trunk.h.

+ Collaboration diagram for fr_trunk_conf_t:
Data Fields
bool always_writable Set to true if our ability to write requests to a connection handle is not dependent on the state of the underlying connection, i.e.

if the library used to implement the connection can always receive and buffer new requests irrespective of the state of the underlying socket. If this is true, fr_trunk_connection_signal_writable does not need to be called, and requests will be enqueued as soon as they're received.

bool backlog_on_failed_conn Assign requests to the backlog when there are no available connections and the last connection event was a failure, instead of failing them immediately.
fr_time_delta_t close_delay How long we must be below target utilisation to close an existing connection.
fr_connection_conf_t const * conn_conf Connection configuration.
uint16_t connecting Maximum number of connections that can be in the connecting state.

Used to throttle connection spawning.

fr_time_delta_t lifetime Time between reconnects.
fr_time_delta_t manage_interval How often we run the management algorithm to open/close connections.
uint16_t max Maximum number of connections in the trunk.
uint32_t max_req_per_conn Maximum connections per request.

Used to determine if we need to create new connections and whether we can enqueue new requests.

uint64_t max_uses The maximum time a connection can be used.
uint16_t min Shouldn't let connections drop below this number.
fr_time_delta_t open_delay How long we must be above target utilisation to spawn a new connection.
fr_time_delta_t req_cleanup_delay How long must a request in the unassigned (free) list not have been used for before it's cleaned up and actually freed.
unsigned req_pool_headers How many chunk headers the talloc pool allocated with the treq should contain.
size_t req_pool_size The size of the talloc pool allocated with the treq.
uint16_t start How many connections to start.
uint32_t target_req_per_conn How many pending requests should ideally be running on each connection.

Averaged across the 'active' set of connections.

◆ fr_trunk_connection_pub_s

struct fr_trunk_connection_pub_s

Public fields for the trunk connection.

This saves the overhead of using accessors for commonly used fields in trunk connections.

Though these fields are public, they should NOT be modified by clients of the trunk API.

Definition at line 349 of file trunk.h.

+ Collaboration diagram for fr_trunk_connection_pub_s:
Data Fields
fr_connection_t *_CONST conn The underlying connection.
fr_trunk_connection_state_t _CONST state What state the connection is in.
fr_trunk_t *_CONST trunk Trunk this connection belongs to.

◆ fr_trunk_io_funcs_t

struct fr_trunk_io_funcs_t

I/O functions to pass to fr_trunk_alloc.

Definition at line 711 of file trunk.h.

+ Collaboration diagram for fr_trunk_io_funcs_t:
Data Fields
fr_trunk_connection_alloc_t connection_alloc Allocate a new fr_connection_t.
fr_trunk_connection_notify_t connection_notify Update the I/O event registrations for.
fr_heap_cmp_t connection_prioritise Ordering function for connections.
fr_trunk_request_cancel_t request_cancel Request should be removed from tracking and should be reset to its initial state.
fr_trunk_request_cancel_mux_t request_cancel_mux !< Read one or more requests from a connection.

Inform an external resource that we no longer care about the result of any queries we issued for this request.

fr_trunk_request_complete_t request_complete Request is complete, interpret the response contained in preq.
fr_trunk_request_conn_release_t request_conn_release Any connection specific resources should be removed from the treq as it's about to be moved or freed.
fr_trunk_request_demux_t request_demux !< Write one or more requests to a connection.
fr_trunk_request_fail_t request_fail Request failed, write out a canned response.
fr_trunk_request_free_t request_free Free the preq and any resources it holds and provide a chance to mark the request as runnable.
fr_trunk_request_mux_t request_mux
fr_heap_cmp_t request_prioritise Ordering function for requests.

Controls where in the outbound queues they're inserted.

◆ fr_trunk_pub_s

struct fr_trunk_pub_s

Public fields for the trunk.

This saves the overhead of using accessors for commonly used fields in the trunk.

Though these fields are public, they should NOT be modified by clients of the trunk API.

Definition at line 279 of file trunk.h.

+ Collaboration diagram for fr_trunk_pub_s:
Data Fields
fr_time_t _CONST last_above_target Last time average utilisation went above the target value.
fr_time_t _CONST last_below_target Last time average utilisation went below the target value.
fr_time_t _CONST last_closed Last time the connection management function closed a connection.
fr_time_t _CONST last_connected Last time a connection connected.
fr_time_t _CONST last_failed Last time a connection failed.
fr_time_t _CONST last_open Last time the connection management function opened a connection.
fr_time_t _CONST last_read_success Last time we read a response.
uint64_t _CONST req_alloc The number of requests currently allocated that have not been freed or returned to the free list.
uint64_t _CONST req_alloc_new How many requests we've allocated.
uint64_t _CONST req_alloc_reused How many requests were reused.
fr_trunk_state_t _CONST state Current state of the trunk.
bool _CONST triggers do we run the triggers?

◆ fr_trunk_request_pub_s

struct fr_trunk_request_pub_s

Public fields for the trunk request.

This saves the overhead of using accessors for commonly used fields in trunk requests.

Though these fields are public, they should NOT be modified by clients of the trunk API.

Definition at line 327 of file trunk.h.

+ Collaboration diagram for fr_trunk_request_pub_s:
Data Fields
void *_CONST preq Data for the muxer to write to the connection.
void *_CONST rctx Resume ctx of the module.
request_t *_CONST request The request that we're writing the data on behalf of.
fr_trunk_request_state_t _CONST state Which list the request is now located in.
fr_trunk_connection_t *_CONST tconn Connection this request belongs to.
fr_trunk_t *_CONST trunk Trunk this request belongs to.

Macro Definition Documentation

◆ _CONST

#define _CONST   const

Definition at line 47 of file trunk.h.

◆ FR_TRUNK_CONN_ALL

#define FR_TRUNK_CONN_ALL
Value:
(\
FR_TRUNK_CONN_INIT | \
FR_TRUNK_CONN_CONNECTING | \
FR_TRUNK_CONN_ACTIVE | \
FR_TRUNK_CONN_CLOSED | \
FR_TRUNK_CONN_FULL | \
FR_TRUNK_CONN_INACTIVE | \
FR_TRUNK_CONN_DRAINING | \
FR_TRUNK_CONN_DRAINING_TO_FREE \
)

All connection states.

Definition at line 111 of file trunk.h.

◆ FR_TRUNK_CONN_PROCESSING

#define FR_TRUNK_CONN_PROCESSING
Value:
(\
FR_TRUNK_CONN_ACTIVE | \
FR_TRUNK_CONN_FULL | \
FR_TRUNK_CONN_INACTIVE | \
FR_TRUNK_CONN_DRAINING | \
FR_TRUNK_CONN_INACTIVE_DRAINING | \
FR_TRUNK_CONN_DRAINING_TO_FREE \
)

States where the connection may be processing requests.

Definition at line 138 of file trunk.h.

◆ FR_TRUNK_CONN_SERVICEABLE

#define FR_TRUNK_CONN_SERVICEABLE
Value:
(\
FR_TRUNK_CONN_ACTIVE | \
FR_TRUNK_CONN_INACTIVE | \
FR_TRUNK_CONN_DRAINING | \
FR_TRUNK_CONN_INACTIVE_DRAINING | \
FR_TRUNK_CONN_DRAINING_TO_FREE \
)

States where the connection may potentially be used to send requests.

Definition at line 126 of file trunk.h.

◆ FR_TRUNK_CONNECTION_VERIFY

#define FR_TRUNK_CONNECTION_VERIFY (   _tconn)    fr_trunk_connection_verify(__FILE__, __LINE__, _tconn)

Definition at line 907 of file trunk.h.

◆ FR_TRUNK_REQUEST_STATE_ALL

#define FR_TRUNK_REQUEST_STATE_ALL
Value:
(\
FR_TRUNK_REQUEST_STATE_BACKLOG | \
FR_TRUNK_REQUEST_STATE_PENDING | \
FR_TRUNK_REQUEST_STATE_PARTIAL | \
FR_TRUNK_REQUEST_STATE_SENT | \
FR_TRUNK_REQUEST_STATE_COMPLETE | \
FR_TRUNK_REQUEST_STATE_FAILED | \
FR_TRUNK_REQUEST_STATE_CANCEL | \
FR_TRUNK_REQUEST_STATE_CANCEL_PARTIAL | \
FR_TRUNK_REQUEST_STATE_CANCEL_SENT | \
FR_TRUNK_REQUEST_STATE_CANCEL_COMPLETE \
)

All request states.

Definition at line 185 of file trunk.h.

◆ FR_TRUNK_REQUEST_STATE_CANCEL_ALL

#define FR_TRUNK_REQUEST_STATE_CANCEL_ALL
Value:
(\
FR_TRUNK_REQUEST_STATE_CANCEL | \
FR_TRUNK_REQUEST_STATE_CANCEL_PARTIAL | \
FR_TRUNK_REQUEST_STATE_CANCEL_SENT | \
FR_TRUNK_REQUEST_STATE_CANCEL_COMPLETE \
)

All requests in various cancellation states.

Definition at line 202 of file trunk.h.

◆ FR_TRUNK_REQUEST_VERIFY

#define FR_TRUNK_REQUEST_VERIFY (   _treq)    fr_trunk_request_verify(__FILE__, __LINE__, _treq)

Definition at line 908 of file trunk.h.

◆ FR_TRUNK_VERIFY

#define FR_TRUNK_VERIFY (   _trunk)    fr_trunk_verify(__FILE__, __LINE__, _trunk)

Definition at line 906 of file trunk.h.

Typedef Documentation

◆ fr_trunk_connection_alloc_t

typedef fr_connection_t*(* fr_trunk_connection_alloc_t) (fr_trunk_connection_t *tconn, fr_event_list_t *el, fr_connection_conf_t const *conf, char const *log_prefix, void *uctx)

Allocate a new connection for the trunk.

The trunk code only interacts with underlying connections via the connection API. As a result the trunk API is shielded from the implementation details of opening and closing connections.

When creating new connections, this callback is used to allocate and configure a new fr_connection_t, this fr_connection_t and the fr_connection API is how the trunk signals the underlying connection that it should start, reconnect, and halt (stop).

The trunk must be informed when the underlying connection is readable, and, if always_writable == false, when the connection is writable.

When the connection is readable, a read I/O handler installed by the init() callback of the fr_connection_t must either:

  • If there's no underlying I/O library, call fr_trunk_connection_signal_readable(tconn) immediately, relying on the trunk demux callback to perform decoding and demuxing.
  • If there is an underlying I/O library, feed any incoming data to that library and then call fr_trunk_connection_signal_readable if the underlying I/O library indicates complete responses are ready for processing.

When the connection is writable a write I/O handler installed by the open() callback of the fr_connection_t must either:

  • If always_writable == true - Inform the underlying I/O library that the connection is writable. The trunk API does not need to be informed as it will immediately pass through any enqueued requests to the I/O library.
  • If always_writable == false and there's an underlying I/O library, call fr_trunk_connection_signal_writable(tconn) to allow the trunk mux callback to pass requests to the underlying I/O library and (optionally) signal the I/O library that the connection is writable.
  • If always_writable == false and there's no underlying I/O library, call fr_trunk_connection_signal_writable(tconn) to allow the trunk mux callback to encode and write requests to a socket.
Parameters
[in]tconnThe trunk connection this connection will be bound to. Should be used as the context for any fr_connection_t allocated.
[in]elThe event list to use for I/O and timer events.
[in]confConfiguration of the fr_connection_t.
[in]log_prefixWhat to prefix connection log messages with.
[in]uctxUser context data passed to fr_trunk_alloc.
Returns
  • A new fr_connection_t on success (should be in the halted state - the default).
  • NULL on error.

Definition at line 411 of file trunk.h.

◆ fr_trunk_connection_notify_t

typedef void(* fr_trunk_connection_notify_t) (fr_trunk_connection_t *tconn, fr_connection_t *conn, fr_event_list_t *el, fr_trunk_connection_event_t notify_on, void *uctx)

Inform the trunk API client which I/O events the trunk wants to receive.

I/O handlers installed by this callback should call one or more of the following functions to signal that an I/O event has occurred:

  • fr_trunk_connection_signal_writable - Connection is now writable.
  • fr_trunk_connection_signal_readable - Connection is now readable.
  • fr_trunk_connection_signal_inactive - Connection is full or congested.
  • fr_trunk_connection_signal_active - Connection is no longer full or congested.
  • fr_trunk_connection_signal_reconnect - Connection is inviable and should be reconnected.
Parameters
[in]tconnThat should be notified of I/O events.
[in]connThe fr_connection_t bound to the tconn. Use conn->h to access the connection handle or file descriptor.
[in]elto insert I/O events into.
[in]notify_onI/O events to signal the trunk connection on.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 434 of file trunk.h.

◆ fr_trunk_connection_t

Definition at line 1 of file trunk.h.

◆ fr_trunk_request_cancel_mux_t

typedef void(* fr_trunk_request_cancel_mux_t) (fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)

Inform a remote service like a datastore that a request should be cancelled.

This callback will be called any time there are one or more requests to be cancelled and a fr_connection_t is writable, or as soon as a request is cancelled if always_writable == true.

For efficiency, this callback should call fr_trunk_connection_pop_cancellation multiple times, and process all outstanding cancellation requests.

If the response (cancel ACK) from the remote service needs to be tracked, then the treq should be inserted into a tracking tree shared with the demuxer, and fr_trunk_request_signal_cancel_sent should be called to move the treq into the cancel_sent state.

As with the main mux callback, if a cancellation request is partially written fr_trunk_request_signal_cancel_partial should be called, and the amount of data written should be tracked in the preq (protocol request).

When the demuxer finds a matching (cancel ACK) response, the demuxer should remove the entry from the tracking tree and call fr_trunk_request_signal_cancel_complete.

Parameters
[in]elTo insert any timers into.
[in]tconnThe trunk connection used to dequeue cancellation requests.
[in]connConnection to write the request to. Use conn->h to access the connection handle or file descriptor.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 554 of file trunk.h.

◆ fr_trunk_request_cancel_t

typedef void(* fr_trunk_request_cancel_t) (fr_connection_t *conn, void *preq_to_reset, fr_trunk_cancel_reason_t reason, void *uctx)

Remove an outstanding "sent" request from a tracking/matching structure.

If the treq (trunk request) is in the FR_TRUNK_REQUEST_STATE_PARTIAL or FR_TRUNK_REQUEST_STATE_SENT states, this callback will be called prior to moving the treq to a new connection, requeueing the treq or freeing the treq.

The treq, and any associated resources, should be removed from the the matching structure associated with the fr_connection_t or uctx.

Which resources should be freed depends on the cancellation reason:

  • FR_TRUNK_CANCEL_REASON_REQUEUE - If an encoded request can be reused, then it should be kept, otherwise it should be freed. Any resources like ID allocations bound to that request should also be freed. fr_trunk_request_conn_release_t callback will not be called in this instance and cannot be used as an alternative.
  • FR_TRUNK_CANCEL_REASON_MOVE - If an encoded request can be reused it should be kept. The trunk mux callback should be aware that an encoded request may already be associated with a preq and use that instead of re-encoding the preq. If the encoded request cannot be reused it should be freed, and any fields in the preq that were modified during the last mux call (other than perhaps counters) should be reset to their initial values. Alternatively the fr_trunk_request_conn_release_t callback can be used for the same purpose, as that will be called before the request is moved.
  • FR_TRUNK_CANCEL_REASON_SIGNAL - The encoded request and any I/O library request handled may be freed though that may (optionally) be left to another callback like fr_trunk_request_conn_release_t, as that will be called as the treq is removed from the conn. Note that the fr_trunk_request_complete_t and fr_trunk_request_fail_t callbacks will not be called in this instance.

After this callback is complete one of several actions will be taken:

  • If the cancellation reason was FR_TRUNK_CANCEL_REASON_REQUEUE the treq will be placed back into the pending list of the connection it was previously associated with.
  • If the cancellation reason was FR_TRUNK_CANCEL_REASON_MOVE, the treq will move to the unassigned state, and then either be placed in the trunk backlog, or immediately enqueued on another trunk connection.
  • If the reason was FR_TRUNK_CANCEL_SIGNAL
    • ...and a request_cancel_mux callback was provided, the the request_cancel_mux callback will be called when the connection is next writable (or immediately if always_writable == true) and the request_cancel_mux callback will send an explicit cancellation request to terminate any outstanding queries on remote datastores.
    • ...and no request_cancel_mux callback was provided, the treq will enter the unassigned state and then be freed.
Note
FR_TRUNK_CANCEL_REASON_MOVE will only be set if the underlying connection is bad. A 'sent' treq will never be moved due to load balancing.
There is no need to signal request state changes in the cancellation function. The trunk will move the request into the correct state. This callback is only to allow the API client to cleanup the preq in preparation for the cancellation event.
Cancellation requests to a remote datastore should not be made here. If that is required, a cancel_mux function should be provided.
Parameters
[in]connto remove request from.
[in]preq_to_resetPreq to reset.
[in]reasonWhy the request was cancelled.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 627 of file trunk.h.

◆ fr_trunk_request_complete_t

typedef void(* fr_trunk_request_complete_t) (request_t *request, void *preq, void *rctx, void *uctx)

Write a successful result to the rctx so that the trunk API client is aware of the result.

The rctx should be modified in such a way that indicates to the trunk API client that the request was sent using the trunk and a response was received.

This function should not free any resources associated with the preq. That should be done in the request_free callback. This function should only be used to translate the contents of the preq into a result, and write it to the rctx.

After this callback is complete, the request_free callback will be called if provided.

Definition at line 657 of file trunk.h.

◆ fr_trunk_request_conn_release_t

typedef void(* fr_trunk_request_conn_release_t) (fr_connection_t *conn, void *preq_to_reset, void *uctx)

Free connection specific resources from a treq, as the treq is being removed from a connection.

Any connection specific resources that the treq currently holds must be released. Examples are connection-specific handles, ID allocations, and connection specific packets.

The treq may be about to be freed or it may be being re-assigned to a new connection.

Parameters
[in]connrequest will be removed from.
[in]preq_to_resetPreq to remove connection specified resources from.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 643 of file trunk.h.

◆ fr_trunk_request_demux_t

typedef void(* fr_trunk_request_demux_t) (fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)

Demultiplex on or more responses, reading them from a connection, decoding them, and matching them with their requests.

This callback should either:

  • If an underlying I/O library is used, request complete responses from the I/O library, and match the responses with a treq (trunk request) using a tracking structure associated with the fr_connection_t or uctx.
  • If no underlying I/O library is used, read responses from the fr_connection_t, decode those responses, and match those responses with a treq using a tracking structure associated with the fr_connection_t or uctx.

The result (positive or negative), should be written to the rctx structure.

fr_trunk_request_signal_complete should be used to inform the trunk that the request is now complete.

If a connection appears to have become unusable, this callback should call fr_connection_signal_reconnect and immediately return. The current treq will either fail, or be re-enqueued depending on the trunk configuration.

fr_trunk_request_signal_fail should NOT be called as this function is only used for reporting failures at an I/O layer level not failures of queries or external services.

Parameters
[in]elFor timer management.
[in]tconnThe trunk connection.
[in]connConnection to read the request from. Use conn->h to access the connection handle or file descriptor.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 520 of file trunk.h.

◆ fr_trunk_request_fail_t

typedef void(* fr_trunk_request_fail_t) (request_t *request, void *preq, void *rctx, fr_trunk_request_state_t state, void *uctx)

Write a failure result to the rctx so that the trunk API client is aware that the request failed.

The rctx should be modified in such a way that indicates to the trunk API client that the request could not be sent using the trunk.

This function should not free any resources associated with the preq. That should be done in the request_free callback. This function should only be used to write a "canned" failure to the rctx.

Note
If a cancel function is provided, the cancel function should be used to remove active requests from any request/response matching, not the fail function. Both the cancel and fail functions will be called for a request that has been sent or partially sent.

After this callback is complete, the request_free callback will be called if provided.

Definition at line 675 of file trunk.h.

◆ fr_trunk_request_free_t

typedef void(* fr_trunk_request_free_t) (request_t *request, void *preq_to_free, void *uctx)

Free resources associated with a trunk request.

The trunk request is complete. If there's a request still associated with the trunk request, that will be provided so that it can be marked runnable, but be aware that the request_t * value will be NULL if the request was cancelled due to a signal.

The preq and any associated data such as encoded packets or I/O library request handled SHOULD be explicitly freed by this function. The exception to this is if the preq is parented by the treq, in which case the preq will be explicitly freed when the treq is returned to the free list.

Parameters
[in]requestto mark as runnable if no further processing is required.
[in]preq_to_freeAs per the name.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 694 of file trunk.h.

◆ fr_trunk_request_mux_t

typedef void(* fr_trunk_request_mux_t) (fr_event_list_t *el, fr_trunk_connection_t *tconn, fr_connection_t *conn, void *uctx)

Multiplex one or more requests into a single connection.

This callback should:

  • Pop one or more requests from the trunk connection's pending queue using fr_trunk_connection_pop_request.
  • Serialize the protocol request data contained within the trunk request's (treq's) pctx, writing it to the provided fr_connection_t (or underlying connection handle).
  • Insert the provided treq into a tracking structure associated with the fr_connection_t or uctx. This tracking structure will be used later in the trunk demux callback to match protocol requests with protocol responses.

If working at the socket level and a write on a file descriptor indicates less data was written than was needed, the trunk API client should track the amount of data written in the protocol request (preq), and should call fr_trunk_request_signal_partial(treq). fr_trunk_request_signal_partial will move the request out of the pending queue, and store it in the partial slot of the trunk connection. The next time fr_trunk_connection_pop_request is called, the partially written treq will be returned first. The API client should continue writing the partially written request to the socket.

After calling fr_trunk_request_signal_partial this callback MUST NOT call fr_trunk_connection_pop_request again, and should immediately return.

If the request can't be written to the connection because it the connection has become unusable, this callback should call fr_connection_signal_reconnect(conn) to notify the connection API that the connection is unusable. The current request will either fail, or be re-enqueued depending on the trunk configuration.

After calling fr_connection_signal_reconnect this callback MUST NOT call fr_trunk_connection_pop_request again, and should immediately return.

If the protocol request data can't be written to the connection because the data is invalid or because some other error occurred, this callback should call fr_trunk_request_signal_fail(treq), this callback may then continue popping/processing other requests.

Parameters
[in]elFor timer management.
[in]tconnThe trunk connection to dequeue trunk requests from.
[in]connConnection to write the request to. Use conn->h to access the connection handle or file descriptor.
[in]uctxUser context data passed to fr_trunk_alloc.

Definition at line 486 of file trunk.h.

◆ fr_trunk_request_t

Definition at line 1 of file trunk.h.

◆ fr_trunk_t

typedef struct fr_trunk_pub_s fr_trunk_t

Definition at line 1 of file trunk.h.

◆ fr_trunk_watch_entry_t

Definition at line 703 of file trunk.h.

◆ fr_trunk_watch_t

typedef void(* fr_trunk_watch_t) (fr_trunk_t *trunk, fr_trunk_state_t prev, fr_trunk_state_t state, void *uctx)

Receive a notification when a trunk enters a particular state.

Parameters
[in]trunkBeing watched.
[in]prevState we came from.
[in]stateState that was entered (the current state)
[in]uctxthat was passed to fr_trunk_add_watch_*.

Definition at line 703 of file trunk.h.

Enumeration Type Documentation

◆ fr_trunk_cancel_reason_t

Reasons for a request being cancelled.

Enumerator
FR_TRUNK_CANCEL_REASON_NONE 

Request has not been cancelled.

FR_TRUNK_CANCEL_REASON_SIGNAL 

Request cancelled due to a signal.

FR_TRUNK_CANCEL_REASON_MOVE 

Request cancelled because it's being moved.

FR_TRUNK_CANCEL_REASON_REQUEUE 

A previously sent request is being requeued.

Definition at line 55 of file trunk.h.

◆ fr_trunk_connection_event_t

What type of I/O events the trunk connection is currently interested in receiving.

Enumerator
FR_TRUNK_CONN_EVENT_NONE 

Don't notify the trunk on connection state changes.

FR_TRUNK_CONN_EVENT_READ 

Trunk should be notified if a connection is readable.

FR_TRUNK_CONN_EVENT_WRITE 

Trunk should be notified if a connection is writable.

FR_TRUNK_CONN_EVENT_BOTH 

Trunk should be notified if a connection is readable or writable.

Definition at line 72 of file trunk.h.

◆ fr_trunk_connection_state_t

Used for sanity checks and to track which list the connection is in.

Enumerator
FR_TRUNK_CONN_HALTED 

Halted, ready to be freed.

FR_TRUNK_CONN_INIT 

In the initial state.

FR_TRUNK_CONN_CONNECTING 

Connection is connecting.

FR_TRUNK_CONN_ACTIVE 

Connection is connected and ready to service requests.

This is active and not 'connected', because a connection can be 'connected' and 'full' or 'connected' and 'active'.

FR_TRUNK_CONN_CLOSED 

Connection was closed, either explicitly or due to failure.

FR_TRUNK_CONN_FULL 

Connection is full and can't accept any more requests.

FR_TRUNK_CONN_INACTIVE 

Connection is inactive and can't accept any more requests.

FR_TRUNK_CONN_INACTIVE_DRAINING 

Connection is inactive, can't accept any more requests, and will be closed once it has no more outstanding requests.

Connections in this state can transition to FR_TRUNK_CONN_DRAINING.

FR_TRUNK_CONN_DRAINING 

Connection will be closed once it has no more outstanding requests, if it's not reactivated.

FR_TRUNK_CONN_DRAINING_TO_FREE 

Connection will be closed once it has no more outstanding requests.

Definition at line 87 of file trunk.h.

◆ fr_trunk_enqueue_t

Enumerator
FR_TRUNK_ENQUEUE_IN_BACKLOG 

Request should be enqueued in backlog.

FR_TRUNK_ENQUEUE_OK 

Operation was successful.

FR_TRUNK_ENQUEUE_NO_CAPACITY 

At maximum number of connections, and no connection has capacity.

FR_TRUNK_ENQUEUE_DST_UNAVAILABLE 

Destination is down.

FR_TRUNK_ENQUEUE_FAIL 

General failure.

Definition at line 148 of file trunk.h.

◆ fr_trunk_request_state_t

Used for sanity checks and to simplify freeing.

Allows us to track which

Enumerator
FR_TRUNK_REQUEST_STATE_INIT 

Initial state.

Requests in this state were never assigned, and the request_t should not have been yielded.

FR_TRUNK_REQUEST_STATE_UNASSIGNED 

Transition state - Request currently not assigned to any connection.

FR_TRUNK_REQUEST_STATE_BACKLOG 

In the backlog.

FR_TRUNK_REQUEST_STATE_PENDING 

In the queue of a connection and is pending writing.

FR_TRUNK_REQUEST_STATE_PARTIAL 

Some of the request was written to the socket, more of it should be written later.

FR_TRUNK_REQUEST_STATE_SENT 

Was written to a socket. Waiting for a response.

FR_TRUNK_REQUEST_STATE_COMPLETE 

The request is complete.

FR_TRUNK_REQUEST_STATE_FAILED 

The request failed.

FR_TRUNK_REQUEST_STATE_CANCEL 

A request on a particular socket was cancel.

FR_TRUNK_REQUEST_STATE_CANCEL_SENT 

We've informed the remote server that the request has been cancelled.

FR_TRUNK_REQUEST_STATE_CANCEL_PARTIAL 

We partially wrote a cancellation request.

FR_TRUNK_REQUEST_STATE_CANCEL_COMPLETE 

Remote server has acknowledged our cancellation.

Definition at line 161 of file trunk.h.

◆ fr_trunk_state_t

Enumerator
FR_TRUNK_STATE_IDLE 

Trunk has no connections.

FR_TRUNK_STATE_ACTIVE 

Trunk has active connections.

FR_TRUNK_STATE_PENDING 

Trunk has connections, but none are active.

FR_TRUNK_STATE_MAX 

Definition at line 62 of file trunk.h.

Function Documentation

◆ fr_trunk_add_watch()

fr_trunk_watch_entry_t* fr_trunk_add_watch ( fr_trunk_t trunk,
fr_trunk_state_t  state,
fr_trunk_watch_t  watch,
bool  oneshot,
void const *  uctx 
)

Add a watch entry to the trunk state list.

Parameters
[in]trunkThe trunk to add the watcher to.
[in]stateto watch for.
[in]watchFunction to add.
[in]oneshotShould this watcher only be run once.
[in]uctxContext to pass to function.
Returns
  • NULL if an invalid state is passed.
  • A new watch entry handle on success.

Definition at line 846 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_alloc()

fr_trunk_t* fr_trunk_alloc ( TALLOC_CTX *  ctx,
fr_event_list_t el,
fr_trunk_io_funcs_t const *  funcs,
fr_trunk_conf_t const *  conf,
char const *  log_prefix,
void const *  uctx,
bool  delay_start 
)

Allocate a new collection of connections.

This function should be called first to allocate a new trunk connection.

After the trunk has been allocated, fr_trunk_request_alloc and fr_trunk_request_enqueue should be used to allocate memory for trunk requests, and pass a preq (protocol request) to the trunk for processing.

The trunk will then asynchronously process the request, writing the result to a specified rctx. See fr_trunk_request_enqueue for more details.

Note
Trunks may not be shared between multiple threads under any circumstances.
Parameters
[in]ctxTo use for any memory allocations. Must be thread local.
[in]elto use for I/O and timer events.
[in]funcsCallback functions.
[in]confCommon user configurable parameters.
[in]log_prefixTo prepend to global messages.
[in]uctxUser data to pass to the alloc function.
[in]delay_startIf true, then we will not spawn any connections until the first request is enqueued.
Returns
  • New trunk handle on success.
  • NULL on error.

Definition at line 4767 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_callback_readable()

void fr_trunk_connection_callback_readable ( fr_event_list_t el,
int  fd,
int  flags,
void *  uctx 
)

◆ fr_trunk_connection_callback_writable()

void fr_trunk_connection_callback_writable ( fr_event_list_t el,
int  fd,
int  flags,
void *  uctx 
)

◆ fr_trunk_connection_count_by_state()

uint16_t fr_trunk_connection_count_by_state ( fr_trunk_t trunk,
int  conn_state 
)

Return the count number of connections in the specified states.

Parameters
[in]trunkto retrieve counts for.
[in]conn_stateOne or more fr_trunk_connection_state_t states or'd together.
Returns
The number of connections in the specified states.

Definition at line 2743 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_in_state()

bool fr_trunk_connection_in_state ( fr_trunk_connection_t tconn,
int  state 
)

Returns true if the trunk connection is in one of the specified states.

Parameters
[in]tconnTo check state for.
[in]stateto check
Returns
  • True if trunk connection is in a particular state.
  • False if trunk connection is not in a particular state.

Definition at line 3920 of file trunk.c.

◆ fr_trunk_connection_manage_schedule()

int fr_trunk_connection_manage_schedule ( fr_trunk_t trunk)

Schedule a trunk management event for the next time the event loop is executed.

Definition at line 4651 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_manage_start()

void fr_trunk_connection_manage_start ( fr_trunk_t trunk)

Allow the trunk to open and close connections in response to load.

Definition at line 4630 of file trunk.c.

◆ fr_trunk_connection_manage_stop()

void fr_trunk_connection_manage_stop ( fr_trunk_t trunk)

Stop the trunk from opening and closing connections in response to load.

Definition at line 4641 of file trunk.c.

◆ fr_trunk_connection_pop_cancellation()

int fr_trunk_connection_pop_cancellation ( fr_trunk_request_t **  treq_out,
fr_trunk_connection_t tconn 
)

Pop a cancellation request off a connection's cancellation queue.

The request we return is advanced by the request moving out of the cancel state and into the cancel_sent or cancel_complete state.

One of these signalling functions must be called after the request has been popped:

Parameters
[out]treq_outto process
[in]tconnConnection to drain cancellation request from.
Returns
  • 1 if no more requests.
  • 0 if a new request was written to treq_out.
  • -1 if the connection was previously freed. Caller MUST NOT touch any memory or requests associated with the connection.
  • -2 if called outside of the cancel muxer.

Definition at line 3708 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_pop_request()

int fr_trunk_connection_pop_request ( fr_trunk_request_t **  treq_out,
fr_trunk_connection_t tconn 
)

Pop a request off a connection's pending queue.

The request we return is advanced by the request moving out of the partial or pending states, when the mux function signals us.

If the same request is returned again and again, it means the muxer isn't actually doing anything with the request we returned, and it's and error in the muxer code.

One of these signalling functions must be used after the request has been popped:

  • fr_trunk_request_signal_complete The request was completed. Either we got a synchronous response, or we knew the response without contacting an external server (cache).
  • fr_trunk_request_signal_fail Failed muxing the request due to a permanent issue, i.e. an invalid request.
  • fr_trunk_request_signal_partial Wrote part of a request. This request will be returned on the next call to this function so that the request_mux function can finish writing it. Only useful for stream type connections. Datagram type connections cannot have partial writes.
  • fr_trunk_request_signal_sent Successfully sent a request.
Parameters
[out]treq_outto process
[in]tconnto pop a request from.
Returns
  • 1 if no more requests.
  • 0 if a new request was written to treq_out.
  • -1 if the connection was previously freed. Caller MUST NOT touch any memory or requests associated with the connection.
  • -2 if called outside of the muxer.

Definition at line 3756 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_requests_requeue()

uint64_t fr_trunk_connection_requests_requeue ( fr_trunk_connection_t tconn,
int  states,
uint64_t  max,
bool  fail_bound 
)

Move requests off of a connection and requeue elsewhere.

Note
We don't re-queue on draining or draining to free, as requests should have already been moved off of the connection. It's also dangerous as the trunk management code main clean up a connection in this state when it's run on re-queue, and then the caller may try and access a now freed connection.
Parameters
[in]tconnto move requests off of.
[in]statesOnly move requests in this state.
[in]maxThe maximum number of requests to dequeue. 0 for unlimited.
[in]fail_boundIf true causes any requests bound to the connection to fail. If false bound requests will not be moved.
Returns
The number of requests requeued.

Definition at line 1933 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_search()

bool fr_trunk_connection_search ( fr_trunk_connection_t tconn,
void *  ptr 
)

Definition at line 5025 of file trunk.c.

◆ fr_trunk_connection_signal_active()

void fr_trunk_connection_signal_active ( fr_trunk_connection_t tconn)

Signal a trunk connection is no longer full.

Parameters
[in]tconnto signal.

Definition at line 3833 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_signal_inactive()

void fr_trunk_connection_signal_inactive ( fr_trunk_connection_t tconn)

Signal a trunk connection cannot accept more requests.

Parameters
[in]tconnto signal.

Definition at line 3810 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_signal_readable()

void fr_trunk_connection_signal_readable ( fr_trunk_connection_t tconn)

Signal that a trunk connection is readable.

Should be called from the 'read' I/O handler to signal that requests should be dequeued.

Parameters
[in]tconnto signal.

Definition at line 3794 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_signal_reconnect()

void fr_trunk_connection_signal_reconnect ( fr_trunk_connection_t tconn,
fr_connection_reason_t  reason 
)

Signal a trunk connection is no longer viable.

Parameters
[in]tconnto signal.
[in]reasonthe connection is being reconnected.

Definition at line 3872 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_signal_writable()

void fr_trunk_connection_signal_writable ( fr_trunk_connection_t tconn)

Signal that a trunk connection is writable.

Should be called from the 'write' I/O handler to signal that requests can be enqueued.

Parameters
[in]tconnto signal.

Definition at line 3776 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_connection_verify()

void fr_trunk_connection_verify ( char const *  file,
int  line,
fr_trunk_connection_t tconn 
)

Definition at line 4909 of file trunk.c.

◆ fr_trunk_del_watch()

int fr_trunk_del_watch ( fr_trunk_t trunk,
fr_trunk_state_t  state,
fr_trunk_watch_t  watch 
)

Remove a watch function from a trunk state list.

Parameters
[in]trunkThe trunk to remove the watcher from.
[in]stateto remove the watch from.
[in]watchFunction to remove.
Returns
  • 0 if the function was removed successfully.
  • -1 if the function wasn't present in the watch list.
  • -2 if an invalid state was passed.

Definition at line 812 of file trunk.c.

+ Here is the call graph for this function:

◆ fr_trunk_reconnect()

void fr_trunk_reconnect ( fr_trunk_t trunk,
int  states,
fr_connection_reason_t  reason 
)

Force the trunk to re-establish its connections.

Parameters
[in]trunkto signal.
[in]statesOne or more states or'd together.
[in]reasonWhy the connections are being signalled to reconnect.

Definition at line 4557 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_alloc()

fr_trunk_request_t* fr_trunk_request_alloc ( fr_trunk_t trunk,
request_t request 
)

(Pre-)Allocate a new trunk request

If trunk->conf.req_pool_headers or trunk->conf.req_pool_size are not zero then the request will be a talloc pool, which can be used to hold the preq.

Note
Do not use MEM to check the result of this allocated as it may fail for non-fatal reasons.
Parameters
[in]trunkto add request to.
[in]requestto wrap in a trunk request (treq).
Returns
  • A newly allocated request.
  • NULL if too many requests are allocated.

Definition at line 2369 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_count_by_connection()

uint32_t fr_trunk_request_count_by_connection ( fr_trunk_connection_t const *  tconn,
int  req_state 
)

Return the count number of requests associated with a trunk connection.

Parameters
[in]tconnto return request count for.
[in]req_stateOne or more request states or'd together.
Returns
The number of requests in the specified states, associated with a tconn.

Definition at line 2767 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_count_by_state()

uint64_t fr_trunk_request_count_by_state ( fr_trunk_t trunk,
int  conn_state,
int  req_state 
)

Return a count of requests on a connection in a specific state.

Parameters
[in]trunkto retrieve counts for.
[in]conn_stateOne or more connection states or'd together.
[in]req_stateOne or more request states or'd together.
Returns
The number of requests in a particular state, on connection in a particular state.

Definition at line 4354 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_enqueue()

fr_trunk_enqueue_t fr_trunk_request_enqueue ( fr_trunk_request_t **  treq_out,
fr_trunk_t trunk,
request_t request,
void *  preq,
void *  rctx 
)

Enqueue a request that needs data written to the trunk.

When a request_t * needs to make an asynchronous request to an external datastore it should call this function, specifying a preq (protocol request) containing the data necessary to request information from the external datastore, and an rctx (resume ctx) used to hold the decoded response and/or any error codes.

After a treq is successfully enqueued it will either be assigned immediately to the pending queue of a connection, or if no connections are available, (depending on the trunk configuration) the treq will be placed in the trunk's global backlog.

After receiving a positive return code from this function the caller should immediately yield, to allow the various timers and I/O handlers that drive tconn (trunk connection) and treq state changes to be called.

When a tconn becomes writable (or the trunk is configured to be always writable) the fr_trunk_request_mux_t callback will be called to dequeue, encode and send any pending requests for that tconn. The fr_trunk_request_mux_t callback is also responsible for tracking the outbound requests to allow the fr_trunk_request_demux_t callback to match inbound responses with the original treq. Once the fr_trunk_request_mux_t callback is done processing the treq it signals what state the treq should enter next using one of the fr_trunk_request_signal_* functions.

When a tconn becomes readable the user specified fr_trunk_request_demux_t callback is called to process any responses, match them with the original treq. and signal what state they should enter next using one of the fr_trunk_request_signal_* functions.

Parameters
[in,out]treq_outA trunk request handle. If the memory pointed to is NULL, a new treq will be allocated. Otherwise treq should point to memory allocated with fr_trunk_request_alloc.
[in]trunkto enqueue request on.
[in]requestto enqueue.
[in]preqProtocol request to write out. Will be freed when treq is freed. Should ideally be parented by the treq if possible. Use fr_trunk_request_alloc for pre-allocation of the treq.
[in]rctxThe resume context to write any result to.
Returns
  • FR_TRUNK_ENQUEUE_OK.
  • FR_TRUNK_ENQUEUE_IN_BACKLOG.
  • FR_TRUNK_ENQUEUE_NO_CAPACITY.
  • FR_TRUNK_ENQUEUE_DST_UNAVAILABLE
  • FR_TRUNK_ENQUEUE_FAIL

Definition at line 2481 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_enqueue_on_conn()

fr_trunk_enqueue_t fr_trunk_request_enqueue_on_conn ( fr_trunk_request_t **  treq_out,
fr_trunk_connection_t tconn,
request_t request,
void *  preq,
void *  rctx,
bool  ignore_limits 
)

Enqueue additional requests on a specific connection.

This may be used to create a series of requests on a single connection, or to generate in-band status checks.

Note
If conf->always_writable, then the muxer will be called immediately. The caller must be able to handle multiple calls to its muxer gracefully.
Parameters
[in,out]treq_outA trunk request handle. If the memory pointed to is NULL, a new treq will be allocated. Otherwise treq should point to memory allocated with fr_trunk_request_alloc.
[in]tconnto enqueue request on.
[in]requestto enqueue.
[in]preqProtocol request to write out. Will be freed when treq is freed. Should ideally be parented by the treq if possible. Use fr_trunk_request_alloc for pre-allocation of the treq.
[in]rctxThe resume context to write any result to.
[in]ignore_limitsIgnore max_req_per_conn. Useful to force status checks through even if the connection is at capacity. Will also allow enqueuing on "inactive", "draining", "draining-to-free" connections.
Returns
  • FR_TRUNK_ENQUEUE_OK.
  • FR_TRUNK_ENQUEUE_NO_CAPACITY - At max_req_per_conn_limit
  • FR_TRUNK_ENQUEUE_DST_UNAVAILABLE - Connection cannot service requests.

Definition at line 2629 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_free()

void fr_trunk_request_free ( fr_trunk_request_t **  treq_to_free)

If the trunk request is freed then update the target requests.

gperftools showed calling the request free function directly was slightly faster than using talloc_free.

Parameters
[in]treq_to_freerequest.

Definition at line 2217 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_requeue()

fr_trunk_enqueue_t fr_trunk_request_requeue ( fr_trunk_request_t treq)

Re-enqueue a request on the same connection.

If the treq has been sent, we assume that we're being signalled to requeue because something outside of the trunk API has determined that a retransmission is required. The easiest way to perform that retransmission is to clean up any tracking information for the request, and the requeue it for transmission.

IF re-queueing fails, the request will enter the fail state. It should not be accessed if this occurs.

Parameters
[in]treqto requeue (retransmit).
Returns
  • FR_TRUNK_ENQUEUE_OK.
  • FR_TRUNK_ENQUEUE_DST_UNAVAILABLE - Connection cannot service requests.
  • FR_TRUNK_ENQUEUE_FAIL - Request isn't in a valid state to be reassigned.

Definition at line 2568 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_search()

bool fr_trunk_request_search ( fr_trunk_request_t treq,
void *  ptr 
)

Definition at line 5083 of file trunk.c.

◆ fr_trunk_request_signal_cancel()

void fr_trunk_request_signal_cancel ( fr_trunk_request_t treq)

Cancel a trunk request.

treq can be in any state, but requests to cancel if the treq is not in the FR_TRUNK_REQUEST_STATE_PARTIAL or FR_TRUNK_REQUEST_STATE_SENT state will be ignored.

The complete or failed callbacks will not be called here, as it's assumed the request_t * is now inviable as it's being cancelled.

The free function however, is called, and that should be used to perform necessary cleanup.

Parameters
[in]treqto signal state change for.

Definition at line 2047 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_cancel_complete()

void fr_trunk_request_signal_cancel_complete ( fr_trunk_request_t treq)

Signal that a remote server acked our cancellation.

Called from request_demux to indicate that it got an ack for the cancellation.

Parameters
[in]treqto signal state change for.

Definition at line 2179 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_cancel_partial()

void fr_trunk_request_signal_cancel_partial ( fr_trunk_request_t treq)

Signal a partial cancel write.

Where there's high load, and the outbound write buffer is full

Parameters
[in]treqto signal state change for.

Definition at line 2131 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_cancel_sent()

void fr_trunk_request_signal_cancel_sent ( fr_trunk_request_t treq)

Signal that a remote server has been notified of the cancellation.

Called from request_cancel_mux to indicate that the datastore has been informed that the response is no longer needed.

Parameters
[in]treqto signal state change for.

Definition at line 2155 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_complete()

void fr_trunk_request_signal_complete ( fr_trunk_request_t treq)

Signal that a trunk request is complete.

The API client will be informed that the request is now complete.

Definition at line 1995 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_fail()

void fr_trunk_request_signal_fail ( fr_trunk_request_t treq)

Signal that a trunk request failed.

The API client will be informed that the request has failed.

Definition at line 2027 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_partial()

void fr_trunk_request_signal_partial ( fr_trunk_request_t treq)

Signal a partial write.

Where there's high load, and the outbound write buffer is full

Parameters
[in]treqto signal state change for.

Definition at line 1952 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_signal_sent()

void fr_trunk_request_signal_sent ( fr_trunk_request_t treq)

Signal that the request was written to a connection successfully.

Parameters
[in]treqto signal state change for.

Definition at line 1973 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_state_log()

void fr_trunk_request_state_log ( fr_log_t const *  log,
fr_log_type_t  log_type,
char const *  file,
int  line,
fr_trunk_request_t const *  treq 
)

Definition at line 2716 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_request_verify()

void fr_trunk_request_verify ( char const *  file,
int  line,
fr_trunk_request_t treq 
)

Definition at line 4969 of file trunk.c.

+ Here is the call graph for this function:

◆ fr_trunk_search()

bool fr_trunk_search ( fr_trunk_t trunk,
void *  ptr 
)

Definition at line 4980 of file trunk.c.

◆ fr_trunk_start()

int fr_trunk_start ( fr_trunk_t trunk)

Start the trunk running.

Definition at line 4596 of file trunk.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_trunk_verify()

void fr_trunk_verify ( char const *  file,
int  line,
fr_trunk_t trunk 
)

Verify a trunk.

A trunk has some number of connections, which each have some number of requests. The connections and requests are in differing kinds of containers depending on their state and how they are used, and may have fields that can only be validated by comparison with a parent. We had planned on passing a "context" down with the ancestral values, but that breaks the foo_verify() API. Each foo_verify() will only verify the foo's children.

Definition at line 4848 of file trunk.c.

+ Here is the call graph for this function:

Variable Documentation

◆ fr_trunk_config

conf_parser_t const fr_trunk_config[]
extern

Config parser definitions to populate a fr_trunk_conf_t.

Definition at line 306 of file trunk.c.