CUBRID Engine  latest
master_heartbeat.h File Reference
#include "heartbeat.h"
#include "log_lsa.hpp"
#include "master_util.h"
#include "porting.h"
#include "system_parameter.h"
Include dependency graph for master_heartbeat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hb_list
 
struct  hb_node_entry
 
struct  hb_ping_host_entry
 
struct  hb_ui_node_entry
 
struct  hb_cluster
 
struct  HB_PROC_ENTRY
 
struct  hb_resource
 
struct  hb_cluster_job_arg
 
struct  hb_resource_job_arg
 
union  hb_job_arg
 
struct  hb_job_entry
 
struct  hb_job
 

Macros

#define HB_PING_UNKNOWN_STR   "UNKNOWN"
 
#define HB_PING_SUCCESS_STR   "SUCCESS"
 
#define HB_PING_USELESS_HOST_STR   "SKIPPED"
 
#define HB_PING_SYS_ERR_STR   "ERROR"
 
#define HB_PING_FAILURE_STR   "FAILURE"
 
#define HB_PING_STR_SIZE   (7)
 
#define HB_PSTATE_UNKNOWN_STR   "unknown"
 
#define HB_PSTATE_DEAD_STR   "dead"
 
#define HB_PSTATE_DEREGISTERED_STR   "deregistered"
 
#define HB_PSTATE_STARTED_STR   "started"
 
#define HB_PSTATE_NOT_REGISTERED_STR   "not_registered"
 
#define HB_PSTATE_REGISTERED_STR   "registered"
 
#define HB_PSTATE_REGISTERED_AND_STANDBY_STR   "registered_and_standby"
 
#define HB_PSTATE_REGISTERED_AND_TO_BE_STANDBY_STR   "registered_and_to_be_standby"
 
#define HB_PSTATE_REGISTERED_AND_ACTIVE_STR   "registered_and_active"
 
#define HB_PSTATE_REGISTERED_AND_TO_BE_ACTIVE_STR   "registered_and_to_be_active"
 
#define HB_PSTATE_STR_SZ   (32)
 
#define HB_REPLICA_PRIORITY   0x7FFF
 
#define HB_NODE_SCORE_MASTER   0x8000
 
#define HB_NODE_SCORE_TO_BE_MASTER   0xF000
 
#define HB_NODE_SCORE_SLAVE   0x0000
 
#define HB_NODE_SCORE_UNKNOWN   0x7FFF
 
#define HB_BUFFER_SZ   (4096)
 
#define HB_MAX_NUM_NODES   (8)
 
#define HB_MAX_NUM_RESOURCE_PROC   (16)
 
#define HB_MAX_PING_CHECK   (3)
 
#define HB_MAX_WAIT_FOR_NEW_MASTER   (60)
 
#define HB_MAX_CHANGEMODE_DIFF_TO_TERM   (12)
 
#define HB_MAX_CHANGEMODE_DIFF_TO_KILL   (24)
 
#define HB_RESULT_SUCCESS_STR   "Success"
 
#define HB_RESULT_FAILURE_STR   "Failure"
 
#define HB_CMD_ACTIVATE_STR   "activate"
 
#define HB_CMD_DEACTIVATE_STR   "deactivate"
 
#define HB_CMD_DEREGISTER_STR   "deregister"
 
#define HB_CMD_RELOAD_STR   "reload"
 
#define HB_CMD_UTIL_START_STR   "util process start"
 
#define HB_VALID_NO_ERROR_STR   "no_error"
 
#define HB_VALID_UNIDENTIFIED_NODE_STR   "unidentified_node"
 
#define HB_VALID_GROUP_NAME_MISMATCH_STR   "group_name_mismatch"
 
#define HB_VALID_IP_ADDR_MISMATCH_STR   "ip_addr_mismatch"
 
#define HB_VALID_CANNOT_RESOLVE_HOST_STR   "cannot_resolve_host_name"
 
#define HB_GET_ELAPSED_TIME(end_time, start_time)
 
#define HB_IS_INITIALIZED_TIME(arg_time)   ((arg_time.tv_sec == 0 && arg_time.tv_usec == 0) ? 1 : 0)
 
#define HB_PROC_RECOVERY_DELAY_TIME   (30* 1000) /* milli-second */
 
#define HB_UI_NODE_CLEANUP_TIME_IN_MSECS   (3600 * 1000)
 
#define HB_UI_NODE_CACHE_TIME_IN_MSECS   (60 * 1000)
 
#define HB_IPV4_STR_LEN   (16)
 

Typedefs

typedef struct hb_list HB_LIST
 
typedef struct hb_node_entry HB_NODE_ENTRY
 
typedef struct hb_ping_host_entry HB_PING_HOST_ENTRY
 
typedef struct hb_ui_node_entry HB_UI_NODE_ENTRY
 
typedef struct hb_cluster HB_CLUSTER
 
typedef struct hb_resource HB_RESOURCE
 
typedef struct hb_cluster_job_arg HB_CLUSTER_JOB_ARG
 
typedef struct hb_resource_job_arg HB_RESOURCE_JOB_ARG
 
typedef union hb_job_arg HB_JOB_ARG
 
typedef void(* HB_JOB_FUNC) (HB_JOB_ARG *)
 
typedef struct hb_job_entry HB_JOB_ENTRY
 
typedef struct hb_job HB_JOB
 

Enumerations

enum  HB_PING_RESULT {
  HB_PING_UNKNOWN = -1, HB_PING_SUCCESS = 0, HB_PING_USELESS_HOST = 1, HB_PING_SYS_ERR = 2,
  HB_PING_FAILURE = 3
}
 
enum  HB_CLUSTER_JOB {
  HB_CJOB_INIT = 0, HB_CJOB_HEARTBEAT = 1, HB_CJOB_CALC_SCORE = 2, HB_CJOB_CHECK_PING = 3,
  HB_CJOB_FAILOVER = 4, HB_CJOB_FAILBACK = 5, HB_CJOB_CHECK_VALID_PING_SERVER = 6, HB_CJOB_DEMOTE = 7,
  HB_CJOB_MAX
}
 
enum  HB_RESOURCE_JOB {
  HB_RJOB_PROC_START = 0, HB_RJOB_PROC_DEREG = 1, HB_RJOB_CONFIRM_START = 2, HB_RJOB_CONFIRM_DEREG = 3,
  HB_RJOB_CHANGE_MODE = 4, HB_RJOB_DEMOTE_START_SHUTDOWN = 5, HB_RJOB_DEMOTE_CONFIRM_SHUTDOWN = 6, HB_RJOB_CLEANUP_ALL = 7,
  HB_RJOB_CONFIRM_CLEANUP_ALL = 8, HB_RJOB_MAX
}
 
enum  HB_PROC_STATE {
  HB_PSTATE_UNKNOWN = 0, HB_PSTATE_DEAD = 1, HB_PSTATE_DEREGISTERED = 2, HB_PSTATE_STARTED = 3,
  HB_PSTATE_NOT_REGISTERED = 4, HB_PSTATE_REGISTERED = 5, HB_PSTATE_REGISTERED_AND_STANDBY = HB_PSTATE_REGISTERED, HB_PSTATE_REGISTERED_AND_TO_BE_STANDBY = 6,
  HB_PSTATE_REGISTERED_AND_ACTIVE = 7, HB_PSTATE_REGISTERED_AND_TO_BE_ACTIVE = 8, HB_PSTATE_MAX
}
 
enum  HB_HOST_CHECK_RESULT { HB_HC_ELIGIBLE_LOCAL, HB_HC_ELIGIBLE_REMOTE, HB_HC_UNAUTHORIZED, HB_HC_FAILED }
 
enum  HB_NOLOG_REASON { HB_NOLOG_DEMOTE_ON_DISK_FAIL, HB_NOLOG_REMOTE_STOP, HB_NOLOG_MAX = HB_NOLOG_REMOTE_STOP }
 
enum  HB_VALID_RESULT {
  HB_VALID_NO_ERROR = 0, HB_VALID_UNIDENTIFIED_NODE = 1, HB_VALID_GROUP_NAME_MISMATCH = 2, HB_VALID_IP_ADDR_MISMATCH = 3,
  HB_VALID_CANNOT_RESOLVE_HOST = 4
}
 

Functions

int hb_master_init (void)
 
void hb_resource_shutdown_and_cleanup (void)
 
void hb_cluster_shutdown_and_cleanup (void)
 
void hb_cleanup_conn_and_start_process (CSS_CONN_ENTRY *conn, SOCKET sfd)
 
void hb_get_node_info_string (char **str, bool verbose_yn)
 
void hb_get_process_info_string (char **str, bool verbose_yn)
 
void hb_get_ping_host_info_string (char **str)
 
void hb_get_admin_info_string (char **str)
 
void hb_kill_all_heartbeat_process (char **str)
 
void hb_deregister_by_pid (pid_t pid)
 
void hb_deregister_by_args (char *args)
 
void hb_reconfig_heartbeat (char **str)
 
int hb_prepare_deactivate_heartbeat (void)
 
int hb_deactivate_heartbeat (void)
 
int hb_activate_heartbeat (void)
 
bool hb_is_registered_process (CSS_CONN_ENTRY *conn, char *args)
 
void hb_register_new_process (CSS_CONN_ENTRY *conn)
 
void hb_resource_receive_changemode (CSS_CONN_ENTRY *conn)
 
void hb_resource_receive_get_eof (CSS_CONN_ENTRY *conn)
 
int hb_check_request_eligibility (SOCKET sd)
 
void hb_start_deactivate_server_info (void)
 
int hb_get_deactivating_server_count (void)
 
bool hb_is_deactivation_started (void)
 
bool hb_is_deactivation_ready (void)
 
void hb_finish_deactivate_server_info (void)
 
int hb_start_util_process (char *args)
 
void hb_enable_er_log (void)
 
void hb_disable_er_log (int reason, const char *msg_fmt,...)
 
int hb_return_proc_state_by_fd (int sfd)
 
bool hb_is_hang_process (int sfd)
 

Variables

HB_CLUSTERhb_Cluster
 
HB_RESOURCEhb_Resource
 
HB_JOBcluster_Jobs
 
HB_JOBresource_Jobs
 
bool hb_Deactivate_immediately
 

Macro Definition Documentation

#define HB_BUFFER_SZ   (4096)
#define HB_CMD_ACTIVATE_STR   "activate"

Definition at line 139 of file master_heartbeat.h.

Referenced by hb_activate_heartbeat().

#define HB_CMD_DEACTIVATE_STR   "deactivate"
#define HB_CMD_DEREGISTER_STR   "deregister"
#define HB_CMD_RELOAD_STR   "reload"

Definition at line 142 of file master_heartbeat.h.

Referenced by hb_reconfig_heartbeat().

#define HB_CMD_UTIL_START_STR   "util process start"

Definition at line 143 of file master_heartbeat.h.

Referenced by hb_start_util_process().

#define HB_GET_ELAPSED_TIME (   end_time,
  start_time 
)
Value:
((double)(end_time.tv_sec - start_time.tv_sec) * 1000 + \
(end_time.tv_usec - start_time.tv_usec)/1000.0)
static struct timeval start_time

Definition at line 176 of file master_heartbeat.h.

Referenced by hb_cleanup_conn_and_start_process(), hb_cleanup_ui_nodes(), hb_cluster_calc_score(), hb_cluster_is_received_heartbeat_from_all(), hb_get_node_info_string(), and hb_resource_job_proc_start().

#define HB_IPV4_STR_LEN   (16)

Definition at line 187 of file master_heartbeat.h.

Referenced by hb_get_node_info_string().

#define HB_IS_INITIALIZED_TIME (   arg_time)    ((arg_time.tv_sec == 0 && arg_time.tv_usec == 0) ? 1 : 0)

Definition at line 180 of file master_heartbeat.h.

Referenced by hb_cluster_calc_score().

#define HB_MAX_CHANGEMODE_DIFF_TO_KILL   (24)

Definition at line 133 of file master_heartbeat.h.

Referenced by hb_resource_send_changemode().

#define HB_MAX_CHANGEMODE_DIFF_TO_TERM   (12)

Definition at line 132 of file master_heartbeat.h.

Referenced by hb_resource_send_changemode().

#define HB_MAX_NUM_NODES   (8)

Definition at line 128 of file master_heartbeat.h.

#define HB_MAX_NUM_RESOURCE_PROC   (16)

Definition at line 129 of file master_heartbeat.h.

#define HB_MAX_PING_CHECK   (3)

Definition at line 130 of file master_heartbeat.h.

Referenced by hb_cluster_job_check_ping().

#define HB_MAX_WAIT_FOR_NEW_MASTER   (60)

Definition at line 131 of file master_heartbeat.h.

Referenced by hb_cluster_job_demote().

#define HB_NODE_SCORE_MASTER   0x8000

Definition at line 122 of file master_heartbeat.h.

Referenced by hb_cluster_calc_score().

#define HB_NODE_SCORE_SLAVE   0x0000

Definition at line 124 of file master_heartbeat.h.

Referenced by hb_cluster_calc_score().

#define HB_NODE_SCORE_TO_BE_MASTER   0xF000

Definition at line 123 of file master_heartbeat.h.

Referenced by hb_cluster_calc_score().

#define HB_NODE_SCORE_UNKNOWN   0x7FFF

Definition at line 125 of file master_heartbeat.h.

Referenced by hb_cluster_calc_score().

#define HB_PING_FAILURE_STR   "FAILURE"

Definition at line 58 of file master_heartbeat.h.

Referenced by hb_ping_result_string().

#define HB_PING_STR_SIZE   (7)

Definition at line 59 of file master_heartbeat.h.

Referenced by hb_get_ping_host_info_string().

#define HB_PING_SUCCESS_STR   "SUCCESS"

Definition at line 55 of file master_heartbeat.h.

Referenced by hb_ping_result_string().

#define HB_PING_SYS_ERR_STR   "ERROR"

Definition at line 57 of file master_heartbeat.h.

Referenced by hb_ping_result_string().

#define HB_PING_UNKNOWN_STR   "UNKNOWN"

Definition at line 54 of file master_heartbeat.h.

Referenced by hb_ping_result_string().

#define HB_PING_USELESS_HOST_STR   "SKIPPED"

Definition at line 56 of file master_heartbeat.h.

Referenced by hb_ping_result_string().

#define HB_PROC_RECOVERY_DELAY_TIME   (30* 1000) /* milli-second */

Definition at line 183 of file master_heartbeat.h.

Referenced by hb_resource_job_proc_start().

#define HB_PSTATE_DEAD_STR   "dead"

Definition at line 108 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_DEREGISTERED_STR   "deregistered"

Definition at line 109 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_NOT_REGISTERED_STR   "not_registered"

Definition at line 111 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_REGISTERED_AND_ACTIVE_STR   "registered_and_active"

Definition at line 115 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_REGISTERED_AND_STANDBY_STR   "registered_and_standby"

Definition at line 113 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_REGISTERED_AND_TO_BE_ACTIVE_STR   "registered_and_to_be_active"

Definition at line 116 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_REGISTERED_AND_TO_BE_STANDBY_STR   "registered_and_to_be_standby"

Definition at line 114 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_REGISTERED_STR   "registered"

Definition at line 112 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_STARTED_STR   "started"

Definition at line 110 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_PSTATE_STR_SZ   (32)

Definition at line 117 of file master_heartbeat.h.

Referenced by hb_get_process_info_string().

#define HB_PSTATE_UNKNOWN_STR   "unknown"

Definition at line 107 of file master_heartbeat.h.

Referenced by hb_process_state_string().

#define HB_REPLICA_PRIORITY   0x7FFF

Definition at line 119 of file master_heartbeat.h.

Referenced by hb_cluster_load_group_and_node_list().

#define HB_UI_NODE_CACHE_TIME_IN_MSECS   (60 * 1000)

Definition at line 186 of file master_heartbeat.h.

Referenced by hb_get_node_info_string().

#define HB_UI_NODE_CLEANUP_TIME_IN_MSECS   (3600 * 1000)

Definition at line 185 of file master_heartbeat.h.

Referenced by hb_cleanup_ui_nodes().

#define HB_VALID_CANNOT_RESOLVE_HOST_STR   "cannot_resolve_host_name"

Definition at line 173 of file master_heartbeat.h.

Referenced by hb_valid_result_string().

#define HB_VALID_GROUP_NAME_MISMATCH_STR   "group_name_mismatch"

Definition at line 171 of file master_heartbeat.h.

Referenced by hb_valid_result_string().

#define HB_VALID_IP_ADDR_MISMATCH_STR   "ip_addr_mismatch"

Definition at line 172 of file master_heartbeat.h.

Referenced by hb_valid_result_string().

#define HB_VALID_NO_ERROR_STR   "no_error"

Definition at line 169 of file master_heartbeat.h.

Referenced by hb_valid_result_string().

#define HB_VALID_UNIDENTIFIED_NODE_STR   "unidentified_node"

Definition at line 170 of file master_heartbeat.h.

Referenced by hb_valid_result_string().

Typedef Documentation

typedef struct hb_cluster HB_CLUSTER

Definition at line 240 of file master_heartbeat.h.

Definition at line 318 of file master_heartbeat.h.

typedef struct hb_job HB_JOB

Definition at line 367 of file master_heartbeat.h.

typedef union hb_job_arg HB_JOB_ARG

Definition at line 342 of file master_heartbeat.h.

typedef struct hb_job_entry HB_JOB_ENTRY

Definition at line 352 of file master_heartbeat.h.

typedef void(* HB_JOB_FUNC) (HB_JOB_ARG *)

Definition at line 349 of file master_heartbeat.h.

typedef struct hb_list HB_LIST

Definition at line 190 of file master_heartbeat.h.

typedef struct hb_node_entry HB_NODE_ENTRY

Definition at line 199 of file master_heartbeat.h.

Definition at line 215 of file master_heartbeat.h.

typedef struct hb_resource HB_RESOURCE

Definition at line 304 of file master_heartbeat.h.

Definition at line 326 of file master_heartbeat.h.

Definition at line 226 of file master_heartbeat.h.

Enumeration Type Documentation

Enumerator
HB_CJOB_INIT 
HB_CJOB_HEARTBEAT 
HB_CJOB_CALC_SCORE 
HB_CJOB_CHECK_PING 
HB_CJOB_FAILOVER 
HB_CJOB_FAILBACK 
HB_CJOB_CHECK_VALID_PING_SERVER 
HB_CJOB_DEMOTE 
HB_CJOB_MAX 

Definition at line 62 of file master_heartbeat.h.

Enumerator
HB_HC_ELIGIBLE_LOCAL 
HB_HC_ELIGIBLE_REMOTE 
HB_HC_UNAUTHORIZED 
HB_HC_FAILED 

Definition at line 145 of file master_heartbeat.h.

Enumerator
HB_NOLOG_DEMOTE_ON_DISK_FAIL 
HB_NOLOG_REMOTE_STOP 
HB_NOLOG_MAX 

Definition at line 153 of file master_heartbeat.h.

Enumerator
HB_PING_UNKNOWN 
HB_PING_SUCCESS 
HB_PING_USELESS_HOST 
HB_PING_SYS_ERR 
HB_PING_FAILURE 

Definition at line 45 of file master_heartbeat.h.

Enumerator
HB_PSTATE_UNKNOWN 
HB_PSTATE_DEAD 
HB_PSTATE_DEREGISTERED 
HB_PSTATE_STARTED 
HB_PSTATE_NOT_REGISTERED 
HB_PSTATE_REGISTERED 
HB_PSTATE_REGISTERED_AND_STANDBY 
HB_PSTATE_REGISTERED_AND_TO_BE_STANDBY 
HB_PSTATE_REGISTERED_AND_ACTIVE 
HB_PSTATE_REGISTERED_AND_TO_BE_ACTIVE 
HB_PSTATE_MAX 

Definition at line 93 of file master_heartbeat.h.

Enumerator
HB_RJOB_PROC_START 
HB_RJOB_PROC_DEREG 
HB_RJOB_CONFIRM_START 
HB_RJOB_CONFIRM_DEREG 
HB_RJOB_CHANGE_MODE 
HB_RJOB_DEMOTE_START_SHUTDOWN 
HB_RJOB_DEMOTE_CONFIRM_SHUTDOWN 
HB_RJOB_CLEANUP_ALL 
HB_RJOB_CONFIRM_CLEANUP_ALL 
HB_RJOB_MAX 

Definition at line 76 of file master_heartbeat.h.

Enumerator
HB_VALID_NO_ERROR 
HB_VALID_UNIDENTIFIED_NODE 
HB_VALID_GROUP_NAME_MISMATCH 
HB_VALID_IP_ADDR_MISMATCH 
HB_VALID_CANNOT_RESOLVE_HOST 

Definition at line 161 of file master_heartbeat.h.

Function Documentation

void hb_cleanup_conn_and_start_process ( CSS_CONN_ENTRY conn,
SOCKET  sfd 
)
void hb_cluster_shutdown_and_cleanup ( void  )

Definition at line 5128 of file master_heartbeat.c.

References hb_cluster_cleanup(), and hb_cluster_job_shutdown().

Referenced by css_process_kill_master(), and hb_deactivate_heartbeat().

Here is the caller graph for this function:

void hb_disable_er_log ( int  reason,
const char *  msg_fmt,
  ... 
)
void hb_enable_er_log ( void  )

Definition at line 6252 of file master_heartbeat.c.

References css_Master_er_log_enable_lock, css_Master_er_log_enabled, hb_Nolog_event_msg, pthread_mutex_lock, pthread_mutex_unlock, and rv.

Referenced by hb_master_init().

Here is the caller graph for this function:

void hb_finish_deactivate_server_info ( void  )
int hb_get_deactivating_server_count ( void  )
bool hb_is_deactivation_ready ( void  )
bool hb_is_deactivation_started ( void  )

Definition at line 6625 of file master_heartbeat.c.

References hb_deactivate_info::info_started.

Referenced by css_process_deact_stop_all(), and css_send_to_existing_server().

Here is the caller graph for this function:

bool hb_is_hang_process ( int  sfd)

Definition at line 6748 of file master_heartbeat.c.

References hb_return_proc_by_fd(), hb_resource::lock, NULL, pthread_mutex_lock, pthread_mutex_unlock, rv, and HB_PROC_ENTRY::server_hang.

Referenced by css_send_to_existing_server().

Here is the caller graph for this function:

bool hb_is_registered_process ( CSS_CONN_ENTRY conn,
char *  args 
)

Definition at line 3855 of file master_heartbeat.c.

References hb_return_proc_by_args(), hb_resource::lock, NULL, pthread_mutex_lock, pthread_mutex_unlock, and hb_resource::shutdown.

Referenced by css_process_is_registered_ha_proc().

Here is the caller graph for this function:

void hb_reconfig_heartbeat ( char **  str)
void hb_resource_shutdown_and_cleanup ( void  )

Definition at line 5066 of file master_heartbeat.c.

References hb_resource_cleanup(), and hb_resource_job_shutdown().

Referenced by css_process_kill_master(), and hb_deactivate_heartbeat().

Here is the caller graph for this function:

int hb_return_proc_state_by_fd ( int  sfd)
void hb_start_deactivate_server_info ( void  )

Definition at line 6611 of file master_heartbeat.c.

References assert, free_and_init, hb_deactivate_info::info_started, NULL, hb_deactivate_info::server_count, and hb_deactivate_info::server_pid_list.

Referenced by css_process_deact_stop_all().

Here is the caller graph for this function:

Variable Documentation

HB_JOB* cluster_Jobs

Definition at line 242 of file master_heartbeat.c.

Referenced by css_process_kill_master().

HB_CLUSTER* hb_Cluster

Definition at line 240 of file master_heartbeat.c.

Referenced by css_process_kill_master().

HB_RESOURCE* hb_Resource

Definition at line 241 of file master_heartbeat.c.

Referenced by css_process_kill_master().

HB_JOB* resource_Jobs

Definition at line 243 of file master_heartbeat.c.

Referenced by css_process_kill_master().