CUBRID Engine  latest
master_util.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  * master_util.h : common module for commdb and master
22  *
23  */
24 
25 #ifndef _MASTER_UTIL_H_
26 #define _MASTER_UTIL_H_
27 
28 #ident "$Id$"
29 
30 #include "connection_defs.h"
31 
32 #if defined(WINDOWS)
33 #define SLEEP_SEC(X) Sleep((X) * 1000)
34 #define SLEEP_MILISEC(sec, msec) Sleep((sec) * 1000 + (msec))
35 #else
36 #define SLEEP_SEC(X) sleep(X)
37 #define SLEEP_MILISEC(sec, msec) \
38  do { \
39  struct timeval sleep_time_val; \
40  sleep_time_val.tv_sec = sec; \
41  sleep_time_val.tv_usec = (msec) * 1000; \
42  select(0, 0, 0, 0, &sleep_time_val); \
43  } while(0)
44 #endif
45 
46 // todo: MASTER_ER_... shouldn't be necessary anymore. each thread has own error context
47 #define MASTER_ER_SET(...) \
48  do { \
49  if (css_Master_er_log_enabled == true) { \
50  pthread_mutex_lock (&css_Master_er_log_lock); \
51  er_set (__VA_ARGS__); \
52  pthread_mutex_unlock (&css_Master_er_log_lock); \
53  } \
54  } while (0)
55 
56 #define MASTER_ER_SET_WITH_OSERROR(...) \
57  do { \
58  if (css_Master_er_log_enabled == true) { \
59  pthread_mutex_lock (&css_Master_er_log_lock); \
60  er_set_with_oserror (__VA_ARGS__); \
61  pthread_mutex_unlock (&css_Master_er_log_lock); \
62  } \
63  } while (0)
64 
65 #define MASTER_ER_LOG_DEBUG(...) \
66  do { \
67  if (css_Master_er_log_enabled == true) { \
68  pthread_mutex_lock (&css_Master_er_log_lock); \
69  er_log_debug (__VA_ARGS__); \
70  pthread_mutex_unlock (&css_Master_er_log_lock); \
71  } \
72  } while (0)
73 
76 {
78  int fd_type;
79  int db_error;
80  int queue_p;
81  int info_p;
82  int error_p;
83  int pid;
84  char *name;
86  char *env_var;
88  int port_id;
89  int ha_mode;
91 };
92 
93 extern bool master_util_config_startup (const char *db_name, int *port_id);
94 extern void master_util_wait_proc_terminate (int pid);
95 
96 extern pthread_mutex_t css_Master_er_log_lock;
97 extern pthread_mutex_t css_Master_er_log_enable_lock;
98 extern bool css_Master_er_log_enabled;
99 
100 #define GET_REAL_MASTER_CONN_NAME(name) (((char *) name) + 1)
101 #define IS_MASTER_CONN_NAME_DRIVER(name) (*((char *)name) == '-')
102 #define IS_MASTER_CONN_NAME_HA_SERVER(name) (*((char *)name) == '#')
103 #define IS_MASTER_CONN_NAME_HA_COPYLOG(name) (*((char *)name) == '$')
104 #define IS_MASTER_CONN_NAME_HA_APPLYLOG(name) (*((char *)name) == '%')
105 
106 #endif /* _MASTER_UTIL_H_ */
char * name
Definition: master_util.h:84
int SOCKET
Definition: porting.h:482
CSS_CONN_ENTRY * conn_ptr
Definition: master_util.h:87
int error_p
Definition: master_util.h:82
int db_error
Definition: master_util.h:79
void master_util_wait_proc_terminate(int pid)
Definition: master_util.c:72
bool css_Master_er_log_enabled
Definition: master.c:131
SOCKET fd
Definition: master_util.h:77
int ha_mode
Definition: master_util.h:89
int info_p
Definition: master_util.h:81
char * env_var
Definition: master_util.h:86
char * version_string
Definition: master_util.h:85
Definition: master_util.h:75
char * db_name
int pid
Definition: master_util.h:83
int queue_p
Definition: master_util.h:80
bool master_util_config_startup(const char *db_name, int *port_id)
Definition: master_util.c:42
int fd_type
Definition: master_util.h:78
pthread_mutex_t css_Master_er_log_enable_lock
Definition: master.c:130
struct socket_queue_entry * next
Definition: master_util.h:90
int port_id
Definition: master_util.h:88
pthread_mutex_t css_Master_er_log_lock
Definition: master.c:129