33 #include <sys/types.h> 34 #include <sys/socket.h> 35 #include <netinet/in.h> 36 #include <arpa/inet.h> 63 #define HB_INFO_STR_MAX 8192 64 #define SERVER_DEREG_MAX_POLL_COUNT 10 66 #define ENTER_FUNC() \ 68 MASTER_ER_LOG_DEBUG (ARG_FILE_LINE, "%s : enter", __func__); \ 73 MASTER_ER_LOG_DEBUG (ARG_FILE_LINE, "%s : exit", __func__); \ 90 static void hb_add_timeval (
struct timeval *tv_p,
unsigned int msec);
92 static const char *
hb_strtime (
char *s,
unsigned int max,
struct timeval *tv_p);
124 unsigned int seq,
char *dest_host_name);
192 #if defined (ENABLE_UNUSED_FUNCTION) 193 static void hb_deregister_nodes (
char *node_to_dereg);
279 #define HA_NODE_INFO_FORMAT_STRING \ 280 " HA-Node Info (current %s, state %s)\n" 281 #define HA_NODE_FORMAT_STRING \ 282 " Node %s (priority %d, state %s)\n" 283 #define HA_UI_NODE_FORMAT_STRING \ 284 " * Node %s (ip %s, group %s, state %s)\n" 285 #define HA_NODE_SCORE_FORMAT_STRING \ 287 #define HA_NODE_HEARTBEAT_GAP_FORMAT_STRING \ 288 " - missed heartbeat %d\n" 290 #define HA_PROCESS_INFO_FORMAT_STRING \ 291 " HA-Process Info (master %d, state %s)\n" 292 #define HA_SERVER_PROCESS_FORMAT_STRING \ 293 " Server %s (pid %d, state %s)\n" 294 #define HA_COPYLOG_PROCESS_FORMAT_STRING \ 295 " Copylogdb %s (pid %d, state %s)\n" 296 #define HA_APPLYLOG_PROCESS_FORMAT_STRING \ 297 " Applylogdb %s (pid %d, state %s)\n" 298 #define HA_PROCESS_EXEC_PATH_FORMAT_STRING \ 299 " - exec-path [%s] \n" 300 #define HA_PROCESS_ARGV_FORMAT_STRING \ 302 #define HA_PROCESS_REGISTER_TIME_FORMAT_STRING \ 303 " - registered-time %s\n" 304 #define HA_PROCESS_DEREGISTER_TIME_FORMAT_STRING \ 305 " - deregistered-time %s\n" 306 #define HA_PROCESS_SHUTDOWN_TIME_FORMAT_STRING \ 307 " - shutdown-time %s\n" 308 #define HA_PROCESS_START_TIME_FORMAT_STRING \ 311 #define HA_PING_HOSTS_INFO_FORMAT_STRING \ 312 " HA-Ping Host Info (PING check %s)\n" 313 #define HA_PING_HOSTS_FORMAT_STRING \ 316 #define HA_ADMIN_INFO_FORMAT_STRING \ 318 #define HA_ADMIN_INFO_NOLOG_FORMAT_STRING \ 319 " Error Logging: disabled\n" 320 #define HA_ADMIN_INFO_NOLOG_EVENT_FORMAT_STRING \ 373 *dest_pp = *source_pp;
376 (*dest_pp)->
prev = dest_pp;
401 tv_p->tv_sec += (msec / 1000);
402 tv_p->tv_usec += ((msec % 1000) * 1000);
430 if (arg1->tv_sec > arg2->tv_sec)
434 else if (arg1->tv_sec == arg2->tv_sec)
436 if (arg1->tv_usec > arg2->tv_usec)
440 else if (arg1->tv_usec == arg2->tv_usec)
466 struct tm hb_tm, *hb_tm_p = &hb_tm;
468 if (s ==
NULL || max < 24 || tv_p == NULL || tv_p->tv_sec == 0)
474 hb_tm_p = localtime_r (&tv_p->tv_sec, &hb_tm);
481 snprintf (s + strftime (s, (max - 5),
"%m/%d/%y %H:%M:%S", hb_tm_p), (max - 1),
".%03ld", tv_p->tv_usec / 1000);
483 return (
const char *) s;
486 return (
const char *)
"00/00/00 00:00:00.000";
513 gettimeofday (&now,
NULL);
518 new_job->
type = job_type;
521 memcpy ((
void *) &(new_job->
expire), (
void *) &now, sizeof (
struct timeval));
524 for (job = &(jobs->
jobs); *job; job = &((*job)->next))
556 gettimeofday (&now,
NULL);
602 gettimeofday (&now,
NULL);
613 for (job = &(jobs->
jobs); *job; job = &((*job)->next))
615 if ((*job)->type == job_type)
622 if (target_job ==
NULL)
628 memcpy ((
void *) &(target_job->
expire), (
void *) &now, sizeof (
struct timeval));
635 for (job = &(jobs->
jobs); *job; job = &((*job)->next))
667 for (job = jobs->
jobs; job; job = job_next)
669 job_next = job->
next;
747 for (node = hb_Cluster->
nodes; node; node = node->
next)
771 unsigned int heartbeat_confirm_time;
775 gettimeofday (&now,
NULL);
777 for (node = hb_Cluster->
nodes; node; node = node->
next)
798 unsigned int failover_wait_time;
849 "More than one master detected and failback will be initiated");
909 "A failover attempted to make the current node a master");
948 int ping_try_count = 0;
949 bool ping_success =
false;
951 unsigned int failover_wait_time;
965 goto ping_check_cancel;
970 for (ping_host = hb_Cluster->
ping_hosts; ping_host; ping_host = ping_host->
next)
989 if (ping_try_count == 0 || ping_success ==
true)
991 goto ping_check_cancel;
996 if (ping_try_count > 0 && ping_success ==
false)
998 goto ping_check_cancel;
1156 if (arg ==
NULL || clst_arg ==
NULL)
1174 "Waiting for a new node to be elected as master");
1184 "Failed to find a new master node and it changes " "its role back to master again");
1196 for (node = hb_Cluster->
nodes; node; node = node->
next)
1257 bool emergency_kill_enabled =
false;
1269 "This master will become a slave and cub_server will be restarted");
1285 proc = hb_Resource->
procs;
1294 if (emergency_kill_enabled ==
false)
1296 size =
sizeof (pid_t) * (count + 1);
1297 pids = (pid_t *) realloc (pids, size);
1306 emergency_kill_enabled =
true;
1307 proc = hb_Resource->
procs;
1310 pids[count++] = proc->
pid;
1317 kill (proc->
pid, SIGKILL);
1325 if (emergency_kill_enabled ==
false)
1356 bool valid_ping_host_exists =
false;
1363 for (ping_host = hb_Cluster->
ping_hosts; ping_host; ping_host = ping_host->
next)
1369 valid_ping_host_exists =
true;
1373 return valid_ping_host_exists;
1386 bool valid_ping_host_exists;
1405 snprintf (buf, LINE_MAX,
1406 "Validity check for PING failed on all hosts " "and PING check is now temporarily disabled.");
1410 else if (valid_ping_host_exists ==
true)
1415 snprintf (buf, LINE_MAX,
"Validity check for PING succeeded " "and PING check is now enabled.");
1446 if (hb_Cluster ==
NULL)
1453 gettimeofday (&now,
NULL);
1455 for (node = hb_Cluster->
nodes; node; node = node->
next)
1472 switch (node->
state)
1499 if (node->
score < min_score)
1501 hb_Cluster->
master = node;
1502 min_score = node->
score;
1524 if (hb_Cluster ==
NULL)
1530 for (node = hb_Cluster->
nodes; node; node = node->
next)
1553 struct sockaddr_in saddr;
1554 socklen_t saddr_len;
1557 memset ((
void *) &saddr, 0,
sizeof (saddr));
1559 (
struct sockaddr *) &saddr, &saddr_len);
1583 memset ((
void *) buffer, 0,
sizeof (buffer));
1592 p = (
char *) (hbp_header + 1);
1603 send_len = sendto (hb_Cluster->
sfd, (
void *) &buffer[0], hb_len, 0, (
struct sockaddr *) saddr, saddr_len);
1630 char error_string[LINE_MAX] =
"";
1634 bool is_state_changed =
false;
1654 if (len != (
int) (
sizeof (*hbp_header) +
htons (hbp_header->
len)))
1657 (
sizeof (*hbp_header) +
htons (hbp_header->
len)));
1664 "hbp_header. (type:%d, r:%d, len:%d, seq:%d, " "orig_host_name:{%s}, dest_host_name:{%s}). \n",
1669 switch (hbp_header->
type)
1675 p = (
char *) (hbp_header + 1);
1680 if (hb_state < HB_NSTATE_UNKNOWN || hb_state >=
HB_NSTATE_MAX)
1692 if (ui_node && ui_node->
v_result != rv)
1698 if (ui_node ==
NULL)
1702 ipv4_p = (
char *) &from->sin_addr.s_addr;
1703 snprintf (error_string,
sizeof (error_string),
1704 "Receive heartbeat from unidentified host. " "(host_name:'%s', group:'%s', " 1706 (
unsigned char) (ipv4_p[0]), (
unsigned char) (ipv4_p[1]), (
unsigned char) (ipv4_p[2]),
1741 is_state_changed =
true;
1744 node->
state = hb_state;
1765 if (is_state_changed ==
true)
1787 char *dest_host_name)
1795 header->
type = type;
1796 header->
r = (is_req) ? 1 : 0;
1822 in_addr = inet_addr (host);
1825 memcpy ((
void *) addr, (
void *) &in_addr,
sizeof (in_addr));
1829 #ifdef HAVE_GETHOSTBYNAME_R 1830 #if defined (HAVE_GETHOSTBYNAME_R_GLIBC) 1831 struct hostent *hp, hent;
1835 if (gethostbyname_r (host, &hent, buf,
sizeof (buf), &hp, &herr) != 0 || hp ==
NULL)
1840 memcpy ((
void *) addr, (
void *) hent.h_addr, hent.h_length);
1841 #elif defined (HAVE_GETHOSTBYNAME_R_SOLARIS) 1842 struct hostent hent;
1846 if (gethostbyname_r (host, &hent, buf,
sizeof (buf), &herr) ==
NULL)
1851 memcpy ((
void *) addr, (
void *) hent.h_addr, hent.h_length);
1852 #elif defined (HAVE_GETHOSTBYNAME_R_HOSTENT_DATA) 1853 struct hostent hent;
1854 struct hostent_data ht_data;
1856 if (gethostbyname_r (host, &hent, &ht_data) == -1)
1861 memcpy ((
void *) addr, (
void *) hent.h_addr, hent.h_length);
1863 #error "HAVE_GETHOSTBYNAME_R" 1870 hp = gethostbyname (host);
1877 memcpy ((
void *) addr, (
void *) hp->h_addr, hp->h_length);
1899 struct sockaddr_in udp_saddr;
1904 memset ((
void *) &udp_saddr, 0,
sizeof (udp_saddr));
1905 udp_saddr.sin_family = AF_INET;
1906 udp_saddr.sin_port =
htons (port);
1914 *slen =
sizeof (udp_saddr);
1915 memcpy ((
void *) saddr, (
void *) &udp_saddr, *slen);
1951 return hb_job_queue (cluster_Jobs, job_type, arg, msec);
2003 if (host_name ==
NULL)
2029 first_pp = &hb_Cluster->
nodes;
2064 for (node = first; node; node = next_node)
2066 next_node = node->
next;
2083 if (host_name ==
NULL)
2133 for (host = first;
host; host = next_host)
2135 next_host = host->
next;
2150 char host_list[LINE_MAX];
2151 char *host_list_p, *host_p, *host_pp;
2153 if (ha_ping_host_list ==
NULL)
2160 for (host_list_p = host_list;; host_list_p =
NULL)
2162 host_p = strtok_r (host_list_p,
" ,:", &host_pp);
2186 for (node = hb_Cluster->
nodes; node; node = node->
next)
2210 for (node = hb_Cluster->
nodes; node; node = node->
next)
2227 struct in_addr sin_addr;
2236 if (strcmp (group_id, hb_Cluster->
group_id) != 0)
2244 if (memcmp ((
void *) &sin_addr, (
void *) &from->sin_addr, sizeof (
struct in_addr)) != 0)
2290 for (node = hb_Cluster->
ui_nodes; node; node = node->
next)
2297 if (strcmp (node->
group_id, group_id) != 0)
2302 if (node->
saddr.sin_addr.s_addr != saddr.sin_addr.s_addr)
2318 hb_add_ui_node (
char *host_name,
char *group_id,
struct sockaddr_in saddr,
int v_result)
2336 memcpy ((
void *) &node->
saddr, (
void *) &saddr, sizeof (
struct sockaddr_in));
2380 gettimeofday (&now,
NULL);
2382 for (node = first; node; node = node_next)
2384 node_next = node->
next;
2404 for (node = first; node; node = node_next)
2406 node_next = node->
next;
2421 int priority, num_nodes;
2422 char tmp_string[LINE_MAX];
2426 if (ha_node_list ==
NULL)
2435 for (priority = 0, p = strtok_r (tmp_string,
"@", &savep);
p; priority++, p = strtok_r (
NULL,
" ,:", &savep))
2452 hb_Cluster->
myself = node;
2453 #if defined (HB_VERBOSE_DEBUG) 2467 num_nodes = priority;
2469 if (ha_replica_list)
2475 tmp_string[0] =
'\0';
2477 for (priority = 0, p = strtok_r (tmp_string,
"@", &savep);
p; priority++, p = strtok_r (
NULL,
" ,:", &savep))
2482 if (strcmp (hb_Cluster->
group_id, p) != 0)
2495 hb_Cluster->
myself = node;
2508 return num_nodes + priority;
2530 char error_string[LINE_MAX] =
"";
2531 int num_connected_rsc = 0;
2535 if (arg ==
NULL || resource_job_arg ==
NULL)
2546 for (proc = hb_Resource->
procs; proc; proc = proc_next)
2551 proc_next = proc->
next;
2553 if (proc->
pid > 0 && (kill (proc->
pid, 0) == 0 || errno != ESRCH))
2555 snprintf (error_string, LINE_MAX,
"(pid: %d, args:%s)", proc->
pid, proc->
args);
2559 "Immediate shutdown requested. Process killed", error_string);
2564 "No response to shutdown request. Process killed", error_string);
2567 kill (proc->
pid, SIGKILL);
2576 goto end_confirm_cleanup;
2579 for (proc = hb_Resource->
procs; proc; proc = proc_next)
2584 proc_next = proc->
next;
2588 if (proc->
pid > 0 && (kill (proc->
pid, 0) == 0 || errno != ESRCH))
2590 kill (proc->
pid, SIGKILL);
2592 snprintf (error_string, LINE_MAX,
"(pid: %d, args:%s)", proc->
pid, proc->
args);
2594 "No response to shutdown request. Process killed", error_string);
2602 if (proc->
pid <= 0 || (kill (proc->
pid, 0) && errno == ESRCH))
2613 num_connected_rsc++;
2619 if (hb_Resource->
num_procs == 0 || num_connected_rsc == 0)
2621 goto end_confirm_cleanup;
2638 end_confirm_cleanup:
2673 for (i = 0, proc = hb_Resource->
procs; proc; proc = proc->
next)
2690 if (job_arg ==
NULL)
2701 resource_job_arg->
retries = 0;
2703 gettimeofday (&resource_job_arg->
ftime,
NULL);
2729 char error_string[LINE_MAX] =
"";
2736 if (arg ==
NULL || proc_arg ==
NULL)
2751 if (proc->being_shutdown)
2754 if (proc_arg->
pid <= 0 || (kill (proc_arg->
pid, 0) && errno == ESRCH))
2756 proc->being_shutdown =
false;
2771 gettimeofday (&now,
NULL);
2786 snprintf (error_string, LINE_MAX,
"(args:%s)", proc->args);
2789 args =
strdup (proc->args);
2812 #if defined (HB_VERBOSE_DEBUG) 2814 "execute:{%s} arg[0]:{%s} arg[1]:{%s} arg[2]:{%s} " 2815 "arg[3]:{%s} arg{4}:{%s} arg[5]:{%s} arg[6]:{%s} " "arg[7]:{%s} arg[8]:{%s} arg[9]:{%s}.\n",
2816 proc->exec_path, (argv[0]) ? argv[0] :
"", (argv[1]) ? argv[1] :
"",
2817 (argv[2]) ? argv[2] :
"", (argv[3]) ? argv[3] :
"", (argv[4]) ? argv[4] :
"",
2818 (argv[5]) ? argv[5] :
"", (argv[6]) ? argv[6] :
"", (argv[7]) ? argv[7] :
"",
2819 (argv[8]) ? argv[8] :
"", (argv[9]) ? argv[9] :
"");
2821 error = execv (proc->exec_path, argv);
2832 gettimeofday (&proc->stime,
NULL);
2866 if (arg ==
NULL || proc_arg ==
NULL)
2871 #if defined (HB_VERBOSE_DEBUG) 2874 #if !defined(WINDOWS) 2883 #if !defined(WINDOWS) 2895 #if !defined(WINDOWS) 2910 goto hb_resource_job_proc_dereg_end;
2913 memset (buffer, 0,
sizeof (buffer));
2914 snprintf (buffer,
sizeof (buffer) - 1,
2916 sock_entq->
name + 1, 0);
2922 if (proc->
pid <= 0 || (kill (proc->
pid, SIGTERM) && errno == ESRCH))
2929 #if !defined(WINDOWS) 2937 hb_resource_job_proc_dereg_end:
2939 #if !defined(WINDOWS) 2968 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
2981 if (proc->
pid > 0 && (kill (proc->
pid, 0) == 0 || errno != ESRCH))
2983 kill (proc->
pid, SIGKILL);
2992 memset (buffer, 0,
sizeof (buffer));
2993 snprintf (buffer,
sizeof (buffer) - 1,
2995 sock_entq->
name + 1, 0);
3015 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
3042 char error_string[LINE_MAX] =
"";
3044 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
3050 if (proc->
pid > 0 && (kill (proc->
pid, 0) == 0 || errno != ESRCH))
3052 snprintf (error_string, LINE_MAX,
"(pid: %d, args:%s)", proc->
pid, proc->
args);
3054 "No response to shutdown request. Process killed", error_string);
3055 kill (proc->
pid, SIGKILL);
3078 if (arg ==
NULL || proc_arg ==
NULL)
3089 goto demote_confirm_shutdown_end;
3105 demote_confirm_shutdown_end:
3109 if (job_arg ==
NULL)
3155 #if !defined(WINDOWS) 3163 #if !defined(WINDOWS) 3168 if (job_arg ==
NULL)
3210 char error_string[LINE_MAX] =
"";
3216 if (arg ==
NULL || proc_arg ==
NULL)
3233 snprintf (error_string, LINE_MAX,
"(exceed max retry count for pid: %d, args:%s)", proc->
pid, proc->
args);
3241 "Failed to restart the process " "and the current node will be demoted", error_string);
3264 "Keep checking to confirm the completion of the process startup", error_string);
3279 error = kill (proc->
pid, 0);
3285 snprintf (error_string, LINE_MAX,
"(process not found, expected pid: %d, args:%s)", proc->
pid, proc->
args);
3361 if (arg ==
NULL || proc_arg ==
NULL)
3367 #if defined (HB_VERBOSE_DEBUG) 3390 error = kill (proc->
pid, 0);
3405 kill (proc->
pid, SIGKILL);
3449 #if !defined(WINDOWS) 3453 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
3478 if (hb_Resource->
procs)
3485 #if !defined(WINDOWS) 3532 return hb_job_queue (resource_Jobs, job_type, arg, msec);
3595 first_pp = &hb_Resource->
procs;
3630 for (proc = first; proc; proc = next_proc)
3632 next_proc = proc->
next;
3648 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
3650 if (strcmp (proc->
args, args))
3670 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
3672 if (proc->
pid != pid)
3693 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
3695 if (proc->
sfd != sfd)
3717 tok = strtok_r (args,
" \t\n", &save);
3722 tok = strtok_r (
NULL,
" \t\n", &save);
3744 char error_string[LINE_MAX] =
"";
3751 if (hb_Resource ==
NULL)
3782 #if defined (HB_VERBOSE_DEBUG) 3787 snprintf (error_string, LINE_MAX,
"(pid:%d, args:%s)", proc->
pid, proc->
args);
3808 snprintf (error_string, LINE_MAX,
"(args:%s)", proc->
args);
3810 "Process failure repeated within a short period of time. " "The current node will be demoted",
3820 if (job_arg ==
NULL)
3828 proc_arg->
pid = proc->
pid;
3829 memcpy ((
void *) &proc_arg->
args[0], proc->
args, sizeof (proc_arg->
args));
3859 if (hb_Resource ==
NULL)
3892 int rv, buffer_size;
3897 char error_string[LINE_MAX] =
"";
3899 if (hb_Resource ==
NULL)
3947 && !(kill (proc->
pid, 0) && errno == ESRCH)))
3949 proc->
state = proc_state;
3950 proc->
sfd = conn->
fd;
3965 memcpy ((
void *) &proc->
args[0], (
void *) &hbp_proc_register->
args[0], sizeof (proc->
args));
3971 #if defined (HB_VERBOSE_DEBUG) 3973 "hbp_proc_register. (sizeof(hbp_proc_register):%d, \n" 3974 "type:%d, state:%d, pid:%d, exec_path:{%s}, " "args:{%s}). \n",
sizeof (
HBP_PROC_REGISTER),
3981 hbp_proc_register->
args);
3991 snprintf (error_string, LINE_MAX,
"%s (expected pid: %d, pid:%d, state:%s, args:%s)",
HB_RESULT_FAILURE_STR,
3993 hbp_proc_register->
args);
4014 char error_string[LINE_MAX] =
"";
4033 if (proc->
pid > 0 && (kill (proc->
pid, 0) == 0 || errno != ESRCH))
4035 snprintf (error_string,
sizeof (error_string),
4036 "process does not respond for a long time. kill pid %d signal %d.", proc->
pid, sig);
4039 kill (proc->
pid, sig);
4044 switch (hb_Resource->
state)
4070 nstate =
htonl ((
int) state);
4074 snprintf (error_string, LINE_MAX,
4075 "Failed to send changemode request to the server. " "(state:%d[%s], args:[%s], pid:%d)", state,
4082 snprintf (error_string, LINE_MAX,
"Send changemode request to the server. " "(state:%d[%s], args:[%s], pid:%d)",
4102 char error_string[LINE_MAX] =
"";
4104 if (hb_Resource ==
NULL)
4127 snprintf (error_string, LINE_MAX,
"Receive changemode response from the server. " "(state:%d[%s], args:[%s], pid:%d)",
4175 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
4198 #if !defined(WINDOWS) 4199 syslog (LOG_ALERT,
"[CUBRID] no change to eof [%lld|%d] received from (pid:%d)",
4207 #if !defined(WINDOWS) 4208 syslog (LOG_ALERT,
"[CUBRID] no response to eof request from (pid:%d)", proc->
pid);
4238 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
4306 #if defined(WINDOWS) 4307 static unsigned __stdcall
4319 #if defined (HB_VERBOSE_DEBUG) 4323 while (cluster_Jobs->
shutdown ==
false)
4334 #if defined (HB_VERBOSE_DEBUG) 4338 #if defined(WINDOWS) 4351 #if defined(WINDOWS) 4352 static unsigned __stdcall
4363 struct pollfd po[1] = { {0, 0, 0} };
4365 struct sockaddr_in from;
4372 #if defined (HB_VERBOSE_DEBUG) 4377 sfd = hb_Cluster->
sfd;
4378 while (hb_Cluster->
shutdown ==
false)
4381 po[0].events = POLLIN;
4382 error = poll (po, 1, 1);
4388 if ((po[0].revents & POLLIN) && sfd == hb_Cluster->
sfd)
4390 from_len =
sizeof (from);
4391 len = recvfrom (sfd, (
void *) aligned_buffer,
HB_BUFFER_SZ, 0, (
struct sockaddr *) &from, &from_len);
4399 #if defined (HB_VERBOSE_DEBUG) 4403 #if defined(WINDOWS) 4416 #if defined(WINDOWS) 4417 static unsigned __stdcall
4429 #if defined (HB_VERBOSE_DEBUG) 4433 while (resource_Jobs->
shutdown ==
false)
4444 #if defined (HB_VERBOSE_DEBUG) 4448 #if defined(WINDOWS) 4461 #if defined(WINDOWS) 4462 static unsigned __stdcall
4471 INT64 remaining_time_msecs = 0;
4476 #if defined (HB_VERBOSE_DEBUG) 4480 while (hb_Resource->
shutdown ==
false)
4483 if (interval > 0 && remaining_time_msecs <= 0)
4485 #if !defined(WINDOWS) 4501 #if !defined(WINDOWS) 4504 syslog (LOG_ALERT,
"[CUBRID] %s () at %s:%d", __func__, __FILE__, __LINE__);
4520 #if !defined(WINDOWS) 4524 remaining_time_msecs = interval * 1000;
4534 #if defined (HB_VERBOSE_DEBUG) 4538 #if defined(WINDOWS) 4559 if (cluster_Jobs ==
NULL)
4562 if (cluster_Jobs ==
NULL)
4598 struct sockaddr_in udp_saddr;
4608 if (hb_Cluster ==
NULL)
4611 if (hb_Cluster ==
NULL)
4669 #if defined (HB_VERBOSE_DEBUG) 4674 hb_Cluster->
sfd = socket (AF_INET, SOCK_DGRAM, 0);
4675 if (hb_Cluster->
sfd < 0)
4682 memset ((
void *) &udp_saddr, 0,
sizeof (udp_saddr));
4683 udp_saddr.sin_family = AF_INET;
4684 udp_saddr.sin_addr.s_addr =
htonl (INADDR_ANY);
4687 if (bind (hb_Cluster->
sfd, (
struct sockaddr *) &udp_saddr, sizeof (udp_saddr)) < 0)
4709 if (hb_Resource ==
NULL)
4712 if (hb_Resource ==
NULL)
4741 if (resource_Jobs ==
NULL)
4744 if (resource_Jobs ==
NULL)
4783 pthread_attr_t thread_attr;
4785 pthread_t cluster_worker_th;
4786 pthread_t resource_worker_th;
4787 pthread_t check_disk_failure_th;
4789 rv = pthread_attr_init (&thread_attr);
4796 rv = pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
4807 pthread_attr_setscope (&thread_attr,
4809 PTHREAD_SCOPE_SYSTEM);
4811 rv = pthread_attr_setscope (&thread_attr, PTHREAD_SCOPE_SYSTEM);
4820 #if !defined(sun) && !defined(SOLARIS) 4821 #if defined(_POSIX_THREAD_ATTR_STACKSIZE) 4822 rv = pthread_attr_getstacksize (&thread_attr, &ts_size);
4832 pthread_attr_getstacksize (&thread_attr, &ts_size);
4867 rv = pthread_attr_destroy (&thread_attr);
4890 #if defined (HB_VERBOSE_DEBUG) 4943 if (hb_Cluster && hb_Cluster->
shutdown ==
false)
4948 if (cluster_Jobs && cluster_Jobs->
shutdown ==
false)
4953 if (hb_Resource && hb_Resource->
shutdown ==
false)
4958 if (resource_Jobs && resource_Jobs->
shutdown ==
false)
4983 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
4989 #if defined (HB_VERBOSE_DEBUG) 5003 memset (buffer, 0,
sizeof (buffer));
5004 snprintf (buffer,
sizeof (buffer) - 1,
5006 sock_ent->
name + 1, 0);
5042 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
5044 if (proc->
conn && proc->
pid > 0)
5046 kill (proc->
pid, SIGKILL);
5087 for (node = hb_Cluster->
nodes; node; node = node->
next)
5105 close (hb_Cluster->
sfd);
5185 switch (ping_result)
5210 int rv, old_num_nodes, old_num_ping_hosts,
error;
5212 HB_NODE_ENTRY *old_node, *old_myself, *old_master, *new_node;
5215 if (hb_Cluster ==
NULL)
5222 #if defined (HB_VERBOSE_DEBUG) 5242 old_myself = hb_Cluster->
myself;
5243 old_master = hb_Cluster->
master;
5254 goto reconfig_error;
5267 goto reconfig_error;
5270 for (new_node = hb_Cluster->
nodes; new_node; new_node = new_node->
next)
5272 #if defined (HB_VERBOSE_DEBUG) 5275 for (old_node = old_nodes; old_node; old_node = old_node->
next)
5283 hb_Cluster->
master = new_node;
5299 if (old_ping_hosts !=
NULL)
5326 hb_Cluster->
myself = old_myself;
5327 hb_Cluster->
master = old_master;
5337 #if defined (ENABLE_UNUSED_FUNCTION) 5339 hb_deregister_nodes (
char *node_to_dereg)
5341 const char *delim =
":";
5349 for (p = strtok_r (node_to_dereg, delim, &savep);
p; p = strtok_r (
NULL, delim, &savep))
5353 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
5362 log_path = proc->argv[3];
5363 node_name = strrchr (log_path,
'_');
5367 if (strncmp (node_name, p,
strlen (p)) == 0)
5398 int rv, buf_size = 0;
5420 *str = (
char *) malloc (
sizeof (
char) * buf_size);
5429 p = (
char *) (*str);
5430 last = p + buf_size;
5450 int rv, buf_size = 0, required_size = 0;
5452 bool valid_ping_host_exists;
5453 bool is_ping_check_enabled =
true;
5456 if (hb_Cluster ==
NULL)
5480 is_ping_check_enabled =
false;
5491 buf_size += required_size;
5498 buf_size += required_size;
5500 *str = (
char *) malloc (
sizeof (
char) * buf_size);
5509 p = (
char *) (*str);
5510 last = p + buf_size;
5515 for (ping_host = hb_Cluster->
ping_hosts; ping_host; ping_host = ping_host->
next)
5539 int rv, buf_size = 0, required_size = 0;
5545 if (hb_Cluster ==
NULL)
5559 buf_size += required_size;
5576 buf_size += required_size;
5586 buf_size += required_size;
5588 *str = (
char *) malloc (
sizeof (
char) * buf_size);
5597 p = (
char *) (*str);
5598 last = p + buf_size;
5604 for (node = hb_Cluster->
nodes; node; node = node->
next)
5617 gettimeofday (&now,
NULL);
5618 for (ui_node = hb_Cluster->
ui_nodes; ui_node; ui_node = ui_node->
next)
5625 ipv4_p = (
char *) &ui_node->
saddr.sin_addr.s_addr;
5626 snprintf (ipv4_str,
sizeof (ipv4_str),
"%u.%u.%u.%u", (
unsigned char) ipv4_p[0], (
unsigned char) ipv4_p[1],
5627 (
unsigned char) ipv4_p[2], (
unsigned char) ipv4_p[3]);
5649 int rv, buf_size = 0, required_size = 0;
5653 if (hb_Resource ==
NULL)
5665 required_size += 10;
5667 buf_size += required_size;
5670 required_size += 256;
5671 required_size += 10;
5681 required_size += 64;
5683 required_size += 64;
5685 required_size += 64;
5687 required_size += 64;
5692 required_size *= hb_Resource->
num_procs;
5693 buf_size += required_size;
5695 *str = (
char *) malloc (
sizeof (
char) * buf_size);
5704 p = (
char *) (*str);
5705 last = p + buf_size;
5711 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
5775 int max_retries, wait_time_in_secs;
5776 int signum = SIGTERM;
5780 wait_time_in_secs = 3;
5781 for (i = 0; i < max_retries; i++)
5784 for (j = 0; j <
count; j++)
5788 error = kill (pids[j], signum);
5789 if (error && errno == ESRCH)
5799 if (finished ==
true)
5807 for (j = 0; j <
count; j++)
5811 kill (pids[j], SIGKILL);
5832 if (hb_Resource ==
NULL)
5841 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
5845 size =
sizeof (pid_t) * (count + 1);
5846 pids = (pid_t *) realloc (pids, size);
5859 for (i = 0; i <
count; i++)
5880 char error_string[LINE_MAX] =
"";
5882 if (hb_Resource ==
NULL)
5892 snprintf (error_string, LINE_MAX,
"%s. (cannot find process to deregister, pid:%d)",
HB_RESULT_FAILURE_STR, pid);
5930 char error_string[LINE_MAX] =
"";
5932 if (hb_Resource ==
NULL)
5942 snprintf (error_string, LINE_MAX,
"%s. (cannot find process to deregister, args:%s)",
HB_RESULT_FAILURE_STR,
5974 char error_string[LINE_MAX] =
"";
5978 snprintf (error_string, LINE_MAX,
"%s. (unexpected process status or invalid pid, status:%d, pid:%d)",
5987 if (job_arg ==
NULL)
5994 proc_arg->
pid = proc->
pid;
5995 memcpy ((
void *) &proc_arg->
args[0], proc->
args, sizeof (proc_arg->
args));
6015 char error_string[LINE_MAX] =
"";
6020 snprintf (error_string, LINE_MAX,
"%s. (failed to reload CUBRID heartbeat configuration)",
HB_RESULT_FAILURE_STR);
6030 snprintf (error_string, LINE_MAX,
"\n%s", (str && *str) ? *str :
"");
6047 char error_string[LINE_MAX] =
"";
6049 if (hb_Cluster ==
NULL || hb_Resource ==
NULL)
6072 snprintf (error_string, LINE_MAX,
"CUBRID heartbeat starts to shutdown all HA processes.");
6088 char error_string[LINE_MAX] =
"";
6090 if (hb_Cluster ==
NULL)
6097 snprintf (error_string, LINE_MAX,
"%s. (CUBRID heartbeat feature already deactivated)",
HB_RESULT_FAILURE_STR);
6103 if (hb_Resource !=
NULL && resource_Jobs !=
NULL)
6108 if (hb_Cluster !=
NULL && cluster_Jobs !=
NULL)
6131 char error_string[LINE_MAX] =
"";
6133 if (hb_Cluster ==
NULL)
6141 snprintf (error_string, LINE_MAX,
"%s. (CUBRID heartbeat feature is being deactivated)",
HB_RESULT_FAILURE_STR);
6148 snprintf (error_string, LINE_MAX,
"%s. (CUBRID heartbeat feature already activated)",
HB_RESULT_FAILURE_STR);
6156 snprintf (error_string, LINE_MAX,
"%s. (failed to initialize CUBRID heartbeat feature)",
HB_RESULT_FAILURE_STR);
6180 char error_string[LINE_MAX] =
"";
6185 int i, num_args = 0;
6190 if (hb_Resource ==
NULL)
6201 snprintf (error_string, LINE_MAX,
"%s. (process already running, args:%s)",
HB_RESULT_FAILURE_STR, args);
6217 memset (argvp, 0,
sizeof (argvp));
6218 memset (argvs, 0,
sizeof (argvs));
6219 s = strtok_r (args,
" \t\n", &save);
6223 s = strtok_r (
NULL,
" \t\n", &save);
6226 for (i = 0; i < num_args; i++)
6228 argvp[
i] = argvs[
i];
6232 (void) execv (executable_path, argvp);
6270 const char *event_name;
6272 struct timeval curr_time;
6285 event_name =
"DEMOTE ON DISK FAILURE";
6289 event_name =
"REMOTE STOP";
6302 gettimeofday (&curr_time,
NULL);
6304 p += snprintf (p, MAX ((last - p), 0),
"[%s][%s]",
hb_strtime (time_str,
sizeof (time_str), &curr_time), event_name);
6306 if (msg_fmt !=
NULL)
6308 va_start (args, msg_fmt);
6309 vsnprintf (p, MAX ((last - p), 0), msg_fmt, args);
6325 #define PING_COMMAND_FORMAT \ 6326 "ping -w 1 -c 1 %s >/dev/null 2>&1; " \ 6329 char ping_command[256], result_str[16];
6338 for (node = hb_Cluster->
nodes; node; node = node->
next)
6343 snprintf (buf,
sizeof (buf),
"Useless PING host name %s", host);
6350 fp = popen (ping_command,
"r");
6358 if (fgets (result_str,
sizeof (result_str), fp) ==
NULL)
6365 result_str[
sizeof (result_str) - 1] = 0;
6369 result =
str_to_int32 (&ping_result, &end_p, result_str, 10);
6370 if (result != 0 || ping_result !=
NO_ERROR)
6373 snprintf (buf,
sizeof (buf),
"PING failed for host %s", host);
6388 if (*buffer !=
'\0')
6390 memset (buffer, 0, max_length);
6394 last = buffer + max_length;
6396 p += snprintf (p, MAX ((last - p), 0),
"HA Ping Host Info\n");
6398 snprintf (p, MAX ((last - p), 0),
6399 "==============================" "==================================================\n");
6402 snprintf (p, MAX ((last - p), 0),
" * PING check is %s\n",
6405 snprintf (p, MAX ((last - p), 0),
6406 "------------------------------" "--------------------------------------------------\n");
6407 p += snprintf (p, MAX ((last - p), 0),
"%-20s %-20s\n",
"hostname",
"PING check result");
6409 snprintf (p, MAX ((last - p), 0),
6410 "------------------------------" "--------------------------------------------------\n");
6411 for (ping_host = hb_Cluster->
ping_hosts; ping_host; ping_host = ping_host->
next)
6414 snprintf (p, MAX ((last - p), 0),
"%-20s %-20s\n", ping_host->
host_name,
6418 snprintf (p, MAX ((last - p), 0),
6419 "==============================" "==================================================\n");
6430 if (*buffer !=
'\0')
6432 memset (buffer, 0, max_length);
6436 last = buffer + max_length;
6438 p += snprintf (p, MAX ((last - p), 0),
"HA Node Info\n");
6440 snprintf (p, MAX ((last - p), 0),
6441 "==============================" "==================================================\n");
6443 snprintf (p, MAX ((last - p), 0),
" * group_id : %s host_name : %s state : %s \n", hb_Cluster->
group_id,
6446 snprintf (p, MAX ((last - p), 0),
6447 "------------------------------" "--------------------------------------------------\n");
6449 snprintf (p, MAX ((last - p), 0),
"%-20s %-10s %-15s %-10s %-20s\n",
"name",
"priority",
"state",
"score",
6450 "missed heartbeat");
6452 snprintf (p, MAX ((last - p), 0),
6453 "------------------------------" "--------------------------------------------------\n");
6455 for (node = hb_Cluster->
nodes; node; node = node->
next)
6458 snprintf (p, MAX ((last - p), 0),
"%-20s %-10u %-15s %-10d %-20d\n", node->
host_name, node->
priority,
6463 snprintf (p, MAX ((last - p), 0),
6464 "==============================" "==================================================\n");
6465 p += snprintf (p, MAX ((last - p), 0),
"\n");
6476 if (*buffer !=
'\0')
6478 memset (buffer, 0, max_length);
6482 last = p + max_length;
6484 p += snprintf (p, MAX ((last - p), 0),
"HA Process Info\n");
6487 snprintf (p, MAX ((last - p), 0),
6488 "==============================" "==================================================\n");
6491 snprintf (p, MAX ((last - p), 0),
6492 "------------------------------" "--------------------------------------------------\n");
6493 p += snprintf (p, MAX ((last - p), 0),
"%-10s %-22s %-15s %-10s\n",
"pid",
"state",
"type",
"socket fd");
6494 p += snprintf (p, MAX ((last - p), 0),
" %-30s %-35s\n",
"exec-path",
"args");
6496 snprintf (p, MAX ((last - p), 0),
6497 "------------------------------" "--------------------------------------------------\n");
6499 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
6507 snprintf (p, MAX ((last - p), 0),
"%-10d %-22s %-15s %-10d\n", proc->
pid,
6509 p += snprintf (p, MAX ((last - p), 0),
" %-30s %-35s\n", proc->
exec_path, proc->
args);
6513 snprintf (p, MAX ((last - p), 0),
6514 "==============================" "==================================================\n");
6515 p += snprintf (p, MAX ((last - p), 0),
"\n");
6527 p = (
char *) &buffer[0];
6528 last = p +
sizeof (buffer);
6530 p += snprintf (p, MAX ((last - p), 0),
"HA Job Info\n");
6532 snprintf (p, MAX ((last - p), 0),
6533 "==============================" "==================================================\n");
6534 p += snprintf (p, MAX ((last - p), 0),
"%-10s %-20s %-20s %-20s\n",
"type",
"func",
"arg",
"expire");
6536 snprintf (p, MAX ((last - p), 0),
6537 "------------------------------" "--------------------------------------------------\n");
6540 for (job = jobs->
jobs; job; job = job->
next)
6543 snprintf (p, MAX ((last - p), 0),
"%-10d %-20p %-20p %-10d.%-10d\n", job->
type, (
void *) job->
func,
6544 (
void *) job->
arg, (
unsigned int) job->
expire.tv_sec, (
unsigned int) job->
expire.tv_usec);
6550 snprintf (p, MAX ((last - p), 0),
6551 "==============================" "==================================================\n");
6552 p += snprintf (p, MAX ((last - p), 0),
"\n");
6561 struct sockaddr_in req_addr;
6562 struct in_addr node_addr;
6563 socklen_t req_addr_len;
6566 req_addr_len =
sizeof (req_addr);
6568 if (getpeername (sd, (
struct sockaddr *) &req_addr, &req_addr_len) < 0)
6574 if (req_addr.sin_family == AF_UNIX)
6582 for (node = hb_Cluster->
nodes; node; node = node->
next)
6592 if (memcmp (&req_addr.sin_addr, &node_addr, sizeof (
struct in_addr)) == 0)
6636 for (proc = hb_Resource->
procs; proc; proc = proc->
next)
6659 int i, num_active_server = 0;
6667 if (kill (hb_Deactivate_info.
server_pid_list[i], 0) && errno == ESRCH)
6674 num_active_server++;
6679 return num_active_server;
6717 if (hb_Resource ==
NULL)
6730 state = (int) proc->
state;
6753 if (hb_Resource ==
NULL)
static void hb_resource_job_change_mode(HB_JOB_ARG *arg)
static void hb_cluster_job_failover(HB_JOB_ARG *arg)
#define HB_PSTATE_REGISTERED_AND_STANDBY_STR
#define SLEEP_MILISEC(sec, msec)
static void hb_resource_send_get_eof(void)
struct hbp_proc_register HBP_PROC_REGISTER
static void hb_resource_demote_kill_server_proc(void)
void hb_finish_deactivate_server_info(void)
#define HB_PSTATE_REGISTERED_AND_ACTIVE_STR
static int hb_check_ping(const char *host)
#define HB_TEMP_CHECK_VALID_PING_SERVER_INTERVAL_IN_MSECS
#define HB_PSTATE_NOT_REGISTERED_STR
static void * hb_thread_check_disk_failure(void *arg)
static void hb_resource_job_cleanup_all(HB_JOB_ARG *arg)
#define HB_VALID_NO_ERROR_STR
struct timeval last_recv_hbtime
#define HA_NODE_SCORE_FORMAT_STRING
#define HA_ADMIN_INFO_FORMAT_STRING
unsigned short changemode_gap
int hb_start_util_process(char *args)
#define HB_PING_SUCCESS_STR
static int hb_help_sprint_ping_host_info(char *buffer, int max_length)
#define ER_CSS_PTHREAD_ATTR_SETDETACHSTATE
#define HB_MAX_PING_CHECK
static int hb_help_sprint_jobs_info(HB_JOB *jobs, char *buffer, int max_length)
#define HB_MAX_CHANGEMODE_DIFF_TO_KILL
HB_CLUSTER_JOB_ARG cluster_job_arg
#define PING_COMMAND_FORMAT
static void hb_cluster_job_heartbeat(HB_JOB_ARG *arg)
static void hb_list_move(HB_LIST **dest_pp, HB_LIST **source_pp)
static char hb_Nolog_event_msg[LINE_MAX]
void hb_deregister_by_args(char *args)
static bool hb_cluster_is_received_heartbeat_from_all(void)
static HB_JOB_ENTRY * hb_job_dequeue(HB_JOB *jobs)
void hb_get_admin_info_string(char **str)
#define HA_PROCESS_REGISTER_TIME_FORMAT_STRING
#define pthread_mutex_init(a, b)
void LSA_COPY(log_lsa *plsa1, const log_lsa *plsa2)
static HB_JOB_FUNC hb_resource_jobs[]
char host_name[CUB_MAXHOSTNAMELEN]
bool is_curr_eof_received
static void hb_remove_ping_host(HB_PING_HOST_ENTRY *entry_p)
static int hb_resource_send_changemode(HB_PROC_ENTRY *proc)
unsigned int htonl(unsigned int from)
void hb_reconfig_heartbeat(char **str)
HB_PING_HOST_ENTRY ** prev
int hb_activate_heartbeat(void)
void hb_kill_all_heartbeat_process(char **str)
#define pthread_mutex_unlock(a)
#define HB_NODE_SCORE_MASTER
#define HB_PSTATE_UNKNOWN_STR
static const char * hb_strtime(char *s, unsigned int max, struct timeval *tv_p)
void(* HB_JOB_FUNC)(HB_JOB_ARG *)
void css_remove_entry_by_conn(CSS_CONN_ENTRY *conn_p, SOCKET_QUEUE_ENTRY **anchor_p)
#define HB_NODE_SCORE_UNKNOWN
bool are_hostnames_equal(const char *hostname_a, const char *hostname_b)
static int hb_cluster_calc_score(void)
static void hb_remove_all_procs(HB_PROC_ENTRY *first)
#define assert_release(e)
HB_RESOURCE_JOB_ARG resource_job_arg
static bool hb_resource_check_server_log_grow(void)
static int hb_cluster_load_ping_host_list(char *ha_ping_host_list)
#define ER_CSS_PTHREAD_CREATE
void hb_register_new_process(CSS_CONN_ENTRY *conn)
static int hb_hostname_to_sin_addr(const char *host, struct in_addr *addr)
static void hb_resource_job_proc_start(HB_JOB_ARG *arg)
pthread_mutex_t css_Master_socket_anchor_lock
#define OR_ALIGNED_BUF(size)
static const char * hb_node_state_string(int nstate)
#define HB_VALID_CANNOT_RESOLVE_HOST_STR
#define MASTER_TO_SRV_MSG_SIZE
#define HA_PROCESS_DEREGISTER_TIME_FORMAT_STRING
#define HB_PSTATE_REGISTERED_STR
#define LSA_AS_ARGS(lsa_ptr)
void css_process_start_shutdown(SOCKET_QUEUE_ENTRY *sock_entq, int timeout, char *buffer)
char host_name[CUB_MAXHOSTNAMELEN]
#define OR_ALIGNED_BUF_SIZE(abuf)
static int hb_resource_job_initialize(void)
char args[HB_MAX_SZ_PROC_ARGS]
#define PTR_ALIGN(addr, boundary)
#define HA_ADMIN_INFO_NOLOG_FORMAT_STRING
int css_receive_heartbeat_data(CSS_CONN_ENTRY *conn, char *data, int size)
char * or_unpack_log_lsa(char *ptr, struct log_lsa *lsa)
#define HB_PROC_RECOVERY_DELAY_TIME
#define HB_PSTATE_REGISTERED_AND_TO_BE_STANDBY_STR
#define ERR_CSS_TCP_HOST_NAME_ERROR
#define HA_COPYLOG_PROCESS_FORMAT_STRING
static void * hb_thread_resource_worker(void *arg)
static void hb_resource_cleanup(void)
#define HB_PING_FAILURE_STR
#define HB_DISK_FAILURE_CHECK_TIMER_IN_MSECS
static void hb_remove_ui_node(HB_UI_NODE_ENTRY *node)
void hb_enable_er_log(void)
static const char * hb_valid_result_string(int v_result)
static pthread_mutex_t gethostbyname_lock
static void hb_resource_job_demote_confirm_shutdown(HB_JOB_ARG *arg)
static int hb_cluster_send_heartbeat_resp(struct sockaddr_in *saddr, socklen_t saddr_len, char *dest_host_name)
#define HB_RESULT_FAILURE_STR
int hb_return_proc_state_by_fd(int sfd)
static void hb_cluster_remove_all_ui_nodes(HB_UI_NODE_ENTRY *first)
#define OR_ALIGNED_BUF_START(abuf)
#define MASTER_ER_SET_WITH_OSERROR(...)
#define HB_UI_NODE_CACHE_TIME_IN_MSECS
static void hb_cluster_job_init(HB_JOB_ARG *arg)
int css_send_heartbeat_data(CSS_CONN_ENTRY *conn, const char *data, int size)
char host_name[CUB_MAXHOSTNAMELEN]
UINT64 prm_get_bigint_value(PARAM_ID prm_id)
static void * hb_thread_cluster_worker(void *arg)
static void hb_list_remove(HB_LIST *n)
#define HB_PING_UNKNOWN_STR
#define HB_CMD_UTIL_START_STR
static HB_UI_NODE_ENTRY * hb_return_ui_node(char *host_name, char *group_id, struct sockaddr_in saddr)
#define HA_NODE_FORMAT_STRING
char host_name[CUB_MAXHOSTNAMELEN]
static int hb_cluster_initialize(const char *nodes, const char *replicas)
static void hb_resource_demote_start_shutdown_server_proc(void)
static void hb_remove_proc(HB_PROC_ENTRY *entry_p)
static void hb_cluster_job_check_valid_ping_server(HB_JOB_ARG *arg)
static void hb_cluster_job_demote(HB_JOB_ARG *arg)
int prm_get_integer_value(PARAM_ID prm_id)
#define HB_VALID_UNIDENTIFIED_NODE_STR
void hb_resource_receive_changemode(CSS_CONN_ENTRY *conn)
void css_master_cleanup(int sig)
char group_id[HB_MAX_GROUP_ID_LEN]
static bool hb_cluster_is_isolated(void)
static int hb_cluster_job_set_expire_and_reorder(unsigned int job_type, unsigned int msec)
#define ER_OUT_OF_VIRTUAL_MEMORY
void hb_start_deactivate_server_info(void)
static void hb_resource_job_demote_start_shutdown(HB_JOB_ARG *arg)
#define HB_MAX_SZ_PROC_ARGS
static void hb_cluster_remove_all_nodes(HB_NODE_ENTRY *first)
static int hb_thread_initialize(void)
static char executable_path[PATH_MAX]
static void hb_cluster_cleanup(void)
#define ER_CSS_PTHREAD_ATTR_SETSCOPE
const char * css_ha_server_state_string(HA_SERVER_STATE state)
void hb_resource_receive_get_eof(CSS_CONN_ENTRY *conn)
#define ER_HA_GENERIC_ERROR
#define ER_HB_PROCESS_EVENT
bool hb_is_registered_process(CSS_CONN_ENTRY *conn, char *args)
#define ERR_CSS_CANNOT_FORK
#define ERR_CSS_TCP_DATAGRAM_BIND
#define HA_PROCESS_START_TIME_FORMAT_STRING
const char * db_error_string(int level)
void hb_resource_shutdown_and_cleanup(void)
static int hb_help_sprint_nodes_info(char *buffer, int max_length)
static HB_NODE_ENTRY * hb_return_node_by_name_except_me(char *name)
#define HB_PING_SYS_ERR_STR
char * envvar_bindir_file(char *path, size_t size, const char *filename)
int sysprm_reload_and_init(const char *db_name, const char *conf_file)
static void * hb_thread_cluster_reader(void *arg)
#define HA_PROCESS_EXEC_PATH_FORMAT_STRING
#define HB_CMD_RELOAD_STR
void hb_get_process_info_string(char **str, bool verbose_yn)
#define HB_CMD_DEACTIVATE_STR
bool hb_is_deactivation_ready(void)
static int hb_cluster_send_heartbeat_internal(struct sockaddr_in *saddr, socklen_t saddr_len, char *dest_host_name, bool is_req)
int str_to_int32(int *ret_p, char **end_p, const char *str_p, int base)
#define strncpy_bufsize(buf, str)
static void hb_add_timeval(struct timeval *tv_p, unsigned int msec)
static void hb_cluster_request_heartbeat_to_all(void)
static HB_UI_NODE_ENTRY * hb_add_ui_node(char *host_name, char *group_id, struct sockaddr_in saddr, int state)
bool hb_is_hang_process(int sfd)
char exec_path[HB_MAX_SZ_PROC_EXEC_PATH]
#define HB_IS_INITIALIZED_TIME(arg_time)
#define ER_HB_COMMAND_EXECUTION
static HB_PROC_ENTRY * hb_return_proc_by_fd(int sfd)
unsigned short htons(unsigned short from)
bool LSA_ISNULL(const log_lsa *lsa_ptr)
static HB_JOB_ENTRY * hb_cluster_job_dequeue(void)
static HB_NODE_ENTRY * hb_add_node_to_cluster(char *host_name, unsigned short priority)
static void hb_cluster_job_calc_score(HB_JOB_ARG *arg)
char * or_unpack_int(char *ptr, int *number)
#define HB_MAX_WAIT_FOR_NEW_MASTER
static int hb_job_queue(HB_JOB *jobs, unsigned int job_type, HB_JOB_ARG *arg, unsigned int msec)
#define HA_PING_HOSTS_FORMAT_STRING
static void hb_resource_job_shutdown(void)
#define HB_MAX_SZ_PROC_EXEC_PATH
static void hb_list_add(HB_LIST **p, HB_LIST *n)
static void hb_resource_job_proc_dereg(HB_JOB_ARG *arg)
#define OR_LOG_LSA_ALIGNED_SIZE
static HB_PING_HOST_ENTRY * hb_add_ping_host(char *host_name)
#define HB_RESULT_SUCCESS_STR
static void hb_cluster_job_check_ping(HB_JOB_ARG *arg)
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
static const char * hb_ping_result_string(int ping_result)
static bool hb_resource_demote_confirm_shutdown_server_proc(void)
#define ER_CSS_PTHREAD_ATTR_INIT
HB_PING_HOST_ENTRY * next
bool is_ping_check_enabled
#define MASTER_ER_LOG_DEBUG(...)
#define ER_BO_UNABLE_TO_FIND_HOSTNAME
static void hb_kill_process(pid_t *pids, int count)
#define HA_NODE_HEARTBEAT_GAP_FORMAT_STRING
#define HB_NODE_SCORE_SLAVE
int css_send_heartbeat_request(CSS_CONN_ENTRY *conn, int command)
void hb_disable_er_log(int reason, const char *msg_fmt,...)
#define HA_NODE_INFO_FORMAT_STRING
static HB_PROC_ENTRY * hb_return_proc_by_pid(int pid)
HB_RESOURCE * hb_Resource
static void error(const char *msg)
#define MASTER_ER_SET(...)
char * or_pack_int(char *ptr, int number)
static void hb_cluster_job_shutdown(void)
#define HB_PSTATE_REGISTERED_AND_TO_BE_ACTIVE_STR
#define HB_MAX_GROUP_ID_LEN
static HB_JOB_ENTRY * hb_resource_job_dequeue(void)
#define HB_PSTATE_DEAD_STR
#define HB_MAX_NUM_PROC_ARGV
static const char * hb_process_state_string(unsigned char ptype, int pstate)
static int hb_resource_job_queue(unsigned int job_type, HB_JOB_ARG *arg, unsigned int msec)
unsigned short ntohs(unsigned short from)
#define HA_PROCESS_SHUTDOWN_TIME_FORMAT_STRING
#define HB_JOB_TIMER_WAIT_100_MILLISECOND
bool hb_Deactivate_immediately
#define HB_JOB_TIMER_WAIT_A_SECOND
enum HB_NODE_STATE HB_NODE_STATE_TYPE
const char * hb_process_type_string(int ptype)
#define free_and_init(ptr)
static bool hb_Is_activated
#define HB_VALID_IP_ADDR_MISMATCH_STR
char * prm_get_string_value(PARAM_ID prm_id)
void LSA_SET_NULL(log_lsa *lsa_ptr)
static HB_JOB_FUNC hb_cluster_jobs[]
#define HB_PSTATE_DEREGISTERED_STR
#define HB_MAX_CHANGEMODE_DIFF_TO_TERM
#define HB_JOB_TIMER_IMMEDIATELY
static void hb_remove_node(HB_NODE_ENTRY *entry_p)
static void hb_resource_job_confirm_start(HB_JOB_ARG *arg)
char group_id[HB_MAX_GROUP_ID_LEN]
bool LSA_GT(const log_lsa *plsa1, const log_lsa *plsa2)
static int hb_cluster_job_initialize(void)
static HB_JOB_ARG * hb_deregister_process(HB_PROC_ENTRY *proc)
void hb_cluster_shutdown_and_cleanup(void)
static int hb_cluster_send_heartbeat_req(char *dest_host_name)
bool prm_get_bool_value(PARAM_ID prm_id)
int hb_get_deactivating_server_count(void)
int util_log_write_errstr(const char *format,...)
#define HB_PSTATE_STARTED_STR
static HB_PROC_ENTRY * hb_alloc_new_proc(void)
struct hbp_header HBP_HEADER
#define HB_PING_USELESS_HOST_STR
#define HA_UI_NODE_FORMAT_STRING
static void hb_resource_shutdown_all_ha_procs(void)
SOCKET_QUEUE_ENTRY * css_return_entry_by_conn(CSS_CONN_ENTRY *conn_p, SOCKET_QUEUE_ENTRY **anchor_p)
int hb_deactivate_heartbeat(void)
static void hb_resource_job_confirm_cleanup_all(HB_JOB_ARG *arg)
static HB_PROC_ENTRY * hb_return_proc_by_args(char *args)
static int hb_hostname_n_port_to_sockaddr(const char *host, int port, struct sockaddr *saddr, socklen_t *slen)
#define HB_CMD_DEREGISTER_STR
char * msgcat_message(int cat_id, int set_id, int msg_id)
int hb_check_request_eligibility(SOCKET sd)
static void hb_cluster_job_failback(HB_JOB_ARG *arg)
const char * prm_get_name(PARAM_ID prm_id)
static int hb_set_net_header(HBP_HEADER *header, unsigned char type, bool is_req, unsigned short len, unsigned int seq, char *dest_host_name)
void hb_deregister_by_pid(pid_t pid)
static HB_DEACTIVATE_INFO hb_Deactivate_info
static void hb_cleanup_ui_nodes(HB_UI_NODE_ENTRY *first)
#define ER_CSS_PTHREAD_ATTR_SETSTACKSIZE
static int hb_cluster_job_queue(unsigned int job_type, HB_JOB_ARG *arg, unsigned int msec)
void hb_get_ping_host_info_string(char **str)
static int hb_resource_initialize(void)
static bool hb_cluster_check_valid_ping_server(void)
char * strdup(const char *str)
static int hb_help_sprint_processes_info(char *buffer, int max_length)
#define HB_VALID_GROUP_NAME_MISMATCH_STR
#define HB_JOB_TIMER_WAIT_500_MILLISECOND
#define pthread_mutex_lock(a)
#define HB_NODE_SCORE_TO_BE_MASTER
#define HA_PROCESS_ARGV_FORMAT_STRING
int hb_prepare_deactivate_heartbeat(void)
unsigned int ping_check_count
HB_UI_NODE_ENTRY * ui_nodes
unsigned int ntohl(unsigned int from)
#define ER_CSS_PTHREAD_ATTR_DESTROY
enum ha_server_state HA_SERVER_STATE
#define HB_UI_NODE_CLEANUP_TIME_IN_MSECS
#define HB_REPLICA_PRIORITY
#define HB_GET_ELAPSED_TIME(end_time, start_time)
static void hb_cluster_receive_heartbeat(char *buffer, int len, struct sockaddr_in *from, socklen_t from_len)
static void hb_job_shutdown(HB_JOB *jobs)
pthread_mutex_t css_Master_er_log_enable_lock
static int hb_compare_timeval(struct timeval *arg1, struct timeval *arg2)
#define HA_PING_HOSTS_INFO_FORMAT_STRING
bool css_Master_er_log_enabled
#define CUB_MAXHOSTNAMELEN
static void hb_resource_job_confirm_dereg(HB_JOB_ARG *arg)
#define HB_MAX_SZ_PROC_ARGV
#define HA_SERVER_PROCESS_FORMAT_STRING
static int hb_cluster_load_group_and_node_list(char *ha_node_list, char *ha_replica_list)
bool hb_is_deactivation_started(void)
static void hb_job_set_expire_and_reorder(HB_JOB *jobs, unsigned int job_type, unsigned int msec)
char exec_path[HB_MAX_SZ_PROC_EXEC_PATH]
#define HA_APPLYLOG_PROCESS_FORMAT_STRING
#define HB_CMD_ACTIVATE_STR
char args[HB_MAX_SZ_PROC_ARGS]
struct timeval last_recv_time
HB_PING_HOST_ENTRY * ping_hosts
static HB_NODE_ENTRY * hb_return_node_by_name(char *name)
static void hb_cluster_remove_all_ping_hosts(HB_PING_HOST_ENTRY *first)
#define HA_PROCESS_INFO_FORMAT_STRING
static void hb_proc_make_arg(char **arg, char *args)
#define GETHOSTNAME(p, l)
SOCKET_QUEUE_ENTRY * css_Master_socket_anchor
static int hb_reload_config(void)
#define ERR_CSS_TCP_DATAGRAM_SOCKET
void hb_get_node_info_string(char **str, bool verbose_yn)
static int hb_is_heartbeat_valid(char *host_name, char *group_id, struct sockaddr_in *from)
#define HA_ADMIN_INFO_NOLOG_EVENT_FORMAT_STRING
#define HB_DEFAULT_CHECK_VALID_PING_SERVER_INTERVAL_IN_MSECS
void hb_cleanup_conn_and_start_process(CSS_CONN_ENTRY *conn, SOCKET sfd)
char args[HB_MAX_SZ_PROC_ARGS]
static int hb_resource_job_set_expire_and_reorder(unsigned int job_type, unsigned int msec)
#define MSGCAT_CATALOG_UTILS