MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:June 27 2008 12:25pm
Subject:bzr commit into mysql-6.0-backup branch (jorgen.loland:2639) Bug#33120
View as plain text  
#At file:///localhome/jl208045/mysql/mysql-6.0-backup-33120/

 2639 Jorgen Loland	2008-06-27 [merge]
      bug#33120 - merging before push
removed:
  sql/backup/debug.h
added:
  mysql-test/r/backup_compression.result
  mysql-test/r/backup_many_dbs.result
  mysql-test/r/backup_multi_blocks.result
  mysql-test/r/backup_procedures.result
  mysql-test/r/backup_triggers_and_events.result
  mysql-test/r/innodb-autoinc.result
  mysql-test/r/innodb_bug34053.result
  mysql-test/r/innodb_bug34300.result
  mysql-test/r/innodb_bug35220.result
  mysql-test/suite/bugs/r/rpl_bug33029.result
  mysql-test/suite/bugs/t/rpl_bug33029.test
  mysql-test/t/backup_compression.test
  mysql-test/t/backup_many_dbs.test
  mysql-test/t/backup_multi_blocks.test
  mysql-test/t/backup_procedures.test
  mysql-test/t/backup_triggers_and_events.test
  mysql-test/t/innodb-autoinc.test
  mysql-test/t/innodb_bug34053.test
  mysql-test/t/innodb_bug34300.test
  mysql-test/t/innodb_bug35220.test
modified:
  Makefile.am
  client/mysql.cc
  config/ac-macros/libevent.m4
  mysql-test/lib/mtr_cases.pl
  mysql-test/lib/mtr_report.pl
  mysql-test/r/backup.result
  mysql-test/r/backup_commit_blocker.result
  mysql-test/r/backup_ddl_blocker.result
  mysql-test/r/backup_progress.result
  mysql-test/r/backup_snapshot.result
  mysql-test/r/backup_view_on_view.result
  mysql-test/r/character_set_server_func.result
  mysql-test/r/innodb.result
  mysql-test/r/merge-sync.result
  mysql-test/r/mysql.result
  mysql-test/r/partition_innodb.result
  mysql-test/r/repair.result
  mysql-test/r/subselect.result
  mysql-test/r/subselect_no_mat.result
  mysql-test/r/subselect_no_opts.result
  mysql-test/r/subselect_no_semijoin.result
  mysql-test/suite/binlog/r/binlog_innodb.result
  mysql-test/suite/rpl/t/disabled.def
  mysql-test/t/backup.test
  mysql-test/t/backup_commit_blocker.test
  mysql-test/t/backup_ddl_blocker.test
  mysql-test/t/backup_no_be.test
  mysql-test/t/backup_progress.test
  mysql-test/t/backup_security.test
  mysql-test/t/backup_snapshot.test
  mysql-test/t/backup_view_on_view.test
  mysql-test/t/character_set_server_func.test
  mysql-test/t/disabled.def
  mysql-test/t/innodb.test
  mysql-test/t/merge-sync.test
  mysql-test/t/mysql_delimiter.sql
  mysql-test/t/partition_innodb.test
  mysql-test/t/subselect.test
  scripts/make_binary_distribution.sh
  sql/backup/Makefile.am
  sql/backup/backup_aux.h
  sql/backup/backup_kernel.h
  sql/backup/backup_test.cc
  sql/backup/be_default.cc
  sql/backup/be_snapshot.cc
  sql/backup/data_backup.cc
  sql/backup/kernel.cc
  sql/backup/logger.h
  sql/backup/stream.cc
  sql/backup/stream.h
  sql/backup/stream_v1_transport.c
  sql/ddl_blocker.cc
  sql/ddl_blocker.h
  sql/debug_sync.cc
  sql/handler.cc
  sql/lex.h
  sql/lock.cc
  sql/share/errmsg.txt
  sql/slave.cc
  sql/sql_class.cc
  sql/sql_delete.cc
  sql/sql_insert.cc
  sql/sql_lex.h
  sql/sql_parse.cc
  sql/sql_plugin.cc
  sql/sql_select.cc
  sql/sql_table.cc
  sql/sql_yacc.yy
  sql/structs.h
  storage/innobase/Makefile.am
  storage/innobase/btr/btr0cur.c
  storage/innobase/buf/buf0buf.c
  storage/innobase/dict/dict0dict.c
  storage/innobase/handler/ha_innodb.cc
  storage/innobase/handler/ha_innodb.h
  storage/innobase/include/buf0buf.h
  storage/innobase/include/dict0dict.h
  storage/innobase/include/dict0mem.h
  storage/innobase/include/mach0data.h
  storage/innobase/include/mach0data.ic
  storage/innobase/include/os0sync.h
  storage/innobase/include/read0read.h
  storage/innobase/include/row0mysql.h
  storage/innobase/include/row0sel.h
  storage/innobase/include/srv0srv.h
  storage/innobase/include/sync0arr.h
  storage/innobase/include/sync0rw.h
  storage/innobase/include/sync0rw.ic
  storage/innobase/include/sync0sync.h
  storage/innobase/include/sync0sync.ic
  storage/innobase/include/trx0undo.h
  storage/innobase/include/univ.i
  storage/innobase/include/ut0ut.h
  storage/innobase/os/os0file.c
  storage/innobase/os/os0sync.c
  storage/innobase/plug.in
  storage/innobase/read/read0read.c
  storage/innobase/row/row0mysql.c
  storage/innobase/row/row0sel.c
  storage/innobase/srv/srv0srv.c
  storage/innobase/srv/srv0start.c
  storage/innobase/sync/sync0arr.c
  storage/innobase/sync/sync0rw.c
  storage/innobase/sync/sync0sync.c
  storage/innobase/trx/trx0trx.c
  storage/innobase/trx/trx0undo.c
  storage/innobase/ut/ut0ut.c

=== modified file 'Makefile.am'
--- a/Makefile.am	2008-05-21 10:17:29 +0000
+++ b/Makefile.am	2008-06-16 19:27:44 +0000
@@ -17,9 +17,14 @@
 
 AUTOMAKE_OPTIONS =	foreign
 
-# These are built from source in the Docs directory
+# Files in the first two lines are built from source in the Docs directory,
+# "CMakeLists.txt" is for Windows only,
+# "libevent_configure.m4" is needed in sources but should be evaluated only
+#    if "--with-libevent" is given (handled in "config/ac-macros/libevent.m4").
 EXTRA_DIST =		INSTALL-SOURCE INSTALL-WIN-SOURCE \
-			README COPYING EXCEPTIONS-CLIENT CMakeLists.txt
+			README COPYING EXCEPTIONS-CLIENT \
+			CMakeLists.txt \
+			config/ac-macros/libevent_configure.m4
 
 SUBDIRS =		. include @docs_dirs@ @zlib_dir@ \
 			@readline_topdir@ sql-common scripts \

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2008-04-01 10:45:05 +0000
+++ b/client/mysql.cc	2008-06-20 19:24:46 +0000
@@ -1848,7 +1848,7 @@ static int read_and_execute(bool interac
         the very beginning of a text file when
         you save the file using "Unicode UTF-8" format.
       */
-      if (!line_number &&
+      if (line && !line_number &&
            (uchar) line[0] == 0xEF &&
            (uchar) line[1] == 0xBB &&
            (uchar) line[2] == 0xBF)
@@ -2128,37 +2128,6 @@ static bool add_line(String &buffer,char
 	continue;
       }
     }
-    else if (!*ml_comment && !*in_string &&
-             (end_of_line - pos) >= 10 &&
-             !my_strnncoll(charset_info, (uchar*) pos, 10,
-                           (const uchar*) "delimiter ", 10))
-    {
-      // Flush previously accepted characters
-      if (out != line)
-      {
-        buffer.append(line, (uint32) (out - line));
-        out= line;
-      }
-
-      // Flush possible comments in the buffer
-      if (!buffer.is_empty())
-      {
-        if (com_go(&buffer, 0) > 0) // < 0 is not fatal
-          DBUG_RETURN(1);
-        buffer.length(0);
-      }
-
-      /*
-        Delimiter wants the get rest of the given line as argument to
-        allow one to change ';' to ';;' and back
-      */
-      buffer.append(pos);
-      if (com_delimiter(&buffer, pos) > 0)
-        DBUG_RETURN(1);
-
-      buffer.length(0);
-      break;
-    }
     else if (!*ml_comment && !*in_string && is_prefix(pos, delimiter))
     {
       // Found a statement. Continue parsing after the delimiter

=== modified file 'config/ac-macros/libevent.m4'
--- a/config/ac-macros/libevent.m4	2008-04-28 23:56:34 +0000
+++ b/config/ac-macros/libevent.m4	2008-06-16 19:27:44 +0000
@@ -22,7 +22,8 @@ AC_DEFUN([MYSQL_USE_BUNDLED_LIBEVENT], [
   AC_DEFINE([HAVE_LIBEVENT], [1], [If we want to use libevent and have connection pooling])
   AC_MSG_RESULT([using bundled libevent])
 
-  dnl Use builtin include to workaround path problems on older versions of aclocal.
+  dnl Get the upstream file with the original libevent configure macros.
+  dnl Use builtin include for this, to work around path problems in old versions of aclocal.
   builtin([include],[config/ac-macros/libevent_configure.m4])
 ])
 

=== modified file 'mysql-test/lib/mtr_cases.pl'
--- a/mysql-test/lib/mtr_cases.pl	2008-02-11 16:11:22 +0000
+++ b/mysql-test/lib/mtr_cases.pl	2008-06-18 03:30:29 +0000
@@ -773,6 +773,13 @@ sub collect_one_test_case($$$$$$$$$) {
 	if ( $::used_default_engine =~ /^innodb/i );
     }
 
+    #enable federated for this test
+    if ($tinfo->{'federated_test'})
+    {
+      push(@{$tinfo->{'master_opt'}}, "--loose-federated");
+      push(@{$tinfo->{'slave_opt'}}, "--loose-federated");
+    }
+
     if ( $tinfo->{'big_test'} and ! $::opt_big_test )
     {
       $tinfo->{'skip'}= 1;
@@ -891,6 +898,8 @@ our @tags=
  ["include/have_ndb_extra.inc", "ndb_extra", 1],
  ["include/ndb_master-slave.inc", "ndb_test", 1],
  ["require_manager", "require_manager", 1],
+ ["include/federated.inc", "federated_test", 1],
+ ["include/have_federated_db.inc", "federated_test", 1],
 );
 
 sub mtr_options_from_test_file($$) {

=== modified file 'mysql-test/lib/mtr_report.pl'
--- a/mysql-test/lib/mtr_report.pl	2008-05-05 19:38:05 +0000
+++ b/mysql-test/lib/mtr_report.pl	2008-06-26 16:20:30 +0000
@@ -333,6 +333,7 @@ sub mtr_report_stats ($) {
 		(
 		  /Backup:/ or /Restore:/ or /Can't open the online backup progress tables/
 		) or
+                
 		# The tablespace test triggers error below on purpose
 		($testname eq 'main.backup_tablespace') and
 		(
@@ -341,6 +342,8 @@ sub mtr_report_stats ($) {
 		
 		# ignore warning generated when backup engine selection algorithm is tested
 		($testname eq 'main.backup_no_be') and /Backup: Cannot create backup engine/ or
+		# ignore warnings generated when backup privilege is tested
+		($testname eq 'main.backup_security') and /(Backup|Restore): Access denied; you need the SUPER/ or
 		
 		/Sort aborted/ or
 		/Time-out in NDB/ or

=== modified file 'mysql-test/r/backup.result'
--- a/mysql-test/r/backup.result	2008-06-12 19:54:19 +0000
+++ b/mysql-test/r/backup.result	2008-06-25 13:39:04 +0000
@@ -1,4 +1,4 @@
-SET GLOBAL debug="d,backup_debug:d,backup";
+SET DEBUG_SYNC= 'RESET';
 DROP DATABASE IF EXISTS db1;
 DROP DATABASE IF EXISTS db2;
 DROP DATABASE IF EXISTS db3;
@@ -42,14 +42,13 @@ CREATE TABLE `tasking` (
 LOCK TABLES `tasking` WRITE;
 INSERT INTO `tasking` VALUES ('333445555','405',23),('123763153','405',33.5),('921312388','601',44),('800122337','300',13),('820123637','300',9.5),('830132335','401',8.5),('333445555','300',11),('921312388','500',13),('800122337','300',44),('820123637','401',500.5),('830132335','400',12),('333445665','600',300.25),('123654321','607',444.75),('123456789','300',1000);
 UNLOCK TABLES;
-breakpoints: Getting lock "locking_thread_added"
-SELECT get_lock("locking_thread_added", 100);
-get_lock("locking_thread_added", 100)
-1
+backup: Activate synchronization points for BACKUP.
+SET DEBUG_SYNC= 'locking_thread_added SIGNAL bup_thread_added
+                 WAIT_FOR finish';
 backup: Send the backup command.
 BACKUP DATABASE db1,db2 TO 'test.ba';
-breakpoints: Check for lock in process list.
-breakpoints: Checking locks.
+breakpoints: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_thread_added';
 SELECT id, command, state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%" OR info LIKE "default driver locking thread%";
 id	#
@@ -58,12 +57,10 @@ state	Locking thread: holding table lock
 info	default driver locking thread
 id	#
 command	Query
-state	debug_sync_point: locking_thread_added
+state	debug sync point: locking_thread_added
 info	BACKUP DATABASE db1,db2 TO 'test.ba'
-breakpoints: Release lock
-SELECT release_lock("locking_thread_added");
-release_lock("locking_thread_added")
-1
+breakpoints: Sending finish signal to wake BACKUP.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 backup_id
 #
 DROP DATABASE db1;
@@ -134,6 +131,7 @@ tasking	CREATE TABLE `tasking` (
 DROP DATABASE db1;
 DROP DATABASE db2;
 DROP DATABASE db3;
+SET DEBUG_SYNC= 'RESET';
 DROP DATABASE IF EXISTS bup_default;
 CREATE DATABASE bup_default;
 CREATE TABLE bup_default.wide (

=== modified file 'mysql-test/r/backup_commit_blocker.result'
--- a/mysql-test/r/backup_commit_blocker.result	2007-12-04 17:38:12 +0000
+++ b/mysql-test/r/backup_commit_blocker.result	2008-06-25 13:39:04 +0000
@@ -1,6 +1,6 @@
+SET DEBUG_SYNC= 'RESET';
 DROP DATABASE IF EXISTS bup_commit_blocker;
 CREATE DATABASE bup_commit_blocker;
-SET GLOBAL debug="d,backup_debug:d,backup";
 
 Starting Test 1
 
@@ -55,62 +55,72 @@ Assumption (b): TRX in commit is include
 BEGIN;
 INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 04 Some data to test");
 INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 05 Some data to test");
-con5: Getting lock on commit blocker.
-SELECT get_lock("commit_blocker_step_1", 0);
-get_lock("commit_blocker_step_1", 0)
-1
+con1: Activate synchronization points for BACKUP.
+SET DEBUG_SYNC= 'before_commit_block SIGNAL bup_commit_block
+                 WAIT_FOR bup_go_read_lock';
+SET DEBUG_SYNC= 'wait_lock_global_read_lock SIGNAL bup_read_lock';
+SET DEBUG_SYNC= 'before_backup_unblock_commit WAIT_FOR finish';
 con1: Backing up database -- will block with lock
 BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak";
-con5: Checking lock
+con5: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_commit_block';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 state	info
-debug_sync_point: commit_blocker_step_1	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
-con3: Starting commit -- will block with lock
+debug sync point: before_commit_block	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+con3: Activate synchronization points for COMMIT.
+SET DEBUG_SYNC= 'within_ha_commit_trans SIGNAL commit_read_locked
+                 WAIT_FOR commit_go_done';
+SET DEBUG_SYNC= 'after_commit SIGNAL commit_done
+                 WAIT_FOR finish';
+con3: Starting commit -- will block on sync point
 COMMIT;
-con5: Checking lock
+con5: Wait for COMMIT to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR commit_read_locked';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 state	info
-debug_sync_point: commit_blocker_step_1	COMMIT
-con5: Getting lock on commit blocker.
-SELECT get_lock("backup_commit_blocker", 0);
-get_lock("backup_commit_blocker", 0)
-1
-con5: Checking lock
+debug sync point: within_ha_commit_trans	COMMIT
+con5: Let BACKUP run until the next sync point.
+SET DEBUG_SYNC= 'now SIGNAL bup_go_read_lock WAIT_FOR bup_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 state	info
-debug_sync_point: backup_commit_blocker	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
-con5: Checking lock
+Waiting to get readlock	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+con5: Let COMMIT continue until end of statement.
+SET DEBUG_SYNC= 'now SIGNAL commit_go_done WAIT_FOR commit_done';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 state	info
-debug_sync_point: backup_commit_blocker	COMMIT
-con4: Starting begin -- will block with lock
+debug sync point: after_commit	COMMIT
+con4: Activate synchronization point for BEGIN.
+SET DEBUG_SYNC= 'before_begin_trans SIGNAL begin_starting
+                 WAIT_FOR finish';
+con4: Starting begin -- will block on sync point
 Assumption (c): TRX not started is not included in backup
 BEGIN;
-con5: Checking lock
+con5: Wait for BEGIN to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR begin_starting';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BEGIN%";
 state	info
-debug_sync_point: backup_commit_blocker	BEGIN
-con5: Releasing lock
-SELECT release_lock("backup_commit_blocker");
-release_lock("backup_commit_blocker")
-1
+debug sync point: before_begin_trans	BEGIN
+con5: Sending finish signal to wake them all.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 con2: Completing transaction
 DELETE FROM bup_commit_blocker.t1 WHERE col_a LIKE '02%';
 COMMIT;
-con3: Completing transaction
+con3: Fetch COMMIT result
+con4: Fetch BEGIN result and completing transaction
 UPDATE bup_commit_blocker.t3 SET col_a = "con4: 05 CHANGED" WHERE col_a LIKE '05%';
 UPDATE bup_commit_blocker.t3 SET col_a = "con4: 06 CHANGED" WHERE col_a LIKE '06%';
 COMMIT;
+con1: Fetch BACKUP result
 backup_id
 #
 con1: Showing data after updates and backup
@@ -185,6 +195,7 @@ count(*)
 0
 con1: Cleanup
 DROP DATABASE bup_commit_blocker;
+SET DEBUG_SYNC= 'RESET';
 
 Starting Test 2
 
@@ -201,23 +212,18 @@ col_a
 30
 40
 50
-con5: Getting lock on commit blocker.
-SELECT get_lock("backup_commit_blocker", 0);
-get_lock("backup_commit_blocker", 0)
-1
-con5: Checking lock
+con1: Activate synchronization point for BACKUP.
+SET DEBUG_SYNC= 'before_backup_data_unlock SIGNAL bup_data_unlock
+                 WAIT_FOR finish';
 con1: Backing up database -- will block with lock
 BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak";
-con5: Getting lock on commit blocker.
-SELECT get_lock("commit_blocker_step_4", 0);
-get_lock("commit_blocker_step_4", 0)
-1
-con5: Checking lock
+con5: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_data_unlock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 state	info
-debug_sync_point: commit_blocker_step_4	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+debug sync point: before_backup_data_unlock	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
 con7: Show that the statement in progress has executed before backup.
 SELECT * FROM bup_commit_blocker.t5;
 col_a
@@ -226,24 +232,22 @@ col_a
 30
 40
 50
-con7: Starting non-trx about to start -- will block with lock
+con7: Activate synchronization point for UPDATE.
+SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL upd_read_lock';
+con7: Starting non-trx about to start
 Assumption (e): non-TRX not started is not included in backup
 UPDATE bup_commit_blocker.t5 SET col_a = 333 WHERE col_a = 30;
-con5: Checking lock
+con5: Wait for UPDATE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR upd_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "UPDATE%";
 state	info
 Waiting for release of readlock	UPDATE bup_commit_blocker.t5 SET col_a = 333 WHERE col_a = 30
-con5: Releasing locks
-SELECT release_lock("commit_blocker_step_4");
-release_lock("commit_blocker_step_4")
-1
-SELECT release_lock("backup_commit_blocker");
-release_lock("backup_commit_blocker")
-NULL
-con6: Completing statement
-con7: Completing statement
+con5: Sending finish signal to wake them all.
+SET DEBUG_SYNC= 'now SIGNAL finish';
+con7: Fetch UPDATE result
+con1: Fetch BACKUP result
 backup_id
 #
 con1: Showing data after updates and backup
@@ -277,6 +281,7 @@ count(*)
 0
 con1: Cleanup
 DROP DATABASE bup_commit_blocker;
+SET DEBUG_SYNC= 'RESET';
 
 Starting Test 3
 
@@ -341,57 +346,68 @@ Assumption (b): TRX in commit is include
 BEGIN;
 INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 04 Some data to test");
 INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 05 Some data to test");
-con5: Getting lock on commit blocker.
-SELECT get_lock("commit_blocker_step_1", 0);
-get_lock("commit_blocker_step_1", 0)
-1
+con1: Activate synchronization points for BACKUP.
+SET DEBUG_SYNC= 'before_commit_block SIGNAL bup_commit_block
+                 WAIT_FOR bup_go_read_lock';
+SET DEBUG_SYNC= 'wait_lock_global_read_lock SIGNAL bup_read_lock';
+SET DEBUG_SYNC= 'before_backup_unblock_commit SIGNAL bup_unblocking
+                 WAIT_FOR finish';
 con1: Backing up database -- will block with lock
 BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak";
-con5: Checking lock
+con5: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_commit_block';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 state	info
-debug_sync_point: commit_blocker_step_1	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
-con3: Starting commit -- will block with lock
+debug sync point: before_commit_block	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+con3: Activate synchronization points for COMMIT.
+SET DEBUG_SYNC= 'within_ha_commit_trans SIGNAL commit_read_locked
+                 WAIT_FOR commit_go_done';
+SET DEBUG_SYNC= 'after_commit WAIT_FOR finish';
+con3: Starting commit -- will block on sync point
 COMMIT;
-con5: Checking lock
+con5: Wait for COMMIT to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR commit_read_locked';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 state	info
-debug_sync_point: commit_blocker_step_1	COMMIT
-con5: Getting lock on commit blocker.
-SELECT get_lock("backup_commit_blocker", 0);
-get_lock("backup_commit_blocker", 0)
-1
-con5: Checking lock
+debug sync point: within_ha_commit_trans	COMMIT
+con5: Let BACKUP run until the next sync point.
+SET DEBUG_SYNC= 'now SIGNAL bup_go_read_lock WAIT_FOR bup_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 state	info
-debug_sync_point: backup_commit_blocker	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
-con5: Checking lock
+Waiting to get readlock	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+con5: Let COMMIT continue until the sync point at its end.
+con5: The completed COMMIT implicitly wakes BACKUP.
+con5: So wait for BACKUP to reach the next synchronization point.
+SET DEBUG_SYNC= 'now SIGNAL commit_go_done WAIT_FOR bup_unblocking';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 state	info
-debug_sync_point: backup_commit_blocker	COMMIT
+debug sync point: after_commit	COMMIT
+SELECT state, info FROM
+INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%";
+state	info
+debug sync point: before_backup_unblock_commit	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+con4: Activate synchronization point for BEGIN.
+SET DEBUG_SYNC= 'before_begin_trans SIGNAL begin_starting
+                 WAIT_FOR finish';
 con4: Starting begin -- will block with lock
 Assumption (c): TRX not started is not included in backup
 BEGIN;
-con5: Checking lock
+con5: Wait for BEGIN to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR begin_starting';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BEGIN%";
 state	info
-debug_sync_point: backup_commit_blocker	BEGIN
-con5: Checking lock
-SELECT state, info FROM
-INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-state	info
-debug_sync_point: backup_commit_blocker	BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak"
+debug sync point: before_begin_trans	BEGIN
 con7: Show that the statement in progress has executed before backup.
 SELECT * FROM bup_commit_blocker.t5;
 col_a
@@ -400,27 +416,30 @@ col_a
 30
 40
 50
+con7: Activate synchronization point for DELETE.
+SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL del_read_lock';
 con7: Starting non-trx about to start -- will block with lock
 Assumption (e): non-TRX not started is not included in backup
 DELETE FROM bup_commit_blocker.t5 WHERE col_a = 50;
-con5: Checking lock
+con5: Wait for DELETE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR del_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "DELETE%";
 state	info
 Waiting for release of readlock	DELETE FROM bup_commit_blocker.t5 WHERE col_a = 50
-con5: Releasing lock
-SELECT release_lock("backup_commit_blocker");
-release_lock("backup_commit_blocker")
-1
+con5: Sending finish signal to wake them all.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 con2: Completing transaction
 DELETE FROM bup_commit_blocker.t2 WHERE col_a LIKE '02%';
 COMMIT;
-con3: Completing transaction
+con3: Fetch COMMIT result
+con4: Fetch BEGIN result and completing transaction
 UPDATE bup_commit_blocker.t3 SET col_a = "con4: 05 CHANGED" WHERE col_a LIKE '05%';
 UPDATE bup_commit_blocker.t3 SET col_a = "con4: 06 CHANGED" WHERE col_a LIKE '06%';
 COMMIT;
-con7: Completing statement
+con7: Fetch DELETE result
+con1: Fetch BACKUP result
 backup_id
 #
 con1: Showing data after updates and backup
@@ -513,3 +532,4 @@ count(*)
 1
 con1: Cleanup
 DROP DATABASE bup_commit_blocker;
+SET DEBUG_SYNC= 'RESET';

=== added file 'mysql-test/r/backup_compression.result'
--- a/mysql-test/r/backup_compression.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_compression.result	2008-06-25 13:30:04 +0000
@@ -0,0 +1,23 @@
+CREATE DATABASE db1;
+CREATE TABLE db1.t1(a INT);
+BACKUP DATABASE db1 TO 'db1.bak.gz' WITH COMPRESSION;
+backup_id
+#
+CREATE TABLE db1.t2(a INT);
+BACKUP DATABASE db1 TO 'db2.bak.gz' WITH COMPRESSION COMPRESSION_ALGORITHM=gzip;
+backup_id
+#
+RESTORE FROM 'db1.bak.gz';
+backup_id
+#
+SHOW TABLES FROM db1;
+Tables_in_db1
+t1
+RESTORE FROM 'db2.bak.gz';
+backup_id
+#
+SHOW TABLES FROM db1;
+Tables_in_db1
+t1
+t2
+DROP DATABASE db1;

=== modified file 'mysql-test/r/backup_ddl_blocker.result'
--- a/mysql-test/r/backup_ddl_blocker.result	2007-12-20 20:32:22 +0000
+++ b/mysql-test/r/backup_ddl_blocker.result	2008-06-25 13:39:04 +0000
@@ -1,4 +1,4 @@
-SET GLOBAL debug="d,backup_debug:d,backup";
+SET DEBUG_SYNC= 'reset';
 
 Starting Test 1 - Backup
 
@@ -23,54 +23,67 @@ INSERT INTO bup_ddl_blocker.t4 VALUES ("
 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;
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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: Checking locks
+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: DDL_in_progress	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
+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: DDL_in_progress	CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB
+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: DDL_in_progress	ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
+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
-DDL blocker: DDL is blocked	CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB
+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
-DDL blocker: DDL is blocked	ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -144,54 +157,67 @@ DROP TABLE bup_ddl_blocker.t1, bup_ddl_b
 BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
 backup_id
 #
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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";
-con6: Checking locks
+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: DDL_in_progress	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak"
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
 state	info
-debug_sync_point: DDL_in_progress	CREATE TABLE bup_ddl_blocker.t1 (col_a CHAR(40)) ENGINE=INNODB
+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: DDL_in_progress	ALTER TABLE bup_ddl_blocker.t2 ADD COLUMN col_b int
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.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
-DDL blocker: DDL is blocked	CREATE TABLE bup_ddl_blocker.t3 (col_a CHAR(40)) ENGINE=INNODB
+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
-DDL blocker: DDL is blocked	ALTER TABLE bup_ddl_blocker.t4 ADD COLUMN col_b int
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -240,54 +266,67 @@ INSERT INTO bup_ddl_blocker.t3 VALUES ("
 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");
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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: Checking locks
+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: DDL_in_progress	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
+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: DDL_in_progress	RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01
+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: DDL_in_progress	REPAIR TABLE bup_ddl_blocker.t2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
+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
-DDL blocker: DDL is blocked	RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03
+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
-DDL blocker: DDL is blocked	REPAIR TABLE bup_ddl_blocker.t4
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -352,54 +391,67 @@ INSERT INTO bup_ddl_blocker.t4 VALUES ("
 BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
 backup_id
 #
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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";
-con6: Checking locks
+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: DDL_in_progress	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak"
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
 state	info
-debug_sync_point: DDL_in_progress	RENAME TABLE bup_ddl_blocker.t1 TO bup_ddl_blocker.t01
+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: DDL_in_progress	REPAIR TABLE bup_ddl_blocker.t2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.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
-DDL blocker: DDL is blocked	RENAME TABLE bup_ddl_blocker.t3 TO bup_ddl_blocker.t03
+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
-DDL blocker: DDL is blocked	REPAIR TABLE bup_ddl_blocker.t4
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -444,54 +496,67 @@ INSERT INTO bup_ddl_blocker.t3 VALUES ("
 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");
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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: Checking locks
+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: DDL_in_progress	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
+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: DDL_in_progress	OPTIMIZE TABLE bup_ddl_blocker.t1
+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: DDL_in_progress	DROP TABLE bup_ddl_blocker.t2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak"
+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
-DDL blocker: DDL is blocked	OPTIMIZE TABLE bup_ddl_blocker.t3
+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
-DDL blocker: DDL is blocked	DROP TABLE bup_ddl_blocker.t4
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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	status	OK
@@ -551,54 +616,67 @@ INSERT INTO bup_ddl_blocker.t4 VALUES ("
 BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
 backup_id
 #
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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";
-con6: Checking locks
+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: DDL_in_progress	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak"
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
 state	info
-debug_sync_point: DDL_in_progress	OPTIMIZE TABLE bup_ddl_blocker.t1
+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: DDL_in_progress	DROP TABLE bup_ddl_blocker.t2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.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
-DDL blocker: DDL is blocked	OPTIMIZE TABLE bup_ddl_blocker.t3
+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
-DDL blocker: DDL is blocked	DROP TABLE bup_ddl_blocker.t4
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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	status	OK
@@ -644,54 +722,67 @@ SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 Database (bup_ddl_blocker_%)
 bup_ddl_blocker_2
 bup_ddl_blocker_4
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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: Checking locks
+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: DDL_in_progress	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
+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: DDL_in_progress	CREATE DATABASE bup_ddl_blocker_1
+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: DDL_in_progress	DROP DATABASE bup_ddl_blocker_2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
+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
-DDL blocker: DDL is blocked	CREATE DATABASE bup_ddl_blocker_3
+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
-DDL blocker: DDL is blocked	DROP DATABASE bup_ddl_blocker_4
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -751,54 +842,67 @@ bup_ddl_blocker_4
 BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
 backup_id
 #
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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";
-con6: Checking locks
+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: DDL_in_progress	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak"
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
 state	info
-debug_sync_point: DDL_in_progress	CREATE DATABASE bup_ddl_blocker_1
+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: DDL_in_progress	DROP DATABASE bup_ddl_blocker_2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.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
-DDL blocker: DDL is blocked	CREATE DATABASE bup_ddl_blocker_3
+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
-DDL blocker: DDL is blocked	DROP DATABASE bup_ddl_blocker_4
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -839,54 +943,67 @@ SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 Database (bup_ddl_blocker_%)
 bup_ddl_blocker_2
 bup_ddl_blocker_4
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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: Checking locks
+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: DDL_in_progress	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
+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: DDL_in_progress	TRUNCATE TABLE bup_ddl_blocker_2.t1
+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: DDL_in_progress	ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	BACKUP DATABASE * TO "bup_ddl_blocker.bak"
+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
-DDL blocker: DDL is blocked	ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2
+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
-DDL blocker: DDL is blocked	TRUNCATE TABLE bup_ddl_blocker_4.t1
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -975,54 +1092,67 @@ bup_ddl_blocker_4
 BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
 backup_id
 #
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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";
-con6: Checking locks
+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: DDL_in_progress	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak"
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
 state	info
-debug_sync_point: DDL_in_progress	ALTER DATABASE bup_ddl_blocker_2 CHARACTER SET latin2
+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: DDL_in_progress	TRUNCATE TABLE bup_ddl_blocker_2.t1
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.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 "TRUNCATE TABLE bup_ddl_blocker_4%";
 state	info
-DDL blocker: DDL is blocked	TRUNCATE TABLE bup_ddl_blocker_4.t1
+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
-DDL blocker: DDL is blocked	ALTER DATABASE bup_ddl_blocker_4 CHARACTER SET latin2
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -1087,60 +1217,73 @@ INSERT INTO bup_ddl_blocker_4.t1 VALUES 
 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);
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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: Checking locks
+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: DDL_in_progress	BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
+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: DDL_in_progress	CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b)
+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: DDL_in_progress	DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	BACKUP DATABASE bup_ddl_blocker_1, bup_ddl_blocker_2,
+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
-DDL blocker: DDL is blocked	CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b)
+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
-DDL blocker: DDL is blocked	DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -1265,57 +1408,67 @@ bup_ddl_blocker_3, bup_ddl_blocker_4
 TO "bup_ddl_blocker_orig.bak";
 backup_id
 #
-con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-get_lock("DDL_in_progress", 0)
-1
+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";
-con6: Checking locks
+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: DDL_in_progress	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: before_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.bak"
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "CREATE INDEX 1t1col_b%";
 state	info
-debug_sync_point: DDL_in_progress	CREATE INDEX 1t1col_b ON bup_ddl_blocker_1.t1 (col_b)
+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: DDL_in_progress	DROP INDEX 2t1col_b ON bup_ddl_blocker_2.t1
-con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-get_lock("DDL_blocked", 0)
-1
-con6: Checking locks
+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: DDL_blocked	RESTORE FROM "bup_ddl_blocker_orig.bak"
+debug sync point: after_block_ddl	RESTORE FROM "bup_ddl_blocker_orig.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
-DDL blocker: DDL is blocked	CREATE INDEX 3t1col_b ON bup_ddl_blocker_3.t1 (col_b)
-Timeout in wait_condition.inc for SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DDROP INDEX 4t1col_b%"
+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
-DDL blocker: DDL is blocked	DROP INDEX 4t1col_b ON bup_ddl_blocker_4.t1
-con6: Releasing lock
-SELECT release_lock("DDL_blocked");
-release_lock("DDL_blocked")
-1
+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
@@ -1397,33 +1550,38 @@ col_a
 01 Some data to test
 02 Some data to test
 03 Some data to test
-con5: Getting lock on DDL in progress.
-SELECT get_lock("DDL_not_blocked", 0);
-get_lock("DDL_not_blocked", 0)
-1
+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: Checking locks
+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: DDL_not_blocked	ALTER TABLE bup_ddl_blocker.t1 ADD COLUMN col_b int
+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: DDL_not_blocked	ALTER TABLE test.t2 ADD COLUMN col_b int
+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: DDL_not_blocked	ALTER TABLE bup_ddl_blocker.t3 ADD COLUMN col_b int
-con5: Releasing lock
-SELECT release_lock("DDL_not_blocked");
-release_lock("DDL_not_blocked")
-1
+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
@@ -1460,3 +1618,4 @@ count(*)
 2
 DROP TABLE test.t2;
 DROP DATABASE bup_ddl_blocker;
+SET DEBUG_SYNC= 'reset';

=== added file 'mysql-test/r/backup_many_dbs.result'
--- a/mysql-test/r/backup_many_dbs.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_many_dbs.result	2008-06-20 08:33:54 +0000
@@ -0,0 +1,106 @@
+Starting regression test for bug 33568
+DROP DATABASE IF EXISTS db1;
+DROP DATABASE IF EXISTS db2;
+DROP DATABASE IF EXISTS db3;
+DROP DATABASE IF EXISTS db4;
+DROP DATABASE IF EXISTS db5;
+DROP DATABASE IF EXISTS db6;
+DROP DATABASE IF EXISTS db7;
+DROP DATABASE IF EXISTS db8;
+DROP DATABASE IF EXISTS db9;
+DROP DATABASE IF EXISTS db10;
+DROP DATABASE IF EXISTS db11;
+DROP DATABASE IF EXISTS db12;
+DROP DATABASE IF EXISTS db13;
+DROP DATABASE IF EXISTS db14;
+DROP DATABASE IF EXISTS db15;
+DROP DATABASE IF EXISTS db16;
+DROP DATABASE IF EXISTS db17;
+DROP DATABASE IF EXISTS db18;
+Creating 18 databases
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+CREATE DATABASE db3;
+CREATE DATABASE db4;
+CREATE DATABASE db5;
+CREATE DATABASE db6;
+CREATE DATABASE db7;
+CREATE DATABASE db8;
+CREATE DATABASE db9;
+CREATE DATABASE db10;
+CREATE DATABASE db11;
+CREATE DATABASE db12;
+CREATE DATABASE db13;
+CREATE DATABASE db14;
+CREATE DATABASE db15;
+CREATE DATABASE db16;
+CREATE DATABASE db17;
+CREATE DATABASE db18;
+Backing up the databases
+BACKUP DATABASE db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, db11, db12, db13, db14, db15, db16, db17, db18  
+TO 'bup_manydbs.bak';
+backup_id
+#
+Dropping the databases
+DROP DATABASE db1;
+DROP DATABASE db2;
+DROP DATABASE db3;
+DROP DATABASE db4;
+DROP DATABASE db5;
+DROP DATABASE db6;
+DROP DATABASE db7;
+DROP DATABASE db8;
+DROP DATABASE db9;
+DROP DATABASE db10;
+DROP DATABASE db11;
+DROP DATABASE db12;
+DROP DATABASE db13;
+DROP DATABASE db14;
+DROP DATABASE db15;
+DROP DATABASE db16;
+DROP DATABASE db17;
+DROP DATABASE db18;
+Restoring databases
+RESTORE FROM 'bup_manydbs.bak';
+backup_id
+#
+Checking that all dbs are there
+SHOW DATABASES LIKE 'db%';
+Database (db%)
+db1
+db10
+db11
+db12
+db13
+db14
+db15
+db16
+db17
+db18
+db2
+db3
+db4
+db5
+db6
+db7
+db8
+db9
+Cleaning up
+DROP DATABASE db1;
+DROP DATABASE db2;
+DROP DATABASE db3;
+DROP DATABASE db4;
+DROP DATABASE db5;
+DROP DATABASE db6;
+DROP DATABASE db7;
+DROP DATABASE db8;
+DROP DATABASE db9;
+DROP DATABASE db10;
+DROP DATABASE db11;
+DROP DATABASE db12;
+DROP DATABASE db13;
+DROP DATABASE db14;
+DROP DATABASE db15;
+DROP DATABASE db16;
+DROP DATABASE db17;
+DROP DATABASE db18;

=== added file 'mysql-test/r/backup_multi_blocks.result'
--- a/mysql-test/r/backup_multi_blocks.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_multi_blocks.result	2008-06-25 13:40:49 +0000
@@ -0,0 +1,42 @@
+DROP DATABASE IF EXISTS mysqltest;
+Creating database and tables ...
+CREATE DATABASE mysqltest;
+USE mysqltest;
+CREATE TABLE t1 (a LONGTEXT) ENGINE=MYISAM;
+Inserting data ...
+USE mysqltest;
+INSERT INTO t1 VALUES ("text");
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+UPDATE t1 SET a=CONCAT(a,a);
+SELECT LENGTH(a) FROM t1;
+LENGTH(a)
+32768
+Performing backup ...
+BACKUP DATABASE mysqltest TO 'test.ba';
+backup_id
+#;
+DROP DATABASE mysqltest;
+Performing restore ...
+RESTORE FROM 'test.ba';
+backup_id
+#;
+Checking contents of restore ...
+SELECT LENGTH(a) FROM t1;
+LENGTH(a)
+32768
+CHECKSUM TABLE t1;
+Table	Checksum
+mysqltest.t1	3394496868
+Clean-up
+DROP DATABASE mysqltest;

=== added file 'mysql-test/r/backup_procedures.result'
--- a/mysql-test/r/backup_procedures.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_procedures.result	2008-06-25 12:40:06 +0000
@@ -0,0 +1,41 @@
+
+Starting regression test for 34868 - Backup: restore failure if two procedures
+
+Create database and procedures
+DROP DATABASE IF EXISTS bup_proc;
+CREATE DATABASE bup_proc;
+USE bup_proc;
+CREATE PROCEDURE p1() SET @a=5;
+CREATE PROCEDURE p2() SET @a=100;
+
+Check that procedures are there before the backup
+CALL p1();
+SELECT @a;
+@a
+5
+CALL p2();
+SELECT @a;
+@a
+100
+
+Backup and restore
+BACKUP DATABASE bup_proc to 'bup_proc.bak';
+backup_id
+#
+DROP DATABASE bup_proc;
+RESTORE FROM 'bup_proc.bak';
+backup_id
+#
+
+Check that procedures are there after the restore
+CALL p1();
+SELECT @a;
+@a
+5
+CALL p2();
+SELECT @a;
+@a
+100
+
+Cleaning up
+DROP DATABASE bup_proc;

=== modified file 'mysql-test/r/backup_progress.result'
--- a/mysql-test/r/backup_progress.result	2008-03-20 14:53:16 +0000
+++ b/mysql-test/r/backup_progress.result	2008-06-25 13:39:04 +0000
@@ -1,6 +1,6 @@
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE IF EXISTS backup_progress;
 DROP TABLE IF EXISTS backup_progress.t1_res;
-SET GLOBAL debug="d,backup_debug:d,backup";
 CREATE DATABASE backup_progress;
 con1: Create table and new users.
 CREATE TABLE backup_progress.t1 (a char(30)) ENGINE=MYISAM;
@@ -25,49 +25,41 @@ INSERT INTO backup_progress.t3 VALUES ("
 INSERT INTO backup_progress.t3 VALUES ("03 Test #1 - progress");
 INSERT INTO backup_progress.t3 VALUES ("04 Test #1 - progress");
 Do backup of database
-SELECT get_lock("bp_starting_state", 0);
-get_lock("bp_starting_state", 0)
-1
+con2: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_log_init     SIGNAL started   WAIT_FOR do_run';
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL phase1    WAIT_FOR backup';
+SET DEBUG_SYNC= 'after_backup_validated    SIGNAL validated WAIT_FOR do_phase2';
+SET DEBUG_SYNC= 'after_backup_binlog       SIGNAL phase2    WAIT_FOR finish';
 con2: Send backup command.
 BACKUP DATABASE backup_progress to 'backup_progress_orig.bak';
-con1: Checking locks.
-con1: Checking progress.
+con1: Wait for the backup to be started.
+SET DEBUG_SYNC= 'now WAIT_FOR started';
+con1: Display progress
 SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "BACKUP DATABASE backup_progress%";
 INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 backup_state
 starting
-con1: Advance the lock.
-SELECT get_lock("bp_running_state", 0);
-get_lock("bp_running_state", 0)
-1
-con1: Checking locks.
-con1: Checking progress.
+con1: Let backup step to running state.
+SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR phase1';
+con1: Display progress
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 backup_state
 running
-con1: Advance the lock.
-SELECT get_lock("bp_vp_state", 0);
-get_lock("bp_vp_state", 0)
-1
-con1: Checking locks.
-con1: Checking progress.
+con1: Let backup do the backup phase1.
+SET DEBUG_SYNC= 'now SIGNAL backup WAIT_FOR validated';
+con1: Display progress
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 backup_state
 validity point
-con1: Advance the lock.
-SELECT get_lock("bp_running_state", 0);
-get_lock("bp_running_state", 0)
-1
-con1: Checking locks.
-con1: Checking progress.
+con1: Let backup do the backup phase2.
+SET DEBUG_SYNC= 'now SIGNAL do_phase2 WAIT_FOR phase2';
+con1: Display progress
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 backup_state
 running
-con1: Advance the lock.
-SELECT release_lock("bp_running_state");
-release_lock("bp_running_state")
-1
+con1: Let backup finish.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 con2: Finish backup command
 backup_id
 #
@@ -98,14 +90,15 @@ backup_id	object	start_time	stop_time	to
 #	backup kernel	#	#	0	0	0	running
 #	backup kernel	#	#	0	0	0	complete
 Do restore of database
-SELECT get_lock("bp_starting_state", 0);
-get_lock("bp_starting_state", 0)
-1
 DELETE FROM backup_progress.t1_res;
+con2: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_log_init      SIGNAL started WAIT_FOR do_run';
+SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR finish';
 con2: Send restore command.
 RESTORE FROM 'backup_progress_orig.bak';
-con1: Checking locks.
-con1: Checking progress.
+con1: Wait for the restore to be started.
+SET DEBUG_SYNC= 'now WAIT_FOR started';
+con1: Display progress
 select * from backup_progress.t1_res;
 id
 SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
@@ -113,19 +106,14 @@ INSERT INTO backup_progress.t1_res (id) 
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 backup_state
 starting
-con1: Advance the lock.
-SELECT get_lock("bp_running_state", 0);
-get_lock("bp_running_state", 0)
-1
-con1: Checking locks.
-con1: Checking progress.
+con1: Let restore step to running state.
+SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR running';
+con1: Display progress
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 backup_state
 running
-con1: Advance the lock.
-SELECT release_lock("bp_running_state");
-release_lock("bp_running_state")
-1
+con1: Let restore do its job and finish.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 con2: Finish restore command
 backup_id
 #
@@ -156,4 +144,5 @@ backup_id	object	start_time	stop_time	to
 #	backup kernel	#	#	0	0	0	starting
 #	backup kernel	#	#	0	0	0	running
 #	backup kernel	#	#	0	0	0	complete
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE backup_progress;

=== modified file 'mysql-test/r/backup_snapshot.result'
--- a/mysql-test/r/backup_snapshot.result	2007-12-04 17:38:12 +0000
+++ b/mysql-test/r/backup_snapshot.result	2008-06-25 13:39:04 +0000
@@ -1,6 +1,9 @@
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE IF EXISTS bup_snapshot;
+#
+# Setup for tests.
+#
 CREATE DATABASE bup_snapshot;
-SET GLOBAL debug="d,backup_debug:d,backup";
 CREATE TABLE bup_snapshot.t1 (word CHAR(20)) ENGINE=INNODB;
 INSERT INTO bup_snapshot.t1 VALUES ("01 Some data to test");
 INSERT INTO bup_snapshot.t1 VALUES ("02 Some data to test");
@@ -23,21 +26,20 @@ COUNT(*)
 SELECT COUNT(*) FROM bup_snapshot.t2;
 COUNT(*)
 5
-con3: Getting lock on driver.
-SELECT get_lock("backup_cs_locked", 100);
-get_lock("backup_cs_locked", 100)
-1
+#
+# Test 1: Check for consistent read prior to open and lock tables
+#
+con1: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_cs_locked SIGNAL locked WAIT_FOR inserting';
 con1: Backing up database. Spawn this and continue...
 BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
-con3: Checking locks.
+con2: Wait for backup to have locked the transaction.
+SET DEBUG_SYNC= 'now WAIT_FOR locked';
+con2: Start an insert now that CS has a transaction 
+con2: Activate sync points for the insert statement.
+SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL inserting';
 INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
-con3: Checking locks.
-con3: Release lock on driver.
-SELECT release_lock("backup_cs_locked");
-release_lock("backup_cs_locked")
-1
-backup_id
-#
+con2: insert additional rows.
 INSERT INTO bup_snapshot.t1 VALUES("- Yes");
 INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
 DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
@@ -50,6 +52,11 @@ word
 SELECT COUNT(*) FROM bup_snapshot.t1;
 COUNT(*)
 12
+con1: retrieve backup result.
+backup_id
+#
+# Now restore the database and then check to make sure the new rows
+# were not backed up.
 con1: Dropping the database
 DROP TABLE bup_snapshot.t1;
 con1: Restoring the database
@@ -65,19 +72,20 @@ COUNT(*)
 SELECT COUNT(*) FROM bup_snapshot.t2;
 COUNT(*)
 5
-con3: Getting lock on driver.
-SELECT get_lock("backup_cs_reading", 100);
-get_lock("backup_cs_reading", 100)
-1
+#
+# Test 2: Check for consistent read after open and lock tables
+#
+con1: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'when_backup_cs_reading SIGNAL reading WAIT_FOR inserting';
 con1: Backing up database. Spawn this and continue...
 BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
-con3: Checking locks.
+con2: Wait for backup to start reading.
+SET DEBUG_SYNC= 'now WAIT_FOR reading';
+con2: Start an insert now that CS has a transaction 
+con2: Activate sync points for the insert statement.
+SET DEBUG_SYNC= 'after_insert_locked_tables SIGNAL inserting';
 INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
-con3: Checking locks.
-con3: Release lock on driver.
-SELECT release_lock("backup_cs_reading");
-release_lock("backup_cs_reading")
-1
+con2: insert additional rows.
 INSERT INTO bup_snapshot.t1 VALUES("- Yes");
 INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
 DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
@@ -90,8 +98,11 @@ word
 SELECT COUNT(*) FROM bup_snapshot.t1;
 COUNT(*)
 12
+con1: retrieve backup result.
 backup_id
 #
+# Now restore the database and then check to make sure the new rows
+# were not backed up.
 con1: Dropping the database
 DROP TABLE bup_snapshot.t1;
 con1: Restoring the database
@@ -107,4 +118,5 @@ COUNT(*)
 SELECT COUNT(*) FROM bup_snapshot.t2;
 COUNT(*)
 5
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE bup_snapshot;

=== added file 'mysql-test/r/backup_triggers_and_events.result'
--- a/mysql-test/r/backup_triggers_and_events.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/backup_triggers_and_events.result	2008-06-26 15:52:25 +0000
@@ -0,0 +1,196 @@
+SET GLOBAL event_scheduler=off;
+SET DEBUG_SYNC = 'RESET';
+Creating log table.
+DROP TABLE IF EXISTS test.logt;
+CREATE TABLE test.logt(ts timestamp, db char(8), msg text);
+Creating database db and its objects.
+DROP DATABASE IF EXISTS db;
+CREATE DATABASE db;
+USE db;
+CREATE TABLE t1 (a int);
+INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6);
+CREATE EVENT ev ON SCHEDULE EVERY 1 second DO 
+BEGIN
+INSERT INTO test.logt(db, msg) VALUES ('db','Db event fired!');
+END;
+||
+CREATE PROCEDURE trg_msg(a int)
+BEGIN
+INSERT INTO test.logt(db, msg) VALUES ('db','Db trigger fired!');
+END;
+||
+CREATE TRIGGER after_ins AFTER INSERT ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+CREATE TRIGGER after_upd AFTER UPDATE ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+CREATE TRIGGER after_del AFTER DELETE ON t1 FOR EACH ROW 
+CALL trg_msg(OLD.a);
+||
+CREATE TRIGGER before_ins BEFORE INSERT ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+CREATE TRIGGER before_upd BEFORE UPDATE ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+CREATE TRIGGER before_del BEFORE DELETE ON t1 FOR EACH ROW 
+CALL trg_msg(OLD.a);
+||
+USE test||
+DROP EVENT IF EXISTS ev||
+DROP TABLE IF EXISTS t1||
+DROP TRIGGER IF EXISTS trg||
+CREATE EVENT ev ON SCHEDULE EVERY 1 second DO
+BEGIN
+INSERT INTO test.logt(db, msg) VALUES ('test','Test event fired!');
+END;
+||
+CREATE TABLE t1 (a int)||
+CREATE TRIGGER trg AFTER INSERT ON t1 FOR EACH ROW
+BEGIN
+INSERT INTO test.logt(db, msg) VALUES ('test','Test trigger fired');   
+END;
+||
+Backing-up database db and dropping it.
+BACKUP DATABASE db TO 'db.bak';
+backup_id
+#
+DROP DATABASE db;
+Enabling event scheduler.
+SET GLOBAL event_scheduler=on;
+con1: clearing log table and starting RESTORE operation.
+con1: RESTORE will pause after restoring table data.
+SET DEBUG_SYNC = 'restore_table_data_before_end SIGNAL waiting WAIT_FOR continue';
+DELETE FROM test.logt;
+RESTORE FROM 'db.bak';
+SELECT now() INTO @start;
+con2: checking that there are no triggers and events at the end of RESTORE execution.
+SET DEBUG_SYNC = 'now WAIT_FOR waiting';
+SHOW TRIGGERS FROM db;
+SHOW EVENTS IN db;
+con2: activating trigger in test database.
+INSERT INTO test.t1 VALUES (1);
+con2: ensuring that RESTORE takes at least 3 secs.
+SET DEBUG_SYNC = 'now SIGNAL continue';
+con1: finishing RESTORE operation.
+backup_id
+#
+SET GLOBAL event_scheduler=off;
+con2: checking that RESTORE took more than 2 secs.
+SELECT timediff(now(),@start) > 2;
+timediff(now(),@start) > 2
+1
+Checking that objects have been restored.
+USE db;
+SHOW TABLES IN db;
+Tables_in_db
+t1
+SELECT count(*) FROM db.t1;
+count(*)
+7
+SHOW TRIGGERS FROM db;
+Trigger	before_ins
+Event	INSERT
+Table	t1
+Statement	CALL trg_msg(NEW.a)
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	#
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	after_ins
+Event	INSERT
+Table	t1
+Statement	CALL trg_msg(NEW.a)
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	#
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	before_upd
+Event	UPDATE
+Table	t1
+Statement	CALL trg_msg(NEW.a)
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	#
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	after_upd
+Event	UPDATE
+Table	t1
+Statement	CALL trg_msg(NEW.a)
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	#
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	before_del
+Event	DELETE
+Table	t1
+Statement	CALL trg_msg(OLD.a)
+Timing	BEFORE
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	#
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Trigger	after_del
+Event	DELETE
+Table	t1
+Statement	CALL trg_msg(OLD.a)
+Timing	AFTER
+Created	NULL
+sql_mode	
+Definer	root@localhost
+character_set_client	#
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+SHOW EVENTS IN db;
+Db	db
+Name	ev
+Definer	root@localhost
+Time zone	SYSTEM
+Type	RECURRING
+Execute at	NULL
+Interval value	1
+Interval field	SECOND
+Starts	#
+Ends	NULL
+Status	ENABLED
+Originator	1
+character_set_client	latin1
+collation_connection	latin1_swedish_ci
+Database Collation	latin1_swedish_ci
+Checking that no db event or trigger fired during RESTORE.
+SELECT * FROM test.logt WHERE db = 'db' AND timediff(ts,@start) < 2;
+ts	db	msg
+Checking that test event and trigger could fire.
+SELECT count(*) > 0 FROM test.logt 
+WHERE db = 'test'
+AND msg LIKE '%trigger fired%'
+AND timediff(ts,@start) < 2;
+count(*) > 0
+1
+SELECT count(*) > 0 FROM test.logt 
+WHERE db = 'test'
+AND msg LIKE '%event fired%'
+AND timediff(ts,@start) < 2;
+count(*) > 0
+1
+Cleaning up.
+DROP EVENT test.ev;
+DROP TRIGGER test.trg;
+DROP TABLE test.logt;
+DROP TABLE test.t1;
+DROP DATABASE db;

=== modified file 'mysql-test/r/backup_view_on_view.result'
--- a/mysql-test/r/backup_view_on_view.result	2008-06-05 12:38:10 +0000
+++ b/mysql-test/r/backup_view_on_view.result	2008-06-25 13:39:04 +0000
@@ -35,3 +35,4 @@ a
 5
 7
 11
+DROP DATABASE db1;

=== modified file 'mysql-test/r/character_set_server_func.result'
--- a/mysql-test/r/character_set_server_func.result	2008-04-10 13:14:28 +0000
+++ b/mysql-test/r/character_set_server_func.result	2008-06-25 13:39:04 +0000
@@ -1,3 +1,4 @@
+DROP DATABASE IF EXISTS db1;
 '#--------------------FN_DYNVARS_009_01-------------------------#'
 SET @global_character_set_server = @@global.character_set_server;
 SET @session_character_set_server = @@session.character_set_server;

=== added file 'mysql-test/r/innodb-autoinc.result'
--- a/mysql-test/r/innodb-autoinc.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb-autoinc.result	2008-06-12 00:08:07 +0000
@@ -0,0 +1,89 @@
+drop table if exists t1;
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+9223372036854775807	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (127, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+127	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (255, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+255	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (32767, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+32767	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (65535, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+65535	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (8388607, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+8388607	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (16777215, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+16777215	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (2147483647, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+2147483647	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4294967295, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+4294967295	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+9223372036854775807	NULL
+DROP TABLE t1;
+CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (18446744073709551615, null);
+INSERT INTO t1 (c2) VALUES ('innodb');
+Got one of the listed errors
+SELECT * FROM t1;
+c1	c2
+18446744073709551615	NULL
+DROP TABLE t1;

=== modified file 'mysql-test/r/innodb.result'
--- a/mysql-test/r/innodb.result	2008-05-14 09:24:14 +0000
+++ b/mysql-test/r/innodb.result	2008-06-12 00:08:07 +0000
@@ -1727,10 +1727,10 @@ Variable_name	Value
 Innodb_page_size	16384
 show status like "Innodb_rows_deleted";
 Variable_name	Value
-Innodb_rows_deleted	70
+Innodb_rows_deleted	71
 show status like "Innodb_rows_inserted";
 Variable_name	Value
-Innodb_rows_inserted	1082
+Innodb_rows_inserted	1084
 show status like "Innodb_rows_updated";
 Variable_name	Value
 Innodb_rows_updated	885
@@ -3218,3 +3218,54 @@ a
 2
 DROP TABLE t1;
 DROP TABLE t2;
+create table t1 (i int, j int) engine=innodb;
+insert into t1 (i, j) values (1, 1), (2, 2);
+update t1 set j = 2;
+affected rows: 1
+info: Rows matched: 2  Changed: 1  Warnings: 0
+drop table t1;
+create table t1 (id int) comment='this is a comment' engine=innodb;
+select table_comment, data_free > 0 as data_free_is_set
+from information_schema.tables
+where table_schema='test' and table_name = 't1';
+table_comment	data_free_is_set
+this is a comment	1
+drop table t1;
+CREATE TABLE t1 (
+c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+c2 VARCHAR(128) NOT NULL,
+PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
+CREATE TABLE t2 (
+c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+c2 INT(10) UNSIGNED DEFAULT NULL,
+PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+AUTO_INCREMENT
+200
+ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+AUTO_INCREMENT
+200
+DROP TABLE t2;
+DROP TABLE t1;
+CREATE TABLE t1 (c1 int default NULL,
+c2 int default NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+TRUNCATE TABLE t1;
+affected rows: 0
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+affected rows: 5
+info: Records: 5  Duplicates: 0  Warnings: 0
+TRUNCATE TABLE t1;
+affected rows: 0
+DROP TABLE t1;
+Variable_name	Value
+Handler_update	0
+Variable_name	Value
+Handler_delete	0
+Variable_name	Value
+Handler_update	1
+Variable_name	Value
+Handler_delete	1

=== added file 'mysql-test/r/innodb_bug34053.result'
--- a/mysql-test/r/innodb_bug34053.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_bug34053.result	2008-06-12 00:08:07 +0000
@@ -0,0 +1 @@
+SET storage_engine=InnoDB;

=== added file 'mysql-test/r/innodb_bug34300.result'
--- a/mysql-test/r/innodb_bug34300.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_bug34300.result	2008-06-12 00:08:07 +0000
@@ -0,0 +1,4 @@
+f4	f8
+xxx	zzz
+f4	f8
+xxx	zzz

=== added file 'mysql-test/r/innodb_bug35220.result'
--- a/mysql-test/r/innodb_bug35220.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/innodb_bug35220.result	2008-06-12 00:08:07 +0000
@@ -0,0 +1 @@
+SET storage_engine=InnoDB;

=== modified file 'mysql-test/r/merge-sync.result'
--- a/mysql-test/r/merge-sync.result	2008-04-29 09:22:04 +0000
+++ b/mysql-test/r/merge-sync.result	2008-06-26 15:52:25 +0000
@@ -1,6 +1,7 @@
 SET DEBUG_SYNC= 'RESET';
 drop table if exists t1,t2,t3,t4,t5,t6;
 drop database if exists mysqltest;
+SET GLOBAL concurrent_insert= 0;
 CREATE TABLE t1 (c1 INT) ENGINE= MyISAM;
 CREATE TABLE t2 (c1 INT) ENGINE= MRG_MYISAM UNION= (t1) INSERT_METHOD= LAST;
 connection con1
@@ -149,3 +150,4 @@ connection con1
 connection default;
 SET DEBUG_SYNC= 'RESET';
 DROP TABLE t1;
+SET GLOBAL concurrent_insert= DEFAULT;

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2007-11-27 17:23:39 +0000
+++ b/mysql-test/r/mysql.result	2008-06-20 19:24:46 +0000
@@ -38,6 +38,8 @@ t2
 t3
 Tables_in_test
 t1
+delimiter
+1
 _
 Test delimiter : from command line
 a

=== modified file 'mysql-test/r/partition_innodb.result'
--- a/mysql-test/r/partition_innodb.result	2008-03-27 19:02:15 +0000
+++ b/mysql-test/r/partition_innodb.result	2008-06-12 00:08:07 +0000
@@ -13,33 +13,33 @@ DROP TABLE t1;
 create table t1 (a int) engine=innodb partition by hash(a) ;
 show table status like 't1';
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	InnoDB	10	Compact	2	8192	16384	0	0	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
+t1	InnoDB	10	Compact	2	8192	16384	0	0	<datafree>	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
 drop table t1;
 create table t1 (a int)
 engine = innodb
 partition by key (a);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	InnoDB	10	Compact	2	8192	16384	0	0	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
+t1	InnoDB	10	Compact	2	8192	16384	0	0	<datafree>	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
 insert into t1 values (0), (1), (2), (3);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	InnoDB	10	Compact	4	4096	16384	0	0	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
+t1	InnoDB	10	Compact	4	4096	16384	0	0	<datafree>	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
 drop table t1;
 create table t1 (a int auto_increment primary key)
 engine = innodb
 partition by key (a);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	InnoDB	10	Compact	2	8192	16384	0	0	0	1	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
+t1	InnoDB	10	Compact	2	8192	16384	0	0	<datafree>	1	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
 insert into t1 values (NULL), (NULL), (NULL), (NULL);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	InnoDB	10	Compact	4	4096	16384	0	0	0	5	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
+t1	InnoDB	10	Compact	4	4096	16384	0	0	<datafree>	5	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
 insert into t1 values (NULL), (NULL), (NULL), (NULL);
 show table status;
 Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
-t1	InnoDB	10	Compact	8	2048	16384	0	0	0	9	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
+t1	InnoDB	10	Compact	8	2048	16384	0	0	<datafree>	9	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
 drop table t1;
 create table t1 (a int)
 partition by key (a)

=== modified file 'mysql-test/r/repair.result'
--- a/mysql-test/r/repair.result	2008-05-12 19:38:57 +0000
+++ b/mysql-test/r/repair.result	2008-06-18 03:30:29 +0000
@@ -130,7 +130,7 @@ test.t1	check	error	Table upgrade requir
 # REPAIR old table USE_FRM should fail
 REPAIR TABLE t1 USE_FRM;
 Table	Op	Msg_type	Msg_text
-t1	repair	error	Failed reparing incompatible .FRM file
+t1	repair	error	Failed repairing incompatible .frm file
 # Run REPAIR TABLE to upgrade .frm file
 REPAIR TABLE t1;
 Table	Op	Msg_type	Msg_text

=== modified file 'mysql-test/r/subselect.result'
--- a/mysql-test/r/subselect.result	2008-05-22 18:40:15 +0000
+++ b/mysql-test/r/subselect.result	2008-06-20 19:24:46 +0000
@@ -4593,6 +4593,13 @@ SELECT * FROM t1 WHERE _utf8'a' = ANY (S
 s1
 a
 DROP TABLE t1;
+CREATE TABLE t1(c int, KEY(c));
+CREATE TABLE t2(a int, b int);
+INSERT INTO t2 VALUES (1, 10), (2, NULL);
+INSERT INTO t1 VALUES (1), (3);
+SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
+a	b
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );

=== modified file 'mysql-test/r/subselect_no_mat.result'
--- a/mysql-test/r/subselect_no_mat.result	2008-05-22 18:40:15 +0000
+++ b/mysql-test/r/subselect_no_mat.result	2008-06-21 09:05:07 +0000
@@ -4597,6 +4597,13 @@ SELECT * FROM t1 WHERE _utf8'a' = ANY (S
 s1
 a
 DROP TABLE t1;
+CREATE TABLE t1(c int, KEY(c));
+CREATE TABLE t2(a int, b int);
+INSERT INTO t2 VALUES (1, 10), (2, NULL);
+INSERT INTO t1 VALUES (1), (3);
+SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
+a	b
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );

=== modified file 'mysql-test/r/subselect_no_opts.result'
--- a/mysql-test/r/subselect_no_opts.result	2008-05-22 18:40:15 +0000
+++ b/mysql-test/r/subselect_no_opts.result	2008-06-21 09:05:07 +0000
@@ -4597,6 +4597,13 @@ SELECT * FROM t1 WHERE _utf8'a' = ANY (S
 s1
 a
 DROP TABLE t1;
+CREATE TABLE t1(c int, KEY(c));
+CREATE TABLE t2(a int, b int);
+INSERT INTO t2 VALUES (1, 10), (2, NULL);
+INSERT INTO t1 VALUES (1), (3);
+SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
+a	b
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );

=== modified file 'mysql-test/r/subselect_no_semijoin.result'
--- a/mysql-test/r/subselect_no_semijoin.result	2008-05-22 18:40:15 +0000
+++ b/mysql-test/r/subselect_no_semijoin.result	2008-06-21 09:05:07 +0000
@@ -4597,6 +4597,13 @@ SELECT * FROM t1 WHERE _utf8'a' = ANY (S
 s1
 a
 DROP TABLE t1;
+CREATE TABLE t1(c int, KEY(c));
+CREATE TABLE t2(a int, b int);
+INSERT INTO t2 VALUES (1, 10), (2, NULL);
+INSERT INTO t1 VALUES (1), (3);
+SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
+a	b
+DROP TABLE t1,t2;
 CREATE TABLE t1( a INT );
 INSERT INTO t1 VALUES (1),(2);
 CREATE TABLE t2( a INT, b INT );

=== modified file 'mysql-test/suite/binlog/r/binlog_innodb.result'
--- a/mysql-test/suite/binlog/r/binlog_innodb.result	2008-05-15 20:56:38 +0000
+++ b/mysql-test/suite/binlog/r/binlog_innodb.result	2008-06-12 00:08:07 +0000
@@ -110,7 +110,6 @@ master-bin.000001	#	Table_map	#	#	table_
 master-bin.000001	#	Update_rows	#	#	table_id: #
 master-bin.000001	#	Update_rows	#	#	table_id: #
 master-bin.000001	#	Update_rows	#	#	table_id: #
-master-bin.000001	#	Update_rows	#	#	table_id: #
 master-bin.000001	#	Update_rows	#	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 master-bin.000001	#	Query	#	#	use `test`; BEGIN

=== added file 'mysql-test/suite/bugs/r/rpl_bug33029.result'
--- a/mysql-test/suite/bugs/r/rpl_bug33029.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/bugs/r/rpl_bug33029.result	2008-06-19 18:47:59 +0000
@@ -0,0 +1,15 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+create table `t1` (`id` int not null auto_increment primary key);
+create trigger `trg` before insert on `t1` for each row begin end;
+set @@global.debug="+d,simulate_bug33029";
+stop slave;
+start slave;
+insert into `t1` values ();
+select * from t1;
+id
+1

=== added file 'mysql-test/suite/bugs/t/rpl_bug33029.test'
--- a/mysql-test/suite/bugs/t/rpl_bug33029.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/bugs/t/rpl_bug33029.test	2008-06-19 18:47:59 +0000
@@ -0,0 +1,25 @@
+#
+# Bug #36443 Server crashes when executing insert when insert trigger on table
+#
+# Emulating the former bug#33029 situation to see that there is no crash anymore.
+# 
+
+
+source include/master-slave.inc;
+
+create table `t1` (`id` int not null auto_increment primary key);
+create trigger `trg` before insert on `t1` for each row begin end;
+
+sync_slave_with_master;
+set @@global.debug="+d,simulate_bug33029";
+
+stop slave;
+start slave;
+
+connection master;
+
+insert into `t1` values ();
+
+sync_slave_with_master;
+select * from t1;
+

=== modified file 'mysql-test/suite/rpl/t/disabled.def'
--- a/mysql-test/suite/rpl/t/disabled.def	2008-05-19 08:32:08 +0000
+++ b/mysql-test/suite/rpl/t/disabled.def	2008-06-20 19:24:46 +0000
@@ -29,4 +29,4 @@ rpl_log_pos                : Bug#8693 Te
 rpl_row_basic_7ndb         : BUG#33360 2007-12-19 mats rpl_ndb_idempotent fails due to null field for table on slave side
 rpl_redirect               : Failure is sporadic and and the test is superfluous (mats)
 rpl_innodb_bug28430        : Failure on Solaris Bug #36793
-
+rpl_server_id1             : Bug #36818 rpl_server_id1 fails expecting slave has stopped (azundris)

=== modified file 'mysql-test/t/backup.test'
--- a/mysql-test/t/backup.test	2008-06-12 19:54:19 +0000
+++ b/mysql-test/t/backup.test	2008-06-25 13:39:04 +0000
@@ -1,15 +1,14 @@
 --source include/have_innodb.inc
 --source include/not_embedded.inc
---source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+SET DEBUG_SYNC= 'RESET';
 
 connect (backup,localhost,root,,);
 connect (breakpoints,localhost,root,,);
 
 connection backup;
 
-# Setup the server to use the backup breakpoints
-SET GLOBAL debug="d,backup_debug:d,backup";
-
 --disable_warnings
 DROP DATABASE IF EXISTS db1;
 DROP DATABASE IF EXISTS db2;
@@ -105,31 +104,24 @@ UNLOCK TABLES;
 # in the process list and not a complete test of the locking
 # thread code.
 #
-connection breakpoints;
---echo breakpoints: Getting lock "locking_thread_added"
-SELECT get_lock("locking_thread_added", 100);
-
 connection backup;
+--echo backup: Activate synchronization points for BACKUP.
+SET DEBUG_SYNC= 'locking_thread_added SIGNAL bup_thread_added
+                 WAIT_FOR finish';
 --echo backup: Send the backup command.
 send BACKUP DATABASE db1,db2 TO 'test.ba';
 
 # get the lock and wait until lock is identified in process list
 connection breakpoints;
---echo breakpoints: Check for lock in process list.
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo breakpoints: Checking locks.
-let $wait_condition = SELECT count(*) = 1
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "default driver locking thread%";
---source include/wait_condition.inc
+--echo breakpoints: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_thread_added';
 
 --replace_column 1 #
 query_vertical SELECT id, command, state, info FROM INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%" OR info LIKE "default driver locking thread%";
 
---echo breakpoints: Release lock
-SELECT release_lock("locking_thread_added");
+--echo breakpoints: Sending finish signal to wake BACKUP.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 
 # reattach to backup job
 connection backup;
@@ -174,6 +166,7 @@ SHOW CREATE TABLE tasking;
 DROP DATABASE db1;
 DROP DATABASE db2;
 DROP DATABASE db3;
+SET DEBUG_SYNC= 'RESET';
 
 #
 # This test is for the default and snapshot online backup drivers

=== modified file 'mysql-test/t/backup_commit_blocker.test'
--- a/mysql-test/t/backup_commit_blocker.test	2007-12-20 20:32:22 +0000
+++ b/mysql-test/t/backup_commit_blocker.test	2008-06-25 13:39:04 +0000
@@ -27,24 +27,13 @@
 #
 # TODO : Add a native driver to the test when one becomes available
 #
-# We use a breakpoint named "backup_commit_blocker" which is placed
-# strategically in the code to allow the threads to pause at the 
-# corresponding location for those goals above.
-#
-# Notes
-#   You must use a dedicated connection for getting and releasing locks.
-# Do not issue a get_lock() or release_lock() in the same connection
-# (thread) as code that calls BACKUP_BREAKPOINT(). Using the same connection
-# to get/release locks and run code that issues BACKUP_BREAKPOINTs will result
-# in an assertion using DEBUG_ASSERT(thd->ull == NULL) from debug_sync_point()
-# in item_func.cc.
-#
 
 --source include/have_innodb.inc
---source include/have_debug.inc
+--source include/have_debug_sync.inc
 --source include/not_embedded.inc
 
 --disable_warnings
+SET DEBUG_SYNC= 'RESET';
 DROP DATABASE IF EXISTS bup_commit_blocker;
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/bup_commit_blocker.bak;
@@ -59,7 +48,7 @@ CREATE DATABASE bup_commit_blocker;
 # con2 - used for setting up transactions in progress
 # con3 - used for setting up transactions in commit
 # con4 - used for setting up transactions about to start
-# con5 - used for setting and releasing breakpoints
+# con5 - used to show status
 # con6 - used for setting up non-transactions in progress
 # con7 - used for setting up non-transactions about to start
 #
@@ -74,9 +63,6 @@ connect (con7,localhost,root,,);
 
 connection con1;
 
-# Setup the server to use the backup breakpoints
-SET GLOBAL debug="d,backup_debug:d,backup";
-
 #
 # Test 1 - transactional statements only
 #
@@ -96,16 +82,12 @@ SET GLOBAL debug="d,backup_debug:d,backu
 #     |       |      BEGIN      |        |
 #     |       |     INSERT t2   |        |
 #     |       |     INSERT t2   |        |
-#     |       |        |        |  lock("commit_blocker_step_1");
+#     |       |        |        |    show status
 #   BACKUP    |        |        |        |
-#     |       |        |        |  <wait for locks>
 #     |       |      COMMIT     |        |
-#     |       |        |        |  <wait for locks>
-#     |       |        |        |  lock("backup_commit_blocker");
-#     |       |        |        |  <wait for locks>
+#     |       |        |        |    show status
 #     |       |        |      BEGIN      |
-#     |       |        |        |  <wait for locks>
-#     |       |        |        |  <release locks>
+#     |       |        |        |    show status
 #     |    DELETE t1   |        |        |
 #     |     COMMIT     |        |        |
 #     |       |      <...>      |        |
@@ -163,14 +145,6 @@ BEGIN;
   INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 04 Some data to test");
   INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 05 Some data to test");
 
-connection con5;
-
-# Set the breakpoint for the commit blocker.
---echo con5: Getting lock on commit blocker.
-SELECT get_lock("commit_blocker_step_1", 0);
-
-# Start the backup and allow it to break on lock.
-
 connection con1;
 
 #
@@ -178,89 +152,73 @@ connection con1;
 # We stop (with the lock) the backup after the metadata but before the
 # commit blocker.
 #
+--echo con1: Activate synchronization points for BACKUP.
+SET DEBUG_SYNC= 'before_commit_block SIGNAL bup_commit_block
+                 WAIT_FOR bup_go_read_lock';
+SET DEBUG_SYNC= 'wait_lock_global_read_lock SIGNAL bup_read_lock';
+SET DEBUG_SYNC= 'before_backup_unblock_commit WAIT_FOR finish';
 --echo con1: Backing up database -- will block with lock
 send BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak";
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: commit_blocker_step_1"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--echo con5: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_commit_block';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 
 connection con3;
 
---echo con3: Starting commit -- will block with lock
+--echo con3: Activate synchronization points for COMMIT.
+SET DEBUG_SYNC= 'within_ha_commit_trans SIGNAL commit_read_locked
+                 WAIT_FOR commit_go_done';
+SET DEBUG_SYNC= 'after_commit SIGNAL commit_done
+                 WAIT_FOR finish';
+--echo con3: Starting commit -- will block on sync point
 send COMMIT;
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: commit_blocker_step_1"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "COMMIT%";
---source include/wait_condition.inc
-
+--echo con5: Wait for COMMIT to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR commit_read_locked';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 
-# Set the breakpoint for the commit blocker.
---echo con5: Getting lock on commit blocker.
-SELECT get_lock("backup_commit_blocker", 0);
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--echo con5: Let BACKUP run until the next sync point.
+SET DEBUG_SYNC= 'now SIGNAL bup_go_read_lock WAIT_FOR bup_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "COMMIT%";
---source include/wait_condition.inc
-
+--echo con5: Let COMMIT continue until end of statement.
+SET DEBUG_SYNC= 'now SIGNAL commit_go_done WAIT_FOR commit_done';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 
 connection con4;
 
---echo con4: Starting begin -- will block with lock
+--echo con4: Activate synchronization point for BEGIN.
+SET DEBUG_SYNC= 'before_begin_trans SIGNAL begin_starting
+                 WAIT_FOR finish';
+--echo con4: Starting begin -- will block on sync point
 --echo Assumption (c): TRX not started is not included in backup
 send BEGIN;
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BEGIN%";
---source include/wait_condition.inc
-
+--echo con5: Wait for BEGIN to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR begin_starting';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BEGIN%";
 
---echo con5: Releasing lock
-SELECT release_lock("backup_commit_blocker");
+--echo con5: Sending finish signal to wake them all.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 
-# Reconnect to con2, con3, and con4 and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 
@@ -269,18 +227,21 @@ connection con2;
 COMMIT;
 
 connection con3;
---echo con3: Completing transaction
+
+--echo con3: Fetch COMMIT result
 reap;
 
 connection con4;
+
+--echo con4: Fetch BEGIN result and completing transaction
 reap;
   UPDATE bup_commit_blocker.t3 SET col_a = "con4: 05 CHANGED" WHERE col_a LIKE '05%';
   UPDATE bup_commit_blocker.t3 SET col_a = "con4: 06 CHANGED" WHERE col_a LIKE '06%';
 COMMIT;
 
-# Reconnect to con1 and let backup finish.
-
 connection con1;
+
+--echo con1: Fetch BACKUP result
 --replace_column 1 #
 reap;
 
@@ -324,6 +285,7 @@ SELECT count(*) FROM bup_commit_blocker.
 DROP DATABASE bup_commit_blocker;
 
 remove_file $MYSQLTEST_VARDIR/master-data/bup_commit_blocker.bak;
+SET DEBUG_SYNC= 'RESET';
 
 #
 # Test 2 - non-transactional statements only
@@ -333,23 +295,29 @@ remove_file $MYSQLTEST_VARDIR/master-dat
 --echo Starting Test 2
 --echo 
 
+# Ingo: DELETE was disabled before converting the test from
+#       BACKUP_BREAKPOINT to DEBUG_SYNC. I left it disabled
+#       as an attempt to enable it made an infinite loop in
+#       write_table_data() in the loop:
+#    while (sch.prepare_count > 0)
+#    if (sch.step())
+#      goto error;
+#        sch.prepare_count did not change from being 1.
+#        When this is fixed, please remove this comment.
+
 #
 # Test 2 sequence diagram (not UML)
 #
 #   con1     con2     con3     con4     con5     con6       con7
 #  (setup)    |        |        |        |        |          |
 #     |       |        |        |        |        |          |
-#     |       |        |        |  lock("backup_commit_blocker");
-#     |       |        |        |        |    DELETE t4      |
-#     |       |        |        |  <wait for locks>          |
+#     |       |        |        |        |   #DELETE t4      |
+#     |       |        |        |   #show status  |          |
 #   BACKUP    |        |        |        |        |          |
-#     |       |        |        |  <wait for locks>          |
-#     |       |        |        |  lock("commit_blocker_step_4");
-#     |       |        |        |  <wait for locks>          |
-#     |       |        |        |    (results)    |          |
+#     |       |        |        |    show status  |          |
+#     |       |        |        |        |        |       (results)
 #     |       |        |        |        |        |       UPDATE t5
-#     |       |        |        |  <wait for locks>          |
-#     |       |        |        |  <release locks>|          |
+#     |       |        |        |    show status  |          |
 #   <...>     |        |        |        |      <...>      <...>
 # (results)   |        |        |        |        |          |
 #
@@ -372,49 +340,34 @@ INSERT INTO bup_commit_blocker.t5 VALUES
 #SELECT * FROM bup_commit_blocker.t4;
 SELECT * FROM bup_commit_blocker.t5;
 
-connection con5;
-
-# Set the breakpoint for the commit blocker.
---echo con5: Getting lock on commit blocker.
-SELECT get_lock("backup_commit_blocker", 0);
-
-connection con6;
-
+#connection con6;
+#
+#--echo con6: Activate synchronization point for DELETE.
+#SET DEBUG_SYNC= 'at_delete_end SIGNAL del_at_end WAIT_FOR finish';
 #--echo con6: Starting non-trx in progress -- will block with lock
 #--echo Assumption (d): non-TRX in progress is included in backup
 #send DELETE FROM bup_commit_blocker.t4 WHERE col_a <= 2;
-
-connection con5;
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-#let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-#                      FROM INFORMATION_SCHEMA.PROCESSLIST
-#                      WHERE info LIKE "DELETE%";
-#--source include/wait_condition.inc
+#
+#connection con5;
+#
+#--echo con5: Wait for DELETE to reach its synchronization point.
+#SET DEBUG_SYNC= 'now WAIT_FOR del_at_end';
+#SELECT state, info FROM
+#INFORMATION_SCHEMA.PROCESSLIST
+#WHERE info LIKE "DELETE%";
 
 connection con1;
 
+--echo con1: Activate synchronization point for BACKUP.
+SET DEBUG_SYNC= 'before_backup_data_unlock SIGNAL bup_data_unlock
+                 WAIT_FOR finish';
 --echo con1: Backing up database -- will block with lock
 send BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak";
 
 connection con5;
 
-# Set the breakpoint for the commit blocker.
-#
-# This allows the statement that was inprogress to finish and unblock the 
-# backup which is waiting on open_and_lock_tables.
-#
---echo con5: Getting lock on commit blocker.
-SELECT get_lock("commit_blocker_step_4", 0);
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: commit_blocker_step_4"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--echo con5: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_data_unlock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
@@ -425,41 +378,38 @@ connection con7;
 #SELECT * FROM bup_commit_blocker.t4;
 SELECT * FROM bup_commit_blocker.t5;
 
---echo con7: Starting non-trx about to start -- will block with lock
+--echo con7: Activate synchronization point for UPDATE.
+SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL upd_read_lock';
+--echo con7: Starting non-trx about to start
 --echo Assumption (e): non-TRX not started is not included in backup
 send UPDATE bup_commit_blocker.t5 SET col_a = 333 WHERE col_a = 30;
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "Waiting for release of readlock"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "UPDATE%";
---source include/wait_condition.inc
-
+--echo con5: Wait for UPDATE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR upd_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "UPDATE%";
 
---echo con5: Releasing locks
-SELECT release_lock("commit_blocker_step_4");
-SELECT release_lock("backup_commit_blocker");
+--echo con5: Sending finish signal to wake them all.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 
-# Reconnect to con6 and con7 and allow them to finish.
+# Reconnect to con6 and con7 and fetch their results.
 
-connection con6;
-
---echo con6: Completing statement
+#connection con6;
+#
+#--echo con6: Fetch DELETE result
 #reap;
 
 connection con7;
---echo con7: Completing statement
-reap;
 
-# Reconnect to con1 and let backup finish.
+--echo con7: Fetch UPDATE result
+reap;
 
 connection con1;
+
+--echo con1: Fetch BACKUP result
 --replace_column 1 #
 reap;
 
@@ -497,6 +447,7 @@ SELECT count(*) FROM bup_commit_blocker.
 DROP DATABASE bup_commit_blocker;
 
 remove_file $MYSQLTEST_VARDIR/master-data/bup_commit_blocker.bak;
+SET DEBUG_SYNC= 'RESET';
 
 #
 # Test 3 - mix of both transactional and non-transactional statements
@@ -517,20 +468,17 @@ remove_file $MYSQLTEST_VARDIR/master-dat
 #     |       |      BEGIN      |        |        |          |
 #     |       |     INSERT t2   |        |        |          |
 #     |       |     INSERT t2   |        |        |          |
-#     |       |        |        |  lock("commit_blocker_step_1");
 #   BACKUP    |        |        |        |        |          |
-#     |       |        |        |        |     INSERT t4     |
-#     |       |        |        |  <wait for locks>          |
+#     |       |        |        |        |    #INSERT t4     |
+#     |       |        |        |    show status  |          |
 #     |       |      COMMIT     |        |        |          |
-#     |       |        |        |  <wait for locks>          |
-#     |       |        |        |  lock("backup_commit_blocker");
-#     |       |        |        |  <wait for locks>          |
+#     |       |        |        |    show status  |          |
 #     |       |        |      BEGIN      |        |          |
-#     |       |        |        |  <wait for locks>          |
+#     |       |        |        |    show status  |          |
 #     |       |        |        |        |        |      (results)
 #     |       |        |        |        |        |       DELETE t5
-#     |       |        |        |  <wait for locks>          |
-#     |       |        |        |  <release locks>|          |
+#     |       |        |        |    show status  |          |
+#     |       |        |        |     wake all    |          |
 #     |    DELETE t1   |        |        |        |          |
 #     |     COMMIT     |        |        |        |          |
 #     |       |      <...>      |        |        |          |
@@ -598,14 +546,6 @@ BEGIN;
   INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 04 Some data to test");
   INSERT INTO bup_commit_blocker.t2 VALUES ("con3: 05 Some data to test");
 
-connection con5;
-
-# Set the breakpoint for the commit blocker.
---echo con5: Getting lock on commit blocker.
-SELECT get_lock("commit_blocker_step_1", 0);
-
-# Start the backup and allow it to break on lock.
-
 connection con1;
 
 #
@@ -613,137 +553,113 @@ connection con1;
 # We stop (with the lock) the backup after the metadata but before the
 # commit blocker.
 #
+--echo con1: Activate synchronization points for BACKUP.
+SET DEBUG_SYNC= 'before_commit_block SIGNAL bup_commit_block
+                 WAIT_FOR bup_go_read_lock';
+SET DEBUG_SYNC= 'wait_lock_global_read_lock SIGNAL bup_read_lock';
+SET DEBUG_SYNC= 'before_backup_unblock_commit SIGNAL bup_unblocking
+                 WAIT_FOR finish';
 --echo con1: Backing up database -- will block with lock
 send BACKUP DATABASE bup_commit_blocker TO "bup_commit_blocker.bak";
 
-connection con6;
-
+#connection con6;
+#
+#--echo con6: Activate synchronization point for INSERT.
+#SET DEBUG_SYNC= 'after_insert_locked_tables SIGNAL insert_table_locked
+#                 WAIT_FOR finish';
 #--echo con6: Starting non-trx in progress -- will block
 #--echo Assumption (d): non-TRX in progress is included in backup
 #send INSERT INTO bup_commit_blocker.t4 VALUES (31), (32), (33);
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: commit_blocker_step_1"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--echo con5: Wait for BACKUP to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR bup_commit_block';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 
-# Wait for lock to be acquired and execution to reach breakpoint
-#--echo con5: Checking lock
-#let $wait_condition = SELECT state = "debug_sync_point: commit_blocker_step_1"
-#                      FROM INFORMATION_SCHEMA.PROCESSLIST
-#                      WHERE info LIKE "INSERT INTO bup_commit_blocker.t4%";
-#--source include/wait_condition.inc
+#--echo con5: Wait for INSERT to reach its synchronization point.
+#SET DEBUG_SYNC= 'now WAIT_FOR insert_table_locked';
+#SELECT state, info FROM
+#INFORMATION_SCHEMA.PROCESSLIST
+#WHERE info LIKE "BACKUP DATABASE%";
 
 connection con3;
 
---echo con3: Starting commit -- will block with lock
+--echo con3: Activate synchronization points for COMMIT.
+SET DEBUG_SYNC= 'within_ha_commit_trans SIGNAL commit_read_locked
+                 WAIT_FOR commit_go_done';
+SET DEBUG_SYNC= 'after_commit WAIT_FOR finish';
+--echo con3: Starting commit -- will block on sync point
 send COMMIT;
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: commit_blocker_step_1"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "COMMIT%";
---source include/wait_condition.inc
-
+--echo con5: Wait for COMMIT to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR commit_read_locked';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
 
-# Set the breakpoint for the commit blocker.
---echo con5: Getting lock on commit blocker.
-SELECT get_lock("backup_commit_blocker", 0);
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--echo con5: Let BACKUP run until the next sync point.
+SET DEBUG_SYNC= 'now SIGNAL bup_go_read_lock WAIT_FOR bup_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BACKUP DATABASE%";
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "COMMIT%";
---source include/wait_condition.inc
-
+--echo con5: Let COMMIT continue until the sync point at its end.
+--echo con5: The completed COMMIT implicitly wakes BACKUP.
+--echo con5: So wait for BACKUP to reach the next synchronization point.
+SET DEBUG_SYNC= 'now SIGNAL commit_go_done WAIT_FOR bup_unblocking';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "COMMIT%";
+SELECT state, info FROM
+INFORMATION_SCHEMA.PROCESSLIST
+WHERE info LIKE "BACKUP DATABASE%";
 
 connection con4;
 
+--echo con4: Activate synchronization point for BEGIN.
+SET DEBUG_SYNC= 'before_begin_trans SIGNAL begin_starting
+                 WAIT_FOR finish';
 --echo con4: Starting begin -- will block with lock
 --echo Assumption (c): TRX not started is not included in backup
 send BEGIN;
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BEGIN%";
---source include/wait_condition.inc
-
+--echo con5: Wait for BEGIN to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR begin_starting';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "BEGIN%";
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-
-let $wait_condition = SELECT state = "debug_sync_point: backup_commit_blocker"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
-SELECT state, info FROM
-INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "BACKUP DATABASE%";
-
 connection con7;
 
 --echo con7: Show that the statement in progress has executed before backup.
 #SELECT * FROM bup_commit_blocker.t4;
 SELECT * FROM bup_commit_blocker.t5;
 
+--echo con7: Activate synchronization point for DELETE.
+SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL del_read_lock';
 --echo con7: Starting non-trx about to start -- will block with lock
 --echo Assumption (e): non-TRX not started is not included in backup
 send DELETE FROM bup_commit_blocker.t5 WHERE col_a = 50;
 
 connection con5;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking lock
-let $wait_condition = SELECT state = "Waiting for release of readlock"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DELETE%";
---source include/wait_condition.inc
-
+--echo con5: Wait for DELETE to reach its synchronization point.
+SET DEBUG_SYNC= 'now WAIT_FOR del_read_lock';
 SELECT state, info FROM
 INFORMATION_SCHEMA.PROCESSLIST
 WHERE info LIKE "DELETE%";
 
---echo con5: Releasing lock
-SELECT release_lock("backup_commit_blocker");
+--echo con5: Sending finish signal to wake them all.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 
-# Reconnect to con2, con3, con4, con6, and con7 and allow them to finish.
+# Reconnect to con2, con3, con4, con6, and con7 and fetch their results.
 
 connection con2;
 
@@ -752,10 +668,13 @@ connection con2;
 COMMIT;
 
 connection con3;
---echo con3: Completing transaction
+
+--echo con3: Fetch COMMIT result
 reap;
 
 connection con4;
+
+--echo con4: Fetch BEGIN result and completing transaction
 reap;
   UPDATE bup_commit_blocker.t3 SET col_a = "con4: 05 CHANGED" WHERE col_a LIKE '05%';
   UPDATE bup_commit_blocker.t3 SET col_a = "con4: 06 CHANGED" WHERE col_a LIKE '06%';
@@ -763,17 +682,17 @@ COMMIT;
 
 connection con6;
 
-#--echo con6: Completing statement
+#--echo con6: Fetch INSERT result
 #reap;
 
 connection con7;
 
---echo con7: Completing statement
+--echo con7: Fetch DELETE result
 reap;
 
-# Reconnect to con1 and let backup finish.
-
 connection con1;
+
+--echo con1: Fetch BACKUP result
 --replace_column 1 #
 reap;
 
@@ -829,5 +748,5 @@ SELECT count(*) FROM bup_commit_blocker.
 DROP DATABASE bup_commit_blocker;
 
 remove_file $MYSQLTEST_VARDIR/master-data/bup_commit_blocker.bak;
-
+SET DEBUG_SYNC= 'RESET';
 

=== added file 'mysql-test/t/backup_compression.test'
--- a/mysql-test/t/backup_compression.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_compression.test	2008-06-25 13:30:04 +0000
@@ -0,0 +1,24 @@
+--source include/not_embedded.inc
+--source include/have_compress.inc
+
+CREATE DATABASE db1;
+
+CREATE TABLE db1.t1(a INT);
+replace_column 1 #;
+BACKUP DATABASE db1 TO 'db1.bak.gz' WITH COMPRESSION;
+
+CREATE TABLE db1.t2(a INT);
+replace_column 1 #;
+BACKUP DATABASE db1 TO 'db2.bak.gz' WITH COMPRESSION COMPRESSION_ALGORITHM=gzip;
+
+replace_column 1 #;
+RESTORE FROM 'db1.bak.gz';
+SHOW TABLES FROM db1;
+
+replace_column 1 #;
+RESTORE FROM 'db2.bak.gz';
+SHOW TABLES FROM db1;
+
+DROP DATABASE db1;
+--remove_file $MYSQLTEST_VARDIR/master-data/db1.bak.gz
+--remove_file $MYSQLTEST_VARDIR/master-data/db2.bak.gz

=== modified file 'mysql-test/t/backup_ddl_blocker.test'
--- a/mysql-test/t/backup_ddl_blocker.test	2008-02-14 20:57:18 +0000
+++ b/mysql-test/t/backup_ddl_blocker.test	2008-06-25 13:39:04 +0000
@@ -1,5 +1,5 @@
 #
-# This test is for the DDL blocker
+# 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.
 #
@@ -42,22 +42,19 @@
 #
 # TODO : Add a native driver to the test when one becomes available
 #
-# Notes
-#   You must use a dedicated connection for getting and releasing locks.
-# Do not issue a get_lock() or release_lock() in the same connection
-# (thread) as code that calls BACKUP_BREAKPOINT(). Using the same connection
-# to get/release locks and run code that issues BACKUP_BREAKPOINTs will result
-# in an assertion using DEBUG_ASSERT(thd->ull == NULL) from debug_sync_point()
-# in item_func.cc.
-#
 
 --source include/have_innodb.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
+#
 
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker_orig.bak;
@@ -69,7 +66,7 @@
 #
 # 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 for setting and releasing breakpoints
+# con6       used to show status/processlist 
 #
 
 connect (con1,localhost,root,,);
@@ -81,9 +78,6 @@ connect (con6,localhost,root,,);
 
 connection con1;
 
-# Setup the server to use the backup breakpoints
-SET GLOBAL debug="d,backup_debug:d,backup";
-
 #
 # Backup test sequence diagram (not UML)
 #
@@ -96,27 +90,30 @@ SET GLOBAL debug="d,backup_debug:d,backu
 # when the backup or restore is already running. Tests results
 # show the realization of the assumptions above.
 #
-#     con1      con2     con3     con4     con6
+#     con1      con2     con3     con4     con5     con6
 #    (setup)     |        |        |        |        |
 #       |        |        |        |        |        |
-#       |        |        |        |        | lock("DDL_in_progress");
+#       |        |        |        |        |        |
 #       |   statememt 1   |        |        |        |
 #       |        |   statement 2   |        |        |
-#       |        |        |        |        |  <wait for locks>
+#       |        |        |        |        |    show status
 # BACKUP/RESTORE |        |        |        |        |
-#       |        |        |        |        | lock("DDL_blocked");
-#       |        |        |        |        | <wait for locks>
+#       |        |        |        |        |        |
+#       |        |        |        |        |        |
 #       |      <...>    <...>      |        |        |
 #       |        |        |   statement 3   |        |
 #       |        |        |        |   statement 4   |
-#       |        |        |        |        | <wait for DDL blocker>
-#       |        |        |        |        |  <release locks>
+#       |        |        |        |        |    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.
 
 
 ##############################################################
@@ -129,19 +126,19 @@ SET GLOBAL debug="d,backup_debug:d,backu
 --source include/backup_ddl_create_data.inc
 DROP TABLE bup_ddl_blocker.t1, bup_ddl_blocker.t3;
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -149,85 +146,61 @@ send ALTER TABLE bup_ddl_blocker.t2 ADD 
 
 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;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "BACKUP DATABASE%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -245,7 +218,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -298,19 +271,19 @@ DROP TABLE bup_ddl_blocker.t1, bup_ddl_b
 --replace_column 1 #
 BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -318,85 +291,61 @@ send ALTER TABLE bup_ddl_blocker.t2 ADD 
 
 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";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "RESTORE FROM%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -414,15 +363,17 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# 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.
@@ -434,6 +385,9 @@ DESCRIBE bup_ddl_blocker.t2;
 DESCRIBE bup_ddl_blocker.t3;
 DESCRIBE bup_ddl_blocker.t4;
 
+# Cleanup
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
+
 
 
 ##############################################################
@@ -445,19 +399,19 @@ DESCRIBE bup_ddl_blocker.t4;
 # Create data for this test and tailor it to the test.
 --source include/backup_ddl_create_data.inc
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -465,87 +419,61 @@ send REPAIR TABLE bup_ddl_blocker.t2;
 
 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
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "BACKUP DATABASE%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t2%";
---source include/wait_condition.inc
-
+  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%";
-
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -563,7 +491,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -610,19 +538,19 @@ SHOW TABLES;
 --replace_column 1 #
 BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -630,85 +558,61 @@ send REPAIR TABLE bup_ddl_blocker.t2;
 
 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";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "RESTORE FROM%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RENAME TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "REPAIR TABLE bup_ddl_blocker.t4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -726,7 +630,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -742,7 +646,8 @@ reap;
 use bup_ddl_blocker;
 SHOW TABLES;
 
-
+# Cleanup
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 
 
 
@@ -755,19 +660,19 @@ SHOW TABLES;
 # Create data for this test and tailor it to the test.
 --source include/backup_ddl_create_data.inc
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -775,86 +680,61 @@ send DROP TABLE bup_ddl_blocker.t2;
 
 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
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 send BACKUP DATABASE bup_ddl_blocker TO "bup_ddl_blocker.bak";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "BACKUP DATABASE%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP TABLE bup_ddl_blocker.t2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -872,7 +752,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -917,19 +797,19 @@ SHOW TABLES;
 --replace_column 1 #
 BACKUP DATABASE bup_ddl_blocker to 'bup_ddl_blocker_orig.bak';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -937,85 +817,61 @@ send DROP TABLE bup_ddl_blocker.t2;
 
 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";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "RESTORE FROM%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP TABLE bup_ddl_blocker.t2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "OPTIMIZE TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "DROP TABLE bup_ddl_blocker.t4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -1033,7 +889,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -1049,7 +905,8 @@ reap;
 use bup_ddl_blocker;
 SHOW TABLES;
 
-
+# Cleanup
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 
 
 
@@ -1088,19 +945,19 @@ INSERT INTO bup_ddl_blocker_4.t1 VALUES 
 --echo con1: Show that the new data doesn't exist before backup.
 SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -1108,86 +965,61 @@ send DROP DATABASE bup_ddl_blocker_2;
 
 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
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 send BACKUP DATABASE * TO "bup_ddl_blocker.bak";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "BACKUP DATABASE%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP DATABASE bup_ddl_blocker_2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -1205,7 +1037,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -1279,19 +1111,19 @@ SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 --replace_column 1 #
 BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -1299,85 +1131,61 @@ send DROP DATABASE bup_ddl_blocker_2;
 
 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";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "RESTORE FROM%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_1%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP DATABASE bup_ddl_blocker_2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE DATABASE bup_ddl_blocker_3%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "DROP DATABASE bup_ddl_blocker_4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -1395,7 +1203,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -1410,7 +1218,8 @@ reap;
 --echo con1: Database bup_ddl_blocker_4 should not be in restored data.
 SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 
-
+# Cleanup
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 
 
 
@@ -1450,19 +1259,19 @@ INSERT INTO bup_ddl_blocker_4.t1 VALUES 
 --echo con1: Show that the new data doesn't exist before backup.
 SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -1470,85 +1279,61 @@ send ALTER DATABASE bup_ddl_blocker_2 CH
 
 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
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 send BACKUP DATABASE * TO "bup_ddl_blocker.bak";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "BACKUP DATABASE%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
---source include/wait_condition.inc
+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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -1566,7 +1351,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -1613,7 +1398,6 @@ SELECT * FROM bup_ddl_blocker_4.t1;
 DROP DATABASE bup_ddl_blocker_2;
 DROP DATABASE bup_ddl_blocker_4;
 
-
 ##############################################################
 --echo 
 --echo Starting Test 5 - Restore
@@ -1655,19 +1439,19 @@ SHOW DATABASES LIKE 'bup_ddl_blocker_%';
 --replace_column 1 #
 BACKUP DATABASE bup_ddl_blocker_2, bup_ddl_blocker_4 to 'bup_ddl_blocker_orig.bak';
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -1675,85 +1459,61 @@ send ALTER DATABASE bup_ddl_blocker_2 CH
 
 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";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "RESTORE FROM%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_2%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_2%";
---source include/wait_condition.inc
-
+  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%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "TRUNCATE TABLE bup_ddl_blocker_4%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
---source include/wait_condition.inc
-
+  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%";
+  WHERE info LIKE "ALTER DATABASE bup_ddl_blocker_4%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -1771,7 +1531,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -1796,7 +1556,8 @@ SELECT * FROM bup_ddl_blocker_4.t1;
 DROP DATABASE bup_ddl_blocker_2;
 DROP DATABASE bup_ddl_blocker_4;
 
-
+# Cleanup
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 
 
 
@@ -1848,19 +1609,19 @@ INSERT INTO bup_ddl_blocker_4.t1 VALUES 
 
 CREATE INDEX 4t1col_b ON bup_ddl_blocker_4.t1 (col_b); 
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -1868,7 +1629,11 @@ send DROP INDEX 2t1col_b ON bup_ddl_bloc
 
 connection con1;
 
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
+--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
@@ -1876,80 +1641,51 @@ send BACKUP DATABASE bup_ddl_blocker_1, 
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE INDEX 1t1col_b%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "BACKUP DATABASE%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE INDEX 1t1col_b%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP INDEX 2t1col_b%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "CREATE INDEX 1t1col_b%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 2t1col_b%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE INDEX 3t1col_b%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP INDEX 4t1col_b%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "CREATE INDEX 3t1col_b%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 4t1col_b%";
+  WHERE info LIKE "DROP INDEX 4t1col_b%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -1967,7 +1703,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -2017,6 +1753,7 @@ DROP DATABASE bup_ddl_blocker_4;
 --echo Starting Test 6 - Restore
 --echo 
 ##############################################################
+
 --disable_warnings
 DROP DATABASE IF EXISTS bup_ddl_blocker_1;
 DROP DATABASE IF EXISTS bup_ddl_blocker_2;
@@ -2066,19 +1803,19 @@ BACKUP DATABASE bup_ddl_blocker_1, bup_d
                 bup_ddl_blocker_3, bup_ddl_blocker_4
                 TO "bup_ddl_blocker_orig.bak";
 
-connection con6;
-
-# Set the breakpoint for DDL in progress.
---echo con6: Getting lock on DDL in progress.
-SELECT get_lock("DDL_in_progress", 0);
-
 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;
 
@@ -2086,85 +1823,61 @@ send DROP INDEX 2t1col_b ON bup_ddl_bloc
 
 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";
 
 connection con6;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE INDEX 1t1col_b%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "RESTORE FROM%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "CREATE INDEX 1t1col_b%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_in_progress"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DROP INDEX 2t1col_b%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "CREATE INDEX 1t1col_b%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 2t1col_b%";
-
-# Now set the breakpoint for DDL blocker.
-# This releases lock on DDL_in_progress stopping all DDLs.
---echo con6: Getting lock on DDL blocker.
-SELECT get_lock("DDL_blocked", 0);
-
-connection con6;
-
---echo con6: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
+  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%";
+  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;
 
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "CREATE INDEX 3t1col_b%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "DDL blocker: DDL is blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "DDROP INDEX 4t1col_b%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "CREATE INDEX 3t1col_b%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "DROP INDEX 4t1col_b%";
+  WHERE info LIKE "DROP INDEX 4t1col_b%";
 
---echo con6: Releasing lock
-SELECT release_lock("DDL_blocked");
+--echo con6: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown2';
 
-# Reconnect to connections and allow them to finish.
+# Reconnect to connections and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -2182,7 +1895,7 @@ connection con5;
 --echo con5: Completing DDL
 reap;
 
-# Reconnect to con1 and let backup finish.
+# Reconnect to con1 and fetch its result.
 
 connection con1;
 --replace_column 1 #
@@ -2207,7 +1920,8 @@ DROP DATABASE bup_ddl_blocker_2;
 DROP DATABASE bup_ddl_blocker_3;
 DROP DATABASE bup_ddl_blocker_4;
 
-
+# Cleanup
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
 
 
 
@@ -2265,59 +1979,46 @@ SELECT * FROM bup_ddl_blocker.t1;
 SELECT * FROM test.t2;
 SELECT * FROM bup_ddl_blocker.t3;
 
-connection con5;
-
-# Set the breakpoint for DDL in progress.
---echo con5: Getting lock on DDL in progress.
-SELECT get_lock("DDL_not_blocked", 0);
-
 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;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con5: Checking locks
-let $wait_condition = SELECT state = "debug_sync_point: DDL_not_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t1%";
---source include/wait_condition.inc
-
+--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%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_not_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE test.t2%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t1%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE test.t2%";
-
-let $wait_condition = SELECT state = "debug_sync_point: DDL_not_blocked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t3%";
---source include/wait_condition.inc
-
+  WHERE info LIKE "ALTER TABLE test.t2%";
 SELECT state, info FROM INFORMATION_SCHEMA.PROCESSLIST
-WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t3%";
+  WHERE info LIKE "ALTER TABLE bup_ddl_blocker.t3%";
 
---echo con5: Releasing lock
-SELECT release_lock("DDL_not_blocked");
+--echo con5: Resume all.
+SET DEBUG_SYNC= 'now SIGNAL status_shown';
 
-# Reconnect to con2, con3, and con4 and allow them to finish.
+# Reconnect to con2, con3, and con4 and fetch their results.
 
 connection con2;
 --echo con2: Completing DDL
@@ -2362,21 +2063,26 @@ WHERE TABLE_NAME = 't3' AND TABLE_SCHEMA
 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.
-#
+# 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 $MYSQLTEST_VARDIR/master-data/test/db.opt
 --remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker_orig.bak
---remove_file $MYSQLTEST_VARDIR/master-data/bup_ddl_blocker.bak
-
-
 
+connection default;
+disconnect con1;
+disconnect con2;
+disconnect con3;
+disconnect con4;
+disconnect con5;
+disconnect con6;
 
+SET DEBUG_SYNC= 'reset';
 

=== added file 'mysql-test/t/backup_many_dbs.test'
--- a/mysql-test/t/backup_many_dbs.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_many_dbs.test	2008-06-25 13:39:04 +0000
@@ -0,0 +1,131 @@
+###########################################################################
+# Regression test for bug#33568
+###############################################################################
+--source include/not_embedded.inc
+
+##############################################################
+--echo Starting regression test for bug 33568
+##############################################################
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_manydbs.bak
+
+--disable_warnings
+DROP DATABASE IF EXISTS db1;
+DROP DATABASE IF EXISTS db2;
+DROP DATABASE IF EXISTS db3;
+DROP DATABASE IF EXISTS db4;
+DROP DATABASE IF EXISTS db5;
+DROP DATABASE IF EXISTS db6;
+DROP DATABASE IF EXISTS db7;
+DROP DATABASE IF EXISTS db8;
+DROP DATABASE IF EXISTS db9;
+DROP DATABASE IF EXISTS db10;
+DROP DATABASE IF EXISTS db11;
+DROP DATABASE IF EXISTS db12;
+DROP DATABASE IF EXISTS db13;
+DROP DATABASE IF EXISTS db14;
+DROP DATABASE IF EXISTS db15;
+DROP DATABASE IF EXISTS db16;
+DROP DATABASE IF EXISTS db17;
+DROP DATABASE IF EXISTS db18;
+--enable_warnings
+
+##############################################################
+--echo Creating 18 databases
+##############################################################
+
+# Create 18 databases. This is the threashold for provoking the bug (16
+# dbs works, nbr 17 overruns memory, nbr 18 crashes server due to
+# overrun memory
+
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+CREATE DATABASE db3;
+CREATE DATABASE db4;
+CREATE DATABASE db5;
+CREATE DATABASE db6;
+CREATE DATABASE db7;
+CREATE DATABASE db8;
+CREATE DATABASE db9;
+CREATE DATABASE db10;
+CREATE DATABASE db11;
+CREATE DATABASE db12;
+CREATE DATABASE db13;
+CREATE DATABASE db14;
+CREATE DATABASE db15;
+CREATE DATABASE db16;
+CREATE DATABASE db17;
+CREATE DATABASE db18;
+
+
+##############################################################
+--echo Backing up the databases
+##############################################################
+
+#Backup and restore data.
+replace_column 1 #;
+BACKUP DATABASE db1, db2, db3, db4, db5, db6, db7, db8, db9, db10, db11, db12, db13, db14, db15, db16, db17, db18  
+TO 'bup_manydbs.bak';
+
+##############################################################
+--echo Dropping the databases
+##############################################################
+DROP DATABASE db1;
+DROP DATABASE db2;
+DROP DATABASE db3;
+DROP DATABASE db4;
+DROP DATABASE db5;
+DROP DATABASE db6;
+DROP DATABASE db7;
+DROP DATABASE db8;
+DROP DATABASE db9;
+DROP DATABASE db10;
+DROP DATABASE db11;
+DROP DATABASE db12;
+DROP DATABASE db13;
+DROP DATABASE db14;
+DROP DATABASE db15;
+DROP DATABASE db16;
+DROP DATABASE db17;
+DROP DATABASE db18;
+
+##############################################################
+--echo Restoring databases
+##############################################################
+
+replace_column 1 #;
+RESTORE FROM 'bup_manydbs.bak';
+
+##############################################################
+--echo Checking that all dbs are there
+##############################################################
+
+SHOW DATABASES LIKE 'db%'; 
+
+##############################################################
+--echo Cleaning up
+##############################################################
+
+DROP DATABASE db1;
+DROP DATABASE db2;
+DROP DATABASE db3;
+DROP DATABASE db4;
+DROP DATABASE db5;
+DROP DATABASE db6;
+DROP DATABASE db7;
+DROP DATABASE db8;
+DROP DATABASE db9;
+DROP DATABASE db10;
+DROP DATABASE db11;
+DROP DATABASE db12;
+DROP DATABASE db13;
+DROP DATABASE db14;
+DROP DATABASE db15;
+DROP DATABASE db16;
+DROP DATABASE db17;
+DROP DATABASE db18;
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_manydbs.bak
+

=== added file 'mysql-test/t/backup_multi_blocks.test'
--- a/mysql-test/t/backup_multi_blocks.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_multi_blocks.test	2008-06-26 16:20:30 +0000
@@ -0,0 +1,44 @@
+--source include/not_embedded.inc
+
+# Test that it is possible to restore backups of tables with more than
+# a single block of data.
+
+--disable_warnings
+DROP DATABASE IF EXISTS mysqltest;
+--enable_warnings
+
+--echo Creating database and tables ...
+CREATE DATABASE mysqltest;
+USE mysqltest;
+
+CREATE TABLE t1 (a LONGTEXT) ENGINE=MYISAM;
+
+--echo Inserting data ...
+USE mysqltest;
+INSERT INTO t1 VALUES ("text");
+LET $1=13;
+WHILE ($1)
+{
+  UPDATE t1 SET a=CONCAT(a,a);
+  DEC $1;
+}
+SELECT LENGTH(a) FROM t1;
+
+--echo Performing backup ...
+--replace_column 1 #;
+BACKUP DATABASE mysqltest TO 'test.ba';
+
+DROP DATABASE mysqltest;
+
+# Perform restore.
+--echo Performing restore ...
+--replace_column 1 #;
+RESTORE FROM 'test.ba';
+
+--echo Checking contents of restore ...
+SELECT LENGTH(a) FROM t1;
+CHECKSUM TABLE t1;
+
+--echo Clean-up
+DROP DATABASE mysqltest;
+--remove_file $MYSQLTEST_VARDIR/master-data/test.ba

=== modified file 'mysql-test/t/backup_no_be.test'
--- a/mysql-test/t/backup_no_be.test	2008-05-10 08:42:49 +0000
+++ b/mysql-test/t/backup_no_be.test	2008-06-25 13:39:04 +0000
@@ -67,7 +67,7 @@ SELECT @@debug;
 --remove_file $MYSQLTEST_VARDIR/master-data/db1.bak
 --replace_column 1 #
 BACKUP DATABASE db1 TO 'db1.bak';
---enable_warings
+--enable_warnings
 
 # Don't show warning message code
 --replace_column 2 #

=== added file 'mysql-test/t/backup_procedures.test'
--- a/mysql-test/t/backup_procedures.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_procedures.test	2008-06-25 12:40:06 +0000
@@ -0,0 +1,57 @@
+###########################################################################
+# Purpose: Regression test for 34868 - "Backup: restore failure if two
+#          procedures". Test added because the bug has been fixed by 
+#          an unknown patch.
+###############################################################################
+--source include/not_embedded.inc
+
+--echo
+--echo Starting regression test for 34868 - Backup: restore failure if two procedures
+
+
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_proc.bak
+
+--echo
+--echo Create database and procedures
+--disable_warnings
+DROP DATABASE IF EXISTS bup_proc;
+--enable_warnings
+
+CREATE DATABASE bup_proc;
+USE bup_proc;
+
+CREATE PROCEDURE p1() SET @a=5;
+CREATE PROCEDURE p2() SET @a=100;
+
+--echo
+--echo Check that procedures are there before the backup
+
+CALL p1();
+SELECT @a;
+CALL p2();
+SELECT @a;
+
+--echo
+--echo Backup and restore
+
+--replace_column 1 #
+BACKUP DATABASE bup_proc to 'bup_proc.bak';
+DROP DATABASE bup_proc;
+--replace_column 1 #
+RESTORE FROM 'bup_proc.bak';
+
+--echo
+--echo Check that procedures are there after the restore
+
+CALL p1();
+SELECT @a;
+CALL p2();
+SELECT @a;
+
+--echo
+--echo Cleaning up
+
+DROP DATABASE bup_proc;
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/bup_proc.bak

=== modified file 'mysql-test/t/backup_progress.test'
--- a/mysql-test/t/backup_progress.test	2008-03-20 14:53:16 +0000
+++ b/mysql-test/t/backup_progress.test	2008-06-25 13:39:04 +0000
@@ -4,11 +4,15 @@
 #
 
 --source include/have_log_bin.inc
---source include/have_debug.inc
+--source include/have_debug_sync.inc
 --source include/have_innodb.inc
 --source include/not_embedded.inc
 
+#
+# Preparative cleanup.
+#
 --disable_warnings
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE IF EXISTS backup_progress;
 DROP TABLE IF EXISTS backup_progress.t1_res;
 --error 0,1
@@ -18,9 +22,6 @@ DROP TABLE IF EXISTS backup_progress.t1_
 connect (con1,localhost,root,,);
 connect (con2,localhost,root,,);
 
-# Setup the server to use the backup breakpoints
-SET GLOBAL debug="d,backup_debug:d,backup";
-
 #
 # Test 1 - Check output of backup.
 #
@@ -58,96 +59,47 @@ INSERT INTO backup_progress.t3 VALUES ("
 
 --echo Do backup of database
 
-SELECT get_lock("bp_starting_state", 0);
-
 connection con2;
 
+--echo con2: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_log_init     SIGNAL started   WAIT_FOR do_run';
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL phase1    WAIT_FOR backup';
+SET DEBUG_SYNC= 'after_backup_validated    SIGNAL validated WAIT_FOR do_phase2';
+SET DEBUG_SYNC= 'after_backup_binlog       SIGNAL phase2    WAIT_FOR finish';
+
 --echo con2: Send backup command.
 send BACKUP DATABASE backup_progress to 'backup_progress_orig.bak';
 
 connection con1;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con1: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: bp_starting_state"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE %";
---source include/wait_condition.inc
-
-# Wait for row to be written to progress table.
---echo con1: Checking progress.
-let $wait_condition = SELECT backup_state = "starting"
-                      FROM mysql.online_backup
-                      WHERE command LIKE "BACKUP DATABASE backup_progress%";
---source include/wait_condition.inc
+--echo con1: Wait for the backup to be started.
+SET DEBUG_SYNC= 'now WAIT_FOR started';
 
---echo: Display progress
+--echo con1: Display progress
 SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "BACKUP DATABASE backup_progress%";
 INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 
---echo con1: Advance the lock.
-SELECT get_lock("bp_running_state", 0);
+--echo con1: Let backup step to running state.
+SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR phase1';
+
+--echo con1: Display progress
+SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
+
+--echo con1: Let backup do the backup phase1.
+SET DEBUG_SYNC= 'now SIGNAL backup WAIT_FOR validated';
+
+--echo con1: Display progress
+SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con1: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: bp_running_state"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE %";
---source include/wait_condition.inc
-
-# Wait for row to be written to progress table.
---echo con1: Checking progress.
-let $wait_condition = SELECT backup_state = "running"
-                      FROM mysql.online_backup
-                      WHERE command LIKE "BACKUP DATABASE backup_progress%";
---source include/wait_condition.inc
-
---echo: Display progress
-SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
-
---echo con1: Advance the lock.
-SELECT get_lock("bp_vp_state", 0);
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con1: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: bp_vp_state"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE %";
---source include/wait_condition.inc
-
-# Wait for row to be written to progress table.
---echo con1: Checking progress.
-let $wait_condition = SELECT backup_state = "validity point"
-                      FROM mysql.online_backup
-                      WHERE command LIKE "BACKUP DATABASE backup_progress%";
---source include/wait_condition.inc
-
---echo: Display progress
-SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
-
---echo con1: Advance the lock.
-SELECT get_lock("bp_running_state", 0);
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con1: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: bp_running_state"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE %";
---source include/wait_condition.inc
-
-# Wait for row to be written to progress table.
---echo con1: Checking progress.
-let $wait_condition = SELECT backup_state = "running"
-                      FROM mysql.online_backup
-                      WHERE command LIKE "BACKUP DATABASE backup_progress%";
---source include/wait_condition.inc
+--echo con1: Let backup do the backup phase2.
+SET DEBUG_SYNC= 'now SIGNAL do_phase2 WAIT_FOR phase2';
 
---echo: Display progress
+--echo con1: Display progress
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 
---echo con1: Advance the lock.
-SELECT release_lock("bp_running_state");
+--echo con1: Let backup finish.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 
 connection con2;
 --echo con2: Finish backup command
@@ -164,59 +116,36 @@ connection con1;
 
 --echo Do restore of database
 
-SELECT get_lock("bp_starting_state", 0);
-
 connection con2;
 
 DELETE FROM backup_progress.t1_res;
+ 
+--echo con2: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_log_init      SIGNAL started WAIT_FOR do_run';
+SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR finish';
 
 --echo con2: Send restore command.
 send RESTORE FROM 'backup_progress_orig.bak';
 
 connection con1;
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con1: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: bp_starting_state"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
---source include/wait_condition.inc
-
-# Wait for row to be written to progress table.
---echo con1: Checking progress.
-let $wait_condition = SELECT backup_state = "starting"
-                      FROM mysql.online_backup
-                      WHERE command LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
---source include/wait_condition.inc
+--echo con1: Wait for the restore to be started.
+SET DEBUG_SYNC= 'now WAIT_FOR started';
 
---echo: Display progress
+--echo con1: Display progress
 select * from backup_progress.t1_res;
 SELECT MAX(backup_id) INTO @bup_id FROM mysql.online_backup WHERE command LIKE "RESTORE FROM%";
 INSERT INTO backup_progress.t1_res (id) VALUES (@bup_id);
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 
---echo con1: Advance the lock.
-SELECT get_lock("bp_running_state", 0);
+--echo con1: Let restore step to running state.
+SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR running';
 
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con1: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: bp_running_state"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
---source include/wait_condition.inc
-
-# Wait for row to be written to progress table.
---echo con1: Checking progress.
-let $wait_condition = SELECT backup_state = "running"
-                      FROM mysql.online_backup
-                      WHERE command LIKE "RESTORE FROM 'backup_progress_orig.bak'%";
---source include/wait_condition.inc
-
---echo: Display progress
+--echo con1: Display progress
 SELECT backup_state FROM mysql.online_backup AS ob JOIN backup_progress.t1_res as t1 ON ob.backup_id = t1.id;
 
---echo con1: Advance the lock.
-SELECT release_lock("bp_running_state");
+--echo con1: Let restore do its job and finish.
+SET DEBUG_SYNC= 'now SIGNAL finish';
 
 connection con2;
 --echo con2: Finish restore command
@@ -234,6 +163,10 @@ SELECT obp.* FROM mysql.online_backup_pr
 
 connection con1;
 
+#
+# Cleanup.
+#
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE backup_progress;
 --remove_file $MYSQLTEST_VARDIR/master-data/backup_progress_orig.bak
 

=== modified file 'mysql-test/t/backup_security.test'
--- a/mysql-test/t/backup_security.test	2007-12-04 17:38:12 +0000
+++ b/mysql-test/t/backup_security.test	2008-06-25 13:39:04 +0000
@@ -45,15 +45,7 @@ FLUSH PRIVILEGES;
 BACKUP DATABASE backup_test to 'backup_test_orig.bak';
 
 --echo default: Connect as user with no rights and attempt backup and restore.
-
 connect (no_rights,localhost,bup_no_rights,,backup_test);
-connection no_rights;
-
-# Checking processes
-let $wait_condition = SELECT count(*) = 0
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
 
 --echo no_rights: Attempting backup. Should fail with error 1227
 --replace_column 1 #
@@ -72,15 +64,7 @@ SELECT * FROM backup_test.t1;
 disconnect no_rights;
 
 --echo Connect as user with rights and attempt backup and restore.
-
 connect (with_rights,localhost,bup_with_rights,,backup_test);
-connection with_rights;
-
-# Checking processes
-let $wait_condition = SELECT count(*) = 0
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
 
 --echo no_rights: Attempting backup. Should succeed
 --replace_column 1 #
@@ -94,15 +78,8 @@ SELECT * FROM backup_test.t1;
 
 disconnect with_rights;
 
-connection default;
-
-# Checking processes
-let $wait_condition = SELECT count(*) = 0
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "RESTORE FROM%";
---source include/wait_condition.inc
-
 --echo default: Do restore to ensure it still works with default test user.
+connection default;
 
 --replace_column 1 #
 RESTORE FROM 'backup_test_orig.bak';

=== modified file 'mysql-test/t/backup_snapshot.test'
--- a/mysql-test/t/backup_snapshot.test	2007-12-20 20:32:22 +0000
+++ b/mysql-test/t/backup_snapshot.test	2008-06-25 13:39:04 +0000
@@ -1,55 +1,47 @@
 #
-# This test is for the consistent snapshot online backup driver
+# This test is for the consistent snapshot online backup driver.
 # The test is designed to show that a consistent snapshot
 # backup can be taken while data is being inserted and deleted.
 #
 # The test is testing the driver to ensure it is entering a 
 # consistent read state during the backup. There are several
-# breakpoints in the code that can be used. The two most 
-# useful ones are:
+# synchronization points in the code that can be used.
+# The two most useful ones are:
 #
-#   backup_cs_unlock - occurs after consistent read 
+#   after_backup_cs_locked - occurs after consistent read 
 #     transaction has been started and before the open and
 #     lock tables.
 #
-#   backup_cs_reading - occurs after the open and lock
+#   when_backup_cs_reading - occurs after the open and lock
 #     tables during the read tables portion.
 #
 # The following tests test these conditions.
 #
-# Notes
-#   You must use a dedicated connection for getting and releasing locks.
-# Do not issue a get_lock() or release_lock() in the same connection
-# (thread) as code that calls BACKUP_BREAKPOINT(). Using the same connection
-# to get/release locks and run code that issues BACKUP_BREAKPOINTs will result
-# in an assertion using DEBUG_ASSERT(thd->ull == NULL) from debug_sync_point()
-# in item_func.cc.
-#
 
 --source include/have_innodb.inc
---source include/have_debug.inc
+--source include/have_debug_sync.inc
 --source include/not_embedded.inc
 
+#
+# Preparative cleanup.
+#
 --disable_warnings
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE IF EXISTS bup_snapshot;
 --error 0,1
 --remove_file $MYSQLTEST_VARDIR/master-data/bup_snapshot.bak;
 --enable_warnings
 
-CREATE DATABASE bup_snapshot;
+--echo #
+--echo # Setup for tests.
+--echo #
 
 connect (con1,localhost,root,,);
 connect (con2,localhost,root,,);
-connect (con3,localhost,root,,);
 
 connection con1;
 
-# Setup the server to use the backup breakpoints
-SET GLOBAL debug="d,backup_debug:d,backup";
-
-#
-# Setup for tests.
-#
+CREATE DATABASE bup_snapshot;
 
 # Create a table and load it with lots of data.
 CREATE TABLE bup_snapshot.t1 (word CHAR(20)) ENGINE=INNODB;
@@ -74,59 +66,34 @@ SELECT * FROM bup_snapshot.t1 WHERE word
 SELECT COUNT(*) FROM bup_snapshot.t1;
 SELECT COUNT(*) FROM bup_snapshot.t2;
 
-connection con3;
-
-#
-# Test 1: Check for consistent read prior to open and lock tables
-#
-
---echo con3: Getting lock on driver.
-SELECT get_lock("backup_cs_locked", 100);
-
+--echo #
+--echo # Test 1: Check for consistent read prior to open and lock tables
+--echo #
 # While a consistent snapshot backup is executed,
 # no external inserts should be visible to the transaction.
 
-connection con1;
+--echo con1: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_cs_locked SIGNAL locked WAIT_FOR inserting';
 
 --echo con1: Backing up database. Spawn this and continue...
 send BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
 
-connection con3;
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con3: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: backup_cs_locked"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE %";
---source include/wait_condition.inc
+connection con2;
 
-# Start an insert now that CS has a transaction 
+--echo con2: Wait for backup to have locked the transaction.
+SET DEBUG_SYNC= 'now WAIT_FOR locked';
+ 
+--echo con2: Start an insert now that CS has a transaction 
 # The commit blocker will block this until the read lock of 
 # the backup is released.
 
-connection con2;
-
-send INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
-
-connection con3;
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con3: Checking locks.
-let $wait_condition = SELECT count(*) = 1
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "INSERT INTO bup_snapshot.t1%";
---source include/wait_condition.inc
-
---echo con3: Release lock on driver.
-SELECT release_lock("backup_cs_locked");
-
-connection con1;
---replace_column 1 #
-reap;
+--echo con2: Activate sync points for the insert statement.
+SET DEBUG_SYNC= 'wait_if_global_read_lock SIGNAL inserting';
 
-connection con2;
+# Insert will wait in wait_if_global_read_lock() until backup is done.
+INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
 
-reap;
+--echo con2: insert additional rows.
 INSERT INTO bup_snapshot.t1 VALUES("- Yes");
 INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
 DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
@@ -135,10 +102,14 @@ DELETE FROM bup_snapshot.t1 WHERE word L
 SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
 SELECT COUNT(*) FROM bup_snapshot.t1;
 
-# Now restore the database and then check to make sure the new rows
-# were not backed up.
+connection con1;
 
-connection con1; 
+--echo con1: retrieve backup result.
+--replace_column 1 #
+reap;
+
+--echo # Now restore the database and then check to make sure the new rows
+--echo # were not backed up.
 
 --echo con1: Dropping the database
 DROP TABLE bup_snapshot.t1;
@@ -154,55 +125,34 @@ SELECT COUNT(*) FROM bup_snapshot.t2;
 
 remove_file $MYSQLTEST_VARDIR/master-data/bup_snapshot.bak;
 
-#
-# Test 2: Check for consistent read after open and lock tables
-#
-
-connection con3;
-
---echo con3: Getting lock on driver.
-SELECT get_lock("backup_cs_reading", 100);
-
+--echo #
+--echo # Test 2: Check for consistent read after open and lock tables
+--echo #
 # While a consistent snapshot backup is executed,
 # no external inserts should be visible to the transaction.
 
-connection con1;
+--echo con1: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'when_backup_cs_reading SIGNAL reading WAIT_FOR inserting';
 
 --echo con1: Backing up database. Spawn this and continue...
 send BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
 
-connection con3;
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con3: Checking locks.
-let $wait_condition = SELECT state = "debug_sync_point: backup_cs_reading"
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "BACKUP DATABASE%";
---source include/wait_condition.inc
+connection con2;
 
-# Start an insert now that CS has a transaction 
+--echo con2: Wait for backup to start reading.
+SET DEBUG_SYNC= 'now WAIT_FOR reading';
+ 
+--echo con2: Start an insert now that CS has a transaction 
 # The commit blocker will block this until the read lock of 
 # the backup is released.
 
-connection con2;
-
-send INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
-
-connection con3;
-
-# Wait for lock to be acquired and execution to reach breakpoint
---echo con3: Checking locks.
-let $wait_condition = SELECT count(*) = 1
-                      FROM INFORMATION_SCHEMA.PROCESSLIST
-                      WHERE info LIKE "INSERT INTO bup_snapshot.t1%";
---source include/wait_condition.inc
-
---echo con3: Release lock on driver.
-SELECT release_lock("backup_cs_reading");
+--echo con2: Activate sync points for the insert statement.
+SET DEBUG_SYNC= 'after_insert_locked_tables SIGNAL inserting';
 
-connection con2;
+# Insert will wait in wait_if_global_read_lock() until backup is done.
+INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
 
-reap;
+--echo con2: insert additional rows.
 INSERT INTO bup_snapshot.t1 VALUES("- Yes");
 INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
 DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
@@ -212,11 +162,13 @@ SELECT * FROM bup_snapshot.t1 WHERE word
 SELECT COUNT(*) FROM bup_snapshot.t1;
 
 connection con1;
+
+--echo con1: retrieve backup result.
 --replace_column 1 #
 reap;
 
-# Now restore the database and then check to make sure the new rows
-# were not backed up.
+--echo # Now restore the database and then check to make sure the new rows
+--echo # were not backed up.
 
 --echo con1: Dropping the database
 DROP TABLE bup_snapshot.t1;
@@ -230,7 +182,10 @@ SELECT * FROM bup_snapshot.t1 WHERE word
 SELECT COUNT(*) FROM bup_snapshot.t1;
 SELECT COUNT(*) FROM bup_snapshot.t2;
 
+#
+# Cleanup
+#
+SET DEBUG_SYNC= 'reset';
 DROP DATABASE bup_snapshot;
-
 remove_file $MYSQLTEST_VARDIR/master-data/bup_snapshot.bak;
 

=== added file 'mysql-test/t/backup_triggers_and_events.test'
--- a/mysql-test/t/backup_triggers_and_events.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/backup_triggers_and_events.test	2008-06-26 15:52:25 +0000
@@ -0,0 +1,214 @@
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+# This test checks that re-created events or triggers are not fired during
+# RESTORE operation.
+#
+# Author: Rafal Somla
+
+--disable_warnings
+--error 0,1
+--remove_file $MYSQL_TEST_DIR/var/master-data/db.bak
+--enable_warnings
+
+SET GLOBAL event_scheduler=off;
+SET DEBUG_SYNC = 'RESET';
+
+# We need a separate connection to measure timing for RESTORE command. This is
+# because of BUG#35806: time stops in a thread executing RESTORE command.
+
+connect(con1, localhost, root,,);
+connect(con2, localhost, root,,);
+
+--connection con1
+
+# Events and triggers will insert entries into a log table so that we can see
+# if they have fired.
+
+--echo Creating log table.
+
+--disable_warnings
+DROP TABLE IF EXISTS test.logt;
+--enable_warnings
+
+CREATE TABLE test.logt(ts timestamp, db char(8), msg text);
+
+--echo Creating database db and its objects.
+
+--disable_warnings
+DROP DATABASE IF EXISTS db;
+--enable_warnings
+
+CREATE DATABASE db;
+USE db;
+
+CREATE TABLE t1 (a int); 
+INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6);
+
+delimiter ||;
+
+CREATE EVENT ev ON SCHEDULE EVERY 1 second DO 
+BEGIN
+  INSERT INTO test.logt(db, msg) VALUES ('db','Db event fired!');
+END;
+||
+
+CREATE PROCEDURE trg_msg(a int)
+BEGIN
+    INSERT INTO test.logt(db, msg) VALUES ('db','Db trigger fired!');
+END;
+||
+
+CREATE TRIGGER after_ins AFTER INSERT ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+
+CREATE TRIGGER after_upd AFTER UPDATE ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+
+CREATE TRIGGER after_del AFTER DELETE ON t1 FOR EACH ROW 
+CALL trg_msg(OLD.a);
+||
+
+CREATE TRIGGER before_ins BEFORE INSERT ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+
+CREATE TRIGGER before_upd BEFORE UPDATE ON t1 FOR EACH ROW 
+CALL trg_msg(NEW.a);
+||
+
+CREATE TRIGGER before_del BEFORE DELETE ON t1 FOR EACH ROW 
+CALL trg_msg(OLD.a);
+||
+
+# Create an event and trigger in test database to see that they are not
+# affected by RESTORE of another database.
+
+USE test||
+
+--disable_warnings
+DROP EVENT IF EXISTS ev||
+DROP TABLE IF EXISTS t1||
+DROP TRIGGER IF EXISTS trg||
+--enable_warnings
+
+CREATE EVENT ev ON SCHEDULE EVERY 1 second DO
+BEGIN
+  INSERT INTO test.logt(db, msg) VALUES ('test','Test event fired!');
+END;
+||
+
+CREATE TABLE t1 (a int)||
+
+CREATE TRIGGER trg AFTER INSERT ON t1 FOR EACH ROW
+BEGIN
+  INSERT INTO test.logt(db, msg) VALUES ('test','Test trigger fired');   
+END;
+||
+
+delimiter ;||
+
+--echo Backing-up database db and dropping it.
+
+--replace_column 1 #
+BACKUP DATABASE db TO 'db.bak';
+DROP DATABASE db;
+
+--echo Enabling event scheduler.
+SET GLOBAL event_scheduler=on;
+
+--connection con1
+
+--echo con1: clearing log table and starting RESTORE operation.
+--echo con1: RESTORE will pause after restoring table data.
+
+# Synchronization point 'restore_table_data_before_end' is inside RESTORE code,
+# after restore drivers have finished their job but before they have been shoot
+# down.
+
+SET DEBUG_SYNC = 'restore_table_data_before_end SIGNAL waiting WAIT_FOR continue';
+DELETE FROM test.logt;
+--send RESTORE FROM 'db.bak'
+
+--connection con2
+
+# Record the time when RESTORE has started.
+SELECT now() INTO @start;
+
+--echo con2: checking that there are no triggers and events at the end of RESTORE execution.
+
+# Wait until RESTORE reaches the moment when all table data is restored.
+SET DEBUG_SYNC = 'now WAIT_FOR waiting';
+# There should be no triggers and no events at this moment (they are created
+# after table data is restored)
+--query_vertical SHOW TRIGGERS FROM db
+--query_vertical SHOW EVENTS IN db
+
+--echo con2: activating trigger in test database.
+INSERT INTO test.t1 VALUES (1);
+
+--echo con2: ensuring that RESTORE takes at least 3 secs.
+
+# This is so that db.ev event has chance to fire if it is not correctly handled
+# (e.g. enabled during table data restore).
+--sleep 3
+SET DEBUG_SYNC = 'now SIGNAL continue';
+
+--connection con1
+
+--echo con1: finishing RESTORE operation.
+--replace_column 1 #
+--reap
+SET GLOBAL event_scheduler=off;
+
+--connection con2
+
+-- echo con2: checking that RESTORE took more than 2 secs.
+
+SELECT timediff(now(),@start) > 2;
+
+--echo Checking that objects have been restored.
+
+USE db;
+
+SHOW TABLES IN db;
+SELECT count(*) FROM db.t1;
+--replace_column 9 #
+--query_vertical SHOW TRIGGERS FROM db
+--replace_column 9 #
+--query_vertical SHOW EVENTS IN db
+
+--echo Checking that no db event or trigger fired during RESTORE.
+
+# There should be no entries in the log table from the time when RESTORE
+# was running (but there could be entries inserted by event firing *after*
+# RESTORE has completed). We know that RESTORE took at least 3 sec and we 
+# take 2 sec window form the beginning of the operation. This is enough
+# to see db.ev in case it fired during RESTORE operation (this event is sheduled
+# to fire every second).
+
+SELECT * FROM test.logt WHERE db = 'db' AND timediff(ts,@start) < 2;
+
+--echo Checking that test event and trigger could fire.
+
+# Checking that the trigger has fired.
+SELECT count(*) > 0 FROM test.logt 
+WHERE db = 'test'
+AND msg LIKE '%trigger fired%'
+AND timediff(ts,@start) < 2;
+
+# Checking that the event has fired.
+SELECT count(*) > 0 FROM test.logt 
+WHERE db = 'test'
+AND msg LIKE '%event fired%'
+AND timediff(ts,@start) < 2;
+
+--echo Cleaning up.
+DROP EVENT test.ev;
+DROP TRIGGER test.trg;
+DROP TABLE test.logt;
+DROP TABLE test.t1;
+DROP DATABASE db;
+--remove_file $MYSQL_TEST_DIR/var/master-data/db.bak

=== modified file 'mysql-test/t/backup_view_on_view.test'
--- a/mysql-test/t/backup_view_on_view.test	2008-06-13 13:43:16 +0000
+++ b/mysql-test/t/backup_view_on_view.test	2008-06-25 13:39:04 +0000
@@ -27,3 +27,6 @@ RESTORE FROM 'test.bak';
 SELECT * FROM db1.v2;
 SELECT * FROM db1.v1;
 SELECT * FROM db1.t1;
+
+DROP DATABASE db1;
+

=== modified file 'mysql-test/t/character_set_server_func.test'
--- a/mysql-test/t/character_set_server_func.test	2008-04-10 13:14:28 +0000
+++ b/mysql-test/t/character_set_server_func.test	2008-06-25 13:39:04 +0000
@@ -18,6 +18,12 @@
 #  server-system-variables.html                                               #
 #                                                                             #
 ###############################################################################
+
+# Preparatory cleanup.
+--disable_warnings
+DROP DATABASE IF EXISTS db1;
+--enable_warnings
+
 --echo '#--------------------FN_DYNVARS_009_01-------------------------#'
 ######################################################################
 # Check if setting character_set_server is changed in new connection # 

=== modified file 'mysql-test/t/disabled.def'
--- a/mysql-test/t/disabled.def	2008-06-04 13:20:03 +0000
+++ b/mysql-test/t/disabled.def	2008-06-25 13:39:04 +0000
@@ -17,12 +17,6 @@ lowercase_table3         : Bug#32667 low
 rpl_log_pos          : Bug#8693 Test 'rpl_log_pos' fails sometimes
 ctype_create         : Bug#32965 main.ctype_create fails
 user_limits          : Bug#23921 2007-12-16 random failure of user_limits.test
-backup                :BUG#34235 pending replacement of test facility with WL#4259
-backup_commit_blocker :BUG#34235 pending replacement of test facility with WL#4259
-backup_ddl_blocker    :BUG#34235 pending replacement of test facility with WL#4259
-backup_progress       :BUG#34235 pending replacement of test facility with WL#4259
-backup_security       :BUG#34235 pending replacement of test facility with WL#4259
-backup_snapshot       :BUG#34235 pending replacement of test facility with WL#4259
 backup_no_engine     : Bug#36021 2008-04-13 rsomla server crashes when openning table with unknown storage engine
 csv_alter_table      : Bug#33696 2008-01-21 pcrews no .result file - bug allows NULL columns in CSV tables
 ctype_latin2_ch      : BUG #33791 2008-01-18 mats Wrong ORDER BY with latin2_czech_cs

=== added file 'mysql-test/t/innodb-autoinc.test'
--- a/mysql-test/t/innodb-autoinc.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb-autoinc.test	2008-06-26 15:52:25 +0000
@@ -0,0 +1,107 @@
+-- source include/have_innodb.inc
+# embedded server ignores 'delayed', so skip this
+-- source include/not_embedded.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# Bug #34335
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+## Test AUTOINC overflow
+##
+
+# TINYINT
+CREATE TABLE t1 (c1 TINYINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (127, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (255, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# SMALLINT
+#
+CREATE TABLE t1 (c1 SMALLINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (32767, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (65535, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# MEDIUMINT
+#
+CREATE TABLE t1 (c1 MEDIUMINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (8388607, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 MEDIUMINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (16777215, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# INT
+#
+CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (2147483647, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (4294967295, null);
+-- error ER_DUP_ENTRY,1062
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+#
+# BIGINT
+#
+CREATE TABLE t1 (c1 BIGINT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (9223372036854775807, null);
+-- error ER_DUP_ENTRY,1062
+#-- warning ER_WARN_DATA_OUT_OF_RANGE,1264
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (c1 BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (18446744073709551615, null);
+-- error ER_AUTOINC_READ_FAILED,1467
+INSERT INTO t1 (c2) VALUES ('innodb');
+SELECT * FROM t1;
+DROP TABLE t1;

=== modified file 'mysql-test/t/innodb.test'
--- a/mysql-test/t/innodb.test	2008-05-14 09:24:14 +0000
+++ b/mysql-test/t/innodb.test	2008-06-12 00:08:07 +0000
@@ -2381,6 +2381,96 @@ DROP TABLE t1;
 DROP TABLE t2;
 DISCONNECT c1;
 DISCONNECT c2;
+CONNECTION default;
+
+#
+# Bug #29157 UPDATE, changed rows incorrect
+#
+create table t1 (i int, j int) engine=innodb;
+insert into t1 (i, j) values (1, 1), (2, 2);
+--enable_info
+update t1 set j = 2;
+--disable_info
+drop table t1;
+
+#
+# Bug #32440 InnoDB free space info does not appear in SHOW TABLE STATUS or
+# I_S
+#
+create table t1 (id int) comment='this is a comment' engine=innodb;
+select table_comment, data_free > 0 as data_free_is_set
+  from information_schema.tables
+  where table_schema='test' and table_name = 't1';
+drop table t1;
+
+#
+# Bug 34920 test
+#
+CONNECTION default;
+CREATE TABLE t1 (
+	c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+	c2 VARCHAR(128) NOT NULL,
+	PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100;
+
+CREATE TABLE t2 (
+	c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
+	c2 INT(10) UNSIGNED DEFAULT NULL,
+	PRIMARY KEY(c1)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200;
+
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1);
+SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2';
+DROP TABLE t2;
+DROP TABLE t1;
+# End 34920 test
+#
+# Bug #29507 TRUNCATE shows to many rows effected
+#
+CONNECTION default;
+CREATE TABLE t1 (c1 int default NULL,
+		 c2 int default NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+--enable_info
+TRUNCATE TABLE t1;
+
+INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
+TRUNCATE TABLE t1;
+
+--disable_info
+DROP TABLE t1;
+#
+# Bug#35537 Innodb doesn't increment handler_update and handler_delete.
+#
+-- disable_query_log
+-- disable_result_log
+
+CONNECT (c1,localhost,root,,);
+
+DROP TABLE IF EXISTS bug35537;
+CREATE TABLE bug35537 (
+  c1 int
+) ENGINE=InnoDB;
+
+INSERT INTO bug35537 VALUES (1);
+
+-- enable_result_log
+
+SHOW SESSION STATUS LIKE 'Handler_update%';
+SHOW SESSION STATUS LIKE 'Handler_delete%';
+
+UPDATE bug35537 SET c1 = 2 WHERE c1 = 1;
+DELETE FROM bug35537 WHERE c1 = 2;
+
+SHOW SESSION STATUS LIKE 'Handler_update%';
+SHOW SESSION STATUS LIKE 'Handler_delete%';
+
+DROP TABLE bug35537;
+
+DISCONNECT c1;
+CONNECTION default;
 
 #######################################################################
 #                                                                     #

=== added file 'mysql-test/t/innodb_bug34053.test'
--- a/mysql-test/t/innodb_bug34053.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug34053.test	2008-06-12 00:08:07 +0000
@@ -0,0 +1,50 @@
+#
+# Make sure http://bugs.mysql.com/34053 remains fixed.
+#
+
+-- source include/not_embedded.inc
+-- source include/have_innodb.inc
+
+SET storage_engine=InnoDB;
+
+# we do not really care about what gets printed, we are only
+# interested in getting success or failure according to our
+# expectations
+-- disable_query_log
+-- disable_result_log
+
+GRANT USAGE ON *.* TO 'shane'@'localhost' IDENTIFIED BY '12345';
+FLUSH PRIVILEGES;
+
+-- connect (con1,localhost,shane,12345,)
+
+-- connection con1
+-- error ER_SPECIFIC_ACCESS_DENIED_ERROR
+CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB;
+-- error ER_SPECIFIC_ACCESS_DENIED_ERROR
+CREATE TABLE innodb_mem_validate (a INT) ENGINE=INNODB;
+CREATE TABLE innodb_monitorx (a INT) ENGINE=INNODB;
+DROP TABLE innodb_monitorx;
+CREATE TABLE innodb_monito (a INT) ENGINE=INNODB;
+DROP TABLE innodb_monito;
+CREATE TABLE xinnodb_monitor (a INT) ENGINE=INNODB;
+DROP TABLE xinnodb_monitor;
+CREATE TABLE nnodb_monitor (a INT) ENGINE=INNODB;
+DROP TABLE nnodb_monitor;
+
+-- connection default
+CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB;
+CREATE TABLE innodb_mem_validate (a INT) ENGINE=INNODB;
+
+-- connection con1
+-- error ER_SPECIFIC_ACCESS_DENIED_ERROR
+DROP TABLE innodb_monitor;
+-- error ER_SPECIFIC_ACCESS_DENIED_ERROR
+DROP TABLE innodb_mem_validate;
+
+-- connection default
+DROP TABLE innodb_monitor;
+DROP TABLE innodb_mem_validate;
+DROP USER 'shane'@'localhost';
+
+-- disconnect con1

=== added file 'mysql-test/t/innodb_bug34300.test'
--- a/mysql-test/t/innodb_bug34300.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug34300.test	2008-06-12 00:08:07 +0000
@@ -0,0 +1,30 @@
+#
+# Bug#34300 Tinyblob & tinytext fields currupted after export/import and alter in 5.1
+# http://bugs.mysql.com/34300
+#
+
+-- source include/have_innodb.inc
+
+-- disable_query_log
+-- disable_result_log
+
+SET @@max_allowed_packet=16777216;
+
+DROP TABLE IF EXISTS bug34300;
+CREATE TABLE bug34300 (
+  f4 TINYTEXT,
+  f6 MEDIUMTEXT,
+  f8 TINYBLOB
+) ENGINE=InnoDB;
+
+INSERT INTO bug34300 VALUES ('xxx', repeat('a', 8459264), 'zzz');
+
+-- enable_result_log
+
+SELECT f4, f8 FROM bug34300;
+
+ALTER TABLE bug34300 ADD COLUMN (f10 INT);
+
+SELECT f4, f8 FROM bug34300;
+
+DROP TABLE bug34300;

=== added file 'mysql-test/t/innodb_bug35220.test'
--- a/mysql-test/t/innodb_bug35220.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/innodb_bug35220.test	2008-06-12 00:08:07 +0000
@@ -0,0 +1,16 @@
+#
+# Bug#35220 ALTER TABLE too picky on reserved word "foreign"
+# http://bugs.mysql.com/35220
+#
+
+-- source include/have_innodb.inc
+
+SET storage_engine=InnoDB;
+
+# we care only that the following SQL commands do not produce errors
+-- disable_query_log
+-- disable_result_log
+
+CREATE TABLE bug35220 (foreign_col INT, dummy_cant_delete_all_columns INT);
+ALTER TABLE bug35220 DROP foreign_col;
+DROP TABLE bug35220;

=== modified file 'mysql-test/t/merge-sync.test'
--- a/mysql-test/t/merge-sync.test	2008-04-29 09:22:04 +0000
+++ b/mysql-test/t/merge-sync.test	2008-06-26 15:52:25 +0000
@@ -15,6 +15,12 @@ drop database if exists mysqltest;
 --enable_warnings
 
 #
+# With concurrent inserts enabled, SELECT does not always see rows inserted
+# by another session immediately before. Disable it to get stable results.
+#
+SET GLOBAL concurrent_insert= 0;
+
+#
 # Bug#26379 - Combination of FLUSH TABLE and REPAIR TABLE corrupts a MERGE table
 # Problem #1
 # A thread trying to lock a MERGE table performed busy waiting while
@@ -382,3 +388,8 @@ connection default;
 SET DEBUG_SYNC= 'RESET';
 DROP TABLE t1;
 
+#
+# Restore to default setting.
+#
+SET GLOBAL concurrent_insert= DEFAULT;
+

=== modified file 'mysql-test/t/mysql_delimiter.sql'
--- a/mysql-test/t/mysql_delimiter.sql	2006-11-22 06:27:06 +0000
+++ b/mysql-test/t/mysql_delimiter.sql	2008-06-20 16:58:14 +0000
@@ -59,3 +59,9 @@ source t/mysql_delimiter_19799.sql
 use test//
 show tables//
 delimiter ; # Reset delimiter
+
+#
+# Bug #33812: mysql client incorrectly parsing DELIMITER
+#
+select a as delimiter from t1
+delimiter ; # Reset delimiter

=== modified file 'mysql-test/t/partition_innodb.test'
--- a/mysql-test/t/partition_innodb.test	2008-03-27 19:02:15 +0000
+++ b/mysql-test/t/partition_innodb.test	2008-06-12 00:08:07 +0000
@@ -20,6 +20,7 @@ DROP TABLE t1;
 # Bug #14673: Wrong InnoDB default row format
 #
 create table t1 (a int) engine=innodb partition by hash(a) ;
+--replace_column 10 <datafree>
 show table status like 't1';
 drop table t1;
 
@@ -29,18 +30,23 @@ drop table t1;
 create table t1 (a int)
 engine = innodb
 partition by key (a);
+--replace_column 10 <datafree>
 show table status;
 insert into t1 values (0), (1), (2), (3);
+--replace_column 10 <datafree>
 show table status;
 drop table t1;
 
 create table t1 (a int auto_increment primary key)
 engine = innodb
 partition by key (a);
+--replace_column 10 <datafree>
 show table status;
 insert into t1 values (NULL), (NULL), (NULL), (NULL);
+--replace_column 10 <datafree>
 show table status;
 insert into t1 values (NULL), (NULL), (NULL), (NULL);
+--replace_column 10 <datafree>
 show table status;
 drop table t1;
 

=== modified file 'mysql-test/t/subselect.test'
--- a/mysql-test/t/subselect.test	2008-05-22 18:40:15 +0000
+++ b/mysql-test/t/subselect.test	2008-06-20 19:24:46 +0000
@@ -3422,6 +3422,19 @@ SELECT * FROM t1 WHERE _utf8'a' = ANY (S
 DROP TABLE t1;
 
 #
+# Bug #37004: NOT IN subquery with MAX over an empty set
+#
+
+CREATE TABLE t1(c int, KEY(c));
+CREATE TABLE t2(a int, b int);
+INSERT INTO t2 VALUES (1, 10), (2, NULL);
+INSERT INTO t1 VALUES (1), (3);
+
+SELECT * FROM t2 WHERE b NOT IN (SELECT max(t.c) FROM t1, t1 t WHERE t.c>10);
+
+DROP TABLE t1,t2;
+
+#
 # Bug#33204: INTO is allowed in subselect, causing inconsistent results
 #
 CREATE TABLE t1( a INT );

=== modified file 'scripts/make_binary_distribution.sh'
--- a/scripts/make_binary_distribution.sh	2008-05-13 13:58:07 +0000
+++ b/scripts/make_binary_distribution.sh	2008-06-18 03:30:29 +0000
@@ -14,36 +14,61 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-# This is a script to create a TAR or ZIP binary distribution out of a
-# built source tree. The output file will be put at the top level of
-# the source tree, as "mysql-<vsn>....{tar.gz,zip}"
+##############################################################################
 #
-# The temporary directory path given to "--tmp=<path>" has to be
-# absolute and with no spaces.
+#  This is a script to create a TAR or ZIP binary distribution out of a
+#  built source tree. The output file will be put at the top level of
+#  the source tree, as "mysql-<vsn>....{tar.gz,zip}"
+#
+#  Note that the structure created by this script is slightly different from
+#  what a normal "make install" would produce. No extra "mysql" sub directory
+#  will be created, i.e. no "$prefix/include/mysql", "$prefix/lib/mysql" or
+#  "$prefix/share/mysql".  This is because the build system explicitly calls
+#  make with pkgdatadir=<datadir>, etc.
+#
+#  In GNU make/automake terms
+#
+#    "pkglibdir"     is set to the same as "libdir"
+#    "pkgincludedir" is set to the same as "includedir"
+#    "pkgdatadir"    is set to the same as "datadir"
+#    "pkgplugindir"  is set to "$pkglibdir/plugin"
+#    "pkgsuppdir"    is set to "@prefix@/support-files",
+#                    normally the same as "datadir"
+#
+#  The temporary directory path given to "--tmp=<path>" has to be
+#  absolute and with no spaces.
+#
+#  Note that for best result, the original "make" should be done with
+#  the same arguments as used for "make install" below, especially the
+#  'pkglibdir', as the RPATH should to be set correctly.
+#
+##############################################################################
+
+##############################################################################
+#
+#  Read the command line arguments that control this script
+#
+##############################################################################
 
 machine=@MACHINE_TYPE@
 system=@SYSTEM_TYPE@
-version=@VERSION@
 SOURCE=`pwd`
 CP="cp -p"
 MV="mv"
 
-STRIP=1
-DEBUG=0
+STRIP=1				# Option ignored
 SILENT=0
-MACHINE=""
 PLATFORM=""
 TMP=/tmp
 SUFFIX=""
-NDBCLUSTER=""
+NDBCLUSTER=""			# Option ignored
 
 for arg do
   case "$arg" in
-    --debug)    DEBUG=1;;
     --tmp=*)    TMP=`echo "$arg" | sed -e "s;--tmp=;;"` ;;
     --suffix=*) SUFFIX=`echo "$arg" | sed -e "s;--suffix=;;"` ;;
     --no-strip) STRIP=0 ;;
-    --machine=*) MACHINE=`echo "$arg" | sed -e "s;--machine=;;"` ;;
+    --machine=*) machine=`echo "$arg" | sed -e "s;--machine=;;"` ;;
     --platform=*) PLATFORM=`echo "$arg" | sed -e "s;--platform=;;"` ;;
     --silent)   SILENT=1 ;;
     --with-ndbcluster) NDBCLUSTER=1 ;;
@@ -54,53 +79,52 @@ for arg do
   esac
 done
 
-# Remove vendor from $system
-system=`echo $system | sed -e 's/[a-z]*-\(.*\)/\1/g'`
-
-# Map OS names to "our" OS names (eg. darwin6.8 -> osx10.2)
-system=`echo $system | sed -e 's/darwin6.*/osx10.2/g'`
-system=`echo $system | sed -e 's/darwin7.*/osx10.3/g'`
-system=`echo $system | sed -e 's/darwin8.*/osx10.4/g'`
-system=`echo $system | sed -e 's/\(aix4.3\).*/\1/g'`
-system=`echo $system | sed -e 's/\(aix5.1\).*/\1/g'`
-system=`echo $system | sed -e 's/\(aix5.2\).*/\1/g'`
-system=`echo $system | sed -e 's/\(aix5.3\).*/\1/g'`
-system=`echo $system | sed -e 's/osf5.1b/tru64/g'`
-system=`echo $system | sed -e 's/linux-gnu/linux/g'`
-system=`echo $system | sed -e 's/solaris2.\([0-9]*\)/solaris\1/g'`
-system=`echo $system | sed -e 's/sco3.2v\(.*\)/openserver\1/g'`
+# ----------------------------------------------------------------------
+# Adjust "system" output from "uname" to be more human readable
+# ----------------------------------------------------------------------
+
+if [ x"$PLATFORM" = x"" ] ; then
+  # FIXME move this to the build tools
+  # Remove vendor from $system
+  system=`echo $system | sed -e 's/[a-z]*-\(.*\)/\1/g'`
+
+  # Map OS names to "our" OS names (eg. darwin6.8 -> osx10.2)
+  system=`echo $system | sed -e 's/darwin6.*/osx10.2/g'`
+  system=`echo $system | sed -e 's/darwin7.*/osx10.3/g'`
+  system=`echo $system | sed -e 's/darwin8.*/osx10.4/g'`
+  system=`echo $system | sed -e 's/\(aix4.3\).*/\1/g'`
+  system=`echo $system | sed -e 's/\(aix5.1\).*/\1/g'`
+  system=`echo $system | sed -e 's/\(aix5.2\).*/\1/g'`
+  system=`echo $system | sed -e 's/\(aix5.3\).*/\1/g'`
+  system=`echo $system | sed -e 's/osf5.1b/tru64/g'`
+  system=`echo $system | sed -e 's/linux-gnu/linux/g'`
+  system=`echo $system | sed -e 's/solaris2.\([0-9]*\)/solaris\1/g'`
+  system=`echo $system | sed -e 's/sco3.2v\(.*\)/openserver\1/g'`
 
-if [ x"$MACHINE" != x"" ] ; then
-  machine=$MACHINE
+  PLATFORM="$system-$machine"
 fi
 
-if [ x"$PLATFORM" != x"" ] ; then
-  platform="$PLATFORM"
-else
-  platform="$system-$machine"
-fi
+# Print the platform name for build logs
+echo "PLATFORM NAME: $PLATFORM"
+
+case $PLATFORM in
+  *netware*) BASE_SYSTEM="netware" ;;
+esac
 
-# FIXME This should really be integrated with automake and not duplicate the
-# installation list.
+# Change the distribution to a long descriptive name
+NEW_NAME=mysql@MYSQL_SERVER_SUFFIX@-@VERSION@-$PLATFORM$SUFFIX
 
+# ----------------------------------------------------------------------
+# Define BASE, and remove the old BASE directory if any
+# ----------------------------------------------------------------------
 BASE=$TMP/my_dist$SUFFIX
-
 if [ -d $BASE ] ; then
  rm -rf $BASE
 fi
 
-BS=""
-BIN_FILES=""
-BASE_SYSTEM="any"
-MYSQL_SHARE=$BASE/share/mysql
-
-case $system in
-  *netware*)
-    BASE_SYSTEM="netware"
-    BS=".nlm"
-    MYSQL_SHARE=$BASE/share
-    ;;
-esac
+# ----------------------------------------------------------------------
+# Find the TAR to use
+# ----------------------------------------------------------------------
 
 # This is needed to prefer GNU tar over platform tar because that can't
 # always handle long filenames
@@ -127,24 +151,149 @@ which_1 ()
 }
 
 tar=`which_1 gnutar gtar`
-if [ "$?" = "1" -o x"$tar" = x"" ] ; then
+if [ $? -ne 0 -o x"$tar" = x"" ] ; then
   tar=tar
 fi
 
 
+##############################################################################
+#
+#  Handle the Unix/Linux packaging using "make install"
+#
+##############################################################################
+
+if [ x"$BASE_SYSTEM" != x"netware" ] ; then
+
+  # ----------------------------------------------------------------------
+  # Terminate on any base level error
+  # ----------------------------------------------------------------------
+  set -e
+
+  # ----------------------------------------------------------------------
+  # Really ugly, one script, "mysql_install_db", needs prefix set to ".",
+  # i.e. makes access relative the current directory. This matches
+  # the documentation, so better not change this. And for another script,
+  # "mysql.server", we make some relative, others not.
+  # ----------------------------------------------------------------------
+
+  cd scripts
+  rm -f mysql_install_db
+  @MAKE@ mysql_install_db \
+    prefix=. \
+    bindir=./bin \
+    sbindir=./bin \
+    scriptdir=./bin \
+    libexecdir=./bin \
+    pkgdatadir=./share \
+    localstatedir=./data
+  cd ..
+
+  cd support-files
+  rm -f mysql.server
+  @MAKE@ mysql.server \
+    bindir=./bin \
+    sbindir=./bin \
+    scriptdir=./bin \
+    libexecdir=./bin \
+    pkgdatadir=@pkgdatadir@
+  cd ..
+
+  # ----------------------------------------------------------------------
+  # Do a install that we later are to pack. Use the same paths as in
+  # the build for the relevant directories.
+  # ----------------------------------------------------------------------
+  @MAKE@ DESTDIR=$BASE install \
+    pkglibdir=@pkglibdir@ \
+    pkgincludedir=@pkgincludedir@ \
+    pkgdatadir=@pkgdatadir@ \
+    pkgplugindir=@pkgplugindir@ \
+    pkgsuppdir=@pkgsuppdir@ \
+    mandir=@mandir@ \
+    infodir=@infodir@
+
+  # ----------------------------------------------------------------------
+  # Rename top directory, and set DEST to the new directory
+  # ----------------------------------------------------------------------
+  mv $BASE@prefix@ $BASE/$NEW_NAME
+  DEST=$BASE/$NEW_NAME
+
+  # ----------------------------------------------------------------------
+  # If we compiled with gcc, copy libgcc.a to the dist as libmygcc.a
+  # ----------------------------------------------------------------------
+  if [ x"@GXX@" = x"yes" ] ; then
+    gcclib=`@CC@ @CFLAGS@ --print-libgcc-file 2>/dev/null` || true
+    if [ -z "$gcclib" ] ; then
+      echo "Warning: Compiler doesn't tell libgcc.a!"
+    elif [ -f "$gcclib" ] ; then
+      $CP $gcclib $DEST/lib/libmygcc.a
+    else
+      echo "Warning: Compiler result '$gcclib' not found / no file!"
+    fi
+  fi
+
+  # FIXME let this script be in "bin/", where it is in the RPMs?
+  # http://dev.mysql.com/doc/refman/5.1/en/mysql-install-db-problems.html
+  mkdir $DEST/scripts
+  mv $DEST/bin/mysql_install_db $DEST/scripts/
+
+  # Note, no legacy "safe_mysqld" link to "mysqld_safe" in 5.1
+
+  # Copy readme and license files
+  cp README Docs/INSTALL-BINARY  $DEST/
+  if [ -f COPYING -a -f EXCEPTIONS-CLIENT ] ; then
+    cp COPYING EXCEPTIONS-CLIENT $DEST/
+  elif [ -f LICENSE.mysql ] ; then
+    cp LICENSE.mysql $DEST/
+  else
+    echo "ERROR: no license files found"
+    exit 1
+  fi
+
+  # FIXME should be handled by make file, and to other dir
+  mkdir -p $DEST/bin $DEST/support-files
+  cp scripts/mysqlaccess.conf $DEST/bin/
+  cp support-files/magic      $DEST/support-files/
+
+  # Create empty data directories, set permission (FIXME why?)
+  mkdir       $DEST/data $DEST/data/mysql $DEST/data/test
+  chmod o-rwx $DEST/data $DEST/data/mysql $DEST/data/test
+
+  # ----------------------------------------------------------------------
+  # Create the result tar file
+  # ----------------------------------------------------------------------
+
+  echo "Using $tar to create archive"
+  OPT=cvf
+  if [ x$SILENT = x1 ] ; then
+    OPT=cf
+  fi
+
+  echo "Creating and compressing archive"
+  rm -f $NEW_NAME.tar.gz
+  (cd $BASE ; $tar $OPT -  $NEW_NAME) | gzip -9 > $NEW_NAME.tar.gz
+  echo "$NEW_NAME.tar.gz created"
+
+  echo "Removing temporary directory"
+  rm -rf $BASE
+  exit 0
+fi
+
+
+##############################################################################
+#
+#  Handle the Netware case, until integrated above
+#
+##############################################################################
+
+BS=".nlm"
+MYSQL_SHARE=$BASE/share
+
 mkdir $BASE $BASE/bin $BASE/docs \
  $BASE/include $BASE/lib $BASE/support-files $BASE/share $BASE/scripts \
  $BASE/mysql-test $BASE/mysql-test/t  $BASE/mysql-test/r \
  $BASE/mysql-test/include $BASE/mysql-test/std_data $BASE/mysql-test/lib \
  $BASE/mysql-test/suite
 
-if [ $BASE_SYSTEM != "netware" ] ; then
- mkdir $BASE/share/mysql $BASE/tests $BASE/sql-bench $BASE/man \
-  $BASE/man/man1 $BASE/man/man8 $BASE/data $BASE/data/mysql $BASE/data/test
-
- chmod o-rwx $BASE/data $BASE/data/*
-fi
-
 # Copy files if they exists, warn for those that don't.
 # Note that when listing files to copy, we might list the file name
 # twice, once in the directory location where it is built, and a
@@ -176,12 +325,13 @@ copyfileto $BASE COPYING COPYING.LIB REA
 BIN_FILES="extra/comp_err$BS extra/replace$BS extra/perror$BS \
   extra/resolveip$BS extra/my_print_defaults$BS \
   extra/resolve_stack_dump$BS extra/mysql_waitpid$BS \
-  myisam/myisamchk$BS myisam/myisampack$BS myisam/myisamlog$BS \
-  myisam/myisam_ftdump$BS \
+  storage/myisam/myisamchk$BS storage/myisam/myisampack$BS \
+  storage/myisam/myisamlog$BS storage/myisam/myisam_ftdump$BS \
   sql/mysqld$BS sql/mysqld-debug$BS \
   sql/mysql_tzinfo_to_sql$BS \
   server-tools/instance-manager/mysqlmanager$BS \
   client/mysql$BS client/mysqlshow$BS client/mysqladmin$BS \
+  client/mysqlslap$BS \
   client/mysqldump$BS client/mysqlimport$BS \
   client/mysqltest$BS client/mysqlcheck$BS \
   client/mysqlbinlog$BS client/mysql_upgrade$BS \
@@ -191,42 +341,16 @@ BIN_FILES="extra/comp_err$BS extra/repla
   ";
 
 # Platform-specific bin dir files:
-if [ $BASE_SYSTEM = "netware" ] ; then
-  BIN_FILES="$BIN_FILES \
+BIN_FILES="$BIN_FILES \
     netware/mysqld_safe$BS netware/mysql_install_db$BS \
-    netware/init_db.sql netware/test_db.sql netware/mysql_explain_log$BS \
+    netware/init_db.sql netware/test_db.sql \
     netware/mysqlhotcopy$BS netware/libmysql$BS netware/init_secure_db.sql \
     ";
-# For all other platforms:
-else
-  BIN_FILES="$BIN_FILES \
-    server-tools/instance-manager/.libs/mysqlmanager \
-    client/mysqltestmanagerc \
-    client/mysqltestmanager-pwgen tools/mysqltestmanager \
-    client/.libs/mysql client/.libs/mysqlshow client/.libs/mysqladmin \
-    client/.libs/mysqldump client/.libs/mysqlimport \
-    client/.libs/mysqltest client/.libs/mysqlcheck \
-    client/.libs/mysqlbinlog client/.libs/mysqltestmanagerc \
-    client/.libs/mysqltestmanager-pwgen tools/.libs/mysqltestmanager \
-    tests/.libs/mysql_client_test \
-    libmysqld/examples/.libs/mysql_client_test_embedded \
-    libmysqld/examples/.libs/mysqltest_embedded \
-  ";
-fi
 
 copyfileto $BASE/bin $BIN_FILES
 
-if [ x$STRIP = x1 ] ; then
-  strip $BASE/bin/*
-fi
-
-# Copy not binary files
-copyfileto $BASE/bin sql/mysqld.sym.gz
-
-if [ $BASE_SYSTEM = "netware" ] ; then
-    $CP netware/*.pl $BASE/scripts
-    $CP scripts/mysqlhotcopy $BASE/scripts/mysqlhotcopy.pl
-fi
+$CP netware/*.pl $BASE/scripts
+$CP scripts/mysqlhotcopy $BASE/scripts/mysqlhotcopy.pl
 
 copyfileto $BASE/lib \
   libmysql/.libs/libmysqlclient.a \
@@ -248,31 +372,17 @@ copyfileto $BASE/lib \
   zlib/.libs/libz.a
 
 # convert the .a to .lib for NetWare
-if [ $BASE_SYSTEM = "netware" ] ; then
-    for i in $BASE/lib/*.a
-    do
-      libname=`basename $i .a`
-      $MV $i $BASE/lib/$libname.lib
-    done
-    rm -f $BASE/lib/*.la
-fi
+for i in $BASE/lib/*.a
+do
+  libname=`basename $i .a`
+  $MV $i $BASE/lib/$libname.lib
+done
+rm -f $BASE/lib/*.la
 
-copyfileto $BASE/include include/*
 
-rm -f $BASE/include/Makefile* $BASE/include/*.in $BASE/include/config-win.h
-if [ $BASE_SYSTEM != "netware" ] ; then
-  rm -f $BASE/include/config-netware.h
-fi
+copyfileto $BASE/include config.h include/*
 
-if [ $BASE_SYSTEM != "netware" ] ; then
-  if [ -d tests ] ; then
-    $CP tests/*.res tests/*.tst tests/*.pl $BASE/tests
-  fi
-  if [ -d man ] ; then
-    $CP man/*.1 $BASE/man/man1
-    $CP man/*.8 $BASE/man/man8
-  fi
-fi
+rm -f $BASE/include/Makefile* $BASE/include/*.in $BASE/include/config-win.h
 
 copyfileto $BASE/support-files support-files/*
 
@@ -291,43 +401,29 @@ copyfileto $BASE/mysql-test \
 $CP mysql-test/lib/*.pl  $BASE/mysql-test/lib
 $CP mysql-test/t/*.def $BASE/mysql-test/t
 $CP mysql-test/include/*.inc $BASE/mysql-test/include
+$CP mysql-test/include/*.sql $BASE/mysql-test/include
 $CP mysql-test/include/*.test $BASE/mysql-test/include
 $CP mysql-test/t/*.def $BASE/mysql-test/t
+$CP mysql-test/std_data/*.dat mysql-test/std_data/*.frm \
+    mysql-test/std_data/*.MYD mysql-test/std_data/*.MYI \
+    mysql-test/std_data/*.pem mysql-test/std_data/Moscow_leap \
+    mysql-test/std_data/Index.xml \
+    mysql-test/std_data/des_key_file mysql-test/std_data/*.*001 \
+    mysql-test/std_data/*.cnf mysql-test/std_data/*.MY* \
+    $BASE/mysql-test/std_data
 $CP mysql-test/t/*.test mysql-test/t/*.imtest \
     mysql-test/t/*.disabled mysql-test/t/*.opt \
     mysql-test/t/*.slave-mi mysql-test/t/*.sh mysql-test/t/*.sql $BASE/mysql-test/t
 $CP mysql-test/r/*.result mysql-test/r/*.require \
     $BASE/mysql-test/r
 
-# Copy the additional suites and data "as is", they are in flux
-$tar cf - mysql-test/suite    | ( cd $BASE ; $tar xf - )
-$tar cf - mysql-test/std_data | ( cd $BASE ; $tar xf - )
+# Copy the additional suites "as is", they are in flux
+$tar cf - mysql-test/suite | ( cd $BASE ; $tar xf - )
 # Clean up if we did this from a bk tree
 if [ -d mysql-test/SCCS ] ; then
   find $BASE/mysql-test -name SCCS -print | xargs rm -rf
 fi
 
-if [ $BASE_SYSTEM != "netware" ] ; then
-  chmod a+x $BASE/bin/*
-  copyfileto $BASE/bin scripts/*
-  $BASE/bin/replace \@localstatedir\@ ./data \@bindir\@ ./bin \@scriptdir\@ \
-      ./bin \@libexecdir\@ ./bin \@sbindir\@ ./bin \@prefix\@ . \@HOSTNAME\@ \
-      @HOSTNAME@ \@pkgdatadir\@ ./share \
-      < scripts/mysql_install_db.sh > $BASE/scripts/mysql_install_db
-  $BASE/bin/replace \@prefix\@ /usr/local/mysql \@bindir\@ ./bin \
-      \@sbindir\@ ./bin \@libexecdir\@ ./bin \
-      \@MYSQLD_USER\@ @MYSQLD_USER@ \@localstatedir\@ /usr/local/mysql/data \
-      \@HOSTNAME\@ @HOSTNAME@ \
-      < support-files/mysql.server.sh > $BASE/support-files/mysql.server
-  $BASE/bin/replace /my/gnu/bin/hostname /bin/hostname -- $BASE/bin/mysqld_safe
-  mv $BASE/support-files/binary-configure $BASE/configure
-  chmod a+x $BASE/bin/* $BASE/scripts/* $BASE/support-files/mysql-log-rotate \
-      $BASE/support-files/*.server $BASE/configure
-  $CP -r sql-bench/* $BASE/sql-bench
-  rm -f $BASE/sql-bench/*.sh $BASE/sql-bench/Makefile* $BASE/lib/*.la
-  rm -f $BASE/bin/*.sql
-fi
-
 rm -f $BASE/bin/Makefile* $BASE/bin/*.in $BASE/bin/*.sh \
     $BASE/bin/mysql_install_db $BASE/bin/make_binary_distribution \
     $BASE/bin/setsomevars $BASE/support-files/Makefile* \
@@ -336,29 +432,19 @@ rm -f $BASE/bin/Makefile* $BASE/bin/*.in
 #
 # Copy system dependent files
 #
-if [ $BASE_SYSTEM = "netware" ] ; then
-  ./scripts/fill_help_tables < ./Docs/manual.texi >> ./netware/init_db.sql
-fi
+./scripts/fill_help_tables < ./Docs/manual.texi >> ./netware/init_db.sql
 
 #
 # Remove system dependent files
 #
-if [ $BASE_SYSTEM = "netware" ] ; then
-  rm -f $BASE/support-files/magic \
+rm -f   $BASE/support-files/magic \
         $BASE/support-files/mysql.server \
         $BASE/support-files/mysql*.spec \
         $BASE/support-files/mysql-log-rotate \
         $BASE/support-files/binary-configure \
         $BASE/support-files/build-tags \
 	$BASE/support-files/MySQL-shared-compat.spec \
-        $BASE/support-files/ndb-config-2-node.ini \
         $BASE/INSTALL-BINARY
-fi
-
-# Make safe_mysqld a symlink to mysqld_safe for backwards portability
-if [ $BASE_SYSTEM != "netware" ] ; then
-  (cd $BASE/bin ; ln -s mysqld_safe safe_mysqld )
-fi
 
 # Clean up if we did this from a bk tree
 if [ -d $BASE/sql-bench/SCCS ] ; then
@@ -366,78 +452,17 @@ if [ -d $BASE/sql-bench/SCCS ] ; then
   find $BASE/sql-bench -name SCCS -print | xargs rm -rf
 fi
 
-# NDB Cluster
-if [ x$NDBCLUSTER = x1 ]; then
-  ( cd ndb            ; @MAKE@ DESTDIR=$BASE/ndb-stage install )
-  ( cd mysql-test/ndb ; @MAKE@ DESTDIR=$BASE/ndb-stage install )
-  $CP $BASE/ndb-stage@bindir@/* $BASE/bin/.
-  $CP $BASE/ndb-stage@libexecdir@/* $BASE/bin/.
-  $CP $BASE/ndb-stage@pkglibdir@/* $BASE/lib/.
-  $CP $BASE/ndb-stage@pkgdatadir@/* $BASE/share/mysql/.
-  $CP -r $BASE/ndb-stage@pkgincludedir@/ndb $BASE/include
-  $CP -r $BASE/ndb-stage@prefix@/mysql-test/ndb $BASE/mysql-test/. || exit 1
-  rm -rf $BASE/ndb-stage
-fi
-
-# Change the distribution to a long descriptive name
-NEW_NAME=mysql@MYSQL_SERVER_SUFFIX@-$version-$platform$SUFFIX
-
-# Print the platform name for build logs
-echo "PLATFORM NAME: $platform"
-
 BASE2=$TMP/$NEW_NAME
 rm -rf $BASE2
 mv $BASE $BASE2
 BASE=$BASE2
+
 #
-# If we are compiling with gcc, copy libgcc.a to the distribution as libmygcc.a
+# Create a zip file for NetWare users
 #
-
-if [ x"@GXX@" = x"yes" ] ; then
-  gcclib=`@CC@ @CFLAGS@ --print-libgcc-file 2>/dev/null` || true
-  if [ -z "$gcclib" ] ; then
-    echo "Warning: Compiler doesn't tell libgcc.a!"
-  elif [ -f "$gcclib" ] ; then
-    $CP $gcclib $BASE/lib/libmygcc.a
-  else
-    echo "Warning: Compiler result '$gcclib' not found / no file!"
-  fi
-fi
-
-#if we are debugging, do not do tar/gz
-if [ x$DEBUG = x1 ] ; then
- exit
-fi
-
-if [ $BASE_SYSTEM != "netware" ] ; then
-
-  #
-  # Create the result tar file
-  #
-
-  echo "Using $tar to create archive"
-
-  OPT=cvf
-  if [ x$SILENT = x1 ] ; then
-    OPT=cf
-  fi
-
-  echo "Creating and compressing archive"
-  rm -f $NEW_NAME.tar.gz
-  (cd $TMP ; $tar $OPT -  $NEW_NAME) | gzip -9 > $NEW_NAME.tar.gz
-  echo "$NEW_NAME.tar.gz created"
-
-else
-
-  #
-  # Create a zip file for NetWare users
-  #
-
-  rm -f $NEW_NAME.zip
-  (cd $TMP; zip -r "$SOURCE/$NEW_NAME.zip" $NEW_NAME)
-  echo "$NEW_NAME.zip created"
-
-fi
+rm -f $NEW_NAME.zip
+(cd $TMP; zip -r "$SOURCE/$NEW_NAME.zip" $NEW_NAME)
+echo "$NEW_NAME.zip created"
 
 echo "Removing temporary directory"
 rm -rf $BASE

=== modified file 'sql/backup/Makefile.am'
--- a/sql/backup/Makefile.am	2008-05-14 00:24:06 +0000
+++ b/sql/backup/Makefile.am	2008-06-26 16:20:30 +0000
@@ -20,6 +20,7 @@
 noinst_LTLIBRARIES = libbackup.la libbackupstream.la
 
 INCLUDES = \
+  @ZLIB_INCLUDES@ \
   -I$(top_builddir)/include \
   -I$(top_srcdir)/include \
   -I$(top_srcdir)/sql \
@@ -52,7 +53,6 @@ noinst_HEADERS = \
   backup_kernel.h \
   backup_stream.h \
   stream_services.h \
-  debug.h \
   error.h \
   stream.h \
   backup_aux.h \

=== modified file 'sql/backup/backup_aux.h'
--- a/sql/backup/backup_aux.h	2008-03-05 17:48:12 +0000
+++ b/sql/backup/backup_aux.h	2008-06-20 08:33:54 +0000
@@ -297,7 +297,7 @@ int Map<uint,T>::insert(ulong pos, T *pt
   uchar *entry;
   DYNAMIC_ARRAY *array= &this->array;
 
-  while (pos > Base::array.max_element)
+  while (pos >= Base::array.max_element)
   {
     entry= alloc_dynamic(array);
     if (!entry)
@@ -306,7 +306,7 @@ int Map<uint,T>::insert(ulong pos, T *pt
 
   clear_free_space();
 
-  if (pos > Base::array.max_element)
+  if (pos >= Base::array.max_element)
     return 1;
 
   if (pos >= Base::array.elements)

=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h	2008-05-05 15:06:40 +0000
+++ b/sql/backup/backup_kernel.h	2008-06-26 12:10:46 +0000
@@ -66,7 +66,7 @@ class Backup_restore_ctx: public backup:
   bool is_valid() const;
   ulonglong op_id() const;
 
-  Backup_info*  prepare_for_backup(LEX_STRING location, const char*);
+  Backup_info*  prepare_for_backup(LEX_STRING location, const char*, bool);
   Restore_info* prepare_for_restore(LEX_STRING location, const char*);  
 
   int do_backup();
@@ -113,6 +113,7 @@ class Backup_restore_ctx: public backup:
 
   int prepare(LEX_STRING location);
   void disable_fkey_constraints();
+  int  restore_triggers_and_events();
   
   friend class Backup_info;
   friend class Restore_info;

=== modified file 'sql/backup/backup_test.cc'
--- a/sql/backup/backup_test.cc	2008-03-17 13:37:42 +0000
+++ b/sql/backup/backup_test.cc	2008-06-25 13:39:04 +0000
@@ -22,7 +22,7 @@ int execute_backup_test_command(THD *thd
 {
   int res= 0;
 
-  DBUG_ENTER("execute_backup_command");
+  DBUG_ENTER("execute_backup_test_command");
   DBUG_ASSERT(thd);
 
   Protocol *protocol= thd->protocol;    // client comms

=== modified file 'sql/backup/be_default.cc'
--- a/sql/backup/be_default.cc	2008-06-12 19:54:19 +0000
+++ b/sql/backup/be_default.cc	2008-06-25 13:39:04 +0000
@@ -68,7 +68,6 @@
 #include "be_default.h"
 #include "backup_aux.h"
 #include "rpl_record.h"
-#include "debug.h"
 
 namespace default_backup {
 
@@ -331,7 +330,7 @@ result_t Backup::get_data(Buffer &buf)
     case LOCK_ACQUIRED:          // First time lock ready for validity point
     {
       locks_acquired= TRUE;
-      BACKUP_BREAKPOINT("locking_thread_added");
+      DEBUG_SYNC(locking_thd->m_thd, "locking_thread_added");
       DBUG_RETURN(READY);
     }
     default:                     // If first call, signal end of init phase

=== modified file 'sql/backup/be_snapshot.cc'
--- a/sql/backup/be_snapshot.cc	2008-06-12 17:43:47 +0000
+++ b/sql/backup/be_snapshot.cc	2008-06-25 13:39:04 +0000
@@ -44,7 +44,6 @@
 #include "backup_engine.h"
 #include "be_snapshot.h"
 #include "backup_aux.h"
-#include "debug.h"
 
 namespace snapshot_backup {
 
@@ -131,7 +130,8 @@ result_t Backup::lock()
     DBUG_RETURN(ERROR);
   m_trans_start= TRUE;
   locking_thd->lock_state= LOCK_ACQUIRED;
-  BACKUP_BREAKPOINT("backup_cs_locked");
+  DBUG_ASSERT(locking_thd->m_thd == current_thd);
+  DEBUG_SYNC(locking_thd->m_thd, "after_backup_cs_locked");
   DBUG_RETURN(OK);
 }
 
@@ -141,7 +141,6 @@ result_t Backup::get_data(Buffer &buf)
 
   if (!tables_open && (locking_thd->lock_state == LOCK_ACQUIRED))
   {
-    BACKUP_BREAKPOINT("backup_cs_open_tables");
     // The lex needs to be cleaned up between consecutive calls to 
     // open_and_lock_tables. Otherwise, open_and_lock_tables will try to open
     // previously opened views and crash.
@@ -151,7 +150,8 @@ result_t Backup::get_data(Buffer &buf)
   }
   if (locking_thd->lock_state == LOCK_ACQUIRED)
   {
-    BACKUP_BREAKPOINT("backup_cs_reading");
+    DBUG_ASSERT(locking_thd->m_thd == current_thd);
+    DEBUG_SYNC(locking_thd->m_thd, "when_backup_cs_reading");
   }
 
   res= default_backup::Backup::get_data(buf);

=== modified file 'sql/backup/data_backup.cc'
--- a/sql/backup/data_backup.cc	2008-06-05 12:26:31 +0000
+++ b/sql/backup/data_backup.cc	2008-06-26 16:20:30 +0000
@@ -19,7 +19,6 @@
 #include "backup_engine.h"
 #include "stream.h"
 #include "backup_progress.h"
-#include "debug.h"
 #include "be_default.h"  // needed for table locking code
 
 /***********************************************
@@ -409,7 +408,7 @@ int block_commits(THD *thd, TABLE_LIST *
   /*
     Step 1 - global read lock.
   */
-  BACKUP_BREAKPOINT("commit_blocker_step_1");
+  DEBUG_SYNC(thd, "before_commit_block");
   if (lock_global_read_lock(thd))
     DBUG_RETURN(1);
 
@@ -425,14 +424,12 @@ int block_commits(THD *thd, TABLE_LIST *
     that do not take lock tables. Thus, it should apply to write locked
     tables only and only to non-transactional engines.
 
-    BACKUP_BREAKPOINT("commit_blocker_step_2");
     result= close_cached_tables(thd, 0, tables);
   */
 
   /*
     Step 3 - make the global read lock to block commits.
   */
-  BACKUP_BREAKPOINT("commit_blocker_step_3");
   if (make_global_read_lock_block_commit(thd))
   {
     /* Don't leave things in a half-locked state */
@@ -455,7 +452,6 @@ int block_commits(THD *thd, TABLE_LIST *
 int unblock_commits(THD *thd)
 {
   DBUG_ENTER("unblock_commits()");
-  BACKUP_BREAKPOINT("commit_blocker_step_5");
   unlock_global_read_lock(thd);
   DBUG_RETURN(0);
 }
@@ -529,7 +525,6 @@ int write_table_data(THD* thd, Backup_in
                             inactive.elements));
 
   DBUG_PRINT("backup_data",("-- INIT PHASE --"));
-  BACKUP_BREAKPOINT("data_init");
 
   /*
    Poll "at end" drivers activating inactive ones on the way.
@@ -592,7 +587,6 @@ int write_table_data(THD* thd, Backup_in
 
     // prepare for VP
     DBUG_PRINT("backup_data",("-- PREPARE PHASE --"));
-    BACKUP_BREAKPOINT("data_prepare");
 
     if (sch.prepare())
       goto error;
@@ -613,7 +607,7 @@ int write_table_data(THD* thd, Backup_in
       the backup progress. It is not to be used to indicate actual
       timing of the validity point.
     */
-    BACKUP_BREAKPOINT("bp_vp_state");
+    DEBUG_SYNC(thd, "after_backup_validated");
     
     /*
       Block commits.
@@ -627,7 +621,6 @@ int write_table_data(THD* thd, Backup_in
     if (error)
       goto error;
 
-    BACKUP_BREAKPOINT("data_lock");
     if (sch.lock())
       goto error;
 
@@ -642,15 +635,14 @@ int write_table_data(THD* thd, Backup_in
     */
     vp_time= my_time(0);
 
-    BACKUP_BREAKPOINT("commit_blocker_step_4");
-    BACKUP_BREAKPOINT("data_unlock");
+    DEBUG_SYNC(thd, "before_backup_data_unlock");
     if (sch.unlock())
       goto error;
 
     /*
       Unblock commits.
     */
-    BACKUP_BREAKPOINT("backup_commit_blocker");
+    DEBUG_SYNC(thd, "before_backup_unblock_commit");
     error= unblock_commits(thd);
     if (error)
       goto error;
@@ -667,13 +659,12 @@ int write_table_data(THD* thd, Backup_in
     }
 
     info.m_ctx.report_state(BUP_RUNNING);
-    BACKUP_BREAKPOINT("bp_running_state");
+    DEBUG_SYNC(thd, "after_backup_binlog");
 
     /**** VP creation (end) ********************************************/
 
     // get final data from drivers
     DBUG_PRINT("backup_data",("-- FINISH PHASE --"));
-    BACKUP_BREAKPOINT("data_finish");
 
     while (sch.finish_count > 0)
     if (sch.step())
@@ -1569,6 +1560,8 @@ int restore_table_data(THD*, Restore_inf
       DBUG_PRINT("restore",("state is %d", state));
   }
 
+  DEBUG_SYNC(::current_thd, "restore_table_data_before_end");
+  
   { // Shutting down drivers
 
     String bad_drivers;

=== removed file 'sql/backup/debug.h'
--- a/sql/backup/debug.h	2008-03-19 09:18:57 +0000
+++ b/sql/backup/debug.h	1970-01-01 00:00:00 +0000
@@ -1,231 +0,0 @@
-#ifndef _BACKUP_DEBUG_H
-#define _BACKUP_DEBUG_H
-
-#define BACKUP_BREAKPOINT_TIMEOUT 300
-
-/*
-  TODO
-  - decide how to configure DEBUG_BACKUP
- */
-
-#ifndef DBUG_OFF
-# define DBUG_BACKUP
-#endif
-
-
-/**
-  @page BACKUP_BREAKPOINT Online Backup Breakpoints
-  Macros for creating breakpoints during testing.
-
-  @section WHAT What are breakpoints?
-  Breakpoints are devices used to pause the execution of the backup system
-  at a certain point in the code. There is a timeout that you can specify
-  when you set the lock for the breakpoint (from get_lock() see below)
-  which will enable execution to continue after the period in seconds
-  expires.
-
-  The best use of these breakpoints is for pausing execution at critical
-  points in the backup code to allow proper testing of certain features.
-  For example, suppose you wanted to ensure the Consistent Snapshot driver
-  was working properly. To do so, you would need to ensure no new @INSERT
-  statements are executed while the data is being backed up. If you use
-  a breakpoint, you can set the breakpoint to pause the backup kernel at
-  the point where it has set the consistent read and is reading rows.
-  You can then insert some rows and release the breakpoint. The result
-  should contain all of the rows in the table except those that were
-  inserted once the consistent read was set.
-
-  @section USAGE How to use breakpoints.
-  To make a breakpoint available, you must add a macro call to the code.
-  Simply insert the macro call as follows. The @c breakpoint_name is a 
-  text string that must be unique among the breakpoints. It is used in 
-  the macro as a means of tagging the code for pausing and resuming
-  execution. Once the code is compiled, you can use a client connection
-  to set and release the breakpoint. Be sure to use a separate connection
-  for getting, checking, and releasing locks. 
-
-  <b><c>BACKUP_BREAKPOINT("<breakpoint_name>");</c></b>
-  
-  Breakpoints use the user-defined locking functions @c get_lock() to set
-  the breakpoint and @c release_lock() to release it.
-
-  @subsection SET Setting breakpoints.
-  To set an existing breakpoint, issue the following command where @c
-  timeout is the number of seconds execution will pause once the breakpoint
-  is reached before continuing execution.
-
-  <b><c>SELECT get_lock("<breakpoint_name>",<timeout>);</c></b>
-
-  @subsection RELEASE Releasing breakpoints.
-  To release an existing breakpoint, issue the following command. This
-  releases execution allow the system to continue.
-
-  <b><c>SELECT release_lock("<breakpoint_name>");</c></b>
-
-  @subsection EXAMPLE Example - Testing the Consistent Snapshot Driver
-  To test the consistent snapshot driver, we can make use of the @c
-  backup_cs_locked breakpoint to pause execution after the consistent read
-  is initiated and before all of the rows from the table have been read.
-  Consider an InnoDB table with the following structure as our test table.
-
-  <c>CREATE TABLE t1 (a INT) ENGINE=INNODB;</c>
-
-  To perform this test using breakpoints, we need two client connections.
-  One will be used to execute the backup command and another to set and
-  release the breakpoint. In the first client, we set the breakpoint with
-  the <c>SELECT get_lock("backup_cs_locked", 100);</c> command. In the 
-  second client, we start the execution of the backup. We can return to
-  the first client and issue several @INSERT statements then issue the
-  <c>SELECT release_lock("backup_cs_locked");</c> command to release the
-  breakpoint.
-
-  We can then return to the second client, select all of the rows from the
-  table to verify the rows were inserted. We can verify that the consistent
-  snapshot worked by restoring the database (which is a destructive restore)
-  and then select all of the rows. This will show that the new rows 
-  inserted while the backup was running were not inserted into the table.
-  The following shows the output of the commands as described.
-
-  <b>First Client</b>
-  @code mysql> SELECT * FROM t1;
-  +---+
-  | a |
-  +---+
-  | 1 |
-  | 2 |
-  | 3 |
-  +---+
-  3 rows in set (0.00 sec)
-
-  mysql> SELECT get_lock("backup_cs_locked", 100);
-  +-----------------------------------+
-  | get_lock("backup_cs_locked", 100) |
-  +-----------------------------------+
-  |                                 1 |
-  +-----------------------------------+
-  1 row in set (0.00 sec) @endcode
-
-  <b>Second Client</b>
-  @code mysql> BACKUP DATABASE test TO 'test.bak'; @endcode
-
-  Note: The backup will pause while the breakpoint is set (the lock is held).
-
-  <b>First Client</b>
-  @code mysql> INSERT INTO t1 VALUES (101), (102), (103);
-  Query OK, 3 rows affected (0.02 sec)
-  Records: 3  Duplicates: 0  Warnings: 0
-
-  mysql> SELECT * FROM t1;
-  +-----+
-  | a   |
-  +-----+
-  |   1 |
-  |   2 |
-  |   3 |
-  | 101 |
-  | 102 |
-  | 103 |
-  +-----+
-  6 rows in set (0.00 sec)
-  
-  mysql> SELECT release_lock("backup_cs_locked");
-  +----------------------------------+
-  | release_lock("backup_cs_locked") |
-  +----------------------------------+
-  |                                1 |
-  +----------------------------------+
-  1 row in set (0.01 sec) @endcode
-
-  <b>Second Client</b>
-  @code +------------------------------+
-  | Backup Summary               |
-  +------------------------------+
-  |  header     =       14 bytes |
-  |  meta-data  =      120 bytes |
-  |  data       =       30 bytes |
-  |               -------------- |
-  |  total             164 bytes |
-  +------------------------------+
-  5 rows in set (33.45 sec)
-
-  mysql> SELECT * FROM t1;
-  +-----+
-  | a   |
-  +-----+
-  |   1 |
-  |   2 |
-  |   3 |
-  | 101 |
-  | 102 |
-  | 103 |
-  +-----+
-  6 rows in set (0.00 sec)
-  
-  mysql> RESTORE FROM 'test.bak';
-  +------------------------------+
-  | Restore Summary              |
-  +------------------------------+
-  |  header     =       14 bytes |
-  |  meta-data  =      120 bytes |
-  |  data       =       30 bytes |
-  |               -------------- |
-  |  total             164 bytes |
-  +------------------------------+
-  5 rows in set (0.08 sec)
-  
-  mysql> SELECT * FROM t1;
-  +---+
-  | a |
-  +---+
-  | 1 |
-  | 2 |
-  | 3 |
-  +---+
-  3 rows in set (0.00 sec)@endcode
-
-  Note: The backup will complete once breakpoint is released (the lock is
-  released).
-
-  @section BREAKPOINTS Breakpoints
-  The following are the available breakpoints included in the code.
-
-  - <b>backup_command</b>  Occurs at the start of the backup operation.
-  - <b>data_init</b>  Occurs at the start of the <b>INITIALIZE PHASE</b>.
-  - <b>data_prepare</b>  Occurs at the start of the <b>PREPARE PHASE</b>.
-  - <b>data_lock</b>  Occurs at the start of the <b>SYNC PHASE</b>.
-  - <b>data_unlock</b>  Occurs before the unlock calls.
-  - <b>data_finish</b>  Occurs at the start of the <b>FINISH PHASE</b>.
-  - <b>backup_meta</b>  Occurs before the call to write_meta_data().
-  - <b>backup_data</b>  Occurs before the call to write_table_data().
-  - <b>backup_done</b>  Occurs after the call to write_table_data() returns.
-  - <b>backup_cs_locked</b>  Consistent Snapshot - after the consistent
-                             read has been initiated but before rows are read.
-  - <b>backup_cs_open_tables</b>  Consistent Snapshot - before the call to
-                             open and lock tables.
-  - <b>backup_cs_reading</b>  Consistent Snapshot - occurs during read.
-
-  @section NOTES Developer Notes
-  - Breakpoints can be used in debug builds only. You must compile
-  the code using the @c DEBUG_EXTRA preprocessor directive. 
-  - When adding breakpoints, you must add a list item for each breakpoint
-  to the documentation for breakpoints. See the code for the macro
-  definition in @ref debug.h for details.
-  - You must use a dedicated connection for getting and releasing locks. Do
-  not issue a get_lock() or release_lock() in the same connection (thread) as
-  code that calls BACKUP_BREAKPOINT(). Using the same connection to get/release
-  locks and run code that issues BACKUP_BREAKPOINTs will result in an
-  assertion using DEBUG_ASSERT(thd->ull == NULL) from debug_sync_point() in
-  item_func.cc.
-
- */
-
-/*
-  Consider: set thd->proc_info when waiting on lock
-*/
-#define BACKUP_BREAKPOINT(S) \
- do { \
-  DBUG_PRINT("backup",("== breakpoint on '%s' ==",(S))); \
-  DBUG_EXECUTE_IF("backup_debug", DBUG_SYNC_POINT((S),BACKUP_BREAKPOINT_TIMEOUT);); \
- } while (0)
-
-#endif

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2008-05-21 10:45:55 +0000
+++ b/sql/backup/kernel.cc	2008-06-26 16:20:30 +0000
@@ -69,7 +69,6 @@
 #include "restore_info.h"
 #include "logger.h"
 #include "stream.h"
-#include "debug.h"
 #include "be_native.h"
 #include "be_default.h"
 #include "be_snapshot.h"
@@ -127,8 +126,6 @@ execute_backup_command(THD *thd, LEX *le
   DBUG_ENTER("execute_backup_command");
   DBUG_ASSERT(thd && lex);
 
-  BACKUP_BREAKPOINT("backup_command");
-
   using namespace backup;
 
   Backup_restore_ctx context(thd); // reports errors
@@ -142,13 +139,14 @@ execute_backup_command(THD *thd, LEX *le
   {
     // prepare for backup operation
     
-    Backup_info *info= context.prepare_for_backup(lex->backup_dir, thd->query);
+    Backup_info *info= context.prepare_for_backup(lex->backup_dir, thd->query,
+                                                  lex->backup_compression);
                                                               // reports errors
 
     if (!info || !info->is_valid())
       DBUG_RETURN(send_error(context, ER_BACKUP_BACKUP_PREPARE));
 
-    BACKUP_BREAKPOINT("bp_running_state");
+    DEBUG_SYNC(thd, "after_backup_start_backup");
 
     // select objects to backup
 
@@ -181,7 +179,6 @@ execute_backup_command(THD *thd, LEX *le
     if (res)
       DBUG_RETURN(send_error(context, ER_BACKUP_BACKUP));
 
-    BACKUP_BREAKPOINT("bp_complete_state");
     break;
   }
 
@@ -192,7 +189,7 @@ execute_backup_command(THD *thd, LEX *le
     if (!info || !info->is_valid())
       DBUG_RETURN(send_error(context, ER_BACKUP_RESTORE_PREPARE));
     
-    BACKUP_BREAKPOINT("bp_running_state");
+    DEBUG_SYNC(thd, "after_backup_start_restore");
 
     res= context.do_restore();      
 
@@ -447,6 +444,7 @@ int Backup_restore_ctx::prepare(LEX_STRI
   
   @param[in] location   path to the file where backup image should be stored
   @param[in] query      BACKUP query starting the operation
+  @param[in] with_compression  backup image compression switch
   
   @returns Pointer to a @c Backup_info instance which can be used for selecting
   which objects to backup. NULL if an error was detected.
@@ -459,7 +457,8 @@ int Backup_restore_ctx::prepare(LEX_STRI
   is performed using @c do_backup() method.
  */ 
 Backup_info* 
-Backup_restore_ctx::prepare_for_backup(LEX_STRING location, const char *query)
+Backup_restore_ctx::prepare_for_backup(LEX_STRING location, const char *query,
+                                       bool with_compression)
 {
   using namespace backup;
   
@@ -488,7 +487,7 @@ Backup_restore_ctx::prepare_for_backup(L
     Open output stream.
    */
 
-  Output_stream *s= new Output_stream(*this, path);
+  Output_stream *s= new Output_stream(*this, path, with_compression);
   
   if (!s)
   {
@@ -734,8 +733,6 @@ int Backup_restore_ctx::do_backup()
   Output_stream &s= *static_cast<Output_stream*>(m_stream);
   Backup_info   &info= *static_cast<Backup_info*>(m_catalog);
 
-  BACKUP_BREAKPOINT("backup_meta");
-
   report_stats_pre(info);
 
   DBUG_PRINT("backup",("Writing preamble"));
@@ -748,8 +745,6 @@ int Backup_restore_ctx::do_backup()
 
   DBUG_PRINT("backup",("Writing table data"));
 
-  BACKUP_BREAKPOINT("backup_data");
-
   if (write_table_data(m_thd, info, s)) // reports errors
     DBUG_RETURN(send_error(*this, ER_BACKUP_BACKUP));
 
@@ -764,11 +759,85 @@ int Backup_restore_ctx::do_backup()
   report_stats_post(info);
 
   DBUG_PRINT("backup",("Backup done."));
-  BACKUP_BREAKPOINT("backup_done");
 
   DBUG_RETURN(0);
 }
 
+/**
+  Create all triggers and events from restore catalogue.
+
+  This helper method iterates over all triggers and events stored in the 
+  restore catalogue and creates them. When metadata section of the backup image 
+  is read, trigger and event objects are materialized and stored in the 
+  catalogue but they are not executed then (see @c bcat_create_item()). 
+  This method can be used to re-create the corresponding server objects after 
+  all other objects and table data have been restored.
+
+  Note that we first restore all triggers and then the events.
+
+  @returns 0 on success, error code otherwise.
+*/ 
+int Backup_restore_ctx::restore_triggers_and_events()
+{
+  using namespace backup;
+
+  DBUG_ASSERT(m_catalog);
+
+  Image_info::Iterator *dbit= m_catalog->get_dbs();
+  Image_info::Obj *obj;
+  List<Image_info::Obj> events;
+  Image_info::Obj::describe_buf buf;
+
+  DBUG_ENTER("restore_triggers_and_events");
+
+  // create all trigers and collect events in the events list
+  
+  while ((obj= (*dbit)++)) 
+  {
+    Image_info::Iterator *it= 
+                    m_catalog->get_db_objects(*static_cast<Image_info::Db*>(obj));
+
+    while ((obj= (*it)++))
+      switch (obj->type()) {
+      
+      case BSTREAM_IT_EVENT:
+        DBUG_ASSERT(obj->m_obj_ptr);
+        events.push_back(obj);
+        break;
+      
+      case BSTREAM_IT_TRIGGER:
+        DBUG_ASSERT(obj->m_obj_ptr);
+        if (obj->m_obj_ptr->execute(m_thd))
+        {
+          delete it;
+          delete dbit;
+          fatal_error(ER_BACKUP_CANT_RESTORE_TRIGGER,obj->describe(buf));
+          DBUG_RETURN(m_error);
+        }
+        break;
+
+      default: break;      
+      }
+
+    delete it;
+  }
+
+  delete dbit;
+
+  // now create all events
+
+  List_iterator<Image_info::Obj> it(events);
+  Image_info::Obj *ev;
+
+  while ((ev= it++)) 
+    if (ev->m_obj_ptr->execute(m_thd))
+    {
+      fatal_error(ER_BACKUP_CANT_RESTORE_EVENT,ev->describe(buf));
+      DBUG_RETURN(m_error);
+    };
+
+  DBUG_RETURN(0);
+}
 
 /**
   Restore objects saved in backup image.
@@ -830,6 +899,21 @@ int Backup_restore_ctx::do_restore()
     DBUG_RETURN(m_error);
   }
 
+  /* 
+   Re-create all triggers and events (it was not done in @c bcat_create_item()).
+  */
+
+  if (restore_triggers_and_events())
+     DBUG_RETURN(ER_BACKUP_RESTORE);
+  
+  /* 
+    FIXME: this call is here because object services doesn't clean the
+    statement execution context properly, which leads to assertion failure.
+    It should be fixed inside object services implementation and then the
+    following line should be removed.
+   */
+  m_thd->main_da.reset_diagnostics_area();
+
   report_stats_post(info);
 
   DBUG_RETURN(0);
@@ -1436,6 +1520,22 @@ int bcat_create_item(st_bstream_image_he
     return BSTREAM_ERROR;
   }
 
+  /*
+    If the item we are creating is an event or trigger, we don't execute it
+    yet. It will be done in @c Backup_restore_ctx::do_restore() after table
+    data has been restored.
+   */ 
+  
+  switch (item->type) {
+
+  case BSTREAM_IT_EVENT:
+  case BSTREAM_IT_TRIGGER:
+    return BSTREAM_OK;
+
+  default: break;
+  
+  }
+
   // If we are to create a tablespace, first check if it already exists.
 
   if (item->type == BSTREAM_IT_TABLESPACE)

=== modified file 'sql/backup/logger.h'
--- a/sql/backup/logger.h	2008-03-21 09:57:45 +0000
+++ b/sql/backup/logger.h	2008-06-25 13:39:04 +0000
@@ -1,9 +1,9 @@
 #ifndef _BACKUP_LOGGER_H
 #define _BACKUP_LOGGER_H
 
+#include "mysql_priv.h"
 #include <backup_stream.h>
 #include <backup/error.h>
-#include <backup/debug.h>
 #include <backup/backup_progress.h>
 
 
@@ -130,7 +130,7 @@ int Logger::init(enum_type type, const L
   m_op_id= report_ob_init(m_thd, m_thd->id, BUP_STARTING, 
                           type == BACKUP ? OP_BACKUP : OP_RESTORE, 
                           0, "", path.str, query);  
-  BACKUP_BREAKPOINT("bp_starting_state");
+  DEBUG_SYNC(m_thd, "after_backup_log_init");
   return 0;
 }
 

=== modified file 'sql/backup/stream.cc'
--- a/sql/backup/stream.cc	2008-03-04 16:06:28 +0000
+++ b/sql/backup/stream.cc	2008-06-26 10:38:48 +0000
@@ -3,6 +3,10 @@
 #include "backup_stream.h"
 #include "stream.h"
 
+#ifdef HAVE_COMPRESS
+#define ZBUF_SIZE 65536 // compression I/O buffer size
+#endif
+
 const unsigned char backup_magic_bytes[8]=
 {
   0xE0, // ###.....
@@ -23,6 +27,8 @@ namespace backup {
   Pointer to this function is stored in @c backup_stream::stream structure
   and then used by other stream library function for physical writing of
   data.
+
+  Performs stream compression if requested.
 */
 extern "C" int stream_write(void *instance, bstream_blob *buf, bstream_blob)
 {
@@ -46,12 +52,34 @@ extern "C" int stream_write(void *instan
   DBUG_ASSERT(buf->end);
 
   size_t howmuch = buf->end - buf->begin;
+#ifdef HAVE_COMPRESS
+  if (s->m_with_compression)
+  {
+    z_stream *zstream= &s->zstream;
+    zstream->next_in= buf->begin;
+    zstream->avail_in= howmuch;
+    do
+    {
+      if (!zstream->avail_out)
+      {
+        if (my_write(fd, s->zbuf, ZBUF_SIZE, MYF(MY_NABP)))
+          DBUG_RETURN(BSTREAM_ERROR);
+        zstream->next_out= s->zbuf;
+        zstream->avail_out= ZBUF_SIZE;
+      }
+      if (deflate(zstream, Z_NO_FLUSH) != Z_OK)
+        DBUG_RETURN(BSTREAM_ERROR);
+    } while (zstream->avail_in);
+  }
+  else
+#endif
+  {
+    res= my_write(fd, buf->begin, howmuch,
+                  MY_NABP /* error if not all bytes written */ );
 
-  res= my_write(fd, buf->begin, howmuch,
-                MY_NABP /* error if not all bytes written */ );
-
-  if (res)
-    DBUG_RETURN(BSTREAM_ERROR);
+    if (res)
+      DBUG_RETURN(BSTREAM_ERROR);
+  }
 
   s->bytes += howmuch;
 
@@ -65,6 +93,8 @@ extern "C" int stream_write(void *instan
   Pointer to this function is stored in @c backup_stream::stream structure
   and then used by other stream library function for physical reading of
   data.
+
+  Performs stream decompression if requested.
 */
 extern "C" int stream_read(void *instance, bstream_blob *buf, bstream_blob)
 {
@@ -88,8 +118,40 @@ extern "C" int stream_read(void *instanc
   DBUG_ASSERT(buf->end);
 
   howmuch= buf->end - buf->begin;
-
-  howmuch= my_read(fd, buf->begin, howmuch, MYF(0));
+#ifdef HAVE_COMPRESS
+  if (s->m_with_compression)
+  {
+    int zerr;
+    z_stream *zstream= &s->zstream;
+    zstream->next_out= buf->begin;
+    zstream->avail_out= howmuch;
+    do
+    {
+      if (!zstream->avail_in)
+      {
+        zstream->avail_in= my_read(fd, s->zbuf, ZBUF_SIZE, MYF(0));
+        if (zstream->avail_in == (size_t) -1)
+          DBUG_RETURN(BSTREAM_ERROR);
+        else if (!zstream->avail_in)
+          break;
+        zstream->next_in= s->zbuf;
+      }
+      zerr= inflate(zstream, Z_NO_FLUSH);
+      if (zerr == Z_STREAM_END)
+      {
+        howmuch= zstream->next_out - buf->begin;
+        break;
+      }
+      else if (zerr != Z_OK)
+        DBUG_RETURN(BSTREAM_ERROR);
+      howmuch= zstream->next_out - buf->begin;
+    } while (zstream->avail_out);
+  }
+  else
+#endif
+  {
+    howmuch= my_read(fd, buf->begin, howmuch, MYF(0));
+  }
 
   /*
    How to detect EOF when reading bytes with my_read().
@@ -142,13 +204,20 @@ void Stream::close()
 
 bool Stream::rewind()
 {
+#ifdef HAVE_COMPRESS
+  /* Compressed stream cannot be rewound */
+  if (m_with_compression)
+    return FALSE;
+#endif
   return m_fd >= 0 && my_seek(m_fd, 0, SEEK_SET, MYF(0)) == 0;
 }
 
 
-Output_stream::Output_stream(Logger &log, const ::String &name)
+Output_stream::Output_stream(Logger &log, const ::String &name,
+                             bool with_compression)
   :Stream(log, name, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC)
 {
+  m_with_compression= with_compression;
   stream.write= stream_write;
   m_block_size=0; // use default block size provided by the backup stram library
 }
@@ -163,7 +232,7 @@ Output_stream::Output_stream(Logger &log
 int Output_stream::write_magic_and_version()
 {
   byte buf[10];
-
+  bstream_blob blob;
   DBUG_ASSERT(m_fd >= 0);
 
   memmove(buf, backup_magic_bytes, 8);
@@ -171,9 +240,10 @@ int Output_stream::write_magic_and_versi
   buf[8]= 0x01;
   buf[9]= 0x00;
 
-  int ret= my_write(m_fd, buf, 10,
-                    MY_NABP /* error if not all bytes written */ );
-  if (ret)
+  blob.begin= buf;
+  blob.end= buf + 10;
+  int ret= stream_write((fd_stream*)this, &blob, blob);
+  if (ret != BSTREAM_OK)
     return -1; // error when writing magic bytes
   else
     return 10;
@@ -221,6 +291,35 @@ bool Output_stream::open()
   if (!ret)
     return FALSE;
 
+  if (m_with_compression)
+  {
+#ifdef HAVE_COMPRESS
+    int zerr;
+    if (!(zbuf= (uchar*) my_malloc(ZBUF_SIZE, MYF(0))))
+    {
+      m_log.report_error(ER_OUTOFMEMORY, ZBUF_SIZE);
+      return FALSE;
+    }
+    zstream.zalloc= 0;
+    zstream.zfree= 0;
+    zstream.opaque= 0;
+    zstream.msg= 0;
+    zstream.next_out= zbuf;
+    zstream.avail_out= ZBUF_SIZE;
+    if ((zerr= deflateInit2(&zstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
+                            MAX_WBITS + 16, MAX_MEM_LEVEL,
+                            Z_DEFAULT_STRATEGY) != Z_OK))
+    {
+      m_log.report_error(ER_BACKUP_FAILED_TO_INIT_COMPRESSION,
+                         zerr, zstream.msg);
+      return FALSE;
+    }
+#else
+    m_log.report_error(ER_FEATURE_DISABLED, "compression", "--with-zlib-dir");
+    return FALSE;
+#endif
+  }
+
   return init();
 }
 
@@ -235,6 +334,34 @@ void Output_stream::close()
     return;
 
   bstream_close(this);
+#ifdef HAVE_COMPRESS
+  if (m_with_compression)
+  {
+    int zerr;
+    zstream.avail_in= 0;
+    zstream.next_in= 0;
+    do
+    {
+      zerr= deflate(&zstream, Z_FINISH);
+      if (zerr != Z_STREAM_END && zerr != Z_OK)
+      {
+        m_log.report_error(ER_GET_ERRMSG, zerr, zstream.msg, "deflate");
+        break;
+      }
+      if (my_write(m_fd, zbuf, ZBUF_SIZE - zstream.avail_out,
+                   MYF(MY_NABP)))
+      {
+        m_log.report_error(ER_GET_ERRMSG, my_errno, "", "my_write");
+        break;
+      }
+      zstream.next_out= zbuf;
+      zstream.avail_out= ZBUF_SIZE;
+    } while (zerr != Z_STREAM_END);
+    if ((zerr= deflateEnd(&zstream)) != Z_OK)
+      m_log.report_error(ER_GET_ERRMSG, zerr, zstream.msg, "deflateEnd");
+    my_free(zbuf, MYF(0));
+  }
+#endif
   Stream::close();
 }
 
@@ -261,6 +388,7 @@ bool Output_stream::rewind()
 Input_stream::Input_stream(Logger &log, const ::String &name)
   :Stream(log, name, O_RDONLY)
 {
+  m_with_compression= false;
   stream.read= stream_read;
 }
 
@@ -274,19 +402,12 @@ Input_stream::Input_stream(Logger &log, 
 */
 int Input_stream::check_magic_and_version()
 {
-  byte buf[10];
-
   DBUG_ASSERT(m_fd >= 0);
 
-  int ret= my_read(m_fd, buf, 10,
-                   MY_NABP /* error if not all bytes read */ );
-  if (ret)
-    return -1; // couldn't read magic bytes
-
-  if (memcmp(buf, backup_magic_bytes, 8))
+  if (memcmp(m_header_buf, backup_magic_bytes, 8))
     return -1; // wrong magic bytes
 
-  unsigned int ver = buf[8] + (buf[9]<<8);
+  unsigned int ver = m_header_buf[8] + (m_header_buf[9]<<8);
 
   if (ver != 1)
     return -1; // unsupported format version
@@ -321,6 +442,14 @@ bool Input_stream::init()
 /**
   Open backup stream for reading.
 
+  @details This method can detect and open compressed streams. In that case
+  stream is initialized for decompression so that stream_read() function will
+  return decompressed data.
+
+  The first 10 bytes in the stream (whether compressed or not) are not
+  available for reading with stream_read(). Instead, they are stored in
+  m_header_buf member and examined by check_magic_and_version().
+
   @retval TRUE  operation succeeded
   @retval FALSE operation failed
 
@@ -335,6 +464,42 @@ bool Input_stream::open()
   if (!ret)
     return FALSE;
 
+  if (my_read(m_fd, m_header_buf, sizeof(m_header_buf),
+              MY_NABP /* error if not all bytes read */ ))
+    return FALSE;
+
+#ifdef HAVE_COMPRESS
+  if (!memcmp(m_header_buf, "\x1f\x8b\x08", 3))
+  {
+    int zerr;
+    bstream_blob blob;
+    if (!(zbuf= (uchar*) my_malloc(ZBUF_SIZE, MYF(0))))
+    {
+      m_log.report_error(ER_OUTOFMEMORY, ZBUF_SIZE);
+      return FALSE;
+    }
+    zstream.zalloc= 0;
+    zstream.zfree= 0;
+    zstream.opaque= 0;
+    zstream.msg= 0;
+    zstream.next_in= zbuf;
+    zstream.avail_in= 10;
+    memcpy(zbuf, m_header_buf, 10);
+    if ((zerr= inflateInit2(&zstream, MAX_WBITS + 16)) != Z_OK)
+    {
+      m_log.report_error(ER_GET_ERRMSG, zerr, zstream.msg, "inflateInit2");
+      my_free(zbuf, MYF(0));
+      return FALSE;
+    }
+    m_with_compression= true;
+    blob.begin= m_header_buf;
+    blob.end= m_header_buf + 10;
+    if (stream_read((fd_stream*) this, &blob, blob) != BSTREAM_OK ||
+        blob.begin != blob.end)
+      return FALSE;
+  }
+#endif
+
   return init();
 }
 
@@ -349,6 +514,15 @@ void Input_stream::close()
     return;
 
   bstream_close(this);
+#ifdef HAVE_COMPRESS
+  if (m_with_compression)
+  {
+    int zerr;
+    if ((zerr= inflateEnd(&zstream)) != Z_OK)
+      m_log.report_error(ER_GET_ERRMSG, zerr, zstream.msg, "inflateEnd");
+    my_free(zbuf, (MYF(0)));
+  }
+#endif
   Stream::close();
 }
 

=== modified file 'sql/backup/stream.h'
--- a/sql/backup/stream.h	2008-03-04 16:06:28 +0000
+++ b/sql/backup/stream.h	2008-06-26 16:20:30 +0000
@@ -5,8 +5,10 @@
 
 #include <backup/api_types.h>    // for Buffer definition
 #include <backup/image_info.h>
-#include <backup/debug.h>        // for definition of DBUG_BACKUP
 #include <backup/logger.h>
+#ifdef HAVE_COMPRESS
+#include <zlib.h>
+#endif
 
 /**
   @file
@@ -55,6 +57,12 @@ struct fd_stream: public backup_stream
 {
   int m_fd;
   size_t bytes;
+  uchar m_header_buf[10];
+  bool m_with_compression;
+#ifdef HAVE_COMPRESS
+  z_stream zstream;
+  uchar *zbuf;
+#endif
   
   fd_stream() :m_fd(-1), bytes(0) {}
 };
@@ -101,7 +109,7 @@ class Output_stream:
 {
  public:
 
-  Output_stream(Logger&, const ::String&);
+  Output_stream(Logger&, const ::String&, bool);
 
   bool open();
   void close();

=== modified file 'sql/backup/stream_v1_transport.c'
--- a/sql/backup/stream_v1_transport.c	2007-12-03 20:28:32 +0000
+++ b/sql/backup/stream_v1_transport.c	2008-06-25 13:40:49 +0000
@@ -696,7 +696,7 @@ int load_buffer(backup_stream *s)
     for (i= 0; i<4; ++i)
     {
       block_size >>= 8;
-      block_size |= (*(s->buf.begin++)) << 3*8;
+      block_size |= ((unsigned long int) *(s->buf.begin++)) << 3 * 8;
     }
 
     /*
@@ -1480,7 +1480,10 @@ int bstream_read_part(backup_stream *s, 
     saved= *data;
     data->end= data->begin + howmuch;
 
-    as_read(&s->stream,data,buf);
+    if (as_read(&s->stream, data, buf) == BSTREAM_EOS)
+    {
+      s->state= EOS;
+    }
 
     s->buf.begin += data->begin - saved.begin;
     s->buf.pos= s->buf.begin;

=== modified file 'sql/ddl_blocker.cc'
--- a/sql/ddl_blocker.cc	2007-12-12 20:13:31 +0000
+++ b/sql/ddl_blocker.cc	2008-06-25 13:39:04 +0000
@@ -110,7 +110,7 @@ void DDL_blocker_class::end_DDL()
 my_bool DDL_blocker_class::check_DDL_blocker(THD *thd)
 {
   DBUG_ENTER("check_DDL_blocker()");
-  BACKUP_BREAKPOINT("DDL_not_blocked");
+  DEBUG_SYNC(thd, "before_check_ddl_blocked");
 
   /*
     Check the ddl blocker condition. Rest until ddl blocker is released.
@@ -122,7 +122,7 @@ my_bool DDL_blocker_class::check_DDL_blo
     pthread_cond_wait(&COND_DDL_blocker, &THR_LOCK_DDL_is_blocked);
   start_DDL();
   thd->exit_cond("DDL blocker: Ok to run DDL");
-  BACKUP_BREAKPOINT("DDL_in_progress");
+  DEBUG_SYNC(thd, "after_start_ddl");
   DBUG_RETURN(TRUE);
 }
 
@@ -143,7 +143,7 @@ my_bool DDL_blocker_class::block_DDL(THD
 {
   DBUG_ENTER("block_DDL()");
 
-  BACKUP_BREAKPOINT("DDL_in_progress");
+  DEBUG_SYNC(thd, "before_block_ddl");
 
   /*
     Only 1 DDL blocking operation can run at a time.
@@ -159,8 +159,6 @@ my_bool DDL_blocker_class::block_DDL(THD
   DDL_blocked= TRUE;
   thd->exit_cond("DDL blocker: Ok to block DDL");
 
-  BACKUP_BREAKPOINT("DDL_blocker_blocked");
-
   /*
     Check the ddl blocker condition. Rest until ddl blocker is released.
   */
@@ -171,7 +169,7 @@ my_bool DDL_blocker_class::block_DDL(THD
     pthread_cond_wait(&COND_process_blocked, &THR_LOCK_DDL_blocker);
   thd->exit_cond("DDL blocker: DDL is now blocked");
 
-  BACKUP_BREAKPOINT("DDL_blocked");
+  DEBUG_SYNC(thd, "after_block_ddl");
   DBUG_RETURN(TRUE);
 }
 

=== modified file 'sql/ddl_blocker.h'
--- a/sql/ddl_blocker.h	2007-12-12 20:13:31 +0000
+++ b/sql/ddl_blocker.h	2008-06-25 13:39:04 +0000
@@ -4,7 +4,6 @@
   Header file for DDL blocker code.
  */
 #include "mysql_priv.h"
-#include "backup/debug.h"
 
 /**
    @class DDL_blocker_class

=== modified file 'sql/debug_sync.cc'
--- a/sql/debug_sync.cc	2008-05-28 15:25:24 +0000
+++ b/sql/debug_sync.cc	2008-06-25 13:39:04 +0000
@@ -259,7 +259,7 @@ struct st_debug_sync_globals
 static st_debug_sync_globals debug_sync_global; /* All globals in one object */
 
 /**
-  Callback pointer from thr_lock.cc
+  Callback pointer from thr_lock.c
 */
 extern "C" void (*debug_sync_wait_for_lock_callback_ptr)(void);
 
@@ -1562,15 +1562,24 @@ static void debug_sync_execute(THD *thd,
   {
     action->execute--;
 
+    /*
+      Protect copying of the signal string to the global string
+      to avoid race conditions during test case development.
+      After approaching a clean test case it should not happen
+      that two threads try to signal at the same time.
+
+      Do also acquire the mutex for a WAIT_FOR action. The sense is to
+      clamp SIGNAL and WAIT_FOR in the mutex. If we wake another thread
+      with the signal, it should not run until we set PROC_INFO in
+      enter_cond().
+
+      Note. When 'execute' is non-zero, at least one of SIGNAL, WAIT_FOR
+      is set.
+    */
+    pthread_mutex_lock(&debug_sync_global.ds_mutex);
+
     if (action->signal.length())
     {
-      /*
-        Protect copying of the signal string to the global string
-        to avoid race conditions during test case development.
-        After approaching a clean test case it should not happen
-        that two threads try to signal at the same time.
-      */
-      pthread_mutex_lock(&debug_sync_global.ds_mutex);
       /* Copy the signal to the global variable. */
       if (debug_sync_global.ds_signal.copy(action->signal))
       {
@@ -1585,8 +1594,6 @@ static void debug_sync_execute(THD *thd,
       DBUG_PRINT("debug_sync_exec", ("signal '%s'  at: '%s'",
                                      action->signal.c_ptr(),
                                      action->sync_point.c_ptr()));
-      pthread_mutex_unlock(&debug_sync_global.ds_mutex);
-
     } /* end if (action->signal.length()) */
 
     if (action->wait_for.length())
@@ -1594,11 +1601,13 @@ static void debug_sync_execute(THD *thd,
       const char      *old_proc_info;
       int             error= 0;
       struct timespec abstime;
+      String          proc_info;
 
-      pthread_mutex_lock(&debug_sync_global.ds_mutex);
+      proc_info.set("debug sync point: ", 18, system_charset_info);
+      proc_info.append(action->sync_point);
       old_proc_info= thd->enter_cond(&debug_sync_global.ds_cond,
                                      &debug_sync_global.ds_mutex,
-                                     action->sync_point.c_ptr());
+                                     proc_info.c_ptr());
 
       set_timespec(abstime, action->timeout);
       DBUG_PRINT("debug_sync_exec", ("wait for '%s'  at: '%s'  curr: '%s'",
@@ -1631,9 +1640,15 @@ static void debug_sync_execute(THD *thd,
                                      action->wait_for.c_ptr(),
                                      action->sync_point.c_ptr()));
 
+      /* exit_cond() does also unlock the mutex. */
       thd->exit_cond(old_proc_info);
 
     } /* end if (action->wait_for.length()) */
+    else
+    {
+      /* Need explicit unlock of mutex as we don't use exit_cond() here. */
+      pthread_mutex_unlock(&debug_sync_global.ds_mutex);
+    }
 
   } /* end if (action->execute) */
 

=== modified file 'sql/handler.cc'
--- a/sql/handler.cc	2008-05-18 08:52:30 +0000
+++ b/sql/handler.cc	2008-06-25 13:39:04 +0000
@@ -27,7 +27,6 @@
 #include "rpl_filter.h"
 #include <myisampack.h>
 #include <errno.h>
-#include "backup/debug.h"
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
@@ -1104,10 +1103,7 @@ int ha_commit_trans(THD *thd, bool all)
       goto end;
     }
 
-    /*
-      Breakpoints for backup testing.
-    */
-    BACKUP_BREAKPOINT("commit_blocker_step_1");
+    DEBUG_SYNC(thd, "within_ha_commit_trans");
 
     if (!trans->no_2pc && (rw_ha_count > 1))
     {

=== modified file 'sql/lex.h'
--- a/sql/lex.h	2008-04-01 15:13:57 +0000
+++ b/sql/lex.h	2008-06-25 13:30:04 +0000
@@ -119,6 +119,8 @@ static SYMBOL symbols[] = {
   { "COMPACT",		SYM(COMPACT_SYM)},
   { "COMPLETION",	SYM(COMPLETION_SYM)},
   { "COMPRESSED",	SYM(COMPRESSED_SYM)},
+  { "COMPRESSION",      SYM(COMPRESSION_SYM)},
+  { "COMPRESSION_ALGORITHM", SYM(COMPRESSION_ALGORITHM_SYM)},
   { "CONCURRENT",	SYM(CONCURRENT)},
   { "CONDITION",        SYM(CONDITION_SYM)},
   { "CONNECTION",       SYM(CONNECTION_SYM)},

=== modified file 'sql/lock.cc'
--- a/sql/lock.cc	2008-05-27 19:47:15 +0000
+++ b/sql/lock.cc	2008-06-25 13:39:04 +0000
@@ -1423,9 +1423,33 @@ bool lock_global_read_lock(THD *thd)
   if (!thd->global_read_lock)
   {
     const char *old_message;
+    const char *new_message= "Waiting to get readlock";
     (void) pthread_mutex_lock(&LOCK_global_read_lock);
+
+#if defined(ENABLED_DEBUG_SYNC)
+    /*
+      The below sync point fires if we have to wait for
+      protect_against_global_read_lock.
+
+      WARNING: Beware to use WAIT_FOR with this sync point. We hold
+      LOCK_global_read_lock here.
+
+      Call the sync point before calling enter_cond() as it does use
+      enter_cond() and exit_cond() itself if a WAIT_FOR action is
+      executed in spite of the above warning.
+
+      Pre-set proc_info so that it is available immediately after the
+      sync point sends a SIGNAL. This makes tests more reliable.
+    */
+    if (protect_against_global_read_lock)
+    {
+      thd_proc_info(thd, new_message);
+      DEBUG_SYNC(thd, "wait_lock_global_read_lock");
+    }
+#endif /* defined(ENABLED_DEBUG_SYNC) */
+
     old_message=thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock,
-                                "Waiting to get readlock");
+                                new_message);
     DBUG_PRINT("info",
 	       ("waiting_for: %d  protect_against: %d",
 		waiting_for_read_lock, protect_against_global_read_lock));
@@ -1501,6 +1525,8 @@ bool wait_if_global_read_lock(THD *thd, 
   (void) pthread_mutex_lock(&LOCK_global_read_lock);
   if ((need_exit_cond= must_wait))
   {
+    const char *new_message= "Waiting for release of readlock";
+
     if (thd->global_read_lock)		// This thread had the read locks
     {
       if (is_not_commit)
@@ -1514,8 +1540,31 @@ bool wait_if_global_read_lock(THD *thd, 
       */
       DBUG_RETURN(is_not_commit);
     }
+
+#if defined(ENABLED_DEBUG_SYNC)
+    /*
+      The below sync point fires if we have to wait for
+      global_read_lock.
+
+      WARNING: Beware to use WAIT_FOR with this sync point. We hold
+      LOCK_global_read_lock here.
+
+      Call the sync point before calling enter_cond() as it does use
+      enter_cond() and exit_cond() itself if a WAIT_FOR action is
+      executed in spite of the above warning.
+
+      Pre-set proc_info so that it is available immediately after the
+      sync point sends a SIGNAL. This makes tests more reliable.
+    */
+    if (must_wait)
+    {
+      thd_proc_info(thd, new_message);
+      DEBUG_SYNC(thd, "wait_if_global_read_lock");
+    }
+#endif /* defined(ENABLED_DEBUG_SYNC) */
+
     old_message=thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock,
-				"Waiting for release of readlock");
+                                new_message);
     while (must_wait && ! thd->killed &&
 	   (!abort_on_refresh || thd->version == refresh_version))
     {
@@ -1527,7 +1576,11 @@ bool wait_if_global_read_lock(THD *thd, 
       result=1;
   }
   if (!abort_on_refresh && !result)
+  {
     protect_against_global_read_lock++;
+    DBUG_PRINT("sql_lock", ("protect_against_global_read_lock incr: %u",
+                            protect_against_global_read_lock));
+  }
   /*
     The following is only true in case of a global read locks (which is rare)
     and if old_message is set
@@ -1550,6 +1603,8 @@ void start_waiting_global_read_lock(THD 
   DBUG_ASSERT(protect_against_global_read_lock);
   tmp= (!--protect_against_global_read_lock &&
         (waiting_for_read_lock || global_read_lock_blocks_commit));
+  DBUG_PRINT("sql_lock", ("protect_against_global_read_lock decr: %u",
+                          protect_against_global_read_lock));
   (void) pthread_mutex_unlock(&LOCK_global_read_lock);
   if (tmp)
     pthread_cond_broadcast(&COND_global_read_lock);

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2008-06-04 13:20:03 +0000
+++ b/sql/share/errmsg.txt	2008-06-25 13:30:04 +0000
@@ -6359,4 +6359,5 @@ ER_DEBUG_SYNC_TIMEOUT
 ER_DEBUG_SYNC_HIT_LIMIT
   eng "debug sync point hit limit reached"
   ger "Debug Sync Point Hit Limit erreicht"
-
+ER_BACKUP_FAILED_TO_INIT_COMPRESSION
+  eng "Could not initialize compression of backup image (function deflateInit2 returned error code %d: %-.64s)"

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2008-05-08 16:01:15 +0000
+++ b/sql/slave.cc	2008-06-23 11:55:24 +0000
@@ -4024,6 +4024,7 @@ bool rpl_master_erroneous_autoinc(THD *t
   if (active_mi && active_mi->rli.sql_thd == thd)
   {
     Relay_log_info *rli= &active_mi->rli;
+    DBUG_EXECUTE_IF("simulate_bug33029", return TRUE;);
     return rpl_master_has_bug(rli, 33029, FALSE);
   }
   return FALSE;

=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc	2008-05-27 19:47:15 +0000
+++ b/sql/sql_class.cc	2008-06-25 14:49:43 +0000
@@ -2960,8 +2960,8 @@ void THD::reset_sub_statement_state(Sub_
    */
   if (rpl_master_erroneous_autoinc(this))
   {
-    backup->auto_inc_intervals_forced= auto_inc_intervals_forced;
-    auto_inc_intervals_forced.empty();
+    DBUG_ASSERT(backup->auto_inc_intervals_forced.nb_elements() == 0);
+    auto_inc_intervals_forced.swap(&backup->auto_inc_intervals_forced);
   }
 #endif
   
@@ -3009,8 +3009,8 @@ void THD::restore_sub_statement_state(Su
    */
   if (rpl_master_erroneous_autoinc(this))
   {
-    auto_inc_intervals_forced= backup->auto_inc_intervals_forced;
-    backup->auto_inc_intervals_forced.empty();
+    backup->auto_inc_intervals_forced.swap(&auto_inc_intervals_forced);
+    DBUG_ASSERT(backup->auto_inc_intervals_forced.nb_elements() == 0);
   }
 #endif
 

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2008-05-08 16:01:15 +0000
+++ b/sql/sql_delete.cc	2008-06-25 13:39:04 +0000
@@ -23,7 +23,6 @@
 #include "sql_select.h"
 #include "sp_head.h"
 #include "sql_trigger.h"
-#include "backup/debug.h"
 
 /**
   Implement DELETE SQL word.
@@ -400,13 +399,7 @@ cleanup:
   DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table);
   free_underlaid_joins(thd, select_lex);
 
-  /*
-    Breakpoints for backup testing.
-  */
-  if (!table->file->has_transactions())
-  {
-    BACKUP_BREAKPOINT("backup_commit_blocker");
-  }
+  DEBUG_SYNC(thd, "at_delete_end");
 
   MYSQL_DELETE_END();
   if (error < 0 || (thd->lex->ignore && !thd->is_fatal_error))

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2008-05-27 19:47:15 +0000
+++ b/sql/sql_insert.cc	2008-06-25 13:39:04 +0000
@@ -61,7 +61,6 @@
 #include "sql_show.h"
 #include "slave.h"
 #include "rpl_mi.h"
-#include "backup/debug.h"
 #include "sql_audit.h"
 
 #ifndef EMBEDDED_LIBRARY
@@ -617,11 +616,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *t
   }
   lock_type= table_list->lock_type;
 
-  /*
-    Breakpoints for backup testing.
-  */
-  BACKUP_BREAKPOINT("backup_cs_reading");
-  BACKUP_BREAKPOINT("commit_blocker_step_1");
+  DEBUG_SYNC(thd, "after_insert_locked_tables");
   thd_proc_info(thd, "init");
   thd->used_tables=0;
   values= its++;

=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h	2008-06-04 13:20:03 +0000
+++ b/sql/sql_lex.h	2008-06-25 13:30:04 +0000
@@ -1526,6 +1526,7 @@ typedef struct st_lex : public Query_tab
   LEX_STRING name;
   char *help_arg;
   LEX_STRING backup_dir;				/* For RESTORE/BACKUP */
+  bool backup_compression;
   char* to_log;                                 /* For PURGE MASTER LOGS TO */
   char* x509_subject,*x509_issuer,*ssl_cipher;
   String *wild;

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-06-04 13:20:03 +0000
+++ b/sql/sql_parse.cc	2008-06-25 13:39:04 +0000
@@ -28,7 +28,6 @@
 #include "events.h"
 #include "sql_trigger.h"
 #include <ddl_blocker.h>
-#include "backup/debug.h"
 #include "sql_audit.h"
 
 #ifdef BACKUP_TEST
@@ -3870,10 +3869,7 @@ end_with_restore_list:
                xa_state_names[thd->transaction.xid_state.xa_state]);
       break;
     }
-    /*
-      Breakpoints for backup testing.
-    */
-    BACKUP_BREAKPOINT("backup_commit_blocker");
+    DEBUG_SYNC(thd, "before_begin_trans");
     if (begin_trans(thd))
       goto error;
     my_ok(thd);
@@ -3882,10 +3878,7 @@ end_with_restore_list:
     if (end_trans(thd, lex->tx_release ? COMMIT_RELEASE :
                               lex->tx_chain ? COMMIT_AND_CHAIN : COMMIT))
       goto error;
-    /*
-      Breakpoints for backup testing.
-    */
-    BACKUP_BREAKPOINT("backup_commit_blocker");
+    DEBUG_SYNC(thd, "after_commit");
     my_ok(thd);
     break;
   case SQLCOM_ROLLBACK:

=== modified file 'sql/sql_plugin.cc'
--- a/sql/sql_plugin.cc	2008-05-08 16:01:15 +0000
+++ b/sql/sql_plugin.cc	2008-06-18 03:30:29 +0000
@@ -1146,9 +1146,10 @@ int plugin_init(int *argc, char **argv, 
   {
     for (plugin= *builtins; plugin->info; plugin++)
     {
-      /* by default, only ndbcluster is disabled */
+      /* by default, ndbcluster and federated are disabled */
       def_enabled=
-        my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0;
+        my_strcasecmp(&my_charset_latin1, plugin->name, "NDBCLUSTER") != 0 &&
+        my_strcasecmp(&my_charset_latin1, plugin->name, "FEDERATED") != 0;
       bzero(&tmp, sizeof(tmp));
       tmp.plugin= plugin;
       tmp.name.str= (char *)plugin->name;

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2008-05-23 05:03:07 +0000
+++ b/sql/sql_select.cc	2008-06-20 19:24:46 +0000
@@ -1479,6 +1479,7 @@ JOIN::optimize()
       {
         DBUG_PRINT("info",("No matching min/max row"));
 	zero_result_cause= "No matching min/max row";
+        tables= 0;
 	error=0;
 	DBUG_RETURN(0);
       }
@@ -1492,6 +1493,7 @@ JOIN::optimize()
       {
         DBUG_PRINT("info",("No matching min/max row"));
         zero_result_cause= "No matching min/max row";
+        tables= 0;
         error=0;
         DBUG_RETURN(0);
       }

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2008-06-04 13:20:03 +0000
+++ b/sql/sql_table.cc	2008-06-25 14:49:43 +0000
@@ -3978,7 +3978,7 @@ static int prepare_for_repair(THD *thd, 
   if (table->s->frm_version != FRM_VER_TRUE_VARCHAR)
   {
     error= send_check_errmsg(thd, table_list, "repair",
-                             "Failed reparing incompatible .FRM file");
+                             "Failed repairing incompatible .frm file");
     goto end;
   }
 

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2008-06-04 13:20:03 +0000
+++ b/sql/sql_yacc.yy	2008-06-26 10:38:48 +0000
@@ -684,6 +684,8 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  COMPACT_SYM
 %token  COMPLETION_SYM
 %token  COMPRESSED_SYM
+%token  COMPRESSION_SYM
+%token  COMPRESSION_ALGORITHM_SYM
 %token  CONCURRENT
 %token  CONDITION_SYM                 /* SQL-2003-N */
 %token  CONNECTION_SYM
@@ -1407,7 +1409,8 @@ bool my_yyoverflow(short **a, YYSTYPE **
         install uninstall partition_entry binlog_base64_event
         init_key_options key_options key_opts key_opt key_using_alg
         server_def server_options_list server_option
-        definer_opt no_definer definer
+        definer_opt no_definer definer opt_compression
+        opt_compression_algorithm
 END_OF_INPUT
 
 %type <NONE> call sp_proc_stmts sp_proc_stmts1 sp_proc_stmt
@@ -6305,6 +6308,7 @@ backup:
           database_list
           TO_SYM
           TEXT_STRING_sys
+          opt_compression
           {
             LEX *lex= Lex;
             if (lex->sphead)
@@ -6324,6 +6328,26 @@ backup:
           }
         ;
 
+opt_compression:
+          /* empty */ { Lex->backup_compression= false; }
+        | WITH COMPRESSION_SYM opt_compression_algorithm
+          {
+            Lex->backup_compression= true;
+          }
+        ;
+
+opt_compression_algorithm:
+          /* empty */ {}
+        | COMPRESSION_ALGORITHM_SYM opt_equal IDENT_sys
+          {
+            if (my_strcasecmp(system_charset_info, $3.str, "gzip"))
+            {
+              my_error(ER_WRONG_ARGUMENTS, MYF(0), "COMPRESSION_ALGORITHM");
+              MYSQL_YYABORT;
+            }
+          }
+        ;
+
 database_list:
           '*'
           {
@@ -10933,6 +10957,8 @@ keyword_sp:
         | COMPACT_SYM              {}
         | COMPLETION_SYM           {}
         | COMPRESSED_SYM           {}
+        | COMPRESSION_SYM          {}
+        | COMPRESSION_ALGORITHM_SYM{}
         | CONCURRENT               {}
         | CONNECTION_SYM           {}
         | CONSISTENT_SYM           {}

=== modified file 'sql/structs.h'
--- a/sql/structs.h	2008-04-01 15:13:57 +0000
+++ b/sql/structs.h	2008-06-23 11:55:24 +0000
@@ -320,31 +320,22 @@ private:
   */
   Discrete_interval        *current;
   uint                  elements; // number of elements
-
-  /* helper function for copy construct and assignment operator */
-  void copy_(const Discrete_intervals_list& from)
-  {
-    for (Discrete_interval *i= from.head; i; i= i->next)
-    {
-      Discrete_interval j= *i;
-      append(&j);
-    }
+  void set_members(Discrete_interval *h, Discrete_interval *t,
+                   Discrete_interval *c, uint el)
+  {  
+    head= h;
+    tail= t;
+    current= c;
+    elements= el;
   }
+  void operator=(Discrete_intervals_list &);  /* prevent use of these */
+  Discrete_intervals_list(const Discrete_intervals_list &);
+
 public:
   Discrete_intervals_list() : head(NULL), current(NULL), elements(0) {};
-  Discrete_intervals_list(const Discrete_intervals_list& from)
-  {
-    copy_(from);
-  }
-  void operator=(const Discrete_intervals_list& from)
-  {
-    empty();
-    copy_(from);
-  }
   void empty_no_free()
   {
-    head= current= NULL;
-    elements= 0;
+    set_members(NULL, NULL, NULL, 0);
   }
   void empty()
   {
@@ -356,7 +347,24 @@ public:
     }
     empty_no_free();
   }
-
+  void copy_shallow(const Discrete_intervals_list * dli)
+  {
+    head= dli->get_head();
+    tail= dli->get_tail();
+    current= dli->get_current();
+    elements= dli->nb_elements();
+  }
+  void swap (Discrete_intervals_list * dli)
+  {
+    Discrete_interval *h, *t, *c;
+    uint el;
+    h= dli->get_head();
+    t= dli->get_tail();
+    c= dli->get_current();
+    el= dli->nb_elements();
+    dli->copy_shallow(this);
+    set_members(h, t, c, el);
+  }
   const Discrete_interval* get_next()
   {
     Discrete_interval *tmp= current;
@@ -370,4 +378,7 @@ public:
   ulonglong minimum()     const { return (head ? head->minimum() : 0); };
   ulonglong maximum()     const { return (head ? tail->maximum() : 0); };
   uint      nb_elements() const { return elements; }
+  Discrete_interval* get_head() const { return head; };
+  Discrete_interval* get_tail() const { return tail; };
+  Discrete_interval* get_current() const { return current; };
 };

=== modified file 'storage/innobase/Makefile.am'
--- a/storage/innobase/Makefile.am	2008-05-14 09:24:14 +0000
+++ b/storage/innobase/Makefile.am	2008-06-20 19:24:46 +0000
@@ -15,21 +15,21 @@
 
 # Process this file with automake to create Makefile.in
 
-MYSQLDATAdir =          $(localstatedir)
-MYSQLSHAREdir =         $(pkgdatadir)
-MYSQLBASEdir=           $(prefix)
-MYSQLLIBdir=            $(pkglibdir)
-pkgplugindir =		$(pkglibdir)/plugin
-INCLUDES =              -I$(top_srcdir)/include -I$(top_builddir)/include \
+MYSQLDATAdir=		$(localstatedir)
+MYSQLSHAREdir=		$(pkgdatadir)
+MYSQLBASEdir=		$(prefix)
+MYSQLLIBdir=		$(pkglibdir)
+pkgplugindir=		$(pkglibdir)/plugin
+INCLUDES=		-I$(top_srcdir)/include -I$(top_builddir)/include \
 			-I$(top_srcdir)/regex \
 			-I$(top_srcdir)/storage/innobase/include \
 			-I$(top_srcdir)/sql \
-                        -I$(srcdir)
+			-I$(srcdir)
 
-DEFS =			@DEFS@
+DEFS=			@DEFS@
 
 
-noinst_HEADERS = include/btr0btr.h include/btr0btr.ic			\
+noinst_HEADERS=		include/btr0btr.h include/btr0btr.ic		\
 			include/btr0cur.h include/btr0cur.ic		\
 			include/btr0pcur.h include/btr0pcur.ic		\
 			include/btr0sea.h include/btr0sea.ic		\
@@ -121,9 +121,9 @@ noinst_HEADERS = include/btr0btr.h inclu
 			include/ut0list.ic include/ut0wqueue.h		\
 			include/ha_prototypes.h handler/ha_innodb.h
 
-EXTRA_LIBRARIES =	libinnobase.a
-noinst_LIBRARIES =	@plugin_innobase_static_target@
-libinnobase_a_SOURCES =	btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c	\
+EXTRA_LIBRARIES=	libinnobase.a
+noinst_LIBRARIES=	@plugin_innobase_static_target@
+libinnobase_a_SOURCES=	btr/btr0btr.c btr/btr0cur.c btr/btr0pcur.c	\
 			btr/btr0sea.c buf/buf0buf.c buf/buf0flu.c	\
 			buf/buf0lru.c buf/buf0rea.c data/data0data.c	\
 			data/data0type.c dict/dict0boot.c		\
@@ -156,17 +156,17 @@ libinnobase_a_SOURCES =	btr/btr0btr.c bt
 			handler/ha_innodb.cc
 
 libinnobase_a_CXXFLAGS=	$(AM_CFLAGS)
-libinnobase_a_CFLAGS  =	$(AM_CFLAGS)
+libinnobase_a_CFLAGS=	$(AM_CFLAGS)
 
-EXTRA_LTLIBRARIES =	ha_innodb.la
-pkglib_LTLIBRARIES =	@plugin_innobase_shared_target@
+EXTRA_LTLIBRARIES=	ha_innodb.la
+pkgplugin_LTLIBRARIES=	@plugin_innobase_shared_target@
 
-ha_innodb_la_LDFLAGS =	-module -rpath $(pkgplugindir)
-ha_innodb_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
-ha_innodb_la_CFLAGS  =	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
-ha_innodb_la_SOURCES =	$(libinnobase_a_SOURCES)
+ha_innodb_la_LDFLAGS=	-module -rpath $(pkgplugindir)
+ha_innodb_la_CXXFLAGS=	$(AM_CFLAGS) $(INNODB_DYNAMIC_CFLAGS)
+ha_innodb_la_CFLAGS=	$(AM_CFLAGS) $(INNODB_DYNAMIC_CFLAGS)
+ha_innodb_la_SOURCES=	$(libinnobase_a_SOURCES)
 
-EXTRA_DIST =		CMakeLists.txt plug.in \
+EXTRA_DIST=		CMakeLists.txt plug.in \
 			pars/make_bison.sh pars/make_flex.sh \
 			pars/pars0grm.y pars/pars0lex.l
 

=== modified file 'storage/innobase/btr/btr0cur.c'
--- a/storage/innobase/btr/btr0cur.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/btr/btr0cur.c	2008-06-12 00:08:07 +0000
@@ -52,7 +52,7 @@ can be released by page reorganize, then
 
 #define BTR_CUR_PAGE_REORGANIZE_LIMIT	(UNIV_PAGE_SIZE / 32)
 
-/* When estimating number of different kay values in an index sample
+/* When estimating number of different key values in an index, sample
 this many index pages */
 #define BTR_KEY_VAL_ESTIMATE_N_PAGES	8
 

=== modified file 'storage/innobase/buf/buf0buf.c'
--- a/storage/innobase/buf/buf0buf.c	2008-02-01 10:55:39 +0000
+++ b/storage/innobase/buf/buf0buf.c	2008-06-12 00:08:07 +0000
@@ -2328,7 +2328,6 @@ buf_print(void)
 
 	ut_a(buf_validate());
 }
-#endif /* UNIV_DEBUG */
 
 /*************************************************************************
 Returns the number of latched pages in the buffer pool. */
@@ -2361,6 +2360,7 @@ buf_get_latched_pages_number(void)
 
 	return(fixed_pages_number);
 }
+#endif /* UNIV_DEBUG */
 
 /*************************************************************************
 Returns the number of pending buf pool ios. */

=== modified file 'storage/innobase/dict/dict0dict.c'
--- a/storage/innobase/dict/dict0dict.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/dict/dict0dict.c	2008-06-12 00:08:07 +0000
@@ -429,7 +429,7 @@ void
 dict_table_autoinc_initialize(
 /*==========================*/
 	dict_table_t*	table,	/* in: table */
-	ib_longlong	value)	/* in: next value to assign to a row */
+	ib_ulonglong	value)	/* in: next value to assign to a row */
 {
 	ut_ad(mutex_own(&table->autoinc_mutex));
 
@@ -441,7 +441,7 @@ dict_table_autoinc_initialize(
 Reads the next autoinc value (== autoinc counter value), 0 if not yet
 initialized. */
 
-ib_longlong
+ib_ulonglong
 dict_table_autoinc_read(
 /*====================*/
 				/* out: value for a new row, or 0 */
@@ -470,7 +470,7 @@ dict_table_autoinc_update(
 /*======================*/
 
 	dict_table_t*	table,	/* in: table */
-	ib_longlong	value)	/* in: value which was assigned to a row */
+	ib_ulonglong	value)	/* in: value which was assigned to a row */
 {
 	if (table->autoinc_inited && value > table->autoinc) {
 
@@ -3395,7 +3395,7 @@ loop:
 
 	ptr = dict_accept(cs, ptr, "FOREIGN", &success);
 
-	if (!success) {
+	if (!success || !my_isspace(cs, *ptr)) {
 
 		goto loop;
 	}

=== modified file 'storage/innobase/handler/ha_innodb.cc'
--- a/storage/innobase/handler/ha_innodb.cc	2008-05-22 18:40:15 +0000
+++ b/storage/innobase/handler/ha_innodb.cc	2008-06-12 00:08:07 +0000
@@ -135,7 +135,7 @@ static my_bool	innobase_locks_unsafe_for
 static my_bool	innobase_rollback_on_timeout		= FALSE;
 static my_bool	innobase_create_status_file		= FALSE;
 static my_bool innobase_stats_on_metadata		= TRUE;
-static my_bool	innobase_use_adaptive_hash_indexes	= TRUE;
+static my_bool	innobase_adaptive_hash_index	= TRUE;
 
 static char*	internal_innobase_data_file_path	= NULL;
 
@@ -340,8 +340,10 @@ static SHOW_VAR innodb_status_variables[
   (char*) &export_vars.innodb_buffer_pool_pages_flushed,  SHOW_LONG},
   {"buffer_pool_pages_free",
   (char*) &export_vars.innodb_buffer_pool_pages_free,	  SHOW_LONG},
+#ifdef UNIV_DEBUG
   {"buffer_pool_pages_latched",
   (char*) &export_vars.innodb_buffer_pool_pages_latched,  SHOW_LONG},
+#endif /* UNIV_DEBUG */
   {"buffer_pool_pages_misc",
   (char*) &export_vars.innodb_buffer_pool_pages_misc,	  SHOW_LONG},
   {"buffer_pool_pages_total",
@@ -606,7 +608,9 @@ convert_error_code_to_mysql(
 		tell it also to MySQL so that MySQL knows to empty the
 		cached binlog for this transaction */
 
-                thd_mark_transaction_to_rollback(thd, TRUE);
+		if (thd) {
+			thd_mark_transaction_to_rollback(thd, TRUE);
+		}
 
 		return(HA_ERR_LOCK_DEADLOCK);
 	} else if (error == (int) DB_LOCK_WAIT_TIMEOUT) {
@@ -615,8 +619,10 @@ convert_error_code_to_mysql(
 		latest SQL statement in a lock wait timeout. Previously, we
 		rolled back the whole transaction. */
 
-                thd_mark_transaction_to_rollback(thd,
-                                             (bool)row_rollback_on_timeout);
+		if (thd) {
+			thd_mark_transaction_to_rollback(
+				thd, (bool)row_rollback_on_timeout);
+		}
 
 		return(HA_ERR_LOCK_WAIT_TIMEOUT);
 
@@ -668,7 +674,9 @@ convert_error_code_to_mysql(
  		tell it also to MySQL so that MySQL knows to empty the
  		cached binlog for this transaction */
 
-                thd_mark_transaction_to_rollback(thd, TRUE);
+		if (thd) {
+			thd_mark_transaction_to_rollback(thd, TRUE);
+		}
 
     		return(HA_ERR_LOCK_TABLE_FULL);
 	} else if (error == DB_TOO_MANY_CONCURRENT_TRXS) {
@@ -1635,7 +1643,7 @@ innobase_init(
 	srv_stats_on_metadata = (ibool) innobase_stats_on_metadata;
 
 	srv_use_adaptive_hash_indexes =
-		(ibool) innobase_use_adaptive_hash_indexes;
+		(ibool) innobase_adaptive_hash_index;
 
 	srv_print_verbose_log = mysqld_embedded ? 0 : 1;
 
@@ -2283,6 +2291,8 @@ ha_innobase::open(
 	dict_table_t*	ib_table;
 	char		norm_name[1000];
 	THD*		thd;
+	ulint		retries = 0;
+	char*		is_part = NULL;
 
 	DBUG_ENTER("ha_innobase::open");
 
@@ -2316,11 +2326,29 @@ ha_innobase::open(
 		DBUG_RETURN(1);
 	}
 
+	/* We look for pattern #P# to see if the table is partitioned
+	MySQL table. The retry logic for partitioned tables is a
+	workaround for http://bugs.mysql.com/bug.php?id=33349. Look
+	at support issue https://support.mysql.com/view.php?id=21080
+	for more details. */
+	is_part = strstr(norm_name, "#P#");
+retry:
 	/* Get pointer to a table object in InnoDB dictionary cache */
-
 	ib_table = dict_table_get(norm_name, TRUE);
-
+	
 	if (NULL == ib_table) {
+		if (is_part && retries < 10) {
+			++retries;
+			os_thread_sleep(100000);
+			goto retry;
+		}
+
+		if (is_part) {
+			sql_print_error("Failed to open table %s after "
+					"%lu attemtps.\n", norm_name,
+					retries);
+		}
+
 		sql_print_error("Cannot find or open table %s from\n"
 				"the internal data dictionary of InnoDB "
 				"though the .frm file for the\n"
@@ -3305,7 +3333,8 @@ ha_innobase::innobase_autoinc_lock(void)
 		old style only if another transaction has already acquired
 		the AUTOINC lock on behalf of a LOAD FILE or INSERT ... SELECT
 		etc. type of statement. */
-		if (thd_sql_command(user_thd) == SQLCOM_INSERT) {
+		if (thd_sql_command(user_thd) == SQLCOM_INSERT
+		    || thd_sql_command(user_thd) == SQLCOM_REPLACE) {
 			dict_table_t*	table = prebuilt->table;
 
 			/* Acquire the AUTOINC mutex. */
@@ -3576,7 +3605,19 @@ no_commit:
 			if (auto_inc > prebuilt->last_value) {
 set_max_autoinc:
 				ut_a(prebuilt->table->autoinc_increment > 0);
-				auto_inc += prebuilt->table->autoinc_increment;
+
+				ulonglong	have;
+				ulonglong	need;
+
+				/* Check for overflow conditions. */
+				need = prebuilt->table->autoinc_increment;
+				have = ~0x0ULL - auto_inc;
+
+				if (have < need) {
+					need = have;
+				}
+
+				auto_inc += need;
 
 				err = innobase_set_max_autoinc(auto_inc);
 
@@ -3771,6 +3812,8 @@ ha_innobase::update_row(
 
 	ut_a(prebuilt->trx == trx);
 
+	ha_statistic_increment(&SSV::ha_update_count);
+
 	if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
 		table->timestamp_field->set_time();
 
@@ -3826,6 +3869,16 @@ ha_innobase::update_row(
 
 	error = convert_error_code_to_mysql(error, user_thd);
 
+	if (error == 0 /* success */
+	    && uvect->n_fields == 0 /* no columns were updated */) {
+
+		/* This is the same as success, but instructs
+		MySQL that the row is not really updated and it
+		should not increase the count of updated rows.
+		This is fix for http://bugs.mysql.com/29157 */
+		error = HA_ERR_RECORD_IS_THE_SAME;
+	}
+
 	/* Tell InnoDB server that there might be work for
 	utility threads: */
 
@@ -3850,6 +3903,8 @@ ha_innobase::delete_row(
 
 	ut_a(prebuilt->trx == trx);
 
+	ha_statistic_increment(&SSV::ha_delete_count);
+
 	/* Only if the table has an AUTOINC column */
 	if (table->found_next_number_field && record == table->record[0]) {
 		ulonglong	dummy = 0;
@@ -4653,6 +4708,12 @@ innodb_check_for_record_too_big_error(
 	}
 }
 
+/* limit innodb monitor access to users with PROCESS privilege.
+See http://bugs.mysql.com/32710 for expl. why we choose PROCESS. */
+#define IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(table_name, thd) \
+	(row_is_magic_monitor_table(table_name) \
+	 && check_global_access(thd, PROCESS_ACL))
+
 /*********************************************************************
 Creates a table definition to an InnoDB database. */
 static
@@ -4689,6 +4750,12 @@ create_table_def(
 	DBUG_ENTER("create_table_def");
 	DBUG_PRINT("enter", ("table_name: %s", table_name));
 
+	ut_a(trx->mysql_thd != NULL);
+	if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(table_name,
+						  (THD*) trx->mysql_thd)) {
+		DBUG_RETURN(HA_ERR_GENERIC);
+	}
+
 	n_cols = form->s->fields;
 
 	/* We pass 0 as the space id, and determine at a lower level the space
@@ -4967,6 +5034,29 @@ ha_innobase::create(
 	DBUG_ENTER("ha_innobase::create");
 
 	DBUG_ASSERT(thd != NULL);
+	DBUG_ASSERT(create_info != NULL);
+
+#ifdef __WIN__
+	/* Names passed in from server are in two formats:
+	1. <database_name>/<table_name>: for normal table creation
+	2. full path: for temp table creation, or sym link
+
+	When srv_file_per_table is on, check for full path pattern, i.e.
+	X:\dir\...,		X is a driver letter, or
+	\\dir1\dir2\...,	UNC path
+	returns error if it is in full path format, but not creating a temp.
+	table. Currently InnoDB does not support symbolic link on Windows. */
+
+	if (srv_file_per_table
+	    && (!create_info->options & HA_LEX_CREATE_TMP_TABLE)) {
+
+		if ((name[1] == ':')
+		    || (name[0] == '\\' && name[1] == '\\')) {
+			sql_print_error("Cannot create table %s\n", name);
+			DBUG_RETURN(HA_ERR_GENERIC);
+		}
+	}
+#endif
 
 	if (form->s->fields > 1000) {
 		/* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
@@ -5101,8 +5191,15 @@ ha_innobase::create(
 
 	DBUG_ASSERT(innobase_table != 0);
 
-	if ((create_info->used_fields & HA_CREATE_USED_AUTO) &&
-	   (create_info->auto_increment_value != 0)) {
+	/* Note: We can't call update_thd() as prebuilt will not be
+	setup at this stage and so we use thd. */
+
+	/* We need to copy the AUTOINC value from the old table if
+	this is an ALTER TABLE. */
+
+	if (((create_info->used_fields & HA_CREATE_USED_AUTO)
+	    || thd_sql_command(thd) == SQLCOM_ALTER_TABLE)
+	    && create_info->auto_increment_value != 0) {
 
 		/* Query was ALTER TABLE...AUTO_INCREMENT = x; or
 		CREATE TABLE ...AUTO_INCREMENT = x; Find out a table
@@ -5229,6 +5326,14 @@ ha_innobase::delete_table(
 
 	DBUG_ENTER("ha_innobase::delete_table");
 
+	/* Strangely, MySQL passes the table name without the '.frm'
+	extension, in contrast to ::create */
+	normalize_table_name(norm_name, name);
+
+	if (IS_MAGIC_TABLE_AND_USER_DENIED_ACCESS(norm_name, thd)) {
+		DBUG_RETURN(HA_ERR_GENERIC);
+	}
+
 	/* Get the transaction associated with the current thd, or create one
 	if not yet created */
 
@@ -5262,11 +5367,6 @@ ha_innobase::delete_table(
 
 	assert(name_len < 1000);
 
-	/* Strangely, MySQL passes the table name without the '.frm'
-	extension, in contrast to ::create */
-
-	normalize_table_name(norm_name, name);
-
 	/* Drop the table in InnoDB */
 
 	error = row_drop_table_for_mysql(norm_name, trx,
@@ -5756,6 +5856,13 @@ ha_innobase::info(
 			n_rows++;
 		}
 
+		/* Fix bug#29507: TRUNCATE shows too many rows affected.
+		Do not show the estimates for TRUNCATE command. */
+		if (thd_sql_command(user_thd) == SQLCOM_TRUNCATE) {
+
+			n_rows = 0;
+		}
+
 		stats.records = (ha_rows)n_rows;
 		stats.deleted = 0;
 		stats.data_file_length = ((ulonglong)
@@ -5764,7 +5871,9 @@ ha_innobase::info(
 		stats.index_file_length = ((ulonglong)
 				ib_table->stat_sum_of_other_index_sizes)
 					* UNIV_PAGE_SIZE;
-		stats.delete_length = 0;
+		stats.delete_length =
+			fsp_get_available_space_in_free_extents(
+				ib_table->space) * 1024;
 		stats.check_time = 0;
 
 		if (stats.records == 0) {
@@ -5847,7 +5956,7 @@ ha_innobase::info(
 	}
 
 	if (flag & HA_STATUS_AUTO && table->found_next_number_field) {
-		longlong	auto_inc;
+		ulonglong	auto_inc;
 		int		ret;
 
 		/* The following function call can the first time fail in
@@ -7211,9 +7320,9 @@ ha_innobase::innobase_read_and_init_auto
 /*=========================================*/
 						/* out: 0 or generic MySQL
 						error code */
-        longlong*	value)			/* out: the autoinc value */
+        ulonglong*	value)			/* out: the autoinc value */
 {
-	longlong	auto_inc;
+	ulonglong	auto_inc;
 	ibool		stmt_start;
 	int		mysql_error = 0;
 	dict_table_t*	innodb_table = prebuilt->table;
@@ -7264,7 +7373,9 @@ ha_innobase::innobase_read_and_init_auto
 			index, autoinc_col_name, &auto_inc);
 
 		if (error == DB_SUCCESS) {
-			++auto_inc;
+			if (auto_inc < ~0x0ULL) {
+				++auto_inc;
+			}
 			dict_table_autoinc_initialize(innodb_table, auto_inc);
 		} else {
 			ut_print_timestamp(stderr);
@@ -7303,6 +7414,7 @@ On return if there is no error then the 
 
 ulong
 ha_innobase::innobase_get_auto_increment(
+/*=====================================*/
 	ulonglong*	value)		/* out: autoinc value */
 {
 	ulong		error;
@@ -7316,14 +7428,14 @@ ha_innobase::innobase_get_auto_increment
 		error = innobase_autoinc_lock();
 
 		if (error == DB_SUCCESS) {
-			ib_longlong	autoinc;
+			ulonglong	autoinc;
 
 			/* Determine the first value of the interval */
 			autoinc = dict_table_autoinc_read(prebuilt->table);
 
 			/* We need to initialize the AUTO-INC value, for
 			that we release all locks.*/
-			if (autoinc <= 0) {
+			if (autoinc == 0) {
 				trx_t*		trx;
 
 				trx = prebuilt->trx;
@@ -7342,14 +7454,11 @@ ha_innobase::innobase_get_auto_increment
 				mysql_error = innobase_read_and_init_auto_inc(
 					&autoinc);
 
-				if (!mysql_error) {
-					/* Should have read the proper value */
-					ut_a(autoinc > 0);
-				} else {
+				if (mysql_error) {
 					error = DB_ERROR;
 				}
 			} else {
-				*value = (ulonglong) autoinc;
+				*value = autoinc;
 			}
 		/* A deadlock error during normal processing is OK
 		and can be ignored. */
@@ -7434,10 +7543,19 @@ ha_innobase::get_auto_increment(
 	/* With old style AUTOINC locking we only update the table's
 	AUTOINC counter after attempting to insert the row. */
 	if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
+		ulonglong	have;
+		ulonglong	need;
+
+		/* Check for overflow conditions. */
+		need = *nb_reserved_values * increment;
+		have = ~0x0ULL - *first_value;
+
+		if (have < need) {
+			need = have;
+		}
 
 		/* Compute the last value in the interval */
-		prebuilt->last_value = *first_value +
-		    (*nb_reserved_values * increment);
+		prebuilt->last_value = *first_value + need;
 
 		ut_a(prebuilt->last_value >= *first_value);
 
@@ -7911,7 +8029,7 @@ bool ha_innobase::check_if_incompatible_
 	}
 
 	/* Check that row format didn't change */
-	if ((info->used_fields & HA_CREATE_USED_AUTO) &&
+	if ((info->used_fields & HA_CREATE_USED_ROW_FORMAT) &&
 		get_row_type() != info->row_type) {
 
 		return COMPATIBLE_DATA_NO;
@@ -8026,9 +8144,10 @@ static MYSQL_SYSVAR_BOOL(stats_on_metada
   "Enable statistics gathering for metadata commands such as SHOW TABLE STATUS (on by default)",
   NULL, NULL, TRUE);
 
-static MYSQL_SYSVAR_BOOL(use_adaptive_hash_indexes, innobase_use_adaptive_hash_indexes,
+static MYSQL_SYSVAR_BOOL(adaptive_hash_index, innobase_adaptive_hash_index,
   PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY,
-  "Enable the InnoDB adaptive hash indexes (enabled by default)",
+  "Enable InnoDB adaptive hash index (enabled by default).  "
+  "Disable with --skip-innodb-adaptive-hash-index.",
   NULL, NULL, TRUE);
 
 static MYSQL_SYSVAR_LONG(additional_mem_pool_size, innobase_additional_mem_pool_size,
@@ -8118,10 +8237,11 @@ static MYSQL_SYSVAR_STR(data_file_path, 
 
 static MYSQL_SYSVAR_LONG(autoinc_lock_mode, innobase_autoinc_lock_mode,
   PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
-  "The AUTOINC lock modes supported by InnoDB:\n"
-  "  0 => Old style AUTOINC locking (for backward compatibility)\n"
-  "  1 => New style AUTOINC locking\n"
-  "  2 => No AUTOINC locking (unsafe for SBR)",
+  "The AUTOINC lock modes supported by InnoDB:               "
+  "0 => Old style AUTOINC locking (for backward"
+  " compatibility)                                           "
+  "1 => New style AUTOINC locking                            "
+  "2 => No AUTOINC locking (unsafe for SBR)",
   NULL, NULL,
   AUTOINC_NEW_STYLE_LOCKING,	/* Default setting */
   AUTOINC_OLD_STYLE_LOCKING,	/* Minimum value */
@@ -8159,7 +8279,7 @@ static struct st_mysql_sys_var* innobase
   MYSQL_SYSVAR(open_files),
   MYSQL_SYSVAR(rollback_on_timeout),
   MYSQL_SYSVAR(stats_on_metadata),
-  MYSQL_SYSVAR(use_adaptive_hash_indexes),
+  MYSQL_SYSVAR(adaptive_hash_index),
   MYSQL_SYSVAR(status_file),
   MYSQL_SYSVAR(support_xa),
   MYSQL_SYSVAR(sync_spin_loops),

=== modified file 'storage/innobase/handler/ha_innodb.h'
--- a/storage/innobase/handler/ha_innodb.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/handler/ha_innodb.h	2008-06-12 00:08:07 +0000
@@ -72,7 +72,7 @@ class ha_innobase: public handler
 	int update_thd(THD* thd);
 	int change_active_index(uint keynr);
 	int general_fetch(uchar* buf, uint direction, uint match_mode);
-	int innobase_read_and_init_auto_inc(longlong* ret);
+	int innobase_read_and_init_auto_inc(ulonglong* ret);
 	ulong innobase_autoinc_lock();
 	ulong innobase_set_max_autoinc(ulonglong auto_inc);
 	ulong innobase_reset_autoinc(ulonglong auto_inc);

=== modified file 'storage/innobase/include/buf0buf.h'
--- a/storage/innobase/include/buf0buf.h	2008-02-01 10:55:39 +0000
+++ b/storage/innobase/include/buf0buf.h	2008-06-12 00:08:07 +0000
@@ -495,7 +495,15 @@ Prints info of the buffer pool data stru
 void
 buf_print(void);
 /*============*/
+
+/*************************************************************************
+Returns the number of latched pages in the buffer pool. */
+
+ulint
+buf_get_latched_pages_number(void);
+/*==============================*/
 #endif /* UNIV_DEBUG */
+
 /************************************************************************
 Prints a page to stderr. */
 
@@ -503,12 +511,7 @@ void
 buf_page_print(
 /*===========*/
 	byte*	read_buf);	/* in: a database page */
-/*************************************************************************
-Returns the number of latched pages in the buffer pool. */
 
-ulint
-buf_get_latched_pages_number(void);
-/*==============================*/
 /*************************************************************************
 Returns the number of pending buf pool ios. */
 

=== modified file 'storage/innobase/include/dict0dict.h'
--- a/storage/innobase/include/dict0dict.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/dict0dict.h	2008-06-12 00:08:07 +0000
@@ -185,12 +185,12 @@ void
 dict_table_autoinc_initialize(
 /*==========================*/
 	dict_table_t*	table,	/* in: table */
-	ib_longlong	value);	/* in: next value to assign to a row */
+	ib_ulonglong	value);	/* in: next value to assign to a row */
 /************************************************************************
 Reads the next autoinc value (== autoinc counter value), 0 if not yet
 initialized. */
 
-ib_longlong
+ib_ulonglong
 dict_table_autoinc_read(
 /*====================*/
 				/* out: value for a new row, or 0 */
@@ -204,7 +204,7 @@ dict_table_autoinc_update(
 /*======================*/
 
 	dict_table_t*	table,	/* in: table */
-	ib_longlong	value);	/* in: value which was assigned to a row */
+	ib_ulonglong	value);	/* in: value which was assigned to a row */
 /************************************************************************
 Release the autoinc lock.*/
 

=== modified file 'storage/innobase/include/dict0mem.h'
--- a/storage/innobase/include/dict0mem.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/dict0mem.h	2008-06-12 00:08:07 +0000
@@ -409,7 +409,7 @@ struct dict_table_struct{
 				/* TRUE if the autoinc counter has been
 				inited; MySQL gets the init value by executing
 				SELECT MAX(auto inc column) */
-	ib_longlong	autoinc;/* autoinc counter value to give to the
+	ib_ulonglong	autoinc;/* autoinc counter value to give to the
 				next inserted row */
 
 	ib_longlong	autoinc_increment;

=== modified file 'storage/innobase/include/mach0data.h'
--- a/storage/innobase/include/mach0data.h	2007-11-06 22:42:58 +0000
+++ b/storage/innobase/include/mach0data.h	2008-06-12 00:08:07 +0000
@@ -331,10 +331,10 @@ mach_write_to_2_little_endian(
 Convert integral type from storage byte order (big endian) to
 host byte order. */
 UNIV_INLINE
-void
+ullint
 mach_read_int_type(
 /*===============*/
-	byte*		dest,		/* out: where to write */
+					/* out: integer value */
 	const byte*	src,		/* in: where to read from */
 	ulint		len,		/* in: length of src */
 	ibool		unsigned_type);	/* in: signed or unsigned flag */

=== modified file 'storage/innobase/include/mach0data.ic'
--- a/storage/innobase/include/mach0data.ic	2007-11-06 22:42:58 +0000
+++ b/storage/innobase/include/mach0data.ic	2008-06-12 00:08:07 +0000
@@ -696,33 +696,39 @@ mach_write_to_2_little_endian(
 Convert integral type from storage byte order (big endian) to
 host byte order. */
 UNIV_INLINE
-void
+ullint
 mach_read_int_type(
 /*===============*/
-	byte*		dest,		/* out: where to write */
+					/* out: integer value */
 	const byte*	src,		/* in: where to read from */
 	ulint		len,		/* in: length of src */
 	ibool		unsigned_type)	/* in: signed or unsigned flag */
 {
-#ifdef WORDS_BIGENDIAN
-	memcpy(dest, src, len);
+	/* XXX this can be optimized on big-endian machines */
 
-	if (!unsigned_type) {
-		dest[0] ^= 128;
+	ullint	ret;
+	uint	i;
+
+	if (unsigned_type || (src[0] & 0x80)) {
+
+		ret = 0x0000000000000000ULL;
+	} else {
+
+		ret = 0xFFFFFFFFFFFFFF00ULL;
 	}
-#else
-	byte*		ptr;
 
-	/* Convert integer data from Innobase to a little-endian format,
-	sign bit restored to normal. */
+	if (unsigned_type) {
 
-	for (ptr = dest + len; ptr != dest; ++src) {
-		--ptr;
-		*ptr = *src;
+		ret |= src[0];
+	} else {
+
+		ret |= src[0] ^ 0x80;
 	}
 
-	if (!unsigned_type) {
-		dest[len - 1] ^= 128;
+	for (i = 1; i < len; i++) {
+		ret <<= 8;
+		ret |= src[i];
 	}
-#endif
+
+	return(ret);
 }

=== modified file 'storage/innobase/include/os0sync.h'
--- a/storage/innobase/include/os0sync.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/os0sync.h	2008-06-12 00:08:07 +0000
@@ -112,9 +112,13 @@ os_event_set(
 	os_event_t	event);	/* in: event to set */
 /**************************************************************
 Resets an event semaphore to the nonsignaled state. Waiting threads will
-stop to wait for the event. */
+stop to wait for the event.
+The return value should be passed to os_even_wait_low() if it is desired
+that this thread should not wait in case of an intervening call to
+os_event_set() between this os_event_reset() and the
+os_event_wait_low() call. See comments for os_event_wait_low(). */
 
-void
+ib_longlong
 os_event_reset(
 /*===========*/
 	os_event_t	event);	/* in: event to reset */
@@ -125,16 +129,38 @@ void
 os_event_free(
 /*==========*/
 	os_event_t	event);	/* in: event to free */
+
 /**************************************************************
 Waits for an event object until it is in the signaled state. If
 srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
 waiting thread when the event becomes signaled (or immediately if the
-event is already in the signaled state). */
+event is already in the signaled state).
+
+Typically, if the event has been signalled after the os_event_reset()
+we'll return immediately because event->is_set == TRUE.
+There are, however, situations (e.g.: sync_array code) where we may
+lose this information. For example:
+
+thread A calls os_event_reset()
+thread B calls os_event_set()   [event->is_set == TRUE]
+thread C calls os_event_reset() [event->is_set == FALSE]
+thread A calls os_event_wait()  [infinite wait!]
+thread C calls os_event_wait()  [infinite wait!]
+
+Where such a scenario is possible, to avoid infinite wait, the
+value returned by os_event_reset() should be passed in as
+reset_sig_count. */
+
+#define os_event_wait(event) os_event_wait_low((event), 0)
+
+void
+os_event_wait_low(
+/*==============*/
+	os_event_t	event,		/* in: event to wait */
+	ib_longlong	reset_sig_count);/* in: zero or the value
+					returned by previous call of
+					os_event_reset(). */
 
-void
-os_event_wait(
-/*==========*/
-	os_event_t	event);	/* in: event to wait */
 /**************************************************************
 Waits for an event object until it is in the signaled state or
 a timeout is exceeded. In Unix the timeout is always infinite. */

=== modified file 'storage/innobase/include/read0read.h'
--- a/storage/innobase/include/read0read.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/read0read.h	2008-06-12 00:08:07 +0000
@@ -111,10 +111,6 @@ struct read_view_struct{
 	dulint	undo_no;	/* (0, 0) or if type is VIEW_HIGH_GRANULARITY
 				transaction undo_no when this high-granularity
 				consistent read view was created */
-	ibool	can_be_too_old;	/* TRUE if the system has had to purge old
-				versions which this read view should be able
-				to access: the read view can bump into the
-				DB_MISSING_HISTORY error */
 	dulint	low_limit_no;	/* The view does not need to see the undo
 				logs for transactions whose transaction number
 				is strictly smaller (<) than this value: they

=== modified file 'storage/innobase/include/row0mysql.h'
--- a/storage/innobase/include/row0mysql.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/row0mysql.h	2008-06-12 00:08:07 +0000
@@ -319,7 +319,7 @@ row_mysql_unfreeze_data_dictionary(
 /*===============================*/
 	trx_t*	trx);	/* in: transaction */
 /*************************************************************************
-Drops a table for MySQL. If the name of the table ends in
+Creates a table for MySQL. If the name of the table ends in
 one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
 "innodb_table_monitor", then this will also start the printing of monitor
 output by the master thread. If the table name ends in "innodb_mem_validate",
@@ -464,6 +464,16 @@ row_check_table_for_mysql(
 	row_prebuilt_t*	prebuilt);	/* in: prebuilt struct in MySQL
 					handle */
 
+/*************************************************************************
+Determines if a table is a magic monitor table. */
+
+ibool
+row_is_magic_monitor_table(
+/*=======================*/
+					/* out: TRUE if monitor table */
+	const char*	table_name);	/* in: name of the table, in the
+					form database/table_name */
+
 /* A struct describing a place for an individual column in the MySQL
 row format which is presented to the table handler in ha_innobase.
 This template struct is used to speed up row transformations between
@@ -671,7 +681,7 @@ struct row_prebuilt_struct {
 					fetched row in fetch_cache */
 	ulint		n_fetch_cached;	/* number of not yet fetched rows
 					in fetch_cache */
-	mem_heap_t*	blob_heap;	/* in SELECTS BLOB fie lds are copied
+	mem_heap_t*	blob_heap;	/* in SELECTS BLOB fields are copied
 					to this heap */
 	mem_heap_t*	old_vers_heap;	/* memory heap where a previous
 					version is built in consistent read */

=== modified file 'storage/innobase/include/row0sel.h'
--- a/storage/innobase/include/row0sel.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/row0sel.h	2008-06-12 00:08:07 +0000
@@ -181,7 +181,7 @@ row_search_max_autoinc(
 					error code */
 	dict_index_t*	index,		/* in: index to search */
 	const char*	col_name,	/* in: autoinc column name */
-	ib_longlong*	value);		/* out: AUTOINC value read */
+	ib_ulonglong*	value);		/* out: AUTOINC value read */
 
 /* A structure for caching column values for prefetched rows */
 struct sel_buf_struct{

=== modified file 'storage/innobase/include/srv0srv.h'
--- a/storage/innobase/include/srv0srv.h	2008-03-31 09:37:03 +0000
+++ b/storage/innobase/include/srv0srv.h	2008-06-12 00:08:07 +0000
@@ -249,11 +249,7 @@ extern srv_sys_t*	srv_sys;
 
 /* Alternatives for the file flush option in Unix; see the InnoDB manual
 about what these mean */
-#define SRV_UNIX_FDATASYNC	1	/* This is the default; it is
-					currently mapped to a call of
-					fsync() because fdatasync() seemed
-					to corrupt files in Linux and
-					Solaris */
+#define SRV_UNIX_FSYNC		1	/* This is the default */
 #define SRV_UNIX_O_DSYNC	2
 #define SRV_UNIX_LITTLESYNC	3
 #define SRV_UNIX_NOSYNC		4
@@ -505,7 +501,9 @@ struct export_var_struct{
 	ulint innodb_buffer_pool_pages_dirty;
 	ulint innodb_buffer_pool_pages_misc;
 	ulint innodb_buffer_pool_pages_free;
+#ifdef UNIV_DEBUG
 	ulint innodb_buffer_pool_pages_latched;
+#endif /* UNIV_DEBUG */
 	ulint innodb_buffer_pool_read_requests;
 	ulint innodb_buffer_pool_reads;
 	ulint innodb_buffer_pool_wait_free;

=== modified file 'storage/innobase/include/sync0arr.h'
--- a/storage/innobase/include/sync0arr.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/sync0arr.h	2008-06-12 00:08:07 +0000
@@ -66,26 +66,21 @@ sync_array_wait_event(
 	sync_array_t*	arr,	/* in: wait array */
 	ulint		index);	 /* in: index of the reserved cell */
 /**********************************************************************
-Frees the cell safely by reserving the sync array mutex and decrementing
-n_reserved if necessary. Should only be called from mutex_spin_wait. */
+Frees the cell. NOTE! sync_array_wait_event frees the cell
+automatically! */
 
 void
-sync_array_free_cell_protected(
-/*===========================*/
+sync_array_free_cell(
+/*=================*/
 	sync_array_t*	arr,	/* in: wait array */
 	ulint		index);	/* in: index of the cell in array */
 /**************************************************************************
-Looks for the cells in the wait array which refer
-to the wait object specified,
-and sets their corresponding events to the signaled state. In this
-way releases the threads waiting for the object to contend for the object.
-It is possible that no such cell is found, in which case does nothing. */
+Note that one of the wait objects was signalled. */
 
 void
-sync_array_signal_object(
-/*=====================*/
-	sync_array_t*	arr,	/* in: wait array */
-	void*		object);/* in: wait object */
+sync_array_object_signalled(
+/*========================*/
+	sync_array_t*	arr);	/* in: wait array */
 /**************************************************************************
 If the wakeup algorithm does not work perfectly at semaphore relases,
 this function will do the waking (see the comment in mutex_exit). This

=== modified file 'storage/innobase/include/sync0rw.h'
--- a/storage/innobase/include/sync0rw.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/sync0rw.h	2008-06-12 00:08:07 +0000
@@ -421,6 +421,18 @@ blocked by readers, a writer may queue f
 field. Then no new readers are allowed in. */
 
 struct rw_lock_struct {
+	os_event_t	event;	/* Used by sync0arr.c for thread queueing */
+
+#ifdef __WIN__
+	os_event_t	wait_ex_event;	/* This windows specific event is
+				used by the thread which has set the
+				lock state to RW_LOCK_WAIT_EX. The
+				rw_lock design guarantees that this
+				thread will be the next one to proceed
+				once the current the event gets
+				signalled. See LEMMA 2 in sync0sync.c */
+#endif
+
 	ulint	reader_count;	/* Number of readers who have locked this
 				lock in the shared mode */
 	ulint	writer;		/* This field is set to RW_LOCK_EX if there

=== modified file 'storage/innobase/include/sync0rw.ic'
--- a/storage/innobase/include/sync0rw.ic	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/sync0rw.ic	2008-06-12 00:08:07 +0000
@@ -381,7 +381,11 @@ rw_lock_s_unlock_func(
 	mutex_exit(mutex);
 
 	if (UNIV_UNLIKELY(sg)) {
-		sync_array_signal_object(sync_primary_wait_array, lock);
+#ifdef __WIN__
+		os_event_set(lock->wait_ex_event);
+#endif
+		os_event_set(lock->event);
+		sync_array_object_signalled(sync_primary_wait_array);
 	}
 
 	ut_ad(rw_lock_validate(lock));
@@ -461,7 +465,11 @@ rw_lock_x_unlock_func(
 	mutex_exit(&(lock->mutex));
 
 	if (UNIV_UNLIKELY(sg)) {
-		sync_array_signal_object(sync_primary_wait_array, lock);
+#ifdef __WIN__
+		os_event_set(lock->wait_ex_event);
+#endif
+		os_event_set(lock->event);
+		sync_array_object_signalled(sync_primary_wait_array);
 	}
 
 	ut_ad(rw_lock_validate(lock));

=== modified file 'storage/innobase/include/sync0sync.h'
--- a/storage/innobase/include/sync0sync.h	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/sync0sync.h	2008-06-12 00:08:07 +0000
@@ -470,6 +470,7 @@ Do not use its fields directly! The stru
 implementation of a mutual exclusion semaphore. */
 
 struct mutex_struct {
+	os_event_t	event;	/* Used by sync0arr.c for the wait queue */
 	ulint	lock_word;	/* This ulint is the target of the atomic
 				test-and-set instruction in Win32 */
 #if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)

=== modified file 'storage/innobase/include/sync0sync.ic'
--- a/storage/innobase/include/sync0sync.ic	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/sync0sync.ic	2008-06-12 00:08:07 +0000
@@ -211,7 +211,7 @@ mutex_exit(
 	perform the read first, which could leave a waiting
 	thread hanging indefinitely.
 
-	Our current solution call every 10 seconds
+	Our current solution call every second
 	sync_arr_wake_threads_if_sema_free()
 	to wake up possible hanging threads if
 	they are missed in mutex_signal_object. */

=== modified file 'storage/innobase/include/trx0undo.h'
--- a/storage/innobase/include/trx0undo.h	2008-03-31 09:37:03 +0000
+++ b/storage/innobase/include/trx0undo.h	2008-06-12 00:08:07 +0000
@@ -240,6 +240,7 @@ trx_undo_set_state_at_finish(
 /*=========================*/
 				/* out: undo log segment header page,
 				x-latched */
+	trx_rseg_t*	rseg,	/* in: rollback segment memory object */
 	trx_t*		trx,	/* in: transaction */
 	trx_undo_t*	undo,	/* in: undo log memory copy */
 	mtr_t*		mtr);	/* in: mtr */

=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/include/univ.i	2008-06-12 00:08:07 +0000
@@ -212,8 +212,11 @@ typedef long int		lint;
 
 #ifdef __WIN__
 typedef __int64			ib_longlong;
+typedef unsigned __int64	ib_ulonglong;
 #else
+/* Note: longlong and ulonglong come from MySQL headers. */
 typedef longlong		ib_longlong;
+typedef ulonglong               ib_ulonglong;
 #endif
 
 typedef unsigned long long int	ullint;

=== modified file 'storage/innobase/include/ut0ut.h'
--- a/storage/innobase/include/ut0ut.h	2007-11-06 22:42:58 +0000
+++ b/storage/innobase/include/ut0ut.h	2008-06-12 00:08:07 +0000
@@ -145,11 +145,15 @@ ib_time_t
 ut_time(void);
 /*=========*/
 /**************************************************************
-Returns system time. */
+Returns system time.
+Upon successful completion, the value 0 is returned; otherwise the
+value -1 is returned and the global variable errno is set to indicate the
+error. */
 
-void
+int
 ut_usectime(
 /*========*/
+			/* out: 0 on success, -1 otherwise */
 	ulint*	sec,	/* out: seconds since the Epoch */
 	ulint*	ms);	/* out: microseconds since the Epoch+*sec */
 /**************************************************************

=== modified file 'storage/innobase/os/os0file.c'
--- a/storage/innobase/os/os0file.c	2008-03-31 09:37:03 +0000
+++ b/storage/innobase/os/os0file.c	2008-06-12 00:08:07 +0000
@@ -22,8 +22,6 @@ Created 10/21/1995 Heikki Tuuri
 #include <errno.h>
 #endif /* UNIV_HOTBACKUP */
 
-#undef HAVE_FDATASYNC
-
 #ifdef POSIX_ASYNC_IO
 /* We assume in this case that the OS has standard Posix aio (at least SunOS
 2.6, HP-UX 11i and AIX 4.3 have) */
@@ -1269,9 +1267,19 @@ try_again:
 	if (file == INVALID_HANDLE_VALUE) {
 		*success = FALSE;
 
-		retry = os_file_handle_error(name,
-					     create_mode == OS_FILE_CREATE ?
-					     "create" : "open");
+		/* When srv_file_per_table is on, file creation failure may not
+		be critical to the whole instance. Do not crash the server in
+		case of unknown errors. */
+		if (srv_file_per_table) {
+			retry = os_file_handle_error_no_exit(name,
+						create_mode == OS_FILE_CREATE ?
+						"create" : "open");
+		} else {
+			retry = os_file_handle_error(name,
+						create_mode == OS_FILE_CREATE ?
+						"create" : "open");
+		}
+
 		if (retry) {
 			goto try_again;
 		}
@@ -1346,9 +1354,19 @@ try_again:
 	if (file == -1) {
 		*success = FALSE;
 
-		retry = os_file_handle_error(name,
-					     create_mode == OS_FILE_CREATE ?
-					     "create" : "open");
+		/* When srv_file_per_table is on, file creation failure may not
+		be critical to the whole instance. Do not crash the server in
+		case of unknown errors. */
+		if (srv_file_per_table) {
+			retry = os_file_handle_error_no_exit(name,
+						create_mode == OS_FILE_CREATE ?
+						"create" : "open");
+		} else {
+			retry = os_file_handle_error(name,
+						create_mode == OS_FILE_CREATE ?
+						"create" : "open");
+		}
+
 		if (retry) {
 			goto try_again;
 		} else {
@@ -1812,6 +1830,55 @@ os_file_set_eof(
 #endif /* __WIN__ */
 }
 
+#ifndef __WIN__
+/***************************************************************************
+Wrapper to fsync(2) that retries the call on some errors.
+Returns the value 0 if successful; otherwise the value -1 is returned and
+the global variable errno is set to indicate the error. */
+
+static
+int
+os_file_fsync(
+/*==========*/
+				/* out: 0 if success, -1 otherwise */
+	os_file_t	file)	/* in: handle to a file */
+{
+	int	ret;
+	int	failures;
+	ibool	retry;
+
+	failures = 0;
+
+	do {
+		ret = fsync(file);
+
+		os_n_fsyncs++;
+
+		if (ret == -1 && errno == ENOLCK) {
+
+			if (failures % 100 == 0) {
+
+				ut_print_timestamp(stderr);
+				fprintf(stderr,
+					"  InnoDB: fsync(): "
+					"No locks available; retrying\n");
+			}
+
+			os_thread_sleep(200000 /* 0.2 sec */);
+
+			failures++;
+
+			retry = TRUE;
+		} else {
+
+			retry = FALSE;
+		}
+	} while (retry);
+
+	return(ret);
+}
+#endif /* !__WIN__ */
+
 /***************************************************************************
 Flushes the write buffers of a given file to the disk. */
 
@@ -1869,23 +1936,19 @@ os_file_flush(
 		/* If we are not on an operating system that supports this,
 		then fall back to a plain fsync. */
 
-		ret = fsync(file);
+		ret = os_file_fsync(file);
 	} else {
 		ret = fcntl(file, F_FULLFSYNC, NULL);
 
 		if (ret) {
 			/* If we are not on a file system that supports this,
 			then fall back to a plain fsync. */
-			ret = fsync(file);
+			ret = os_file_fsync(file);
 		}
 	}
-#elif HAVE_FDATASYNC
-	ret = fdatasync(file);
 #else
-	/*	fprintf(stderr, "Flushing to file %p\n", file); */
-	ret = fsync(file);
+	ret = os_file_fsync(file);
 #endif
-	os_n_fsyncs++;
 
 	if (ret == 0) {
 		return(TRUE);

=== modified file 'storage/innobase/os/os0sync.c'
--- a/storage/innobase/os/os0sync.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/os/os0sync.c	2008-06-12 00:08:07 +0000
@@ -21,6 +21,7 @@ Created 9/6/1995 Heikki Tuuri
 
 /* Type definition for an operating system mutex struct */
 struct os_mutex_struct{
+	os_event_t	event;	/* Used by sync0arr.c for queing threads */
 	void*		handle;	/* OS handle to mutex */
 	ulint		count;	/* we use this counter to check
 				that the same thread does not
@@ -35,6 +36,7 @@ struct os_mutex_struct{
 /* Mutex protecting counts and the lists of OS mutexes and events */
 os_mutex_t	os_sync_mutex;
 ibool		os_sync_mutex_inited	= FALSE;
+ibool		os_sync_free_called	= FALSE;
 
 /* This is incremented by 1 in os_thread_create and decremented by 1 in
 os_thread_exit */
@@ -50,6 +52,10 @@ ulint	os_event_count		= 0;
 ulint	os_mutex_count		= 0;
 ulint	os_fast_mutex_count	= 0;
 
+/* Because a mutex is embedded inside an event and there is an
+event embedded inside a mutex, on free, this generates a recursive call.
+This version of the free event function doesn't acquire the global lock */
+static void os_event_free_internal(os_event_t	event);
 
 /*************************************************************
 Initializes global event and OS 'slow' mutex lists. */
@@ -76,6 +82,7 @@ os_sync_free(void)
 	os_event_t	event;
 	os_mutex_t	mutex;
 
+	os_sync_free_called = TRUE;
 	event = UT_LIST_GET_FIRST(os_event_list);
 
 	while (event) {
@@ -99,6 +106,7 @@ os_sync_free(void)
 
 		mutex = UT_LIST_GET_FIRST(os_mutex_list);
 	}
+	os_sync_free_called = FALSE;
 }
 
 /*************************************************************
@@ -144,17 +152,31 @@ os_event_create(
 	ut_a(0 == pthread_cond_init(&(event->cond_var), NULL));
 #endif
 	event->is_set = FALSE;
-	event->signal_count = 0;
+
+	/* We return this value in os_event_reset(), which can then be
+	be used to pass to the os_event_wait_low(). The value of zero
+	is reserved in os_event_wait_low() for the case when the
+	caller does not want to pass any signal_count value. To
+	distinguish between the two cases we initialize signal_count
+	to 1 here. */
+	event->signal_count = 1;
 #endif /* __WIN__ */
 
-	/* Put to the list of events */
-	os_mutex_enter(os_sync_mutex);
+	/* The os_sync_mutex can be NULL because during startup an event
+	can be created [ because it's embedded in the mutex/rwlock ] before
+	this module has been initialized */
+	if (os_sync_mutex != NULL) {
+		os_mutex_enter(os_sync_mutex);
+	}
 
+	/* Put to the list of events */
 	UT_LIST_ADD_FIRST(os_event_list, os_event_list, event);
 
 	os_event_count++;
 
-	os_mutex_exit(os_sync_mutex);
+	if (os_sync_mutex != NULL) {
+		os_mutex_exit(os_sync_mutex);
+	}
 
 	return(event);
 }
@@ -231,13 +253,20 @@ os_event_set(
 
 /**************************************************************
 Resets an event semaphore to the nonsignaled state. Waiting threads will
-stop to wait for the event. */
+stop to wait for the event.
+The return value should be passed to os_even_wait_low() if it is desired
+that this thread should not wait in case of an intervening call to
+os_event_set() between this os_event_reset() and the
+os_event_wait_low() call. See comments for os_event_wait_low(). */
 
-void
+ib_longlong
 os_event_reset(
 /*===========*/
+				/* out: current signal_count. */
 	os_event_t	event)	/* in: event to reset */
 {
+	ib_longlong	ret = 0;
+
 #ifdef __WIN__
 	ut_a(event);
 
@@ -252,9 +281,40 @@ os_event_reset(
 	} else {
 		event->is_set = FALSE;
 	}
+	ret = event->signal_count;
 
 	os_fast_mutex_unlock(&(event->os_mutex));
 #endif
+	return(ret);
+}
+
+/**************************************************************
+Frees an event object, without acquiring the global lock. */
+static
+void
+os_event_free_internal(
+/*===================*/
+	os_event_t	event)	/* in: event to free */
+{
+#ifdef __WIN__
+	ut_a(event);
+
+	ut_a(CloseHandle(event->handle));
+#else
+	ut_a(event);
+
+	/* This is to avoid freeing the mutex twice */
+	os_fast_mutex_free(&(event->os_mutex));
+
+	ut_a(0 == pthread_cond_destroy(&(event->cond_var)));
+#endif
+	/* Remove from the list of events */
+
+	UT_LIST_REMOVE(os_event_list, os_event_list, event);
+
+	os_event_count--;
+
+	ut_free(event);
 }
 
 /**************************************************************
@@ -293,18 +353,38 @@ os_event_free(
 Waits for an event object until it is in the signaled state. If
 srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
 waiting thread when the event becomes signaled (or immediately if the
-event is already in the signaled state). */
+event is already in the signaled state).
+
+Typically, if the event has been signalled after the os_event_reset()
+we'll return immediately because event->is_set == TRUE.
+There are, however, situations (e.g.: sync_array code) where we may
+lose this information. For example:
+
+thread A calls os_event_reset()
+thread B calls os_event_set()   [event->is_set == TRUE]
+thread C calls os_event_reset() [event->is_set == FALSE]
+thread A calls os_event_wait()  [infinite wait!]
+thread C calls os_event_wait()  [infinite wait!]
+
+Where such a scenario is possible, to avoid infinite wait, the
+value returned by os_event_reset() should be passed in as
+reset_sig_count. */
 
 void
-os_event_wait(
-/*==========*/
-	os_event_t	event)	/* in: event to wait */
+os_event_wait_low(
+/*==============*/
+	os_event_t	event,		/* in: event to wait */
+	ib_longlong	reset_sig_count)/* in: zero or the value
+					returned by previous call of
+					os_event_reset(). */
 {
 #ifdef __WIN__
 	DWORD	err;
 
 	ut_a(event);
 
+	UT_NOT_USED(reset_sig_count);
+
 	/* Specify an infinite time limit for waiting */
 	err = WaitForSingleObject(event->handle, INFINITE);
 
@@ -318,7 +398,11 @@ os_event_wait(
 
 	os_fast_mutex_lock(&(event->os_mutex));
 
-	old_signal_count = event->signal_count;
+	if (reset_sig_count) {
+		old_signal_count = reset_sig_count;
+	} else {
+		old_signal_count = event->signal_count;
+	}
 
 	for (;;) {
 		if (event->is_set == TRUE
@@ -458,6 +542,7 @@ os_mutex_create(
 
 	mutex_str->handle = mutex;
 	mutex_str->count = 0;
+	mutex_str->event = os_event_create(NULL);
 
 	if (os_sync_mutex_inited) {
 		/* When creating os_sync_mutex itself we cannot reserve it */
@@ -534,6 +619,10 @@ os_mutex_free(
 {
 	ut_a(mutex);
 
+	if (!os_sync_free_called) {
+		os_event_free_internal(mutex->event);
+	}
+
 	if (os_sync_mutex_inited) {
 		os_mutex_enter(os_sync_mutex);
 	}

=== modified file 'storage/innobase/plug.in'
--- a/storage/innobase/plug.in	2008-05-14 09:24:14 +0000
+++ b/storage/innobase/plug.in	2008-06-12 00:08:07 +0000
@@ -15,25 +15,30 @@ MYSQL_PLUGIN_ACTIONS(innobase,  [
   AC_CHECK_FUNCS(localtime_r)
   AC_C_BIGENDIAN
   case "$target_os" in
-         lin*)
-           CFLAGS="$CFLAGS -DUNIV_LINUX";;
-         hpux10*)
-           CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE -DUNIV_HPUX -DUNIV_HPUX10";;
-         hp*)
-           CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE -DUNIV_HPUX";;
-         aix*)
-           CFLAGS="$CFLAGS -DUNIV_AIX";;
-         irix*)
-           CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
-         osf*)
-           CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
-	 *solaris*|*SunOS*)
-           CFLAGS="$CFLAGS -DUNIV_SOLARIS";;
-         sysv5uw7*)
-           # Problem when linking on SCO
-           CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
-         openbsd*)
-           CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
+	lin*)
+		CFLAGS="$CFLAGS -DUNIV_LINUX";;
+	hpux10*)
+		CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE -DUNIV_HPUX -DUNIV_HPUX10";;
+	hp*)
+		CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE -DUNIV_HPUX";;
+	aix*)
+		CFLAGS="$CFLAGS -DUNIV_AIX";;
+	irix*|osf*|sysv5uw7*|openbsd*)
+		CFLAGS="$CFLAGS -DUNIV_MUST_NOT_INLINE";;
+	*solaris*|*SunOS*)
+		CFLAGS="$CFLAGS -DUNIV_SOLARIS";;
   esac
+  INNODB_DYNAMIC_CFLAGS="-DMYSQL_DYNAMIC_PLUGIN"
+  case "$target_cpu" in
+	x86_64)
+		# The AMD64 ABI forbids absolute addresses in shared libraries
+		;;
+	*86)
+		# Use absolute addresses on IA-32
+		INNODB_DYNAMIC_CFLAGS="$INNODB_DYNAMIC_CFLAGS -prefer-non-pic"
+		;;
+  esac
+  AC_SUBST(INNODB_DYNAMIC_CFLAGS)
   ])
 
+# vim: set ft=config:

=== modified file 'storage/innobase/read/read0read.c'
--- a/storage/innobase/read/read0read.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/read/read0read.c	2008-06-12 00:08:07 +0000
@@ -212,7 +212,6 @@ read_view_oldest_copy_or_open_new(
 	view_copy->low_limit_no = old_view->low_limit_no;
 	view_copy->low_limit_id = old_view->low_limit_id;
 
-	view_copy->can_be_too_old = FALSE;
 
 	if (n > 0) {
 		/* The last active transaction has the smallest id: */
@@ -258,8 +257,6 @@ read_view_open_now(
 	view->low_limit_no = trx_sys->max_trx_id;
 	view->low_limit_id = view->low_limit_no;
 
-	view->can_be_too_old = FALSE;
-
 	n = 0;
 	trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
 
@@ -432,8 +429,6 @@ read_cursor_view_create_for_mysql(
 	view->low_limit_no = trx_sys->max_trx_id;
 	view->low_limit_id = view->low_limit_no;
 
-	view->can_be_too_old = FALSE;
-
 	n = 0;
 	trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
 

=== modified file 'storage/innobase/row/row0mysql.c'
--- a/storage/innobase/row/row0mysql.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/row/row0mysql.c	2008-06-12 00:08:07 +0000
@@ -57,6 +57,12 @@ static const char S_innodb_tablespace_mo
 static const char S_innodb_table_monitor[] = "innodb_table_monitor";
 static const char S_innodb_mem_validate[] = "innodb_mem_validate";
 
+/* Evaluates to true if str1 equals str2_onstack, used for comparing
+the above strings. */
+#define STR_EQ(str1, str1_len, str2_onstack) \
+	((str1_len) == sizeof(str2_onstack) \
+	 && memcmp(str1, str2_onstack, sizeof(str2_onstack)) == 0)
+
 /***********************************************************************
 Determine if the given name is a name reserved for MySQL system tables. */
 static
@@ -1728,7 +1734,7 @@ row_mysql_unlock_data_dictionary(
 }
 
 /*************************************************************************
-Drops a table for MySQL. If the name of the table ends in
+Creates a table for MySQL. If the name of the table ends in
 one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
 "innodb_table_monitor", then this will also start the printing of monitor
 output by the master thread. If the table name ends in "innodb_mem_validate",
@@ -1809,9 +1815,7 @@ row_create_table_for_mysql(
 	table_name++;
 	table_name_len = strlen(table_name) + 1;
 
-	if (table_name_len == sizeof S_innodb_monitor
-	    && !memcmp(table_name, S_innodb_monitor,
-		       sizeof S_innodb_monitor)) {
+	if (STR_EQ(table_name, table_name_len, S_innodb_monitor)) {
 
 		/* Table equals "innodb_monitor":
 		start monitor prints */
@@ -1822,28 +1826,24 @@ row_create_table_for_mysql(
 		of InnoDB monitor prints */
 
 		os_event_set(srv_lock_timeout_thread_event);
-	} else if (table_name_len == sizeof S_innodb_lock_monitor
-		   && !memcmp(table_name, S_innodb_lock_monitor,
-			      sizeof S_innodb_lock_monitor)) {
+	} else if (STR_EQ(table_name, table_name_len,
+			  S_innodb_lock_monitor)) {
 
 		srv_print_innodb_monitor = TRUE;
 		srv_print_innodb_lock_monitor = TRUE;
 		os_event_set(srv_lock_timeout_thread_event);
-	} else if (table_name_len == sizeof S_innodb_tablespace_monitor
-		   && !memcmp(table_name, S_innodb_tablespace_monitor,
-			      sizeof S_innodb_tablespace_monitor)) {
+	} else if (STR_EQ(table_name, table_name_len,
+			  S_innodb_tablespace_monitor)) {
 
 		srv_print_innodb_tablespace_monitor = TRUE;
 		os_event_set(srv_lock_timeout_thread_event);
-	} else if (table_name_len == sizeof S_innodb_table_monitor
-		   && !memcmp(table_name, S_innodb_table_monitor,
-			      sizeof S_innodb_table_monitor)) {
+	} else if (STR_EQ(table_name, table_name_len,
+			  S_innodb_table_monitor)) {
 
 		srv_print_innodb_table_monitor = TRUE;
 		os_event_set(srv_lock_timeout_thread_event);
-	} else if (table_name_len == sizeof S_innodb_mem_validate
-		   && !memcmp(table_name, S_innodb_mem_validate,
-			      sizeof S_innodb_mem_validate)) {
+	} else if (STR_EQ(table_name, table_name_len,
+			  S_innodb_mem_validate)) {
 		/* We define here a debugging feature intended for
 		developers */
 
@@ -1963,6 +1963,7 @@ row_create_index_for_mysql(
 	ulint		err;
 	ulint		i, j;
 	ulint		len;
+	char*		table_name;
 
 #ifdef UNIV_SYNC_DEBUG
 	ut_ad(rw_lock_own(&dict_operation_lock, RW_LOCK_EX));
@@ -1972,6 +1973,11 @@ row_create_index_for_mysql(
 
 	trx->op_info = "creating index";
 
+	/* Copy the table name because we may want to drop the
+	table later, after the index object is freed (inside
+	que_run_threads()) and thus index->table_name is not available. */
+	table_name = mem_strdup(index->table_name);
+
 	trx_start_if_not_started(trx);
 
 	/* Check that the same column does not appear twice in the index.
@@ -2044,13 +2050,15 @@ error_handling:
 
 		trx_general_rollback_for_mysql(trx, FALSE, NULL);
 
-		row_drop_table_for_mysql(index->table_name, trx, FALSE);
+		row_drop_table_for_mysql(table_name, trx, FALSE);
 
 		trx->error_state = DB_SUCCESS;
 	}
 
 	trx->op_info = "";
 
+	mem_free(table_name);
+
 	return((int) err);
 }
 
@@ -3312,6 +3320,66 @@ funct_exit:
 	return((int) err);
 }
 
+/***********************************************************************
+Drop all foreign keys in a database, see Bug#18942.
+Called at the end of row_drop_database_for_mysql(). */
+static
+ulint
+drop_all_foreign_keys_in_db(
+/*========================*/
+				/* out: error code or DB_SUCCESS */
+	const char*	name,	/* in: database name which ends to '/' */
+	trx_t*		trx)	/* in: transaction handle */
+{
+	pars_info_t*	pinfo;
+	ulint		err;
+
+	ut_a(name[strlen(name) - 1] == '/');
+
+	pinfo = pars_info_create();
+
+	pars_info_add_str_literal(pinfo, "dbname", name);
+
+/* true if for_name is not prefixed with dbname */
+#define TABLE_NOT_IN_THIS_DB \
+"SUBSTR(for_name, 0, LENGTH(:dbname)) <> :dbname"
+
+	err = que_eval_sql(pinfo,
+			   "PROCEDURE DROP_ALL_FOREIGN_KEYS_PROC () IS\n"
+			   "foreign_id CHAR;\n"
+			   "for_name CHAR;\n"
+			   "found INT;\n"
+			   "DECLARE CURSOR cur IS\n"
+			   "SELECT ID, FOR_NAME FROM SYS_FOREIGN\n"
+			   "WHERE FOR_NAME >= :dbname\n"
+			   "LOCK IN SHARE MODE\n"
+			   "ORDER BY FOR_NAME;\n"
+			   "BEGIN\n"
+			   "found := 1;\n"
+			   "OPEN cur;\n"
+			   "WHILE found = 1 LOOP\n"
+			   "        FETCH cur INTO foreign_id, for_name;\n"
+			   "        IF (SQL % NOTFOUND) THEN\n"
+			   "                found := 0;\n"
+			   "        ELSIF (" TABLE_NOT_IN_THIS_DB ") THEN\n"
+			   "                found := 0;\n"
+			   "        ELSIF (1=1) THEN\n"
+			   "                DELETE FROM SYS_FOREIGN_COLS\n"
+			   "                WHERE ID = foreign_id;\n"
+			   "                DELETE FROM SYS_FOREIGN\n"
+			   "                WHERE ID = foreign_id;\n"
+			   "        END IF;\n"
+			   "END LOOP;\n"
+			   "CLOSE cur;\n"
+			   "COMMIT WORK;\n"
+			   "END;\n",
+			   FALSE, /* do not reserve dict mutex,
+				  we are already holding it */
+			   trx);
+
+	return(err);
+}
+
 /*************************************************************************
 Drops a database for MySQL. */
 
@@ -3382,6 +3450,19 @@ loop:
 		}
 	}
 
+	if (err == DB_SUCCESS) {
+		/* after dropping all tables try to drop all leftover
+		foreign keys in case orphaned ones exist */
+		err = (int) drop_all_foreign_keys_in_db(name, trx);
+
+		if (err != DB_SUCCESS) {
+			fputs("InnoDB: DROP DATABASE ", stderr);
+			ut_print_name(stderr, trx, TRUE, name);
+			fprintf(stderr, " failed with error %d while "
+				"dropping all foreign keys", err);
+		}
+	}
+
 	trx_commit_for_mysql(trx);
 
 	row_mysql_unlock_data_dictionary(trx);
@@ -4057,3 +4138,33 @@ row_check_table_for_mysql(
 
 	return(ret);
 }
+
+/*************************************************************************
+Determines if a table is a magic monitor table. */
+
+ibool
+row_is_magic_monitor_table(
+/*=======================*/
+					/* out: TRUE if monitor table */
+	const char*	table_name)	/* in: name of the table, in the
+					form database/table_name */
+{
+	const char*	name; /* table_name without database/ */
+	ulint		len;
+
+	name = strchr(table_name, '/');
+	ut_a(name != NULL);
+	name++;
+	len = strlen(name) + 1;
+
+	if (STR_EQ(name, len, S_innodb_monitor)
+	    || STR_EQ(name, len, S_innodb_lock_monitor)
+	    || STR_EQ(name, len, S_innodb_tablespace_monitor)
+	    || STR_EQ(name, len, S_innodb_table_monitor)
+	    || STR_EQ(name, len, S_innodb_mem_validate)) {
+
+		return(TRUE);
+	}
+
+	return(FALSE);
+}

=== modified file 'storage/innobase/row/row0sel.c'
--- a/storage/innobase/row/row0sel.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/row/row0sel.c	2008-06-12 00:08:07 +0000
@@ -2645,6 +2645,25 @@ row_sel_store_mysql_rec(
 
 			data = rec_get_nth_field(rec, offsets,
 						 templ->rec_field_no, &len);
+
+			if (UNIV_UNLIKELY(templ->type == DATA_BLOB)
+			    && len != UNIV_SQL_NULL) {
+
+				/* It is a BLOB field locally stored in the
+				InnoDB record: we MUST copy its contents to
+				prebuilt->blob_heap here because later code
+				assumes all BLOB values have been copied to a
+				safe place. */
+
+				if (prebuilt->blob_heap == NULL) {
+					prebuilt->blob_heap = mem_heap_create(
+						UNIV_PAGE_SIZE);
+				}
+
+				data = memcpy(mem_heap_alloc(
+						prebuilt->blob_heap, len),
+						data, len);
+			}
 		}
 
 		if (len != UNIV_SQL_NULL) {
@@ -3583,7 +3602,9 @@ shortcut_fails_too_big_rec:
 
 	if (trx->isolation_level <= TRX_ISO_READ_COMMITTED
 	    && prebuilt->select_lock_type != LOCK_NONE
-	    && trx->mysql_query_str && trx->mysql_thd) {
+	    && trx->mysql_thd != NULL
+	    && trx->mysql_query_str != NULL
+	    && *trx->mysql_query_str != NULL) {
 
 		/* Scan the MySQL query string; check if SELECT is the first
 		word there */
@@ -4582,7 +4603,7 @@ row_search_check_if_query_cache_permitte
 Read the AUTOINC column from the current row. If the value is less than
 0 and the type is not unsigned then we reset the value to 0. */
 static
-ib_longlong
+ib_ulonglong
 row_search_autoinc_read_column(
 /*===========================*/
 					/* out: value read from the column */
@@ -4593,10 +4614,8 @@ row_search_autoinc_read_column(
 {
 	ulint		len;
 	const byte*	data;
-	ib_longlong	value;
+	ib_ulonglong	value;
 	mem_heap_t*	heap = NULL;
-	/* Our requirement is that dest should be word aligned. */
-	byte		dest[sizeof(value)];
 	ulint		offsets_[REC_OFFS_NORMAL_SIZE];
 	ulint*		offsets	= offsets_;
 
@@ -4614,41 +4633,14 @@ row_search_autoinc_read_column(
 	ut_a(len != UNIV_SQL_NULL);
 	ut_a(len <= sizeof value);
 
-	mach_read_int_type(dest, data, len, unsigned_type);
-
-	/* The assumption here is that the AUTOINC value can't be negative
-	and that dest is word aligned. */
-	switch (len) {
-	case 8:
-		value = *(ib_longlong*) dest;
-		break;
-
-	case 4:
-		value = *(ib_uint32_t*) dest;
-		break;
-
-	case 3:
-		value = *(ib_uint32_t*) dest;
-		value &= 0xFFFFFF;
-		break;
-
-	case 2:
-		value = *(uint16 *) dest;
-		break;
-
-	case 1:
-		value = *dest;
-		break;
-
-	default:
-		ut_error;
-	}
+	value = mach_read_int_type(data, len, unsigned_type);
 
 	if (UNIV_LIKELY_NULL(heap)) {
 		mem_heap_free(heap);
 	}
 
-	if (!unsigned_type && value < 0) {
+	/* We assume that the autoinc counter can't be negative. */
+	if (!unsigned_type && (ib_longlong) value < 0) {
 		value = 0;
 	}
 
@@ -4687,7 +4679,7 @@ row_search_max_autoinc(
 					column name can't be found in index */
 	dict_index_t*	index,		/* in: index to search */
 	const char*	col_name,	/* in: name of autoinc column */
-	ib_longlong*	value)		/* out: AUTOINC value read */
+	ib_ulonglong*	value)		/* out: AUTOINC value read */
 {
 	ulint		i;
 	ulint		n_cols;

=== modified file 'storage/innobase/srv/srv0srv.c'
--- a/storage/innobase/srv/srv0srv.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/srv/srv0srv.c	2008-06-12 00:08:07 +0000
@@ -192,7 +192,7 @@ a heavier load on the I/O sub system. */
 ulong	srv_insert_buffer_batch_size = 20;
 
 char*	srv_file_flush_method_str = NULL;
-ulint	srv_unix_file_flush_method = SRV_UNIX_FDATASYNC;
+ulint	srv_unix_file_flush_method = SRV_UNIX_FSYNC;
 ulint	srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
 
 ulint	srv_max_n_open_files	  = 300;
@@ -1453,8 +1453,11 @@ srv_suspend_mysql_thread(
 		srv_n_lock_wait_count++;
 		srv_n_lock_wait_current_count++;
 
-		ut_usectime(&sec, &ms);
-		start_time = (ib_longlong)sec * 1000000 + ms;
+		if (ut_usectime(&sec, &ms) == -1) {
+			start_time = -1;
+		} else {
+			start_time = (ib_longlong)sec * 1000000 + ms;
+		}
 	}
 	/* Wake the lock timeout monitor thread, if it is suspended */
 
@@ -1508,14 +1511,20 @@ srv_suspend_mysql_thread(
 	wait_time = ut_difftime(ut_time(), slot->suspend_time);
 
 	if (thr->lock_state == QUE_THR_LOCK_ROW) {
-		ut_usectime(&sec, &ms);
-		finish_time = (ib_longlong)sec * 1000000 + ms;
+		if (ut_usectime(&sec, &ms) == -1) {
+			finish_time = -1;
+		} else {
+			finish_time = (ib_longlong)sec * 1000000 + ms;
+		}
 
 		diff_time = (ulint) (finish_time - start_time);
 
 		srv_n_lock_wait_current_count--;
 		srv_n_lock_wait_time = srv_n_lock_wait_time + diff_time;
-		if (diff_time > srv_n_lock_max_wait_time) {
+		if (diff_time > srv_n_lock_max_wait_time &&
+		    /* only update the variable if we successfully
+		    retrieved the start and finish times. See Bug#36819. */
+		    start_time != -1 && finish_time != -1) {
 			srv_n_lock_max_wait_time = diff_time;
 		}
 	}
@@ -1825,8 +1834,10 @@ srv_export_innodb_status(void)
 		= UT_LIST_GET_LEN(buf_pool->flush_list);
 	export_vars.innodb_buffer_pool_pages_free
 		= UT_LIST_GET_LEN(buf_pool->free);
+#ifdef UNIV_DEBUG
 	export_vars.innodb_buffer_pool_pages_latched
 		= buf_get_latched_pages_number();
+#endif /* UNIV_DEBUG */
 	export_vars.innodb_buffer_pool_pages_total = buf_pool->curr_size;
 
 	export_vars.innodb_buffer_pool_pages_misc = buf_pool->max_size
@@ -1904,12 +1915,6 @@ loop:
 
 	os_thread_sleep(1000000);
 
-	/* In case mutex_exit is not a memory barrier, it is
-	theoretically possible some threads are left waiting though
-	the semaphore is already released. Wake up those threads: */
-
-	sync_arr_wake_threads_if_sema_free();
-
 	current_time = time(NULL);
 
 	time_elapsed = difftime(current_time, last_monitor_time);
@@ -2106,9 +2111,15 @@ loop:
 		srv_refresh_innodb_monitor_stats();
 	}
 
+	/* In case mutex_exit is not a memory barrier, it is
+	theoretically possible some threads are left waiting though
+	the semaphore is already released. Wake up those threads: */
+	
+	sync_arr_wake_threads_if_sema_free();
+
 	if (sync_array_print_long_waits()) {
 		fatal_cnt++;
-		if (fatal_cnt > 5) {
+		if (fatal_cnt > 10) {
 
 			fprintf(stderr,
 				"InnoDB: Error: semaphore wait has lasted"
@@ -2128,7 +2139,7 @@ loop:
 
 	fflush(stderr);
 
-	os_thread_sleep(2000000);
+	os_thread_sleep(1000000);
 
 	if (srv_shutdown_state < SRV_SHUTDOWN_CLEANUP) {
 

=== modified file 'storage/innobase/srv/srv0start.c'
--- a/storage/innobase/srv/srv0start.c	2008-03-31 09:37:03 +0000
+++ b/storage/innobase/srv/srv0start.c	2008-06-12 00:08:07 +0000
@@ -202,13 +202,13 @@ srv_parse_data_file_paths_and_sizes(
 
 		str = srv_parse_megabytes(str, &size);
 
-		if (0 == memcmp(str, ":autoextend",
-				(sizeof ":autoextend") - 1)) {
+		if (0 == strncmp(str, ":autoextend",
+				 (sizeof ":autoextend") - 1)) {
 
 			str += (sizeof ":autoextend") - 1;
 
-			if (0 == memcmp(str, ":max:",
-					(sizeof ":max:") - 1)) {
+			if (0 == strncmp(str, ":max:",
+					 (sizeof ":max:") - 1)) {
 
 				str += (sizeof ":max:") - 1;
 
@@ -290,14 +290,15 @@ srv_parse_data_file_paths_and_sizes(
 		(*data_file_names)[i] = path;
 		(*data_file_sizes)[i] = size;
 
-		if (0 == memcmp(str, ":autoextend",
-				(sizeof ":autoextend") - 1)) {
+		if (0 == strncmp(str, ":autoextend",
+				 (sizeof ":autoextend") - 1)) {
 
 			*is_auto_extending = TRUE;
 
 			str += (sizeof ":autoextend") - 1;
 
-			if (0 == memcmp(str, ":max:", (sizeof ":max:") - 1)) {
+			if (0 == strncmp(str, ":max:",
+					 (sizeof ":max:") - 1)) {
 
 				str += (sizeof ":max:") - 1;
 
@@ -1122,12 +1123,12 @@ innobase_start_or_create_for_mysql(void)
 	if (srv_file_flush_method_str == NULL) {
 		/* These are the default options */
 
-		srv_unix_file_flush_method = SRV_UNIX_FDATASYNC;
+		srv_unix_file_flush_method = SRV_UNIX_FSYNC;
 
 		srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
 #ifndef __WIN__
-	} else if (0 == ut_strcmp(srv_file_flush_method_str, "fdatasync")) {
-		srv_unix_file_flush_method = SRV_UNIX_FDATASYNC;
+	} else if (0 == ut_strcmp(srv_file_flush_method_str, "fsync")) {
+		srv_unix_file_flush_method = SRV_UNIX_FSYNC;
 
 	} else if (0 == ut_strcmp(srv_file_flush_method_str, "O_DSYNC")) {
 		srv_unix_file_flush_method = SRV_UNIX_O_DSYNC;

=== modified file 'storage/innobase/sync/sync0arr.c'
--- a/storage/innobase/sync/sync0arr.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/sync/sync0arr.c	2008-06-12 00:08:07 +0000
@@ -40,24 +40,23 @@ because we can do with a very small numb
 say 200. In NT 3.51, allocating events seems to be a quadratic
 algorithm, because 10 000 events are created fast, but
 100 000 events takes a couple of minutes to create.
-*/
+
+As of 5.0.30 the above mentioned design is changed. Since now
+OS can handle millions of wait events efficiently, we no longer
+have this concept of each cell of wait array having one event.
+Instead, now the event that a thread wants to wait on is embedded
+in the wait object (mutex or rw_lock). We still keep the global
+wait array for the sake of diagnostics and also to avoid infinite
+wait The error_monitor thread scans the global wait array to signal
+any waiting threads who have missed the signal. */
 
 /* A cell where an individual thread may wait suspended
 until a resource is released. The suspending is implemented
 using an operating system event semaphore. */
 struct sync_cell_struct {
-	/* State of the cell. SC_WAKING_UP means
-	sync_array_struct->n_reserved has been decremented, but the thread
-	in this cell has not waken up yet. When it does, it will set the
-	state to SC_FREE. Note that this is done without the protection of
-	any mutex. */
-	enum { SC_FREE, SC_RESERVED, SC_WAKING_UP } state;
-
 	void*		wait_object;	/* pointer to the object the
-					thread is waiting for; this is not
-					reseted to NULL when a cell is
-					freed. */
-
+					thread is waiting for; if NULL
+					the cell is free for use */
 	mutex_t*	old_wait_mutex;	/* the latest wait mutex in cell */
 	rw_lock_t*	old_wait_rw_lock;/* the latest wait rw-lock in cell */
 	ulint		request_type;	/* lock type requested on the
@@ -71,13 +70,23 @@ struct sync_cell_struct {
 	ibool		waiting;	/* TRUE if the thread has already
 					called sync_array_event_wait
 					on this cell */
-	ibool		event_set;	/* TRUE if the event is set */
-	os_event_t	event;		/* operating system event
-					semaphore handle */
+	ib_longlong	signal_count;	/* We capture the signal_count
+					of the wait_object when we
+					reset the event. This value is
+					then passed on to os_event_wait
+					and we wait only if the event
+					has not been signalled in the
+					period between the reset and
+					wait call. */
 	time_t		reservation_time;/* time when the thread reserved
 					the wait cell */
 };
 
+/* NOTE: It is allowed for a thread to wait
+for an event allocated for the array without owning the
+protecting mutex (depending on the case: OS or database mutex), but
+all changes (set or reset) to the state of the event must be made
+while owning the mutex. */
 struct sync_array_struct {
 	ulint		n_reserved;	/* number of currently reserved
 					cells in the wait array */
@@ -220,12 +229,9 @@ sync_array_create(
 
 	for (i = 0; i < n_cells; i++) {
 		cell = sync_array_get_nth_cell(arr, i);
-		cell->state = SC_FREE;
-		cell->wait_object = NULL;
-
-		/* Create an operating system event semaphore with no name */
-		cell->event = os_event_create(NULL);
-		cell->event_set = FALSE; /* it is created in reset state */
+	cell->wait_object = NULL;
+		cell->waiting = FALSE;
+		cell->signal_count = 0;
 	}
 
 	return(arr);
@@ -239,19 +245,12 @@ sync_array_free(
 /*============*/
 	sync_array_t*	arr)	/* in, own: sync wait array */
 {
-	ulint		i;
-	sync_cell_t*	cell;
 	ulint		protection;
 
 	ut_a(arr->n_reserved == 0);
 
 	sync_array_validate(arr);
 
-	for (i = 0; i < arr->n_cells; i++) {
-		cell = sync_array_get_nth_cell(arr, i);
-		os_event_free(cell->event);
-	}
-
 	protection = arr->protection;
 
 	/* Release the mutex protecting the wait array complex */
@@ -285,8 +284,7 @@ sync_array_validate(
 
 	for (i = 0; i < arr->n_cells; i++) {
 		cell = sync_array_get_nth_cell(arr, i);
-
-		if (cell->state == SC_RESERVED) {
+		if (cell->wait_object != NULL) {
 			count++;
 		}
 	}
@@ -296,6 +294,29 @@ sync_array_validate(
 	sync_array_exit(arr);
 }
 
+/***********************************************************************
+Puts the cell event in reset state. */
+static
+ib_longlong
+sync_cell_event_reset(
+/*==================*/
+				/* out: value of signal_count
+				at the time of reset. */
+	ulint		type,	/* in: lock type mutex/rw_lock */
+	void*		object) /* in: the rw_lock/mutex object */
+{
+	if (type == SYNC_MUTEX) {
+		return(os_event_reset(((mutex_t *) object)->event));
+#ifdef __WIN__
+	} else if (type == RW_LOCK_WAIT_EX) {
+		return(os_event_reset(
+		       ((rw_lock_t *) object)->wait_ex_event));
+#endif
+	} else {
+		return(os_event_reset(((rw_lock_t *) object)->event));
+	}
+}
+
 /**********************************************************************
 Reserves a wait array cell for waiting for an object.
 The event of the cell is reset to nonsignalled state. */
@@ -324,21 +345,9 @@ sync_array_reserve_cell(
 	for (i = 0; i < arr->n_cells; i++) {
 		cell = sync_array_get_nth_cell(arr, i);
 
-		if (cell->state == SC_FREE) {
-
-			/* We do not check cell->event_set because it is
-			set outside the protection of the sync array mutex
-			and we had a bug regarding it, and since resetting
-			an event when it is not needed does no harm it is
-			safer always to do it. */
-
-			cell->event_set = FALSE;
-			os_event_reset(cell->event);
-
-			cell->state = SC_RESERVED;
-			cell->reservation_time = time(NULL);
-			cell->thread = os_thread_get_curr_id();
+		if (cell->wait_object == NULL) {
 
+			cell->waiting = FALSE;
 			cell->wait_object = object;
 
 			if (type == SYNC_MUTEX) {
@@ -348,7 +357,6 @@ sync_array_reserve_cell(
 			}
 
 			cell->request_type = type;
-			cell->waiting = FALSE;
 
 			cell->file = file;
 			cell->line = line;
@@ -359,6 +367,16 @@ sync_array_reserve_cell(
 
 			sync_array_exit(arr);
 
+			/* Make sure the event is reset and also store
+			the value of signal_count at which the event
+			was reset. */
+			cell->signal_count = sync_cell_event_reset(type,
+								object);
+
+			cell->reservation_time = time(NULL);
+
+			cell->thread = os_thread_get_curr_id();
+
 			return;
 		}
 	}
@@ -369,68 +387,6 @@ sync_array_reserve_cell(
 }
 
 /**********************************************************************
-Frees the cell. Note that we don't have any mutex reserved when calling
-this. */
-static
-void
-sync_array_free_cell(
-/*=================*/
-	sync_array_t*	arr,	/* in: wait array */
-	ulint		index)	/* in: index of the cell in array */
-{
-	sync_cell_t*	cell;
-
-	cell = sync_array_get_nth_cell(arr, index);
-
-	ut_a(cell->state == SC_WAKING_UP);
-	ut_a(cell->wait_object != NULL);
-
-	cell->state = SC_FREE;
-}
-
-/**********************************************************************
-Frees the cell safely by reserving the sync array mutex and decrementing
-n_reserved if necessary. Should only be called from mutex_spin_wait. */
-
-void
-sync_array_free_cell_protected(
-/*===========================*/
-	sync_array_t*	arr,	/* in: wait array */
-	ulint		index)	/* in: index of the cell in array */
-{
-	sync_cell_t*	cell;
-
-	sync_array_enter(arr);
-
-	cell = sync_array_get_nth_cell(arr, index);
-
-	ut_a(cell->state != SC_FREE);
-	ut_a(cell->wait_object != NULL);
-
-	/* We only need to decrement n_reserved if it has not already been
-	done by sync_array_signal_object. */
-	if (cell->state == SC_RESERVED) {
-		ut_a(arr->n_reserved > 0);
-		arr->n_reserved--;
-	} else if (cell->state == SC_WAKING_UP) {
-		/* This is tricky; if we don't wait for the event to be
-		signaled, signal_object can set the state of a cell to
-		SC_WAKING_UP, mutex_spin_wait can call this and set the
-		state to SC_FREE, and then signal_object gets around to
-		calling os_set_event for the cell but since it's already
-		been freed things break horribly. */
-
-		sync_array_exit(arr);
-		os_event_wait(cell->event);
-		sync_array_enter(arr);
-	}
-
-	cell->state = SC_FREE;
-
-	sync_array_exit(arr);
-}
-
-/**********************************************************************
 This function should be called when a thread starts to wait on
 a wait array cell. In the debug version this function checks
 if the wait for a semaphore will result in a deadlock, in which
@@ -447,15 +403,28 @@ sync_array_wait_event(
 
 	ut_a(arr);
 
+	sync_array_enter(arr);
+
 	cell = sync_array_get_nth_cell(arr, index);
 
-	ut_a((cell->state == SC_RESERVED) || (cell->state == SC_WAKING_UP));
 	ut_a(cell->wait_object);
 	ut_a(!cell->waiting);
 	ut_ad(os_thread_get_curr_id() == cell->thread);
 
-	event = cell->event;
-	cell->waiting = TRUE;
+	if (cell->request_type == SYNC_MUTEX) {
+		event = ((mutex_t*) cell->wait_object)->event;
+#ifdef __WIN__
+	/* On windows if the thread about to wait is the one which
+	has set the state of the rw_lock to RW_LOCK_WAIT_EX, then
+	it waits on a special event i.e.: wait_ex_event. */
+	} else if (cell->request_type == RW_LOCK_WAIT_EX) {
+		event = ((rw_lock_t*) cell->wait_object)->wait_ex_event;
+#endif
+	} else {
+		event = ((rw_lock_t*) cell->wait_object)->event;
+	}
+
+		cell->waiting = TRUE;
 
 #ifdef UNIV_SYNC_DEBUG
 
@@ -464,7 +433,6 @@ sync_array_wait_event(
 	recursively sync_array routines, leading to trouble.
 	rw_lock_debug_mutex freezes the debug lists. */
 
-	sync_array_enter(arr);
 	rw_lock_debug_mutex_enter();
 
 	if (TRUE == sync_array_detect_deadlock(arr, cell, cell, 0)) {
@@ -474,16 +442,16 @@ sync_array_wait_event(
 	}
 
 	rw_lock_debug_mutex_exit();
-	sync_array_exit(arr);
 #endif
-	os_event_wait(event);
+	sync_array_exit(arr);
+
+	os_event_wait_low(event, cell->signal_count);
 
 	sync_array_free_cell(arr, index);
 }
 
 /**********************************************************************
-Reports info of a wait array cell. Note: sync_array_print_long_waits()
-calls this without mutex protection. */
+Reports info of a wait array cell. */
 static
 void
 sync_array_cell_print(
@@ -503,17 +471,8 @@ sync_array_cell_print(
 		(ulong) os_thread_pf(cell->thread), cell->file,
 		(ulong) cell->line,
 		difftime(time(NULL), cell->reservation_time));
-	fprintf(file, "Wait array cell state %lu\n", (ulong)cell->state);
-
-	/* If the memory area pointed to by old_wait_mutex /
-	old_wait_rw_lock has been freed, this can crash. */
-
-	if (cell->state != SC_RESERVED) {
-		/* If cell has this state, then even if we are holding the sync
-		array mutex, the wait object may get freed meanwhile. Do not
-		print the wait object then. */
 
-	} else if (type == SYNC_MUTEX) {
+	if (type == SYNC_MUTEX) {
 		/* We use old_wait_mutex in case the cell has already
 		been freed meanwhile */
 		mutex = cell->old_wait_mutex;
@@ -531,7 +490,11 @@ sync_array_cell_print(
 #endif /* UNIV_SYNC_DEBUG */
 			(ulong) mutex->waiters);
 
-	} else if (type == RW_LOCK_EX || type == RW_LOCK_SHARED) {
+	} else if (type == RW_LOCK_EX
+#ifdef __WIN__
+		   || type == RW_LOCK_WAIT_EX
+#endif
+		   || type == RW_LOCK_SHARED) {
 
 		fputs(type == RW_LOCK_EX ? "X-lock on" : "S-lock on", file);
 
@@ -565,8 +528,8 @@ sync_array_cell_print(
 		ut_error;
 	}
 
-	if (cell->event_set) {
-		fputs("wait is ending\n", file);
+	if (!cell->waiting) {
+		fputs("wait has ended\n", file);
 	}
 }
 
@@ -589,7 +552,7 @@ sync_array_find_thread(
 
 		cell = sync_array_get_nth_cell(arr, i);
 
-		if ((cell->state == SC_RESERVED)
+		if (cell->wait_object != NULL
 		    && os_thread_eq(cell->thread, thread)) {
 
 			return(cell);	/* Found */
@@ -679,7 +642,7 @@ sync_array_detect_deadlock(
 
 	depth++;
 
-	if (cell->event_set || !cell->waiting) {
+	if (!cell->waiting) {
 
 		return(FALSE); /* No deadlock here */
 	}
@@ -704,10 +667,8 @@ sync_array_detect_deadlock(
 						       depth);
 			if (ret) {
 				fprintf(stderr,
-					"Mutex %p owned by thread %lu"
-					" file %s line %lu\n",
-					(void*) mutex,
-					(ulong) os_thread_pf(mutex->thread_id),
+			"Mutex %p owned by thread %lu file %s line %lu\n",
+					mutex, (ulong) os_thread_pf(mutex->thread_id),
 					mutex->file_name, (ulong) mutex->line);
 				sync_array_cell_print(stderr, cell);
 
@@ -717,7 +678,8 @@ sync_array_detect_deadlock(
 
 		return(FALSE); /* No deadlock */
 
-	} else if (cell->request_type == RW_LOCK_EX) {
+	} else if (cell->request_type == RW_LOCK_EX
+		   || cell->request_type == RW_LOCK_WAIT_EX) {
 
 		lock = cell->wait_object;
 
@@ -816,7 +778,8 @@ sync_arr_cell_can_wake_up(
 			return(TRUE);
 		}
 
-	} else if (cell->request_type == RW_LOCK_EX) {
+	} else if (cell->request_type == RW_LOCK_EX
+		   || cell->request_type == RW_LOCK_WAIT_EX) {
 
 		lock = cell->wait_object;
 
@@ -845,101 +808,47 @@ sync_arr_cell_can_wake_up(
 	return(FALSE);
 }
 
-/**************************************************************************
-Looks for the cells in the wait array which refer to the wait object
-specified, and sets their corresponding events to the signaled state. In this
-way releases the threads waiting for the object to contend for the object.
-It is possible that no such cell is found, in which case does nothing. */
+/**********************************************************************
+Frees the cell. NOTE! sync_array_wait_event frees the cell
+automatically! */
 
 void
-sync_array_signal_object(
-/*=====================*/
+sync_array_free_cell(
+/*=================*/
 	sync_array_t*	arr,	/* in: wait array */
-	void*		object)	/* in: wait object */
+	ulint		index)  /* in: index of the cell in array */
 {
 	sync_cell_t*	cell;
-	ulint		count;
-	ulint		i;
-	ulint		res_count;
-
-	/* We store the addresses of cells we need to signal and signal
-	them only after we have released the sync array's mutex (for
-	performance reasons). cell_count is the number of such cells, and
-	cell_ptr points to the first one. If there are less than
-	UT_ARR_SIZE(cells) of them, cell_ptr == &cells[0], otherwise
-	cell_ptr points to malloc'd memory that we must free. */
-
-	sync_cell_t*	cells[100];
-	sync_cell_t**	cell_ptr = &cells[0];
-	ulint		cell_count = 0;
-	ulint		cell_max_count = UT_ARR_SIZE(cells);
-
-	ut_a(100 == cell_max_count);
 
 	sync_array_enter(arr);
 
-	arr->sg_count++;
-
-	i = 0;
-	count = 0;
-
-	/* We need to store this to a local variable because it is modified
-	inside the loop */
-	res_count = arr->n_reserved;
-
-	while (count < res_count) {
+	cell = sync_array_get_nth_cell(arr, index);
 
-		cell = sync_array_get_nth_cell(arr, i);
+	ut_a(cell->wait_object != NULL);
 
-		if (cell->state == SC_RESERVED) {
+	cell->waiting = FALSE;
+	cell->wait_object =  NULL;
+	cell->signal_count = 0;
 
-			count++;
-			if (cell->wait_object == object) {
-				cell->state = SC_WAKING_UP;
+	ut_a(arr->n_reserved > 0);
+	arr->n_reserved--;
 
-				ut_a(arr->n_reserved > 0);
-				arr->n_reserved--;
+	sync_array_exit(arr);
+}
 
-				if (cell_count == cell_max_count) {
-					sync_cell_t** old_cell_ptr = cell_ptr;
-					size_t old_size, new_size;
-
-					old_size = cell_max_count
-						* sizeof(sync_cell_t*);
-					cell_max_count *= 2;
-					new_size = cell_max_count
-						* sizeof(sync_cell_t*);
-
-					cell_ptr = malloc(new_size);
-					ut_a(cell_ptr);
-					memcpy(cell_ptr, old_cell_ptr,
-					       old_size);
-
-					if (old_cell_ptr != &cells[0]) {
-						free(old_cell_ptr);
-					}
-				}
+/**************************************************************************
+Increments the signalled count. */
 
-				cell_ptr[cell_count] = cell;
-				cell_count++;
-			}
-		}
+void
+sync_array_object_signalled(
+/*========================*/
+	sync_array_t*	arr)	/* in: wait array */
+{
+	sync_array_enter(arr);
 
-		i++;
-	}
+	arr->sg_count++;
 
 	sync_array_exit(arr);
-
-	for (i = 0; i < cell_count; i++) {
-		cell = cell_ptr[i];
-
-		cell->event_set = TRUE;
-		os_event_set(cell->event);
-	}
-
-	if (cell_ptr != &cells[0]) {
-		free(cell_ptr);
-	}
 }
 
 /**************************************************************************
@@ -959,33 +868,41 @@ sync_arr_wake_threads_if_sema_free(void)
 	sync_cell_t*	cell;
 	ulint		count;
 	ulint		i;
-	ulint		res_count;
 
 	sync_array_enter(arr);
 
 	i = 0;
 	count = 0;
 
-	/* We need to store this to a local variable because it is modified
-	inside the loop */
-
-	res_count = arr->n_reserved;
-
-	while (count < res_count) {
+	while (count < arr->n_reserved) {
 
 		cell = sync_array_get_nth_cell(arr, i);
 
-		if (cell->state == SC_RESERVED) {
+		if (cell->wait_object != NULL) {
 
 			count++;
 
 			if (sync_arr_cell_can_wake_up(cell)) {
-				cell->state = SC_WAKING_UP;
-				cell->event_set = TRUE;
-				os_event_set(cell->event);
 
-				ut_a(arr->n_reserved > 0);
-				arr->n_reserved--;
+				if (cell->request_type == SYNC_MUTEX) {
+					mutex_t*	mutex;
+
+					mutex = cell->wait_object;
+					os_event_set(mutex->event);
+#ifdef __WIN__
+				} else if (cell->request_type
+					   == RW_LOCK_WAIT_EX) {
+					rw_lock_t*	lock;
+
+					lock = cell->wait_object;
+					os_event_set(lock->wait_ex_event);
+#endif
+				} else {
+					rw_lock_t*	lock;
+
+					lock = cell->wait_object;
+					os_event_set(lock->event);
+				}
 			}
 		}
 
@@ -1015,7 +932,7 @@ sync_array_print_long_waits(void)
 
 		cell = sync_array_get_nth_cell(sync_primary_wait_array, i);
 
-		if ((cell->state != SC_FREE)
+		if (cell->wait_object != NULL && cell->waiting
 		    && difftime(time(NULL), cell->reservation_time) > 240) {
 			fputs("InnoDB: Warning: a long semaphore wait:\n",
 			      stderr);
@@ -1023,7 +940,7 @@ sync_array_print_long_waits(void)
 			noticed = TRUE;
 		}
 
-		if ((cell->state != SC_FREE)
+		if (cell->wait_object != NULL && cell->waiting
 		    && difftime(time(NULL), cell->reservation_time)
 		    > fatal_timeout) {
 			fatal = TRUE;
@@ -1072,20 +989,25 @@ sync_array_output_info(
 				mutex */
 {
 	sync_cell_t*	cell;
+	ulint		count;
 	ulint		i;
 
 	fprintf(file,
-		"OS WAIT ARRAY INFO: reservation count %ld,"
-		" signal count %ld\n",
-		(long) arr->res_count,
-		(long) arr->sg_count);
-	for (i = 0; i < arr->n_cells; i++) {
+		"OS WAIT ARRAY INFO: reservation count %ld, signal count %ld\n",
+						(long) arr->res_count, (long) arr->sg_count);
+	i = 0;
+	count = 0;
+
+	while (count < arr->n_reserved) {
 
 		cell = sync_array_get_nth_cell(arr, i);
 
-		if (cell->state != SC_FREE) {
+	if (cell->wait_object != NULL) {
+		count++;
 			sync_array_cell_print(file, cell);
 		}
+
+		i++;
 	}
 }
 

=== modified file 'storage/innobase/sync/sync0rw.c'
--- a/storage/innobase/sync/sync0rw.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/sync/sync0rw.c	2008-06-12 00:08:07 +0000
@@ -151,6 +151,11 @@ rw_lock_create_func(
 	lock->last_x_file_name = "not yet reserved";
 	lock->last_s_line = 0;
 	lock->last_x_line = 0;
+	lock->event = os_event_create(NULL);
+
+#ifdef __WIN__
+	lock->wait_ex_event = os_event_create(NULL);
+#endif
 
 	mutex_enter(&rw_lock_list_mutex);
 
@@ -184,6 +189,11 @@ rw_lock_free(
 	mutex_free(rw_lock_get_mutex(lock));
 
 	mutex_enter(&rw_lock_list_mutex);
+	os_event_free(lock->event);
+
+#ifdef __WIN__
+	os_event_free(lock->wait_ex_event);
+#endif
 
 	if (UT_LIST_GET_PREV(list, lock)) {
 		ut_a(UT_LIST_GET_PREV(list, lock)->magic_n == RW_LOCK_MAGIC_N);
@@ -544,7 +554,15 @@ lock_loop:
 	rw_x_system_call_count++;
 
 	sync_array_reserve_cell(sync_primary_wait_array,
-				lock, RW_LOCK_EX,
+				lock,
+#ifdef __WIN__
+				/* On windows RW_LOCK_WAIT_EX signifies
+				that this thread should wait on the
+				special wait_ex_event. */
+				(state == RW_LOCK_WAIT_EX)
+				 ? RW_LOCK_WAIT_EX :
+#endif
+				RW_LOCK_EX,
 				file_name, line,
 				&index);
 

=== modified file 'storage/innobase/sync/sync0sync.c'
--- a/storage/innobase/sync/sync0sync.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/sync/sync0sync.c	2008-06-12 00:08:07 +0000
@@ -95,17 +95,47 @@ have happened that the thread which was 
 it and did not see the waiters byte set to 1, a case which would lead the
 other thread to an infinite wait.
 
-LEMMA 1: After a thread resets the event of the cell it reserves for waiting
-========
-for a mutex, some thread will eventually call sync_array_signal_object with
-the mutex as an argument. Thus no infinite wait is possible.
+LEMMA 1: After a thread resets the event of a mutex (or rw_lock), some
+=======
+thread will eventually call os_event_set() on that particular event.
+Thus no infinite wait is possible in this case.
 
 Proof:	After making the reservation the thread sets the waiters field in the
 mutex to 1. Then it checks that the mutex is still reserved by some thread,
 or it reserves the mutex for itself. In any case, some thread (which may be
 also some earlier thread, not necessarily the one currently holding the mutex)
 will set the waiters field to 0 in mutex_exit, and then call
-sync_array_signal_object with the mutex as an argument.
+os_event_set() with the mutex as an argument.
+Q.E.D.
+
+LEMMA 2: If an os_event_set() call is made after some thread has called
+=======
+the os_event_reset() and before it starts wait on that event, the call
+will not be lost to the second thread. This is true even if there is an
+intervening call to os_event_reset() by another thread.
+Thus no infinite wait is possible in this case.
+
+Proof (non-windows platforms): os_event_reset() returns a monotonically
+increasing value of signal_count. This value is increased at every
+call of os_event_set() If thread A has called os_event_reset() followed
+by thread B calling os_event_set() and then some other thread C calling
+os_event_reset(), the is_set flag of the event will be set to FALSE;
+but now if thread A calls os_event_wait_low() with the signal_count
+value returned from the earlier call of os_event_reset(), it will
+return immediately without waiting.
+Q.E.D.
+
+Proof (windows): If there is a writer thread which is forced to wait for
+the lock, it may be able to set the state of rw_lock to RW_LOCK_WAIT_EX
+The design of rw_lock ensures that there is one and only one thread
+that is able to change the state to RW_LOCK_WAIT_EX and this thread is
+guaranteed to acquire the lock after it is released by the current
+holders and before any other waiter gets the lock.
+On windows this thread waits on a separate event i.e.: wait_ex_event.
+Since only one thread can wait on this event there is no chance
+of this event getting reset before the writer starts wait on it.
+Therefore, this thread is guaranteed to catch the os_set_event()
+signalled unconditionally at the release of the lock.
 Q.E.D. */
 
 /* The number of system calls made in this module. Intended for performance
@@ -217,6 +247,7 @@ mutex_create_func(
 	os_fast_mutex_init(&(mutex->os_fast_mutex));
 	mutex->lock_word = 0;
 #endif
+	mutex->event = os_event_create(NULL);
 	mutex_set_waiters(mutex, 0);
 #ifdef UNIV_DEBUG
 	mutex->magic_n = MUTEX_MAGIC_N;
@@ -300,6 +331,8 @@ mutex_free(
 		mutex_exit(&mutex_list_mutex);
 	}
 
+	os_event_free(mutex->event);
+
 #if !defined(_WIN32) || !defined(UNIV_CAN_USE_X86_ASSEMBLER)
 	os_fast_mutex_free(&(mutex->os_fast_mutex));
 #endif
@@ -509,8 +542,7 @@ spin_loop:
 		if (mutex_test_and_set(mutex) == 0) {
 			/* Succeeded! Free the reserved wait cell */
 
-			sync_array_free_cell_protected(sync_primary_wait_array,
-						       index);
+			sync_array_free_cell(sync_primary_wait_array, index);
 
 			ut_d(mutex->thread_id = os_thread_get_curr_id());
 #ifdef UNIV_SYNC_DEBUG
@@ -591,8 +623,8 @@ mutex_signal_object(
 
 	/* The memory order of resetting the waiters field and
 	signaling the object is important. See LEMMA 1 above. */
-
-	sync_array_signal_object(sync_primary_wait_array, mutex);
+	os_event_set(mutex->event);
+	sync_array_object_signalled(sync_primary_wait_array);
 }
 
 #ifdef UNIV_SYNC_DEBUG
@@ -1130,6 +1162,7 @@ sync_thread_add_level(
 		break;
 	case SYNC_TREE_NODE:
 		ut_a(sync_thread_levels_contain(array, SYNC_INDEX_TREE)
+		     || sync_thread_levels_contain(array, SYNC_DICT_OPERATION)
 		     || sync_thread_levels_g(array, SYNC_TREE_NODE - 1));
 		break;
 	case SYNC_TREE_NODE_NEW:

=== modified file 'storage/innobase/trx/trx0trx.c'
--- a/storage/innobase/trx/trx0trx.c	2008-05-15 20:56:38 +0000
+++ b/storage/innobase/trx/trx0trx.c	2008-06-12 00:08:07 +0000
@@ -757,8 +757,8 @@ trx_commit_off_kernel(
 		mutex_enter(&(rseg->mutex));
 
 		if (trx->insert_undo != NULL) {
-			trx_undo_set_state_at_finish(trx, trx->insert_undo,
-						     &mtr);
+			trx_undo_set_state_at_finish(
+				rseg, trx, trx->insert_undo, &mtr);
 		}
 
 		undo = trx->update_undo;
@@ -774,7 +774,7 @@ trx_commit_off_kernel(
 			transaction commit for this transaction. */
 
 			update_hdr_page = trx_undo_set_state_at_finish(
-				trx, undo, &mtr);
+				rseg, trx, undo, &mtr);
 
 			/* We have to do the cleanup for the update log while
 			holding the rseg mutex because update log headers
@@ -933,6 +933,7 @@ trx_commit_off_kernel(
 	trx->rseg = NULL;
 	trx->undo_no = ut_dulint_zero;
 	trx->last_sql_stat_start.least_undo_no = ut_dulint_zero;
+	trx->mysql_query_str = NULL;
 
 	ut_ad(UT_LIST_GET_LEN(trx->wait_thrs) == 0);
 	ut_ad(UT_LIST_GET_LEN(trx->trx_locks) == 0);

=== modified file 'storage/innobase/trx/trx0undo.c'
--- a/storage/innobase/trx/trx0undo.c	2008-03-31 09:37:03 +0000
+++ b/storage/innobase/trx/trx0undo.c	2008-06-12 00:08:07 +0000
@@ -1725,6 +1725,7 @@ trx_undo_set_state_at_finish(
 /*=========================*/
 				/* out: undo log segment header page,
 				x-latched */
+	trx_rseg_t*	rseg,	/* in: rollback segment memory object */
 	trx_t*		trx __attribute__((unused)), /* in: transaction */
 	trx_undo_t*	undo,	/* in: undo log memory copy */
 	mtr_t*		mtr)	/* in: mtr */
@@ -1734,7 +1735,10 @@ trx_undo_set_state_at_finish(
 	page_t*		undo_page;
 	ulint		state;
 
-	ut_ad(trx && undo && mtr);
+	ut_ad(trx);
+	ut_ad(undo);
+	ut_ad(mtr);
+	ut_ad(mutex_own(&rseg->mutex));
 
 	if (undo->id >= TRX_RSEG_N_SLOTS) {
 		fprintf(stderr, "InnoDB: Error: undo->id is %lu\n",
@@ -1748,9 +1752,23 @@ trx_undo_set_state_at_finish(
 	seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
 	page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
 
-	if (undo->size == 1 && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
-	    < TRX_UNDO_PAGE_REUSE_LIMIT) {
-		state = TRX_UNDO_CACHED;
+	if (undo->size == 1
+	    && mach_read_from_2(page_hdr + TRX_UNDO_PAGE_FREE)
+	       < TRX_UNDO_PAGE_REUSE_LIMIT) {
+
+		/* This is a heuristic to avoid the problem of all UNDO
+		slots ending up in one of the UNDO lists. Previously if
+		the server crashed with all the slots in one of the lists,
+		transactions that required the slots of a different type
+		would fail for lack of slots. */
+
+		if (UT_LIST_GET_LEN(rseg->update_undo_list) < 500
+		    && UT_LIST_GET_LEN(rseg->insert_undo_list) < 500) {
+
+			state = TRX_UNDO_CACHED;
+		} else {
+			state = TRX_UNDO_TO_FREE;
+		}
 
 	} else if (undo->type == TRX_UNDO_INSERT) {
 

=== modified file 'storage/innobase/ut/ut0ut.c'
--- a/storage/innobase/ut/ut0ut.c	2007-11-06 22:42:58 +0000
+++ b/storage/innobase/ut/ut0ut.c	2008-06-12 00:08:07 +0000
@@ -112,19 +112,45 @@ ut_time(void)
 }
 
 /**************************************************************
-Returns system time. */
+Returns system time.
+Upon successful completion, the value 0 is returned; otherwise the
+value -1 is returned and the global variable errno is set to indicate the
+error. */
 
-void
+int
 ut_usectime(
 /*========*/
+			/* out: 0 on success, -1 otherwise */
 	ulint*	sec,	/* out: seconds since the Epoch */
 	ulint*	ms)	/* out: microseconds since the Epoch+*sec */
 {
 	struct timeval	tv;
+	int		ret;
+	int		errno_gettimeofday;
+	int		i;
+
+	for (i = 0; i < 10; i++) {
+
+		ret = ut_gettimeofday(&tv, NULL);
+
+		if (ret == -1) {
+			errno_gettimeofday = errno;
+			ut_print_timestamp(stderr);
+			fprintf(stderr, "  InnoDB: gettimeofday(): %s\n",
+				strerror(errno_gettimeofday));
+			os_thread_sleep(100000);  /* 0.1 sec */
+			errno = errno_gettimeofday;
+		} else {
+			break;
+		}
+	}
+
+	if (ret != -1) {
+		*sec = (ulint) tv.tv_sec;
+		*ms  = (ulint) tv.tv_usec;
+	}
 
-	ut_gettimeofday(&tv, NULL);
-	*sec = (ulint) tv.tv_sec;
-	*ms  = (ulint) tv.tv_usec;
+	return(ret);
 }
 
 /**************************************************************

Thread
bzr commit into mysql-6.0-backup branch (jorgen.loland:2639) Bug#33120Jorgen Loland27 Jun