#At file:///export/home/z/mysql-next-bugfixing-bug42074/ based on revid:alik@stripped
2857 Jon Olav Hauglid 2009-09-16
Bug #42074 concurrent optimize table and
alter table = Assertion failed: thd->is_error()
This assertion could occur if OPTIMIZE TABLE was started on a InnoDB table
and the table was altered to different storage engine after OPTIMIZE
had started. This allowed OPTIMIZE to pass the initial checks for
storage engine support, but fail once it reached "recreate+analyze"
if this operation was not supported by the new storage engine.
The bug had no consequences for non-debug builds of the server.
In detail, the assertion was triggered when ha_analyze() returned
HA_ADMIN_NOT_IMPLEMENTED. This led to a code path which included an
assert checking for diagnostics area contents. Since this area had
not been filled, the assertion was triggered. The diagnostics area
is in this case only used to provide more detailed information about
why optimize failed. The triggered code path sends this information
to the client and clears the diagnostic area.
This patch fixed the problem by adding an error message to the diagnostic
area if ha_analyze() fails. This error message contains the error code
returned by ha_analyze().
Test case added to innodb_mysql_sync.test.
added:
mysql-test/r/innodb_mysql_sync.result
mysql-test/t/innodb_mysql_sync.test
modified:
sql/sql_table.cc
=== added file 'mysql-test/r/innodb_mysql_sync.result'
--- a/mysql-test/r/innodb_mysql_sync.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_mysql_sync.result 2009-09-16 09:24:31 +0000
@@ -0,0 +1,26 @@
+#
+# Bug 42074 concurrent optimize table and
+# alter table = Assertion failed: thd->is_error()
+#
+DROP TABLE IF EXISTS t1;
+# Create InnoDB table
+CREATE TABLE t1 (id INT) engine=innodb;
+# Connection 1
+# Start optimizing table
+SET DEBUG_SYNC='ha_admin_try_alter SIGNAL optimize_started WAIT_FOR table_altered';
+OPTIMIZE TABLE t1;
+# Connection 2
+# Change table to engine=memory
+SET DEBUG_SYNC='now WAIT_FOR optimize_started';
+ALTER TABLE t1 engine=memory;
+SET DEBUG_SYNC='now SIGNAL table_altered';
+# Connection 1
+# Complete optimization
+Table Op Msg_type Msg_text
+test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
+test.t1 optimize error Got error -1 from storage engine
+test.t1 optimize status Operation failed
+Warnings:
+Error 1030 Got error -1 from storage engine
+DROP TABLE t1;
+SET DEBUG_SYNC='RESET';
=== added file 'mysql-test/t/innodb_mysql_sync.test'
--- a/mysql-test/t/innodb_mysql_sync.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_mysql_sync.test 2009-09-16 09:24:31 +0000
@@ -0,0 +1,48 @@
+#
+# Test file for InnoDB tests that require the debug sync facility
+#
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+
+--echo #
+--echo # Bug 42074 concurrent optimize table and
+--echo # alter table = Assertion failed: thd->is_error()
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--echo # Create InnoDB table
+CREATE TABLE t1 (id INT) engine=innodb;
+connect (con2, localhost, root);
+
+--echo # Connection 1
+--echo # Start optimizing table
+connection default;
+SET DEBUG_SYNC='ha_admin_try_alter SIGNAL optimize_started WAIT_FOR table_altered';
+--send OPTIMIZE TABLE t1
+
+--echo # Connection 2
+--echo # Change table to engine=memory
+connection con2;
+SET DEBUG_SYNC='now WAIT_FOR optimize_started';
+ALTER TABLE t1 engine=memory;
+SET DEBUG_SYNC='now SIGNAL table_altered';
+
+--echo # Connection 1
+--echo # Complete optimization
+connection default;
+--reap
+
+disconnect con2;
+DROP TABLE t1;
+SET DEBUG_SYNC='RESET';
+
+
+# Check that all connections opened by test cases in this file are really
+# gone so execution of other tests won't be affected by their presence.
+--source include/wait_until_count_sessions.inc
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2009-09-16 08:23:16 +0000
+++ b/sql/sql_table.cc 2009-09-16 09:24:31 +0000
@@ -4842,6 +4842,7 @@ send_result_message:
close_thread_tables(thd);
if (!thd->locked_tables_mode)
thd->mdl_context.release_all_locks();
+ DEBUG_SYNC(thd, "ha_admin_try_alter");
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
protocol->store(STRING_WITH_LEN(
"Table does not support optimize, doing recreate + analyze instead"),
@@ -4875,6 +4876,8 @@ send_result_message:
if ((table->table= open_ltable(thd, table, lock_type, 0)) &&
((result_code= table->table->file->ha_analyze(thd, check_opt)) > 0))
result_code= 0; // analyze went ok
+ if (result_code) // analyze failed
+ table->table->file->print_error(result_code, MYF(0));
}
/* Start a new row for the final status row */
protocol->prepare_for_resend();
Attachment: [text/bzr-bundle] bzr/jon.hauglid@sun.com-20090916092431-d00gx36ggv747ifj.bundle
Thread |
---|
• bzr commit into mysql-5.4 branch (jon.hauglid:2857) Bug#42074 | Jon Olav Hauglid | 16 Sep |