GCS  0.2.3
gcs.h
1 /*
2  * Copyright (C) 2008-2014 Codership Oy <info@codership.com>
3  *
4  * $Id: gcs.h 3455 2014-02-01 18:11:09Z alex $
5  */
6 
11 #ifndef _gcs_h_
12 #define _gcs_h_
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include <stdint.h>
19 #include <stdbool.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 
23 #include "gu_config.h"
24 #include "gu_buf.h"
25 #include "gcache.h"
26 #include "gu_errno.h"
27 
29 typedef int64_t gcs_seqno_t;
30 
32 static const gcs_seqno_t GCS_SEQNO_ILL = -1;
34 static const gcs_seqno_t GCS_SEQNO_NIL = 0;
36 static const gcs_seqno_t GCS_SEQNO_FIRST = 1;
38 #define GCS_UUID_LEN 16
39 
40 #define GCS_MAX_ACT_SIZE 0x7FFFFFFF
41 
43 typedef struct gcs_conn gcs_conn_t;
44 
56 extern gcs_conn_t*
57 gcs_create (gu_config_t* conf, gcache_t* cache,
58  const char* node_name, const char* inc_addr,
59  int repl_proto_ver, int appl_proto_ver);
60 
78 extern long gcs_init (gcs_conn_t *conn,
79  gcs_seqno_t seqno,
80  const uint8_t uuid[GCS_UUID_LEN]);
81 
98 extern long gcs_open (gcs_conn_t *conn,
99  const char *channel,
100  const char *url,
101  bool bootstrap);
102 
108 extern long gcs_close (gcs_conn_t *conn);
109 
115 extern long gcs_destroy (gcs_conn_t *conn);
116 
123 extern long gcs_wait (gcs_conn_t *conn);
124 
146 typedef enum gcs_act_type
147 {
148 /* ordered actions */
149  GCS_ACT_TORDERED,
150  // global seqno
151  GCS_ACT_COMMIT_CUT,
152  GCS_ACT_STATE_REQ,
153  GCS_ACT_CONF,
154  GCS_ACT_JOIN,
155  GCS_ACT_SYNC,
156  GCS_ACT_FLOW,
157  GCS_ACT_SERVICE,
158  GCS_ACT_ERROR,
159  GCS_ACT_UNKNOWN
160 }
161 gcs_act_type_t;
162 
164 extern const char* gcs_act_type_to_str(gcs_act_type_t);
165 
179 extern long gcs_sendv (gcs_conn_t* conn,
180  const struct gu_buf* act_bufs,
181  size_t act_size,
182  gcs_act_type_t act_type,
183  bool scheduled);
184 
186 static inline long gcs_send (gcs_conn_t* const conn,
187  const void* const act,
188  size_t const act_size,
189  gcs_act_type_t const act_type,
190  bool const scheduled)
191 {
192  struct gu_buf const buf = { act, (ssize_t)act_size };
193  return gcs_sendv (conn, &buf, act_size, act_type, scheduled);
194 }
195 
196 
197 struct gcs_action {
198  const void* buf;
199  ssize_t size;
200  gcs_seqno_t seqno_g;
201  gcs_seqno_t seqno_l;
202  gcs_act_type_t type;
203 };
204 
217 extern long gcs_replv (gcs_conn_t* conn,
218  const struct gu_buf* act_in,
219  struct gcs_action* action,
220  bool scheduled);
221 
223 static inline long gcs_repl (gcs_conn_t* const conn,
224  struct gcs_action* const action,
225  bool const scheduled)
226 {
227  struct gu_buf const buf = { action->buf, action->size };
228  return gcs_replv (conn, &buf, action, scheduled);
229 }
230 
245 extern long gcs_recv (gcs_conn_t* conn,
246  struct gcs_action* action);
247 
257 extern long gcs_schedule (gcs_conn_t* conn);
258 
268 extern long gcs_interrupt (gcs_conn_t* conn, long handle);
269 
278 extern long gcs_resume_recv (gcs_conn_t* conn);
279 
286 extern gcs_seqno_t gcs_caused(gcs_conn_t* conn);
287 
304 extern long gcs_request_state_transfer (gcs_conn_t *conn,
305  const void *req,
306  size_t size,
307  const char *donor,
308  gcs_seqno_t *seqno);
309 
319 extern long gcs_desync (gcs_conn_t* conn, gcs_seqno_t* seqno);
320 
329 extern long gcs_join (gcs_conn_t *conn, gcs_seqno_t status);
330 
337 extern gcs_seqno_t gcs_local_sequence(gcs_conn_t* conn);
338 
339 
341 
342 /* Service functions */
343 
345 extern long gcs_set_last_applied (gcs_conn_t* conn, gcs_seqno_t seqno);
346 
347 /* GCS Configuration */
348 
350 extern void
351 gcs_register_params (gu_config_t* conf);
352 
356 extern long
357 gcs_param_set (gcs_conn_t* conn, const char* key, const char *value);
358 
362 extern const char*
363 gcs_param_get (gcs_conn_t* conn, const char* key);
364 
365 /* Logging options */
366 extern long gcs_conf_set_log_file (FILE *file);
367 extern long gcs_conf_set_log_callback (void (*logger) (int, const char*));
368 extern long gcs_conf_self_tstamp_on ();
369 extern long gcs_conf_self_tstamp_off ();
370 extern long gcs_conf_debug_on ();
371 extern long gcs_conf_debug_off ();
372 
373 /* Sending options (deprecated, use gcs_param_set instead) */
374 /* Sets maximum DESIRED network packet size.
375  * For best results should be multiple of MTU */
376 extern long
377 gcs_conf_set_pkt_size (gcs_conn_t *conn, long pkt_size);
378 
379 #define GCS_DEFAULT_PKT_SIZE 64500 /* 43 Eth. frames to carry max IP packet */
380 
381 /*
382  * Configuration action
383  */
384 
386 typedef enum gcs_node_state
387 {
388  GCS_NODE_STATE_NON_PRIM,
389  GCS_NODE_STATE_PRIM,
390  GCS_NODE_STATE_JOINER,
391  GCS_NODE_STATE_DONOR,
392  GCS_NODE_STATE_JOINED,
393  GCS_NODE_STATE_SYNCED,
394  GCS_NODE_STATE_MAX
395 }
396 gcs_node_state_t;
397 
399 extern const char*
400 gcs_node_state_to_str (gcs_node_state_t state);
401 
403 typedef struct gcs_act_conf {
404  gcs_seqno_t seqno;
405  gcs_seqno_t conf_id;
406  uint8_t uuid[GCS_UUID_LEN];
407  long memb_num;
408  long my_idx;
409  gcs_node_state_t my_state;
412  char data[1];
415 
416 struct gcs_stats
417 {
418  double send_q_len_avg;
419  double recv_q_len_avg;
420  long long fc_paused_ns;
421  double fc_paused_avg;
422  long long fc_sent;
423  long long fc_received;
424  size_t recv_q_size;
427 };
428 
430 extern void gcs_get_stats (gcs_conn_t *conn, struct gcs_stats* stats);
432 extern void gcs_flush_stats(gcs_conn_t *conn);
433 
435 #define GCS_ARBITRATOR_NAME "garb"
436 
437 #ifdef __cplusplus
438 }
439 #endif
440 
441 #endif // _gcs_h_
gcs_node_state_t my_state
index of this node in the configuration
Definition: gcs.h:409
long gcs_open(gcs_conn_t *conn, const char *channel, const char *url, bool const bootstrap)
Opens connection to group (joins channel).
Definition: gcs.c:1253
const char * gcs_act_type_to_str(gcs_act_type_t type)
Definition: gcs.c:47
void gcs_register_params(gu_config_t *const conf)
Definition: gcs.c:2046
int recv_q_len
current recv queue size
Definition: gcs.h:425
long long fc_sent
faction of time paused due to flow control
Definition: gcs.h:422
int repl_proto_ver
current node state
Definition: gcs.h:410
long long fc_received
flow control stops sent
Definition: gcs.h:423
long gcs_schedule(gcs_conn_t *conn)
Schedules entry to CGS send monitor. Locks send monitor and should be quickly followed by gcs_repl()/...
Definition: gcs.c:1449
ssize_t size
Definition: gcs.h:199
char data[1]
application protocol version to use
Definition: gcs.h:412
Definition: gcs.c:103
long gcs_wait(gcs_conn_t *conn)
Deprecated. Waits until the group catches up. This call checks if any member of the group (including ...
Definition: gcs.c:1764
long gcs_resume_recv(gcs_conn_t *conn)
Definition: gcs.c:1742
long gcs_recv(gcs_conn_t *conn, struct gcs_action *action)
Receives an action from group. Blocks if no actions are available. Action buffer is allocated by GCS ...
Definition: gcs.c:1666
uint8_t uuid[GCS_UUID_LEN]
configuration ID (-1 if non-primary)
Definition: gcs.h:406
int appl_proto_ver
replicator protocol version to use
Definition: gcs.h:411
const char * gcs_param_get(gcs_conn_t *conn, const char *key)
Definition: gcs.c:2083
long gcs_replv(gcs_conn_t *const conn, const struct gu_buf *const act_in, struct gcs_action *const act, bool const scheduled)
Replicates a vector of buffers as a single action. Sends action to group and blocks until it is recei...
Definition: gcs.c:1465
void gcs_flush_stats(gcs_conn_t *conn)
Definition: gcs.c:1842
double recv_q_len_avg
average send queue length per send call
Definition: gcs.h:419
long gcs_request_state_transfer(gcs_conn_t *conn, const void *req, size_t size, const char *donor, gcs_seqno_t *local)
Sends state transfer request Broadcasts state transfer request which will be passed to one of the sui...
Definition: gcs.c:1588
const char * gcs_node_state_to_str(gcs_node_state_t state)
Definition: gcs.c:29
gcs_seqno_t gcs_caused(gcs_conn_t *conn)
Definition: gcs.c:1459
long gcs_param_set(gcs_conn_t *conn, const char *key, const char *value)
Definition: gcs.c:2052
long gcs_interrupt(gcs_conn_t *conn, long handle)
Interrupt a thread waiting to enter send monitor.
Definition: gcs.c:1454
long gcs_desync(gcs_conn_t *conn, gcs_seqno_t *local)
Turns off flow control on the node. Effectively desynchronizes the node from the cluster (while the n...
Definition: gcs.c:1645
size_t recv_q_size
flow control stops received
Definition: gcs.h:424
long gcs_destroy(gcs_conn_t *conn)
Frees resources associuated with connection handle.
Definition: gcs.c:1362
Definition: gcs.h:403
gcs_seqno_t gcs_local_sequence(gcs_conn_t *conn)
Allocate local seqno for accessing local resources.
Definition: gcs.c:1817
Definition: gcs.h:197
long gcs_set_last_applied(gcs_conn_t *conn, gcs_seqno_t seqno)
Definition: gcs.c:1791
long gcs_join(gcs_conn_t *conn, gcs_seqno_t seqno)
Informs group on behalf of donor that state stransfer is over. If status is non-negative, joiner will be considered fully joined to group.
Definition: gcs.c:1809
void gcs_get_stats(gcs_conn_t *conn, struct gcs_stats *stats)
Definition: gcs.c:1823
long memb_num
group UUID
Definition: gcs.h:407
long my_idx
number of members in configuration
Definition: gcs.h:408
gcs_seqno_t conf_id
last global seqno applied by this group
Definition: gcs.h:405
long gcs_close(gcs_conn_t *conn)
Closes connection to group.
Definition: gcs.c:1310
Definition: gcs.h:416
long long fc_paused_ns
average recv queue length per queued action
Definition: gcs.h:420
int send_q_len
current recv queue length
Definition: gcs.h:426
double fc_paused_avg
total nanoseconds spent in paused state
Definition: gcs.h:421
gcs_conn_t * gcs_create(gu_config_t *const conf, gcache_t *const gcache, const char *const node_name, const char *const inc_addr, int const repl_proto_ver, int const appl_proto_ver)
Creates GCS connection handle.
Definition: gcs.c:220
long gcs_sendv(gcs_conn_t *const conn, const struct gu_buf *const act_bufs, size_t const act_size, gcs_act_type_t const act_type, bool const scheduled)
Sends a vector of buffers as a single action to group and returns. A copy of action will be returned ...
Definition: gcs.c:1421