CUBRID Engine  latest
heartbeat.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * heartbeat.h -
22  */
23 
24 #ifndef _HEARTBEAT_H_
25 #define _HEARTBEAT_H_
26 
27 #ident "$Id$"
28 
29 #include "connection_defs.h"
30 
31 /* heartbeat */
32 #define HB_DEFAULT_HA_PORT_ID (59901)
33 #define HB_DEFAULT_APPLY_MAX_MEM_SIZE (500)
34 
35 #define HB_DEFAULT_INIT_TIMER_IN_MSECS (10*1000)
36 #define HB_DEFAULT_HEARTBEAT_INTERVAL_IN_MSECS (500)
37 #define HB_DEFAULT_CALC_SCORE_INTERVAL_IN_MSECS (3*1000)
38 #define HB_DEFAULT_CHECK_VALID_PING_SERVER_INTERVAL_IN_MSECS (1*60*60*1000)
39 #define HB_TEMP_CHECK_VALID_PING_SERVER_INTERVAL_IN_MSECS (5*60*1000)
40 #define HB_DEFAULT_FAILOVER_WAIT_TIME_IN_MSECS (3*1000)
41 #define HB_DEFAULT_START_CONFIRM_INTERVAL_IN_MSECS (3*1000)
42 #define HB_DEFAULT_DEREG_CONFIRM_INTERVAL_IN_MSECS (500)
43 #define HB_DEFAULT_MAX_PROCESS_START_CONFIRM (20)
44 #define HB_DEFAULT_MAX_PROCESS_DEREG_CONFIRM (120)
45 #define HB_DEFAULT_UNACCEPTABLE_PROC_RESTART_TIMEDIFF_IN_MSECS (2*60*1000)
46 #define HB_DEFAULT_CHANGEMODE_INTERVAL_IN_MSECS (5*1000)
47 #define HB_DEFAULT_MAX_HEARTBEAT_GAP (5)
48 #define HB_MIN_DIFF_CHECK_DISK_FAILURE_INTERVAL_IN_SECS (10)
49 
50 #define HB_JOB_TIMER_IMMEDIATELY (0)
51 #define HB_JOB_TIMER_WAIT_A_SECOND (1*1000)
52 #define HB_JOB_TIMER_WAIT_500_MILLISECOND (5*100)
53 #define HB_JOB_TIMER_WAIT_100_MILLISECOND (1*100)
54 #define HB_DISK_FAILURE_CHECK_TIMER_IN_MSECS (1*100)
55 
56 #define HB_START_WAITING_TIME_IN_SECS (10)
57 #define HB_STOP_WAITING_TIME_IN_SECS (1)
58 
59 /* heartbeat resource process type */
61 {
66 };
68 #define HB_PTYPE_SERVER_STR "HA-server"
69 #define HB_PTYPE_COPYLOGDB_STR "HA-copylogdb"
70 #define HB_PTYPE_APPLYLOGDB_STR "HA-applylogdb"
71 #define HB_PTYPE_STR_SZ (16)
72 
74 {
77 };
78 
79 #define HB_MAX_GROUP_ID_LEN (64)
80 #define HB_MAX_SZ_PROC_EXEC_PATH (128)
81 #define HB_MAX_NUM_PROC_ARGV (16)
82 #define HB_MAX_SZ_PROC_ARGV (64)
83 #define HB_MAX_SZ_PROC_ARGS (HB_MAX_NUM_PROC_ARGV*HB_MAX_SZ_PROC_ARGV)
84 
85 /* heartbeat node state */
87 {
95 };
96 
97 #define HB_NSTATE_UNKNOWN_STR "unknown"
98 #define HB_NSTATE_SLAVE_STR "slave"
99 #define HB_NSTATE_TO_BE_MASTER_STR "to-be-master"
100 #define HB_NSTATE_TO_BE_SLAVE_STR "to-be-slave"
101 #define HB_NSTATE_MASTER_STR "master"
102 #define HB_NSTATE_REPLICA_STR "replica"
103 
104 #define HB_NSTATE_STR_SZ (32)
105 
107 
108 /*
109  * heartbeat cluster message header and body
110  */
111 
112 /* heartbeat net header */
113 typedef struct hbp_header HBP_HEADER;
115 {
116  unsigned char type;
117 #if defined(HPUX) || defined(_AIX) || defined(sparc)
118  char r:1; /* is request? */
119  char reserved:7;
120 #else
121  char reserved:7;
122  char r:1; /* is request? */
123 #endif
124  unsigned short len;
125  unsigned int seq;
129 };
130 
131 
132 /*
133  * heartbeat resource message body
134  */
135 
136 /* process register */
139 {
140  int pid;
141  int type;
142  char exec_path[HB_MAX_SZ_PROC_EXEC_PATH];
144 };
145 
146 
147 /*
148  * externs
149  */
150 extern const char *hb_process_type_string (int ptype);
151 extern void hb_set_exec_path (char *exec_path);
152 extern void hb_set_argv (char **argv);
153 extern int css_send_heartbeat_request (CSS_CONN_ENTRY * conn, int command);
154 extern int css_send_heartbeat_data (CSS_CONN_ENTRY * conn, const char *data, int size);
155 extern int css_receive_heartbeat_request (CSS_CONN_ENTRY * conn, int *command);
156 extern int css_receive_heartbeat_data (CSS_CONN_ENTRY * conn, char *data, int size);
157 extern int hb_process_master_request (void);
158 extern int hb_register_to_master (CSS_CONN_ENTRY * conn, int type);
159 extern int hb_deregister_from_master (void);
160 extern int hb_process_init (const char *server_name, const char *log_path, HB_PROC_TYPE type);
161 extern void hb_process_term (void);
162 extern const char *hb_node_state_string (HB_NODE_STATE_TYPE nstate);
163 
164 extern bool hb_Proc_shutdown;
165 
166 #endif /* _HEARTBEAT_H_ */
unsigned int seq
Definition: heartbeat.h:125
int hb_process_master_request(void)
Definition: heartbeat.c:447
int css_receive_heartbeat_data(CSS_CONN_ENTRY *conn, char *data, int size)
Definition: heartbeat.c:230
int css_send_heartbeat_request(CSS_CONN_ENTRY *conn, int command)
Definition: heartbeat.c:151
hb_proc_type
Definition: heartbeat.h:60
char group_id[HB_MAX_GROUP_ID_LEN]
Definition: heartbeat.h:126
char reserved
Definition: heartbeat.h:121
int hb_register_to_master(CSS_CONN_ENTRY *conn, int type)
Definition: heartbeat.c:355
unsigned short len
Definition: heartbeat.h:124
const char * hb_process_type_string(int ptype)
Definition: heartbeat.c:104
int hb_process_init(const char *server_name, const char *log_path, HB_PROC_TYPE type)
Definition: heartbeat.c:682
HBP_CLUSTER_MESSAGE
Definition: heartbeat.h:73
#define HB_MAX_SZ_PROC_ARGS
Definition: heartbeat.h:83
enum hb_proc_type HB_PROC_TYPE
Definition: heartbeat.h:67
char dest_host_name[CUB_MAXHOSTNAMELEN]
Definition: heartbeat.h:128
#define HB_MAX_SZ_PROC_EXEC_PATH
Definition: heartbeat.h:80
void hb_set_exec_path(char *exec_path)
Definition: heartbeat.c:125
#define HB_MAX_GROUP_ID_LEN
Definition: heartbeat.h:79
void hb_process_term(void)
Definition: heartbeat.c:735
bool hb_Proc_shutdown
Definition: heartbeat.c:93
const char * hb_node_state_string(HB_NODE_STATE_TYPE nstate)
Definition: heartbeat.c:752
unsigned char type
Definition: heartbeat.h:116
enum HB_NODE_STATE HB_NODE_STATE_TYPE
Definition: heartbeat.h:106
const char ** argv
Definition: dynamic_load.c:952
void hb_set_argv(char **argv)
Definition: heartbeat.c:137
int css_receive_heartbeat_request(CSS_CONN_ENTRY *conn, int *command)
Definition: heartbeat.c:202
HB_NODE_STATE
Definition: heartbeat.h:86
#define CUB_MAXHOSTNAMELEN
Definition: porting.h:379
int hb_deregister_from_master(void)
Definition: heartbeat.c:321
int css_send_heartbeat_data(CSS_CONN_ENTRY *conn, const char *data, int size)
Definition: heartbeat.c:178
char orig_host_name[CUB_MAXHOSTNAMELEN]
Definition: heartbeat.h:127