GCS  0.2.3
gcs_node.h
1 /*
2  * Copyright (C) 2008-2013 Codership Oy <info@codership.com>
3  *
4  * $Id: gcs_node.h 3277 2013-09-10 17:43:22Z alex $
5  */
6 
11 #ifndef _gcs_node_h_
12 #define _gcs_node_h_
13 
14 #include <errno.h>
15 
16 #include "gcs.h"
17 #include "gcs_defrag.h"
18 #include "gcs_comp_msg.h"
19 #include "gcs_state_msg.h"
20 
21 #include <gcache.h>
22 
23 #define NODE_NO_ID "undefined"
24 #define NODE_NO_NAME "unspecified"
25 #define NODE_NO_ADDR "unspecified"
26 
27 struct gcs_node
28 {
29  gcs_defrag_t app; // defragmenter for application actions
30  gcs_defrag_t oob; // defragmenter for out-of-band service acts.
31 
32  // globally unique id from a component message
33  const char id[GCS_COMP_MEMB_ID_MAX_LEN + 1];
34 
35  // to track snapshot status
36  char joiner[GCS_COMP_MEMB_ID_MAX_LEN + 1];
37  char donor [GCS_COMP_MEMB_ID_MAX_LEN + 1];
38 
39  const char* name; // human-given name
40  const char* inc_addr; // incoming address - for load balancer
41  const gcs_state_msg_t* state_msg;// state message
42 
43  gcs_seqno_t last_applied; // last applied action on that node
44  int gcs_proto_ver;// supported protocol versions
45  int repl_proto_ver;
46  int appl_proto_ver;
47  gcs_node_state_t status; // node status
48  gcs_segment_t segment;
49  bool count_last_applied; // should it be counted
50  bool bootstrap; // is part of prim comp bootstrap process
51 };
52 typedef struct gcs_node gcs_node_t;
53 
55 extern void
56 gcs_node_init (gcs_node_t* node,
57  gcache_t* gcache,
58  const char* id,
59  const char* name,
60  const char* inc_addr,
61  int gcs_proto_ver,
62  int repl_proto_ver,
63  int appl_proto_ver,
64  gcs_segment_t segment);
65 
67 extern void
68 gcs_node_move (gcs_node_t* dest, gcs_node_t* src);
69 
71 extern void
72 gcs_node_free (gcs_node_t* node);
73 
75 extern void
76 gcs_node_reset (gcs_node_t* node);
77 
79 extern void
80 gcs_node_reset_local (gcs_node_t* node);
81 
87 static inline ssize_t
88 gcs_node_handle_act_frag (gcs_node_t* node,
89  const gcs_act_frag_t* frg,
90  struct gcs_act* act,
91  bool local)
92 {
93  if (gu_likely(GCS_ACT_SERVICE != frg->act_type)) {
94  return gcs_defrag_handle_frag (&node->app, frg, act, local);
95  }
96  else if (GCS_ACT_SERVICE == frg->act_type) {
97  return gcs_defrag_handle_frag (&node->oob, frg, act, local);
98  }
99  else {
100  gu_warn ("Unrecognised action type: %d", frg->act_type);
101  assert(0);
102  return -EPROTO;
103  }
104 }
105 
106 static inline void
107 gcs_node_set_last_applied (gcs_node_t* node, gcs_seqno_t seqno)
108 {
109  if (gu_unlikely(seqno < node->last_applied)) {
110  gu_warn ("Received bogus LAST message: %lld, from node %s, "
111  "expected >= %lld. Ignoring.",
112  seqno, node->id, node->last_applied);
113  } else {
114  node->last_applied = seqno;
115  }
116 }
117 
118 static inline gcs_seqno_t
119 gcs_node_get_last_applied (gcs_node_t* node)
120 {
121  return node->last_applied;
122 }
123 
125 extern void
126 gcs_node_record_state (gcs_node_t* node, gcs_state_msg_t* state);
127 
129 extern void
130 gcs_node_update_status (gcs_node_t* node, const gcs_state_quorum_t* quorum);
131 
132 static inline gcs_node_state_t
133 gcs_node_get_status (const gcs_node_t* node)
134 {
135  return node->status;
136 }
137 
138 static inline gcs_seqno_t
139 gcs_node_cached (const gcs_node_t* node)
140 {
141  /* node->state_msg check is needed in NON-PRIM situations, where no
142  * state message exchange happens */
143  if (node->state_msg)
144  return gcs_state_msg_cached(node->state_msg);
145  else
146  return GCS_SEQNO_ILL;
147 }
148 
149 static inline uint8_t
150 gcs_node_flags (const gcs_node_t* node)
151 {
152  return gcs_state_msg_flags(node->state_msg);
153 }
154 
155 static inline bool
156 gcs_node_is_joined (const gcs_node_state_t st)
157 {
158  return (st >= GCS_NODE_STATE_DONOR);
159 }
160 
161 #endif /* _gcs_node_h_ */
Definition: gcs_node.h:27
Definition: gcs_defrag.h:25
Definition: gcs_act_proto.h:24
Definition: gcs_act.h:12
Definition: gcs_state_msg.h:53