GCS
0.2.3
|
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <assert.h>
#include <galerautils.h>
#include "gcs_priv.h"
#include "gcs_params.h"
#include "gcs_fc.h"
#include "gcs_seqno.h"
#include "gcs_core.h"
#include "gcs_fifo_lite.h"
#include "gcs_sm.h"
#include "gcs_gcache.h"
Data Structures | |
struct | gcs_fc_event |
struct | gcs_conn |
struct | gcs_recv_act |
struct | gcs_repl_act |
Macros | |
#define | GCS_CLOSED_ERROR -EBADFD; |
Functions | |
const char * | gcs_node_state_to_str (gcs_node_state_t state) |
const char * | gcs_act_type_to_str (gcs_act_type_t type) |
struct gcs_fc_event | __attribute__ ((__packed__)) |
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. More... | |
long | gcs_init (gcs_conn_t *conn, gcs_seqno_t seqno, const uint8_t uuid[GU_UUID_LEN]) |
long | gcs_open (gcs_conn_t *conn, const char *channel, const char *url, bool const bootstrap) |
Opens connection to group (joins channel). More... | |
long | gcs_close (gcs_conn_t *conn) |
Closes connection to group. More... | |
long | gcs_destroy (gcs_conn_t *conn) |
Frees resources associuated with connection handle. More... | |
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 through gcs_recv() call, or discarded in case it is not delivered by group. For a better means to replicate an action see gcs_repl(). More... | |
long | gcs_schedule (gcs_conn_t *conn) |
Schedules entry to CGS send monitor. Locks send monitor and should be quickly followed by gcs_repl()/gcs_send() More... | |
long | gcs_interrupt (gcs_conn_t *conn, long handle) |
Interrupt a thread waiting to enter send monitor. More... | |
gcs_seqno_t | gcs_caused (gcs_conn_t *conn) |
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 received. Upon return global and local IDs are set. Arguments are the same as in gcs_recv(). More... | |
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 suitable group members. More... | |
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 node keeps on receiving all the actions). Requires gcs_join() to return to normal. More... | |
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 and must be freed by application when action is no longer needed. Also sets global and local action IDs. Global action ID uniquely identifies action in the history of the group and can be used to identify the state of the application for state snapshot purposes. Local action ID is a monotonic gapless number sequence starting with 1 which can be used to serialize access to critical sections. More... | |
long | gcs_resume_recv (gcs_conn_t *conn) |
long | gcs_wait (gcs_conn_t *conn) |
Deprecated. Waits until the group catches up. This call checks if any member of the group (including this one) has a long slave queue. Should be called before gcs_repl(), gcs_send(). More... | |
long | gcs_conf_set_pkt_size (gcs_conn_t *conn, long pkt_size) |
long | gcs_set_last_applied (gcs_conn_t *conn, gcs_seqno_t seqno) |
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. More... | |
gcs_seqno_t | gcs_local_sequence (gcs_conn_t *conn) |
Allocate local seqno for accessing local resources. More... | |
void | gcs_get_stats (gcs_conn_t *conn, struct gcs_stats *stats) |
void | gcs_flush_stats (gcs_conn_t *conn) |
void | gcs_register_params (gu_config_t *const conf) |
long | gcs_param_set (gcs_conn_t *conn, const char *key, const char *value) |
const char * | gcs_param_get (gcs_conn_t *conn, const char *key) |
Variables | |
uint32_t | conf_id |
uint32_t | stop |
struct gcs_conn | __attribute__ |
Public GCS API
const char* gcs_act_type_to_str | ( | gcs_act_type_t | ) |
String representations of action types
Referenced by gcs_replv().
gcs_seqno_t gcs_caused | ( | gcs_conn_t * | conn | ) |
After action with this seqno is applied, this thread is guaranteed to see all the changes made by the client, even on other nodes.
long gcs_close | ( | gcs_conn_t * | conn | ) |
Closes connection to group.
conn | connection handle |
Referenced by gcs_recv(), and gcs_resume_recv().
gcs_conn_t* gcs_create | ( | gu_config_t * | conf, |
gcache_t * | cache, | ||
const char * | node_name, | ||
const char * | inc_addr, | ||
int | repl_proto_ver, | ||
int | appl_proto_ver | ||
) |
Creates GCS connection handle.
conf | gu_config_t* configuration object, can be null. |
cache | pointer to the gcache object. |
node_name | human readable name of the node, can be null. |
inc_addr | address at which application accepts incoming requests. Used for load balancing, can be null. |
repl_proto_ver | max replicator protocol version. |
appl_proto_ver | max application ptotocol version. |
long gcs_destroy | ( | gcs_conn_t * | conn | ) |
Frees resources associuated with connection handle.
conn | connection handle |
long gcs_desync | ( | gcs_conn_t * | conn, |
gcs_seqno_t * | seqno | ||
) |
Turns off flow control on the node. Effectively desynchronizes the node from the cluster (while the node keeps on receiving all the actions). Requires gcs_join() to return to normal.
conn | connection to group |
seqno | response to request was ordered with this seqno. Must be skipped in local queues. |
References gcs_request_state_transfer().
void gcs_flush_stats | ( | gcs_conn_t * | conn | ) |
flushes stats counters
void gcs_get_stats | ( | gcs_conn_t * | conn, |
struct gcs_stats * | stats | ||
) |
Fills stats struct
References gcs_stats::fc_paused_avg, gcs_stats::fc_paused_ns, gcs_stats::fc_received, gcs_stats::fc_sent, gcs_stats::recv_q_len, gcs_stats::recv_q_len_avg, gcs_stats::recv_q_size, and gcs_stats::send_q_len.
long gcs_interrupt | ( | gcs_conn_t * | conn, |
long | handle | ||
) |
Interrupt a thread waiting to enter send monitor.
conn | GCS connection |
handle | queue handle returned by gcs_schedule(). Must be > 0 |
0 | success |
-ESRCH | no such thread/already interrupted |
long gcs_join | ( | gcs_conn_t * | conn, |
gcs_seqno_t | status | ||
) |
Informs group on behalf of donor that state stransfer is over. If status is non-negative, joiner will be considered fully joined to group.
conn | opened connection to group |
status | negative error code in case of state transfer failure, 0 or (optional) seqno corresponding to transferred state. |
gcs_seqno_t gcs_local_sequence | ( | gcs_conn_t * | conn | ) |
Allocate local seqno for accessing local resources.
conn | connection to group |
const char* gcs_node_state_to_str | ( | gcs_node_state_t | state | ) |
Convert state code to null-terminates string
long gcs_open | ( | gcs_conn_t * | conn, |
const char * | channel, | ||
const char * | url, | ||
bool | bootstrap | ||
) |
Opens connection to group (joins channel).
conn | connection object |
channel | a name of the channel to join. It must uniquely identify the channel. If the channel with such name does not exist, it is created. Processes that joined the same channel receive the same actions. |
url | an URL-like string that specifies backend communication driver in the form "TYPE://ADDRESS?options". For gcomm backend it can be "gcomm://localhost:4567", for dummy backend ADDRESS field is ignored. Currently supported backend types: "dummy", "vsbes", "gcomm" |
bootstrap | bootstrap a new group |
const char* gcs_param_get | ( | gcs_conn_t * | conn, |
const char * | key | ||
) |
returns the value of the key
long gcs_param_set | ( | gcs_conn_t * | conn, |
const char * | key, | ||
const char * | value | ||
) |
sets the key to a given value
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 and must be freed by application when action is no longer needed. Also sets global and local action IDs. Global action ID uniquely identifies action in the history of the group and can be used to identify the state of the application for state snapshot purposes. Local action ID is a monotonic gapless number sequence starting with 1 which can be used to serialize access to critical sections.
conn | group connection handle |
action | action object |
0 | on connection close |
References gcs_close(), and gcs_action::size.
void gcs_register_params | ( | gu_config_t * | conf | ) |
Registers configurable parameters with conf object
long gcs_replv | ( | gcs_conn_t * | conn, |
const struct gu_buf * | act_in, | ||
struct gcs_action * | action, | ||
bool | scheduled | ||
) |
Replicates a vector of buffers as a single action. Sends action to group and blocks until it is received. Upon return global and local IDs are set. Arguments are the same as in gcs_recv().
conn | group connection handle |
act_in | action buffer vector (total size is passed in action) |
action | action struct |
scheduled | whether the call was preceded by gcs_schedule() |
-EINTR | thread was interrupted while waiting to enter the monitor |
conn | in |
act_in | in |
act | inout |
scheduled | in |
References gcs_act_type_to_str(), and gcs_action::size.
long gcs_request_state_transfer | ( | gcs_conn_t * | conn, |
const void * | req, | ||
size_t | size, | ||
const char * | donor, | ||
gcs_seqno_t * | seqno | ||
) |
Sends state transfer request Broadcasts state transfer request which will be passed to one of the suitable group members.
conn | connection to group |
req | opaque byte array that contains data required for the state transfer (application dependent) |
size | request size |
donor | desired state transfer donor name. Supply empty string to choose automatically. |
seqno | response to request was ordered with this seqno. Must be skipped in local queues. |
Referenced by gcs_desync().
long gcs_resume_recv | ( | gcs_conn_t * | conn | ) |
Resume receivng from group.
conn | GCS connection |
0 | success |
-EBADFD | connection is in closed state |
References gcs_close().
long gcs_schedule | ( | gcs_conn_t * | conn | ) |
Schedules entry to CGS send monitor. Locks send monitor and should be quickly followed by gcs_repl()/gcs_send()
0 | - won't queue |
>0 | - queue handle |
-EAGAIN | - too many queued threads |
-EBADFD | - connection is closed |
long gcs_sendv | ( | gcs_conn_t * | conn, |
const struct gu_buf * | act_bufs, | ||
size_t | act_size, | ||
gcs_act_type_t | act_type, | ||
bool | scheduled | ||
) |
Sends a vector of buffers as a single action to group and returns. A copy of action will be returned through gcs_recv() call, or discarded in case it is not delivered by group. For a better means to replicate an action see gcs_repl().
conn | group connection handle |
act_bufs | action buffer vector |
act_size | total action size (the sum of buffer sizes) |
act_type | action type |
scheduled | whether the call was scheduled by gcs_schedule() |
-EINTR | thread was interrupted while waiting to enter the monitor |
locking connection here to avoid race with gcs_close()
long gcs_set_last_applied | ( | gcs_conn_t * | conn, |
gcs_seqno_t | seqno | ||
) |
Informs group about the last applied action on this node
long gcs_wait | ( | gcs_conn_t * | conn | ) |
Deprecated. Waits until the group catches up. This call checks if any member of the group (including this one) has a long slave queue. Should be called before gcs_repl(), gcs_send().