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
|
|
|
|
|
2007-08-15 18:11:16 +02:00
|
|
|
/**
|
|
|
|
@defgroup Replication Replication
|
|
|
|
@{
|
|
|
|
|
|
|
|
@file
|
|
|
|
*/
|
2009-09-29 13:16:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Some of defines are need in parser even though replication is not
|
|
|
|
compiled in (embedded).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
The maximum is defined as (ULONG_MAX/1000) with 4 bytes ulong
|
|
|
|
*/
|
|
|
|
#define SLAVE_MAX_HEARTBEAT_PERIOD 4294967
|
|
|
|
|
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
|
2007-08-16 07:37:50 +02:00
|
|
|
class Relay_log_info;
|
2007-08-16 08:52:50 +02:00
|
|
|
class Master_info;
|
2007-04-12 08:58:04 +02:00
|
|
|
|
2007-08-16 07:37:50 +02:00
|
|
|
|
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
|
2007-08-16 08:52:50 +02: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
|
2007-08-16 07:37:50 +02: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:
|
|
|
|
|
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
|
2007-08-16 08:52:50 +02:00
|
|
|
shutdown, and not changed: it always points to the same Master_info struct),
|
2004-03-11 16:23:35 +01:00
|
|
|
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
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
In Master_info: run_lock, data_lock
|
2008-02-05 16:36:26 +01:00
|
|
|
run_lock protects all information about the run state: slave_running, thd
|
|
|
|
and the existence of the I/O thread to stop/start it, you need this mutex).
|
2003-08-25 16:20:21 +02:00
|
|
|
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
|
|
|
|
2007-08-16 07:37:50 +02:00
|
|
|
In Relay_log_info: run_lock, data_lock
|
2007-08-16 08:52:50 +02:00
|
|
|
see Master_info
|
2003-08-25 16:20:21 +02:00
|
|
|
|
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;
|
2008-11-22 00:22:21 +01:00
|
|
|
extern char slave_skip_error_names[];
|
2002-01-22 23:05:11 +01:00
|
|
|
extern bool use_slave_mask;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern char *slave_load_tmpdir;
|
|
|
|
extern char *master_info_file, *relay_log_info_file;
|
|
|
|
extern char *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
|
|
|
|
2004-12-16 18:12:22 +01:00
|
|
|
/*
|
2007-08-16 08:52:50 +02:00
|
|
|
3 possible values for Master_info::slave_running and
|
2007-08-16 07:37:50 +02:00
|
|
|
Relay_log_info::slave_running.
|
2004-12-16 18:12:22 +01:00
|
|
|
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.
|
2007-08-16 07:37:50 +02:00
|
|
|
The same way, code is assuming that in Relay_log_info we use only values
|
2004-12-16 18:12:22 +01:00
|
|
|
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
|
|
|
|
|
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();
|
2009-09-30 23:41:05 +02:00
|
|
|
int init_recovery(Master_info* mi, const char** errmsg);
|
2002-04-30 15:40:46 +02:00
|
|
|
void init_slave_skip_errors(const char* arg);
|
2007-08-16 07:37:50 +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);
|
2007-08-16 08:52:50 +02:00
|
|
|
int terminate_slave_threads(Master_info* mi, int thread_mask,
|
2002-01-20 03:16:52 +01:00
|
|
|
bool skip_lock = 0);
|
|
|
|
int start_slave_threads(bool need_slave_mutex, bool wait_for_start,
|
2007-08-16 08:52:50 +02:00
|
|
|
Master_info* mi, const char* master_info_fname,
|
2002-01-20 03:16:52 +01:00
|
|
|
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,
|
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,
|
2009-11-23 17:57:31 +01:00
|
|
|
Master_info* mi);
|
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);
|
|
|
|
|
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,
|
2007-08-16 08:52:50 +02:00
|
|
|
Master_info* mi, MYSQL* mysql, bool overwrite);
|
2001-05-29 03:18:23 +02:00
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
bool show_master_info(THD* thd, Master_info* mi);
|
2004-10-20 03:04:37 +02:00
|
|
|
bool show_binlog_info(THD* thd);
|
BUG#37426: RBR breaks for CHAR() UTF-8 fields > 85 chars
In order to handle CHAR() fields, 8 bits were reserved for
the size of the CHAR field. However, instead of denoting the
number of characters in the field, field_length was used which
denotes the number of bytes in the field.
Since UTF-8 fields can have three bytes per character (and
has been extended to have four bytes per character in 6.0),
an extra two bits have been encoded in the field metadata
work for fields of type Field_string (i.e., CHAR fields).
Since the metadata word is filled, the extra bits have been
encoded in the upper 4 bits of the real type (the most
significant byte of the metadata word) by computing the
bitwise xor of the extra two bits. Since the upper 4 bits
of the real type always is 1111 for Field_string, this
means that for fields of length <256, the encoding is
identical to the encoding used in pre-5.1.26 servers, but
for lengths of 256 or more, an unrecognized type is formed,
causing an old slave (that does not handle lengths of 256
or more) to stop.
2008-06-30 22:11:18 +02:00
|
|
|
bool rpl_master_has_bug(const Relay_log_info *rli, uint bug_id, bool report,
|
|
|
|
bool (*pred)(const void *), const void *param);
|
BUG#33029 5.0 to 5.1 replication fails on dup key when inserting
using a trig in SP
For all 5.0 and up to 5.1.12 exclusive, when a stored routine or
trigger caused an INSERT into an AUTO_INCREMENT column, the
generated AUTO_INCREMENT value should not be written into the
binary log, which means if a statement does not generate
AUTO_INCREMENT value itself, there will be no Intvar event (SET
INSERT_ID) associated with it even if one of the stored routine
or trigger caused generation of such a value. And meanwhile, when
executing a stored routine or trigger, it would ignore the
INSERT_ID value even if there is a INSERT_ID value available set
by a SET INSERT_ID statement.
Starting from MySQL 5.1.12, the generated AUTO_INCREMENT value is
written into the binary log, and the value will be used if
available when executing the stored routine or trigger.
Prior fix of this bug in MySQL 5.0 and prior MySQL 5.1.12
(referenced as the buggy versions in the text below), when a
statement that generates AUTO_INCREMENT value by the top
statement was executed in the body of a SP, all statements in the
SP after this statement would be treated as if they had generated
AUTO_INCREMENT by the top statement. When a statement that did
not generate AUTO_INCREMENT value by the top statement but by a
function/trigger called by it, an erroneous Intvar event would be
associated with the statement, this erroneous INSERT_ID value
wouldn't cause problem when replicating between masters and
slaves of 5.0.x or prior 5.1.12, because the erroneous INSERT_ID
value was not used when executing functions/triggers. But when
replicating from buggy versions to 5.1.12 or newer, which will
use the INSERT_ID value in functions/triggers, the erroneous
value will be used, which would cause duplicate entry error and
cause the slave to stop.
The patch for 5.1 fixed it to ignore the SET INSERT_ID value when
executing functions/triggers if it is replicating from a master
of buggy versions, another patch for 5.0 fixed it not to generate
the erroneous Intvar event.
2008-03-14 04:35:41 +01:00
|
|
|
bool rpl_master_erroneous_autoinc(THD* thd);
|
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);
|
2001-08-03 23:57:53 +02:00
|
|
|
void skip_load_data_infile(NET* net);
|
2000-11-11 22:50:39 +01:00
|
|
|
|
2009-06-23 11:10:04 +02:00
|
|
|
void end_slave(); /* release slave threads */
|
|
|
|
void close_active_mi(); /* clean up slave threads data */
|
2007-08-16 07:37:50 +02:00
|
|
|
void clear_until_condition(Relay_log_info* rli);
|
|
|
|
void clear_slave_error(Relay_log_info* rli);
|
|
|
|
void end_relay_log_info(Relay_log_info* rli);
|
2007-08-16 08:52:50 +02:00
|
|
|
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);
|
2007-08-16 07:37:50 +02:00
|
|
|
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.
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
|
|
|
|
2007-08-16 07:37:50 +02:00
|
|
|
int purge_relay_logs(Relay_log_info* rli, THD *thd, bool just_reset,
|
2002-08-08 02:12:02 +02:00
|
|
|
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.
2003-12-18 01:09:05 +01:00
|
|
|
void set_slave_thread_options(THD* thd);
|
2007-08-16 07:37:50 +02:00
|
|
|
void set_slave_thread_default_charset(THD *thd, Relay_log_info const *rli);
|
2007-08-16 08:52:50 +02:00
|
|
|
void rotate_relay_log(Master_info* mi);
|
2009-10-14 03:39:05 +02:00
|
|
|
int apply_event_and_update_pos(Log_event* ev, THD* thd, Relay_log_info* rli);
|
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;
|
2007-08-16 08:52:50 +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;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern char * master_user, *master_password, *master_host;
|
|
|
|
extern char *master_info_file, *relay_log_info_file, *report_user;
|
|
|
|
extern char *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;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
extern char *master_ssl_ca, *master_ssl_capath, *master_ssl_cert;
|
|
|
|
extern char *master_ssl_cipher, *master_ssl_key;
|
2003-09-01 13:16:20 +02:00
|
|
|
|
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
|
|
|
|
2007-08-15 18:11:16 +02:00
|
|
|
/**
|
|
|
|
@} (end of group Replication)
|
|
|
|
*/
|
2005-12-22 06:39:02 +01:00
|
|
|
|
2007-08-15 18:11:16 +02:00
|
|
|
#endif
|