GCS  0.2.3
Data Structures | Macros | Enumerations | Functions | Variables
gcs.c File Reference
#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;
 

Enumerations

enum  gcs_conn_state_t {
  GCS_CONN_SYNCED, GCS_CONN_JOINED, GCS_CONN_DONOR, GCS_CONN_JOINER,
  GCS_CONN_PRIMARY, GCS_CONN_OPEN, GCS_CONN_CLOSED, GCS_CONN_DESTROYED,
  GCS_CONN_ERROR, GCS_CONN_STATE_MAX
}
 

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_tgcs_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__
 

Detailed Description

Public GCS API

Function Documentation

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.

Returns
global sequence number or negative error code
long gcs_close ( gcs_conn_t conn)

Closes connection to group.

Parameters
connconnection handle
Returns
negative error code or 0 in case of success.

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.

Parameters
confgu_config_t* configuration object, can be null.
cachepointer to the gcache object.
node_namehuman readable name of the node, can be null.
inc_addraddress at which application accepts incoming requests. Used for load balancing, can be null.
repl_proto_vermax replicator protocol version.
appl_proto_vermax application ptotocol version.
Returns
pointer to GCS connection handle, NULL in case of failure.
long gcs_destroy ( gcs_conn_t conn)

Frees resources associuated with connection handle.

Parameters
connconnection handle
Returns
negative error code or 0 in case of success.
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.

Parameters
connconnection to group
seqnoresponse to request was ordered with this seqno. Must be skipped in local queues.
Returns
negative error code, 0 in case of success.

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 
)
long gcs_interrupt ( gcs_conn_t conn,
long  handle 
)

Interrupt a thread waiting to enter send monitor.

Parameters
connGCS connection
handlequeue handle returned by gcs_schedule(). Must be > 0
Return values
0success
-ESRCHno 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.

Parameters
connopened connection to group
statusnegative error code in case of state transfer failure, 0 or (optional) seqno corresponding to transferred state.
Returns
negative error code, 0 in case of success
gcs_seqno_t gcs_local_sequence ( gcs_conn_t conn)

Allocate local seqno for accessing local resources.

Parameters
connconnection to group
Returns
local seqno, negative error code in case of error
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).

Parameters
connconnection object
channela 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.
urlan 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"
bootstrapbootstrap a new group
Returns
negative error code, 0 in case of success.
const char* gcs_param_get ( gcs_conn_t conn,
const char *  key 
)

returns the value of the key

Returns
NULL if key not found
long gcs_param_set ( gcs_conn_t conn,
const char *  key,
const char *  value 
)

sets the key to a given value

Returns
0 in case of success, 1 if key not found or negative error code
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.

Parameters
conngroup connection handle
actionaction object
Returns
negative error code, action size in case of success,
Return values
0on 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().

See also
gcs_recv()
Parameters
conngroup connection handle
act_inaction buffer vector (total size is passed in action)
actionaction struct
scheduledwhether the call was preceded by gcs_schedule()
Returns
negative error code, action size in case of success
Return values
-EINTRthread was interrupted while waiting to enter the monitor
Parameters
connin
act_inin
actinout
scheduledin

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.

Parameters
connconnection to group
reqopaque byte array that contains data required for the state transfer (application dependent)
sizerequest size
donordesired state transfer donor name. Supply empty string to choose automatically.
seqnoresponse to request was ordered with this seqno. Must be skipped in local queues.
Returns
negative error code, index of state transfer donor in case of success (notably, -EAGAIN means try later, -EHOSTUNREACH means desired donor is unavailable)

Referenced by gcs_desync().

long gcs_resume_recv ( gcs_conn_t conn)

Resume receivng from group.

Parameters
connGCS connection
Return values
0success
-EBADFDconnection 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()

Return values
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().

See also
gcs_repl()
Parameters
conngroup connection handle
act_bufsaction buffer vector
act_sizetotal action size (the sum of buffer sizes)
act_typeaction type
scheduledwhether the call was scheduled by gcs_schedule()
Returns
negative error code, action size in case of success
Return values
-EINTRthread was interrupted while waiting to enter the monitor

locking connection here to avoid race with gcs_close()

Note
: gcs_repl() and gcs_recv() cannot lock connection because they block indefinitely waiting for actions
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().

Returns
negative error code, 1 if wait is required, 0 otherwise