List:Commits« Previous MessageNext Message »
From:Rafal Somla Date:February 11 2009 1:11pm
Subject:bzr commit into mysql-6.0-backup branch (Rafal.Somla:2765) Bug#32702
View as plain text  
#At file:///ext/mysql/bzr/backup/bug32702/

 2765 Rafal Somla	2009-02-11
      BUG#32702 - Backup: DDL blocker does not block all it should
      
      After this patch, the DDL blocker will be renamed to Backup Metadata Lock and 
      will block all the statements listed in WL#4644. Test backup_ddl_blocker will be 
      renamed to backup_bml and extended to test all these statements.
      
      This patch implements desing described in WL#4644. It marks all statements which 
      need to be blocked by BML with special CF_BLOCKED_BY_BML flag. Then registering 
      and unregistering marked statements with BML is done globally in 
      mysql_execute_command(). 
      
      This makes changes in the parser code minimal, makes it easy to trace the list 
      of statements which ale blocked and easily ensures that each bml_enter() call is 
      matched with bml_leave().
added:
  mysql-test/suite/backup/include/
  mysql-test/suite/backup/include/bml_test.inc
renamed:
  mysql-test/suite/backup/r/backup_ddl_blocker.result => mysql-test/suite/backup/r/backup_bml.result
  mysql-test/suite/backup/t/backup_ddl_blocker.test => mysql-test/suite/backup/t/backup_bml.test
  sql/ddl_blocker.cc => sql/bml.cc
  sql/ddl_blocker.h => sql/bml.h
modified:
  libmysqld/Makefile.am
  mysql-test/suite/backup/r/backup_timeout.result
  mysql-test/suite/backup/t/backup_timeout.test
  mysql-test/suite/backup/t/disabled.def
  sql/CMakeLists.txt
  sql/Makefile.am
  sql/backup/backup_aux.h
  sql/backup/backup_engine.h
  sql/backup/backup_kernel.h
  sql/backup/be_default.cc
  sql/backup/be_nodata.cc
  sql/backup/be_nodata.h
  sql/backup/be_snapshot.cc
  sql/backup/be_thread.cc
  sql/backup/kernel.cc
  sql/backup/logger.h
  sql/mysqld.cc
  sql/si_objects.cc
  sql/si_objects.h
  sql/sql_class.cc
  sql/sql_class.h
  sql/sql_parse.cc
  mysql-test/suite/backup/r/backup_bml.result
  mysql-test/suite/backup/t/backup_bml.test
  sql/bml.cc
  sql/bml.h

per-file messages:
  mysql-test/suite/backup/include/bml_test.inc
    A "subroutine" for backup_bml.test.
  mysql-test/suite/backup/t/backup_bml.test
    Refactored and extended with all DDL statements which are blocked by BML.
  mysql-test/suite/backup/t/backup_timeout.test
    Remove references to "DDL blocker" and update synchronization point names.
  mysql-test/suite/backup/t/disabled.def
    No need to disable backup_ddl_blocker any more.
  sql/CMakeLists.txt
    Rename ddl_blocker.{h,cc} -> bml.{h,cc}.
  sql/Makefile.am
    Rename ddl_blocker.{h,cc} -> bml.{h,cc}.
  sql/backup/backup_aux.h
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/backup_engine.h
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/backup_kernel.h
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/be_default.cc
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/be_nodata.cc
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/be_nodata.h
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/be_snapshot.cc
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/be_thread.cc
    Do not use "online backup" name, but "MySQL backup".
  sql/backup/kernel.cc
    - Add new sync. points "after_backup_restore_prepare" and "start_do_restore" 
      (needed in backup_bml.test).
    - Do not use "online backup" name, but "MySQL backup".
  sql/backup/logger.h
    Do not use "online backup" name, but "MySQL backup".
  sql/bml.cc
    Rename "DDL blocker" -> "Backup Metadata Lock":
    - change class and member names.
    - update documentation.
  sql/bml.h
    Rename "DDL blocker" -> "Backup Metadata Lock":
    - change class and member names.
    - update documentation.
  sql/mysqld.cc
    Rename "DDL blocker" -> "Backup Metadata Lock".
  sql/si_objects.cc
    Rename "DDL blocker" -> "Backup Metadata Lock".
  sql/si_objects.h
    Rename "DDL blocker" -> "Backup Metadata Lock".
  sql/sql_class.cc
    Rename "DDL blocker" -> "Backup Metadata Lock".
  sql/sql_class.h
    - Rename "DDL blocker" -> "Backup Metadata Lock".
    - Define CF_BLOCKED_BY_BML flag.
  sql/sql_parse.cc
    Handle statements which should be blocked by BML:
    - Mark each statement with CF_BLOCKED_BY_BML flag.
    - In mysql_execute_command(), for each marked statement call bml_enter() before 
      the big switch and bml_leave() after it.
    - Remove earlier DDL blocker calls from within the big switch.
=== modified file 'libmysqld/Makefile.am'
--- a/libmysqld/Makefile.am	2008-12-24 10:48:24 +0000
+++ b/libmysqld/Makefile.am	2009-02-11 13:10:41 +0000
@@ -81,7 +81,7 @@ sqlsources = derror.cc field.cc field_co
 	rpl_filter.cc sql_partition.cc sql_builtin.cc sql_plugin.cc \
 	debug_sync.cc sql_tablespace.cc transaction.cc \
 	rpl_injector.cc my_user.c partition_info.cc \
-	sql_servers.cc ddl_blocker.cc si_objects.cc sql_audit.cc \
+	sql_servers.cc bml.cc si_objects.cc sql_audit.cc \
         event_parse_data.cc mdl.cc \
         rpl_handler.cc
 

=== added directory 'mysql-test/suite/backup/include'
=== added file 'mysql-test/suite/backup/include/bml_test.inc'
--- a/mysql-test/suite/backup/include/bml_test.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/include/bml_test.inc	2009-02-11 13:10:41 +0000
@@ -0,0 +1,319 @@
+# This is a "subroutine" for backup_bml test. It executes DDL
+# statements given by variables $DDL1-4 in parallel with BACKUP/RESTORE 
+# statement and checks that they correctly block each other.
+#
+# If $backup_to has value, then BACKUP operation is performed and backup image 
+# is stored at location $backup_to.
+#
+# If $restore_from has value, then RESTORE operation from the given image is 
+# performed.
+#
+# To use this file the following conditions must be satisfied:
+# - five connections con1-5 must be set up,
+# - database bml_test must exist,
+# - procedure test.check_results(), used to check effects of DDLs must 
+#   be defined,
+# - If $restore_from is set, it must point at valid backup image.
+#
+# It is responsibility of the user of this file to populate bml_test
+# database with data prior to using it.
+#
+# Backup test sequence diagram (not UML)
+# --------------------------------------
+# Four DDL statements and a backup command are specified.
+# The first two DDL statements are run as "in progress" when
+# the backup starts. The other two DDL statements are run
+# when the backup or restore is already running. Tests results
+# show the realization of the assumptions above.
+#
+#     con5      con1     con2     con3     con4   default
+#    (setup)     |        |        |        |        |
+#       |        |        |        |        |        |
+#       |        |        |        |        |     check A
+#       |       DDL1      |        |        |        |
+#       |        *       DDL2      |        |        |
+#       |        *        *        |        |        |
+# BACKUP/RESTORE *        *        |        |        |
+#       *        *        *        |        |        |
+#       *        *        *        |        |     check B
+#       *        =        =        |        |        |
+#       *        |        |        |        |     check C
+#       *        |        |       DDL3      |        |
+#       *        |        |        *       DDL4      |
+#       *        |        |        *        *     check D
+#       =        |        |        *        *        |
+#       |        |        |        =        =        |
+#       |        |        |        |        |     check E
+#
+# Notes: Symbol '*' denotes execution of a statement, symbol '=' its 
+# termination.
+#
+# During test, the following checks are made:
+#
+# Checkpoint A) To see the initial situation.
+# Checkpoint B) BACKUP/RESTORE is blocked.
+# Checkpoint C) DDL1 and DDL2 completed and BACKUP/RESTORE started its job.
+# Checkpoint D) DDL3 and DDL4 are blocked.
+# Checkpoint E) BACKUP/RESTORE and all DDLs completed.
+#
+# Note by Ingo: I wonder if the line above "(results)" is correct.
+# I understand the above explanations so that DDL3 and 4 cannot
+# resume before BACKUP/RESTORE finished. But the line indicates
+# that these can resume in any order.
+
+if (`select '$backup_to' <> ''`)
+{
+  let $operation= BACKUP DATABASE bml_test TO '$backup_to';
+}
+
+if (`select '$restore_from' <> ''`)
+{
+  let $operation= RESTORE FROM '$restore_from' OVERWRITE;
+}
+
+--echo
+--echo ########################################################
+--echo # Running BML test for the following statements:
+--echo #
+--echo # DDL1= $DDL1
+--echo # DDL2= $DDL2
+--echo # DDL3= $DDL3
+--echo # DDL4= $DDL4
+--echo #
+--echo # BML is activated by $operation.
+--echo ########################################################
+--echo
+
+connection default;
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+
+#
+# Make bml_test the default database in all connections.
+#
+USE bml_test;
+connection con1;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+connection con2;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+connection con3;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+connection con4;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+connection con5;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+--echo
+--echo == Checkpoint A ==
+--echo # Check the initial situation.
+CALL test.check_results();
+--echo ==================
+--echo
+
+# Start DDL1 and DDL2
+
+ connection con1;
+ --echo # con1: Start DDL1 making it to stop after it has started (and 
+ --echo #       possibly registered with BML).
+ SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+ --send
+ eval $DDL1;
+
+   connection con2;
+   --echo # con2: Wait for DDL1 to reach its synchronization point.
+   SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 15';
+   --echo # con2: Start DDL2 making it to stop after it has started (and 
+   --echo #       possibly registered with BML).
+   SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+   --send
+   eval $DDL2;
+
+# Start BACKUP/RESTORE
+ 
+         connection con5;
+         --echo # con5: Wait for DDL2 to reach its synchronization point.
+         SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 15';
+         # To be safe clear before_execute_sql_command which is hit by
+         # every executed statement
+         SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+
+         --echo # con5: Activate synchronization points for BACKUP/RESTORE.
+         # 
+         # Make BACKUP/RESTORE to operation which should be blocked by ongoing
+         # statements. Make it send 'bup_waiting' signal just before it checks
+         # for registered statements inside BML. 
+         #
+         SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+         #
+         # Whether BACKUP/RESTORE is blocked or not make it stop after it 
+         # completes preparations, including activating the BML.
+         #
+         SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+         SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+	 #
+	 # Also make it to stop in the middle of operation after seeing 
+	 # 'continue_bup' so that DDL3 and DDL4 can be started in parallel
+	 #
+	 SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+	 SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';	 
+
+         --echo # con5: Starting BACKUP/RESTORE operation -- should be blocked 
+         --echo #       by ongoing DDLs.
+         # arrange for deterministic backup_id = 500
+         SET SESSION debug="+d,set_backup_id";
+         --send
+         eval $operation;
+ 
+connection default;
+--echo # Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 15';
+
+--echo
+--echo == Checkpoint B ==
+--echo #
+--echo # DDL1= $DDL1
+--echo # DDL2= $DDL2
+--echo # DDL3= $DDL3
+--echo # DDL4= $DDL4
+--echo #
+eval SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+  WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "$DDL1%"
+     OR info LIKE "$DDL2%";
+--echo # Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+--echo # Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+--echo ==================
+--echo
+
+--echo # Resume DDL1 and DDL2. 
+--echo # Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+
+ connection con1;
+ --echo # con1: Reaping DDL1
+ reap;
+
+   connection con2;
+   --echo # con2: Reaping DDL2
+   reap;
+
+connection default;
+# Ensure that BACKUP/RESTORE is in progress, after activating BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 15';
+
+--echo
+--echo == Checkpoint C ==
+--echo #
+--echo # DDL1= $DDL1
+--echo # DDL2= $DDL2
+--echo # DDL3= $DDL3
+--echo # DDL4= $DDL4
+--echo #
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+  WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+--echo # Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+--echo ==================
+--echo
+
+# Start DDL3 and DDL4 while BML is taken.
+
+     connection con3;
+     --echo # con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+     --echo #       (will not be in backup) make it send signal when
+     --echo #       blocked on BML.
+     SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+     --send
+     eval $DDL3;
+
+       connection con4;
+       --echo # Wait for DDL3 to send its signal.
+       SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 15';
+       --echo # con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+       --echo #       (will not be in backup) make it send signal when
+       --echo #       blocked on BML.
+       SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+       --send
+       eval $DDL4;
+
+# check that DDL3 and DDL4 are blocked
+
+connection default;
+--echo # Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 15';
+
+--echo
+--echo == Checkpoint D ==
+--echo #
+--echo # DDL1= $DDL1
+--echo # DDL2= $DDL2
+--echo # DDL3= $DDL3
+--echo # DDL4= $DDL4
+--echo #
+eval SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+  WHERE info LIKE "$DDL3%"
+     OR info LIKE "$DDL4%";
+--echo # Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+--echo ==================
+--echo
+
+--echo # Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+
+         connection con5;
+         --echo # con5: Reaping BACKUP/RESTORE
+         reap;
+         SET debug="-d";
+
+     connection con3;
+     --echo # con3: Completing DDL3
+     reap;
+
+       connection con4;
+       --echo # con4: Completing DDL4
+       reap;
+
+connection default;
+
+--echo
+--echo == Checkpoint E ==
+--echo #
+--echo # DDL1= $DDL1
+--echo # DDL2= $DDL2
+--echo # DDL3= $DDL3
+--echo # DDL4= $DDL4
+--echo #
+--echo # Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+--echo ==================
+--echo
+
+# Cleanup
+
+connection con1;
+SET DEBUG_SYNC= 'reset';
+connection con2;
+SET DEBUG_SYNC= 'reset';
+connection con3;
+SET DEBUG_SYNC= 'reset';
+connection con4;
+SET DEBUG_SYNC= 'reset';
+connection con5;
+SET DEBUG_SYNC= 'reset';
+connection default;
+SET DEBUG_SYNC= 'reset';
+
+let $backup_to=;
+let $restore_from=;

=== renamed file 'mysql-test/suite/backup/r/backup_ddl_blocker.result' => 'mysql-test/suite/backup/r/backup_bml.result'
--- a/mysql-test/suite/backup/r/backup_ddl_blocker.result	2008-11-20 14:07:23 +0000
+++ b/mysql-test/suite/backup/r/backup_bml.result	2009-02-11 13:10:41 +0000
@@ -1,1625 +1,3344 @@
+DROP DATABASE IF EXISTS bml_test;
+CREATE DATABASE bml_test;
+USE test;
+CREATE TABLE objects (pos int, type char(10), name char(16), args text);
+CREATE FUNCTION drop_stmt(pos_arg int) RETURNS text
+BEGIN
+DECLARE stmt text;
+SELECT concat('DROP ', type, ' ', name)
+INTO stmt
+FROM test.objects WHERE pos=pos_arg;
+RETURN stmt;
+END\\
+CREATE FUNCTION create_stmt(pos_arg int) RETURNS text
+BEGIN
+DECLARE stmt text;
+SELECT concat('CREATE ', type, ' ', name, args)
+INTO stmt
+FROM test.objects WHERE pos=pos_arg;
+RETURN stmt;
+END\\
+CREATE FUNCTION alter_stmt(pos_arg int) RETURNS text
+BEGIN
+DECLARE stmt text;
+SELECT concat('ALTER ', type, ' ', name, args)
+INTO stmt
+FROM test.objects WHERE pos=pos_arg;
+RETURN stmt;
+END\\
+USE test;
+TRUNCATE TABLE test.objects;
+INSERT INTO test.objects VALUES 
+(1, 'DATABASE', 'bml_test_db1', ''), 
+(2, 'TABLE',    't1',	'(a int)'), 
+(3, 'VIEW',	  'v1',	' AS SELECT * FROM t2'), 
+(4, 'FUNCTION', 'f1',	'() RETURNS int RETURN 1'),
+(5, 'PROCEDURE','p1',	'() SET @foo=1'),
+(6, 'EVENT',	  'e1',	' ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1'),
+(7, 'TRIGGER',  'r1',	' AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1'),
+(8, 'INDEX',	  'i1 ON t2', '(b)');
+DROP PROCEDURE IF EXISTS test.check_results\\
+Warnings:
+Note	1305	PROCEDURE test.check_results does not exist
+CREATE PROCEDURE test.check_results()
+BEGIN
+# show databases
+SHOW DATABASES LIKE 'bml%';
+# show objects in bml_test database
+SELECT table_name AS name, table_type AS type
+FROM information_schema.tables
+WHERE table_schema = 'bml_test'
+  UNION SELECT routine_name , routine_type
+FROM information_schema.routines
+WHERE routine_schema = 'bml_test'
+  UNION SELECT event_name, 'EVENT'
+    FROM information_schema.events
+WHERE event_schema = 'bml_test'
+  UNION SELECT trigger_name, 'TRIGGER'
+    FROM information_schema.triggers
+WHERE trigger_schema = 'bml_test';
+# show definiton of t2 to see the index if created
+SHOW CREATE TABLE bml_test.t2;
+END\\
+USE bml_test;
+CREATE TABLE t2 (b int);
+CREATE DATABASE bml_test_db1;
+CREATE TABLE t1(a int);
+CREATE VIEW v1 AS SELECT * FROM t2;
+CREATE FUNCTION f1() RETURNS int RETURN 1;
+CREATE PROCEDURE p1() SET @foo=1;
+CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1;
+CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1;
+CREATE INDEX i1 ON t2(b);
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t1	BASE TABLE
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+BACKUP DATABASE bml_test, bml_test_db1 TO 'bml_test_orig.bkp';
+backup_id
+#
+DROP VIEW v1;
+DROP TABLE t1;
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= CREATE VIEW v1 AS SELECT * FROM t2
+# DDL2= DROP FUNCTION f1
+# DDL3= DROP DATABASE bml_test_db1
+# DDL4= CREATE TABLE t1(a int)
+#
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
 SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
 
-Starting Test 1 - Backup
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+f1	FUNCTION
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+CREATE VIEW v1 AS SELECT * FROM t2;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+DROP FUNCTION f1;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= CREATE VIEW v1 AS SELECT * FROM t2
+# DDL2= DROP FUNCTION f1
+# DDL3= DROP DATABASE bml_test_db1
+# DDL4= CREATE TABLE t1(a int)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "CREATE VIEW v1 AS SELECT * FROM t2%"
+     OR info LIKE "DROP FUNCTION f1%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	DROP FUNCTION f1
+debug sync point: before_execute_sql_command	CREATE VIEW v1 AS SELECT * FROM t2
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+f1	FUNCTION
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= CREATE VIEW v1 AS SELECT * FROM t2
+# DDL2= DROP FUNCTION f1
+# DDL3= DROP DATABASE bml_test_db1
+# DDL4= CREATE TABLE t1(a int)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+DROP DATABASE bml_test_db1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+CREATE TABLE t1(a int);
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= CREATE VIEW v1 AS SELECT * FROM t2
+# DDL2= DROP FUNCTION f1
+# DDL3= DROP DATABASE bml_test_db1
+# DDL4= CREATE TABLE t1(a int)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "DROP DATABASE bml_test_db1%"
+     OR info LIKE "CREATE TABLE t1(a int)%";
+state	info
+BML: waiting until released	CREATE TABLE t1(a int)
+BML: waiting until released	DROP DATABASE bml_test_db1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= CREATE VIEW v1 AS SELECT * FROM t2
+# DDL2= DROP FUNCTION f1
+# DDL3= DROP DATABASE bml_test_db1
+# DDL4= CREATE TABLE t1(a int)
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+name	type
+t1	BASE TABLE
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
 
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t4 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("03 Some data to test");
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Backing up database -- will block with lock
-BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: before_block_ddl	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t2%";
-state	info
-debug sync point: after_start_ddl	ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int
-con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: after_block_ddl	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: before_check_ddl_blocked	CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
-state	info
-debug sync point: before_check_ddl_blocked	ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 1 results for backup.
-
-con1: Showing columns after updates and backup
-DESCRIBE bup_ddl_blocker.t1;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t2;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t3;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t4;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-con1: Dropping the database tables
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t2,
-bup_ddl_blocker.t3, bup_ddl_blocker.t4;
-con1: Restoring the database
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-backup_id
-#
-con1: Showing columns that were backed up
-con1: Table t3 should not be in restored data.
-con1: Table t4 should not have new column in restored data.
-DESCRIBE bup_ddl_blocker.t1;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t2;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t3;
-ERROR 42S02: Table 'bup_ddl_blocker.t3' doesn't exist
-DESCRIBE bup_ddl_blocker.t4;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-
-Starting Test 1 - Restore
-
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t4 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("03 Some data to test");
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
-backup_id
-#
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Restoring database -- will block with lock
-RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t2%";
-state	info
-debug sync point: after_start_ddl	ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int
-con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: before_check_ddl_blocked	CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
-state	info
-debug sync point: before_check_ddl_blocked	ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 1 results for restore.
-
-con1: Table t1 should not be in restored data.
-con1: Table t2 should not have new column in restored data.
-con1: Table t3 should be in restored data.
-con1: Table t4 should have new column in restored data.
-DESCRIBE bup_ddl_blocker.t1;
-ERROR 42S02: Table 'bup_ddl_blocker.t1' doesn't exist
-DESCRIBE bup_ddl_blocker.t2;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t3;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t4;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-
-Starting Test 2 - Backup
-
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t4 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("03 Some data to test");
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-REPAIR TABLE bup_ddl_blocker.t2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Backing up database -- will block with lock
-BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: before_block_ddl	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t2%";
-state	info
-debug sync point: after_start_ddl	REPAIR TABLE bup_ddl_blocker.t2
-con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: after_block_ddl	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-REPAIR TABLE bup_ddl_blocker.t4;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: before_check_ddl_blocked	RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
-state	info
-debug sync point: before_check_ddl_blocked	REPAIR TABLE bup_ddl_blocker.t4
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t2	repair	status	OK
-con4: Completing DDL
-con5: Completing DDL
-Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t4	repair	status	OK
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= CREATE DATABASE bml_test_db1
+# DDL2= DROP TABLE t1
+# DDL3= DROP VIEW v1
+# DDL4= CREATE FUNCTION f1() RETURNS int RETURN 1
+#
+# BML is activated by RESTORE FROM 'bml_test.bkp' OVERWRITE.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database (bml%)
+bml_test
+name	type
+t1	BASE TABLE
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+CREATE DATABASE bml_test_db1;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+DROP TABLE t1;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= CREATE DATABASE bml_test_db1
+# DDL2= DROP TABLE t1
+# DDL3= DROP VIEW v1
+# DDL4= CREATE FUNCTION f1() RETURNS int RETURN 1
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "CREATE DATABASE bml_test_db1%"
+     OR info LIKE "DROP TABLE t1%";
+state	info
+BML: waiting for all statements to leave	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	DROP TABLE t1
+debug sync point: before_execute_sql_command	CREATE DATABASE bml_test_db1
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+name	type
+t1	BASE TABLE
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= CREATE DATABASE bml_test_db1
+# DDL2= DROP TABLE t1
+# DDL3= DROP VIEW v1
+# DDL4= CREATE FUNCTION f1() RETURNS int RETURN 1
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: start_do_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+DROP VIEW v1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+CREATE FUNCTION f1() RETURNS int RETURN 1;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= CREATE DATABASE bml_test_db1
+# DDL2= DROP TABLE t1
+# DDL3= DROP VIEW v1
+# DDL4= CREATE FUNCTION f1() RETURNS int RETURN 1
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "DROP VIEW v1%"
+     OR info LIKE "CREATE FUNCTION f1() RETURNS int RETURN 1%";
+state	info
+BML: waiting until released	CREATE FUNCTION f1() RETURNS int RETURN 1
+BML: waiting until released	DROP VIEW v1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= CREATE DATABASE bml_test_db1
+# DDL2= DROP TABLE t1
+# DDL3= DROP VIEW v1
+# DDL4= CREATE FUNCTION f1() RETURNS int RETURN 1
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+f1	FUNCTION
+p1	PROCEDURE
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+CREATE VIEW v1 AS SELECT * FROM t2;
+DROP TRIGGER r1;
+DROP EVENT e1;
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1
+# DDL2= DROP INDEX i1 ON t2
+# DDL3= DROP PROCEDURE p1
+# DDL4= CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1
+#
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+DROP INDEX i1 ON t2;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1
+# DDL2= DROP INDEX i1 ON t2
+# DDL3= DROP PROCEDURE p1
+# DDL4= CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1%"
+     OR info LIKE "DROP INDEX i1 ON t2%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	DROP INDEX i1 ON t2
+debug sync point: before_execute_sql_command	CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1
+# DDL2= DROP INDEX i1 ON t2
+# DDL3= DROP PROCEDURE p1
+# DDL4= CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+DROP PROCEDURE p1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1
+# DDL2= DROP INDEX i1 ON t2
+# DDL3= DROP PROCEDURE p1
+# DDL4= CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "DROP PROCEDURE p1%"
+     OR info LIKE "CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1%";
+state	info
+BML: waiting until released	CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1
+BML: waiting until released	DROP PROCEDURE p1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1
+# DDL2= DROP INDEX i1 ON t2
+# DDL3= DROP PROCEDURE p1
+# DDL4= CREATE EVENT e1 ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= CREATE PROCEDURE p1() SET @foo=1
+# DDL2= DROP EVENT e1
+# DDL3= DROP TRIGGER r1
+# DDL4= CREATE INDEX i1 ON t2(b)
+#
+# BML is activated by RESTORE FROM 'bml_test.bkp' OVERWRITE.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+CREATE PROCEDURE p1() SET @foo=1;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+DROP EVENT e1;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= CREATE PROCEDURE p1() SET @foo=1
+# DDL2= DROP EVENT e1
+# DDL3= DROP TRIGGER r1
+# DDL4= CREATE INDEX i1 ON t2(b)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "CREATE PROCEDURE p1() SET @foo=1%"
+     OR info LIKE "DROP EVENT e1%";
+state	info
+BML: waiting for all statements to leave	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	DROP EVENT e1
+debug sync point: before_execute_sql_command	CREATE PROCEDURE p1() SET @foo=1
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+e1	EVENT
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= CREATE PROCEDURE p1() SET @foo=1
+# DDL2= DROP EVENT e1
+# DDL3= DROP TRIGGER r1
+# DDL4= CREATE INDEX i1 ON t2(b)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: start_do_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+DROP TRIGGER r1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+CREATE INDEX i1 ON t2(b);
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= CREATE PROCEDURE p1() SET @foo=1
+# DDL2= DROP EVENT e1
+# DDL3= DROP TRIGGER r1
+# DDL4= CREATE INDEX i1 ON t2(b)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "DROP TRIGGER r1%"
+     OR info LIKE "CREATE INDEX i1 ON t2(b)%";
+state	info
+BML: waiting until released	CREATE INDEX i1 ON t2(b)
+BML: waiting until released	DROP TRIGGER r1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+r1	TRIGGER
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= CREATE PROCEDURE p1() SET @foo=1
+# DDL2= DROP EVENT e1
+# DDL3= DROP TRIGGER r1
+# DDL4= CREATE INDEX i1 ON t2(b)
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database (bml%)
+bml_test
+bml_test_db1
+name	type
+t2	BASE TABLE
+v1	VIEW
+f1	FUNCTION
+p1	PROCEDURE
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `b` int(11) DEFAULT NULL,
+  KEY `i1` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1;
+RESTORE FROM 'bml_test_orig.bkp' OVERWRITE;
 backup_id
+501
+TRUNCATE TABLE test.objects;
+INSERT INTO test.objects VALUES
+(1, 'DATABASE',  'bml_test_db1', ' CHARACTER SET = utf8'),
+(2, 'TABLE',	   't1', ' ADD INDEX `i` (a)'),
+(3, 'VIEW',	   'v1', ' AS SELECT 1'),
+(4, 'FUNCTION',  'f1', " COMMENT 'testing alter'"),
+(5, 'PROCEDURE', 'p1', " COMMENT 'testing alter'"),
+(6, 'EVENT',	   'e1', ' RENAME TO e2');
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+SHOW CREATE DATABASE  bml_test_db1;
+SHOW CREATE TABLE     bml_test.t1;
+SHOW CREATE VIEW      bml_test.v1;
+SHOW CREATE FUNCTION  bml_test.f1;
+SHOW CREATE PROCEDURE bml_test.p1;
+SELECT event_name FROM information_schema.events
+WHERE event_schema = 'bml_test';
+END\\
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
 #
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
 
-Verifying Test 2 results for backup.
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
 
-con1: Showing columns after updates and backup
-use bup_ddl_blocker;
-SHOW TABLES;
-Tables_in_bup_ddl_blocker
-t01
-t03
-t2
-t4
-con1: Dropping the database tables
-DROP TABLE bup_ddl_blocker.t01, bup_ddl_blocker.t2,
-bup_ddl_blocker.t03, bup_ddl_blocker.t4;
-con1: Restoring the database
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-backup_id
-#
-con1: Showing columns that were backed up
-con1: Table t01 should be in restore
-con1: Table t03 should not be in restore
-use bup_ddl_blocker;
-SHOW TABLES;
-Tables_in_bup_ddl_blocker
-t01
-t2
-t3
-t4
-
-Starting Test 2 - Restore
-
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t4 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("03 Some data to test");
-BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
-backup_id
-#
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-REPAIR TABLE bup_ddl_blocker.t2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Restoring database -- will block with lock
-RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t2%";
-state	info
-debug sync point: after_start_ddl	REPAIR TABLE bup_ddl_blocker.t2
-con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-REPAIR TABLE bup_ddl_blocker.t4;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: before_check_ddl_blocked	RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
-state	info
-debug sync point: before_check_ddl_blocked	REPAIR TABLE bup_ddl_blocker.t4
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t2	repair	status	OK
-con4: Completing DDL
-con5: Completing DDL
-Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t4	repair	status	OK
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+ALTER DATABASE bml_test_db1 CHARACTER SET = utf8;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+ALTER TABLE t1 ADD INDEX `i` (a);
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "ALTER DATABASE bml_test_db1 CHARACTER SET = utf8%"
+     OR info LIKE "ALTER TABLE t1 ADD INDEX `i` (a)%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	ALTER TABLE t1 ADD INDEX `i` (a)
+debug sync point: before_execute_sql_command	ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+ALTER VIEW v1 AS SELECT 1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+ALTER FUNCTION f1 COMMENT 'testing alter';
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "ALTER VIEW v1 AS SELECT 1%"
+     OR info LIKE "ALTER FUNCTION f1 COMMENT 'testing alter'%";
+state	info
+BML: waiting until released	ALTER FUNCTION f1 COMMENT 'testing alter'
+BML: waiting until released	ALTER VIEW v1 AS SELECT 1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+    COMMENT 'testing alter'
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+RESTORE FROM 'bml_test_orig.bkp'  OVERWRITE;
+backup_id
+501
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= ALTER VIEW v1 AS SELECT 1
+# DDL2= ALTER FUNCTION f1 COMMENT 'testing alter'
+# DDL3= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL4= ALTER EVENT e1 RENAME TO e2
+#
+# BML is activated by RESTORE FROM 'bml_test.bkp' OVERWRITE.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+ALTER VIEW v1 AS SELECT 1;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+ALTER FUNCTION f1 COMMENT 'testing alter';
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= ALTER VIEW v1 AS SELECT 1
+# DDL2= ALTER FUNCTION f1 COMMENT 'testing alter'
+# DDL3= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL4= ALTER EVENT e1 RENAME TO e2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "ALTER VIEW v1 AS SELECT 1%"
+     OR info LIKE "ALTER FUNCTION f1 COMMENT 'testing alter'%";
+state	info
+BML: waiting for all statements to leave	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	ALTER FUNCTION f1 COMMENT 'testing alter'
+debug sync point: before_execute_sql_command	ALTER VIEW v1 AS SELECT 1
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= ALTER VIEW v1 AS SELECT 1
+# DDL2= ALTER FUNCTION f1 COMMENT 'testing alter'
+# DDL3= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL4= ALTER EVENT e1 RENAME TO e2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: start_do_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+    COMMENT 'testing alter'
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+ALTER PROCEDURE p1 COMMENT 'testing alter';
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+ALTER EVENT e1 RENAME TO e2;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= ALTER VIEW v1 AS SELECT 1
+# DDL2= ALTER FUNCTION f1 COMMENT 'testing alter'
+# DDL3= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL4= ALTER EVENT e1 RENAME TO e2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "ALTER PROCEDURE p1 COMMENT 'testing alter'%"
+     OR info LIKE "ALTER EVENT e1 RENAME TO e2%";
+state	info
+BML: waiting until released	ALTER EVENT e1 RENAME TO e2
+BML: waiting until released	ALTER PROCEDURE p1 COMMENT 'testing alter'
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+    COMMENT 'testing alter'
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= ALTER VIEW v1 AS SELECT 1
+# DDL2= ALTER FUNCTION f1 COMMENT 'testing alter'
+# DDL3= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL4= ALTER EVENT e1 RENAME TO e2
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+    COMMENT 'testing alter'
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e2
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+RESTORE FROM 'bml_test_orig.bkp'  OVERWRITE;
+backup_id
+501
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL2= ALTER EVENT e1 RENAME TO e2
+# DDL3= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL4= ALTER TABLE t1 ADD INDEX `i` (a)
+#
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+ALTER PROCEDURE p1 COMMENT 'testing alter';
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+ALTER EVENT e1 RENAME TO e2;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL2= ALTER EVENT e1 RENAME TO e2
+# DDL3= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL4= ALTER TABLE t1 ADD INDEX `i` (a)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "ALTER PROCEDURE p1 COMMENT 'testing alter'%"
+     OR info LIKE "ALTER EVENT e1 RENAME TO e2%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	ALTER EVENT e1 RENAME TO e2
+debug sync point: before_execute_sql_command	ALTER PROCEDURE p1 COMMENT 'testing alter'
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL2= ALTER EVENT e1 RENAME TO e2
+# DDL3= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL4= ALTER TABLE t1 ADD INDEX `i` (a)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+    COMMENT 'testing alter'
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e2
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+ALTER DATABASE bml_test_db1 CHARACTER SET = utf8;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+ALTER TABLE t1 ADD INDEX `i` (a);
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL2= ALTER EVENT e1 RENAME TO e2
+# DDL3= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL4= ALTER TABLE t1 ADD INDEX `i` (a)
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "ALTER DATABASE bml_test_db1 CHARACTER SET = utf8%"
+     OR info LIKE "ALTER TABLE t1 ADD INDEX `i` (a)%";
+state	info
+BML: waiting until released	ALTER TABLE t1 ADD INDEX `i` (a)
+BML: waiting until released	ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+    COMMENT 'testing alter'
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e2
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= ALTER PROCEDURE p1 COMMENT 'testing alter'
+# DDL2= ALTER EVENT e1 RENAME TO e2
+# DDL3= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL4= ALTER TABLE t1 ADD INDEX `i` (a)
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+    COMMENT 'testing alter'
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e2
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+RESTORE FROM 'bml_test_orig.bkp'  OVERWRITE;
+backup_id
+501
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+# BML is activated by RESTORE FROM 'bml_test.bkp' OVERWRITE.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+ALTER DATABASE bml_test_db1 CHARACTER SET = utf8;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+ALTER TABLE t1 ADD INDEX `i` (a);
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "ALTER DATABASE bml_test_db1 CHARACTER SET = utf8%"
+     OR info LIKE "ALTER TABLE t1 ADD INDEX `i` (a)%";
+state	info
+BML: waiting for all statements to leave	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	ALTER TABLE t1 ADD INDEX `i` (a)
+debug sync point: before_execute_sql_command	ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: start_do_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+ALTER VIEW v1 AS SELECT 1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+ALTER FUNCTION f1 COMMENT 'testing alter';
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "ALTER VIEW v1 AS SELECT 1%"
+     OR info LIKE "ALTER FUNCTION f1 COMMENT 'testing alter'%";
+state	info
+BML: waiting until released	ALTER FUNCTION f1 COMMENT 'testing alter'
+BML: waiting until released	ALTER VIEW v1 AS SELECT 1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  KEY `i` (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select `bml_test`.`t2`.`b` AS `b` from `bml_test`.`t2`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e1
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= ALTER DATABASE bml_test_db1 CHARACTER SET = utf8
+# DDL2= ALTER TABLE t1 ADD INDEX `i` (a)
+# DDL3= ALTER VIEW v1 AS SELECT 1
+# DDL4= ALTER FUNCTION f1 COMMENT 'testing alter'
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Database	Create Database
+bml_test_db1	CREATE DATABASE `bml_test_db1` /*!40100 DEFAULT CHARACTER SET utf8 */
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `bml_test`.`v1` AS select 1 AS `1`	latin1	latin1_swedish_ci
+Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
+f1		CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+    COMMENT 'testing alter'
+RETURN 1	latin1	latin1_swedish_ci	latin1_swedish_ci
+Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
+p1		CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+SET @foo=1	latin1	latin1_swedish_ci	latin1_swedish_ci
+event_name
+e2
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+RESTORE FROM 'bml_test_orig.bkp'  OVERWRITE;
 backup_id
+501
+DROP DATABASE IF EXISTS bml_test_db1;
+DROP TABLE test.objects;
+DROP FUNCTION test.drop_stmt;
+DROP FUNCTION test.create_stmt;
+DROP FUNCTION test.alter_stmt;
+DROP DATABASE bml_test;
+CREATE DATABASE bml_test;
+CREATE USER bml_u1;
+CREATE USER bml_u2;
+CREATE USER bml_u3;
+CREATE TABLESPACE bml_ts1 ADD DATAFILE 'bml_ts1.dat' ENGINE=falcon;
+CREATE TABLESPACE bml_ts2 ADD DATAFILE 'bml_ts2.dat' ENGINE=falcon;
+CREATE TABLE bml_test.t1 (a int);
+CREATE TABLE bml_test.t2 (b int);
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+SHOW TABLES IN bml_test;
+# show users
+SELECT DISTINCT grantee AS user 
+FROM information_schema.user_privileges
+WHERE grantee like '%bml%';
+# show privileges
+SELECT grantee, count(*) > 0 AS has_privileges
+FROM information_schema.schema_privileges
+WHERE grantee like '%bml%'
+    GROUP BY grantee;
+# show tablespaces
+SELECT tablespace_name, file_name 
+FROM information_schema.files
+WHERE tablespace_name like 'bml%';
+END\\
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= RENAME TABLE t1 TO t1_renamed
+# DDL2= DROP USER bml_u1
+# DDL3= RENAME USER bml_u2 TO bml_u2_renamed
+# DDL4= DROP TABLESPACE bml_ts1 ENGINE=falcon
 #
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
 
-Verifying Test 2 results for restore.
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
 
-con1: Table t01 should not be in restored data.
-use bup_ddl_blocker;
-SHOW TABLES;
-Tables_in_bup_ddl_blocker
-t03
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+user
+'bml_u1'@'%'
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts1	bml_ts1.dat
+bml_ts2	bml_ts2.dat
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+RENAME TABLE t1 TO t1_renamed;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+DROP USER bml_u1;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= RENAME TABLE t1 TO t1_renamed
+# DDL2= DROP USER bml_u1
+# DDL3= RENAME USER bml_u2 TO bml_u2_renamed
+# DDL4= DROP TABLESPACE bml_ts1 ENGINE=falcon
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "RENAME TABLE t1 TO t1_renamed%"
+     OR info LIKE "DROP USER bml_u1%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	DROP USER bml_u1
+debug sync point: before_execute_sql_command	RENAME TABLE t1 TO t1_renamed
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
 t1
 t2
-t4
+user
+'bml_u1'@'%'
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts1	bml_ts1.dat
+bml_ts2	bml_ts2.dat
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= RENAME TABLE t1 TO t1_renamed
+# DDL2= DROP USER bml_u1
+# DDL3= RENAME USER bml_u2 TO bml_u2_renamed
+# DDL4= DROP TABLESPACE bml_ts1 ENGINE=falcon
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts1	bml_ts1.dat
+bml_ts2	bml_ts2.dat
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+RENAME USER bml_u2 TO bml_u2_renamed;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+DROP TABLESPACE bml_ts1 ENGINE=falcon;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= RENAME TABLE t1 TO t1_renamed
+# DDL2= DROP USER bml_u1
+# DDL3= RENAME USER bml_u2 TO bml_u2_renamed
+# DDL4= DROP TABLESPACE bml_ts1 ENGINE=falcon
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "RENAME USER bml_u2 TO bml_u2_renamed%"
+     OR info LIKE "DROP TABLESPACE bml_ts1 ENGINE=falcon%";
+state	info
+BML: waiting until released	DROP TABLESPACE bml_ts1 ENGINE=falcon
+BML: waiting until released	RENAME USER bml_u2 TO bml_u2_renamed
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts1	bml_ts1.dat
+bml_ts2	bml_ts2.dat
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= RENAME TABLE t1 TO t1_renamed
+# DDL2= DROP USER bml_u1
+# DDL3= RENAME USER bml_u2 TO bml_u2_renamed
+# DDL4= DROP TABLESPACE bml_ts1 ENGINE=falcon
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2_renamed'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
 
-Starting Test 3 - Backup
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
 
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t4 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("03 Some data to test");
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-OPTIMIZE TABLE bup_ddl_blocker.t1;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-DROP TABLE bup_ddl_blocker.t2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Backing up database -- will block with lock
-BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: before_block_ddl	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	OPTIMIZE TABLE bup_ddl_blocker.t1
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP TABLE bup_ddl_blocker.t2%";
-state	info
-debug sync point: after_start_ddl	DROP TABLE bup_ddl_blocker.t2
-con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: after_block_ddl	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-OPTIMIZE TABLE bup_ddl_blocker.t3;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-DROP TABLE bup_ddl_blocker.t4;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: before_check_ddl_blocked	OPTIMIZE TABLE bup_ddl_blocker.t3
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
-state	info
-debug sync point: before_check_ddl_blocked	DROP TABLE bup_ddl_blocker.t4
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
-bup_ddl_blocker.t1	optimize	status	OK
-con3: Completing DDL
-con4: Completing DDL
-Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t3	optimize	note	Table does not support optimize, doing recreate + analyze instead
-bup_ddl_blocker.t3	optimize	status	OK
-con5: Completing DDL
-backup_id
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= RENAME USER bml_u2_renamed TO bml_u2
+# DDL2= GRANT ALL ON bml_test.* TO bml_u3
+# DDL3= RENAME TABLE t1_renamed TO t1
+# DDL4= GRANT ALL ON bml_test.* TO bml_u2
 #
+# BML is activated by RESTORE FROM 'bml_test.bkp' OVERWRITE.
+########################################################
 
-Verifying Test 3 results for backup.
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
 
-con1: Showing columns after updates and backup
-use bup_ddl_blocker;
-SHOW TABLES;
-Tables_in_bup_ddl_blocker
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2_renamed'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+RENAME USER bml_u2_renamed TO bml_u2;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+GRANT ALL ON bml_test.* TO bml_u3;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= RENAME USER bml_u2_renamed TO bml_u2
+# DDL2= GRANT ALL ON bml_test.* TO bml_u3
+# DDL3= RENAME TABLE t1_renamed TO t1
+# DDL4= GRANT ALL ON bml_test.* TO bml_u2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "RENAME USER bml_u2_renamed TO bml_u2%"
+     OR info LIKE "GRANT ALL ON bml_test.* TO bml_u3%";
+state	info
+BML: waiting for all statements to leave	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	GRANT ALL ON bml_test.* TO bml_u3
+debug sync point: before_execute_sql_command	RENAME USER bml_u2_renamed TO bml_u2
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2_renamed'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= RENAME USER bml_u2_renamed TO bml_u2
+# DDL2= GRANT ALL ON bml_test.* TO bml_u3
+# DDL3= RENAME TABLE t1_renamed TO t1
+# DDL4= GRANT ALL ON bml_test.* TO bml_u2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: start_do_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u3'@'%'	1
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+RENAME TABLE t1_renamed TO t1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+GRANT ALL ON bml_test.* TO bml_u2;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= RENAME USER bml_u2_renamed TO bml_u2
+# DDL2= GRANT ALL ON bml_test.* TO bml_u3
+# DDL3= RENAME TABLE t1_renamed TO t1
+# DDL4= GRANT ALL ON bml_test.* TO bml_u2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "RENAME TABLE t1_renamed TO t1%"
+     OR info LIKE "GRANT ALL ON bml_test.* TO bml_u2%";
+state	info
+BML: waiting until released	GRANT ALL ON bml_test.* TO bml_u2
+BML: waiting until released	RENAME TABLE t1_renamed TO t1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1_renamed
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u3'@'%'	1
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= RENAME USER bml_u2_renamed TO bml_u2
+# DDL2= GRANT ALL ON bml_test.* TO bml_u3
+# DDL3= RENAME TABLE t1_renamed TO t1
+# DDL4= GRANT ALL ON bml_test.* TO bml_u2
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Tables_in_bml_test
 t1
-t3
-con1: Dropping the database tables
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-con1: Restoring the database
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-backup_id
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u2'@'%'	1
+'bml_u3'@'%'	1
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+
+########################################################
+# Running BML test for the following statements:
 #
-con1: Showing columns that were backed up
-con1: Table t2 should not be in restore
-use bup_ddl_blocker;
-SHOW TABLES;
-Tables_in_bup_ddl_blocker
+# DDL1= DROP TABLESPACE bml_ts2 ENGINE=falcon
+# DDL2= REVOKE ALL ON bml_test.* FROM bml_u2
+# DDL3= DROP USER bml_u2
+# DDL4= REVOKE ALL ON bml_test.* FROM bml_u3
+#
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Tables_in_bml_test
 t1
-t3
-t4
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u2'@'%'	1
+'bml_u3'@'%'	1
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+DROP TABLESPACE bml_ts2 ENGINE=falcon;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+REVOKE ALL ON bml_test.* FROM bml_u2;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= DROP TABLESPACE bml_ts2 ENGINE=falcon
+# DDL2= REVOKE ALL ON bml_test.* FROM bml_u2
+# DDL3= DROP USER bml_u2
+# DDL4= REVOKE ALL ON bml_test.* FROM bml_u3
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "DROP TABLESPACE bml_ts2 ENGINE=falcon%"
+     OR info LIKE "REVOKE ALL ON bml_test.* FROM bml_u2%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	REVOKE ALL ON bml_test.* FROM bml_u2
+debug sync point: before_execute_sql_command	DROP TABLESPACE bml_ts2 ENGINE=falcon
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u2'@'%'	1
+'bml_u3'@'%'	1
+tablespace_name	file_name
+bml_ts2	bml_ts2.dat
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= DROP TABLESPACE bml_ts2 ENGINE=falcon
+# DDL2= REVOKE ALL ON bml_test.* FROM bml_u2
+# DDL3= DROP USER bml_u2
+# DDL4= REVOKE ALL ON bml_test.* FROM bml_u3
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u3'@'%'	1
+tablespace_name	file_name
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+DROP USER bml_u2;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+REVOKE ALL ON bml_test.* FROM bml_u3;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= DROP TABLESPACE bml_ts2 ENGINE=falcon
+# DDL2= REVOKE ALL ON bml_test.* FROM bml_u2
+# DDL3= DROP USER bml_u2
+# DDL4= REVOKE ALL ON bml_test.* FROM bml_u3
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "DROP USER bml_u2%"
+     OR info LIKE "REVOKE ALL ON bml_test.* FROM bml_u3%";
+state	info
+BML: waiting until released	REVOKE ALL ON bml_test.* FROM bml_u3
+BML: waiting until released	DROP USER bml_u2
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+user
+'bml_u2'@'%'
+'bml_u3'@'%'
+grantee	has_privileges
+'bml_u3'@'%'	1
+tablespace_name	file_name
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= DROP TABLESPACE bml_ts2 ENGINE=falcon
+# DDL2= REVOKE ALL ON bml_test.* FROM bml_u2
+# DDL3= DROP USER bml_u2
+# DDL4= REVOKE ALL ON bml_test.* FROM bml_u3
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+user
+'bml_u3'@'%'
+grantee	has_privileges
+tablespace_name	file_name
+==================
 
-Starting Test 3 - Restore
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+DROP USER bml_u3;
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+user
+grantee	has_privileges
+tablespace_name	file_name
+DROP DATABASE bml_test;
+CREATE DATABASE bml_test;
+USE bml_test;
+CREATE TABLE t1 (a int) ENGINE=myisam;
+CREATE TABLE t2 (a int) ENGINE=myisam;
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (3),(4);
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+SHOW TABLES IN bml_test;
+SELECT count(*) AS rows_in_t1 FROM bml_test.t1;
+SELECT count(*) AS rows_in_t2 FROM bml_test.t2;
+CHECKSUM TABLE bml_test.t1, bml_test.t2 EXTENDED;
+END\\
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= OPTIMIZE TABLE t1
+# DDL2= REPAIR TABLE t2 USE_FRM
+# DDL3= TRUNCATE TABLE t1
+# DDL4= TRUNCATE TABLE t2
+#
+# BML is activated by BACKUP DATABASE bml_test TO 'bml_test.bkp'.
+########################################################
 
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker.t4 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t4 VALUES ("03 Some data to test");
-BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
-backup_id
-#
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-OPTIMIZE TABLE bup_ddl_blocker.t1;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-DROP TABLE bup_ddl_blocker.t2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Restoring database -- will block with lock
-RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	OPTIMIZE TABLE bup_ddl_blocker.t1
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP TABLE bup_ddl_blocker.t2%";
-state	info
-debug sync point: after_start_ddl	DROP TABLE bup_ddl_blocker.t2
-con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-OPTIMIZE TABLE bup_ddl_blocker.t3;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-DROP TABLE bup_ddl_blocker.t4;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: before_check_ddl_blocked	OPTIMIZE TABLE bup_ddl_blocker.t3
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
-state	info
-debug sync point: before_check_ddl_blocked	DROP TABLE bup_ddl_blocker.t4
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+2
+rows_in_t2
+2
+Table	Checksum
+bml_test.t1	2865344526
+bml_test.t2	1578680517
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+OPTIMIZE TABLE t1;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+REPAIR TABLE t2 USE_FRM;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= OPTIMIZE TABLE t1
+# DDL2= REPAIR TABLE t2 USE_FRM
+# DDL3= TRUNCATE TABLE t1
+# DDL4= TRUNCATE TABLE t2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "OPTIMIZE TABLE t1%"
+     OR info LIKE "REPAIR TABLE t2 USE_FRM%";
+state	info
+BML: waiting for all statements to leave	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	REPAIR TABLE t2 USE_FRM
+debug sync point: before_execute_sql_command	OPTIMIZE TABLE t1
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+2
+rows_in_t2
+2
+Table	Checksum
+bml_test.t1	2865344526
+bml_test.t2	1578680517
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
 Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
-bup_ddl_blocker.t1	optimize	status	OK
-con3: Completing DDL
-con4: Completing DDL
+bml_test.t1	optimize	status	OK
+# con2: Reaping DDL2
 Table	Op	Msg_type	Msg_text
-bup_ddl_blocker.t3	optimize	note	Table does not support optimize, doing recreate + analyze instead
-bup_ddl_blocker.t3	optimize	status	OK
-con5: Completing DDL
-backup_id
+bml_test.t2	repair	warning	Number of rows changed from 0 to 2
+bml_test.t2	repair	status	OK
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
 #
+# DDL1= OPTIMIZE TABLE t1
+# DDL2= REPAIR TABLE t2 USE_FRM
+# DDL3= TRUNCATE TABLE t1
+# DDL4= TRUNCATE TABLE t2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: before_backup_meta	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+2
+rows_in_t2
+2
+Table	Checksum
+bml_test.t1	2865344526
+bml_test.t2	1578680517
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+TRUNCATE TABLE t1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+TRUNCATE TABLE t2;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= OPTIMIZE TABLE t1
+# DDL2= REPAIR TABLE t2 USE_FRM
+# DDL3= TRUNCATE TABLE t1
+# DDL4= TRUNCATE TABLE t2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "TRUNCATE TABLE t1%"
+     OR info LIKE "TRUNCATE TABLE t2%";
+state	info
+BML: waiting until released	TRUNCATE TABLE t2
+BML: waiting until released	TRUNCATE TABLE t1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+2
+rows_in_t2
+2
+Table	Checksum
+bml_test.t1	2865344526
+bml_test.t2	1578680517
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+# con4: Completing DDL4
+
+== Checkpoint E ==
+#
+# DDL1= OPTIMIZE TABLE t1
+# DDL2= REPAIR TABLE t2 USE_FRM
+# DDL3= TRUNCATE TABLE t1
+# DDL4= TRUNCATE TABLE t2
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+0
+rows_in_t2
+0
+Table	Checksum
+bml_test.t1	0
+bml_test.t2	0
+==================
 
-Verifying Test 3 results for restore.
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (3);
+
+########################################################
+# Running BML test for the following statements:
+#
+# DDL1= TRUNCATE t1
+# DDL2= TRUNCATE t2
+# DDL3= REPAIR TABLE t1
+# DDL4= OPTIMIZE TABLE t2
+#
+# BML is activated by RESTORE FROM 'bml_test.bkp' OVERWRITE.
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
+SET DEBUG_SYNC= 'reset';
+USE bml_test;
 
-con1: Table t4 should not be in restored data.
-use bup_ddl_blocker;
-SHOW TABLES;
-Tables_in_bup_ddl_blocker
+== Checkpoint A ==
+# Check the initial situation.
+CALL test.check_results();
+Tables_in_bml_test
 t1
 t2
-t3
-
-Starting Test 4 - Backup
+rows_in_t1
+1
+rows_in_t2
+1
+Table	Checksum
+bml_test.t1	3459908756
+bml_test.t2	1681116191
+==================
+
+# con1: Start DDL1 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started 
+   					       WAIT_FOR continue_ddl';
+TRUNCATE t1;
+# con2: Wait for DDL1 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+# con2: Start DDL2 making it to stop after it has started (and 
+#       possibly registered with BML).
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl2_started 
+   					       WAIT_FOR continue_ddl';
+TRUNCATE t2;
+# con5: Wait for DDL2 to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl2_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Activate synchronization points for BACKUP/RESTORE.
+SET DEBUG_SYNC= 'bml_get_check2 SIGNAL bup_waiting';
+SET DEBUG_SYNC= 'after_backup_start_backup  WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'after_backup_start_restore WAIT_FOR continue_bup';
+SET DEBUG_SYNC= 'before_backup_meta SIGNAL bup_running WAIT_FOR finish_bup';
+SET DEBUG_SYNC= 'start_do_restore SIGNAL bup_running WAIT_FOR finish_bup';
+# con5: Starting BACKUP/RESTORE operation -- should be blocked 
+#       by ongoing DDLs.
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;
+# Waiting for BACKUP/RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_waiting TIMEOUT 1';
+
+== Checkpoint B ==
+#
+# DDL1= TRUNCATE t1
+# DDL2= TRUNCATE t2
+# DDL3= REPAIR TABLE t1
+# DDL4= OPTIMIZE TABLE t2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%"
+     OR info LIKE "TRUNCATE t1%"
+     OR info LIKE "TRUNCATE t2%";
+state	info
+BML: waiting for all statements to leave	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	TRUNCATE t2
+debug sync point: before_execute_sql_command	TRUNCATE t1
+# Checking that BACKUP is blocked by DDLs.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Checking that DDL1 and DDL2 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+1
+rows_in_t2
+1
+Table	Checksum
+bml_test.t1	3459908756
+bml_test.t2	1681116191
+==================
+
+# Resume DDL1 and DDL2. 
+# Now BACKUP/RESTORE should stop after acquiring BML.
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# con1: Reaping DDL1
+# con2: Reaping DDL2
+SET DEBUG_SYNC= 'now SIGNAL continue_bup WAIT_FOR bup_running TIMEOUT 1';
+
+== Checkpoint C ==
+#
+# DDL1= TRUNCATE t1
+# DDL2= TRUNCATE t2
+# DDL3= REPAIR TABLE t1
+# DDL4= OPTIMIZE TABLE t2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "RESTORE FROM%";
+state	info
+debug sync point: start_do_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+# Checking that DDL1 and DDL2 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+0
+rows_in_t2
+0
+Table	Checksum
+bml_test.t1	0
+bml_test.t2	0
+==================
+
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl3_blocked';
+REPAIR TABLE t1;
+# Wait for DDL3 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl3_blocked TIMEOUT 3';
+# con3: Send DDL3 but it is blocked by BACKUP/RESTORE 
+#       (will not be in backup) make it send signal when
+#       blocked on BML.
+SET DEBUG_SYNC= 'bml_enter_check SIGNAL ddl4_blocked';
+OPTIMIZE TABLE t2;
+# Wait for DDL4 to send its signal.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl4_blocked TIMEOUT 3';
+
+== Checkpoint D ==
+#
+# DDL1= TRUNCATE t1
+# DDL2= TRUNCATE t2
+# DDL3= REPAIR TABLE t1
+# DDL4= OPTIMIZE TABLE t2
+#
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "REPAIR TABLE t1%"
+     OR info LIKE "OPTIMIZE TABLE t2%";
+state	info
+BML: waiting until released	OPTIMIZE TABLE t2
+BML: waiting until released	REPAIR TABLE t1
+# Checking that DDL3 and DDL4 have not executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
+0
+rows_in_t2
+0
+Table	Checksum
+bml_test.t1	0
+bml_test.t2	0
+==================
+
+# Resume BACKUP/RESTORE - this allows DDL3 and DDL4 to complete.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# con5: Reaping BACKUP/RESTORE
+backup_id
+500
+SET debug="-d";
+# con3: Completing DDL3
+Table	Op	Msg_type	Msg_text
+bml_test.t1	repair	status	OK
+# con4: Completing DDL4
+Table	Op	Msg_type	Msg_text
+bml_test.t2	optimize	status	OK
 
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
-con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_4;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-CREATE DATABASE bup_ddl_blocker_1;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-DROP DATABASE bup_ddl_blocker_2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Backing up database -- will block with lock
-BACKUP DATABASE * TO "bup_ddl_blocker.bak";
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: before_block_ddl	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
-state	info
-debug sync point: after_start_ddl	CREATE DATABASE bup_ddl_blocker_1
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP DATABASE bup_ddl_blocker_2%";
-state	info
-debug sync point: after_start_ddl	DROP DATABASE bup_ddl_blocker_2
-con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: after_block_ddl	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-CREATE DATABASE bup_ddl_blocker_3;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-DROP DATABASE bup_ddl_blocker_4;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_3%";
-state	info
-debug sync point: before_check_ddl_blocked	CREATE DATABASE bup_ddl_blocker_3
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
-state	info
-debug sync point: before_check_ddl_blocked	DROP DATABASE bup_ddl_blocker_4
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 4 results for backup.
-
-con1: Showing databases after updates and backup
-con1: bup_ddl_blocker_2 and bup_ddl_blocker_4 are not present
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_1
-bup_ddl_blocker_3
-con1: Dropping the database tables
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_3;
-con1: Restoring the database
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-backup_id
-#
-con1: Showing databases that were backed up
-con1: bup_ddl_blocker_2 and bup_ddl_blocker_3 are not present
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_1
-bup_ddl_blocker_4
-con1: Cleanup
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_4;
-
-Starting Test 4 - Restore
-
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
-con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_4;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
-backup_id
-#
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-CREATE DATABASE bup_ddl_blocker_1;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-DROP DATABASE bup_ddl_blocker_2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Restoring database -- will block with lock
-RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
-state	info
-debug sync point: after_start_ddl	CREATE DATABASE bup_ddl_blocker_1
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP DATABASE bup_ddl_blocker_2%";
-state	info
-debug sync point: after_start_ddl	DROP DATABASE bup_ddl_blocker_2
-con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-CREATE DATABASE bup_ddl_blocker_3;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-DROP DATABASE bup_ddl_blocker_4;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_3%";
-state	info
-debug sync point: before_check_ddl_blocked	CREATE DATABASE bup_ddl_blocker_3
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
-state	info
-debug sync point: before_check_ddl_blocked	DROP DATABASE bup_ddl_blocker_4
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 4 results for restore.
-
-con1: Database bup_ddl_blocker_4 should not be in restored data.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_1
-bup_ddl_blocker_2
-bup_ddl_blocker_3
-
-Starting Test 5 - Backup
-
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
-con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2 CHARACTER SET latin1;
-CREATE DATABASE bup_ddl_blocker_4 CHARACTER SET latin1;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-TRUNCATE TABLE bup_ddl_blocker_2.t1;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Backing up database -- will block with lock
-BACKUP DATABASE * TO "bup_ddl_blocker.bak";
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: before_block_ddl	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
-state	info
-debug sync point: after_start_ddl	TRUNCATE TABLE bup_ddl_blocker_2.t1
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
-state	info
-debug sync point: after_start_ddl	ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2
-con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: after_block_ddl	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-TRUNCATE TABLE bup_ddl_blocker_4.t1;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
-state	info
-debug sync point: before_check_ddl_blocked	ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
-state	info
-debug sync point: before_check_ddl_blocked	TRUNCATE TABLE bup_ddl_blocker_4.t1
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 5 results for backup.
-
-con1: Showing databases after updates and backup
-con1: bup_ddl_blocker_2.t1 has been truncated.
-con1: bup_ddl_blocker_1 and bup_ddl_blocker_3 are renamed 
-con1: bup_ddl_blocker_4.t1 has been truncated.
-con1: bup_ddl_blocker_2 and bup_ddl_blocker_4 have had their charset changed. 
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-SHOW CREATE DATABASE bup_ddl_blocker_2;
-Database	Create Database
-bup_ddl_blocker_2	CREATE DATABASE `bup_ddl_blocker_2` /*!40100 DEFAULT CHARACTER SET latin2 */
-SHOW CREATE DATABASE bup_ddl_blocker_4;
-Database	Create Database
-bup_ddl_blocker_4	CREATE DATABASE `bup_ddl_blocker_4` /*!40100 DEFAULT CHARACTER SET latin2 */
-SELECT * FROM bup_ddl_blocker_2.t1;
-col_a
-SELECT * FROM bup_ddl_blocker_4.t1;
-col_a
-con1: Dropping the database tables
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_4;
-con1: Restoring the database
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-backup_id
-#
-con1: Showing databases that were backed up
-con1: bup_ddl_blocker_1 has been renamed and
-con1: bup_ddl_blocker_2.t1 has been truncated.
-con1: bup_ddl_blocker_4 has not had its character set changed. 
-con1: bup_ddl_blocker_4.t1 has not been truncated.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-SHOW CREATE DATABASE bup_ddl_blocker_2;
-Database	Create Database
-bup_ddl_blocker_2	CREATE DATABASE `bup_ddl_blocker_2` /*!40100 DEFAULT CHARACTER SET latin2 */
-SHOW CREATE DATABASE bup_ddl_blocker_4;
-Database	Create Database
-bup_ddl_blocker_4	CREATE DATABASE `bup_ddl_blocker_4` /*!40100 DEFAULT CHARACTER SET latin1 */
-SELECT * FROM bup_ddl_blocker_2.t1;
-col_a
-SELECT * FROM bup_ddl_blocker_4.t1;
-col_a
-01 Some data to test
-02 Some data to test
-03 Some data to test
-con1: Cleanup
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_4;
-
-Starting Test 5 - Restore
-
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
-con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2 CHARACTER SET latin1;
-CREATE DATABASE bup_ddl_blocker_4 CHARACTER SET latin1;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-con1: Loading data
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
-backup_id
-#
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-TRUNCATE TABLE bup_ddl_blocker_2.t1;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Restoring database -- will block with lock
-RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
-state	info
-debug sync point: after_start_ddl	ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
-state	info
-debug sync point: after_start_ddl	TRUNCATE TABLE bup_ddl_blocker_2.t1
-con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-TRUNCATE TABLE bup_ddl_blocker_4.t1;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
-state	info
-debug sync point: before_check_ddl_blocked	TRUNCATE TABLE bup_ddl_blocker_4.t1
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
-state	info
-debug sync point: before_check_ddl_blocked	ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 5 results for restore.
-
-con1: bup_ddl_blocker_4 has had its character set changed. 
-con1: bup_ddl_blocker_2.t1 has not been truncated.
-con1: bup_ddl_blocker_4.t1 has been truncated.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-Database (bup_ddl_blocker_%)
-bup_ddl_blocker_2
-bup_ddl_blocker_4
-SHOW CREATE DATABASE bup_ddl_blocker_2;
-Database	Create Database
-bup_ddl_blocker_2	CREATE DATABASE `bup_ddl_blocker_2` /*!40100 DEFAULT CHARACTER SET latin1 */
-SHOW CREATE DATABASE bup_ddl_blocker_4;
-Database	Create Database
-bup_ddl_blocker_4	CREATE DATABASE `bup_ddl_blocker_4` /*!40100 DEFAULT CHARACTER SET latin2 */
-SELECT * FROM bup_ddl_blocker_2.t1;
-col_a
-01 Some data to test
-02 Some data to test
-03 Some data to test
-SELECT * FROM bup_ddl_blocker_4.t1;
-col_a
-con1: Cleanup
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_4;
-
-Starting Test 6 - Backup
-
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
-con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_1;
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_3;
-CREATE DATABASE bup_ddl_blocker_4;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker_1.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_3.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-con1: Loading data
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("01 Some data to test", 10);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("02 Some data to test", 09);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("03 Some data to test", 12);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test", 3);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test", 8);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test", 11);
-CREATE INDEX 2t1col_b ON bup_ddl_blocker_2.t1 (col_b);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("01 Some data to test", 2);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("02 Some data to test", 4);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("03 Some data to test", 5);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test", 1);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test", 12);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test", 3);
-CREATE INDEX 4t1col_b ON bup_ddl_blocker_4.t1 (col_b);
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b);
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Backing up database -- will block with lock
-BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
-bup_ddl_blocker_3, bup_ddl_blocker_4
-TO "bup_ddl_blocker.bak";
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: before_block_ddl	BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
-bup_ddl_blocker_3, bup_ddl_blocker_4
-TO "bup_ddl_blocker.bak"
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE INDEX 1t1col_b%";
-state	info
-debug sync point: after_start_ddl	CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b)
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 2t1col_b%";
-state	info
-debug sync point: after_start_ddl	DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1
-con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug sync point: after_block_ddl	BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
-bup_ddl_blocker_3, bup_ddl_blocker_4
-TO "bup_ddl_blocker.bak"
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b);
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE INDEX 3t1col_b%";
-state	info
-debug sync point: before_check_ddl_blocked	CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b)
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 4t1col_b%";
-state	info
-debug sync point: before_check_ddl_blocked	DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 6 results for backup.
-
-con1: Showing database tables after updates and backup
-con1: bup_ddl_blocker_2 and bup_ddl_blocker_4 indexes are not present
-SHOW INDEX FROM bup_ddl_blocker_1.t1;
-Table	t1
-Non_unique	1
-Key_name	1t1col_b
-Seq_in_index	1
-Column_name	col_b
-Collation	A
-Cardinality	3
-Sub_part	NULL
-Packed	NULL
-Null	YES
-Index_type	BTREE
-Comment	
-Index_Comment	
-SHOW INDEX FROM bup_ddl_blocker_2.t1;
-SHOW INDEX FROM bup_ddl_blocker_3.t1;
-Table	t1
-Non_unique	1
-Key_name	3t1col_b
-Seq_in_index	1
-Column_name	col_b
-Collation	A
-Cardinality	3
-Sub_part	NULL
-Packed	NULL
-Null	YES
-Index_type	BTREE
-Comment	
-Index_Comment	
-SHOW INDEX FROM bup_ddl_blocker_4.t1;
-con1: Dropping the database tables
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_3;
-DROP DATABASE bup_ddl_blocker_4;
-con1: Restoring the database
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-backup_id
-#
-con1: Showing databases that were backed up
-con1: bup_ddl_blocker_2 and bup_ddl_blocker_3 indexes are not present
-SHOW INDEX FROM bup_ddl_blocker_1.t1;
-Table	t1
-Non_unique	1
-Key_name	1t1col_b
-Seq_in_index	1
-Column_name	col_b
-Collation	A
-Cardinality	3
-Sub_part	NULL
-Packed	NULL
-Null	YES
-Index_type	BTREE
-Comment	
-Index_Comment	
-SHOW INDEX FROM bup_ddl_blocker_2.t1;
-SHOW INDEX FROM bup_ddl_blocker_3.t1;
-SHOW INDEX FROM bup_ddl_blocker_4.t1;
-Table	t1
-Non_unique	1
-Key_name	4t1col_b
-Seq_in_index	1
-Column_name	col_b
-Collation	A
-Cardinality	3
-Sub_part	NULL
-Packed	NULL
-Null	YES
-Index_type	BTREE
-Comment	
-Index_Comment	
-con1: Cleanup
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_3;
-DROP DATABASE bup_ddl_blocker_4;
-
-Starting Test 6 - Restore
-
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
-con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_1;
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_3;
-CREATE DATABASE bup_ddl_blocker_4;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker_1.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_3.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-con1: Loading data
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("01 Some data to test", 10);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("02 Some data to test", 09);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("03 Some data to test", 12);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test", 3);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test", 8);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test", 11);
-CREATE INDEX 2t1col_b ON bup_ddl_blocker_2.t1 (col_b);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("01 Some data to test", 2);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("02 Some data to test", 4);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("03 Some data to test", 5);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test", 1);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test", 12);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test", 3);
-CREATE INDEX 4t1col_b ON bup_ddl_blocker_4.t1 (col_b);
-BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
-bup_ddl_blocker_3, bup_ddl_blocker_4
-TO "bup_ddl_blocker_orig.bak";
-backup_id
-#
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b);
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1;
-con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
-con1: Restoring database -- will block with lock
-RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE INDEX 1t1col_b%";
-state	info
-debug sync point: after_start_ddl	CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b)
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 2t1col_b%";
-state	info
-debug sync point: after_start_ddl	DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1
-con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RESTORE FROM%";
-state	info
-debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE
-con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
-con4: Try a DDL but it is blocked by backup -- will not be in backup
-CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b);
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
-con5: Try a DDL but it is blocked by backup -- will not be in backup
-DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1;
-con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE INDEX 3t1col_b%";
-state	info
-debug sync point: before_check_ddl_blocked	CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b)
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 4t1col_b%";
-state	info
-debug sync point: before_check_ddl_blocked	DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1
-con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con5: Completing DDL
-backup_id
-#
-
-Verifying Test 6 results for restore.
-
-con1: Showing databases that were backed up
-con1: bup_ddl_blocker_1 and bup_ddl_blocker_4 indexes are not present
-SHOW INDEX FROM bup_ddl_blocker_1.t1;
-SHOW INDEX FROM bup_ddl_blocker_2.t1;
-Table	t1
-Non_unique	1
-Key_name	2t1col_b
-Seq_in_index	1
-Column_name	col_b
-Collation	A
-Cardinality	3
-Sub_part	NULL
-Packed	NULL
-Null	YES
-Index_type	BTREE
-Comment	
-Index_Comment	
-SHOW INDEX FROM bup_ddl_blocker_3.t1;
-Table	t1
-Non_unique	1
-Key_name	3t1col_b
-Seq_in_index	1
-Column_name	col_b
-Collation	A
-Cardinality	3
-Sub_part	NULL
-Packed	NULL
-Null	YES
-Index_type	BTREE
-Comment	
-Index_Comment	
-SHOW INDEX FROM bup_ddl_blocker_4.t1;
-con1: Cleanup
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_3;
-DROP DATABASE bup_ddl_blocker_4;
-
-Starting Test 7
-
-DROP TABLE IF EXISTS test.t2;
-DROP TABLE IF EXISTS bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE test.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY;
-con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-INSERT INTO test.t2 VALUES ("01 Some data to test");
-INSERT INTO test.t2 VALUES ("02 Some data to test");
-INSERT INTO test.t2 VALUES ("03 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-con1: Show that the new data doesn't exist before backup.
-SELECT * FROM bup_ddl_blocker.t1;
-col_a
-01 Some data to test
-02 Some data to test
-03 Some data to test
-SELECT * FROM test.t2;
-col_a
-01 Some data to test
-02 Some data to test
-03 Some data to test
-SELECT * FROM bup_ddl_blocker.t3;
-col_a
-01 Some data to test
-02 Some data to test
-03 Some data to test
-con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
-con2: Get a DDL going and stop in the middle
-ALTER TABLE bup_ddl_blocker.t1 ADD COLUMN col_b int;
-con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
-con3: Get a DDL going and stop in the middle
-ALTER TABLE test.t2 ADD COLUMN col_b int;
-con3: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
-con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con4_started WAIT_FOR status_shown';
-con4: Get a DDL going and stop in the middle
-ALTER TABLE bup_ddl_blocker.t3 ADD COLUMN col_b int;
-con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t1%";
-state	info
-debug sync point: after_start_ddl	ALTER TABLE bup_ddl_blocker.t1 ADD COLUMN col_b int
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE test.t2%";
-state	info
-debug sync point: after_start_ddl	ALTER TABLE test.t2 ADD COLUMN col_b int
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t3%";
-state	info
-debug sync point: after_start_ddl	ALTER TABLE bup_ddl_blocker.t3 ADD COLUMN col_b int
-con5: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown';
-con2: Completing DDL
-con3: Completing DDL
-con4: Completing DDL
-con1: Showing columns after updates and backup
-DESCRIBE bup_ddl_blocker.t1;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-DESCRIBE test.t2;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-DESCRIBE bup_ddl_blocker.t3;
-Field	Type	Null	Key	Default	Extra
-col_a	char(40)	YES		NULL	
-col_b	int(11)	YES		NULL	
-
-Verifying Test 7 results:
-
-T1 should have the changes after backup - count(*) = 2
-SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS
-WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'bup_ddl_blocker';
-count(*)
-2
-T2 should the changes after backup - count(*) = 2
-SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS
-WHERE TABLE_NAME = 't2' AND TABLE_SCHEMA = 'test';
-count(*)
+== Checkpoint E ==
+#
+# DDL1= TRUNCATE t1
+# DDL2= TRUNCATE t2
+# DDL3= REPAIR TABLE t1
+# DDL4= OPTIMIZE TABLE t2
+#
+# Checking that DDL3 and DDL4 have executed.
+CALL test.check_results();
+Tables_in_bml_test
+t1
+t2
+rows_in_t1
 2
-T3 should not have the changes after backup - count(*) = 2
-SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS
-WHERE TABLE_NAME = 't3' AND TABLE_SCHEMA = 'bup_ddl_blocker';
-count(*)
+rows_in_t2
 2
-DROP TABLE test.t2;
-DROP DATABASE bup_ddl_blocker;
+Table	Checksum
+bml_test.t1	2865344526
+bml_test.t2	1578680517
+==================
+
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+DROP DATABASE bml_test;
+DROP PROCEDURE test.check_results;
+
+########################################################
+#
+# Test BACKUP with statements not blocked by BML: 
+#   CREATE USER and CREATE SERVER
+#
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+CREATE DATABASE bml_test;
+# con1: Start CREATE USER statement and make it stop after it has started.
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started  
+                                             WAIT_FOR continue_ddl';
+CREATE USER bml_usr;;
+# con5: Wait for DDL to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Start BACKUP command making it to stop in the middle.
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL bup_started 
+         					    WAIT_FOR finish_bup';
+SET SESSION debug="+d,set_backup_id";
+BACKUP DATABASE bml_test TO 'bml_test.bkp';;
+# Waiting for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_started TIMEOUT 3';
+# Check the state of both statements.
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "CREATE USER%";
+state	info
+debug sync point: after_backup_start_backup	BACKUP DATABASE bml_test TO 'bml_test.bkp'
+debug sync point: before_execute_sql_command	CREATE USER bml_usr
+# Checking that CREATE USER has not executed yet.
+SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+User	Password
+# Checking that BACKUP is not blocked by DDL.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Resume and reap CREATE USER;
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# Check that CREATE USER has executed.
+SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+User	Password
+bml_usr	
+# See that bml_srv does not exist at this point.
+SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+Server_name
+# Start CREATE SERVER while BACKUP is in progress.
+CREATE SERVER bml_srv FOREIGN DATA WRAPPER mysql OPTIONS  (USER 'user');
+# See that it has executed.
+SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+Server_name
+bml_srv
+# Let BACKUP finish its operation.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# Reap BACKUP.
+backup_id
+500
+SET debug="-d";
+SET DEBUG_SYNC= 'reset';
+
+########################################################
+#
+# Test RESTORE with statements not blocked by BML: 
+#   DROP SERVER and SET PASSWORD
+#
+########################################################
+
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+SET DEBUG_SYNC= 'reset';
+# con1: Start DROP SERVER statement and make it stop after it has started.
+SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl_started  
+ 					     WAIT_FOR continue_ddl';
+DROP SERVER bml_srv;;
+# con5: Wait for DDL to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR ddl_started TIMEOUT 3';
+SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+# con5: Start RESTORE command making it to stop in the middle.
+SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL bup_started 
+         					     WAIT_FOR finish_bup';
+SET SESSION debug="+d,set_backup_id";
+RESTORE FROM 'bml_test.bkp' OVERWRITE;;
+# Waiting for RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_started TIMEOUT 3';
+# Check the state of both statements.
+SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "RESTORE FROM%"
+     OR info LIKE "DROP SERVER%";
+state	info
+debug sync point: after_backup_start_restore	RESTORE FROM 'bml_test.bkp' OVERWRITE
+debug sync point: before_execute_sql_command	DROP SERVER bml_srv
+# Checking that DROP SERVER has not executed yet.
+SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+Server_name
+bml_srv
+# Checking that RESTORE is not blocked by DDL.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+object	notes	error_num
+backup kernel	starting	0
+backup kernel	running	0
+# Resume and reap DROP SERVER;
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+# Check that DROP SERVER has executed.
+SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+Server_name
+# Check current user's pasword.
+SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+User	Password
+bml_usr	
+# Start SET PASSWORD while RESTORE is in progress.
+SET PASSWORD FOR bml_usr = PASSWORD('password');
+# See that password was set.
+SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+User	Password
+bml_usr	*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19
+# Let RESTORE finish its operation.
+SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+# Reap RESTORE.
+backup_id
+500
+SET debug="-d";
+SET DEBUG_SYNC= 'reset';
+SET DEBUG_SYNC= 'reset';
+DROP DATABASE bml_test;
+DROP USER bml_usr;
+PURGE BACKUP LOGS;
 SET DEBUG_SYNC= 'reset';

=== modified file 'mysql-test/suite/backup/r/backup_timeout.result'
--- a/mysql-test/suite/backup/r/backup_timeout.result	2008-11-19 22:01:28 +0000
+++ b/mysql-test/suite/backup/r/backup_timeout.result	2009-02-11 13:10:41 +0000
@@ -1,29 +1,29 @@
 SET DEBUG_SYNC= 'reset';
-DROP DATABASE IF EXISTS bup_ddl_blocker;
-CREATE DATABASE bup_ddl_blocker;
+DROP DATABASE IF EXISTS bup_bml;
+CREATE DATABASE bup_bml;
 con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
+CREATE TABLE bup_bml.t1 (col_a CHAR(40)) ENGINE=INNODB;
 con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
+INSERT INTO bup_bml.t1 VALUES ("01 Some data to test");
+INSERT INTO bup_bml.t1 VALUES ("02 Some data to test");
+INSERT INTO bup_bml.t1 VALUES ("03 Some data to test");
 SHOW VARIABLES LIKE 'backup_wait%';
 Variable_name	Value
 backup_wait_timeout	50
 Part A
 con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_blocked WAIT_FOR timeout_done';
-con1: Get a backup going and stop after the DDL blocker is fired.
-BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
+SET DEBUG_SYNC= 'after_bml_activated SIGNAL bup_blocked WAIT_FOR timeout_done';
+con1: Get a backup going and stop after BML is activated.
+BACKUP DATABASE bup_bml TO "bup_bml.bak";
 SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-Set ddl timeout to 1 second
+Set timeout to 1 second
 SET backup_wait_timeout = 1;
 SHOW VARIABLES LIKE 'backup_wait%';
 Variable_name	Value
 backup_wait_timeout	1
 con2: Try a ddl operation and watch it expire
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MEMORY;
-ERROR HY000: The backup wait timeout has expired for query 'CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MEMORY'.
+CREATE TABLE bup_bml.t2 (col_a CHAR(40)) ENGINE=MEMORY;
+ERROR HY000: The backup wait timeout has expired for query 'CREATE TABLE bup_bml.t2 (col_a CHAR(40)) ENGINE=MEMORY'.
 release the lock.
 con5: Resume all.
 SET DEBUG_SYNC= 'now SIGNAL timeout_done';
@@ -31,32 +31,32 @@ backup_id
 #
 Part B
 con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_blocked WAIT_FOR timeout_done';
+SET DEBUG_SYNC= 'after_bml_activated SIGNAL bup_blocked WAIT_FOR timeout_done';
 con1: Get a backup going and stop after the DDL blocker is fired.
-BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
+BACKUP DATABASE bup_bml TO "bup_bml.bak";
 SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-Set ddl timeout to 0 seconds
+Set timeout to 0 seconds
 SET backup_wait_timeout = 0;
 SHOW VARIABLES LIKE 'backup_wait%';
 Variable_name	Value
 backup_wait_timeout	0
 con2: Try a ddl operation and it should expire
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY;
-ERROR HY000: The backup wait timeout has expired for query 'CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY'.
+CREATE TABLE bup_bml.t3 (col_a CHAR(40)) ENGINE=MEMORY;
+ERROR HY000: The backup wait timeout has expired for query 'CREATE TABLE bup_bml.t3 (col_a CHAR(40)) ENGINE=MEMORY'.
 SET backup_wait_timeout = 100;
 SHOW VARIABLES LIKE 'backup_wait%';
 Variable_name	Value
 backup_wait_timeout	100
 con3: Try a ddl operation and it should not expire
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY;
+CREATE TABLE bup_bml.t3 (col_a CHAR(40)) ENGINE=MEMORY;
 release the lock.
 con5: Resume all.
 SET DEBUG_SYNC= 'now SIGNAL timeout_done';
 backup_id
 #
-USE bup_ddl_blocker;
+USE bup_bml;
 SHOW FULL TABLES;
-Tables_in_bup_ddl_blocker	Table_type
+Tables_in_bup_bml	Table_type
 t1	BASE TABLE
 t3	BASE TABLE
 Part C
@@ -70,5 +70,5 @@ SET backup_wait_timeout = DEFAULT;
 SHOW VARIABLES LIKE 'backup_wait%';
 Variable_name	Value
 backup_wait_timeout	50
-DROP DATABASE bup_ddl_blocker;
+DROP DATABASE bup_bml;
 SET DEBUG_SYNC= 'reset';

=== renamed file 'mysql-test/suite/backup/t/backup_ddl_blocker.test' => 'mysql-test/suite/backup/t/backup_bml.test'
--- a/mysql-test/suite/backup/t/backup_ddl_blocker.test	2008-12-06 00:24:23 +0000
+++ b/mysql-test/suite/backup/t/backup_bml.test	2009-02-11 13:10:41 +0000
@@ -1,73 +1,54 @@
 #
-# This test is for the DDL blocker.
-# The goals of the test should be to ensure the following assumptions for
-# the behaviour of the DDL blocker hold true.
-#
-# a) DDL that are running are allowed to complete and backup blocks
-# b) backup blocks all DDL even if not part of backup
-# c) DDL operations do not block each other
-#
-# The results of the backup should show (based on statements above):
-#
-# a) Test result for this assumption: Included in backup
-# b) Test result for this assumption: Not included in backup
-#
-# The test shall run two sets of data definition statements. 
-#
-# 1) test DDL in progress that block backup and while the backup in progress
-#    check that DDLs that start after the backup are blocked
-# 2) DDL do not block each other
-#
-# These set of DDL statements to test include the following. The DDL 
-# statements shall be run in sets with each set a separate test. These tests
-# will show the assumptions above to be true.
-#
-# Test  DDL Tested
-# ----  ------------------
-#  1    CREATE TABLE
-#  1    ALTER TABLE
-#  2    RENAME TABLE
-#  2    REPAIR TABLE
-#  3    OPTIMIZE TABLE
-#  3    DROP TABLE
-#  4    CREATE DATABASE
-#  4    DROP DATABASE
-#  5    ALTER DATABASE
-#  5    TRUNCATE TABLE
-#  6    CREATE INDEX
-#  6    DROP INDEX
-#  7    DDL statements do not block each other
+# This test is for the Backup Metadata Lock.
 #
-# The tests shall be run once for backup and again for restore.
+# Per WL#4644, BML blocks execution of the following statements.
 #
-# TODO : Add a native driver to the test when one becomes available
+#  DROP   DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TRIGGER/INDEX
+#  DROP   USER/TABLESPACE
+#  CREATE DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TRIGGER/INDEX
+#  ALTER  DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TABLESPACE
+#  RENAME TABLE/USER
+#  GRANT/REVOKE
+#  TRUNCATE/OPTIMIZE/REPAIR TABLE
+#
+# This gives 32 statements which are blocked by DML.
+#
+# For each blocked statement the following requirements will be checked:
+#
+# a) Statement that is running when BACKUP/RESTORE starts is allowed to complete 
+#    and BACKUP/RESTORE blocks waiting for its completion.
+# b) Once BACKUP/RESTORE is started, the statement is blocked and waits for
+#    the BACKUP/RESTORE statement to complete.
+# c) Statmenents blocked by BML do not block each other. 
+#
+# Additionally:
+#
+# d) Statements not listed above should not be blocked by BML.
+#
+# The above assumptions will be tested using a "subroutine" bml_test.inc.
+#
+# Note: the fact that blocked statement will timeout after specified time is
+# tested in backup_timeout test.
 #
 
+--source include/not_embedded.inc
 --source include/have_innodb.inc
+--source include/have_falcon.inc
+--source include/have_debug.inc
 --source include/have_debug_sync.inc
---source include/not_embedded.inc
-
-SET DEBUG_SYNC= 'reset';
 
 #
 # Remove backup files (if they exist)
 #
-# Note: More preparatory cleanup is done in
-# include/backup_ddl_create_data.inc
-#
 
-let $MYSQLD_DATADIR= `select @@datadir`;
+let $bdir=`select @@backupdir`;
 --error 0,1
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
+--remove_file $bdir/bml_test_orig.bkp;
 --error 0,1
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
+--remove_file $bdir/bml_test.bkp;
 
 #
-# Connections used in this test
-#
-# con1       used to create data, load data, and run the backup 
-# con2-con5  used for DDL statements: 2 before backup and 2 during backup
-# con6       used to show status/processlist 
+# Connections used by bml_test.inc
 #
 
 connect (con1,localhost,root,,);
@@ -75,2007 +56,631 @@ connect (con2,localhost,root,,);
 connect (con3,localhost,root,,);
 connect (con4,localhost,root,,);
 connect (con5,localhost,root,,);
-connect (con6,localhost,root,,);
-
-connection con1;
 
 #
-# Backup test sequence diagram (not UML)
+# Create bml_test database
 #
-# The included test files follow this pattern of execution
-# for backup or restore operations.
-#
-# Four DDL statements and a backup command are specified.
-# The first two DDL statements are run as "in progress" when
-# the backup starts. The other two DDL statements are run
-# when the backup or restore is already running. Tests results
-# show the realization of the assumptions above.
-#
-#     con1      con2     con3     con4     con5     con6
-#    (setup)     |        |        |        |        |
-#       |        |        |        |        |        |
-#       |        |        |        |        |        |
-#       |   statememt 1   |        |        |        |
-#       |        |   statement 2   |        |        |
-#       |        |        |        |        |    show status
-# BACKUP/RESTORE |        |        |        |        |
-#       |        |        |        |        |        |
-#       |        |        |        |        |        |
-#       |      <...>    <...>      |        |        |
-#       |        |        |   statement 3   |        |
-#       |        |        |        |   statement 4   |
-#       |        |        |        |        |    show status
-#     <...>      |        |      <...>    <...>      |
-#   (results)    |        |        |        |        |
-#
-# Note: The resume of the commands is indicated with <...> and
-#       may occur in any order.
-#
-# Note by Ingo: I wonder if the line above "(results)" is correct.
-# I understand the above explanations so that DDL3 and 4 cannot
-# resume before BACKUP/RESTORE finished. But the line indicates
-# that these can resume in any order.
-
-
-##############################################################
---echo 
---echo Starting Test 1 - Backup
---echo 
-##############################################################
-
-# Create data for this test and tailor it to the test.
---source include/backup_ddl_create_data.inc
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Backing up database -- will block with lock
-send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t2%";
-
---echo con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 1 results for backup.
---echo
-##############################################################
-
-# Show that all changes got applied.
---echo con1: Showing columns after updates and backup
-DESCRIBE bup_ddl_blocker.t1;
-DESCRIBE bup_ddl_blocker.t2;
-DESCRIBE bup_ddl_blocker.t3;
-DESCRIBE bup_ddl_blocker.t4;
-
---echo con1: Dropping the database tables
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t2,
-           bup_ddl_blocker.t3, bup_ddl_blocker.t4;
-
---echo con1: Restoring the database
---replace_column 1 #
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-
---echo con1: Showing columns that were backed up
-
---echo con1: Table t3 should not be in restored data.
---echo con1: Table t4 should not have new column in restored data.
-DESCRIBE bup_ddl_blocker.t1;
-DESCRIBE bup_ddl_blocker.t2;
---error ER_NO_SUCH_TABLE
-DESCRIBE bup_ddl_blocker.t3;
-DESCRIBE bup_ddl_blocker.t4;
-
-
-
-##############################################################
---echo 
---echo Starting Test 1 - Restore
---echo 
-##############################################################
-
-# Create data for this test and tailor it to the test.
---source include/backup_ddl_create_data.inc
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-
-# Get a backup to work with.
---replace_column 1 #
-BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Restoring database -- will block with lock
-send RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t2%";
-
---echo con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 1 results for restore.
---echo
-##############################################################
-
---echo con1: Table t1 should not be in restored data.
---echo con1: Table t2 should not have new column in restored data.
---echo con1: Table t3 should be in restored data.
---echo con1: Table t4 should have new column in restored data.
---error ER_NO_SUCH_TABLE
-DESCRIBE bup_ddl_blocker.t1;
-DESCRIBE bup_ddl_blocker.t2;
-DESCRIBE bup_ddl_blocker.t3;
-DESCRIBE bup_ddl_blocker.t4;
-
-# Cleanup
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
-
-
-
-##############################################################
---echo 
---echo Starting Test 2 - Backup
---echo 
-##############################################################
-
-# Create data for this test and tailor it to the test.
---source include/backup_ddl_create_data.inc
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send REPAIR TABLE bup_ddl_blocker.t2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Backing up database -- will block with lock
-send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t2%";
-
---echo con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send REPAIR TABLE bup_ddl_blocker.t4;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 2 results for backup.
---echo
-##############################################################
-
-# Show that all changes got applied.
---echo con1: Showing columns after updates and backup
-use bup_ddl_blocker;
-SHOW TABLES;
-
---echo con1: Dropping the database tables
-DROP TABLE bup_ddl_blocker.t01, bup_ddl_blocker.t2,
-           bup_ddl_blocker.t03, bup_ddl_blocker.t4;
-
---echo con1: Restoring the database
---replace_column 1 #
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-
---echo con1: Showing columns that were backed up
---echo con1: Table t01 should be in restore
---echo con1: Table t03 should not be in restore
-use bup_ddl_blocker;
-SHOW TABLES;
-
-
-
-##############################################################
---echo 
---echo Starting Test 2 - Restore
---echo 
-##############################################################
-
-# Create data for this test and tailor it to the test.
---source include/backup_ddl_create_data.inc
-
-# Get a backup to work with.
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
---replace_column 1 #
-BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send REPAIR TABLE bup_ddl_blocker.t2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Restoring database -- will block with lock
-send RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t2%";
-
---echo con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send REPAIR TABLE bup_ddl_blocker.t4;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 2 results for restore.
---echo
-##############################################################
-
---echo con1: Table t01 should not be in restored data.
-use bup_ddl_blocker;
-SHOW TABLES;
-
-# Cleanup
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
-
-
-
-##############################################################
---echo 
---echo Starting Test 3 - Backup
---echo 
-##############################################################
-
-# Create data for this test and tailor it to the test.
---source include/backup_ddl_create_data.inc
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send OPTIMIZE TABLE bup_ddl_blocker.t1;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send DROP TABLE bup_ddl_blocker.t2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Backing up database -- will block with lock
-send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP TABLE bup_ddl_blocker.t2%";
-
---echo con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send OPTIMIZE TABLE bup_ddl_blocker.t3;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send DROP TABLE bup_ddl_blocker.t4;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 3 results for backup.
---echo
-##############################################################
-
-# Show that all changes got applied.
---echo con1: Showing columns after updates and backup
-use bup_ddl_blocker;
-SHOW TABLES;
-
---echo con1: Dropping the database tables
-DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
-
---echo con1: Restoring the database
---replace_column 1 #
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
-
---echo con1: Showing columns that were backed up
---echo con1: Table t2 should not be in restore
-use bup_ddl_blocker;
-SHOW TABLES;
-
-
-
-##############################################################
---echo 
---echo Starting Test 3 - Restore
---echo 
-##############################################################
-
-# Create data for this test and tailor it to the test.
---source include/backup_ddl_create_data.inc
-
-# Get a backup to work with.
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
---replace_column 1 #
-BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send OPTIMIZE TABLE bup_ddl_blocker.t1;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send DROP TABLE bup_ddl_blocker.t2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Restoring database -- will block with lock
-send RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP TABLE bup_ddl_blocker.t2%";
-
---echo con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send OPTIMIZE TABLE bup_ddl_blocker.t3;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send DROP TABLE bup_ddl_blocker.t4;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 3 results for restore.
---echo
-##############################################################
-
---echo con1: Table t4 should not be in restored data.
-use bup_ddl_blocker;
-SHOW TABLES;
-
-# Cleanup
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
-
-
-
-##############################################################
---echo 
---echo Starting Test 4 - Backup
---echo 
-##############################################################
-
---disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
---enable_warnings
-
-# Create databases.
---echo con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_4;
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-
---echo con1: Loading data
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-
---echo con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send CREATE DATABASE bup_ddl_blocker_1;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send DROP DATABASE bup_ddl_blocker_2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Backing up database -- will block with lock
-send BACKUP DATABASE * TO "bup_ddl_blocker.bak";
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP DATABASE bup_ddl_blocker_2%";
-
---echo con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send CREATE DATABASE bup_ddl_blocker_3;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send DROP DATABASE bup_ddl_blocker_4;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
-
-##############################################################
---echo
---echo Verifying Test 4 results for backup.
---echo
-##############################################################
-
-# Show that all changes got applied.
---echo con1: Showing databases after updates and backup
---echo con1: bup_ddl_blocker_2 and bup_ddl_blocker_4 are not present
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-
---echo con1: Dropping the database tables
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_3;
-
---echo con1: Restoring the database
---replace_column 1 #
 --disable_warnings
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
+DROP DATABASE IF EXISTS bml_test;
 --enable_warnings
+CREATE DATABASE bml_test;
 
---echo con1: Showing databases that were backed up
---echo con1: bup_ddl_blocker_2 and bup_ddl_blocker_3 are not present
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-
---echo con1: Cleanup
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_4;
-
-##############################################################
---echo 
---echo Starting Test 4 - Restore
---echo 
-##############################################################
---disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
---enable_warnings
-
-# Create databases.
---echo con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_4;
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-
---echo con1: Loading data
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-
---echo con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-
-# Get a backup to work with.
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
---replace_column 1 #
-BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send CREATE DATABASE bup_ddl_blocker_1;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send DROP DATABASE bup_ddl_blocker_2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Restoring database -- will block with lock
-send RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP DATABASE bup_ddl_blocker_2%";
-
---echo con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send CREATE DATABASE bup_ddl_blocker_3;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send DROP DATABASE bup_ddl_blocker_4;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_3%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
+#
+# Infrastructure for automatic generation of DDL statements.
+#
 
-##############################################################
---echo
---echo Verifying Test 4 results for restore.
---echo
-##############################################################
+USE test;
 
---echo con1: Database bup_ddl_blocker_4 should not be in restored data.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
+CREATE TABLE objects (pos int, type char(10), name char(16), args text);
+
+--delimiter \\
+
+CREATE FUNCTION drop_stmt(pos_arg int) RETURNS text
+BEGIN
+  DECLARE stmt text;
+  SELECT concat('DROP ', type, ' ', name)
+    INTO stmt
+    FROM test.objects WHERE pos=pos_arg;
+  RETURN stmt;
+END\\
+
+
+CREATE FUNCTION create_stmt(pos_arg int) RETURNS text
+BEGIN
+  DECLARE stmt text;
+  SELECT concat('CREATE ', type, ' ', name, args)
+    INTO stmt
+    FROM test.objects WHERE pos=pos_arg;
+  RETURN stmt;
+END\\
+
+CREATE FUNCTION alter_stmt(pos_arg int) RETURNS text
+BEGIN
+  DECLARE stmt text;
+  SELECT concat('ALTER ', type, ' ', name, args)
+    INTO stmt
+    FROM test.objects WHERE pos=pos_arg;
+  RETURN stmt;
+END\\
+
+--delimiter ;
+
+
+
+################################################################
+# 
+# First group of statements.
+#
+# drop: DATABASE TABLE VIEW FUNCTION PROCEDURE EVENT TRIGGER INDEX
+# create: DATABASE TABLE VIEW FUNCTION PROCEDURE EVENT TRIGGER INDEX
+#
+################################################################
+
+USE test;
+
+TRUNCATE TABLE test.objects;
+INSERT INTO test.objects VALUES 
+  (1, 'DATABASE', 'bml_test_db1', ''), 
+  (2, 'TABLE',    't1',	'(a int)'), 
+  (3, 'VIEW',	  'v1',	' AS SELECT * FROM t2'), 
+  (4, 'FUNCTION', 'f1',	'() RETURNS int RETURN 1'),
+  (5, 'PROCEDURE','p1',	'() SET @foo=1'),
+  (6, 'EVENT',	  'e1',	' ON SCHEDULE EVERY 1 YEAR DISABLE DO SET @foo=1'),
+  (7, 'TRIGGER',  'r1',	' AFTER UPDATE ON t2 FOR EACH ROW SET @foo=1'),
+  (8, 'INDEX',	  'i1 ON t2', '(b)');
+
+--delimiter \\
+
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+  # show databases
+  SHOW DATABASES LIKE 'bml%';
+  # show objects in bml_test database
+  SELECT table_name AS name, table_type AS type
+    FROM information_schema.tables
+    WHERE table_schema = 'bml_test'
+  UNION SELECT routine_name , routine_type
+    FROM information_schema.routines
+    WHERE routine_schema = 'bml_test'
+  UNION SELECT event_name, 'EVENT'
+    FROM information_schema.events
+    WHERE event_schema = 'bml_test'
+  UNION SELECT trigger_name, 'TRIGGER'
+    FROM information_schema.triggers
+    WHERE trigger_schema = 'bml_test';
+  # show definiton of t2 to see the index if created
+  SHOW CREATE TABLE bml_test.t2;
+END\\
+
+--delimiter ;
+
+#
+# Populate bml_test database 
+#
+
+USE bml_test;
+
+# base table for the view
+CREATE TABLE t2 (b int);
+
+# all the objects specified in test.objects table
+let $count=`SELECT count(*) FROM test.objects`;
+let $iter= $count;
+while ($iter)
+{
+  let $pos= $count - $iter + 1;
+  # Create objects in correct order - starting from 1
+  let $stmt=`SELECT test.create_stmt($count - $iter + 1)`;
+  --eval $stmt
+  dec $iter;
+}
+
+# Show contents of the database and backup it for the future.
+CALL test.check_results();
+--replace_column 1 #
+BACKUP DATABASE bml_test, bml_test_db1 TO 'bml_test_orig.bkp';
+
+#
+# Test the statements:
+#
+# Let Ci be the CREATE statement for object i in table objects, Di be the 
+# DELETE statement for that object. Statements will be tested in the following
+# order:
+#
+#	DDL1	DDL2	DDL3	DDL4	backup or restore
+#      ==================================================
+#	C3	D4	D1	C2	BACKUP
+#	C1	D2	D3	C4	RESTORE
+#	C7	D8	D5	C6	BACKUP
+#	C3	D4	D7	C8	RESTORE
+#	and so on ...
+#
+# Note: The order *is* important. RESTORE is using the image created by previous
+# BACKUP and it is important that this image does not contain the object to be
+# created by DDL4. 
+# For example, DDL2 drops object 4 before first BACKUP completes and thus this 
+# object will not be included in the backup image. This, when DDL4 is executed 
+# after RESTORE has completed, it will create object 4 without an error.
+#
+
+let $pos=0;
+while (`select $pos < $count`)
+{
+  let $pos1= 1 + (($pos+0) % $count);	  # position of obj1
+  let $pos2= 1 + (($pos+1) % $count);	  # position of obj2
+  let $pos3= 1 + (($pos+2) % $count);	  # position of obj3
+  let $pos4= 1 + (($pos+3) % $count);	  # position of obj4
+
+  let $C1= `select test.create_stmt($pos1)`;
+  let $D1= `select test.drop_stmt($pos1)`;
+  let $C2= `select test.create_stmt($pos2)`;
+  let $D2= `select test.drop_stmt($pos2)`;
+  let $C3= `select test.create_stmt($pos3)`;
+  let $D3= `select test.drop_stmt($pos3)`;
+  let $C4= `select test.create_stmt($pos4)`;
+  let $D4= `select test.drop_stmt($pos4)`;
+
+  #
+  #  Testing BACKUP operation with DDLs on objects at pos ($pos, $pos+1)
+  #
+  #  Note: obj4 will be deleted by DDL2 before BACKUP completes and thus
+  #  will not be included in the backup image.
+  #
+
+  let $DDL1= $C3;
+  let $DDL2= $D4; 
+  let $DDL3= $D1;
+  let $DDL4= $C2;
+
+  # drop obj3 and obj3 to be created by DDL1 and DDL4
+  --eval $D3
+  --eval $D2
+
+  # test BACKUP operation
+  let $backup_to= bml_test.bkp;
+  --source suite/backup/include/bml_test.inc 
+
+  #
+  #  Testing RESTORE operation with DDLs on objects at pos ($pos+2, $pos+3)
+  # 
+
+  let $DDL1= $C1; # obj1 was dropped by DDL3 above
+  let $DDL2= $D2;
+  let $DDL3= $D3;
+  let $DDL4= $C4; # obj4 not present after RESTORE
+
+  # test RESTORE operation
+  let $restore_from= bml_test.bkp;
+  --source suite/backup/include/bml_test.inc 
+
+  # re-create obj3 dropped by DDL3
+  --eval $C3
+
+  # prepare for next iteration
+
+  --remove_file $bdir/bml_test.bkp
+
+  inc $pos;
+  inc $pos;
+  inc $pos;
+  inc $pos;
+}
+
+
+################################################################
+# 
+# Second group of statements.
+#
+# alter: DATABASE TABLE VIEW FUNCTION PROCEDURE EVENT (TABLESPACE)
+#
+################################################################
+
+RESTORE FROM 'bml_test_orig.bkp' OVERWRITE;
+
+TRUNCATE TABLE test.objects;
+INSERT INTO test.objects VALUES
+  (1, 'DATABASE',  'bml_test_db1', ' CHARACTER SET = utf8'),
+  (2, 'TABLE',	   't1', ' ADD INDEX `i` (a)'),
+  (3, 'VIEW',	   'v1', ' AS SELECT 1'),
+  (4, 'FUNCTION',  'f1', " COMMENT 'testing alter'"),
+  (5, 'PROCEDURE', 'p1', " COMMENT 'testing alter'"),
+  (6, 'EVENT',	   'e1', ' RENAME TO e2');
+
+# Note: I could not get ALTER TABLESPACE to work - see Bug#41548
+# When the bug is fixed add the following line to objects table:
+# (7, 'TABLESPACE', 'bml_ts1', " ADD DATAFILE 'bml_ts1.dat' ENGINE=falcon");
+
+--delimiter \\
+
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+  SHOW CREATE DATABASE  bml_test_db1;
+  SHOW CREATE TABLE     bml_test.t1;
+  SHOW CREATE VIEW      bml_test.v1;
+  SHOW CREATE FUNCTION  bml_test.f1;
+  SHOW CREATE PROCEDURE bml_test.p1;
+  SELECT event_name FROM information_schema.events
+                    WHERE event_schema = 'bml_test';
+END\\
+
+--delimiter ;
+
+#
+# check situation before tests
+#
+
+CALL test.check_results();
+
+#
+# Test the statements
+#
+
+let $count= `select count(*) from test.objects`;
+let $pos= 0;
+while (`select $pos < $count`)
+{
+  #
+  # Testing BACKUP and DDLs for objects at positions: 0,1,2,3
+  #
+  
+  let $DDL1= `select test.alter_stmt(1 + (($pos+0) % $count))`;
+  let $DDL2= `select test.alter_stmt(1 + (($pos+1) % $count))`;
+  let $DDL3= `select test.alter_stmt(1 + (($pos+2) % $count))`;
+  let $DDL4= `select test.alter_stmt(1 + (($pos+3) % $count))`;
+
+  # test BACKUP operation
+  let $backup_to= bml_test.bkp;
+  --source suite/backup/include/bml_test.inc 
+
+  RESTORE FROM 'bml_test_orig.bkp'  OVERWRITE;
+  
+  #
+  # Testing RESTORE and DDLs for objects at positions: 2,3,4,5
+  #
+
+  inc $pos;
+  inc $pos;
+
+  let $DDL1= `select test.alter_stmt(1 + (($pos+0) % $count))`;
+  let $DDL2= `select test.alter_stmt(1 + (($pos+1) % $count))`;
+  let $DDL3= `select test.alter_stmt(1 + (($pos+2) % $count))`;
+  let $DDL4= `select test.alter_stmt(1 + (($pos+3) % $count))`;
+
+  # test RESTORE operation
+  let $restore_from= bml_test.bkp;
+  --source suite/backup/include/bml_test.inc 
+
+  --remove_file $bdir/bml_test.bkp
+  RESTORE FROM 'bml_test_orig.bkp'  OVERWRITE;
+
+  inc $pos;
+  inc $pos;
+}
 
+#
 # Cleanup
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
-
-
-
-##############################################################
---echo 
---echo Starting Test 5 - Backup
---echo 
-##############################################################
+#
 
 --disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
+DROP DATABASE IF EXISTS bml_test_db1;
+--remove_file $bdir/bml_test_orig.bkp
+DROP TABLE test.objects;
+DROP FUNCTION test.drop_stmt;
+DROP FUNCTION test.create_stmt;
+DROP FUNCTION test.alter_stmt;
 --enable_warnings
 
-# Create databases.
---echo con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2 CHARACTER SET latin1;
-CREATE DATABASE bup_ddl_blocker_4 CHARACTER SET latin1;
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-
---echo con1: Loading data
-
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
-
---echo con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send TRUNCATE TABLE bup_ddl_blocker_2.t1;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Backing up database -- will block with lock
-send BACKUP DATABASE * TO "bup_ddl_blocker.bak";
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
-
---echo con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send TRUNCATE TABLE bup_ddl_blocker_4.t1;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
-
-connection con1;
---replace_column 1 #
-reap;
+################################################################
+# 
+# Third group of statements.
+#
+# drop:       USER TABLESPACE
+# privileges: GRANT REVOKE
+# rename:     TABLE USER
+#
+################################################################
+
+DROP DATABASE bml_test;
+CREATE DATABASE bml_test;
+
+CREATE USER bml_u1;
+CREATE USER bml_u2;
+CREATE USER bml_u3;
+CREATE TABLESPACE bml_ts1 ADD DATAFILE 'bml_ts1.dat' ENGINE=falcon;
+CREATE TABLESPACE bml_ts2 ADD DATAFILE 'bml_ts2.dat' ENGINE=falcon;
+
+CREATE TABLE bml_test.t1 (a int);
+CREATE TABLE bml_test.t2 (b int);
+
+--delimiter \\
+
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+  SHOW TABLES IN bml_test;
+  # show users
+  SELECT DISTINCT grantee AS user 
+    FROM information_schema.user_privileges
+    WHERE grantee like '%bml%';
+  # show privileges
+  SELECT grantee, count(*) > 0 AS has_privileges
+    FROM information_schema.schema_privileges
+    WHERE grantee like '%bml%'
+    GROUP BY grantee;
+  # show tablespaces
+  SELECT tablespace_name, file_name 
+    FROM information_schema.files
+    WHERE tablespace_name like 'bml%';
+END\\
+
+--delimiter ;
+
+#
+# Round 1
+#
+let $DDL1= RENAME TABLE t1 TO t1_renamed;
+let $DDL2= DROP USER bml_u1;
+let $DDL3= RENAME USER bml_u2 TO bml_u2_renamed;
+let $DDL4= DROP TABLESPACE bml_ts1 ENGINE=falcon;
+let $backup_to= bml_test.bkp;
+--source suite/backup/include/bml_test.inc 
+
+
+#
+# Round 2
+#
+let $DDL1= RENAME USER bml_u2_renamed TO bml_u2;
+let $DDL2= GRANT ALL ON bml_test.* TO bml_u3;
+let $DDL3= RENAME TABLE t1_renamed TO t1;
+let $DDL4= GRANT ALL ON bml_test.* TO bml_u2;
+let $restore_from= bml_test.bkp;
+--source suite/backup/include/bml_test.inc 
+
+--remove_file $bdir/bml_test.bkp
+
+#
+# Round 3
+#
+let $DDL1= DROP TABLESPACE bml_ts2 ENGINE=falcon;
+let $DDL2= REVOKE ALL ON bml_test.* FROM bml_u2;
+let $DDL3= DROP USER bml_u2;
+let $DDL4= REVOKE ALL ON bml_test.* FROM bml_u3;
+let $backup_to= bml_test.bkp;
+--source suite/backup/include/bml_test.inc 
 
-##############################################################
---echo
---echo Verifying Test 5 results for backup.
---echo
-##############################################################
+#
+# Cleanup
+# 
 
-# Show that all changes got applied.
---echo con1: Showing databases after updates and backup
---echo con1: bup_ddl_blocker_2.t1 has been truncated.
---echo con1: bup_ddl_blocker_1 and bup_ddl_blocker_3 are renamed 
---echo con1: bup_ddl_blocker_4.t1 has been truncated.
---echo con1: bup_ddl_blocker_2 and bup_ddl_blocker_4 have had their charset changed. 
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-SHOW CREATE DATABASE bup_ddl_blocker_2;
-SHOW CREATE DATABASE bup_ddl_blocker_4;
-SELECT * FROM bup_ddl_blocker_2.t1;
-SELECT * FROM bup_ddl_blocker_4.t1;
-
---echo con1: Dropping the database tables
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_4;
+--remove_file $bdir/bml_test.bkp
+DROP USER bml_u3;
+# check that no global objects are  left-over
+CALL test.check_results();
 
---echo con1: Restoring the database
---replace_column 1 #
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
 
---echo con1: Showing databases that were backed up
---echo con1: bup_ddl_blocker_1 has been renamed and
---echo con1: bup_ddl_blocker_2.t1 has been truncated.
---echo con1: bup_ddl_blocker_4 has not had its character set changed. 
---echo con1: bup_ddl_blocker_4.t1 has not been truncated.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-SHOW CREATE DATABASE bup_ddl_blocker_2;
-SHOW CREATE DATABASE bup_ddl_blocker_4;
-SELECT * FROM bup_ddl_blocker_2.t1;
-SELECT * FROM bup_ddl_blocker_4.t1;
-
---echo con1: Cleanup
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_4;
-
-##############################################################
---echo 
---echo Starting Test 5 - Restore
---echo 
-##############################################################
+################################################################
+# 
+# Fourth group of statements.
+#
+# table maintenance: TRUNCATE OPTIMIZE REPAIR
+#
+################################################################
 
---disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
---enable_warnings
+DROP DATABASE bml_test;
+CREATE DATABASE bml_test;
 
-# Create databases.
---echo con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_2 CHARACTER SET latin1;
-CREATE DATABASE bup_ddl_blocker_4 CHARACTER SET latin1;
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40)) ENGINE=MYISAM;
-
---echo con1: Loading data
-
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test");
-
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test");
+USE bml_test;
 
---echo con1: Show that the new data doesn't exist before backup.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
+CREATE TABLE t1 (a int) ENGINE=myisam;
+CREATE TABLE t2 (a int) ENGINE=myisam;
 
-# Get a backup to work with.
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
---replace_column 1 #
-BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
+INSERT INTO t1 VALUES (1),(2);
+INSERT INTO t2 VALUES (3),(4);
 
-connection con2;
+--delimiter \\
 
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send TRUNCATE TABLE bup_ddl_blocker_2.t1;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Restoring database -- will block with lock
-send RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
-
---echo con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send TRUNCATE TABLE bup_ddl_blocker_4.t1;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
+DROP PROCEDURE IF EXISTS test.check_results\\
+CREATE PROCEDURE test.check_results()
+BEGIN
+ SHOW TABLES IN bml_test;
+ SELECT count(*) AS rows_in_t1 FROM bml_test.t1;
+ SELECT count(*) AS rows_in_t2 FROM bml_test.t2;
+ CHECKSUM TABLE bml_test.t1, bml_test.t2 EXTENDED;
+END\\
 
-# Reconnect to con1 and fetch its result.
+--delimiter ;
 
-connection con1;
---replace_column 1 #
-reap;
+#
+# Check with BACKUP
+#
+let $DDL1= OPTIMIZE TABLE t1;
+let $DDL2= REPAIR TABLE t2 USE_FRM;
+let $DDL3= TRUNCATE TABLE t1;
+let $DDL4= TRUNCATE TABLE t2;
+let $backup_to= bml_test.bkp;
+--source suite/backup/include/bml_test.inc 
 
-##############################################################
---echo
---echo Verifying Test 5 results for restore.
---echo
-##############################################################
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (3);
 
---echo con1: bup_ddl_blocker_4 has had its character set changed. 
---echo con1: bup_ddl_blocker_2.t1 has not been truncated.
---echo con1: bup_ddl_blocker_4.t1 has been truncated.
-SHOW DATABASES LIKE 'bup_ddl_blocker_%';
-SHOW CREATE DATABASE bup_ddl_blocker_2;
-SHOW CREATE DATABASE bup_ddl_blocker_4;
-SELECT * FROM bup_ddl_blocker_2.t1;
-SELECT * FROM bup_ddl_blocker_4.t1;
-
---echo con1: Cleanup
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_4;
+#
+# Check with RESTORE
+#
+let $DDL1= TRUNCATE t1;
+let $DDL2= TRUNCATE t2;
+let $DDL3= REPAIR TABLE t1;
+let $DDL4= OPTIMIZE TABLE t2;
+let $restore_from= bml_test.bkp;
+--source suite/backup/include/bml_test.inc 
 
+#
 # Cleanup
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
-
-
-
-##############################################################
---echo 
---echo Starting Test 6 - Backup
---echo 
-##############################################################
-
---disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
---enable_warnings
-
-# Create databases.
---echo con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_1;
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_3;
-CREATE DATABASE bup_ddl_blocker_4;
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker_1.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_3.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-
---echo con1: Loading data
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("01 Some data to test", 10);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("02 Some data to test", 09);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("03 Some data to test", 12);
-
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test", 3);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test", 8);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test", 11);
-
-CREATE INDEX 2t1col_b ON bup_ddl_blocker_2.t1 (col_b); 
-
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("01 Some data to test", 2);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("02 Some data to test", 4);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("03 Some data to test", 5);
-
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test", 1);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test", 12);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test", 3);
-
-CREATE INDEX 4t1col_b ON bup_ddl_blocker_4.t1 (col_b); 
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b); 
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Backing up database -- will block with lock
-send BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
-                     bup_ddl_blocker_3, bup_ddl_blocker_4
-                     TO "bup_ddl_blocker.bak";
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE INDEX 1t1col_b%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP INDEX 2t1col_b%";
-
---echo con6: Resume all and wait for backup to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "BACKUP DATABASE%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b);
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE INDEX 3t1col_b%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP INDEX 4t1col_b%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
+#
 
-connection con1;
---replace_column 1 #
-reap;
+--remove_file $bdir/bml_test.bkp
+DROP DATABASE bml_test;
+DROP PROCEDURE test.check_results;
 
-##############################################################
 --echo
---echo Verifying Test 6 results for backup.
+--echo ########################################################
+--echo #
+--echo # Test BACKUP with statements not blocked by BML: 
+--echo #   CREATE USER and CREATE SERVER
+--echo #
+--echo ########################################################
 --echo
-##############################################################
-
-# Show that all changes got applied.
---echo con1: Showing database tables after updates and backup
---echo con1: bup_ddl_blocker_2 and bup_ddl_blocker_4 indexes are not present
---query_vertical SHOW INDEX FROM bup_ddl_blocker_1.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_2.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_3.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_4.t1
-
---echo con1: Dropping the database tables
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_3;
-DROP DATABASE bup_ddl_blocker_4;
-
---echo con1: Restoring the database
---replace_column 1 #
---disable_warnings
-RESTORE FROM "bup_ddl_blocker.bak" OVERWRITE;
---enable_warnings
-
---echo con1: Showing databases that were backed up
---echo con1: bup_ddl_blocker_2 and bup_ddl_blocker_3 indexes are not present
---query_vertical SHOW INDEX FROM bup_ddl_blocker_1.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_2.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_3.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_4.t1
-
---echo con1: Cleanup
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_3;
-DROP DATABASE bup_ddl_blocker_4;
-
-##############################################################
---echo 
---echo Starting Test 6 - Restore
---echo 
-##############################################################
-
---disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker_1;
-DROP DATABASE IF EXISTS bup_ddl_blocker_2;
-DROP DATABASE IF EXISTS bup_ddl_blocker_3;
-DROP DATABASE IF EXISTS bup_ddl_blocker_4;
---enable_warnings
-
-# Create databases.
---echo con1: Creating databases
-CREATE DATABASE bup_ddl_blocker_1;
-CREATE DATABASE bup_ddl_blocker_2;
-CREATE DATABASE bup_ddl_blocker_3;
-CREATE DATABASE bup_ddl_blocker_4;
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker_1.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_2.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_3.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-CREATE TABLE bup_ddl_blocker_4.t1 (col_a CHAR(40), col_b int) ENGINE=INNODB;
-
---echo con1: Loading data
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("01 Some data to test", 10);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("02 Some data to test", 09);
-INSERT INTO bup_ddl_blocker_1.t1 VALUES ("03 Some data to test", 12);
-
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("01 Some data to test", 3);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("02 Some data to test", 8);
-INSERT INTO bup_ddl_blocker_2.t1 VALUES ("03 Some data to test", 11);
-
-CREATE INDEX 2t1col_b ON bup_ddl_blocker_2.t1 (col_b); 
-
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("01 Some data to test", 2);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("02 Some data to test", 4);
-INSERT INTO bup_ddl_blocker_3.t1 VALUES ("03 Some data to test", 5);
-
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("01 Some data to test", 1);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("02 Some data to test", 12);
-INSERT INTO bup_ddl_blocker_4.t1 VALUES ("03 Some data to test", 3);
-
-CREATE INDEX 4t1col_b ON bup_ddl_blocker_4.t1 (col_b); 
 
-# Get a backup to work with.
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
---replace_column 1 #
-BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
-                bup_ddl_blocker_3, bup_ddl_blocker_4
-                TO "bup_ddl_blocker_orig.bak";
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b);
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1;
-
-# Start the backup and allow it to break on lock.
-
-connection con1;
-
---echo con1: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con1: Activate synchronization points for restore.
-SET DEBUG_SYNC= 'before_block_ddl SIGNAL bup_blocked WAIT_FOR status_shown';
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_started WAIT_FOR status_shown2';
---echo con1: Restoring database -- will block with lock
-send RESTORE FROM "bup_ddl_blocker_orig.bak" OVERWRITE;
-
-connection con6;
-
---echo con6: Wait for con1 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE INDEX 1t1col_b%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP INDEX 2t1col_b%";
-
---echo con6: Resume all and wait for restore to start after DDL finish.
-SET DEBUG_SYNC= 'now SIGNAL status_shown WAIT_FOR bup_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "RESTORE FROM%";
-
-connection con4;
-
---echo con4: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con4_started
-                 WAIT_FOR status_shown2';
---echo con4: Try a DDL but it is blocked by backup -- will not be in backup
-send CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b);
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
---echo con5: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'before_check_ddl_blocked SIGNAL con5_started
-                 WAIT_FOR status_shown2';
---echo con5: Try a DDL but it is blocked by backup -- will not be in backup
-send DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1;
-
-connection con6;
-
---echo con6: Wait for con5 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con5_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "CREATE INDEX 3t1col_b%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "DROP INDEX 4t1col_b%";
-
---echo con6: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown2';
-
-# Reconnect to connections and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-connection con5;
---echo con5: Completing DDL
-reap;
-
-# Reconnect to con1 and fetch its result.
+connection default;
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
+CREATE DATABASE bml_test;
 
-connection con1;
---replace_column 1 #
-reap;
+ connection con1;
+ --echo # con1: Start CREATE USER statement and make it stop after it has started.
+ SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl1_started  
+                                             WAIT_FOR continue_ddl';
+ --send CREATE USER bml_usr;
+
+# Start BACKUP
+ 
+         connection con5;
+         --echo # con5: Wait for DDL to reach its synchronization point.
+         SET DEBUG_SYNC= 'now WAIT_FOR ddl1_started TIMEOUT 3';
+         # To be safe clear before_execute_sql_command which is hit by
+         # every executed statement
+         SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+
+         --echo # con5: Start BACKUP command making it to stop in the middle.
+         SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL bup_started 
+         					    WAIT_FOR finish_bup';
+         # arrange for deterministic backup_id = 500
+         SET SESSION debug="+d,set_backup_id";
+         --send BACKUP DATABASE bml_test TO 'bml_test.bkp';
+ 
+connection default;
+--echo # Waiting for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_started TIMEOUT 3';
 
-##############################################################
+--echo # Check the state of both statements.
+eval SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+  WHERE info LIKE "BACKUP DATABASE%"
+     OR info LIKE "CREATE USER%";
+--echo # Checking that CREATE USER has not executed yet.
+SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+--echo # Checking that BACKUP is not blocked by DDL.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+
+--echo # Resume and reap CREATE USER;
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+
+ connection con1;
+ --reap
+ --echo # Check that CREATE USER has executed.
+ SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+ 
+ --echo # See that bml_srv does not exist at this point.
+ SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+ --echo # Start CREATE SERVER while BACKUP is in progress.
+ CREATE SERVER bml_srv FOREIGN DATA WRAPPER mysql OPTIONS  (USER 'user');
+ --echo # See that it has executed.
+ SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+
+ --echo # Let BACKUP finish its operation.
+ SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+
+         connection con5;
+         --echo # Reap BACKUP.
+         --reap
+         SET debug="-d";
+	 SET DEBUG_SYNC= 'reset';
+
+--echo
+--echo ########################################################
+--echo #
+--echo # Test RESTORE with statements not blocked by BML: 
+--echo #   DROP SERVER and SET PASSWORD
+--echo #
+--echo ########################################################
 --echo
---echo Verifying Test 6 results for restore.
---echo
-##############################################################
-
---echo con1: Showing databases that were backed up
---echo con1: bup_ddl_blocker_1 and bup_ddl_blocker_4 indexes are not present
---query_vertical SHOW INDEX FROM bup_ddl_blocker_1.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_2.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_3.t1
---query_vertical SHOW INDEX FROM bup_ddl_blocker_4.t1
-
---echo con1: Cleanup
-DROP DATABASE bup_ddl_blocker_1;
-DROP DATABASE bup_ddl_blocker_2;
-DROP DATABASE bup_ddl_blocker_3;
-DROP DATABASE bup_ddl_blocker_4;
 
-# Cleanup
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak;
+connection default;
+SET DEBUG_SYNC= 'reset';
+PURGE BACKUP LOGS;
 
+ connection con1;
+ SET DEBUG_SYNC= 'reset';
+ --echo # con1: Start DROP SERVER statement and make it stop after it has started.
+ SET DEBUG_SYNC= 'before_execute_sql_command SIGNAL ddl_started  
+ 					     WAIT_FOR continue_ddl';
+ --send DROP SERVER bml_srv;
+
+# Start RESTORE
+ 
+         connection con5;
+        --echo # con5: Wait for DDL to reach its synchronization point.
+         SET DEBUG_SYNC= 'now WAIT_FOR ddl_started TIMEOUT 3';
+         # To be safe clear before_execute_sql_command which is hit by
+         # every executed statement
+         SET DEBUG_SYNC='before_execute_sql_command CLEAR';
+
+         --echo # con5: Start RESTORE command making it to stop in the middle.
+         SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL bup_started 
+         					     WAIT_FOR finish_bup';
+         # arrange for deterministic backup_id = 500
+         SET SESSION debug="+d,set_backup_id";
+         --send RESTORE FROM 'bml_test.bkp' OVERWRITE;
+ 
+connection default;
+--echo # Waiting for RESTORE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_started TIMEOUT 3';
 
+--echo # Check the state of both statements.
+eval SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
+  WHERE info LIKE "RESTORE FROM%"
+     OR info LIKE "DROP SERVER%";
+--echo # Checking that DROP SERVER has not executed yet.
+SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+--echo # Checking that RESTORE is not blocked by DDL.
+SELECT object, notes, error_num FROM mysql.backup_progress WHERE backup_id=500;
+
+--echo # Resume and reap DROP SERVER;
+SET DEBUG_SYNC= 'now SIGNAL continue_ddl';
+
+ connection con1;
+ --reap
+ --echo # Check that DROP SERVER has executed.
+ SELECT Server_name FROM mysql.servers WHERE Server_name like 'bml%';
+ 
+ --echo # Check current user's pasword.
+ SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+ --echo # Start SET PASSWORD while RESTORE is in progress.
+ SET PASSWORD FOR bml_usr = PASSWORD('password');
+ --echo # See that password was set.
+ SELECT User, Password FROM mysql.user WHERE User like 'bml%';
+
+ --echo # Let RESTORE finish its operation.
+ SET DEBUG_SYNC= 'now SIGNAL finish_bup';
+
+         connection con5;
+         --echo # Reap RESTORE.
+         --reap
+         SET debug="-d";
+         SET DEBUG_SYNC= 'reset';
 
-##############################################################
---echo 
---echo Starting Test 7
---echo 
-##############################################################
+ connection con1;
+ SET DEBUG_SYNC= 'reset';
 
 #
-# Test 7 sequence diagram (not UML)
-#
-#   con1     con2     con3     con4       con5
-#  (setup)    |        |        |          |
-#     |       |        |        |          |
-#     |   ALTER a.t1   |        |          |
-#     |       |   ALTER b.t2    |          |
-#     |       |        |    ALTER a.t3     |
-#     |       |        |        | lock("DDL_in_progress");
-#     |       |        |        |    <wait for locks>
-#     |       |        |        |    <release locks>
-#     |     <...>    <...>    <...>        |
-# (results)   |        |        |          | 
-#
-# Note: The resume of the commands is indicated with <...> and
-#       may occur in any order.
+# Cleanup
 #
 
---disable_warnings
-DROP TABLE IF EXISTS test.t2;
-DROP TABLE IF EXISTS bup_ddl_blocker.t1, bup_ddl_blocker.t3;
---enable_warnings
-
-# Create transaction tables and load them with data.
---echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
-CREATE TABLE test.t2 (col_a CHAR(40)) ENGINE=MYISAM;
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY;
-
---echo con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
-
-INSERT INTO test.t2 VALUES ("01 Some data to test");
-INSERT INTO test.t2 VALUES ("02 Some data to test");
-INSERT INTO test.t2 VALUES ("03 Some data to test");
-
-INSERT INTO bup_ddl_blocker.t3 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t3 VALUES ("03 Some data to test");
-
---echo con1: Show that the new data doesn't exist before backup.
-SELECT * FROM bup_ddl_blocker.t1;
-SELECT * FROM test.t2;
-SELECT * FROM bup_ddl_blocker.t3;
-
-connection con2;
-
---echo con2: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con2_started WAIT_FOR status_shown';
---echo con2: Get a DDL going and stop in the middle
-send ALTER TABLE bup_ddl_blocker.t1 ADD COLUMN col_b int;
-
-connection con3;
-
---echo con3: Wait for con2 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con2_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con3_started WAIT_FOR status_shown';
---echo con3: Get a DDL going and stop in the middle
-send ALTER TABLE test.t2 ADD COLUMN col_b int;
-
-connection con4;
-
---echo con3: Wait for con3 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con3_started';
---echo con3: Activate synchronization point for DDL.
-SET DEBUG_SYNC= 'after_start_ddl SIGNAL con4_started WAIT_FOR status_shown';
---echo con4: Get a DDL going and stop in the middle
-send ALTER TABLE bup_ddl_blocker.t3 ADD COLUMN col_b int;
-
-connection con5;
-
---echo con5: Wait for con4 to reach its synchronization point.
-SET DEBUG_SYNC= 'now WAIT_FOR con4_started';
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t1%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE test.t2%";
-SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t3%";
-
---echo con5: Resume all.
-SET DEBUG_SYNC= 'now SIGNAL status_shown';
-
-# Reconnect to con2, con3, and con4 and fetch their results.
-
-connection con2;
---echo con2: Completing DDL
-reap;
-
-connection con3;
---echo con3: Completing DDL
-reap;
-
-connection con4;
---echo con4: Completing DDL
-reap;
-
-# Reconnect to con1 and show results
-
-connection con1;
-
-# Do selects to show that all changes got applied.
---echo con1: Showing columns after updates and backup
-DESCRIBE bup_ddl_blocker.t1;
-DESCRIBE test.t2;
-DESCRIBE bup_ddl_blocker.t3;
 
-##############################################################
---echo
---echo Verifying Test 7 results:
---echo
-##############################################################
-
---echo T1 should have the changes after backup - count(*) = 2
-SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS
-WHERE TABLE_NAME = 't1' AND TABLE_SCHEMA = 'bup_ddl_blocker';
-
---echo T2 should the changes after backup - count(*) = 2
-SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS
-WHERE TABLE_NAME = 't2' AND TABLE_SCHEMA = 'test';
-
---echo T3 should not have the changes after backup - count(*) = 2
-SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS
-WHERE TABLE_NAME = 't3' AND TABLE_SCHEMA = 'bup_ddl_blocker';
-
-DROP TABLE test.t2;
-DROP DATABASE bup_ddl_blocker;
-
-# Normally, when tests are run the test/ directory corresponding to the
-# test database is empty. In particular, it doesn't contain the db.opt
-# file storing database settings. Some tests rely on that, as they use
-# server options to determine these settings. If we backup test database
-# (e.g., with "BACKUP DATABASE * ...") and then restore it, then it will
-# be created using "CREATE DATABASE test" statement and this will create
-# the db.opt file. As a result, some tests run after that will fail. To
-# avoid this situation we remove the test/db.opt file as a part of
-# clean-up.
---error 0,1
-remove_file $MYSQLD_DATADIR/test/db.opt;
-remove_file $MYSQLD_DATADIR/bup_ddl_blocker_orig.bak;
+--remove_file $bdir/bml_test.bkp
+DROP DATABASE bml_test;
+DROP USER bml_usr;
 
 connection default;
 disconnect con1;
@@ -2083,7 +688,6 @@ disconnect con2;
 disconnect con3;
 disconnect con4;
 disconnect con5;
-disconnect con6;
 
+PURGE BACKUP LOGS;
 SET DEBUG_SYNC= 'reset';
-

=== modified file 'mysql-test/suite/backup/t/backup_timeout.test'
--- a/mysql-test/suite/backup/t/backup_timeout.test	2008-12-06 00:24:23 +0000
+++ b/mysql-test/suite/backup/t/backup_timeout.test	2009-02-11 13:10:41 +0000
@@ -1,5 +1,5 @@
 #
-# This test is for the DDL blocker timeout feature.
+# This test is for the backup metadata lock (BML) timeout feature.
 #
 
 --source include/have_innodb.inc
@@ -16,7 +16,7 @@ SET DEBUG_SYNC= 'reset';
 #
 
 --error 0,1
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak;
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_blocker.bak;
 
 #
 # Connections used in this test
@@ -36,19 +36,19 @@ connection con1;
 
 # Create data for this test and tailor it to the test.
 --disable_warnings
-DROP DATABASE IF EXISTS bup_ddl_blocker;
+DROP DATABASE IF EXISTS bup_bml;
 --enable_warnings
 
-CREATE DATABASE bup_ddl_blocker;
+CREATE DATABASE bup_bml;
 
 # Create a table and load it with data.
 --echo con1: Creating tables
-CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB;
+CREATE TABLE bup_bml.t1 (col_a CHAR(40)) ENGINE=INNODB;
 
 --echo con1: Loading data
-INSERT INTO bup_ddl_blocker.t1 VALUES ("01 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("02 Some data to test");
-INSERT INTO bup_ddl_blocker.t1 VALUES ("03 Some data to test");
+INSERT INTO bup_bml.t1 VALUES ("01 Some data to test");
+INSERT INTO bup_bml.t1 VALUES ("02 Some data to test");
+INSERT INTO bup_bml.t1 VALUES ("03 Some data to test");
 
 SHOW VARIABLES LIKE 'backup_wait%';
 
@@ -58,27 +58,27 @@ SHOW VARIABLES LIKE 'backup_wait%';
 --echo Part A
 
 --error 0,1
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_bml.bak
 
 connection con1;
 
 --echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_blocked WAIT_FOR timeout_done';
+SET DEBUG_SYNC= 'after_bml_activated SIGNAL bup_blocked WAIT_FOR timeout_done';
 
---echo con1: Get a backup going and stop after the DDL blocker is fired.
-send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
+--echo con1: Get a backup going and stop after BML is activated.
+send BACKUP DATABASE bup_bml TO "bup_bml.bak";
 
 connection con2;
 
 SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
 
---echo Set ddl timeout to 1 second
+--echo Set timeout to 1 second
 SET backup_wait_timeout = 1; 
 SHOW VARIABLES LIKE 'backup_wait%';
 
 --echo con2: Try a ddl operation and watch it expire
 --error ER_DDL_TIMEOUT
-CREATE TABLE bup_ddl_blocker.t2 (col_a CHAR(40)) ENGINE=MEMORY;
+CREATE TABLE bup_bml.t2 (col_a CHAR(40)) ENGINE=MEMORY;
 
 connection con5;
 --echo release the lock.
@@ -98,27 +98,27 @@ reap;
 --echo Part B
 
 --error 0,1
---remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak
+--remove_file $MYSQLD_DATADIR/bup_bml.bak
 
 connection con1;
 
 --echo con1: Activate synchronization points for backup.
-SET DEBUG_SYNC= 'after_block_ddl SIGNAL bup_blocked WAIT_FOR timeout_done';
+SET DEBUG_SYNC= 'after_bml_activated SIGNAL bup_blocked WAIT_FOR timeout_done';
 
 --echo con1: Get a backup going and stop after the DDL blocker is fired.
-send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
+send BACKUP DATABASE bup_bml TO "bup_bml.bak";
 
 connection con2;
 
 SET DEBUG_SYNC= 'now WAIT_FOR bup_blocked';
 
---echo Set ddl timeout to 0 seconds
+--echo Set timeout to 0 seconds
 SET backup_wait_timeout = 0; 
 SHOW VARIABLES LIKE 'backup_wait%';
 
 --echo con2: Try a ddl operation and it should expire
 --error ER_DDL_TIMEOUT
-CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY;
+CREATE TABLE bup_bml.t3 (col_a CHAR(40)) ENGINE=MEMORY;
 
 connection con3;
 
@@ -126,7 +126,7 @@ SET backup_wait_timeout = 100;
 SHOW VARIABLES LIKE 'backup_wait%';
 
 --echo con3: Try a ddl operation and it should not expire
-send CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=MEMORY;
+send CREATE TABLE bup_bml.t3 (col_a CHAR(40)) ENGINE=MEMORY;
 
 connection con5;
 --echo release the lock.
@@ -142,7 +142,7 @@ reap;
 connection con3;
 reap;
 
-USE bup_ddl_blocker;
+USE bup_bml;
 SHOW FULL TABLES;
 
 #
@@ -159,7 +159,8 @@ SHOW VARIABLES LIKE 'backup_wait%';
 SET backup_wait_timeout = DEFAULT; 
 SHOW VARIABLES LIKE 'backup_wait%';
 
-DROP DATABASE bup_ddl_blocker;
+DROP DATABASE bup_bml;
 
 SET DEBUG_SYNC= 'reset';
---remove_file $MYSQLD_DATADIR/bup_ddl_blocker.bak
+
+--remove_file $MYSQLD_DATADIR/bup_bml.bak

=== modified file 'mysql-test/suite/backup/t/disabled.def'
--- a/mysql-test/suite/backup/t/disabled.def	2008-12-29 12:06:48 +0000
+++ b/mysql-test/suite/backup/t/disabled.def	2009-02-11 13:10:41 +0000
@@ -1,4 +1,4 @@
-|##############################################################################
+##############################################################################
 #
 #  List the test cases that are to be disabled temporarily.
 #
@@ -12,5 +12,4 @@
 backup_no_engine              : Bug#36021 2008-04-13 rsomla server crashes when openning table with unknown storage engine
 backup_triggers_and_events    : Bug#37762 2008-07-01 rafal Test fails on remove_file for unknown reasons
 backup_no_data                : Bug#41008 2008-12-08 alik union.test does not cleanup
-backup_ddl_blocker            : Bug#41008 2008-12-08 alik union.test does not cleanup
 backup_views                  : Bug#41360 2008-12-10 ingo Test fails after merge of main and backup trees

=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt	2009-01-26 16:03:39 +0000
+++ b/sql/CMakeLists.txt	2009-02-11 13:10:41 +0000
@@ -70,8 +70,8 @@ ADD_EXECUTABLE(mysqld
                partition_info.cc rpl_utility.cc rpl_injector.cc sql_locale.cc
                rpl_rli.cc rpl_mi.cc sql_servers.cc sql_audit.cc
                sql_connect.cc scheduler.cc transaction.cc
-               ddl_blocker.cc si_objects.cc si_logs.cc
-               sql_profile.cc event_parse_data.cc mdl.cc rpl_handler.cc
+               bml.cc si_objects.cc si_logs.cc
+               sql_profile.cc event_parse_data.cc mdl.cc
                rpl_handler.cc
                ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
                ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h

=== modified file 'sql/Makefile.am'
--- a/sql/Makefile.am	2009-01-18 23:21:43 +0000
+++ b/sql/Makefile.am	2009-02-11 13:10:41 +0000
@@ -100,7 +100,7 @@ noinst_HEADERS =	item.h item_func.h item
 			event_data_objects.h event_scheduler.h \
 			sql_partition.h partition_info.h partition_element.h \
 			probes.h sql_audit.h transaction.h \
-			contributors.h sql_servers.h ddl_blocker.h \
+			contributors.h sql_servers.h bml.h \
 			si_objects.h si_logs.h sql_plist.h mdl.h records.h \
 			rpl_handler.h replication.h sql_prepare.h debug_sync.h
 
@@ -149,7 +149,7 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.
 			sql_plugin.cc sql_binlog.cc \
 			sql_builtin.cc sql_tablespace.cc partition_info.cc \
 			sql_servers.cc sql_audit.cc sha2.cc \
-			ddl_blocker.cc si_objects.cc si_logs.cc \
+			bml.cc si_objects.cc si_logs.cc \
 			event_parse_data.cc mdl.cc transaction.cc \
 			rpl_handler.cc
 

=== modified file 'sql/backup/backup_aux.h'
--- a/sql/backup/backup_aux.h	2009-02-04 10:49:16 +0000
+++ b/sql/backup/backup_aux.h	2009-02-11 13:10:41 +0000
@@ -4,7 +4,7 @@
 /** 
   @file
  
-  @brief Auxiliary declarations used in online backup code.
+  @brief Auxiliary declarations used in MySQL backup code.
 
 */ 
 

=== modified file 'sql/backup/backup_engine.h'
--- a/sql/backup/backup_engine.h	2008-12-18 21:46:36 +0000
+++ b/sql/backup/backup_engine.h	2009-02-11 13:10:41 +0000
@@ -9,7 +9,7 @@
  @file backup_engine.h
  @brief Backup engine and backup/restore driver API
 
- The interface between online backup kernel and a backup solution has form of
+ The interface between MySQL backup kernel and a backup solution has form of
  two abstract classes: @c Backup_driver implementing backup
  functionality and @c Restore_driver for restore functionality.
  Instances of these two classes are created by a factory class
@@ -27,9 +27,9 @@ class Restore_driver;
 
 /**
  @class Engine
- @brief Encapsulates online backup/restore functionality.
+ @brief Encapsulates backup/restore functionality.
 
- Any backup solution is represented in the online backup kernel by an instance
+ Any backup solution is represented in the MySQL backup kernel by an instance
  of this class, so called <em>backup engine</em>. This object is used to find
  out general information about the solution (e.g. version number). It also
  constructs backup and restore drivers (instances of @c Backup_driver

=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h	2009-01-13 12:57:55 +0000
+++ b/sql/backup/backup_kernel.h	2009-02-11 13:10:41 +0000
@@ -18,7 +18,7 @@
 #define DATA_BUFFER_SIZE  (1024*1024)
 
 /*
-  Functions used to initialize and shut down the online backup system.
+  Functions used to initialize and shut down the MySQL backup system.
   
   Note: these functions are called at plugin load and plugin shutdown time,
   respectively.

=== modified file 'sql/backup/be_default.cc'
--- a/sql/backup/be_default.cc	2009-02-03 07:48:09 +0000
+++ b/sql/backup/be_default.cc	2009-02-11 13:10:41 +0000
@@ -20,7 +20,7 @@
    @brief Contains the default backup algorithm driver.
  
    This file contains the default backup algorithm (also called a "driver"
-   in the online backup terminology. The default backup algorithm may be
+   in the MySQL backup terminology. The default backup algorithm may be
    used in place of an engine-specific driver if one does not exist or if
    chosen by the user.
  

=== modified file 'sql/backup/be_nodata.cc'
--- a/sql/backup/be_nodata.cc	2008-12-18 21:46:36 +0000
+++ b/sql/backup/be_nodata.cc	2009-02-11 13:10:41 +0000
@@ -20,7 +20,7 @@
   @brief Contains the nodata backup algorithm driver.
  
   This file contains the nodata backup algorithm (also called a "driver"
-  in the online backup terminology. The nodata driver does not read or
+  in the MySQL backup terminology. The nodata driver does not read or
   write to any files or tables. It is used to allow the backup and 
   restore of storage engines that do not store data. These include:
 

=== modified file 'sql/backup/be_nodata.h'
--- a/sql/backup/be_nodata.h	2008-12-18 21:46:36 +0000
+++ b/sql/backup/be_nodata.h	2009-02-11 13:10:41 +0000
@@ -16,7 +16,7 @@ using backup::Buffer;
 /**
   @class Engine
  
-  Encapsulates nodata online backup/restore functionality.
+  Encapsulates nodata backup/restore functionality.
  
   Using this class, the caller can create an instance of the nodata backup
   backup and restore class. The nodata driver does not read or write to any 

=== modified file 'sql/backup/be_snapshot.cc'
--- a/sql/backup/be_snapshot.cc	2009-01-21 15:00:23 +0000
+++ b/sql/backup/be_snapshot.cc	2009-02-11 13:10:41 +0000
@@ -20,7 +20,7 @@
    @brief Contains the snapshot backup algorithm driver.
   
    This file contains the snapshot backup algorithm (also called a "driver"
-   in the online backup terminology. The snapshot backup algorithm may be
+   in the MySQL backup terminology. The snapshot backup algorithm may be
    used in place of an engine-specific driver if one does not exist or if
    chosen by the user.
   

=== modified file 'sql/backup/be_thread.cc'
--- a/sql/backup/be_thread.cc	2009-01-21 15:06:10 +0000
+++ b/sql/backup/be_thread.cc	2009-02-11 13:10:41 +0000
@@ -17,7 +17,7 @@
 /**
   @file
   
-  @brief Contains the thread methods for online backup.
+  @brief Contains the thread methods for MYSQL backup.
   
   The methods in this class are used to initialize the mutexes
   for the backup threads. Helper methods are included to make thread

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2009-02-11 08:12:45 +0000
+++ b/sql/backup/kernel.cc	2009-02-11 13:10:41 +0000
@@ -71,12 +71,11 @@
 #include "be_default.h"
 #include "be_snapshot.h"
 #include "be_nodata.h"
-#include "ddl_blocker.h"
 #include "transaction.h"
 
 
 /** 
-  Global Initialization for online backup system.
+  Global Initialization for MYSQL backup system.
  
   @note This function is called in the server initialization sequence, just
   after it loads all its plugins.
@@ -89,7 +88,7 @@ int backup_init()
 }
 
 /**
-  Global clean-up for online backup system.
+  Global clean-up for MySQL backup system.
   
   @note This function is called in the server shut-down sequences, just before
   it shuts-down all its plugins.
@@ -557,10 +556,12 @@ int Backup_restore_ctx::prepare(::String
 
   // Freeze all meta-data. 
 
-  ret= obs::ddl_blocker_enable(m_thd);
+  ret= obs::bml_get(m_thd);
   if (ret)
     return fatal_error(report_error(ER_DDL_BLOCK));
 
+  DEBUG_SYNC(m_thd, "after_backup_restore_prepare");
+
   return 0;
 }
 
@@ -671,8 +672,8 @@ Backup_restore_ctx::prepare_for_backup(S
 
   info->save_start_time(when);
   m_catalog= info;
-  m_state= PREPARED_FOR_BACKUP;
-  
+  m_state= PREPARED_FOR_BACKUP;  
+
   return info;
 }
 
@@ -1025,7 +1026,7 @@ int Backup_restore_ctx::close()
   unlock_tables();                              // Never errors
 
   // unfreeze meta-data
-  obs::ddl_blocker_disable();                   // Never errors
+  obs::bml_release();                           // Never errors
 
   // restore thread options
 
@@ -1272,6 +1273,8 @@ int Backup_restore_ctx::do_restore(bool 
   Input_stream &s= *static_cast<Input_stream*>(m_stream);
   Restore_info &info= *static_cast<Restore_info*>(m_catalog);
 
+  DEBUG_SYNC(m_thd, "start_do_restore");
+
   report_stats_pre(info);                       // Never errors
 
   DBUG_PRINT("restore", ("Restoring meta-data"));

=== modified file 'sql/backup/logger.h'
--- a/sql/backup/logger.h	2009-01-21 15:00:23 +0000
+++ b/sql/backup/logger.h	2009-02-11 13:10:41 +0000
@@ -29,7 +29,7 @@ class Image_info;
 
   Destination of the messages is determined by the implementation. Currently
   messages are:
-  - for errors, reported to the online backup progress table,
+  - for errors, reported to the MySQL backup progress table,
   - for errors and warning, pushed on client's error stack,
   - written to error log and trace file (if enabled)
   

=== renamed file 'sql/ddl_blocker.cc' => 'sql/bml.cc'
--- a/sql/ddl_blocker.cc	2008-12-12 11:36:54 +0000
+++ b/sql/bml.cc	2009-02-11 13:10:41 +0000
@@ -17,7 +17,7 @@
 /**
    @file
 
-   @brief Contains methods to implement a basic DDL blocker.
+   @brief Contains methods to implement the Backup Metadata Lock (BML) service.
 
    This file contains methods that allow DDL statements to register and 
    another process (such as backup) to check to see if there are any DDL
@@ -25,122 +25,137 @@
 
    It also allows a process (such as backup) to register itself to block
    all DDL methods until the process is complete.
-  */
 
-#include "ddl_blocker.h"
+   The list of statements which should obey BML is as follows:
+
+    DROP   DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TRIGGER/INDEX
+    DROP   USER/TABLESPACE
+    CREATE DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TRIGGER/INDEX
+    ALTER  DATABASE/TABLE/VIEW/FUNCTION/PROCEDURE/EVENT/TABLESPACE
+    RENAME TABLE/USER
+    GRANT/REVOKE
+    TRUNCATE/OPTIMIZE/REPAIR TABLE
+
+   The parser (mysql_execute_command() in sql_parse.cc) arranges for calls to
+   bml_enter() and bml_leave() for these statements.
+*/
+
+#include "bml.h"
 #include "debug_sync.h"
 
-DDL_blocker_class *DDL_blocker_class::m_instance= NULL;
+BML_class *BML_class::m_instance= NULL;
 
-DDL_blocker_class *DDL_blocker_class::get_DDL_blocker_class_instance()
+BML_class *BML_class::get_BML_class_instance()
 {
   if (m_instance == NULL)
-    m_instance = new DDL_blocker_class();
+    m_instance = new BML_class();
   return m_instance;
 }
 
-void DDL_blocker_class::destroy_DDL_blocker_class_instance()
+void BML_class::destroy_BML_class_instance()
 {
   delete m_instance;
   m_instance= NULL;
 }
 
-DDL_blocker_class::DDL_blocker_class()
+BML_class::BML_class()
 {
-  pthread_mutex_init(&THR_LOCK_DDL_blocker, MY_MUTEX_INIT_FAST);
-  pthread_mutex_init(&THR_LOCK_DDL_is_blocked, MY_MUTEX_INIT_FAST);
-  pthread_mutex_init(&THR_LOCK_DDL_blocker_blocked, MY_MUTEX_INIT_FAST);
-  pthread_cond_init(&COND_DDL_blocker, NULL);
-  pthread_cond_init(&COND_process_blocked, NULL);
-  pthread_cond_init(&COND_DDL_blocker_blocked, NULL);
-  DDL_blocked= FALSE;
-  DDL_blocks= 0;
+  pthread_mutex_init(&THR_LOCK_BML, MY_MUTEX_INIT_FAST);
+  pthread_mutex_init(&THR_LOCK_BML_active, MY_MUTEX_INIT_FAST);
+  pthread_mutex_init(&THR_LOCK_BML_get, MY_MUTEX_INIT_FAST);
+  pthread_cond_init(&COND_BML, NULL);
+  pthread_cond_init(&COND_BML_registered, NULL);
+  pthread_cond_init(&COND_BML_release, NULL);
+  BML_active= FALSE;
+  BML_registered= 0;
 }
 
-DDL_blocker_class::~DDL_blocker_class()
+BML_class::~BML_class()
 {
-  pthread_mutex_destroy(&THR_LOCK_DDL_blocker);
-  pthread_mutex_destroy(&THR_LOCK_DDL_is_blocked);
-  pthread_mutex_destroy(&THR_LOCK_DDL_blocker_blocked);
-  pthread_cond_destroy(&COND_DDL_blocker);
-  pthread_cond_destroy(&COND_process_blocked);
-  pthread_cond_destroy(&COND_DDL_blocker_blocked);
+  pthread_mutex_destroy(&THR_LOCK_BML);
+  pthread_mutex_destroy(&THR_LOCK_BML_active);
+  pthread_mutex_destroy(&THR_LOCK_BML_get);
+  pthread_cond_destroy(&COND_BML);
+  pthread_cond_destroy(&COND_BML_registered);
+  pthread_cond_destroy(&COND_BML_release);
 }
 
 /**
-   start_DDL()
+   do_enter()
 
-   Increments the DDL_blocks counter to indicate a DDL is in progress.
-  */
-void DDL_blocker_class::start_DDL()
+   Registers operation which obeys BML by increasing BML_registered counter.
+*/
+void BML_class::do_enter()
 {
-  DBUG_ENTER("start_DDL()");
-  pthread_mutex_lock(&THR_LOCK_DDL_blocker);
-  DDL_blocks++;
-  pthread_mutex_unlock(&THR_LOCK_DDL_blocker);
+  DBUG_ENTER("BML_class::do_enter()");
+  pthread_mutex_lock(&THR_LOCK_BML);
+  BML_registered++;
+  pthread_mutex_unlock(&THR_LOCK_BML);
   DBUG_VOID_RETURN;
 }
 
 /**
-   end_DDL()
+   bml_leave()
 
-   Decrements the DDL_blocks counter to indicate a DDL is done.
-   Signals blocked process if counter == 0.
-  */
-void DDL_blocker_class::end_DDL()
-{
-  DBUG_ENTER("end_DDL()");
-  pthread_mutex_lock(&THR_LOCK_DDL_blocker);
-  if (DDL_blocks > 0)
-    DDL_blocks--;
-  if (DDL_blocks == 0)
-    pthread_cond_broadcast(&COND_process_blocked);
-  pthread_mutex_unlock(&THR_LOCK_DDL_blocker);
+   Unregister operation which checked for BML with bml_enter(). 
+   Decrements the BML_registered counter to indicate the operation 
+   is done. Signals COND_BML_registered if counter == 0.
+*/
+void BML_class::bml_leave()
+{
+  DBUG_ENTER("BML_class::bml_leave()");
+  pthread_mutex_lock(&THR_LOCK_BML);
+  if (BML_registered > 0)
+    BML_registered--;
+  if (BML_registered == 0)
+    pthread_cond_broadcast(&COND_BML_registered);
+  pthread_mutex_unlock(&THR_LOCK_BML);
   DBUG_VOID_RETURN;
 }
 
 /**
-    check_DDL_blocker
+   bml_enter
 
-    Check to see if we are blocked from continuing. If so, wait until block is 
-    removed or the timeout specified by backup_wait_timeout variable occurs.
+   Check to see if BML is active. If so, wait until it is deactivated.
+   When BML is not active, register the operation with BML.
+
+   If a timeout specified by backup_wait_timeout variable occurs, this
+   method returns FALS. The operation is not registered in that case.
     
-    @param[in] thd        The THD object from the caller.
+   @param[in] thd        The THD object from the caller.
 
-    @note: This operation blocks DDL operations until end_ddl() is called.
+   @note: A successful call to bml_enter() must be matched by bml_leave().
 
-    @returns TRUE if not blocked
-    @returns FALSE if ddl is blocked and timeout occurs
-  */
-my_bool DDL_blocker_class::check_DDL_blocker(THD *thd)
+   @returns TRUE if not blocked
+   @returns FALSE if ddl is blocked and timeout occurs
+*/
+my_bool BML_class::bml_enter(THD *thd)
 {
   int ret = 0;
   struct timespec ddl_timeout;
-  DBUG_ENTER("check_DDL_blocker()");
-  DEBUG_SYNC(thd, "before_check_ddl_blocked");
+  DBUG_ENTER("BML_class::bml_enter()");
 
   set_timespec(ddl_timeout, thd->backup_wait_timeout);
 
   /*
-    Check the ddl blocker condition. Rest until ddl blocker is released.
+    Check whether BML is active. If yes, wait for deactivation which is 
+    signalled with COND_BML.
   */
-  pthread_mutex_lock(&THR_LOCK_DDL_is_blocked);
-  thd->enter_cond(&COND_DDL_blocker, &THR_LOCK_DDL_is_blocked,
-                  "DDL blocker: DDL is blocked");
-  while (DDL_blocked && !thd->DDL_exception && (ret == 0))
+  pthread_mutex_lock(&THR_LOCK_BML_active);
+  thd->enter_cond(&COND_BML, &THR_LOCK_BML_active,
+                  "BML: waiting until released");
+  DEBUG_SYNC(thd, "bml_enter_check");
+  while (BML_active && !thd->BML_exception && (ret == 0))
   {
     if (thd->backup_wait_timeout == 0)
       ret = -1;
     else
-      ret= pthread_cond_timedwait(&COND_DDL_blocker, &THR_LOCK_DDL_is_blocked,
+      ret= pthread_cond_timedwait(&COND_BML, &THR_LOCK_BML_active,
                                   &ddl_timeout);
   }
-  thd->exit_cond("DDL blocker: DDL is not blocked");
+  thd->exit_cond("BML: entered");
   if (ret == 0)
-  {
-    start_DDL();
-    DEBUG_SYNC(thd, "after_start_ddl");
-  }
+    do_enter();
   else
     my_error(ER_DDL_TIMEOUT, MYF(0), thd->query);
 
@@ -148,64 +163,69 @@ my_bool DDL_blocker_class::check_DDL_blo
 }
 
 /**
-   block_DDL
+   bml_get
 
-   This method is used to block all DDL commands. It checks the counter
-   DDL_blocks and if > 0 it blocks the process until all DDL operations are
-   complete and the condition variable has been signaled. 
-
-   The method also sets the boolean DDL_blocked to TRUE to tell the DDL
-   operations that they must block until the blocking operation is complete.
+  This method is used to activate BML. It waits for any operations which
+  registered with bml_enter() to unregister using bml_leave().
+  The method also prevents any other thread from activating the lock until
+  bml_release() is called.
+
+  It checks the counter BML_registered and if > 0 it blocks the process until 
+  all registerd operations are complete and the condition variable has been 
+  signaled. The fact that BML is in force is indicated by setting the boolean 
+  BML_active to TRUE.
 
    @params thd THD object.
    @returns TRUE
   */
-my_bool DDL_blocker_class::block_DDL(THD *thd)
+my_bool BML_class::bml_get(THD *thd)
 {
-  DBUG_ENTER("block_DDL()");
-
-  DEBUG_SYNC(thd, "before_block_ddl");
+  DBUG_ENTER("BML_class::bml_get()");
 
   /*
-    Only 1 DDL blocking operation can run at a time.
-    Check the blocker blocked condition. 
-    Rest until another blocker is done.
+    Only 1 thread can hold the BML. If BML_active is TRUE, wait for
+    bml_release() which signals COND_BML_release condition.
   */
-  pthread_mutex_lock(&THR_LOCK_DDL_blocker_blocked);
-  thd->enter_cond(&COND_DDL_blocker_blocked, &THR_LOCK_DDL_blocker_blocked,
-                  "DDL blocker: Checking block on blocker");
-  while (DDL_blocked)
-    pthread_cond_wait(&COND_DDL_blocker_blocked,
-                      &THR_LOCK_DDL_blocker_blocked);
-  DDL_blocked= TRUE;
-  thd->exit_cond("DDL blocker: Ok to block DDL");
+  pthread_mutex_lock(&THR_LOCK_BML_get);
+  thd->enter_cond(&COND_BML_release, &THR_LOCK_BML_get,
+                  "BML: witing for release before activating");
+  DEBUG_SYNC(thd, "bml_get_check1");
+  while (BML_active)
+    pthread_cond_wait(&COND_BML_release,
+                      &THR_LOCK_BML_get);
+  BML_active= TRUE;
+  thd->exit_cond("BML: activating");
 
   /*
-    Check the ddl blocker condition. Rest until ddl blocker is released.
+    Wait for all registered statements to complete, i.e., until BML_registered
+    is zero in which case COND_BML_registered is signalled.
   */
-  pthread_mutex_lock(&THR_LOCK_DDL_blocker);
-  thd->enter_cond(&COND_process_blocked, &THR_LOCK_DDL_blocker,
-                  "DDL blocker: Checking block on DDL");
-  while (DDL_blocks != 0)
-    pthread_cond_wait(&COND_process_blocked, &THR_LOCK_DDL_blocker);
-  thd->exit_cond("DDL blocker: DDL is now blocked");
+  pthread_mutex_lock(&THR_LOCK_BML);
+  thd->enter_cond(&COND_BML_registered, &THR_LOCK_BML,
+                  "BML: waiting for all statements to leave");
+  DEBUG_SYNC(thd, "bml_get_check2");
+  while (BML_registered != 0)
+    pthread_cond_wait(&COND_BML_registered, &THR_LOCK_BML);
+  thd->exit_cond("BML: activated");
 
-  DEBUG_SYNC(thd, "after_block_ddl");
+  DEBUG_SYNC(thd, "after_bml_activated");
   DBUG_RETURN(TRUE);
 }
 
 /**
-   unblock_DDL
+   bml_release
 
-   This method is used to unblock all DDL commands. It sets the boolean
-   DDL_blocked to FALSE to tell the DDL operations that they can proceed.
-  */
-void DDL_blocker_class::unblock_DDL()
-{
-  pthread_mutex_lock(&THR_LOCK_DDL_blocker);
-  DDL_blocked= FALSE;
-  pthread_cond_broadcast(&COND_DDL_blocker);
-  pthread_cond_signal(&COND_DDL_blocker_blocked);
-  pthread_mutex_unlock(&THR_LOCK_DDL_blocker);
-}
+   This method is used to deactivate BML. All operations which are waiting
+   in bml_enter() call (if any) will be allowed to continue.
 
+   The BML_active flag is set to FALSE to indicate that BML is not active and
+   conditions COND_BML and COND_BML_release are signalled.
+*/
+void BML_class::bml_release()
+{
+  pthread_mutex_lock(&THR_LOCK_BML);
+  BML_active= FALSE;
+  pthread_cond_broadcast(&COND_BML);
+  pthread_cond_signal(&COND_BML_release);
+  pthread_mutex_unlock(&THR_LOCK_BML);
+}

=== renamed file 'sql/ddl_blocker.h' => 'sql/bml.h'
--- a/sql/ddl_blocker.h	2008-11-21 19:35:55 +0000
+++ b/sql/bml.h	2009-02-11 13:10:41 +0000
@@ -1,122 +1,121 @@
 /**
   @file
 
-  Header file for DDL blocker code.
+  Header file for Backup Metadata Lock.
  */
 #include "mysql_priv.h"
 
 /**
-   @class DDL_blocker_class
+   @class BML_class
  
-   @brief Implements a simple DDL blocker mechanism.
+   @brief Implements a simple Backup Metadata Lock (BML) mechanism.
  
-   The DDL_blocker_class is a singleton class designed to allow DDL
-   operations to be blocked while an operation that uses this class
-   executes. The class is designed to allow any number of DDL operations
-   to execute but only one blocking operation can block DDL operations
-   at a time. 
-
-   If an operation has blocked DDL operations and another operation attempts
-   to block DDL operations, the second blocking operation will wait
-   until the first blocking operation is complete.
+   The BML_class is a singleton class designed to allow blocking statements 
+   changing metadata which should be constant during backup/restore operation.
+   Only one thread can hold the lock but there is no restriction on number
+   of blocked statements which can run in parallel. 
+
+   If a thread has acquired BML and another thread attempts to activate it,
+   the second thread will wait until the first one is complete.
  
    Checking for Block
-   For any DDL operation that needs to be blocked while another 
-   operation is executing, you can check the status of the DDL blocker
-   by calling @c check_DDL_blocker(). This method will return when there
-   is no block or wait while the blocking operation is running. Once the
-   method returns, the DDL operation that called the method is registered
-   so that any other blocking operation will wait while the DDL operation
-   is running. When the DDL operation is complete, you must unregister the
-   DDL operation by calling end_DDL().
-
-   Blocking DDL Operations
-   To block a DDL operation, call block_DDL(). This registers the blocking
-   operation and prevents any DDL operations that use check_DDL_blocker()
-   to block while the blocking operation is running. When the blocking
-   operation is complete, you must call unblock_DDL() to unregister
-   the blocking operation.
+   Any statement that needs to be blocked by BML should call @c bml_enter() at
+   the beginning of its execution. This method will return when BML is not active
+   or wait until it becomes inactive. Once the method returns, the statement
+   which called the method is registered and while it is running, it will be not
+   possible to activate BML. When the statement is complete, you must unregister
+   it by calling bml_leave(). All this is done inside the parser
+   (@c mysql_execute_command()).
+
+   Blocking Statements
+   To prevent metadata changes, call bml_get(). This activates the lock and
+   prevents any statements which use bml_enter() from executing. To remove the
+   lock bml_release().
 
    Singleton Methods
    The creation of the singleton is accomplished using 
-   get_DDL_blocker_class_instance(). This method is called from mysqld.cc
+   get_BML_class_instance(). This method is called from mysqld.cc
    and creates and initializes all of the private mutex, condition, and
-   controlling variables. The method destroy_DDL_blocker_class_instance()
+   controlling variables. The method destroy_BML_class_instance()
    destroys the mutex and condition variables. 
 
    Calling the Singleton
    To call the singleton class, you must declare an external variable
-   to the global variable DDL_blocker as shown below.
+   to the global variable BML_instance as shown below.
 
-   @c extern DDL_blocker_class *DDL_blocker;
+   @c extern BML_class *BML_instance;
 
-   Calling methods on the singleton is accomplished using the DDL_blocker
-   variable such as: @c DDL_blocker->block_DDL().
+   Calling methods on the singleton is accomplished using the BML_instance
+   variable such as: @c BML_instance->bml_get().
 
-   @note: This class is currently only used in online backup. If you would
+   @note: This class is currently only used in MySQL backup. If you would
           like to use it elsewhere and have questions, please contact
           Chuck Bell (cbell@stripped) for more details and how to setup
           a test case to test the DDL blocking mechanism for your use.
   */
-class DDL_blocker_class
+class BML_class
 {
   public:
 
     /*
       Singleton class
     */
-    static DDL_blocker_class *get_DDL_blocker_class_instance();
-    static void destroy_DDL_blocker_class_instance();
+    static BML_class *get_BML_class_instance();
+    static void destroy_BML_class_instance();
 
     /*
-      Check to see if we are blocked from continuing. If so,
-      wait until the backup process signals the condition.
+      Check to see if BML is active. If so, wait until it is deactivated.
+      When BML is not active, register the operation with BML.
     */
-    my_bool check_DDL_blocker(THD *thd);
+    my_bool bml_enter(THD *thd);
 
     /*
-      Decrements the backup's counter to indicate a DDL is done.
-      Signals backup process if counter == 0.
+      Unregister operation which checked for BML with bml_enter(). 
     */
-    void end_DDL();
+    void bml_leave();
 
     /*
-      This method is used to block all DDL commands. It checks the counter
-      DDL_blocks and if > 0 it blocks the backup until all DDL operations are
-      complete and the condition variable has been signaled. 
-
-      The method also sets the boolean DDL_blocked to TRUE to tell the DDL
-      operations that they must block until the backup operation is complete.
+      This method is used to activate BML. It waits for any operations which
+      registered with bml_enter() to unregister using bml_leave().
+      The method also prevents any other thread from activating the lock until
+      bml_release() is called.
     */
-    my_bool block_DDL(THD *thd);
+    my_bool bml_get(THD *thd);
 
     /*
-      This method is used to unblock all DDL commands. It sets the boolean
-      DDL_blocked to FALSE to tell the DDL operations that they can proceed.
+      This method is used to deactivate BML. All operations which are waiting
+      in bml_enter() call (if any) will be allowed to continue.
     */
-    void unblock_DDL();
+    void bml_release();
 
   private:
 
-    DDL_blocker_class();
-    ~DDL_blocker_class();
+    BML_class();
+    ~BML_class();
 
     /*
-      Increments the backup's counter to indicate a DDL is in progress.
+      Registers operation which obeys BML.
     */
-    void start_DDL();
+    void do_enter();
 
     /*
-      These variables are used to implement the metadata freeze "DDL blocker"
-      for online backup.
+      These variables are used to implement the Backup Metadata Lock.
     */
-    pthread_mutex_t THR_LOCK_DDL_blocker;    ///< Mutex for blocking DDL   
-    pthread_mutex_t THR_LOCK_DDL_is_blocked; ///< Mutex for checking block DDL 
-    pthread_mutex_t THR_LOCK_DDL_blocker_blocked; ///< One blocker at a time 
-    pthread_cond_t COND_DDL_blocker;         ///< cond for blocking DDL
-    pthread_cond_t COND_process_blocked;     ///< cond for checking block DDL
-    pthread_cond_t COND_DDL_blocker_blocked; ///< cond for blocker blocked
-    my_bool DDL_blocked;                     ///< Is blocking operation running
-    int DDL_blocks;              ///< Number of DDL operations in progress.
-    static DDL_blocker_class *m_instance;    ///< instance var for singleton 
+
+    /// Mutex for protecting BML_registered counter.
+    pthread_mutex_t THR_LOCK_BML;
+    /// Mutex for proteting BML_active falg.
+    pthread_mutex_t THR_LOCK_BML_active;
+    /// Mutex for serializing BML usage. 
+    pthread_mutex_t THR_LOCK_BML_get;
+    /// Signals deactivation of BML for statements waiting in bml_enter(). 
+    pthread_cond_t COND_BML;
+    /// Signals deactivation of BML for threads waiting in bml_get().
+    pthread_cond_t COND_BML_release;
+    /// Signals that BML_reagistered count dropped to 0.
+    pthread_cond_t COND_BML_registered;
+
+    my_bool BML_active;           ///< Is BML activated.
+    int BML_registered;           ///< Number of statements registered with BML.
+    static BML_class *m_instance; ///< instance var for singleton 
 };

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-02-09 18:17:55 +0000
+++ b/sql/mysqld.cc	2009-02-11 13:10:41 +0000
@@ -26,7 +26,7 @@
 #include "mysqld_suffix.h"
 #include "mysys_err.h"
 #include "events.h"
-#include "ddl_blocker.h"
+#include "bml.h"
 #include "sql_audit.h"
 #include "debug_sync.h"
 #include <waiting_threads.h>
@@ -433,7 +433,7 @@ static pthread_cond_t COND_thread_cache,
 
 /* Global variables */
 
-extern DDL_blocker_class *DDL_blocker;
+extern BML_class *BML_instance;
 bool opt_update_log, opt_bin_log;
 my_bool opt_log, opt_slow_log;
 my_bool opt_backup_history_log;
@@ -1520,7 +1520,7 @@ static void clean_up_mutexes()
   (void) pthread_cond_destroy(&COND_thread_cache);
   (void) pthread_cond_destroy(&COND_flush_thread_cache);
   (void) pthread_cond_destroy(&COND_manager);
-  DDL_blocker_class::destroy_DDL_blocker_class_instance();
+  BML_class::destroy_BML_class_instance();
   DBUG_VOID_RETURN;
 }
 
@@ -3787,7 +3787,7 @@ static int init_thread_environment()
   /*
     Initialize the DDL blocker
   */
-  DDL_blocker= DDL_blocker_class::get_DDL_blocker_class_instance();
+  BML_instance= BML_class::get_BML_class_instance();
 
   sp_cache_init();
 #ifdef HAVE_EVENT_SCHEDULER
@@ -4142,7 +4142,7 @@ server.");
 #ifndef EMBEDDED_LIBRARY
   if (backup_init())
   {
-    sql_print_error("Failed to initialize online backup.");
+    sql_print_error("Failed to initialize MySQL backup.");
     unireg_abort(1);
   }
 #endif

=== modified file 'sql/si_objects.cc'
--- a/sql/si_objects.cc	2009-02-04 10:49:16 +0000
+++ b/sql/si_objects.cc	2009-02-11 13:10:41 +0000
@@ -19,7 +19,7 @@
 #include "sql_prepare.h"
 
 #include "si_objects.h"
-#include "ddl_blocker.h"
+#include "bml.h"
 #include "sql_show.h"
 #include "sql_trigger.h"
 #include "sp.h"
@@ -32,7 +32,7 @@
 #include "event_db_repository.h"
 #endif
 
-DDL_blocker_class *DDL_blocker= NULL;
+BML_class *BML_instance= NULL;
 
 extern my_bool disable_slaves;
 
@@ -764,7 +764,7 @@ bool Abstract_obj::create(THD *thd)
   session_context.reset_si_ctx(thd);
 
   /* Allow to execute DDL operations. */
-  ::obs::ddl_blocker_exception_on(thd);
+  ::obs::bml_exception_on(thd);
 
   /* Run queries from the serialization image. */
   while ((sql_text= it++))
@@ -781,7 +781,7 @@ bool Abstract_obj::create(THD *thd)
   }
 
   /* Disable further DDL execution. */
-  ::obs::ddl_blocker_exception_off(thd);
+  ::obs::bml_exception_off(thd);
 
   session_context.restore_si_ctx(thd);
 
@@ -821,13 +821,13 @@ bool Abstract_obj::drop(THD *thd)
   session_context.reset_si_ctx(thd);
 
   /* Allow to execute DDL operations. */
-  ::obs::ddl_blocker_exception_on(thd);
+  ::obs::bml_exception_on(thd);
 
   /* Execute DDL operation. */
   rc= ed_connection.execute_direct(*sql_text);
 
   /* Disable further DDL execution. */
-  ::obs::ddl_blocker_exception_off(thd);
+  ::obs::bml_exception_off(thd);
 
   session_context.restore_si_ctx(thd);
 
@@ -2817,76 +2817,75 @@ bool compare_tablespace_attributes(Obj *
 ///////////////////////////////////////////////////////////////////////////
 
 //
-// Implementation: DDL Blocker.
+// Implementation: Backup Metadata Lock.
 //
 
 ///////////////////////////////////////////////////////////////////////////
 
 /*
-  DDL Blocker methods
+  BML methods
 */
 
 /**
-  Turn on the ddl blocker
+   Get the backup metadata lock.
 
-  This method is used to start the ddl blocker blocking DDL commands.
+   After successful acquiring of the lock, all statements marked as 
+   CF_BLOCKED_BY_BML will be blocked (see @c sql_command_flags[] in 
+   sql_parse.cc).
 
-  @param[in] thd  current thread
+   @param[in] thd  current thread
 
   @return Error status.
     @retval FALSE on success.
     @retval TRUE on error.
 */
-bool ddl_blocker_enable(THD *thd)
+bool bml_get(THD *thd)
 {
-  DBUG_ENTER("obs::ddl_blocker_enable");
-  if (!DDL_blocker->block_DDL(thd))
+  DBUG_ENTER("obs::bml_get");
+  if (!BML_instance->bml_get(thd))
     DBUG_RETURN(TRUE);
   DBUG_RETURN(FALSE);
 }
 
 
 /**
-  Turn off the ddl blocker
-
-  This method is used to stop the ddl blocker from blocking DDL commands.
+  Release the backup metadata lock if acquired earlier.
 */
-void ddl_blocker_disable()
+void bml_release()
 {
-  DBUG_ENTER("obs::ddl_blocker_disable");
-  DDL_blocker->unblock_DDL();
+  DBUG_ENTER("obs::bml_release");
+  BML_instance->bml_release();
   DBUG_VOID_RETURN;
 }
 
 
 /**
-  Turn on the ddl blocker exception
+   Turn on the backup metadata lock exception
 
-  This method is used to allow the exception allowing a restore operation to
-  perform DDL operations while the ddl blocker blocking DDL commands.
+   The thread for which this method is called is allowed to execute statements 
+   which normally are blocked by BML.
 
-  @param[in] thd  current thread
+   @param[in] thd  current thread
 */
-void ddl_blocker_exception_on(THD *thd)
+void bml_exception_on(THD *thd)
 {
-  DBUG_ENTER("obs::ddl_blocker_exception_on");
-  thd->DDL_exception= TRUE;
+  DBUG_ENTER("obs::bml_exception_on");
+  thd->BML_exception= TRUE;
   DBUG_VOID_RETURN;
 }
 
 
 /**
-  Turn off the ddl blocker exception
+   Turn off the backup metadata lock exception
 
-  This method is used to suspend the exception allowing a restore operation to
-  perform DDL operations while the ddl blocker blocking DDL commands.
+   This method cancels the exception activated with @c bml_exception_on().
 
-  @param[in] thd  current thread
-*/
-void ddl_blocker_exception_off(THD *thd)
+   @param[in] thd  current thread
+  */
+void bml_exception_off(THD *thd)
 {
-  DBUG_ENTER("obs::ddl_blocker_exception_off");
-  thd->DDL_exception= FALSE;
+  DBUG_ENTER("obs::bml_exception_off");
+  thd->BML_exception= FALSE;
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/si_objects.h'
--- a/sql/si_objects.h	2009-01-21 15:06:10 +0000
+++ b/sql/si_objects.h	2009-02-11 13:10:41 +0000
@@ -32,7 +32,8 @@
   Additionally, the interface provides two helper services
   for backup:
     - execute an arbitrary SQL statement
-    - lock and unlock all metadata, so called "DDL blocker"
+    - block DDL statements interferring with backup/restore operations - so 
+      called Backup Metadata Lock.
 */
 
 namespace obs {
@@ -396,50 +397,49 @@ bool compare_tablespace_attributes(Obj *
 ///////////////////////////////////////////////////////////////////////////
 
 //
-// DDL blocker methods.
+// Backup Metadata Lock (BML) methods.
 //
 
 ///////////////////////////////////////////////////////////////////////////
 
 /**
-  Turn on the ddl blocker.
+   Get the backup metadata lock.
 
-  This method is used to start the ddl blocker blocking DDL commands.
+   After successful acquiring of the lock, all statements marked as 
+   CF_BLOCKED_BY_BML will be blocked (see @c sql_command_flags[] in 
+   sql_parse.cc).
 
-  @param[in] thd  Thread context.
+   @param[in] thd  current thread
 
-  @return error status.
+  @return Error status.
     @retval FALSE on success.
     @retval TRUE on error.
 */
-bool ddl_blocker_enable(THD *thd);
+bool bml_get(THD *thd);
 
 /**
-  Turn off the ddl blocker.
-
-  This method is used to stop the ddl blocker from blocking DDL commands.
+  Release the backup metadata lock if acquired earlier.
 */
-void ddl_blocker_disable();
+void bml_release();
 
 /**
-  Turn on the ddl blocker exception
+   Turn on the backup metadata lock exception
 
-  This method is used to allow the exception allowing a restore operation to
-  perform DDL operations while the ddl blocker blocking DDL commands.
+   The thread for which this method is called is allowed to execute statements 
+   which normally are blocked by BML.
 
-  @param[in] thd  Thread context.
+   @param[in] thd  current thread
 */
-void ddl_blocker_exception_on(THD *thd);
+void bml_exception_on(THD *thd);
 
 /**
-  Turn off the ddl blocker exception.
+   Turn off the backup metadata lock exception
 
-  This method is used to suspend the exception allowing a restore operation to
-  perform DDL operations while the ddl blocker blocking DDL commands.
+   This method cancels the exception activated with @c bml_exception_on().
 
-  @param[in] thd  Thread context.
-*/
-void ddl_blocker_exception_off(THD *thd);
+   @param[in] thd  current thread
+  */
+void bml_exception_off(THD *thd);
 
 /*
   The following class is used to manage name locks on a list of tables.

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2009-02-04 10:49:16 +0000
+++ b/sql/sql_class.cc	2009-02-11 13:10:41 +0000
@@ -415,12 +415,12 @@ THD::THD()
    spcont(NULL),
    m_parser_state(NULL),
   /*
-    @todo The following is a work around for online backup and the DDL blocker.
-          It should be removed when the generalized solution is in place.
-          This is needed to ensure the restore (which uses DDL) is not blocked
-          when the DDL blocker is engaged.
+    @todo The following is a work around for MySQL backup and the Backup 
+    Metadata Lock (BML). It should be removed when the generalized solution 
+    is in place. This is needed to ensure the restore thread (which uses BML) 
+    is not blocked by the lock.
   */
-   DDL_exception(FALSE),
+   BML_exception(FALSE),
    backup_wait_timeout(BACKUP_WAIT_TIMEOUT_DEFAULT),
 #if defined(ENABLED_DEBUG_SYNC)
    debug_sync_control(0),

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2009-02-04 10:49:16 +0000
+++ b/sql/sql_class.h	2009-02-11 13:10:41 +0000
@@ -1796,12 +1796,12 @@ public:
   Parser_state *m_parser_state;
 
   /*
-    @todo The following is a work around for online backup and the DDL blocker.
-          It should be removed when the generalized solution is in place.
-          This is needed to ensure the restore (which uses DDL) is not blocked
-          when the DDL blocker is engaged.
+    @todo The following is a work around for MySQL backup and the Backup 
+    Metadata Lock (BML). It should be removed when the generalized solution 
+    is in place. This is needed to ensure the restore thread (which uses BML) 
+    is not blocked by the lock.
   */
-  my_bool DDL_exception; // Allow some DDL if there is an exception
+  my_bool BML_exception; // Allow some DDL if there is an exception
   ulong backup_wait_timeout;
 
   Locked_tables_list locked_tables_list;
@@ -3041,6 +3041,12 @@ public:
   modifies our currently non-transactional system tables.
 */
 #define CF_AUTO_COMMIT_TRANS  (CF_IMPLICT_COMMIT_BEGIN | CF_IMPLICIT_COMMIT_END)
+/**
+  Mark statements which shuld be blocked when the Backup Metadata Lock is
+  active. See bml.cc.
+*/ 
+#define CF_BLOCKED_BY_BML       (1U << 8)
+
 
 /* Bits in server_command_flags */
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-02-04 10:49:16 +0000
+++ b/sql/sql_parse.cc	2009-02-11 13:10:41 +0000
@@ -28,7 +28,7 @@
 #include "sp_cache.h"
 #include "events.h"
 #include "sql_trigger.h"
-#include <ddl_blocker.h>
+#include "bml.h"
 #include "sql_audit.h"
 #include "transaction.h"
 #include "sql_prepare.h"
@@ -99,7 +99,7 @@ const char *xa_state_names[]={
   "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED", "ROLLBACK ONLY"
 };
 
-extern DDL_blocker_class *DDL_blocker;
+extern BML_class *BML_instance;
 
 #ifdef HAVE_REPLICATION
 /**
@@ -332,6 +332,47 @@ void init_update_queries(void)
 
   sql_command_flags[SQLCOM_BACKUP]=             CF_AUTO_COMMIT_TRANS;
   sql_command_flags[SQLCOM_RESTORE]=            CF_AUTO_COMMIT_TRANS;
+
+  /*
+    Mark commands to be blocked by Backup Metadata Lock. See bml.cc.
+  */ 
+  sql_command_flags[SQLCOM_DROP_USER]|=         CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_DROP_DB]|=           CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_DROP_TABLE]|=        CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_DROP_VIEW]|=         CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_DROP_FUNCTION]|=     CF_BLOCKED_BY_BML;  
+  sql_command_flags[SQLCOM_DROP_PROCEDURE]|=    CF_BLOCKED_BY_BML;  
+  sql_command_flags[SQLCOM_DROP_EVENT]|=        CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_DROP_TRIGGER]|=      CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_DROP_INDEX]|=        CF_BLOCKED_BY_BML;
+
+  sql_command_flags[SQLCOM_CREATE_DB]|=         CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_TABLE]|=      CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_VIEW]|=       CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_SPFUNCTION]|= CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_PROCEDURE]|=  CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_EVENT]|=      CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_TRIGGER]|=    CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_CREATE_INDEX]|=      CF_BLOCKED_BY_BML;
+
+  sql_command_flags[SQLCOM_ALTER_TABLESPACE]|=  CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_ALTER_DB]|=          CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_ALTER_DB_UPGRADE]|=  CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_ALTER_TABLE]|=       CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_ALTER_FUNCTION]|=    CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_ALTER_PROCEDURE]|=   CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_ALTER_EVENT]|=       CF_BLOCKED_BY_BML;
+
+  sql_command_flags[SQLCOM_RENAME_USER]|=       CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_RENAME_TABLE]|=      CF_BLOCKED_BY_BML;
+
+  sql_command_flags[SQLCOM_GRANT]|=             CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_REVOKE]|=            CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_REVOKE_ALL]|=        CF_BLOCKED_BY_BML;
+
+  sql_command_flags[SQLCOM_REPAIR]|=            CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_OPTIMIZE]|=          CF_BLOCKED_BY_BML;
+  sql_command_flags[SQLCOM_TRUNCATE]|=          CF_BLOCKED_BY_BML;
 }
 
 
@@ -352,6 +393,13 @@ bool is_log_table_write_query(enum enum_
   return (sql_command_flags[command] & CF_WRITE_LOGS_COMMAND) != 0;
 }
 
+static
+bool is_bml_blocked(const enum enum_sql_command command)
+{
+  DBUG_ASSERT(command <= SQLCOM_END);
+  return (sql_command_flags[command] & CF_BLOCKED_BY_BML) != 0;
+}
+
 void execute_init_command(THD *thd, sys_var_str *init_command_var,
 			  rw_lock_t *var_mutex)
 {
@@ -1822,6 +1870,7 @@ mysql_execute_command(THD *thd)
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   thd->work_part_info= 0;
 #endif
+  bool bml_registered= FALSE;
 
   /*
     In many cases first table of main SELECT_LEX have special meaning =>
@@ -1994,6 +2043,15 @@ mysql_execute_command(THD *thd)
   if (opt_implicit_commit(thd, CF_IMPLICT_COMMIT_BEGIN))
     goto error;
 
+  if (is_bml_blocked(lex->sql_command) && 
+      !(bml_registered= BML_instance->bml_enter(thd)))
+    goto error;
+  
+#ifndef DBUG_OFF
+  if (lex->sql_command != SQLCOM_SET_OPTION)
+    DEBUG_SYNC(thd,"before_execute_sql_command");
+#endif
+
   switch (lex->sql_command) {
 
   case SQLCOM_SHOW_EVENTS:
@@ -2492,11 +2550,6 @@ mysql_execute_command(THD *thd)
       TABLE in the same way. That way we avoid that a new table is
       created during a gobal read lock.
     */
-    if (!DDL_blocker->check_DDL_blocker(thd))
-    {
-      res= 1;
-      goto ddl_blocker_err;
-    }
     if (!thd->locked_tables_mode &&
         !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
     {
@@ -2597,7 +2650,6 @@ mysql_execute_command(THD *thd)
           res= handle_select(thd, lex, result, 0);
           delete result;
         }
-        DDL_blocker->end_DDL();
       }
       else if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
         create_table= lex->unlink_first_table(&link_to_local);
@@ -2624,8 +2676,6 @@ mysql_execute_command(THD *thd)
 
     /* put tables back for PS rexecuting */
 end_with_restore_list:
-    DDL_blocker->end_DDL();
-ddl_blocker_err:
     lex->link_first_table_back(create_table, link_to_local);
     break;
   }
@@ -2641,8 +2691,6 @@ ddl_blocker_err:
     table without having to do a full rebuild.
   */
   {
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     /* Prepare stack copies to be re-execution safe */
     HA_CREATE_INFO create_info;
     Alter_info alter_info(lex->alter_info, thd->mem_root);
@@ -2668,7 +2716,6 @@ ddl_blocker_err:
     res= mysql_alter_table(thd, first_table->db, first_table->table_name,
                            &create_info, first_table, &alter_info,
                            0, (ORDER*) 0, 0);
-    DDL_blocker->end_DDL();
     break;
   }
 #ifdef HAVE_REPLICATION
@@ -2710,8 +2757,6 @@ ddl_blocker_err:
 
   case SQLCOM_ALTER_TABLE:
     {
-      if (!DDL_blocker->check_DDL_blocker(thd))
-        goto error;
       ulong priv=0;
       ulong priv_needed= ALTER_ACL;
 
@@ -2727,10 +2772,7 @@ ddl_blocker_err:
       Alter_info alter_info(lex->alter_info, thd->mem_root);
 
       if (thd->is_fatal_error) /* OOM creating a copy of alter_info */
-      {
-        DDL_blocker->end_DDL();
         goto error;
-      }
       /*
         We also require DROP priv for ALTER TABLE ... DROP PARTITION, as well
         as for RENAME TO, as being done by SQLCOM_RENAME_TABLE
@@ -2748,10 +2790,8 @@ ddl_blocker_err:
 	  check_merge_table_access(thd, first_table->db,
 				   (TABLE_LIST *)
 				   create_info.merge_list.first))
-      {
-        DDL_blocker->end_DDL();
 	goto error;				/* purecov: inspected */
-      }
+
       if (check_grant(thd, priv_needed, all_tables, 0, UINT_MAX, 0))
         goto error;
       if (lex->name.str && !test_all_bits(priv,INSERT_ACL | CREATE_ACL))
@@ -2763,10 +2803,7 @@ ddl_blocker_err:
           tmp_table.grant.privilege=priv;
           if (check_grant(thd, INSERT_ACL | CREATE_ACL, &tmp_table, 0,
               UINT_MAX, 0))
-          {
-            DDL_blocker->end_DDL();
             goto error;
-          }
       }
 
       /* Don't yet allow changing of symlinks with ALTER TABLE */
@@ -2784,7 +2821,6 @@ ddl_blocker_err:
           !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
       {
         res= 1;
-        DDL_blocker->end_DDL();
         break;
       }
 
@@ -2796,7 +2832,6 @@ ddl_blocker_err:
                              select_lex->order_list.elements,
                              (ORDER *) select_lex->order_list.first,
                              lex->ignore);
-      DDL_blocker->end_DDL();
       break;
     }
   case SQLCOM_RENAME_TABLE:
@@ -2825,14 +2860,8 @@ ddl_blocker_err:
         goto error;
     }
 
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     if (mysql_rename_tables(thd, first_table, 0))
-    {
-      DDL_blocker->end_DDL();
       goto error;
-    }
-    DDL_blocker->end_DDL();
     break;
   }
 #ifndef EMBEDDED_LIBRARY
@@ -2926,10 +2955,7 @@ ddl_blocker_err:
     if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, FALSE, FALSE, UINT_MAX))
       goto error; /* purecov: inspected */
     thd->enable_slow_log= opt_log_slow_admin_statements;
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= mysql_repair_table(thd, first_table, &lex->check_opt);
-    DDL_blocker->end_DDL();
     /* ! we write after unlocking the table */
     if (!res && !lex->no_write_to_binlog)
     {
@@ -2979,12 +3005,9 @@ ddl_blocker_err:
     if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, FALSE, FALSE, UINT_MAX))
       goto error; /* purecov: inspected */
     thd->enable_slow_log= opt_log_slow_admin_statements;
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
       mysql_recreate_table(thd, first_table) :
       mysql_optimize_table(thd, first_table, &lex->check_opt);
-    DDL_blocker->end_DDL();
     /* ! we write after unlocking the table */
     if (!res && !lex->no_write_to_binlog)
     {
@@ -3225,10 +3248,7 @@ ddl_blocker_err:
       goto error;
     }
 
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= mysql_truncate(thd, first_table, 0);
-    DDL_blocker->end_DDL();
 
     break;
   case SQLCOM_DELETE:
@@ -3331,12 +3351,9 @@ ddl_blocker_err:
       /* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
       thd->options|= OPTION_KEEP_LOG;
     }
-      if (!DDL_blocker->check_DDL_blocker(thd))
-        goto error;
     /* DDL and binlog write order protected by LOCK_open */
     res= mysql_rm_table(thd, first_table, lex->drop_if_exists,
 			lex->drop_temporary);
-      DDL_blocker->end_DDL();
   }
   break;
   case SQLCOM_SHOW_PROCESSLIST:
@@ -3578,11 +3595,8 @@ ddl_blocker_err:
     if (check_access(thd,CREATE_ACL,lex->name.str, 0, 1, 0,
                      is_schema_db(lex->name.str)))
       break;
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= mysql_create_db(thd,(lower_case_table_names == 2 ? alias :
                               lex->name.str), &create_info, 0);
-    DDL_blocker->end_DDL();
     break;
   }
   case SQLCOM_DROP_DB:
@@ -3617,10 +3631,7 @@ ddl_blocker_err:
                  ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
       goto error;
     }
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= mysql_rm_db(thd, lex->name.str, lex->drop_if_exists, 0);
-    DDL_blocker->end_DDL();
     break;
   }
   case SQLCOM_ALTER_DB_UPGRADE:
@@ -3656,10 +3667,7 @@ ddl_blocker_err:
       goto error;
     }
 
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= mysql_upgrade_db(thd, db);
-    DDL_blocker->end_DDL();
     if (!res)
       my_ok(thd);
     break;
@@ -3697,10 +3705,7 @@ ddl_blocker_err:
                  ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
       goto error;
     }
-    if (!DDL_blocker->check_DDL_blocker(thd))
-      goto error;
     res= mysql_alter_db(thd, db->str, &create_info);
-    DDL_blocker->end_DDL();
     break;
   }
   case SQLCOM_SHOW_CREATE_DB:
@@ -3717,7 +3722,7 @@ ddl_blocker_err:
   }
   case SQLCOM_CREATE_EVENT:
   case SQLCOM_ALTER_EVENT:
-  #ifdef HAVE_EVENT_SCHEDULER
+#ifdef HAVE_EVENT_SCHEDULER
   do
   {
     DBUG_ASSERT(lex->event_parse_data);
@@ -4682,6 +4687,10 @@ create_sp_error:
     thd->row_count_func= -1;
 
 finish:
+
+  if (bml_registered)
+    BML_instance->bml_leave();
+
   if (need_start_waiting)
   {
     /*

Thread
bzr commit into mysql-6.0-backup branch (Rafal.Somla:2765) Bug#32702Rafal Somla11 Feb