All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cluster.h
Go to the documentation of this file.
1 /*
2  * This program is is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or (at
5  * your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /**
18  * $Id: 6455947cb2d7987e776342f2dac7e535f0580a20 $
19  * @file cluster.h
20  * @brief Common functions for interacting with Redis cluster via Hiredis
21  *
22  * @author Arran Cudbard-Bell
23  *
24  * @copyright 2015 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
25  * @copyright 2015 Network RADIUS <info@networkradius.com>
26  * @copyright 2015 The FreeRADIUS server project
27  */
28 
29 #ifndef LIBFREERADIUS_REDIS_CLUSTER_H
30 #define LIBFREERADIUS_REDIS_CLUSTER_H
31 
32 RCSIDH(cluster_h, "$Id: 6455947cb2d7987e776342f2dac7e535f0580a20 $")
33 
35 
36 /** Redis connection sequence state
37  *
38  * Tracks how many operations we've performed attempting to execute a single command.
39  *
40  * Used by callers of the cluster code. Allocated on the stack and passed to
41  * #fr_redis_cluster_state_init and #fr_redis_cluster_state_next.
42  */
43 typedef struct fr_redis_cluster_state {
44  bool close_conn; //!< Set by caller of fr_redis_cluster_state_next,
45  //!< to indicate that connection must be closed, as it's
46  //!< now in an unknown state.
47 
48  uint8_t const *key; //!< Key we performed hashing on.
49  size_t key_len; //!< Length of the key.
50 
51  struct fr_redis_cluster_node *node; //!< Node we're communicating with.
52  uint32_t redirects; //!< How many redirects have we followed.
53 
54  uint32_t retries; //!< How many time's we've received TRYAGAIN
55  uint32_t in_pool; //!< How many available connections are there in the pool.
56  uint32_t reconnects; //!< How many connections we've tried in this pool.
58 
59 /*
60  * Callback for the connection pool to create a new connection
61  */
62 void *fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout);
63 
64 /*
65  * Reserve/release connections, follow redirects, reconnect
66  * connections implement retry delays.
67  */
69  fr_redis_cluster_t *cluster, REQUEST *request,
70  uint8_t const *key, size_t key_len, bool read_only);
71 
73  fr_redis_cluster_t *cluster, REQUEST *request,
74  fr_redis_rcode_t status, redisReply **reply);
75 
76 /*
77  * Testing only
78  */
80  fr_ipaddr_t *ipaddr, uint16_t port, bool create);
81 
82 /*
83  * Initialise a new cluster connection, and perform initial mapping.
84  */
85 bool fr_redis_cluster_min_version(fr_redis_cluster_t *cluster, char const *min_version);
86 
88 
89 #endif /* LIBFREERADIUS_REDIS_CLUSTER_H */
int fr_redis_cluster_pool_by_node_addr(fr_connection_pool_t **pool, fr_redis_cluster_t *cluster, fr_ipaddr_t *ipaddr, uint16_t port, bool create)
Get the pool associated with a node in the cluster.
Definition: cluster.c:1919
#define RCSIDH(h, id)
Definition: build.h:136
A Redis cluster node.
Definition: cluster.c:223
Configuration parameters for a redis connection.
Definition: redis.h:88
uint32_t reconnects
How many connections we've tried in this pool.
Definition: cluster.h:56
bool close_conn
Set by caller of fr_redis_cluster_state_next, to indicate that connection must be closed...
Definition: cluster.h:44
fr_connection_pool_t * pool
Pool associated with this node.
Definition: cluster.c:235
uint8_t const * key
Key we performed hashing on.
Definition: cluster.h:48
static float timeout
Definition: radclient.c:43
bool fr_redis_cluster_min_version(fr_redis_cluster_t *cluster, char const *min_version)
Check if members of the cluster are above a certain version.
Definition: cluster.c:2031
A redis cluster.
Definition: cluster.c:254
void * fr_redis_cluster_conn_create(TALLOC_CTX *ctx, void *instance, struct timeval const *timeout)
Create a new connection to a Redis node.
Definition: cluster.c:1415
uint32_t redirects
How many redirects have we followed.
Definition: cluster.h:52
struct fr_redis_cluster_node * node
Node we're communicating with.
Definition: cluster.h:51
fr_redis_rcode_t fr_redis_cluster_state_init(fr_redis_cluster_state_t *state, fr_redis_conn_t **conn, fr_redis_cluster_t *cluster, REQUEST *request, uint8_t const *key, size_t key_len, bool read_only)
Resolve a key to a pool, and reserve a connection in that pool.
Definition: cluster.c:1594
Redis connection sequence state.
Definition: cluster.h:43
static rs_t * conf
Definition: radsniff.c:46
size_t key_len
Length of the key.
Definition: cluster.h:49
fr_redis_rcode_t fr_redis_cluster_state_next(fr_redis_cluster_state_t *state, fr_redis_conn_t **conn, fr_redis_cluster_t *cluster, REQUEST *request, fr_redis_rcode_t status, redisReply **reply)
Get the next connection to attempt a command against.
Definition: cluster.c:1714
struct fr_redis_cluster_state fr_redis_cluster_state_t
Redis connection sequence state.
unsigned int state
Definition: proto_bfd.c:200
fr_redis_cluster_t * fr_redis_cluster_alloc(TALLOC_CTX *ctx, CONF_SECTION *cs, fr_redis_conf_t *conf)
Allocate and initialise a new cluster structure.
Definition: cluster.c:2059
uint32_t in_pool
How many available connections are there in the pool.
Definition: cluster.h:55
A connection pool.
Definition: connection.c:85
fr_redis_rcode_t
Codes are ordered inversely by priority.
Definition: redis.h:67
uint32_t retries
How many time's we've received TRYAGAIN.
Definition: cluster.h:54
IPv4/6 prefix.
Definition: inet.h:41
Connection handle, holding a redis context.
Definition: redis.h:80