mariadb/mysql-test/t/merge-big.test
Konstantin Osipov 7f628ac2dd Backport of:
----------------------------------------------------------
revno: 2630.4.38
committer: Konstantin Osipov <konstantin@mysql.com>
branch nick: mysql-6.0-4144
timestamp: Wed 2008-06-25 22:07:06 +0400
message:
  WL#4144 - Lock MERGE engine children.
  Committing a version of the patch merged with WL#3726
  on behalf of Ingo.

  Step #1: Move locking from parent to children.

  MERGE children are now left in the query list of tables
  after inserted there in open_tables(). So they are locked
  by lock_tables() as all other tables are.

  The MERGE parent does not store locks any more. It appears
  in a MYSQL_LOCK with zero lock data. This is kind of a "dummy"
  lock.

  All other lock handling is also done directly on the children.
  To protect against parent or child modifications during LOCK
  TABLES, the children are detached after every statement and
  attached before every statement, even under LOCK TABLES.

  The children table list is removed from the query list of tables
  on every detach and on close of the parent.

  Step #2: Move MERGE specific functionality from SQL layer
  into table handler.

  Functionality moved from SQL layer (mainly sql_base.cc)
  to the table handler (ha_myisammrg.cc).

  Unnecessary code is removed from the SQL layer.

  Step #3: Moved all MERGE specific members from TABLE
  to ha_myisammrg.

  Moved members from TABLE to ha_myisammrg.
  Renamed some mebers.
  Fixed comments.

  Step #4: Valgrind and coverage testing

  Valgrind did not uncover new problems.
  Added purecov comments.

  Added a new test for DATA/INDEX DIRECTORY options.
  Changed handling of ::reset() for non-attached children.
  Fixed the merge-big test.

  Step #5: Fixed crashes detected during review
  Changed detection when to attach/detach.
  Added new tests.

Backport also the fix for Bug#44040 "MySQL allows creating a 
MERGE table upon VIEWs but crashes when using it"


include/my_base.h:
  WL#4144 - Lock MERGE engine children
  Added HA_EXTRA_ADD_CHILDREN_LIST and HA_EXTRA_IS_ATTACHED_CHILDREN
  for MERGE table support
mysql-test/r/merge.result:
  WL#4144 - Lock MERGE engine children
  Fixed test result.
mysql-test/t/disabled.def:
  Enable merge.test, which now is working again (WL#4144).
mysql-test/t/merge-big.test:
  Fix the messages for wait_condition (merge with WL#3726).
mysql-test/t/merge.test:
  WL#4144 - Lock MERGE engine children
  Fixed one test to meet coding standards for tests
  (upper case keywords, engine names as in SHOW ENGINES).
  Fixed error codes.
  Added a test for DATA/INDEX DIRECTORY.
mysys/thr_lock.c:
  WL#4144 - Lock MERGE engine children
  Added purecov comments.
sql/ha_partition.cc:
  WL#4144 - Lock MERGE engine children
  Added MERGE specific extra operations to ha_partition::extra().
  Extended comments.
  Changed function comment to doxygen style.
  Fixed nomenclature: 'parameter' -> 'operation'.
sql/mysql_priv.h:
  WL#4144 - Lock MERGE engine children
  Removed declarations for removed functions.
sql/sql_base.cc:
  WL#4144 - Lock MERGE engine children
  Leave the children in the query list of tables after open_tables().
  Set proper back links (prev_global).
  Attach MERGE children before and detach them after every
  statement. Even under LOCK TABLES.
  Remove children from the query list when they are detached.
  Remove lock forwarding from children to parent.
  Moved MERGE specific functions to ha_myisammrg.cc.
  Added purecov comments.
  Backport the fix for Bug#44040 "MySQL allows creating a MERGE table upon VIEWs but crashes when using it"
sql/sql_table.cc:
  WL#4144 - Lock MERGE engine children
  Changed detection of MERGE tables.
sql/table.cc:
  WL#4144 - Lock MERGE engine children
  Moved is_children_attached() method from TABLE to ha_myisammrg.
sql/table.h:
  WL#4144 - Lock MERGE engine children
  Moved all MERGE specific members from TABLE to ha_myisammrg.
storage/myisammrg/ha_myisammrg.cc:
  WL#4144 - Lock MERGE engine children
  Set proper back links in the child list (prev_global).
  Added a function for removal of the child list from the query list.
  Remove children from the query list when the parent is closed.
  Make parent lock handling a dummy (zero locks).
  Moved MERGE specific functionality from SQL layer to here.
  Moved all MERGE specific members from TABLE to ha_myisammrg.
  Renamed children list pointers.
  Added initialization and free for the children list mem_root.
  Fixed comments.
  Added purecov comments.
storage/myisammrg/ha_myisammrg.h:
  WL#4144 - Lock MERGE engine children
  Added method add_children_list().
  Moved all MERGE specific members from TABLE to ha_myisammrg.
  Renamed children list pointers.
  Added a mem_root for the children list.
storage/myisammrg/myrg_extra.c:
  WL#4144 - Lock MERGE engine children
  Changed handling of ::reset() for non-attached children.
2009-12-03 02:09:22 +03:00

82 lines
3 KiB
Text

#
# Test of MERGE tables with multisession and many waits.
#
# This test takes rather long time so let us run it only in --big-test mode
--source include/big_test.inc
# We use some debug-only features in this test
--source include/have_debug.inc
# We use INFORMATION_SCHEMA.PROCESSLIST in this test
--source include/not_embedded.inc
--disable_warnings
drop table if exists t1,t2,t3,t4,t5,t6;
--enable_warnings
--echo #
--echo # Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE
--echo # corrupts a MERGE table
--echo # Problem #3
--echo #
# Two FLUSH TABLES within a LOCK TABLES segment could invalidate the lock.
# This did *not* require a MERGE table.
#
# To increase reproducibility it was necessary to enter a sleep of 2
# seconds at the end of wait_for_tables() after unlock of LOCK_open. In
# 5.0 and 5.1 the sleep must be inserted in open_and_lock_tables() after
# open_tables() instead. wait_for_tables() is not used in this case. The
# problem was that FLUSH TABLES releases LOCK_open while having unlocked
# and closed all tables. When this happened while a thread was in the
# loop in mysql_lock_tables() right after wait_for_tables()
# (open_tables()) and before retrying to lock, the thread got the lock.
# And it did not notice that the table needed a refresh after the
# [re-]open. So it executed its statement on the table.
#
# The first FLUSH TABLES kicked the INSERT out of thr_multi_lock() and
# let it wait in wait_for_tables() (open_table()). The second FLUSH
# TABLES must happen while the INSERT was on its way from
# wait_for_tables() (open_table()) to the next call of thr_multi_lock().
# This needed to be supported by a sleep to make it repeatable.
#
CREATE TABLE t1 (c1 INT) ENGINE= MyISAM;
LOCK TABLE t1 WRITE;
#SELECT NOW();
--echo # connection con1
connect (con1,localhost,root,,);
let $con1_id= `SELECT CONNECTION_ID()`;
SET SESSION debug="+d,sleep_open_and_lock_after_open";
send INSERT INTO t1 VALUES (1);
--echo # connection default
connection default;
--echo # Let INSERT go into thr_multi_lock().
#--sleep 8
#SELECT ID,STATE,INFO FROM INFORMATION_SCHEMA.PROCESSLIST;
let $wait_condition= SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE ID = $con1_id AND STATE = 'Table lock';
--source include/wait_condition.inc
#SELECT NOW();
--echo # Kick INSERT out of thr_multi_lock().
FLUSH TABLES;
#SELECT NOW();
--echo # Let INSERT go through open_tables() where it sleeps.
#--sleep 8
#SELECT ID,STATE,INFO FROM INFORMATION_SCHEMA.PROCESSLIST;
let $wait_condition= SELECT 1 FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE ID = $con1_id AND STATE = 'Table lock';
--source include/wait_condition.inc
#SELECT NOW();
--echo # Unlock and close table and wait for con1 to close too.
FLUSH TABLES;
#SELECT NOW();
--echo # This should give no result.
SELECT * FROM t1;
#SELECT NOW();
UNLOCK TABLES;
--echo # connection con1
connection con1;
reap;
SET SESSION debug="-d,sleep_open_and_lock_after_open";
disconnect con1;
--echo # connection default
connection default;
DROP TABLE t1;