All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
rlm_sql_cassandra.c File Reference

This is free and unencumbered software released into the public domain. More...

#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/rad_assert.h>
#include <cassandra.h>
#include "rlm_sql.h"
+ Include dependency graph for rlm_sql_cassandra.c:

Go to the source code of this file.

Data Structures

struct  rlm_sql_cassandra_config
 Cassandra driver instance. More...
 
struct  rlm_sql_cassandra_conn
 Cassandra cluster connection. More...
 

Macros

#define DO_CASS_OPTION(_opt, _x)
 
#define RLM_CASS_ERR_DATA_RETRIVE(_t)
 

Typedefs

typedef struct
rlm_sql_cassandra_config 
rlm_sql_cassandra_config_t
 Cassandra driver instance. More...
 
typedef struct
rlm_sql_cassandra_conn 
rlm_sql_cassandra_conn_t
 Cassandra cluster connection. More...
 

Functions

static int _mod_destructor (rlm_sql_cassandra_config_t *config)
 
static void _rlm_sql_cassandra_log (CassLogMessage const *message, UNUSED void *data)
 Log callback for libcassandra. More...
 
static int _sql_socket_destructor (rlm_sql_cassandra_conn_t *conn)
 
static int mod_instantiate (CONF_SECTION *conf, rlm_sql_config_t *config)
 
static int sql_affected_rows (UNUSED rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static size_t sql_error (UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static sql_rcode_t sql_fetch_row (rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 
static sql_rcode_t sql_fields (char const **out[], rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 
static sql_rcode_t sql_finish_query (rlm_sql_handle_t *handle, rlm_sql_config_t *config)
 
static sql_rcode_t sql_free_result (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static int sql_num_fields (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static int sql_num_rows (rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
 
static sql_rcode_t sql_query (rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query)
 
static void sql_set_last_error (rlm_sql_cassandra_conn_t *conn, char const *message, size_t len)
 Replace the last error messages associated with the connection. More...
 
static void sql_set_last_error_printf (rlm_sql_cassandra_conn_t *conn, char const *fmt,...) CC_HINT(format(printf
 Replace the last error messages associated with the connection. More...
 
static sql_rcode_t sql_socket_init (rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
 

Variables

static const FR_NAME_NUMBER consistency_levels []
 
static const CONF_PARSER driver_config []
 
static CONF_PARSER latency_aware_routing_config []
 
static CONF_PARSER load_balance_dc_aware_config []
 
static int rlm_sql_cass_instances = 0
 
rlm_sql_module_t rlm_sql_cassandra
 
static CONF_PARSER tls_config []
 
static const FR_NAME_NUMBER verify_cert_table []
 

Detailed Description

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org

Id:
907f73a71f076e5484a1be1adcd3e9ad5dd6e5cf

Cassandra SQL driver

Author
Linnaea Von Lavia le.co.nosp@m.ncor.nosp@m.de.45.nosp@m.90@g.nosp@m.mail..nosp@m.com
Arran Cudbard-Bell a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg

Definition in file rlm_sql_cassandra.c.


Data Structure Documentation

struct rlm_sql_cassandra_config

Cassandra driver instance.

Definition at line 60 of file rlm_sql_cassandra.c.

Data Fields
CassCluster * cluster Configuration of the cassandra cluster connection.
uint32_t connections_per_host Number of connections to each server in each IO thread.
uint32_t connections_per_host_max Maximum number of connections to each server in each IO threads.
CassConsistency consistency Level of consistency converted to a constant.
char const * consistency_str Level of consistency required.
bool done_connect_keyspace Whether we've connected to a keyspace.
uint32_t event_queue_size Sets the size of the the fixed size queue that stores events.
uint32_t io_flush_requests_max Maximum number of requests processed by an IO worker per flush.
uint32_t io_queue_size Size of the the fixed size queue that stores pending requests.
uint32_t io_threads Number of IO threads.
struct timeval lar_exclusion_threshold How much worse the latency me be, compared to the average latency of the best performing node before it's penalized.

This gets mangled to a double.

uint64_t lar_min_measured The minimum number of measurements per-host required to be considered by the policy.
struct timeval lar_retry_period The amount of time a node is penalized by the policy before being given a second chance when the current average latency exceeds the calculated threshold (exclusion_threshold * best_average_latency).
struct timeval lar_scale Weight given to older latencies when calculating the average latency of a node.

A bigger scale will give more weight to older latency measurements.

struct timeval lar_update_rate The rate at which the best average latency is recomputed.
bool lbdc_allow_remote_dcs_for_local_cl Allows remote hosts to be used if no local.

dc hosts are available and the consistency level is LOCAL_ONE or LOCAL_QUORUM.

uint32_t lbdc_hosts_per_remote_dc The number of host used in each remote DC if no hosts are available in the local dc.
char const * lbdc_local_dc The primary data center to try first.
bool load_balance_round_robin Enable round robin load balancing.
uint32_t pending_requests_high Sets the high water mark for the number of requests queued waiting for a connection in a connection pool.

Disables writes to a host on an IO worker if the number of requests queued exceed this value.

uint32_t pending_requests_low Sets the low water mark for the number of requests queued waiting for a connection in a connection pool.

After exceeding high water mark requests, writes to a host will only resume once the number of requests fall below this value.

uint32_t protocol_version The protocol version.
CassSession * session Cluster's connection pool.
uint32_t spawn_max The maximum number of connections that will be created concurrently.
struct timeval spawn_retry_delay Amount of time to wait before attempting to reconnect.
uint32_t spawn_threshold Threshold for the maximum number of concurrent requests in-flight on a connection before creating a new connection.
CassSsl * ssl Connection's SSL context.
uint32_t tcp_keepalive How often to send TCP keepalives.
bool tcp_nodelay Disable TCP naggle algorithm.
char const * tls_ca_file Path to the CA used to validate the server's certificate.
char const * tls_certificate_file Public certificate we present to the server.
char const * tls_private_key_file Private key for the certificate we present to the server.
char const * tls_private_key_password String to decrypt private key.
char const * tls_verify_cert_str Whether we validate the cert provided by the server.
bool token_aware_routing Whether to use token aware routing.
uint32_t write_bytes_high High water mark for the number of bytes outstanding on a connection.

Disables writes to a connection if the number of bytes queued exceed this value.

uint32_t write_bytes_low Low water mark for number of bytes outstanding on a connection.

After exceeding high water mark bytes, writes will only resume once the number of bytes fall below this value.

struct rlm_sql_cassandra_conn

Cassandra cluster connection.

Definition at line 48 of file rlm_sql_cassandra.c.

+ Collaboration diagram for rlm_sql_cassandra_conn:
Data Fields
CassIterator * iterator Row set iterator.
sql_log_entry_t last_error
TALLOC_CTX * log_ctx Prevent unneeded memory allocation by keeping a permanent pool, to store log entries.
CassResult const * result Result from executing a query.

Macro Definition Documentation

#define DO_CASS_OPTION (   _opt,
  _x 
)
Value:
do {\
CassError _ret;\
if ((_ret = (_x)) != CASS_OK) {\
ERROR("rlm_sql_cassandra: Error setting " _opt ": %s", cass_error_desc(_ret));\
return RLM_SQL_ERROR;\
}\
} while (0)
General connection/server error.
Definition: rlm_sql.h:46
#define ERROR(fmt,...)
Definition: log.h:145
#define RLM_CASS_ERR_DATA_RETRIVE (   _t)
Value:
do {\
char const *_col_name;\
size_t _col_name_len;\
CassError _ret;\
if ((_ret = cass_result_column_name(conn->result, i, &_col_name, &_col_name_len)) != CASS_OK) {\
_col_name = "<INVALID>";\
}\
sql_set_last_error_printf(conn, "Failed to retrieve " _t " data at column %s (%d): %s", \
_col_name, i, cass_error_desc(_ret));\
TALLOC_FREE(handle->row);\
return RLM_SQL_ERROR;\
} while(0)
General connection/server error.
Definition: rlm_sql.h:46
static void sql_set_last_error_printf(rlm_sql_cassandra_conn_t *conn, char const *fmt,...) CC_HINT(format(printf
Replace the last error messages associated with the connection.

Typedef Documentation

Cassandra driver instance.

Cassandra cluster connection.

Function Documentation

static int _mod_destructor ( rlm_sql_cassandra_config_t config)
static

Definition at line 347 of file rlm_sql_cassandra.c.

+ Here is the caller graph for this function:

static void _rlm_sql_cassandra_log ( CassLogMessage const *  message,
UNUSED void *  data 
)
static

Log callback for libcassandra.

libcassandra seems to use this to log global events in the library, other messages like query errors are not logged here, and should be retrieved with functions like cass_future_error_message();

Messages here do not need to be made available via sql_error.

Parameters
messageContains the log message and information about its source.
datauser data (not used).

Definition at line 260 of file rlm_sql_cassandra.c.

+ Here is the caller graph for this function:

static int _sql_socket_destructor ( rlm_sql_cassandra_conn_t conn)
static

Definition at line 605 of file rlm_sql_cassandra.c.

+ Here is the caller graph for this function:

static int mod_instantiate ( CONF_SECTION conf,
rlm_sql_config_t config 
)
static

Definition at line 361 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

static int sql_affected_rows ( UNUSED rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 934 of file rlm_sql_cassandra.c.

static size_t sql_error ( UNUSED TALLOC_CTX *  ctx,
sql_log_entry_t  out[],
size_t  outlen,
rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 897 of file rlm_sql_cassandra.c.

static sql_rcode_t sql_fetch_row ( rlm_sql_row_t out,
rlm_sql_handle_t handle,
rlm_sql_config_t config 
)
static

Definition at line 746 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_fields ( char const **  out[],
rlm_sql_handle_t handle,
rlm_sql_config_t config 
)
static

Definition at line 720 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_finish_query ( rlm_sql_handle_t handle,
rlm_sql_config_t config 
)
static

Definition at line 913 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

static sql_rcode_t sql_free_result ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 878 of file rlm_sql_cassandra.c.

+ Here is the caller graph for this function:

static int sql_num_fields ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 706 of file rlm_sql_cassandra.c.

+ Here is the caller graph for this function:

static int sql_num_rows ( rlm_sql_handle_t handle,
UNUSED rlm_sql_config_t config 
)
static

Definition at line 713 of file rlm_sql_cassandra.c.

static sql_rcode_t sql_query ( rlm_sql_handle_t handle,
rlm_sql_config_t config,
char const *  query 
)
static

Definition at line 667 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void sql_set_last_error ( rlm_sql_cassandra_conn_t conn,
char const *  message,
size_t  len 
)
static

Replace the last error messages associated with the connection.

This could be modified in future to maintain a circular buffer of log entries, but it's not required for now.

Parameters
connto replace log message in.
messagefrom libcassandra.
lenof message.

Definition at line 315 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void static void sql_set_last_error_printf ( rlm_sql_cassandra_conn_t conn,
char const *  fmt,
  ... 
)
static

Replace the last error messages associated with the connection.

This could be modified in future to maintain a circular buffer of log entries, but it's not required for now.

Parameters
connto replace log message in.
fmtof message.
...args.

Definition at line 335 of file rlm_sql_cassandra.c.

+ Here is the caller graph for this function:

static sql_rcode_t sql_socket_init ( rlm_sql_handle_t handle,
rlm_sql_config_t config,
struct timeval const *  timeout 
)
static

Definition at line 615 of file rlm_sql_cassandra.c.

+ Here is the call graph for this function:

Variable Documentation

const FR_NAME_NUMBER consistency_levels[]
static
Initial value:
= {
{ "any", CASS_CONSISTENCY_ANY },
{ "one", CASS_CONSISTENCY_ONE },
{ "two", CASS_CONSISTENCY_TWO },
{ "three", CASS_CONSISTENCY_THREE },
{ "quorum", CASS_CONSISTENCY_QUORUM },
{ "all", CASS_CONSISTENCY_ALL },
{ "each_quorum", CASS_CONSISTENCY_EACH_QUORUM },
{ "local_quorum", CASS_CONSISTENCY_LOCAL_QUORUM },
{ "local_one", CASS_CONSISTENCY_LOCAL_ONE },
{ NULL, 0 }
}

Definition at line 169 of file rlm_sql_cassandra.c.

const CONF_PARSER driver_config[]
static

Definition at line 213 of file rlm_sql_cassandra.c.

CONF_PARSER latency_aware_routing_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("exclusion_threshold", PW_TYPE_TIMEVAL, rlm_sql_cassandra_config_t, lar_exclusion_threshold), .dflt = "2.0" },
{ FR_CONF_OFFSET("scale", PW_TYPE_TIMEVAL, rlm_sql_cassandra_config_t, lar_scale), .dflt = "0.1" },
{ FR_CONF_OFFSET("retry_period", PW_TYPE_TIMEVAL, rlm_sql_cassandra_config_t, lar_retry_period), .dflt = "10" },
{ FR_CONF_OFFSET("update_rate", PW_TYPE_TIMEVAL, rlm_sql_cassandra_config_t, lar_update_rate), .dflt = "0.1" },
{ FR_CONF_OFFSET("min_measured", PW_TYPE_INTEGER64, rlm_sql_cassandra_config_t, lar_min_measured), .dflt = "50" }
}
Time value (struct timeval), only for config items.
Definition: radius.h:55
Cassandra driver instance.
64 Bit unsigned integer.
Definition: radius.h:51
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168

Definition at line 195 of file rlm_sql_cassandra.c.

CONF_PARSER load_balance_dc_aware_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("local_dc", PW_TYPE_STRING, rlm_sql_cassandra_config_t, lbdc_local_dc) },
{ FR_CONF_OFFSET("hosts_per_remote_dc", PW_TYPE_INTEGER, rlm_sql_cassandra_config_t, lbdc_hosts_per_remote_dc), .dflt = "0" },
{ FR_CONF_OFFSET("allow_remote_dcs_for_local_cl", PW_TYPE_BOOLEAN, rlm_sql_cassandra_config_t, lbdc_allow_remote_dcs_for_local_cl), .dflt = "no" }
}
Cassandra driver instance.
A truth value.
Definition: radius.h:56
32 Bit unsigned integer.
Definition: radius.h:34
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33

Definition at line 189 of file rlm_sql_cassandra.c.

int rlm_sql_cass_instances = 0
static

Definition at line 43 of file rlm_sql_cassandra.c.

rlm_sql_module_t rlm_sql_cassandra
Initial value:
= {
.name = "rlm_sql_cassandra",
.mod_instantiate = mod_instantiate,
.sql_socket_init = sql_socket_init,
.sql_query = sql_query,
.sql_select_query = sql_query,
.sql_num_fields = sql_num_fields,
.sql_num_rows = sql_num_rows,
.sql_affected_rows = sql_affected_rows,
.sql_fields = sql_fields,
.sql_fetch_row = sql_fetch_row,
.sql_free_result = sql_free_result,
.sql_error = sql_error,
.sql_finish_query = sql_finish_query,
.sql_finish_select_query = sql_finish_query
}
static int sql_affected_rows(UNUSED rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
static sql_rcode_t sql_free_result(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_fields(char const **out[], rlm_sql_handle_t *handle, rlm_sql_config_t *config)
static sql_rcode_t sql_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config, char const *query)
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static int sql_num_rows(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_finish_query(rlm_sql_handle_t *handle, rlm_sql_config_t *config)
static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *config, struct timeval const *timeout)
static int sql_num_fields(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *config)
static sql_rcode_t sql_fetch_row(rlm_sql_row_t *out, rlm_sql_handle_t *handle, rlm_sql_config_t *config)

Definition at line 941 of file rlm_sql_cassandra.c.

CONF_PARSER tls_config[]
static
Initial value:
= {
{ FR_CONF_OFFSET("certificate_file", PW_TYPE_FILE_INPUT, rlm_sql_cassandra_config_t, tls_certificate_file) },
{ FR_CONF_OFFSET("private_key_file", PW_TYPE_FILE_INPUT, rlm_sql_cassandra_config_t, tls_private_key_file) },
{ FR_CONF_OFFSET("private_key_password", PW_TYPE_STRING | PW_TYPE_SECRET, rlm_sql_cassandra_config_t, tls_private_key_password) },
{ FR_CONF_OFFSET("verify_cert", PW_TYPE_STRING, rlm_sql_cassandra_config_t, tls_verify_cert_str) },
}
#define PW_TYPE_FILE_INPUT
File matching value must exist, and must be readable.
Definition: conffile.h:204
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
#define PW_TYPE_SECRET
Only print value if debug level >= 3.
Definition: conffile.h:202
Cassandra driver instance.
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
String of printable characters.
Definition: radius.h:33

Definition at line 203 of file rlm_sql_cassandra.c.

const FR_NAME_NUMBER verify_cert_table[]
static
Initial value:
= {
{ "no", CASS_SSL_VERIFY_NONE },
{ "yes", CASS_SSL_VERIFY_PEER_CERT },
{ "identity", CASS_SSL_VERIFY_PEER_IDENTITY },
{ NULL, 0 }
}

Definition at line 182 of file rlm_sql_cassandra.c.