~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/slave.h

Removing global errbuff and cleaning up two remaining instances that referenced it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
#ifndef DRIZZLE_SERVER_SLAVE_H
21
 
#define DRIZZLE_SERVER_SLAVE_H
22
 
 
23
 
/**
24
 
  @defgroup Replication Replication
25
 
  @{
26
 
 
27
 
  @file
28
 
*/
29
 
 
30
 
/** 
31
 
   Some of defines are need in parser even though replication is not 
32
 
   compiled in (embedded).
33
 
*/
34
 
 
35
 
/**
36
 
   The maximum is defined as (ULONG_MAX/1000) with 4 bytes uint32_t
37
 
*/
38
 
#define SLAVE_MAX_HEARTBEAT_PERIOD 4294967
39
 
 
40
 
#include "log.h"
41
 
#include <mysys/my_list.h>
42
 
#include "rpl_filter.h"
43
 
#include "rpl_tblmap.h"
44
 
 
45
 
#define SLAVE_NET_TIMEOUT  3600
46
 
 
47
 
#define MAX_SLAVE_ERROR    2000
48
 
 
49
 
// Forward declarations
50
 
class Relay_log_info;
51
 
class Master_info;
52
 
 
53
 
 
54
 
/*****************************************************************************
55
 
 
56
 
  MySQL Replication
57
 
 
58
 
  Replication is implemented via two types of threads:
59
 
 
60
 
    I/O Thread - One of these threads is started for each master server.
61
 
                 They maintain a connection to their master server, read log
62
 
                 events from the master as they arrive, and queues them into
63
 
                 a single, shared relay log file.  A Master_info 
64
 
                 represents each of these threads.
65
 
 
66
 
    SQL Thread - One of these threads is started and reads from the relay log
67
 
                 file, executing each event.  A Relay_log_info 
68
 
                 represents this thread.
69
 
 
70
 
  Buffering in the relay log file makes it unnecessary to reread events from
71
 
  a master server across a slave restart.  It also decouples the slave from
72
 
  the master where long-running updates and event logging are concerned--ie
73
 
  it can continue to log new events while a slow query executes on the slave.
74
 
 
75
 
*****************************************************************************/
76
 
 
77
 
/*
78
 
  MUTEXES in replication:
79
 
 
80
 
  LOCK_active_mi: [note: this was originally meant for multimaster, to switch
81
 
  from a master to another, to protect active_mi] It is used to SERIALIZE ALL
82
 
  administrative commands of replication: START SLAVE, STOP SLAVE, CHANGE
83
 
  MASTER, RESET SLAVE, end_slave() (when mysqld stops) [init_slave() does not
84
 
  need it it's called early]. Any of these commands holds the mutex from the
85
 
  start till the end. This thus protects us against a handful of deadlocks
86
 
  (consider start_slave_thread() which, when starting the I/O thread, releases
87
 
  mi->run_lock, keeps rli->run_lock, and tries to re-acquire mi->run_lock).
88
 
 
89
 
  Currently active_mi never moves (it's created at startup and deleted at
90
 
  shutdown, and not changed: it always points to the same Master_info struct),
91
 
  because we don't have multimaster. So for the moment, mi does not move, and
92
 
  mi->rli does not either.
93
 
 
94
 
  In Master_info: run_lock, data_lock
95
 
  run_lock protects all information about the run state: slave_running, thd
96
 
  and the existence of the I/O thread to stop/start it, you need this mutex).
97
 
  data_lock protects some moving members of the struct: counters (log name,
98
 
  position) and relay log (DRIZZLE_BIN_LOG object).
99
 
 
100
 
  In Relay_log_info: run_lock, data_lock
101
 
  see Master_info
102
 
  
103
 
  Order of acquisition: if you want to have LOCK_active_mi and a run_lock, you
104
 
  must acquire LOCK_active_mi first.
105
 
 
106
 
  In DRIZZLE_BIN_LOG: LOCK_log, LOCK_index of the binlog and the relay log
107
 
  LOCK_log: when you write to it. LOCK_index: when you create/delete a binlog
108
 
  (so that you have to update the .index file).
109
 
*/
110
 
 
111
 
extern uint32_t master_retry_count;
112
 
extern MY_BITMAP slave_error_mask;
113
 
extern bool use_slave_mask;
114
 
extern char *slave_load_tmpdir;
115
 
extern char *master_info_file, *relay_log_info_file;
116
 
extern char *opt_relay_logname, *opt_relaylog_index_name;
117
 
extern bool opt_skip_slave_start;
118
 
extern bool opt_reckless_slave;
119
 
extern bool opt_log_slave_updates;
120
 
extern uint64_t relay_log_space_limit;
121
 
 
122
 
/*
123
 
  3 possible values for Master_info::slave_running and
124
 
  Relay_log_info::slave_running.
125
 
  The values 0,1,2 are very important: to keep the diff small, I didn't
126
 
  substitute places where we use 0/1 with the newly defined symbols. So don't change
127
 
  these values.
128
 
  The same way, code is assuming that in Relay_log_info we use only values
129
 
  0/1.
130
 
  I started with using an enum, but
131
 
  enum_variable=1; is not legal so would have required many line changes.
132
 
*/
133
 
#define DRIZZLE_SLAVE_NOT_RUN         0
134
 
#define DRIZZLE_SLAVE_RUN_NOT_CONNECT 1
135
 
#define DRIZZLE_SLAVE_RUN_CONNECT     2
136
 
 
137
 
#define RPL_LOG_NAME (rli->group_master_log_name[0] ? rli->group_master_log_name :\
138
 
 "FIRST")
139
 
#define IO_RPL_LOG_NAME (mi->master_log_name[0] ? mi->master_log_name :\
140
 
 "FIRST")
141
 
 
142
 
/*
143
 
  If the following is set, if first gives an error, second will be
144
 
  tried. Otherwise, if first fails, we fail.
145
 
*/
146
 
#define SLAVE_FORCE_ALL 4
147
 
 
148
 
int32_t init_slave();
149
 
void init_slave_skip_errors(const char* arg);
150
 
bool flush_relay_log_info(Relay_log_info* rli);
151
 
int32_t register_slave_on_master(DRIZZLE *drizzle);
152
 
int32_t terminate_slave_threads(Master_info* mi, int32_t thread_mask,
153
 
                             bool skip_lock = 0);
154
 
int32_t start_slave_threads(bool need_slave_mutex, bool wait_for_start,
155
 
                        Master_info* mi, const char* master_info_fname,
156
 
                        const char* slave_info_fname, int32_t thread_mask);
157
 
/*
158
 
  cond_lock is usually same as start_lock. It is needed for the case when
159
 
  start_lock is 0 which happens if start_slave_thread() is called already
160
 
  inside the start_lock section, but at the same time we want a
161
 
  pthread_cond_wait() on start_cond,start_lock
162
 
*/
163
 
int32_t start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock,
164
 
                       pthread_mutex_t *cond_lock,
165
 
                       pthread_cond_t* start_cond,
166
 
                       volatile uint32_t *slave_running,
167
 
                       volatile uint32_t *slave_run_id,
168
 
                       Master_info* mi,
169
 
                       bool high_priority);
170
 
 
171
 
/* If fd is -1, dump to NET */
172
 
int32_t mysql_table_dump(THD* thd, const char* db,
173
 
                     const char* tbl_name, int32_t fd = -1);
174
 
 
175
 
/* retrieve table from master and copy to slave*/
176
 
int32_t fetch_master_table(THD* thd, const char* db_name, const char* table_name,
177
 
                       Master_info* mi, DRIZZLE *drizzle, bool overwrite);
178
 
 
179
 
bool show_master_info(THD* thd, Master_info* mi);
180
 
bool show_binlog_info(THD* thd);
181
 
bool rpl_master_has_bug(Relay_log_info *rli, uint32_t bug_id, bool report= true);
182
 
bool rpl_master_erroneous_autoinc(THD* thd);
183
 
 
184
 
const char *print_slave_db_safe(const char *db);
185
 
int32_t check_expected_error(THD* thd, Relay_log_info const *rli, int32_t error_code);
186
 
void skip_load_data_infile(NET* net);
187
 
 
188
 
void end_slave(); /* clean up */
189
 
void clear_until_condition(Relay_log_info* rli);
190
 
void clear_slave_error(Relay_log_info* rli);
191
 
void end_relay_log_info(Relay_log_info* rli);
192
 
void lock_slave_threads(Master_info* mi);
193
 
void unlock_slave_threads(Master_info* mi);
194
 
void init_thread_mask(int32_t* mask,Master_info* mi,bool inverse);
195
 
int32_t init_relay_log_pos(Relay_log_info* rli,const char* log,uint64_t pos,
196
 
                       bool need_data_lock, const char** errmsg,
197
 
                       bool look_for_description_event);
198
 
 
199
 
int32_t purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset,
200
 
                     const char** errmsg);
201
 
void set_slave_thread_options(THD* thd);
202
 
void set_slave_thread_default_charset(THD *thd, Relay_log_info const *rli);
203
 
void rotate_relay_log(Master_info* mi);
204
 
int32_t apply_event_and_update_pos(Log_event* ev, THD* thd, Relay_log_info* rli,
205
 
                               bool skip);
206
 
 
207
 
pthread_handler_t handle_slave_io(void *arg);
208
 
pthread_handler_t handle_slave_sql(void *arg);
209
 
extern bool volatile abort_loop;
210
 
extern Master_info main_mi, *active_mi; /* active_mi for multi-master */
211
 
extern LIST master_list;
212
 
extern bool replicate_same_server_id;
213
 
 
214
 
extern int32_t disconnect_slave_event_count, abort_slave_event_count ;
215
 
 
216
 
/* the master variables are defaults read from my.cnf or command line */
217
 
extern uint32_t master_port, master_connect_retry, report_port;
218
 
extern char * master_user, *master_password, *master_host;
219
 
extern char *master_info_file, *relay_log_info_file, *report_user;
220
 
extern char *report_host, *report_password;
221
 
 
222
 
extern bool master_ssl;
223
 
extern char *master_ssl_ca, *master_ssl_capath, *master_ssl_cert;
224
 
extern char *master_ssl_cipher, *master_ssl_key;
225
 
       
226
 
extern I_List<THD> threads;
227
 
 
228
 
/* masks for start/stop operations on io and sql slave threads */
229
 
#define SLAVE_IO  1
230
 
#define SLAVE_SQL 2
231
 
 
232
 
/**
233
 
  @} (end of group Replication)
234
 
*/
235
 
 
236
 
#endif /* DRIZZLE_SERVER_SLAVE_H */