2012-03-28 01:04:46 +02:00
|
|
|
/* Copyright (c) 2006, 2012, Oracle and/or its affiliates.
|
2006-10-31 16:51:51 +01: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-27 02:23:51 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-10-31 16:51:51 +01: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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2011-06-30 17:46:53 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
#ifndef RPL_MI_H
|
|
|
|
#define RPL_MI_H
|
|
|
|
|
|
|
|
#ifdef HAVE_REPLICATION
|
|
|
|
|
2007-04-12 08:58:04 +02:00
|
|
|
#include "rpl_rli.h"
|
2007-06-11 22:15:39 +02:00
|
|
|
#include "rpl_reporting.h"
|
2009-10-01 18:44:53 +02:00
|
|
|
#include "my_sys.h"
|
2007-04-12 08:58:04 +02:00
|
|
|
|
2010-03-31 16:05:33 +02:00
|
|
|
typedef struct st_mysql MYSQL;
|
2007-04-12 08:58:04 +02:00
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
Replication IO Thread
|
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
Master_info contains:
|
2006-10-31 16:51:51 +01:00
|
|
|
- information about how to connect to a master
|
|
|
|
- current master log name
|
|
|
|
- current master log offset
|
|
|
|
- misc control variables
|
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
Master_info is initialized once from the master.info file if such
|
2006-10-31 16:51:51 +01:00
|
|
|
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()
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
class Master_info : public Slave_reporting_capability
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-09-28 01:06:56 +02:00
|
|
|
Master_info(LEX_STRING *connection_name, bool is_slave_recovery);
|
2007-08-16 08:52:50 +02:00
|
|
|
~Master_info();
|
2009-10-01 18:44:53 +02:00
|
|
|
bool shall_ignore_server_id(ulong s_id);
|
BUG#11809016 - NO WAY TO DISCOVER AN INSTANCE IS NO LONGER A SLAVE FOLLOWING MYSQL BUG#28796
Before BUG#28796, an empty host was used to identify that an instance was no
longer a slave. However, BUG#28796 changed this behavior and one cannot set
an empty host. Besides, a RESET SLAVE only cleans up information on the next
event to retrieve from the master, disables ssl and resets heartbeat period.
So a call to SHOW SLAVE STATUS after issuing a RESET SLAVE still returns some
valid information, such as host, port, user and password.
To fix this problem, we have introduced the command RESET SLAVE ALL that does
what a regular RESET SLAVE does and also clears host, port, user and password
information thus allowing users to identify when an instance is no longer a
slave.
2011-07-18 19:18:03 +02:00
|
|
|
void clear_in_memory_info(bool all);
|
2012-09-28 01:06:56 +02:00
|
|
|
bool error()
|
|
|
|
{
|
|
|
|
/* If malloc() in initialization failed */
|
|
|
|
return connection_name.str == 0;
|
|
|
|
}
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
/* the variables below are needed because we can change masters on the fly */
|
2012-09-28 01:06:56 +02:00
|
|
|
char master_log_name[FN_REFLEN+6]; /* Place for multi-*/
|
2006-10-31 16:51:51 +01:00
|
|
|
char host[HOSTNAME_LENGTH+1];
|
|
|
|
char user[USERNAME_LENGTH+1];
|
|
|
|
char password[MAX_PASSWORD_LENGTH+1];
|
2012-09-28 01:06:56 +02:00
|
|
|
LEX_STRING connection_name; /* User supplied connection name */
|
|
|
|
LEX_STRING cmp_connection_name; /* Connection name in lower case */
|
2010-09-24 00:00:32 +02:00
|
|
|
bool ssl; // enables use of SSL connection if true
|
2006-10-31 16:51:51 +01:00
|
|
|
char ssl_ca[FN_REFLEN], ssl_capath[FN_REFLEN], ssl_cert[FN_REFLEN];
|
|
|
|
char ssl_cipher[FN_REFLEN], ssl_key[FN_REFLEN];
|
2010-09-24 00:00:32 +02:00
|
|
|
bool ssl_verify_server_cert;
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
my_off_t master_log_pos;
|
|
|
|
File fd; // we keep the file open, so we need to remember the file pointer
|
|
|
|
IO_CACHE file;
|
|
|
|
|
2012-01-23 13:09:37 +01:00
|
|
|
mysql_mutex_t data_lock, run_lock, sleep_lock;
|
|
|
|
mysql_cond_t data_cond, start_cond, stop_cond, sleep_cond;
|
2006-10-31 16:51:51 +01:00
|
|
|
THD *io_thd;
|
|
|
|
MYSQL* mysql;
|
|
|
|
uint32 file_id; /* for 3.23 load data infile */
|
2007-08-16 07:37:50 +02:00
|
|
|
Relay_log_info rli;
|
2006-10-31 16:51:51 +01:00
|
|
|
uint port;
|
2011-05-03 14:01:11 +02:00
|
|
|
/*
|
|
|
|
to hold checksum alg in use until IO thread has received FD.
|
|
|
|
Initialized to novalue, then set to the queried from master
|
|
|
|
@@global.binlog_checksum and deactivated once FD has been received.
|
|
|
|
*/
|
|
|
|
uint8 checksum_alg_before_fd;
|
2006-10-31 16:51:51 +01:00
|
|
|
uint connect_retry;
|
|
|
|
#ifndef DBUG_OFF
|
|
|
|
int events_till_disconnect;
|
|
|
|
#endif
|
|
|
|
bool inited;
|
|
|
|
volatile bool abort_slave;
|
|
|
|
volatile uint slave_running;
|
|
|
|
volatile ulong slave_run_id;
|
|
|
|
/*
|
|
|
|
The difference in seconds between the clock of the master and the clock of
|
|
|
|
the slave (second - first). It must be signed as it may be <0 or >0.
|
|
|
|
clock_diff_with_master is computed when the I/O thread starts; for this the
|
|
|
|
I/O thread does a SELECT UNIX_TIMESTAMP() on the master.
|
|
|
|
"how late the slave is compared to the master" is computed like this:
|
|
|
|
clock_of_slave - last_timestamp_executed_by_SQL_thread - clock_diff_with_master
|
|
|
|
|
|
|
|
*/
|
|
|
|
long clock_diff_with_master;
|
BUG#40337 Fsyncing master and relay log to disk after every event is too slow
NOTE: Backporting the patch to next-mr.
The fix proposed in BUG#35542 and BUG#31665 introduces a performance issue
when fsyncing the master.info, relay.info and relay-log.bin* after #th events.
Although such solution has been proposed to reduce the probability of corrupted
files due to a slave-crash, the performance penalty introduced by it has
made the approach impractical for highly intensive workloads.
In a nutshell, the option --syn-relay-log proposed in BUG#35542 and BUG#31665
simultaneously fsyncs master.info, relay-log.info and relay-log.bin* and
this is the main source of performance issues.
This patch introduces new options that give more control to the user on
what should be fsynced and how often:
1) (--sync-master-info, integer) which syncs the master.info after #th event;
2) (--sync-relay-log, integer) which syncs the relay-log.bin* after #th
events.
3) (--sync-relay-log-info, integer) which syncs the relay.info after #th
transactions.
To provide both performance and increased reliability, we recommend the following
setup:
1) --sync-master-info = 0 eventually the operating system will fsync it;
2) --sync-relay-log = 0 eventually the operating system will fsync it;
3) --sync-relay-log-info = 1 fsyncs it after every transaction;
Notice, that the previous setup does not reduce the probability of
corrupted master.info and relay-log.bin*. To overcome the issue, this patch also
introduces a recovery mechanism that right after restart throws away relay-log.bin*
retrieved from a master and updates the master.info based on the relay.info:
4) (--relay-log-recovery, boolean) which enables a recovery mechanism that
throws away relay-log.bin* after a crash.
However, it can only recover the incorrect binlog file and position in master.info,
if other informations (host, port password, etc) are corrupted or incorrect,
then this recovery mechanism will fail to work.
2009-09-29 16:40:52 +02:00
|
|
|
/*
|
|
|
|
Keeps track of the number of events before fsyncing.
|
|
|
|
The option --sync-master-info determines how many
|
|
|
|
events should happen before fsyncing.
|
|
|
|
*/
|
|
|
|
uint sync_counter;
|
2009-10-01 18:44:53 +02:00
|
|
|
float heartbeat_period; // interface with CHANGE MASTER or master.info
|
|
|
|
ulonglong received_heartbeats; // counter of received heartbeat events
|
|
|
|
DYNAMIC_ARRAY ignore_server_ids;
|
|
|
|
ulong master_id;
|
2006-10-31 16:51:51 +01:00
|
|
|
};
|
2007-08-16 08:52:50 +02:00
|
|
|
int init_master_info(Master_info* mi, const char* master_info_fname,
|
2006-10-31 16:51:51 +01:00
|
|
|
const char* slave_info_fname,
|
|
|
|
bool abort_if_no_master_info_file,
|
|
|
|
int thread_mask);
|
2007-08-16 08:52:50 +02:00
|
|
|
void end_master_info(Master_info* mi);
|
2010-02-03 17:56:17 +01:00
|
|
|
int flush_master_info(Master_info* mi,
|
|
|
|
bool flush_relay_log_cache,
|
|
|
|
bool need_lock_relay_log);
|
2009-10-01 18:44:53 +02:00
|
|
|
int change_master_server_id_cmp(ulong *id1, ulong *id2);
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
/*
|
|
|
|
Multi master are handled trough this struct.
|
|
|
|
Changes to this needs to be protected by LOCK_active_mi;
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Master_info_index
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
IO_CACHE index_file;
|
|
|
|
char index_file_name[FN_REFLEN];
|
|
|
|
|
|
|
|
public:
|
|
|
|
Master_info_index();
|
|
|
|
~Master_info_index();
|
|
|
|
|
|
|
|
HASH master_info_hash;
|
|
|
|
|
|
|
|
bool init_all_master_info();
|
|
|
|
bool write_master_name_to_index_file(LEX_STRING *connection_name,
|
|
|
|
bool do_sync);
|
|
|
|
|
|
|
|
bool check_duplicate_master_info(LEX_STRING *connection_name,
|
|
|
|
const char *host, uint port);
|
|
|
|
bool add_master_info(Master_info *mi, bool write_to_file);
|
|
|
|
bool remove_master_info(LEX_STRING *connection_name);
|
|
|
|
Master_info *get_master_info(LEX_STRING *connection_name,
|
|
|
|
MYSQL_ERROR::enum_warning_level warning);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool check_master_connection_name(LEX_STRING *name);
|
|
|
|
void create_signed_file_name(char *res_file_name, uint length,
|
|
|
|
const char *info_file,
|
|
|
|
char separator,
|
|
|
|
LEX_STRING *suffix);
|
|
|
|
|
|
|
|
uchar *get_key_master_info(Master_info *mi, size_t *length,
|
|
|
|
my_bool not_used __attribute__((unused)));
|
|
|
|
void free_key_master_info(Master_info *mi);
|
|
|
|
|
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
#endif /* HAVE_REPLICATION */
|
|
|
|
#endif /* RPL_MI_H */
|