2011-06-30 17:37:13 +02:00
|
|
|
/*
|
2012-01-13 15:50:02 +01:00
|
|
|
Copyright (c) 2001, 2011, Oracle and/or its affiliates.
|
2001-10-10 04:56:24 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-10-10 04:56:24 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
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 */
|
2001-10-10 04:56:24 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
|
|
|
@file
|
|
|
|
|
|
|
|
All of the functions defined in this file which are not used (the ones to
|
|
|
|
handle failsafe) are not used; their code has not been updated for more
|
|
|
|
than one year now so should be considered as BADLY BROKEN. Do not enable
|
|
|
|
it. The used functions (to handle LOAD DATA FROM MASTER, plus some small
|
|
|
|
functions like register_slave()) are working.
|
|
|
|
*/
|
|
|
|
|
2017-06-18 05:42:16 +02:00
|
|
|
#include "mariadb.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_priv.h"
|
|
|
|
#include "sql_parse.h" // check_access
|
2003-01-15 09:11:44 +01:00
|
|
|
#ifdef HAVE_REPLICATION
|
|
|
|
|
2001-10-10 04:56:24 +02:00
|
|
|
#include "repl_failsafe.h"
|
2010-03-31 16:05:33 +02:00
|
|
|
#include "sql_acl.h" // REPL_SLAVE_ACL
|
2001-10-23 21:28:03 +02:00
|
|
|
#include "sql_repl.h"
|
|
|
|
#include "slave.h"
|
2007-04-12 08:58:04 +02:00
|
|
|
#include "rpl_mi.h"
|
2005-03-21 22:09:42 +01:00
|
|
|
#include "rpl_filter.h"
|
2001-11-11 06:24:12 +01:00
|
|
|
#include "log_event.h"
|
2001-10-23 21:28:03 +02:00
|
|
|
#include <mysql.h>
|
2001-11-11 06:24:12 +01:00
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
|
|
|
|
struct Slave_info
|
|
|
|
{
|
|
|
|
uint32 server_id;
|
|
|
|
uint32 master_id;
|
|
|
|
char host[HOSTNAME_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1];
|
|
|
|
char user[USERNAME_LENGTH+1];
|
|
|
|
char password[MAX_PASSWORD_LENGTH*SYSTEM_CHARSET_MBMAXLEN+1];
|
|
|
|
uint16 port;
|
|
|
|
};
|
2001-11-11 06:24:12 +01:00
|
|
|
|
2001-10-10 04:56:24 +02:00
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
Atomic_counter<uint32_t> binlog_dump_thread_count;
|
2010-10-11 16:50:14 +02:00
|
|
|
ulong rpl_status=RPL_NULL;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_t LOCK_rpl_status;
|
2001-10-10 04:56:24 +02:00
|
|
|
|
2001-10-10 23:36:35 +02:00
|
|
|
const char *rpl_role_type[] = {"MASTER","SLAVE",NullS};
|
|
|
|
TYPELIB rpl_role_typelib = {array_elements(rpl_role_type)-1,"",
|
2004-10-25 14:51:26 +02:00
|
|
|
rpl_role_type, NULL};
|
2001-10-10 04:56:24 +02:00
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
const char* rpl_status_type[]=
|
|
|
|
{
|
2009-12-22 10:35:56 +01:00
|
|
|
"AUTH_MASTER","IDLE_SLAVE","ACTIVE_SLAVE","LOST_SOLDIER","TROOP_SOLDIER",
|
2002-06-11 10:20:31 +02:00
|
|
|
"RECOVERY_CAPTAIN","NULL",NullS
|
|
|
|
};
|
|
|
|
|
2003-12-04 22:42:18 +01:00
|
|
|
/*
|
|
|
|
All of the functions defined in this file which are not used (the ones to
|
|
|
|
handle failsafe) are not used; their code has not been updated for more than
|
|
|
|
one year now so should be considered as BADLY BROKEN. Do not enable it.
|
|
|
|
The used functions (to handle LOAD DATA FROM MASTER, plus some small
|
|
|
|
functions like register_slave()) are working.
|
|
|
|
*/
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2010-10-11 16:50:14 +02:00
|
|
|
void change_rpl_status(ulong from_status, ulong to_status)
|
2001-10-11 21:54:06 +02:00
|
|
|
{
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_lock(&LOCK_rpl_status);
|
2001-10-11 21:54:06 +02:00
|
|
|
if (rpl_status == from_status || rpl_status == RPL_ANY)
|
|
|
|
rpl_status = to_status;
|
2010-01-07 06:42:07 +01:00
|
|
|
mysql_mutex_unlock(&LOCK_rpl_status);
|
2001-10-23 21:28:03 +02:00
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2008-01-31 15:51:20 +01:00
|
|
|
#define get_object(p, obj, msg) \
|
2001-11-11 06:24:12 +01:00
|
|
|
{\
|
|
|
|
uint len = (uint)*p++; \
|
|
|
|
if (p + len > p_end || len >= sizeof(obj)) \
|
2008-01-31 15:51:20 +01:00
|
|
|
{\
|
|
|
|
errmsg= msg;\
|
2001-11-11 06:24:12 +01:00
|
|
|
goto err; \
|
2008-01-31 15:51:20 +01:00
|
|
|
}\
|
2019-03-01 21:41:33 +01:00
|
|
|
::strmake(obj, (char*) p, len); \
|
2001-11-11 06:24:12 +01:00
|
|
|
p+= len; \
|
|
|
|
}\
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
void THD::unregister_slave()
|
2001-11-11 06:24:12 +01:00
|
|
|
{
|
2019-03-01 21:41:33 +01:00
|
|
|
if (auto old_si= slave_info)
|
2001-11-11 06:24:12 +01:00
|
|
|
{
|
2019-03-01 21:41:33 +01:00
|
|
|
mysql_mutex_lock(&LOCK_thd_data);
|
|
|
|
slave_info= 0;
|
|
|
|
mysql_mutex_unlock(&LOCK_thd_data);
|
2020-01-29 13:50:26 +01:00
|
|
|
my_free(old_si);
|
2019-03-01 21:41:33 +01:00
|
|
|
binlog_dump_thread_count--;
|
2001-11-11 06:24:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-11 10:20:31 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
/**
|
2019-03-01 21:41:33 +01:00
|
|
|
Register slave
|
2002-08-21 21:04:22 +02:00
|
|
|
|
2007-10-11 20:37:45 +02:00
|
|
|
@return
|
|
|
|
0 ok
|
|
|
|
@return
|
|
|
|
1 Error. Error message sent to client
|
2002-08-21 21:04:22 +02:00
|
|
|
*/
|
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
int THD::register_slave(uchar *packet, size_t packet_length)
|
2001-11-11 06:24:12 +01:00
|
|
|
{
|
2019-03-01 21:41:33 +01:00
|
|
|
Slave_info *si;
|
2002-08-21 21:04:22 +02:00
|
|
|
uchar *p= packet, *p_end= packet + packet_length;
|
2008-01-31 15:51:20 +01:00
|
|
|
const char *errmsg= "Wrong parameters to function register_slave";
|
2001-11-11 06:24:12 +01:00
|
|
|
|
2021-04-12 11:24:02 +02:00
|
|
|
if (check_access(this, PRIV_COM_REGISTER_SLAVE, any_db.str, NULL,NULL,0,0))
|
2019-03-01 21:41:33 +01:00
|
|
|
return 1;
|
2020-01-29 13:50:26 +01:00
|
|
|
if (!(si= (Slave_info*)my_malloc(key_memory_SLAVE_INFO, sizeof(Slave_info),
|
|
|
|
MYF(MY_WME))))
|
2001-11-11 06:24:12 +01:00
|
|
|
return 1;
|
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
variables.server_id= si->server_id= uint4korr(p);
|
2002-08-21 21:04:22 +02:00
|
|
|
p+= 4;
|
2008-01-31 15:51:20 +01:00
|
|
|
get_object(p,si->host, "Failed to register slave: too long 'report-host'");
|
|
|
|
get_object(p,si->user, "Failed to register slave: too long 'report-user'");
|
|
|
|
get_object(p,si->password, "Failed to register slave; too long 'report-password'");
|
BUG#49259: Slave I/O thread could not register on master
The slave thread changed the format of the information it used to
connect to the master after patch for BUG 13963. This resulted
in old master getting confused, thence rejecting the slave
connection attempt.
In particular, patch for BUG 13963 removed the rpl_recovery_rank
variable which was, at that time, packed together with the rest
of the information which the slave would use to register itself
on the master. Based on this data, the master would then assert
that the number of bytes received in the connection command was
consistent to what it was expecting.
Therefore, given that a slave, patched with the aforementioned
patch, would not pack the four bytes related to the
rpl_recovery_rank variable, the old master would reject the
connection attempt. It would assume that the data was
inconsistent (fewer bytes than it was expecting) and return
an error.
We fix this by faking an rpl_recovery_rank variable when
registering the slave on the master. In practice this reverts a
small part of patch for BUG 13963, the one related to the slave
connecting to the master.
sql/repl_failsafe.cc:
Added bypassing of removed rpl_recovery_rank variable information in
packet. This should also make more sense when old servers connect
to a new master (ie, master with patch for BUG 13963). If this was not
done, the new master could interpert information an old slave sends as
master_id, when in fact it could be the rpl_recovery_rank data.
sql/slave.cc:
Faking a rpl_recovery_rank so that we can register as a slave in
an old master.
2009-12-18 03:54:54 +01:00
|
|
|
if (p+10 > p_end)
|
2002-08-21 21:04:22 +02:00
|
|
|
goto err;
|
|
|
|
si->port= uint2korr(p);
|
2001-11-11 06:24:12 +01:00
|
|
|
p += 2;
|
BUG#49259: Slave I/O thread could not register on master
The slave thread changed the format of the information it used to
connect to the master after patch for BUG 13963. This resulted
in old master getting confused, thence rejecting the slave
connection attempt.
In particular, patch for BUG 13963 removed the rpl_recovery_rank
variable which was, at that time, packed together with the rest
of the information which the slave would use to register itself
on the master. Based on this data, the master would then assert
that the number of bytes received in the connection command was
consistent to what it was expecting.
Therefore, given that a slave, patched with the aforementioned
patch, would not pack the four bytes related to the
rpl_recovery_rank variable, the old master would reject the
connection attempt. It would assume that the data was
inconsistent (fewer bytes than it was expecting) and return
an error.
We fix this by faking an rpl_recovery_rank variable when
registering the slave on the master. In practice this reverts a
small part of patch for BUG 13963, the one related to the slave
connecting to the master.
sql/repl_failsafe.cc:
Added bypassing of removed rpl_recovery_rank variable information in
packet. This should also make more sense when old servers connect
to a new master (ie, master with patch for BUG 13963). If this was not
done, the new master could interpert information an old slave sends as
master_id, when in fact it could be the rpl_recovery_rank data.
sql/slave.cc:
Faking a rpl_recovery_rank so that we can register as a slave in
an old master.
2009-12-18 03:54:54 +01:00
|
|
|
/*
|
|
|
|
We need to by pass the bytes used in the fake rpl_recovery_rank
|
|
|
|
variable. It was removed in patch for BUG#13963. But this would
|
|
|
|
make a server with that patch unable to connect to an old master.
|
|
|
|
See: BUG#49259
|
|
|
|
*/
|
|
|
|
// si->rpl_recovery_rank= uint4korr(p);
|
|
|
|
p += 4;
|
2002-08-21 21:04:22 +02:00
|
|
|
if (!(si->master_id= uint4korr(p)))
|
2012-10-23 12:46:29 +02:00
|
|
|
si->master_id= global_system_variables.server_id;
|
2001-11-11 06:24:12 +01:00
|
|
|
|
2019-07-04 11:59:18 +02:00
|
|
|
if (!*si->host)
|
|
|
|
::strmake(si->host, main_security_ctx.host_or_ip, sizeof(si->host));
|
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
unregister_slave();
|
|
|
|
mysql_mutex_lock(&LOCK_thd_data);
|
|
|
|
slave_info= si;
|
|
|
|
mysql_mutex_unlock(&LOCK_thd_data);
|
2019-03-07 05:12:26 +01:00
|
|
|
binlog_dump_thread_count++;
|
2019-03-01 21:41:33 +01:00
|
|
|
return 0;
|
2001-11-11 06:24:12 +01:00
|
|
|
|
|
|
|
err:
|
2024-06-18 14:12:57 +02:00
|
|
|
my_free(si);
|
2008-03-18 13:38:12 +01:00
|
|
|
my_message(ER_UNKNOWN_ERROR, errmsg, MYF(0)); /* purecov: inspected */
|
2002-08-21 21:04:22 +02:00
|
|
|
return 1;
|
2001-11-11 06:24:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-07 05:12:26 +01:00
|
|
|
bool THD::is_binlog_dump_thread()
|
|
|
|
{
|
|
|
|
mysql_mutex_lock(&LOCK_thd_data);
|
|
|
|
bool res= slave_info != NULL;
|
|
|
|
mysql_mutex_unlock(&LOCK_thd_data);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
static my_bool show_slave_hosts_callback(THD *thd, Protocol *protocol)
|
2001-11-11 06:24:12 +01:00
|
|
|
{
|
2019-03-01 21:41:33 +01:00
|
|
|
my_bool res= FALSE;
|
|
|
|
mysql_mutex_lock(&thd->LOCK_thd_data);
|
|
|
|
if (auto si= thd->slave_info)
|
2001-12-20 05:14:11 +01:00
|
|
|
{
|
2019-03-01 21:41:33 +01:00
|
|
|
protocol->prepare_for_resend();
|
|
|
|
protocol->store(si->server_id);
|
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
|
|
|
protocol->store(si->host, strlen(si->host), &my_charset_bin);
|
2019-03-01 21:41:33 +01:00
|
|
|
if (opt_show_slave_auth_info)
|
|
|
|
{
|
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
|
|
|
protocol->store(si->user, safe_strlen(si->user), &my_charset_bin);
|
|
|
|
protocol->store(si->password, safe_strlen(si->password), &my_charset_bin);
|
2019-03-01 21:41:33 +01:00
|
|
|
}
|
|
|
|
protocol->store((uint32) si->port);
|
|
|
|
protocol->store(si->master_id);
|
|
|
|
res= protocol->write();
|
2001-12-20 05:14:11 +01:00
|
|
|
}
|
2019-03-01 21:41:33 +01:00
|
|
|
mysql_mutex_unlock(&thd->LOCK_thd_data);
|
|
|
|
return res;
|
2001-11-11 06:24:12 +01:00
|
|
|
}
|
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
|
2009-01-09 13:49:24 +01:00
|
|
|
/**
|
|
|
|
Execute a SHOW SLAVE HOSTS statement.
|
|
|
|
|
|
|
|
@param thd Pointer to THD object for the client thread executing the
|
|
|
|
statement.
|
|
|
|
|
|
|
|
@retval FALSE success
|
|
|
|
@retval TRUE failure
|
|
|
|
*/
|
2004-10-20 03:04:37 +02:00
|
|
|
bool show_slave_hosts(THD* thd)
|
2001-11-11 06:24:12 +01:00
|
|
|
{
|
|
|
|
List<Item> field_list;
|
2002-12-11 08:17:51 +01:00
|
|
|
Protocol *protocol= thd->protocol;
|
2015-08-20 14:24:13 +02:00
|
|
|
MEM_ROOT *mem_root= thd->mem_root;
|
2001-11-11 06:24:12 +01:00
|
|
|
DBUG_ENTER("show_slave_hosts");
|
|
|
|
|
2015-08-24 13:42:07 +02:00
|
|
|
field_list.push_back(new (mem_root)
|
|
|
|
Item_return_int(thd, "Server_id", 10,
|
|
|
|
MYSQL_TYPE_LONG),
|
|
|
|
thd->mem_root);
|
|
|
|
field_list.push_back(new (mem_root)
|
|
|
|
Item_empty_string(thd, "Host", 20),
|
|
|
|
thd->mem_root);
|
2001-11-11 06:24:12 +01:00
|
|
|
if (opt_show_slave_auth_info)
|
|
|
|
{
|
2015-08-24 13:42:07 +02:00
|
|
|
field_list.push_back(new (mem_root) Item_empty_string(thd, "User", 20),
|
|
|
|
thd->mem_root);
|
|
|
|
field_list.push_back(new (mem_root) Item_empty_string(thd, "Password", 20),
|
|
|
|
thd->mem_root);
|
2001-11-11 06:24:12 +01:00
|
|
|
}
|
2015-08-24 13:42:07 +02:00
|
|
|
field_list.push_back(new (mem_root)
|
|
|
|
Item_return_int(thd, "Port", 7, MYSQL_TYPE_LONG),
|
|
|
|
thd->mem_root);
|
|
|
|
field_list.push_back(new (mem_root)
|
|
|
|
Item_return_int(thd, "Master_id", 10, MYSQL_TYPE_LONG),
|
|
|
|
thd->mem_root);
|
2001-11-11 06:24:12 +01:00
|
|
|
|
Backport of revno 2630.28.10, 2630.28.31, 2630.28.26, 2630.33.1,
2630.39.1, 2630.28.29, 2630.34.3, 2630.34.2, 2630.34.1, 2630.29.29,
2630.29.28, 2630.31.1, 2630.28.13, 2630.28.10, 2617.23.14 and
some other minor revisions.
This patch implements:
WL#4264 "Backup: Stabilize Service Interface" -- all the
server prerequisites except si_objects.{h,cc} themselves (they can
be just copied over, when needed).
WL#4435: Support OUT-parameters in prepared statements.
(and all issues in the initial patches for these two
tasks, that were discovered in pushbuild and during testing).
Bug#39519: mysql_stmt_close() should flush all data
associated with the statement.
After execution of a prepared statement, send OUT parameters of the invoked
stored procedure, if any, to the client.
When using the binary protocol, send the parameters in an additional result
set over the wire. When using the text protocol, assign out parameters to
the user variables from the CALL(@var1, @var2, ...) specification.
The following refactoring has been made:
- Protocol::send_fields() was renamed to Protocol::send_result_set_metadata();
- A new Protocol::send_result_set_row() was introduced to incapsulate
common functionality for sending row data.
- Signature of Protocol::prepare_for_send() was changed: this operation
does not need a list of items, the number of items is fully sufficient.
The following backward incompatible changes have been made:
- CLIENT_MULTI_RESULTS is now enabled by default in the client;
- CLIENT_PS_MULTI_RESUTLS is now enabled by default in the client.
include/mysql.h:
Add a new flag to MYSQL_METHODS::flush_use_result
function pointer. This flag determines if all results
should be flushed or only the first one:
- if flush_all_results is TRUE, then cli_flush_use_result()
will read/flush all pending results. I.e. it will read
all packets while server status attribute indicates that
there are more results. This is a new semantic, required
to fix the bug.
- if flush_all_results is FALSE, the old sematic
is preserved -- i.e. cli_flush_use_result() reads data
until first EOF-packet.
include/mysql.h.pp:
Update the ABI with new calls (compatible changes).
include/mysql_com.h:
Add CLIENT_PS_OUT_PARAMS -- a client capability indicating that the client supportsю
libmysql/libmysql.c:
Add mysql_stmt_next_result() -- analogue of mysql_next_result() for binary protocol.
Fix a minor bug in alloc_fields() -- not all members were copied over,
and some only shallow-copied (catalog).
Flush all results in mysql_stmt_close() (Bug#39519).
libmysqld/lib_sql.cc:
Rename send_fields() -> send_result_set_metadata().
Refactoring: change prepare_for_send() so that it accepts only
what it really needs -- a number of elements in the list.
mysql-test/r/ps.result:
Update results: WL#4435.
mysql-test/t/ps.test:
WL#4435: A test case for an SQL-part of the problem.
sql-common/client.c:
Bug#39519.
Implement new functionality in cli_flush_use_result():
if flush_all_delete is TRUE, then it should read/flush
all pending results.
sql/Makefile.am:
Add a new header sql_prepare.h to the list
of build headers.
sql/events.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/handler.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/mysql_priv.h:
Move sql_prepare.cc-specific declarations to a new
header - sql_prepare.h.
sql/procedure.h:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/protocol.cc:
Move the logic responsible for sending of one result
set row to the Protocol class. Define a template
for end-of-statement action.
Refactoring: change prepare_for_send() so that it accepts
only what it really needs -- a number of elements in the list.
Rename send_fields() to send_result_set_metadata().
sql/protocol.h:
Update with new declarations (WL#4435).
Rename send_fields() -> send_result_set_metadata().
prepare_for_send() only needs the number of columns to send,
and doesn't use the item list - update signature to require
only what's needed.
Add a new protocol type -- Protocol_local.
sql/repl_failsafe.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/slave.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_acl.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_base.cc:
Include sql_prepare.h (for Reprepare_observer).
sql/sql_cache.cc:
Extend the query cache flags block to be able
to store a numeric id for the result format,
not just a flag binary/non-binary.
sql/sql_class.cc:
Update to use the rename of Protocol::send_fields()
to Protocol::send_result_set_metadata().
Use Protocol::send_one_result_set_row().
sql/sql_class.h:
Move the declaration of Reprepare_observer to the
new header - sql_prepare.h.
Update to the new signature of class Protocol::send_fields().
sql/sql_connect.cc:
Use a protocol template method instead of
raw NET layer API at the end of a statement.
sql/sql_cursor.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_error.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_handler.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
Use new method Protocol::send_one_result_set_row().
sql/sql_help.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_lex.cc:
Initialize multi_statements variable.
Add a handy constant for empty lex
string.
sql/sql_lex.h:
Add a separate member for a standalone
parsing option - multi-statements support.
sql/sql_list.cc:
sql_list.h is a standalone header now,
no need to include mysql_priv.h.
sql/sql_list.h:
Make sql_list.h a stand-alone header.
sql/sql_parse.cc:
Include sql_prepare.h for prepared
statements- related declarations.
Use a new Protocol template method to end
each statement (send OK, EOF or ERROR to
the client).
sql/sql_prepare.cc:
Implement Execute Direct API (WL#4264),
currently unused. It will be used by the service
interface (Backup).
Use a new header - sql_prepare.h.
Add support for OUT parameters in the
binary and text protocol (prepared statements
only).
sql/sql_prepare.h:
Add a new header to contain (for now)
all prepared statement- external
related declarations.
sql/sql_profile.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_repl.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_select.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_show.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_string.h:
Add a way to convert a String to LEX_STRING.
sql/sql_table.cc:
Rename: Protocol::send_fields() ->
Protocol::send_result_set_metadata().
sql/sql_update.cc:
Remove an extraneous my_error(). The error
is already reported in update_non_unique_table_error().
sql/sql_yacc.yy:
Support for multi-statements is an independent
property of parsing, not derived from
the protocol type.
tests/mysql_client_test.c:
Add tests for WL#4435 (binary protocol).
2009-10-21 22:02:06 +02:00
|
|
|
if (protocol->send_result_set_metadata(&field_list,
|
Port of cursors to be pushed into 5.0 tree:
- client side part is simple and may be considered stable
- server side part now just joggles with THD state to save execution
state and has no additional locking wisdom.
Lot's of it are to be rewritten.
include/mysql.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new statement attribute STMT_ATTR_CURSOR_TYPE
- MYSQL_STMT::flags to store statement cursor type
- MYSQL_STMT::server_status to store server status (i. e. if the server
was able to open a cursor for this query).
include/mysql_com.h:
Cursor patch to push into the main tree, client library part (considered
stable):
- new COMmand, COM_FETCH, to fetch K rows from read-only cursor.
By design should support scrollable cursors as well.
- a few new server statuses:
SERVER_STATUS_CURSOR_EXISTS is sent by server in reply to COM_EXECUTE,
when cursor was successfully opened for this query
SERVER_STATUS_LAST_ROW_SENT is sent along with the last row to prevent one
more round trip just for finding out that all rows were fetched from
this cursor (this is server mem savier also).
- and finally, all possible values of STMT_ATTR_CURSOR_TYPE,
while now we support only CURSORT_TYPE_NO_CURSOR and
CURSOR_TYPE_READ_ONLY
libmysql/libmysql.c:
Cursor patch to push into the main tree, client library part (considered
stable):
- simple additions to mysql_stmt_fetch implementation to read data
from an opened cursor: we can read up to iteration count rows per
one request; read rows are buffered in the same way as rows of
mysql_stmt_store_result.
- now send stmt->flags to server to let him now if we wish to have
a cursor for this statement.
- support for setting/getting statement cursor type.
libmysqld/examples/Makefile.am:
Testing cursors was originally implemented in C++. Now when these tests
go into client_test, it's time to convert it to C++ as well.
libmysqld/lib_sql.cc:
- cleanup: send_fields flags are now named.
sql/ha_innodb.cc:
- cleanup: send_fields flags are now named.
sql/mysql_priv.h:
- cursors support: declaration for server-side handler of COM_FETCH
sql/protocol.cc:
- cleanup: send_fields flags are now named.
- we can't anymore assert that field_types[field_pos] is sensible:
if we have COM_EXCUTE(stmt1), COM_EXECUTE(stmt2), COM_FETCH(stmt1)
field_types[field_pos] will point to fields of stmt2.
sql/protocol.h:
- cleanup: send_fields flag_s_ are now named.
sql/protocol_cursor.cc:
- cleanup: send_fields flags are now named.
sql/repl_failsafe.cc:
- cleanup: send_fields flags are now named.
sql/slave.cc:
- cleanup: send_fields flags are now named.
sql/sp.cc:
- cleanup: send_fields flags are now named.
sql/sp_head.cc:
- cleanup: send_fields flags are now named.
sql/sql_acl.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.cc:
- cleanup: send_fields flags are now named.
sql/sql_class.h:
- cleanup: send_fields flags are now named.
sql/sql_error.cc:
- cleanup: send_fields flags are now named.
sql/sql_handler.cc:
- cleanup: send_fields flags are now named.
sql/sql_help.cc:
- cleanup: send_fields flags are now named.
sql/sql_parse.cc:
Server side support for cursors:
- handle COM_FETCH
- enforce assumption that whenever we free thd->free_list,
we reset it to zero. This way it's much easier to handle free_list
in prepared statements implementation.
sql/sql_prepare.cc:
Server side support for cursors:
- implementation of mysql_stmt_fetch (fetch some rows from open cursor).
- management of cursors memory is quite tricky now.
- execute_stmt can't be reused anymore in mysql_stmt_execute and
mysql_sql_stmt_execute
sql/sql_repl.cc:
- cleanup: send_fields flags are now named.
sql/sql_select.cc:
Server side support for cursors:
- implementation of Cursor::open, Cursor::fetch (buggy when it comes to
non-equi joins), cursor cleanups.
- -4 -3 -0 constants indicating return value of sub_select and end_send are
to be renamed to something more readable:
it turned out to be not so simple, so it should come with the other patch.
sql/sql_select.h:
Server side support for cursors:
- declaration of Cursor class.
- JOIN::fetch_limit contains runtime value of rows fetched via cursor.
sql/sql_show.cc:
- cleanup: send_fields flags are now named.
sql/sql_table.cc:
- cleanup: send_fields flags are now named.
sql/sql_union.cc:
- if there was a cursor, don't cleanup unit: we'll need it to fetch
the rest of the rows.
tests/Makefile.am:
Now client_test is in C++.
tests/client_test.cc:
A few elementary tests for cursors.
BitKeeper/etc/ignore:
Added libmysqld/examples/client_test.cc to the ignore list
2004-08-03 12:32:21 +02:00
|
|
|
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
2004-10-20 03:04:37 +02:00
|
|
|
DBUG_RETURN(TRUE);
|
2001-11-11 06:24:12 +01:00
|
|
|
|
2019-03-01 21:41:33 +01:00
|
|
|
if (server_threads.iterate(show_slave_hosts_callback, protocol))
|
|
|
|
DBUG_RETURN(true);
|
2001-11-11 06:24:12 +01:00
|
|
|
|
2008-02-19 13:58:08 +01:00
|
|
|
my_eof(thd);
|
2004-10-20 03:04:37 +02:00
|
|
|
DBUG_RETURN(FALSE);
|
2001-11-11 06:24:12 +01:00
|
|
|
}
|
|
|
|
|
2003-01-15 09:11:44 +01:00
|
|
|
#endif /* HAVE_REPLICATION */
|
2002-12-16 14:33:29 +01:00
|
|
|
|