2004-09-09 03:26:19 +02:00
|
|
|
/* Copyright (C) 2000-2003 MySQL AB
|
2005-02-01 15:36:48 +01:00
|
|
|
|
2004-09-09 03:26:19 +02:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2005-02-01 15:36:48 +01:00
|
|
|
|
2004-09-09 03:26:19 +02:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2005-02-01 15:36:48 +01:00
|
|
|
|
2004-09-09 03:26:19 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
2000-11-11 22:50:39 +01:00
|
|
|
#ifndef SLAVE_H
|
|
|
|
#define SLAVE_H
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
#ifdef HAVE_REPLICATION
|
|
|
|
|
|
|
|
#include "log.h"
|
2002-01-20 03:16:52 +01:00
|
|
|
#include "my_list.h"
|
2005-03-21 22:09:42 +01:00
|
|
|
#include "rpl_filter.h"
|
2005-12-22 06:39:02 +01:00
|
|
|
#include "rpl_tblmap.h"
|
2005-03-10 14:36:48 +01:00
|
|
|
|
2001-07-17 22:22:52 +02:00
|
|
|
#define SLAVE_NET_TIMEOUT 3600
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2002-01-22 23:05:11 +01:00
|
|
|
#define MAX_SLAVE_ERROR 2000
|
2002-01-20 03:16:52 +01:00
|
|
|
|
2007-04-12 08:58:04 +02:00
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
struct st_relay_log_info;
|
|
|
|
typedef st_relay_log_info RELAY_LOG_INFO;
|
|
|
|
|
|
|
|
class MASTER_INFO;
|
|
|
|
|
2002-10-29 23:12:47 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
|
|
|
|
MySQL Replication
|
|
|
|
|
|
|
|
Replication is implemented via two types of threads:
|
|
|
|
|
|
|
|
I/O Thread - One of these threads is started for each master server.
|
|
|
|
They maintain a connection to their master server, read log
|
|
|
|
events from the master as they arrive, and queues them into
|
2006-10-31 16:51:51 +01:00
|
|
|
a single, shared relay log file. A MASTER_INFO
|
2002-10-29 23:12:47 +01:00
|
|
|
represents each of these threads.
|
|
|
|
|
|
|
|
SQL Thread - One of these threads is started and reads from the relay log
|
2006-10-31 16:51:51 +01:00
|
|
|
file, executing each event. A RELAY_LOG_INFO
|
2002-10-29 23:12:47 +01:00
|
|
|
represents this thread.
|
|
|
|
|
|
|
|
Buffering in the relay log file makes it unnecessary to reread events from
|
|
|
|
a master server across a slave restart. It also decouples the slave from
|
|
|
|
the master where long-running updates and event logging are concerned--ie
|
|
|
|
it can continue to log new events while a slow query executes on the slave.
|
|
|
|
|
|
|
|
*****************************************************************************/
|
2001-07-17 22:22:52 +02:00
|
|
|
|
2003-08-25 16:20:21 +02:00
|
|
|
/*
|
|
|
|
MUTEXES in replication:
|
|
|
|
|
Fix for BUG#2921 "Replication problem on mutex lock in mySQL-4.0.18":
re-using unused LOCK_active_mi to serialize all administrative
commands related to replication:
START SLAVE, STOP SLAVE, RESET SLAVE, CHANGE MASTER, init_slave()
(replication autostart at server startup), end_slave() (replication
autostop at server shutdown), LOAD DATA FROM MASTER.
This protects us against a handful of deadlocks (like BUG#2921
when two START SLAVE, but when two STOP SLAVE too).
Removing unused variables.
sql/item_func.cc:
We don't need LOCK_active_mi just to MASTER_POS_WAIT().
sql/repl_failsafe.cc:
no need for macro
sql/set_var.cc:
no need for macro
sql/slave.cc:
Re-using unused LOCK_active_mi to serialize all administrative
commands related to replication:
START SLAVE, STOP SLAVE, RESET SLAVE, CHANGE MASTER, init_slave()
(replication autostart at server startup), end_slave() (replication
autostop at server shutdown), LOAD DATA FROM MASTER.
This protects us against a handful of deadlocks.
Removing unused variables.
sql/slave.h:
Re-using LOCK_active_mi to serialize administrative replication commands.
Macros unneeded. Removing unneeded variables.
sql/sql_parse.cc:
found unused variable.
Replacing macros.
sql/sql_show.cc:
replacing macros
2004-03-11 16:23:35 +01:00
|
|
|
LOCK_active_mi: [note: this was originally meant for multimaster, to switch
|
|
|
|
from a master to another, to protect active_mi] It is used to SERIALIZE ALL
|
|
|
|
administrative commands of replication: START SLAVE, STOP SLAVE, CHANGE
|
|
|
|
MASTER, RESET SLAVE, end_slave() (when mysqld stops) [init_slave() does not
|
|
|
|
need it it's called early]. Any of these commands holds the mutex from the
|
|
|
|
start till the end. This thus protects us against a handful of deadlocks
|
|
|
|
(consider start_slave_thread() which, when starting the I/O thread, releases
|
|
|
|
mi->run_lock, keeps rli->run_lock, and tries to re-acquire mi->run_lock).
|
|
|
|
|
|
|
|
Currently active_mi never moves (it's created at startup and deleted at
|
|
|
|
shutdown, and not changed: it always points to the same MASTER_INFO struct),
|
|
|
|
because we don't have multimaster. So for the moment, mi does not move, and
|
|
|
|
mi->rli does not either.
|
2003-08-25 16:20:21 +02:00
|
|
|
|
|
|
|
In MASTER_INFO: run_lock, data_lock
|
|
|
|
run_lock protects all information about the run state: slave_running, and the
|
|
|
|
existence of the I/O thread (to stop/start it, you need this mutex).
|
|
|
|
data_lock protects some moving members of the struct: counters (log name,
|
2006-05-05 08:45:58 +02:00
|
|
|
position) and relay log (MYSQL_BIN_LOG object).
|
2003-08-25 16:20:21 +02:00
|
|
|
|
|
|
|
In RELAY_LOG_INFO: run_lock, data_lock
|
|
|
|
see MASTER_INFO
|
|
|
|
|
Fix for BUG#2921 "Replication problem on mutex lock in mySQL-4.0.18":
re-using unused LOCK_active_mi to serialize all administrative
commands related to replication:
START SLAVE, STOP SLAVE, RESET SLAVE, CHANGE MASTER, init_slave()
(replication autostart at server startup), end_slave() (replication
autostop at server shutdown), LOAD DATA FROM MASTER.
This protects us against a handful of deadlocks (like BUG#2921
when two START SLAVE, but when two STOP SLAVE too).
Removing unused variables.
sql/item_func.cc:
We don't need LOCK_active_mi just to MASTER_POS_WAIT().
sql/repl_failsafe.cc:
no need for macro
sql/set_var.cc:
no need for macro
sql/slave.cc:
Re-using unused LOCK_active_mi to serialize all administrative
commands related to replication:
START SLAVE, STOP SLAVE, RESET SLAVE, CHANGE MASTER, init_slave()
(replication autostart at server startup), end_slave() (replication
autostop at server shutdown), LOAD DATA FROM MASTER.
This protects us against a handful of deadlocks.
Removing unused variables.
sql/slave.h:
Re-using LOCK_active_mi to serialize administrative replication commands.
Macros unneeded. Removing unneeded variables.
sql/sql_parse.cc:
found unused variable.
Replacing macros.
sql/sql_show.cc:
replacing macros
2004-03-11 16:23:35 +01:00
|
|
|
Order of acquisition: if you want to have LOCK_active_mi and a run_lock, you
|
|
|
|
must acquire LOCK_active_mi first.
|
|
|
|
|
2006-05-05 08:45:58 +02:00
|
|
|
In MYSQL_BIN_LOG: LOCK_log, LOCK_index of the binlog and the relay log
|
2003-08-25 16:20:21 +02:00
|
|
|
LOCK_log: when you write to it. LOCK_index: when you create/delete a binlog
|
|
|
|
(so that you have to update the .index file).
|
|
|
|
*/
|
|
|
|
|
2003-06-04 07:57:42 +02:00
|
|
|
extern ulong master_retry_count;
|
2002-01-22 23:05:11 +01:00
|
|
|
extern MY_BITMAP slave_error_mask;
|
|
|
|
extern bool use_slave_mask;
|
2001-08-03 23:57:53 +02:00
|
|
|
extern char* slave_load_tmpdir;
|
2002-01-20 03:16:52 +01:00
|
|
|
extern my_string master_info_file,relay_log_info_file;
|
|
|
|
extern my_string opt_relay_logname, opt_relaylog_index_name;
|
2002-08-22 15:50:58 +02:00
|
|
|
extern my_bool opt_skip_slave_start, opt_reckless_slave;
|
|
|
|
extern my_bool opt_log_slave_updates;
|
2002-08-23 14:14:01 +02:00
|
|
|
extern ulonglong relay_log_space_limit;
|
2002-01-20 03:16:52 +01:00
|
|
|
|
A change of behaviour of Seconds_Behind_Master from SHOW SLAVE STATUS. It's going into 4.1
because old behaviour was somewhat nonsensical (kind of bug). Changes are that if repl threads are
down or disconnected the column will be NULL, and if master is idle the column will not grow indefinitely anymore.
sql/slave.cc:
mi->slave_running and rli->slave_running now uints (was needed only for mi but because of start_slave_thread() usage,
had to change both).
So mi->slave_running can now take 3 values: not running, running & not connected, running and connected.
The last value serves for calculation of Seconds_Behind_Master in SHOW SLAVE STATUS.
Changing this column's behaviour: if SQL or I/O thread is not running, or if I/O thread is not connected
(for example if it is reconnecting), it's NULL (to mean "unknown"). And if master is idle, the column will
not grow indefinitely like it used to (that was meaningless); this is fixed by forcing a value of 0
when the slave SQL thread has hit EOF of relay log (which has only a limited number of caveats explained
in comments in code).
sql/slave.h:
slave_running used to be bool but we need to distinguish, for the I/O slave thread, between
"running & connected" and "running & not connected" ("running" means the thread exists).
sql/sql_repl.cc:
we don't need anymore to set rli->last_master_timestamp to 0 (we used that to make Seconds_Behind_Master
be NULL) in RESET SLAVE and CHANGE MASTER, as these commands imply that slave threads are not running
and so Seconds_Behind_Master is already NULL because of that.
2004-12-16 18:12:22 +01:00
|
|
|
/*
|
|
|
|
3 possible values for MASTER_INFO::slave_running and
|
|
|
|
RELAY_LOG_INFO::slave_running.
|
|
|
|
The values 0,1,2 are very important: to keep the diff small, I didn't
|
|
|
|
substitute places where we use 0/1 with the newly defined symbols. So don't change
|
|
|
|
these values.
|
|
|
|
The same way, code is assuming that in RELAY_LOG_INFO we use only values
|
|
|
|
0/1.
|
|
|
|
I started with using an enum, but
|
|
|
|
enum_variable=1; is not legal so would have required many line changes.
|
|
|
|
*/
|
|
|
|
#define MYSQL_SLAVE_NOT_RUN 0
|
|
|
|
#define MYSQL_SLAVE_RUN_NOT_CONNECT 1
|
|
|
|
#define MYSQL_SLAVE_RUN_CONNECT 2
|
|
|
|
|
Replication: new code to not modify in-memory log positions until the COMMIT
is executed, even if the transaction spans on >=2 relay logs (bug #53).
New variable relay_log_purge =0|1
New test to verify bug #53
sql/log.cc:
Now we purge a relay log only when we are sure we won't need it,
i.e. we have executed the final query (if autocommit=1) or the COMMIT.
sql/log_event.cc:
Better tracking of the relay log's name and position
lastly executed, even if we are in a transaction which spans on
2 or more relay logs.
sql/mysql_priv.h:
new option relay_log_purge (the user can now decide himself
if he wants his relay logs to be automatically purged or not,
we don't make unsafe guesses like before)
sql/mysqld.cc:
new option --innodb (replaces --skip-innodb).
Useful for the test suite : we have skip-innodb in mysql-test-run,
but we can ('-opt.info' file) choose to start the server with
InnoDB for this test only.
New option --bdb
sql/repl_failsafe.cc:
Better tracking of the relay log's name and position
lastly executed, even if we are in a transaction which spans on
2 or more relay logs.
sql/set_var.cc:
new variable relay_log_purge
sql/slave.cc:
Better tracking of the relay log's name and position
lastly executed, even if we are in a transaction which spans on
2 or more relay logs.
Now we purge a relay log only when we are sure we won't need it,
i.e. we have executed the final query (if autocommit=1) or the COMMIT
sql/slave.h:
Better tracking of the relay log's name and position
lastly executed, even if we are in a transaction which spans on
2 or more relay logs.
sql/sql_class.h:
prototypes change
sql/sql_parse.cc:
removed thd argument (was not used in the function's body)
sql/sql_repl.cc:
Better tracking of the relay log's name and position
lastly executed, even if we are in a transaction which spans on
2 or more relay logs.
Turn relay_log_purge silently off when someone does CHANGE
MASTER TO RELAY_LOG_*
2003-04-24 15:29:25 +02:00
|
|
|
#define RPL_LOG_NAME (rli->group_master_log_name[0] ? rli->group_master_log_name :\
|
2002-01-20 03:16:52 +01:00
|
|
|
"FIRST")
|
|
|
|
#define IO_RPL_LOG_NAME (mi->master_log_name[0] ? mi->master_log_name :\
|
2001-08-03 23:57:53 +02:00
|
|
|
"FIRST")
|
|
|
|
|
2002-01-29 17:32:16 +01:00
|
|
|
/*
|
|
|
|
If the following is set, if first gives an error, second will be
|
|
|
|
tried. Otherwise, if first fails, we fail.
|
|
|
|
*/
|
|
|
|
#define SLAVE_FORCE_ALL 4
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2002-01-20 03:16:52 +01:00
|
|
|
int init_slave();
|
2002-04-30 15:40:46 +02:00
|
|
|
void init_slave_skip_errors(const char* arg);
|
2002-08-08 02:12:02 +02:00
|
|
|
bool flush_relay_log_info(RELAY_LOG_INFO* rli);
|
2001-05-31 02:50:56 +02:00
|
|
|
int register_slave_on_master(MYSQL* mysql);
|
2002-01-20 03:16:52 +01:00
|
|
|
int terminate_slave_threads(MASTER_INFO* mi, int thread_mask,
|
|
|
|
bool skip_lock = 0);
|
|
|
|
int terminate_slave_thread(THD* thd, pthread_mutex_t* term_mutex,
|
|
|
|
pthread_mutex_t* cond_lock,
|
|
|
|
pthread_cond_t* term_cond,
|
A change of behaviour of Seconds_Behind_Master from SHOW SLAVE STATUS. It's going into 4.1
because old behaviour was somewhat nonsensical (kind of bug). Changes are that if repl threads are
down or disconnected the column will be NULL, and if master is idle the column will not grow indefinitely anymore.
sql/slave.cc:
mi->slave_running and rli->slave_running now uints (was needed only for mi but because of start_slave_thread() usage,
had to change both).
So mi->slave_running can now take 3 values: not running, running & not connected, running and connected.
The last value serves for calculation of Seconds_Behind_Master in SHOW SLAVE STATUS.
Changing this column's behaviour: if SQL or I/O thread is not running, or if I/O thread is not connected
(for example if it is reconnecting), it's NULL (to mean "unknown"). And if master is idle, the column will
not grow indefinitely like it used to (that was meaningless); this is fixed by forcing a value of 0
when the slave SQL thread has hit EOF of relay log (which has only a limited number of caveats explained
in comments in code).
sql/slave.h:
slave_running used to be bool but we need to distinguish, for the I/O slave thread, between
"running & connected" and "running & not connected" ("running" means the thread exists).
sql/sql_repl.cc:
we don't need anymore to set rli->last_master_timestamp to 0 (we used that to make Seconds_Behind_Master
be NULL) in RESET SLAVE and CHANGE MASTER, as these commands imply that slave threads are not running
and so Seconds_Behind_Master is already NULL because of that.
2004-12-16 18:12:22 +01:00
|
|
|
volatile uint* slave_running);
|
2002-01-20 03:16:52 +01:00
|
|
|
int start_slave_threads(bool need_slave_mutex, bool wait_for_start,
|
|
|
|
MASTER_INFO* mi, const char* master_info_fname,
|
|
|
|
const char* slave_info_fname, int thread_mask);
|
2002-01-29 17:32:16 +01:00
|
|
|
/*
|
|
|
|
cond_lock is usually same as start_lock. It is needed for the case when
|
|
|
|
start_lock is 0 which happens if start_slave_thread() is called already
|
|
|
|
inside the start_lock section, but at the same time we want a
|
|
|
|
pthread_cond_wait() on start_cond,start_lock
|
2002-01-20 03:16:52 +01:00
|
|
|
*/
|
|
|
|
int start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock,
|
|
|
|
pthread_mutex_t *cond_lock,
|
|
|
|
pthread_cond_t* start_cond,
|
A change of behaviour of Seconds_Behind_Master from SHOW SLAVE STATUS. It's going into 4.1
because old behaviour was somewhat nonsensical (kind of bug). Changes are that if repl threads are
down or disconnected the column will be NULL, and if master is idle the column will not grow indefinitely anymore.
sql/slave.cc:
mi->slave_running and rli->slave_running now uints (was needed only for mi but because of start_slave_thread() usage,
had to change both).
So mi->slave_running can now take 3 values: not running, running & not connected, running and connected.
The last value serves for calculation of Seconds_Behind_Master in SHOW SLAVE STATUS.
Changing this column's behaviour: if SQL or I/O thread is not running, or if I/O thread is not connected
(for example if it is reconnecting), it's NULL (to mean "unknown"). And if master is idle, the column will
not grow indefinitely like it used to (that was meaningless); this is fixed by forcing a value of 0
when the slave SQL thread has hit EOF of relay log (which has only a limited number of caveats explained
in comments in code).
sql/slave.h:
slave_running used to be bool but we need to distinguish, for the I/O slave thread, between
"running & connected" and "running & not connected" ("running" means the thread exists).
sql/sql_repl.cc:
we don't need anymore to set rli->last_master_timestamp to 0 (we used that to make Seconds_Behind_Master
be NULL) in RESET SLAVE and CHANGE MASTER, as these commands imply that slave threads are not running
and so Seconds_Behind_Master is already NULL because of that.
2004-12-16 18:12:22 +01:00
|
|
|
volatile uint *slave_running,
|
2002-08-24 04:44:16 +02:00
|
|
|
volatile ulong *slave_run_id,
|
2003-03-01 23:59:27 +01:00
|
|
|
MASTER_INFO* mi,
|
|
|
|
bool high_priority);
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2002-07-17 14:17:20 +02:00
|
|
|
/* If fd is -1, dump to NET */
|
2001-05-29 03:18:23 +02:00
|
|
|
int mysql_table_dump(THD* thd, const char* db,
|
|
|
|
const char* tbl_name, int fd = -1);
|
|
|
|
|
* Fix for BUG#1248: "LOAD DATA FROM MASTER drops the slave's db unexpectedly".
Now LOAD DATA FROM MASTER does not drop the database, instead it only tries to
create it, and drops/creates table-by-table.
* replicate_wild_ignore_table='db1.%' is now considered as "ignore the 'db1'
database as a whole", as it already works for CREATE DATABASE and DROP DATABASE.
mysql-test/r/rpl000009.result:
result update
mysql-test/t/rpl000009.test:
test that LOAD DATA FROM MASTER does not drop databases,
but rather table by table, thus preserving non-replicated tables.
Test that LOAD DATA FROM MASTER reports the error when a table could not
be dropped (system's "permission denied" for example).
Test that LOAD TABLE FROM MASTER reports the error when the table already exists.
sql/repl_failsafe.cc:
* replicate_wild_ignore_table='db1.%' is now considered as "ignore the 'db1'
database as a whole", as it already works for CREATE DATABASE and DROP DATABASE.
* If a db matches replicate_*_db rules, we don't drop/recreate it because this
could drop some tables in this db which could be slave-specific. Instead,
we do a CREATE DATABASE IF EXISTS, and we will drop each table which has
an equivalent on the master, table-by-table.
sql/slave.cc:
New argument to drop the table in create_table_from_dump()
(LOAD TABLE/DATA FROM MASTER are the only places where this function is used).
This is needed because LOAD DATA FROM MASTER does not drop the database anymore.
The behaviour when the table exists is unchanged: LOAD DATA silently replaces
the table, LOAD TABLE gives error.
sql/slave.h:
new argument to drop the table in fetch_master_table
sql/sql_parse.cc:
do not drop the table in LOAD TABLE FROM MASTER (this behaviour is already
true; but changes in LOAD DATA FROM MASTER made the argument needed).
2003-09-11 23:17:28 +02:00
|
|
|
/* retrieve table from master and copy to slave*/
|
2002-01-29 17:32:16 +01:00
|
|
|
int fetch_master_table(THD* thd, const char* db_name, const char* table_name,
|
* Fix for BUG#1248: "LOAD DATA FROM MASTER drops the slave's db unexpectedly".
Now LOAD DATA FROM MASTER does not drop the database, instead it only tries to
create it, and drops/creates table-by-table.
* replicate_wild_ignore_table='db1.%' is now considered as "ignore the 'db1'
database as a whole", as it already works for CREATE DATABASE and DROP DATABASE.
mysql-test/r/rpl000009.result:
result update
mysql-test/t/rpl000009.test:
test that LOAD DATA FROM MASTER does not drop databases,
but rather table by table, thus preserving non-replicated tables.
Test that LOAD DATA FROM MASTER reports the error when a table could not
be dropped (system's "permission denied" for example).
Test that LOAD TABLE FROM MASTER reports the error when the table already exists.
sql/repl_failsafe.cc:
* replicate_wild_ignore_table='db1.%' is now considered as "ignore the 'db1'
database as a whole", as it already works for CREATE DATABASE and DROP DATABASE.
* If a db matches replicate_*_db rules, we don't drop/recreate it because this
could drop some tables in this db which could be slave-specific. Instead,
we do a CREATE DATABASE IF EXISTS, and we will drop each table which has
an equivalent on the master, table-by-table.
sql/slave.cc:
New argument to drop the table in create_table_from_dump()
(LOAD TABLE/DATA FROM MASTER are the only places where this function is used).
This is needed because LOAD DATA FROM MASTER does not drop the database anymore.
The behaviour when the table exists is unchanged: LOAD DATA silently replaces
the table, LOAD TABLE gives error.
sql/slave.h:
new argument to drop the table in fetch_master_table
sql/sql_parse.cc:
do not drop the table in LOAD TABLE FROM MASTER (this behaviour is already
true; but changes in LOAD DATA FROM MASTER made the argument needed).
2003-09-11 23:17:28 +02:00
|
|
|
MASTER_INFO* mi, MYSQL* mysql, bool overwrite);
|
2001-05-29 03:18:23 +02:00
|
|
|
|
2004-10-20 03:04:37 +02:00
|
|
|
bool show_master_info(THD* thd, MASTER_INFO* mi);
|
|
|
|
bool show_binlog_info(THD* thd);
|
Fix for BUG#24432
"INSERT... ON DUPLICATE KEY UPDATE skips auto_increment values".
When in an INSERT ON DUPLICATE KEY UPDATE, using
an autoincrement column, we inserted some autogenerated values and
also updated some rows, some autogenerated values were not used
(for example, even if 10 was the largest autoinc value in the table
at the start of the statement, 12 could be the first autogenerated
value inserted by the statement, instead of 11). One autogenerated
value was lost per updated row. Led to exhausting the range of the
autoincrement column faster.
Bug introduced by fix of BUG#20188; present since 5.0.24 and 5.1.12.
This bug breaks replication from a pre-5.0.24 master.
But the present bugfix, as it makes INSERT ON DUP KEY UPDATE
behave like pre-5.0.24, breaks replication from a [5.0.24,5.0.34]
master to a fixed (5.0.36) slave! To warn users against this when
they upgrade their slave, as agreed with the support team, we add
code for a fixed slave to detect that it is connected to a buggy
master in a situation (INSERT ON DUP KEY UPDATE into autoinc column)
likely to break replication, in which case it cannot replicate so
stops and prints a message to the slave's error log and to SHOW SLAVE
STATUS.
For 5.0.36->[5.0.24,5.0.34] replication we cannot warn as master
does not know the slave's version (but we always recommended to users
to have slave at least as new as master).
As agreed with support, I'll also ask for an alert to be put into
the MySQL Network Monitoring and Advisory Service.
mysql-test/r/rpl_insert_id.result:
results to check the bugfix; without the bugfix, you would see, in
master and slave:
"3,2" instead of "2,2" for the INSERT VALUES testcase,
"11,6,..." instead of "6,6,..." for the INSERT SELECT testcase.
mysql-test/t/rpl_insert_id.test:
testing that BUG#24432 is fixed
sql/log_event.cc:
A trick to force the master to pretend it is old and features BUG#24432.
To do fast lookups in the list of known bugs by version, we compute
the 3 X.Y.Z numbers from the master's version string and cache that
into a new member Format_description_log_event::server_version_split.
We do this computation in the event's two constructors.
A simple prevention against buffer overrun when reading the master's
version from a binlog event (assume the event is corrupted on disk,
and so the version string on disk is longer than ST_SERVER_VER_LEN
(50), then we would not get a closing 0 at the end of the class member.
sql/log_event.h:
new member to hold the "split server version" (3 numbers X.Y.Z),
and a method to compute this from the version string.
sql/slave.cc:
a function which tells, based on master's version (as found
in the Format_description event in the relay log being executed),
if master can have a certain bug. This function uses a list of
bug_id / first_version_with_bug / first_version_with_fix.
If the test is positive, a short error message is put into SHOW SLAVE
STATUS, and a verbose message is put into the slave's error log.
The caller is expected to stop the slave in this case.
sql/slave.h:
new function to test if the replication master has a bug
sql/sql_insert.cc:
Fix for BUG#24432:t he reason was a misplaced restore_auto_increment()
(misplaced when fixing BUG#20188). Indeed, when updating the row,
it is clear that the autogenerated auto_increment value will not be
used for this row (and if by "chance" the autoinc value present
in the updated row is >= to the not used autogenerated value,
adjust_next_insert_id_after_explicit_value() will fix next_insert_id).
We also add code for a fixed slave to detect that it is connected to
a buggy master (in which case it cannot replicate so stops).
mysql-test/r/rpl_known_bugs_detection.result:
see that SHOW SLAVE STATUS prints information that slave found a bug
in master, and does not execute the dangerous event (table stays
empty).
mysql-test/t/rpl_known_bugs_detection-master.opt:
pass debug symbol to make the master pretend it has BUG#24432
mysql-test/t/rpl_known_bugs_detection.test:
new test to see if bug detection by slave works
2007-02-08 15:53:14 +01:00
|
|
|
bool rpl_master_has_bug(RELAY_LOG_INFO *rli, uint bug_id);
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2004-10-19 22:27:19 +02:00
|
|
|
const char *print_slave_db_safe(const char *db);
|
2006-11-10 15:10:41 +01:00
|
|
|
int check_expected_error(THD* thd, RELAY_LOG_INFO const *rli, int error_code);
|
2001-08-03 23:57:53 +02:00
|
|
|
void skip_load_data_infile(NET* net);
|
2006-11-10 15:10:41 +01:00
|
|
|
void slave_print_msg(enum loglevel level, RELAY_LOG_INFO const *rli,
|
2006-09-29 05:20:33 +02:00
|
|
|
int err_code, const char* msg, ...)
|
|
|
|
ATTRIBUTE_FORMAT(printf, 4, 5);
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2002-07-17 14:17:20 +02:00
|
|
|
void end_slave(); /* clean up */
|
2003-09-13 22:13:41 +02:00
|
|
|
void clear_until_condition(RELAY_LOG_INFO* rli);
|
A change of behaviour of Seconds_Behind_Master from SHOW SLAVE STATUS. It's going into 4.1
because old behaviour was somewhat nonsensical (kind of bug). Changes are that if repl threads are
down or disconnected the column will be NULL, and if master is idle the column will not grow indefinitely anymore.
sql/slave.cc:
mi->slave_running and rli->slave_running now uints (was needed only for mi but because of start_slave_thread() usage,
had to change both).
So mi->slave_running can now take 3 values: not running, running & not connected, running and connected.
The last value serves for calculation of Seconds_Behind_Master in SHOW SLAVE STATUS.
Changing this column's behaviour: if SQL or I/O thread is not running, or if I/O thread is not connected
(for example if it is reconnecting), it's NULL (to mean "unknown"). And if master is idle, the column will
not grow indefinitely like it used to (that was meaningless); this is fixed by forcing a value of 0
when the slave SQL thread has hit EOF of relay log (which has only a limited number of caveats explained
in comments in code).
sql/slave.h:
slave_running used to be bool but we need to distinguish, for the I/O slave thread, between
"running & connected" and "running & not connected" ("running" means the thread exists).
sql/sql_repl.cc:
we don't need anymore to set rli->last_master_timestamp to 0 (we used that to make Seconds_Behind_Master
be NULL) in RESET SLAVE and CHANGE MASTER, as these commands imply that slave threads are not running
and so Seconds_Behind_Master is already NULL because of that.
2004-12-16 18:12:22 +01:00
|
|
|
void clear_slave_error(RELAY_LOG_INFO* rli);
|
2002-01-20 03:16:52 +01:00
|
|
|
void end_relay_log_info(RELAY_LOG_INFO* rli);
|
|
|
|
void lock_slave_threads(MASTER_INFO* mi);
|
|
|
|
void unlock_slave_threads(MASTER_INFO* mi);
|
|
|
|
void init_thread_mask(int* mask,MASTER_INFO* mi,bool inverse);
|
|
|
|
int init_relay_log_pos(RELAY_LOG_INFO* rli,const char* log,ulonglong pos,
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
client/Makefile.am:
mysqlbinlog.cc depends slightly on sql/mysql_priv.h
client/mysqlbinlog.cc:
Make mysqlbinlog able to read the new binlog format,
by seeking to the start and reading the first few events, to
detect the format of the binlog.
include/my_sys.h:
a correct tell() for SEQ_READ_APPEND caches.
mysys/mf_iocache2.c:
a correct tell() for SEQ_READ_APPEND caches
(my_b_tell() is not working for such caches).
sql/ha_innodb.cc:
we are getting rid of event lengthes here and there, which is good.
sql/log.cc:
Start events will have created==0 if generated by rotation (like in 3.23).
In 5.0 we always write a Format_description_log_event at the beginning of
every master's binary log and of every slave's relay log.
We also add Rotate and Stop to relay logs (like there already was in
master's binary logs).
When we rotate a relay log, we write the previous relay log's Start event
(the one which was sent from the master) to the beginning of the new log,
so that we don't need the previous relay log to understand the new one;
that's the purpose of MYSQL_LOG::description_event_for_queue.
Removed logging of SET FOREIGN_KEY_CHECKS, because we handle it as flags
in the Query event now.
sql/log_event.cc:
New event type: Format_description_log_event, to describe the log's format.
read_log_event() needs to be passed this event to be able to read 5.0 events.
Query_log_event has new members flags2 and sql_mode for replication of session
variables (except charsets which are WL#1062) and SQL_MODE.
flags2 is in fact a kind of copy of thd->options (&'d with a mask).
Now with this replication of FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS
and SQL_MODE work; with mysqlbinlog too.
sql/log_event.h:
Binlog version is changed to 4.
New classes (details in sql/log_event.cc).
Removing some useless #defines.
sql/mysql_priv.h:
Definition of SELECT_DISTINCT and others must be visible in client/mysqlbinlog.cc,
so adding #ifdefs.
sql/mysqld.cc:
update for prototype change
sql/slave.cc:
When the slave opens a relay log, it reads the first few events to know the format.
When slave I/O thread receives a Rotate from the master, it rotates its relay log
(to avoid mixed format in the relay log).
sql/slave.h:
in the slave we avoid lengthes and rely on absolute positions instead;
hence the introduction of future_group_master_log_pos and future_event_relay_log_pos
(explained in code).
sql/sql_class.cc:
catalog in THD
sql/sql_class.h:
catalog, and new members in MYSQL_LOG
sql/sql_repl.cc:
When the master starts sending binlog to slave, it must
first read the first few events to detect the binlog's format.
Same for SHOW BINLOG EVENTS.
2003-12-18 01:09:05 +01:00
|
|
|
bool need_data_lock, const char** errmsg,
|
|
|
|
bool look_for_description_event);
|
2001-01-24 17:15:34 +01:00
|
|
|
|
2002-08-08 02:12:02 +02:00
|
|
|
int purge_relay_logs(RELAY_LOG_INFO* rli, THD *thd, bool just_reset,
|
|
|
|
const char** errmsg);
|
This will be pushed only after I fix the testsuite.
This is the main commit for Worklog tasks:
* A more dynamic binlog format which allows small changes (1064)
* Log session variables in Query_log_event (1063)
Below 5.0 means 5.0.0.
MySQL 5.0 is able to replicate FOREIGN_KEY_CHECKS, UNIQUE_KEY_CHECKS (for speed),
SQL_AUTO_IS_NULL, SQL_MODE. Not charsets (WL#1062), not some vars (I can only think
of SQL_SELECT_LIMIT, which deserves a special treatment). Note that this
works for queries, except LOAD DATA INFILE (for this it would have to wait
for Dmitri's push of WL#874, which in turns waits for the present push, so...
the deadlock must be broken!). Note that when Dmitri pushes WL#874 in 5.0.1,
5.0.0 won't be able to replicate a LOAD DATA INFILE from 5.0.1.
Apart from that, the new binlog format is designed so that it can tolerate
a little variation in the events (so that a 5.0.0 slave could replicate a
5.0.1 master, except for LOAD DATA INFILE unfortunately); that is, when I
later add replication of charsets it should break nothing. And when I later
add a UID to every event, it should break nothing.
The main change brought by this patch is a new type of event, Format_description_log_event,
which describes some lengthes in other event types. This event is needed for
the master/slave/mysqlbinlog to understand a 5.0 log. Thanks to this event,
we can later add more bytes to the header of every event without breaking compatibility.
Inside Query_log_event, we have some additional dynamic format, as every Query_log_event
can have a different number of status variables, stored as pairs (code, value); that's
how SQL_MODE and session variables and catalog are stored. Like this, we can later
add count of affected rows, charsets... and we can have options --don't-log-count-affected-rows
if we want.
MySQL 5.0 is able to run on 4.x relay logs, 4.x binlogs.
Upgrading a 4.x master to 5.0 is ok (no need to delete binlogs),
upgrading a 4.x slave to 5.0 is ok (no need to delete relay logs);
so both can be "hot" upgrades.
Upgrading a 3.23 master to 5.0 requires as much as upgrading it to 4.0.
3.23 and 4.x can't be slaves of 5.0.
So downgrading from 5.0 to 4.x may be complicated.
Log_event::log_pos is now the position of the end of the event, which is
more useful than the position of the beginning. We take care about compatibility
with <5.0 (in which log_pos is the beginning).
I added a short test for replication of SQL_MODE and some other variables.
TODO:
- after committing this, merge the latest 5.0 into it
- fix all tests
- update the manual with upgrade notes.
client/Makefile.am:
mysqlbinlog.cc depends slightly on sql/mysql_priv.h
client/mysqlbinlog.cc:
Make mysqlbinlog able to read the new binlog format,
by seeking to the start and reading the first few events, to
detect the format of the binlog.
include/my_sys.h:
a correct tell() for SEQ_READ_APPEND caches.
mysys/mf_iocache2.c:
a correct tell() for SEQ_READ_APPEND caches
(my_b_tell() is not working for such caches).
sql/ha_innodb.cc:
we are getting rid of event lengthes here and there, which is good.
sql/log.cc:
Start events will have created==0 if generated by rotation (like in 3.23).
In 5.0 we always write a Format_description_log_event at the beginning of
every master's binary log and of every slave's relay log.
We also add Rotate and Stop to relay logs (like there already was in
master's binary logs).
When we rotate a relay log, we write the previous relay log's Start event
(the one which was sent from the master) to the beginning of the new log,
so that we don't need the previous relay log to understand the new one;
that's the purpose of MYSQL_LOG::description_event_for_queue.
Removed logging of SET FOREIGN_KEY_CHECKS, because we handle it as flags
in the Query event now.
sql/log_event.cc:
New event type: Format_description_log_event, to describe the log's format.
read_log_event() needs to be passed this event to be able to read 5.0 events.
Query_log_event has new members flags2 and sql_mode for replication of session
variables (except charsets which are WL#1062) and SQL_MODE.
flags2 is in fact a kind of copy of thd->options (&'d with a mask).
Now with this replication of FOREIGN_KEY_CHECKS, SQL_AUTO_IS_NULL, UNIQUE_CHECKS
and SQL_MODE work; with mysqlbinlog too.
sql/log_event.h:
Binlog version is changed to 4.
New classes (details in sql/log_event.cc).
Removing some useless #defines.
sql/mysql_priv.h:
Definition of SELECT_DISTINCT and others must be visible in client/mysqlbinlog.cc,
so adding #ifdefs.
sql/mysqld.cc:
update for prototype change
sql/slave.cc:
When the slave opens a relay log, it reads the first few events to know the format.
When slave I/O thread receives a Rotate from the master, it rotates its relay log
(to avoid mixed format in the relay log).
sql/slave.h:
in the slave we avoid lengthes and rely on absolute positions instead;
hence the introduction of future_group_master_log_pos and future_event_relay_log_pos
(explained in code).
sql/sql_class.cc:
catalog in THD
sql/sql_class.h:
catalog, and new members in MYSQL_LOG
sql/sql_repl.cc:
When the master starts sending binlog to slave, it must
first read the first few events to detect the binlog's format.
Same for SHOW BINLOG EVENTS.
2003-12-18 01:09:05 +01:00
|
|
|
void set_slave_thread_options(THD* thd);
|
2006-11-10 15:10:41 +01:00
|
|
|
void set_slave_thread_default_charset(THD *thd, RELAY_LOG_INFO const *rli);
|
2003-07-06 17:59:54 +02:00
|
|
|
void rotate_relay_log(MASTER_INFO* mi);
|
2002-01-20 03:16:52 +01:00
|
|
|
|
2005-10-08 16:39:55 +02:00
|
|
|
pthread_handler_t handle_slave_io(void *arg);
|
|
|
|
pthread_handler_t handle_slave_sql(void *arg);
|
2002-01-20 03:16:52 +01:00
|
|
|
extern bool volatile abort_loop;
|
2002-07-17 14:17:20 +02:00
|
|
|
extern MASTER_INFO main_mi, *active_mi; /* active_mi for multi-master */
|
2002-01-20 03:16:52 +01:00
|
|
|
extern LIST master_list;
|
2005-10-04 18:52:12 +02:00
|
|
|
extern my_bool replicate_same_server_id;
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2000-12-02 18:11:50 +01:00
|
|
|
extern int disconnect_slave_event_count, abort_slave_event_count ;
|
2000-11-22 08:23:31 +01:00
|
|
|
|
2002-07-17 14:17:20 +02:00
|
|
|
/* the master variables are defaults read from my.cnf or command line */
|
2001-05-31 02:50:56 +02:00
|
|
|
extern uint master_port, master_connect_retry, report_port;
|
2000-11-11 22:50:39 +01:00
|
|
|
extern my_string master_user, master_password, master_host,
|
2002-01-29 17:32:16 +01:00
|
|
|
master_info_file, relay_log_info_file, report_user, report_host,
|
|
|
|
report_password;
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2003-09-01 13:16:20 +02:00
|
|
|
extern my_bool master_ssl;
|
|
|
|
extern my_string master_ssl_ca, master_ssl_capath, master_ssl_cert,
|
|
|
|
master_ssl_cipher, master_ssl_key;
|
|
|
|
|
2000-11-11 22:50:39 +01:00
|
|
|
extern I_List<THD> threads;
|
|
|
|
|
2005-12-22 06:39:02 +01:00
|
|
|
#endif /* HAVE_REPLICATION */
|
|
|
|
|
|
|
|
/* masks for start/stop operations on io and sql slave threads */
|
2002-12-16 14:33:29 +01:00
|
|
|
#define SLAVE_IO 1
|
|
|
|
#define SLAVE_SQL 2
|
2005-12-22 06:39:02 +01:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|