Commit d909f4a5 authored by monty@mashka.mysql.fi's avatar monty@mashka.mysql.fi

Fix wrong usage of constant which could cause mysqld to use index when doing...

Fix wrong usage of constant which could cause mysqld to use index when doing an update/delete on small tables.
code cleanup
parent 5b766472
...@@ -46928,6 +46928,8 @@ not yet 100% confident in this code. ...@@ -46928,6 +46928,8 @@ not yet 100% confident in this code.
@appendixsubsec Changes in release 3.23.52 @appendixsubsec Changes in release 3.23.52
@itemize @bullet @itemize @bullet
@item @item
Don't write slave-timeout reconnects to the error log.
@item
Fixed bug with slave net read timeouting Fixed bug with slave net read timeouting
@item @item
Fixed bug in ALTERing TABLE of BDB type. Fixed bug in ALTERing TABLE of BDB type.
...@@ -1990,7 +1990,7 @@ ha_innobase::change_active_index( ...@@ -1990,7 +1990,7 @@ ha_innobase::change_active_index(
InnoDB */ InnoDB */
{ {
row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt; row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
KEY* key; KEY* key=0;
statistic_increment(ha_read_key_count, &LOCK_status); statistic_increment(ha_read_key_count, &LOCK_status);
...@@ -2011,7 +2011,7 @@ ha_innobase::change_active_index( ...@@ -2011,7 +2011,7 @@ ha_innobase::change_active_index(
if (!prebuilt->index) { if (!prebuilt->index) {
fprintf(stderr, fprintf(stderr,
"InnoDB: Could not find key n:o %u with name %s from dict cache\n" "InnoDB: Could not find key n:o %u with name %s from dict cache\n"
"InnoDB: for table %s\n", keynr, key->name, prebuilt->table->name); "InnoDB: for table %s\n", keynr, key ? key->name : "NULL", prebuilt->table->name);
return(1); return(1);
} }
......
...@@ -55,7 +55,7 @@ inline bool slave_killed(THD* thd); ...@@ -55,7 +55,7 @@ inline bool slave_killed(THD* thd);
static int init_slave_thread(THD* thd); static int init_slave_thread(THD* thd);
static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi); static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi);
static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi, static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
bool suppress_prints_as_normal_reconnect_after_timeout); bool suppress_warnings);
static int safe_sleep(THD* thd, int sec); static int safe_sleep(THD* thd, int sec);
static int request_table_dump(MYSQL* mysql, char* db, char* table); static int request_table_dump(MYSQL* mysql, char* db, char* table);
static int create_table_from_dump(THD* thd, NET* net, const char* db, static int create_table_from_dump(THD* thd, NET* net, const char* db,
...@@ -839,13 +839,15 @@ command"); ...@@ -839,13 +839,15 @@ command");
return 0; return 0;
} }
/* We set suppress_prints_as_normal_reconnect_after_timeout TRUE
when a normal net read timeout has caused us to try a reconnect.
We do not want to print anything to the error log in this case
because this a anormal event in an idle server. */
static uint read_event(MYSQL* mysql, MASTER_INFO *mi, /*
bool* suppress_prints_as_normal_reconnect_after_timeout) We set suppress_warnings TRUE when a normal net read timeout has
caused us to try a reconnect. We do not want to print anything to
the error log in this case because this a anormal event in an idle
server.
*/
static uint read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings)
{ {
uint len = packet_error; uint len = packet_error;
...@@ -855,24 +857,25 @@ static uint read_event(MYSQL* mysql, MASTER_INFO *mi, ...@@ -855,24 +857,25 @@ static uint read_event(MYSQL* mysql, MASTER_INFO *mi,
if (disconnect_slave_event_count && !(events_till_disconnect--)) if (disconnect_slave_event_count && !(events_till_disconnect--))
return packet_error; return packet_error;
#endif #endif
*suppress_prints_as_normal_reconnect_after_timeout = 0; *suppress_warnings= 0;
len = mc_net_safe_read(mysql); len = mc_net_safe_read(mysql);
if (len == packet_error || (long) len < 1) if (len == packet_error || (long) len < 1)
{ {
if (mc_mysql_errno(mysql) == ER_NET_READ_INTERRUPTED) { if (mc_mysql_errno(mysql) == ER_NET_READ_INTERRUPTED)
{
/* We are trying a normal reconnect after a read timeout; /*
we suppress prints to .err file as long as the reconnect We are trying a normal reconnect after a read timeout;
happens without problems */ we suppress prints to .err file as long as the reconnect
*suppress_prints_as_normal_reconnect_after_timeout = TRUE; happens without problems
*/
*suppress_warnings= TRUE;
} }
else
if (!(*suppress_prints_as_normal_reconnect_after_timeout))
sql_print_error("Error reading packet from server: %s (\ sql_print_error("Error reading packet from server: %s (\
server_errno=%d)", server_errno=%d)",
mc_mysql_error(mysql), mc_mysql_errno(mysql)); mc_mysql_error(mysql), mc_mysql_errno(mysql));
return packet_error; return packet_error;
} }
...@@ -1380,15 +1383,13 @@ try again, log '%s' at postion %s", RPL_LOG_NAME, ...@@ -1380,15 +1383,13 @@ try again, log '%s' at postion %s", RPL_LOG_NAME,
while(!slave_killed(thd)) while(!slave_killed(thd))
{ {
bool suppress_prints_as_normal_reconnect_after_timeout = 0; bool suppress_warnings= 0;
thd->proc_info = "Reading master update"; thd->proc_info = "Reading master update";
uint event_len = read_event(mysql, &glob_mi, uint event_len = read_event(mysql, &glob_mi, &suppress_warnings);
&suppress_prints_as_normal_reconnect_after_timeout);
if(slave_killed(thd)) if(slave_killed(thd))
{ {
suppress_prints_as_normal_reconnect_after_timeout = 0;
sql_print_error("Slave thread killed while reading event"); sql_print_error("Slave thread killed while reading event");
goto err; goto err;
} }
...@@ -1397,7 +1398,6 @@ try again, log '%s' at postion %s", RPL_LOG_NAME, ...@@ -1397,7 +1398,6 @@ try again, log '%s' at postion %s", RPL_LOG_NAME,
{ {
if(mc_mysql_errno(mysql) == ER_NET_PACKET_TOO_LARGE) if(mc_mysql_errno(mysql) == ER_NET_PACKET_TOO_LARGE)
{ {
suppress_prints_as_normal_reconnect_after_timeout = 0;
sql_print_error("Log entry on master is longer than \ sql_print_error("Log entry on master is longer than \
max_allowed_packet on slave. Slave thread will be aborted. If the entry is \ max_allowed_packet on slave. Slave thread will be aborted. If the entry is \
really supposed to be that long, restart the server with a higher value of \ really supposed to be that long, restart the server with a higher value of \
...@@ -1415,7 +1415,6 @@ max_allowed_packet. The current value is %ld", max_allowed_packet); ...@@ -1415,7 +1415,6 @@ max_allowed_packet. The current value is %ld", max_allowed_packet);
if(slave_killed(thd)) if(slave_killed(thd))
{ {
suppress_prints_as_normal_reconnect_after_timeout = 0;
sql_print_error("Slave thread killed while waiting to \ sql_print_error("Slave thread killed while waiting to \
reconnect after a failed read"); reconnect after a failed read");
goto err; goto err;
...@@ -1423,21 +1422,19 @@ reconnect after a failed read"); ...@@ -1423,21 +1422,19 @@ reconnect after a failed read");
thd->proc_info = "Reconnecting after a failed read"; thd->proc_info = "Reconnecting after a failed read";
last_failed_pos= glob_mi.pos; last_failed_pos= glob_mi.pos;
if (!suppress_prints_as_normal_reconnect_after_timeout) if (!suppress_warnings)
sql_print_error("Slave: Failed reading log event, \ sql_print_error("Slave: Failed reading log event, \
reconnecting to retry, log '%s' position %s", RPL_LOG_NAME, reconnecting to retry, log '%s' position %s", RPL_LOG_NAME,
llstr(last_failed_pos, llbuff)); llstr(last_failed_pos, llbuff));
if(safe_reconnect(thd, mysql, &glob_mi, if(safe_reconnect(thd, mysql, &glob_mi,
suppress_prints_as_normal_reconnect_after_timeout) suppress_warnings)
|| slave_killed(thd)) || slave_killed(thd))
{ {
suppress_prints_as_normal_reconnect_after_timeout = 0;
sql_print_error("Slave thread killed during or after a \ sql_print_error("Slave thread killed during or after a \
reconnect done to recover from failed read"); reconnect done to recover from failed read");
goto err; goto err;
} }
suppress_prints_as_normal_reconnect_after_timeout = 0;
goto connected; goto connected;
} // if(event_len == packet_error) } // if(event_len == packet_error)
...@@ -1550,7 +1547,7 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi) ...@@ -1550,7 +1547,7 @@ static int safe_connect(THD* thd, MYSQL* mysql, MASTER_INFO* mi)
*/ */
static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi, static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
bool suppress_prints_as_normal_reconnect_after_timeout) bool suppress_warnings)
{ {
int slave_was_killed; int slave_was_killed;
int last_errno= -2; // impossible error int last_errno= -2; // impossible error
...@@ -1570,7 +1567,7 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi, ...@@ -1570,7 +1567,7 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
/* Don't repeat last error */ /* Don't repeat last error */
if (mc_mysql_errno(mysql) != last_errno) if (mc_mysql_errno(mysql) != last_errno)
{ {
suppress_prints_as_normal_reconnect_after_timeout = 0; suppress_warnings= 0;
sql_print_error("Slave thread: error re-connecting to master: \ sql_print_error("Slave thread: error re-connecting to master: \
%s, last_errno=%d, retry in %d sec", %s, last_errno=%d, retry in %d sec",
mc_mysql_error(mysql), last_errno=mc_mysql_errno(mysql), mc_mysql_error(mysql), last_errno=mc_mysql_errno(mysql),
...@@ -1587,7 +1584,7 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi, ...@@ -1587,7 +1584,7 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, MASTER_INFO* mi,
if (!slave_was_killed) if (!slave_was_killed)
{ {
if (!suppress_prints_as_normal_reconnect_after_timeout) if (!suppress_warnings)
sql_print_error("Slave: reconnected to master '%s@%s:%d',\ sql_print_error("Slave: reconnected to master '%s@%s:%d',\
replication resumed in log '%s' at position %s", glob_mi.user, replication resumed in log '%s' at position %s", glob_mi.user,
glob_mi.host, glob_mi.port, glob_mi.host, glob_mi.port,
......
...@@ -166,11 +166,12 @@ void mysql_rm_db(THD *thd,char *db,bool if_exists) ...@@ -166,11 +166,12 @@ void mysql_rm_db(THD *thd,char *db,bool if_exists)
if ((deleted=mysql_rm_known_files(thd, dirp, path,0)) >= 0) if ((deleted=mysql_rm_known_files(thd, dirp, path,0)) >= 0)
{ {
/* If there are running queries on the tables, MySQL needs to get /*
access to LOCK_open to end them. InnoDB on the other hand waits If there are running queries on the tables, MySQL needs to get
for the queries to end before dropping the database. That is why we access to LOCK_open to end them. InnoDB on the other hand waits
must do the dropping with LOCK_open released. */ for the queries to end before dropping the database. That is why we
must do the dropping with LOCK_open released.
*/
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
ha_drop_database(path); ha_drop_database(path);
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
......
...@@ -169,7 +169,7 @@ int mysql_delete(THD *thd,TABLE_LIST *table_list,COND *conds,ha_rows limit, ...@@ -169,7 +169,7 @@ int mysql_delete(THD *thd,TABLE_LIST *table_list,COND *conds,ha_rows limit,
select=make_select(table,0,0,conds,&error); select=make_select(table,0,0,conds,&error);
if (error) if (error)
DBUG_RETURN(-1); DBUG_RETURN(-1);
if ((select && select->check_quick(test(thd->options & SQL_SAFE_UPDATES), if ((select && select->check_quick(test(thd->options & OPTION_SAFE_UPDATES),
limit)) || limit)) ||
!limit) !limit)
{ {
......
...@@ -110,7 +110,7 @@ int mysql_update(THD *thd,TABLE_LIST *table_list,List<Item> &fields, ...@@ -110,7 +110,7 @@ int mysql_update(THD *thd,TABLE_LIST *table_list,List<Item> &fields,
table->used_keys=0; table->used_keys=0;
select=make_select(table,0,0,conds,&error); select=make_select(table,0,0,conds,&error);
if (error || if (error ||
(select && select->check_quick(test(thd->options & SQL_SAFE_UPDATES), (select && select->check_quick(test(thd->options & OPTION_SAFE_UPDATES),
limit)) || limit)) ||
!limit) !limit)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment