GCS  0.2.3
gcs_state_msg.h
1 /*
2  * Copyright (C) 2008-2013 Codership Oy <info@codership.com>
3  *
4  * $Id: gcs_state_msg.h 3277 2013-09-10 17:43:22Z alex $
5  */
6 /*
7  * Interface to state messages
8  *
9  */
10 
11 #ifndef _gcs_state_msg_h_
12 #define _gcs_state_msg_h_
13 
14 #include "gcs.h"
15 #include "gcs_seqno.h"
16 #include "gcs_act_proto.h"
17 
18 #include <unistd.h>
19 #include <stdbool.h>
20 
21 /* State flags */
22 #define GCS_STATE_FREP 0x01 // group representative
23 #define GCS_STATE_FCLA 0x02 // count last applied (for JOINED node)
24 #define GCS_STATE_FBOOTSTRAP 0x04 // part of prim bootstrap process
25 #define GCS_STATE_ARBITRATOR 0x08 // arbitrator or otherwise incomplete node
26 
27 #ifdef GCS_STATE_MSG_ACCESS
28 typedef struct gcs_state_msg
29 {
30  gu_uuid_t state_uuid; // UUID of the current state exchange
31  gu_uuid_t group_uuid; // UUID of the group
32  gu_uuid_t prim_uuid; // last PC state UUID
33  gcs_seqno_t prim_seqno; // last PC state seqno
34  gcs_seqno_t received; // last action seqno (received up to)
35  gcs_seqno_t cached; // earliest action cached
36  const char* name; // human assigned node name
37  const char* inc_addr; // incoming address string
38  int version; // version of state message
39  int gcs_proto_ver;
40  int repl_proto_ver;
41  int appl_proto_ver;
42  int prim_joined; // number of joined nodes in its last PC
43  gcs_node_state_t prim_state; // state of the node in its last PC
44  gcs_node_state_t current_state; // current state of the node
45  uint8_t flags;
46 }
47 gcs_state_msg_t;
48 #else
49 typedef struct gcs_state_msg gcs_state_msg_t;
50 #endif
51 
53 typedef struct gcs_state_quorum
54 {
55  gu_uuid_t group_uuid;
56  gcs_seqno_t act_id;
57  gcs_seqno_t conf_id;
58  bool primary;
59  int version;
61  int repl_proto_ver;
62  int appl_proto_ver;
63 }
65 
66 #define GCS_QUORUM_NON_PRIMARY (gcs_state_quorum_t){ \
67  GU_UUID_NIL, \
68  GCS_SEQNO_ILL, \
69  GCS_SEQNO_ILL, \
70  false, \
71  -1, -1, -1, -1 \
72  }
73 
74 extern gcs_state_msg_t*
75 gcs_state_msg_create (const gu_uuid_t* state_uuid,
76  const gu_uuid_t* group_uuid,
77  const gu_uuid_t* prim_uuid,
78  gcs_seqno_t prim_seqno,
79  gcs_seqno_t received,
80  gcs_seqno_t cached,
81  int prim_joined,
82  gcs_node_state_t prim_state,
83  gcs_node_state_t current_state,
84  const char* name,
85  const char* inc_addr,
86  int gcs_proto_ver,
87  int repl_proto_ver,
88  int appl_proto_ver,
89  uint8_t flags);
90 
91 extern void
92 gcs_state_msg_destroy (gcs_state_msg_t* state);
93 
94 /* Returns length needed to serialize gcs_state_msg_t for sending */
95 extern size_t
96 gcs_state_msg_len (gcs_state_msg_t* state);
97 
98 /* Serialize gcs_state_msg_t into message */
99 extern ssize_t
100 gcs_state_msg_write (void* msg, const gcs_state_msg_t* state);
101 
102 /* De-serialize gcs_state_msg_t from message */
103 extern gcs_state_msg_t*
104 gcs_state_msg_read (const void* msg, ssize_t msg_len);
105 
106 /* Get state uuid */
107 extern const gu_uuid_t*
108 gcs_state_msg_uuid (const gcs_state_msg_t* state);
109 
110 /* Get group uuid */
111 extern const gu_uuid_t*
112 gcs_state_msg_group_uuid (const gcs_state_msg_t* state);
113 
114 /* Get last PC uuid */
115 //extern const gu_uuid_t*
116 //gcs_state_prim_uuid (const gcs_state_msg_t* state);
117 
118 /* Get last received action seqno */
119 extern gcs_seqno_t
120 gcs_state_msg_received (const gcs_state_msg_t* state);
121 
122 /* Get last received action seqno */
123 extern gcs_seqno_t
124 gcs_state_msg_cached (const gcs_state_msg_t* state);
125 
126 /* Get current node state */
127 extern gcs_node_state_t
128 gcs_state_msg_current_state (const gcs_state_msg_t* state);
129 
130 /* Get last prim node state */
131 extern gcs_node_state_t
132 gcs_state_msg_prim_state (const gcs_state_msg_t* state);
133 
134 /* Get node name */
135 extern const char*
136 gcs_state_msg_name (const gcs_state_msg_t* state);
137 
138 /* Get node incoming address */
139 extern const char*
140 gcs_state_msg_inc_addr (const gcs_state_msg_t* state);
141 
142 /* Get supported protocols */
143 extern void
144 gcs_state_msg_get_proto_ver (const gcs_state_msg_t* state,
145  int* gcs_proto_ver,
146  int* repl_proto_ver,
147  int* appl_proto_ver);
148 
149 /* Get state message flags */
150 extern uint8_t
151 gcs_state_msg_flags (const gcs_state_msg_t* state);
152 
160 extern long
161 gcs_state_msg_get_quorum (const gcs_state_msg_t* states[],
162  long states_num,
163  gcs_state_quorum_t* quorum);
164 
165 /* Print state message contents to buffer */
166 extern int
167 gcs_state_msg_snprintf (char* str, size_t size, const gcs_state_msg_t* msg);
168 
169 #endif /* _gcs_state_msg_h_ */
int gcs_proto_ver
state excahnge version (max understood by all)
Definition: gcs_state_msg.h:60
int version
primary configuration or not
Definition: gcs_state_msg.h:59
bool primary
configuration id
Definition: gcs_state_msg.h:58
gcs_seqno_t conf_id
next global seqno
Definition: gcs_state_msg.h:57
gcs_seqno_t act_id
group UUID
Definition: gcs_state_msg.h:56
Definition: gcs_state_msg.h:53