2017-07-18 14:59:10 +02:00
|
|
|
/* Copyright (c) 2006, 2017, Oracle and/or its affiliates.
|
2022-07-28 09:33:26 +02:00
|
|
|
Copyright (c) 2010, 2022, MariaDB Corporation.
|
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
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2017-06-18 05:42:16 +02:00
|
|
|
#include "mariadb.h" // For HAVE_REPLICATION
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
2006-10-31 16:51:51 +01:00
|
|
|
#include <my_dir.h>
|
|
|
|
#include "rpl_mi.h"
|
2016-09-22 08:26:45 +02:00
|
|
|
#include "slave.h"
|
2012-09-28 01:06:56 +02:00
|
|
|
#include "strfunc.h"
|
2012-10-03 00:44:54 +02:00
|
|
|
#include "sql_repl.h"
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_REPLICATION
|
|
|
|
|
2009-11-04 13:28:20 +01:00
|
|
|
#define DEFAULT_CONNECT_RETRY 60
|
2006-10-31 16:51:51 +01:00
|
|
|
|
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
|
|
|
static void init_master_log_pos(Master_info* mi);
|
|
|
|
|
2017-04-23 18:39:57 +02:00
|
|
|
Master_info::Master_info(LEX_CSTRING *connection_name_arg,
|
2012-09-28 01:06:56 +02:00
|
|
|
bool is_slave_recovery)
|
2007-06-09 07:19:37 +02:00
|
|
|
:Slave_reporting_capability("I/O"),
|
2023-09-04 15:32:36 +02:00
|
|
|
ssl(1), ssl_verify_server_cert(1), fd(-1), io_thd(0),
|
2010-01-25 22:34:34 +01:00
|
|
|
rli(is_slave_recovery), port(MYSQL_PORT),
|
2011-10-19 21:45:18 +02:00
|
|
|
checksum_alg_before_fd(BINLOG_CHECKSUM_ALG_UNDEF),
|
2010-01-25 22:34:34 +01:00
|
|
|
connect_retry(DEFAULT_CONNECT_RETRY), inited(0), abort_slave(0),
|
2016-01-03 12:20:07 +01:00
|
|
|
slave_running(MYSQL_SLAVE_NOT_RUN), slave_run_id(0),
|
|
|
|
clock_diff_with_master(0),
|
2015-04-30 19:48:11 +02:00
|
|
|
sync_counter(0), heartbeat_period(0), received_heartbeats(0),
|
|
|
|
master_id(0), prev_master_id(0),
|
MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it
This commit makes replicas crash-safe by default by changing the
Using_Gtid value to be Slave_Pos on a fresh slave start and after
RESET SLAVE is issued. If the primary server does not support GTIDs
(i.e., version < 10), the replica will fall back to Using_Gtid=No on
slave start and after RESET SLAVE.
The following additional informational messages/warnings are added:
1. When Using_Gtid is automatically changed. That is, if RESET
SLAVE reverts Using_Gtid back to Slave_Pos, or Using_Gtid is
inferred to No from a CHANGE MASTER TO given with log coordinates
without MASTER_USE_GTID.
2. If options are ignored in CHANGE MASTER TO. If CHANGE MASTER TO
is given with log coordinates, yet also specifies
MASTER_USE_GTID=Slave_Pos, a warning message is given that the log
coordinate options are ignored.
Additionally, an MTR macro has been added for RESET SLAVE,
reset_slave.inc, which provides modes/options for resetting a slave
in log coordinate or gtid modes. When in log coordinates mode, the
macro will execute CHANGE MASTER TO MASTER_USE_GTID=No after the
RESET SLAVE command. When in GTID mode, an extra parameter,
reset_slave_keep_gtid_state, can be set to reset or preserve the
value of gtid_slave_pos.
Reviewed By:
===========
Andrei Elkin <andrei.elkin@mariadb.com>
2022-05-23 22:14:00 +02:00
|
|
|
using_gtid(USE_GTID_SLAVE_POS), events_queued_since_last_gtid(0),
|
2017-01-29 21:10:56 +01:00
|
|
|
gtid_reconnect_event_skip_count(0), gtid_event_seen(false),
|
2017-06-05 09:40:24 +02:00
|
|
|
in_start_all_slaves(0), in_stop_all_slaves(0), in_flush_all_relay_logs(0),
|
2018-04-19 11:01:20 +02:00
|
|
|
users(0), killed(0),
|
2022-07-28 09:33:26 +02:00
|
|
|
total_ddl_groups(0), total_non_trans_groups(0), total_trans_groups(0)
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
char *tmp;
|
2006-10-31 16:51:51 +01:00
|
|
|
host[0] = 0; user[0] = 0; password[0] = 0;
|
|
|
|
ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
|
|
|
|
ssl_cipher[0]= 0; ssl_key[0]= 0;
|
2012-08-14 16:23:34 +02:00
|
|
|
ssl_crl[0]= 0; ssl_crlpath[0]= 0;
|
2007-03-29 15:09:57 +02:00
|
|
|
|
2012-10-03 00:44:54 +02:00
|
|
|
/*
|
|
|
|
Store connection name and lower case connection name
|
|
|
|
It's safe to ignore any OMM errors as this is checked by error()
|
|
|
|
*/
|
2012-09-28 01:06:56 +02:00
|
|
|
connection_name.length= cmp_connection_name.length=
|
|
|
|
connection_name_arg->length;
|
2017-04-23 18:39:57 +02:00
|
|
|
if ((connection_name.str= tmp= (char*)
|
2020-01-29 13:50:26 +01:00
|
|
|
my_malloc(PSI_INSTRUMENT_ME, connection_name_arg->length*2+2, MYF(MY_WME))))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
strmake(tmp, connection_name_arg->str, connection_name.length);
|
|
|
|
tmp+= connection_name_arg->length+1;
|
|
|
|
cmp_connection_name.str= tmp;
|
|
|
|
memcpy(tmp, connection_name_arg->str, connection_name.length+1);
|
|
|
|
my_casedn_str(system_charset_info, tmp);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
2015-02-01 21:39:59 +01:00
|
|
|
/*
|
|
|
|
When MySQL restarted, all Rpl_filter settings which aren't in the my.cnf
|
|
|
|
will be lost. If you want to lose a setting after restart, you
|
|
|
|
should add them into my.cnf
|
|
|
|
*/
|
2013-04-16 13:43:28 +02:00
|
|
|
rpl_filter= get_or_create_rpl_filter(connection_name.str,
|
|
|
|
connection_name.length);
|
|
|
|
copy_filter_setting(rpl_filter, global_rpl_filter);
|
2012-09-28 01:06:56 +02:00
|
|
|
|
2015-02-01 21:39:59 +01:00
|
|
|
parallel_mode= rpl_filter->get_parallel_mode();
|
2014-12-05 16:09:48 +01:00
|
|
|
|
2020-02-27 11:52:20 +01:00
|
|
|
my_init_dynamic_array(PSI_INSTRUMENT_ME, &ignore_server_ids,
|
2012-10-23 12:46:29 +02:00
|
|
|
sizeof(global_system_variables.server_id), 16, 16,
|
|
|
|
MYF(0));
|
2006-10-31 16:51:51 +01:00
|
|
|
bzero((char*) &file, sizeof(file));
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_init(key_master_info_run_lock, &run_lock, MY_MUTEX_INIT_FAST);
|
|
|
|
mysql_mutex_init(key_master_info_data_lock, &data_lock, MY_MUTEX_INIT_FAST);
|
2017-01-29 22:44:24 +01:00
|
|
|
mysql_mutex_init(key_master_info_start_stop_lock, &start_stop_lock,
|
|
|
|
MY_MUTEX_INIT_SLOW);
|
MDEV-11675 Lag Free Alter On Slave
This commit implements two phase binloggable ALTER.
When a new
@@session.binlog_alter_two_phase = YES
ALTER query gets logged in two parts, the START ALTER and the COMMIT
or ROLLBACK ALTER. START Alter is written in binlog as soon as
necessary locks have been acquired for the table. The timing is
such that any concurrent DML:s that update the same table are either
committed, thus logged into binary log having done work on the old
version of the table, or will be queued for execution on its new
version.
The "COMPLETE" COMMIT or ROLLBACK ALTER are written at the very point
of a normal "single-piece" ALTER that is after the most of
the query work is done. When its result is positive COMMIT ALTER is
written, otherwise ROLLBACK ALTER is written with specific error
happened after START ALTER phase.
Replication of two-phase binloggable ALTER is
cross-version safe. Specifically the OLD slave merely does not
recognized the start alter part, still being able to process and
memorize its gtid.
Two phase logged ALTER is read from binlog by mysqlbinlog to produce
BINLOG 'string', where 'string' contains base64 encoded
Query_log_event containing either the start part of ALTER, or a
completion part. The Query details can be displayed with `-v` flag,
similarly to ROW format events. Notice, mysqlbinlog output containing
parts of two-phase binloggable ALTER is processable correctly only by
binlog_alter_two_phase server.
@@log_warnings > 2 can reveal details of binlogging and slave side
processing of the ALTER parts.
The current commit also carries fixes to the following list of
reported bugs:
MDEV-27511, MDEV-27471, MDEV-27349, MDEV-27628, MDEV-27528.
Thanks to all people involved into early discussion of the feature
including Kristian Nielsen, those who helped to design, implement and
test: Sergei Golubchik, Andrei Elkin who took the burden of the
implemenation completion, Sujatha Sivakumar, Brandon
Nesterenko, Alice Sherepa, Ramesh Sivaraman, Jan Lindstrom.
2021-01-29 12:59:14 +01:00
|
|
|
/*
|
|
|
|
start_alter_lock will protect individual start_alter_info while
|
|
|
|
start_alter_list_lock is for list insertion and deletion operations
|
|
|
|
*/
|
|
|
|
mysql_mutex_init(key_master_info_start_alter_lock, &start_alter_lock,
|
|
|
|
MY_MUTEX_INIT_FAST);
|
|
|
|
mysql_mutex_init(key_master_info_start_alter_list_lock, &start_alter_list_lock,
|
|
|
|
MY_MUTEX_INIT_FAST);
|
2011-10-19 21:53:14 +02:00
|
|
|
mysql_mutex_setflags(&run_lock, MYF_NO_DEADLOCK_DETECTION);
|
|
|
|
mysql_mutex_setflags(&data_lock, MYF_NO_DEADLOCK_DETECTION);
|
2012-01-23 13:09:37 +01:00
|
|
|
mysql_mutex_init(key_master_info_sleep_lock, &sleep_lock, MY_MUTEX_INIT_FAST);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_cond_init(key_master_info_data_cond, &data_cond, NULL);
|
|
|
|
mysql_cond_init(key_master_info_start_cond, &start_cond, NULL);
|
|
|
|
mysql_cond_init(key_master_info_stop_cond, &stop_cond, NULL);
|
2012-01-23 13:09:37 +01:00
|
|
|
mysql_cond_init(key_master_info_sleep_cond, &sleep_cond, NULL);
|
MDEV-11675 Lag Free Alter On Slave
This commit implements two phase binloggable ALTER.
When a new
@@session.binlog_alter_two_phase = YES
ALTER query gets logged in two parts, the START ALTER and the COMMIT
or ROLLBACK ALTER. START Alter is written in binlog as soon as
necessary locks have been acquired for the table. The timing is
such that any concurrent DML:s that update the same table are either
committed, thus logged into binary log having done work on the old
version of the table, or will be queued for execution on its new
version.
The "COMPLETE" COMMIT or ROLLBACK ALTER are written at the very point
of a normal "single-piece" ALTER that is after the most of
the query work is done. When its result is positive COMMIT ALTER is
written, otherwise ROLLBACK ALTER is written with specific error
happened after START ALTER phase.
Replication of two-phase binloggable ALTER is
cross-version safe. Specifically the OLD slave merely does not
recognized the start alter part, still being able to process and
memorize its gtid.
Two phase logged ALTER is read from binlog by mysqlbinlog to produce
BINLOG 'string', where 'string' contains base64 encoded
Query_log_event containing either the start part of ALTER, or a
completion part. The Query details can be displayed with `-v` flag,
similarly to ROW format events. Notice, mysqlbinlog output containing
parts of two-phase binloggable ALTER is processable correctly only by
binlog_alter_two_phase server.
@@log_warnings > 2 can reveal details of binlogging and slave side
processing of the ALTER parts.
The current commit also carries fixes to the following list of
reported bugs:
MDEV-27511, MDEV-27471, MDEV-27349, MDEV-27628, MDEV-27528.
Thanks to all people involved into early discussion of the feature
including Kristian Nielsen, those who helped to design, implement and
test: Sergei Golubchik, Andrei Elkin who took the burden of the
implemenation completion, Sujatha Sivakumar, Brandon
Nesterenko, Alice Sherepa, Ramesh Sivaraman, Jan Lindstrom.
2021-01-29 12:59:14 +01:00
|
|
|
init_sql_alloc(PSI_INSTRUMENT_ME, &mem_root, MEM_ROOT_BLOCK_SIZE, 0, MYF(0));
|
2006-10-31 16:51:51 +01:00
|
|
|
}
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Wait until no one is using Master_info
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Master_info::wait_until_free()
|
|
|
|
{
|
|
|
|
mysql_mutex_lock(&sleep_lock);
|
|
|
|
killed= 1;
|
|
|
|
while (users)
|
|
|
|
mysql_cond_wait(&sleep_cond, &sleep_lock);
|
|
|
|
mysql_mutex_unlock(&sleep_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Delete master_info
|
|
|
|
*/
|
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
Master_info::~Master_info()
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
wait_until_free();
|
2017-04-23 18:39:57 +02:00
|
|
|
my_free(const_cast<char*>(connection_name.str));
|
2009-10-01 18:44:53 +02:00
|
|
|
delete_dynamic(&ignore_server_ids);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_destroy(&run_lock);
|
|
|
|
mysql_mutex_destroy(&data_lock);
|
2012-01-23 13:09:37 +01:00
|
|
|
mysql_mutex_destroy(&sleep_lock);
|
2017-01-29 22:44:24 +01:00
|
|
|
mysql_mutex_destroy(&start_stop_lock);
|
MDEV-11675 Lag Free Alter On Slave
This commit implements two phase binloggable ALTER.
When a new
@@session.binlog_alter_two_phase = YES
ALTER query gets logged in two parts, the START ALTER and the COMMIT
or ROLLBACK ALTER. START Alter is written in binlog as soon as
necessary locks have been acquired for the table. The timing is
such that any concurrent DML:s that update the same table are either
committed, thus logged into binary log having done work on the old
version of the table, or will be queued for execution on its new
version.
The "COMPLETE" COMMIT or ROLLBACK ALTER are written at the very point
of a normal "single-piece" ALTER that is after the most of
the query work is done. When its result is positive COMMIT ALTER is
written, otherwise ROLLBACK ALTER is written with specific error
happened after START ALTER phase.
Replication of two-phase binloggable ALTER is
cross-version safe. Specifically the OLD slave merely does not
recognized the start alter part, still being able to process and
memorize its gtid.
Two phase logged ALTER is read from binlog by mysqlbinlog to produce
BINLOG 'string', where 'string' contains base64 encoded
Query_log_event containing either the start part of ALTER, or a
completion part. The Query details can be displayed with `-v` flag,
similarly to ROW format events. Notice, mysqlbinlog output containing
parts of two-phase binloggable ALTER is processable correctly only by
binlog_alter_two_phase server.
@@log_warnings > 2 can reveal details of binlogging and slave side
processing of the ALTER parts.
The current commit also carries fixes to the following list of
reported bugs:
MDEV-27511, MDEV-27471, MDEV-27349, MDEV-27628, MDEV-27528.
Thanks to all people involved into early discussion of the feature
including Kristian Nielsen, those who helped to design, implement and
test: Sergei Golubchik, Andrei Elkin who took the burden of the
implemenation completion, Sujatha Sivakumar, Brandon
Nesterenko, Alice Sherepa, Ramesh Sivaraman, Jan Lindstrom.
2021-01-29 12:59:14 +01:00
|
|
|
mysql_mutex_destroy(&start_alter_lock);
|
|
|
|
mysql_mutex_destroy(&start_alter_list_lock);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_cond_destroy(&data_cond);
|
|
|
|
mysql_cond_destroy(&start_cond);
|
|
|
|
mysql_cond_destroy(&stop_cond);
|
2012-01-23 13:09:37 +01:00
|
|
|
mysql_cond_destroy(&sleep_cond);
|
MDEV-11675 Lag Free Alter On Slave
This commit implements two phase binloggable ALTER.
When a new
@@session.binlog_alter_two_phase = YES
ALTER query gets logged in two parts, the START ALTER and the COMMIT
or ROLLBACK ALTER. START Alter is written in binlog as soon as
necessary locks have been acquired for the table. The timing is
such that any concurrent DML:s that update the same table are either
committed, thus logged into binary log having done work on the old
version of the table, or will be queued for execution on its new
version.
The "COMPLETE" COMMIT or ROLLBACK ALTER are written at the very point
of a normal "single-piece" ALTER that is after the most of
the query work is done. When its result is positive COMMIT ALTER is
written, otherwise ROLLBACK ALTER is written with specific error
happened after START ALTER phase.
Replication of two-phase binloggable ALTER is
cross-version safe. Specifically the OLD slave merely does not
recognized the start alter part, still being able to process and
memorize its gtid.
Two phase logged ALTER is read from binlog by mysqlbinlog to produce
BINLOG 'string', where 'string' contains base64 encoded
Query_log_event containing either the start part of ALTER, or a
completion part. The Query details can be displayed with `-v` flag,
similarly to ROW format events. Notice, mysqlbinlog output containing
parts of two-phase binloggable ALTER is processable correctly only by
binlog_alter_two_phase server.
@@log_warnings > 2 can reveal details of binlogging and slave side
processing of the ALTER parts.
The current commit also carries fixes to the following list of
reported bugs:
MDEV-27511, MDEV-27471, MDEV-27349, MDEV-27628, MDEV-27528.
Thanks to all people involved into early discussion of the feature
including Kristian Nielsen, those who helped to design, implement and
test: Sergei Golubchik, Andrei Elkin who took the burden of the
implemenation completion, Sujatha Sivakumar, Brandon
Nesterenko, Alice Sherepa, Ramesh Sivaraman, Jan Lindstrom.
2021-01-29 12:59:14 +01:00
|
|
|
free_root(&mem_root, MYF(0));
|
2006-10-31 16:51:51 +01:00
|
|
|
}
|
|
|
|
|
2009-10-01 18:44:53 +02:00
|
|
|
/**
|
|
|
|
A comparison function to be supplied as argument to @c sort_dynamic()
|
|
|
|
and @c bsearch()
|
|
|
|
|
|
|
|
@return -1 if first argument is less, 0 if it equal to, 1 if it is greater
|
|
|
|
than the second
|
|
|
|
*/
|
2014-12-04 04:30:48 +01:00
|
|
|
static int change_master_id_cmp(const void *id1, const void *id2)
|
2009-10-01 18:44:53 +02:00
|
|
|
{
|
2014-12-04 04:30:48 +01:00
|
|
|
return (*(ulong *) id1 - *(ulong *) id2);
|
2009-10-01 18:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reports if the s_id server has been configured to ignore events
|
|
|
|
it generates with
|
|
|
|
|
|
|
|
CHANGE MASTER IGNORE_SERVER_IDS= ( list of server ids )
|
|
|
|
|
|
|
|
Method is called from the io thread event receiver filtering.
|
|
|
|
|
|
|
|
@param s_id the master server identifier
|
|
|
|
|
|
|
|
@retval TRUE if s_id is in the list of ignored master servers,
|
|
|
|
@retval FALSE otherwise.
|
|
|
|
*/
|
|
|
|
bool Master_info::shall_ignore_server_id(ulong s_id)
|
|
|
|
{
|
|
|
|
if (likely(ignore_server_ids.elements == 1))
|
|
|
|
return (* (ulong*) dynamic_array_ptr(&ignore_server_ids, 0)) == s_id;
|
2014-12-04 04:30:48 +01:00
|
|
|
else
|
2009-10-01 18:44:53 +02:00
|
|
|
return bsearch((const ulong *) &s_id,
|
|
|
|
ignore_server_ids.buffer,
|
|
|
|
ignore_server_ids.elements, sizeof(ulong),
|
2014-12-04 04:30:48 +01:00
|
|
|
change_master_id_cmp) != NULL;
|
2009-10-01 18:44:53 +02:00
|
|
|
}
|
2006-10-31 16:51:51 +01:00
|
|
|
|
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 Master_info::clear_in_memory_info(bool all)
|
|
|
|
{
|
|
|
|
init_master_log_pos(this);
|
|
|
|
if (all)
|
|
|
|
{
|
|
|
|
port= MYSQL_PORT;
|
|
|
|
host[0] = 0; user[0] = 0; password[0] = 0;
|
MDEV-25284: Assertion `info->type == READ_CACHE || info->type == WRITE_CACHE' failed
Problem:
========
This patch addresses two issues.
First, if a CHANGE MASTER command is issued and an error happens
while locating the replica’s relay logs, the logs can be put into an
invalid state where future updates fail and future CHANGE MASTER
calls crash the server. More specifically, right before a replica
purges the relay logs (part of the `CHANGE MASTER TO` logic), the
relay log is temporarily closed with state LOG_TO_BE_OPENED. If the
server errors in-between the temporary log closure and purge, i.e.
during the function find_log_pos, the log should be closed.
MDEV-25284 reveals the log is not properly closed.
Second, upon issuing a RESET SLAVE ALL command, a slave’s GTID
filters are not cleared (DO_DOMAIN_IDS, IGNORE_DOMIAN_IDS,
IGNORE_SERVER_IDS). MySQL had a similar bug report, Bug #18816897,
which fixed this issue to clear IGNORE_SERVER_IDS after issuing
RESET SLAVE ALL in version 5.7.
Solution:
=========
To fix the first problem, the CHANGE MASTER error handling logic was
extended to transition the relay log state to LOG_CLOSED from
LOG_TO_BE_OPENED.
To fix the second problem, the RESET SLAVE ALL logic is extended to
clear the domain_id filter and ignore_server_ids.
Reviewed By:
============
Andrei Elkin <andrei.elkin@mariadb.com>
2021-10-13 15:31:32 +02:00
|
|
|
domain_id_filter.clear_ids();
|
|
|
|
reset_dynamic(&ignore_server_ids);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
MDEV-26: Global transaction ID.
Fix problems related to reconnect. When we need to reconnect (ie. explict
stop/start of just the IO thread by user, or automatic reconnect due to
loosing network connection with the master), it is a bit complex to correctly
resume at the right point without causing duplicate or missing events in the
relay log. The previous code had multiple problems in this regard.
With this patch, the problem is solved as follows. The IO thread keeps track
(in memory) of which GTID was last queued to the relay log. If it needs to
reconnect, it resumes at that GTID position. It also counts number of events
received within the last, possibly partial, event group, and skips the same
number of events after a reconnect, so that events already enqueued before the
reconnect are not duplicated.
(There is no need to keep any persistent state; whenever we restart slave
threads after both of them being stopped (such as after server restart), we
erase the relay logs and start over from the last GTID applied by SQL thread.
But while the SQL thread is running, this patch is needed to get correct relay
log).
2013-06-05 14:32:47 +02:00
|
|
|
|
|
|
|
const char *
|
|
|
|
Master_info::using_gtid_astext(enum enum_using_gtid arg)
|
|
|
|
{
|
|
|
|
switch (arg)
|
|
|
|
{
|
|
|
|
case USE_GTID_NO:
|
|
|
|
return "No";
|
|
|
|
case USE_GTID_SLAVE_POS:
|
|
|
|
return "Slave_Pos";
|
|
|
|
default:
|
|
|
|
DBUG_ASSERT(arg == USE_GTID_CURRENT_POS);
|
|
|
|
return "Current_Pos";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 13:28:20 +01:00
|
|
|
void init_master_log_pos(Master_info* mi)
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
2009-11-04 13:28:20 +01:00
|
|
|
DBUG_ENTER("init_master_log_pos");
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
mi->master_log_name[0] = 0;
|
|
|
|
mi->master_log_pos = BIN_LOG_HEADER_SIZE; // skip magic number
|
MDEV-19801: Change defaults for CHANGE MASTER TO so that GTID-based replication is used by default if master supports it
This commit makes replicas crash-safe by default by changing the
Using_Gtid value to be Slave_Pos on a fresh slave start and after
RESET SLAVE is issued. If the primary server does not support GTIDs
(i.e., version < 10), the replica will fall back to Using_Gtid=No on
slave start and after RESET SLAVE.
The following additional informational messages/warnings are added:
1. When Using_Gtid is automatically changed. That is, if RESET
SLAVE reverts Using_Gtid back to Slave_Pos, or Using_Gtid is
inferred to No from a CHANGE MASTER TO given with log coordinates
without MASTER_USE_GTID.
2. If options are ignored in CHANGE MASTER TO. If CHANGE MASTER TO
is given with log coordinates, yet also specifies
MASTER_USE_GTID=Slave_Pos, a warning message is given that the log
coordinate options are ignored.
Additionally, an MTR macro has been added for RESET SLAVE,
reset_slave.inc, which provides modes/options for resetting a slave
in log coordinate or gtid modes. When in log coordinates mode, the
macro will execute CHANGE MASTER TO MASTER_USE_GTID=No after the
RESET SLAVE command. When in GTID mode, an extra parameter,
reset_slave_keep_gtid_state, can be set to reset or preserve the
value of gtid_slave_pos.
Reviewed By:
===========
Andrei Elkin <andrei.elkin@mariadb.com>
2022-05-23 22:14:00 +02:00
|
|
|
if (mi->master_supports_gtid)
|
|
|
|
{
|
|
|
|
mi->using_gtid= Master_info::USE_GTID_SLAVE_POS;
|
|
|
|
}
|
MDEV-26: Global transaction ID.
Fix problems related to reconnect. When we need to reconnect (ie. explict
stop/start of just the IO thread by user, or automatic reconnect due to
loosing network connection with the master), it is a bit complex to correctly
resume at the right point without causing duplicate or missing events in the
relay log. The previous code had multiple problems in this regard.
With this patch, the problem is solved as follows. The IO thread keeps track
(in memory) of which GTID was last queued to the relay log. If it needs to
reconnect, it resumes at that GTID position. It also counts number of events
received within the last, possibly partial, event group, and skips the same
number of events after a reconnect, so that events already enqueued before the
reconnect are not duplicated.
(There is no need to keep any persistent state; whenever we restart slave
threads after both of them being stopped (such as after server restart), we
erase the relay logs and start over from the last GTID applied by SQL thread.
But while the SQL thread is running, this patch is needed to get correct relay
log).
2013-06-05 14:32:47 +02:00
|
|
|
mi->gtid_current_pos.reset();
|
|
|
|
mi->events_queued_since_last_gtid= 0;
|
|
|
|
mi->gtid_reconnect_event_skip_count= 0;
|
|
|
|
mi->gtid_event_seen= false;
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2009-09-29 13:16:23 +02:00
|
|
|
/*
|
|
|
|
always request heartbeat unless master_heartbeat_period is set
|
|
|
|
explicitly zero. Here is the default value for heartbeat period
|
|
|
|
if CHANGE MASTER did not specify it. (no data loss in conversion
|
|
|
|
as hb period has a max)
|
|
|
|
*/
|
2013-03-25 23:03:13 +01:00
|
|
|
mi->heartbeat_period= (float) MY_MIN(SLAVE_MAX_HEARTBEAT_PERIOD,
|
2009-09-29 13:16:23 +02:00
|
|
|
(slave_net_timeout/2.0));
|
|
|
|
DBUG_ASSERT(mi->heartbeat_period > (float) 0.001
|
|
|
|
|| mi->heartbeat_period == 0);
|
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2014-12-04 04:30:48 +01:00
|
|
|
/**
|
|
|
|
Parses the IO_CACHE for "key=" and returns the "key".
|
2016-04-07 14:44:29 +02:00
|
|
|
If no '=' found, returns the whole line (for END_MARKER).
|
2014-12-04 04:30:48 +01:00
|
|
|
|
|
|
|
@param key [OUT] Key buffer
|
|
|
|
@param max_size [IN] Maximum buffer size
|
|
|
|
@param f [IN] IO_CACHE file
|
2016-04-07 14:44:29 +02:00
|
|
|
@param found_equal [OUT] Set true if a '=' was found.
|
2014-12-04 04:30:48 +01:00
|
|
|
|
|
|
|
@retval 0 Either "key=" or '\n' found
|
|
|
|
@retval 1 EOF
|
|
|
|
*/
|
2016-04-07 14:44:29 +02:00
|
|
|
static int
|
|
|
|
read_mi_key_from_file(char *key, int max_size, IO_CACHE *f, bool *found_equal)
|
2014-12-04 04:30:48 +01:00
|
|
|
{
|
|
|
|
int i= 0, c;
|
|
|
|
|
|
|
|
DBUG_ENTER("read_key_from_file");
|
|
|
|
|
2016-04-07 14:44:29 +02:00
|
|
|
*found_equal= false;
|
|
|
|
if (max_size <= 0)
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
for (;;)
|
2014-12-04 04:30:48 +01:00
|
|
|
{
|
2016-04-07 14:44:29 +02:00
|
|
|
if (i >= max_size-1)
|
2014-12-04 04:30:48 +01:00
|
|
|
{
|
2016-04-07 14:44:29 +02:00
|
|
|
key[i] = '\0';
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
c= my_b_get(f);
|
|
|
|
if (c == my_b_EOF)
|
|
|
|
{
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
else if (c == '\n')
|
|
|
|
{
|
|
|
|
key[i]= '\0';
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
else if (c == '=')
|
|
|
|
{
|
|
|
|
key[i]= '\0';
|
|
|
|
*found_equal= true;
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key[i]= c;
|
|
|
|
++i;
|
2014-12-04 04:30:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-07 14:44:29 +02:00
|
|
|
/* NotReached */
|
2014-12-04 04:30:48 +01:00
|
|
|
}
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2007-03-29 15:09:57 +02:00
|
|
|
enum {
|
|
|
|
LINES_IN_MASTER_INFO_WITH_SSL= 14,
|
|
|
|
|
|
|
|
/* 5.1.16 added value of master_ssl_verify_server_cert */
|
|
|
|
LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT= 15,
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
|
|
|
|
/* 5.5 added value of master_heartbeat_period */
|
2009-09-29 13:16:23 +02:00
|
|
|
LINE_FOR_MASTER_HEARTBEAT_PERIOD= 16,
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
|
2010-06-02 10:11:49 +02:00
|
|
|
/* MySQL Cluster 6.3 added master_bind */
|
|
|
|
LINE_FOR_MASTER_BIND = 17,
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
|
2009-10-01 18:44:53 +02:00
|
|
|
/* 6.0 added value of master_ignore_server_id */
|
2010-06-02 10:11:49 +02:00
|
|
|
LINE_FOR_REPLICATE_IGNORE_SERVER_IDS= 18,
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
|
|
|
|
/* 6.0 added value of master_uuid */
|
|
|
|
LINE_FOR_MASTER_UUID= 19,
|
|
|
|
|
|
|
|
/* line for master_retry_count */
|
|
|
|
LINE_FOR_MASTER_RETRY_COUNT= 20,
|
|
|
|
|
|
|
|
/* line for ssl_crl */
|
|
|
|
LINE_FOR_SSL_CRL= 21,
|
|
|
|
|
|
|
|
/* line for ssl_crl */
|
|
|
|
LINE_FOR_SSL_CRLPATH= 22,
|
|
|
|
|
2013-01-22 15:18:36 +01:00
|
|
|
/* MySQL 5.6 fixed-position lines. */
|
2013-04-17 15:17:01 +02:00
|
|
|
LINE_FOR_FIRST_MYSQL_5_6=23,
|
2013-01-22 15:18:36 +01:00
|
|
|
LINE_FOR_LAST_MYSQL_5_6=23,
|
|
|
|
/* Reserved lines for MySQL future versions. */
|
|
|
|
LINE_FOR_LAST_MYSQL_FUTURE=33,
|
|
|
|
/* Number of (fixed-position) lines used when saving master info file */
|
|
|
|
LINES_IN_MASTER_INFO= LINE_FOR_LAST_MYSQL_FUTURE
|
2007-03-29 15:09:57 +02:00
|
|
|
};
|
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)
|
|
|
|
{
|
|
|
|
int fd,error;
|
|
|
|
char fname[FN_REFLEN+128];
|
|
|
|
DBUG_ENTER("init_master_info");
|
|
|
|
|
|
|
|
if (mi->inited)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We have to reset read position of relay-log-bin as we may have
|
|
|
|
already been reading from 'hotlog' when the slave was stopped
|
|
|
|
last time. If this case pos_in_file would be set and we would
|
|
|
|
get a crash when trying to read the signature for the binary
|
|
|
|
relay log.
|
|
|
|
|
|
|
|
We only rewind the read position if we are starting the SQL
|
|
|
|
thread. The handle_slave_sql thread assumes that the read
|
|
|
|
position is at the beginning of the file, and will read the
|
|
|
|
"signature" and then fast-forward to the last position read.
|
|
|
|
*/
|
|
|
|
if (thread_mask & SLAVE_SQL)
|
|
|
|
{
|
2010-06-24 20:03:23 +02:00
|
|
|
bool hot_log= FALSE;
|
|
|
|
/*
|
|
|
|
my_b_seek does an implicit flush_io_cache, so we need to:
|
|
|
|
|
|
|
|
1. check if this log is active (hot)
|
|
|
|
2. if it is we keep log_lock until the seek ends, otherwise
|
|
|
|
release it right away.
|
|
|
|
|
|
|
|
If we did not take log_lock, SQL thread might race with IO
|
|
|
|
thread for the IO_CACHE mutex.
|
|
|
|
|
|
|
|
*/
|
|
|
|
mysql_mutex_t *log_lock= mi->rli.relay_log.get_log_lock();
|
|
|
|
mysql_mutex_lock(log_lock);
|
|
|
|
hot_log= mi->rli.relay_log.is_active(mi->rli.linfo.log_file_name);
|
|
|
|
|
|
|
|
if (!hot_log)
|
|
|
|
mysql_mutex_unlock(log_lock);
|
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
my_b_seek(mi->rli.cur_log, (my_off_t) 0);
|
2010-06-24 20:03:23 +02:00
|
|
|
|
|
|
|
if (hot_log)
|
|
|
|
mysql_mutex_unlock(log_lock);
|
2006-10-31 16:51:51 +01:00
|
|
|
}
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->mysql=0;
|
|
|
|
mi->file_id=1;
|
|
|
|
fn_format(fname, master_info_fname, mysql_data_home, "", 4+32);
|
|
|
|
|
|
|
|
/*
|
|
|
|
We need a mutex while we are changing master info parameters to
|
|
|
|
keep other threads from reading bogus info
|
|
|
|
*/
|
|
|
|
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&mi->data_lock);
|
2006-10-31 16:51:51 +01:00
|
|
|
fd = mi->fd;
|
|
|
|
|
|
|
|
/* does master.info exist ? */
|
|
|
|
|
|
|
|
if (access(fname,F_OK))
|
|
|
|
{
|
|
|
|
if (abort_if_no_master_info_file)
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&mi->data_lock);
|
2006-10-31 16:51:51 +01:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if someone removed the file from underneath our feet, just close
|
|
|
|
the old descriptor and re-create the old file
|
|
|
|
*/
|
|
|
|
if (fd >= 0)
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_file_close(fd, MYF(MY_WME));
|
|
|
|
if ((fd= mysql_file_open(key_file_master_info,
|
|
|
|
fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0 )
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
|
|
|
sql_print_error("Failed to create a new master info file (\
|
|
|
|
file '%s', errno %d)", fname, my_errno);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,0,
|
|
|
|
MYF(MY_WME)))
|
|
|
|
{
|
|
|
|
sql_print_error("Failed to create a cache on master info file (\
|
|
|
|
file '%s')", fname);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->fd = fd;
|
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
|
|
|
mi->clear_in_memory_info(false);
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
else // file exists
|
|
|
|
{
|
|
|
|
if (fd >= 0)
|
|
|
|
reinit_io_cache(&mi->file, READ_CACHE, 0L,0,0);
|
|
|
|
else
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
if ((fd= mysql_file_open(key_file_master_info,
|
|
|
|
fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0 )
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
|
|
|
sql_print_error("Failed to open the existing master info file (\
|
|
|
|
file '%s', errno %d)", fname, my_errno);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (init_io_cache(&mi->file, fd, IO_SIZE*2, READ_CACHE, 0L,
|
|
|
|
0, MYF(MY_WME)))
|
|
|
|
{
|
|
|
|
sql_print_error("Failed to create a cache on master info file (\
|
|
|
|
file '%s')", fname);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->fd = fd;
|
2007-03-29 15:09:57 +02:00
|
|
|
int port, connect_retry, master_log_pos, lines;
|
|
|
|
int ssl= 0, ssl_verify_server_cert= 0;
|
2009-09-29 13:16:23 +02:00
|
|
|
float master_heartbeat_period= 0.0;
|
2006-10-31 16:51:51 +01:00
|
|
|
char *first_non_digit;
|
2013-01-22 15:18:36 +01:00
|
|
|
char buf[HOSTNAME_LENGTH+1];
|
2006-10-31 16:51:51 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Starting from 4.1.x master.info has new format. Now its
|
|
|
|
first line contains number of lines in file. By reading this
|
|
|
|
number we will be always distinguish to which version our
|
|
|
|
master.info corresponds to. We can't simply count lines in
|
|
|
|
file since versions before 4.1.x could generate files with more
|
|
|
|
lines than needed.
|
|
|
|
If first line doesn't contain a number or contain number less than
|
2007-03-29 15:09:57 +02:00
|
|
|
LINES_IN_MASTER_INFO_WITH_SSL then such file is treated like file
|
|
|
|
from pre 4.1.1 version.
|
2006-10-31 16:51:51 +01:00
|
|
|
There is no ambiguity when reading an old master.info, as before
|
|
|
|
4.1.1, the first line contained the binlog's name, which is either
|
|
|
|
empty or has an extension (contains a '.'), so can't be confused
|
|
|
|
with an integer.
|
|
|
|
|
|
|
|
So we're just reading first line and trying to figure which version
|
|
|
|
is this.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
The first row is temporarily stored in mi->master_log_name,
|
|
|
|
if it is line count and not binlog name (new format) it will be
|
|
|
|
overwritten by the second row later.
|
|
|
|
*/
|
|
|
|
if (init_strvar_from_file(mi->master_log_name,
|
|
|
|
sizeof(mi->master_log_name), &mi->file,
|
|
|
|
""))
|
|
|
|
goto errwithmsg;
|
|
|
|
|
|
|
|
lines= strtoul(mi->master_log_name, &first_non_digit, 10);
|
|
|
|
|
|
|
|
if (mi->master_log_name[0]!='\0' &&
|
|
|
|
*first_non_digit=='\0' && lines >= LINES_IN_MASTER_INFO_WITH_SSL)
|
2007-03-29 15:09:57 +02:00
|
|
|
{
|
|
|
|
/* Seems to be new format => read master log name from next line */
|
2006-10-31 16:51:51 +01:00
|
|
|
if (init_strvar_from_file(mi->master_log_name,
|
|
|
|
sizeof(mi->master_log_name), &mi->file, ""))
|
|
|
|
goto errwithmsg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lines= 7;
|
|
|
|
|
|
|
|
if (init_intvar_from_file(&master_log_pos, &mi->file, 4) ||
|
2009-11-04 13:28:20 +01:00
|
|
|
init_strvar_from_file(mi->host, sizeof(mi->host), &mi->file, 0) ||
|
|
|
|
init_strvar_from_file(mi->user, sizeof(mi->user), &mi->file, "test") ||
|
2006-10-31 16:51:51 +01:00
|
|
|
init_strvar_from_file(mi->password, SCRAMBLED_PASSWORD_CHAR_LENGTH+1,
|
2009-11-04 13:28:20 +01:00
|
|
|
&mi->file, 0) ||
|
|
|
|
init_intvar_from_file(&port, &mi->file, MYSQL_PORT) ||
|
2006-10-31 16:51:51 +01:00
|
|
|
init_intvar_from_file(&connect_retry, &mi->file,
|
2009-11-04 13:28:20 +01:00
|
|
|
DEFAULT_CONNECT_RETRY))
|
2006-10-31 16:51:51 +01:00
|
|
|
goto errwithmsg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
If file has ssl part use it even if we have server without
|
2009-11-04 13:28:20 +01:00
|
|
|
SSL support. But these options will be ignored later when
|
2006-10-31 16:51:51 +01:00
|
|
|
slave will try connect to master, so in this case warning
|
|
|
|
is printed.
|
|
|
|
*/
|
2007-03-29 15:09:57 +02:00
|
|
|
if (lines >= LINES_IN_MASTER_INFO_WITH_SSL)
|
|
|
|
{
|
2009-11-04 13:28:20 +01:00
|
|
|
if (init_intvar_from_file(&ssl, &mi->file, 0) ||
|
2007-03-29 15:09:57 +02:00
|
|
|
init_strvar_from_file(mi->ssl_ca, sizeof(mi->ssl_ca),
|
2009-11-04 13:28:20 +01:00
|
|
|
&mi->file, 0) ||
|
2007-03-29 15:09:57 +02:00
|
|
|
init_strvar_from_file(mi->ssl_capath, sizeof(mi->ssl_capath),
|
2009-11-04 13:28:20 +01:00
|
|
|
&mi->file, 0) ||
|
2007-03-29 15:09:57 +02:00
|
|
|
init_strvar_from_file(mi->ssl_cert, sizeof(mi->ssl_cert),
|
2009-11-04 13:28:20 +01:00
|
|
|
&mi->file, 0) ||
|
2007-03-29 15:09:57 +02:00
|
|
|
init_strvar_from_file(mi->ssl_cipher, sizeof(mi->ssl_cipher),
|
2009-11-04 13:28:20 +01:00
|
|
|
&mi->file, 0) ||
|
2007-03-29 15:09:57 +02:00
|
|
|
init_strvar_from_file(mi->ssl_key, sizeof(mi->ssl_key),
|
2009-11-04 13:28:20 +01:00
|
|
|
&mi->file, 0))
|
2007-03-29 15:09:57 +02:00
|
|
|
goto errwithmsg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Starting from 5.1.16 ssl_verify_server_cert might be
|
|
|
|
in the file
|
|
|
|
*/
|
|
|
|
if (lines >= LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT &&
|
|
|
|
init_intvar_from_file(&ssl_verify_server_cert, &mi->file, 0))
|
|
|
|
goto errwithmsg;
|
2009-09-29 13:16:23 +02:00
|
|
|
/*
|
|
|
|
Starting from 6.0 master_heartbeat_period might be
|
|
|
|
in the file
|
|
|
|
*/
|
|
|
|
if (lines >= LINE_FOR_MASTER_HEARTBEAT_PERIOD &&
|
|
|
|
init_floatvar_from_file(&master_heartbeat_period, &mi->file, 0.0))
|
|
|
|
goto errwithmsg;
|
2010-06-02 10:11:49 +02:00
|
|
|
/*
|
|
|
|
Starting from MySQL Cluster 6.3 master_bind might be in the file
|
|
|
|
(this is just a reservation to avoid future upgrade problems)
|
|
|
|
*/
|
|
|
|
if (lines >= LINE_FOR_MASTER_BIND &&
|
2013-01-22 15:18:36 +01:00
|
|
|
init_strvar_from_file(buf, sizeof(buf), &mi->file, ""))
|
2010-06-02 10:11:49 +02:00
|
|
|
goto errwithmsg;
|
2009-10-01 18:44:53 +02:00
|
|
|
/*
|
|
|
|
Starting from 6.0 list of server_id of ignorable servers might be
|
|
|
|
in the file
|
|
|
|
*/
|
|
|
|
if (lines >= LINE_FOR_REPLICATE_IGNORE_SERVER_IDS &&
|
|
|
|
init_dynarray_intvar_from_file(&mi->ignore_server_ids, &mi->file))
|
|
|
|
{
|
|
|
|
sql_print_error("Failed to initialize master info ignore_server_ids");
|
|
|
|
goto errwithmsg;
|
|
|
|
}
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
|
|
|
|
/* reserved */
|
|
|
|
if (lines >= LINE_FOR_MASTER_UUID &&
|
2013-04-17 15:17:01 +02:00
|
|
|
init_strvar_from_file(buf, sizeof(buf), &mi->file, ""))
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
goto errwithmsg;
|
|
|
|
|
|
|
|
/* Starting from 5.5 the master_retry_count may be in the repository. */
|
|
|
|
if (lines >= LINE_FOR_MASTER_RETRY_COUNT &&
|
2013-04-17 15:17:01 +02:00
|
|
|
init_strvar_from_file(buf, sizeof(buf), &mi->file, ""))
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
goto errwithmsg;
|
|
|
|
|
|
|
|
if (lines >= LINE_FOR_SSL_CRLPATH &&
|
|
|
|
(init_strvar_from_file(mi->ssl_crl, sizeof(mi->ssl_crl),
|
|
|
|
&mi->file, "") ||
|
|
|
|
init_strvar_from_file(mi->ssl_crlpath, sizeof(mi->ssl_crlpath),
|
|
|
|
&mi->file, "")))
|
|
|
|
goto errwithmsg;
|
2013-04-17 15:17:01 +02:00
|
|
|
|
2013-01-22 15:18:36 +01:00
|
|
|
/*
|
|
|
|
Starting with MariaDB 10.0, we use a key=value syntax, which is nicer
|
|
|
|
in several ways. But we leave a bunch of empty lines to accomodate
|
|
|
|
any future old-style additions in MySQL (this will make it easier for
|
|
|
|
users moving from MariaDB to MySQL, to not have MySQL try to
|
|
|
|
interpret a MariaDB key=value line.)
|
|
|
|
*/
|
|
|
|
if (lines >= LINE_FOR_LAST_MYSQL_FUTURE)
|
|
|
|
{
|
|
|
|
uint i;
|
2016-04-07 14:44:29 +02:00
|
|
|
bool got_eq;
|
|
|
|
bool seen_using_gtid= false;
|
|
|
|
bool seen_do_domain_ids=false, seen_ignore_domain_ids=false;
|
|
|
|
|
2013-01-22 15:18:36 +01:00
|
|
|
/* Skip lines used by / reserved for MySQL >= 5.6. */
|
|
|
|
for (i= LINE_FOR_FIRST_MYSQL_5_6; i <= LINE_FOR_LAST_MYSQL_FUTURE; ++i)
|
|
|
|
{
|
|
|
|
if (init_strvar_from_file(buf, sizeof(buf), &mi->file, ""))
|
|
|
|
goto errwithmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-04 04:30:48 +01:00
|
|
|
Parse any extra key=value lines. read_key_from_file() parses the file
|
|
|
|
for "key=" and returns the "key" if found. The "value" can then the
|
|
|
|
parsed on case by case basis. The "unknown" lines would be ignored to
|
|
|
|
facilitate downgrades.
|
2016-04-07 14:44:29 +02:00
|
|
|
10.0 does not have the END_MARKER before any left-overs at the end
|
|
|
|
of the file. So ignore any but the first occurrence of a key.
|
2013-01-22 15:18:36 +01:00
|
|
|
*/
|
2016-04-07 14:44:29 +02:00
|
|
|
while (!read_mi_key_from_file(buf, sizeof(buf), &mi->file, &got_eq))
|
2013-01-22 15:18:36 +01:00
|
|
|
{
|
2016-04-07 14:44:29 +02:00
|
|
|
if (got_eq && !seen_using_gtid && !strcmp(buf, "using_gtid"))
|
2014-12-04 04:30:48 +01:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
if (!init_intvar_from_file(&val, &mi->file, 0))
|
|
|
|
{
|
|
|
|
if (val == Master_info::USE_GTID_CURRENT_POS)
|
|
|
|
mi->using_gtid= Master_info::USE_GTID_CURRENT_POS;
|
|
|
|
else if (val == Master_info::USE_GTID_SLAVE_POS)
|
|
|
|
mi->using_gtid= Master_info::USE_GTID_SLAVE_POS;
|
|
|
|
else
|
|
|
|
mi->using_gtid= Master_info::USE_GTID_NO;
|
2016-04-07 14:44:29 +02:00
|
|
|
seen_using_gtid= true;
|
2014-12-04 04:30:48 +01:00
|
|
|
} else {
|
|
|
|
sql_print_error("Failed to initialize master info using_gtid");
|
|
|
|
goto errwithmsg;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 14:44:29 +02:00
|
|
|
else if (got_eq && !seen_do_domain_ids && !strcmp(buf, "do_domain_ids"))
|
2013-05-22 17:36:48 +02:00
|
|
|
{
|
2014-12-04 04:30:48 +01:00
|
|
|
if (mi->domain_id_filter.init_ids(&mi->file,
|
|
|
|
Domain_id_filter::DO_DOMAIN_IDS))
|
|
|
|
{
|
|
|
|
sql_print_error("Failed to initialize master info do_domain_ids");
|
|
|
|
goto errwithmsg;
|
|
|
|
}
|
2016-04-07 14:44:29 +02:00
|
|
|
seen_do_domain_ids= true;
|
2014-12-04 04:30:48 +01:00
|
|
|
}
|
2016-04-07 14:44:29 +02:00
|
|
|
else if (got_eq && !seen_ignore_domain_ids &&
|
|
|
|
!strcmp(buf, "ignore_domain_ids"))
|
2014-12-04 04:30:48 +01:00
|
|
|
{
|
|
|
|
if (mi->domain_id_filter.init_ids(&mi->file,
|
|
|
|
Domain_id_filter::IGNORE_DOMAIN_IDS))
|
|
|
|
{
|
|
|
|
sql_print_error("Failed to initialize master info "
|
|
|
|
"ignore_domain_ids");
|
|
|
|
goto errwithmsg;
|
|
|
|
}
|
2016-04-07 14:44:29 +02:00
|
|
|
seen_ignore_domain_ids= true;
|
2013-05-22 17:36:48 +02:00
|
|
|
}
|
2016-04-07 14:44:29 +02:00
|
|
|
else if (!got_eq && !strcmp(buf, "END_MARKER"))
|
2014-12-05 16:09:48 +01:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Guard agaist extra left-overs at the end of file, in case a later
|
|
|
|
update causes the file to shrink compared to earlier contents.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
2013-01-22 15:18:36 +01:00
|
|
|
}
|
|
|
|
}
|
2007-03-29 15:09:57 +02:00
|
|
|
}
|
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
#ifndef HAVE_OPENSSL
|
|
|
|
if (ssl)
|
|
|
|
sql_print_warning("SSL information in the master info file "
|
2009-11-04 13:28:20 +01:00
|
|
|
"('%s') are ignored because this MySQL slave was "
|
|
|
|
"compiled without SSL support.", fname);
|
2006-10-31 16:51:51 +01:00
|
|
|
#endif /* HAVE_OPENSSL */
|
|
|
|
|
|
|
|
/*
|
|
|
|
This has to be handled here as init_intvar_from_file can't handle
|
|
|
|
my_off_t types
|
|
|
|
*/
|
|
|
|
mi->master_log_pos= (my_off_t) master_log_pos;
|
|
|
|
mi->port= (uint) port;
|
|
|
|
mi->connect_retry= (uint) connect_retry;
|
|
|
|
mi->ssl= (my_bool) ssl;
|
2007-03-29 15:09:57 +02:00
|
|
|
mi->ssl_verify_server_cert= ssl_verify_server_cert;
|
2017-05-17 14:42:36 +02:00
|
|
|
mi->heartbeat_period= MY_MIN(SLAVE_MAX_HEARTBEAT_PERIOD, master_heartbeat_period);
|
2006-10-31 16:51:51 +01:00
|
|
|
}
|
|
|
|
DBUG_PRINT("master_info",("log_file_name: %s position: %ld",
|
|
|
|
mi->master_log_name,
|
|
|
|
(ulong) mi->master_log_pos));
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
mi->rli.mi= mi;
|
2016-09-22 13:36:45 +02:00
|
|
|
if (mi->rli.init(slave_info_fname))
|
2006-10-31 16:51:51 +01:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
mi->inited = 1;
|
2009-09-30 23:41:05 +02:00
|
|
|
mi->rli.is_relay_log_recovery= FALSE;
|
2006-10-31 16:51:51 +01:00
|
|
|
// now change cache READ -> WRITE - must do this before flush_master_info
|
|
|
|
reinit_io_cache(&mi->file, WRITE_CACHE, 0L, 0, 1);
|
2018-04-04 11:16:12 +02:00
|
|
|
if (unlikely((error= MY_TEST(flush_master_info(mi, TRUE, TRUE)))))
|
2006-10-31 16:51:51 +01:00
|
|
|
sql_print_error("Failed to flush master info file");
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&mi->data_lock);
|
2006-10-31 16:51:51 +01:00
|
|
|
DBUG_RETURN(error);
|
|
|
|
|
|
|
|
errwithmsg:
|
|
|
|
sql_print_error("Error reading master configuration");
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_file_close(fd, MYF(0));
|
2006-10-31 16:51:51 +01:00
|
|
|
end_io_cache(&mi->file);
|
|
|
|
}
|
|
|
|
mi->fd= -1;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&mi->data_lock);
|
2006-10-31 16:51:51 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
RETURN
|
|
|
|
2 - flush relay log failed
|
|
|
|
1 - flush master info failed
|
|
|
|
0 - all ok
|
|
|
|
*/
|
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)
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
|
|
|
IO_CACHE* file = &mi->file;
|
|
|
|
char lbuf[22];
|
2009-09-29 16:27:12 +02:00
|
|
|
int err= 0;
|
2007-03-29 15:09:57 +02:00
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
DBUG_ENTER("flush_master_info");
|
|
|
|
DBUG_PRINT("enter",("master_pos: %ld", (long) mi->master_log_pos));
|
|
|
|
|
|
|
|
/*
|
|
|
|
Flush the relay log to disk. If we don't do it, then the relay log while
|
|
|
|
have some part (its last kilobytes) in memory only, so if the slave server
|
|
|
|
dies now, with, say, from master's position 100 to 150 in memory only (not
|
|
|
|
on disk), and with position 150 in master.info, then when the slave
|
|
|
|
restarts, the I/O thread will fetch binlogs from 150, so in the relay log
|
|
|
|
we will have "[0, 100] U [150, infinity[" and nobody will notice it, so the
|
|
|
|
SQL thread will jump from 100 to 150, and replication will silently break.
|
|
|
|
|
|
|
|
When we come to this place in code, relay log may or not be initialized;
|
|
|
|
the caller is responsible for setting 'flush_relay_log_cache' accordingly.
|
|
|
|
*/
|
2009-09-29 16:27:12 +02:00
|
|
|
if (flush_relay_log_cache)
|
|
|
|
{
|
2010-02-03 18:19:58 +01:00
|
|
|
mysql_mutex_t *log_lock= mi->rli.relay_log.get_log_lock();
|
2009-09-29 16:27:12 +02:00
|
|
|
IO_CACHE *log_file= mi->rli.relay_log.get_log_file();
|
2010-02-03 17:56:17 +01:00
|
|
|
|
|
|
|
if (need_lock_relay_log)
|
2010-02-03 18:19:58 +01:00
|
|
|
mysql_mutex_lock(log_lock);
|
2010-02-03 17:56:17 +01:00
|
|
|
|
2010-02-03 18:19:58 +01:00
|
|
|
mysql_mutex_assert_owner(log_lock);
|
2010-02-03 17:56:17 +01:00
|
|
|
err= flush_io_cache(log_file);
|
|
|
|
|
|
|
|
if (need_lock_relay_log)
|
2010-02-03 18:19:58 +01:00
|
|
|
mysql_mutex_unlock(log_lock);
|
2010-02-03 17:56:17 +01:00
|
|
|
|
|
|
|
if (err)
|
2009-09-29 16:27:12 +02:00
|
|
|
DBUG_RETURN(2);
|
|
|
|
}
|
2014-12-04 04:30:48 +01:00
|
|
|
|
2009-10-01 18:44:53 +02:00
|
|
|
/*
|
|
|
|
produce a line listing the total number and all the ignored server_id:s
|
|
|
|
*/
|
|
|
|
char* ignore_server_ids_buf;
|
|
|
|
{
|
|
|
|
ignore_server_ids_buf=
|
2020-01-29 13:50:26 +01:00
|
|
|
(char *) my_malloc(PSI_INSTRUMENT_ME,
|
|
|
|
(sizeof(global_system_variables.server_id) * 3 + 1) *
|
2009-10-01 18:44:53 +02:00
|
|
|
(1 + mi->ignore_server_ids.elements), MYF(MY_WME));
|
|
|
|
if (!ignore_server_ids_buf)
|
2014-12-04 04:30:48 +01:00
|
|
|
DBUG_RETURN(1); /* error */
|
2021-09-03 06:38:54 +02:00
|
|
|
ulong cur_len= sprintf(ignore_server_ids_buf, "%zu",
|
2010-07-09 14:28:51 +02:00
|
|
|
mi->ignore_server_ids.elements);
|
|
|
|
for (ulong i= 0; i < mi->ignore_server_ids.elements; i++)
|
2009-10-01 18:44:53 +02:00
|
|
|
{
|
|
|
|
ulong s_id;
|
|
|
|
get_dynamic(&mi->ignore_server_ids, (uchar*) &s_id, i);
|
2010-07-09 14:28:51 +02:00
|
|
|
cur_len+= sprintf(ignore_server_ids_buf + cur_len, " %lu", s_id);
|
2009-10-01 18:44:53 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2014-12-04 04:30:48 +01:00
|
|
|
char *do_domain_ids_buf= 0, *ignore_domain_ids_buf= 0;
|
|
|
|
|
|
|
|
do_domain_ids_buf=
|
|
|
|
mi->domain_id_filter.as_string(Domain_id_filter::DO_DOMAIN_IDS);
|
|
|
|
if (do_domain_ids_buf == NULL)
|
|
|
|
{
|
|
|
|
err= 1; /* error */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ignore_domain_ids_buf=
|
|
|
|
mi->domain_id_filter.as_string(Domain_id_filter::IGNORE_DOMAIN_IDS);
|
|
|
|
if (ignore_domain_ids_buf == NULL)
|
|
|
|
{
|
|
|
|
err= 1; /* error */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
/*
|
|
|
|
We flushed the relay log BEFORE the master.info file, because if we crash
|
|
|
|
now, we will get a duplicate event in the relay log at restart. If we
|
|
|
|
flushed in the other order, we would get a hole in the relay log.
|
|
|
|
And duplicate is better than hole (with a duplicate, in later versions we
|
|
|
|
can add detection and scrap one event; with a hole there's nothing we can
|
|
|
|
do).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
In certain cases this code may create master.info files that seems
|
|
|
|
corrupted, because of extra lines filled with garbage in the end
|
|
|
|
file (this happens if new contents take less space than previous
|
|
|
|
contents of file). But because of number of lines in the first line
|
|
|
|
of file we don't care about this garbage.
|
|
|
|
*/
|
2017-05-15 13:33:59 +02:00
|
|
|
char heartbeat_buf[FLOATING_POINT_BUFFER];
|
|
|
|
my_fcvt(mi->heartbeat_period, 3, heartbeat_buf, NULL);
|
2006-10-31 16:51:51 +01:00
|
|
|
my_b_seek(file, 0L);
|
2007-03-29 15:09:57 +02:00
|
|
|
my_b_printf(file,
|
2013-04-17 15:17:01 +02:00
|
|
|
"%u\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n%s\n%s\n%s\n%s\n%s\n%d\n%s\n%s\n%s\n%s\n%d\n%s\n%s\n"
|
|
|
|
"\n\n\n\n\n\n\n\n\n\n\n"
|
2014-12-04 04:30:48 +01:00
|
|
|
"using_gtid=%d\n"
|
|
|
|
"do_domain_ids=%s\n"
|
2014-12-05 16:09:48 +01:00
|
|
|
"ignore_domain_ids=%s\n"
|
|
|
|
"END_MARKER\n",
|
2007-03-29 15:09:57 +02:00
|
|
|
LINES_IN_MASTER_INFO,
|
2006-10-31 16:51:51 +01:00
|
|
|
mi->master_log_name, llstr(mi->master_log_pos, lbuf),
|
|
|
|
mi->host, mi->user,
|
|
|
|
mi->password, mi->port, mi->connect_retry,
|
|
|
|
(int)(mi->ssl), mi->ssl_ca, mi->ssl_capath, mi->ssl_cert,
|
2009-09-29 13:16:23 +02:00
|
|
|
mi->ssl_cipher, mi->ssl_key, mi->ssl_verify_server_cert,
|
fixes for test failures
and small collateral changes
mysql-test/lib/My/Test.pm:
somehow with "print" we get truncated writes sometimes
mysql-test/suite/perfschema/r/digest_table_full.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/dml_handler.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/information_schema.result:
host table is not ported over yet
mysql-test/suite/perfschema/r/nesting.result:
this differs, because we don't rewrite general log queries, and multi-statement
packets are logged as a one entry. this result file is identical to what mysql-5.6.5
produces with the --log-raw option.
mysql-test/suite/perfschema/r/relaylog.result:
MariaDB modifies the binlog index file directly, while MySQL 5.6 has a feature "crash-safe binlog index" and modifies a special "crash-safe" shadow copy of the index file and then moves it over. That's why this test shows "NONE" index file writes in MySQL and "MANY" in MariaDB.
mysql-test/suite/perfschema/r/server_init.result:
MariaDB initializes the "manager" resources from the "manager" thread, and starts this thread only when --flush-time is not 0. MySQL 5.6 initializes "manager" resources unconditionally on server startup.
mysql-test/suite/perfschema/r/stage_mdl_global.result:
this differs, because MariaDB disables query cache when query_cache_size=0. MySQL does not
do that, and this causes useless mutex locks and waits.
mysql-test/suite/perfschema/r/statement_digest.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_consumers.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/perfschema/r/statement_digest_long_query.result:
md5 hashes of statement digests differ, because yacc token codes are different in mariadb
mysql-test/suite/rpl/r/rpl_mixed_drop_create_temp_table.result:
will be updated to match 5.6 when alfranio.correia@oracle.com-20110512172919-c1b5kmum4h52g0ni and anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y are merged
mysql-test/suite/rpl/r/rpl_non_direct_mixed_mixing_engines.result:
will be updated to match 5.6 when anders.song@greatopensource.com-20110105052107-zoab0bsf5a6xxk2y is merged
2012-09-27 20:09:46 +02:00
|
|
|
heartbeat_buf, "", ignore_server_ids_buf,
|
|
|
|
"", 0,
|
2014-12-04 04:30:48 +01:00
|
|
|
mi->ssl_crl, mi->ssl_crlpath, mi->using_gtid,
|
|
|
|
do_domain_ids_buf, ignore_domain_ids_buf);
|
2009-09-29 16:27:12 +02:00
|
|
|
err= flush_io_cache(file);
|
2014-12-04 04:30:48 +01:00
|
|
|
if (sync_masterinfo_period && !err &&
|
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
|
|
|
++(mi->sync_counter) >= sync_masterinfo_period)
|
|
|
|
{
|
2009-09-29 16:27:12 +02:00
|
|
|
err= my_sync(mi->fd, MYF(MY_WME));
|
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
|
|
|
mi->sync_counter= 0;
|
|
|
|
}
|
2014-12-04 04:30:48 +01:00
|
|
|
|
|
|
|
/* Fix err; flush_io_cache()/my_sync() may return -1 */
|
|
|
|
err= (err != 0) ? 1 : 0;
|
|
|
|
|
|
|
|
done:
|
|
|
|
my_free(ignore_server_ids_buf);
|
|
|
|
my_free(do_domain_ids_buf);
|
|
|
|
my_free(ignore_domain_ids_buf);
|
|
|
|
DBUG_RETURN(err);
|
2006-10-31 16:51:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-16 08:52:50 +02:00
|
|
|
void end_master_info(Master_info* mi)
|
2006-10-31 16:51:51 +01:00
|
|
|
{
|
|
|
|
DBUG_ENTER("end_master_info");
|
|
|
|
|
|
|
|
if (!mi->inited)
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
if (mi->fd >= 0)
|
|
|
|
{
|
|
|
|
end_io_cache(&mi->file);
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_file_close(mi->fd, MYF(MY_WME));
|
2006-10-31 16:51:51 +01:00
|
|
|
mi->fd = -1;
|
|
|
|
}
|
|
|
|
mi->inited = 0;
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
/* Multi-Master By P.Linux */
|
|
|
|
uchar *get_key_master_info(Master_info *mi, size_t *length,
|
|
|
|
my_bool not_used __attribute__((unused)))
|
|
|
|
{
|
|
|
|
/* Return lower case name */
|
|
|
|
*length= mi->cmp_connection_name.length;
|
|
|
|
return (uchar*) mi->cmp_connection_name.str;
|
|
|
|
}
|
|
|
|
|
2017-01-29 22:44:24 +01:00
|
|
|
/*
|
|
|
|
Delete a master info
|
|
|
|
|
|
|
|
Called from my_hash_delete(&master_info_hash)
|
|
|
|
Stops associated slave threads and frees master_info
|
|
|
|
*/
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
void free_key_master_info(Master_info *mi)
|
|
|
|
{
|
|
|
|
DBUG_ENTER("free_key_master_info");
|
2017-01-29 22:44:24 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
/* Ensure that we are not in reset_slave while this is done */
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->lock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
terminate_slave_threads(mi,SLAVE_FORCE_ALL);
|
2017-01-29 21:10:56 +01:00
|
|
|
/* We use 2 here instead of 1 just to make it easier when debugging */
|
|
|
|
mi->killed= 2;
|
2012-09-28 01:06:56 +02:00
|
|
|
end_master_info(mi);
|
2017-07-27 12:42:21 +02:00
|
|
|
end_relay_log_info(&mi->rli);
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->unlock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
delete mi;
|
2017-01-29 22:44:24 +01:00
|
|
|
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
2012-09-28 01:06:56 +02:00
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check if connection name for master_info is valid.
|
|
|
|
|
2012-10-03 00:44:54 +02:00
|
|
|
It's valid if it's a valid system name of length less than
|
2012-09-28 01:06:56 +02:00
|
|
|
MAX_CONNECTION_NAME.
|
|
|
|
|
|
|
|
@return
|
|
|
|
0 ok
|
|
|
|
1 error
|
|
|
|
*/
|
|
|
|
|
2017-04-23 18:39:57 +02:00
|
|
|
bool check_master_connection_name(LEX_CSTRING *name)
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
if (name->length >= MAX_CONNECTION_NAME)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2012-10-03 00:44:54 +02:00
|
|
|
Create a log file with a given suffix.
|
2012-09-28 01:06:56 +02:00
|
|
|
|
|
|
|
@param
|
|
|
|
res_file_name Store result here
|
|
|
|
length Length of res_file_name buffer
|
|
|
|
info_file Original file name (prefix)
|
2012-10-01 01:30:44 +02:00
|
|
|
append 1 if we should add suffix last (not before ext)
|
2012-09-28 01:06:56 +02:00
|
|
|
suffix Suffix
|
|
|
|
|
|
|
|
@note
|
2012-10-01 01:30:44 +02:00
|
|
|
The suffix is added before the extension of the file name prefixed with '-'.
|
|
|
|
The suffix is also converted to lower case and we transform
|
|
|
|
all not safe character, as we do with MySQL table names.
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
If suffix is an empty string, then we don't add any suffix.
|
|
|
|
This is to allow one to use this function also to generate old
|
|
|
|
file names without a prefix.
|
|
|
|
*/
|
|
|
|
|
2012-10-23 11:19:42 +02:00
|
|
|
void create_logfile_name_with_suffix(char *res_file_name, size_t length,
|
2013-05-03 00:50:42 +02:00
|
|
|
const char *info_file, bool append,
|
2017-04-23 18:39:57 +02:00
|
|
|
LEX_CSTRING *suffix)
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2013-05-03 00:50:42 +02:00
|
|
|
char buff[MAX_CONNECTION_NAME+1],
|
|
|
|
res[MAX_CONNECTION_NAME * MAX_FILENAME_MBWIDTH+1], *p;
|
2012-10-01 01:30:44 +02:00
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
p= strmake(res_file_name, info_file, length);
|
2012-10-01 01:30:44 +02:00
|
|
|
/* If not empty suffix and there is place left for some part of the suffix */
|
|
|
|
if (suffix->length != 0 && p <= res_file_name + length -1)
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2012-10-01 01:30:44 +02:00
|
|
|
const char *info_file_end= info_file + (p - res_file_name);
|
|
|
|
const char *ext= append ? info_file_end : fn_ext2(info_file);
|
2013-07-03 21:50:34 +02:00
|
|
|
size_t res_length, ext_pos, from_length;
|
2012-09-28 01:06:56 +02:00
|
|
|
uint errors;
|
|
|
|
|
|
|
|
/* Create null terminated string */
|
2013-07-03 21:50:34 +02:00
|
|
|
from_length= strmake(buff, suffix->str, suffix->length) - buff;
|
2012-09-28 01:06:56 +02:00
|
|
|
/* Convert to characters usable in a file name */
|
2013-07-03 21:50:34 +02:00
|
|
|
res_length= strconvert(system_charset_info, buff, from_length,
|
2012-09-28 01:06:56 +02:00
|
|
|
&my_charset_filename, res, sizeof(res), &errors);
|
2012-10-01 01:30:44 +02:00
|
|
|
|
|
|
|
ext_pos= (size_t) (ext - info_file);
|
|
|
|
length-= (suffix->length - ext_pos); /* Leave place for extension */
|
|
|
|
p= res_file_name + ext_pos;
|
|
|
|
*p++= '-'; /* Add separator */
|
2013-03-25 23:03:13 +01:00
|
|
|
p= strmake(p, res, MY_MIN((size_t) (length - (p - res_file_name)),
|
2012-10-04 22:58:59 +02:00
|
|
|
res_length));
|
2012-10-01 01:30:44 +02:00
|
|
|
/* Add back extension. We have checked above that there is space for it */
|
|
|
|
strmov(p, ext);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 13:43:28 +02:00
|
|
|
void copy_filter_setting(Rpl_filter* dst_filter, Rpl_filter* src_filter)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
String tmp(buf, sizeof(buf), &my_charset_bin);
|
|
|
|
|
|
|
|
dst_filter->get_do_db(&tmp);
|
|
|
|
if (tmp.is_empty())
|
|
|
|
{
|
|
|
|
src_filter->get_do_db(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_do_db(tmp.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_filter->get_do_table(&tmp);
|
|
|
|
if (tmp.is_empty())
|
|
|
|
{
|
|
|
|
src_filter->get_do_table(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_do_table(tmp.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_filter->get_ignore_db(&tmp);
|
|
|
|
if (tmp.is_empty())
|
|
|
|
{
|
|
|
|
src_filter->get_ignore_db(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_ignore_db(tmp.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_filter->get_ignore_table(&tmp);
|
|
|
|
if (tmp.is_empty())
|
|
|
|
{
|
|
|
|
src_filter->get_ignore_table(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_ignore_table(tmp.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_filter->get_wild_do_table(&tmp);
|
|
|
|
if (tmp.is_empty())
|
|
|
|
{
|
|
|
|
src_filter->get_wild_do_table(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_wild_do_table(tmp.ptr());
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_filter->get_wild_ignore_table(&tmp);
|
|
|
|
if (tmp.is_empty())
|
|
|
|
{
|
|
|
|
src_filter->get_wild_ignore_table(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_wild_ignore_table(tmp.ptr());
|
|
|
|
}
|
|
|
|
|
2022-08-09 13:50:12 +02:00
|
|
|
dst_filter->get_rewrite_db(&tmp);
|
|
|
|
if (tmp.is_empty())
|
2013-04-16 13:43:28 +02:00
|
|
|
{
|
2022-08-09 13:50:12 +02:00
|
|
|
src_filter->get_rewrite_db(&tmp);
|
|
|
|
if (!tmp.is_empty())
|
|
|
|
dst_filter->set_rewrite_db(tmp.ptr());
|
2013-04-16 13:43:28 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 01:06:56 +02:00
|
|
|
|
|
|
|
Master_info_index::Master_info_index()
|
|
|
|
{
|
2012-09-28 20:22:24 +02:00
|
|
|
size_t filename_length, dir_length;
|
|
|
|
/*
|
|
|
|
Create the Master_info index file by prepending 'multi-' before
|
|
|
|
the master_info_file file name.
|
|
|
|
*/
|
|
|
|
fn_format(index_file_name, master_info_file, mysql_data_home,
|
|
|
|
"", MY_UNPACK_FILENAME);
|
|
|
|
filename_length= strlen(index_file_name) + 1; /* Count 0 byte */
|
|
|
|
dir_length= dirname_length(index_file_name);
|
|
|
|
bmove_upp((uchar*) index_file_name + filename_length + 6,
|
|
|
|
(uchar*) index_file_name + filename_length,
|
|
|
|
filename_length - dir_length);
|
|
|
|
memcpy(index_file_name + dir_length, "multi-", 6);
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
bzero((char*) &index_file, sizeof(index_file));
|
2015-01-24 09:37:58 +01:00
|
|
|
index_file.file= -1;
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Free all connection threads
|
|
|
|
|
|
|
|
This is done during early stages of shutdown
|
|
|
|
to give connection threads and slave threads time
|
|
|
|
to die before ~Master_info_index is called
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Master_info_index::free_connections()
|
|
|
|
{
|
2017-01-29 22:44:24 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_active_mi);
|
2017-01-29 21:10:56 +01:00
|
|
|
my_hash_reset(&master_info_hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Free all connection threads and free structures
|
|
|
|
*/
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
Master_info_index::~Master_info_index()
|
|
|
|
{
|
|
|
|
my_hash_free(&master_info_hash);
|
|
|
|
end_io_cache(&index_file);
|
2015-01-24 09:37:58 +01:00
|
|
|
if (index_file.file >= 0)
|
2012-09-28 01:06:56 +02:00
|
|
|
my_close(index_file.file, MYF(MY_WME));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Load All Master_info from master.info.index File
|
|
|
|
* RETURN:
|
|
|
|
* 0 - All Success
|
|
|
|
* 1 - All Fail
|
|
|
|
* 2 - Some Success, Some Fail
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool Master_info_index::init_all_master_info()
|
|
|
|
{
|
|
|
|
int thread_mask;
|
|
|
|
int err_num= 0, succ_num= 0; // The number of success read Master_info
|
2013-05-03 00:50:42 +02:00
|
|
|
char sign[MAX_CONNECTION_NAME+1];
|
2012-09-28 01:06:56 +02:00
|
|
|
File index_file_nr;
|
2017-03-06 15:25:01 +01:00
|
|
|
THD *thd;
|
2012-09-28 01:06:56 +02:00
|
|
|
DBUG_ENTER("init_all_master_info");
|
|
|
|
|
2014-09-06 08:33:56 +02:00
|
|
|
DBUG_ASSERT(master_info_index);
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
if ((index_file_nr= my_open(index_file_name,
|
|
|
|
O_RDWR | O_CREAT | O_BINARY ,
|
2018-05-29 23:54:25 +02:00
|
|
|
MYF(MY_WME | ME_ERROR_LOG))) < 0 ||
|
2012-09-28 01:06:56 +02:00
|
|
|
my_sync(index_file_nr, MYF(MY_WME)) ||
|
|
|
|
init_io_cache(&index_file, index_file_nr,
|
|
|
|
IO_SIZE, READ_CACHE,
|
|
|
|
my_seek(index_file_nr,0L,MY_SEEK_END,MYF(0)),
|
|
|
|
0, MYF(MY_WME | MY_WAIT_IF_FULL)))
|
|
|
|
{
|
|
|
|
if (index_file_nr >= 0)
|
|
|
|
my_close(index_file_nr,MYF(0));
|
|
|
|
|
|
|
|
sql_print_error("Creation of Master_info index file '%s' failed",
|
|
|
|
index_file_name);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize Master_info Hash Table */
|
2020-02-27 11:52:20 +01:00
|
|
|
if (my_hash_init(PSI_INSTRUMENT_ME, &master_info_hash, system_charset_info,
|
2012-09-28 01:06:56 +02:00
|
|
|
MAX_REPLICATION_THREAD, 0, 0,
|
|
|
|
(my_hash_get_key) get_key_master_info,
|
2020-02-27 11:52:20 +01:00
|
|
|
(my_hash_free_key)free_key_master_info, HASH_UNIQUE))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
sql_print_error("Initializing Master_info hash table failed");
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
2017-03-30 12:48:42 +02:00
|
|
|
thd= new THD(next_thread_id()); /* Needed by start_slave_threads */
|
2017-03-06 15:25:01 +01:00
|
|
|
thd->thread_stack= (char*) &thd;
|
|
|
|
thd->store_globals();
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
reinit_io_cache(&index_file, READ_CACHE, 0L,0,0);
|
|
|
|
while (!init_strvar_from_file(sign, sizeof(sign),
|
|
|
|
&index_file, NULL))
|
|
|
|
{
|
2017-04-23 18:39:57 +02:00
|
|
|
LEX_CSTRING connection_name;
|
2012-09-28 01:06:56 +02:00
|
|
|
Master_info *mi;
|
|
|
|
char buf_master_info_file[FN_REFLEN];
|
|
|
|
char buf_relay_log_info_file[FN_REFLEN];
|
|
|
|
|
|
|
|
connection_name.str= sign;
|
|
|
|
connection_name.length= strlen(sign);
|
|
|
|
if (!(mi= new Master_info(&connection_name, relay_log_recovery)) ||
|
|
|
|
mi->error())
|
|
|
|
{
|
|
|
|
delete mi;
|
2017-03-06 15:25:01 +01:00
|
|
|
goto error;
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
|
|
|
|
|
2013-05-03 00:50:42 +02:00
|
|
|
create_logfile_name_with_suffix(buf_master_info_file,
|
|
|
|
sizeof(buf_master_info_file),
|
|
|
|
master_info_file, 0,
|
|
|
|
&mi->cmp_connection_name);
|
2012-10-03 00:44:54 +02:00
|
|
|
create_logfile_name_with_suffix(buf_relay_log_info_file,
|
2013-05-03 00:50:42 +02:00
|
|
|
sizeof(buf_relay_log_info_file),
|
|
|
|
relay_log_info_file, 0,
|
|
|
|
&mi->cmp_connection_name);
|
2012-09-28 01:06:56 +02:00
|
|
|
if (global_system_variables.log_warnings > 1)
|
|
|
|
sql_print_information("Reading Master_info: '%s' Relay_info:'%s'",
|
|
|
|
buf_master_info_file, buf_relay_log_info_file);
|
|
|
|
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->lock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
if (init_master_info(mi, buf_master_info_file, buf_relay_log_info_file,
|
|
|
|
0, thread_mask))
|
|
|
|
{
|
|
|
|
err_num++;
|
|
|
|
sql_print_error("Initialized Master_info from '%s' failed",
|
|
|
|
buf_master_info_file);
|
|
|
|
if (!master_info_index->get_master_info(&connection_name,
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_condition::WARN_LEVEL_NOTE))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
/* Master_info is not in HASH; Add it */
|
|
|
|
if (master_info_index->add_master_info(mi, FALSE))
|
2017-03-06 15:25:01 +01:00
|
|
|
goto error;
|
2012-09-28 01:06:56 +02:00
|
|
|
succ_num++;
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->unlock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Master_info already in HASH */
|
2015-07-06 19:24:14 +02:00
|
|
|
sql_print_error(ER_THD_OR_DEFAULT(current_thd,
|
|
|
|
ER_CONNECTION_ALREADY_EXISTS),
|
2017-02-10 21:39:22 +01:00
|
|
|
(int) connection_name.length, connection_name.str,
|
2012-09-28 01:06:56 +02:00
|
|
|
(int) connection_name.length, connection_name.str);
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->unlock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
delete mi;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-21 21:06:08 +01:00
|
|
|
/* Initialization of Master_info succeeded. Add it to HASH */
|
2012-09-28 01:06:56 +02:00
|
|
|
if (global_system_variables.log_warnings > 1)
|
|
|
|
sql_print_information("Initialized Master_info from '%s'",
|
|
|
|
buf_master_info_file);
|
|
|
|
if (master_info_index->get_master_info(&connection_name,
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_condition::WARN_LEVEL_NOTE))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
/* Master_info was already registered */
|
2015-07-06 19:24:14 +02:00
|
|
|
sql_print_error(ER_THD_OR_DEFAULT(current_thd,
|
|
|
|
ER_CONNECTION_ALREADY_EXISTS),
|
2017-02-10 21:39:22 +01:00
|
|
|
(int) connection_name.length, connection_name.str,
|
2012-09-28 01:06:56 +02:00
|
|
|
(int) connection_name.length, connection_name.str);
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->unlock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
delete mi;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Master_info was not registered; add it */
|
|
|
|
if (master_info_index->add_master_info(mi, FALSE))
|
2017-03-06 15:25:01 +01:00
|
|
|
goto error;
|
2012-09-28 01:06:56 +02:00
|
|
|
succ_num++;
|
|
|
|
|
|
|
|
if (!opt_skip_slave_start)
|
|
|
|
{
|
2015-07-15 15:27:14 +02:00
|
|
|
if (start_slave_threads(current_thd,
|
|
|
|
1 /* need mutex */,
|
2017-03-21 19:20:44 +01:00
|
|
|
1 /* wait for start*/,
|
2015-07-15 15:27:14 +02:00
|
|
|
mi,
|
|
|
|
buf_master_info_file,
|
|
|
|
buf_relay_log_info_file,
|
|
|
|
SLAVE_IO | SLAVE_SQL))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2012-10-03 00:44:54 +02:00
|
|
|
sql_print_error("Failed to create slave threads for connection '%.*s'",
|
2012-09-28 01:06:56 +02:00
|
|
|
(int) connection_name.length,
|
|
|
|
connection_name.str);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (global_system_variables.log_warnings)
|
|
|
|
sql_print_information("Started replication for '%.*s'",
|
|
|
|
(int) connection_name.length,
|
|
|
|
connection_name.str);
|
|
|
|
}
|
2017-01-29 22:44:24 +01:00
|
|
|
mi->unlock_slave_threads();
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-06 15:25:01 +01:00
|
|
|
thd->reset_globals();
|
|
|
|
delete thd;
|
2012-09-28 01:06:56 +02:00
|
|
|
|
|
|
|
if (!err_num) // No Error on read Master_info
|
|
|
|
{
|
2021-03-15 14:45:47 +01:00
|
|
|
if (global_system_variables.log_warnings > 2)
|
2019-05-30 08:41:57 +02:00
|
|
|
sql_print_information("Reading of all Master_info entries succeeded");
|
2012-09-28 01:06:56 +02:00
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
2021-03-15 14:45:47 +01:00
|
|
|
|
2017-03-06 15:25:01 +01:00
|
|
|
if (succ_num) // Have some Error and some Success
|
2012-09-28 01:06:56 +02:00
|
|
|
sql_print_warning("Reading of some Master_info entries failed");
|
2021-03-15 14:45:47 +01:00
|
|
|
else
|
|
|
|
sql_print_error("Reading of all Master_info entries failed!");
|
2017-03-06 15:25:01 +01:00
|
|
|
DBUG_RETURN(1);
|
|
|
|
|
|
|
|
error:
|
|
|
|
thd->reset_globals();
|
|
|
|
delete thd;
|
|
|
|
DBUG_RETURN(1);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Write new master.info to master.info.index File */
|
2017-04-23 18:39:57 +02:00
|
|
|
bool Master_info_index::write_master_name_to_index_file(LEX_CSTRING *name,
|
2012-09-28 01:06:56 +02:00
|
|
|
bool do_sync)
|
|
|
|
{
|
|
|
|
DBUG_ASSERT(my_b_inited(&index_file) != 0);
|
|
|
|
DBUG_ENTER("write_master_name_to_index_file");
|
|
|
|
|
|
|
|
/* Don't write default slave to master_info.index */
|
|
|
|
if (name->length == 0)
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
|
|
|
|
reinit_io_cache(&index_file, WRITE_CACHE,
|
|
|
|
my_b_filelength(&index_file), 0, 0);
|
|
|
|
|
|
|
|
if (my_b_write(&index_file, (uchar*) name->str, name->length) ||
|
|
|
|
my_b_write(&index_file, (uchar*) "\n", 1) ||
|
|
|
|
flush_io_cache(&index_file) ||
|
|
|
|
(do_sync && my_sync(index_file.file, MYF(MY_WME))))
|
|
|
|
{
|
|
|
|
sql_print_error("Write of new Master_info for '%.*s' to index file failed",
|
|
|
|
(int) name->length, name->str);
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
/**
|
|
|
|
Get Master_info for a connection and lock the object from deletion
|
|
|
|
|
|
|
|
@param
|
|
|
|
connection_name Connection name
|
|
|
|
warning WARN_LEVEL_NOTE -> Don't print anything
|
|
|
|
WARN_LEVEL_WARN -> Issue warning if not exists
|
|
|
|
WARN_LEVEL_ERROR-> Issue error if not exists
|
|
|
|
*/
|
|
|
|
|
2017-04-23 18:39:57 +02:00
|
|
|
Master_info *get_master_info(const LEX_CSTRING *connection_name,
|
2017-01-29 21:10:56 +01:00
|
|
|
Sql_condition::enum_warning_level warning)
|
|
|
|
{
|
|
|
|
Master_info *mi;
|
|
|
|
DBUG_ENTER("get_master_info");
|
|
|
|
|
|
|
|
/* Protect against inserts into hash */
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
|
|
|
/*
|
|
|
|
The following can only be true during shutdown when slave has been killed
|
|
|
|
but some other threads are still trying to access slave statistics.
|
|
|
|
*/
|
|
|
|
if (unlikely(!master_info_index))
|
|
|
|
{
|
|
|
|
if (warning != Sql_condition::WARN_LEVEL_NOTE)
|
|
|
|
my_error(WARN_NO_MASTER_INFO,
|
|
|
|
MYF(warning == Sql_condition::WARN_LEVEL_WARN ?
|
2018-05-29 23:54:25 +02:00
|
|
|
ME_WARNING : 0),
|
2017-01-29 21:10:56 +01:00
|
|
|
(int) connection_name->length, connection_name->str);
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
DBUG_RETURN(0);
|
|
|
|
}
|
|
|
|
if ((mi= master_info_index->get_master_info(connection_name, warning)))
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
We have to use sleep_lock here. If we would use LOCK_active_mi
|
|
|
|
then we would take locks in wrong order in Master_info::release()
|
|
|
|
*/
|
|
|
|
mysql_mutex_lock(&mi->sleep_lock);
|
|
|
|
mi->users++;
|
|
|
|
DBUG_PRINT("info",("users: %d", mi->users));
|
|
|
|
mysql_mutex_unlock(&mi->sleep_lock);
|
|
|
|
}
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
DBUG_RETURN(mi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Release master info.
|
|
|
|
Signals ~Master_info that it's now safe to delete it
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Master_info::release()
|
|
|
|
{
|
|
|
|
mysql_mutex_lock(&sleep_lock);
|
|
|
|
if (!--users && killed)
|
|
|
|
{
|
|
|
|
/* Signal ~Master_info that it's ok to now free it */
|
|
|
|
mysql_cond_signal(&sleep_cond);
|
|
|
|
}
|
|
|
|
mysql_mutex_unlock(&sleep_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
/**
|
|
|
|
Get Master_info for a connection
|
|
|
|
|
|
|
|
@param
|
|
|
|
connection_name Connection name
|
|
|
|
warning WARN_LEVEL_NOTE -> Don't print anything
|
|
|
|
WARN_LEVEL_WARN -> Issue warning if not exists
|
|
|
|
WARN_LEVEL_ERROR-> Issue error if not exists
|
|
|
|
*/
|
|
|
|
|
|
|
|
Master_info *
|
2017-04-23 18:39:57 +02:00
|
|
|
Master_info_index::get_master_info(const LEX_CSTRING *connection_name,
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_condition::enum_warning_level warning)
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
Master_info *mi;
|
2012-09-28 20:22:24 +02:00
|
|
|
DBUG_ENTER("get_master_info");
|
|
|
|
DBUG_PRINT("enter",
|
|
|
|
("connection_name: '%.*s'", (int) connection_name->length,
|
|
|
|
connection_name->str));
|
2012-09-28 01:06:56 +02:00
|
|
|
|
|
|
|
/* Make name lower case for comparison */
|
2023-08-26 12:39:18 +02:00
|
|
|
IdentBufferCasedn<MAX_CONNECTION_NAME> buff(*connection_name);
|
2012-09-28 01:06:56 +02:00
|
|
|
mi= (Master_info*) my_hash_search(&master_info_hash,
|
2023-08-26 12:39:18 +02:00
|
|
|
(const uchar*) buff.ptr(), buff.length());
|
2013-06-15 17:32:08 +02:00
|
|
|
if (!mi && warning != Sql_condition::WARN_LEVEL_NOTE)
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
my_error(WARN_NO_MASTER_INFO,
|
2018-05-29 23:54:25 +02:00
|
|
|
MYF(warning == Sql_condition::WARN_LEVEL_WARN ? ME_WARNING :
|
2012-09-28 01:06:56 +02:00
|
|
|
0),
|
|
|
|
(int) connection_name->length,
|
|
|
|
connection_name->str);
|
|
|
|
}
|
2012-09-28 20:22:24 +02:00
|
|
|
DBUG_RETURN(mi);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Check Master_host & Master_port is duplicated or not */
|
2017-04-23 18:39:57 +02:00
|
|
|
bool Master_info_index::check_duplicate_master_info(LEX_CSTRING *name_arg,
|
2012-09-28 01:06:56 +02:00
|
|
|
const char *host,
|
|
|
|
uint port)
|
|
|
|
{
|
|
|
|
Master_info *mi;
|
2012-09-28 20:22:24 +02:00
|
|
|
DBUG_ENTER("check_duplicate_master_info");
|
2012-09-28 01:06:56 +02:00
|
|
|
|
2014-09-06 08:33:56 +02:00
|
|
|
mysql_mutex_assert_owner(&LOCK_active_mi);
|
|
|
|
DBUG_ASSERT(master_info_index);
|
|
|
|
|
2012-09-28 01:06:56 +02:00
|
|
|
/* Get full host and port name */
|
|
|
|
if ((mi= master_info_index->get_master_info(name_arg,
|
2013-06-15 17:32:08 +02:00
|
|
|
Sql_condition::WARN_LEVEL_NOTE)))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
|
|
|
if (!host)
|
|
|
|
host= mi->host;
|
|
|
|
if (!port)
|
|
|
|
port= mi->port;
|
|
|
|
}
|
|
|
|
if (!host || !port)
|
2012-09-28 20:22:24 +02:00
|
|
|
DBUG_RETURN(FALSE); // Not comparable yet
|
2012-09-28 01:06:56 +02:00
|
|
|
|
|
|
|
for (uint i= 0; i < master_info_hash.records; ++i)
|
|
|
|
{
|
|
|
|
Master_info *tmp_mi;
|
|
|
|
tmp_mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
|
|
|
if (tmp_mi == mi)
|
|
|
|
continue; // Current connection
|
|
|
|
if (!strcasecmp(host, tmp_mi->host) && port == tmp_mi->port)
|
|
|
|
{
|
2012-09-28 20:22:24 +02:00
|
|
|
my_error(ER_CONNECTION_ALREADY_EXISTS, MYF(0),
|
|
|
|
(int) name_arg->length,
|
|
|
|
name_arg->str,
|
|
|
|
(int) tmp_mi->connection_name.length,
|
|
|
|
tmp_mi->connection_name.str);
|
|
|
|
DBUG_RETURN(TRUE);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-28 20:22:24 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Add a Master_info class to Hash Table */
|
|
|
|
bool Master_info_index::add_master_info(Master_info *mi, bool write_to_file)
|
|
|
|
{
|
2017-01-29 22:44:24 +01:00
|
|
|
/*
|
|
|
|
We have to protect against shutdown to ensure we are not calling
|
|
|
|
my_hash_insert() while my_hash_free() is in progress
|
|
|
|
*/
|
2019-01-25 11:24:35 +01:00
|
|
|
if (unlikely(abort_loop) ||
|
2017-01-29 22:44:24 +01:00
|
|
|
!my_hash_insert(&master_info_hash, (uchar*) mi))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2021-03-15 14:45:47 +01:00
|
|
|
if (global_system_variables.log_warnings > 2)
|
2012-09-28 01:06:56 +02:00
|
|
|
sql_print_information("Added new Master_info '%.*s' to hash table",
|
|
|
|
(int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
if (write_to_file)
|
|
|
|
return write_master_name_to_index_file(&mi->connection_name, 1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Impossible error (EOM) ? */
|
|
|
|
sql_print_error("Adding new entry '%.*s' to master_info failed",
|
|
|
|
(int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Remove a Master_info class From Hash Table
|
|
|
|
|
|
|
|
TODO: Change this to use my_rename() to make the file name creation
|
|
|
|
atomic
|
|
|
|
*/
|
|
|
|
|
2021-08-23 23:38:30 +02:00
|
|
|
bool Master_info_index::remove_master_info(Master_info *mi, bool clear_log_files)
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2021-08-23 23:38:30 +02:00
|
|
|
char tmp_name[FN_REFLEN];
|
2012-09-28 01:06:56 +02:00
|
|
|
DBUG_ENTER("remove_master_info");
|
2017-01-29 21:10:56 +01:00
|
|
|
mysql_mutex_assert_owner(&LOCK_active_mi);
|
2012-09-28 01:06:56 +02:00
|
|
|
|
2021-08-23 23:38:30 +02:00
|
|
|
if (clear_log_files)
|
|
|
|
{
|
|
|
|
/* This code is only executed when change_master() failes to create a new master info */
|
|
|
|
|
|
|
|
// Delete any temporary relay log files that could have been created by change_master()
|
|
|
|
mi->rli.relay_log.reset_logs(current_thd, 0, (rpl_gtid*) 0, 0, 0);
|
|
|
|
/* Delete master-'connection'.info */
|
|
|
|
create_logfile_name_with_suffix(tmp_name,
|
|
|
|
sizeof(tmp_name),
|
|
|
|
master_info_file, 0,
|
|
|
|
&mi->cmp_connection_name);
|
|
|
|
my_delete(tmp_name, MYF(0));
|
|
|
|
/* Delete relay-log-'connection'.info */
|
|
|
|
create_logfile_name_with_suffix(tmp_name,
|
|
|
|
sizeof(tmp_name),
|
|
|
|
relay_log_info_file, 0,
|
|
|
|
&mi->cmp_connection_name);
|
|
|
|
my_delete(tmp_name, MYF(0));
|
|
|
|
}
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
// Delete Master_info and rewrite others to file
|
|
|
|
if (!my_hash_delete(&master_info_hash, (uchar*) mi))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
File index_file_nr;
|
|
|
|
|
|
|
|
// Close IO_CACHE and FILE handler fisrt
|
|
|
|
end_io_cache(&index_file);
|
|
|
|
my_close(index_file.file, MYF(MY_WME));
|
|
|
|
|
|
|
|
// Reopen File and truncate it
|
|
|
|
if ((index_file_nr= my_open(index_file_name,
|
|
|
|
O_RDWR | O_CREAT | O_TRUNC | O_BINARY ,
|
|
|
|
MYF(MY_WME))) < 0 ||
|
|
|
|
init_io_cache(&index_file, index_file_nr,
|
|
|
|
IO_SIZE, WRITE_CACHE,
|
|
|
|
my_seek(index_file_nr,0L,MY_SEEK_END,MYF(0)),
|
|
|
|
0, MYF(MY_WME | MY_WAIT_IF_FULL)))
|
2012-09-28 01:06:56 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
int error= my_errno;
|
|
|
|
if (index_file_nr >= 0)
|
|
|
|
my_close(index_file_nr,MYF(0));
|
2012-09-28 01:06:56 +02:00
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
sql_print_error("Create of Master Info Index file '%s' failed with "
|
|
|
|
"error: %M",
|
|
|
|
index_file_name, error);
|
|
|
|
DBUG_RETURN(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite Master_info.index
|
|
|
|
for (uint i= 0; i< master_info_hash.records; ++i)
|
|
|
|
{
|
|
|
|
Master_info *tmp_mi;
|
|
|
|
tmp_mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
|
|
|
write_master_name_to_index_file(&tmp_mi->connection_name, 0);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
2017-01-29 21:10:56 +01:00
|
|
|
if (my_sync(index_file_nr, MYF(MY_WME)))
|
|
|
|
DBUG_RETURN(TRUE);
|
2012-09-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(FALSE);
|
|
|
|
}
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2012-10-03 00:44:54 +02:00
|
|
|
|
|
|
|
/**
|
2017-01-29 21:10:56 +01:00
|
|
|
give_error_if_slave_running()
|
|
|
|
|
|
|
|
@param
|
|
|
|
already_locked 0 if we need to lock, 1 if we have LOCK_active_mi_locked
|
2012-10-03 00:44:54 +02:00
|
|
|
|
|
|
|
@return
|
|
|
|
TRUE If some slave is running. An error is printed
|
|
|
|
FALSE No slave is running
|
|
|
|
*/
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
bool give_error_if_slave_running(bool already_locked)
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
bool ret= 0;
|
2015-03-11 09:18:16 +01:00
|
|
|
DBUG_ENTER("give_error_if_slave_running");
|
2012-10-03 00:44:54 +02:00
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
if (!already_locked)
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
|
|
|
if (!master_info_index)
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
my_error(ER_SERVER_SHUTDOWN, MYF(0));
|
|
|
|
ret= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HASH *hash= &master_info_index->master_info_hash;
|
|
|
|
for (uint i= 0; i< hash->records; ++i)
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *) my_hash_element(hash, i);
|
|
|
|
if (mi->rli.slave_running != MYSQL_SLAVE_NOT_RUN)
|
|
|
|
{
|
|
|
|
my_error(ER_SLAVE_MUST_STOP, MYF(0), (int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
ret= 1;
|
|
|
|
break;
|
|
|
|
}
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-29 21:10:56 +01:00
|
|
|
if (!already_locked)
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
DBUG_RETURN(ret);
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-11 09:18:16 +01:00
|
|
|
/**
|
2017-01-29 21:10:56 +01:00
|
|
|
any_slave_sql_running()
|
2015-03-11 09:18:16 +01:00
|
|
|
|
2017-04-23 10:49:58 +02:00
|
|
|
@param
|
|
|
|
already_locked 0 if we need to lock, 1 if we have LOCK_active_mi_locked
|
|
|
|
|
2015-03-11 09:18:16 +01:00
|
|
|
@return
|
2016-01-03 12:20:07 +01:00
|
|
|
0 No Slave SQL thread is running
|
|
|
|
# Number of slave SQL thread running
|
2017-01-29 22:44:24 +01:00
|
|
|
|
|
|
|
Note that during shutdown we return 1. This is needed to ensure we
|
|
|
|
don't try to resize thread pool during shutdown as during shutdown
|
|
|
|
master_info_hash may be freeing the hash and during that time
|
|
|
|
hash entries can't be accessed.
|
2015-03-11 09:18:16 +01:00
|
|
|
*/
|
|
|
|
|
2017-04-23 10:49:58 +02:00
|
|
|
uint any_slave_sql_running(bool already_locked)
|
2015-03-11 09:18:16 +01:00
|
|
|
{
|
2016-01-03 12:20:07 +01:00
|
|
|
uint count= 0;
|
2017-01-29 22:44:24 +01:00
|
|
|
HASH *hash;
|
2015-03-11 09:18:16 +01:00
|
|
|
DBUG_ENTER("any_slave_sql_running");
|
|
|
|
|
2017-04-23 10:49:58 +02:00
|
|
|
if (!already_locked)
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
2020-02-14 16:42:23 +01:00
|
|
|
else
|
|
|
|
mysql_mutex_assert_owner(&LOCK_active_mi);
|
2019-01-25 11:24:35 +01:00
|
|
|
if (unlikely(abort_loop || !master_info_index))
|
2017-04-23 10:49:58 +02:00
|
|
|
count= 1;
|
|
|
|
else
|
2015-03-11 09:18:16 +01:00
|
|
|
{
|
2017-04-23 10:49:58 +02:00
|
|
|
hash= &master_info_index->master_info_hash;
|
|
|
|
for (uint i= 0; i< hash->records; ++i)
|
|
|
|
{
|
|
|
|
Master_info *mi= (Master_info *)my_hash_element(hash, i);
|
|
|
|
if (mi->rli.slave_running != MYSQL_SLAVE_NOT_RUN)
|
|
|
|
count++;
|
|
|
|
}
|
2015-03-11 09:18:16 +01:00
|
|
|
}
|
2017-04-23 10:49:58 +02:00
|
|
|
if (!already_locked)
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
2016-01-03 12:20:07 +01:00
|
|
|
DBUG_RETURN(count);
|
2015-03-11 09:18:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-03 00:44:54 +02:00
|
|
|
/**
|
|
|
|
Master_info_index::start_all_slaves()
|
|
|
|
|
|
|
|
Start all slaves that was not running.
|
|
|
|
|
|
|
|
@return
|
|
|
|
TRUE Error
|
|
|
|
FALSE Everything ok.
|
2017-01-29 21:10:56 +01:00
|
|
|
|
|
|
|
This code is written so that we don't keep LOCK_active_mi active
|
|
|
|
while we are starting a slave.
|
2012-10-03 00:44:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Master_info_index::start_all_slaves(THD *thd)
|
|
|
|
{
|
|
|
|
bool result= FALSE;
|
2017-01-29 21:10:56 +01:00
|
|
|
DBUG_ENTER("start_all_slaves");
|
2012-10-03 00:44:54 +02:00
|
|
|
mysql_mutex_assert_owner(&LOCK_active_mi);
|
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
for (uint i= 0; i< master_info_hash.records; i++)
|
|
|
|
{
|
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
|
|
|
mi->in_start_all_slaves= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint i= 0; i< master_info_hash.records; )
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Try to start all slaves that are configured (host is defined)
|
|
|
|
and are not already running
|
|
|
|
*/
|
2017-01-29 21:10:56 +01:00
|
|
|
if (!((mi->slave_running == MYSQL_SLAVE_NOT_RUN ||
|
|
|
|
!mi->rli.slave_running) && *mi->host) ||
|
|
|
|
mi->in_start_all_slaves)
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
i++;
|
|
|
|
continue;
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
2017-01-29 21:10:56 +01:00
|
|
|
mi->in_start_all_slaves= 1;
|
|
|
|
|
|
|
|
mysql_mutex_lock(&mi->sleep_lock);
|
|
|
|
mi->users++; // Mark used
|
|
|
|
mysql_mutex_unlock(&mi->sleep_lock);
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
error= start_slave(thd, mi, 1);
|
|
|
|
mi->release();
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
2018-04-04 11:16:12 +02:00
|
|
|
if (unlikely(error))
|
2017-01-29 21:10:56 +01:00
|
|
|
{
|
|
|
|
my_error(ER_CANT_START_STOP_SLAVE, MYF(0),
|
|
|
|
"START",
|
|
|
|
(int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
result= 1;
|
|
|
|
if (error < 0) // fatal error
|
|
|
|
break;
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
2017-03-03 12:27:12 +01:00
|
|
|
else if (thd)
|
2017-01-29 21:10:56 +01:00
|
|
|
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
|
2017-03-03 12:27:12 +01:00
|
|
|
ER_SLAVE_STARTED, ER_THD(thd, ER_SLAVE_STARTED),
|
2017-01-29 21:10:56 +01:00
|
|
|
(int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
/* Restart from first element as master_info_hash may have changed */
|
|
|
|
i= 0;
|
|
|
|
continue;
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Master_info_index::stop_all_slaves()
|
|
|
|
|
|
|
|
Start all slaves that was not running.
|
|
|
|
|
2015-07-15 15:27:14 +02:00
|
|
|
@param thread id from user
|
|
|
|
|
2012-10-03 00:44:54 +02:00
|
|
|
@return
|
|
|
|
TRUE Error
|
|
|
|
FALSE Everything ok.
|
2017-01-29 21:10:56 +01:00
|
|
|
|
|
|
|
This code is written so that we don't keep LOCK_active_mi active
|
|
|
|
while we are stopping a slave.
|
2012-10-03 00:44:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
bool Master_info_index::stop_all_slaves(THD *thd)
|
|
|
|
{
|
|
|
|
bool result= FALSE;
|
2017-01-29 21:10:56 +01:00
|
|
|
DBUG_ENTER("stop_all_slaves");
|
2012-10-03 00:44:54 +02:00
|
|
|
mysql_mutex_assert_owner(&LOCK_active_mi);
|
2015-07-15 15:27:14 +02:00
|
|
|
DBUG_ASSERT(thd);
|
2012-10-03 00:44:54 +02:00
|
|
|
|
2017-01-29 21:10:56 +01:00
|
|
|
for (uint i= 0; i< master_info_hash.records; i++)
|
|
|
|
{
|
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
|
|
|
mi->in_stop_all_slaves= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint i= 0; i< master_info_hash.records ;)
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
2017-01-29 21:10:56 +01:00
|
|
|
if (!(mi->slave_running != MYSQL_SLAVE_NOT_RUN ||
|
|
|
|
mi->rli.slave_running) ||
|
|
|
|
mi->in_stop_all_slaves)
|
2012-10-03 00:44:54 +02:00
|
|
|
{
|
2017-01-29 21:10:56 +01:00
|
|
|
i++;
|
|
|
|
continue;
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
2017-01-29 21:10:56 +01:00
|
|
|
mi->in_stop_all_slaves= 1; // Protection for loops
|
|
|
|
|
|
|
|
mysql_mutex_lock(&mi->sleep_lock);
|
|
|
|
mi->users++; // Mark used
|
|
|
|
mysql_mutex_unlock(&mi->sleep_lock);
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
error= stop_slave(thd, mi, 1);
|
|
|
|
mi->release();
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
2018-04-04 11:16:12 +02:00
|
|
|
if (unlikely(error))
|
2017-01-29 21:10:56 +01:00
|
|
|
{
|
|
|
|
my_error(ER_CANT_START_STOP_SLAVE, MYF(0),
|
|
|
|
"STOP",
|
|
|
|
(int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
result= 1;
|
|
|
|
if (error < 0) // Fatal error
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
|
2017-03-03 12:27:12 +01:00
|
|
|
ER_SLAVE_STOPPED, ER_THD(thd, ER_SLAVE_STOPPED),
|
2017-01-29 21:10:56 +01:00
|
|
|
(int) mi->connection_name.length,
|
|
|
|
mi->connection_name.str);
|
|
|
|
/* Restart from first element as master_info_hash may have changed */
|
|
|
|
i= 0;
|
|
|
|
continue;
|
2012-10-03 00:44:54 +02:00
|
|
|
}
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
2006-10-31 16:51:51 +01:00
|
|
|
|
2014-12-04 04:30:48 +01:00
|
|
|
Domain_id_filter::Domain_id_filter() : m_filter(false)
|
|
|
|
{
|
|
|
|
for (int i= DO_DOMAIN_IDS; i <= IGNORE_DOMAIN_IDS; i ++)
|
|
|
|
{
|
2020-02-27 11:52:20 +01:00
|
|
|
my_init_dynamic_array(PSI_INSTRUMENT_ME, &m_domain_ids[i], sizeof(ulong),
|
|
|
|
16, 16, MYF(0));
|
2014-12-04 04:30:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Domain_id_filter::~Domain_id_filter()
|
|
|
|
{
|
|
|
|
for (int i= DO_DOMAIN_IDS; i <= IGNORE_DOMAIN_IDS; i ++)
|
|
|
|
{
|
|
|
|
delete_dynamic(&m_domain_ids[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update m_filter flag for the current group by looking up its domain id in the
|
|
|
|
domain ids list. DO_DOMAIN_IDS list is only looked-up is both (do & ignore)
|
|
|
|
list are non-empty.
|
|
|
|
*/
|
|
|
|
void Domain_id_filter::do_filter(ulong domain_id)
|
|
|
|
{
|
|
|
|
DYNAMIC_ARRAY *do_domain_ids= &m_domain_ids[DO_DOMAIN_IDS];
|
|
|
|
DYNAMIC_ARRAY *ignore_domain_ids= &m_domain_ids[IGNORE_DOMAIN_IDS];
|
|
|
|
|
|
|
|
if (do_domain_ids->elements > 0)
|
|
|
|
{
|
|
|
|
if (likely(do_domain_ids->elements == 1))
|
|
|
|
m_filter= ((* (ulong *) dynamic_array_ptr(do_domain_ids, 0))
|
|
|
|
!= domain_id);
|
|
|
|
else
|
|
|
|
m_filter= (bsearch((const ulong *) &domain_id, do_domain_ids->buffer,
|
|
|
|
do_domain_ids->elements, sizeof(ulong),
|
|
|
|
change_master_id_cmp) == NULL);
|
|
|
|
}
|
|
|
|
else if (ignore_domain_ids->elements > 0)
|
|
|
|
{
|
|
|
|
if (likely(ignore_domain_ids->elements == 1))
|
|
|
|
m_filter= ((* (ulong *) dynamic_array_ptr(ignore_domain_ids, 0)) ==
|
|
|
|
domain_id);
|
|
|
|
else
|
|
|
|
m_filter= (bsearch((const ulong *) &domain_id, ignore_domain_ids->buffer,
|
|
|
|
ignore_domain_ids->elements, sizeof(ulong),
|
|
|
|
change_master_id_cmp) != NULL);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Reset m_filter. It should be called when IO thread receives COMMIT_EVENT or
|
|
|
|
XID_EVENT.
|
|
|
|
*/
|
|
|
|
void Domain_id_filter::reset_filter()
|
|
|
|
{
|
|
|
|
m_filter= false;
|
|
|
|
}
|
|
|
|
|
MDEV-25284: Assertion `info->type == READ_CACHE || info->type == WRITE_CACHE' failed
Problem:
========
This patch addresses two issues.
First, if a CHANGE MASTER command is issued and an error happens
while locating the replica’s relay logs, the logs can be put into an
invalid state where future updates fail and future CHANGE MASTER
calls crash the server. More specifically, right before a replica
purges the relay logs (part of the `CHANGE MASTER TO` logic), the
relay log is temporarily closed with state LOG_TO_BE_OPENED. If the
server errors in-between the temporary log closure and purge, i.e.
during the function find_log_pos, the log should be closed.
MDEV-25284 reveals the log is not properly closed.
Second, upon issuing a RESET SLAVE ALL command, a slave’s GTID
filters are not cleared (DO_DOMAIN_IDS, IGNORE_DOMIAN_IDS,
IGNORE_SERVER_IDS). MySQL had a similar bug report, Bug #18816897,
which fixed this issue to clear IGNORE_SERVER_IDS after issuing
RESET SLAVE ALL in version 5.7.
Solution:
=========
To fix the first problem, the CHANGE MASTER error handling logic was
extended to transition the relay log state to LOG_CLOSED from
LOG_TO_BE_OPENED.
To fix the second problem, the RESET SLAVE ALL logic is extended to
clear the domain_id filter and ignore_server_ids.
Reviewed By:
============
Andrei Elkin <andrei.elkin@mariadb.com>
2021-10-13 15:31:32 +02:00
|
|
|
void Domain_id_filter::clear_ids()
|
|
|
|
{
|
|
|
|
reset_dynamic(&m_domain_ids[DO_DOMAIN_IDS]);
|
|
|
|
reset_dynamic(&m_domain_ids[IGNORE_DOMAIN_IDS]);
|
2014-12-04 04:30:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Update the do/ignore domain id filter lists.
|
|
|
|
|
|
|
|
@param do_ids [IN] domain ids to be kept
|
|
|
|
@param ignore_ids [IN] domain ids to be filtered out
|
|
|
|
@param using_gtid [IN] use GTID?
|
|
|
|
|
|
|
|
@retval false Success
|
|
|
|
true Error
|
|
|
|
*/
|
|
|
|
bool Domain_id_filter::update_ids(DYNAMIC_ARRAY *do_ids,
|
|
|
|
DYNAMIC_ARRAY *ignore_ids,
|
|
|
|
bool using_gtid)
|
|
|
|
{
|
|
|
|
bool do_list_empty, ignore_list_empty;
|
|
|
|
|
|
|
|
if (do_ids)
|
|
|
|
{
|
|
|
|
do_list_empty= (do_ids->elements > 0) ? false : true;
|
|
|
|
} else {
|
|
|
|
do_list_empty= (m_domain_ids[DO_DOMAIN_IDS].elements > 0) ? false : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ignore_ids)
|
|
|
|
{
|
|
|
|
ignore_list_empty= (ignore_ids->elements > 0) ? false : true;
|
|
|
|
} else {
|
|
|
|
ignore_list_empty= (m_domain_ids[IGNORE_DOMAIN_IDS].elements > 0) ? false :
|
|
|
|
true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!do_list_empty && !ignore_list_empty)
|
|
|
|
{
|
|
|
|
sql_print_error("Both DO_DOMAIN_IDS & IGNORE_DOMAIN_IDS lists can't be "
|
|
|
|
"non-empty at the same time");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (using_gtid == Master_info::USE_GTID_NO &&
|
|
|
|
(!do_list_empty || !ignore_list_empty))
|
|
|
|
{
|
|
|
|
sql_print_error("DO_DOMAIN_IDS or IGNORE_DOMAIN_IDS lists can't be "
|
|
|
|
"non-empty in non-GTID mode (MASTER_USE_GTID=no)");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_ids)
|
|
|
|
update_change_master_ids(do_ids, &m_domain_ids[DO_DOMAIN_IDS]);
|
|
|
|
|
|
|
|
if (ignore_ids)
|
|
|
|
update_change_master_ids(ignore_ids, &m_domain_ids[IGNORE_DOMAIN_IDS]);
|
|
|
|
|
|
|
|
m_filter= false;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Serialize and store the ids from domain id lists into the thd's protocol
|
|
|
|
buffer.
|
|
|
|
|
|
|
|
@param thd [IN] thread handler
|
|
|
|
|
|
|
|
@retval void
|
|
|
|
*/
|
|
|
|
void Domain_id_filter::store_ids(THD *thd)
|
|
|
|
{
|
|
|
|
for (int i= DO_DOMAIN_IDS; i <= IGNORE_DOMAIN_IDS; i ++)
|
|
|
|
{
|
|
|
|
prot_store_ids(thd, &m_domain_ids[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize the given domain_id list (DYNAMIC_ARRAY) with the
|
|
|
|
space-separated list of numbers from the specified IO_CACHE where
|
|
|
|
the first number represents the total number of entries to follows.
|
|
|
|
|
|
|
|
@param f [IN] IO_CACHE file
|
|
|
|
@param type [IN] domain id list type
|
|
|
|
|
|
|
|
@retval false Success
|
|
|
|
true Error
|
|
|
|
*/
|
|
|
|
bool Domain_id_filter::init_ids(IO_CACHE *f, enum_list_type type)
|
|
|
|
{
|
|
|
|
return init_dynarray_intvar_from_file(&m_domain_ids[type], f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the elements of the give domain id list type as string.
|
|
|
|
|
|
|
|
@param type [IN] domain id list type
|
|
|
|
|
|
|
|
@retval a string buffer storing the total number
|
|
|
|
of elements followed by the individual
|
|
|
|
elements (space-separated) in the
|
|
|
|
specified list.
|
|
|
|
|
|
|
|
Note: Its caller's responsibility to free the returned string buffer.
|
|
|
|
*/
|
|
|
|
char *Domain_id_filter::as_string(enum_list_type type)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
size_t sz;
|
|
|
|
DYNAMIC_ARRAY *ids= &m_domain_ids[type];
|
|
|
|
|
|
|
|
sz= (sizeof(ulong) * 3 + 1) * (1 + ids->elements);
|
|
|
|
|
2020-01-29 13:50:26 +01:00
|
|
|
if (!(buf= (char *) my_malloc(PSI_INSTRUMENT_ME, sz, MYF(MY_WME))))
|
2014-12-04 04:30:48 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Store the total number of elements followed by the individual elements.
|
2021-09-03 06:38:54 +02:00
|
|
|
size_t cur_len= sprintf(buf, "%zu", ids->elements);
|
2014-12-04 04:30:48 +01:00
|
|
|
sz-= cur_len;
|
|
|
|
|
|
|
|
for (uint i= 0; i < ids->elements; i++)
|
|
|
|
{
|
|
|
|
ulong domain_id;
|
|
|
|
get_dynamic(ids, (void *) &domain_id, i);
|
2017-04-23 18:39:57 +02:00
|
|
|
cur_len+= my_snprintf(buf + cur_len, sz, " %lu", domain_id);
|
2014-12-04 04:30:48 +01:00
|
|
|
sz-= cur_len;
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_change_master_ids(DYNAMIC_ARRAY *new_ids, DYNAMIC_ARRAY *old_ids)
|
|
|
|
{
|
|
|
|
reset_dynamic(old_ids);
|
|
|
|
|
|
|
|
/* bsearch requires an ordered list. */
|
|
|
|
sort_dynamic(new_ids, change_master_id_cmp);
|
|
|
|
|
|
|
|
for (uint i= 0; i < new_ids->elements; i++)
|
|
|
|
{
|
|
|
|
ulong id;
|
|
|
|
get_dynamic(new_ids, (void *) &id, i);
|
|
|
|
|
|
|
|
if (bsearch((const ulong *) &id, old_ids->buffer, old_ids->elements,
|
|
|
|
sizeof(ulong), change_master_id_cmp) == NULL)
|
|
|
|
{
|
|
|
|
insert_dynamic(old_ids, (ulong *) &id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Serialize and store the ids from the given ids DYNAMIC_ARRAY into the thd's
|
|
|
|
protocol buffer.
|
|
|
|
|
|
|
|
@param thd [IN] thread handler
|
|
|
|
@param ids [IN] ids list
|
|
|
|
|
|
|
|
@retval void
|
|
|
|
*/
|
|
|
|
|
|
|
|
void prot_store_ids(THD *thd, DYNAMIC_ARRAY *ids)
|
|
|
|
{
|
|
|
|
char buff[FN_REFLEN];
|
|
|
|
uint i, cur_len;
|
|
|
|
|
|
|
|
for (i= 0, buff[0]= 0, cur_len= 0; i < ids->elements; i++)
|
|
|
|
{
|
|
|
|
ulong id, len;
|
|
|
|
char dbuff[FN_REFLEN];
|
|
|
|
get_dynamic(ids, (void *) &id, i);
|
|
|
|
len= sprintf(dbuff, (i == 0 ? "%lu" : ", %lu"), id);
|
|
|
|
if (cur_len + len + 4 > FN_REFLEN)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
break the loop whenever remained space could not fit
|
|
|
|
ellipses on the next cycle
|
|
|
|
*/
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
cur_len+= sprintf(dbuff + cur_len, "...");
|
2014-12-04 04:30:48 +01:00
|
|
|
break;
|
|
|
|
}
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
cur_len+= sprintf(buff + cur_len, "%s", dbuff);
|
2014-12-04 04:30:48 +01:00
|
|
|
}
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
thd->protocol->store(buff, cur_len, &my_charset_bin);
|
2014-12-04 04:30:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2020-08-12 19:29:55 +02:00
|
|
|
|
2017-06-05 09:40:24 +02:00
|
|
|
bool Master_info_index::flush_all_relay_logs()
|
|
|
|
{
|
|
|
|
DBUG_ENTER("flush_all_relay_logs");
|
|
|
|
bool result= false;
|
|
|
|
int error= 0;
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
|
|
|
for (uint i= 0; i< master_info_hash.records; i++)
|
|
|
|
{
|
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *) my_hash_element(&master_info_hash, i);
|
|
|
|
mi->in_flush_all_relay_logs= 0;
|
|
|
|
}
|
|
|
|
for (uint i=0; i < master_info_hash.records;)
|
|
|
|
{
|
|
|
|
Master_info *mi;
|
|
|
|
mi= (Master_info *)my_hash_element(&master_info_hash, i);
|
|
|
|
DBUG_ASSERT(mi);
|
|
|
|
|
|
|
|
if (mi->in_flush_all_relay_logs)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mi->in_flush_all_relay_logs= 1;
|
|
|
|
|
|
|
|
mysql_mutex_lock(&mi->sleep_lock);
|
|
|
|
mi->users++; // Mark used
|
|
|
|
mysql_mutex_unlock(&mi->sleep_lock);
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
|
|
|
|
mysql_mutex_lock(&mi->data_lock);
|
|
|
|
error= rotate_relay_log(mi);
|
|
|
|
mysql_mutex_unlock(&mi->data_lock);
|
|
|
|
mi->release();
|
|
|
|
mysql_mutex_lock(&LOCK_active_mi);
|
|
|
|
|
2018-04-04 11:16:12 +02:00
|
|
|
if (unlikely(error))
|
2017-06-05 09:40:24 +02:00
|
|
|
{
|
|
|
|
result= true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Restart from first element as master_info_hash may have changed */
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mysql_mutex_unlock(&LOCK_active_mi);
|
|
|
|
DBUG_RETURN(result);
|
|
|
|
}
|
|
|
|
|
2006-10-31 16:51:51 +01:00
|
|
|
#endif /* HAVE_REPLICATION */
|