| 1 |
/* |
| 2 |
* This program is free software; you can redistribute it and/or modify |
| 3 |
* it under the terms of the GNU General Public License as published by |
| 4 |
* the Free Software Foundation; either version 2 of the License, or |
| 5 |
* (at your option) any later version. |
| 6 |
* |
| 7 |
* This program is distributed in the hope that it will be useful, |
| 8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 |
* GNU General Public License for more details. |
| 11 |
* |
| 12 |
* You should have received a copy of the GNU General Public License |
| 13 |
* along with this program; if not, write to the Free Software |
| 14 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <lha_internal.h> |
| 18 |
|
| 19 |
#include "ccm.h" |
| 20 |
#include "ccmmsg.h" |
| 21 |
#include "ccmmisc.h" |
| 22 |
#include <clplumbing/cl_plugin.h> |
| 23 |
#include <clplumbing/cl_quorum.h> |
| 24 |
#include <clplumbing/cl_tiebreaker.h> |
| 25 |
|
| 26 |
#include <clplumbing/cl_signal.h> |
| 27 |
#include <clplumbing/coredumps.h> |
| 28 |
static void dump_sending_msg(struct ha_msg* msg, const char* node); |
| 29 |
|
| 30 |
/* FIXEM dead code alert: unused?? */ |
| 31 |
int |
| 32 |
ccm_send_cluster_msg(ll_cluster_t* hb, struct ha_msg* msg) |
| 33 |
{ |
| 34 |
int rc; |
| 35 |
|
| 36 |
dump_sending_msg(msg, NULL); |
| 37 |
rc = hb->llc_ops->sendclustermsg(hb, msg); |
| 38 |
if (rc != HA_OK){ |
| 39 |
ccm_log(LOG_ERR, "sending out message failed"); |
| 40 |
ccm_message_debug2(LOG_DEBUG, msg); |
| 41 |
return rc; |
| 42 |
} |
| 43 |
|
| 44 |
return HA_OK; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/* FIXEM dead code alert: unused?? */ |
| 49 |
int |
| 50 |
ccm_send_node_msg(ll_cluster_t* hb, |
| 51 |
struct ha_msg* msg, |
| 52 |
const char* node) |
| 53 |
{ |
| 54 |
int rc; |
| 55 |
|
| 56 |
dump_sending_msg(msg, node); |
| 57 |
rc = hb->llc_ops->sendnodemsg(hb, msg, node); |
| 58 |
if (rc != HA_OK){ |
| 59 |
ccm_log(LOG_ERR, "sending out message failed"); |
| 60 |
ccm_message_debug2(LOG_DEBUG, msg); |
| 61 |
return rc; |
| 62 |
} |
| 63 |
|
| 64 |
return HA_OK; |
| 65 |
|
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
static struct ha_msg* |
| 71 |
ccm_create_minimum_msg(ccm_info_t * info, int type) |
| 72 |
{ |
| 73 |
struct ha_msg *m; |
| 74 |
char majortrans[15]; |
| 75 |
snprintf(majortrans, sizeof(majortrans), "%d", |
| 76 |
info->ccm_transition_major); |
| 77 |
|
| 78 |
if ((m=ha_msg_new(0)) == NULL) { |
| 79 |
ccm_log(LOG_ERR, "%s: creating a new message failed", |
| 80 |
__FUNCTION__); |
| 81 |
return NULL; |
| 82 |
} |
| 83 |
|
| 84 |
if( ha_msg_add(m, F_TYPE, ccm_type2string(type)) == HA_FAIL |
| 85 |
||(ha_msg_add(m, CCM_MAJORTRANS, majortrans) == HA_FAIL) |
| 86 |
||ha_msg_add_int(m, F_NUMNODES, info->llm.nodecount) == HA_FAIL){ |
| 87 |
ccm_log(LOG_ERR, "%s: adding fields to an message failed", |
| 88 |
__FUNCTION__); |
| 89 |
ha_msg_del(m); |
| 90 |
return NULL; |
| 91 |
} |
| 92 |
|
| 93 |
return m; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
struct ha_msg* |
| 98 |
ccm_create_msg(ccm_info_t * info, int type) |
| 99 |
{ |
| 100 |
struct ha_msg *m = ccm_create_minimum_msg(info, type); |
| 101 |
char majortrans[15]; |
| 102 |
char minortrans[15]; |
| 103 |
char joinedtrans[15]; |
| 104 |
char *cookie; |
| 105 |
|
| 106 |
if (m == NULL) { |
| 107 |
ccm_log(LOG_ERR, "%s: creating a new message failed", |
| 108 |
__FUNCTION__); |
| 109 |
return NULL; |
| 110 |
} |
| 111 |
|
| 112 |
snprintf(majortrans, sizeof(majortrans), "%d", |
| 113 |
info->ccm_transition_major); |
| 114 |
snprintf(minortrans, sizeof(minortrans), "%d", |
| 115 |
info->ccm_transition_minor); |
| 116 |
snprintf(joinedtrans, sizeof(joinedtrans), "%d", |
| 117 |
info->ccm_joined_transition); |
| 118 |
cookie = info->ccm_cookie; |
| 119 |
assert(cookie && *cookie); |
| 120 |
|
| 121 |
if((ha_msg_add(m, CCM_COOKIE, cookie) == HA_FAIL) |
| 122 |
||(ha_msg_add(m, CCM_MAJORTRANS, majortrans) == HA_FAIL) |
| 123 |
||(ha_msg_add(m, CCM_UPTIME, joinedtrans) == HA_FAIL) |
| 124 |
||(ha_msg_add(m, CCM_MINORTRANS, minortrans) == HA_FAIL)){ |
| 125 |
ccm_log(LOG_ERR, "%s: adding fields to an message failed", |
| 126 |
__FUNCTION__); |
| 127 |
ha_msg_del(m); |
| 128 |
return NULL; |
| 129 |
} |
| 130 |
|
| 131 |
return m; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
static int |
| 136 |
ccm_mod_msg(struct ha_msg* msg, ccm_info_t * info, int type) |
| 137 |
{ |
| 138 |
struct ha_msg *m; |
| 139 |
char majortrans[15]; /* 10 is the maximum number of digits in |
| 140 |
UINT_MAX , adding a buffer of 5 */ |
| 141 |
char minortrans[15]; /* ditto */ |
| 142 |
char joinedtrans[15]; /* ditto */ |
| 143 |
char *cookie; |
| 144 |
llm_info_t* llm = &info->llm; |
| 145 |
|
| 146 |
if (msg == NULL){ |
| 147 |
ccm_log(LOG_ERR, "NULL message"); |
| 148 |
return HA_FAIL; |
| 149 |
} |
| 150 |
|
| 151 |
m = msg; |
| 152 |
|
| 153 |
snprintf(majortrans, sizeof(majortrans), "%d", |
| 154 |
info->ccm_transition_major); |
| 155 |
snprintf(minortrans, sizeof(minortrans), "%d", |
| 156 |
info->ccm_transition_minor); |
| 157 |
snprintf(joinedtrans, sizeof(joinedtrans), "%d", |
| 158 |
info->ccm_joined_transition); |
| 159 |
cookie = info->ccm_cookie; |
| 160 |
|
| 161 |
if (cookie == NULL){ |
| 162 |
abort(); |
| 163 |
} |
| 164 |
|
| 165 |
if(ha_msg_mod(m, F_TYPE, ccm_type2string(type)) == HA_FAIL |
| 166 |
|| ha_msg_mod(m, CCM_COOKIE, cookie) == HA_FAIL |
| 167 |
|| ha_msg_mod(m, CCM_MAJORTRANS, majortrans) == HA_FAIL |
| 168 |
|| ha_msg_mod(m, CCM_UPTIME, joinedtrans) == HA_FAIL |
| 169 |
|| ha_msg_mod(m, CCM_MINORTRANS, minortrans) == HA_FAIL |
| 170 |
|| ha_msg_mod_int(m, F_NUMNODES, llm->nodecount) == HA_FAIL){ |
| 171 |
ccm_log(LOG_ERR, "%s: moding fields to an message failed", |
| 172 |
__FUNCTION__); |
| 173 |
return HA_FAIL; |
| 174 |
} |
| 175 |
|
| 176 |
return HA_OK; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
int |
| 183 |
ccm_send_standard_clustermsg(ll_cluster_t* hb, ccm_info_t* info, int type) |
| 184 |
{ |
| 185 |
struct ha_msg *m = ccm_create_msg(info, type); |
| 186 |
int rc; |
| 187 |
if (m == NULL){ |
| 188 |
ccm_log(LOG_ERR, "creating message failed"); |
| 189 |
return HA_FAIL; |
| 190 |
} |
| 191 |
dump_sending_msg(m, NULL); |
| 192 |
rc = hb->llc_ops->sendclustermsg(hb, m); |
| 193 |
ha_msg_del(m); |
| 194 |
return(rc); |
| 195 |
} |
| 196 |
|
| 197 |
static int |
| 198 |
ccm_send_minimum_clustermsg(ll_cluster_t* hb, ccm_info_t* info, int type) |
| 199 |
{ |
| 200 |
struct ha_msg *m = ccm_create_minimum_msg(info, type); |
| 201 |
int rc; |
| 202 |
|
| 203 |
if (m == NULL) { |
| 204 |
ccm_log(LOG_ERR, "creating a new message failed"); |
| 205 |
return(HA_FAIL); |
| 206 |
} |
| 207 |
|
| 208 |
dump_sending_msg(m, NULL); |
| 209 |
rc = hb->llc_ops->sendclustermsg(hb, m); |
| 210 |
ha_msg_del(m); |
| 211 |
return(rc); |
| 212 |
|
| 213 |
|
| 214 |
} |
| 215 |
|
| 216 |
static int |
| 217 |
ccm_send_extra_clustermsg(ll_cluster_t* hb, ccm_info_t* info, int type, |
| 218 |
const char* fieldname, const char* fieldvalue ) |
| 219 |
{ |
| 220 |
struct ha_msg *m = ccm_create_msg(info, type); |
| 221 |
int rc; |
| 222 |
|
| 223 |
if (fieldname == NULL || fieldvalue == NULL){ |
| 224 |
ccm_log(LOG_ERR, "NULL argument"); |
| 225 |
return HA_FAIL; |
| 226 |
} |
| 227 |
|
| 228 |
if (m == NULL){ |
| 229 |
ccm_log(LOG_ERR, "message creating failed"); |
| 230 |
return HA_FAIL; |
| 231 |
} |
| 232 |
|
| 233 |
if ( ha_msg_add(m, fieldname, fieldvalue) == HA_FAIL){ |
| 234 |
ccm_log(LOG_ERR, "Adding a field failed"); |
| 235 |
ha_msg_del(m); |
| 236 |
return HA_FAIL; |
| 237 |
} |
| 238 |
|
| 239 |
dump_sending_msg(m, NULL); |
| 240 |
rc = hb->llc_ops->sendclustermsg(hb, m); |
| 241 |
ha_msg_del(m); |
| 242 |
return(rc); |
| 243 |
|
| 244 |
} |
| 245 |
|
| 246 |
static int |
| 247 |
ccm_send_extra_nodemsg(ll_cluster_t* hb, ccm_info_t* info, int type, |
| 248 |
const char* fieldname, const char* fieldvalue, |
| 249 |
const char* nodename ) |
| 250 |
{ |
| 251 |
|
| 252 |
struct ha_msg *m = ccm_create_msg(info, type); |
| 253 |
int rc; |
| 254 |
|
| 255 |
if (fieldname == NULL || fieldvalue == NULL){ |
| 256 |
ccm_log(LOG_ERR, "NULL argument"); |
| 257 |
return HA_FAIL; |
| 258 |
} |
| 259 |
|
| 260 |
if (m == NULL){ |
| 261 |
ccm_log(LOG_ERR, "message creating failed"); |
| 262 |
return HA_FAIL; |
| 263 |
} |
| 264 |
|
| 265 |
if ( ha_msg_add(m, fieldname, fieldvalue) == HA_FAIL){ |
| 266 |
ccm_log(LOG_ERR, "Adding a field failed"); |
| 267 |
ha_msg_del(m); |
| 268 |
return HA_FAIL; |
| 269 |
} |
| 270 |
dump_sending_msg(m, nodename); |
| 271 |
rc = hb->llc_ops->sendnodemsg(hb, m, nodename); |
| 272 |
ha_msg_del(m); |
| 273 |
return(rc); |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
int |
| 278 |
ccm_send_protoversion(ll_cluster_t *hb, ccm_info_t *info) |
| 279 |
{ |
| 280 |
return ccm_send_minimum_clustermsg(hb, info, CCM_TYPE_PROTOVERSION); |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
int |
| 285 |
ccm_send_join(ll_cluster_t *hb, ccm_info_t *info) |
| 286 |
{ |
| 287 |
return ccm_send_standard_clustermsg(hb, info, CCM_TYPE_JOIN); |
| 288 |
} |
| 289 |
|
| 290 |
int |
| 291 |
ccm_send_memlist_request(ll_cluster_t *hb, ccm_info_t *info) |
| 292 |
{ |
| 293 |
return ccm_send_standard_clustermsg(hb, info, CCM_TYPE_REQ_MEMLIST); |
| 294 |
} |
| 295 |
|
| 296 |
int |
| 297 |
ccm_send_memlist_res(ll_cluster_t *hb, |
| 298 |
ccm_info_t *info, |
| 299 |
const char *nodename, |
| 300 |
const char *memlist) |
| 301 |
{ |
| 302 |
struct ha_msg *m = ccm_create_msg(info, CCM_TYPE_RES_MEMLIST); |
| 303 |
char maxtrans[15]; |
| 304 |
int rc; |
| 305 |
snprintf(maxtrans, sizeof(maxtrans), "%d", |
| 306 |
info->ccm_max_transition); |
| 307 |
if (!memlist) { |
| 308 |
memlist= ""; |
| 309 |
} |
| 310 |
|
| 311 |
if ( (ha_msg_add(m, CCM_MAXTRANS, maxtrans) == HA_FAIL) |
| 312 |
|| (ha_msg_add(m, CCM_MEMLIST, memlist) == HA_FAIL)) { |
| 313 |
ccm_log(LOG_ERR, "ccm_send_memlist_res: Cannot create " |
| 314 |
"RES_MEMLIST message"); |
| 315 |
rc = HA_FAIL; |
| 316 |
ha_msg_del(m); |
| 317 |
return HA_FAIL; |
| 318 |
} |
| 319 |
|
| 320 |
dump_sending_msg(m, nodename); |
| 321 |
rc = hb->llc_ops->sendnodemsg(hb, m, nodename); |
| 322 |
ha_msg_del(m); |
| 323 |
return(rc); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
int |
| 328 |
ccm_send_final_memlist(ll_cluster_t *hb, |
| 329 |
ccm_info_t *info, |
| 330 |
char *newcookie, |
| 331 |
char *finallist, |
| 332 |
uint32_t max_tran) |
| 333 |
{ |
| 334 |
struct ha_msg *m = ccm_create_msg(info, CCM_TYPE_FINAL_MEMLIST); |
| 335 |
char activeproto[3]; |
| 336 |
char maxtrans[15]; |
| 337 |
int rc; |
| 338 |
|
| 339 |
|
| 340 |
if (m == NULL){ |
| 341 |
ccm_log(LOG_ERR, "msg creation failure"); |
| 342 |
return HA_FAIL; |
| 343 |
} |
| 344 |
|
| 345 |
snprintf(activeproto, sizeof(activeproto), "%d", |
| 346 |
info->ccm_active_proto); |
| 347 |
snprintf(maxtrans, sizeof(maxtrans), "%d", max_tran); |
| 348 |
assert(finallist); |
| 349 |
info->has_quorum = ccm_calculate_quorum(info); |
| 350 |
if (ha_msg_add(m, CCM_MAXTRANS, maxtrans) == HA_FAIL |
| 351 |
|| ha_msg_add(m, CCM_MEMLIST, finallist) == HA_FAIL |
| 352 |
|| ha_msg_add_int(m, CCM_QUORUM, info->has_quorum) == HA_FAIL |
| 353 |
||(!newcookie?FALSE:(ha_msg_add(m,CCM_NEWCOOKIE,newcookie) |
| 354 |
==HA_FAIL))) { |
| 355 |
ccm_log(LOG_ERR, "ccm_send_final_memlist: Cannot create " |
| 356 |
"FINAL_MEMLIST message"); |
| 357 |
rc = HA_FAIL; |
| 358 |
} else { |
| 359 |
dump_sending_msg(m, NULL); |
| 360 |
rc = hb->llc_ops->sendclustermsg(hb, m); |
| 361 |
} |
| 362 |
ha_msg_del(m); |
| 363 |
return(rc); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
int |
| 368 |
ccm_send_one_join_reply(ll_cluster_t *hb, ccm_info_t *info, const char *joiner) |
| 369 |
{ |
| 370 |
struct ha_msg *m; |
| 371 |
char activeproto[3]; |
| 372 |
char clsize[5]; |
| 373 |
int rc; |
| 374 |
|
| 375 |
|
| 376 |
/*send the membership information to all the nodes of the cluster*/ |
| 377 |
m=ccm_create_msg(info, CCM_TYPE_PROTOVERSION_RESP); |
| 378 |
if (m == NULL){ |
| 379 |
ccm_log(LOG_ERR, "%s: creating a message failed", |
| 380 |
__FUNCTION__); |
| 381 |
return(HA_FAIL); |
| 382 |
} |
| 383 |
|
| 384 |
snprintf(activeproto, sizeof(activeproto), "%d", |
| 385 |
info->ccm_active_proto); |
| 386 |
snprintf(clsize, sizeof(clsize), "%d", |
| 387 |
info->memcount); |
| 388 |
if ( ha_msg_add(m, CCM_PROTOCOL, activeproto) == HA_FAIL |
| 389 |
|| ha_msg_add(m, CCM_CLSIZE, clsize) == HA_FAIL){ |
| 390 |
ccm_log(LOG_ERR, "ccm_send_one_join_reply: Cannot create JOIN " |
| 391 |
"reply message"); |
| 392 |
rc = HA_FAIL; |
| 393 |
} else { |
| 394 |
dump_sending_msg(m, joiner); |
| 395 |
rc = hb->llc_ops->sendnodemsg(hb, m, joiner); |
| 396 |
} |
| 397 |
ha_msg_del(m); |
| 398 |
return(rc); |
| 399 |
} |
| 400 |
|
| 401 |
int |
| 402 |
ccm_send_abort(ll_cluster_t *hb, ccm_info_t *info, |
| 403 |
const char *dest, |
| 404 |
const int major, |
| 405 |
const int minor) |
| 406 |
{ |
| 407 |
struct ha_msg *m = ccm_create_msg(info, CCM_TYPE_ABORT); |
| 408 |
int rc; |
| 409 |
char majortrans[15]; |
| 410 |
char minortrans[15]; |
| 411 |
|
| 412 |
if (m == NULL){ |
| 413 |
return HA_FAIL; |
| 414 |
} |
| 415 |
|
| 416 |
snprintf(majortrans, sizeof(majortrans), "%d", |
| 417 |
info->ccm_transition_major); |
| 418 |
snprintf(minortrans, sizeof(minortrans), "%d", |
| 419 |
info->ccm_transition_minor); |
| 420 |
|
| 421 |
if (ha_msg_mod(m,CCM_MAJORTRANS ,majortrans) != HA_OK |
| 422 |
|| ha_msg_mod(m,CCM_MINORTRANS ,majortrans) != HA_OK){ |
| 423 |
ccm_log(LOG_ERR, "modifying fields failed"); |
| 424 |
ha_msg_del(m); |
| 425 |
return HA_FAIL; |
| 426 |
} |
| 427 |
dump_sending_msg(m, dest); |
| 428 |
rc = hb->llc_ops->sendnodemsg(hb, m, dest); |
| 429 |
ha_msg_del(m); |
| 430 |
return(rc); |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
/* Fake up a leave message. |
| 437 |
* This is generally done when heartbeat informs ccm of the crash of |
| 438 |
* a cluster member. |
| 439 |
*/ |
| 440 |
struct ha_msg * |
| 441 |
ccm_create_leave_msg(ccm_info_t *info, int uuid) |
| 442 |
{ |
| 443 |
struct ha_msg *m = ccm_create_msg(info, CCM_TYPE_LEAVE); |
| 444 |
llm_info_t *llm; |
| 445 |
const char *nodename; |
| 446 |
|
| 447 |
if (m == NULL){ |
| 448 |
ccm_log(LOG_ERR, "message creating failed"); |
| 449 |
return NULL; |
| 450 |
} |
| 451 |
|
| 452 |
/* find the name of the node at index */ |
| 453 |
llm = &(info->llm); |
| 454 |
nodename = llm_get_nodename(llm, uuid); |
| 455 |
|
| 456 |
if(ha_msg_add(m, F_ORIG, nodename) == HA_FAIL) { |
| 457 |
ccm_log(LOG_ERR, "adding field failed"); |
| 458 |
ha_msg_del(m); |
| 459 |
return NULL; |
| 460 |
} |
| 461 |
|
| 462 |
return(m); |
| 463 |
} |
| 464 |
|
| 465 |
int |
| 466 |
timeout_msg_init(ccm_info_t *info) |
| 467 |
{ |
| 468 |
return HA_OK; |
| 469 |
} |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
static struct ha_msg * timeout_msg = NULL; |
| 475 |
|
| 476 |
struct ha_msg * |
| 477 |
timeout_msg_mod(ccm_info_t *info) |
| 478 |
{ |
| 479 |
struct ha_msg *m = timeout_msg; |
| 480 |
char *hname; |
| 481 |
|
| 482 |
if (m !=NULL){ |
| 483 |
if (ccm_mod_msg(m, info, CCM_TYPE_TIMEOUT) != HA_OK){ |
| 484 |
ccm_log(LOG_ERR, "mod message failed"); |
| 485 |
ha_msg_del(timeout_msg); |
| 486 |
timeout_msg = NULL; |
| 487 |
return NULL; |
| 488 |
} |
| 489 |
|
| 490 |
return m; |
| 491 |
} |
| 492 |
|
| 493 |
m = ccm_create_minimum_msg(info, CCM_TYPE_TIMEOUT); |
| 494 |
if (m == NULL){ |
| 495 |
ccm_log(LOG_ERR, "creating a message failed"); |
| 496 |
return NULL; |
| 497 |
} |
| 498 |
|
| 499 |
hname = info->llm.nodes[info->llm.myindex].nodename; |
| 500 |
|
| 501 |
if (ha_msg_add(m, F_ORIG, hname) == HA_FAIL |
| 502 |
|| ha_msg_add(m, CCM_COOKIE, " ") == HA_FAIL |
| 503 |
|| ha_msg_add(m, CCM_MAJORTRANS, "0") == HA_FAIL |
| 504 |
||(ha_msg_add(m, CCM_MINORTRANS, "0") == HA_FAIL)){ |
| 505 |
ccm_log(LOG_ERR, "Adding field to a message failed"); |
| 506 |
ha_msg_del(m); |
| 507 |
return NULL; |
| 508 |
} |
| 509 |
timeout_msg = m; |
| 510 |
return m; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
/*broadcast CCM_TYPE_NODE_LEAVE_NOTICE */ |
| 516 |
int |
| 517 |
ccm_bcast_node_leave_notice(ll_cluster_t* hb, |
| 518 |
ccm_info_t* info, |
| 519 |
const char* node) |
| 520 |
{ |
| 521 |
return ccm_send_extra_clustermsg(hb, info, CCM_TYPE_NODE_LEAVE_NOTICE, |
| 522 |
F_NODE, node); |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
int |
| 529 |
send_node_leave_to_leader(ll_cluster_t *hb, ccm_info_t *info, const char *node) |
| 530 |
{ |
| 531 |
return ccm_send_extra_nodemsg(hb, info, CCM_TYPE_NODE_LEAVE, |
| 532 |
F_NODE, node, |
| 533 |
node); |
| 534 |
|
| 535 |
} |
| 536 |
|
| 537 |
int |
| 538 |
ccm_send_to_all(ll_cluster_t *hb, ccm_info_t *info, |
| 539 |
char *memlist, char *newcookie, |
| 540 |
int *uptime_list, size_t uptime_size) |
| 541 |
{ |
| 542 |
struct ha_msg *m = ccm_create_msg(info, CCM_TYPE_MEM_LIST); |
| 543 |
char activeproto[3]; |
| 544 |
int rc; |
| 545 |
|
| 546 |
if (m == NULL){ |
| 547 |
ccm_log(LOG_ERR, "creating msg failed"); |
| 548 |
return HA_FAIL; |
| 549 |
} |
| 550 |
|
| 551 |
snprintf(activeproto, sizeof(activeproto), "%d", info->ccm_active_proto); |
| 552 |
|
| 553 |
info->has_quorum = ccm_calculate_quorum(info); |
| 554 |
if ( ha_msg_add(m, CCM_MEMLIST, memlist) == HA_FAIL |
| 555 |
|| ha_msg_add_int(m, CCM_QUORUM, info->has_quorum) == HA_FAIL |
| 556 |
|| cl_msg_add_list_int(m, CCM_UPTIMELIST, uptime_list, uptime_size) |
| 557 |
== HA_FAIL |
| 558 |
|| !newcookie? FALSE: (ha_msg_add(m, CCM_NEWCOOKIE, newcookie) |
| 559 |
==HA_FAIL)) { |
| 560 |
ccm_log(LOG_ERR, "ccm_send_final_memlist: Cannot create " |
| 561 |
"FINAL_MEMLIST message"); |
| 562 |
ha_msg_del(m); |
| 563 |
return HA_FAIL; |
| 564 |
} |
| 565 |
|
| 566 |
dump_sending_msg(m, NULL); |
| 567 |
rc = hb->llc_ops->sendclustermsg(hb, m); |
| 568 |
ha_msg_del(m); |
| 569 |
return(rc); |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
int ccm_send_alive_msg(ll_cluster_t *hb, ccm_info_t *info) |
| 574 |
{ |
| 575 |
return ccm_send_standard_clustermsg(hb, info, CCM_TYPE_ALIVE); |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
int |
| 580 |
ccm_send_newnode_to_leader(ll_cluster_t *hb, |
| 581 |
ccm_info_t *info, |
| 582 |
const char *node) |
| 583 |
{ |
| 584 |
|
| 585 |
return ccm_send_extra_nodemsg(hb, info, CCM_TYPE_NEW_NODE, |
| 586 |
F_NODE, node, |
| 587 |
info->llm.nodes[info->ccm_cluster_leader].nodename); |
| 588 |
} |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
/* send a message to node |
| 593 |
* the message contains my state informaton |
| 594 |
*/ |
| 595 |
|
| 596 |
int |
| 597 |
ccm_send_state_info(ll_cluster_t* hb, ccm_info_t* info, const char* node) |
| 598 |
{ |
| 599 |
|
| 600 |
return ccm_send_extra_nodemsg(hb, info, CCM_TYPE_STATE_INFO, |
| 601 |
F_STATE, state2string(info->state), |
| 602 |
node); |
| 603 |
|
| 604 |
} |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
int |
| 609 |
ccm_send_restart_msg(ll_cluster_t* hb, ccm_info_t* info) |
| 610 |
{ |
| 611 |
return ccm_send_minimum_clustermsg(hb, info, CCM_TYPE_RESTART); |
| 612 |
} |
| 613 |
|
| 614 |
static void |
| 615 |
dump_sending_msg(struct ha_msg* msg, const char* node) |
| 616 |
{ |
| 617 |
const char* type; |
| 618 |
const char* status; |
| 619 |
|
| 620 |
type = ha_msg_value(msg, F_TYPE); |
| 621 |
status = ha_msg_value(msg, F_STATUS); |
| 622 |
|
| 623 |
ccm_debug(LOG_DEBUG, "send msg %s to %s, status:%s" |
| 624 |
, type, node==NULL?"cluster":node, (status ? status : "[null]")); |
| 625 |
ccm_message_debug2(LOG_DEBUG, msg); |
| 626 |
} |