From f17cc60413d38b4576f4fc287b2107daff801c34 Mon Sep 17 00:00:00 2001 From: Luis Soares Date: Fri, 24 Sep 2010 10:44:53 +0100 Subject: [PATCH 01/15] BUG#55263: assert in check_binlog_magic The procedure for setting up a fake binary log, by changing the relay log files manually, is run twice when we issue mtr with --repeat=2. However, when setting it up for the second time, neither the sql thread is reset nor the server is restarted. This means that previous stale relay log IO_CACHE metadata - from first run - is left around. As a consequence, when the test is run for the second time, the IO_CACHE for the relay log has position in file different than zero, triggering the assertion. We fix this by deploying a call to my_b_seek before calling check_binlog_magic in next_event. This prevents the server from asserting, in the cases that the SQL thread was reads from a hot log (relay.NNNNN), then is stopped, then is restarted from a previous cold log (relay.MMMMM), and then it reaches the hot log relay.NNNNN again, in which case, the read coordinates are not set to zero, but to the old values. Additionally, some comments to the source code were added. --- sql/rpl_rli.h | 10 ++++++++ sql/slave.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h index 87516c366fb..69988fe5995 100644 --- a/sql/rpl_rli.h +++ b/sql/rpl_rli.h @@ -94,6 +94,16 @@ public: */ MYSQL_BIN_LOG relay_log; LOG_INFO linfo; + + /* + cur_log + Pointer that either points at relay_log.get_log_file() or + &rli->cache_buf, depending on whether the log is hot or there was + the need to open a cold relay_log. + + cache_buf + IO_CACHE used when opening cold relay logs. + */ IO_CACHE cache_buf,*cur_log; /* The following variables are safe to read any time */ diff --git a/sql/slave.cc b/sql/slave.cc index f1e0962e7e8..bd9017e6318 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -4349,12 +4349,66 @@ static Log_event* next_event(Relay_log_info* rli) DBUG_ASSERT(rli->cur_log_fd == -1); /* - Read pointer has to be at the start since we are the only - reader. - We must keep the LOCK_log to read the 4 first bytes, as this is a hot - log (same as when we call read_log_event() above: for a hot log we - take the mutex). + When the SQL thread is [stopped and] (re)started the + following may happen: + + 1. Log was hot at stop time and remains hot at restart + + SQL thread reads again from hot_log (SQL thread was + reading from the active log when it was stopped and the + very same log is still active on SQL thread restart). + + In this case, my_b_seek is performed on cur_log, while + cur_log points to relay_log.get_log_file(); + + 2. Log was hot at stop time but got cold before restart + + The log was hot when SQL thread stopped, but it is not + anymore when the SQL thread restarts. + + In this case, the SQL thread reopens the log, using + cache_buf, ie, cur_log points to &cache_buf, and thence + its coordinates are reset. + + 3. Log was already cold at stop time + + The log was not hot when the SQL thread stopped, and, of + course, it will not be hot when it restarts. + + In this case, the SQL thread opens the cold log again, + using cache_buf, ie, cur_log points to &cache_buf, and + thence its coordinates are reset. + + 4. Log was hot at stop time, DBA changes to previous cold + log and restarts SQL thread + + The log was hot when the SQL thread was stopped, but the + user changed the coordinates of the SQL thread to + restart from a previous cold log. + + In this case, at start time, cur_log points to a cold + log, opened using &cache_buf as cache, and coordinates + are reset. However, as it moves on to the next logs, it + will eventually reach the hot log. If the hot log is the + same at the time the SQL thread was stopped, then + coordinates were not reset - the cur_log will point to + relay_log.get_log_file(), and not a freshly opened + IO_CACHE through cache_buf. For this reason we need to + deploy a my_b_seek before calling check_binlog_magic at + this point of the code (see: BUG#55263 for more + details). + + NOTES: + - We must keep the LOCK_log to read the 4 first bytes, as + this is a hot log (same as when we call read_log_event() + above: for a hot log we take the mutex). + + - Because of scenario #4 above, we need to have a + my_b_seek here. Otherwise, we might hit the assertion + inside check_binlog_magic. */ + + my_b_seek(cur_log, (my_off_t) 0); if (check_binlog_magic(cur_log,&errmsg)) { if (!hot_log) pthread_mutex_unlock(log_lock); From 5109d5401e9b59b7d5210af462c3f266ced87185 Mon Sep 17 00:00:00 2001 From: Luis Soares Date: Wed, 6 Oct 2010 12:23:46 +0100 Subject: [PATCH 02/15] BUG#38718: slave sql thread crashes when reading relay log Suprisingly, a Slave_log_event would show up in the binary log. This event is never used and should not appear in the logs. As such, when the slave (or the mysqlbinlog tool) reads the event, it will hit an invalid pointer (reference to the descriptor event when deserializing the Slave_log_event was purposodely set to NULL). The presence of the Slave_log_event denotes a corrupted log, but we cannot tell how the log got corrupted in the first place. However, we can make the server cope with such events when it reads them - in case of log corruption - and fail gracefully. This patch makes the server/mysqlbinlog to report that it has found an invalid log event when Slave_log_event is read. --- sql/log_event.cc | 14 ++++++++++---- sql/log_event.h | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sql/log_event.cc b/sql/log_event.cc index 7becdf51747..98ce3fbade8 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1225,7 +1225,7 @@ Log_event* Log_event::read_log_event(const char* buf, uint event_len, break; #ifdef HAVE_REPLICATION case SLAVE_EVENT: /* can never happen (unused event) */ - ev = new Slave_log_event(buf, event_len); + ev = new Slave_log_event(buf, event_len, description_event); break; #endif /* HAVE_REPLICATION */ case CREATE_FILE_EVENT: @@ -1313,8 +1313,10 @@ Log_event* Log_event::read_log_event(const char* buf, uint event_len, (because constructor is "void") ; so instead we leave the pointer we wanted to allocate (e.g. 'query') to 0 and we test it in is_valid(). Same for Format_description_log_event, member 'post_header_len'. + + SLAVE_EVENT is never used, so it should not be read ever. */ - if (!ev || !ev->is_valid()) + if (!ev || !ev->is_valid() || (event_type == SLAVE_EVENT)) { DBUG_PRINT("error",("Found invalid event in binary log")); @@ -5978,8 +5980,12 @@ void Slave_log_event::init_from_mem_pool(int data_size) /** This code is not used, so has not been updated to be format-tolerant. */ -Slave_log_event::Slave_log_event(const char* buf, uint event_len) - :Log_event(buf,0) /*unused event*/ ,mem_pool(0),master_host(0) +/* We are using description_event so that slave does not crash on Log_event + constructor */ +Slave_log_event::Slave_log_event(const char* buf, + uint event_len, + const Format_description_log_event* description_event) + :Log_event(buf,description_event),mem_pool(0),master_host(0) { if (event_len < LOG_EVENT_HEADER_LEN) return; diff --git a/sql/log_event.h b/sql/log_event.h index 816a241e55d..662fec23639 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -1782,7 +1782,9 @@ public: void print(FILE* file, PRINT_EVENT_INFO* print_event_info); #endif - Slave_log_event(const char* buf, uint event_len); + Slave_log_event(const char* buf, + uint event_len, + const Format_description_log_event *description_event); ~Slave_log_event(); int get_data_size(); bool is_valid() const { return master_host != 0; } From fea55c7ff512b244bce9c0d94c8fb6517d2f5277 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Wed, 13 Oct 2010 12:28:58 +0700 Subject: [PATCH 03/15] Fixed bug#36742 - GRANT hostname case handling inconsistent. --- mysql-test/r/grant.result | 11 +++++++++++ mysql-test/t/grant.test | 10 ++++++++++ sql/sql_yacc.yy | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 6831ef6183d..f6277323964 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -1429,3 +1429,14 @@ DROP USER 'testbug'@localhost; DROP TABLE db2.t1; DROP DATABASE db1; DROP DATABASE db2; +# +# Bug #36742 +# +grant usage on Foo.* to myuser@Localhost identified by 'foo'; +grant select on Foo.* to myuser@localhost; +select host,user from mysql.user where User='myuser'; +host user +localhost myuser +revoke select on Foo.* from myuser@localhost; +delete from mysql.user where User='myuser'; +flush privileges; diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index cb8d3c63be8..2fafeb7d264 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -1550,5 +1550,15 @@ DROP TABLE db2.t1; DROP DATABASE db1; DROP DATABASE db2; +--echo # +--echo # Bug #36742 +--echo # +grant usage on Foo.* to myuser@Localhost identified by 'foo'; +grant select on Foo.* to myuser@localhost; +select host,user from mysql.user where User='myuser'; +revoke select on Foo.* from myuser@localhost; +delete from mysql.user where User='myuser'; +flush privileges; + # Wait till we reached the initial number of concurrent sessions --source include/wait_until_count_sessions.inc diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index aa41a408e5b..4e24e69af42 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -11567,6 +11567,12 @@ user: system_charset_info, 0) || check_host_name(&$$->host)) MYSQL_YYABORT; + /* + Convert hostname part of username to lowercase. + It's OK to use in-place lowercase as long as + the character set is utf8. + */ + my_casedn_str(system_charset_info, $$->host.str); } | CURRENT_USER optional_braces { From 46f2610b26641928d5fdd131a97ee3f0346bed61 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Wed, 13 Oct 2010 13:34:02 +0400 Subject: [PATCH 04/15] Reverting a patch for Bug#45445 (cannot execute procedures with thread_stack set to 128k). Some platforms don't work with 4 * STACK_MIN_SIZE. Thus, reverting back to 8 * STACK_MIN_SIZE and waiting for another fix. --- sql/sp_head.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 52f658cbe0e..1fd4e9302c4 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1233,8 +1233,11 @@ sp_head::execute(THD *thd) The same with db_load_routine() required circa 7k bytes and 14k bytes accordingly. Hence, here we book the stack with some reasonable margin. + + Reverting back to 8 * STACK_MIN_SIZE until further fix. + 8 * STACK_MIN_SIZE is required on some exotic platforms. */ - if (check_stack_overrun(thd, 4 * STACK_MIN_SIZE, (uchar*)&old_packet)) + if (check_stack_overrun(thd, 8 * STACK_MIN_SIZE, (uchar*)&old_packet)) DBUG_RETURN(TRUE); /* init per-instruction memroot */ From e2599d9f7597ca530066d97c47336cc45332f247 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Wed, 13 Oct 2010 12:11:29 -0300 Subject: [PATCH 05/15] Use a guard macro to prevent the inclusion of system headers when checking the ABI with the C Preprocessor. Also, add the new hearders to the cmake based ABI check. --- Makefile.am | 2 ++ cmake/abi_check.cmake | 6 ++++-- include/mysql/client_plugin.h | 2 ++ include/mysql/client_plugin.h.pp | 2 -- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index fadd73d5094..c47d8e780cf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -263,6 +263,8 @@ test-full-qa: # # Headers which need to be checked for abi/api compatibility. # +# Attention: do not forget to also add to cmake/abi_check.cmake +# API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin_audit.h \ $(top_srcdir)/include/mysql/plugin_ftparser.h \ diff --git a/cmake/abi_check.cmake b/cmake/abi_check.cmake index b9ff9f7af73..2488bcefe33 100644 --- a/cmake/abi_check.cmake +++ b/cmake/abi_check.cmake @@ -27,12 +27,14 @@ IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_SYSTEM_NAME MATCHES "Linux") ELSE() SET(COMPILER ${CMAKE_C_COMPILER}) ENDIF() - SET(API_PREPROCESSOR_HEADER + SET(API_PREPROCESSOR_HEADER ${CMAKE_SOURCE_DIR}/include/mysql/plugin_audit.h ${CMAKE_SOURCE_DIR}/include/mysql/plugin_ftparser.h ${CMAKE_SOURCE_DIR}/include/mysql.h - ${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v1.h + ${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v1.h ${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v2.h + ${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h ) ADD_CUSTOM_TARGET(abi_check ALL diff --git a/include/mysql/client_plugin.h b/include/mysql/client_plugin.h index ddd3b64ca56..d9c0dd02008 100644 --- a/include/mysql/client_plugin.h +++ b/include/mysql/client_plugin.h @@ -23,8 +23,10 @@ */ #define MYSQL_CLIENT_PLUGIN_INCLUDED +#ifndef MYSQL_ABI_CHECK #include #include +#endif /* known plugin types */ #define MYSQL_CLIENT_reserved1 0 diff --git a/include/mysql/client_plugin.h.pp b/include/mysql/client_plugin.h.pp index 58627e06f09..e508f821aad 100644 --- a/include/mysql/client_plugin.h.pp +++ b/include/mysql/client_plugin.h.pp @@ -1,5 +1,3 @@ -#include -#include struct st_mysql_client_plugin { int type; unsigned int interface_version; const char *name; const char *author; const char *desc; unsigned int version[3]; const char *license; void *mysql_api; int (*init)(char *, size_t, int, va_list); int (*deinit)(); int (*options)(const char *option, const void *); From dab7abbed8869b7c3a96e75b7bb52944ac58fef1 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Wed, 13 Oct 2010 21:25:41 +0400 Subject: [PATCH 06/15] Bump version after 5.5.7 clone-off. --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index c272efe9214..4725008b473 100644 --- a/configure.in +++ b/configure.in @@ -27,7 +27,7 @@ dnl dnl When changing the major version number please also check the switch dnl statement in mysqlbinlog::check_master_version(). You may also need dnl to update version.c in ndb. -AC_INIT([MySQL Server], [5.5.7-rc], [], [mysql]) +AC_INIT([MySQL Server], [5.5.8-ga], [], [mysql]) AC_CONFIG_SRCDIR([sql/mysqld.cc]) AC_CANONICAL_SYSTEM From 7d64c364865599b14f4b30f42a7ffcd1c7e1557c Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Wed, 13 Oct 2010 22:54:07 -0300 Subject: [PATCH 07/15] Bug#56096: STOP SLAVE hangs if executed in parallel with user sleep The root of the problem is that to interrupt a slave SQL thread wait, the STOP SLAVE implementation uses thd->awake(THD::NOT_KILLED). This appears as a spurious wakeup (e.g. from a sleep on a condition variable) to the code that the slave SQL thread is executing at the time of the STOP. If the code is not written to be spurious-wakeup safe, unexpected behavior can occur. For the reported case, this problem led to an infinite loop around the interruptible_wait() function in item_func.cc (SLEEP() function implementation). The loop was not being properly restarted and, consequently, would not come to an end. Since the SLEEP function sleeps on a timed event in order to be killable and to perform periodic checks until the requested time has elapsed, the spurious wake up was causing the requested sleep time to be reset every two seconds. The solution is to calculate the requested absolute time only once and to ensure that the thread only sleeps until this time is elapsed. In case of a spurious wake up, the sleep is restarted using the previously calculated absolute time. This restores the behavior present in previous releases. If a slave thread is executing a SLEEP function, a STOP SLAVE statement will wait until the time requested in the sleep function has elapsed. --- .../extra/rpl_tests/rpl_start_stop_slave.test | 56 +++++++++++ .../rpl/r/rpl_stm_start_stop_slave.result | 22 +++++ sql/item_func.cc | 96 ++++++++++++++----- 3 files changed, 151 insertions(+), 23 deletions(-) diff --git a/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test b/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test index 05836737717..5c99fa1bc74 100644 --- a/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test +++ b/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test @@ -122,4 +122,60 @@ drop table t1i, t2m; sync_slave_with_master; +--echo # +--echo # Bug#56096 STOP SLAVE hangs if executed in parallel with user sleep +--echo # + +--connection master + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (a INT ); + +sync_slave_with_master; + +--connection slave1 +--echo # Slave1: lock table for synchronization +LOCK TABLES t1 WRITE; + +--connection master +--echo # Master: insert into the table +INSERT INTO t1 SELECT SLEEP(4); + +--connection slave +--echo # Slave: wait for the insert +let $wait_condition= + SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST + WHERE STATE = "Waiting for table metadata lock" + AND INFO = "INSERT INTO t1 SELECT SLEEP(4)"; +--source include/wait_condition.inc + +--echo # Slave: send slave stop +--send STOP SLAVE + +--connection slave1 +--echo # Slave1: wait for stop slave +let $wait_condition= + SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST + WHERE INFO = "STOP SLAVE"; +--source include/wait_condition.inc + +--echo # Slave1: unlock the table +UNLOCK TABLES; + +--connection slave +--echo # Slave: wait for the slave to stop +--reap +--source include/wait_for_slave_to_stop.inc + +--echo # Start slave again +--source include/start_slave.inc + +--echo # Clean up +--connection master +DROP TABLE t1; +sync_slave_with_master; + # End of tests diff --git a/mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result b/mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result index 71ad0177bae..8bb8b0bdf08 100644 --- a/mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result +++ b/mysql-test/suite/rpl/r/rpl_stm_start_stop_slave.result @@ -43,3 +43,25 @@ one 1 include/start_slave.inc drop table t1i, t2m; +# +# Bug#56096 STOP SLAVE hangs if executed in parallel with user sleep +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a INT ); +# Slave1: lock table for synchronization +LOCK TABLES t1 WRITE; +# Master: insert into the table +INSERT INTO t1 SELECT SLEEP(4); +Warnings: +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. +# Slave: wait for the insert +# Slave: send slave stop +STOP SLAVE; +# Slave1: wait for stop slave +# Slave1: unlock the table +UNLOCK TABLES; +# Slave: wait for the slave to stop +# Start slave again +include/start_slave.inc +# Clean up +DROP TABLE t1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 7906ed71bc7..afb09ff5b17 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3691,48 +3691,92 @@ longlong Item_master_pos_wait::val_int() } +/** + Enables a session to wait on a condition until a timeout or a network + disconnect occurs. + + @remark The connection is polled every m_interrupt_interval nanoseconds. +*/ + +class Interruptible_wait +{ + THD *m_thd; + struct timespec m_abs_timeout; + static const ulonglong m_interrupt_interval; + + public: + Interruptible_wait(THD *thd) + : m_thd(thd) {} + + ~Interruptible_wait() {} + + public: + /** + Set the absolute timeout. + + @param timeout The amount of time in nanoseconds to wait + */ + void set_timeout(ulonglong timeout) + { + /* + Calculate the absolute system time at the start so it can + be controlled in slices. It relies on the fact that once + the absolute time passes, the timed wait call will fail + automatically with a timeout error. + */ + set_timespec_nsec(m_abs_timeout, timeout); + } + + /** The timed wait. */ + int wait(mysql_cond_t *, mysql_mutex_t *); +}; + + +/** Time to wait before polling the connection status. */ +const ulonglong Interruptible_wait::m_interrupt_interval= 5 * ULL(1000000000); + /** - Wait for a given condition to be signaled within the specified timeout. + Wait for a given condition to be signaled. - @param cond the condition variable to wait on - @param lock the associated mutex - @param abstime the amount of time in seconds to wait + @param cond The condition variable to wait on. + @param mutex The associated mutex. + + @remark The absolute timeout is preserved across calls. @retval return value from mysql_cond_timedwait */ -#define INTERRUPT_INTERVAL (5 * ULL(1000000000)) - -static int interruptible_wait(THD *thd, mysql_cond_t *cond, - mysql_mutex_t *lock, double time) +int Interruptible_wait::wait(mysql_cond_t *cond, mysql_mutex_t *mutex) { int error; - struct timespec abstime; - ulonglong slice, timeout= (ulonglong) (time * 1000000000.0); + struct timespec timeout; - do + while (1) { /* Wait for a fixed interval. */ - if (timeout > INTERRUPT_INTERVAL) - slice= INTERRUPT_INTERVAL; - else - slice= timeout; + set_timespec_nsec(timeout, m_interrupt_interval); - timeout-= slice; - set_timespec_nsec(abstime, slice); - error= mysql_cond_timedwait(cond, lock, &abstime); + /* But only if not past the absolute timeout. */ + if (cmp_timespec(timeout, m_abs_timeout) > 0) + timeout= m_abs_timeout; + + error= mysql_cond_timedwait(cond, mutex, &timeout); if (error == ETIMEDOUT || error == ETIME) { /* Return error if timed out or connection is broken. */ - if (!timeout || !thd->is_connected()) + if (!cmp_timespec(timeout, m_abs_timeout) || !m_thd->is_connected()) break; } - } while (error && timeout); + /* Otherwise, propagate status to the caller. */ + else + break; + } return error; } + /** Get a user level lock. If the thread has an old lock this is first released. @@ -3748,10 +3792,11 @@ longlong Item_func_get_lock::val_int() { DBUG_ASSERT(fixed == 1); String *res=args[0]->val_str(&value); - double timeout= args[1]->val_real(); + ulonglong timeout= args[1]->val_int(); THD *thd=current_thd; User_level_lock *ull; int error; + Interruptible_wait timed_cond(thd); DBUG_ENTER("Item_func_get_lock::val_int"); /* @@ -3812,11 +3857,13 @@ longlong Item_func_get_lock::val_int() thd->mysys_var->current_mutex= &LOCK_user_locks; thd->mysys_var->current_cond= &ull->cond; + timed_cond.set_timeout(timeout * ULL(1000000000)); + error= 0; while (ull->locked && !thd->killed) { DBUG_PRINT("info", ("waiting on lock")); - error= interruptible_wait(thd, &ull->cond, &LOCK_user_locks, timeout); + error= timed_cond.wait(&ull->cond, &LOCK_user_locks); if (error == ETIMEDOUT || error == ETIME) { DBUG_PRINT("info", ("lock wait timeout")); @@ -4011,6 +4058,7 @@ void Item_func_benchmark::print(String *str, enum_query_type query_type) longlong Item_func_sleep::val_int() { THD *thd= current_thd; + Interruptible_wait timed_cond(thd); mysql_cond_t cond; double timeout; int error; @@ -4030,6 +4078,8 @@ longlong Item_func_sleep::val_int() if (timeout < 0.00001) return 0; + timed_cond.set_timeout((ulonglong) (timeout * 1000000000.0)); + mysql_cond_init(key_item_func_sleep_cond, &cond, NULL); mysql_mutex_lock(&LOCK_user_locks); @@ -4040,7 +4090,7 @@ longlong Item_func_sleep::val_int() error= 0; while (!thd->killed) { - error= interruptible_wait(thd, &cond, &LOCK_user_locks, timeout); + error= timed_cond.wait(&cond, &LOCK_user_locks); if (error == ETIMEDOUT || error == ETIME) break; error= 0; From 69693c26330665ba6c8d9cff0fb7c20758e8ced7 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Thu, 14 Oct 2010 14:05:59 +0400 Subject: [PATCH 08/15] A patch for Bug#48874 (Test "is_triggers" fails because of wrong charset info). The thing is that the following attributes are fixed (remembered) when a trigger is created: - character_set_client - character_set_results - collation_connection There are two triggers created in mysql-test/include/mtr_warnings.sql. They were created using "current default" character set / collation. is_triggers.test shows definition of these triggers including recorded character set information. The problem was that if "current default" changed, the recorded character set information was not accurate. There might be two ways to fix that: a) update is_triggers.test so that it does not put character-set information into result-file; b) update mtr_warnings.sql so that the triggers are created using hard-coded character sets. This patch implements option b). --- mysql-test/include/mtr_warnings.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mysql-test/include/mtr_warnings.sql b/mysql-test/include/mtr_warnings.sql index bf0a58788d6..f793ff54e86 100644 --- a/mysql-test/include/mtr_warnings.sql +++ b/mysql-test/include/mtr_warnings.sql @@ -16,6 +16,12 @@ CREATE TABLE test_suppressions ( -- no invalid patterns can be inserted -- into test_suppressions -- +SET @character_set_client_saved = @@character_set_client|| +SET @character_set_results_saved = @@character_set_results|| +SET @collation_connection_saved = @@collation_connection|| +SET @@character_set_client = latin1|| +SET @@character_set_results = latin1|| +SET @@collation_connection = latin1_swedish_ci|| /*!50002 CREATE DEFINER=root@localhost TRIGGER ts_insert BEFORE INSERT ON test_suppressions @@ -24,6 +30,9 @@ FOR EACH ROW BEGIN SELECT "" REGEXP NEW.pattern INTO dummy; END */|| +SET @@character_set_client = @character_set_client_saved|| +SET @@character_set_results = @character_set_results_saved|| +SET @@collation_connection = @collation_connection_saved|| -- @@ -38,6 +47,12 @@ CREATE TABLE global_suppressions ( -- no invalid patterns can be inserted -- into global_suppressions -- +SET @character_set_client_saved = @@character_set_client|| +SET @character_set_results_saved = @@character_set_results|| +SET @collation_connection_saved = @@collation_connection|| +SET @@character_set_client = latin1|| +SET @@character_set_results = latin1|| +SET @@collation_connection = latin1_swedish_ci|| /*!50002 CREATE DEFINER=root@localhost TRIGGER gs_insert BEFORE INSERT ON global_suppressions @@ -46,6 +61,9 @@ FOR EACH ROW BEGIN SELECT "" REGEXP NEW.pattern INTO dummy; END */|| +SET @@character_set_client = @character_set_client_saved|| +SET @@character_set_results = @character_set_results_saved|| +SET @@collation_connection = @collation_connection_saved|| From 131e3e38fd301ae9beee898eacfd8d72f7983200 Mon Sep 17 00:00:00 2001 From: Date: Sat, 16 Oct 2010 20:03:44 +0800 Subject: [PATCH 09/15] Bug#56118 STOP SLAVE does not wait till trx with CREATE TMP TABLE ends, replication aborts When recieving a 'SLAVE STOP' command, slave SQL thread will roll back the transaction and stop immidiately if there is only transactional table updated, even through 'CREATE|DROP TEMPOARY TABLE' statement are in it. But These statements can never be rolled back. Because the temporary tables to the user session mapping remain until 'RESET SLAVE', Therefore it will abort SQL thread with an error that the table already exists or doesn't exist, when it restarts and executes the whole transaction again. After this patch, SQL thread always waits till the transaction ends and then stops, if 'CREATE|DROP TEMPOARY TABLE' statement are in it. --- .../extra/rpl_tests/rpl_stop_slave.test | 61 +++++++++ mysql-test/suite/rpl/r/rpl_stop_slave.result | 127 ++++++++++++++++++ mysql-test/suite/rpl/t/rpl_stop_slave.test | 60 +++++++++ sql/slave.cc | 11 +- sql/sql_parse.cc | 10 ++ 5 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 mysql-test/extra/rpl_tests/rpl_stop_slave.test create mode 100644 mysql-test/suite/rpl/r/rpl_stop_slave.result create mode 100644 mysql-test/suite/rpl/t/rpl_stop_slave.test diff --git a/mysql-test/extra/rpl_tests/rpl_stop_slave.test b/mysql-test/extra/rpl_tests/rpl_stop_slave.test new file mode 100644 index 00000000000..7c88afe3532 --- /dev/null +++ b/mysql-test/extra/rpl_tests/rpl_stop_slave.test @@ -0,0 +1,61 @@ +# +# Auxiliary file which is used to test BUG#56118 +# +# Slave should apply all statements in the transaction before stop if any +# temporary table is created or dropped. +# +# USEAGE: +# --let $tmp_table_stm= a SQL statement +# --source extra/rpl_tests/rpl_stop_slave.test +# + +if (`SELECT "$tmp_table_stm" = ''`) +{ + --echo \$tmp_table_stm is NULL + --die $tmp_table_stm is NULL +} + +--echo +--echo [ On Master ] +connection master; +BEGIN; +DELETE FROM t1; +eval $tmp_table_stm; +INSERT INTO t1 VALUES (1); +DROP TEMPORARY TABLE tt1; +COMMIT; + +--echo +--echo [ On Slave ] +connection slave; + +# To check if slave SQL thread is applying INSERT statement +let $show_statement= SHOW PROCESSLIST; +let $field= Info; +let $condition= LIKE 'INSERT%'; +source include/wait_show_condition.inc; + +send STOP SLAVE SQL_THREAD; + +--echo +--echo [ On Slave1 ] +connection slave1; +--echo # To resume slave SQL thread +SET DEBUG_SYNC= 'now SIGNAL signal.continue'; +SET DEBUG_SYNC= 'RESET'; + +--echo +--echo [ On Slave ] +connection slave; +reap; +source include/wait_for_slave_sql_to_stop.inc; + +--echo # Slave should stop after the transaction has committed. +--echo # So t1 on master is same to t1 on slave. +let diff_table_1=master:test.t1; +let diff_table_2=slave:test.t1; +source include/diff_tables.inc; + +connection slave; +START SLAVE SQL_THREAD; +source include/wait_for_slave_sql_to_start.inc; diff --git a/mysql-test/suite/rpl/r/rpl_stop_slave.result b/mysql-test/suite/rpl/r/rpl_stop_slave.result new file mode 100644 index 00000000000..49146417ab7 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_stop_slave.result @@ -0,0 +1,127 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; + +# BUG#56118 STOP SLAVE does not wait till trx with CREATE TMP TABLE ends +# +# If a temporary table is created or dropped, the transaction should be +# regarded similarly that a non-transactional table is modified. So +# STOP SLAVE should wait until the transaction has finished. +CREATE TABLE t1(c1 INT) ENGINE=InnoDB; +CREATE TABLE t2(c1 INT) ENGINE=InnoDB; +SET DEBUG_SYNC= 'RESET'; +include/stop_slave.inc + +# Suspend the INSERT statement in current transaction on SQL thread. +# It guarantees that SQL thread is applying the transaction when +# STOP SLAVE command launchs. +SET GLOBAL debug= 'd,after_mysql_insert'; +include/start_slave.inc + +# CREATE TEMPORARY TABLE with InnoDB engine +# ----------------------------------------- + +[ On Master ] +BEGIN; +DELETE FROM t1; +CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = InnoDB; +INSERT INTO t1 VALUES (1); +DROP TEMPORARY TABLE tt1; +COMMIT; + +[ On Slave ] +STOP SLAVE SQL_THREAD; + +[ On Slave1 ] +# To resume slave SQL thread +SET DEBUG_SYNC= 'now SIGNAL signal.continue'; +SET DEBUG_SYNC= 'RESET'; + +[ On Slave ] +# Slave should stop after the transaction has committed. +# So t1 on master is same to t1 on slave. +Comparing tables master:test.t1 and slave:test.t1 +START SLAVE SQL_THREAD; + +# CREATE TEMPORARY TABLE with MyISAM engine +# ----------------------------------------- + +[ On Master ] +BEGIN; +DELETE FROM t1; +CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = MyISAM; +INSERT INTO t1 VALUES (1); +DROP TEMPORARY TABLE tt1; +COMMIT; + +[ On Slave ] +STOP SLAVE SQL_THREAD; + +[ On Slave1 ] +# To resume slave SQL thread +SET DEBUG_SYNC= 'now SIGNAL signal.continue'; +SET DEBUG_SYNC= 'RESET'; + +[ On Slave ] +# Slave should stop after the transaction has committed. +# So t1 on master is same to t1 on slave. +Comparing tables master:test.t1 and slave:test.t1 +START SLAVE SQL_THREAD; + +# CREATE TEMPORARY TABLE ... SELECT with InnoDB engine +# ---------------------------------------------------- + +[ On Master ] +BEGIN; +DELETE FROM t1; +CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = InnoDB +SELECT c1 FROM t2; +INSERT INTO t1 VALUES (1); +DROP TEMPORARY TABLE tt1; +COMMIT; + +[ On Slave ] +STOP SLAVE SQL_THREAD; + +[ On Slave1 ] +# To resume slave SQL thread +SET DEBUG_SYNC= 'now SIGNAL signal.continue'; +SET DEBUG_SYNC= 'RESET'; + +[ On Slave ] +# Slave should stop after the transaction has committed. +# So t1 on master is same to t1 on slave. +Comparing tables master:test.t1 and slave:test.t1 +START SLAVE SQL_THREAD; + +# CREATE TEMPORARY TABLE ... SELECT with MyISAM engine +# ---------------------------------------------------- + +[ On Master ] +BEGIN; +DELETE FROM t1; +CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = MyISAM +SELECT 1 AS c1; +INSERT INTO t1 VALUES (1); +DROP TEMPORARY TABLE tt1; +COMMIT; + +[ On Slave ] +STOP SLAVE SQL_THREAD; + +[ On Slave1 ] +# To resume slave SQL thread +SET DEBUG_SYNC= 'now SIGNAL signal.continue'; +SET DEBUG_SYNC= 'RESET'; + +[ On Slave ] +# Slave should stop after the transaction has committed. +# So t1 on master is same to t1 on slave. +Comparing tables master:test.t1 and slave:test.t1 +START SLAVE SQL_THREAD; +# Test end +SET GLOBAL debug= '$debug_save'; +DROP TABLE t1, t2; diff --git a/mysql-test/suite/rpl/t/rpl_stop_slave.test b/mysql-test/suite/rpl/t/rpl_stop_slave.test new file mode 100644 index 00000000000..e44cf3e94b7 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_stop_slave.test @@ -0,0 +1,60 @@ +source include/master-slave.inc; +source include/have_innodb.inc; +source include/have_debug.inc; +source include/have_debug_sync.inc; +source include/have_binlog_format_mixed_or_statement.inc; + +--echo +--echo # BUG#56118 STOP SLAVE does not wait till trx with CREATE TMP TABLE ends +--echo # +--echo # If a temporary table is created or dropped, the transaction should be +--echo # regarded similarly that a non-transactional table is modified. So +--echo # STOP SLAVE should wait until the transaction has finished. + +CREATE TABLE t1(c1 INT) ENGINE=InnoDB; +CREATE TABLE t2(c1 INT) ENGINE=InnoDB; + +sync_slave_with_master; +SET DEBUG_SYNC= 'RESET'; +source include/stop_slave.inc; + +--echo +--echo # Suspend the INSERT statement in current transaction on SQL thread. +--echo # It guarantees that SQL thread is applying the transaction when +--echo # STOP SLAVE command launchs. +let $debug_save= `SELECT @@GLOBAL.debug`; +SET GLOBAL debug= 'd,after_mysql_insert'; +source include/start_slave.inc; + +--echo +--echo # CREATE TEMPORARY TABLE with InnoDB engine +--echo # ----------------------------------------- +let $tmp_table_stm= CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = InnoDB; +source extra/rpl_tests/rpl_stop_slave.test; + +--echo +--echo # CREATE TEMPORARY TABLE with MyISAM engine +--echo # ----------------------------------------- +let $tmp_table_stm= CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = MyISAM; +source extra/rpl_tests/rpl_stop_slave.test; + +--echo +--echo # CREATE TEMPORARY TABLE ... SELECT with InnoDB engine +--echo # ---------------------------------------------------- +let $tmp_table_stm= CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = InnoDB + SELECT c1 FROM t2; +source extra/rpl_tests/rpl_stop_slave.test; + +--echo +--echo # CREATE TEMPORARY TABLE ... SELECT with MyISAM engine +--echo # ---------------------------------------------------- +let $tmp_table_stm= CREATE TEMPORARY TABLE tt1(c1 INT) ENGINE = MyISAM + SELECT 1 AS c1; +source extra/rpl_tests/rpl_stop_slave.test; + +--echo # Test end +SET GLOBAL debug= '$debug_save'; + +connection master; +DROP TABLE t1, t2; +source include/master-slave-end.inc; diff --git a/sql/slave.cc b/sql/slave.cc index 964adfdbf53..57d673ea1f4 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -740,8 +740,17 @@ static bool sql_slave_killed(THD* thd, Relay_log_info* rli) DBUG_ASSERT(rli->slave_running == 1);// tracking buffer overrun if (abort_loop || thd->killed || rli->abort_slave) { + /* + The transaction should always be binlogged if OPTION_KEEP_LOG is set + (it implies that something can not be rolled back). And such case + should be regarded similarly as modifing a non-transactional table + because retrying of the transaction will lead to an error or inconsistency + as well. + Example: OPTION_KEEP_LOG is set if a temporary table is created or dropped. + */ if (rli->abort_slave && rli->is_in_group() && - thd->transaction.all.modified_non_trans_table) + (thd->transaction.all.modified_non_trans_table || + (thd->options & OPTION_KEEP_LOG))) DBUG_RETURN(0); /* If we are in an unsafe situation (stopping could corrupt replication), diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fbe9c9753d9..b38cdf4a983 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -27,6 +27,7 @@ #include "sp_cache.h" #include "events.h" #include "sql_trigger.h" +#include "debug_sync.h" /** @defgroup Runtime_Environment Runtime Environment @@ -3258,6 +3259,15 @@ end_with_restore_list: thd->first_successful_insert_id_in_cur_stmt= thd->first_successful_insert_id_in_prev_stmt; + DBUG_EXECUTE_IF("after_mysql_insert", + { + const char act[]= + "now " + "wait_for signal.continue"; + DBUG_ASSERT(opt_debug_sync_timeout > 0); + DBUG_ASSERT(!debug_sync_set_action(current_thd, + STRING_WITH_LEN(act))); + };); break; } case SQLCOM_REPLACE_SELECT: From 08531533466732294306afe1c216f66a61b929cb Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Mon, 18 Oct 2010 13:24:34 +0200 Subject: [PATCH 10/15] Bug#52172 test binlog.binlog_index needs --skip-core-file to avoid leaving core files For crash testing: kill the server without generating core file. include/my_dbug.h Use kill(getpid(), SIGKILL) which cannot be caught by signal handlers. All DBUG_XXX macros should be no-ops in optimized mode, do that for DBUG_ABORT as well. sql/handler.cc Kill server without generating core. sql/log.cc Kill server without generating core. --- dbug/dbug.c | 8 ++++++++ include/my_dbug.h | 51 +++++++++++++++++++++++++++++++++++++++++++---- sql/handler.cc | 10 +++++----- sql/log.cc | 18 ++++++++--------- 4 files changed, 69 insertions(+), 18 deletions(-) diff --git a/dbug/dbug.c b/dbug/dbug.c index 76723fa8767..7278acca2a9 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -2267,6 +2267,14 @@ static void dbug_flush(CODE_STATE *cs) } /* dbug_flush */ +void _db_flush_() +{ + CODE_STATE *cs; + get_code_state_or_return; + (void) fflush(cs->stack->out_file); +} + + void _db_lock_file_() { CODE_STATE *cs=0; diff --git a/include/my_dbug.h b/include/my_dbug.h index 0ba72b2210d..f08e94a1882 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -13,8 +13,18 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _dbug_h -#define _dbug_h +#ifndef MY_DBUG_INCLUDED +#define MY_DBUG_INCLUDED + +#ifndef __WIN__ +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#endif /* not __WIN__ */ #if defined(__cplusplus) && !defined(DBUG_OFF) class Dbug_violation_helper @@ -69,6 +79,7 @@ extern void _db_end_(void); extern void _db_lock_file_(void); extern void _db_unlock_file_(void); extern FILE *_db_fp_(void); +extern void _db_flush_(); #ifdef __cplusplus @@ -124,6 +135,34 @@ extern FILE *_db_fp_(void); #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len)) #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) #define IF_DBUG(A) A +#ifndef __WIN__ +#define DBUG_ABORT() (_db_flush_(), abort()) +#else +/* + Avoid popup with abort/retry/ignore buttons. When BUG#31745 is fixed we can + call abort() instead of _exit(3) (now it would cause a "test signal" popup). +*/ +#include +#define DBUG_ABORT() (_db_flush_(),\ + (void)_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE),\ + (void)_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR),\ + _exit(3)) +#endif + +/* + Make the program fail, without creating a core file. + abort() will send SIGABRT which (most likely) generates core. + Use SIGKILL instead, which cannot be caught. + We also pause the current thread, until the signal is actually delivered. + An alternative would be to use _exit(EXIT_FAILURE), + but then valgrind would report lots of memory leaks. + */ +#ifdef __WIN__ +#define DBUG_SUICIDE() DBUG_ABORT() +#else +#define DBUG_SUICIDE() (_db_flush_(), kill(getpid(), SIGKILL), pause()) +#endif + #else /* No debugger */ #define DBUG_ENTER(a1) @@ -152,8 +191,12 @@ extern FILE *_db_fp_(void); #define DBUG_EXPLAIN(buf,len) #define DBUG_EXPLAIN_INITIAL(buf,len) #define IF_DBUG(A) +#define DBUG_ABORT() do { } while(0) +#define DBUG_SUICIDE() do { } while(0) + #endif #ifdef __cplusplus } #endif -#endif + +#endif /* MY_DBUG_INCLUDED */ diff --git a/sql/handler.cc b/sql/handler.cc index 19f397ef09f..a47a5fd8a3c 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1127,7 +1127,7 @@ int ha_commit_trans(THD *thd, bool all) uint rw_ha_count; bool rw_trans; - DBUG_EXECUTE_IF("crash_commit_before", abort();); + DBUG_EXECUTE_IF("crash_commit_before", DBUG_SUICIDE();); /* Close all cursors that can not survive COMMIT */ if (is_real_trans) /* not a statement commit */ @@ -1179,7 +1179,7 @@ int ha_commit_trans(THD *thd, bool all) } status_var_increment(thd->status_var.ha_prepare_count); } - DBUG_EXECUTE_IF("crash_commit_after_prepare", abort();); + DBUG_EXECUTE_IF("crash_commit_after_prepare", DBUG_SUICIDE();); if (error || (is_real_trans && xid && (error= !(cookie= tc_log->log_xid(thd, xid))))) { @@ -1187,13 +1187,13 @@ int ha_commit_trans(THD *thd, bool all) error= 1; goto end; } - DBUG_EXECUTE_IF("crash_commit_after_log", abort();); + DBUG_EXECUTE_IF("crash_commit_after_log", DBUG_SUICIDE();); } error=ha_commit_one_phase(thd, all) ? (cookie ? 2 : 1) : 0; - DBUG_EXECUTE_IF("crash_commit_before_unlog", abort();); + DBUG_EXECUTE_IF("crash_commit_before_unlog", DBUG_SUICIDE();); if (cookie) tc_log->unlog(cookie, xid); - DBUG_EXECUTE_IF("crash_commit_after", abort();); + DBUG_EXECUTE_IF("crash_commit_after", DBUG_SUICIDE();); end: if (rw_trans) start_waiting_global_read_lock(thd); diff --git a/sql/log.cc b/sql/log.cc index 56f151fe2ab..2d5b62a5b2b 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2600,7 +2600,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, sql_print_error("MSYQL_BIN_LOG::open failed to sync the index file."); DBUG_RETURN(1); } - DBUG_EXECUTE_IF("crash_create_non_critical_before_update_index", abort();); + DBUG_EXECUTE_IF("crash_create_non_critical_before_update_index", DBUG_SUICIDE();); #endif write_error= 0; @@ -2697,7 +2697,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, if (write_file_name_to_index_file) { #ifdef HAVE_REPLICATION - DBUG_EXECUTE_IF("crash_create_critical_before_update_index", abort();); + DBUG_EXECUTE_IF("crash_create_critical_before_update_index", DBUG_SUICIDE();); #endif DBUG_ASSERT(my_b_inited(&index_file) != 0); @@ -2716,7 +2716,7 @@ bool MYSQL_BIN_LOG::open(const char *log_name, goto err; #ifdef HAVE_REPLICATION - DBUG_EXECUTE_IF("crash_create_after_update_index", abort();); + DBUG_EXECUTE_IF("crash_create_after_update_index", DBUG_SUICIDE();); #endif } } @@ -3168,7 +3168,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included) /* Store where we are in the new file for the execution thread */ flush_relay_log_info(rli); - DBUG_EXECUTE_IF("crash_before_purge_logs", abort();); + DBUG_EXECUTE_IF("crash_before_purge_logs", DBUG_SUICIDE();); pthread_mutex_lock(&rli->log_space_lock); rli->relay_log.purge_logs(to_purge_if_included, included, @@ -3296,7 +3296,7 @@ int MYSQL_BIN_LOG::purge_logs(const char *to_log, break; } - DBUG_EXECUTE_IF("crash_purge_before_update_index", abort();); + DBUG_EXECUTE_IF("crash_purge_before_update_index", DBUG_SUICIDE();); if ((error= sync_purge_index_file())) { @@ -3311,7 +3311,7 @@ int MYSQL_BIN_LOG::purge_logs(const char *to_log, goto err; } - DBUG_EXECUTE_IF("crash_purge_critical_after_update_index", abort();); + DBUG_EXECUTE_IF("crash_purge_critical_after_update_index", DBUG_SUICIDE();); err: /* Read each entry from purge_index_file and delete the file. */ @@ -3321,7 +3321,7 @@ err: " that would be purged."); close_purge_index_file(); - DBUG_EXECUTE_IF("crash_purge_non_critical_after_update_index", abort();); + DBUG_EXECUTE_IF("crash_purge_non_critical_after_update_index", DBUG_SUICIDE();); if (need_mutex) pthread_mutex_unlock(&LOCK_index); @@ -4832,7 +4832,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, DBUG_PRINT("info", ("error writing binlog cache: %d", write_error)); DBUG_PRINT("info", ("crashing before writing xid")); - abort(); + DBUG_SUICIDE(); }); if ((write_error= write_cache(cache, false, false))) @@ -4846,7 +4846,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event, if (flush_and_sync()) goto err; - DBUG_EXECUTE_IF("half_binlogged_transaction", abort();); + DBUG_EXECUTE_IF("half_binlogged_transaction", DBUG_SUICIDE();); if (cache->error) // Error on read { sql_print_error(ER(ER_ERROR_ON_READ), cache->file_name, errno); From 990771432a1da7abc51fc6d6818ef92818177851 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Mon, 18 Oct 2010 21:03:53 +0700 Subject: [PATCH 11/15] Follow up for bug#36742. Changed test case for bug#19828 because currently hostname stored in db in lowercase. --- mysql-test/r/grant3.result | 25 +++++-------------------- mysql-test/t/grant3.test | 5 +++++ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/mysql-test/r/grant3.result b/mysql-test/r/grant3.result index 59c64ee84ae..fd51a83d4b2 100644 --- a/mysql-test/r/grant3.result +++ b/mysql-test/r/grant3.result @@ -21,123 +21,108 @@ grant select on test.* to CUser@LOCALHOST; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser' order by 1,2; user host db select_priv -CUser LOCALHOST test Y CUser localhost test Y REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'CUser'@'LOCALHOST'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser' order by 1,2; user host db select_priv -CUser localhost test Y REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'CUser'@'localhost'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser' order by 1,2; user host db select_priv DROP USER CUser@localhost; DROP USER CUser@LOCALHOST; +ERROR HY000: Operation DROP USER failed for 'CUser'@'localhost' create table t1 (a int); grant select on test.t1 to CUser@localhost; grant select on test.t1 to CUser@LOCALHOST; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; user host db Table_name Table_priv Column_priv -CUser LOCALHOST test t1 Select CUser localhost test t1 Select REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'CUser'@'LOCALHOST'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; user host db Table_name Table_priv Column_priv -CUser localhost test t1 Select REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'CUser'@'localhost'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; user host db Table_name Table_priv Column_priv DROP USER CUser@localhost; DROP USER CUser@LOCALHOST; +ERROR HY000: Operation DROP USER failed for 'CUser'@'localhost' grant select(a) on test.t1 to CUser@localhost; grant select(a) on test.t1 to CUser@LOCALHOST; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; user host db Table_name Table_priv Column_priv -CUser LOCALHOST test t1 Select CUser localhost test t1 Select REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'CUser'@'LOCALHOST'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; user host db Table_name Table_priv Column_priv -CUser localhost test t1 Select REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'CUser'@'localhost'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; user host -CUser LOCALHOST CUser localhost SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; user host db Table_name Table_priv Column_priv DROP USER CUser@localhost; DROP USER CUser@LOCALHOST; +ERROR HY000: Operation DROP USER failed for 'CUser'@'localhost' drop table t1; grant select on test.* to CUser2@localhost; grant select on test.* to CUser2@LOCALHOST; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser2' order by 1,2; user host -CUser2 LOCALHOST CUser2 localhost SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser2' order by 1,2; user host db select_priv -CUser2 LOCALHOST test Y CUser2 localhost test Y REVOKE SELECT ON test.* FROM 'CUser2'@'LOCALHOST'; flush privileges; SELECT user, host FROM mysql.user where user = 'CUser2' order by 1,2; user host -CUser2 LOCALHOST CUser2 localhost SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser2' order by 1,2; user host db select_priv -CUser2 localhost test Y REVOKE SELECT ON test.* FROM 'CUser2'@'localhost'; +ERROR 42000: There is no such grant defined for user 'CUser2' on host 'localhost' flush privileges; SELECT user, host FROM mysql.user where user = 'CUser2' order by 1,2; user host -CUser2 LOCALHOST CUser2 localhost SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser2' order by 1,2; user host db select_priv DROP USER CUser2@localhost; DROP USER CUser2@LOCALHOST; +ERROR HY000: Operation DROP USER failed for 'CUser2'@'localhost' CREATE DATABASE mysqltest_1; CREATE TABLE mysqltest_1.t1 (a INT); CREATE USER 'mysqltest1'@'%'; diff --git a/mysql-test/t/grant3.test b/mysql-test/t/grant3.test index 437fc9a278f..d24b2de17eb 100644 --- a/mysql-test/t/grant3.test +++ b/mysql-test/t/grant3.test @@ -64,6 +64,7 @@ SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser' order by 1,2; DROP USER CUser@localhost; +--error ER_CANNOT_USER DROP USER CUser@LOCALHOST; #### table grants @@ -88,6 +89,7 @@ SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; DROP USER CUser@localhost; +--error ER_CANNOT_USER DROP USER CUser@LOCALHOST; ### column grants @@ -112,6 +114,7 @@ SELECT user, host FROM mysql.user where user = 'CUser' order by 1,2; SELECT user, host, db, Table_name, Table_priv, Column_priv FROM mysql.tables_priv where user = 'CUser' order by 1,2; DROP USER CUser@localhost; +--error ER_CANNOT_USER DROP USER CUser@LOCALHOST; drop table t1; @@ -131,6 +134,7 @@ flush privileges; SELECT user, host FROM mysql.user where user = 'CUser2' order by 1,2; SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser2' order by 1,2; +--error ER_NONEXISTING_GRANT REVOKE SELECT ON test.* FROM 'CUser2'@'localhost'; flush privileges; @@ -138,6 +142,7 @@ SELECT user, host FROM mysql.user where user = 'CUser2' order by 1,2; SELECT user, host, db, select_priv FROM mysql.db where user = 'CUser2' order by 1,2; DROP USER CUser2@localhost; +--error ER_CANNOT_USER DROP USER CUser2@LOCALHOST; From ff72d36125e0faf3f2bfc3f7f4eb0182d13b527b Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Mon, 18 Oct 2010 23:20:26 +0700 Subject: [PATCH 12/15] Follow-up for bug#36742: changed results for test ipv4_as_ipv6 because hostname is case-insensitive. --- mysql-test/r/ipv4_as_ipv6.result | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mysql-test/r/ipv4_as_ipv6.result b/mysql-test/r/ipv4_as_ipv6.result index 8523dc82f02..82bca393d71 100644 --- a/mysql-test/r/ipv4_as_ipv6.result +++ b/mysql-test/r/ipv4_as_ipv6.result @@ -32,9 +32,9 @@ mysqld is alive CREATE USER testuser@'0:0:0:0:0:FFFF:127.0.0.1' identified by '1234'; GRANT ALL ON test.* TO testuser@'0:0:0:0:0:FFFF:127.0.0.1'; SHOW GRANTS FOR testuser@'0:0:0:0:0:FFFF:127.0.0.1'; -Grants for testuser@0:0:0:0:0:FFFF:127.0.0.1 -GRANT USAGE ON *.* TO 'testuser'@'0:0:0:0:0:FFFF:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' -GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0:0:0:0:FFFF:127.0.0.1' +Grants for testuser@0:0:0:0:0:ffff:127.0.0.1 +GRANT USAGE ON *.* TO 'testuser'@'0:0:0:0:0:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' +GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0:0:0:0:ffff:127.0.0.1' SET @nip= inet_aton('0:0:0:0:0:FFFF:127.0.0.1'); SELECT @nip; @nip @@ -61,9 +61,9 @@ mysqld is alive CREATE USER testuser@'0000:0000:0000:0000:0000:FFFF:127.0.0.1' identified by '1234'; GRANT ALL ON test.* TO testuser@'0000:0000:0000:0000:0000:FFFF:127.0.0.1'; SHOW GRANTS FOR testuser@'0000:0000:0000:0000:0000:FFFF:127.0.0.1'; -Grants for testuser@0000:0000:0000:0000:0000:FFFF:127.0.0.1 -GRANT USAGE ON *.* TO 'testuser'@'0000:0000:0000:0000:0000:FFFF:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' -GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0000:0000:0000:0000:0000:FFFF:127.0.0.1' +Grants for testuser@0000:0000:0000:0000:0000:ffff:127.0.0.1 +GRANT USAGE ON *.* TO 'testuser'@'0000:0000:0000:0000:0000:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' +GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0000:0000:0000:0000:0000:ffff:127.0.0.1' SET @nip= inet_aton('0000:0000:0000:0000:0000:FFFF:127.0.0.1'); SELECT @nip; @nip @@ -90,9 +90,9 @@ mysqld is alive CREATE USER testuser@'0:0000:0000:0:0000:FFFF:127.0.0.1' identified by '1234'; GRANT ALL ON test.* TO testuser@'0:0000:0000:0:0000:FFFF:127.0.0.1'; SHOW GRANTS FOR testuser@'0:0000:0000:0:0000:FFFF:127.0.0.1'; -Grants for testuser@0:0000:0000:0:0000:FFFF:127.0.0.1 -GRANT USAGE ON *.* TO 'testuser'@'0:0000:0000:0:0000:FFFF:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' -GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0000:0000:0:0000:FFFF:127.0.0.1' +Grants for testuser@0:0000:0000:0:0000:ffff:127.0.0.1 +GRANT USAGE ON *.* TO 'testuser'@'0:0000:0000:0:0000:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' +GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0:0000:0000:0:0000:ffff:127.0.0.1' SET @nip= inet_aton('0:0000:0000:0:0000:FFFF:127.0.0.1'); SELECT @nip; @nip @@ -119,9 +119,9 @@ mysqld is alive CREATE USER testuser@'0::0000:FFFF:127.0.0.1' identified by '1234'; GRANT ALL ON test.* TO testuser@'0::0000:FFFF:127.0.0.1'; SHOW GRANTS FOR testuser@'0::0000:FFFF:127.0.0.1'; -Grants for testuser@0::0000:FFFF:127.0.0.1 -GRANT USAGE ON *.* TO 'testuser'@'0::0000:FFFF:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' -GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0::0000:FFFF:127.0.0.1' +Grants for testuser@0::0000:ffff:127.0.0.1 +GRANT USAGE ON *.* TO 'testuser'@'0::0000:ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' +GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'0::0000:ffff:127.0.0.1' SET @nip= inet_aton('0::0000:FFFF:127.0.0.1'); SELECT @nip; @nip @@ -149,9 +149,9 @@ mysqld is alive CREATE USER testuser@'::FFFF:127.0.0.1' identified by '1234'; GRANT ALL ON test.* TO testuser@'::FFFF:127.0.0.1'; SHOW GRANTS FOR testuser@'::FFFF:127.0.0.1'; -Grants for testuser@::FFFF:127.0.0.1 -GRANT USAGE ON *.* TO 'testuser'@'::FFFF:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' -GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'::FFFF:127.0.0.1' +Grants for testuser@::ffff:127.0.0.1 +GRANT USAGE ON *.* TO 'testuser'@'::ffff:127.0.0.1' IDENTIFIED BY PASSWORD '*A4B6157319038724E3560894F7F932C8886EBFCF' +GRANT ALL PRIVILEGES ON `test`.* TO 'testuser'@'::ffff:127.0.0.1' SET @nip= inet_aton('::FFFF:127.0.0.1'); SELECT @nip; @nip From c474fcfab93cdfc24155f5bbd4be24e8de519df9 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Mon, 18 Oct 2010 14:27:10 -0200 Subject: [PATCH 13/15] Bug#45288: pb2 returns a lot of compilation warnings on linux Enable the MySQL maintainer-specific development environment (which add various warning related options to the compiler flags) if debugging support is enabled. --- config/ac-macros/maintainer.m4 | 3 ++- configure.in | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config/ac-macros/maintainer.m4 b/config/ac-macros/maintainer.m4 index 24be31395f2..5960853d7f1 100644 --- a/config/ac-macros/maintainer.m4 +++ b/config/ac-macros/maintainer.m4 @@ -8,7 +8,8 @@ AC_DEFUN([MY_MAINTAINER_MODE], [ [AS_HELP_STRING([--enable-mysql-maintainer-mode], [Enable a MySQL maintainer-specific development environment])], [USE_MYSQL_MAINTAINER_MODE=$enableval], - [USE_MYSQL_MAINTAINER_MODE=no]) + [AS_IF([test "$with_debug" != "no"], + [USE_MYSQL_MAINTAINER_MODE=yes], [USE_MYSQL_MAINTAINER_MODE=no])]) AC_MSG_RESULT([$USE_MYSQL_MAINTAINER_MODE]) ]) diff --git a/configure.in b/configure.in index c1672557bd1..09885dbbae7 100644 --- a/configure.in +++ b/configure.in @@ -103,6 +103,13 @@ AC_SUBST(SHARED_LIB_MAJOR_VERSION) AC_SUBST(SHARED_LIB_VERSION) AC_SUBST(AVAILABLE_LANGUAGES) +# Check whether a debug mode should be enabled. +AC_ARG_WITH([debug], + AS_HELP_STRING([--with-debug@<:@=full@:>@], + [Enable various amounts of debugging support (full adds a slow memory checker).]), + [with_debug=$withval], + [with_debug=no]) + # Whether the maintainer mode should be enabled. MY_MAINTAINER_MODE @@ -1674,11 +1681,6 @@ then DEBUG_OPTIMIZE_CXX="" fi -AC_ARG_WITH(debug, - [ --with-debug Add debug code - --with-debug=full Add debug code (adds memory checker, very slow)], - [with_debug=$withval], - [with_debug=no]) if test "$with_debug" = "yes" then # Medium debug. From a3357b55c2aa7e89c58291618ce99aa347d3f3f2 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Tue, 19 Oct 2010 09:06:48 +0200 Subject: [PATCH 14/15] Bug#52172 post-push fix: init auto-variable to NULL --- dbug/dbug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbug/dbug.c b/dbug/dbug.c index 7278acca2a9..e5e11d5be00 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -2269,7 +2269,7 @@ static void dbug_flush(CODE_STATE *cs) void _db_flush_() { - CODE_STATE *cs; + CODE_STATE *cs= NULL; get_code_state_or_return; (void) fflush(cs->stack->out_file); } From 6da8a65bf0ebeb74f8fdd9a83c8650745e811aaa Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Tue, 19 Oct 2010 10:19:57 +0200 Subject: [PATCH 15/15] Bug #57274 SET GLOBAL debug crashes on Solaris in embedded server mode (variables_debug fails) The problem was that "SET GLOBAL debug" could cause a crash on Solaris. The crash happened if the server failed to open the trace file given in the "SET GLOBAL debug" statement. This caused an error message to be printed to stderr containing the process name. However, printing to stderr crashed the server since the pointer to the process name had not been initialized. This patch fixes the problem by initializing the process name properly when doing "SET GLOBAL debug". No test case added as this bug was repeatable with existing test coverage in variables_debug.test. --- dbug/dbug.c | 1 + 1 file changed, 1 insertion(+) diff --git a/dbug/dbug.c b/dbug/dbug.c index e5e11d5be00..fecdd4f8a6c 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -744,6 +744,7 @@ void _db_set_init_(const char *control) CODE_STATE tmp_cs; bzero((uchar*) &tmp_cs, sizeof(tmp_cs)); tmp_cs.stack= &init_settings; + tmp_cs.process= db_process ? db_process : "dbug"; DbugParse(&tmp_cs, control); }