mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
034b44cb9f
BitKeeper/etc/logging_ok: auto-union scripts/make_win_src_distribution.old: Merge rename: scripts/make_win_src_distribution.sh -> scripts/make_win_src_distribution.old BUILD/compile-pentium-debug-max: Auto merged BitKeeper/deleted/.del-sel000001.result~383913ae4505ec86: Auto merged BitKeeper/deleted/.del-sel000001.test~9567c1646058cc: Auto merged Build-tools/Bootstrap: Auto merged Build-tools/Do-compile: Auto merged Docs/Makefile.am: Auto merged client/get_password.c: Auto merged client/mysql.cc: Auto merged client/mysqltest.c: Auto merged extra/perror.c: Auto merged include/config-win.h: Auto merged include/my_sys.h: Auto merged innobase/btr/btr0cur.c: Auto merged innobase/btr/btr0pcur.c: Auto merged innobase/buf/buf0buf.c: Auto merged innobase/buf/buf0flu.c: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/dict/dict0load.c: Auto merged innobase/include/buf0buf.h: Auto merged innobase/include/log0recv.h: Auto merged innobase/include/row0sel.h: Auto merged innobase/include/srv0srv.h: Auto merged innobase/include/ut0mem.h: Auto merged innobase/lock/lock0lock.c: Auto merged innobase/log/log0log.c: Auto merged innobase/mem/mem0pool.c: Auto merged innobase/os/os0file.c: Auto merged innobase/row/row0mysql.c: Auto merged innobase/row/row0sel.c: Auto merged innobase/srv/srv0srv.c: Auto merged innobase/srv/srv0start.c: Auto merged innobase/trx/trx0sys.c: Auto merged innobase/trx/trx0trx.c: Auto merged innobase/ut/ut0mem.c: Auto merged innobase/ut/ut0ut.c: Auto merged myisam/ft_boolean_search.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_extra.c: Auto merged myisam/mi_key.c: Auto merged myisam/myisamdef.h: Auto merged myisammrg/myrg_queue.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/ctype_latin1_de.result: Auto merged mysql-test/r/flush.result: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/grant_cache.result: Auto merged mysql-test/r/join.result: Auto merged mysql-test/r/join_outer.result: Auto merged mysql-test/r/range.result: Auto merged mysql-test/r/rpl000018.result: Auto merged mysql-test/r/rpl_insert_id.result: Auto merged mysql-test/r/rpl_master_pos_wait.result: Auto merged mysql-test/r/rpl_relayspace.result: Auto merged mysql-test/r/select_safe.result: Auto merged mysql-test/r/symlink.result: Auto merged mysql-test/r/type_date.result: Auto merged mysql-test/r/type_datetime.result: Auto merged mysql-test/t/alias.test: Auto merged mysql-test/t/ctype_latin1_de.test: Auto merged mysql-test/t/fulltext_left_join.test: Auto merged mysql-test/t/func_time.test: Auto merged mysql-test/t/handler.test: Auto merged mysql-test/t/heap.test: Auto merged mysql-test/t/join.test: Auto merged mysql-test/t/join_outer.test: Auto merged mysql-test/t/order_by.test: Auto merged mysql-test/t/range.test: Auto merged mysql-test/t/rpl000001.test: Auto merged mysql-test/t/rpl000018.test: Auto merged mysql-test/t/rpl_insert_id.test: Auto merged mysql-test/t/sel000100.test: Auto merged mysql-test/t/select_safe.test: Auto merged mysql-test/t/type_date.test: Auto merged mysql-test/t/type_datetime.test: Auto merged mysql-test/t/user_var.test: Auto merged mysys/default.c: Auto merged mysys/mf_format.c: Auto merged mysys/my_getopt.c: Auto merged mysys/thr_lock.c: Auto merged mysys/tree.c: Auto merged scripts/Makefile.am: Auto merged scripts/mysql_install_db.sh: Auto merged scripts/mysqld_safe.sh: Auto merged sql/Makefile.am: Auto merged sql/field_conv.cc: Auto merged sql/ha_innodb.h: Auto merged sql/ha_myisam.cc: Auto merged sql/ha_myisammrg.h: Auto merged sql/handler.cc: Auto merged sql/handler.h: Auto merged sql/item.h: Auto merged sql/item_func.cc: Auto merged sql/item_timefunc.cc: Auto merged sql/net_serv.cc: Auto merged sql/nt_servc.cc: Auto merged sql/opt_range.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_cache.h: Auto merged sql/sql_db.cc: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_list.h: Auto merged sql/sql_load.cc: Auto merged sql/sql_rename.cc: Auto merged sql/sql_repl.h: Auto merged sql/sql_update.cc: Auto merged sql/table.cc: Auto merged sql/table.h: Auto merged sql/uniques.cc: Auto merged support-files/mysql.spec.sh: Auto merged vio/viosocket.c: Auto merged BitKeeper/deleted/.del-ctype-latin1_de.c~c5d8f9208bceb98e: merge BitKeeper/deleted/.del-mini_client.cc~8677895ec8169183: merge acinclude.m4: Merge with 4.0 (openssl patch) client/mysqlbinlog.cc: Merge with 4.0 in which we had added code from 4.1 (We are basicly only using the 4.1 code here) configure.in: Keep 4.1 file heap/hp_open.c: merge with 4.0 include/my_base.h: merge with 4.0 include/my_global.h: merge with 4.0 include/mysqld_error.h: merge with 4.0 innobase/ha/ha0ha.c: merge with 4.0 (Code should be same but we use indentaion from 4.0) innobase/log/log0recv.c: merge with 4.0 libmysql/libmysql.c: Remove with 4.0 code that was ported from 4.1 libmysqld/lib_sql.cc: merge with 4.0 myisam/mi_open.c: Remove 4.0 specific code myisam/myisamchk.c: merge with 4.0 myisammrg/myrg_rkey.c: merge with 4.0 mysql-test/r/alter_table.result: May need to be fixed after merge mysql-test/r/create.result: May need to be fixed after merge mysql-test/r/distinct.result: May need to be fixed after merge mysql-test/r/drop.result: May need to be fixed after merge mysql-test/r/fulltext.result: May need to be fixed after merge mysql-test/r/func_set.result: May need to be fixed after merge mysql-test/r/func_str.result: May need to be fixed after merge mysql-test/r/func_test.result: May need to be fixed after merge mysql-test/r/grant.result: May need to be fixed after merge mysql-test/r/group_by.result: May need to be fixed after merge mysql-test/r/handler.result: May need to be fixed after merge mysql-test/r/heap.result: May need to be fixed after merge mysql-test/r/innodb.result: May need to be fixed after merge mysql-test/r/insert.result: May need to be fixed after merge mysql-test/r/insert_select.result: May need to be fixed after merge mysql-test/r/key_diff.result: May need to be fixed after merge mysql-test/r/merge.result: May need to be fixed after merge mysql-test/r/myisam.result: May need to be fixed after merge mysql-test/r/order_by.result: May need to be fixed after merge mysql-test/r/query_cache.result: May need to be fixed after merge mysql-test/r/rpl_flush_log_loop.result: May need to be fixed after merge mysql-test/r/rpl_loaddata.result: May need to be fixed after merge mysql-test/r/rpl_log.result: May need to be fixed after merge mysql-test/r/rpl_log_pos.result: May need to be fixed after merge mysql-test/r/rpl_rotate_logs.result: May need to be fixed after merge mysql-test/r/select.result: May need to be fixed after merge mysql-test/r/union.result: May need to be fixed after merge mysql-test/r/user_var.result: May need to be fixed after merge mysql-test/t/alter_table.test: merge with 4.0 mysql-test/t/create.test: merge with 4.0 mysql-test/t/distinct.test: merge with 4.0 mysql-test/t/drop.test: merge with 4.0 mysql-test/t/flush.test: merge with 4.0 mysql-test/t/fulltext.test: merge with 4.0 mysql-test/t/func_set.test: merge with 4.0 mysql-test/t/func_str.test: merge with 4.0 mysql-test/t/func_test.test: merge with 4.0 mysql-test/t/grant.test: merge with 4.0 mysql-test/t/grant_cache.test: merge with 4.0 mysql-test/t/innodb.test: Add back EXPLAIN and SHOW KEYS statements, but make them independent of number of rows returned by InnoDB mysql-test/t/insert.test: merge with 4.0 mysql-test/t/insert_select.test: merge with 4.0 mysql-test/t/merge.test: merge with 4.0 mysql-test/t/query_cache.test: merge with 4.0 mysql-test/t/rpl_flush_log_loop.test: merge with 4.0 mysql-test/t/rpl_loaddata.test: merge with 4.0 mysql-test/t/rpl_rotate_logs.test: merge with 4.0 mysql-test/t/select.test: merge with 4.0 mysql-test/t/symlink.test: merge with 4.0 mysql-test/t/union.test: merge with 4.0 mysys/charset.c: merge with 4.0 scripts/mysql_fix_privilege_tables.sh: merge with 4.0 (Add quoting for some variables) sql/field.h: merge with 4.0 sql/ha_innodb.cc: merge with 4.0 sql/item_cmpfunc.cc: merge with 4.0 sql/item_cmpfunc.h: merge with 4.0 sql/item_func.h: merge with 4.0 sql/item_strfunc.cc: merge with 4.0 Fixed null handling with ELT() sql/item_timefunc.h: merge with 4.0 sql/lex.h: merge with 4.0 sql/log.cc: merge with 4.0 sql/log_event.cc: Merge with 4.0 Cleanups: - Indentation - #endif comments - Replace strmov() with *pos++= for two byte strings - Moved variable declarations to start of functions - Merged identical code (LOAD_EVENT) - Added casts when subtracting pointers Did a full diff between this and 4.0 to ensure that the file is correct after merge. sql/log_event.h: merge with 4.0 sql/mysql_priv.h: merge with 4.0 sql/mysqld.cc: merge with 4.0 sql/repl_failsafe.cc: merge with 4.0 sql/set_var.cc: merge with 4.0 sql/set_var.h: merge with 4.0 sql/share/czech/errmsg.txt: merge with 4.0 sql/share/danish/errmsg.txt: merge with 4.0 sql/share/dutch/errmsg.txt: merge with 4.0 sql/share/english/errmsg.txt: merge with 4.0 sql/share/estonian/errmsg.txt: merge with 4.0 sql/share/french/errmsg.txt: merge with 4.0 sql/share/german/errmsg.txt: merge with 4.0 sql/share/greek/errmsg.txt: merge with 4.0 sql/share/hungarian/errmsg.txt: merge with 4.0 sql/share/italian/errmsg.txt: merge with 4.0 sql/share/japanese/errmsg.txt: merge with 4.0 sql/share/korean/errmsg.txt: merge with 4.0 sql/share/norwegian-ny/errmsg.txt: merge with 4.0 sql/share/norwegian/errmsg.txt: merge with 4.0 sql/share/polish/errmsg.txt: merge with 4.0 sql/share/portuguese/errmsg.txt: merge with 4.0 sql/share/romanian/errmsg.txt: merge with 4.0 sql/share/russian/errmsg.txt: merge with 4.0 sql/share/slovak/errmsg.txt: merge with 4.0 sql/share/spanish/errmsg.txt: merge with 4.0 sql/share/swedish/errmsg.txt: merge with 4.0 sql/share/ukrainian/errmsg.txt: merge with 4.0 sql/slave.cc: Merge + some indentation fixes sql/slave.h: merge with 4.0 sql/sql_acl.cc: merge with 4.0 Some end space removal to make it easier to do future merges sql/sql_acl.h: merge with 4.0 sql/sql_cache.cc: merge with 4.0 sql/sql_class.h: merge with 4.0 sql/sql_handler.cc: merge with 4.0 sql/sql_lex.cc: merge with 4.0 sql/sql_lex.h: merge with 4.0 sql/sql_parse.cc: merge with 4.0 sql/sql_repl.cc: merge with 4.0 sql/sql_select.cc: merge with 4.0 sql/sql_table.cc: merge with 4.0 sql/sql_union.cc: Merge with 4.0 Note that I couldn't find out how to merge OPTION_FOUND_ROWS handling so this has to be fixed later sql/sql_yacc.yy: merge with 4.0 Removed end space to make merge easier vio/Makefile.am: merge with 4.0
479 lines
16 KiB
C
479 lines
16 KiB
C
#ifdef HAVE_REPLICATION
|
|
|
|
#ifndef SLAVE_H
|
|
#define SLAVE_H
|
|
|
|
#include "mysql.h"
|
|
#include "my_list.h"
|
|
#define SLAVE_NET_TIMEOUT 3600
|
|
#define MAX_SLAVE_ERRMSG 1024
|
|
#define MAX_SLAVE_ERROR 2000
|
|
|
|
/*****************************************************************************
|
|
|
|
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
|
|
a single, shared relay log file. A MASTER_INFO struct
|
|
represents each of these threads.
|
|
|
|
SQL Thread - One of these threads is started and reads from the relay log
|
|
file, executing each event. A RELAY_LOG_INFO struct
|
|
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.
|
|
|
|
*****************************************************************************/
|
|
|
|
extern ulong master_retry_count;
|
|
extern MY_BITMAP slave_error_mask;
|
|
extern bool use_slave_mask;
|
|
extern char* slave_load_tmpdir;
|
|
extern my_string master_info_file,relay_log_info_file;
|
|
extern my_string opt_relay_logname, opt_relaylog_index_name;
|
|
extern my_bool opt_skip_slave_start, opt_reckless_slave;
|
|
extern my_bool opt_log_slave_updates;
|
|
extern ulonglong relay_log_space_limit;
|
|
struct st_master_info;
|
|
|
|
extern "C" {
|
|
extern ulong slave_net_timeout;
|
|
};
|
|
|
|
enum enum_binlog_formats {
|
|
BINLOG_FORMAT_CURRENT=0, /* 0 is important for easy 'if (mi->old_format)' */
|
|
BINLOG_FORMAT_323_LESS_57,
|
|
BINLOG_FORMAT_323_GEQ_57 };
|
|
|
|
/*
|
|
TODO: this needs to be redone, but for now it does not matter since
|
|
we do not have multi-master yet.
|
|
*/
|
|
|
|
#define LOCK_ACTIVE_MI { pthread_mutex_lock(&LOCK_active_mi); \
|
|
++active_mi_in_use; \
|
|
pthread_mutex_unlock(&LOCK_active_mi);}
|
|
|
|
#define UNLOCK_ACTIVE_MI { pthread_mutex_lock(&LOCK_active_mi); \
|
|
--active_mi_in_use; \
|
|
pthread_mutex_unlock(&LOCK_active_mi); }
|
|
|
|
/*****************************************************************************
|
|
|
|
Replication SQL Thread
|
|
|
|
st_relay_log_info contains:
|
|
- the current relay log
|
|
- the current relay log offset
|
|
- master log name
|
|
- master log sequence corresponding to the last update
|
|
- misc information specific to the SQL thread
|
|
|
|
st_relay_log_info is initialized from the slave.info file if such exists.
|
|
Otherwise, data members are intialized with defaults. The initialization is
|
|
done with init_relay_log_info() call.
|
|
|
|
The format of slave.info file:
|
|
|
|
relay_log_name
|
|
relay_log_pos
|
|
master_log_name
|
|
master_log_pos
|
|
|
|
To clean up, call end_relay_log_info()
|
|
|
|
*****************************************************************************/
|
|
|
|
typedef struct st_relay_log_info
|
|
{
|
|
/*** The following variables can only be read when protect by data lock ****/
|
|
|
|
/*
|
|
info_fd - file descriptor of the info file. set only during
|
|
initialization or clean up - safe to read anytime
|
|
cur_log_fd - file descriptor of the current read relay log
|
|
*/
|
|
File info_fd,cur_log_fd;
|
|
|
|
/*
|
|
Protected with internal locks.
|
|
Must get data_lock when resetting the logs.
|
|
*/
|
|
MYSQL_LOG relay_log;
|
|
LOG_INFO linfo;
|
|
IO_CACHE cache_buf,*cur_log;
|
|
|
|
/* The following variables are safe to read any time */
|
|
|
|
/* IO_CACHE of the info file - set only during init or end */
|
|
IO_CACHE info_file;
|
|
|
|
/*
|
|
When we restart slave thread we need to have access to the previously
|
|
created temporary tables. Modified only on init/end and by the SQL
|
|
thread, read only by SQL thread.
|
|
*/
|
|
TABLE *save_temporary_tables;
|
|
|
|
/*
|
|
standard lock acquistion order to avoid deadlocks:
|
|
run_lock, data_lock, relay_log.LOCK_log, relay_log.LOCK_index
|
|
*/
|
|
pthread_mutex_t data_lock,run_lock;
|
|
|
|
/*
|
|
start_cond is broadcast when SQL thread is started
|
|
stop_cond - when stopped
|
|
data_cond - when data protected by data_lock changes
|
|
*/
|
|
pthread_cond_t start_cond, stop_cond, data_cond;
|
|
|
|
/* parent master info structure */
|
|
struct st_master_info *mi;
|
|
|
|
/*
|
|
Needed to deal properly with cur_log getting closed and re-opened with
|
|
a different log under our feet
|
|
*/
|
|
uint32 cur_log_old_open_count;
|
|
|
|
/*
|
|
Let's call a group (of events) :
|
|
- a transaction
|
|
or
|
|
- an autocommiting query + its associated events (INSERT_ID,
|
|
TIMESTAMP...)
|
|
We need these rli coordinates :
|
|
- relay log name and position of the beginning of the group we currently are
|
|
executing. Needed to know where we have to restart when replication has
|
|
stopped in the middle of a group (which has been rolled back by the slave).
|
|
- relay log name and position just after the event we have just
|
|
executed. This event is part of the current group.
|
|
Formerly we only had the immediately above coordinates, plus a 'pending'
|
|
variable, but this dealt wrong with the case of a transaction starting on a
|
|
relay log and finishing (commiting) on another relay log. Case which can
|
|
happen when, for example, the relay log gets rotated because of
|
|
max_binlog_size.
|
|
*/
|
|
char group_relay_log_name[FN_REFLEN];
|
|
ulonglong group_relay_log_pos;
|
|
char event_relay_log_name[FN_REFLEN];
|
|
ulonglong event_relay_log_pos;
|
|
/*
|
|
Original log name and position of the group we're currently executing
|
|
(whose coordinates are group_relay_log_name/pos in the relay log)
|
|
in the master's binlog. These concern the *group*, because in the master's
|
|
binlog the log_pos that comes with each event is the position of the
|
|
beginning of the group.
|
|
*/
|
|
char group_master_log_name[FN_REFLEN];
|
|
volatile my_off_t group_master_log_pos;
|
|
|
|
/*
|
|
Handling of the relay_log_space_limit optional constraint.
|
|
ignore_log_space_limit is used to resolve a deadlock between I/O and SQL
|
|
threads, it makes the I/O thread temporarily forget about the constraint
|
|
*/
|
|
ulonglong log_space_limit,log_space_total;
|
|
bool ignore_log_space_limit;
|
|
|
|
/*
|
|
InnoDB internally stores the master log position it has processed
|
|
so far; the position to store is really the sum of
|
|
pos + pending + event_len here since we must store the pos of the
|
|
END of the current log event
|
|
*/
|
|
int event_len;
|
|
|
|
/*
|
|
Needed for problems when slave stops and we want to restart it
|
|
skipping one or more events in the master log that have caused
|
|
errors, and have been manually applied by DBA already.
|
|
*/
|
|
volatile uint32 slave_skip_counter;
|
|
volatile ulong abort_pos_wait; /* Incremented on change master */
|
|
volatile ulong slave_run_id; /* Incremented on slave start */
|
|
pthread_mutex_t log_space_lock;
|
|
pthread_cond_t log_space_cond;
|
|
THD * sql_thd;
|
|
int last_slave_errno;
|
|
#ifndef DBUG_OFF
|
|
int events_till_abort;
|
|
#endif
|
|
char last_slave_error[MAX_SLAVE_ERRMSG];
|
|
|
|
/* if not set, the value of other members of the structure are undefined */
|
|
bool inited;
|
|
volatile bool abort_slave, slave_running;
|
|
|
|
st_relay_log_info();
|
|
~st_relay_log_info();
|
|
|
|
inline void inc_event_relay_log_pos(ulonglong val)
|
|
{
|
|
event_relay_log_pos+= val;
|
|
}
|
|
|
|
void inc_group_relay_log_pos(ulonglong val, ulonglong log_pos, bool skip_lock=0)
|
|
{
|
|
if (!skip_lock)
|
|
pthread_mutex_lock(&data_lock);
|
|
inc_event_relay_log_pos(val);
|
|
group_relay_log_pos= event_relay_log_pos;
|
|
strmake(group_relay_log_name,event_relay_log_name,
|
|
sizeof(group_relay_log_name)-1);
|
|
/*
|
|
If the slave does not support transactions and replicates a transaction,
|
|
users should not trust group_master_log_pos (which they can display with
|
|
SHOW SLAVE STATUS or read from relay-log.info), because to compute
|
|
group_master_log_pos the slave relies on log_pos stored in the master's
|
|
binlog, but if we are in a master's transaction these positions are always
|
|
the BEGIN's one (excepted for the COMMIT), so group_master_log_pos does
|
|
not advance as it should on the non-transactional slave (it advances by
|
|
big leaps, whereas it should advance by small leaps).
|
|
*/
|
|
if (log_pos) // 3.23 binlogs don't have log_posx
|
|
group_master_log_pos= log_pos+ val;
|
|
pthread_cond_broadcast(&data_cond);
|
|
if (!skip_lock)
|
|
pthread_mutex_unlock(&data_lock);
|
|
}
|
|
|
|
int wait_for_pos(THD* thd, String* log_name, longlong log_pos,
|
|
longlong timeout);
|
|
} RELAY_LOG_INFO;
|
|
|
|
|
|
Log_event* next_event(RELAY_LOG_INFO* rli);
|
|
|
|
/*****************************************************************************
|
|
|
|
Replication IO Thread
|
|
|
|
st_master_info contains:
|
|
- information about how to connect to a master
|
|
- current master log name
|
|
- current master log offset
|
|
- misc control variables
|
|
|
|
st_master_info is initialized once from the master.info file if such
|
|
exists. Otherwise, data members corresponding to master.info fields
|
|
are initialized with defaults specified by master-* options. The
|
|
initialization is done through init_master_info() call.
|
|
|
|
The format of master.info file:
|
|
|
|
log_name
|
|
log_pos
|
|
master_host
|
|
master_user
|
|
master_pass
|
|
master_port
|
|
master_connect_retry
|
|
|
|
To write out the contents of master.info file to disk ( needed every
|
|
time we read and queue data from the master ), a call to
|
|
flush_master_info() is required.
|
|
|
|
To clean up, call end_master_info()
|
|
|
|
*****************************************************************************/
|
|
|
|
typedef struct st_master_info
|
|
{
|
|
char master_log_name[FN_REFLEN];
|
|
char host[HOSTNAME_LENGTH+1];
|
|
char user[USERNAME_LENGTH+1];
|
|
char password[MAX_PASSWORD_LENGTH+1];
|
|
|
|
my_off_t master_log_pos;
|
|
File fd; // we keep the file open, so we need to remember the file pointer
|
|
IO_CACHE file;
|
|
|
|
/* the variables below are needed because we can change masters on the fly */
|
|
pthread_mutex_t data_lock,run_lock;
|
|
pthread_cond_t data_cond,start_cond,stop_cond;
|
|
THD *io_thd;
|
|
MYSQL* mysql;
|
|
uint32 file_id; /* for 3.23 load data infile */
|
|
RELAY_LOG_INFO rli;
|
|
uint port;
|
|
uint connect_retry;
|
|
#ifndef DBUG_OFF
|
|
int events_till_abort;
|
|
#endif
|
|
bool inited;
|
|
enum enum_binlog_formats old_format;
|
|
volatile bool abort_slave, slave_running;
|
|
volatile ulong slave_run_id;
|
|
|
|
st_master_info()
|
|
:fd(-1), io_thd(0), inited(0), old_format(BINLOG_FORMAT_CURRENT),
|
|
abort_slave(0),slave_running(0), slave_run_id(0)
|
|
{
|
|
host[0] = 0; user[0] = 0; password[0] = 0;
|
|
bzero((char*) &file, sizeof(file));
|
|
pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
|
|
pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
|
|
pthread_cond_init(&data_cond, NULL);
|
|
pthread_cond_init(&start_cond, NULL);
|
|
pthread_cond_init(&stop_cond, NULL);
|
|
}
|
|
|
|
~st_master_info()
|
|
{
|
|
pthread_mutex_destroy(&run_lock);
|
|
pthread_mutex_destroy(&data_lock);
|
|
pthread_cond_destroy(&data_cond);
|
|
pthread_cond_destroy(&start_cond);
|
|
pthread_cond_destroy(&stop_cond);
|
|
}
|
|
|
|
} MASTER_INFO;
|
|
|
|
|
|
int queue_event(MASTER_INFO* mi,const char* buf,ulong event_len);
|
|
|
|
typedef struct st_table_rule_ent
|
|
{
|
|
char* db;
|
|
char* tbl_name;
|
|
uint key_len;
|
|
} TABLE_RULE_ENT;
|
|
|
|
#define TABLE_RULE_HASH_SIZE 16
|
|
#define TABLE_RULE_ARR_SIZE 16
|
|
#define MAX_SLAVE_ERRMSG 1024
|
|
|
|
#define RPL_LOG_NAME (rli->group_master_log_name[0] ? rli->group_master_log_name :\
|
|
"FIRST")
|
|
#define IO_RPL_LOG_NAME (mi->master_log_name[0] ? mi->master_log_name :\
|
|
"FIRST")
|
|
|
|
/* masks for start/stop operations on io and sql slave threads */
|
|
#define SLAVE_IO 1
|
|
#define SLAVE_SQL 2
|
|
|
|
/*
|
|
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
|
|
|
|
int init_slave();
|
|
void init_slave_skip_errors(const char* arg);
|
|
bool flush_master_info(MASTER_INFO* mi);
|
|
bool flush_relay_log_info(RELAY_LOG_INFO* rli);
|
|
int register_slave_on_master(MYSQL* mysql);
|
|
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,
|
|
volatile bool* slave_running);
|
|
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);
|
|
/*
|
|
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
|
|
*/
|
|
int start_slave_thread(pthread_handler h_func, pthread_mutex_t* start_lock,
|
|
pthread_mutex_t *cond_lock,
|
|
pthread_cond_t* start_cond,
|
|
volatile bool *slave_running,
|
|
volatile ulong *slave_run_id,
|
|
MASTER_INFO* mi,
|
|
bool high_priority);
|
|
|
|
/* If fd is -1, dump to NET */
|
|
int mysql_table_dump(THD* thd, const char* db,
|
|
const char* tbl_name, int fd = -1);
|
|
|
|
/* retrieve non-exitent table from master */
|
|
int fetch_master_table(THD* thd, const char* db_name, const char* table_name,
|
|
MASTER_INFO* mi, MYSQL* mysql);
|
|
|
|
void table_rule_ent_hash_to_str(String* s, HASH* h);
|
|
void table_rule_ent_dynamic_array_to_str(String* s, DYNAMIC_ARRAY* a);
|
|
int show_master_info(THD* thd, MASTER_INFO* mi);
|
|
int show_binlog_info(THD* thd);
|
|
|
|
/* See if the query uses any tables that should not be replicated */
|
|
int tables_ok(THD* thd, TABLE_LIST* tables);
|
|
|
|
/*
|
|
Check to see if the database is ok to operate on with respect to the
|
|
do and ignore lists - used in replication
|
|
*/
|
|
int db_ok(const char* db, I_List<i_string> &do_list,
|
|
I_List<i_string> &ignore_list );
|
|
int db_ok_with_wild_table(const char *db);
|
|
|
|
int add_table_rule(HASH* h, const char* table_spec);
|
|
int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
|
|
void init_table_rule_hash(HASH* h, bool* h_inited);
|
|
void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
|
|
const char *rewrite_db(const char* db);
|
|
const char *print_slave_db_safe(const char* db);
|
|
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code);
|
|
void skip_load_data_infile(NET* net);
|
|
void slave_print_error(RELAY_LOG_INFO* rli, int err_code, const char* msg, ...);
|
|
|
|
void end_slave(); /* clean up */
|
|
void init_master_info_with_options(MASTER_INFO* mi);
|
|
void clear_last_slave_error(RELAY_LOG_INFO* rli);
|
|
int init_master_info(MASTER_INFO* mi, const char* master_info_fname,
|
|
const char* slave_info_fname,
|
|
bool abort_if_no_master_info_file);
|
|
void end_master_info(MASTER_INFO* mi);
|
|
int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname);
|
|
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,
|
|
bool need_data_lock, const char** errmsg);
|
|
|
|
int purge_relay_logs(RELAY_LOG_INFO* rli, THD *thd, bool just_reset,
|
|
const char** errmsg);
|
|
void rotate_relay_log(MASTER_INFO* mi);
|
|
|
|
extern "C" pthread_handler_decl(handle_slave_io,arg);
|
|
extern "C" pthread_handler_decl(handle_slave_sql,arg);
|
|
extern bool volatile abort_loop;
|
|
extern MASTER_INFO main_mi, *active_mi; /* active_mi for multi-master */
|
|
extern volatile int active_mi_in_use;
|
|
extern LIST master_list;
|
|
extern HASH replicate_do_table, replicate_ignore_table;
|
|
extern DYNAMIC_ARRAY replicate_wild_do_table, replicate_wild_ignore_table;
|
|
extern bool do_table_inited, ignore_table_inited,
|
|
wild_do_table_inited, wild_ignore_table_inited;
|
|
extern bool table_rules_on;
|
|
|
|
extern int disconnect_slave_event_count, abort_slave_event_count ;
|
|
|
|
/* the master variables are defaults read from my.cnf or command line */
|
|
extern uint master_port, master_connect_retry, report_port;
|
|
extern my_string master_user, master_password, master_host,
|
|
master_info_file, relay_log_info_file, report_user, report_host,
|
|
report_password;
|
|
|
|
extern I_List<i_string> replicate_do_db, replicate_ignore_db;
|
|
extern I_List<i_string_pair> replicate_rewrite_db;
|
|
extern I_List<THD> threads;
|
|
|
|
#endif
|
|
#else
|
|
#define SLAVE_IO 1
|
|
#define SLAVE_SQL 2
|
|
#endif /* HAVE_REPLICATION */
|