390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
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 |
*/
|
|
1
by brian
clean slate |
19 |
|
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
20 |
#ifndef DRIZZLE_SERVER_SLAVE_H
|
21 |
#define DRIZZLE_SERVER_SLAVE_H
|
|
1
by brian
clean slate |
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 |
#include "log.h" |
|
212.5.28
by Monty Taylor
Moved my_bit and my_list |
37 |
#include <mysys/my_list.h> |
1
by brian
clean slate |
38 |
#include "rpl_filter.h" |
39 |
#include "rpl_tblmap.h" |
|
40 |
||
41 |
||
42 |
// Forward declarations
|
|
43 |
class Relay_log_info; |
|
44 |
class Master_info; |
|
45 |
||
46 |
||
47 |
/*****************************************************************************
|
|
48 |
||
49 |
MySQL Replication
|
|
50 |
||
51 |
Replication is implemented via two types of threads:
|
|
52 |
||
53 |
I/O Thread - One of these threads is started for each master server.
|
|
54 |
They maintain a connection to their master server, read log
|
|
55 |
events from the master as they arrive, and queues them into
|
|
56 |
a single, shared relay log file. A Master_info
|
|
57 |
represents each of these threads.
|
|
58 |
||
59 |
SQL Thread - One of these threads is started and reads from the relay log
|
|
60 |
file, executing each event. A Relay_log_info
|
|
61 |
represents this thread.
|
|
62 |
||
63 |
Buffering in the relay log file makes it unnecessary to reread events from
|
|
64 |
a master server across a slave restart. It also decouples the slave from
|
|
65 |
the master where long-running updates and event logging are concerned--ie
|
|
66 |
it can continue to log new events while a slow query executes on the slave.
|
|
67 |
||
68 |
*****************************************************************************/
|
|
69 |
||
70 |
/*
|
|
71 |
MUTEXES in replication:
|
|
72 |
||
73 |
LOCK_active_mi: [note: this was originally meant for multimaster, to switch
|
|
74 |
from a master to another, to protect active_mi] It is used to SERIALIZE ALL
|
|
75 |
administrative commands of replication: START SLAVE, STOP SLAVE, CHANGE
|
|
76 |
MASTER, RESET SLAVE, end_slave() (when mysqld stops) [init_slave() does not
|
|
77 |
need it it's called early]. Any of these commands holds the mutex from the
|
|
78 |
start till the end. This thus protects us against a handful of deadlocks
|
|
79 |
(consider start_slave_thread() which, when starting the I/O thread, releases
|
|
80 |
mi->run_lock, keeps rli->run_lock, and tries to re-acquire mi->run_lock).
|
|
81 |
||
82 |
Currently active_mi never moves (it's created at startup and deleted at
|
|
83 |
shutdown, and not changed: it always points to the same Master_info struct),
|
|
84 |
because we don't have multimaster. So for the moment, mi does not move, and
|
|
85 |
mi->rli does not either.
|
|
86 |
||
87 |
In Master_info: run_lock, data_lock
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
88 |
run_lock protects all information about the run state: slave_running, session
|
1
by brian
clean slate |
89 |
and the existence of the I/O thread to stop/start it, you need this mutex).
|
90 |
data_lock protects some moving members of the struct: counters (log name,
|
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
91 |
position) and relay log (DRIZZLE_BIN_LOG object).
|
1
by brian
clean slate |
92 |
|
93 |
In Relay_log_info: run_lock, data_lock
|
|
94 |
see Master_info
|
|
95 |
|
|
96 |
Order of acquisition: if you want to have LOCK_active_mi and a run_lock, you
|
|
97 |
must acquire LOCK_active_mi first.
|
|
98 |
||
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
99 |
In DRIZZLE_BIN_LOG: LOCK_log, LOCK_index of the binlog and the relay log
|
1
by brian
clean slate |
100 |
LOCK_log: when you write to it. LOCK_index: when you create/delete a binlog
|
101 |
(so that you have to update the .index file).
|
|
102 |
*/
|
|
103 |
||
130
by Brian Aker
ulong cleanup |
104 |
extern uint32_t master_retry_count; |
1
by brian
clean slate |
105 |
extern MY_BITMAP slave_error_mask; |
106 |
extern bool use_slave_mask; |
|
107 |
extern char *slave_load_tmpdir; |
|
108 |
extern char *master_info_file, *relay_log_info_file; |
|
109 |
extern char *opt_relay_logname, *opt_relaylog_index_name; |
|
150
by Brian Aker
More bool removal. More cow bell! |
110 |
extern bool opt_skip_slave_start; |
111 |
extern bool opt_reckless_slave; |
|
112 |
extern bool opt_log_slave_updates; |
|
130
by Brian Aker
ulong cleanup |
113 |
extern uint64_t relay_log_space_limit; |
1
by brian
clean slate |
114 |
|
115 |
/*
|
|
116 |
3 possible values for Master_info::slave_running and
|
|
117 |
Relay_log_info::slave_running.
|
|
118 |
The values 0,1,2 are very important: to keep the diff small, I didn't
|
|
119 |
substitute places where we use 0/1 with the newly defined symbols. So don't change
|
|
120 |
these values.
|
|
121 |
The same way, code is assuming that in Relay_log_info we use only values
|
|
122 |
0/1.
|
|
123 |
I started with using an enum, but
|
|
124 |
enum_variable=1; is not legal so would have required many line changes.
|
|
125 |
*/
|
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
126 |
#define DRIZZLE_SLAVE_NOT_RUN 0
|
127 |
#define DRIZZLE_SLAVE_RUN_NOT_CONNECT 1
|
|
128 |
#define DRIZZLE_SLAVE_RUN_CONNECT 2
|
|
1
by brian
clean slate |
129 |
|
490
by Brian Aker
More effort around master.info (and relay.info) |
130 |
#define RPL_LOG_NAME (rli->group_master_log_name.length() ? rli->group_master_log_name.c_str() : "FIRST")
|
494
by Brian Aker
Wrote out master.info (more of it). Add to this more private'izing of |
131 |
#define IO_RPL_LOG_NAME (mi->getLogName() ? mi->getLogName() : "FIRST")
|
1
by brian
clean slate |
132 |
|
133 |
/*
|
|
134 |
If the following is set, if first gives an error, second will be
|
|
135 |
tried. Otherwise, if first fails, we fail.
|
|
136 |
*/
|
|
137 |
#define SLAVE_FORCE_ALL 4
|
|
138 |
||
130
by Brian Aker
ulong cleanup |
139 |
int32_t init_slave(); |
1
by brian
clean slate |
140 |
void init_slave_skip_errors(const char* arg); |
141 |
bool flush_relay_log_info(Relay_log_info* rli); |
|
206.3.1
by Patrick Galbraith
Most everything working with client rename |
142 |
int32_t register_slave_on_master(DRIZZLE *drizzle); |
130
by Brian Aker
ulong cleanup |
143 |
int32_t terminate_slave_threads(Master_info* mi, int32_t thread_mask, |
1
by brian
clean slate |
144 |
bool skip_lock = 0); |
130
by Brian Aker
ulong cleanup |
145 |
int32_t start_slave_threads(bool need_slave_mutex, bool wait_for_start, |
1
by brian
clean slate |
146 |
Master_info* mi, const char* master_info_fname, |
130
by Brian Aker
ulong cleanup |
147 |
const char* slave_info_fname, int32_t thread_mask); |
1
by brian
clean slate |
148 |
/*
|
149 |
cond_lock is usually same as start_lock. It is needed for the case when
|
|
150 |
start_lock is 0 which happens if start_slave_thread() is called already
|
|
151 |
inside the start_lock section, but at the same time we want a
|
|
152 |
pthread_cond_wait() on start_cond,start_lock
|
|
153 |
*/
|
|
130
by Brian Aker
ulong cleanup |
154 |
int32_t start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock, |
1
by brian
clean slate |
155 |
pthread_mutex_t *cond_lock, |
156 |
pthread_cond_t* start_cond, |
|
130
by Brian Aker
ulong cleanup |
157 |
volatile uint32_t *slave_running, |
158 |
volatile uint32_t *slave_run_id, |
|
1
by brian
clean slate |
159 |
Master_info* mi, |
160 |
bool high_priority); |
|
161 |
||
162 |
/* If fd is -1, dump to NET */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
163 |
int32_t mysql_table_dump(Session* session, const char* db, |
130
by Brian Aker
ulong cleanup |
164 |
const char* tbl_name, int32_t fd = -1); |
1
by brian
clean slate |
165 |
|
166 |
/* retrieve table from master and copy to slave*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
167 |
int32_t fetch_master_table(Session* session, const char* db_name, const char* table_name, |
206.3.1
by Patrick Galbraith
Most everything working with client rename |
168 |
Master_info* mi, DRIZZLE *drizzle, bool overwrite); |
1
by brian
clean slate |
169 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
170 |
bool show_master_info(Session* session, Master_info* mi); |
171 |
bool show_binlog_info(Session* session); |
|
130
by Brian Aker
ulong cleanup |
172 |
bool rpl_master_has_bug(Relay_log_info *rli, uint32_t bug_id, bool report= true); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
173 |
bool rpl_master_erroneous_autoinc(Session* session); |
1
by brian
clean slate |
174 |
|
175 |
const char *print_slave_db_safe(const char *db); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
176 |
int32_t check_expected_error(Session* session, Relay_log_info const *rli, int32_t error_code); |
1
by brian
clean slate |
177 |
void skip_load_data_infile(NET* net); |
178 |
||
179 |
void end_slave(); /* clean up */ |
|
180 |
void clear_until_condition(Relay_log_info* rli); |
|
181 |
void clear_slave_error(Relay_log_info* rli); |
|
182 |
void end_relay_log_info(Relay_log_info* rli); |
|
183 |
void lock_slave_threads(Master_info* mi); |
|
184 |
void unlock_slave_threads(Master_info* mi); |
|
130
by Brian Aker
ulong cleanup |
185 |
void init_thread_mask(int32_t* mask,Master_info* mi,bool inverse); |
186 |
int32_t init_relay_log_pos(Relay_log_info* rli,const char* log,uint64_t pos, |
|
1
by brian
clean slate |
187 |
bool need_data_lock, const char** errmsg, |
188 |
bool look_for_description_event); |
|
189 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
190 |
int32_t purge_relay_logs(Relay_log_info* rli, Session *session, bool just_reset, |
1
by brian
clean slate |
191 |
const char** errmsg); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
192 |
void set_slave_thread_options(Session* session); |
1
by brian
clean slate |
193 |
void rotate_relay_log(Master_info* mi); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
194 |
int32_t apply_event_and_update_pos(Log_event* ev, Session* session, Relay_log_info* rli, |
1
by brian
clean slate |
195 |
bool skip); |
196 |
||
197 |
pthread_handler_t handle_slave_io(void *arg); |
|
198 |
pthread_handler_t handle_slave_sql(void *arg); |
|
199 |
extern bool volatile abort_loop; |
|
200 |
extern Master_info main_mi, *active_mi; /* active_mi for multi-master */ |
|
201 |
extern LIST master_list; |
|
197
by Brian Aker
More my_bool cleanup. |
202 |
extern bool replicate_same_server_id; |
1
by brian
clean slate |
203 |
|
130
by Brian Aker
ulong cleanup |
204 |
extern int32_t disconnect_slave_event_count, abort_slave_event_count ; |
1
by brian
clean slate |
205 |
|
520.4.28
by Monty Taylor
Changed my.cnf to drizzle.cnf and /etc/mysql to /etc/drizzle. |
206 |
/* the master variables are defaults read from drizzle.cnf or command line */
|
130
by Brian Aker
ulong cleanup |
207 |
extern uint32_t master_port, master_connect_retry, report_port; |
1
by brian
clean slate |
208 |
extern char * master_user, *master_password, *master_host; |
209 |
extern char *master_info_file, *relay_log_info_file, *report_user; |
|
210 |
extern char *report_host, *report_password; |
|
211 |
||
197
by Brian Aker
More my_bool cleanup. |
212 |
extern bool master_ssl; |
1
by brian
clean slate |
213 |
extern char *master_ssl_ca, *master_ssl_capath, *master_ssl_cert; |
214 |
extern char *master_ssl_cipher, *master_ssl_key; |
|
215 |
||
520.1.21
by Brian Aker
THD -> Session rename |
216 |
extern I_List<Session> threads; |
1
by brian
clean slate |
217 |
|
218 |
||
219 |
/**
|
|
220 |
@} (end of group Replication)
|
|
221 |
*/
|
|
222 |
||
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
223 |
#endif /* DRIZZLE_SERVER_SLAVE_H */ |