diff --git a/.bzr-mysql/default.conf b/.bzr-mysql/default.conf
index e6ad6e85da478bf22401107808ce52a7c283b389..55da30ab626d65886010172b5d4e4f44bdb64b5b 100644
--- a/.bzr-mysql/default.conf
+++ b/.bzr-mysql/default.conf
@@ -1,4 +1,4 @@
 [MYSQL]
 post_commit_to = "commits@lists.mysql.com"
 post_push_to = "commits@lists.mysql.com"
-tree_name = "mysql-5.5.0-next-mr"
+tree_name = "mysql-5.1-rpl-merge"
diff --git a/client/my_readline.h b/client/my_readline.h
index 62ad19bece93aa6e9683683837c21d3da943fd01..08cff5658190ed9f6a7a24f385758a5e18a81567 100644
--- a/client/my_readline.h
+++ b/client/my_readline.h
@@ -1,3 +1,6 @@
+#ifndef CLIENT_MY_READLINE_INCLUDED
+#define CLIENT_MY_READLINE_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -31,3 +34,5 @@ extern LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file);
 extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, char * str);
 extern char *batch_readline(LINE_BUFFER *buffer, bool *truncated);
 extern void batch_readline_end(LINE_BUFFER *buffer);
+
+#endif /* CLIENT_MY_READLINE_INCLUDED */
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 5bfde5b606c9d2b3eea536ed5ddec7dce3b836d8..e82271fceec8e73237f49038cdf370657328b802 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -1349,7 +1349,6 @@ static int parse_args(int *argc, char*** argv)
   int ho_error;
 
   result_file = stdout;
-  load_defaults("my",load_default_groups,argc,argv);
   if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
     exit(ho_error);
   if (debug_info_flag)
@@ -2001,8 +2000,9 @@ int main(int argc, char** argv)
 
   my_init_time(); // for time functions
 
+  load_defaults("my", load_default_groups, &argc, &argv);
+  defaults_argv= argv;
   parse_args(&argc, (char***)&argv);
-  defaults_argv=argv;
 
   if (!argc)
   {
diff --git a/client/sql_string.h b/client/sql_string.h
index da19c1ccfe563496d0600dc509df94b0aba474e4..0e6d6da4476de3b55ab50b33ef2f47661981388b 100644
--- a/client/sql_string.h
+++ b/client/sql_string.h
@@ -1,3 +1,6 @@
+#ifndef CLIENT_SQL_STRING_INCLUDED
+#define CLIENT_SQL_STRING_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -353,3 +356,5 @@ class String
     return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
   }
 };
+
+#endif /* CLIENT_SQL_STRING_INCLUDED */
diff --git a/dbug/dbug.c b/dbug/dbug.c
index baf080f5e273ed50b4bae8030ff08b9a8f31d570..1ea160852eb3c2d891617d15ff026134048d2e7b 100644
--- a/dbug/dbug.c
+++ b/dbug/dbug.c
@@ -1662,6 +1662,27 @@ BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword)
           InList(cs->stack->processes, cs->process));
 }
 
+/*
+ *  FUNCTION
+ *
+ *      _db_keywords_    test keyword formed by a set of strings for member
+ *                       of keyword list
+ *
+ *  DESCRIPTION
+ *
+ *      This function is similar to _db_keyword but receives a set of strings to
+ *      be concatenated in order to make the keyword to be compared.
+ */
+
+BOOLEAN _db_keywords_(const char *function, const char *type)
+{
+  char dest[_DBUG_MAX_FUNC_NAME_ + 1];
+
+  strxnmov(dest, _DBUG_MAX_FUNC_NAME_, function, type, NULL);
+
+  return _db_strict_keyword_(dest);
+}
+
 /*
  *  FUNCTION
  *
@@ -2281,6 +2302,13 @@ void _db_unlock_file_()
   pthread_mutex_unlock(&THR_LOCK_dbug);
 }
 
+const char* _db_get_func_(void)
+{
+  CODE_STATE *cs= 0;
+  get_code_state_or_return NULL;
+  return cs->func;
+}
+
 /*
  * Here we need the definitions of the clock routine.  Add your
  * own for whatever system that you have.
diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c
index 06f7e51c3804be8ec91c969ae35d5d0af20d39b1..42a5cbd687777eebf1a9ffbcf4ee03373aa6c9f8 100644
--- a/extra/my_print_defaults.c
+++ b/extra/my_print_defaults.c
@@ -192,7 +192,8 @@ int main(int argc, char **argv)
   }
 
   for (argument= arguments+1 ; *argument ; argument++)
-    puts(*argument);
+    if (*argument != args_separator)           /* skip arguments separator */
+      puts(*argument);
   my_free((char*) load_default_groups,MYF(0));
   free_defaults(arguments);
 
diff --git a/include/atomic/gcc_builtins.h b/include/atomic/gcc_builtins.h
index 509701b30a59344b9306409360abd141cbdd8875..01ebc38707ed47f78f2d2c4e0cb41645ee3678a2 100644
--- a/include/atomic/gcc_builtins.h
+++ b/include/atomic/gcc_builtins.h
@@ -1,3 +1,6 @@
+#ifndef ATOMIC_GCC_BUILTINS_INCLUDED
+#define ATOMIC_GCC_BUILTINS_INCLUDED
+
 /* Copyright (C) 2008 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -31,3 +34,5 @@
 #define make_atomic_store_body(S)                   \
   (void) __sync_lock_test_and_set(a, v);
 #endif
+
+#endif /* ATOMIC_GCC_BUILTINS_INCLUDED */
diff --git a/include/atomic/nolock.h b/include/atomic/nolock.h
index 0e6c8089b84fbfacc67799764f14823ab3e2e6f9..d7d87167ade6a6f6d44861b60f491b0aa60823d3 100644
--- a/include/atomic/nolock.h
+++ b/include/atomic/nolock.h
@@ -1,3 +1,6 @@
+#ifndef ATOMIC_NOLOCK_INCLUDED
+#define ATOMIC_NOLOCK_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -59,3 +62,4 @@ typedef struct { } my_atomic_rwlock_t;
 
 #endif
 
+#endif /* ATOMIC_NOLOCK_INCLUDED */
diff --git a/include/atomic/rwlock.h b/include/atomic/rwlock.h
index 18b77e93d80cb61b6ebd1abb0b4dd541dde394ff..0ff4d16c545009ecf3275cfd54107316de157125 100644
--- a/include/atomic/rwlock.h
+++ b/include/atomic/rwlock.h
@@ -1,3 +1,6 @@
+#ifndef ATOMIC_RWLOCK_INCLUDED
+#define ATOMIC_RWLOCK_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -46,3 +49,4 @@ typedef struct {pthread_rwlock_t rw;} my_atomic_rwlock_t;
 #define make_atomic_load_body(S)    ret= *a;
 #define make_atomic_store_body(S)   *a= v;
 
+#endif /* ATOMIC_RWLOCK_INCLUDED */
diff --git a/include/atomic/x86-gcc.h b/include/atomic/x86-gcc.h
index 726c98213fb1541957cde48845247127f3c12a66..c3029f9c1b46de27a795908cce4f7fb13f7d45ce 100644
--- a/include/atomic/x86-gcc.h
+++ b/include/atomic/x86-gcc.h
@@ -1,3 +1,6 @@
+#ifndef ATOMIC_X86_GCC_INCLUDED
+#define ATOMIC_X86_GCC_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -56,3 +59,4 @@
   asm volatile ("; xchg %0, %1;" : "+m" (*a) : "r" (v))
 #endif
 
+#endif /* ATOMIC_X86_GCC_INCLUDED */
diff --git a/include/config-win.h b/include/config-win.h
index 725b4fdf07b72494f4984bb1c7fd4bcaeda12f35..702c6bcdeaee90b18408308e807da370d0fe164f 100644
--- a/include/config-win.h
+++ b/include/config-win.h
@@ -1,3 +1,6 @@
+#ifndef CONFIG_WIN_INCLUDED
+#define CONFIG_WIN_INCLUDED
+
 /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -407,3 +410,5 @@ inline ulonglong double2ulonglong(double d)
 
 #define HAVE_UCA_COLLATIONS 1
 #define HAVE_BOOL 1
+
+#endif /* CONFIG_WIN_INCLUDED */
diff --git a/include/errmsg.h b/include/errmsg.h
index a6d8c770de889bdb629043fbeb548722f45930f4..5754e99ba5e6f52d6448cef912c235df2ffc9895 100644
--- a/include/errmsg.h
+++ b/include/errmsg.h
@@ -1,3 +1,6 @@
+#ifndef ERRMSG_INCLUDED
+#define ERRMSG_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -100,3 +103,4 @@ extern const char *client_errors[];	/* Error messages */
 #define CR_ERROR_LAST  /*Copy last error nr:*/  2057
 /* Add error numbers before CR_ERROR_LAST and change it accordingly. */
 
+#endif /* ERRMSG_INCLUDED */
diff --git a/include/help_end.h b/include/help_end.h
index 4426cb80bce3ae6b4dcba5735aef6e6dbe9f7542..92953efe35a25bf3d320c8a38bfe30b529624635 100644
--- a/include/help_end.h
+++ b/include/help_end.h
@@ -1,3 +1,6 @@
+#ifndef HELP_END_INCLUDED
+#define HELP_END_INCLUDED
+
 /* Copyright (C) 2004-2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -20,3 +23,4 @@
 #undef fputc
 #undef putchar
 #endif
+#endif /* HELP_END_INCLUDED */
diff --git a/include/help_start.h b/include/help_start.h
index 3ae20eea7d724eced06761b3f29b0e58566ea54f..414f7ec93a048047697cbff28415b62cd4ef2f9c 100644
--- a/include/help_start.h
+++ b/include/help_start.h
@@ -1,3 +1,6 @@
+#ifndef HELP_START_INCLUDED
+#define HELP_START_INCLUDED
+
 /* Copyright (C) 2004-2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -22,3 +25,4 @@
 #define fputc(s,f)   consoleprintf("%c", s)
 #define putchar(s)   consoleprintf("%c", s)
 #endif
+#endif /* HELP_START_INCLUDED */
diff --git a/include/my_aes.h b/include/my_aes.h
index 1bbdf5663eae9aa44b2d5b3aec05940fe4c92233..2e2a66b496825344969eb5cd2bdbe000cc9a5643 100644
--- a/include/my_aes.h
+++ b/include/my_aes.h
@@ -1,3 +1,6 @@
+#ifndef MY_AES_INCLUDED
+#define MY_AES_INCLUDED
+
 /* Copyright (C) 2002 MySQL AB
 
  This program is free software; you can redistribute it and/or modify
@@ -63,3 +66,5 @@ int my_aes_decrypt(const char *source, int source_length, char *dest,
 int my_aes_get_size(int source_length);
 
 C_MODE_END
+
+#endif /* MY_AES_INCLUDED */
diff --git a/include/my_atomic.h b/include/my_atomic.h
index 03f7d08198165e8481f4ba7165e3da2807215a69..f5da6e6a0d976d2bd1de7375a0e0d34ee600f28c 100644
--- a/include/my_atomic.h
+++ b/include/my_atomic.h
@@ -1,3 +1,6 @@
+#ifndef MY_ATOMIC_INCLUDED
+#define MY_ATOMIC_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -150,3 +153,4 @@ extern int my_atomic_initialize();
 
 #endif
 
+#endif /* MY_ATOMIC_INCLUDED */
diff --git a/include/my_bit.h b/include/my_bit.h
index 2e464e89049bfa68e28199deb87d4555c3a4ac21..5cbf4f8b83eabf4b155182ed2b63fbce68858871 100644
--- a/include/my_bit.h
+++ b/include/my_bit.h
@@ -1,3 +1,6 @@
+#ifndef MY_BIT_INCLUDED
+#define MY_BIT_INCLUDED
+
 /*
   Some useful bit functions
 */
@@ -107,3 +110,5 @@ extern uint my_count_bits(ulonglong v);
 extern uint my_count_bits_ushort(ushort v);
 #endif /* HAVE_INLINE */
 C_MODE_END
+
+#endif /* MY_BIT_INCLUDED */
diff --git a/include/my_dbug.h b/include/my_dbug.h
index 0ba72b2210d8f91c529daf9791b17e92ffcdb219..0451a868aa4f6ae966c5f090b871fb03fa0957f8 100644
--- a/include/my_dbug.h
+++ b/include/my_dbug.h
@@ -45,6 +45,7 @@ extern "C" {
 #if !defined(DBUG_OFF) && !defined(_lint)
 struct _db_code_state_;
 extern	int _db_keyword_(struct _db_code_state_ *cs, const char *keyword);
+extern  int _db_keywords_(const char *, const char *);
 extern  int _db_strict_keyword_(const char *keyword);
 extern  int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len);
 extern  int _db_explain_init_(char *buf, size_t len);
@@ -69,6 +70,7 @@ extern	void _db_end_(void);
 extern	void _db_lock_file_(void);
 extern	void _db_unlock_file_(void);
 extern FILE *_db_fp_(void);
+extern  const char* _db_get_func_(void);
 
 #ifdef __cplusplus
 
@@ -124,6 +126,20 @@ extern FILE *_db_fp_(void);
 #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len))
 #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len))
 #define IF_DBUG(A) A
+#define _DBUG_MAX_FUNC_NAME_ 255
+#define DBUG_CHECK_CRASH(func, op) \
+        do { \
+          if (_db_keywords_((func), (op))) \
+            { abort(); } \
+        } while (0)
+#define DBUG_CRASH_ENTER(func) \
+  DBUG_ENTER(func); DBUG_CHECK_CRASH(func, "_crash_enter")
+#define DBUG_CRASH_RETURN(val) \
+  do {DBUG_CHECK_CRASH(_db_get_func_(), "_crash_return"); \
+    DBUG_RETURN(val);} while(0)
+#define DBUG_CRASH_VOID_RETURN \
+  do {DBUG_CHECK_CRASH (_db_get_func_(), "_crash_return"); \
+    DBUG_VOID_RETURN;} while(0)
 #else						/* No debugger */
 
 #define DBUG_ENTER(a1)
@@ -152,6 +168,9 @@ extern FILE *_db_fp_(void);
 #define DBUG_EXPLAIN(buf,len)
 #define DBUG_EXPLAIN_INITIAL(buf,len)
 #define IF_DBUG(A)
+#define DBUG_CRASH_ENTER(func)
+#define DBUG_CRASH_RETURN(val)      do { return(val); } while(0)
+#define DBUG_CRASH_VOID_RETURN      do { return; } while(0)
 #endif
 #ifdef	__cplusplus
 }
diff --git a/include/my_libwrap.h b/include/my_libwrap.h
index 9a8579475fbe5e51cb5da8f9097ec32b23cb31ab..8235c00d8f37a82c317f2acd96f3cc42bbb63233 100644
--- a/include/my_libwrap.h
+++ b/include/my_libwrap.h
@@ -1,3 +1,6 @@
+#ifndef MY_LIBWRAP_INCLUDED
+#define MY_LIBWRAP_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -25,3 +28,4 @@ extern int my_hosts_access(struct request_info *req);
 extern char *my_eval_client(struct request_info *req);
 
 #endif /* HAVE_LIBWRAP */
+#endif /* MY_LIBWRAP_INCLUDED */
diff --git a/include/my_md5.h b/include/my_md5.h
index 6458f27c5cccd7bc029702701bd31d9809da5c7f..782bef8a27aa502aff8356f38ebb9fe392bef282 100644
--- a/include/my_md5.h
+++ b/include/my_md5.h
@@ -1,3 +1,6 @@
+#ifndef MY_MD5_INCLUDED
+#define MY_MD5_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -52,3 +55,5 @@ do { \
   my_MD5Update (&ctx, buf, len); \
   my_MD5Final (digest, &ctx); \
 } while (0)
+
+#endif /* MY_MD__INCLUDED */
diff --git a/include/my_no_pthread.h b/include/my_no_pthread.h
index b11dbff42f021a822e861e791c77e0f5667a8e3f..31c1bf2b6aca720c31bb7be41d330e3335058473 100644
--- a/include/my_no_pthread.h
+++ b/include/my_no_pthread.h
@@ -1,3 +1,6 @@
+#ifndef MY_NO_PTHREAD_INCLUDED
+#define MY_NO_PTHREAD_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -14,9 +17,7 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
-#if !defined(_my_no_pthread_h) && !defined(THREAD)
-#define _my_no_pthread_h
-
+#ifndef THREAD
 
 /*
   This block is to access some thread-related type definitions
@@ -48,3 +49,4 @@
 #define rwlock_destroy(A)
 
 #endif
+#endif /* MY_NO_PTHREAD_INCLUDED */
diff --git a/include/my_sys.h b/include/my_sys.h
index 320b7e944673787ba67d9916fd6cc1e89e63dc0d..b4366a4cd3d9006046e2a1c8a08709c6e88e4851 100644
--- a/include/my_sys.h
+++ b/include/my_sys.h
@@ -877,6 +877,7 @@ extern void *memdup_root(MEM_ROOT *root,const void *str, size_t len);
 extern int get_defaults_options(int argc, char **argv,
                                 char **defaults, char **extra_defaults,
                                 char **group_suffix);
+extern const char *args_separator;
 extern int my_load_defaults(const char *conf_file, const char **groups,
                             int *argc, char ***argv, const char ***);
 extern int load_defaults(const char *conf_file, const char **groups,
diff --git a/include/my_uctype.h b/include/my_uctype.h
index 9aaf478810c879f5f07a0fbb8d2e4bce4a0d54c3..580eb646e11d67ad14430fe60d7e39b7f7d4ea91 100644
--- a/include/my_uctype.h
+++ b/include/my_uctype.h
@@ -1,3 +1,6 @@
+#ifndef MY_UCTYPE_INCLUDED
+#define MY_UCTYPE_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -1477,3 +1480,4 @@ MY_UNI_CTYPE my_uni_ctype[256]={
 };
 
 
+#endif /* MY_UCTYPE_INCLUDED */
diff --git a/include/myisampack.h b/include/myisampack.h
index 7d4871bd1cbf307b988ccbe8f4a505792b15d1c3..ecf35520a88bf016a75d28ea8c0af964ea2fc9b6 100644
--- a/include/myisampack.h
+++ b/include/myisampack.h
@@ -1,3 +1,6 @@
+#ifndef MYISAMPACK_INCLUDED
+#define MYISAMPACK_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -236,3 +239,4 @@
                                      mi_int4store(((T) + 4), A); }}
 #define mi_sizekorr(T)      mi_uint4korr((uchar*) (T) + 4)
 #endif
+#endif /* MYISAMPACK_INCLUDED */
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h
index 2e59262d0614a7f3627f1f9fcadb191cd9f057c8..45d0234cb670f4323aee7b5d6ea4b72f62b41741 100644
--- a/include/mysql/plugin.h
+++ b/include/mysql/plugin.h
@@ -16,6 +16,11 @@
 #ifndef _my_plugin_h
 #define _my_plugin_h
 
+/* size_t */
+#include <stdlib.h>
+
+typedef struct st_mysql MYSQL;
+
 
 /*
   On Windows, exports from DLL need to be declared
@@ -75,7 +80,8 @@ typedef struct st_mysql_xid MYSQL_XID;
 #define MYSQL_FTPARSER_PLUGIN        2  /* Full-text parser plugin      */
 #define MYSQL_DAEMON_PLUGIN          3  /* The daemon/raw plugin type */
 #define MYSQL_INFORMATION_SCHEMA_PLUGIN  4  /* The I_S plugin type */
-#define MYSQL_MAX_PLUGIN_TYPE_NUM    5  /* The number of plugin types   */
+#define MYSQL_REPLICATION_PLUGIN     5	/* The replication plugin type */
+#define MYSQL_MAX_PLUGIN_TYPE_NUM    6  /* The number of plugin types   */
 
 /* We use the following strings to define licenses for plugins */
 #define PLUGIN_LICENSE_PROPRIETARY 0
@@ -650,6 +656,17 @@ struct st_mysql_information_schema
   int interface_version;
 };
 
+/*
+  API for Replication plugin. (MYSQL_REPLICATION_PLUGIN)
+*/
+ #define MYSQL_REPLICATION_INTERFACE_VERSION 0x0100
+ 
+ /**
+    Replication plugin descriptor
+ */
+ struct Mysql_replication {
+   int interface_version;
+ };
 
 /*
   st_mysql_value struct for reading values from mysqld.
@@ -801,6 +818,64 @@ void mysql_query_cache_invalidate4(MYSQL_THD thd,
                                    const char *key, unsigned int key_length,
                                    int using_trx);
 
+/**
+   Get the value of user variable as an integer.
+
+   This function will return the value of variable @a name as an
+   integer. If the original value of the variable is not an integer,
+   the value will be converted into an integer.
+
+   @param name     user variable name
+   @param value    pointer to return the value
+   @param null_value if not NULL, the function will set it to true if
+   the value of variable is null, set to false if not
+
+   @retval 0 Success
+   @retval 1 Variable not found
+*/
+int get_user_var_int(const char *name,
+                     long long int *value, int *null_value);
+
+/**
+   Get the value of user variable as a double precision float number.
+
+   This function will return the value of variable @a name as real
+   number. If the original value of the variable is not a real number,
+   the value will be converted into a real number.
+
+   @param name     user variable name
+   @param value    pointer to return the value
+   @param null_value if not NULL, the function will set it to true if
+   the value of variable is null, set to false if not
+
+   @retval 0 Success
+   @retval 1 Variable not found
+*/
+int get_user_var_real(const char *name,
+                      double *value, int *null_value);
+
+/**
+   Get the value of user variable as a string.
+
+   This function will return the value of variable @a name as
+   string. If the original value of the variable is not a string,
+   the value will be converted into a string.
+
+   @param name     user variable name
+   @param value    pointer to the value buffer
+   @param len      length of the value buffer
+   @param precision precision of the value if it is a float number
+   @param null_value if not NULL, the function will set it to true if
+   the value of variable is null, set to false if not
+
+   @retval 0 Success
+   @retval 1 Variable not found
+*/
+int get_user_var_str(const char *name,
+                     char *value, unsigned long len,
+                     unsigned int precision, int *null_value);
+
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mysql/plugin.h.pp b/include/mysql/plugin.h.pp
index 50511f515abd91b6775ad03cb1e6342b4acf9363..d864140333b09cf918ae7ee5b144d257618d98e4 100644
--- a/include/mysql/plugin.h.pp
+++ b/include/mysql/plugin.h.pp
@@ -1,3 +1,5 @@
+#include <stdlib.h>
+typedef struct st_mysql MYSQL;
 struct st_mysql_lex_string
 {
   char *str;
@@ -105,6 +107,9 @@ struct st_mysql_information_schema
 {
   int interface_version;
 };
+struct Mysql_replication {
+  int interface_version;
+};
 struct st_mysql_value
 {
   int (*value_type)(struct st_mysql_value *);
@@ -137,3 +142,10 @@ void thd_get_xid(const void* thd, MYSQL_XID *xid);
 void mysql_query_cache_invalidate4(void* thd,
                                    const char *key, unsigned int key_length,
                                    int using_trx);
+int get_user_var_int(const char *name,
+                     long long int *value, int *null_value);
+int get_user_var_real(const char *name,
+                      double *value, int *null_value);
+int get_user_var_str(const char *name,
+                     char *value, unsigned long len,
+                     unsigned int precision, int *null_value);
diff --git a/include/mysql_embed.h b/include/mysql_embed.h
index 4a7fd3ef63c216a38adab08d58c8e9970f7bd5ec..0e5a360585e716173927e8001d9acac3a78c72f0 100644
--- a/include/mysql_embed.h
+++ b/include/mysql_embed.h
@@ -1,3 +1,6 @@
+#ifndef MYSQL_EMBED_INCLUDED
+#define MYSQL_EMBED_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -28,3 +31,4 @@
 #define DONT_USE_RAID
 
 #endif /* EMBEDDED_LIBRARY */
+#endif /* MYSQL_EMBED_INCLUDED */
diff --git a/include/rijndael.h b/include/rijndael.h
index 89963a85c9959e912f95585ad560ca710ee4af11..71df1c48dbfd7638cd9b1963d19e5cc02df939d9 100644
--- a/include/rijndael.h
+++ b/include/rijndael.h
@@ -1,3 +1,6 @@
+#ifndef RIJNDAEL_INCLUDED
+#define RIJNDAEL_INCLUDED
+
 /* Copyright (C) 2002 MySQL AB
 
  This program is free software; you can redistribute it and/or modify
@@ -39,3 +42,5 @@ void rijndaelEncrypt(const uint32 rk[/*4*(Nr + 1)*/], int Nr,
 		     const uint8 pt[16], uint8 ct[16]);
 void rijndaelDecrypt(const uint32 rk[/*4*(Nr + 1)*/], int Nr,
 		     const uint8 ct[16], uint8 pt[16]);
+
+#endif /* RIJNDAEL_INCLUDED */
diff --git a/include/sha1.h b/include/sha1.h
index e476456a9bd02ca75e948269d3f43370df74cca2..5b4dc5d46edb2f425b9a7f7b108316a8cb741c2b 100644
--- a/include/sha1.h
+++ b/include/sha1.h
@@ -1,3 +1,6 @@
+#ifndef SHA1_INCLUDED
+#define SHA1_INCLUDED
+
 /* Copyright (C) 2002, 2006 MySQL AB
 
  This program is free software; you can redistribute it and/or modify
@@ -64,3 +67,5 @@ int mysql_sha1_input(SHA1_CONTEXT*, const uint8 *, unsigned int);
 int mysql_sha1_result(SHA1_CONTEXT* , uint8 Message_Digest[SHA1_HASH_SIZE]);
 
 C_MODE_END
+
+#endif /* SHA__INCLUDED */
diff --git a/include/sql_common.h b/include/sql_common.h
index 9e43d076ba933e62792676398e8a54bb8cf69062..5fd8778d62b919d204d6ad7861922bfc146e3eb6 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -1,3 +1,6 @@
+#ifndef SQL_COMMON_INCLUDED
+#define SQL_COMMON_INCLUDED
+
 /* Copyright (C) 2003-2004, 2006 MySQL AB
    
    This program is free software; you can redistribute it and/or modify
@@ -48,3 +51,4 @@ void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate);
 
 #define protocol_41(A) ((A)->server_capabilities & CLIENT_PROTOCOL_41)
 
+#endif /* SQL_COMMON_INCLUDED */
diff --git a/include/sslopt-case.h b/include/sslopt-case.h
index adb9a28503bde9352e974573c0ede79065a06b53..ce46cf65cc9817c4405e69cc30dceca6abbe16eb 100644
--- a/include/sslopt-case.h
+++ b/include/sslopt-case.h
@@ -1,3 +1,6 @@
+#ifndef SSLOPT_CASE_INCLUDED
+#define SSLOPT_CASE_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -26,3 +29,4 @@
       opt_use_ssl= 1;
       break;
 #endif
+#endif /* SSLOPT_CASE_INCLUDED */
diff --git a/include/sslopt-longopts.h b/include/sslopt-longopts.h
index c76b5dcd2523e37ee6a773ce6d6a0b1429dbe9e7..eae1424238bfc771ac6638b1afa6c2cf31004dee 100644
--- a/include/sslopt-longopts.h
+++ b/include/sslopt-longopts.h
@@ -1,3 +1,6 @@
+#ifndef SSLOPT_LONGOPTS_INCLUDED
+#define SSLOPT_LONGOPTS_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -43,3 +46,4 @@
     0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 #endif
 #endif /* HAVE_OPENSSL */
+#endif /* SSLOPT_LONGOPTS_INCLUDED */
diff --git a/include/sslopt-vars.h b/include/sslopt-vars.h
index 3369f870db2a22dde4d937258f8589cedcd8a38d..4493fbc59abf74e46e2c597f8cd6ea9b7fdd1f4c 100644
--- a/include/sslopt-vars.h
+++ b/include/sslopt-vars.h
@@ -1,3 +1,6 @@
+#ifndef SSLOPT_VARS_INCLUDED
+#define SSLOPT_VARS_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -29,3 +32,4 @@ SSL_STATIC char *opt_ssl_key    = 0;
 SSL_STATIC my_bool opt_ssl_verify_server_cert= 0;
 #endif
 #endif
+#endif /* SSLOPT_VARS_INCLUDED */
diff --git a/libmysql/client_settings.h b/libmysql/client_settings.h
index f87e625771f8e18aefeba63df764b8c8ac92d8e3..1fd8619a7461b7a1a92aeb18dce317eaab7106cc 100644
--- a/libmysql/client_settings.h
+++ b/libmysql/client_settings.h
@@ -13,6 +13,12 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
+#ifndef CLIENT_SETTINGS_INCLUDED
+#define CLIENT_SETTINGS_INCLUDED
+#else
+#error You have already included an client_settings.h and it should not be included twice
+#endif /* CLIENT_SETTINGS_INCLUDED */
+
 extern uint		mysql_port;
 extern char *	mysql_unix_port;
 
diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt
index ab81faa773405254a2d8195d77b22f3fc7ccabd8..65b8e12bc262c5708391726577aff4e598f723c5 100644
--- a/libmysqld/CMakeLists.txt
+++ b/libmysqld/CMakeLists.txt
@@ -132,7 +132,7 @@ SET(LIBMYSQLD_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
            ../sql/time.cc ../sql/tztime.cc ../sql/uniques.cc ../sql/unireg.cc
            ../sql/partition_info.cc ../sql/sql_connect.cc 
            ../sql/scheduler.cc ../sql/event_parse_data.cc
-           ../sql/sql_signal.cc
+           ../sql/sql_signal.cc ../sql/rpl_handler.cc
            ${GEN_SOURCES}
            ${LIB_SOURCES})
 
diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am
index b80381de5bec8501ab1811ba3f7ddc8fb2f4d4d3..ec73741eaaf41659a1492cd89d7e1020b561bf6c 100644
--- a/libmysqld/Makefile.am
+++ b/libmysqld/Makefile.am
@@ -78,7 +78,8 @@ sqlsources = derror.cc field.cc field_conv.cc strfunc.cc filesort.cc \
 	debug_sync.cc \
 	sql_tablespace.cc \
 	rpl_injector.cc my_user.c partition_info.cc \
-	sql_servers.cc event_parse_data.cc sql_signal.cc
+	sql_servers.cc event_parse_data.cc sql_signal.cc \
+	rpl_handler.cc
 
 libmysqld_int_a_SOURCES= $(libmysqld_sources)
 nodist_libmysqld_int_a_SOURCES= $(libmysqlsources) $(sqlsources)
diff --git a/mysql-test/collections/default.experimental b/mysql-test/collections/default.experimental
index 7f862b9f3938562eb3f5357d7e3e07fe45eb3a94..443eb62a02bfd1990440cdef1c5751ea810bcedd 100644
--- a/mysql-test/collections/default.experimental
+++ b/mysql-test/collections/default.experimental
@@ -78,3 +78,4 @@ parts.partition_syntax_ndb
 parts.partition_alter1_1_2_ndb
 parts.partition_basic_ndb
 parts.partition_mgm_lc0_ndb
+
diff --git a/mysql-test/extra/binlog_tests/binlog.test b/mysql-test/extra/binlog_tests/binlog.test
index b819996acb0e2de86279c2d0355c0d7e10fab418..b79093b6740cbdff8083faf4cd4ee2d93a96e7ff 100644
--- a/mysql-test/extra/binlog_tests/binlog.test
+++ b/mysql-test/extra/binlog_tests/binlog.test
@@ -43,10 +43,10 @@ commit;
 drop table t1;
 --replace_column 2 # 5 #
 --replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
-show binlog events in 'master-bin.000001' from 106;
+show binlog events in 'master-bin.000001' from 107;
 --replace_column 2 # 5 #
 --replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
-show binlog events in 'master-bin.000002' from 106;
+show binlog events in 'master-bin.000002' from 107;
 
 
 #
diff --git a/mysql-test/extra/binlog_tests/implicit.test b/mysql-test/extra/binlog_tests/implicit.test
new file mode 100644
index 0000000000000000000000000000000000000000..84d80288d36f04b53fd285a2e9722ce6ebdf0b11
--- /dev/null
+++ b/mysql-test/extra/binlog_tests/implicit.test
@@ -0,0 +1,28 @@
+# First part: outside a transaction
+RESET MASTER;
+eval $prepare;
+
+INSERT INTO t1 VALUES (1);
+source include/show_binlog_events.inc;
+eval $statement;
+source include/show_binlog_events.inc;
+if (`select '$cleanup' != ''`) {
+  eval $cleanup;
+}
+
+# Second part: inside a transaction
+RESET MASTER;
+eval $prepare;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+source include/show_binlog_events.inc;
+eval $statement;
+source include/show_binlog_events.inc;
+INSERT INTO t1 VALUES (3);
+source include/show_binlog_events.inc;
+COMMIT;
+source include/show_binlog_events.inc;
+if (`select '$cleanup' != ''`) {
+  eval $cleanup;
+}
+
diff --git a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test
index 5db79e4f848297a7cd161dcac7d3f9d04b785c52..da0b77fbc2368772966640c5f552e8b1ac8b1d8e 100644
--- a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test
+++ b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test
@@ -323,12 +323,12 @@ let $MYSQLD_DATADIR= `select @@datadir`;
 # and does not make slave to stop)
 if (`select @@binlog_format = 'ROW'`)
 {
-  --exec $MYSQL_BINLOG --start-position=524 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
+  --exec $MYSQL_BINLOG --start-position=525 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
 }
 
 if (`select @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'`)
 {
-  --exec $MYSQL_BINLOG --start-position=555 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
+  --exec $MYSQL_BINLOG --start-position=556 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
 }
 
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
diff --git a/mysql-test/extra/rpl_tests/rpl_extraSlave_Col.test b/mysql-test/extra/rpl_tests/rpl_extraSlave_Col.test
index a7b02065144b95aa27015b91fb136c735585a1b5..46168d6b97ac05e983032351cee3decb28843911 100644
--- a/mysql-test/extra/rpl_tests/rpl_extraSlave_Col.test
+++ b/mysql-test/extra/rpl_tests/rpl_extraSlave_Col.test
@@ -407,37 +407,57 @@ sync_slave_with_master;
 ###########################################
 # Bug#22234, Bug#23907 Extra Slave Col is not 
 # erroring on extra col with no default values.
-########################################################
+###############################################################
+# Error reaction is up to sql_mode of the slave sql (bug#38173)
 #--echo *** Create t9 on slave  ***
-STOP SLAVE;
-RESET SLAVE;
-eval CREATE TABLE t9 (a INT KEY, b BLOB, c CHAR(5),
-                      d TIMESTAMP,
-                      e INT NOT NULL) ENGINE=$engine_type;
-
---echo *** Create t9 on Master ***
-connection master;
-eval CREATE TABLE t9 (a INT PRIMARY KEY, b BLOB, c CHAR(5)
+# Please, check BUG#47741 to see why you are not testing NDB.
+if (`SELECT $engine_type != 'NDB'`)
+{
+  STOP SLAVE;
+  RESET SLAVE;
+  eval CREATE TABLE t9 (a INT KEY, b BLOB, c CHAR(5),
+                        d TIMESTAMP,
+                        e INT NOT NULL,
+                        f text not null,
+                        g text,
+                        h blob not null,
+                        i blob) ENGINE=$engine_type;
+
+  --echo *** Create t9 on Master ***
+  connection master;
+  eval CREATE TABLE t9 (a INT PRIMARY KEY, b BLOB, c CHAR(5)
                        ) ENGINE=$engine_type;
-RESET MASTER;
+  RESET MASTER;
 
---echo *** Start Slave ***
-connection slave;
-START SLAVE;
+  --echo *** Start Slave ***
+  connection slave;
+  START SLAVE;
 
---echo *** Master Data Insert ***
-connection master;
-set @b1 = 'b1b1b1b1';
-set @b1 = concat(@b1,@b1);
-INSERT INTO t9 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
+  --echo *** Master Data Insert ***
+  connection master;
+  set @b1 = 'b1b1b1b1';
 
-connection slave;
---source include/wait_for_slave_sql_to_stop.inc
---replace_result $MASTER_MYPORT MASTER_PORT
---replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
---query_vertical SHOW SLAVE STATUS
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
+  set @b1 = concat(@b1,@b1);
+  INSERT INTO t9 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
+
+  # the test would stop slave if @@sql_mode for the sql thread
+  # was set to strict. Otherwise, as with this tests setup, 
+  # the implicit defaults will be inserted into fields even though
+  # they are declared without DEFAULT clause.
+
+  sync_slave_with_master;
+  select * from t9;
+
+  # todo: fix Bug #43992 slave sql thread can't tune own sql_mode ...
+  # and add/restore waiting for stop test
+
+  #--source include/wait_for_slave_sql_to_stop.inc
+  #--replace_result $MASTER_MYPORT MASTER_PORT
+  #--replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
+  #--query_vertical SHOW SLAVE STATUS
+  #SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
+  #START SLAVE;
+}
 
 #--echo *** Drop t9  ***
 #connection master;
diff --git a/mysql-test/extra/rpl_tests/rpl_loaddata.test b/mysql-test/extra/rpl_tests/rpl_loaddata.test
index 26916642caeeabc3797d11fc85ce88abfaa60a61..129a39ac5090ccb9d5b5394dce5dde8bcdbfa77b 100644
--- a/mysql-test/extra/rpl_tests/rpl_loaddata.test
+++ b/mysql-test/extra/rpl_tests/rpl_loaddata.test
@@ -72,7 +72,7 @@ start slave;
 sync_with_master;
 --replace_result $MASTER_MYPORT MASTER_PORT
 --replace_column 1 # 8 # 9 # 16 # 23 # 33 #
-show slave status;
+--query_vertical show slave status;
 
 # Trigger error again to test CHANGE MASTER
 
@@ -94,7 +94,7 @@ change master to master_user='test';
 change master to master_user='root';
 --replace_result $MASTER_MYPORT MASTER_PORT
 --replace_column 1 # 8 # 9 # 16 # 23 # 33 #
-show slave status;
+--query_vertical show slave status;
 
 # Trigger error again to test RESET SLAVE
 
@@ -116,7 +116,7 @@ stop slave;
 reset slave;
 --replace_result $MASTER_MYPORT MASTER_PORT
 --replace_column 1 # 8 # 9 # 16 # 23 # 33 #
-show slave status;
+--query_vertical show slave status;
 
 # Finally, see if logging is done ok on master for a failing LOAD DATA INFILE
 
diff --git a/mysql-test/extra/rpl_tests/rpl_log.test b/mysql-test/extra/rpl_tests/rpl_log.test
index e4ebfd68761a26efc4d7be9c3ace5fb06096307c..0517fea1be3c2e9265477b01a05bb972c1495eeb 100644
--- a/mysql-test/extra/rpl_tests/rpl_log.test
+++ b/mysql-test/extra/rpl_tests/rpl_log.test
@@ -37,13 +37,13 @@ select count(*) from t1;
 show binlog events;
 --replace_column 2 # 5 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-show binlog events from 106 limit 1;
+show binlog events from 107 limit 1;
 --replace_column 2 # 5 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-show binlog events from 106 limit 2;
+show binlog events from 107 limit 2;
 --replace_column 2 # 5 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-show binlog events from 106 limit 2,1;
+show binlog events from 107 limit 2,1;
 flush logs;
 
 # We need an extra update before doing save_master_pos.
diff --git a/mysql-test/extra/rpl_tests/rpl_not_null.test b/mysql-test/extra/rpl_tests/rpl_not_null.test
new file mode 100644
index 0000000000000000000000000000000000000000..58dbd9ce29f1d1ab2f4c7ce328b422c39ce37212
--- /dev/null
+++ b/mysql-test/extra/rpl_tests/rpl_not_null.test
@@ -0,0 +1,364 @@
+#################################################################################
+# This test checks if the replication between "null" fields to either "null"
+# fields or "not null" fields works properly. In the first case, the execution
+# should work fine. In the second case, it may fail according to the sql_mode
+# being used.
+#
+# The test is devided in three main parts:
+#
+# 1 - NULL --> NULL (no failures)
+# 2 - NULL --> NOT NULL ( sql-mode  = STRICT and failures)
+# 3 - NULL --> NOT NULL ( sql-mode != STRICT and no failures)
+#
+#################################################################################
+connection master;
+
+SET SQL_LOG_BIN= 0;
+eval CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+eval CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+eval CREATE TABLE t3(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+eval CREATE TABLE t4(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+SET SQL_LOG_BIN= 1;
+
+connection slave;
+
+eval CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+eval CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+eval CREATE TABLE t3(`a` INT, `b` DATE DEFAULT '0000-00-00',
+`c` INT DEFAULT 500, 
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+eval CREATE TABLE t4(`a` INT, `b` DATE DEFAULT '0000-00-00',
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+--echo ************* EXECUTION WITH INSERTS *************
+connection master;
+INSERT INTO t1(a,b,c) VALUES (1, null, 1);
+INSERT INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
+INSERT INTO t1(a,b) VALUES (3, null);
+INSERT INTO t1(a,c) VALUES (4, 4);
+INSERT INTO t1(a) VALUES (5);
+
+INSERT INTO t2(a,b) VALUES (1, null);
+INSERT INTO t2(a,b) VALUES (2,'1111-11-11');
+INSERT INTO t2(a) VALUES (3);
+
+INSERT INTO t3(a,b) VALUES (1, null);
+INSERT INTO t3(a,b) VALUES (2,'1111-11-11');
+INSERT INTO t3(a) VALUES (3);
+
+INSERT INTO t4(a,b,c) VALUES (1, null, 1);
+INSERT INTO t4(a,b,c) VALUES (2,'1111-11-11', 2);
+INSERT INTO t4(a,b) VALUES (3, null);
+INSERT INTO t4(a,c) VALUES (4, 4);
+INSERT INTO t4(a) VALUES (5);
+
+--echo ************* SHOWING THE RESULT SETS WITH INSERTS *************
+sync_slave_with_master;
+
+--echo TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+ 
+let $diff_table_1=master:test.t2;
+let $diff_table_2=slave:test.t2;
+source include/diff_tables.inc;
+
+--echo TABLES t2 and t3 must be different.
+connection master;
+SELECT * FROM t3 ORDER BY a;
+connection slave;
+SELECT * FROM t3 ORDER BY a;
+connection master;
+SELECT * FROM t4 ORDER BY a;
+connection slave;
+SELECT * FROM t4 ORDER BY a;
+
+--echo ************* EXECUTION WITH UPDATES and REPLACES *************
+connection master;
+DELETE FROM t1;
+INSERT INTO t1(a,b,c) VALUES (1,'1111-11-11', 1);
+REPLACE INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
+UPDATE t1 set b= NULL, c= 300 where a= 1;
+REPLACE INTO t1(a,b,c) VALUES (2, NULL, 300);
+
+--echo ************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
+sync_slave_with_master;
+
+--echo TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+
+--echo ************* CLEANING *************
+connection master;
+
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP TABLE t4;
+
+sync_slave_with_master;
+  
+connection master;
+
+SET SQL_LOG_BIN= 0;
+eval CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT NULL, `c` BIT DEFAULT NULL, 
+PRIMARY KEY (`a`)) ENGINE= $engine;
+SET SQL_LOG_BIN= 1;
+
+connection slave;
+
+eval CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT b'01', `c` BIT DEFAULT NULL,
+PRIMARY KEY (`a`)) ENGINE= $engine;
+
+--echo ************* EXECUTION WITH INSERTS *************
+connection master;
+INSERT INTO t1(a,b,c) VALUES (1, null, b'01');
+INSERT INTO t1(a,b,c) VALUES (2,b'00', b'01');
+INSERT INTO t1(a,b) VALUES (3, null);
+INSERT INTO t1(a,c) VALUES (4, b'01');
+INSERT INTO t1(a) VALUES (5);
+
+--echo ************* SHOWING THE RESULT SETS WITH INSERTS *************
+--echo TABLES t1 and t2 must be different.
+sync_slave_with_master;
+connection master;
+SELECT a,b+0,c+0 FROM t1 ORDER BY a;
+connection slave;
+SELECT a,b+0,c+0 FROM t1 ORDER BY a;
+
+--echo ************* EXECUTION WITH UPDATES and REPLACES *************
+connection master;
+DELETE FROM t1;
+INSERT INTO t1(a,b,c) VALUES (1,b'00', b'01');
+REPLACE INTO t1(a,b,c) VALUES (2,b'00',b'01');
+UPDATE t1 set b= NULL, c= b'00' where a= 1;
+REPLACE INTO t1(a,b,c) VALUES (2, NULL, b'00');
+
+--echo ************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
+--echo TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+sync_slave_with_master;
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+ 
+connection master;
+
+DROP TABLE t1;
+
+sync_slave_with_master;
+  
+--echo ################################################################################
+--echo #                       NULL ---> NOT NULL (STRICT MODE)
+--echo #                    UNCOMMENT THIS AFTER FIXING BUG#43992
+--echo ################################################################################
+#connection slave;
+#SET GLOBAL sql_mode="TRADITIONAL";
+#
+#STOP SLAVE;
+#--source include/wait_for_slave_to_stop.inc
+#START SLAVE;
+#--source include/wait_for_slave_to_start.inc
+#
+#let $y=0;
+#while (`select $y < 6`)
+#{
+#  connection master;
+#
+#  SET SQL_LOG_BIN= 0;
+#  eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT,
+#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+#  eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT,
+#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+#  eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT,
+#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+#  SET SQL_LOG_BIN= 1;
+#  
+#  connection slave;
+#  
+#  eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT NOT NULL, 
+#  `c` INT NOT NULL,
+#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+#  eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT NOT NULL,
+#  `c` INT, 
+#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+#  eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT NOT NULL,
+#  `c` INT DEFAULT 500, 
+#  PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+#  
+#  if (`select $y=0`)
+#  {
+#    --echo ************* EXECUTION WITH INSERTS *************
+#    connection master;
+#    INSERT INTO t1(a) VALUES (1);
+#  }
+#  
+#  if (`select $y=1`)
+#  {
+#    --echo ************* EXECUTION WITH INSERTS *************
+#    connection master;
+#    INSERT INTO t1(a, b) VALUES (1, NULL);
+#  }
+#  
+#  if (`select $y=2`)
+#  {
+#    --echo ************* EXECUTION WITH UPDATES *************
+#    connection master;
+#    INSERT INTO t3(a, b) VALUES (1, 1);
+#    INSERT INTO t3(a, b) VALUES (2, 1);
+#    UPDATE t3 SET b = NULL where a= 1;
+#  }
+#  
+#  if (`select $y=3`)
+#  {
+#    --echo ************* EXECUTION WITH INSERTS/REPLACES *************
+#    connection master;
+#    REPLACE INTO t3(a, b) VALUES (1, null);
+#  }
+#   
+#  if (`select $y=4`)
+#  {
+#    --echo ************* EXECUTION WITH UPDATES/REPLACES *************
+#    connection master;
+#    INSERT INTO t3(a, b) VALUES (1, 1);
+#    REPLACE INTO t3(a, b) VALUES (1, null);
+#  }
+#   
+#  if (`select $y=5`)
+#  {
+#    --echo ************* EXECUTION WITH MULTI-ROW INSERTS *************
+#    connection master;
+#
+#    SET SQL_LOG_BIN= 0;
+#    INSERT INTO t2(a, b) VALUES (1, 1);
+#    INSERT INTO t2(a, b) VALUES (2, 1);
+#    INSERT INTO t2(a, b) VALUES (3, null);
+#    INSERT INTO t2(a, b) VALUES (4, 1);
+#    INSERT INTO t2(a, b) VALUES (5, 1);
+#    SET SQL_LOG_BIN= 1;
+#
+#    INSERT INTO t2 SELECT a + 10, b from t2;
+#    --echo The statement below is just executed to stop processing
+#    INSERT INTO t1(a) VALUES (1);
+#  }
+#  
+#  --echo ************* SHOWING THE RESULT SETS *************
+#  connection slave;
+#  --source include/wait_for_slave_sql_to_stop.inc
+#  connection master;
+#  SELECT * FROM t1 ORDER BY a;
+#  connection slave;
+#  SELECT * FROM t1 ORDER BY a;
+#  connection master;
+#  SELECT * FROM t2 ORDER BY a;
+#  connection slave;
+#  SELECT * FROM t2 ORDER BY a;
+#  connection master;
+#  SELECT * FROM t3 ORDER BY a;
+#  connection slave;
+#  SELECT * FROM t3 ORDER BY a;
+#  --source include/reset_master_and_slave.inc
+#  
+#  connection master;
+#  
+#  DROP TABLE t1;
+#  DROP TABLE t2;
+#  DROP TABLE t3;
+#  
+#  sync_slave_with_master;
+#
+#  inc $y;
+#}
+#connection slave;
+#SET GLOBAL sql_mode="";
+#
+#STOP SLAVE;
+#source include/wait_for_slave_to_stop.inc;
+#START SLAVE;
+#--source include/wait_for_slave_to_start.inc
+
+--echo ################################################################################
+--echo #                       NULL ---> NOT NULL (NON-STRICT MODE)
+--echo ################################################################################
+connection master;
+
+SET SQL_LOG_BIN= 0;
+eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+SET SQL_LOG_BIN= 1;
+
+connection slave;
+
+eval CREATE TABLE t1(`a` INT NOT NULL, `b` INT NOT NULL, 
+`c` INT NOT NULL,
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+eval CREATE TABLE t2(`a` INT NOT NULL, `b` INT NOT NULL,
+`c` INT, 
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+eval CREATE TABLE t3(`a` INT NOT NULL, `b` INT NOT NULL,
+`c` INT DEFAULT 500, 
+PRIMARY KEY(`a`)) ENGINE=$engine DEFAULT CHARSET=LATIN1;
+
+--echo ************* EXECUTION WITH INSERTS *************
+connection master;
+INSERT INTO t1(a) VALUES (1);
+INSERT INTO t1(a, b) VALUES (2, NULL);
+INSERT INTO t1(a, b) VALUES (3, 1);
+
+INSERT INTO t2(a) VALUES (1);
+INSERT INTO t2(a, b) VALUES (2, NULL);
+INSERT INTO t2(a, b) VALUES (3, 1);
+
+INSERT INTO t3(a) VALUES (1);
+INSERT INTO t3(a, b) VALUES (2, NULL);
+INSERT INTO t3(a, b) VALUES (3, 1);
+INSERT INTO t3(a, b) VALUES (4, 1);
+REPLACE INTO t3(a, b) VALUES (5, null);
+
+REPLACE INTO t3(a, b) VALUES (3, null);
+UPDATE t3 SET b = NULL where a = 4;
+
+--echo ************* SHOWING THE RESULT SETS *************
+connection master;
+sync_slave_with_master;
+
+connection master;
+SELECT * FROM t1 ORDER BY a;
+connection slave;
+SELECT * FROM t1 ORDER BY a;
+connection master;
+SELECT * FROM t2 ORDER BY a;
+connection slave;
+SELECT * FROM t2 ORDER BY a;
+connection master;
+SELECT * FROM t3 ORDER BY a;
+connection slave;
+SELECT * FROM t3 ORDER BY a;
+
+connection master;
+
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+
+sync_slave_with_master;
diff --git a/mysql-test/extra/rpl_tests/rpl_row_tabledefs.test b/mysql-test/extra/rpl_tests/rpl_row_tabledefs.test
index 3b03caee35c5eea17217e3a93bc4426cc85d2e98..083088f12ff1cc90c8e22343529143d665d72447 100644
--- a/mysql-test/extra/rpl_tests/rpl_row_tabledefs.test
+++ b/mysql-test/extra/rpl_tests/rpl_row_tabledefs.test
@@ -111,21 +111,18 @@ SELECT a,b,x FROM t1_int ORDER BY a;
 SELECT a,b,HEX(x),HEX(y),HEX(z) FROM t1_bit ORDER BY a;
 SELECT a,b,x FROM t1_char ORDER BY a;
 
-# Each of these inserts should generate an error and stop the slave
-
 connection master;
 INSERT INTO t9 VALUES (2);
 sync_slave_with_master;
 # Now slave is guaranteed to be running
 connection master;
 INSERT INTO t1_nodef VALUES (1,2);
-connection slave;
---source include/wait_for_slave_sql_to_stop.inc
---replace_result $MASTER_MYPORT MASTER_PORT
---replace_column 1 # 4 # 7 # 8 # 9 # 20 <Last_Error> 22 # 23 # 33 # 35 <Last_IO_Errno> 36 <Last_IO_Error> 38 <Last_SQL_Error>
---query_vertical SHOW SLAVE STATUS
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
+
+# Last insert on wider slave table succeeds while slave sql sql_mode permits.
+# The previous version of the above test expected slave sql to stop.
+# bug#38173 relaxed conditions to stop only with the strict mode.
+sync_slave_with_master;
+select count(*) from t1_nodef;
 
 #
 # Replicating to tables with fewer columns at the end works as of WL#3228
diff --git a/mysql-test/extra/rpl_tests/rpl_show_relaylog_events.inc b/mysql-test/extra/rpl_tests/rpl_show_relaylog_events.inc
new file mode 100644
index 0000000000000000000000000000000000000000..50036e564a79b6246e8ead48344b3e098b690ce8
--- /dev/null
+++ b/mysql-test/extra/rpl_tests/rpl_show_relaylog_events.inc
@@ -0,0 +1,121 @@
+-- connection master
+
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+INSERT INTO t1 VALUES (3);
+INSERT INTO t1 VALUES (4);
+INSERT INTO t1 VALUES (5);
+INSERT INTO t1 VALUES (6);
+
+-- echo [MASTER] ********* SOW BINLOG EVENTS IN ...  *********
+let $binary_log_file= master-bin.000001;
+-- source include/show_binlog_events.inc
+
+-- echo [MASTER] ********* SOW BINLOG EVENTS         *********
+let $binary_log_file= ;
+-- source include/show_binlog_events.inc
+
+-- echo [MASTER] ********* SOW BINLOG EVENTS ... LIMIT rows  *********
+let $binary_log_file= ;
+let $binary_log_limit_row= 3;
+-- source include/show_binlog_events.inc
+
+-- echo [MASTER] ********* SOW BINLOG EVENTS ... LIMIT offset,rows  *********
+let $binary_log_file= ;
+let $binary_log_limit_row= 3;
+let $binary_log_limit_offset= 1;
+-- source include/show_binlog_events.inc
+
+# clear show_binlog_event/show_relaylog_events parameters
+let $binary_log_file= ;
+let $binary_log_limit_row= ;
+let $binary_log_limit_offset= ;
+
+-- sync_slave_with_master
+
+-- echo [SLAVE] ********* SOW BINLOG EVENTS IN ...   *********
+let $binary_log_file= slave-bin.000001;
+-- source include/show_binlog_events.inc
+
+-- echo [SLAVE] ********* SOW BINLOG EVENTS          *********
+let $binary_log_file= ;
+-- source include/show_binlog_events.inc
+
+-- echo [SLAVE] ********* SOW BINLOG EVENTS ... LIMIT rows  *********
+let $binary_log_file= ;
+let $binary_log_limit_row= 3;
+-- source include/show_binlog_events.inc
+
+-- echo [SLAVE] ********* SOW BINLOG EVENTS ... LIMIT offset,rows  *********
+let $binary_log_file= ;
+let $binary_log_limit_row= 3;
+let $binary_log_limit_offset= 1;
+-- source include/show_binlog_events.inc
+
+# clear show_binlog_event/show_relaylog_events parameters
+let $binary_log_file= ;
+let $binary_log_limit_row= ;
+let $binary_log_limit_offset= ;
+
+-- echo [SLAVE] ********* SOW RELAYLOG EVENTS IN ... *********
+let $binary_log_file= slave-relay-bin.000003;
+-- source include/show_relaylog_events.inc
+
+-- echo [SLAVE] ********* SOW RELAYLOG EVENTS        *********
+let $binary_log_file= ;
+-- source include/show_relaylog_events.inc
+
+-- echo [MASTER] ********* SOW RELAYLOG EVENTS ... LIMIT rows  *********
+let $binary_log_file= slave-relay-bin.000003;
+let $binary_log_limit_row= 3;
+let $binary_log_limit_offset= ;
+-- source include/show_relaylog_events.inc
+
+-- echo [MASTER] ********* SOW RELAYLOG EVENTS ... LIMIT offset,rows  *********
+let $binary_log_file= slave-relay-bin.000003;
+let $binary_log_limit_offset= 1;
+let $binary_log_limit_row= 3;
+-- source include/show_relaylog_events.inc
+
+FLUSH LOGS;
+
+-- connection master
+FLUSH LOGS;
+DROP TABLE t1;
+
+# clear show_binlog_event/show_relaylog_events parameters
+let $binary_log_file= ;
+let $binary_log_limit_row= ;
+let $binary_log_limit_offset= ;
+
+-- echo [MASTER] ********* SOW BINLOG EVENTS IN ...  *********
+let $binary_log_file= master-bin.000002;
+-- source include/show_binlog_events.inc
+
+-- echo [MASTER] ********* SOW BINLOG EVENTS         *********
+let $binary_log_file= ;
+-- source include/show_binlog_events.inc
+
+-- sync_slave_with_master
+
+-- echo [SLAVE] ********* SOW BINLOG EVENTS IN ...   *********
+let $binary_log_file= slave-bin.000002;
+-- source include/show_binlog_events.inc
+
+-- echo [SLAVE] ********* SOW BINLOG EVENTS          *********
+let $binary_log_file= ;
+-- source include/show_binlog_events.inc
+
+-- echo [SLAVE] ********* SOW RELAYLOG EVENTS IN ... *********
+let $binary_log_file= slave-relay-bin.000005;
+-- source include/show_relaylog_events.inc
+
+-- echo [SLAVE] ********* SOW RELAYLOG EVENTS        *********
+let $binary_log_file= ;
+-- source include/show_relaylog_events.inc
+
+# clear show_binlog_event/show_relaylog_events parameters
+let $binary_log_name= ;
+let $binary_log_limit_row= ;
+let $binary_log_limit_offset= ;
diff --git a/mysql-test/include/have_semisync_plugin.inc b/mysql-test/include/have_semisync_plugin.inc
new file mode 100644
index 0000000000000000000000000000000000000000..38e2fcd611507e16c7ed46ac62afe4a8923550f5
--- /dev/null
+++ b/mysql-test/include/have_semisync_plugin.inc
@@ -0,0 +1,15 @@
+#
+# Check if dynamic loading is supported
+#
+--require r/have_dynamic_loading.require
+disable_query_log;
+show variables like 'have_dynamic_loading';
+enable_query_log;
+
+#
+# Check if the variable SEMISYNC_MASTER_PLUGIN is set
+#
+if (`select LENGTH('$SEMISYNC_MASTER_PLUGIN') = 0`)
+{
+  skip Need semisync plugins;
+}
diff --git a/mysql-test/include/have_ssl_communication.inc b/mysql-test/include/have_ssl_communication.inc
new file mode 100644
index 0000000000000000000000000000000000000000..6f2d5587a75665417560c27eab0ec0c15be15722
--- /dev/null
+++ b/mysql-test/include/have_ssl_communication.inc
@@ -0,0 +1,4 @@
+-- require r/have_ssl.require
+disable_query_log;
+show variables like 'have_ssl';
+enable_query_log;
diff --git a/mysql-test/include/master-slave.inc b/mysql-test/include/master-slave.inc
index e0eb87f02f73fbe3c8d6e24749b5456e69ebf21e..25e0150dd0ac293f63ea70b4fa3d7f34029794a3 100644
--- a/mysql-test/include/master-slave.inc
+++ b/mysql-test/include/master-slave.inc
@@ -8,5 +8,7 @@ connect (slave1,127.0.0.1,root,,test,$SLAVE_MYPORT,);
 
 -- source include/master-slave-reset.inc
 
+connection master;
+sync_slave_with_master;
 # Set the default connection to 'master'
 connection master;
diff --git a/mysql-test/include/setup_fake_relay_log.inc b/mysql-test/include/setup_fake_relay_log.inc
index f88806e1079671e887230e3624339d24a9ba9698..b11e6afbecac4f14898bb7d721bef4a4c27566bd 100644
--- a/mysql-test/include/setup_fake_relay_log.inc
+++ b/mysql-test/include/setup_fake_relay_log.inc
@@ -69,7 +69,21 @@ let $_fake_relay_log_purge= `SELECT @@global.relay_log_purge`;
 # Create relay log file.
 copy_file $fake_relay_log $_fake_relay_log;
 # Create relay log index.
---exec echo $_fake_filename-fake.000001 > $_fake_relay_index
+
+# After patch for BUG#12190, the filename used in CHANGE MASTER
+# RELAY_LOG_FILE will be automatically added the directory of the
+# relay log before comparison, thus we need to added the directory
+# part (./ on unix .\ on windows) when faking the relay-log-bin.index.
+
+if (`select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows") = 0`)
+{
+  eval select './$_fake_filename-fake.000001\n' into dumpfile '$_fake_relay_index';
+}
+
+if (`select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows") != 0`)
+{
+  eval select '.\\\\$_fake_filename-fake.000001\n' into dumpfile '$_fake_relay_index';
+}
 
 # Setup replication from existing relay log.
 eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4;
diff --git a/mysql-test/include/show_binlog_events.inc b/mysql-test/include/show_binlog_events.inc
index 68f913a16a3bb6562826a8607a9da4d0b29f5f45..fcdc52eaf14a256ac5426633655820ea1739f458 100644
--- a/mysql-test/include/show_binlog_events.inc
+++ b/mysql-test/include/show_binlog_events.inc
@@ -1,10 +1,35 @@
 # $binlog_start can be set by caller or take a default value
+# $binary_log_file the name of the log file show
+# $binary_log_limit_row - sets the number of binlog rows to be returned
+# $binary_log_limit_offset - sets the offset where to start returning events
+
+let $show_binlog_events= show binlog events;
 
 if (!$binlog_start)
 {
-  let $binlog_start=106;
+  # defaults to chop the first event in the binary log
+  let $binlog_start=107;
 }
+
+if (!`SELECT '$binary_log_file' = ''`)
+{
+    let $show_binlog_events= $show_binlog_events in '$binary_log_file';
+}
+let $show_binlog_events= $show_binlog_events from $binlog_start;
+
+if ($binary_log_limit_row)
+{
+  let $limit= limit;
+  if ($binary_log_limit_offset)
+  {
+    let $limit= $limit $binary_log_limit_offset, ;
+  }
+
+  let $limit= $limit $binary_log_limit_row;
+  let $show_binlog_events= $show_binlog_events $limit;
+}
+
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR $binlog_start <binlog_start>
 --replace_column 2 # 4 # 5 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /file_id=[0-9]+/file_id=#/ /block_len=[0-9]+/block_len=#/
---eval show binlog events from $binlog_start
+--eval $show_binlog_events
diff --git a/mysql-test/include/show_binlog_events2.inc b/mysql-test/include/show_binlog_events2.inc
index 5dd272c562d1ed30c3e86759e44b29f69d0d4083..0e1a889baccd5c137b5cac94a482bd114fb4b3de 100644
--- a/mysql-test/include/show_binlog_events2.inc
+++ b/mysql-test/include/show_binlog_events2.inc
@@ -1,4 +1,4 @@
---let $binlog_start=106
+--let $binlog_start=107
 --replace_result $binlog_start <binlog_start>
 --replace_column 2 # 5 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
diff --git a/mysql-test/include/show_relaylog_events.inc b/mysql-test/include/show_relaylog_events.inc
new file mode 100644
index 0000000000000000000000000000000000000000..6f63b055d5838d4768e782f423f8c01edd2dca35
--- /dev/null
+++ b/mysql-test/include/show_relaylog_events.inc
@@ -0,0 +1,35 @@
+# $binlog_start can be set by caller or take a default value
+# $binary_log_file the name of the log file show
+# $binary_log_limit_row - sets the number of binlog rows to be returned
+# $binary_log_limit_offset - sets the offset where to start returning events
+
+let $show_binlog_events= show relaylog events;
+
+if (!$binlog_start)
+{
+  # defaults to chop the first event in the binary log
+  let $binlog_start=106;
+}
+
+if (!`SELECT '$binary_log_file' = ''`)
+{
+    let $show_binlog_events= $show_binlog_events in '$binary_log_file';
+}
+let $show_binlog_events= $show_binlog_events from $binlog_start;
+
+if ($binary_log_limit_row)
+{
+  let $limit= limit;
+  if ($binary_log_limit_offset)
+  {
+    let $limit= $limit $binary_log_limit_offset, ;
+  }
+
+  let $limit= $limit $binary_log_limit_row;
+  let $show_binlog_events= $show_binlog_events $limit;
+}
+
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR $binlog_start <binlog_start>
+--replace_column 2 # 4 # 5 #
+--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /file_id=[0-9]+/file_id=#/ /block_len=[0-9]+/block_len=#/ /Server ver:.*$/SERVER_VERSION, BINLOG_VERSION/
+--eval $show_binlog_events
diff --git a/mysql-test/include/test_fieldsize.inc b/mysql-test/include/test_fieldsize.inc
index cbe63e2631812ad3923d7b92114b998e2cb1d7f9..606bc63779d1eaf8bca9836ce101ea168904f8c4 100644
--- a/mysql-test/include/test_fieldsize.inc
+++ b/mysql-test/include/test_fieldsize.inc
@@ -22,7 +22,7 @@ eval $test_insert;
 
 connection slave;
 START SLAVE;
-wait_for_slave_to_stop;
+--source include/wait_for_slave_sql_to_stop.inc
 --replace_result $MASTER_MYPORT MASTER_PORT
 --replace_column 1 # 4 # 7 # 8 # 9 # 16 # 22 # 23 # 33 # 35 # 36 #
 --query_vertical SHOW SLAVE STATUS
diff --git a/mysql-test/include/wait_until_disconnected.inc b/mysql-test/include/wait_until_disconnected.inc
index a4362e52d01958ce5513bfcac6d4d6894a1a7f77..8a989becc1819c7c1bb67a1eb47f1b84d6e66a1b 100644
--- a/mysql-test/include/wait_until_disconnected.inc
+++ b/mysql-test/include/wait_until_disconnected.inc
@@ -7,7 +7,7 @@ let $counter= 500;
 let $mysql_errno= 0;
 while (!$mysql_errno)
 {
-  --error 0,1053,2002,2006,2013
+  --error 0,1040,1053,2002,2003,2006,2013
   show status;
 
   dec $counter;
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index ec41403abd0cd7db68edba772f418c70b5c37fab..c92e80ae6913d77945fadfb5699acb995801c05c 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -1830,6 +1830,30 @@ sub environment_setup {
     $ENV{'EXAMPLE_PLUGIN_LOAD'}= "";
   }
 
+  # --------------------------------------------------------------------------
+  # Add the path where mysqld will find semisync plugins
+  # --------------------------------------------------------------------------
+  my $lib_semisync_master_plugin=
+      mtr_file_exists(vs_config_dirs('plugin/semisync',"libsemisync_master.so"),
+		      "$basedir/plugin/semisync/.libs/libsemisync_master.so",
+                      "$basedir/lib/mysql/plugin/libsemisync_master.so");
+  my $lib_semisync_slave_plugin=
+      mtr_file_exists(vs_config_dirs('plugin/semisync',"libsemisync_slave.so"),
+		      "$basedir/plugin/semisync/.libs/libsemisync_slave.so",
+                      "$basedir/lib/mysql/plugin/libsemisync_slave.so");
+  if ($lib_semisync_master_plugin && $lib_semisync_slave_plugin)
+  {
+    $ENV{'SEMISYNC_MASTER_PLUGIN'}= basename($lib_semisync_master_plugin);
+    $ENV{'SEMISYNC_SLAVE_PLUGIN'}= basename($lib_semisync_slave_plugin);
+    $ENV{'SEMISYNC_PLUGIN_OPT'}= "--plugin-dir=".dirname($lib_semisync_master_plugin);
+  }
+  else
+  {
+    $ENV{'SEMISYNC_MASTER_PLUGIN'}= "";
+    $ENV{'SEMISYNC_SLAVE_PLUGIN'}= "";
+    $ENV{'SEMISYNC_PLUGIN_OPT'}="--plugin-dir=";
+  }
+
   # ----------------------------------------------------
   # Add the path where mysqld will find mypluglib.so
   # ----------------------------------------------------
diff --git a/mysql-test/r/ctype_cp932_binlog_stm.result b/mysql-test/r/ctype_cp932_binlog_stm.result
index 044885d1ea7d307f9692fef4cd528a811ea5e57d..bb971e5453be85ed3257577cd31837f453d65ba2 100644
--- a/mysql-test/r/ctype_cp932_binlog_stm.result
+++ b/mysql-test/r/ctype_cp932_binlog_stm.result
@@ -29,22 +29,22 @@ HEX(s1)	HEX(s2)	d
 466F6F2773206120426172	ED40ED41ED42	47.93
 DROP PROCEDURE bug18293|
 DROP TABLE t4|
-SHOW BINLOG EVENTS FROM 370|
+SHOW BINLOG EVENTS FROM 371|
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	370	Query	1	536	use `test`; CREATE TABLE t4 (s1 CHAR(50) CHARACTER SET latin1,
+master-bin.000001	371	Query	1	537	use `test`; CREATE TABLE t4 (s1 CHAR(50) CHARACTER SET latin1,
 s2 CHAR(50) CHARACTER SET cp932,
 d DECIMAL(10,2))
-master-bin.000001	536	Query	1	785	use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `bug18293`(IN ins1 CHAR(50),
+master-bin.000001	537	Query	1	786	use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `bug18293`(IN ins1 CHAR(50),
 IN ins2 CHAR(50) CHARACTER SET cp932,
 IN ind DECIMAL(10,2))
 BEGIN
 INSERT INTO t4 VALUES (ins1, ins2, ind);
 END
-master-bin.000001	785	Query	1	1049	use `test`; INSERT INTO t4 VALUES ( NAME_CONST('ins1',_latin1 0x466F6F2773206120426172 COLLATE 'latin1_swedish_ci'),  NAME_CONST('ins2',_cp932 0xED40ED41ED42 COLLATE 'cp932_japanese_ci'),  NAME_CONST('ind',47.93))
-master-bin.000001	1049	Query	1	1138	use `test`; DROP PROCEDURE bug18293
-master-bin.000001	1138	Query	1	1217	use `test`; DROP TABLE t4
+master-bin.000001	786	Query	1	1050	use `test`; INSERT INTO t4 VALUES ( NAME_CONST('ins1',_latin1 0x466F6F2773206120426172 COLLATE 'latin1_swedish_ci'),  NAME_CONST('ins2',_cp932 0xED40ED41ED42 COLLATE 'cp932_japanese_ci'),  NAME_CONST('ind',47.93))
+master-bin.000001	1050	Query	1	1139	use `test`; DROP PROCEDURE bug18293
+master-bin.000001	1139	Query	1	1218	use `test`; DROP TABLE t4
 End of 5.0 tests
-SHOW BINLOG EVENTS FROM 365;
+SHOW BINLOG EVENTS FROM 366;
 ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
 Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment.
 CREATE TABLE t1 (a varchar(16)) character set cp932;
diff --git a/mysql-test/r/events_bugs.result b/mysql-test/r/events_bugs.result
index 6d4d7a7e11b2f712678dfaa1533947ad3333dcae..6b4263eb02e8d379ce9a823daebfea3a1fe264dc 100644
--- a/mysql-test/r/events_bugs.result
+++ b/mysql-test/r/events_bugs.result
@@ -375,7 +375,7 @@ SELECT event_name, definer FROM INFORMATION_SCHEMA.EVENTS;
 event_name	definer
 e1	mysqltest_u1@localhost
 ALTER DEFINER=root@localhost EVENT e1 ON SCHEDULE EVERY 1 HOUR;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 SELECT event_name, definer FROM INFORMATION_SCHEMA.EVENTS;
 event_name	definer
 e1	mysqltest_u1@localhost
@@ -386,7 +386,7 @@ event_name	definer
 e1	mysqltest_u1@localhost
 DROP EVENT e1;
 CREATE DEFINER=root@localhost EVENT e1 ON SCHEDULE EVERY 1 DAY DO SELECT 1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 DROP EVENT e1;
 ERROR HY000: Unknown event 'e1'
 DROP USER mysqltest_u1@localhost;
diff --git a/mysql-test/r/flush_block_commit_notembedded.result b/mysql-test/r/flush_block_commit_notembedded.result
index c7fd7a118770139e96b975ff29b7007e510bac34..4348dbd67e55e51bc68cb98716b584af02ec41ad 100644
--- a/mysql-test/r/flush_block_commit_notembedded.result
+++ b/mysql-test/r/flush_block_commit_notembedded.result
@@ -9,13 +9,13 @@ INSERT t1 VALUES (1);
 FLUSH TABLES WITH READ LOCK;
 SHOW MASTER STATUS;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	106		
+master-bin.000001	107		
 # Switch to connection con1
 COMMIT;
 # Switch to connection con2
 SHOW MASTER STATUS;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	106		
+master-bin.000001	107		
 UNLOCK TABLES;
 # Switch to connection con1
 DROP TABLE t1;
diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result
index 7c2023127f08afbe456bec88f8f9591f51675385..461ad78bbb6a0ae24caebc31fff6e2fc6d4cc1dc 100644
--- a/mysql-test/r/grant2.result
+++ b/mysql-test/r/grant2.result
@@ -121,9 +121,9 @@ mysqltest_5@host5, mysqltest_6@host6, mysqltest_7@host7;
 create database mysqltest_1;
 grant select, insert, update on `mysqltest\_1`.* to mysqltest_1@localhost;
 set sql_log_off = 1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 set sql_log_bin = 0;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 delete from mysql.user where user like 'mysqltest\_1';
 delete from mysql.db where user like 'mysqltest\_1';
 drop database mysqltest_1;
diff --git a/mysql-test/r/information_schema_db.result b/mysql-test/r/information_schema_db.result
index 5fa38f93993151b61aec1909e5bd25f2a62880de..34a413afc1b4d57303558d3ce24549c6dfe4650b 100644
--- a/mysql-test/r/information_schema_db.result
+++ b/mysql-test/r/information_schema_db.result
@@ -121,7 +121,7 @@ grant insert on v1 to testdb_2@localhost;
 create view v5 as select f1 from t1;
 grant show view on v5 to testdb_2@localhost;
 create definer=`no_such_user`@`no_such_host` view v6 as select f1 from t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 use testdb_1;
 create view v6 as select f1 from t1;
 grant show view on v6 to testdb_2@localhost;
diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result
index 449333a4ae6a83b859bff93b041372d0b1226c8d..4f22029814c7da531b8f138e8627789339c0964f 100644
--- a/mysql-test/r/multi_update.result
+++ b/mysql-test/r/multi_update.result
@@ -604,7 +604,7 @@ a	b
 4	4
 show master status /* there must be the UPDATE query event */;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	206		
+master-bin.000001	207		
 delete from t1;
 delete from t2;
 insert into t1 values (1,2),(3,4),(4,4);
@@ -614,7 +614,7 @@ UPDATE t2,t1  SET t2.a=t2.b where t2.a=t1.a;
 ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
 show master status /* there must be the UPDATE query event */;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	221		
+master-bin.000001	222		
 drop table t1, t2;
 set @@session.binlog_format= @sav_binlog_format;
 drop table if exists t1, t2, t3;
diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result
index e4889b86987317998853ebfb048e9ff02c4652ed..5c82e48faeb04885c2f72141cb8a983196bc54d3 100644
--- a/mysql-test/r/mysqldump.result
+++ b/mysql-test/r/mysqldump.result
@@ -3554,11 +3554,11 @@ use test;
 create user mysqltest_1@localhost;
 create table t1(a int, b varchar(34));
 reset master;
-mysqldump: Couldn't execute 'FLUSH /*!40101 LOCAL */ TABLES': Access denied; you need the RELOAD privilege for this operation (1227)
-mysqldump: Couldn't execute 'FLUSH /*!40101 LOCAL */ TABLES': Access denied; you need the RELOAD privilege for this operation (1227)
+mysqldump: Couldn't execute 'FLUSH /*!40101 LOCAL */ TABLES': Access denied; you need (at least one of) the RELOAD privilege(s) for this operation (1227)
+mysqldump: Couldn't execute 'FLUSH /*!40101 LOCAL */ TABLES': Access denied; you need (at least one of) the RELOAD privilege(s) for this operation (1227)
 grant RELOAD on *.* to mysqltest_1@localhost;
-mysqldump: Couldn't execute 'SHOW MASTER STATUS': Access denied; you need the SUPER,REPLICATION CLIENT privilege for this operation (1227)
-mysqldump: Couldn't execute 'SHOW MASTER STATUS': Access denied; you need the SUPER,REPLICATION CLIENT privilege for this operation (1227)
+mysqldump: Couldn't execute 'SHOW MASTER STATUS': Access denied; you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation (1227)
+mysqldump: Couldn't execute 'SHOW MASTER STATUS': Access denied; you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation (1227)
 grant REPLICATION CLIENT on *.* to mysqltest_1@localhost;
 drop table t1;
 drop user mysqltest_1@localhost;
diff --git a/mysql-test/r/outfile_loaddata.result b/mysql-test/r/outfile_loaddata.result
index 453e3adb54c9d5b51a3ca3ef297f2cd137e8c1e4..66ff28298ba247d95218fb7479ebbc77521a62f9 100644
--- a/mysql-test/r/outfile_loaddata.result
+++ b/mysql-test/r/outfile_loaddata.result
@@ -92,14 +92,14 @@ HEX(c1)
 C3
 SELECT * INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/bug32533.txt' FIELDS ENCLOSED BY 0xC3 FROM t1;
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 TRUNCATE t1;
 SELECT HEX(LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug32533.txt'));
 HEX(LOAD_FILE('MYSQLTEST_VARDIR/tmp/bug32533.txt'))
 C35CC3C30A
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/bug32533.txt' INTO TABLE t1 FIELDS ENCLOSED BY 0xC3;
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 SELECT HEX(c1) FROM t1;
 HEX(c1)
 C3
@@ -124,17 +124,17 @@ ERROR 42000: Field separator argument is not what is expected; check the manual
 # LOAD DATA rises error or has unpredictable result -- to be fixed later
 SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS ENCLOSED BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary FIELDS ENCLOSED BY 'ÑŠ';
 ERROR 42000: Field separator argument is not what is expected; check the manual
 SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS ESCAPED BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary FIELDS ESCAPED BY 'ÑŠ';
 ERROR 42000: Field separator argument is not what is expected; check the manual
 SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' FIELDS TERMINATED BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 ##################################################
 1ÑŠABC-áâ÷ÑŠDEF-ÂÃÄ
 2ÑŠ\NÑŠ\N
@@ -142,7 +142,7 @@ Warning	1638	Non-ASCII separator arguments are not fully supported
 TRUNCATE t2;
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary FIELDS TERMINATED BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 Warning	1265	Data truncated for column 'a' at row 1
 Warning	1261	Row 1 doesn't contain data for all columns
 Warning	1261	Row 1 doesn't contain data for all columns
@@ -156,7 +156,7 @@ a	b	c
 2	NULL	NULL
 SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' LINES STARTING BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 ##################################################
 ÑŠ1	ABC-áâ÷	DEF-ÂÃÄ
 ÑŠ2	\N	\N
@@ -164,20 +164,20 @@ Warning	1638	Non-ASCII separator arguments are not fully supported
 TRUNCATE t2;
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary LINES STARTING BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
 a	b	c
 1	ABC-АБВ	DEF-ÂÃÄ
 2	NULL	NULL
 SELECT * FROM t1 INTO OUTFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' LINES TERMINATED BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 ##################################################
 1	ABC-áâ÷	DEF-ÂÃÄÑŠ2	\N	\NÑŠ##################################################
 TRUNCATE t2;
 LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t2 CHARACTER SET binary LINES TERMINATED BY 'ÑŠ';
 Warnings:
-Warning	1638	Non-ASCII separator arguments are not fully supported
+Warning	1639	Non-ASCII separator arguments are not fully supported
 SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a, b, c;
 a	b	c
 1	ABC-АБВ	DEF-ÂÃÄ
diff --git a/mysql-test/r/sp-security.result b/mysql-test/r/sp-security.result
index 65c94577a5709358f7bb216c474653a49acf1d97..ecac8fed8c4022f7eabd7e7916268ebfb63efe88 100644
--- a/mysql-test/r/sp-security.result
+++ b/mysql-test/r/sp-security.result
@@ -349,9 +349,9 @@ CREATE FUNCTION wl2897_f1() RETURNS INT RETURN 1;
 ---> connection: mysqltest_1_con
 USE mysqltest;
 CREATE DEFINER=root@localhost PROCEDURE wl2897_p2() SELECT 2;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 CREATE DEFINER=root@localhost FUNCTION wl2897_f2() RETURNS INT RETURN 2;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 
 ---> connection: mysqltest_2_con
 use mysqltest;
diff --git a/mysql-test/r/sp_trans_log.result b/mysql-test/r/sp_trans_log.result
index 7a6173b89e25f6225b208c8f810582a342d25414..117f6de754a3bcb1aa563e7fd5c0f934d8fe28dd 100644
--- a/mysql-test/r/sp_trans_log.result
+++ b/mysql-test/r/sp_trans_log.result
@@ -14,15 +14,5 @@ end|
 reset master|
 insert into t2 values (bug23333(),1)|
 ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
-show binlog events from 106 /* with fixes for #23333 will show there is the query */|
-Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	#	Query	1	#	#
-master-bin.000001	#	Table_map	1	#	#
-master-bin.000001	#	Table_map	1	#	#
-master-bin.000001	#	Write_rows	1	#	#
-master-bin.000001	#	Query	1	#	#
-select count(*),@a from t1 /* must be 1,1 */|
-count(*)	@a
-1	1
 drop table t1,t2;
 drop function if exists bug23333;
diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result
index a9e0d7f457d3d7d9cadccdea0fbff5f407689bd7..b427340d250cb61771da175c090e325af12fe510 100644
--- a/mysql-test/r/strict.result
+++ b/mysql-test/r/strict.result
@@ -1327,7 +1327,7 @@ create table t1
   123456789*123456789*123456789*123456789*
   123456789*123456789*123456789*123456789*');
 Warnings:
-Warning	1629	Comment for field 'i' is too long (max = 255)
+Warning	1630	Comment for field 'i' is too long (max = 255)
 select column_name, column_comment from information_schema.columns where
 table_schema = 'test' and table_name = 't1';
 column_name	column_comment
diff --git a/mysql-test/r/trigger_notembedded.result b/mysql-test/r/trigger_notembedded.result
index d66308a9bd75645433870f7649d1562f43df819e..4673ac26f73b896b66a2d63f0c63573d9374a26a 100644
--- a/mysql-test/r/trigger_notembedded.result
+++ b/mysql-test/r/trigger_notembedded.result
@@ -117,7 +117,7 @@ CREATE DEFINER='mysqltest_inv'@'localhost'
   TRIGGER trg1 BEFORE INSERT ON t1
 FOR EACH ROW
 SET @new_sum = 0;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 
 ---> connection: default
 use mysqltest_db1;
@@ -471,7 +471,7 @@ SELECT trigger_name FROM INFORMATION_SCHEMA.TRIGGERS
 WHERE trigger_schema = 'db1';
 trigger_name
 SHOW CREATE TRIGGER db1.trg;
-ERROR 42000: Access denied; you need the TRIGGER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the TRIGGER privilege(s) for this operation
 DROP USER 'no_rights'@'localhost';
 DROP DATABASE db1;
 End of 5.1 tests.
diff --git a/mysql-test/r/view_grant.result b/mysql-test/r/view_grant.result
index 4e43f52d8d724d13e4d69d46892ae0e391090fa4..a9d4164cda43b59a9a996b0d96d19267b6b961e4 100644
--- a/mysql-test/r/view_grant.result
+++ b/mysql-test/r/view_grant.result
@@ -16,7 +16,7 @@ create table mysqltest.t2 (a int, b int);
 grant select on mysqltest.t1 to mysqltest_1@localhost;
 grant create view,select on test.* to mysqltest_1@localhost;
 create definer=root@localhost view v1 as select * from mysqltest.t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 create view v1 as select * from mysqltest.t1;
 alter view v1 as select * from mysqltest.t1;
 ERROR 42000: DROP command denied to user 'mysqltest_1'@'localhost' for table 'v1'
@@ -779,11 +779,11 @@ GRANT CREATE VIEW ON db26813.v2 TO u26813@localhost;
 GRANT DROP, CREATE VIEW ON db26813.v3 TO u26813@localhost;
 GRANT SELECT ON db26813.t1 TO u26813@localhost;
 ALTER VIEW v1 AS SELECT f2 FROM t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 ALTER VIEW v2 AS SELECT f2 FROM t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 ALTER VIEW v3 AS SELECT f2 FROM t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 SHOW CREATE VIEW v3;
 View	Create View	character_set_client	collation_connection
 v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`f1` AS `f1` from `t1`	latin1	latin1_swedish_ci
@@ -807,9 +807,9 @@ GRANT DROP, CREATE VIEW ON mysqltest_29908.v1 TO u29908_2@localhost;
 GRANT DROP, CREATE VIEW, SHOW VIEW ON mysqltest_29908.v2 TO u29908_2@localhost;
 GRANT SELECT ON mysqltest_29908.t1 TO u29908_2@localhost;
 ALTER VIEW v1 AS SELECT f2 FROM t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 ALTER VIEW v2 AS SELECT f2 FROM t1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 SHOW CREATE VIEW v2;
 View	Create View	character_set_client	collation_connection
 v2	CREATE ALGORITHM=UNDEFINED DEFINER=`u29908_1`@`localhost` SQL SECURITY INVOKER VIEW `v2` AS select `t1`.`f1` AS `f1` from `t1`	latin1	latin1_swedish_ci
diff --git a/mysql-test/suite/binlog/r/binlog_grant.result b/mysql-test/suite/binlog/r/binlog_grant.result
index 21ebb8911034598cc10556d6b190e8aa1a789706..548013fcbf24d15a4747ecf8e59586a2f1bce192 100644
--- a/mysql-test/suite/binlog/r/binlog_grant.result
+++ b/mysql-test/suite/binlog/r/binlog_grant.result
@@ -13,16 +13,16 @@ set session sql_log_bin = 1;
 set global sql_log_bin = 1;
 ERROR HY000: Variable 'sql_log_bin' is a SESSION variable and can't be used with SET GLOBAL
 set session sql_log_bin = 1;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 **** Variable BINLOG_FORMAT ****
 [root]
 set global binlog_format = row;
 set session binlog_format = row;
 [plain]
 set global binlog_format = row;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 set session binlog_format = row;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 **** Clean up ****
 set global binlog_format = @saved_binlog_format;
 drop user mysqltest_1@localhost;
diff --git a/mysql-test/suite/binlog/r/binlog_implicit_commit.result b/mysql-test/suite/binlog/r/binlog_implicit_commit.result
new file mode 100644
index 0000000000000000000000000000000000000000..ea43b31bde93eb4af977b24769fb47ed700a2d52
--- /dev/null
+++ b/mysql-test/suite/binlog/r/binlog_implicit_commit.result
@@ -0,0 +1,345 @@
+CREATE TABLE t1 (id INT) ENGINE = InnoDB;
+SET BINLOG_FORMAT = STATEMENT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+SET BINLOG_FORMAT = ROW;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 1;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 1;
+BEGIN;
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+SET AUTOCOMMIT = 0;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+INSERT INTO t1 VALUES (3);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+INSERT INTO t1 VALUES (1);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+LOCK TABLES t1 WRITE;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+INSERT INTO t1 VALUES (2);
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+UNLOCK TABLES;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+COMMIT;
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+DROP TABLE t1;
diff --git a/mysql-test/suite/binlog/r/binlog_innodb.result b/mysql-test/suite/binlog/r/binlog_innodb.result
index 1922897f631d9be3eef3a06d86599cdd7878915e..424f7d60829bc85174dee7a67a84cfe071d6cd4a 100644
--- a/mysql-test/suite/binlog/r/binlog_innodb.result
+++ b/mysql-test/suite/binlog/r/binlog_innodb.result
@@ -156,9 +156,10 @@ select * from t2 /* must be (3,1), (4,4) */;
 a	b
 1	1
 4	4
-show master status /* there must no UPDATE in binlog */;
+there must no UPDATE in binlog
+show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	106		
+master-bin.000001	#	<Binlog_Do_DB>	<Binlog_Ignore_DB>
 delete from t1;
 delete from t2;
 insert into t1 values (1,2),(3,4),(4,4);
@@ -166,8 +167,9 @@ insert into t2 values (1,2),(3,4),(4,4);
 reset master;
 UPDATE t2,t1  SET t2.a=t2.b where t2.a=t1.a;
 ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
-show master status /* there must be no UPDATE query event */;
+there must no UPDATE in binlog
+show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	106		
+master-bin.000001	#	<Binlog_Do_DB>	<Binlog_Ignore_DB>
 drop table t1, t2;
 End of tests
diff --git a/mysql-test/suite/binlog/r/binlog_row_binlog.result b/mysql-test/suite/binlog/r/binlog_row_binlog.result
index 4d32a4f47397936638da8e4258bbb90778fc3402..7dc37d7c365db59e13adba01b8ab2942dc890b05 100644
--- a/mysql-test/suite/binlog/r/binlog_row_binlog.result
+++ b/mysql-test/suite/binlog/r/binlog_row_binlog.result
@@ -26,7 +26,7 @@ create table t1 (n int) engine=innodb;
 begin;
 commit;
 drop table t1;
-show binlog events in 'master-bin.000001' from 106;
+show binlog events in 'master-bin.000001' from 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1 (n int) engine=innodb
 master-bin.000001	#	Query	1	#	BEGIN
@@ -232,7 +232,7 @@ master-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	1	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Xid	1	#	COMMIT /* xid= */
 master-bin.000001	#	Rotate	1	#	master-bin.000002;pos=4
-show binlog events in 'master-bin.000002' from 106;
+show binlog events in 'master-bin.000002' from 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000002	#	Query	1	#	use `test`; drop table t1
 set @ac = @@autocommit;
@@ -247,25 +247,8 @@ commit;
 drop table t1;
 show binlog events from 0;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server version, Binlog ver: 4
-master-bin.000001	106	Query	1	205	use `test`; create table t1(n int) engine=innodb
-master-bin.000001	205	Query	1	273	BEGIN
-master-bin.000001	273	Table_map	1	314	table_id: # (test.t1)
-master-bin.000001	314	Write_rows	1	348	table_id: # flags: STMT_END_F
-master-bin.000001	348	Table_map	1	389	table_id: # (test.t1)
-master-bin.000001	389	Write_rows	1	423	table_id: # flags: STMT_END_F
-master-bin.000001	423	Table_map	1	464	table_id: # (test.t1)
-master-bin.000001	464	Write_rows	1	498	table_id: # flags: STMT_END_F
-master-bin.000001	498	Xid	1	525	COMMIT /* XID */
-master-bin.000001	525	Query	1	601	use `test`; drop table t1
-set @bcs = @@binlog_cache_size;
-set global binlog_cache_size=4096;
-reset master;
-create table t1 (a int) engine=innodb;
-show binlog events from 0;
-Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server version, Binlog ver: 4
-master-bin.000001	106	Query	1	206	use `test`; create table t1 (a int) engine=innodb
+master-bin.000001	4	Format_desc	1	107	Server version, Binlog ver: 4
+master-bin.000001	107	Query	1	206	use `test`; create table t1(n int) engine=innodb
 master-bin.000001	206	Query	1	274	BEGIN
 master-bin.000001	274	Table_map	1	315	table_id: # (test.t1)
 master-bin.000001	315	Write_rows	1	349	table_id: # flags: STMT_END_F
@@ -273,802 +256,819 @@ master-bin.000001	349	Table_map	1	390	table_id: # (test.t1)
 master-bin.000001	390	Write_rows	1	424	table_id: # flags: STMT_END_F
 master-bin.000001	424	Table_map	1	465	table_id: # (test.t1)
 master-bin.000001	465	Write_rows	1	499	table_id: # flags: STMT_END_F
-master-bin.000001	499	Table_map	1	540	table_id: # (test.t1)
-master-bin.000001	540	Write_rows	1	574	table_id: # flags: STMT_END_F
-master-bin.000001	574	Table_map	1	615	table_id: # (test.t1)
-master-bin.000001	615	Write_rows	1	649	table_id: # flags: STMT_END_F
-master-bin.000001	649	Table_map	1	690	table_id: # (test.t1)
-master-bin.000001	690	Write_rows	1	724	table_id: # flags: STMT_END_F
-master-bin.000001	724	Table_map	1	765	table_id: # (test.t1)
-master-bin.000001	765	Write_rows	1	799	table_id: # flags: STMT_END_F
-master-bin.000001	799	Table_map	1	840	table_id: # (test.t1)
-master-bin.000001	840	Write_rows	1	874	table_id: # flags: STMT_END_F
-master-bin.000001	874	Table_map	1	915	table_id: # (test.t1)
-master-bin.000001	915	Write_rows	1	949	table_id: # flags: STMT_END_F
-master-bin.000001	949	Table_map	1	990	table_id: # (test.t1)
-master-bin.000001	990	Write_rows	1	1024	table_id: # flags: STMT_END_F
-master-bin.000001	1024	Table_map	1	1065	table_id: # (test.t1)
-master-bin.000001	1065	Write_rows	1	1099	table_id: # flags: STMT_END_F
-master-bin.000001	1099	Table_map	1	1140	table_id: # (test.t1)
-master-bin.000001	1140	Write_rows	1	1174	table_id: # flags: STMT_END_F
-master-bin.000001	1174	Table_map	1	1215	table_id: # (test.t1)
-master-bin.000001	1215	Write_rows	1	1249	table_id: # flags: STMT_END_F
-master-bin.000001	1249	Table_map	1	1290	table_id: # (test.t1)
-master-bin.000001	1290	Write_rows	1	1324	table_id: # flags: STMT_END_F
-master-bin.000001	1324	Table_map	1	1365	table_id: # (test.t1)
-master-bin.000001	1365	Write_rows	1	1399	table_id: # flags: STMT_END_F
-master-bin.000001	1399	Table_map	1	1440	table_id: # (test.t1)
-master-bin.000001	1440	Write_rows	1	1474	table_id: # flags: STMT_END_F
-master-bin.000001	1474	Table_map	1	1515	table_id: # (test.t1)
-master-bin.000001	1515	Write_rows	1	1549	table_id: # flags: STMT_END_F
-master-bin.000001	1549	Table_map	1	1590	table_id: # (test.t1)
-master-bin.000001	1590	Write_rows	1	1624	table_id: # flags: STMT_END_F
-master-bin.000001	1624	Table_map	1	1665	table_id: # (test.t1)
-master-bin.000001	1665	Write_rows	1	1699	table_id: # flags: STMT_END_F
-master-bin.000001	1699	Table_map	1	1740	table_id: # (test.t1)
-master-bin.000001	1740	Write_rows	1	1774	table_id: # flags: STMT_END_F
-master-bin.000001	1774	Table_map	1	1815	table_id: # (test.t1)
-master-bin.000001	1815	Write_rows	1	1849	table_id: # flags: STMT_END_F
-master-bin.000001	1849	Table_map	1	1890	table_id: # (test.t1)
-master-bin.000001	1890	Write_rows	1	1924	table_id: # flags: STMT_END_F
-master-bin.000001	1924	Table_map	1	1965	table_id: # (test.t1)
-master-bin.000001	1965	Write_rows	1	1999	table_id: # flags: STMT_END_F
-master-bin.000001	1999	Table_map	1	2040	table_id: # (test.t1)
-master-bin.000001	2040	Write_rows	1	2074	table_id: # flags: STMT_END_F
-master-bin.000001	2074	Table_map	1	2115	table_id: # (test.t1)
-master-bin.000001	2115	Write_rows	1	2149	table_id: # flags: STMT_END_F
-master-bin.000001	2149	Table_map	1	2190	table_id: # (test.t1)
-master-bin.000001	2190	Write_rows	1	2224	table_id: # flags: STMT_END_F
-master-bin.000001	2224	Table_map	1	2265	table_id: # (test.t1)
-master-bin.000001	2265	Write_rows	1	2299	table_id: # flags: STMT_END_F
-master-bin.000001	2299	Table_map	1	2340	table_id: # (test.t1)
-master-bin.000001	2340	Write_rows	1	2374	table_id: # flags: STMT_END_F
-master-bin.000001	2374	Table_map	1	2415	table_id: # (test.t1)
-master-bin.000001	2415	Write_rows	1	2449	table_id: # flags: STMT_END_F
-master-bin.000001	2449	Table_map	1	2490	table_id: # (test.t1)
-master-bin.000001	2490	Write_rows	1	2524	table_id: # flags: STMT_END_F
-master-bin.000001	2524	Table_map	1	2565	table_id: # (test.t1)
-master-bin.000001	2565	Write_rows	1	2599	table_id: # flags: STMT_END_F
-master-bin.000001	2599	Table_map	1	2640	table_id: # (test.t1)
-master-bin.000001	2640	Write_rows	1	2674	table_id: # flags: STMT_END_F
-master-bin.000001	2674	Table_map	1	2715	table_id: # (test.t1)
-master-bin.000001	2715	Write_rows	1	2749	table_id: # flags: STMT_END_F
-master-bin.000001	2749	Table_map	1	2790	table_id: # (test.t1)
-master-bin.000001	2790	Write_rows	1	2824	table_id: # flags: STMT_END_F
-master-bin.000001	2824	Table_map	1	2865	table_id: # (test.t1)
-master-bin.000001	2865	Write_rows	1	2899	table_id: # flags: STMT_END_F
-master-bin.000001	2899	Table_map	1	2940	table_id: # (test.t1)
-master-bin.000001	2940	Write_rows	1	2974	table_id: # flags: STMT_END_F
-master-bin.000001	2974	Table_map	1	3015	table_id: # (test.t1)
-master-bin.000001	3015	Write_rows	1	3049	table_id: # flags: STMT_END_F
-master-bin.000001	3049	Table_map	1	3090	table_id: # (test.t1)
-master-bin.000001	3090	Write_rows	1	3124	table_id: # flags: STMT_END_F
-master-bin.000001	3124	Table_map	1	3165	table_id: # (test.t1)
-master-bin.000001	3165	Write_rows	1	3199	table_id: # flags: STMT_END_F
-master-bin.000001	3199	Table_map	1	3240	table_id: # (test.t1)
-master-bin.000001	3240	Write_rows	1	3274	table_id: # flags: STMT_END_F
-master-bin.000001	3274	Table_map	1	3315	table_id: # (test.t1)
-master-bin.000001	3315	Write_rows	1	3349	table_id: # flags: STMT_END_F
-master-bin.000001	3349	Table_map	1	3390	table_id: # (test.t1)
-master-bin.000001	3390	Write_rows	1	3424	table_id: # flags: STMT_END_F
-master-bin.000001	3424	Table_map	1	3465	table_id: # (test.t1)
-master-bin.000001	3465	Write_rows	1	3499	table_id: # flags: STMT_END_F
-master-bin.000001	3499	Table_map	1	3540	table_id: # (test.t1)
-master-bin.000001	3540	Write_rows	1	3574	table_id: # flags: STMT_END_F
-master-bin.000001	3574	Table_map	1	3615	table_id: # (test.t1)
-master-bin.000001	3615	Write_rows	1	3649	table_id: # flags: STMT_END_F
-master-bin.000001	3649	Table_map	1	3690	table_id: # (test.t1)
-master-bin.000001	3690	Write_rows	1	3724	table_id: # flags: STMT_END_F
-master-bin.000001	3724	Table_map	1	3765	table_id: # (test.t1)
-master-bin.000001	3765	Write_rows	1	3799	table_id: # flags: STMT_END_F
-master-bin.000001	3799	Table_map	1	3840	table_id: # (test.t1)
-master-bin.000001	3840	Write_rows	1	3874	table_id: # flags: STMT_END_F
-master-bin.000001	3874	Table_map	1	3915	table_id: # (test.t1)
-master-bin.000001	3915	Write_rows	1	3949	table_id: # flags: STMT_END_F
-master-bin.000001	3949	Table_map	1	3990	table_id: # (test.t1)
-master-bin.000001	3990	Write_rows	1	4024	table_id: # flags: STMT_END_F
-master-bin.000001	4024	Table_map	1	4065	table_id: # (test.t1)
-master-bin.000001	4065	Write_rows	1	4099	table_id: # flags: STMT_END_F
-master-bin.000001	4099	Table_map	1	4140	table_id: # (test.t1)
-master-bin.000001	4140	Write_rows	1	4174	table_id: # flags: STMT_END_F
-master-bin.000001	4174	Table_map	1	4215	table_id: # (test.t1)
-master-bin.000001	4215	Write_rows	1	4249	table_id: # flags: STMT_END_F
-master-bin.000001	4249	Table_map	1	4290	table_id: # (test.t1)
-master-bin.000001	4290	Write_rows	1	4324	table_id: # flags: STMT_END_F
-master-bin.000001	4324	Table_map	1	4365	table_id: # (test.t1)
-master-bin.000001	4365	Write_rows	1	4399	table_id: # flags: STMT_END_F
-master-bin.000001	4399	Table_map	1	4440	table_id: # (test.t1)
-master-bin.000001	4440	Write_rows	1	4474	table_id: # flags: STMT_END_F
-master-bin.000001	4474	Table_map	1	4515	table_id: # (test.t1)
-master-bin.000001	4515	Write_rows	1	4549	table_id: # flags: STMT_END_F
-master-bin.000001	4549	Table_map	1	4590	table_id: # (test.t1)
-master-bin.000001	4590	Write_rows	1	4624	table_id: # flags: STMT_END_F
-master-bin.000001	4624	Table_map	1	4665	table_id: # (test.t1)
-master-bin.000001	4665	Write_rows	1	4699	table_id: # flags: STMT_END_F
-master-bin.000001	4699	Table_map	1	4740	table_id: # (test.t1)
-master-bin.000001	4740	Write_rows	1	4774	table_id: # flags: STMT_END_F
-master-bin.000001	4774	Table_map	1	4815	table_id: # (test.t1)
-master-bin.000001	4815	Write_rows	1	4849	table_id: # flags: STMT_END_F
-master-bin.000001	4849	Table_map	1	4890	table_id: # (test.t1)
-master-bin.000001	4890	Write_rows	1	4924	table_id: # flags: STMT_END_F
-master-bin.000001	4924	Table_map	1	4965	table_id: # (test.t1)
-master-bin.000001	4965	Write_rows	1	4999	table_id: # flags: STMT_END_F
-master-bin.000001	4999	Table_map	1	5040	table_id: # (test.t1)
-master-bin.000001	5040	Write_rows	1	5074	table_id: # flags: STMT_END_F
-master-bin.000001	5074	Table_map	1	5115	table_id: # (test.t1)
-master-bin.000001	5115	Write_rows	1	5149	table_id: # flags: STMT_END_F
-master-bin.000001	5149	Table_map	1	5190	table_id: # (test.t1)
-master-bin.000001	5190	Write_rows	1	5224	table_id: # flags: STMT_END_F
-master-bin.000001	5224	Table_map	1	5265	table_id: # (test.t1)
-master-bin.000001	5265	Write_rows	1	5299	table_id: # flags: STMT_END_F
-master-bin.000001	5299	Table_map	1	5340	table_id: # (test.t1)
-master-bin.000001	5340	Write_rows	1	5374	table_id: # flags: STMT_END_F
-master-bin.000001	5374	Table_map	1	5415	table_id: # (test.t1)
-master-bin.000001	5415	Write_rows	1	5449	table_id: # flags: STMT_END_F
-master-bin.000001	5449	Table_map	1	5490	table_id: # (test.t1)
-master-bin.000001	5490	Write_rows	1	5524	table_id: # flags: STMT_END_F
-master-bin.000001	5524	Table_map	1	5565	table_id: # (test.t1)
-master-bin.000001	5565	Write_rows	1	5599	table_id: # flags: STMT_END_F
-master-bin.000001	5599	Table_map	1	5640	table_id: # (test.t1)
-master-bin.000001	5640	Write_rows	1	5674	table_id: # flags: STMT_END_F
-master-bin.000001	5674	Table_map	1	5715	table_id: # (test.t1)
-master-bin.000001	5715	Write_rows	1	5749	table_id: # flags: STMT_END_F
-master-bin.000001	5749	Table_map	1	5790	table_id: # (test.t1)
-master-bin.000001	5790	Write_rows	1	5824	table_id: # flags: STMT_END_F
-master-bin.000001	5824	Table_map	1	5865	table_id: # (test.t1)
-master-bin.000001	5865	Write_rows	1	5899	table_id: # flags: STMT_END_F
-master-bin.000001	5899	Table_map	1	5940	table_id: # (test.t1)
-master-bin.000001	5940	Write_rows	1	5974	table_id: # flags: STMT_END_F
-master-bin.000001	5974	Table_map	1	6015	table_id: # (test.t1)
-master-bin.000001	6015	Write_rows	1	6049	table_id: # flags: STMT_END_F
-master-bin.000001	6049	Table_map	1	6090	table_id: # (test.t1)
-master-bin.000001	6090	Write_rows	1	6124	table_id: # flags: STMT_END_F
-master-bin.000001	6124	Table_map	1	6165	table_id: # (test.t1)
-master-bin.000001	6165	Write_rows	1	6199	table_id: # flags: STMT_END_F
-master-bin.000001	6199	Table_map	1	6240	table_id: # (test.t1)
-master-bin.000001	6240	Write_rows	1	6274	table_id: # flags: STMT_END_F
-master-bin.000001	6274	Table_map	1	6315	table_id: # (test.t1)
-master-bin.000001	6315	Write_rows	1	6349	table_id: # flags: STMT_END_F
-master-bin.000001	6349	Table_map	1	6390	table_id: # (test.t1)
-master-bin.000001	6390	Write_rows	1	6424	table_id: # flags: STMT_END_F
-master-bin.000001	6424	Table_map	1	6465	table_id: # (test.t1)
-master-bin.000001	6465	Write_rows	1	6499	table_id: # flags: STMT_END_F
-master-bin.000001	6499	Table_map	1	6540	table_id: # (test.t1)
-master-bin.000001	6540	Write_rows	1	6574	table_id: # flags: STMT_END_F
-master-bin.000001	6574	Table_map	1	6615	table_id: # (test.t1)
-master-bin.000001	6615	Write_rows	1	6649	table_id: # flags: STMT_END_F
-master-bin.000001	6649	Table_map	1	6690	table_id: # (test.t1)
-master-bin.000001	6690	Write_rows	1	6724	table_id: # flags: STMT_END_F
-master-bin.000001	6724	Table_map	1	6765	table_id: # (test.t1)
-master-bin.000001	6765	Write_rows	1	6799	table_id: # flags: STMT_END_F
-master-bin.000001	6799	Table_map	1	6840	table_id: # (test.t1)
-master-bin.000001	6840	Write_rows	1	6874	table_id: # flags: STMT_END_F
-master-bin.000001	6874	Table_map	1	6915	table_id: # (test.t1)
-master-bin.000001	6915	Write_rows	1	6949	table_id: # flags: STMT_END_F
-master-bin.000001	6949	Table_map	1	6990	table_id: # (test.t1)
-master-bin.000001	6990	Write_rows	1	7024	table_id: # flags: STMT_END_F
-master-bin.000001	7024	Table_map	1	7065	table_id: # (test.t1)
-master-bin.000001	7065	Write_rows	1	7099	table_id: # flags: STMT_END_F
-master-bin.000001	7099	Table_map	1	7140	table_id: # (test.t1)
-master-bin.000001	7140	Write_rows	1	7174	table_id: # flags: STMT_END_F
-master-bin.000001	7174	Table_map	1	7215	table_id: # (test.t1)
-master-bin.000001	7215	Write_rows	1	7249	table_id: # flags: STMT_END_F
-master-bin.000001	7249	Table_map	1	7290	table_id: # (test.t1)
-master-bin.000001	7290	Write_rows	1	7324	table_id: # flags: STMT_END_F
-master-bin.000001	7324	Table_map	1	7365	table_id: # (test.t1)
-master-bin.000001	7365	Write_rows	1	7399	table_id: # flags: STMT_END_F
-master-bin.000001	7399	Table_map	1	7440	table_id: # (test.t1)
-master-bin.000001	7440	Write_rows	1	7474	table_id: # flags: STMT_END_F
-master-bin.000001	7474	Table_map	1	7515	table_id: # (test.t1)
-master-bin.000001	7515	Write_rows	1	7549	table_id: # flags: STMT_END_F
-master-bin.000001	7549	Table_map	1	7590	table_id: # (test.t1)
-master-bin.000001	7590	Write_rows	1	7624	table_id: # flags: STMT_END_F
-master-bin.000001	7624	Table_map	1	7665	table_id: # (test.t1)
-master-bin.000001	7665	Write_rows	1	7699	table_id: # flags: STMT_END_F
-master-bin.000001	7699	Table_map	1	7740	table_id: # (test.t1)
-master-bin.000001	7740	Write_rows	1	7774	table_id: # flags: STMT_END_F
-master-bin.000001	7774	Table_map	1	7815	table_id: # (test.t1)
-master-bin.000001	7815	Write_rows	1	7849	table_id: # flags: STMT_END_F
-master-bin.000001	7849	Table_map	1	7890	table_id: # (test.t1)
-master-bin.000001	7890	Write_rows	1	7924	table_id: # flags: STMT_END_F
-master-bin.000001	7924	Table_map	1	7965	table_id: # (test.t1)
-master-bin.000001	7965	Write_rows	1	7999	table_id: # flags: STMT_END_F
-master-bin.000001	7999	Table_map	1	8040	table_id: # (test.t1)
-master-bin.000001	8040	Write_rows	1	8074	table_id: # flags: STMT_END_F
-master-bin.000001	8074	Table_map	1	8115	table_id: # (test.t1)
-master-bin.000001	8115	Write_rows	1	8149	table_id: # flags: STMT_END_F
-master-bin.000001	8149	Table_map	1	8190	table_id: # (test.t1)
-master-bin.000001	8190	Write_rows	1	8224	table_id: # flags: STMT_END_F
-master-bin.000001	8224	Table_map	1	8265	table_id: # (test.t1)
-master-bin.000001	8265	Write_rows	1	8299	table_id: # flags: STMT_END_F
-master-bin.000001	8299	Table_map	1	8340	table_id: # (test.t1)
-master-bin.000001	8340	Write_rows	1	8374	table_id: # flags: STMT_END_F
-master-bin.000001	8374	Table_map	1	8415	table_id: # (test.t1)
-master-bin.000001	8415	Write_rows	1	8449	table_id: # flags: STMT_END_F
-master-bin.000001	8449	Table_map	1	8490	table_id: # (test.t1)
-master-bin.000001	8490	Write_rows	1	8524	table_id: # flags: STMT_END_F
-master-bin.000001	8524	Table_map	1	8565	table_id: # (test.t1)
-master-bin.000001	8565	Write_rows	1	8599	table_id: # flags: STMT_END_F
-master-bin.000001	8599	Table_map	1	8640	table_id: # (test.t1)
-master-bin.000001	8640	Write_rows	1	8674	table_id: # flags: STMT_END_F
-master-bin.000001	8674	Table_map	1	8715	table_id: # (test.t1)
-master-bin.000001	8715	Write_rows	1	8749	table_id: # flags: STMT_END_F
-master-bin.000001	8749	Table_map	1	8790	table_id: # (test.t1)
-master-bin.000001	8790	Write_rows	1	8824	table_id: # flags: STMT_END_F
-master-bin.000001	8824	Table_map	1	8865	table_id: # (test.t1)
-master-bin.000001	8865	Write_rows	1	8899	table_id: # flags: STMT_END_F
-master-bin.000001	8899	Table_map	1	8940	table_id: # (test.t1)
-master-bin.000001	8940	Write_rows	1	8974	table_id: # flags: STMT_END_F
-master-bin.000001	8974	Table_map	1	9015	table_id: # (test.t1)
-master-bin.000001	9015	Write_rows	1	9049	table_id: # flags: STMT_END_F
-master-bin.000001	9049	Table_map	1	9090	table_id: # (test.t1)
-master-bin.000001	9090	Write_rows	1	9124	table_id: # flags: STMT_END_F
-master-bin.000001	9124	Table_map	1	9165	table_id: # (test.t1)
-master-bin.000001	9165	Write_rows	1	9199	table_id: # flags: STMT_END_F
-master-bin.000001	9199	Table_map	1	9240	table_id: # (test.t1)
-master-bin.000001	9240	Write_rows	1	9274	table_id: # flags: STMT_END_F
-master-bin.000001	9274	Table_map	1	9315	table_id: # (test.t1)
-master-bin.000001	9315	Write_rows	1	9349	table_id: # flags: STMT_END_F
-master-bin.000001	9349	Table_map	1	9390	table_id: # (test.t1)
-master-bin.000001	9390	Write_rows	1	9424	table_id: # flags: STMT_END_F
-master-bin.000001	9424	Table_map	1	9465	table_id: # (test.t1)
-master-bin.000001	9465	Write_rows	1	9499	table_id: # flags: STMT_END_F
-master-bin.000001	9499	Table_map	1	9540	table_id: # (test.t1)
-master-bin.000001	9540	Write_rows	1	9574	table_id: # flags: STMT_END_F
-master-bin.000001	9574	Table_map	1	9615	table_id: # (test.t1)
-master-bin.000001	9615	Write_rows	1	9649	table_id: # flags: STMT_END_F
-master-bin.000001	9649	Table_map	1	9690	table_id: # (test.t1)
-master-bin.000001	9690	Write_rows	1	9724	table_id: # flags: STMT_END_F
-master-bin.000001	9724	Table_map	1	9765	table_id: # (test.t1)
-master-bin.000001	9765	Write_rows	1	9799	table_id: # flags: STMT_END_F
-master-bin.000001	9799	Table_map	1	9840	table_id: # (test.t1)
-master-bin.000001	9840	Write_rows	1	9874	table_id: # flags: STMT_END_F
-master-bin.000001	9874	Table_map	1	9915	table_id: # (test.t1)
-master-bin.000001	9915	Write_rows	1	9949	table_id: # flags: STMT_END_F
-master-bin.000001	9949	Table_map	1	9990	table_id: # (test.t1)
-master-bin.000001	9990	Write_rows	1	10024	table_id: # flags: STMT_END_F
-master-bin.000001	10024	Table_map	1	10065	table_id: # (test.t1)
-master-bin.000001	10065	Write_rows	1	10099	table_id: # flags: STMT_END_F
-master-bin.000001	10099	Table_map	1	10140	table_id: # (test.t1)
-master-bin.000001	10140	Write_rows	1	10174	table_id: # flags: STMT_END_F
-master-bin.000001	10174	Table_map	1	10215	table_id: # (test.t1)
-master-bin.000001	10215	Write_rows	1	10249	table_id: # flags: STMT_END_F
-master-bin.000001	10249	Table_map	1	10290	table_id: # (test.t1)
-master-bin.000001	10290	Write_rows	1	10324	table_id: # flags: STMT_END_F
-master-bin.000001	10324	Table_map	1	10365	table_id: # (test.t1)
-master-bin.000001	10365	Write_rows	1	10399	table_id: # flags: STMT_END_F
-master-bin.000001	10399	Table_map	1	10440	table_id: # (test.t1)
-master-bin.000001	10440	Write_rows	1	10474	table_id: # flags: STMT_END_F
-master-bin.000001	10474	Table_map	1	10515	table_id: # (test.t1)
-master-bin.000001	10515	Write_rows	1	10549	table_id: # flags: STMT_END_F
-master-bin.000001	10549	Table_map	1	10590	table_id: # (test.t1)
-master-bin.000001	10590	Write_rows	1	10624	table_id: # flags: STMT_END_F
-master-bin.000001	10624	Table_map	1	10665	table_id: # (test.t1)
-master-bin.000001	10665	Write_rows	1	10699	table_id: # flags: STMT_END_F
-master-bin.000001	10699	Table_map	1	10740	table_id: # (test.t1)
-master-bin.000001	10740	Write_rows	1	10774	table_id: # flags: STMT_END_F
-master-bin.000001	10774	Table_map	1	10815	table_id: # (test.t1)
-master-bin.000001	10815	Write_rows	1	10849	table_id: # flags: STMT_END_F
-master-bin.000001	10849	Table_map	1	10890	table_id: # (test.t1)
-master-bin.000001	10890	Write_rows	1	10924	table_id: # flags: STMT_END_F
-master-bin.000001	10924	Table_map	1	10965	table_id: # (test.t1)
-master-bin.000001	10965	Write_rows	1	10999	table_id: # flags: STMT_END_F
-master-bin.000001	10999	Table_map	1	11040	table_id: # (test.t1)
-master-bin.000001	11040	Write_rows	1	11074	table_id: # flags: STMT_END_F
-master-bin.000001	11074	Table_map	1	11115	table_id: # (test.t1)
-master-bin.000001	11115	Write_rows	1	11149	table_id: # flags: STMT_END_F
-master-bin.000001	11149	Table_map	1	11190	table_id: # (test.t1)
-master-bin.000001	11190	Write_rows	1	11224	table_id: # flags: STMT_END_F
-master-bin.000001	11224	Table_map	1	11265	table_id: # (test.t1)
-master-bin.000001	11265	Write_rows	1	11299	table_id: # flags: STMT_END_F
-master-bin.000001	11299	Table_map	1	11340	table_id: # (test.t1)
-master-bin.000001	11340	Write_rows	1	11374	table_id: # flags: STMT_END_F
-master-bin.000001	11374	Table_map	1	11415	table_id: # (test.t1)
-master-bin.000001	11415	Write_rows	1	11449	table_id: # flags: STMT_END_F
-master-bin.000001	11449	Table_map	1	11490	table_id: # (test.t1)
-master-bin.000001	11490	Write_rows	1	11524	table_id: # flags: STMT_END_F
-master-bin.000001	11524	Table_map	1	11565	table_id: # (test.t1)
-master-bin.000001	11565	Write_rows	1	11599	table_id: # flags: STMT_END_F
-master-bin.000001	11599	Table_map	1	11640	table_id: # (test.t1)
-master-bin.000001	11640	Write_rows	1	11674	table_id: # flags: STMT_END_F
-master-bin.000001	11674	Table_map	1	11715	table_id: # (test.t1)
-master-bin.000001	11715	Write_rows	1	11749	table_id: # flags: STMT_END_F
-master-bin.000001	11749	Table_map	1	11790	table_id: # (test.t1)
-master-bin.000001	11790	Write_rows	1	11824	table_id: # flags: STMT_END_F
-master-bin.000001	11824	Table_map	1	11865	table_id: # (test.t1)
-master-bin.000001	11865	Write_rows	1	11899	table_id: # flags: STMT_END_F
-master-bin.000001	11899	Table_map	1	11940	table_id: # (test.t1)
-master-bin.000001	11940	Write_rows	1	11974	table_id: # flags: STMT_END_F
-master-bin.000001	11974	Table_map	1	12015	table_id: # (test.t1)
-master-bin.000001	12015	Write_rows	1	12049	table_id: # flags: STMT_END_F
-master-bin.000001	12049	Table_map	1	12090	table_id: # (test.t1)
-master-bin.000001	12090	Write_rows	1	12124	table_id: # flags: STMT_END_F
-master-bin.000001	12124	Table_map	1	12165	table_id: # (test.t1)
-master-bin.000001	12165	Write_rows	1	12199	table_id: # flags: STMT_END_F
-master-bin.000001	12199	Table_map	1	12240	table_id: # (test.t1)
-master-bin.000001	12240	Write_rows	1	12274	table_id: # flags: STMT_END_F
-master-bin.000001	12274	Table_map	1	12315	table_id: # (test.t1)
-master-bin.000001	12315	Write_rows	1	12349	table_id: # flags: STMT_END_F
-master-bin.000001	12349	Table_map	1	12390	table_id: # (test.t1)
-master-bin.000001	12390	Write_rows	1	12424	table_id: # flags: STMT_END_F
-master-bin.000001	12424	Table_map	1	12465	table_id: # (test.t1)
-master-bin.000001	12465	Write_rows	1	12499	table_id: # flags: STMT_END_F
-master-bin.000001	12499	Table_map	1	12540	table_id: # (test.t1)
-master-bin.000001	12540	Write_rows	1	12574	table_id: # flags: STMT_END_F
-master-bin.000001	12574	Table_map	1	12615	table_id: # (test.t1)
-master-bin.000001	12615	Write_rows	1	12649	table_id: # flags: STMT_END_F
-master-bin.000001	12649	Table_map	1	12690	table_id: # (test.t1)
-master-bin.000001	12690	Write_rows	1	12724	table_id: # flags: STMT_END_F
-master-bin.000001	12724	Table_map	1	12765	table_id: # (test.t1)
-master-bin.000001	12765	Write_rows	1	12799	table_id: # flags: STMT_END_F
-master-bin.000001	12799	Table_map	1	12840	table_id: # (test.t1)
-master-bin.000001	12840	Write_rows	1	12874	table_id: # flags: STMT_END_F
-master-bin.000001	12874	Table_map	1	12915	table_id: # (test.t1)
-master-bin.000001	12915	Write_rows	1	12949	table_id: # flags: STMT_END_F
-master-bin.000001	12949	Table_map	1	12990	table_id: # (test.t1)
-master-bin.000001	12990	Write_rows	1	13024	table_id: # flags: STMT_END_F
-master-bin.000001	13024	Table_map	1	13065	table_id: # (test.t1)
-master-bin.000001	13065	Write_rows	1	13099	table_id: # flags: STMT_END_F
-master-bin.000001	13099	Table_map	1	13140	table_id: # (test.t1)
-master-bin.000001	13140	Write_rows	1	13174	table_id: # flags: STMT_END_F
-master-bin.000001	13174	Table_map	1	13215	table_id: # (test.t1)
-master-bin.000001	13215	Write_rows	1	13249	table_id: # flags: STMT_END_F
-master-bin.000001	13249	Table_map	1	13290	table_id: # (test.t1)
-master-bin.000001	13290	Write_rows	1	13324	table_id: # flags: STMT_END_F
-master-bin.000001	13324	Table_map	1	13365	table_id: # (test.t1)
-master-bin.000001	13365	Write_rows	1	13399	table_id: # flags: STMT_END_F
-master-bin.000001	13399	Table_map	1	13440	table_id: # (test.t1)
-master-bin.000001	13440	Write_rows	1	13474	table_id: # flags: STMT_END_F
-master-bin.000001	13474	Table_map	1	13515	table_id: # (test.t1)
-master-bin.000001	13515	Write_rows	1	13549	table_id: # flags: STMT_END_F
-master-bin.000001	13549	Table_map	1	13590	table_id: # (test.t1)
-master-bin.000001	13590	Write_rows	1	13624	table_id: # flags: STMT_END_F
-master-bin.000001	13624	Table_map	1	13665	table_id: # (test.t1)
-master-bin.000001	13665	Write_rows	1	13699	table_id: # flags: STMT_END_F
-master-bin.000001	13699	Table_map	1	13740	table_id: # (test.t1)
-master-bin.000001	13740	Write_rows	1	13774	table_id: # flags: STMT_END_F
-master-bin.000001	13774	Table_map	1	13815	table_id: # (test.t1)
-master-bin.000001	13815	Write_rows	1	13849	table_id: # flags: STMT_END_F
-master-bin.000001	13849	Table_map	1	13890	table_id: # (test.t1)
-master-bin.000001	13890	Write_rows	1	13924	table_id: # flags: STMT_END_F
-master-bin.000001	13924	Table_map	1	13965	table_id: # (test.t1)
-master-bin.000001	13965	Write_rows	1	13999	table_id: # flags: STMT_END_F
-master-bin.000001	13999	Table_map	1	14040	table_id: # (test.t1)
-master-bin.000001	14040	Write_rows	1	14074	table_id: # flags: STMT_END_F
-master-bin.000001	14074	Table_map	1	14115	table_id: # (test.t1)
-master-bin.000001	14115	Write_rows	1	14149	table_id: # flags: STMT_END_F
-master-bin.000001	14149	Table_map	1	14190	table_id: # (test.t1)
-master-bin.000001	14190	Write_rows	1	14224	table_id: # flags: STMT_END_F
-master-bin.000001	14224	Table_map	1	14265	table_id: # (test.t1)
-master-bin.000001	14265	Write_rows	1	14299	table_id: # flags: STMT_END_F
-master-bin.000001	14299	Table_map	1	14340	table_id: # (test.t1)
-master-bin.000001	14340	Write_rows	1	14374	table_id: # flags: STMT_END_F
-master-bin.000001	14374	Table_map	1	14415	table_id: # (test.t1)
-master-bin.000001	14415	Write_rows	1	14449	table_id: # flags: STMT_END_F
-master-bin.000001	14449	Table_map	1	14490	table_id: # (test.t1)
-master-bin.000001	14490	Write_rows	1	14524	table_id: # flags: STMT_END_F
-master-bin.000001	14524	Table_map	1	14565	table_id: # (test.t1)
-master-bin.000001	14565	Write_rows	1	14599	table_id: # flags: STMT_END_F
-master-bin.000001	14599	Table_map	1	14640	table_id: # (test.t1)
-master-bin.000001	14640	Write_rows	1	14674	table_id: # flags: STMT_END_F
-master-bin.000001	14674	Table_map	1	14715	table_id: # (test.t1)
-master-bin.000001	14715	Write_rows	1	14749	table_id: # flags: STMT_END_F
-master-bin.000001	14749	Table_map	1	14790	table_id: # (test.t1)
-master-bin.000001	14790	Write_rows	1	14824	table_id: # flags: STMT_END_F
-master-bin.000001	14824	Table_map	1	14865	table_id: # (test.t1)
-master-bin.000001	14865	Write_rows	1	14899	table_id: # flags: STMT_END_F
-master-bin.000001	14899	Table_map	1	14940	table_id: # (test.t1)
-master-bin.000001	14940	Write_rows	1	14974	table_id: # flags: STMT_END_F
-master-bin.000001	14974	Table_map	1	15015	table_id: # (test.t1)
-master-bin.000001	15015	Write_rows	1	15049	table_id: # flags: STMT_END_F
-master-bin.000001	15049	Table_map	1	15090	table_id: # (test.t1)
-master-bin.000001	15090	Write_rows	1	15124	table_id: # flags: STMT_END_F
-master-bin.000001	15124	Table_map	1	15165	table_id: # (test.t1)
-master-bin.000001	15165	Write_rows	1	15199	table_id: # flags: STMT_END_F
-master-bin.000001	15199	Table_map	1	15240	table_id: # (test.t1)
-master-bin.000001	15240	Write_rows	1	15274	table_id: # flags: STMT_END_F
-master-bin.000001	15274	Table_map	1	15315	table_id: # (test.t1)
-master-bin.000001	15315	Write_rows	1	15349	table_id: # flags: STMT_END_F
-master-bin.000001	15349	Table_map	1	15390	table_id: # (test.t1)
-master-bin.000001	15390	Write_rows	1	15424	table_id: # flags: STMT_END_F
-master-bin.000001	15424	Table_map	1	15465	table_id: # (test.t1)
-master-bin.000001	15465	Write_rows	1	15499	table_id: # flags: STMT_END_F
-master-bin.000001	15499	Table_map	1	15540	table_id: # (test.t1)
-master-bin.000001	15540	Write_rows	1	15574	table_id: # flags: STMT_END_F
-master-bin.000001	15574	Table_map	1	15615	table_id: # (test.t1)
-master-bin.000001	15615	Write_rows	1	15649	table_id: # flags: STMT_END_F
-master-bin.000001	15649	Table_map	1	15690	table_id: # (test.t1)
-master-bin.000001	15690	Write_rows	1	15724	table_id: # flags: STMT_END_F
-master-bin.000001	15724	Table_map	1	15765	table_id: # (test.t1)
-master-bin.000001	15765	Write_rows	1	15799	table_id: # flags: STMT_END_F
-master-bin.000001	15799	Table_map	1	15840	table_id: # (test.t1)
-master-bin.000001	15840	Write_rows	1	15874	table_id: # flags: STMT_END_F
-master-bin.000001	15874	Table_map	1	15915	table_id: # (test.t1)
-master-bin.000001	15915	Write_rows	1	15949	table_id: # flags: STMT_END_F
-master-bin.000001	15949	Table_map	1	15990	table_id: # (test.t1)
-master-bin.000001	15990	Write_rows	1	16024	table_id: # flags: STMT_END_F
-master-bin.000001	16024	Table_map	1	16065	table_id: # (test.t1)
-master-bin.000001	16065	Write_rows	1	16099	table_id: # flags: STMT_END_F
-master-bin.000001	16099	Table_map	1	16140	table_id: # (test.t1)
-master-bin.000001	16140	Write_rows	1	16174	table_id: # flags: STMT_END_F
-master-bin.000001	16174	Table_map	1	16215	table_id: # (test.t1)
-master-bin.000001	16215	Write_rows	1	16249	table_id: # flags: STMT_END_F
-master-bin.000001	16249	Table_map	1	16290	table_id: # (test.t1)
-master-bin.000001	16290	Write_rows	1	16324	table_id: # flags: STMT_END_F
-master-bin.000001	16324	Table_map	1	16365	table_id: # (test.t1)
-master-bin.000001	16365	Write_rows	1	16399	table_id: # flags: STMT_END_F
-master-bin.000001	16399	Table_map	1	16440	table_id: # (test.t1)
-master-bin.000001	16440	Write_rows	1	16474	table_id: # flags: STMT_END_F
-master-bin.000001	16474	Table_map	1	16515	table_id: # (test.t1)
-master-bin.000001	16515	Write_rows	1	16549	table_id: # flags: STMT_END_F
-master-bin.000001	16549	Table_map	1	16590	table_id: # (test.t1)
-master-bin.000001	16590	Write_rows	1	16624	table_id: # flags: STMT_END_F
-master-bin.000001	16624	Table_map	1	16665	table_id: # (test.t1)
-master-bin.000001	16665	Write_rows	1	16699	table_id: # flags: STMT_END_F
-master-bin.000001	16699	Table_map	1	16740	table_id: # (test.t1)
-master-bin.000001	16740	Write_rows	1	16774	table_id: # flags: STMT_END_F
-master-bin.000001	16774	Table_map	1	16815	table_id: # (test.t1)
-master-bin.000001	16815	Write_rows	1	16849	table_id: # flags: STMT_END_F
-master-bin.000001	16849	Table_map	1	16890	table_id: # (test.t1)
-master-bin.000001	16890	Write_rows	1	16924	table_id: # flags: STMT_END_F
-master-bin.000001	16924	Table_map	1	16965	table_id: # (test.t1)
-master-bin.000001	16965	Write_rows	1	16999	table_id: # flags: STMT_END_F
-master-bin.000001	16999	Table_map	1	17040	table_id: # (test.t1)
-master-bin.000001	17040	Write_rows	1	17074	table_id: # flags: STMT_END_F
-master-bin.000001	17074	Table_map	1	17115	table_id: # (test.t1)
-master-bin.000001	17115	Write_rows	1	17149	table_id: # flags: STMT_END_F
-master-bin.000001	17149	Table_map	1	17190	table_id: # (test.t1)
-master-bin.000001	17190	Write_rows	1	17224	table_id: # flags: STMT_END_F
-master-bin.000001	17224	Table_map	1	17265	table_id: # (test.t1)
-master-bin.000001	17265	Write_rows	1	17299	table_id: # flags: STMT_END_F
-master-bin.000001	17299	Table_map	1	17340	table_id: # (test.t1)
-master-bin.000001	17340	Write_rows	1	17374	table_id: # flags: STMT_END_F
-master-bin.000001	17374	Table_map	1	17415	table_id: # (test.t1)
-master-bin.000001	17415	Write_rows	1	17449	table_id: # flags: STMT_END_F
-master-bin.000001	17449	Table_map	1	17490	table_id: # (test.t1)
-master-bin.000001	17490	Write_rows	1	17524	table_id: # flags: STMT_END_F
-master-bin.000001	17524	Table_map	1	17565	table_id: # (test.t1)
-master-bin.000001	17565	Write_rows	1	17599	table_id: # flags: STMT_END_F
-master-bin.000001	17599	Table_map	1	17640	table_id: # (test.t1)
-master-bin.000001	17640	Write_rows	1	17674	table_id: # flags: STMT_END_F
-master-bin.000001	17674	Table_map	1	17715	table_id: # (test.t1)
-master-bin.000001	17715	Write_rows	1	17749	table_id: # flags: STMT_END_F
-master-bin.000001	17749	Table_map	1	17790	table_id: # (test.t1)
-master-bin.000001	17790	Write_rows	1	17824	table_id: # flags: STMT_END_F
-master-bin.000001	17824	Table_map	1	17865	table_id: # (test.t1)
-master-bin.000001	17865	Write_rows	1	17899	table_id: # flags: STMT_END_F
-master-bin.000001	17899	Table_map	1	17940	table_id: # (test.t1)
-master-bin.000001	17940	Write_rows	1	17974	table_id: # flags: STMT_END_F
-master-bin.000001	17974	Table_map	1	18015	table_id: # (test.t1)
-master-bin.000001	18015	Write_rows	1	18049	table_id: # flags: STMT_END_F
-master-bin.000001	18049	Table_map	1	18090	table_id: # (test.t1)
-master-bin.000001	18090	Write_rows	1	18124	table_id: # flags: STMT_END_F
-master-bin.000001	18124	Table_map	1	18165	table_id: # (test.t1)
-master-bin.000001	18165	Write_rows	1	18199	table_id: # flags: STMT_END_F
-master-bin.000001	18199	Table_map	1	18240	table_id: # (test.t1)
-master-bin.000001	18240	Write_rows	1	18274	table_id: # flags: STMT_END_F
-master-bin.000001	18274	Table_map	1	18315	table_id: # (test.t1)
-master-bin.000001	18315	Write_rows	1	18349	table_id: # flags: STMT_END_F
-master-bin.000001	18349	Table_map	1	18390	table_id: # (test.t1)
-master-bin.000001	18390	Write_rows	1	18424	table_id: # flags: STMT_END_F
-master-bin.000001	18424	Table_map	1	18465	table_id: # (test.t1)
-master-bin.000001	18465	Write_rows	1	18499	table_id: # flags: STMT_END_F
-master-bin.000001	18499	Table_map	1	18540	table_id: # (test.t1)
-master-bin.000001	18540	Write_rows	1	18574	table_id: # flags: STMT_END_F
-master-bin.000001	18574	Table_map	1	18615	table_id: # (test.t1)
-master-bin.000001	18615	Write_rows	1	18649	table_id: # flags: STMT_END_F
-master-bin.000001	18649	Table_map	1	18690	table_id: # (test.t1)
-master-bin.000001	18690	Write_rows	1	18724	table_id: # flags: STMT_END_F
-master-bin.000001	18724	Table_map	1	18765	table_id: # (test.t1)
-master-bin.000001	18765	Write_rows	1	18799	table_id: # flags: STMT_END_F
-master-bin.000001	18799	Table_map	1	18840	table_id: # (test.t1)
-master-bin.000001	18840	Write_rows	1	18874	table_id: # flags: STMT_END_F
-master-bin.000001	18874	Table_map	1	18915	table_id: # (test.t1)
-master-bin.000001	18915	Write_rows	1	18949	table_id: # flags: STMT_END_F
-master-bin.000001	18949	Table_map	1	18990	table_id: # (test.t1)
-master-bin.000001	18990	Write_rows	1	19024	table_id: # flags: STMT_END_F
-master-bin.000001	19024	Table_map	1	19065	table_id: # (test.t1)
-master-bin.000001	19065	Write_rows	1	19099	table_id: # flags: STMT_END_F
-master-bin.000001	19099	Table_map	1	19140	table_id: # (test.t1)
-master-bin.000001	19140	Write_rows	1	19174	table_id: # flags: STMT_END_F
-master-bin.000001	19174	Table_map	1	19215	table_id: # (test.t1)
-master-bin.000001	19215	Write_rows	1	19249	table_id: # flags: STMT_END_F
-master-bin.000001	19249	Table_map	1	19290	table_id: # (test.t1)
-master-bin.000001	19290	Write_rows	1	19324	table_id: # flags: STMT_END_F
-master-bin.000001	19324	Table_map	1	19365	table_id: # (test.t1)
-master-bin.000001	19365	Write_rows	1	19399	table_id: # flags: STMT_END_F
-master-bin.000001	19399	Table_map	1	19440	table_id: # (test.t1)
-master-bin.000001	19440	Write_rows	1	19474	table_id: # flags: STMT_END_F
-master-bin.000001	19474	Table_map	1	19515	table_id: # (test.t1)
-master-bin.000001	19515	Write_rows	1	19549	table_id: # flags: STMT_END_F
-master-bin.000001	19549	Table_map	1	19590	table_id: # (test.t1)
-master-bin.000001	19590	Write_rows	1	19624	table_id: # flags: STMT_END_F
-master-bin.000001	19624	Table_map	1	19665	table_id: # (test.t1)
-master-bin.000001	19665	Write_rows	1	19699	table_id: # flags: STMT_END_F
-master-bin.000001	19699	Table_map	1	19740	table_id: # (test.t1)
-master-bin.000001	19740	Write_rows	1	19774	table_id: # flags: STMT_END_F
-master-bin.000001	19774	Table_map	1	19815	table_id: # (test.t1)
-master-bin.000001	19815	Write_rows	1	19849	table_id: # flags: STMT_END_F
-master-bin.000001	19849	Table_map	1	19890	table_id: # (test.t1)
-master-bin.000001	19890	Write_rows	1	19924	table_id: # flags: STMT_END_F
-master-bin.000001	19924	Table_map	1	19965	table_id: # (test.t1)
-master-bin.000001	19965	Write_rows	1	19999	table_id: # flags: STMT_END_F
-master-bin.000001	19999	Table_map	1	20040	table_id: # (test.t1)
-master-bin.000001	20040	Write_rows	1	20074	table_id: # flags: STMT_END_F
-master-bin.000001	20074	Table_map	1	20115	table_id: # (test.t1)
-master-bin.000001	20115	Write_rows	1	20149	table_id: # flags: STMT_END_F
-master-bin.000001	20149	Table_map	1	20190	table_id: # (test.t1)
-master-bin.000001	20190	Write_rows	1	20224	table_id: # flags: STMT_END_F
-master-bin.000001	20224	Table_map	1	20265	table_id: # (test.t1)
-master-bin.000001	20265	Write_rows	1	20299	table_id: # flags: STMT_END_F
-master-bin.000001	20299	Table_map	1	20340	table_id: # (test.t1)
-master-bin.000001	20340	Write_rows	1	20374	table_id: # flags: STMT_END_F
-master-bin.000001	20374	Table_map	1	20415	table_id: # (test.t1)
-master-bin.000001	20415	Write_rows	1	20449	table_id: # flags: STMT_END_F
-master-bin.000001	20449	Table_map	1	20490	table_id: # (test.t1)
-master-bin.000001	20490	Write_rows	1	20524	table_id: # flags: STMT_END_F
-master-bin.000001	20524	Table_map	1	20565	table_id: # (test.t1)
-master-bin.000001	20565	Write_rows	1	20599	table_id: # flags: STMT_END_F
-master-bin.000001	20599	Table_map	1	20640	table_id: # (test.t1)
-master-bin.000001	20640	Write_rows	1	20674	table_id: # flags: STMT_END_F
-master-bin.000001	20674	Table_map	1	20715	table_id: # (test.t1)
-master-bin.000001	20715	Write_rows	1	20749	table_id: # flags: STMT_END_F
-master-bin.000001	20749	Table_map	1	20790	table_id: # (test.t1)
-master-bin.000001	20790	Write_rows	1	20824	table_id: # flags: STMT_END_F
-master-bin.000001	20824	Table_map	1	20865	table_id: # (test.t1)
-master-bin.000001	20865	Write_rows	1	20899	table_id: # flags: STMT_END_F
-master-bin.000001	20899	Table_map	1	20940	table_id: # (test.t1)
-master-bin.000001	20940	Write_rows	1	20974	table_id: # flags: STMT_END_F
-master-bin.000001	20974	Table_map	1	21015	table_id: # (test.t1)
-master-bin.000001	21015	Write_rows	1	21049	table_id: # flags: STMT_END_F
-master-bin.000001	21049	Table_map	1	21090	table_id: # (test.t1)
-master-bin.000001	21090	Write_rows	1	21124	table_id: # flags: STMT_END_F
-master-bin.000001	21124	Table_map	1	21165	table_id: # (test.t1)
-master-bin.000001	21165	Write_rows	1	21199	table_id: # flags: STMT_END_F
-master-bin.000001	21199	Table_map	1	21240	table_id: # (test.t1)
-master-bin.000001	21240	Write_rows	1	21274	table_id: # flags: STMT_END_F
-master-bin.000001	21274	Table_map	1	21315	table_id: # (test.t1)
-master-bin.000001	21315	Write_rows	1	21349	table_id: # flags: STMT_END_F
-master-bin.000001	21349	Table_map	1	21390	table_id: # (test.t1)
-master-bin.000001	21390	Write_rows	1	21424	table_id: # flags: STMT_END_F
-master-bin.000001	21424	Table_map	1	21465	table_id: # (test.t1)
-master-bin.000001	21465	Write_rows	1	21499	table_id: # flags: STMT_END_F
-master-bin.000001	21499	Table_map	1	21540	table_id: # (test.t1)
-master-bin.000001	21540	Write_rows	1	21574	table_id: # flags: STMT_END_F
-master-bin.000001	21574	Table_map	1	21615	table_id: # (test.t1)
-master-bin.000001	21615	Write_rows	1	21649	table_id: # flags: STMT_END_F
-master-bin.000001	21649	Table_map	1	21690	table_id: # (test.t1)
-master-bin.000001	21690	Write_rows	1	21724	table_id: # flags: STMT_END_F
-master-bin.000001	21724	Table_map	1	21765	table_id: # (test.t1)
-master-bin.000001	21765	Write_rows	1	21799	table_id: # flags: STMT_END_F
-master-bin.000001	21799	Table_map	1	21840	table_id: # (test.t1)
-master-bin.000001	21840	Write_rows	1	21874	table_id: # flags: STMT_END_F
-master-bin.000001	21874	Table_map	1	21915	table_id: # (test.t1)
-master-bin.000001	21915	Write_rows	1	21949	table_id: # flags: STMT_END_F
-master-bin.000001	21949	Table_map	1	21990	table_id: # (test.t1)
-master-bin.000001	21990	Write_rows	1	22024	table_id: # flags: STMT_END_F
-master-bin.000001	22024	Table_map	1	22065	table_id: # (test.t1)
-master-bin.000001	22065	Write_rows	1	22099	table_id: # flags: STMT_END_F
-master-bin.000001	22099	Table_map	1	22140	table_id: # (test.t1)
-master-bin.000001	22140	Write_rows	1	22174	table_id: # flags: STMT_END_F
-master-bin.000001	22174	Table_map	1	22215	table_id: # (test.t1)
-master-bin.000001	22215	Write_rows	1	22249	table_id: # flags: STMT_END_F
-master-bin.000001	22249	Table_map	1	22290	table_id: # (test.t1)
-master-bin.000001	22290	Write_rows	1	22324	table_id: # flags: STMT_END_F
-master-bin.000001	22324	Table_map	1	22365	table_id: # (test.t1)
-master-bin.000001	22365	Write_rows	1	22399	table_id: # flags: STMT_END_F
-master-bin.000001	22399	Table_map	1	22440	table_id: # (test.t1)
-master-bin.000001	22440	Write_rows	1	22474	table_id: # flags: STMT_END_F
-master-bin.000001	22474	Table_map	1	22515	table_id: # (test.t1)
-master-bin.000001	22515	Write_rows	1	22549	table_id: # flags: STMT_END_F
-master-bin.000001	22549	Table_map	1	22590	table_id: # (test.t1)
-master-bin.000001	22590	Write_rows	1	22624	table_id: # flags: STMT_END_F
-master-bin.000001	22624	Table_map	1	22665	table_id: # (test.t1)
-master-bin.000001	22665	Write_rows	1	22699	table_id: # flags: STMT_END_F
-master-bin.000001	22699	Table_map	1	22740	table_id: # (test.t1)
-master-bin.000001	22740	Write_rows	1	22774	table_id: # flags: STMT_END_F
-master-bin.000001	22774	Table_map	1	22815	table_id: # (test.t1)
-master-bin.000001	22815	Write_rows	1	22849	table_id: # flags: STMT_END_F
-master-bin.000001	22849	Table_map	1	22890	table_id: # (test.t1)
-master-bin.000001	22890	Write_rows	1	22924	table_id: # flags: STMT_END_F
-master-bin.000001	22924	Table_map	1	22965	table_id: # (test.t1)
-master-bin.000001	22965	Write_rows	1	22999	table_id: # flags: STMT_END_F
-master-bin.000001	22999	Table_map	1	23040	table_id: # (test.t1)
-master-bin.000001	23040	Write_rows	1	23074	table_id: # flags: STMT_END_F
-master-bin.000001	23074	Table_map	1	23115	table_id: # (test.t1)
-master-bin.000001	23115	Write_rows	1	23149	table_id: # flags: STMT_END_F
-master-bin.000001	23149	Table_map	1	23190	table_id: # (test.t1)
-master-bin.000001	23190	Write_rows	1	23224	table_id: # flags: STMT_END_F
-master-bin.000001	23224	Table_map	1	23265	table_id: # (test.t1)
-master-bin.000001	23265	Write_rows	1	23299	table_id: # flags: STMT_END_F
-master-bin.000001	23299	Table_map	1	23340	table_id: # (test.t1)
-master-bin.000001	23340	Write_rows	1	23374	table_id: # flags: STMT_END_F
-master-bin.000001	23374	Table_map	1	23415	table_id: # (test.t1)
-master-bin.000001	23415	Write_rows	1	23449	table_id: # flags: STMT_END_F
-master-bin.000001	23449	Table_map	1	23490	table_id: # (test.t1)
-master-bin.000001	23490	Write_rows	1	23524	table_id: # flags: STMT_END_F
-master-bin.000001	23524	Table_map	1	23565	table_id: # (test.t1)
-master-bin.000001	23565	Write_rows	1	23599	table_id: # flags: STMT_END_F
-master-bin.000001	23599	Table_map	1	23640	table_id: # (test.t1)
-master-bin.000001	23640	Write_rows	1	23674	table_id: # flags: STMT_END_F
-master-bin.000001	23674	Table_map	1	23715	table_id: # (test.t1)
-master-bin.000001	23715	Write_rows	1	23749	table_id: # flags: STMT_END_F
-master-bin.000001	23749	Table_map	1	23790	table_id: # (test.t1)
-master-bin.000001	23790	Write_rows	1	23824	table_id: # flags: STMT_END_F
-master-bin.000001	23824	Table_map	1	23865	table_id: # (test.t1)
-master-bin.000001	23865	Write_rows	1	23899	table_id: # flags: STMT_END_F
-master-bin.000001	23899	Table_map	1	23940	table_id: # (test.t1)
-master-bin.000001	23940	Write_rows	1	23974	table_id: # flags: STMT_END_F
-master-bin.000001	23974	Table_map	1	24015	table_id: # (test.t1)
-master-bin.000001	24015	Write_rows	1	24049	table_id: # flags: STMT_END_F
-master-bin.000001	24049	Table_map	1	24090	table_id: # (test.t1)
-master-bin.000001	24090	Write_rows	1	24124	table_id: # flags: STMT_END_F
-master-bin.000001	24124	Table_map	1	24165	table_id: # (test.t1)
-master-bin.000001	24165	Write_rows	1	24199	table_id: # flags: STMT_END_F
-master-bin.000001	24199	Table_map	1	24240	table_id: # (test.t1)
-master-bin.000001	24240	Write_rows	1	24274	table_id: # flags: STMT_END_F
-master-bin.000001	24274	Table_map	1	24315	table_id: # (test.t1)
-master-bin.000001	24315	Write_rows	1	24349	table_id: # flags: STMT_END_F
-master-bin.000001	24349	Table_map	1	24390	table_id: # (test.t1)
-master-bin.000001	24390	Write_rows	1	24424	table_id: # flags: STMT_END_F
-master-bin.000001	24424	Table_map	1	24465	table_id: # (test.t1)
-master-bin.000001	24465	Write_rows	1	24499	table_id: # flags: STMT_END_F
-master-bin.000001	24499	Table_map	1	24540	table_id: # (test.t1)
-master-bin.000001	24540	Write_rows	1	24574	table_id: # flags: STMT_END_F
-master-bin.000001	24574	Table_map	1	24615	table_id: # (test.t1)
-master-bin.000001	24615	Write_rows	1	24649	table_id: # flags: STMT_END_F
-master-bin.000001	24649	Table_map	1	24690	table_id: # (test.t1)
-master-bin.000001	24690	Write_rows	1	24724	table_id: # flags: STMT_END_F
-master-bin.000001	24724	Table_map	1	24765	table_id: # (test.t1)
-master-bin.000001	24765	Write_rows	1	24799	table_id: # flags: STMT_END_F
-master-bin.000001	24799	Table_map	1	24840	table_id: # (test.t1)
-master-bin.000001	24840	Write_rows	1	24874	table_id: # flags: STMT_END_F
-master-bin.000001	24874	Table_map	1	24915	table_id: # (test.t1)
-master-bin.000001	24915	Write_rows	1	24949	table_id: # flags: STMT_END_F
-master-bin.000001	24949	Table_map	1	24990	table_id: # (test.t1)
-master-bin.000001	24990	Write_rows	1	25024	table_id: # flags: STMT_END_F
-master-bin.000001	25024	Table_map	1	25065	table_id: # (test.t1)
-master-bin.000001	25065	Write_rows	1	25099	table_id: # flags: STMT_END_F
-master-bin.000001	25099	Table_map	1	25140	table_id: # (test.t1)
-master-bin.000001	25140	Write_rows	1	25174	table_id: # flags: STMT_END_F
-master-bin.000001	25174	Table_map	1	25215	table_id: # (test.t1)
-master-bin.000001	25215	Write_rows	1	25249	table_id: # flags: STMT_END_F
-master-bin.000001	25249	Table_map	1	25290	table_id: # (test.t1)
-master-bin.000001	25290	Write_rows	1	25324	table_id: # flags: STMT_END_F
-master-bin.000001	25324	Table_map	1	25365	table_id: # (test.t1)
-master-bin.000001	25365	Write_rows	1	25399	table_id: # flags: STMT_END_F
-master-bin.000001	25399	Table_map	1	25440	table_id: # (test.t1)
-master-bin.000001	25440	Write_rows	1	25474	table_id: # flags: STMT_END_F
-master-bin.000001	25474	Table_map	1	25515	table_id: # (test.t1)
-master-bin.000001	25515	Write_rows	1	25549	table_id: # flags: STMT_END_F
-master-bin.000001	25549	Table_map	1	25590	table_id: # (test.t1)
-master-bin.000001	25590	Write_rows	1	25624	table_id: # flags: STMT_END_F
-master-bin.000001	25624	Table_map	1	25665	table_id: # (test.t1)
-master-bin.000001	25665	Write_rows	1	25699	table_id: # flags: STMT_END_F
-master-bin.000001	25699	Table_map	1	25740	table_id: # (test.t1)
-master-bin.000001	25740	Write_rows	1	25774	table_id: # flags: STMT_END_F
-master-bin.000001	25774	Table_map	1	25815	table_id: # (test.t1)
-master-bin.000001	25815	Write_rows	1	25849	table_id: # flags: STMT_END_F
-master-bin.000001	25849	Table_map	1	25890	table_id: # (test.t1)
-master-bin.000001	25890	Write_rows	1	25924	table_id: # flags: STMT_END_F
-master-bin.000001	25924	Table_map	1	25965	table_id: # (test.t1)
-master-bin.000001	25965	Write_rows	1	25999	table_id: # flags: STMT_END_F
-master-bin.000001	25999	Table_map	1	26040	table_id: # (test.t1)
-master-bin.000001	26040	Write_rows	1	26074	table_id: # flags: STMT_END_F
-master-bin.000001	26074	Table_map	1	26115	table_id: # (test.t1)
-master-bin.000001	26115	Write_rows	1	26149	table_id: # flags: STMT_END_F
-master-bin.000001	26149	Table_map	1	26190	table_id: # (test.t1)
-master-bin.000001	26190	Write_rows	1	26224	table_id: # flags: STMT_END_F
-master-bin.000001	26224	Table_map	1	26265	table_id: # (test.t1)
-master-bin.000001	26265	Write_rows	1	26299	table_id: # flags: STMT_END_F
-master-bin.000001	26299	Table_map	1	26340	table_id: # (test.t1)
-master-bin.000001	26340	Write_rows	1	26374	table_id: # flags: STMT_END_F
-master-bin.000001	26374	Table_map	1	26415	table_id: # (test.t1)
-master-bin.000001	26415	Write_rows	1	26449	table_id: # flags: STMT_END_F
-master-bin.000001	26449	Table_map	1	26490	table_id: # (test.t1)
-master-bin.000001	26490	Write_rows	1	26524	table_id: # flags: STMT_END_F
-master-bin.000001	26524	Table_map	1	26565	table_id: # (test.t1)
-master-bin.000001	26565	Write_rows	1	26599	table_id: # flags: STMT_END_F
-master-bin.000001	26599	Table_map	1	26640	table_id: # (test.t1)
-master-bin.000001	26640	Write_rows	1	26674	table_id: # flags: STMT_END_F
-master-bin.000001	26674	Table_map	1	26715	table_id: # (test.t1)
-master-bin.000001	26715	Write_rows	1	26749	table_id: # flags: STMT_END_F
-master-bin.000001	26749	Table_map	1	26790	table_id: # (test.t1)
-master-bin.000001	26790	Write_rows	1	26824	table_id: # flags: STMT_END_F
-master-bin.000001	26824	Table_map	1	26865	table_id: # (test.t1)
-master-bin.000001	26865	Write_rows	1	26899	table_id: # flags: STMT_END_F
-master-bin.000001	26899	Table_map	1	26940	table_id: # (test.t1)
-master-bin.000001	26940	Write_rows	1	26974	table_id: # flags: STMT_END_F
-master-bin.000001	26974	Table_map	1	27015	table_id: # (test.t1)
-master-bin.000001	27015	Write_rows	1	27049	table_id: # flags: STMT_END_F
-master-bin.000001	27049	Table_map	1	27090	table_id: # (test.t1)
-master-bin.000001	27090	Write_rows	1	27124	table_id: # flags: STMT_END_F
-master-bin.000001	27124	Table_map	1	27165	table_id: # (test.t1)
-master-bin.000001	27165	Write_rows	1	27199	table_id: # flags: STMT_END_F
-master-bin.000001	27199	Table_map	1	27240	table_id: # (test.t1)
-master-bin.000001	27240	Write_rows	1	27274	table_id: # flags: STMT_END_F
-master-bin.000001	27274	Table_map	1	27315	table_id: # (test.t1)
-master-bin.000001	27315	Write_rows	1	27349	table_id: # flags: STMT_END_F
-master-bin.000001	27349	Table_map	1	27390	table_id: # (test.t1)
-master-bin.000001	27390	Write_rows	1	27424	table_id: # flags: STMT_END_F
-master-bin.000001	27424	Table_map	1	27465	table_id: # (test.t1)
-master-bin.000001	27465	Write_rows	1	27499	table_id: # flags: STMT_END_F
-master-bin.000001	27499	Table_map	1	27540	table_id: # (test.t1)
-master-bin.000001	27540	Write_rows	1	27574	table_id: # flags: STMT_END_F
-master-bin.000001	27574	Table_map	1	27615	table_id: # (test.t1)
-master-bin.000001	27615	Write_rows	1	27649	table_id: # flags: STMT_END_F
-master-bin.000001	27649	Table_map	1	27690	table_id: # (test.t1)
-master-bin.000001	27690	Write_rows	1	27724	table_id: # flags: STMT_END_F
-master-bin.000001	27724	Table_map	1	27765	table_id: # (test.t1)
-master-bin.000001	27765	Write_rows	1	27799	table_id: # flags: STMT_END_F
-master-bin.000001	27799	Table_map	1	27840	table_id: # (test.t1)
-master-bin.000001	27840	Write_rows	1	27874	table_id: # flags: STMT_END_F
-master-bin.000001	27874	Table_map	1	27915	table_id: # (test.t1)
-master-bin.000001	27915	Write_rows	1	27949	table_id: # flags: STMT_END_F
-master-bin.000001	27949	Table_map	1	27990	table_id: # (test.t1)
-master-bin.000001	27990	Write_rows	1	28024	table_id: # flags: STMT_END_F
-master-bin.000001	28024	Table_map	1	28065	table_id: # (test.t1)
-master-bin.000001	28065	Write_rows	1	28099	table_id: # flags: STMT_END_F
-master-bin.000001	28099	Table_map	1	28140	table_id: # (test.t1)
-master-bin.000001	28140	Write_rows	1	28174	table_id: # flags: STMT_END_F
-master-bin.000001	28174	Table_map	1	28215	table_id: # (test.t1)
-master-bin.000001	28215	Write_rows	1	28249	table_id: # flags: STMT_END_F
-master-bin.000001	28249	Table_map	1	28290	table_id: # (test.t1)
-master-bin.000001	28290	Write_rows	1	28324	table_id: # flags: STMT_END_F
-master-bin.000001	28324	Table_map	1	28365	table_id: # (test.t1)
-master-bin.000001	28365	Write_rows	1	28399	table_id: # flags: STMT_END_F
-master-bin.000001	28399	Table_map	1	28440	table_id: # (test.t1)
-master-bin.000001	28440	Write_rows	1	28474	table_id: # flags: STMT_END_F
-master-bin.000001	28474	Table_map	1	28515	table_id: # (test.t1)
-master-bin.000001	28515	Write_rows	1	28549	table_id: # flags: STMT_END_F
-master-bin.000001	28549	Table_map	1	28590	table_id: # (test.t1)
-master-bin.000001	28590	Write_rows	1	28624	table_id: # flags: STMT_END_F
-master-bin.000001	28624	Table_map	1	28665	table_id: # (test.t1)
-master-bin.000001	28665	Write_rows	1	28699	table_id: # flags: STMT_END_F
-master-bin.000001	28699	Table_map	1	28740	table_id: # (test.t1)
-master-bin.000001	28740	Write_rows	1	28774	table_id: # flags: STMT_END_F
-master-bin.000001	28774	Table_map	1	28815	table_id: # (test.t1)
-master-bin.000001	28815	Write_rows	1	28849	table_id: # flags: STMT_END_F
-master-bin.000001	28849	Table_map	1	28890	table_id: # (test.t1)
-master-bin.000001	28890	Write_rows	1	28924	table_id: # flags: STMT_END_F
-master-bin.000001	28924	Table_map	1	28965	table_id: # (test.t1)
-master-bin.000001	28965	Write_rows	1	28999	table_id: # flags: STMT_END_F
-master-bin.000001	28999	Table_map	1	29040	table_id: # (test.t1)
-master-bin.000001	29040	Write_rows	1	29074	table_id: # flags: STMT_END_F
-master-bin.000001	29074	Table_map	1	29115	table_id: # (test.t1)
-master-bin.000001	29115	Write_rows	1	29149	table_id: # flags: STMT_END_F
-master-bin.000001	29149	Table_map	1	29190	table_id: # (test.t1)
-master-bin.000001	29190	Write_rows	1	29224	table_id: # flags: STMT_END_F
-master-bin.000001	29224	Table_map	1	29265	table_id: # (test.t1)
-master-bin.000001	29265	Write_rows	1	29299	table_id: # flags: STMT_END_F
-master-bin.000001	29299	Table_map	1	29340	table_id: # (test.t1)
-master-bin.000001	29340	Write_rows	1	29374	table_id: # flags: STMT_END_F
-master-bin.000001	29374	Table_map	1	29415	table_id: # (test.t1)
-master-bin.000001	29415	Write_rows	1	29449	table_id: # flags: STMT_END_F
-master-bin.000001	29449	Table_map	1	29490	table_id: # (test.t1)
-master-bin.000001	29490	Write_rows	1	29524	table_id: # flags: STMT_END_F
-master-bin.000001	29524	Table_map	1	29565	table_id: # (test.t1)
-master-bin.000001	29565	Write_rows	1	29599	table_id: # flags: STMT_END_F
-master-bin.000001	29599	Table_map	1	29640	table_id: # (test.t1)
-master-bin.000001	29640	Write_rows	1	29674	table_id: # flags: STMT_END_F
-master-bin.000001	29674	Table_map	1	29715	table_id: # (test.t1)
-master-bin.000001	29715	Write_rows	1	29749	table_id: # flags: STMT_END_F
-master-bin.000001	29749	Table_map	1	29790	table_id: # (test.t1)
-master-bin.000001	29790	Write_rows	1	29824	table_id: # flags: STMT_END_F
-master-bin.000001	29824	Table_map	1	29865	table_id: # (test.t1)
-master-bin.000001	29865	Write_rows	1	29899	table_id: # flags: STMT_END_F
-master-bin.000001	29899	Table_map	1	29940	table_id: # (test.t1)
-master-bin.000001	29940	Write_rows	1	29974	table_id: # flags: STMT_END_F
-master-bin.000001	29974	Table_map	1	30015	table_id: # (test.t1)
-master-bin.000001	30015	Write_rows	1	30049	table_id: # flags: STMT_END_F
-master-bin.000001	30049	Table_map	1	30090	table_id: # (test.t1)
-master-bin.000001	30090	Write_rows	1	30124	table_id: # flags: STMT_END_F
-master-bin.000001	30124	Table_map	1	30165	table_id: # (test.t1)
-master-bin.000001	30165	Write_rows	1	30199	table_id: # flags: STMT_END_F
-master-bin.000001	30199	Table_map	1	30240	table_id: # (test.t1)
-master-bin.000001	30240	Write_rows	1	30274	table_id: # flags: STMT_END_F
-master-bin.000001	30274	Xid	1	30301	COMMIT /* XID */
-master-bin.000001	30301	Rotate	1	30345	master-bin.000002;pos=4
+master-bin.000001	499	Xid	1	526	COMMIT /* XID */
+master-bin.000001	526	Query	1	602	use `test`; drop table t1
+set @bcs = @@binlog_cache_size;
+set global binlog_cache_size=4096;
+reset master;
+create table t1 (a int) engine=innodb;
+show binlog events from 0;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	4	Format_desc	1	107	Server version, Binlog ver: 4
+master-bin.000001	107	Query	1	207	use `test`; create table t1 (a int) engine=innodb
+master-bin.000001	207	Query	1	275	BEGIN
+master-bin.000001	275	Table_map	1	316	table_id: # (test.t1)
+master-bin.000001	316	Write_rows	1	350	table_id: # flags: STMT_END_F
+master-bin.000001	350	Table_map	1	391	table_id: # (test.t1)
+master-bin.000001	391	Write_rows	1	425	table_id: # flags: STMT_END_F
+master-bin.000001	425	Table_map	1	466	table_id: # (test.t1)
+master-bin.000001	466	Write_rows	1	500	table_id: # flags: STMT_END_F
+master-bin.000001	500	Table_map	1	541	table_id: # (test.t1)
+master-bin.000001	541	Write_rows	1	575	table_id: # flags: STMT_END_F
+master-bin.000001	575	Table_map	1	616	table_id: # (test.t1)
+master-bin.000001	616	Write_rows	1	650	table_id: # flags: STMT_END_F
+master-bin.000001	650	Table_map	1	691	table_id: # (test.t1)
+master-bin.000001	691	Write_rows	1	725	table_id: # flags: STMT_END_F
+master-bin.000001	725	Table_map	1	766	table_id: # (test.t1)
+master-bin.000001	766	Write_rows	1	800	table_id: # flags: STMT_END_F
+master-bin.000001	800	Table_map	1	841	table_id: # (test.t1)
+master-bin.000001	841	Write_rows	1	875	table_id: # flags: STMT_END_F
+master-bin.000001	875	Table_map	1	916	table_id: # (test.t1)
+master-bin.000001	916	Write_rows	1	950	table_id: # flags: STMT_END_F
+master-bin.000001	950	Table_map	1	991	table_id: # (test.t1)
+master-bin.000001	991	Write_rows	1	1025	table_id: # flags: STMT_END_F
+master-bin.000001	1025	Table_map	1	1066	table_id: # (test.t1)
+master-bin.000001	1066	Write_rows	1	1100	table_id: # flags: STMT_END_F
+master-bin.000001	1100	Table_map	1	1141	table_id: # (test.t1)
+master-bin.000001	1141	Write_rows	1	1175	table_id: # flags: STMT_END_F
+master-bin.000001	1175	Table_map	1	1216	table_id: # (test.t1)
+master-bin.000001	1216	Write_rows	1	1250	table_id: # flags: STMT_END_F
+master-bin.000001	1250	Table_map	1	1291	table_id: # (test.t1)
+master-bin.000001	1291	Write_rows	1	1325	table_id: # flags: STMT_END_F
+master-bin.000001	1325	Table_map	1	1366	table_id: # (test.t1)
+master-bin.000001	1366	Write_rows	1	1400	table_id: # flags: STMT_END_F
+master-bin.000001	1400	Table_map	1	1441	table_id: # (test.t1)
+master-bin.000001	1441	Write_rows	1	1475	table_id: # flags: STMT_END_F
+master-bin.000001	1475	Table_map	1	1516	table_id: # (test.t1)
+master-bin.000001	1516	Write_rows	1	1550	table_id: # flags: STMT_END_F
+master-bin.000001	1550	Table_map	1	1591	table_id: # (test.t1)
+master-bin.000001	1591	Write_rows	1	1625	table_id: # flags: STMT_END_F
+master-bin.000001	1625	Table_map	1	1666	table_id: # (test.t1)
+master-bin.000001	1666	Write_rows	1	1700	table_id: # flags: STMT_END_F
+master-bin.000001	1700	Table_map	1	1741	table_id: # (test.t1)
+master-bin.000001	1741	Write_rows	1	1775	table_id: # flags: STMT_END_F
+master-bin.000001	1775	Table_map	1	1816	table_id: # (test.t1)
+master-bin.000001	1816	Write_rows	1	1850	table_id: # flags: STMT_END_F
+master-bin.000001	1850	Table_map	1	1891	table_id: # (test.t1)
+master-bin.000001	1891	Write_rows	1	1925	table_id: # flags: STMT_END_F
+master-bin.000001	1925	Table_map	1	1966	table_id: # (test.t1)
+master-bin.000001	1966	Write_rows	1	2000	table_id: # flags: STMT_END_F
+master-bin.000001	2000	Table_map	1	2041	table_id: # (test.t1)
+master-bin.000001	2041	Write_rows	1	2075	table_id: # flags: STMT_END_F
+master-bin.000001	2075	Table_map	1	2116	table_id: # (test.t1)
+master-bin.000001	2116	Write_rows	1	2150	table_id: # flags: STMT_END_F
+master-bin.000001	2150	Table_map	1	2191	table_id: # (test.t1)
+master-bin.000001	2191	Write_rows	1	2225	table_id: # flags: STMT_END_F
+master-bin.000001	2225	Table_map	1	2266	table_id: # (test.t1)
+master-bin.000001	2266	Write_rows	1	2300	table_id: # flags: STMT_END_F
+master-bin.000001	2300	Table_map	1	2341	table_id: # (test.t1)
+master-bin.000001	2341	Write_rows	1	2375	table_id: # flags: STMT_END_F
+master-bin.000001	2375	Table_map	1	2416	table_id: # (test.t1)
+master-bin.000001	2416	Write_rows	1	2450	table_id: # flags: STMT_END_F
+master-bin.000001	2450	Table_map	1	2491	table_id: # (test.t1)
+master-bin.000001	2491	Write_rows	1	2525	table_id: # flags: STMT_END_F
+master-bin.000001	2525	Table_map	1	2566	table_id: # (test.t1)
+master-bin.000001	2566	Write_rows	1	2600	table_id: # flags: STMT_END_F
+master-bin.000001	2600	Table_map	1	2641	table_id: # (test.t1)
+master-bin.000001	2641	Write_rows	1	2675	table_id: # flags: STMT_END_F
+master-bin.000001	2675	Table_map	1	2716	table_id: # (test.t1)
+master-bin.000001	2716	Write_rows	1	2750	table_id: # flags: STMT_END_F
+master-bin.000001	2750	Table_map	1	2791	table_id: # (test.t1)
+master-bin.000001	2791	Write_rows	1	2825	table_id: # flags: STMT_END_F
+master-bin.000001	2825	Table_map	1	2866	table_id: # (test.t1)
+master-bin.000001	2866	Write_rows	1	2900	table_id: # flags: STMT_END_F
+master-bin.000001	2900	Table_map	1	2941	table_id: # (test.t1)
+master-bin.000001	2941	Write_rows	1	2975	table_id: # flags: STMT_END_F
+master-bin.000001	2975	Table_map	1	3016	table_id: # (test.t1)
+master-bin.000001	3016	Write_rows	1	3050	table_id: # flags: STMT_END_F
+master-bin.000001	3050	Table_map	1	3091	table_id: # (test.t1)
+master-bin.000001	3091	Write_rows	1	3125	table_id: # flags: STMT_END_F
+master-bin.000001	3125	Table_map	1	3166	table_id: # (test.t1)
+master-bin.000001	3166	Write_rows	1	3200	table_id: # flags: STMT_END_F
+master-bin.000001	3200	Table_map	1	3241	table_id: # (test.t1)
+master-bin.000001	3241	Write_rows	1	3275	table_id: # flags: STMT_END_F
+master-bin.000001	3275	Table_map	1	3316	table_id: # (test.t1)
+master-bin.000001	3316	Write_rows	1	3350	table_id: # flags: STMT_END_F
+master-bin.000001	3350	Table_map	1	3391	table_id: # (test.t1)
+master-bin.000001	3391	Write_rows	1	3425	table_id: # flags: STMT_END_F
+master-bin.000001	3425	Table_map	1	3466	table_id: # (test.t1)
+master-bin.000001	3466	Write_rows	1	3500	table_id: # flags: STMT_END_F
+master-bin.000001	3500	Table_map	1	3541	table_id: # (test.t1)
+master-bin.000001	3541	Write_rows	1	3575	table_id: # flags: STMT_END_F
+master-bin.000001	3575	Table_map	1	3616	table_id: # (test.t1)
+master-bin.000001	3616	Write_rows	1	3650	table_id: # flags: STMT_END_F
+master-bin.000001	3650	Table_map	1	3691	table_id: # (test.t1)
+master-bin.000001	3691	Write_rows	1	3725	table_id: # flags: STMT_END_F
+master-bin.000001	3725	Table_map	1	3766	table_id: # (test.t1)
+master-bin.000001	3766	Write_rows	1	3800	table_id: # flags: STMT_END_F
+master-bin.000001	3800	Table_map	1	3841	table_id: # (test.t1)
+master-bin.000001	3841	Write_rows	1	3875	table_id: # flags: STMT_END_F
+master-bin.000001	3875	Table_map	1	3916	table_id: # (test.t1)
+master-bin.000001	3916	Write_rows	1	3950	table_id: # flags: STMT_END_F
+master-bin.000001	3950	Table_map	1	3991	table_id: # (test.t1)
+master-bin.000001	3991	Write_rows	1	4025	table_id: # flags: STMT_END_F
+master-bin.000001	4025	Table_map	1	4066	table_id: # (test.t1)
+master-bin.000001	4066	Write_rows	1	4100	table_id: # flags: STMT_END_F
+master-bin.000001	4100	Table_map	1	4141	table_id: # (test.t1)
+master-bin.000001	4141	Write_rows	1	4175	table_id: # flags: STMT_END_F
+master-bin.000001	4175	Table_map	1	4216	table_id: # (test.t1)
+master-bin.000001	4216	Write_rows	1	4250	table_id: # flags: STMT_END_F
+master-bin.000001	4250	Table_map	1	4291	table_id: # (test.t1)
+master-bin.000001	4291	Write_rows	1	4325	table_id: # flags: STMT_END_F
+master-bin.000001	4325	Table_map	1	4366	table_id: # (test.t1)
+master-bin.000001	4366	Write_rows	1	4400	table_id: # flags: STMT_END_F
+master-bin.000001	4400	Table_map	1	4441	table_id: # (test.t1)
+master-bin.000001	4441	Write_rows	1	4475	table_id: # flags: STMT_END_F
+master-bin.000001	4475	Table_map	1	4516	table_id: # (test.t1)
+master-bin.000001	4516	Write_rows	1	4550	table_id: # flags: STMT_END_F
+master-bin.000001	4550	Table_map	1	4591	table_id: # (test.t1)
+master-bin.000001	4591	Write_rows	1	4625	table_id: # flags: STMT_END_F
+master-bin.000001	4625	Table_map	1	4666	table_id: # (test.t1)
+master-bin.000001	4666	Write_rows	1	4700	table_id: # flags: STMT_END_F
+master-bin.000001	4700	Table_map	1	4741	table_id: # (test.t1)
+master-bin.000001	4741	Write_rows	1	4775	table_id: # flags: STMT_END_F
+master-bin.000001	4775	Table_map	1	4816	table_id: # (test.t1)
+master-bin.000001	4816	Write_rows	1	4850	table_id: # flags: STMT_END_F
+master-bin.000001	4850	Table_map	1	4891	table_id: # (test.t1)
+master-bin.000001	4891	Write_rows	1	4925	table_id: # flags: STMT_END_F
+master-bin.000001	4925	Table_map	1	4966	table_id: # (test.t1)
+master-bin.000001	4966	Write_rows	1	5000	table_id: # flags: STMT_END_F
+master-bin.000001	5000	Table_map	1	5041	table_id: # (test.t1)
+master-bin.000001	5041	Write_rows	1	5075	table_id: # flags: STMT_END_F
+master-bin.000001	5075	Table_map	1	5116	table_id: # (test.t1)
+master-bin.000001	5116	Write_rows	1	5150	table_id: # flags: STMT_END_F
+master-bin.000001	5150	Table_map	1	5191	table_id: # (test.t1)
+master-bin.000001	5191	Write_rows	1	5225	table_id: # flags: STMT_END_F
+master-bin.000001	5225	Table_map	1	5266	table_id: # (test.t1)
+master-bin.000001	5266	Write_rows	1	5300	table_id: # flags: STMT_END_F
+master-bin.000001	5300	Table_map	1	5341	table_id: # (test.t1)
+master-bin.000001	5341	Write_rows	1	5375	table_id: # flags: STMT_END_F
+master-bin.000001	5375	Table_map	1	5416	table_id: # (test.t1)
+master-bin.000001	5416	Write_rows	1	5450	table_id: # flags: STMT_END_F
+master-bin.000001	5450	Table_map	1	5491	table_id: # (test.t1)
+master-bin.000001	5491	Write_rows	1	5525	table_id: # flags: STMT_END_F
+master-bin.000001	5525	Table_map	1	5566	table_id: # (test.t1)
+master-bin.000001	5566	Write_rows	1	5600	table_id: # flags: STMT_END_F
+master-bin.000001	5600	Table_map	1	5641	table_id: # (test.t1)
+master-bin.000001	5641	Write_rows	1	5675	table_id: # flags: STMT_END_F
+master-bin.000001	5675	Table_map	1	5716	table_id: # (test.t1)
+master-bin.000001	5716	Write_rows	1	5750	table_id: # flags: STMT_END_F
+master-bin.000001	5750	Table_map	1	5791	table_id: # (test.t1)
+master-bin.000001	5791	Write_rows	1	5825	table_id: # flags: STMT_END_F
+master-bin.000001	5825	Table_map	1	5866	table_id: # (test.t1)
+master-bin.000001	5866	Write_rows	1	5900	table_id: # flags: STMT_END_F
+master-bin.000001	5900	Table_map	1	5941	table_id: # (test.t1)
+master-bin.000001	5941	Write_rows	1	5975	table_id: # flags: STMT_END_F
+master-bin.000001	5975	Table_map	1	6016	table_id: # (test.t1)
+master-bin.000001	6016	Write_rows	1	6050	table_id: # flags: STMT_END_F
+master-bin.000001	6050	Table_map	1	6091	table_id: # (test.t1)
+master-bin.000001	6091	Write_rows	1	6125	table_id: # flags: STMT_END_F
+master-bin.000001	6125	Table_map	1	6166	table_id: # (test.t1)
+master-bin.000001	6166	Write_rows	1	6200	table_id: # flags: STMT_END_F
+master-bin.000001	6200	Table_map	1	6241	table_id: # (test.t1)
+master-bin.000001	6241	Write_rows	1	6275	table_id: # flags: STMT_END_F
+master-bin.000001	6275	Table_map	1	6316	table_id: # (test.t1)
+master-bin.000001	6316	Write_rows	1	6350	table_id: # flags: STMT_END_F
+master-bin.000001	6350	Table_map	1	6391	table_id: # (test.t1)
+master-bin.000001	6391	Write_rows	1	6425	table_id: # flags: STMT_END_F
+master-bin.000001	6425	Table_map	1	6466	table_id: # (test.t1)
+master-bin.000001	6466	Write_rows	1	6500	table_id: # flags: STMT_END_F
+master-bin.000001	6500	Table_map	1	6541	table_id: # (test.t1)
+master-bin.000001	6541	Write_rows	1	6575	table_id: # flags: STMT_END_F
+master-bin.000001	6575	Table_map	1	6616	table_id: # (test.t1)
+master-bin.000001	6616	Write_rows	1	6650	table_id: # flags: STMT_END_F
+master-bin.000001	6650	Table_map	1	6691	table_id: # (test.t1)
+master-bin.000001	6691	Write_rows	1	6725	table_id: # flags: STMT_END_F
+master-bin.000001	6725	Table_map	1	6766	table_id: # (test.t1)
+master-bin.000001	6766	Write_rows	1	6800	table_id: # flags: STMT_END_F
+master-bin.000001	6800	Table_map	1	6841	table_id: # (test.t1)
+master-bin.000001	6841	Write_rows	1	6875	table_id: # flags: STMT_END_F
+master-bin.000001	6875	Table_map	1	6916	table_id: # (test.t1)
+master-bin.000001	6916	Write_rows	1	6950	table_id: # flags: STMT_END_F
+master-bin.000001	6950	Table_map	1	6991	table_id: # (test.t1)
+master-bin.000001	6991	Write_rows	1	7025	table_id: # flags: STMT_END_F
+master-bin.000001	7025	Table_map	1	7066	table_id: # (test.t1)
+master-bin.000001	7066	Write_rows	1	7100	table_id: # flags: STMT_END_F
+master-bin.000001	7100	Table_map	1	7141	table_id: # (test.t1)
+master-bin.000001	7141	Write_rows	1	7175	table_id: # flags: STMT_END_F
+master-bin.000001	7175	Table_map	1	7216	table_id: # (test.t1)
+master-bin.000001	7216	Write_rows	1	7250	table_id: # flags: STMT_END_F
+master-bin.000001	7250	Table_map	1	7291	table_id: # (test.t1)
+master-bin.000001	7291	Write_rows	1	7325	table_id: # flags: STMT_END_F
+master-bin.000001	7325	Table_map	1	7366	table_id: # (test.t1)
+master-bin.000001	7366	Write_rows	1	7400	table_id: # flags: STMT_END_F
+master-bin.000001	7400	Table_map	1	7441	table_id: # (test.t1)
+master-bin.000001	7441	Write_rows	1	7475	table_id: # flags: STMT_END_F
+master-bin.000001	7475	Table_map	1	7516	table_id: # (test.t1)
+master-bin.000001	7516	Write_rows	1	7550	table_id: # flags: STMT_END_F
+master-bin.000001	7550	Table_map	1	7591	table_id: # (test.t1)
+master-bin.000001	7591	Write_rows	1	7625	table_id: # flags: STMT_END_F
+master-bin.000001	7625	Table_map	1	7666	table_id: # (test.t1)
+master-bin.000001	7666	Write_rows	1	7700	table_id: # flags: STMT_END_F
+master-bin.000001	7700	Table_map	1	7741	table_id: # (test.t1)
+master-bin.000001	7741	Write_rows	1	7775	table_id: # flags: STMT_END_F
+master-bin.000001	7775	Table_map	1	7816	table_id: # (test.t1)
+master-bin.000001	7816	Write_rows	1	7850	table_id: # flags: STMT_END_F
+master-bin.000001	7850	Table_map	1	7891	table_id: # (test.t1)
+master-bin.000001	7891	Write_rows	1	7925	table_id: # flags: STMT_END_F
+master-bin.000001	7925	Table_map	1	7966	table_id: # (test.t1)
+master-bin.000001	7966	Write_rows	1	8000	table_id: # flags: STMT_END_F
+master-bin.000001	8000	Table_map	1	8041	table_id: # (test.t1)
+master-bin.000001	8041	Write_rows	1	8075	table_id: # flags: STMT_END_F
+master-bin.000001	8075	Table_map	1	8116	table_id: # (test.t1)
+master-bin.000001	8116	Write_rows	1	8150	table_id: # flags: STMT_END_F
+master-bin.000001	8150	Table_map	1	8191	table_id: # (test.t1)
+master-bin.000001	8191	Write_rows	1	8225	table_id: # flags: STMT_END_F
+master-bin.000001	8225	Table_map	1	8266	table_id: # (test.t1)
+master-bin.000001	8266	Write_rows	1	8300	table_id: # flags: STMT_END_F
+master-bin.000001	8300	Table_map	1	8341	table_id: # (test.t1)
+master-bin.000001	8341	Write_rows	1	8375	table_id: # flags: STMT_END_F
+master-bin.000001	8375	Table_map	1	8416	table_id: # (test.t1)
+master-bin.000001	8416	Write_rows	1	8450	table_id: # flags: STMT_END_F
+master-bin.000001	8450	Table_map	1	8491	table_id: # (test.t1)
+master-bin.000001	8491	Write_rows	1	8525	table_id: # flags: STMT_END_F
+master-bin.000001	8525	Table_map	1	8566	table_id: # (test.t1)
+master-bin.000001	8566	Write_rows	1	8600	table_id: # flags: STMT_END_F
+master-bin.000001	8600	Table_map	1	8641	table_id: # (test.t1)
+master-bin.000001	8641	Write_rows	1	8675	table_id: # flags: STMT_END_F
+master-bin.000001	8675	Table_map	1	8716	table_id: # (test.t1)
+master-bin.000001	8716	Write_rows	1	8750	table_id: # flags: STMT_END_F
+master-bin.000001	8750	Table_map	1	8791	table_id: # (test.t1)
+master-bin.000001	8791	Write_rows	1	8825	table_id: # flags: STMT_END_F
+master-bin.000001	8825	Table_map	1	8866	table_id: # (test.t1)
+master-bin.000001	8866	Write_rows	1	8900	table_id: # flags: STMT_END_F
+master-bin.000001	8900	Table_map	1	8941	table_id: # (test.t1)
+master-bin.000001	8941	Write_rows	1	8975	table_id: # flags: STMT_END_F
+master-bin.000001	8975	Table_map	1	9016	table_id: # (test.t1)
+master-bin.000001	9016	Write_rows	1	9050	table_id: # flags: STMT_END_F
+master-bin.000001	9050	Table_map	1	9091	table_id: # (test.t1)
+master-bin.000001	9091	Write_rows	1	9125	table_id: # flags: STMT_END_F
+master-bin.000001	9125	Table_map	1	9166	table_id: # (test.t1)
+master-bin.000001	9166	Write_rows	1	9200	table_id: # flags: STMT_END_F
+master-bin.000001	9200	Table_map	1	9241	table_id: # (test.t1)
+master-bin.000001	9241	Write_rows	1	9275	table_id: # flags: STMT_END_F
+master-bin.000001	9275	Table_map	1	9316	table_id: # (test.t1)
+master-bin.000001	9316	Write_rows	1	9350	table_id: # flags: STMT_END_F
+master-bin.000001	9350	Table_map	1	9391	table_id: # (test.t1)
+master-bin.000001	9391	Write_rows	1	9425	table_id: # flags: STMT_END_F
+master-bin.000001	9425	Table_map	1	9466	table_id: # (test.t1)
+master-bin.000001	9466	Write_rows	1	9500	table_id: # flags: STMT_END_F
+master-bin.000001	9500	Table_map	1	9541	table_id: # (test.t1)
+master-bin.000001	9541	Write_rows	1	9575	table_id: # flags: STMT_END_F
+master-bin.000001	9575	Table_map	1	9616	table_id: # (test.t1)
+master-bin.000001	9616	Write_rows	1	9650	table_id: # flags: STMT_END_F
+master-bin.000001	9650	Table_map	1	9691	table_id: # (test.t1)
+master-bin.000001	9691	Write_rows	1	9725	table_id: # flags: STMT_END_F
+master-bin.000001	9725	Table_map	1	9766	table_id: # (test.t1)
+master-bin.000001	9766	Write_rows	1	9800	table_id: # flags: STMT_END_F
+master-bin.000001	9800	Table_map	1	9841	table_id: # (test.t1)
+master-bin.000001	9841	Write_rows	1	9875	table_id: # flags: STMT_END_F
+master-bin.000001	9875	Table_map	1	9916	table_id: # (test.t1)
+master-bin.000001	9916	Write_rows	1	9950	table_id: # flags: STMT_END_F
+master-bin.000001	9950	Table_map	1	9991	table_id: # (test.t1)
+master-bin.000001	9991	Write_rows	1	10025	table_id: # flags: STMT_END_F
+master-bin.000001	10025	Table_map	1	10066	table_id: # (test.t1)
+master-bin.000001	10066	Write_rows	1	10100	table_id: # flags: STMT_END_F
+master-bin.000001	10100	Table_map	1	10141	table_id: # (test.t1)
+master-bin.000001	10141	Write_rows	1	10175	table_id: # flags: STMT_END_F
+master-bin.000001	10175	Table_map	1	10216	table_id: # (test.t1)
+master-bin.000001	10216	Write_rows	1	10250	table_id: # flags: STMT_END_F
+master-bin.000001	10250	Table_map	1	10291	table_id: # (test.t1)
+master-bin.000001	10291	Write_rows	1	10325	table_id: # flags: STMT_END_F
+master-bin.000001	10325	Table_map	1	10366	table_id: # (test.t1)
+master-bin.000001	10366	Write_rows	1	10400	table_id: # flags: STMT_END_F
+master-bin.000001	10400	Table_map	1	10441	table_id: # (test.t1)
+master-bin.000001	10441	Write_rows	1	10475	table_id: # flags: STMT_END_F
+master-bin.000001	10475	Table_map	1	10516	table_id: # (test.t1)
+master-bin.000001	10516	Write_rows	1	10550	table_id: # flags: STMT_END_F
+master-bin.000001	10550	Table_map	1	10591	table_id: # (test.t1)
+master-bin.000001	10591	Write_rows	1	10625	table_id: # flags: STMT_END_F
+master-bin.000001	10625	Table_map	1	10666	table_id: # (test.t1)
+master-bin.000001	10666	Write_rows	1	10700	table_id: # flags: STMT_END_F
+master-bin.000001	10700	Table_map	1	10741	table_id: # (test.t1)
+master-bin.000001	10741	Write_rows	1	10775	table_id: # flags: STMT_END_F
+master-bin.000001	10775	Table_map	1	10816	table_id: # (test.t1)
+master-bin.000001	10816	Write_rows	1	10850	table_id: # flags: STMT_END_F
+master-bin.000001	10850	Table_map	1	10891	table_id: # (test.t1)
+master-bin.000001	10891	Write_rows	1	10925	table_id: # flags: STMT_END_F
+master-bin.000001	10925	Table_map	1	10966	table_id: # (test.t1)
+master-bin.000001	10966	Write_rows	1	11000	table_id: # flags: STMT_END_F
+master-bin.000001	11000	Table_map	1	11041	table_id: # (test.t1)
+master-bin.000001	11041	Write_rows	1	11075	table_id: # flags: STMT_END_F
+master-bin.000001	11075	Table_map	1	11116	table_id: # (test.t1)
+master-bin.000001	11116	Write_rows	1	11150	table_id: # flags: STMT_END_F
+master-bin.000001	11150	Table_map	1	11191	table_id: # (test.t1)
+master-bin.000001	11191	Write_rows	1	11225	table_id: # flags: STMT_END_F
+master-bin.000001	11225	Table_map	1	11266	table_id: # (test.t1)
+master-bin.000001	11266	Write_rows	1	11300	table_id: # flags: STMT_END_F
+master-bin.000001	11300	Table_map	1	11341	table_id: # (test.t1)
+master-bin.000001	11341	Write_rows	1	11375	table_id: # flags: STMT_END_F
+master-bin.000001	11375	Table_map	1	11416	table_id: # (test.t1)
+master-bin.000001	11416	Write_rows	1	11450	table_id: # flags: STMT_END_F
+master-bin.000001	11450	Table_map	1	11491	table_id: # (test.t1)
+master-bin.000001	11491	Write_rows	1	11525	table_id: # flags: STMT_END_F
+master-bin.000001	11525	Table_map	1	11566	table_id: # (test.t1)
+master-bin.000001	11566	Write_rows	1	11600	table_id: # flags: STMT_END_F
+master-bin.000001	11600	Table_map	1	11641	table_id: # (test.t1)
+master-bin.000001	11641	Write_rows	1	11675	table_id: # flags: STMT_END_F
+master-bin.000001	11675	Table_map	1	11716	table_id: # (test.t1)
+master-bin.000001	11716	Write_rows	1	11750	table_id: # flags: STMT_END_F
+master-bin.000001	11750	Table_map	1	11791	table_id: # (test.t1)
+master-bin.000001	11791	Write_rows	1	11825	table_id: # flags: STMT_END_F
+master-bin.000001	11825	Table_map	1	11866	table_id: # (test.t1)
+master-bin.000001	11866	Write_rows	1	11900	table_id: # flags: STMT_END_F
+master-bin.000001	11900	Table_map	1	11941	table_id: # (test.t1)
+master-bin.000001	11941	Write_rows	1	11975	table_id: # flags: STMT_END_F
+master-bin.000001	11975	Table_map	1	12016	table_id: # (test.t1)
+master-bin.000001	12016	Write_rows	1	12050	table_id: # flags: STMT_END_F
+master-bin.000001	12050	Table_map	1	12091	table_id: # (test.t1)
+master-bin.000001	12091	Write_rows	1	12125	table_id: # flags: STMT_END_F
+master-bin.000001	12125	Table_map	1	12166	table_id: # (test.t1)
+master-bin.000001	12166	Write_rows	1	12200	table_id: # flags: STMT_END_F
+master-bin.000001	12200	Table_map	1	12241	table_id: # (test.t1)
+master-bin.000001	12241	Write_rows	1	12275	table_id: # flags: STMT_END_F
+master-bin.000001	12275	Table_map	1	12316	table_id: # (test.t1)
+master-bin.000001	12316	Write_rows	1	12350	table_id: # flags: STMT_END_F
+master-bin.000001	12350	Table_map	1	12391	table_id: # (test.t1)
+master-bin.000001	12391	Write_rows	1	12425	table_id: # flags: STMT_END_F
+master-bin.000001	12425	Table_map	1	12466	table_id: # (test.t1)
+master-bin.000001	12466	Write_rows	1	12500	table_id: # flags: STMT_END_F
+master-bin.000001	12500	Table_map	1	12541	table_id: # (test.t1)
+master-bin.000001	12541	Write_rows	1	12575	table_id: # flags: STMT_END_F
+master-bin.000001	12575	Table_map	1	12616	table_id: # (test.t1)
+master-bin.000001	12616	Write_rows	1	12650	table_id: # flags: STMT_END_F
+master-bin.000001	12650	Table_map	1	12691	table_id: # (test.t1)
+master-bin.000001	12691	Write_rows	1	12725	table_id: # flags: STMT_END_F
+master-bin.000001	12725	Table_map	1	12766	table_id: # (test.t1)
+master-bin.000001	12766	Write_rows	1	12800	table_id: # flags: STMT_END_F
+master-bin.000001	12800	Table_map	1	12841	table_id: # (test.t1)
+master-bin.000001	12841	Write_rows	1	12875	table_id: # flags: STMT_END_F
+master-bin.000001	12875	Table_map	1	12916	table_id: # (test.t1)
+master-bin.000001	12916	Write_rows	1	12950	table_id: # flags: STMT_END_F
+master-bin.000001	12950	Table_map	1	12991	table_id: # (test.t1)
+master-bin.000001	12991	Write_rows	1	13025	table_id: # flags: STMT_END_F
+master-bin.000001	13025	Table_map	1	13066	table_id: # (test.t1)
+master-bin.000001	13066	Write_rows	1	13100	table_id: # flags: STMT_END_F
+master-bin.000001	13100	Table_map	1	13141	table_id: # (test.t1)
+master-bin.000001	13141	Write_rows	1	13175	table_id: # flags: STMT_END_F
+master-bin.000001	13175	Table_map	1	13216	table_id: # (test.t1)
+master-bin.000001	13216	Write_rows	1	13250	table_id: # flags: STMT_END_F
+master-bin.000001	13250	Table_map	1	13291	table_id: # (test.t1)
+master-bin.000001	13291	Write_rows	1	13325	table_id: # flags: STMT_END_F
+master-bin.000001	13325	Table_map	1	13366	table_id: # (test.t1)
+master-bin.000001	13366	Write_rows	1	13400	table_id: # flags: STMT_END_F
+master-bin.000001	13400	Table_map	1	13441	table_id: # (test.t1)
+master-bin.000001	13441	Write_rows	1	13475	table_id: # flags: STMT_END_F
+master-bin.000001	13475	Table_map	1	13516	table_id: # (test.t1)
+master-bin.000001	13516	Write_rows	1	13550	table_id: # flags: STMT_END_F
+master-bin.000001	13550	Table_map	1	13591	table_id: # (test.t1)
+master-bin.000001	13591	Write_rows	1	13625	table_id: # flags: STMT_END_F
+master-bin.000001	13625	Table_map	1	13666	table_id: # (test.t1)
+master-bin.000001	13666	Write_rows	1	13700	table_id: # flags: STMT_END_F
+master-bin.000001	13700	Table_map	1	13741	table_id: # (test.t1)
+master-bin.000001	13741	Write_rows	1	13775	table_id: # flags: STMT_END_F
+master-bin.000001	13775	Table_map	1	13816	table_id: # (test.t1)
+master-bin.000001	13816	Write_rows	1	13850	table_id: # flags: STMT_END_F
+master-bin.000001	13850	Table_map	1	13891	table_id: # (test.t1)
+master-bin.000001	13891	Write_rows	1	13925	table_id: # flags: STMT_END_F
+master-bin.000001	13925	Table_map	1	13966	table_id: # (test.t1)
+master-bin.000001	13966	Write_rows	1	14000	table_id: # flags: STMT_END_F
+master-bin.000001	14000	Table_map	1	14041	table_id: # (test.t1)
+master-bin.000001	14041	Write_rows	1	14075	table_id: # flags: STMT_END_F
+master-bin.000001	14075	Table_map	1	14116	table_id: # (test.t1)
+master-bin.000001	14116	Write_rows	1	14150	table_id: # flags: STMT_END_F
+master-bin.000001	14150	Table_map	1	14191	table_id: # (test.t1)
+master-bin.000001	14191	Write_rows	1	14225	table_id: # flags: STMT_END_F
+master-bin.000001	14225	Table_map	1	14266	table_id: # (test.t1)
+master-bin.000001	14266	Write_rows	1	14300	table_id: # flags: STMT_END_F
+master-bin.000001	14300	Table_map	1	14341	table_id: # (test.t1)
+master-bin.000001	14341	Write_rows	1	14375	table_id: # flags: STMT_END_F
+master-bin.000001	14375	Table_map	1	14416	table_id: # (test.t1)
+master-bin.000001	14416	Write_rows	1	14450	table_id: # flags: STMT_END_F
+master-bin.000001	14450	Table_map	1	14491	table_id: # (test.t1)
+master-bin.000001	14491	Write_rows	1	14525	table_id: # flags: STMT_END_F
+master-bin.000001	14525	Table_map	1	14566	table_id: # (test.t1)
+master-bin.000001	14566	Write_rows	1	14600	table_id: # flags: STMT_END_F
+master-bin.000001	14600	Table_map	1	14641	table_id: # (test.t1)
+master-bin.000001	14641	Write_rows	1	14675	table_id: # flags: STMT_END_F
+master-bin.000001	14675	Table_map	1	14716	table_id: # (test.t1)
+master-bin.000001	14716	Write_rows	1	14750	table_id: # flags: STMT_END_F
+master-bin.000001	14750	Table_map	1	14791	table_id: # (test.t1)
+master-bin.000001	14791	Write_rows	1	14825	table_id: # flags: STMT_END_F
+master-bin.000001	14825	Table_map	1	14866	table_id: # (test.t1)
+master-bin.000001	14866	Write_rows	1	14900	table_id: # flags: STMT_END_F
+master-bin.000001	14900	Table_map	1	14941	table_id: # (test.t1)
+master-bin.000001	14941	Write_rows	1	14975	table_id: # flags: STMT_END_F
+master-bin.000001	14975	Table_map	1	15016	table_id: # (test.t1)
+master-bin.000001	15016	Write_rows	1	15050	table_id: # flags: STMT_END_F
+master-bin.000001	15050	Table_map	1	15091	table_id: # (test.t1)
+master-bin.000001	15091	Write_rows	1	15125	table_id: # flags: STMT_END_F
+master-bin.000001	15125	Table_map	1	15166	table_id: # (test.t1)
+master-bin.000001	15166	Write_rows	1	15200	table_id: # flags: STMT_END_F
+master-bin.000001	15200	Table_map	1	15241	table_id: # (test.t1)
+master-bin.000001	15241	Write_rows	1	15275	table_id: # flags: STMT_END_F
+master-bin.000001	15275	Table_map	1	15316	table_id: # (test.t1)
+master-bin.000001	15316	Write_rows	1	15350	table_id: # flags: STMT_END_F
+master-bin.000001	15350	Table_map	1	15391	table_id: # (test.t1)
+master-bin.000001	15391	Write_rows	1	15425	table_id: # flags: STMT_END_F
+master-bin.000001	15425	Table_map	1	15466	table_id: # (test.t1)
+master-bin.000001	15466	Write_rows	1	15500	table_id: # flags: STMT_END_F
+master-bin.000001	15500	Table_map	1	15541	table_id: # (test.t1)
+master-bin.000001	15541	Write_rows	1	15575	table_id: # flags: STMT_END_F
+master-bin.000001	15575	Table_map	1	15616	table_id: # (test.t1)
+master-bin.000001	15616	Write_rows	1	15650	table_id: # flags: STMT_END_F
+master-bin.000001	15650	Table_map	1	15691	table_id: # (test.t1)
+master-bin.000001	15691	Write_rows	1	15725	table_id: # flags: STMT_END_F
+master-bin.000001	15725	Table_map	1	15766	table_id: # (test.t1)
+master-bin.000001	15766	Write_rows	1	15800	table_id: # flags: STMT_END_F
+master-bin.000001	15800	Table_map	1	15841	table_id: # (test.t1)
+master-bin.000001	15841	Write_rows	1	15875	table_id: # flags: STMT_END_F
+master-bin.000001	15875	Table_map	1	15916	table_id: # (test.t1)
+master-bin.000001	15916	Write_rows	1	15950	table_id: # flags: STMT_END_F
+master-bin.000001	15950	Table_map	1	15991	table_id: # (test.t1)
+master-bin.000001	15991	Write_rows	1	16025	table_id: # flags: STMT_END_F
+master-bin.000001	16025	Table_map	1	16066	table_id: # (test.t1)
+master-bin.000001	16066	Write_rows	1	16100	table_id: # flags: STMT_END_F
+master-bin.000001	16100	Table_map	1	16141	table_id: # (test.t1)
+master-bin.000001	16141	Write_rows	1	16175	table_id: # flags: STMT_END_F
+master-bin.000001	16175	Table_map	1	16216	table_id: # (test.t1)
+master-bin.000001	16216	Write_rows	1	16250	table_id: # flags: STMT_END_F
+master-bin.000001	16250	Table_map	1	16291	table_id: # (test.t1)
+master-bin.000001	16291	Write_rows	1	16325	table_id: # flags: STMT_END_F
+master-bin.000001	16325	Table_map	1	16366	table_id: # (test.t1)
+master-bin.000001	16366	Write_rows	1	16400	table_id: # flags: STMT_END_F
+master-bin.000001	16400	Table_map	1	16441	table_id: # (test.t1)
+master-bin.000001	16441	Write_rows	1	16475	table_id: # flags: STMT_END_F
+master-bin.000001	16475	Table_map	1	16516	table_id: # (test.t1)
+master-bin.000001	16516	Write_rows	1	16550	table_id: # flags: STMT_END_F
+master-bin.000001	16550	Table_map	1	16591	table_id: # (test.t1)
+master-bin.000001	16591	Write_rows	1	16625	table_id: # flags: STMT_END_F
+master-bin.000001	16625	Table_map	1	16666	table_id: # (test.t1)
+master-bin.000001	16666	Write_rows	1	16700	table_id: # flags: STMT_END_F
+master-bin.000001	16700	Table_map	1	16741	table_id: # (test.t1)
+master-bin.000001	16741	Write_rows	1	16775	table_id: # flags: STMT_END_F
+master-bin.000001	16775	Table_map	1	16816	table_id: # (test.t1)
+master-bin.000001	16816	Write_rows	1	16850	table_id: # flags: STMT_END_F
+master-bin.000001	16850	Table_map	1	16891	table_id: # (test.t1)
+master-bin.000001	16891	Write_rows	1	16925	table_id: # flags: STMT_END_F
+master-bin.000001	16925	Table_map	1	16966	table_id: # (test.t1)
+master-bin.000001	16966	Write_rows	1	17000	table_id: # flags: STMT_END_F
+master-bin.000001	17000	Table_map	1	17041	table_id: # (test.t1)
+master-bin.000001	17041	Write_rows	1	17075	table_id: # flags: STMT_END_F
+master-bin.000001	17075	Table_map	1	17116	table_id: # (test.t1)
+master-bin.000001	17116	Write_rows	1	17150	table_id: # flags: STMT_END_F
+master-bin.000001	17150	Table_map	1	17191	table_id: # (test.t1)
+master-bin.000001	17191	Write_rows	1	17225	table_id: # flags: STMT_END_F
+master-bin.000001	17225	Table_map	1	17266	table_id: # (test.t1)
+master-bin.000001	17266	Write_rows	1	17300	table_id: # flags: STMT_END_F
+master-bin.000001	17300	Table_map	1	17341	table_id: # (test.t1)
+master-bin.000001	17341	Write_rows	1	17375	table_id: # flags: STMT_END_F
+master-bin.000001	17375	Table_map	1	17416	table_id: # (test.t1)
+master-bin.000001	17416	Write_rows	1	17450	table_id: # flags: STMT_END_F
+master-bin.000001	17450	Table_map	1	17491	table_id: # (test.t1)
+master-bin.000001	17491	Write_rows	1	17525	table_id: # flags: STMT_END_F
+master-bin.000001	17525	Table_map	1	17566	table_id: # (test.t1)
+master-bin.000001	17566	Write_rows	1	17600	table_id: # flags: STMT_END_F
+master-bin.000001	17600	Table_map	1	17641	table_id: # (test.t1)
+master-bin.000001	17641	Write_rows	1	17675	table_id: # flags: STMT_END_F
+master-bin.000001	17675	Table_map	1	17716	table_id: # (test.t1)
+master-bin.000001	17716	Write_rows	1	17750	table_id: # flags: STMT_END_F
+master-bin.000001	17750	Table_map	1	17791	table_id: # (test.t1)
+master-bin.000001	17791	Write_rows	1	17825	table_id: # flags: STMT_END_F
+master-bin.000001	17825	Table_map	1	17866	table_id: # (test.t1)
+master-bin.000001	17866	Write_rows	1	17900	table_id: # flags: STMT_END_F
+master-bin.000001	17900	Table_map	1	17941	table_id: # (test.t1)
+master-bin.000001	17941	Write_rows	1	17975	table_id: # flags: STMT_END_F
+master-bin.000001	17975	Table_map	1	18016	table_id: # (test.t1)
+master-bin.000001	18016	Write_rows	1	18050	table_id: # flags: STMT_END_F
+master-bin.000001	18050	Table_map	1	18091	table_id: # (test.t1)
+master-bin.000001	18091	Write_rows	1	18125	table_id: # flags: STMT_END_F
+master-bin.000001	18125	Table_map	1	18166	table_id: # (test.t1)
+master-bin.000001	18166	Write_rows	1	18200	table_id: # flags: STMT_END_F
+master-bin.000001	18200	Table_map	1	18241	table_id: # (test.t1)
+master-bin.000001	18241	Write_rows	1	18275	table_id: # flags: STMT_END_F
+master-bin.000001	18275	Table_map	1	18316	table_id: # (test.t1)
+master-bin.000001	18316	Write_rows	1	18350	table_id: # flags: STMT_END_F
+master-bin.000001	18350	Table_map	1	18391	table_id: # (test.t1)
+master-bin.000001	18391	Write_rows	1	18425	table_id: # flags: STMT_END_F
+master-bin.000001	18425	Table_map	1	18466	table_id: # (test.t1)
+master-bin.000001	18466	Write_rows	1	18500	table_id: # flags: STMT_END_F
+master-bin.000001	18500	Table_map	1	18541	table_id: # (test.t1)
+master-bin.000001	18541	Write_rows	1	18575	table_id: # flags: STMT_END_F
+master-bin.000001	18575	Table_map	1	18616	table_id: # (test.t1)
+master-bin.000001	18616	Write_rows	1	18650	table_id: # flags: STMT_END_F
+master-bin.000001	18650	Table_map	1	18691	table_id: # (test.t1)
+master-bin.000001	18691	Write_rows	1	18725	table_id: # flags: STMT_END_F
+master-bin.000001	18725	Table_map	1	18766	table_id: # (test.t1)
+master-bin.000001	18766	Write_rows	1	18800	table_id: # flags: STMT_END_F
+master-bin.000001	18800	Table_map	1	18841	table_id: # (test.t1)
+master-bin.000001	18841	Write_rows	1	18875	table_id: # flags: STMT_END_F
+master-bin.000001	18875	Table_map	1	18916	table_id: # (test.t1)
+master-bin.000001	18916	Write_rows	1	18950	table_id: # flags: STMT_END_F
+master-bin.000001	18950	Table_map	1	18991	table_id: # (test.t1)
+master-bin.000001	18991	Write_rows	1	19025	table_id: # flags: STMT_END_F
+master-bin.000001	19025	Table_map	1	19066	table_id: # (test.t1)
+master-bin.000001	19066	Write_rows	1	19100	table_id: # flags: STMT_END_F
+master-bin.000001	19100	Table_map	1	19141	table_id: # (test.t1)
+master-bin.000001	19141	Write_rows	1	19175	table_id: # flags: STMT_END_F
+master-bin.000001	19175	Table_map	1	19216	table_id: # (test.t1)
+master-bin.000001	19216	Write_rows	1	19250	table_id: # flags: STMT_END_F
+master-bin.000001	19250	Table_map	1	19291	table_id: # (test.t1)
+master-bin.000001	19291	Write_rows	1	19325	table_id: # flags: STMT_END_F
+master-bin.000001	19325	Table_map	1	19366	table_id: # (test.t1)
+master-bin.000001	19366	Write_rows	1	19400	table_id: # flags: STMT_END_F
+master-bin.000001	19400	Table_map	1	19441	table_id: # (test.t1)
+master-bin.000001	19441	Write_rows	1	19475	table_id: # flags: STMT_END_F
+master-bin.000001	19475	Table_map	1	19516	table_id: # (test.t1)
+master-bin.000001	19516	Write_rows	1	19550	table_id: # flags: STMT_END_F
+master-bin.000001	19550	Table_map	1	19591	table_id: # (test.t1)
+master-bin.000001	19591	Write_rows	1	19625	table_id: # flags: STMT_END_F
+master-bin.000001	19625	Table_map	1	19666	table_id: # (test.t1)
+master-bin.000001	19666	Write_rows	1	19700	table_id: # flags: STMT_END_F
+master-bin.000001	19700	Table_map	1	19741	table_id: # (test.t1)
+master-bin.000001	19741	Write_rows	1	19775	table_id: # flags: STMT_END_F
+master-bin.000001	19775	Table_map	1	19816	table_id: # (test.t1)
+master-bin.000001	19816	Write_rows	1	19850	table_id: # flags: STMT_END_F
+master-bin.000001	19850	Table_map	1	19891	table_id: # (test.t1)
+master-bin.000001	19891	Write_rows	1	19925	table_id: # flags: STMT_END_F
+master-bin.000001	19925	Table_map	1	19966	table_id: # (test.t1)
+master-bin.000001	19966	Write_rows	1	20000	table_id: # flags: STMT_END_F
+master-bin.000001	20000	Table_map	1	20041	table_id: # (test.t1)
+master-bin.000001	20041	Write_rows	1	20075	table_id: # flags: STMT_END_F
+master-bin.000001	20075	Table_map	1	20116	table_id: # (test.t1)
+master-bin.000001	20116	Write_rows	1	20150	table_id: # flags: STMT_END_F
+master-bin.000001	20150	Table_map	1	20191	table_id: # (test.t1)
+master-bin.000001	20191	Write_rows	1	20225	table_id: # flags: STMT_END_F
+master-bin.000001	20225	Table_map	1	20266	table_id: # (test.t1)
+master-bin.000001	20266	Write_rows	1	20300	table_id: # flags: STMT_END_F
+master-bin.000001	20300	Table_map	1	20341	table_id: # (test.t1)
+master-bin.000001	20341	Write_rows	1	20375	table_id: # flags: STMT_END_F
+master-bin.000001	20375	Table_map	1	20416	table_id: # (test.t1)
+master-bin.000001	20416	Write_rows	1	20450	table_id: # flags: STMT_END_F
+master-bin.000001	20450	Table_map	1	20491	table_id: # (test.t1)
+master-bin.000001	20491	Write_rows	1	20525	table_id: # flags: STMT_END_F
+master-bin.000001	20525	Table_map	1	20566	table_id: # (test.t1)
+master-bin.000001	20566	Write_rows	1	20600	table_id: # flags: STMT_END_F
+master-bin.000001	20600	Table_map	1	20641	table_id: # (test.t1)
+master-bin.000001	20641	Write_rows	1	20675	table_id: # flags: STMT_END_F
+master-bin.000001	20675	Table_map	1	20716	table_id: # (test.t1)
+master-bin.000001	20716	Write_rows	1	20750	table_id: # flags: STMT_END_F
+master-bin.000001	20750	Table_map	1	20791	table_id: # (test.t1)
+master-bin.000001	20791	Write_rows	1	20825	table_id: # flags: STMT_END_F
+master-bin.000001	20825	Table_map	1	20866	table_id: # (test.t1)
+master-bin.000001	20866	Write_rows	1	20900	table_id: # flags: STMT_END_F
+master-bin.000001	20900	Table_map	1	20941	table_id: # (test.t1)
+master-bin.000001	20941	Write_rows	1	20975	table_id: # flags: STMT_END_F
+master-bin.000001	20975	Table_map	1	21016	table_id: # (test.t1)
+master-bin.000001	21016	Write_rows	1	21050	table_id: # flags: STMT_END_F
+master-bin.000001	21050	Table_map	1	21091	table_id: # (test.t1)
+master-bin.000001	21091	Write_rows	1	21125	table_id: # flags: STMT_END_F
+master-bin.000001	21125	Table_map	1	21166	table_id: # (test.t1)
+master-bin.000001	21166	Write_rows	1	21200	table_id: # flags: STMT_END_F
+master-bin.000001	21200	Table_map	1	21241	table_id: # (test.t1)
+master-bin.000001	21241	Write_rows	1	21275	table_id: # flags: STMT_END_F
+master-bin.000001	21275	Table_map	1	21316	table_id: # (test.t1)
+master-bin.000001	21316	Write_rows	1	21350	table_id: # flags: STMT_END_F
+master-bin.000001	21350	Table_map	1	21391	table_id: # (test.t1)
+master-bin.000001	21391	Write_rows	1	21425	table_id: # flags: STMT_END_F
+master-bin.000001	21425	Table_map	1	21466	table_id: # (test.t1)
+master-bin.000001	21466	Write_rows	1	21500	table_id: # flags: STMT_END_F
+master-bin.000001	21500	Table_map	1	21541	table_id: # (test.t1)
+master-bin.000001	21541	Write_rows	1	21575	table_id: # flags: STMT_END_F
+master-bin.000001	21575	Table_map	1	21616	table_id: # (test.t1)
+master-bin.000001	21616	Write_rows	1	21650	table_id: # flags: STMT_END_F
+master-bin.000001	21650	Table_map	1	21691	table_id: # (test.t1)
+master-bin.000001	21691	Write_rows	1	21725	table_id: # flags: STMT_END_F
+master-bin.000001	21725	Table_map	1	21766	table_id: # (test.t1)
+master-bin.000001	21766	Write_rows	1	21800	table_id: # flags: STMT_END_F
+master-bin.000001	21800	Table_map	1	21841	table_id: # (test.t1)
+master-bin.000001	21841	Write_rows	1	21875	table_id: # flags: STMT_END_F
+master-bin.000001	21875	Table_map	1	21916	table_id: # (test.t1)
+master-bin.000001	21916	Write_rows	1	21950	table_id: # flags: STMT_END_F
+master-bin.000001	21950	Table_map	1	21991	table_id: # (test.t1)
+master-bin.000001	21991	Write_rows	1	22025	table_id: # flags: STMT_END_F
+master-bin.000001	22025	Table_map	1	22066	table_id: # (test.t1)
+master-bin.000001	22066	Write_rows	1	22100	table_id: # flags: STMT_END_F
+master-bin.000001	22100	Table_map	1	22141	table_id: # (test.t1)
+master-bin.000001	22141	Write_rows	1	22175	table_id: # flags: STMT_END_F
+master-bin.000001	22175	Table_map	1	22216	table_id: # (test.t1)
+master-bin.000001	22216	Write_rows	1	22250	table_id: # flags: STMT_END_F
+master-bin.000001	22250	Table_map	1	22291	table_id: # (test.t1)
+master-bin.000001	22291	Write_rows	1	22325	table_id: # flags: STMT_END_F
+master-bin.000001	22325	Table_map	1	22366	table_id: # (test.t1)
+master-bin.000001	22366	Write_rows	1	22400	table_id: # flags: STMT_END_F
+master-bin.000001	22400	Table_map	1	22441	table_id: # (test.t1)
+master-bin.000001	22441	Write_rows	1	22475	table_id: # flags: STMT_END_F
+master-bin.000001	22475	Table_map	1	22516	table_id: # (test.t1)
+master-bin.000001	22516	Write_rows	1	22550	table_id: # flags: STMT_END_F
+master-bin.000001	22550	Table_map	1	22591	table_id: # (test.t1)
+master-bin.000001	22591	Write_rows	1	22625	table_id: # flags: STMT_END_F
+master-bin.000001	22625	Table_map	1	22666	table_id: # (test.t1)
+master-bin.000001	22666	Write_rows	1	22700	table_id: # flags: STMT_END_F
+master-bin.000001	22700	Table_map	1	22741	table_id: # (test.t1)
+master-bin.000001	22741	Write_rows	1	22775	table_id: # flags: STMT_END_F
+master-bin.000001	22775	Table_map	1	22816	table_id: # (test.t1)
+master-bin.000001	22816	Write_rows	1	22850	table_id: # flags: STMT_END_F
+master-bin.000001	22850	Table_map	1	22891	table_id: # (test.t1)
+master-bin.000001	22891	Write_rows	1	22925	table_id: # flags: STMT_END_F
+master-bin.000001	22925	Table_map	1	22966	table_id: # (test.t1)
+master-bin.000001	22966	Write_rows	1	23000	table_id: # flags: STMT_END_F
+master-bin.000001	23000	Table_map	1	23041	table_id: # (test.t1)
+master-bin.000001	23041	Write_rows	1	23075	table_id: # flags: STMT_END_F
+master-bin.000001	23075	Table_map	1	23116	table_id: # (test.t1)
+master-bin.000001	23116	Write_rows	1	23150	table_id: # flags: STMT_END_F
+master-bin.000001	23150	Table_map	1	23191	table_id: # (test.t1)
+master-bin.000001	23191	Write_rows	1	23225	table_id: # flags: STMT_END_F
+master-bin.000001	23225	Table_map	1	23266	table_id: # (test.t1)
+master-bin.000001	23266	Write_rows	1	23300	table_id: # flags: STMT_END_F
+master-bin.000001	23300	Table_map	1	23341	table_id: # (test.t1)
+master-bin.000001	23341	Write_rows	1	23375	table_id: # flags: STMT_END_F
+master-bin.000001	23375	Table_map	1	23416	table_id: # (test.t1)
+master-bin.000001	23416	Write_rows	1	23450	table_id: # flags: STMT_END_F
+master-bin.000001	23450	Table_map	1	23491	table_id: # (test.t1)
+master-bin.000001	23491	Write_rows	1	23525	table_id: # flags: STMT_END_F
+master-bin.000001	23525	Table_map	1	23566	table_id: # (test.t1)
+master-bin.000001	23566	Write_rows	1	23600	table_id: # flags: STMT_END_F
+master-bin.000001	23600	Table_map	1	23641	table_id: # (test.t1)
+master-bin.000001	23641	Write_rows	1	23675	table_id: # flags: STMT_END_F
+master-bin.000001	23675	Table_map	1	23716	table_id: # (test.t1)
+master-bin.000001	23716	Write_rows	1	23750	table_id: # flags: STMT_END_F
+master-bin.000001	23750	Table_map	1	23791	table_id: # (test.t1)
+master-bin.000001	23791	Write_rows	1	23825	table_id: # flags: STMT_END_F
+master-bin.000001	23825	Table_map	1	23866	table_id: # (test.t1)
+master-bin.000001	23866	Write_rows	1	23900	table_id: # flags: STMT_END_F
+master-bin.000001	23900	Table_map	1	23941	table_id: # (test.t1)
+master-bin.000001	23941	Write_rows	1	23975	table_id: # flags: STMT_END_F
+master-bin.000001	23975	Table_map	1	24016	table_id: # (test.t1)
+master-bin.000001	24016	Write_rows	1	24050	table_id: # flags: STMT_END_F
+master-bin.000001	24050	Table_map	1	24091	table_id: # (test.t1)
+master-bin.000001	24091	Write_rows	1	24125	table_id: # flags: STMT_END_F
+master-bin.000001	24125	Table_map	1	24166	table_id: # (test.t1)
+master-bin.000001	24166	Write_rows	1	24200	table_id: # flags: STMT_END_F
+master-bin.000001	24200	Table_map	1	24241	table_id: # (test.t1)
+master-bin.000001	24241	Write_rows	1	24275	table_id: # flags: STMT_END_F
+master-bin.000001	24275	Table_map	1	24316	table_id: # (test.t1)
+master-bin.000001	24316	Write_rows	1	24350	table_id: # flags: STMT_END_F
+master-bin.000001	24350	Table_map	1	24391	table_id: # (test.t1)
+master-bin.000001	24391	Write_rows	1	24425	table_id: # flags: STMT_END_F
+master-bin.000001	24425	Table_map	1	24466	table_id: # (test.t1)
+master-bin.000001	24466	Write_rows	1	24500	table_id: # flags: STMT_END_F
+master-bin.000001	24500	Table_map	1	24541	table_id: # (test.t1)
+master-bin.000001	24541	Write_rows	1	24575	table_id: # flags: STMT_END_F
+master-bin.000001	24575	Table_map	1	24616	table_id: # (test.t1)
+master-bin.000001	24616	Write_rows	1	24650	table_id: # flags: STMT_END_F
+master-bin.000001	24650	Table_map	1	24691	table_id: # (test.t1)
+master-bin.000001	24691	Write_rows	1	24725	table_id: # flags: STMT_END_F
+master-bin.000001	24725	Table_map	1	24766	table_id: # (test.t1)
+master-bin.000001	24766	Write_rows	1	24800	table_id: # flags: STMT_END_F
+master-bin.000001	24800	Table_map	1	24841	table_id: # (test.t1)
+master-bin.000001	24841	Write_rows	1	24875	table_id: # flags: STMT_END_F
+master-bin.000001	24875	Table_map	1	24916	table_id: # (test.t1)
+master-bin.000001	24916	Write_rows	1	24950	table_id: # flags: STMT_END_F
+master-bin.000001	24950	Table_map	1	24991	table_id: # (test.t1)
+master-bin.000001	24991	Write_rows	1	25025	table_id: # flags: STMT_END_F
+master-bin.000001	25025	Table_map	1	25066	table_id: # (test.t1)
+master-bin.000001	25066	Write_rows	1	25100	table_id: # flags: STMT_END_F
+master-bin.000001	25100	Table_map	1	25141	table_id: # (test.t1)
+master-bin.000001	25141	Write_rows	1	25175	table_id: # flags: STMT_END_F
+master-bin.000001	25175	Table_map	1	25216	table_id: # (test.t1)
+master-bin.000001	25216	Write_rows	1	25250	table_id: # flags: STMT_END_F
+master-bin.000001	25250	Table_map	1	25291	table_id: # (test.t1)
+master-bin.000001	25291	Write_rows	1	25325	table_id: # flags: STMT_END_F
+master-bin.000001	25325	Table_map	1	25366	table_id: # (test.t1)
+master-bin.000001	25366	Write_rows	1	25400	table_id: # flags: STMT_END_F
+master-bin.000001	25400	Table_map	1	25441	table_id: # (test.t1)
+master-bin.000001	25441	Write_rows	1	25475	table_id: # flags: STMT_END_F
+master-bin.000001	25475	Table_map	1	25516	table_id: # (test.t1)
+master-bin.000001	25516	Write_rows	1	25550	table_id: # flags: STMT_END_F
+master-bin.000001	25550	Table_map	1	25591	table_id: # (test.t1)
+master-bin.000001	25591	Write_rows	1	25625	table_id: # flags: STMT_END_F
+master-bin.000001	25625	Table_map	1	25666	table_id: # (test.t1)
+master-bin.000001	25666	Write_rows	1	25700	table_id: # flags: STMT_END_F
+master-bin.000001	25700	Table_map	1	25741	table_id: # (test.t1)
+master-bin.000001	25741	Write_rows	1	25775	table_id: # flags: STMT_END_F
+master-bin.000001	25775	Table_map	1	25816	table_id: # (test.t1)
+master-bin.000001	25816	Write_rows	1	25850	table_id: # flags: STMT_END_F
+master-bin.000001	25850	Table_map	1	25891	table_id: # (test.t1)
+master-bin.000001	25891	Write_rows	1	25925	table_id: # flags: STMT_END_F
+master-bin.000001	25925	Table_map	1	25966	table_id: # (test.t1)
+master-bin.000001	25966	Write_rows	1	26000	table_id: # flags: STMT_END_F
+master-bin.000001	26000	Table_map	1	26041	table_id: # (test.t1)
+master-bin.000001	26041	Write_rows	1	26075	table_id: # flags: STMT_END_F
+master-bin.000001	26075	Table_map	1	26116	table_id: # (test.t1)
+master-bin.000001	26116	Write_rows	1	26150	table_id: # flags: STMT_END_F
+master-bin.000001	26150	Table_map	1	26191	table_id: # (test.t1)
+master-bin.000001	26191	Write_rows	1	26225	table_id: # flags: STMT_END_F
+master-bin.000001	26225	Table_map	1	26266	table_id: # (test.t1)
+master-bin.000001	26266	Write_rows	1	26300	table_id: # flags: STMT_END_F
+master-bin.000001	26300	Table_map	1	26341	table_id: # (test.t1)
+master-bin.000001	26341	Write_rows	1	26375	table_id: # flags: STMT_END_F
+master-bin.000001	26375	Table_map	1	26416	table_id: # (test.t1)
+master-bin.000001	26416	Write_rows	1	26450	table_id: # flags: STMT_END_F
+master-bin.000001	26450	Table_map	1	26491	table_id: # (test.t1)
+master-bin.000001	26491	Write_rows	1	26525	table_id: # flags: STMT_END_F
+master-bin.000001	26525	Table_map	1	26566	table_id: # (test.t1)
+master-bin.000001	26566	Write_rows	1	26600	table_id: # flags: STMT_END_F
+master-bin.000001	26600	Table_map	1	26641	table_id: # (test.t1)
+master-bin.000001	26641	Write_rows	1	26675	table_id: # flags: STMT_END_F
+master-bin.000001	26675	Table_map	1	26716	table_id: # (test.t1)
+master-bin.000001	26716	Write_rows	1	26750	table_id: # flags: STMT_END_F
+master-bin.000001	26750	Table_map	1	26791	table_id: # (test.t1)
+master-bin.000001	26791	Write_rows	1	26825	table_id: # flags: STMT_END_F
+master-bin.000001	26825	Table_map	1	26866	table_id: # (test.t1)
+master-bin.000001	26866	Write_rows	1	26900	table_id: # flags: STMT_END_F
+master-bin.000001	26900	Table_map	1	26941	table_id: # (test.t1)
+master-bin.000001	26941	Write_rows	1	26975	table_id: # flags: STMT_END_F
+master-bin.000001	26975	Table_map	1	27016	table_id: # (test.t1)
+master-bin.000001	27016	Write_rows	1	27050	table_id: # flags: STMT_END_F
+master-bin.000001	27050	Table_map	1	27091	table_id: # (test.t1)
+master-bin.000001	27091	Write_rows	1	27125	table_id: # flags: STMT_END_F
+master-bin.000001	27125	Table_map	1	27166	table_id: # (test.t1)
+master-bin.000001	27166	Write_rows	1	27200	table_id: # flags: STMT_END_F
+master-bin.000001	27200	Table_map	1	27241	table_id: # (test.t1)
+master-bin.000001	27241	Write_rows	1	27275	table_id: # flags: STMT_END_F
+master-bin.000001	27275	Table_map	1	27316	table_id: # (test.t1)
+master-bin.000001	27316	Write_rows	1	27350	table_id: # flags: STMT_END_F
+master-bin.000001	27350	Table_map	1	27391	table_id: # (test.t1)
+master-bin.000001	27391	Write_rows	1	27425	table_id: # flags: STMT_END_F
+master-bin.000001	27425	Table_map	1	27466	table_id: # (test.t1)
+master-bin.000001	27466	Write_rows	1	27500	table_id: # flags: STMT_END_F
+master-bin.000001	27500	Table_map	1	27541	table_id: # (test.t1)
+master-bin.000001	27541	Write_rows	1	27575	table_id: # flags: STMT_END_F
+master-bin.000001	27575	Table_map	1	27616	table_id: # (test.t1)
+master-bin.000001	27616	Write_rows	1	27650	table_id: # flags: STMT_END_F
+master-bin.000001	27650	Table_map	1	27691	table_id: # (test.t1)
+master-bin.000001	27691	Write_rows	1	27725	table_id: # flags: STMT_END_F
+master-bin.000001	27725	Table_map	1	27766	table_id: # (test.t1)
+master-bin.000001	27766	Write_rows	1	27800	table_id: # flags: STMT_END_F
+master-bin.000001	27800	Table_map	1	27841	table_id: # (test.t1)
+master-bin.000001	27841	Write_rows	1	27875	table_id: # flags: STMT_END_F
+master-bin.000001	27875	Table_map	1	27916	table_id: # (test.t1)
+master-bin.000001	27916	Write_rows	1	27950	table_id: # flags: STMT_END_F
+master-bin.000001	27950	Table_map	1	27991	table_id: # (test.t1)
+master-bin.000001	27991	Write_rows	1	28025	table_id: # flags: STMT_END_F
+master-bin.000001	28025	Table_map	1	28066	table_id: # (test.t1)
+master-bin.000001	28066	Write_rows	1	28100	table_id: # flags: STMT_END_F
+master-bin.000001	28100	Table_map	1	28141	table_id: # (test.t1)
+master-bin.000001	28141	Write_rows	1	28175	table_id: # flags: STMT_END_F
+master-bin.000001	28175	Table_map	1	28216	table_id: # (test.t1)
+master-bin.000001	28216	Write_rows	1	28250	table_id: # flags: STMT_END_F
+master-bin.000001	28250	Table_map	1	28291	table_id: # (test.t1)
+master-bin.000001	28291	Write_rows	1	28325	table_id: # flags: STMT_END_F
+master-bin.000001	28325	Table_map	1	28366	table_id: # (test.t1)
+master-bin.000001	28366	Write_rows	1	28400	table_id: # flags: STMT_END_F
+master-bin.000001	28400	Table_map	1	28441	table_id: # (test.t1)
+master-bin.000001	28441	Write_rows	1	28475	table_id: # flags: STMT_END_F
+master-bin.000001	28475	Table_map	1	28516	table_id: # (test.t1)
+master-bin.000001	28516	Write_rows	1	28550	table_id: # flags: STMT_END_F
+master-bin.000001	28550	Table_map	1	28591	table_id: # (test.t1)
+master-bin.000001	28591	Write_rows	1	28625	table_id: # flags: STMT_END_F
+master-bin.000001	28625	Table_map	1	28666	table_id: # (test.t1)
+master-bin.000001	28666	Write_rows	1	28700	table_id: # flags: STMT_END_F
+master-bin.000001	28700	Table_map	1	28741	table_id: # (test.t1)
+master-bin.000001	28741	Write_rows	1	28775	table_id: # flags: STMT_END_F
+master-bin.000001	28775	Table_map	1	28816	table_id: # (test.t1)
+master-bin.000001	28816	Write_rows	1	28850	table_id: # flags: STMT_END_F
+master-bin.000001	28850	Table_map	1	28891	table_id: # (test.t1)
+master-bin.000001	28891	Write_rows	1	28925	table_id: # flags: STMT_END_F
+master-bin.000001	28925	Table_map	1	28966	table_id: # (test.t1)
+master-bin.000001	28966	Write_rows	1	29000	table_id: # flags: STMT_END_F
+master-bin.000001	29000	Table_map	1	29041	table_id: # (test.t1)
+master-bin.000001	29041	Write_rows	1	29075	table_id: # flags: STMT_END_F
+master-bin.000001	29075	Table_map	1	29116	table_id: # (test.t1)
+master-bin.000001	29116	Write_rows	1	29150	table_id: # flags: STMT_END_F
+master-bin.000001	29150	Table_map	1	29191	table_id: # (test.t1)
+master-bin.000001	29191	Write_rows	1	29225	table_id: # flags: STMT_END_F
+master-bin.000001	29225	Table_map	1	29266	table_id: # (test.t1)
+master-bin.000001	29266	Write_rows	1	29300	table_id: # flags: STMT_END_F
+master-bin.000001	29300	Table_map	1	29341	table_id: # (test.t1)
+master-bin.000001	29341	Write_rows	1	29375	table_id: # flags: STMT_END_F
+master-bin.000001	29375	Table_map	1	29416	table_id: # (test.t1)
+master-bin.000001	29416	Write_rows	1	29450	table_id: # flags: STMT_END_F
+master-bin.000001	29450	Table_map	1	29491	table_id: # (test.t1)
+master-bin.000001	29491	Write_rows	1	29525	table_id: # flags: STMT_END_F
+master-bin.000001	29525	Table_map	1	29566	table_id: # (test.t1)
+master-bin.000001	29566	Write_rows	1	29600	table_id: # flags: STMT_END_F
+master-bin.000001	29600	Table_map	1	29641	table_id: # (test.t1)
+master-bin.000001	29641	Write_rows	1	29675	table_id: # flags: STMT_END_F
+master-bin.000001	29675	Table_map	1	29716	table_id: # (test.t1)
+master-bin.000001	29716	Write_rows	1	29750	table_id: # flags: STMT_END_F
+master-bin.000001	29750	Table_map	1	29791	table_id: # (test.t1)
+master-bin.000001	29791	Write_rows	1	29825	table_id: # flags: STMT_END_F
+master-bin.000001	29825	Table_map	1	29866	table_id: # (test.t1)
+master-bin.000001	29866	Write_rows	1	29900	table_id: # flags: STMT_END_F
+master-bin.000001	29900	Table_map	1	29941	table_id: # (test.t1)
+master-bin.000001	29941	Write_rows	1	29975	table_id: # flags: STMT_END_F
+master-bin.000001	29975	Table_map	1	30016	table_id: # (test.t1)
+master-bin.000001	30016	Write_rows	1	30050	table_id: # flags: STMT_END_F
+master-bin.000001	30050	Table_map	1	30091	table_id: # (test.t1)
+master-bin.000001	30091	Write_rows	1	30125	table_id: # flags: STMT_END_F
+master-bin.000001	30125	Table_map	1	30166	table_id: # (test.t1)
+master-bin.000001	30166	Write_rows	1	30200	table_id: # flags: STMT_END_F
+master-bin.000001	30200	Table_map	1	30241	table_id: # (test.t1)
+master-bin.000001	30241	Write_rows	1	30275	table_id: # flags: STMT_END_F
+master-bin.000001	30275	Xid	1	30302	COMMIT /* XID */
+master-bin.000001	30302	Rotate	1	30346	master-bin.000002;pos=4
 drop table t1;
 set global binlog_cache_size=@bcs;
 set session autocommit = @ac;
@@ -1083,13 +1083,13 @@ deallocate prepare stmt;
 drop table t1;
 show binlog events from 0;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server version, Binlog ver: 4
-master-bin.000001	106	Query	1	227	use `test`; create table t1 (a bigint unsigned, b bigint(20) unsigned)
-master-bin.000001	227	Query	1	295	BEGIN
-master-bin.000001	295	Table_map	1	337	table_id: # (test.t1)
-master-bin.000001	337	Write_rows	1	383	table_id: # flags: STMT_END_F
-master-bin.000001	383	Query	1	452	COMMIT
-master-bin.000001	452	Query	1	528	use `test`; drop table t1
+master-bin.000001	4	Format_desc	1	107	Server version, Binlog ver: 4
+master-bin.000001	107	Query	1	228	use `test`; create table t1 (a bigint unsigned, b bigint(20) unsigned)
+master-bin.000001	228	Query	1	296	BEGIN
+master-bin.000001	296	Table_map	1	338	table_id: # (test.t1)
+master-bin.000001	338	Write_rows	1	384	table_id: # flags: STMT_END_F
+master-bin.000001	384	Query	1	453	COMMIT
+master-bin.000001	453	Query	1	529	use `test`; drop table t1
 reset master;
 CREATE DATABASE bug39182 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 USE bug39182;
@@ -1289,14 +1289,14 @@ drop table if exists t3;
 create table t3 (a int(11) NOT NULL AUTO_INCREMENT, b text, PRIMARY KEY (a) ) engine=innodb;
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	346		
+master-bin.000001	347		
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 show master status /* must show new binlog index after rotating */;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000002	106		
+master-bin.000002	107		
 drop table t3;
 #
 # Bug #45998: database crashes when running "create as select"
diff --git a/mysql-test/suite/binlog/r/binlog_stm_binlog.result b/mysql-test/suite/binlog/r/binlog_stm_binlog.result
index eebcfceaa25aa29ab250533e19aa56b6fb78bfee..c5ac0a726ba3d8a945a14900afbf794bb1894689 100644
--- a/mysql-test/suite/binlog/r/binlog_stm_binlog.result
+++ b/mysql-test/suite/binlog/r/binlog_stm_binlog.result
@@ -4,11 +4,11 @@ insert into t1 values (1,2);
 commit;
 show binlog events;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: #, Binlog ver: #
-master-bin.000001	106	Query	1	213	use `test`; create table t1 (a int, b int) engine=innodb
-master-bin.000001	213	Query	1	281	BEGIN
-master-bin.000001	281	Query	1	371	use `test`; insert into t1 values (1,2)
-master-bin.000001	371	Xid	1	398	COMMIT /* XID */
+master-bin.000001	4	Format_desc	1	107	Server ver: #, Binlog ver: #
+master-bin.000001	107	Query	1	214	use `test`; create table t1 (a int, b int) engine=innodb
+master-bin.000001	214	Query	1	282	BEGIN
+master-bin.000001	282	Query	1	372	use `test`; insert into t1 values (1,2)
+master-bin.000001	372	Xid	1	399	COMMIT /* XID */
 drop table t1;
 drop table if exists t1, t2;
 reset master;
@@ -36,7 +36,7 @@ create table t1 (n int) engine=innodb;
 begin;
 commit;
 drop table t1;
-show binlog events in 'master-bin.000001' from 106;
+show binlog events in 'master-bin.000001' from 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1 (n int) engine=innodb
 master-bin.000001	#	Query	1	#	BEGIN
@@ -142,7 +142,7 @@ master-bin.000001	#	Query	1	#	use `test`; insert into t1 values(2 + 4)
 master-bin.000001	#	Query	1	#	use `test`; insert into t1 values(1 + 4)
 master-bin.000001	#	Xid	1	#	COMMIT /* xid= */
 master-bin.000001	#	Rotate	1	#	master-bin.000002;pos=4
-show binlog events in 'master-bin.000002' from 106;
+show binlog events in 'master-bin.000002' from 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000002	#	Query	1	#	use `test`; drop table t1
 set @ac = @@autocommit;
@@ -157,425 +157,425 @@ commit;
 drop table t1;
 show binlog events from 0;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server version, Binlog ver: 4
-master-bin.000001	106	Query	1	205	use `test`; create table t1(n int) engine=innodb
-master-bin.000001	205	Query	1	273	BEGIN
-master-bin.000001	273	Query	1	361	use `test`; insert into t1 values (1)
-master-bin.000001	361	Query	1	449	use `test`; insert into t1 values (2)
-master-bin.000001	449	Query	1	537	use `test`; insert into t1 values (3)
-master-bin.000001	537	Xid	1	564	COMMIT /* XID */
-master-bin.000001	564	Query	1	640	use `test`; drop table t1
+master-bin.000001	4	Format_desc	1	107	Server version, Binlog ver: 4
+master-bin.000001	107	Query	1	206	use `test`; create table t1(n int) engine=innodb
+master-bin.000001	206	Query	1	274	BEGIN
+master-bin.000001	274	Query	1	362	use `test`; insert into t1 values (1)
+master-bin.000001	362	Query	1	450	use `test`; insert into t1 values (2)
+master-bin.000001	450	Query	1	538	use `test`; insert into t1 values (3)
+master-bin.000001	538	Xid	1	565	COMMIT /* XID */
+master-bin.000001	565	Query	1	641	use `test`; drop table t1
 set @bcs = @@binlog_cache_size;
 set global binlog_cache_size=4096;
 reset master;
 create table t1 (a int) engine=innodb;
 show binlog events from 0;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server version, Binlog ver: 4
-master-bin.000001	106	Query	1	206	use `test`; create table t1 (a int) engine=innodb
-master-bin.000001	206	Query	1	274	BEGIN
-master-bin.000001	274	Query	1	365	use `test`; insert into t1 values( 400 )
-master-bin.000001	365	Query	1	456	use `test`; insert into t1 values( 399 )
-master-bin.000001	456	Query	1	547	use `test`; insert into t1 values( 398 )
-master-bin.000001	547	Query	1	638	use `test`; insert into t1 values( 397 )
-master-bin.000001	638	Query	1	729	use `test`; insert into t1 values( 396 )
-master-bin.000001	729	Query	1	820	use `test`; insert into t1 values( 395 )
-master-bin.000001	820	Query	1	911	use `test`; insert into t1 values( 394 )
-master-bin.000001	911	Query	1	1002	use `test`; insert into t1 values( 393 )
-master-bin.000001	1002	Query	1	1093	use `test`; insert into t1 values( 392 )
-master-bin.000001	1093	Query	1	1184	use `test`; insert into t1 values( 391 )
-master-bin.000001	1184	Query	1	1275	use `test`; insert into t1 values( 390 )
-master-bin.000001	1275	Query	1	1366	use `test`; insert into t1 values( 389 )
-master-bin.000001	1366	Query	1	1457	use `test`; insert into t1 values( 388 )
-master-bin.000001	1457	Query	1	1548	use `test`; insert into t1 values( 387 )
-master-bin.000001	1548	Query	1	1639	use `test`; insert into t1 values( 386 )
-master-bin.000001	1639	Query	1	1730	use `test`; insert into t1 values( 385 )
-master-bin.000001	1730	Query	1	1821	use `test`; insert into t1 values( 384 )
-master-bin.000001	1821	Query	1	1912	use `test`; insert into t1 values( 383 )
-master-bin.000001	1912	Query	1	2003	use `test`; insert into t1 values( 382 )
-master-bin.000001	2003	Query	1	2094	use `test`; insert into t1 values( 381 )
-master-bin.000001	2094	Query	1	2185	use `test`; insert into t1 values( 380 )
-master-bin.000001	2185	Query	1	2276	use `test`; insert into t1 values( 379 )
-master-bin.000001	2276	Query	1	2367	use `test`; insert into t1 values( 378 )
-master-bin.000001	2367	Query	1	2458	use `test`; insert into t1 values( 377 )
-master-bin.000001	2458	Query	1	2549	use `test`; insert into t1 values( 376 )
-master-bin.000001	2549	Query	1	2640	use `test`; insert into t1 values( 375 )
-master-bin.000001	2640	Query	1	2731	use `test`; insert into t1 values( 374 )
-master-bin.000001	2731	Query	1	2822	use `test`; insert into t1 values( 373 )
-master-bin.000001	2822	Query	1	2913	use `test`; insert into t1 values( 372 )
-master-bin.000001	2913	Query	1	3004	use `test`; insert into t1 values( 371 )
-master-bin.000001	3004	Query	1	3095	use `test`; insert into t1 values( 370 )
-master-bin.000001	3095	Query	1	3186	use `test`; insert into t1 values( 369 )
-master-bin.000001	3186	Query	1	3277	use `test`; insert into t1 values( 368 )
-master-bin.000001	3277	Query	1	3368	use `test`; insert into t1 values( 367 )
-master-bin.000001	3368	Query	1	3459	use `test`; insert into t1 values( 366 )
-master-bin.000001	3459	Query	1	3550	use `test`; insert into t1 values( 365 )
-master-bin.000001	3550	Query	1	3641	use `test`; insert into t1 values( 364 )
-master-bin.000001	3641	Query	1	3732	use `test`; insert into t1 values( 363 )
-master-bin.000001	3732	Query	1	3823	use `test`; insert into t1 values( 362 )
-master-bin.000001	3823	Query	1	3914	use `test`; insert into t1 values( 361 )
-master-bin.000001	3914	Query	1	4005	use `test`; insert into t1 values( 360 )
-master-bin.000001	4005	Query	1	4096	use `test`; insert into t1 values( 359 )
-master-bin.000001	4096	Query	1	4187	use `test`; insert into t1 values( 358 )
-master-bin.000001	4187	Query	1	4278	use `test`; insert into t1 values( 357 )
-master-bin.000001	4278	Query	1	4369	use `test`; insert into t1 values( 356 )
-master-bin.000001	4369	Query	1	4460	use `test`; insert into t1 values( 355 )
-master-bin.000001	4460	Query	1	4551	use `test`; insert into t1 values( 354 )
-master-bin.000001	4551	Query	1	4642	use `test`; insert into t1 values( 353 )
-master-bin.000001	4642	Query	1	4733	use `test`; insert into t1 values( 352 )
-master-bin.000001	4733	Query	1	4824	use `test`; insert into t1 values( 351 )
-master-bin.000001	4824	Query	1	4915	use `test`; insert into t1 values( 350 )
-master-bin.000001	4915	Query	1	5006	use `test`; insert into t1 values( 349 )
-master-bin.000001	5006	Query	1	5097	use `test`; insert into t1 values( 348 )
-master-bin.000001	5097	Query	1	5188	use `test`; insert into t1 values( 347 )
-master-bin.000001	5188	Query	1	5279	use `test`; insert into t1 values( 346 )
-master-bin.000001	5279	Query	1	5370	use `test`; insert into t1 values( 345 )
-master-bin.000001	5370	Query	1	5461	use `test`; insert into t1 values( 344 )
-master-bin.000001	5461	Query	1	5552	use `test`; insert into t1 values( 343 )
-master-bin.000001	5552	Query	1	5643	use `test`; insert into t1 values( 342 )
-master-bin.000001	5643	Query	1	5734	use `test`; insert into t1 values( 341 )
-master-bin.000001	5734	Query	1	5825	use `test`; insert into t1 values( 340 )
-master-bin.000001	5825	Query	1	5916	use `test`; insert into t1 values( 339 )
-master-bin.000001	5916	Query	1	6007	use `test`; insert into t1 values( 338 )
-master-bin.000001	6007	Query	1	6098	use `test`; insert into t1 values( 337 )
-master-bin.000001	6098	Query	1	6189	use `test`; insert into t1 values( 336 )
-master-bin.000001	6189	Query	1	6280	use `test`; insert into t1 values( 335 )
-master-bin.000001	6280	Query	1	6371	use `test`; insert into t1 values( 334 )
-master-bin.000001	6371	Query	1	6462	use `test`; insert into t1 values( 333 )
-master-bin.000001	6462	Query	1	6553	use `test`; insert into t1 values( 332 )
-master-bin.000001	6553	Query	1	6644	use `test`; insert into t1 values( 331 )
-master-bin.000001	6644	Query	1	6735	use `test`; insert into t1 values( 330 )
-master-bin.000001	6735	Query	1	6826	use `test`; insert into t1 values( 329 )
-master-bin.000001	6826	Query	1	6917	use `test`; insert into t1 values( 328 )
-master-bin.000001	6917	Query	1	7008	use `test`; insert into t1 values( 327 )
-master-bin.000001	7008	Query	1	7099	use `test`; insert into t1 values( 326 )
-master-bin.000001	7099	Query	1	7190	use `test`; insert into t1 values( 325 )
-master-bin.000001	7190	Query	1	7281	use `test`; insert into t1 values( 324 )
-master-bin.000001	7281	Query	1	7372	use `test`; insert into t1 values( 323 )
-master-bin.000001	7372	Query	1	7463	use `test`; insert into t1 values( 322 )
-master-bin.000001	7463	Query	1	7554	use `test`; insert into t1 values( 321 )
-master-bin.000001	7554	Query	1	7645	use `test`; insert into t1 values( 320 )
-master-bin.000001	7645	Query	1	7736	use `test`; insert into t1 values( 319 )
-master-bin.000001	7736	Query	1	7827	use `test`; insert into t1 values( 318 )
-master-bin.000001	7827	Query	1	7918	use `test`; insert into t1 values( 317 )
-master-bin.000001	7918	Query	1	8009	use `test`; insert into t1 values( 316 )
-master-bin.000001	8009	Query	1	8100	use `test`; insert into t1 values( 315 )
-master-bin.000001	8100	Query	1	8191	use `test`; insert into t1 values( 314 )
-master-bin.000001	8191	Query	1	8282	use `test`; insert into t1 values( 313 )
-master-bin.000001	8282	Query	1	8373	use `test`; insert into t1 values( 312 )
-master-bin.000001	8373	Query	1	8464	use `test`; insert into t1 values( 311 )
-master-bin.000001	8464	Query	1	8555	use `test`; insert into t1 values( 310 )
-master-bin.000001	8555	Query	1	8646	use `test`; insert into t1 values( 309 )
-master-bin.000001	8646	Query	1	8737	use `test`; insert into t1 values( 308 )
-master-bin.000001	8737	Query	1	8828	use `test`; insert into t1 values( 307 )
-master-bin.000001	8828	Query	1	8919	use `test`; insert into t1 values( 306 )
-master-bin.000001	8919	Query	1	9010	use `test`; insert into t1 values( 305 )
-master-bin.000001	9010	Query	1	9101	use `test`; insert into t1 values( 304 )
-master-bin.000001	9101	Query	1	9192	use `test`; insert into t1 values( 303 )
-master-bin.000001	9192	Query	1	9283	use `test`; insert into t1 values( 302 )
-master-bin.000001	9283	Query	1	9374	use `test`; insert into t1 values( 301 )
-master-bin.000001	9374	Query	1	9465	use `test`; insert into t1 values( 300 )
-master-bin.000001	9465	Query	1	9556	use `test`; insert into t1 values( 299 )
-master-bin.000001	9556	Query	1	9647	use `test`; insert into t1 values( 298 )
-master-bin.000001	9647	Query	1	9738	use `test`; insert into t1 values( 297 )
-master-bin.000001	9738	Query	1	9829	use `test`; insert into t1 values( 296 )
-master-bin.000001	9829	Query	1	9920	use `test`; insert into t1 values( 295 )
-master-bin.000001	9920	Query	1	10011	use `test`; insert into t1 values( 294 )
-master-bin.000001	10011	Query	1	10102	use `test`; insert into t1 values( 293 )
-master-bin.000001	10102	Query	1	10193	use `test`; insert into t1 values( 292 )
-master-bin.000001	10193	Query	1	10284	use `test`; insert into t1 values( 291 )
-master-bin.000001	10284	Query	1	10375	use `test`; insert into t1 values( 290 )
-master-bin.000001	10375	Query	1	10466	use `test`; insert into t1 values( 289 )
-master-bin.000001	10466	Query	1	10557	use `test`; insert into t1 values( 288 )
-master-bin.000001	10557	Query	1	10648	use `test`; insert into t1 values( 287 )
-master-bin.000001	10648	Query	1	10739	use `test`; insert into t1 values( 286 )
-master-bin.000001	10739	Query	1	10830	use `test`; insert into t1 values( 285 )
-master-bin.000001	10830	Query	1	10921	use `test`; insert into t1 values( 284 )
-master-bin.000001	10921	Query	1	11012	use `test`; insert into t1 values( 283 )
-master-bin.000001	11012	Query	1	11103	use `test`; insert into t1 values( 282 )
-master-bin.000001	11103	Query	1	11194	use `test`; insert into t1 values( 281 )
-master-bin.000001	11194	Query	1	11285	use `test`; insert into t1 values( 280 )
-master-bin.000001	11285	Query	1	11376	use `test`; insert into t1 values( 279 )
-master-bin.000001	11376	Query	1	11467	use `test`; insert into t1 values( 278 )
-master-bin.000001	11467	Query	1	11558	use `test`; insert into t1 values( 277 )
-master-bin.000001	11558	Query	1	11649	use `test`; insert into t1 values( 276 )
-master-bin.000001	11649	Query	1	11740	use `test`; insert into t1 values( 275 )
-master-bin.000001	11740	Query	1	11831	use `test`; insert into t1 values( 274 )
-master-bin.000001	11831	Query	1	11922	use `test`; insert into t1 values( 273 )
-master-bin.000001	11922	Query	1	12013	use `test`; insert into t1 values( 272 )
-master-bin.000001	12013	Query	1	12104	use `test`; insert into t1 values( 271 )
-master-bin.000001	12104	Query	1	12195	use `test`; insert into t1 values( 270 )
-master-bin.000001	12195	Query	1	12286	use `test`; insert into t1 values( 269 )
-master-bin.000001	12286	Query	1	12377	use `test`; insert into t1 values( 268 )
-master-bin.000001	12377	Query	1	12468	use `test`; insert into t1 values( 267 )
-master-bin.000001	12468	Query	1	12559	use `test`; insert into t1 values( 266 )
-master-bin.000001	12559	Query	1	12650	use `test`; insert into t1 values( 265 )
-master-bin.000001	12650	Query	1	12741	use `test`; insert into t1 values( 264 )
-master-bin.000001	12741	Query	1	12832	use `test`; insert into t1 values( 263 )
-master-bin.000001	12832	Query	1	12923	use `test`; insert into t1 values( 262 )
-master-bin.000001	12923	Query	1	13014	use `test`; insert into t1 values( 261 )
-master-bin.000001	13014	Query	1	13105	use `test`; insert into t1 values( 260 )
-master-bin.000001	13105	Query	1	13196	use `test`; insert into t1 values( 259 )
-master-bin.000001	13196	Query	1	13287	use `test`; insert into t1 values( 258 )
-master-bin.000001	13287	Query	1	13378	use `test`; insert into t1 values( 257 )
-master-bin.000001	13378	Query	1	13469	use `test`; insert into t1 values( 256 )
-master-bin.000001	13469	Query	1	13560	use `test`; insert into t1 values( 255 )
-master-bin.000001	13560	Query	1	13651	use `test`; insert into t1 values( 254 )
-master-bin.000001	13651	Query	1	13742	use `test`; insert into t1 values( 253 )
-master-bin.000001	13742	Query	1	13833	use `test`; insert into t1 values( 252 )
-master-bin.000001	13833	Query	1	13924	use `test`; insert into t1 values( 251 )
-master-bin.000001	13924	Query	1	14015	use `test`; insert into t1 values( 250 )
-master-bin.000001	14015	Query	1	14106	use `test`; insert into t1 values( 249 )
-master-bin.000001	14106	Query	1	14197	use `test`; insert into t1 values( 248 )
-master-bin.000001	14197	Query	1	14288	use `test`; insert into t1 values( 247 )
-master-bin.000001	14288	Query	1	14379	use `test`; insert into t1 values( 246 )
-master-bin.000001	14379	Query	1	14470	use `test`; insert into t1 values( 245 )
-master-bin.000001	14470	Query	1	14561	use `test`; insert into t1 values( 244 )
-master-bin.000001	14561	Query	1	14652	use `test`; insert into t1 values( 243 )
-master-bin.000001	14652	Query	1	14743	use `test`; insert into t1 values( 242 )
-master-bin.000001	14743	Query	1	14834	use `test`; insert into t1 values( 241 )
-master-bin.000001	14834	Query	1	14925	use `test`; insert into t1 values( 240 )
-master-bin.000001	14925	Query	1	15016	use `test`; insert into t1 values( 239 )
-master-bin.000001	15016	Query	1	15107	use `test`; insert into t1 values( 238 )
-master-bin.000001	15107	Query	1	15198	use `test`; insert into t1 values( 237 )
-master-bin.000001	15198	Query	1	15289	use `test`; insert into t1 values( 236 )
-master-bin.000001	15289	Query	1	15380	use `test`; insert into t1 values( 235 )
-master-bin.000001	15380	Query	1	15471	use `test`; insert into t1 values( 234 )
-master-bin.000001	15471	Query	1	15562	use `test`; insert into t1 values( 233 )
-master-bin.000001	15562	Query	1	15653	use `test`; insert into t1 values( 232 )
-master-bin.000001	15653	Query	1	15744	use `test`; insert into t1 values( 231 )
-master-bin.000001	15744	Query	1	15835	use `test`; insert into t1 values( 230 )
-master-bin.000001	15835	Query	1	15926	use `test`; insert into t1 values( 229 )
-master-bin.000001	15926	Query	1	16017	use `test`; insert into t1 values( 228 )
-master-bin.000001	16017	Query	1	16108	use `test`; insert into t1 values( 227 )
-master-bin.000001	16108	Query	1	16199	use `test`; insert into t1 values( 226 )
-master-bin.000001	16199	Query	1	16290	use `test`; insert into t1 values( 225 )
-master-bin.000001	16290	Query	1	16381	use `test`; insert into t1 values( 224 )
-master-bin.000001	16381	Query	1	16472	use `test`; insert into t1 values( 223 )
-master-bin.000001	16472	Query	1	16563	use `test`; insert into t1 values( 222 )
-master-bin.000001	16563	Query	1	16654	use `test`; insert into t1 values( 221 )
-master-bin.000001	16654	Query	1	16745	use `test`; insert into t1 values( 220 )
-master-bin.000001	16745	Query	1	16836	use `test`; insert into t1 values( 219 )
-master-bin.000001	16836	Query	1	16927	use `test`; insert into t1 values( 218 )
-master-bin.000001	16927	Query	1	17018	use `test`; insert into t1 values( 217 )
-master-bin.000001	17018	Query	1	17109	use `test`; insert into t1 values( 216 )
-master-bin.000001	17109	Query	1	17200	use `test`; insert into t1 values( 215 )
-master-bin.000001	17200	Query	1	17291	use `test`; insert into t1 values( 214 )
-master-bin.000001	17291	Query	1	17382	use `test`; insert into t1 values( 213 )
-master-bin.000001	17382	Query	1	17473	use `test`; insert into t1 values( 212 )
-master-bin.000001	17473	Query	1	17564	use `test`; insert into t1 values( 211 )
-master-bin.000001	17564	Query	1	17655	use `test`; insert into t1 values( 210 )
-master-bin.000001	17655	Query	1	17746	use `test`; insert into t1 values( 209 )
-master-bin.000001	17746	Query	1	17837	use `test`; insert into t1 values( 208 )
-master-bin.000001	17837	Query	1	17928	use `test`; insert into t1 values( 207 )
-master-bin.000001	17928	Query	1	18019	use `test`; insert into t1 values( 206 )
-master-bin.000001	18019	Query	1	18110	use `test`; insert into t1 values( 205 )
-master-bin.000001	18110	Query	1	18201	use `test`; insert into t1 values( 204 )
-master-bin.000001	18201	Query	1	18292	use `test`; insert into t1 values( 203 )
-master-bin.000001	18292	Query	1	18383	use `test`; insert into t1 values( 202 )
-master-bin.000001	18383	Query	1	18474	use `test`; insert into t1 values( 201 )
-master-bin.000001	18474	Query	1	18565	use `test`; insert into t1 values( 200 )
-master-bin.000001	18565	Query	1	18656	use `test`; insert into t1 values( 199 )
-master-bin.000001	18656	Query	1	18747	use `test`; insert into t1 values( 198 )
-master-bin.000001	18747	Query	1	18838	use `test`; insert into t1 values( 197 )
-master-bin.000001	18838	Query	1	18929	use `test`; insert into t1 values( 196 )
-master-bin.000001	18929	Query	1	19020	use `test`; insert into t1 values( 195 )
-master-bin.000001	19020	Query	1	19111	use `test`; insert into t1 values( 194 )
-master-bin.000001	19111	Query	1	19202	use `test`; insert into t1 values( 193 )
-master-bin.000001	19202	Query	1	19293	use `test`; insert into t1 values( 192 )
-master-bin.000001	19293	Query	1	19384	use `test`; insert into t1 values( 191 )
-master-bin.000001	19384	Query	1	19475	use `test`; insert into t1 values( 190 )
-master-bin.000001	19475	Query	1	19566	use `test`; insert into t1 values( 189 )
-master-bin.000001	19566	Query	1	19657	use `test`; insert into t1 values( 188 )
-master-bin.000001	19657	Query	1	19748	use `test`; insert into t1 values( 187 )
-master-bin.000001	19748	Query	1	19839	use `test`; insert into t1 values( 186 )
-master-bin.000001	19839	Query	1	19930	use `test`; insert into t1 values( 185 )
-master-bin.000001	19930	Query	1	20021	use `test`; insert into t1 values( 184 )
-master-bin.000001	20021	Query	1	20112	use `test`; insert into t1 values( 183 )
-master-bin.000001	20112	Query	1	20203	use `test`; insert into t1 values( 182 )
-master-bin.000001	20203	Query	1	20294	use `test`; insert into t1 values( 181 )
-master-bin.000001	20294	Query	1	20385	use `test`; insert into t1 values( 180 )
-master-bin.000001	20385	Query	1	20476	use `test`; insert into t1 values( 179 )
-master-bin.000001	20476	Query	1	20567	use `test`; insert into t1 values( 178 )
-master-bin.000001	20567	Query	1	20658	use `test`; insert into t1 values( 177 )
-master-bin.000001	20658	Query	1	20749	use `test`; insert into t1 values( 176 )
-master-bin.000001	20749	Query	1	20840	use `test`; insert into t1 values( 175 )
-master-bin.000001	20840	Query	1	20931	use `test`; insert into t1 values( 174 )
-master-bin.000001	20931	Query	1	21022	use `test`; insert into t1 values( 173 )
-master-bin.000001	21022	Query	1	21113	use `test`; insert into t1 values( 172 )
-master-bin.000001	21113	Query	1	21204	use `test`; insert into t1 values( 171 )
-master-bin.000001	21204	Query	1	21295	use `test`; insert into t1 values( 170 )
-master-bin.000001	21295	Query	1	21386	use `test`; insert into t1 values( 169 )
-master-bin.000001	21386	Query	1	21477	use `test`; insert into t1 values( 168 )
-master-bin.000001	21477	Query	1	21568	use `test`; insert into t1 values( 167 )
-master-bin.000001	21568	Query	1	21659	use `test`; insert into t1 values( 166 )
-master-bin.000001	21659	Query	1	21750	use `test`; insert into t1 values( 165 )
-master-bin.000001	21750	Query	1	21841	use `test`; insert into t1 values( 164 )
-master-bin.000001	21841	Query	1	21932	use `test`; insert into t1 values( 163 )
-master-bin.000001	21932	Query	1	22023	use `test`; insert into t1 values( 162 )
-master-bin.000001	22023	Query	1	22114	use `test`; insert into t1 values( 161 )
-master-bin.000001	22114	Query	1	22205	use `test`; insert into t1 values( 160 )
-master-bin.000001	22205	Query	1	22296	use `test`; insert into t1 values( 159 )
-master-bin.000001	22296	Query	1	22387	use `test`; insert into t1 values( 158 )
-master-bin.000001	22387	Query	1	22478	use `test`; insert into t1 values( 157 )
-master-bin.000001	22478	Query	1	22569	use `test`; insert into t1 values( 156 )
-master-bin.000001	22569	Query	1	22660	use `test`; insert into t1 values( 155 )
-master-bin.000001	22660	Query	1	22751	use `test`; insert into t1 values( 154 )
-master-bin.000001	22751	Query	1	22842	use `test`; insert into t1 values( 153 )
-master-bin.000001	22842	Query	1	22933	use `test`; insert into t1 values( 152 )
-master-bin.000001	22933	Query	1	23024	use `test`; insert into t1 values( 151 )
-master-bin.000001	23024	Query	1	23115	use `test`; insert into t1 values( 150 )
-master-bin.000001	23115	Query	1	23206	use `test`; insert into t1 values( 149 )
-master-bin.000001	23206	Query	1	23297	use `test`; insert into t1 values( 148 )
-master-bin.000001	23297	Query	1	23388	use `test`; insert into t1 values( 147 )
-master-bin.000001	23388	Query	1	23479	use `test`; insert into t1 values( 146 )
-master-bin.000001	23479	Query	1	23570	use `test`; insert into t1 values( 145 )
-master-bin.000001	23570	Query	1	23661	use `test`; insert into t1 values( 144 )
-master-bin.000001	23661	Query	1	23752	use `test`; insert into t1 values( 143 )
-master-bin.000001	23752	Query	1	23843	use `test`; insert into t1 values( 142 )
-master-bin.000001	23843	Query	1	23934	use `test`; insert into t1 values( 141 )
-master-bin.000001	23934	Query	1	24025	use `test`; insert into t1 values( 140 )
-master-bin.000001	24025	Query	1	24116	use `test`; insert into t1 values( 139 )
-master-bin.000001	24116	Query	1	24207	use `test`; insert into t1 values( 138 )
-master-bin.000001	24207	Query	1	24298	use `test`; insert into t1 values( 137 )
-master-bin.000001	24298	Query	1	24389	use `test`; insert into t1 values( 136 )
-master-bin.000001	24389	Query	1	24480	use `test`; insert into t1 values( 135 )
-master-bin.000001	24480	Query	1	24571	use `test`; insert into t1 values( 134 )
-master-bin.000001	24571	Query	1	24662	use `test`; insert into t1 values( 133 )
-master-bin.000001	24662	Query	1	24753	use `test`; insert into t1 values( 132 )
-master-bin.000001	24753	Query	1	24844	use `test`; insert into t1 values( 131 )
-master-bin.000001	24844	Query	1	24935	use `test`; insert into t1 values( 130 )
-master-bin.000001	24935	Query	1	25026	use `test`; insert into t1 values( 129 )
-master-bin.000001	25026	Query	1	25117	use `test`; insert into t1 values( 128 )
-master-bin.000001	25117	Query	1	25208	use `test`; insert into t1 values( 127 )
-master-bin.000001	25208	Query	1	25299	use `test`; insert into t1 values( 126 )
-master-bin.000001	25299	Query	1	25390	use `test`; insert into t1 values( 125 )
-master-bin.000001	25390	Query	1	25481	use `test`; insert into t1 values( 124 )
-master-bin.000001	25481	Query	1	25572	use `test`; insert into t1 values( 123 )
-master-bin.000001	25572	Query	1	25663	use `test`; insert into t1 values( 122 )
-master-bin.000001	25663	Query	1	25754	use `test`; insert into t1 values( 121 )
-master-bin.000001	25754	Query	1	25845	use `test`; insert into t1 values( 120 )
-master-bin.000001	25845	Query	1	25936	use `test`; insert into t1 values( 119 )
-master-bin.000001	25936	Query	1	26027	use `test`; insert into t1 values( 118 )
-master-bin.000001	26027	Query	1	26118	use `test`; insert into t1 values( 117 )
-master-bin.000001	26118	Query	1	26209	use `test`; insert into t1 values( 116 )
-master-bin.000001	26209	Query	1	26300	use `test`; insert into t1 values( 115 )
-master-bin.000001	26300	Query	1	26391	use `test`; insert into t1 values( 114 )
-master-bin.000001	26391	Query	1	26482	use `test`; insert into t1 values( 113 )
-master-bin.000001	26482	Query	1	26573	use `test`; insert into t1 values( 112 )
-master-bin.000001	26573	Query	1	26664	use `test`; insert into t1 values( 111 )
-master-bin.000001	26664	Query	1	26755	use `test`; insert into t1 values( 110 )
-master-bin.000001	26755	Query	1	26846	use `test`; insert into t1 values( 109 )
-master-bin.000001	26846	Query	1	26937	use `test`; insert into t1 values( 108 )
-master-bin.000001	26937	Query	1	27028	use `test`; insert into t1 values( 107 )
-master-bin.000001	27028	Query	1	27119	use `test`; insert into t1 values( 106 )
-master-bin.000001	27119	Query	1	27210	use `test`; insert into t1 values( 105 )
-master-bin.000001	27210	Query	1	27301	use `test`; insert into t1 values( 104 )
-master-bin.000001	27301	Query	1	27392	use `test`; insert into t1 values( 103 )
-master-bin.000001	27392	Query	1	27483	use `test`; insert into t1 values( 102 )
-master-bin.000001	27483	Query	1	27574	use `test`; insert into t1 values( 101 )
-master-bin.000001	27574	Query	1	27665	use `test`; insert into t1 values( 100 )
-master-bin.000001	27665	Query	1	27755	use `test`; insert into t1 values( 99 )
-master-bin.000001	27755	Query	1	27845	use `test`; insert into t1 values( 98 )
-master-bin.000001	27845	Query	1	27935	use `test`; insert into t1 values( 97 )
-master-bin.000001	27935	Query	1	28025	use `test`; insert into t1 values( 96 )
-master-bin.000001	28025	Query	1	28115	use `test`; insert into t1 values( 95 )
-master-bin.000001	28115	Query	1	28205	use `test`; insert into t1 values( 94 )
-master-bin.000001	28205	Query	1	28295	use `test`; insert into t1 values( 93 )
-master-bin.000001	28295	Query	1	28385	use `test`; insert into t1 values( 92 )
-master-bin.000001	28385	Query	1	28475	use `test`; insert into t1 values( 91 )
-master-bin.000001	28475	Query	1	28565	use `test`; insert into t1 values( 90 )
-master-bin.000001	28565	Query	1	28655	use `test`; insert into t1 values( 89 )
-master-bin.000001	28655	Query	1	28745	use `test`; insert into t1 values( 88 )
-master-bin.000001	28745	Query	1	28835	use `test`; insert into t1 values( 87 )
-master-bin.000001	28835	Query	1	28925	use `test`; insert into t1 values( 86 )
-master-bin.000001	28925	Query	1	29015	use `test`; insert into t1 values( 85 )
-master-bin.000001	29015	Query	1	29105	use `test`; insert into t1 values( 84 )
-master-bin.000001	29105	Query	1	29195	use `test`; insert into t1 values( 83 )
-master-bin.000001	29195	Query	1	29285	use `test`; insert into t1 values( 82 )
-master-bin.000001	29285	Query	1	29375	use `test`; insert into t1 values( 81 )
-master-bin.000001	29375	Query	1	29465	use `test`; insert into t1 values( 80 )
-master-bin.000001	29465	Query	1	29555	use `test`; insert into t1 values( 79 )
-master-bin.000001	29555	Query	1	29645	use `test`; insert into t1 values( 78 )
-master-bin.000001	29645	Query	1	29735	use `test`; insert into t1 values( 77 )
-master-bin.000001	29735	Query	1	29825	use `test`; insert into t1 values( 76 )
-master-bin.000001	29825	Query	1	29915	use `test`; insert into t1 values( 75 )
-master-bin.000001	29915	Query	1	30005	use `test`; insert into t1 values( 74 )
-master-bin.000001	30005	Query	1	30095	use `test`; insert into t1 values( 73 )
-master-bin.000001	30095	Query	1	30185	use `test`; insert into t1 values( 72 )
-master-bin.000001	30185	Query	1	30275	use `test`; insert into t1 values( 71 )
-master-bin.000001	30275	Query	1	30365	use `test`; insert into t1 values( 70 )
-master-bin.000001	30365	Query	1	30455	use `test`; insert into t1 values( 69 )
-master-bin.000001	30455	Query	1	30545	use `test`; insert into t1 values( 68 )
-master-bin.000001	30545	Query	1	30635	use `test`; insert into t1 values( 67 )
-master-bin.000001	30635	Query	1	30725	use `test`; insert into t1 values( 66 )
-master-bin.000001	30725	Query	1	30815	use `test`; insert into t1 values( 65 )
-master-bin.000001	30815	Query	1	30905	use `test`; insert into t1 values( 64 )
-master-bin.000001	30905	Query	1	30995	use `test`; insert into t1 values( 63 )
-master-bin.000001	30995	Query	1	31085	use `test`; insert into t1 values( 62 )
-master-bin.000001	31085	Query	1	31175	use `test`; insert into t1 values( 61 )
-master-bin.000001	31175	Query	1	31265	use `test`; insert into t1 values( 60 )
-master-bin.000001	31265	Query	1	31355	use `test`; insert into t1 values( 59 )
-master-bin.000001	31355	Query	1	31445	use `test`; insert into t1 values( 58 )
-master-bin.000001	31445	Query	1	31535	use `test`; insert into t1 values( 57 )
-master-bin.000001	31535	Query	1	31625	use `test`; insert into t1 values( 56 )
-master-bin.000001	31625	Query	1	31715	use `test`; insert into t1 values( 55 )
-master-bin.000001	31715	Query	1	31805	use `test`; insert into t1 values( 54 )
-master-bin.000001	31805	Query	1	31895	use `test`; insert into t1 values( 53 )
-master-bin.000001	31895	Query	1	31985	use `test`; insert into t1 values( 52 )
-master-bin.000001	31985	Query	1	32075	use `test`; insert into t1 values( 51 )
-master-bin.000001	32075	Query	1	32165	use `test`; insert into t1 values( 50 )
-master-bin.000001	32165	Query	1	32255	use `test`; insert into t1 values( 49 )
-master-bin.000001	32255	Query	1	32345	use `test`; insert into t1 values( 48 )
-master-bin.000001	32345	Query	1	32435	use `test`; insert into t1 values( 47 )
-master-bin.000001	32435	Query	1	32525	use `test`; insert into t1 values( 46 )
-master-bin.000001	32525	Query	1	32615	use `test`; insert into t1 values( 45 )
-master-bin.000001	32615	Query	1	32705	use `test`; insert into t1 values( 44 )
-master-bin.000001	32705	Query	1	32795	use `test`; insert into t1 values( 43 )
-master-bin.000001	32795	Query	1	32885	use `test`; insert into t1 values( 42 )
-master-bin.000001	32885	Query	1	32975	use `test`; insert into t1 values( 41 )
-master-bin.000001	32975	Query	1	33065	use `test`; insert into t1 values( 40 )
-master-bin.000001	33065	Query	1	33155	use `test`; insert into t1 values( 39 )
-master-bin.000001	33155	Query	1	33245	use `test`; insert into t1 values( 38 )
-master-bin.000001	33245	Query	1	33335	use `test`; insert into t1 values( 37 )
-master-bin.000001	33335	Query	1	33425	use `test`; insert into t1 values( 36 )
-master-bin.000001	33425	Query	1	33515	use `test`; insert into t1 values( 35 )
-master-bin.000001	33515	Query	1	33605	use `test`; insert into t1 values( 34 )
-master-bin.000001	33605	Query	1	33695	use `test`; insert into t1 values( 33 )
-master-bin.000001	33695	Query	1	33785	use `test`; insert into t1 values( 32 )
-master-bin.000001	33785	Query	1	33875	use `test`; insert into t1 values( 31 )
-master-bin.000001	33875	Query	1	33965	use `test`; insert into t1 values( 30 )
-master-bin.000001	33965	Query	1	34055	use `test`; insert into t1 values( 29 )
-master-bin.000001	34055	Query	1	34145	use `test`; insert into t1 values( 28 )
-master-bin.000001	34145	Query	1	34235	use `test`; insert into t1 values( 27 )
-master-bin.000001	34235	Query	1	34325	use `test`; insert into t1 values( 26 )
-master-bin.000001	34325	Query	1	34415	use `test`; insert into t1 values( 25 )
-master-bin.000001	34415	Query	1	34505	use `test`; insert into t1 values( 24 )
-master-bin.000001	34505	Query	1	34595	use `test`; insert into t1 values( 23 )
-master-bin.000001	34595	Query	1	34685	use `test`; insert into t1 values( 22 )
-master-bin.000001	34685	Query	1	34775	use `test`; insert into t1 values( 21 )
-master-bin.000001	34775	Query	1	34865	use `test`; insert into t1 values( 20 )
-master-bin.000001	34865	Query	1	34955	use `test`; insert into t1 values( 19 )
-master-bin.000001	34955	Query	1	35045	use `test`; insert into t1 values( 18 )
-master-bin.000001	35045	Query	1	35135	use `test`; insert into t1 values( 17 )
-master-bin.000001	35135	Query	1	35225	use `test`; insert into t1 values( 16 )
-master-bin.000001	35225	Query	1	35315	use `test`; insert into t1 values( 15 )
-master-bin.000001	35315	Query	1	35405	use `test`; insert into t1 values( 14 )
-master-bin.000001	35405	Query	1	35495	use `test`; insert into t1 values( 13 )
-master-bin.000001	35495	Query	1	35585	use `test`; insert into t1 values( 12 )
-master-bin.000001	35585	Query	1	35675	use `test`; insert into t1 values( 11 )
-master-bin.000001	35675	Query	1	35765	use `test`; insert into t1 values( 10 )
-master-bin.000001	35765	Query	1	35854	use `test`; insert into t1 values( 9 )
-master-bin.000001	35854	Query	1	35943	use `test`; insert into t1 values( 8 )
-master-bin.000001	35943	Query	1	36032	use `test`; insert into t1 values( 7 )
-master-bin.000001	36032	Query	1	36121	use `test`; insert into t1 values( 6 )
-master-bin.000001	36121	Query	1	36210	use `test`; insert into t1 values( 5 )
-master-bin.000001	36210	Query	1	36299	use `test`; insert into t1 values( 4 )
-master-bin.000001	36299	Query	1	36388	use `test`; insert into t1 values( 3 )
-master-bin.000001	36388	Query	1	36477	use `test`; insert into t1 values( 2 )
-master-bin.000001	36477	Query	1	36566	use `test`; insert into t1 values( 1 )
-master-bin.000001	36566	Xid	1	36593	COMMIT /* XID */
-master-bin.000001	36593	Rotate	1	36637	master-bin.000002;pos=4
+master-bin.000001	4	Format_desc	1	107	Server version, Binlog ver: 4
+master-bin.000001	107	Query	1	207	use `test`; create table t1 (a int) engine=innodb
+master-bin.000001	207	Query	1	275	BEGIN
+master-bin.000001	275	Query	1	366	use `test`; insert into t1 values( 400 )
+master-bin.000001	366	Query	1	457	use `test`; insert into t1 values( 399 )
+master-bin.000001	457	Query	1	548	use `test`; insert into t1 values( 398 )
+master-bin.000001	548	Query	1	639	use `test`; insert into t1 values( 397 )
+master-bin.000001	639	Query	1	730	use `test`; insert into t1 values( 396 )
+master-bin.000001	730	Query	1	821	use `test`; insert into t1 values( 395 )
+master-bin.000001	821	Query	1	912	use `test`; insert into t1 values( 394 )
+master-bin.000001	912	Query	1	1003	use `test`; insert into t1 values( 393 )
+master-bin.000001	1003	Query	1	1094	use `test`; insert into t1 values( 392 )
+master-bin.000001	1094	Query	1	1185	use `test`; insert into t1 values( 391 )
+master-bin.000001	1185	Query	1	1276	use `test`; insert into t1 values( 390 )
+master-bin.000001	1276	Query	1	1367	use `test`; insert into t1 values( 389 )
+master-bin.000001	1367	Query	1	1458	use `test`; insert into t1 values( 388 )
+master-bin.000001	1458	Query	1	1549	use `test`; insert into t1 values( 387 )
+master-bin.000001	1549	Query	1	1640	use `test`; insert into t1 values( 386 )
+master-bin.000001	1640	Query	1	1731	use `test`; insert into t1 values( 385 )
+master-bin.000001	1731	Query	1	1822	use `test`; insert into t1 values( 384 )
+master-bin.000001	1822	Query	1	1913	use `test`; insert into t1 values( 383 )
+master-bin.000001	1913	Query	1	2004	use `test`; insert into t1 values( 382 )
+master-bin.000001	2004	Query	1	2095	use `test`; insert into t1 values( 381 )
+master-bin.000001	2095	Query	1	2186	use `test`; insert into t1 values( 380 )
+master-bin.000001	2186	Query	1	2277	use `test`; insert into t1 values( 379 )
+master-bin.000001	2277	Query	1	2368	use `test`; insert into t1 values( 378 )
+master-bin.000001	2368	Query	1	2459	use `test`; insert into t1 values( 377 )
+master-bin.000001	2459	Query	1	2550	use `test`; insert into t1 values( 376 )
+master-bin.000001	2550	Query	1	2641	use `test`; insert into t1 values( 375 )
+master-bin.000001	2641	Query	1	2732	use `test`; insert into t1 values( 374 )
+master-bin.000001	2732	Query	1	2823	use `test`; insert into t1 values( 373 )
+master-bin.000001	2823	Query	1	2914	use `test`; insert into t1 values( 372 )
+master-bin.000001	2914	Query	1	3005	use `test`; insert into t1 values( 371 )
+master-bin.000001	3005	Query	1	3096	use `test`; insert into t1 values( 370 )
+master-bin.000001	3096	Query	1	3187	use `test`; insert into t1 values( 369 )
+master-bin.000001	3187	Query	1	3278	use `test`; insert into t1 values( 368 )
+master-bin.000001	3278	Query	1	3369	use `test`; insert into t1 values( 367 )
+master-bin.000001	3369	Query	1	3460	use `test`; insert into t1 values( 366 )
+master-bin.000001	3460	Query	1	3551	use `test`; insert into t1 values( 365 )
+master-bin.000001	3551	Query	1	3642	use `test`; insert into t1 values( 364 )
+master-bin.000001	3642	Query	1	3733	use `test`; insert into t1 values( 363 )
+master-bin.000001	3733	Query	1	3824	use `test`; insert into t1 values( 362 )
+master-bin.000001	3824	Query	1	3915	use `test`; insert into t1 values( 361 )
+master-bin.000001	3915	Query	1	4006	use `test`; insert into t1 values( 360 )
+master-bin.000001	4006	Query	1	4097	use `test`; insert into t1 values( 359 )
+master-bin.000001	4097	Query	1	4188	use `test`; insert into t1 values( 358 )
+master-bin.000001	4188	Query	1	4279	use `test`; insert into t1 values( 357 )
+master-bin.000001	4279	Query	1	4370	use `test`; insert into t1 values( 356 )
+master-bin.000001	4370	Query	1	4461	use `test`; insert into t1 values( 355 )
+master-bin.000001	4461	Query	1	4552	use `test`; insert into t1 values( 354 )
+master-bin.000001	4552	Query	1	4643	use `test`; insert into t1 values( 353 )
+master-bin.000001	4643	Query	1	4734	use `test`; insert into t1 values( 352 )
+master-bin.000001	4734	Query	1	4825	use `test`; insert into t1 values( 351 )
+master-bin.000001	4825	Query	1	4916	use `test`; insert into t1 values( 350 )
+master-bin.000001	4916	Query	1	5007	use `test`; insert into t1 values( 349 )
+master-bin.000001	5007	Query	1	5098	use `test`; insert into t1 values( 348 )
+master-bin.000001	5098	Query	1	5189	use `test`; insert into t1 values( 347 )
+master-bin.000001	5189	Query	1	5280	use `test`; insert into t1 values( 346 )
+master-bin.000001	5280	Query	1	5371	use `test`; insert into t1 values( 345 )
+master-bin.000001	5371	Query	1	5462	use `test`; insert into t1 values( 344 )
+master-bin.000001	5462	Query	1	5553	use `test`; insert into t1 values( 343 )
+master-bin.000001	5553	Query	1	5644	use `test`; insert into t1 values( 342 )
+master-bin.000001	5644	Query	1	5735	use `test`; insert into t1 values( 341 )
+master-bin.000001	5735	Query	1	5826	use `test`; insert into t1 values( 340 )
+master-bin.000001	5826	Query	1	5917	use `test`; insert into t1 values( 339 )
+master-bin.000001	5917	Query	1	6008	use `test`; insert into t1 values( 338 )
+master-bin.000001	6008	Query	1	6099	use `test`; insert into t1 values( 337 )
+master-bin.000001	6099	Query	1	6190	use `test`; insert into t1 values( 336 )
+master-bin.000001	6190	Query	1	6281	use `test`; insert into t1 values( 335 )
+master-bin.000001	6281	Query	1	6372	use `test`; insert into t1 values( 334 )
+master-bin.000001	6372	Query	1	6463	use `test`; insert into t1 values( 333 )
+master-bin.000001	6463	Query	1	6554	use `test`; insert into t1 values( 332 )
+master-bin.000001	6554	Query	1	6645	use `test`; insert into t1 values( 331 )
+master-bin.000001	6645	Query	1	6736	use `test`; insert into t1 values( 330 )
+master-bin.000001	6736	Query	1	6827	use `test`; insert into t1 values( 329 )
+master-bin.000001	6827	Query	1	6918	use `test`; insert into t1 values( 328 )
+master-bin.000001	6918	Query	1	7009	use `test`; insert into t1 values( 327 )
+master-bin.000001	7009	Query	1	7100	use `test`; insert into t1 values( 326 )
+master-bin.000001	7100	Query	1	7191	use `test`; insert into t1 values( 325 )
+master-bin.000001	7191	Query	1	7282	use `test`; insert into t1 values( 324 )
+master-bin.000001	7282	Query	1	7373	use `test`; insert into t1 values( 323 )
+master-bin.000001	7373	Query	1	7464	use `test`; insert into t1 values( 322 )
+master-bin.000001	7464	Query	1	7555	use `test`; insert into t1 values( 321 )
+master-bin.000001	7555	Query	1	7646	use `test`; insert into t1 values( 320 )
+master-bin.000001	7646	Query	1	7737	use `test`; insert into t1 values( 319 )
+master-bin.000001	7737	Query	1	7828	use `test`; insert into t1 values( 318 )
+master-bin.000001	7828	Query	1	7919	use `test`; insert into t1 values( 317 )
+master-bin.000001	7919	Query	1	8010	use `test`; insert into t1 values( 316 )
+master-bin.000001	8010	Query	1	8101	use `test`; insert into t1 values( 315 )
+master-bin.000001	8101	Query	1	8192	use `test`; insert into t1 values( 314 )
+master-bin.000001	8192	Query	1	8283	use `test`; insert into t1 values( 313 )
+master-bin.000001	8283	Query	1	8374	use `test`; insert into t1 values( 312 )
+master-bin.000001	8374	Query	1	8465	use `test`; insert into t1 values( 311 )
+master-bin.000001	8465	Query	1	8556	use `test`; insert into t1 values( 310 )
+master-bin.000001	8556	Query	1	8647	use `test`; insert into t1 values( 309 )
+master-bin.000001	8647	Query	1	8738	use `test`; insert into t1 values( 308 )
+master-bin.000001	8738	Query	1	8829	use `test`; insert into t1 values( 307 )
+master-bin.000001	8829	Query	1	8920	use `test`; insert into t1 values( 306 )
+master-bin.000001	8920	Query	1	9011	use `test`; insert into t1 values( 305 )
+master-bin.000001	9011	Query	1	9102	use `test`; insert into t1 values( 304 )
+master-bin.000001	9102	Query	1	9193	use `test`; insert into t1 values( 303 )
+master-bin.000001	9193	Query	1	9284	use `test`; insert into t1 values( 302 )
+master-bin.000001	9284	Query	1	9375	use `test`; insert into t1 values( 301 )
+master-bin.000001	9375	Query	1	9466	use `test`; insert into t1 values( 300 )
+master-bin.000001	9466	Query	1	9557	use `test`; insert into t1 values( 299 )
+master-bin.000001	9557	Query	1	9648	use `test`; insert into t1 values( 298 )
+master-bin.000001	9648	Query	1	9739	use `test`; insert into t1 values( 297 )
+master-bin.000001	9739	Query	1	9830	use `test`; insert into t1 values( 296 )
+master-bin.000001	9830	Query	1	9921	use `test`; insert into t1 values( 295 )
+master-bin.000001	9921	Query	1	10012	use `test`; insert into t1 values( 294 )
+master-bin.000001	10012	Query	1	10103	use `test`; insert into t1 values( 293 )
+master-bin.000001	10103	Query	1	10194	use `test`; insert into t1 values( 292 )
+master-bin.000001	10194	Query	1	10285	use `test`; insert into t1 values( 291 )
+master-bin.000001	10285	Query	1	10376	use `test`; insert into t1 values( 290 )
+master-bin.000001	10376	Query	1	10467	use `test`; insert into t1 values( 289 )
+master-bin.000001	10467	Query	1	10558	use `test`; insert into t1 values( 288 )
+master-bin.000001	10558	Query	1	10649	use `test`; insert into t1 values( 287 )
+master-bin.000001	10649	Query	1	10740	use `test`; insert into t1 values( 286 )
+master-bin.000001	10740	Query	1	10831	use `test`; insert into t1 values( 285 )
+master-bin.000001	10831	Query	1	10922	use `test`; insert into t1 values( 284 )
+master-bin.000001	10922	Query	1	11013	use `test`; insert into t1 values( 283 )
+master-bin.000001	11013	Query	1	11104	use `test`; insert into t1 values( 282 )
+master-bin.000001	11104	Query	1	11195	use `test`; insert into t1 values( 281 )
+master-bin.000001	11195	Query	1	11286	use `test`; insert into t1 values( 280 )
+master-bin.000001	11286	Query	1	11377	use `test`; insert into t1 values( 279 )
+master-bin.000001	11377	Query	1	11468	use `test`; insert into t1 values( 278 )
+master-bin.000001	11468	Query	1	11559	use `test`; insert into t1 values( 277 )
+master-bin.000001	11559	Query	1	11650	use `test`; insert into t1 values( 276 )
+master-bin.000001	11650	Query	1	11741	use `test`; insert into t1 values( 275 )
+master-bin.000001	11741	Query	1	11832	use `test`; insert into t1 values( 274 )
+master-bin.000001	11832	Query	1	11923	use `test`; insert into t1 values( 273 )
+master-bin.000001	11923	Query	1	12014	use `test`; insert into t1 values( 272 )
+master-bin.000001	12014	Query	1	12105	use `test`; insert into t1 values( 271 )
+master-bin.000001	12105	Query	1	12196	use `test`; insert into t1 values( 270 )
+master-bin.000001	12196	Query	1	12287	use `test`; insert into t1 values( 269 )
+master-bin.000001	12287	Query	1	12378	use `test`; insert into t1 values( 268 )
+master-bin.000001	12378	Query	1	12469	use `test`; insert into t1 values( 267 )
+master-bin.000001	12469	Query	1	12560	use `test`; insert into t1 values( 266 )
+master-bin.000001	12560	Query	1	12651	use `test`; insert into t1 values( 265 )
+master-bin.000001	12651	Query	1	12742	use `test`; insert into t1 values( 264 )
+master-bin.000001	12742	Query	1	12833	use `test`; insert into t1 values( 263 )
+master-bin.000001	12833	Query	1	12924	use `test`; insert into t1 values( 262 )
+master-bin.000001	12924	Query	1	13015	use `test`; insert into t1 values( 261 )
+master-bin.000001	13015	Query	1	13106	use `test`; insert into t1 values( 260 )
+master-bin.000001	13106	Query	1	13197	use `test`; insert into t1 values( 259 )
+master-bin.000001	13197	Query	1	13288	use `test`; insert into t1 values( 258 )
+master-bin.000001	13288	Query	1	13379	use `test`; insert into t1 values( 257 )
+master-bin.000001	13379	Query	1	13470	use `test`; insert into t1 values( 256 )
+master-bin.000001	13470	Query	1	13561	use `test`; insert into t1 values( 255 )
+master-bin.000001	13561	Query	1	13652	use `test`; insert into t1 values( 254 )
+master-bin.000001	13652	Query	1	13743	use `test`; insert into t1 values( 253 )
+master-bin.000001	13743	Query	1	13834	use `test`; insert into t1 values( 252 )
+master-bin.000001	13834	Query	1	13925	use `test`; insert into t1 values( 251 )
+master-bin.000001	13925	Query	1	14016	use `test`; insert into t1 values( 250 )
+master-bin.000001	14016	Query	1	14107	use `test`; insert into t1 values( 249 )
+master-bin.000001	14107	Query	1	14198	use `test`; insert into t1 values( 248 )
+master-bin.000001	14198	Query	1	14289	use `test`; insert into t1 values( 247 )
+master-bin.000001	14289	Query	1	14380	use `test`; insert into t1 values( 246 )
+master-bin.000001	14380	Query	1	14471	use `test`; insert into t1 values( 245 )
+master-bin.000001	14471	Query	1	14562	use `test`; insert into t1 values( 244 )
+master-bin.000001	14562	Query	1	14653	use `test`; insert into t1 values( 243 )
+master-bin.000001	14653	Query	1	14744	use `test`; insert into t1 values( 242 )
+master-bin.000001	14744	Query	1	14835	use `test`; insert into t1 values( 241 )
+master-bin.000001	14835	Query	1	14926	use `test`; insert into t1 values( 240 )
+master-bin.000001	14926	Query	1	15017	use `test`; insert into t1 values( 239 )
+master-bin.000001	15017	Query	1	15108	use `test`; insert into t1 values( 238 )
+master-bin.000001	15108	Query	1	15199	use `test`; insert into t1 values( 237 )
+master-bin.000001	15199	Query	1	15290	use `test`; insert into t1 values( 236 )
+master-bin.000001	15290	Query	1	15381	use `test`; insert into t1 values( 235 )
+master-bin.000001	15381	Query	1	15472	use `test`; insert into t1 values( 234 )
+master-bin.000001	15472	Query	1	15563	use `test`; insert into t1 values( 233 )
+master-bin.000001	15563	Query	1	15654	use `test`; insert into t1 values( 232 )
+master-bin.000001	15654	Query	1	15745	use `test`; insert into t1 values( 231 )
+master-bin.000001	15745	Query	1	15836	use `test`; insert into t1 values( 230 )
+master-bin.000001	15836	Query	1	15927	use `test`; insert into t1 values( 229 )
+master-bin.000001	15927	Query	1	16018	use `test`; insert into t1 values( 228 )
+master-bin.000001	16018	Query	1	16109	use `test`; insert into t1 values( 227 )
+master-bin.000001	16109	Query	1	16200	use `test`; insert into t1 values( 226 )
+master-bin.000001	16200	Query	1	16291	use `test`; insert into t1 values( 225 )
+master-bin.000001	16291	Query	1	16382	use `test`; insert into t1 values( 224 )
+master-bin.000001	16382	Query	1	16473	use `test`; insert into t1 values( 223 )
+master-bin.000001	16473	Query	1	16564	use `test`; insert into t1 values( 222 )
+master-bin.000001	16564	Query	1	16655	use `test`; insert into t1 values( 221 )
+master-bin.000001	16655	Query	1	16746	use `test`; insert into t1 values( 220 )
+master-bin.000001	16746	Query	1	16837	use `test`; insert into t1 values( 219 )
+master-bin.000001	16837	Query	1	16928	use `test`; insert into t1 values( 218 )
+master-bin.000001	16928	Query	1	17019	use `test`; insert into t1 values( 217 )
+master-bin.000001	17019	Query	1	17110	use `test`; insert into t1 values( 216 )
+master-bin.000001	17110	Query	1	17201	use `test`; insert into t1 values( 215 )
+master-bin.000001	17201	Query	1	17292	use `test`; insert into t1 values( 214 )
+master-bin.000001	17292	Query	1	17383	use `test`; insert into t1 values( 213 )
+master-bin.000001	17383	Query	1	17474	use `test`; insert into t1 values( 212 )
+master-bin.000001	17474	Query	1	17565	use `test`; insert into t1 values( 211 )
+master-bin.000001	17565	Query	1	17656	use `test`; insert into t1 values( 210 )
+master-bin.000001	17656	Query	1	17747	use `test`; insert into t1 values( 209 )
+master-bin.000001	17747	Query	1	17838	use `test`; insert into t1 values( 208 )
+master-bin.000001	17838	Query	1	17929	use `test`; insert into t1 values( 207 )
+master-bin.000001	17929	Query	1	18020	use `test`; insert into t1 values( 206 )
+master-bin.000001	18020	Query	1	18111	use `test`; insert into t1 values( 205 )
+master-bin.000001	18111	Query	1	18202	use `test`; insert into t1 values( 204 )
+master-bin.000001	18202	Query	1	18293	use `test`; insert into t1 values( 203 )
+master-bin.000001	18293	Query	1	18384	use `test`; insert into t1 values( 202 )
+master-bin.000001	18384	Query	1	18475	use `test`; insert into t1 values( 201 )
+master-bin.000001	18475	Query	1	18566	use `test`; insert into t1 values( 200 )
+master-bin.000001	18566	Query	1	18657	use `test`; insert into t1 values( 199 )
+master-bin.000001	18657	Query	1	18748	use `test`; insert into t1 values( 198 )
+master-bin.000001	18748	Query	1	18839	use `test`; insert into t1 values( 197 )
+master-bin.000001	18839	Query	1	18930	use `test`; insert into t1 values( 196 )
+master-bin.000001	18930	Query	1	19021	use `test`; insert into t1 values( 195 )
+master-bin.000001	19021	Query	1	19112	use `test`; insert into t1 values( 194 )
+master-bin.000001	19112	Query	1	19203	use `test`; insert into t1 values( 193 )
+master-bin.000001	19203	Query	1	19294	use `test`; insert into t1 values( 192 )
+master-bin.000001	19294	Query	1	19385	use `test`; insert into t1 values( 191 )
+master-bin.000001	19385	Query	1	19476	use `test`; insert into t1 values( 190 )
+master-bin.000001	19476	Query	1	19567	use `test`; insert into t1 values( 189 )
+master-bin.000001	19567	Query	1	19658	use `test`; insert into t1 values( 188 )
+master-bin.000001	19658	Query	1	19749	use `test`; insert into t1 values( 187 )
+master-bin.000001	19749	Query	1	19840	use `test`; insert into t1 values( 186 )
+master-bin.000001	19840	Query	1	19931	use `test`; insert into t1 values( 185 )
+master-bin.000001	19931	Query	1	20022	use `test`; insert into t1 values( 184 )
+master-bin.000001	20022	Query	1	20113	use `test`; insert into t1 values( 183 )
+master-bin.000001	20113	Query	1	20204	use `test`; insert into t1 values( 182 )
+master-bin.000001	20204	Query	1	20295	use `test`; insert into t1 values( 181 )
+master-bin.000001	20295	Query	1	20386	use `test`; insert into t1 values( 180 )
+master-bin.000001	20386	Query	1	20477	use `test`; insert into t1 values( 179 )
+master-bin.000001	20477	Query	1	20568	use `test`; insert into t1 values( 178 )
+master-bin.000001	20568	Query	1	20659	use `test`; insert into t1 values( 177 )
+master-bin.000001	20659	Query	1	20750	use `test`; insert into t1 values( 176 )
+master-bin.000001	20750	Query	1	20841	use `test`; insert into t1 values( 175 )
+master-bin.000001	20841	Query	1	20932	use `test`; insert into t1 values( 174 )
+master-bin.000001	20932	Query	1	21023	use `test`; insert into t1 values( 173 )
+master-bin.000001	21023	Query	1	21114	use `test`; insert into t1 values( 172 )
+master-bin.000001	21114	Query	1	21205	use `test`; insert into t1 values( 171 )
+master-bin.000001	21205	Query	1	21296	use `test`; insert into t1 values( 170 )
+master-bin.000001	21296	Query	1	21387	use `test`; insert into t1 values( 169 )
+master-bin.000001	21387	Query	1	21478	use `test`; insert into t1 values( 168 )
+master-bin.000001	21478	Query	1	21569	use `test`; insert into t1 values( 167 )
+master-bin.000001	21569	Query	1	21660	use `test`; insert into t1 values( 166 )
+master-bin.000001	21660	Query	1	21751	use `test`; insert into t1 values( 165 )
+master-bin.000001	21751	Query	1	21842	use `test`; insert into t1 values( 164 )
+master-bin.000001	21842	Query	1	21933	use `test`; insert into t1 values( 163 )
+master-bin.000001	21933	Query	1	22024	use `test`; insert into t1 values( 162 )
+master-bin.000001	22024	Query	1	22115	use `test`; insert into t1 values( 161 )
+master-bin.000001	22115	Query	1	22206	use `test`; insert into t1 values( 160 )
+master-bin.000001	22206	Query	1	22297	use `test`; insert into t1 values( 159 )
+master-bin.000001	22297	Query	1	22388	use `test`; insert into t1 values( 158 )
+master-bin.000001	22388	Query	1	22479	use `test`; insert into t1 values( 157 )
+master-bin.000001	22479	Query	1	22570	use `test`; insert into t1 values( 156 )
+master-bin.000001	22570	Query	1	22661	use `test`; insert into t1 values( 155 )
+master-bin.000001	22661	Query	1	22752	use `test`; insert into t1 values( 154 )
+master-bin.000001	22752	Query	1	22843	use `test`; insert into t1 values( 153 )
+master-bin.000001	22843	Query	1	22934	use `test`; insert into t1 values( 152 )
+master-bin.000001	22934	Query	1	23025	use `test`; insert into t1 values( 151 )
+master-bin.000001	23025	Query	1	23116	use `test`; insert into t1 values( 150 )
+master-bin.000001	23116	Query	1	23207	use `test`; insert into t1 values( 149 )
+master-bin.000001	23207	Query	1	23298	use `test`; insert into t1 values( 148 )
+master-bin.000001	23298	Query	1	23389	use `test`; insert into t1 values( 147 )
+master-bin.000001	23389	Query	1	23480	use `test`; insert into t1 values( 146 )
+master-bin.000001	23480	Query	1	23571	use `test`; insert into t1 values( 145 )
+master-bin.000001	23571	Query	1	23662	use `test`; insert into t1 values( 144 )
+master-bin.000001	23662	Query	1	23753	use `test`; insert into t1 values( 143 )
+master-bin.000001	23753	Query	1	23844	use `test`; insert into t1 values( 142 )
+master-bin.000001	23844	Query	1	23935	use `test`; insert into t1 values( 141 )
+master-bin.000001	23935	Query	1	24026	use `test`; insert into t1 values( 140 )
+master-bin.000001	24026	Query	1	24117	use `test`; insert into t1 values( 139 )
+master-bin.000001	24117	Query	1	24208	use `test`; insert into t1 values( 138 )
+master-bin.000001	24208	Query	1	24299	use `test`; insert into t1 values( 137 )
+master-bin.000001	24299	Query	1	24390	use `test`; insert into t1 values( 136 )
+master-bin.000001	24390	Query	1	24481	use `test`; insert into t1 values( 135 )
+master-bin.000001	24481	Query	1	24572	use `test`; insert into t1 values( 134 )
+master-bin.000001	24572	Query	1	24663	use `test`; insert into t1 values( 133 )
+master-bin.000001	24663	Query	1	24754	use `test`; insert into t1 values( 132 )
+master-bin.000001	24754	Query	1	24845	use `test`; insert into t1 values( 131 )
+master-bin.000001	24845	Query	1	24936	use `test`; insert into t1 values( 130 )
+master-bin.000001	24936	Query	1	25027	use `test`; insert into t1 values( 129 )
+master-bin.000001	25027	Query	1	25118	use `test`; insert into t1 values( 128 )
+master-bin.000001	25118	Query	1	25209	use `test`; insert into t1 values( 127 )
+master-bin.000001	25209	Query	1	25300	use `test`; insert into t1 values( 126 )
+master-bin.000001	25300	Query	1	25391	use `test`; insert into t1 values( 125 )
+master-bin.000001	25391	Query	1	25482	use `test`; insert into t1 values( 124 )
+master-bin.000001	25482	Query	1	25573	use `test`; insert into t1 values( 123 )
+master-bin.000001	25573	Query	1	25664	use `test`; insert into t1 values( 122 )
+master-bin.000001	25664	Query	1	25755	use `test`; insert into t1 values( 121 )
+master-bin.000001	25755	Query	1	25846	use `test`; insert into t1 values( 120 )
+master-bin.000001	25846	Query	1	25937	use `test`; insert into t1 values( 119 )
+master-bin.000001	25937	Query	1	26028	use `test`; insert into t1 values( 118 )
+master-bin.000001	26028	Query	1	26119	use `test`; insert into t1 values( 117 )
+master-bin.000001	26119	Query	1	26210	use `test`; insert into t1 values( 116 )
+master-bin.000001	26210	Query	1	26301	use `test`; insert into t1 values( 115 )
+master-bin.000001	26301	Query	1	26392	use `test`; insert into t1 values( 114 )
+master-bin.000001	26392	Query	1	26483	use `test`; insert into t1 values( 113 )
+master-bin.000001	26483	Query	1	26574	use `test`; insert into t1 values( 112 )
+master-bin.000001	26574	Query	1	26665	use `test`; insert into t1 values( 111 )
+master-bin.000001	26665	Query	1	26756	use `test`; insert into t1 values( 110 )
+master-bin.000001	26756	Query	1	26847	use `test`; insert into t1 values( 109 )
+master-bin.000001	26847	Query	1	26938	use `test`; insert into t1 values( 108 )
+master-bin.000001	26938	Query	1	27029	use `test`; insert into t1 values( 107 )
+master-bin.000001	27029	Query	1	27120	use `test`; insert into t1 values( 106 )
+master-bin.000001	27120	Query	1	27211	use `test`; insert into t1 values( 105 )
+master-bin.000001	27211	Query	1	27302	use `test`; insert into t1 values( 104 )
+master-bin.000001	27302	Query	1	27393	use `test`; insert into t1 values( 103 )
+master-bin.000001	27393	Query	1	27484	use `test`; insert into t1 values( 102 )
+master-bin.000001	27484	Query	1	27575	use `test`; insert into t1 values( 101 )
+master-bin.000001	27575	Query	1	27666	use `test`; insert into t1 values( 100 )
+master-bin.000001	27666	Query	1	27756	use `test`; insert into t1 values( 99 )
+master-bin.000001	27756	Query	1	27846	use `test`; insert into t1 values( 98 )
+master-bin.000001	27846	Query	1	27936	use `test`; insert into t1 values( 97 )
+master-bin.000001	27936	Query	1	28026	use `test`; insert into t1 values( 96 )
+master-bin.000001	28026	Query	1	28116	use `test`; insert into t1 values( 95 )
+master-bin.000001	28116	Query	1	28206	use `test`; insert into t1 values( 94 )
+master-bin.000001	28206	Query	1	28296	use `test`; insert into t1 values( 93 )
+master-bin.000001	28296	Query	1	28386	use `test`; insert into t1 values( 92 )
+master-bin.000001	28386	Query	1	28476	use `test`; insert into t1 values( 91 )
+master-bin.000001	28476	Query	1	28566	use `test`; insert into t1 values( 90 )
+master-bin.000001	28566	Query	1	28656	use `test`; insert into t1 values( 89 )
+master-bin.000001	28656	Query	1	28746	use `test`; insert into t1 values( 88 )
+master-bin.000001	28746	Query	1	28836	use `test`; insert into t1 values( 87 )
+master-bin.000001	28836	Query	1	28926	use `test`; insert into t1 values( 86 )
+master-bin.000001	28926	Query	1	29016	use `test`; insert into t1 values( 85 )
+master-bin.000001	29016	Query	1	29106	use `test`; insert into t1 values( 84 )
+master-bin.000001	29106	Query	1	29196	use `test`; insert into t1 values( 83 )
+master-bin.000001	29196	Query	1	29286	use `test`; insert into t1 values( 82 )
+master-bin.000001	29286	Query	1	29376	use `test`; insert into t1 values( 81 )
+master-bin.000001	29376	Query	1	29466	use `test`; insert into t1 values( 80 )
+master-bin.000001	29466	Query	1	29556	use `test`; insert into t1 values( 79 )
+master-bin.000001	29556	Query	1	29646	use `test`; insert into t1 values( 78 )
+master-bin.000001	29646	Query	1	29736	use `test`; insert into t1 values( 77 )
+master-bin.000001	29736	Query	1	29826	use `test`; insert into t1 values( 76 )
+master-bin.000001	29826	Query	1	29916	use `test`; insert into t1 values( 75 )
+master-bin.000001	29916	Query	1	30006	use `test`; insert into t1 values( 74 )
+master-bin.000001	30006	Query	1	30096	use `test`; insert into t1 values( 73 )
+master-bin.000001	30096	Query	1	30186	use `test`; insert into t1 values( 72 )
+master-bin.000001	30186	Query	1	30276	use `test`; insert into t1 values( 71 )
+master-bin.000001	30276	Query	1	30366	use `test`; insert into t1 values( 70 )
+master-bin.000001	30366	Query	1	30456	use `test`; insert into t1 values( 69 )
+master-bin.000001	30456	Query	1	30546	use `test`; insert into t1 values( 68 )
+master-bin.000001	30546	Query	1	30636	use `test`; insert into t1 values( 67 )
+master-bin.000001	30636	Query	1	30726	use `test`; insert into t1 values( 66 )
+master-bin.000001	30726	Query	1	30816	use `test`; insert into t1 values( 65 )
+master-bin.000001	30816	Query	1	30906	use `test`; insert into t1 values( 64 )
+master-bin.000001	30906	Query	1	30996	use `test`; insert into t1 values( 63 )
+master-bin.000001	30996	Query	1	31086	use `test`; insert into t1 values( 62 )
+master-bin.000001	31086	Query	1	31176	use `test`; insert into t1 values( 61 )
+master-bin.000001	31176	Query	1	31266	use `test`; insert into t1 values( 60 )
+master-bin.000001	31266	Query	1	31356	use `test`; insert into t1 values( 59 )
+master-bin.000001	31356	Query	1	31446	use `test`; insert into t1 values( 58 )
+master-bin.000001	31446	Query	1	31536	use `test`; insert into t1 values( 57 )
+master-bin.000001	31536	Query	1	31626	use `test`; insert into t1 values( 56 )
+master-bin.000001	31626	Query	1	31716	use `test`; insert into t1 values( 55 )
+master-bin.000001	31716	Query	1	31806	use `test`; insert into t1 values( 54 )
+master-bin.000001	31806	Query	1	31896	use `test`; insert into t1 values( 53 )
+master-bin.000001	31896	Query	1	31986	use `test`; insert into t1 values( 52 )
+master-bin.000001	31986	Query	1	32076	use `test`; insert into t1 values( 51 )
+master-bin.000001	32076	Query	1	32166	use `test`; insert into t1 values( 50 )
+master-bin.000001	32166	Query	1	32256	use `test`; insert into t1 values( 49 )
+master-bin.000001	32256	Query	1	32346	use `test`; insert into t1 values( 48 )
+master-bin.000001	32346	Query	1	32436	use `test`; insert into t1 values( 47 )
+master-bin.000001	32436	Query	1	32526	use `test`; insert into t1 values( 46 )
+master-bin.000001	32526	Query	1	32616	use `test`; insert into t1 values( 45 )
+master-bin.000001	32616	Query	1	32706	use `test`; insert into t1 values( 44 )
+master-bin.000001	32706	Query	1	32796	use `test`; insert into t1 values( 43 )
+master-bin.000001	32796	Query	1	32886	use `test`; insert into t1 values( 42 )
+master-bin.000001	32886	Query	1	32976	use `test`; insert into t1 values( 41 )
+master-bin.000001	32976	Query	1	33066	use `test`; insert into t1 values( 40 )
+master-bin.000001	33066	Query	1	33156	use `test`; insert into t1 values( 39 )
+master-bin.000001	33156	Query	1	33246	use `test`; insert into t1 values( 38 )
+master-bin.000001	33246	Query	1	33336	use `test`; insert into t1 values( 37 )
+master-bin.000001	33336	Query	1	33426	use `test`; insert into t1 values( 36 )
+master-bin.000001	33426	Query	1	33516	use `test`; insert into t1 values( 35 )
+master-bin.000001	33516	Query	1	33606	use `test`; insert into t1 values( 34 )
+master-bin.000001	33606	Query	1	33696	use `test`; insert into t1 values( 33 )
+master-bin.000001	33696	Query	1	33786	use `test`; insert into t1 values( 32 )
+master-bin.000001	33786	Query	1	33876	use `test`; insert into t1 values( 31 )
+master-bin.000001	33876	Query	1	33966	use `test`; insert into t1 values( 30 )
+master-bin.000001	33966	Query	1	34056	use `test`; insert into t1 values( 29 )
+master-bin.000001	34056	Query	1	34146	use `test`; insert into t1 values( 28 )
+master-bin.000001	34146	Query	1	34236	use `test`; insert into t1 values( 27 )
+master-bin.000001	34236	Query	1	34326	use `test`; insert into t1 values( 26 )
+master-bin.000001	34326	Query	1	34416	use `test`; insert into t1 values( 25 )
+master-bin.000001	34416	Query	1	34506	use `test`; insert into t1 values( 24 )
+master-bin.000001	34506	Query	1	34596	use `test`; insert into t1 values( 23 )
+master-bin.000001	34596	Query	1	34686	use `test`; insert into t1 values( 22 )
+master-bin.000001	34686	Query	1	34776	use `test`; insert into t1 values( 21 )
+master-bin.000001	34776	Query	1	34866	use `test`; insert into t1 values( 20 )
+master-bin.000001	34866	Query	1	34956	use `test`; insert into t1 values( 19 )
+master-bin.000001	34956	Query	1	35046	use `test`; insert into t1 values( 18 )
+master-bin.000001	35046	Query	1	35136	use `test`; insert into t1 values( 17 )
+master-bin.000001	35136	Query	1	35226	use `test`; insert into t1 values( 16 )
+master-bin.000001	35226	Query	1	35316	use `test`; insert into t1 values( 15 )
+master-bin.000001	35316	Query	1	35406	use `test`; insert into t1 values( 14 )
+master-bin.000001	35406	Query	1	35496	use `test`; insert into t1 values( 13 )
+master-bin.000001	35496	Query	1	35586	use `test`; insert into t1 values( 12 )
+master-bin.000001	35586	Query	1	35676	use `test`; insert into t1 values( 11 )
+master-bin.000001	35676	Query	1	35766	use `test`; insert into t1 values( 10 )
+master-bin.000001	35766	Query	1	35855	use `test`; insert into t1 values( 9 )
+master-bin.000001	35855	Query	1	35944	use `test`; insert into t1 values( 8 )
+master-bin.000001	35944	Query	1	36033	use `test`; insert into t1 values( 7 )
+master-bin.000001	36033	Query	1	36122	use `test`; insert into t1 values( 6 )
+master-bin.000001	36122	Query	1	36211	use `test`; insert into t1 values( 5 )
+master-bin.000001	36211	Query	1	36300	use `test`; insert into t1 values( 4 )
+master-bin.000001	36300	Query	1	36389	use `test`; insert into t1 values( 3 )
+master-bin.000001	36389	Query	1	36478	use `test`; insert into t1 values( 2 )
+master-bin.000001	36478	Query	1	36567	use `test`; insert into t1 values( 1 )
+master-bin.000001	36567	Xid	1	36594	COMMIT /* XID */
+master-bin.000001	36594	Rotate	1	36638	master-bin.000002;pos=4
 drop table t1;
 set global binlog_cache_size=@bcs;
 set session autocommit = @ac;
@@ -590,10 +590,10 @@ deallocate prepare stmt;
 drop table t1;
 show binlog events from 0;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server version, Binlog ver: 4
-master-bin.000001	106	Query	1	227	use `test`; create table t1 (a bigint unsigned, b bigint(20) unsigned)
-master-bin.000001	227	Query	1	351	use `test`; insert into t1 values (9999999999999999,14632475938453979136)
-master-bin.000001	351	Query	1	427	use `test`; drop table t1
+master-bin.000001	4	Format_desc	1	107	Server version, Binlog ver: 4
+master-bin.000001	107	Query	1	228	use `test`; create table t1 (a bigint unsigned, b bigint(20) unsigned)
+master-bin.000001	228	Query	1	352	use `test`; insert into t1 values (9999999999999999,14632475938453979136)
+master-bin.000001	352	Query	1	428	use `test`; drop table t1
 reset master;
 CREATE DATABASE bug39182 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
 USE bug39182;
@@ -764,14 +764,14 @@ drop table if exists t3;
 create table t3 (a int(11) NOT NULL AUTO_INCREMENT, b text, PRIMARY KEY (a) ) engine=innodb;
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000001	346		
+master-bin.000001	347		
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 insert into t3(b) values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
 show master status /* must show new binlog index after rotating */;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
-master-bin.000002	106		
+master-bin.000002	107		
 drop table t3;
 #
 # Bug #45998: database crashes when running "create as select"
diff --git a/mysql-test/suite/binlog/t/binlog_auto_increment_bug33029.test b/mysql-test/suite/binlog/t/binlog_auto_increment_bug33029.test
index 5297767675c4fc578c82f63ec92407e161702592..19137066429de642de7bcdea816c0bac1779d8d8 100644
--- a/mysql-test/suite/binlog/t/binlog_auto_increment_bug33029.test
+++ b/mysql-test/suite/binlog/t/binlog_auto_increment_bug33029.test
@@ -25,9 +25,22 @@ let $MYSQLD_DATADIR= `select @@datadir`;
 
 copy_file $MYSQL_TEST_DIR/std_data/bug33029-slave-relay-bin.000001 $MYSQLD_DATADIR/slave-relay-bin.000001;
 
-write_file $MYSQLD_DATADIR/slave-relay-bin.index;
-slave-relay-bin.000001
-EOF
+
+# After patch for BUG#12190, the filename used in CHANGE MASTER
+# RELAY_LOG_FILE will be automatically added the directory of the
+# relay log before comparison, thus we need to added the directory
+# part (./ on unix .\ on windows) when faking the relay-log-bin.index.
+disable_query_log;
+if (`select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows") = 0`)
+{
+  eval select './slave-relay-bin.000001\n' into dumpfile '$MYSQLD_DATADIR/slave-relay-bin.index';
+}
+
+if (`select convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows") != 0`)
+{
+  eval select '.\\\\slave-relay-bin.000001\n' into dumpfile '$MYSQLD_DATADIR/slave-relay-bin.index';
+}
+enable_query_log;
 
 change master to
   MASTER_HOST='dummy.localdomain',
diff --git a/mysql-test/suite/binlog/t/binlog_implicit_commit.test b/mysql-test/suite/binlog/t/binlog_implicit_commit.test
new file mode 100644
index 0000000000000000000000000000000000000000..a682ab95e3d1964c3c261c3fb6666e6da135ed93
--- /dev/null
+++ b/mysql-test/suite/binlog/t/binlog_implicit_commit.test
@@ -0,0 +1,63 @@
+# The purpose of this test is to test that setting autocommit does a
+# commit of outstanding transactions and nothing is left pending in
+# the transaction cache.
+
+source include/have_log_bin.inc;
+source include/have_innodb.inc;
+
+# We need a transactional engine, so let's use InnoDB
+CREATE TABLE t1 (id INT) ENGINE = InnoDB;
+
+# Testing SET AUTOCOMMIT
+SET BINLOG_FORMAT = STATEMENT;
+
+let $cleanup = COMMIT;
+
+let $prepare = SET AUTOCOMMIT = 0;
+let $statement = SET AUTOCOMMIT = 1;
+source extra/binlog_tests/implicit.test;
+
+let $prepare = SET AUTOCOMMIT = 1;
+let $statement = SET AUTOCOMMIT = 1;
+source extra/binlog_tests/implicit.test;
+
+let $prepare = SET AUTOCOMMIT = 0;
+let $statement = SET AUTOCOMMIT = 0;
+source extra/binlog_tests/implicit.test;
+
+let $prepare = SET AUTOCOMMIT = 1;
+let $statement = SET AUTOCOMMIT = 0;
+source extra/binlog_tests/implicit.test;
+
+SET BINLOG_FORMAT = ROW;
+let $prepare = SET AUTOCOMMIT = 0;
+let $statement = SET AUTOCOMMIT = 1;
+source extra/binlog_tests/implicit.test;
+
+let $prepare = SET AUTOCOMMIT = 1;
+let $statement = SET AUTOCOMMIT = 1;
+source extra/binlog_tests/implicit.test;
+
+let $prepare = SET AUTOCOMMIT = 0;
+let $statement = SET AUTOCOMMIT = 0;
+source extra/binlog_tests/implicit.test;
+
+let $prepare = SET AUTOCOMMIT = 1;
+let $statement = SET AUTOCOMMIT = 0;
+source extra/binlog_tests/implicit.test;
+
+RESET MASTER;
+SET AUTOCOMMIT = 0;
+INSERT INTO t1 VALUES (1);
+source include/show_binlog_events.inc;
+LOCK TABLES t1 WRITE;
+source include/show_binlog_events.inc;
+INSERT INTO t1 VALUES (2);
+source include/show_binlog_events.inc;
+UNLOCK TABLES;
+source include/show_binlog_events.inc;
+COMMIT;
+source include/show_binlog_events.inc;
+
+# Cleaning up
+DROP TABLE t1;
diff --git a/mysql-test/suite/binlog/t/binlog_incident.test b/mysql-test/suite/binlog/t/binlog_incident.test
index 901ac49ea24cefe783c9179043f121f28946ca4d..88e7332e88e4c84cb189168b3615843d126beaa1 100644
--- a/mysql-test/suite/binlog/t/binlog_incident.test
+++ b/mysql-test/suite/binlog/t/binlog_incident.test
@@ -20,7 +20,7 @@ REPLACE INTO t1 VALUES (4);
 DROP TABLE t1;
 FLUSH LOGS;
 
-exec $MYSQL_BINLOG --start-position=106 $MYSQLD_DATADIR/master-bin.000001 >$MYSQLTEST_VARDIR/tmp/binlog_incident-bug44442.sql;
+exec $MYSQL_BINLOG --start-position=107 $MYSQLD_DATADIR/master-bin.000001 >$MYSQLTEST_VARDIR/tmp/binlog_incident-bug44442.sql;
 --disable_query_log
 eval SELECT cont LIKE '%RELOAD DATABASE; # Shall generate syntax error%' AS `Contain RELOAD DATABASE` FROM (SELECT load_file('$MYSQLTEST_VARDIR/tmp/binlog_incident-bug44442.sql') AS cont) AS tbl;
 --enable_query_log
diff --git a/mysql-test/suite/binlog/t/binlog_innodb.test b/mysql-test/suite/binlog/t/binlog_innodb.test
index f84fd65226ab0fd47fcc59cd961a615cfc6c47a0..4469fa6224c1ece809b5e817840a0effbbe10e6f 100644
--- a/mysql-test/suite/binlog/t/binlog_innodb.test
+++ b/mysql-test/suite/binlog/t/binlog_innodb.test
@@ -155,7 +155,8 @@ reset master;
 UPDATE t2,t1 SET t2.a=t1.a+2;
 # check
 select * from t2 /* must be (3,1), (4,4) */;
-show master status /* there must no UPDATE in binlog */;
+--echo there must no UPDATE in binlog
+source include/show_master_status.inc;
 
 # B. testing multi_update::send_error() execution branch
 delete from t1;
@@ -165,7 +166,8 @@ insert into t2 values (1,2),(3,4),(4,4);
 reset master;
 --error ER_DUP_ENTRY
 UPDATE t2,t1  SET t2.a=t2.b where t2.a=t1.a;
-show master status /* there must be no UPDATE query event */;
+--echo there must no UPDATE in binlog
+source include/show_master_status.inc;
 
 # cleanup bug#27716
 drop table t1, t2;
diff --git a/mysql-test/suite/binlog/t/binlog_killed.test b/mysql-test/suite/binlog/t/binlog_killed.test
index 9b30ec4a0db266a52c9e46a49aefc0d12cbe5454..d4aa91140cf3a7f957712c4443c888db7b9bc30b 100644
--- a/mysql-test/suite/binlog/t/binlog_killed.test
+++ b/mysql-test/suite/binlog/t/binlog_killed.test
@@ -51,7 +51,7 @@ reap;
 let $rows= `select count(*) from t2  /* must be 2 or 0 */`;
 
 let $MYSQLD_DATADIR= `select @@datadir`;
---exec $MYSQL_BINLOG --force-if-open --start-position=134 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
+--exec $MYSQL_BINLOG --force-if-open --start-position=135 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 eval select
 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
diff --git a/mysql-test/suite/binlog/t/binlog_killed_simulate.test b/mysql-test/suite/binlog/t/binlog_killed_simulate.test
index ec61271ae885f8df40f0c2674b6459786f9f6e15..f9240291dbab44864a22101807d14056a2bbfe78 100644
--- a/mysql-test/suite/binlog/t/binlog_killed_simulate.test
+++ b/mysql-test/suite/binlog/t/binlog_killed_simulate.test
@@ -24,7 +24,7 @@ update t1 set a=2 /* will be "killed" after work has been done */;
 #      for some constants like the offset of the first real event
 #      that is different between severs versions.
 let $MYSQLD_DATADIR= `select @@datadir`;
---exec $MYSQL_BINLOG --force-if-open --start-position=106 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
+--exec $MYSQL_BINLOG --force-if-open --start-position=107 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 eval select
 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
@@ -52,7 +52,7 @@ load data infile '../../std_data/rpl_loaddata.dat' into table t2 /* will be "kil
 
 source include/show_binlog_events.inc;
 
---exec $MYSQL_BINLOG --force-if-open --start-position=98 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
+--exec $MYSQL_BINLOG --force-if-open --start-position=107 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 eval select
 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
diff --git a/mysql-test/suite/federated/federated_server.result b/mysql-test/suite/federated/federated_server.result
index 2c20d1c1d57af33c7b7d02d167f01cbeb151cc23..5079a4dcfa03d469d52a95af82d25c5448be8a90 100644
--- a/mysql-test/suite/federated/federated_server.result
+++ b/mysql-test/suite/federated/federated_server.result
@@ -197,13 +197,13 @@ select * from federated.t1;
 id	name
 1	this is legitimate
 alter server s1 options (database 'db_bogus');
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 flush tables;
 select * from federated.t1;
 id	name
 1	this is legitimate
 alter server s1 options (database 'db_bogus');
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 flush tables;
 select * from federated.t1;
 id	name
@@ -214,7 +214,7 @@ select * from federated.t1;
 id	name
 2	this is bogus
 drop server if exists 's1';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 create server 's1' foreign data wrapper 'mysql' options
 (HOST '127.0.0.1',
 DATABASE 'db_legitimate',
@@ -223,7 +223,7 @@ PASSWORD '',
 PORT SLAVE_PORT,
 SOCKET '',
 OWNER 'root');
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 drop server 's1';
 create server 's1' foreign data wrapper 'mysql' options
 (HOST '127.0.0.1',
diff --git a/mysql-test/suite/funcs_1/r/innodb_trig_03e.result b/mysql-test/suite/funcs_1/r/innodb_trig_03e.result
index 476ccc6ebd826be0d0ed6f45bd67cc8e51cb99c2..25edc0f68bb8da8a809a7e7497f8b4f88fca50c6 100644
--- a/mysql-test/suite/funcs_1/r/innodb_trig_03e.result
+++ b/mysql-test/suite/funcs_1/r/innodb_trig_03e.result
@@ -1251,7 +1251,7 @@ drop trigger trg1_0;
 create definer=not_ex_user@localhost trigger trg1_0
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_0-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 create definer=current_user trigger trg1_1
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-yes';
@@ -1284,7 +1284,7 @@ GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'loca
 create definer=not_ex_user@localhost trigger trg1_3
 after UPDATE on t1 for each row
 set @var1 = 'trig 1_3-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 select current_user;
 current_user
 root@localhost
diff --git a/mysql-test/suite/funcs_1/r/memory_trig_03e.result b/mysql-test/suite/funcs_1/r/memory_trig_03e.result
index bbee7d47e7e44026ab40cc4b24b940e880b33f23..462a88580292cfe6c635353bc9bb19ed3ff7a1be 100644
--- a/mysql-test/suite/funcs_1/r/memory_trig_03e.result
+++ b/mysql-test/suite/funcs_1/r/memory_trig_03e.result
@@ -1252,7 +1252,7 @@ drop trigger trg1_0;
 create definer=not_ex_user@localhost trigger trg1_0
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_0-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 create definer=current_user trigger trg1_1
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-yes';
@@ -1285,7 +1285,7 @@ GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'loca
 create definer=not_ex_user@localhost trigger trg1_3
 after UPDATE on t1 for each row
 set @var1 = 'trig 1_3-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 select current_user;
 current_user
 root@localhost
diff --git a/mysql-test/suite/funcs_1/r/myisam_trig_03e.result b/mysql-test/suite/funcs_1/r/myisam_trig_03e.result
index e4dc67098ad16b361410a7b4d32dfb342c009105..104db478638182d611f10a5eb5dce7d302c0ea95 100644
--- a/mysql-test/suite/funcs_1/r/myisam_trig_03e.result
+++ b/mysql-test/suite/funcs_1/r/myisam_trig_03e.result
@@ -1252,7 +1252,7 @@ drop trigger trg1_0;
 create definer=not_ex_user@localhost trigger trg1_0
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_0-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 create definer=current_user trigger trg1_1
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-yes';
@@ -1285,7 +1285,7 @@ GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'loca
 create definer=not_ex_user@localhost trigger trg1_3
 after UPDATE on t1 for each row
 set @var1 = 'trig 1_3-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 select current_user;
 current_user
 root@localhost
diff --git a/mysql-test/suite/funcs_1/r/ndb_trig_03e.result b/mysql-test/suite/funcs_1/r/ndb_trig_03e.result
index 84260822edf0a2b09f38d25ebb970f2c7036eddf..7338868048142d92a3df2e8d1bc1658a08755c31 100644
--- a/mysql-test/suite/funcs_1/r/ndb_trig_03e.result
+++ b/mysql-test/suite/funcs_1/r/ndb_trig_03e.result
@@ -1251,7 +1251,7 @@ drop trigger trg1_0;
 create definer=not_ex_user@localhost trigger trg1_0
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_0-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 create definer=current_user trigger trg1_1
 before INSERT on t1 for each row
 set new.f1 = 'trig 1_1-yes';
@@ -1284,7 +1284,7 @@ GRANT SELECT, INSERT, UPDATE, TRIGGER ON `priv_db`.`t1` TO 'test_yesprivs'@'loca
 create definer=not_ex_user@localhost trigger trg1_3
 after UPDATE on t1 for each row
 set @var1 = 'trig 1_3-yes';
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 select current_user;
 current_user
 root@localhost
diff --git a/mysql-test/suite/parts/r/rpl_partition.result b/mysql-test/suite/parts/r/rpl_partition.result
index c2537815631391ecdf149c5edf975cbcc662b341..dfce1c3cdfa8356b12488e403bd000fa0ccc0fd4 100644
--- a/mysql-test/suite/parts/r/rpl_partition.result
+++ b/mysql-test/suite/parts/r/rpl_partition.result
@@ -177,6 +177,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT count(*) "Slave norm" FROM t1;
 Slave norm	500
 SELECT count(*) "Slave bykey" FROM t2;
diff --git a/mysql-test/suite/rpl/r/rpl_000015.result b/mysql-test/suite/rpl/r/rpl_000015.result
index 03b96d5870b08f1d454aa2867152bbab5eedd93e..d6cb544df7ccdfa77ac5d4c01fcf6e6870f211ed 100644
--- a/mysql-test/suite/rpl/r/rpl_000015.result
+++ b/mysql-test/suite/rpl/r/rpl_000015.result
@@ -44,6 +44,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	0
 change master to master_host='127.0.0.1',master_user='root',
 master_password='',master_port=MASTER_PORT;
 SHOW SLAVE STATUS;
@@ -85,6 +87,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	0
 start slave;
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -125,6 +129,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 drop table if exists t1;
 create table t1 (n int, PRIMARY KEY(n));
 insert into t1 values (10),(45),(90);
diff --git a/mysql-test/suite/rpl/r/rpl_binlog_grant.result b/mysql-test/suite/rpl/r/rpl_binlog_grant.result
index 4a789f361c63f25666c3187cce81077ce0e7791d..2a7e440150099f2aa96319ce9507d72dcb985c84 100644
--- a/mysql-test/suite/rpl/r/rpl_binlog_grant.result
+++ b/mysql-test/suite/rpl/r/rpl_binlog_grant.result
@@ -17,16 +17,15 @@ show grants for x@y;
 Grants for x@y
 GRANT USAGE ON *.* TO 'x'@'y'
 GRANT SELECT ON `d1`.`t` TO 'x'@'y'
-show binlog events;
+show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: VERSION, Binlog ver: 4
-master-bin.000001	106	Query	1	193	drop database if exists d1
-master-bin.000001	193	Query	1	272	create database d1
-master-bin.000001	272	Query	1	370	use `d1`; create table t (s1 int) engine=innodb
-master-bin.000001	370	Query	1	436	BEGIN
-master-bin.000001	436	Query	1	521	use `d1`; insert into t values (1)
-master-bin.000001	521	Xid	1	548	COMMIT /* XID */
-master-bin.000001	548	Query	1	633	use `d1`; grant select on t to x@y
+master-bin.000001	#	Query	#	#	drop database if exists d1
+master-bin.000001	#	Query	#	#	create database d1
+master-bin.000001	#	Query	#	#	use `d1`; create table t (s1 int) engine=innodb
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `d1`; insert into t values (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	use `d1`; grant select on t to x@y
 start transaction;
 insert into t values (2);
 revoke select on t from x@y;
@@ -38,19 +37,18 @@ s1
 show grants for x@y;
 Grants for x@y
 GRANT USAGE ON *.* TO 'x'@'y'
-show binlog events;
+show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: VERSION, Binlog ver: 4
-master-bin.000001	106	Query	1	193	drop database if exists d1
-master-bin.000001	193	Query	1	272	create database d1
-master-bin.000001	272	Query	1	370	use `d1`; create table t (s1 int) engine=innodb
-master-bin.000001	370	Query	1	436	BEGIN
-master-bin.000001	436	Query	1	521	use `d1`; insert into t values (1)
-master-bin.000001	521	Xid	1	548	COMMIT /* XID */
-master-bin.000001	548	Query	1	633	use `d1`; grant select on t to x@y
-master-bin.000001	633	Query	1	699	BEGIN
-master-bin.000001	699	Query	1	784	use `d1`; insert into t values (2)
-master-bin.000001	784	Xid	1	811	COMMIT /* XID */
-master-bin.000001	811	Query	1	899	use `d1`; revoke select on t from x@y
+master-bin.000001	#	Query	#	#	drop database if exists d1
+master-bin.000001	#	Query	#	#	create database d1
+master-bin.000001	#	Query	#	#	use `d1`; create table t (s1 int) engine=innodb
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `d1`; insert into t values (1)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	use `d1`; grant select on t to x@y
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Query	#	#	use `d1`; insert into t values (2)
+master-bin.000001	#	Xid	#	#	COMMIT /* XID */
+master-bin.000001	#	Query	#	#	use `d1`; revoke select on t from x@y
 drop user x@y;
 drop database d1;
diff --git a/mysql-test/suite/rpl/r/rpl_bug33931.result b/mysql-test/suite/rpl/r/rpl_bug33931.result
index a17941f6ba92bf206aed2493a7f5b266aa9327d5..ba3c3ebafe6be77a4b61965c3318991dea6c8c40 100644
--- a/mysql-test/suite/rpl/r/rpl_bug33931.result
+++ b/mysql-test/suite/rpl/r/rpl_bug33931.result
@@ -43,4 +43,6 @@ Last_IO_Errno	0
 Last_IO_Error	
 Last_SQL_Errno	#
 Last_SQL_Error	Failed during slave thread initialization
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	0
 SET GLOBAL debug="";
diff --git a/mysql-test/suite/rpl/r/rpl_change_master.result b/mysql-test/suite/rpl/r/rpl_change_master.result
index c06c1201e3dad4315d3c19e37070e9564aaed1d6..a51ba50475b395f98e6fbde3b88b007a9ebe2fa2 100644
--- a/mysql-test/suite/rpl/r/rpl_change_master.result
+++ b/mysql-test/suite/rpl/r/rpl_change_master.result
@@ -50,6 +50,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 change master to master_user='root';
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -90,9 +92,28 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave;
 select * from t1;
 n
 1
 2
 drop table t1;
+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 (a int);
+insert into t1 values (1);
+flush logs;
+insert into t1 values (2);
+include/stop_slave.inc
+delete from t1 where a=2;
+CHANGE MASTER TO relay_log_file='slave-relay-bin.000005', relay_log_pos=4;
+start slave sql_thread;
+start slave io_thread;
+set global relay_log_purge=1;
+drop table t1;
diff --git a/mysql-test/suite/rpl/r/rpl_deadlock_innodb.result b/mysql-test/suite/rpl/r/rpl_deadlock_innodb.result
index 6c8d35619e5375f344eeff865019bb448e3cebcc..25c31675b535d2a80333b458254398846850b3cd 100644
--- a/mysql-test/suite/rpl/r/rpl_deadlock_innodb.result
+++ b/mysql-test/suite/rpl/r/rpl_deadlock_innodb.result
@@ -89,6 +89,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 *** Test lock wait timeout ***
 include/stop_slave.inc
@@ -151,13 +153,15 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 *** Test lock wait timeout and purged relay logs ***
 SET @my_max_relay_log_size= @@global.max_relay_log_size;
 SET global max_relay_log_size=0;
 include/stop_slave.inc
 DELETE FROM t2;
-CHANGE MASTER TO MASTER_LOG_POS=440;
+CHANGE MASTER TO MASTER_LOG_POS=441;
 BEGIN;
 SELECT * FROM t1 FOR UPDATE;
 a
@@ -218,6 +222,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 *** Clean up ***
 DROP TABLE t1,t2,t3;
diff --git a/mysql-test/suite/rpl/r/rpl_empty_master_host.result b/mysql-test/suite/rpl/r/rpl_empty_master_host.result
new file mode 100644
index 0000000000000000000000000000000000000000..46ef32d415b74e1dfec9fdec2c5eb3209186ad4e
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_empty_master_host.result
@@ -0,0 +1,16 @@
+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;
+STOP SLAVE;
+Master_Host = '127.0.0.1' (expected '127.0.0.1')
+CHANGE MASTER TO MASTER_HOST="";
+ERROR HY000: Incorrect arguments to MASTER_HOST
+Master_Host = '127.0.0.1' (expected '127.0.0.1')
+CHANGE MASTER TO MASTER_HOST="foo";
+Master_Host = 'foo' (expected 'foo')
+CHANGE MASTER TO MASTER_HOST="127.0.0.1";
+Master_Host = '127.0.0.1' (expected '127.0.0.1')
+START SLAVE;
diff --git a/mysql-test/suite/rpl/r/rpl_extraCol_innodb.result b/mysql-test/suite/rpl/r/rpl_extraCol_innodb.result
index e2ec78e7adc8e6b8bbffabffd08a7b185e0bf2de..21d9fc5a919aeae05340df6e77f7199d2fe9be67 100644
--- a/mysql-test/suite/rpl/r/rpl_extraCol_innodb.result
+++ b/mysql-test/suite/rpl/r/rpl_extraCol_innodb.result
@@ -93,6 +93,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 size mismatch - master has size 10, test.t2 on slave has size 6. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 SELECT * FROM t2 ORDER BY a;
@@ -160,6 +162,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 252, test.t3 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t3  ***
@@ -222,6 +226,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 246, test.t4 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t4  ***
@@ -284,6 +290,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 5 type mismatch - received type 4, test.t5 has type 246
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t5  ***
@@ -345,6 +353,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 3 type mismatch - received type 16, test.t6 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=3;
 *** Drop t6  ***
 DROP TABLE t6;
@@ -404,7 +414,11 @@ STOP SLAVE;
 RESET SLAVE;
 CREATE TABLE t9 (a INT KEY, b BLOB, c CHAR(5),
 d TIMESTAMP,
-e INT NOT NULL) ENGINE='InnoDB';
+e INT NOT NULL,
+f text not null,
+g text,
+h blob not null,
+i blob) ENGINE='InnoDB';
 *** Create t9 on Master ***
 CREATE TABLE t9 (a INT PRIMARY KEY, b BLOB, c CHAR(5)
 ) ENGINE='InnoDB';
@@ -415,47 +429,11 @@ START SLAVE;
 set @b1 = 'b1b1b1b1';
 set @b1 = concat(@b1,@b1);
 INSERT INTO t9 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
-SHOW SLAVE STATUS;
-Slave_IO_State	#
-Master_Host	127.0.0.1
-Master_User	root
-Master_Port	#
-Connect_Retry	1
-Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	#
-Relay_Log_File	#
-Relay_Log_Pos	#
-Relay_Master_Log_File	master-bin.000001
-Slave_IO_Running	Yes
-Slave_SQL_Running	No
-Replicate_Do_DB	
-Replicate_Ignore_DB	
-Replicate_Do_Table	
-Replicate_Ignore_Table	#
-Replicate_Wild_Do_Table	
-Replicate_Wild_Ignore_Table	
-Last_Errno	1364
-Last_Error	Could not execute Write_rows event on table test.t9; Field 'e' doesn't have a default value, Error_code: 1364; handler error HA_ERR_ROWS_EVENT_APPLY; the event's master log master-bin.000001, end_log_pos 330
-Skip_Counter	0
-Exec_Master_Log_Pos	#
-Relay_Log_Space	#
-Until_Condition	None
-Until_Log_File	
-Until_Log_Pos	0
-Master_SSL_Allowed	No
-Master_SSL_CA_File	
-Master_SSL_CA_Path	
-Master_SSL_Cert	
-Master_SSL_Cipher	
-Master_SSL_Key	
-Seconds_Behind_Master	#
-Master_SSL_Verify_Server_Cert	No
-Last_IO_Errno	#
-Last_IO_Error	#
-Last_SQL_Errno	1364
-Last_SQL_Error	Could not execute Write_rows event on table test.t9; Field 'e' doesn't have a default value, Error_code: 1364; handler error HA_ERR_ROWS_EVENT_APPLY; the event's master log master-bin.000001, end_log_pos 330
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
+select * from t9;
+a	b	c	d	e	f	g	h	i
+1	b1b1b1b1b1b1b1b1	Kyle	0000-00-00 00:00:00	0		NULL		NULL
+2	b1b1b1b1b1b1b1b1	JOE	0000-00-00 00:00:00	0		NULL		NULL
+3	b1b1b1b1b1b1b1b1	QA	0000-00-00 00:00:00	0		NULL		NULL
 *** Create t10 on slave  ***
 STOP SLAVE;
 RESET SLAVE;
@@ -513,6 +491,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 254, test.t10 has type 5
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t10  ***
@@ -574,6 +554,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 15, test.t11 has type 252
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t11  ***
@@ -824,6 +806,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1060
 Last_SQL_Error	Error 'Duplicate column name 'c6'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c6 INT AFTER c5'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 *** Try to insert in master ****
@@ -964,6 +948,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 8, test.t17 has type 2
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 ** DROP table t17 ***
diff --git a/mysql-test/suite/rpl/r/rpl_extraCol_myisam.result b/mysql-test/suite/rpl/r/rpl_extraCol_myisam.result
index ed5b4eac27dbf29e77bc0fac92907e499e4ddcc8..053dee9067b2615be84d8a77711a60387560cc8b 100644
--- a/mysql-test/suite/rpl/r/rpl_extraCol_myisam.result
+++ b/mysql-test/suite/rpl/r/rpl_extraCol_myisam.result
@@ -93,6 +93,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 size mismatch - master has size 10, test.t2 on slave has size 6. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 SELECT * FROM t2 ORDER BY a;
@@ -160,6 +162,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 252, test.t3 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t3  ***
@@ -222,6 +226,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 246, test.t4 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t4  ***
@@ -284,6 +290,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 5 type mismatch - received type 4, test.t5 has type 246
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t5  ***
@@ -345,6 +353,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 3 type mismatch - received type 16, test.t6 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=3;
 *** Drop t6  ***
 DROP TABLE t6;
@@ -404,7 +414,11 @@ STOP SLAVE;
 RESET SLAVE;
 CREATE TABLE t9 (a INT KEY, b BLOB, c CHAR(5),
 d TIMESTAMP,
-e INT NOT NULL) ENGINE='MyISAM';
+e INT NOT NULL,
+f text not null,
+g text,
+h blob not null,
+i blob) ENGINE='MyISAM';
 *** Create t9 on Master ***
 CREATE TABLE t9 (a INT PRIMARY KEY, b BLOB, c CHAR(5)
 ) ENGINE='MyISAM';
@@ -415,47 +429,11 @@ START SLAVE;
 set @b1 = 'b1b1b1b1';
 set @b1 = concat(@b1,@b1);
 INSERT INTO t9 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
-SHOW SLAVE STATUS;
-Slave_IO_State	#
-Master_Host	127.0.0.1
-Master_User	root
-Master_Port	#
-Connect_Retry	1
-Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	#
-Relay_Log_File	#
-Relay_Log_Pos	#
-Relay_Master_Log_File	master-bin.000001
-Slave_IO_Running	Yes
-Slave_SQL_Running	No
-Replicate_Do_DB	
-Replicate_Ignore_DB	
-Replicate_Do_Table	
-Replicate_Ignore_Table	#
-Replicate_Wild_Do_Table	
-Replicate_Wild_Ignore_Table	
-Last_Errno	1364
-Last_Error	Could not execute Write_rows event on table test.t9; Field 'e' doesn't have a default value, Error_code: 1364; handler error HA_ERR_ROWS_EVENT_APPLY; the event's master log master-bin.000001, end_log_pos 330
-Skip_Counter	0
-Exec_Master_Log_Pos	#
-Relay_Log_Space	#
-Until_Condition	None
-Until_Log_File	
-Until_Log_Pos	0
-Master_SSL_Allowed	No
-Master_SSL_CA_File	
-Master_SSL_CA_Path	
-Master_SSL_Cert	
-Master_SSL_Cipher	
-Master_SSL_Key	
-Seconds_Behind_Master	#
-Master_SSL_Verify_Server_Cert	No
-Last_IO_Errno	#
-Last_IO_Error	#
-Last_SQL_Errno	1364
-Last_SQL_Error	Could not execute Write_rows event on table test.t9; Field 'e' doesn't have a default value, Error_code: 1364; handler error HA_ERR_ROWS_EVENT_APPLY; the event's master log master-bin.000001, end_log_pos 330
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
+select * from t9;
+a	b	c	d	e	f	g	h	i
+1	b1b1b1b1b1b1b1b1	Kyle	0000-00-00 00:00:00	0		NULL		NULL
+2	b1b1b1b1b1b1b1b1	JOE	0000-00-00 00:00:00	0		NULL		NULL
+3	b1b1b1b1b1b1b1b1	QA	0000-00-00 00:00:00	0		NULL		NULL
 *** Create t10 on slave  ***
 STOP SLAVE;
 RESET SLAVE;
@@ -513,6 +491,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 254, test.t10 has type 5
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t10  ***
@@ -574,6 +554,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 15, test.t11 has type 252
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t11  ***
@@ -824,6 +806,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1060
 Last_SQL_Error	Error 'Duplicate column name 'c6'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c6 INT AFTER c5'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 *** Try to insert in master ****
@@ -964,6 +948,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 8, test.t17 has type 2
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 ** DROP table t17 ***
diff --git a/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result b/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result
index ad67f96db71d3f18e0d803e9c493b1f0eda07c31..ffc42c852be581b2b323955bf94de73c51a5e5b2 100644
--- a/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result
+++ b/mysql-test/suite/rpl/r/rpl_extraColmaster_innodb.result
@@ -133,6 +133,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 
 ***** Testing Altering table def scenario *****
@@ -509,6 +511,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 ****************************************
 * columns in master at middle of table *
@@ -583,6 +587,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 5, test.t10 has type 254
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -658,6 +664,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 252, test.t11 has type 15
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -809,6 +817,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1091
 Last_SQL_Error	Error 'Can't DROP 'c7'; check that column/key exists' on query. Default database: 'test'. Query: 'ALTER TABLE t14 DROP COLUMN c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -895,6 +905,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1054
 Last_SQL_Error	Error 'Unknown column 'c7' in 't15'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c2 DECIMAL(8,2) AFTER c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -981,6 +993,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1072
 Last_SQL_Error	Error 'Key column 'c6' doesn't exist in table' on query. Default database: 'test'. Query: 'CREATE INDEX part_of_c6 ON t16 (c6)'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -1274,6 +1288,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 
 ***** Testing Altering table def scenario *****
@@ -1650,6 +1666,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 ****************************************
 * columns in master at middle of table *
@@ -1724,6 +1742,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 5, test.t10 has type 254
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -1799,6 +1819,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 252, test.t11 has type 15
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -1950,6 +1972,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1091
 Last_SQL_Error	Error 'Can't DROP 'c7'; check that column/key exists' on query. Default database: 'test'. Query: 'ALTER TABLE t14 DROP COLUMN c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -2036,6 +2060,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1054
 Last_SQL_Error	Error 'Unknown column 'c7' in 't15'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c2 DECIMAL(8,2) AFTER c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -2122,6 +2148,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1072
 Last_SQL_Error	Error 'Key column 'c6' doesn't exist in table' on query. Default database: 'test'. Query: 'CREATE INDEX part_of_c6 ON t16 (c6)'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -2415,6 +2443,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 
 ***** Testing Altering table def scenario *****
@@ -2791,6 +2821,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 ****************************************
 * columns in master at middle of table *
@@ -2865,6 +2897,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 5, test.t10 has type 254
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -2940,6 +2974,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 252, test.t11 has type 15
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -3091,6 +3127,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1091
 Last_SQL_Error	Error 'Can't DROP 'c7'; check that column/key exists' on query. Default database: 'test'. Query: 'ALTER TABLE t14 DROP COLUMN c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -3177,6 +3215,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1054
 Last_SQL_Error	Error 'Unknown column 'c7' in 't15'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c2 DECIMAL(8,2) AFTER c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -3263,6 +3303,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1072
 Last_SQL_Error	Error 'Key column 'c6' doesn't exist in table' on query. Default database: 'test'. Query: 'CREATE INDEX part_of_c6 ON t16 (c6)'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
diff --git a/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result b/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result
index 8859a8e24e3e37fe70793804bb0fb9602e048382..0c3dd7ed21db000dcbe07ff5a7e81927bbf5553c 100644
--- a/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result
+++ b/mysql-test/suite/rpl/r/rpl_extraColmaster_myisam.result
@@ -133,6 +133,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 
 ***** Testing Altering table def scenario *****
@@ -509,6 +511,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 ****************************************
 * columns in master at middle of table *
@@ -583,6 +587,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 5, test.t10 has type 254
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -658,6 +664,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 252, test.t11 has type 15
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -809,6 +817,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1091
 Last_SQL_Error	Error 'Can't DROP 'c7'; check that column/key exists' on query. Default database: 'test'. Query: 'ALTER TABLE t14 DROP COLUMN c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -895,6 +905,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1054
 Last_SQL_Error	Error 'Unknown column 'c7' in 't15'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c2 DECIMAL(8,2) AFTER c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -981,6 +993,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1072
 Last_SQL_Error	Error 'Key column 'c6' doesn't exist in table' on query. Default database: 'test'. Query: 'CREATE INDEX part_of_c6 ON t16 (c6)'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -1274,6 +1288,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 
 ***** Testing Altering table def scenario *****
@@ -1650,6 +1666,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 ****************************************
 * columns in master at middle of table *
@@ -1724,6 +1742,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 5, test.t10 has type 254
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -1799,6 +1819,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 252, test.t11 has type 15
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -1950,6 +1972,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1091
 Last_SQL_Error	Error 'Can't DROP 'c7'; check that column/key exists' on query. Default database: 'test'. Query: 'ALTER TABLE t14 DROP COLUMN c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -2036,6 +2060,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1054
 Last_SQL_Error	Error 'Unknown column 'c7' in 't15'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c2 DECIMAL(8,2) AFTER c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -2122,6 +2148,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1072
 Last_SQL_Error	Error 'Key column 'c6' doesn't exist in table' on query. Default database: 'test'. Query: 'CREATE INDEX part_of_c6 ON t16 (c6)'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -2415,6 +2443,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 
 ***** Testing Altering table def scenario *****
@@ -2791,6 +2821,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 
 ****************************************
 * columns in master at middle of table *
@@ -2865,6 +2897,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 5, test.t10 has type 254
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -2940,6 +2974,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 252, test.t11 has type 15
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 
@@ -3091,6 +3127,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1091
 Last_SQL_Error	Error 'Can't DROP 'c7'; check that column/key exists' on query. Default database: 'test'. Query: 'ALTER TABLE t14 DROP COLUMN c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -3177,6 +3215,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1054
 Last_SQL_Error	Error 'Unknown column 'c7' in 't15'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c2 DECIMAL(8,2) AFTER c7'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
@@ -3263,6 +3303,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1072
 Last_SQL_Error	Error 'Key column 'c6' doesn't exist in table' on query. Default database: 'test'. Query: 'CREATE INDEX part_of_c6 ON t16 (c6)'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 
diff --git a/mysql-test/suite/rpl/r/rpl_flushlog_loop.result b/mysql-test/suite/rpl/r/rpl_flushlog_loop.result
index 600ac44fc86d1dcb8a9ccbee1c654fe3d417a6d8..5e74a4eb9991a369cc92bbb854be45a411fed9e5 100644
--- a/mysql-test/suite/rpl/r/rpl_flushlog_loop.result
+++ b/mysql-test/suite/rpl/r/rpl_flushlog_loop.result
@@ -10,6 +10,7 @@ relay_log	MYSQLD_DATADIR/relay-log
 relay_log_index	
 relay_log_info_file	relay-log.info
 relay_log_purge	ON
+relay_log_recovery	OFF
 relay_log_space_limit	0
 stop slave;
 change master to master_host='127.0.0.1',master_user='root',
@@ -59,3 +60,5 @@ Last_IO_Errno	#
 Last_IO_Error	
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	2
diff --git a/mysql-test/suite/rpl/r/rpl_grant.result b/mysql-test/suite/rpl/r/rpl_grant.result
index 1bed6101e3cfb3b6c12e30cddb1a106cf84c7ba1..fc32dcefec76c344d04ade88a63c05ec665f1d4d 100644
--- a/mysql-test/suite/rpl/r/rpl_grant.result
+++ b/mysql-test/suite/rpl/r/rpl_grant.result
@@ -80,3 +80,5 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat.result b/mysql-test/suite/rpl/r/rpl_heartbeat.result
new file mode 100644
index 0000000000000000000000000000000000000000..b79545b8336a1bb757c36a897573c5157c33c4b4
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat.result
@@ -0,0 +1,145 @@
+reset master;
+set @restore_slave_net_timeout= @@global.slave_net_timeout;
+set @@global.slave_net_timeout= 10;
+Warnings:
+Warning	1624	The currect value for master_heartbeat_period exceeds the new value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout.
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root';
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	5.000
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 4294968;
+ERROR HY000: The requested value for the heartbeat period  is negative or exceeds the maximum  4294967 seconds
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	5.000
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 0.0009999;
+Warnings:
+Warning	1624	The requested value for the heartbeat period  is less than 1 msec.  The period is reset to zero which means no heartbeats will be sending
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	0.000
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 4294967;
+Warnings:
+Warning	1624	The requested value for the heartbeat period  exceeds the value of `slave_net_timeout' sec.  A sensible value for the period should be less than the timeout.
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	4294967.000
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 0.001;
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	0.001
+reset slave;
+set @@global.slave_net_timeout= 5;
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 5.001;
+Warnings:
+Warning	1624	The requested value for the heartbeat period  exceeds the value of `slave_net_timeout' sec.  A sensible value for the period should be less than the timeout.
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	5.001
+reset slave;
+set @@global.slave_net_timeout= 5;
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 4;
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	4.000
+set @@global.slave_net_timeout= 3 /* must be a warning */;
+Warnings:
+Warning	1624	The currect value for master_heartbeat_period exceeds the new value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout.
+reset slave;
+drop table if exists t1;
+set @@global.slave_net_timeout= 10;
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 0.5;
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	0.500
+start slave;
+create table t1 (f1 int);
+SHOW SLAVE STATUS;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	master-bin.000001
+Read_Master_Log_Pos	280
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	master-bin.000001
+Slave_IO_Running	Yes
+Slave_SQL_Running	Yes
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	#
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	0
+Last_Error	
+Skip_Counter	0
+Exec_Master_Log_Pos	280
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	#
+Last_IO_Error	#
+Last_SQL_Errno	0
+Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
+SHOW SLAVE STATUS;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	master-bin.000001
+Read_Master_Log_Pos	280
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	master-bin.000001
+Slave_IO_Running	Yes
+Slave_SQL_Running	Yes
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	#
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	0
+Last_Error	
+Skip_Counter	0
+Exec_Master_Log_Pos	280
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	#
+Last_IO_Error	#
+Last_SQL_Errno	0
+Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
+show status like 'Slave_heartbeat_period';;
+Variable_name	Slave_heartbeat_period
+Value	0.500
+A heartbeat has been received by the slave
+drop table t1;
+set @@global.slave_net_timeout= @restore_slave_net_timeout;
+End of tests
diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat_2slaves.result b/mysql-test/suite/rpl/r/rpl_heartbeat_2slaves.result
new file mode 100644
index 0000000000000000000000000000000000000000..ecb7c62c488c9fd9509f5d1709f42d78fed8b92a
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat_2slaves.result
@@ -0,0 +1,55 @@
+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;
+
+*** Preparing ***
+[on slave]
+include/stop_slave.inc
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1, MASTER_LOG_FILE='MASTER_BINLOG';
+include/start_slave.inc
+[on slave1]
+STOP SLAVE;
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=1, MASTER_LOG_FILE='MASTER_BINLOG';
+include/start_slave.inc
+
+*** 2 slaves ***
+Slave has received heartbeat event
+Slave1 has received heartbeat event
+Slave has received more heartbeats than Slave1 (1 means 'yes'): 1
+
+*** Master->data->Slave1->heartbeat->Slave: ***
+[on slave1]
+RESET MASTER;
+[on slave]
+include/stop_slave.inc
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=SLAVE1_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.2, MASTER_LOG_FILE='SLAVE1_BINLOG';
+include/start_slave.inc
+Slave has received heartbeat event
+[on master]
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10), c LONGTEXT);
+INSERT INTO t1 VALUES (1, 'on master', '');
+SHOW TABLES;
+Tables_in_test
+t1
+[on slave1]
+SHOW TABLES;
+Tables_in_test
+t1
+[on slave]
+SHOW TABLES;
+Tables_in_test
+[on master]
+creating updates on master and send to slave1 during 5 second
+[on slave]
+Slave has received heartbeats (1 means 'yes'): 1
+
+*** Clean up ***
+DROP TABLE t1;
+
+End of 6.0 test
diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result
new file mode 100644
index 0000000000000000000000000000000000000000..d229e1260dd131412f974c4623abeaacaa1ea0e5
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result
@@ -0,0 +1,299 @@
+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;
+
+*** Preparing ***
+include/stop_slave.inc
+RESET SLAVE;
+SET @restore_slave_net_timeout=@@global.slave_net_timeout;
+RESET MASTER;
+SET @restore_slave_net_timeout=@@global.slave_net_timeout;
+SET @restore_event_scheduler=@@global.event_scheduler;
+
+*** Default value ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root';
+slave_net_timeout/slave_heartbeat_timeout=2.0000
+RESET SLAVE;
+
+*** Reset slave affect ***
+SET @@global.slave_net_timeout=30;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=5;
+RESET SLAVE;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	15.000
+
+*** Default value if slave_net_timeout changed ***
+SET @@global.slave_net_timeout=50;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root';
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	25.000
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+RESET SLAVE;
+
+*** Warning if updated slave_net_timeout < slave_heartbeat_timeout ***
+SET @@global.slave_net_timeout=FLOOR(SLAVE_HEARTBEAT_TIMEOUT)-1;
+Warnings:
+Warning	1624	The currect value for master_heartbeat_period exceeds the new value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout.
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+RESET SLAVE;
+
+*** Warning if updated slave_heartbeat_timeout > slave_net_timeout ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=SLAVE_NET_TIMEOUT;
+Warnings:
+Warning	1624	The requested value for the heartbeat period  exceeds the value of `slave_net_timeout' sec.  A sensible value for the period should be less than the timeout.
+RESET SLAVE;
+
+*** CHANGE MASTER statement only updates slave_heartbeat_period ***
+SET @@global.slave_net_timeout=20;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=5;
+SHOW VARIABLES LIKE 'slave_net_timeout';
+Variable_name	Value
+slave_net_timeout	20
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	5.000
+SET @@global.slave_net_timeout=2*@@global.slave_net_timeout;
+SHOW VARIABLES LIKE 'slave_net_timeout';
+Variable_name	Value
+slave_net_timeout	40
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	5.000
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+RESET SLAVE;
+
+*** Update slave_net_timeout on master ***
+SET @@global.slave_net_timeout=500;
+SET @@global.slave_net_timeout=200;
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root';
+include/start_slave.inc
+SHOW VARIABLES LIKE 'slave_net_timeout';
+Variable_name	Value
+slave_net_timeout	200
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	100.000
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+include/stop_slave.inc
+RESET SLAVE;
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+
+*** Start/stop slave ***
+SET @@global.slave_net_timeout=100;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=20;
+include/start_slave.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	20.000
+include/stop_slave.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	20.000
+
+*** Reload slave ***
+SET @@global.slave_net_timeout=50;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=30;
+Reload slave
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	30.000
+SET @restore_slave_net_timeout=@@global.slave_net_timeout;
+
+*** Disable heartbeat ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	0.000
+SHOW STATUS LIKE 'slave_received_heartbeats';
+Variable_name	Value
+Slave_received_heartbeats	0
+include/start_slave.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	0.000
+SHOW STATUS LIKE 'slave_received_heartbeats';
+Variable_name	Value
+Slave_received_heartbeats	0
+include/stop_slave.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	0.000
+SHOW STATUS LIKE 'slave_received_heartbeats';
+Variable_name	Value
+Slave_received_heartbeats	0
+RESET SLAVE;
+SELECT SLAVE_HEARTBEAT_TIMEOUT = 0 AS Result;
+Result
+0
+
+*** Min slave_heartbeat_timeout ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.001;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	0.001
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.0009;
+Warnings:
+Warning	1624	The requested value for the heartbeat period  is less than 1 msec.  The period is reset to zero which means no heartbeats will be sending
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	0.000
+RESET SLAVE;
+
+*** Max slave_heartbeat_timeout ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294967;
+Warnings:
+Warning	1624	The requested value for the heartbeat period  exceeds the value of `slave_net_timeout' sec.  A sensible value for the period should be less than the timeout.
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+Variable_name	Value
+Slave_heartbeat_period	4294967.000
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294968;
+ERROR HY000: The requested value for the heartbeat period  is negative or exceeds the maximum  4294967 seconds
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=8589935;
+ERROR HY000: The requested value for the heartbeat period  is negative or exceeds the maximum  4294967 seconds
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294967296;
+ERROR HY000: The requested value for the heartbeat period  is negative or exceeds the maximum  4294967 seconds
+RESET SLAVE;
+
+*** Misc incorrect values ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD='-1';
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''-1'' at line 1
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD='123abc';
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''123abc'' at line 1
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD='';
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''' at line 1
+RESET SLAVE;
+
+*** Running slave ***
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+include/start_slave.inc
+Heartbeat event received
+
+*** Stopped slave ***
+include/stop_slave.inc
+Number of received heartbeat events while slave stopped: 0
+
+*** Started slave ***
+include/start_slave.inc
+Heartbeat event received
+
+*** Stopped IO thread ***
+STOP SLAVE IO_THREAD;
+Number of received heartbeat events while io thread stopped: 0
+
+*** Started IO thread ***
+START SLAVE IO_THREAD;
+Heartbeat event received
+
+*** Stopped SQL thread ***
+STOP SLAVE SQL_THREAD;
+Heartbeat events are received while sql thread stopped (1 means 'yes'): 1
+
+*** Started SQL thread ***
+START SLAVE SQL_THREAD;
+Heartbeat event received
+
+*** Stopped SQL thread by error ***
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10), c LONGTEXT);
+INSERT INTO t1 VALUES (1, 'on slave', NULL);
+INSERT INTO t1 VALUES (1, 'on master', NULL);
+Heartbeat events are received while sql thread stopped (1 means 'yes'): 1
+include/stop_slave.inc
+DROP TABLE t1;
+
+*** Master send to slave ***
+CREATE EVENT e1 
+ON SCHEDULE EVERY 1 SECOND
+DO
+BEGIN
+UPDATE test.t1 SET a = a + 1 WHERE a < 10;
+END|
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=5;
+include/start_slave.inc
+SET @@global.event_scheduler=1;
+Number of received heartbeat events: 0
+DELETE FROM t1;
+DROP EVENT e1;
+
+*** Flush logs on slave ***
+STOP SLAVE;
+RESET SLAVE;
+DROP TABLE t1;
+DROP TABLE t1;
+RESET MASTER;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.5;
+include/start_slave.inc
+Heartbeat events are received while rotation of relay logs (1 means 'yes'): 1
+
+*** Compressed protocol ***
+SET @@global.slave_compressed_protocol=1;
+include/stop_slave.inc
+RESET SLAVE;
+SET @@global.slave_compressed_protocol=1;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+include/start_slave.inc
+Heartbeat event received
+SET @@global.slave_compressed_protocol=0;
+SET @@global.slave_compressed_protocol=0;
+
+*** Reset master ***
+STOP SLAVE;
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+include/start_slave.inc
+RESET MASTER;
+Heartbeat events are received after reset of master (1 means 'yes'): 1
+
+*** Reload master ***
+STOP SLAVE;
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+include/start_slave.inc
+Heartbeat event received
+Reload master
+Heartbeat event received
+
+*** Circular replication ***
+RESET MASTER;
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10));
+include/stop_slave.inc
+RESET MASTER;
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1, MASTER_LOG_FILE='MASTER_BINLOG';
+RESET SLAVE;
+CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=SLAVE_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=1, MASTER_LOG_FILE='SLAVE_BINLOG';
+include/start_slave.inc
+INSERT INTO t1 VALUES(1, 'on master');
+include/start_slave.inc
+INSERT INTO t1 VALUES(2, 'on slave');
+SELECT * FROM t1 ORDER BY a;
+a	b
+1	on master
+2	on slave
+SELECT * FROM t1 ORDER BY a;
+a	b
+1	on master
+2	on slave
+Heartbeat event received on master
+Heartbeat event received on slave
+Slave has received more events than master (1 means 'yes'): 1
+
+*** Clean up ***
+include/stop_slave.inc
+DROP TABLE t1;
+include/stop_slave.inc
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+
+End of 6.0 test
diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat_ssl.result b/mysql-test/suite/rpl/r/rpl_heartbeat_ssl.result
new file mode 100644
index 0000000000000000000000000000000000000000..42de3c459cb298dd782880fdabdcf78b7a01ae21
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat_ssl.result
@@ -0,0 +1,27 @@
+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;
+
+*** Heartbeat over SSL ***
+include/stop_slave.inc
+RESET SLAVE;
+CHANGE MASTER TO 
+MASTER_HOST='127.0.0.1',
+MASTER_PORT=MASTER_PORT,
+MASTER_USER='root',
+MASTER_HEARTBEAT_PERIOD=0.1,
+MASTER_LOG_FILE='MASTER_BINLOG',
+MASTER_SSL=1,
+MASTER_SSL_CA='MYSQL_TEST_DIR/std_data/cacert.pem',
+MASTER_SSL_CERT='MYSQL_TEST_DIR/std_data/client-cert.pem',
+MASTER_SSL_KEY='MYSQL_TEST_DIR/std_data/client-key.pem';
+include/start_slave.inc
+Master_SSL_Allowed: Yes
+Heartbeat event has received
+
+*** Clean up ***
+
+End of 6.0 test
diff --git a/mysql-test/suite/rpl/r/rpl_incident.result b/mysql-test/suite/rpl/r/rpl_incident.result
index c3baabbdbc310a6a8b6df8c1d8786a8de9e12823..a9b641b243b7ca29f7f86c644cf15b900ddd5f73 100644
--- a/mysql-test/suite/rpl/r/rpl_incident.result
+++ b/mysql-test/suite/rpl/r/rpl_incident.result
@@ -64,6 +64,8 @@ Last_IO_Errno	0
 Last_IO_Error	
 Last_SQL_Errno	1590
 Last_SQL_Error	The incident LOST_EVENTS occured on the master. Message: <none>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 SELECT * FROM t1;
@@ -111,4 +113,6 @@ Last_IO_Errno	0
 Last_IO_Error	
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result b/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result
index 75180334c2849d80149ec1bdcbb80180f5520ee8..7f3460702907d5cc71cb19e28290fdb3b783b1ab 100644
--- a/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result
+++ b/mysql-test/suite/rpl/r/rpl_known_bugs_detection.result
@@ -33,7 +33,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	1105
 Last_Error	Error 'master may suffer from http://bugs.mysql.com/bug.php?id=24432 so slave stops; check error log on slave for more info' on query. Default database: 'test'. Query: 'INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10'
 Skip_Counter	0
-Exec_Master_Log_Pos	246
+Exec_Master_Log_Pos	247
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -50,6 +50,8 @@ Last_IO_Errno	0
 Last_IO_Error	
 Last_SQL_Errno	1105
 Last_SQL_Error	Error 'master may suffer from http://bugs.mysql.com/bug.php?id=24432 so slave stops; check error log on slave for more info' on query. Default database: 'test'. Query: 'INSERT INTO t1(b) VALUES(1),(1),(2) ON DUPLICATE KEY UPDATE t1.b=10'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT * FROM t1;
 a	b
 stop slave;
@@ -120,7 +122,7 @@ FROM t2
 ON DUPLICATE KEY UPDATE
 t1.field_3 = t2.field_c'
 Skip_Counter	0
-Exec_Master_Log_Pos	1278
+Exec_Master_Log_Pos	1279
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -141,6 +143,8 @@ SELECT t2.field_a, t2.field_b, t2.field_c
 FROM t2
 ON DUPLICATE KEY UPDATE
 t1.field_3 = t2.field_c'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT * FROM t1;
 id	field_1	field_2	field_3
 drop table t1, t2;
diff --git a/mysql-test/suite/rpl/r/rpl_loaddata.result b/mysql-test/suite/rpl/r/rpl_loaddata.result
index 0653936f0ec863ff71fb100da351062305867d57..4c6fd43da136ee8956db30ec9574347f264b2d8f 100644
--- a/mysql-test/suite/rpl/r/rpl_loaddata.result
+++ b/mysql-test/suite/rpl/r/rpl_loaddata.result
@@ -34,9 +34,47 @@ insert into t1 values(1,10);
 load data infile '../../std_data/rpl_loaddata.dat' into table t1;
 set global sql_slave_skip_counter=1;
 start slave;
-show slave status;
-Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error
-#	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	2009	#	#	master-bin.000001	Yes	Yes				#			0		0	2009	#	None		0	No						#	No	0		0	
+show slave status;;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	master-bin.000001
+Read_Master_Log_Pos	2010
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	master-bin.000001
+Slave_IO_Running	Yes
+Slave_SQL_Running	Yes
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	#
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	0
+Last_Error	
+Skip_Counter	0
+Exec_Master_Log_Pos	2010
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	0
+Last_IO_Error	
+Last_SQL_Errno	0
+Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 set sql_log_bin=0;
 delete from t1;
 set sql_log_bin=1;
@@ -44,9 +82,47 @@ load data infile '../../std_data/rpl_loaddata.dat' into table t1;
 stop slave;
 change master to master_user='test';
 change master to master_user='root';
-show slave status;
-Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error
-#	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	2044	#	#	master-bin.000001	No	No				#			0		0	2044	#	None		0	No						#	No	0		0	
+show slave status;;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	master-bin.000001
+Read_Master_Log_Pos	2045
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	master-bin.000001
+Slave_IO_Running	No
+Slave_SQL_Running	No
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	#
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	0
+Last_Error	
+Skip_Counter	0
+Exec_Master_Log_Pos	2045
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	0
+Last_IO_Error	
+Last_SQL_Errno	0
+Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 set global sql_slave_skip_counter=1;
 start slave;
 set sql_log_bin=0;
@@ -55,9 +131,47 @@ set sql_log_bin=1;
 load data infile '../../std_data/rpl_loaddata.dat' into table t1;
 stop slave;
 reset slave;
-show slave status;
-Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error
-#	127.0.0.1	root	MASTER_PORT	1		4	#	#		No	No				#			0		0	0	#	None		0	No						#	No	0		0	
+show slave status;;
+Slave_IO_State	#
+Master_Host	127.0.0.1
+Master_User	root
+Master_Port	MASTER_PORT
+Connect_Retry	1
+Master_Log_File	
+Read_Master_Log_Pos	4
+Relay_Log_File	#
+Relay_Log_Pos	#
+Relay_Master_Log_File	
+Slave_IO_Running	No
+Slave_SQL_Running	No
+Replicate_Do_DB	
+Replicate_Ignore_DB	
+Replicate_Do_Table	
+Replicate_Ignore_Table	#
+Replicate_Wild_Do_Table	
+Replicate_Wild_Ignore_Table	
+Last_Errno	0
+Last_Error	
+Skip_Counter	0
+Exec_Master_Log_Pos	0
+Relay_Log_Space	#
+Until_Condition	None
+Until_Log_File	
+Until_Log_Pos	0
+Master_SSL_Allowed	No
+Master_SSL_CA_File	
+Master_SSL_CA_Path	
+Master_SSL_Cert	
+Master_SSL_Cipher	
+Master_SSL_Key	
+Seconds_Behind_Master	#
+Master_SSL_Verify_Server_Cert	No
+Last_IO_Errno	0
+Last_IO_Error	
+Last_SQL_Errno	0
+Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 reset master;
 create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
 unique(day)) engine=MyISAM;
diff --git a/mysql-test/suite/rpl/r/rpl_loaddata_fatal.result b/mysql-test/suite/rpl/r/rpl_loaddata_fatal.result
index 35696615b5a0030d5e510535a91a74fde6bfea2a..a4d6e419d8372dfe956f89c353d271480803d07d 100644
--- a/mysql-test/suite/rpl/r/rpl_loaddata_fatal.result
+++ b/mysql-test/suite/rpl/r/rpl_loaddata_fatal.result
@@ -13,7 +13,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	290
+Read_Master_Log_Pos	291
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000001
@@ -28,7 +28,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	290
+Exec_Master_Log_Pos	291
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -45,6 +45,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 LOAD DATA INFILE '../../std_data/rpl_loaddata.dat' INTO TABLE t1;
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -53,7 +55,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	556
+Read_Master_Log_Pos	557
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000001
@@ -68,7 +70,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	1593
 Last_Error	Fatal error: Not enough memory
 Skip_Counter	0
-Exec_Master_Log_Pos	325
+Exec_Master_Log_Pos	326
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -85,6 +87,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1593
 Last_SQL_Error	Fatal error: Not enough memory
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl/r/rpl_log_pos.result b/mysql-test/suite/rpl/r/rpl_log_pos.result
index 85fa4c10eace5ed3fd94b1e07f81c68a1ac6b166..433351b41f79ff67f2c9ca898fbc73002a6b9b95 100644
--- a/mysql-test/suite/rpl/r/rpl_log_pos.result
+++ b/mysql-test/suite/rpl/r/rpl_log_pos.result
@@ -49,6 +49,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave;
 include/stop_slave.inc
 SHOW SLAVE STATUS;
@@ -90,6 +92,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
 master-bin.000001	#	<Binlog_Do_DB>	<Binlog_Ignore_DB>
diff --git a/mysql-test/suite/rpl/r/rpl_not_null_innodb.result b/mysql-test/suite/rpl/r/rpl_not_null_innodb.result
new file mode 100644
index 0000000000000000000000000000000000000000..b09fbab905a75295fc927a2c7b1e1506de7c1b2c
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_not_null_innodb.result
@@ -0,0 +1,202 @@
+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;
+SET SQL_LOG_BIN= 0;
+CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t4(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+SET SQL_LOG_BIN= 1;
+CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT, `b` DATE DEFAULT '0000-00-00',
+`c` INT DEFAULT 500, 
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t4(`a` INT, `b` DATE DEFAULT '0000-00-00',
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+************* EXECUTION WITH INSERTS *************
+INSERT INTO t1(a,b,c) VALUES (1, null, 1);
+INSERT INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
+INSERT INTO t1(a,b) VALUES (3, null);
+INSERT INTO t1(a,c) VALUES (4, 4);
+INSERT INTO t1(a) VALUES (5);
+INSERT INTO t2(a,b) VALUES (1, null);
+INSERT INTO t2(a,b) VALUES (2,'1111-11-11');
+INSERT INTO t2(a) VALUES (3);
+INSERT INTO t3(a,b) VALUES (1, null);
+INSERT INTO t3(a,b) VALUES (2,'1111-11-11');
+INSERT INTO t3(a) VALUES (3);
+INSERT INTO t4(a,b,c) VALUES (1, null, 1);
+INSERT INTO t4(a,b,c) VALUES (2,'1111-11-11', 2);
+INSERT INTO t4(a,b) VALUES (3, null);
+INSERT INTO t4(a,c) VALUES (4, 4);
+INSERT INTO t4(a) VALUES (5);
+************* SHOWING THE RESULT SETS WITH INSERTS *************
+TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+Comparing tables master:test.t1 and slave:test.t1
+Comparing tables master:test.t2 and slave:test.t2
+TABLES t2 and t3 must be different.
+SELECT * FROM t3 ORDER BY a;
+a	b
+1	NULL
+2	1111-11-11
+3	NULL
+SELECT * FROM t3 ORDER BY a;
+a	b	c
+1	NULL	500
+2	1111-11-11	500
+3	NULL	500
+SELECT * FROM t4 ORDER BY a;
+a	b	c
+1	NULL	1
+2	1111-11-11	2
+3	NULL	NULL
+4	NULL	4
+5	NULL	NULL
+SELECT * FROM t4 ORDER BY a;
+a	b
+1	NULL
+2	1111-11-11
+3	NULL
+4	NULL
+5	NULL
+************* EXECUTION WITH UPDATES and REPLACES *************
+DELETE FROM t1;
+INSERT INTO t1(a,b,c) VALUES (1,'1111-11-11', 1);
+REPLACE INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
+UPDATE t1 set b= NULL, c= 300 where a= 1;
+REPLACE INTO t1(a,b,c) VALUES (2, NULL, 300);
+************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
+TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+Comparing tables master:test.t1 and slave:test.t1
+************* CLEANING *************
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP TABLE t4;
+SET SQL_LOG_BIN= 0;
+CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT NULL, `c` BIT DEFAULT NULL, 
+PRIMARY KEY (`a`)) ENGINE= Innodb;
+SET SQL_LOG_BIN= 1;
+CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT b'01', `c` BIT DEFAULT NULL,
+PRIMARY KEY (`a`)) ENGINE= Innodb;
+************* EXECUTION WITH INSERTS *************
+INSERT INTO t1(a,b,c) VALUES (1, null, b'01');
+INSERT INTO t1(a,b,c) VALUES (2,b'00', b'01');
+INSERT INTO t1(a,b) VALUES (3, null);
+INSERT INTO t1(a,c) VALUES (4, b'01');
+INSERT INTO t1(a) VALUES (5);
+************* SHOWING THE RESULT SETS WITH INSERTS *************
+TABLES t1 and t2 must be different.
+SELECT a,b+0,c+0 FROM t1 ORDER BY a;
+a	b+0	c+0
+1	NULL	1
+2	0	1
+3	NULL	NULL
+4	NULL	1
+5	NULL	NULL
+SELECT a,b+0,c+0 FROM t1 ORDER BY a;
+a	b+0	c+0
+1	NULL	1
+2	0	1
+3	NULL	NULL
+4	NULL	1
+5	NULL	NULL
+************* EXECUTION WITH UPDATES and REPLACES *************
+DELETE FROM t1;
+INSERT INTO t1(a,b,c) VALUES (1,b'00', b'01');
+REPLACE INTO t1(a,b,c) VALUES (2,b'00',b'01');
+UPDATE t1 set b= NULL, c= b'00' where a= 1;
+REPLACE INTO t1(a,b,c) VALUES (2, NULL, b'00');
+************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
+TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+Comparing tables master:test.t1 and slave:test.t1
+DROP TABLE t1;
+################################################################################
+#                       NULL ---> NOT NULL (STRICT MODE)
+#                    UNCOMMENT THIS AFTER FIXING BUG#43992
+################################################################################
+################################################################################
+#                       NULL ---> NOT NULL (NON-STRICT MODE)
+################################################################################
+SET SQL_LOG_BIN= 0;
+CREATE TABLE t1(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+SET SQL_LOG_BIN= 1;
+CREATE TABLE t1(`a` INT NOT NULL, `b` INT NOT NULL, 
+`c` INT NOT NULL,
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT NOT NULL, `b` INT NOT NULL,
+`c` INT, 
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT NOT NULL, `b` INT NOT NULL,
+`c` INT DEFAULT 500, 
+PRIMARY KEY(`a`)) ENGINE=Innodb DEFAULT CHARSET=LATIN1;
+************* EXECUTION WITH INSERTS *************
+INSERT INTO t1(a) VALUES (1);
+INSERT INTO t1(a, b) VALUES (2, NULL);
+INSERT INTO t1(a, b) VALUES (3, 1);
+INSERT INTO t2(a) VALUES (1);
+INSERT INTO t2(a, b) VALUES (2, NULL);
+INSERT INTO t2(a, b) VALUES (3, 1);
+INSERT INTO t3(a) VALUES (1);
+INSERT INTO t3(a, b) VALUES (2, NULL);
+INSERT INTO t3(a, b) VALUES (3, 1);
+INSERT INTO t3(a, b) VALUES (4, 1);
+REPLACE INTO t3(a, b) VALUES (5, null);
+REPLACE INTO t3(a, b) VALUES (3, null);
+UPDATE t3 SET b = NULL where a = 4;
+************* SHOWING THE RESULT SETS *************
+SELECT * FROM t1 ORDER BY a;
+a	b
+1	NULL
+2	NULL
+3	1
+SELECT * FROM t1 ORDER BY a;
+a	b	c
+1	0	0
+2	0	0
+3	1	0
+SELECT * FROM t2 ORDER BY a;
+a	b
+1	NULL
+2	NULL
+3	1
+SELECT * FROM t2 ORDER BY a;
+a	b	c
+1	0	NULL
+2	0	NULL
+3	1	NULL
+SELECT * FROM t3 ORDER BY a;
+a	b
+1	NULL
+2	NULL
+3	NULL
+4	NULL
+5	NULL
+SELECT * FROM t3 ORDER BY a;
+a	b	c
+1	0	500
+2	0	500
+3	0	500
+4	0	500
+5	0	500
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
diff --git a/mysql-test/suite/rpl/r/rpl_not_null_myisam.result b/mysql-test/suite/rpl/r/rpl_not_null_myisam.result
new file mode 100644
index 0000000000000000000000000000000000000000..09611dc64801edc153974c3309fc5d293aad7288
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_not_null_myisam.result
@@ -0,0 +1,202 @@
+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;
+SET SQL_LOG_BIN= 0;
+CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t4(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+SET SQL_LOG_BIN= 1;
+CREATE TABLE t1(`a` INT, `b` DATE DEFAULT NULL,
+`c` INT DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT, `b` DATE DEFAULT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT, `b` DATE DEFAULT '0000-00-00',
+`c` INT DEFAULT 500, 
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t4(`a` INT, `b` DATE DEFAULT '0000-00-00',
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+************* EXECUTION WITH INSERTS *************
+INSERT INTO t1(a,b,c) VALUES (1, null, 1);
+INSERT INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
+INSERT INTO t1(a,b) VALUES (3, null);
+INSERT INTO t1(a,c) VALUES (4, 4);
+INSERT INTO t1(a) VALUES (5);
+INSERT INTO t2(a,b) VALUES (1, null);
+INSERT INTO t2(a,b) VALUES (2,'1111-11-11');
+INSERT INTO t2(a) VALUES (3);
+INSERT INTO t3(a,b) VALUES (1, null);
+INSERT INTO t3(a,b) VALUES (2,'1111-11-11');
+INSERT INTO t3(a) VALUES (3);
+INSERT INTO t4(a,b,c) VALUES (1, null, 1);
+INSERT INTO t4(a,b,c) VALUES (2,'1111-11-11', 2);
+INSERT INTO t4(a,b) VALUES (3, null);
+INSERT INTO t4(a,c) VALUES (4, 4);
+INSERT INTO t4(a) VALUES (5);
+************* SHOWING THE RESULT SETS WITH INSERTS *************
+TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+Comparing tables master:test.t1 and slave:test.t1
+Comparing tables master:test.t2 and slave:test.t2
+TABLES t2 and t3 must be different.
+SELECT * FROM t3 ORDER BY a;
+a	b
+1	NULL
+2	1111-11-11
+3	NULL
+SELECT * FROM t3 ORDER BY a;
+a	b	c
+1	NULL	500
+2	1111-11-11	500
+3	NULL	500
+SELECT * FROM t4 ORDER BY a;
+a	b	c
+1	NULL	1
+2	1111-11-11	2
+3	NULL	NULL
+4	NULL	4
+5	NULL	NULL
+SELECT * FROM t4 ORDER BY a;
+a	b
+1	NULL
+2	1111-11-11
+3	NULL
+4	NULL
+5	NULL
+************* EXECUTION WITH UPDATES and REPLACES *************
+DELETE FROM t1;
+INSERT INTO t1(a,b,c) VALUES (1,'1111-11-11', 1);
+REPLACE INTO t1(a,b,c) VALUES (2,'1111-11-11', 2);
+UPDATE t1 set b= NULL, c= 300 where a= 1;
+REPLACE INTO t1(a,b,c) VALUES (2, NULL, 300);
+************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
+TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+Comparing tables master:test.t1 and slave:test.t1
+************* CLEANING *************
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP TABLE t4;
+SET SQL_LOG_BIN= 0;
+CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT NULL, `c` BIT DEFAULT NULL, 
+PRIMARY KEY (`a`)) ENGINE= MyISAM;
+SET SQL_LOG_BIN= 1;
+CREATE TABLE t1 (`a` INT, `b` BIT DEFAULT b'01', `c` BIT DEFAULT NULL,
+PRIMARY KEY (`a`)) ENGINE= MyISAM;
+************* EXECUTION WITH INSERTS *************
+INSERT INTO t1(a,b,c) VALUES (1, null, b'01');
+INSERT INTO t1(a,b,c) VALUES (2,b'00', b'01');
+INSERT INTO t1(a,b) VALUES (3, null);
+INSERT INTO t1(a,c) VALUES (4, b'01');
+INSERT INTO t1(a) VALUES (5);
+************* SHOWING THE RESULT SETS WITH INSERTS *************
+TABLES t1 and t2 must be different.
+SELECT a,b+0,c+0 FROM t1 ORDER BY a;
+a	b+0	c+0
+1	NULL	1
+2	0	1
+3	NULL	NULL
+4	NULL	1
+5	NULL	NULL
+SELECT a,b+0,c+0 FROM t1 ORDER BY a;
+a	b+0	c+0
+1	NULL	1
+2	0	1
+3	NULL	NULL
+4	NULL	1
+5	NULL	NULL
+************* EXECUTION WITH UPDATES and REPLACES *************
+DELETE FROM t1;
+INSERT INTO t1(a,b,c) VALUES (1,b'00', b'01');
+REPLACE INTO t1(a,b,c) VALUES (2,b'00',b'01');
+UPDATE t1 set b= NULL, c= b'00' where a= 1;
+REPLACE INTO t1(a,b,c) VALUES (2, NULL, b'00');
+************* SHOWING THE RESULT SETS WITH UPDATES and REPLACES *************
+TABLES t1 and t2 must be equal otherwise an error will be thrown. 
+Comparing tables master:test.t1 and slave:test.t1
+DROP TABLE t1;
+################################################################################
+#                       NULL ---> NOT NULL (STRICT MODE)
+#                    UNCOMMENT THIS AFTER FIXING BUG#43992
+################################################################################
+################################################################################
+#                       NULL ---> NOT NULL (NON-STRICT MODE)
+################################################################################
+SET SQL_LOG_BIN= 0;
+CREATE TABLE t1(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT NOT NULL, `b` INT,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+SET SQL_LOG_BIN= 1;
+CREATE TABLE t1(`a` INT NOT NULL, `b` INT NOT NULL, 
+`c` INT NOT NULL,
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t2(`a` INT NOT NULL, `b` INT NOT NULL,
+`c` INT, 
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+CREATE TABLE t3(`a` INT NOT NULL, `b` INT NOT NULL,
+`c` INT DEFAULT 500, 
+PRIMARY KEY(`a`)) ENGINE=MyISAM DEFAULT CHARSET=LATIN1;
+************* EXECUTION WITH INSERTS *************
+INSERT INTO t1(a) VALUES (1);
+INSERT INTO t1(a, b) VALUES (2, NULL);
+INSERT INTO t1(a, b) VALUES (3, 1);
+INSERT INTO t2(a) VALUES (1);
+INSERT INTO t2(a, b) VALUES (2, NULL);
+INSERT INTO t2(a, b) VALUES (3, 1);
+INSERT INTO t3(a) VALUES (1);
+INSERT INTO t3(a, b) VALUES (2, NULL);
+INSERT INTO t3(a, b) VALUES (3, 1);
+INSERT INTO t3(a, b) VALUES (4, 1);
+REPLACE INTO t3(a, b) VALUES (5, null);
+REPLACE INTO t3(a, b) VALUES (3, null);
+UPDATE t3 SET b = NULL where a = 4;
+************* SHOWING THE RESULT SETS *************
+SELECT * FROM t1 ORDER BY a;
+a	b
+1	NULL
+2	NULL
+3	1
+SELECT * FROM t1 ORDER BY a;
+a	b	c
+1	0	0
+2	0	0
+3	1	0
+SELECT * FROM t2 ORDER BY a;
+a	b
+1	NULL
+2	NULL
+3	1
+SELECT * FROM t2 ORDER BY a;
+a	b	c
+1	0	NULL
+2	0	NULL
+3	1	NULL
+SELECT * FROM t3 ORDER BY a;
+a	b
+1	NULL
+2	NULL
+3	NULL
+4	NULL
+5	NULL
+SELECT * FROM t3 ORDER BY a;
+a	b	c
+1	0	500
+2	0	500
+3	0	500
+4	0	500
+5	0	500
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
diff --git a/mysql-test/suite/rpl/r/rpl_rbr_to_sbr.result b/mysql-test/suite/rpl/r/rpl_rbr_to_sbr.result
index 2e707fb62c11f06867d9201b89dc0c9bc8d5e9a7..53e8899d27f4aa622b260d178359d7ee94e6fe7e 100644
--- a/mysql-test/suite/rpl/r/rpl_rbr_to_sbr.result
+++ b/mysql-test/suite/rpl/r/rpl_rbr_to_sbr.result
@@ -31,7 +31,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	594
+Read_Master_Log_Pos	595
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000001
@@ -46,7 +46,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	594
+Exec_Master_Log_Pos	595
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -63,6 +63,8 @@ Last_IO_Errno	#
 Last_IO_Error	
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SHOW BINLOG EVENTS;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 slave-bin.000001	#	Format_desc	2	#	Server ver: VERSION, Binlog ver: 4
diff --git a/mysql-test/suite/rpl/r/rpl_replicate_do.result b/mysql-test/suite/rpl/r/rpl_replicate_do.result
index 33088ee2ec82e37c225f8a37633dda0740e52b99..2fbd283a9c899481cde3345516a5d5e33e66a72c 100644
--- a/mysql-test/suite/rpl/r/rpl_replicate_do.result
+++ b/mysql-test/suite/rpl/r/rpl_replicate_do.result
@@ -65,6 +65,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 create table t1 (ts timestamp);
 set one_shot time_zone='met';
 insert into t1 values('2005-08-12 00:00:00');
diff --git a/mysql-test/suite/rpl/r/rpl_rotate_logs.result b/mysql-test/suite/rpl/r/rpl_rotate_logs.result
index 013ba87ec0bc4083ce1c92c44878fdb112178c20..b3b1480a740f7dbedbb46b0f13c02bcbc25c4de2 100644
--- a/mysql-test/suite/rpl/r/rpl_rotate_logs.result
+++ b/mysql-test/suite/rpl/r/rpl_rotate_logs.result
@@ -53,6 +53,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 select * from t1;
 s
 Could not break slave
@@ -132,6 +134,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 select * from t2;
 m
 34
@@ -196,6 +200,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 lock tables t3 read;
 select count(*) from t3 where n >= 4;
 count(*)
diff --git a/mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result b/mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result
index 7920b9a981dcf15a8e0914fdb72ca8bd5d17b6a8..27960be8054fc6db963ae7ae66ef677b5623b7b2 100644
--- a/mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result
+++ b/mysql-test/suite/rpl/r/rpl_row_basic_11bugs.result
@@ -58,12 +58,12 @@ DELETE FROM t1 WHERE a = 0;
 UPDATE t1 SET a=99 WHERE a = 0;
 SHOW BINLOG EVENTS;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: SERVER_VERSION, Binlog ver: 4
-master-bin.000001	106	Query	1	192	use `test`; CREATE TABLE t1 (a INT)
-master-bin.000001	192	Query	1	260	BEGIN
-master-bin.000001	260	Table_map	1	301	table_id: # (test.t1)
-master-bin.000001	301	Write_rows	1	340	table_id: # flags: STMT_END_F
-master-bin.000001	340	Query	1	409	COMMIT
+master-bin.000001	4	Format_desc	1	107	Server ver: SERVER_VERSION, Binlog ver: 4
+master-bin.000001	107	Query	1	193	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	193	Query	1	261	BEGIN
+master-bin.000001	261	Table_map	1	302	table_id: # (test.t1)
+master-bin.000001	302	Write_rows	1	341	table_id: # flags: STMT_END_F
+master-bin.000001	341	Query	1	410	COMMIT
 DROP TABLE t1;
 ================ Test for BUG#17620 ================
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
diff --git a/mysql-test/suite/rpl/r/rpl_row_colSize.result b/mysql-test/suite/rpl/r/rpl_row_colSize.result
index 6d002a722f168e23c50d4ba7f7fe7e2a30a80d08..acda689ca9b074fe85f0c1cb581b335604fb468a 100644
--- a/mysql-test/suite/rpl/r/rpl_row_colSize.result
+++ b/mysql-test/suite/rpl/r/rpl_row_colSize.result
@@ -57,6 +57,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 10, test.t1 on slave has size 3. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -111,6 +113,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 12, test.t1 on slave has size 12. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -165,6 +169,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 10, test.t1 on slave has size 3. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -220,6 +226,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 5, test.t1 has type 4
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -275,6 +283,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 8, test.t1 on slave has size 1. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -329,6 +339,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 2, test.t1 on slave has size 2. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -384,6 +396,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 2, test.t1 on slave has size 1. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -439,6 +453,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 20, test.t1 on slave has size 11. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -525,6 +541,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 2, test.t1 on slave has size 1. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -580,6 +598,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 2000, test.t1 on slave has size 100. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -634,6 +654,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 200, test.t1 on slave has size 10. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -688,6 +710,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 2000, test.t1 on slave has size 1000. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
@@ -743,6 +767,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 size mismatch - master has size 4, test.t1 on slave has size 1. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT COUNT(*) FROM t1;
 COUNT(*)
 0
diff --git a/mysql-test/suite/rpl/r/rpl_row_conflicts.result b/mysql-test/suite/rpl/r/rpl_row_conflicts.result
index 0f15bfc71563969ae4d7414d28a11c6bd699af5e..6f98c25c335ed7059d8f735acd482794fd7c460e 100644
--- a/mysql-test/suite/rpl/r/rpl_row_conflicts.result
+++ b/mysql-test/suite/rpl/r/rpl_row_conflicts.result
@@ -24,7 +24,7 @@ a
 1
 [on slave]
 ---- Wait until slave stops with an error ----
-Last_SQL_Error = Could not execute Write_rows event on table test.t1; Duplicate entry '1' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log master-bin.000001, end_log_pos 346 (expected "duplicate key" error)
+Last_SQL_Error = Could not execute Write_rows event on table test.t1; Duplicate entry '1' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log master-bin.000001, end_log_pos 347 (expected "duplicate key" error)
 SELECT * FROM t1;
 a
 1
@@ -50,7 +50,7 @@ SELECT * FROM t1;
 a
 [on slave]
 ---- Wait until slave stops with an error ----
-Last_SQL_Error = Could not execute Delete_rows event on table test.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log master-bin.000001, end_log_pos 982 (expected "can't find record" error)
+Last_SQL_Error = Could not execute Delete_rows event on table test.t1; Can't find record in 't1', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log master-bin.000001, end_log_pos 983 (expected "can't find record" error)
 SELECT * FROM t1;
 a
 ---- Resolve the conflict on the slave and restart SQL thread ----
diff --git a/mysql-test/suite/rpl/r/rpl_row_create_table.result b/mysql-test/suite/rpl/r/rpl_row_create_table.result
index b7122adea2ace92c26e191f7d3a7d2b4920d01e6..e23b3e333174b6e46721d1ea2671f6ea3e8b1175 100644
--- a/mysql-test/suite/rpl/r/rpl_row_create_table.result
+++ b/mysql-test/suite/rpl/r/rpl_row_create_table.result
@@ -13,30 +13,30 @@ CREATE TABLE t1 (a INT, b INT);
 CREATE TABLE t2 (a INT, b INT) ENGINE=Merge;
 CREATE TABLE t3 (a INT, b INT) CHARSET=utf8;
 CREATE TABLE t4 (a INT, b INT) ENGINE=Merge CHARSET=utf8;
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	#
-Pos	106
+Pos	107
 Event_type	Query
 Server_id	#
-End_log_pos	199
+End_log_pos	200
 Info	use `test`; CREATE TABLE t1 (a INT, b INT)
 Log_name	#
-Pos	199
+Pos	200
 Event_type	Query
 Server_id	#
-End_log_pos	305
+End_log_pos	306
 Info	use `test`; CREATE TABLE t2 (a INT, b INT) ENGINE=Merge
 Log_name	#
-Pos	305
+Pos	306
 Event_type	Query
 Server_id	#
-End_log_pos	411
+End_log_pos	412
 Info	use `test`; CREATE TABLE t3 (a INT, b INT) CHARSET=utf8
 Log_name	#
-Pos	411
+Pos	412
 Event_type	Query
 Server_id	#
-End_log_pos	530
+End_log_pos	531
 Info	use `test`; CREATE TABLE t4 (a INT, b INT) ENGINE=Merge CHARSET=utf8
 **** On Master ****
 SHOW CREATE TABLE t1;
@@ -137,7 +137,7 @@ RESET MASTER;
 include/start_slave.inc
 CREATE TABLE t7 (UNIQUE(b)) SELECT a,b FROM tt3;
 ERROR 23000: Duplicate entry '2' for key 'b'
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 CREATE TABLE t7 (a INT, b INT UNIQUE);
 INSERT INTO t7 SELECT a,b FROM tt3;
@@ -147,13 +147,13 @@ a	b
 1	2
 2	4
 3	6
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-#	106	Query	#	206	use `test`; CREATE TABLE t7 (a INT, b INT UNIQUE)
-#	206	Query	#	274	BEGIN
-#	274	Table_map	#	316	table_id: # (test.t7)
-#	316	Write_rows	#	372	table_id: # flags: STMT_END_F
-#	372	Query	#	443	ROLLBACK
+#	107	Query	#	207	use `test`; CREATE TABLE t7 (a INT, b INT UNIQUE)
+#	207	Query	#	275	BEGIN
+#	275	Table_map	#	317	table_id: # (test.t7)
+#	317	Write_rows	#	373	table_id: # flags: STMT_END_F
+#	373	Query	#	444	ROLLBACK
 SELECT * FROM t7 ORDER BY a,b;
 a	b
 1	2
@@ -171,12 +171,12 @@ INSERT INTO t7 SELECT a,b FROM tt4;
 ROLLBACK;
 Warnings:
 Warning	1196	Some non-transactional changed tables couldn't be rolled back
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-#	106	Query	#	174	BEGIN
-#	174	Table_map	#	216	table_id: # (test.t7)
-#	216	Write_rows	#	272	table_id: # flags: STMT_END_F
-#	272	Query	#	341	COMMIT
+#	107	Query	#	175	BEGIN
+#	175	Table_map	#	217	table_id: # (test.t7)
+#	217	Write_rows	#	273	table_id: # flags: STMT_END_F
+#	273	Query	#	342	COMMIT
 SELECT * FROM t7 ORDER BY a,b;
 a	b
 1	2
@@ -216,10 +216,10 @@ Create Table	CREATE TABLE `t9` (
   `a` int(11) DEFAULT NULL,
   `b` int(11) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-#	106	Query	#	192	use `test`; CREATE TABLE t8 LIKE t4
-#	192	Query	#	331	use `test`; CREATE TABLE `t9` (
+#	107	Query	#	193	use `test`; CREATE TABLE t8 LIKE t4
+#	193	Query	#	332	use `test`; CREATE TABLE `t9` (
   `a` int(11) DEFAULT NULL,
   `b` int(11) DEFAULT NULL
 )
@@ -296,38 +296,38 @@ a
 1
 2
 3
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-#	106	Query	#	192	use `test`; CREATE TABLE t1 (a INT)
-#	192	Query	#	260	BEGIN
-#	260	Table_map	#	301	table_id: # (test.t1)
-#	301	Write_rows	#	345	table_id: # flags: STMT_END_F
-#	345	Query	#	414	COMMIT
-#	414	Query	#	482	BEGIN
-#	482	Query	#	607	use `test`; CREATE TABLE `t2` (
+#	107	Query	#	193	use `test`; CREATE TABLE t1 (a INT)
+#	193	Query	#	261	BEGIN
+#	261	Table_map	#	302	table_id: # (test.t1)
+#	302	Write_rows	#	346	table_id: # flags: STMT_END_F
+#	346	Query	#	415	COMMIT
+#	415	Query	#	483	BEGIN
+#	483	Query	#	608	use `test`; CREATE TABLE `t2` (
   `a` int(11) DEFAULT NULL
 ) ENGINE=InnoDB
-#	607	Table_map	#	648	table_id: # (test.t2)
-#	648	Write_rows	#	692	table_id: # flags: STMT_END_F
-#	692	Xid	#	719	COMMIT /* XID */
-#	719	Query	#	787	BEGIN
-#	787	Query	#	912	use `test`; CREATE TABLE `t3` (
+#	608	Table_map	#	649	table_id: # (test.t2)
+#	649	Write_rows	#	693	table_id: # flags: STMT_END_F
+#	693	Xid	#	720	COMMIT /* XID */
+#	720	Query	#	788	BEGIN
+#	788	Query	#	913	use `test`; CREATE TABLE `t3` (
   `a` int(11) DEFAULT NULL
 ) ENGINE=InnoDB
-#	912	Table_map	#	953	table_id: # (test.t3)
-#	953	Write_rows	#	997	table_id: # flags: STMT_END_F
-#	997	Xid	#	1024	COMMIT /* XID */
-#	1024	Query	#	1092	BEGIN
-#	1092	Query	#	1217	use `test`; CREATE TABLE `t4` (
+#	913	Table_map	#	954	table_id: # (test.t3)
+#	954	Write_rows	#	998	table_id: # flags: STMT_END_F
+#	998	Xid	#	1025	COMMIT /* XID */
+#	1025	Query	#	1093	BEGIN
+#	1093	Query	#	1218	use `test`; CREATE TABLE `t4` (
   `a` int(11) DEFAULT NULL
 ) ENGINE=InnoDB
-#	1217	Table_map	#	1258	table_id: # (test.t4)
-#	1258	Write_rows	#	1302	table_id: # flags: STMT_END_F
-#	1302	Xid	#	1329	COMMIT /* XID */
-#	1329	Query	#	1397	BEGIN
-#	1397	Table_map	#	1438	table_id: # (test.t1)
-#	1438	Write_rows	#	1482	table_id: # flags: STMT_END_F
-#	1482	Query	#	1551	COMMIT
+#	1218	Table_map	#	1259	table_id: # (test.t4)
+#	1259	Write_rows	#	1303	table_id: # flags: STMT_END_F
+#	1303	Xid	#	1330	COMMIT /* XID */
+#	1330	Query	#	1398	BEGIN
+#	1398	Table_map	#	1439	table_id: # (test.t1)
+#	1439	Write_rows	#	1483	table_id: # flags: STMT_END_F
+#	1483	Query	#	1552	COMMIT
 SHOW TABLES;
 Tables_in_test
 t1
@@ -390,20 +390,20 @@ a
 4
 6
 9
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-#	106	Query	#	192	use `test`; CREATE TABLE t1 (a INT)
-#	192	Query	#	260	BEGIN
-#	260	Table_map	#	301	table_id: # (test.t1)
-#	301	Write_rows	#	345	table_id: # flags: STMT_END_F
-#	345	Query	#	414	COMMIT
-#	414	Query	#	514	use `test`; CREATE TABLE t2 (a INT) ENGINE=INNODB
-#	514	Query	#	582	BEGIN
-#	582	Table_map	#	623	table_id: # (test.t2)
-#	623	Write_rows	#	667	table_id: # flags: STMT_END_F
-#	667	Table_map	#	708	table_id: # (test.t2)
-#	708	Write_rows	#	747	table_id: # flags: STMT_END_F
-#	747	Xid	#	774	COMMIT /* XID */
+#	107	Query	#	193	use `test`; CREATE TABLE t1 (a INT)
+#	193	Query	#	261	BEGIN
+#	261	Table_map	#	302	table_id: # (test.t1)
+#	302	Write_rows	#	346	table_id: # flags: STMT_END_F
+#	346	Query	#	415	COMMIT
+#	415	Query	#	515	use `test`; CREATE TABLE t2 (a INT) ENGINE=INNODB
+#	515	Query	#	583	BEGIN
+#	583	Table_map	#	624	table_id: # (test.t2)
+#	624	Write_rows	#	668	table_id: # flags: STMT_END_F
+#	668	Table_map	#	709	table_id: # (test.t2)
+#	709	Write_rows	#	748	table_id: # flags: STMT_END_F
+#	748	Xid	#	775	COMMIT /* XID */
 SELECT * FROM t2 ORDER BY a;
 a
 1
@@ -429,14 +429,14 @@ Warnings:
 Warning	1196	Some non-transactional changed tables couldn't be rolled back
 SELECT * FROM t2 ORDER BY a;
 a
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-#	106	Query	#	174	BEGIN
-#	174	Table_map	#	215	table_id: # (test.t2)
-#	215	Write_rows	#	259	table_id: # flags: STMT_END_F
-#	259	Table_map	#	300	table_id: # (test.t2)
-#	300	Write_rows	#	339	table_id: # flags: STMT_END_F
-#	339	Query	#	410	ROLLBACK
+#	107	Query	#	175	BEGIN
+#	175	Table_map	#	216	table_id: # (test.t2)
+#	216	Write_rows	#	260	table_id: # flags: STMT_END_F
+#	260	Table_map	#	301	table_id: # (test.t2)
+#	301	Write_rows	#	340	table_id: # flags: STMT_END_F
+#	340	Query	#	411	ROLLBACK
 SELECT * FROM t2 ORDER BY a;
 a
 DROP TABLE t1,t2;
diff --git a/mysql-test/suite/rpl/r/rpl_row_drop.result b/mysql-test/suite/rpl/r/rpl_row_drop.result
index 89654ebf16549d1aa14d8992fe5424c009fa14bd..f1a350b3df0e9ee2f2950ff13c103daf9c61aa10 100644
--- a/mysql-test/suite/rpl/r/rpl_row_drop.result
+++ b/mysql-test/suite/rpl/r/rpl_row_drop.result
@@ -43,10 +43,10 @@ t2
 DROP TABLE t1,t2;
 SHOW BINLOG EVENTS;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: VERSION, Binlog ver: 4
-master-bin.000001	106	Query	1	192	use `test`; CREATE TABLE t1 (a int)
-master-bin.000001	192	Query	1	278	use `test`; CREATE TABLE t2 (a int)
-master-bin.000001	278	Query	1	382	use `test`; DROP TABLE `t1` /* generated by server */
+master-bin.000001	4	Format_desc	1	107	Server ver: VERSION, Binlog ver: 4
+master-bin.000001	107	Query	1	193	use `test`; CREATE TABLE t1 (a int)
+master-bin.000001	193	Query	1	279	use `test`; CREATE TABLE t2 (a int)
+master-bin.000001	279	Query	1	383	use `test`; DROP TABLE `t1` /* generated by server */
 SHOW TABLES;
 Tables_in_test
 t2
diff --git a/mysql-test/suite/rpl/r/rpl_row_flsh_tbls.result b/mysql-test/suite/rpl/r/rpl_row_flsh_tbls.result
index 129bad0fbcc4685337f3b904d7d3b867a37d9617..384573c0461c042c473c4f2124df68416fffd984 100644
--- a/mysql-test/suite/rpl/r/rpl_row_flsh_tbls.result
+++ b/mysql-test/suite/rpl/r/rpl_row_flsh_tbls.result
@@ -12,13 +12,13 @@ create table t4 (a int);
 insert into t4 select * from t3;
 rename table t1 to t5, t2 to t1;
 flush no_write_to_binlog tables;
-SHOW BINLOG EVENTS FROM 897 ;
+SHOW BINLOG EVENTS FROM 898 ;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; rename table t1 to t5, t2 to t1
 select * from t3;
 a
 flush tables;
-SHOW BINLOG EVENTS FROM 897 ;
+SHOW BINLOG EVENTS FROM 898 ;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; rename table t1 to t5, t2 to t1
 master-bin.000001	#	Query	1	#	use `test`; flush tables
diff --git a/mysql-test/suite/rpl/r/rpl_row_log.result b/mysql-test/suite/rpl/r/rpl_row_log.result
index 9593b009d1f1af7428cef7259747682e176e7e0d..789db064eb5352fc6b28fccd7bd12e745da38bc0 100644
--- a/mysql-test/suite/rpl/r/rpl_row_log.result
+++ b/mysql-test/suite/rpl/r/rpl_row_log.result
@@ -30,14 +30,14 @@ master-bin.000001	#	Query	1	#	BEGIN
 master-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	1	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Query	1	#	COMMIT
-show binlog events from 106 limit 1;
+show binlog events from 107 limit 1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=MyISAM
-show binlog events from 106 limit 2;
+show binlog events from 107 limit 2;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=MyISAM
 master-bin.000001	#	Query	1	#	BEGIN
-show binlog events from 106 limit 2,1;
+show binlog events from 107 limit 2,1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
 flush logs;
@@ -251,7 +251,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000002
-Read_Master_Log_Pos	516
+Read_Master_Log_Pos	517
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000002
@@ -266,7 +266,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	516
+Exec_Master_Log_Pos	517
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -283,6 +283,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 show binlog events in 'slave-bin.000005' from 4;
 ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not find target log
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl/r/rpl_row_log_innodb.result b/mysql-test/suite/rpl/r/rpl_row_log_innodb.result
index 8526bad558bbc7949077e1a6ac71a82286f0c501..fbd9f685ba989f145602a23ecc8022569088ce39 100644
--- a/mysql-test/suite/rpl/r/rpl_row_log_innodb.result
+++ b/mysql-test/suite/rpl/r/rpl_row_log_innodb.result
@@ -30,14 +30,14 @@ master-bin.000001	#	Query	1	#	BEGIN
 master-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	1	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Xid	1	#	COMMIT /* XID */
-show binlog events from 106 limit 1;
+show binlog events from 107 limit 1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=InnoDB
-show binlog events from 106 limit 2;
+show binlog events from 107 limit 2;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=InnoDB
 master-bin.000001	#	Query	1	#	BEGIN
-show binlog events from 106 limit 2,1;
+show binlog events from 107 limit 2,1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
 flush logs;
@@ -251,7 +251,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000002
-Read_Master_Log_Pos	474
+Read_Master_Log_Pos	475
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000002
@@ -266,7 +266,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	474
+Exec_Master_Log_Pos	475
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -283,6 +283,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 show binlog events in 'slave-bin.000005' from 4;
 ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not find target log
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl/r/rpl_row_max_relay_size.result b/mysql-test/suite/rpl/r/rpl_row_max_relay_size.result
index 2215b34814e923186b44d84a9378ffad69108f50..c2554218f733b0ab6019d5f5d1ec8b6927d79ef2 100644
--- a/mysql-test/suite/rpl/r/rpl_row_max_relay_size.result
+++ b/mysql-test/suite/rpl/r/rpl_row_max_relay_size.result
@@ -60,6 +60,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 2
 #
@@ -108,6 +110,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 3: max_relay_log_size = 0
 #
@@ -156,6 +160,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 4: Tests below are mainly to ensure that we have not coded with wrong assumptions
 #
@@ -201,6 +207,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 5
 #
@@ -247,6 +255,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 6: one more rotation, to be sure Relay_Log_Space is correctly updated
 #
@@ -291,6 +301,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 flush logs;
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
diff --git a/mysql-test/suite/rpl/r/rpl_row_reset_slave.result b/mysql-test/suite/rpl/r/rpl_row_reset_slave.result
index fa40d8760a87f8e7fd2de2ec32a3065510158979..501749e12f9e130ac6770b5d87e5b62e093b48d0 100644
--- a/mysql-test/suite/rpl/r/rpl_row_reset_slave.result
+++ b/mysql-test/suite/rpl/r/rpl_row_reset_slave.result
@@ -43,6 +43,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 stop slave;
 change master to master_user='test';
 SHOW SLAVE STATUS;
@@ -84,6 +86,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 reset slave;
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -124,6 +128,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave;
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -164,6 +170,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 stop slave;
 reset slave;
 start slave;
diff --git a/mysql-test/suite/rpl/r/rpl_row_show_relaylog_events.result b/mysql-test/suite/rpl/r/rpl_row_show_relaylog_events.result
new file mode 100644
index 0000000000000000000000000000000000000000..461ab14a93a44c10667ce46f1a6ff29518515a34
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_row_show_relaylog_events.result
@@ -0,0 +1,274 @@
+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 (a INT);
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+INSERT INTO t1 VALUES (3);
+INSERT INTO t1 VALUES (4);
+INSERT INTO t1 VALUES (5);
+INSERT INTO t1 VALUES (6);
+[MASTER] ********* SOW BINLOG EVENTS IN ...  *********
+show binlog events in 'master-bin.000001' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+[MASTER] ********* SOW BINLOG EVENTS         *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+[MASTER] ********* SOW BINLOG EVENTS ... LIMIT rows  *********
+show binlog events from <binlog_start> limit 3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+[MASTER] ********* SOW BINLOG EVENTS ... LIMIT offset,rows  *********
+show binlog events from <binlog_start> limit 1,  3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+[SLAVE] ********* SOW BINLOG EVENTS IN ...   *********
+show binlog events in 'slave-bin.000001' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+[SLAVE] ********* SOW BINLOG EVENTS          *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+[SLAVE] ********* SOW BINLOG EVENTS ... LIMIT rows  *********
+show binlog events from <binlog_start> limit 3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+[SLAVE] ********* SOW BINLOG EVENTS ... LIMIT offset,rows  *********
+show binlog events from <binlog_start> limit 1,  3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+[SLAVE] ********* SOW RELAYLOG EVENTS IN ... *********
+show relaylog events in 'slave-relay-bin.000003' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000003	#	Rotate	#	#	master-bin.000001;pos=4
+slave-relay-bin.000003	#	Format_desc	#	#	SERVER_VERSION, BINLOG_VERSION
+slave-relay-bin.000003	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+slave-relay-bin.000003	#	Table_map	#	#	table_id: # (test.t1)
+slave-relay-bin.000003	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-relay-bin.000003	#	Query	#	#	COMMIT
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+slave-relay-bin.000003	#	Table_map	#	#	table_id: # (test.t1)
+slave-relay-bin.000003	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-relay-bin.000003	#	Query	#	#	COMMIT
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+slave-relay-bin.000003	#	Table_map	#	#	table_id: # (test.t1)
+slave-relay-bin.000003	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-relay-bin.000003	#	Query	#	#	COMMIT
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+slave-relay-bin.000003	#	Table_map	#	#	table_id: # (test.t1)
+slave-relay-bin.000003	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-relay-bin.000003	#	Query	#	#	COMMIT
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+slave-relay-bin.000003	#	Table_map	#	#	table_id: # (test.t1)
+slave-relay-bin.000003	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-relay-bin.000003	#	Query	#	#	COMMIT
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+slave-relay-bin.000003	#	Table_map	#	#	table_id: # (test.t1)
+slave-relay-bin.000003	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-relay-bin.000003	#	Query	#	#	COMMIT
+[SLAVE] ********* SOW RELAYLOG EVENTS        *********
+show relaylog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000002	#	Rotate	#	#	slave-relay-bin.000003;pos=4
+[MASTER] ********* SOW RELAYLOG EVENTS ... LIMIT rows  *********
+show relaylog events in 'slave-relay-bin.000003' from <binlog_start> limit 3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000003	#	Rotate	#	#	master-bin.000001;pos=4
+slave-relay-bin.000003	#	Format_desc	#	#	SERVER_VERSION, BINLOG_VERSION
+slave-relay-bin.000003	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+[MASTER] ********* SOW RELAYLOG EVENTS ... LIMIT offset,rows  *********
+show relaylog events in 'slave-relay-bin.000003' from <binlog_start> limit 1,  3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000003	#	Format_desc	#	#	SERVER_VERSION, BINLOG_VERSION
+slave-relay-bin.000003	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-relay-bin.000003	#	Query	#	#	BEGIN
+FLUSH LOGS;
+FLUSH LOGS;
+DROP TABLE t1;
+[MASTER] ********* SOW BINLOG EVENTS IN ...  *********
+show binlog events in 'master-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000002	#	Query	#	#	use `test`; DROP TABLE t1
+[MASTER] ********* SOW BINLOG EVENTS         *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Query	#	#	BEGIN
+master-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+master-bin.000001	#	Query	#	#	COMMIT
+master-bin.000001	#	Rotate	#	#	master-bin.000002;pos=4
+[SLAVE] ********* SOW BINLOG EVENTS IN ...   *********
+show binlog events in 'slave-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000002	#	Query	#	#	use `test`; DROP TABLE t1
+[SLAVE] ********* SOW BINLOG EVENTS          *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Query	#	#	BEGIN
+slave-bin.000001	#	Table_map	#	#	table_id: # (test.t1)
+slave-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F
+slave-bin.000001	#	Query	#	#	COMMIT
+slave-bin.000001	#	Rotate	#	#	slave-bin.000002;pos=4
+[SLAVE] ********* SOW RELAYLOG EVENTS IN ... *********
+show relaylog events in 'slave-relay-bin.000005' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000005	#	Rotate	#	#	master-bin.000002;pos=4
+slave-relay-bin.000005	#	Rotate	#	#	slave-relay-bin.000006;pos=4
+[SLAVE] ********* SOW RELAYLOG EVENTS        *********
+show relaylog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000005	#	Rotate	#	#	master-bin.000002;pos=4
+slave-relay-bin.000005	#	Rotate	#	#	slave-relay-bin.000006;pos=4
diff --git a/mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result b/mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result
deleted file mode 100644
index 1934b01505c2bb9cc8117f586d726165f489a51d..0000000000000000000000000000000000000000
--- a/mysql-test/suite/rpl/r/rpl_row_stop_middle_update.result
+++ /dev/null
@@ -1,17 +0,0 @@
-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 (words varchar(20)) engine=myisam;
-load data infile '../../std_data/words.dat' into table t1 (words);
-select count(*) from t1;
-count(*)
-70
-select count(*) from t1;
-count(*)
-70
-drop table t1;
-include/stop_slave.inc
-drop table t1;
diff --git a/mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result b/mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result
index a6a2181cd2a1ee16b561ee87ea38e265b5bad28d..cb91fd95fab3406aec23afc8a3a45bd41a370551 100644
--- a/mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result
+++ b/mysql-test/suite/rpl/r/rpl_row_tabledefs_2myisam.result
@@ -105,47 +105,9 @@ a	b	x
 2	10	Foo is a bar
 INSERT INTO t9 VALUES (2);
 INSERT INTO t1_nodef VALUES (1,2);
-SHOW SLAVE STATUS;
-Slave_IO_State	#
-Master_Host	127.0.0.1
-Master_User	root
-Master_Port	#
-Connect_Retry	1
-Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	#
-Relay_Log_File	#
-Relay_Log_Pos	#
-Relay_Master_Log_File	master-bin.000001
-Slave_IO_Running	Yes
-Slave_SQL_Running	No
-Replicate_Do_DB	
-Replicate_Ignore_DB	
-Replicate_Do_Table	
-Replicate_Ignore_Table	
-Replicate_Wild_Do_Table	
-Replicate_Wild_Ignore_Table	
-Last_Errno	1364
-Last_Error	<Last_Error>
-Skip_Counter	0
-Exec_Master_Log_Pos	#
-Relay_Log_Space	#
-Until_Condition	None
-Until_Log_File	
-Until_Log_Pos	0
-Master_SSL_Allowed	No
-Master_SSL_CA_File	
-Master_SSL_CA_Path	
-Master_SSL_Cert	
-Master_SSL_Cipher	
-Master_SSL_Key	
-Seconds_Behind_Master	#
-Master_SSL_Verify_Server_Cert	No
-Last_IO_Errno	<Last_IO_Errno>
-Last_IO_Error	<Last_IO_Error>
-Last_SQL_Errno	1364
-Last_SQL_Error	<Last_SQL_Error>
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
+select count(*) from t1_nodef;
+count(*)
+1
 INSERT INTO t9 VALUES (2);
 **** On Master ****
 INSERT INTO t2 VALUES (2,4);
@@ -195,6 +157,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	0
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 INSERT INTO t9 VALUES (4);
 INSERT INTO t4 VALUES (4);
 SHOW SLAVE STATUS;
@@ -236,6 +200,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	1535
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 INSERT INTO t9 VALUES (5);
@@ -279,6 +245,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	1535
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 INSERT INTO t9 VALUES (6);
@@ -322,6 +290,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	1535
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 INSERT INTO t9 VALUES (6);
@@ -364,6 +334,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	0
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 INSERT INTO t7 VALUES (1),(2),(3);
 INSERT INTO t8 VALUES (1),(2),(3);
 SELECT * FROM t7 ORDER BY a;
diff --git a/mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result b/mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result
index 02e8c0743540a9a38421372cd3f3ef9796cece19..8a87c3ca7a00dde38a3e074f6ae198550ad1250f 100644
--- a/mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result
+++ b/mysql-test/suite/rpl/r/rpl_row_tabledefs_3innodb.result
@@ -105,47 +105,9 @@ a	b	x
 2	10	Foo is a bar
 INSERT INTO t9 VALUES (2);
 INSERT INTO t1_nodef VALUES (1,2);
-SHOW SLAVE STATUS;
-Slave_IO_State	#
-Master_Host	127.0.0.1
-Master_User	root
-Master_Port	#
-Connect_Retry	1
-Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	#
-Relay_Log_File	#
-Relay_Log_Pos	#
-Relay_Master_Log_File	master-bin.000001
-Slave_IO_Running	Yes
-Slave_SQL_Running	No
-Replicate_Do_DB	
-Replicate_Ignore_DB	
-Replicate_Do_Table	
-Replicate_Ignore_Table	
-Replicate_Wild_Do_Table	
-Replicate_Wild_Ignore_Table	
-Last_Errno	1364
-Last_Error	<Last_Error>
-Skip_Counter	0
-Exec_Master_Log_Pos	#
-Relay_Log_Space	#
-Until_Condition	None
-Until_Log_File	
-Until_Log_Pos	0
-Master_SSL_Allowed	No
-Master_SSL_CA_File	
-Master_SSL_CA_Path	
-Master_SSL_Cert	
-Master_SSL_Cipher	
-Master_SSL_Key	
-Seconds_Behind_Master	#
-Master_SSL_Verify_Server_Cert	No
-Last_IO_Errno	<Last_IO_Errno>
-Last_IO_Error	<Last_IO_Error>
-Last_SQL_Errno	1364
-Last_SQL_Error	<Last_SQL_Error>
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
+select count(*) from t1_nodef;
+count(*)
+1
 INSERT INTO t9 VALUES (2);
 **** On Master ****
 INSERT INTO t2 VALUES (2,4);
@@ -195,6 +157,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	0
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 INSERT INTO t9 VALUES (4);
 INSERT INTO t4 VALUES (4);
 SHOW SLAVE STATUS;
@@ -236,6 +200,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	1535
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 INSERT INTO t9 VALUES (5);
@@ -279,6 +245,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	1535
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 INSERT INTO t9 VALUES (6);
@@ -322,6 +290,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	1535
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 INSERT INTO t9 VALUES (6);
@@ -364,6 +334,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	0
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 INSERT INTO t7 VALUES (1),(2),(3);
 INSERT INTO t8 VALUES (1),(2),(3);
 SELECT * FROM t7 ORDER BY a;
diff --git a/mysql-test/suite/rpl/r/rpl_row_until.result b/mysql-test/suite/rpl/r/rpl_row_until.result
index ad54450af74f3364a6683f1c80030a623400fe07..e878456e296b7192c52b4510585182317d72bf49 100644
--- a/mysql-test/suite/rpl/r/rpl_row_until.result
+++ b/mysql-test/suite/rpl/r/rpl_row_until.result
@@ -59,6 +59,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 START SLAVE UNTIL MASTER_LOG_FILE='master-no-such-bin.000001', MASTER_LOG_POS=291;
 SELECT * FROM t1;
 n
@@ -105,6 +107,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 START SLAVE UNTIL RELAY_LOG_FILE='slave-relay-bin.000002', RELAY_LOG_POS=relay_pos_insert1_t2
 SELECT * FROM t2;
 n
@@ -149,6 +153,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 START SLAVE;
 include/stop_slave.inc
 START SLAVE SQL_THREAD UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=master_pos_create_t2
@@ -191,6 +197,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 START SLAVE UNTIL MASTER_LOG_FILE='master-bin', MASTER_LOG_POS=561;
 ERROR HY000: Incorrect parameter or combination of parameters for START SLAVE UNTIL
 START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=561, RELAY_LOG_POS=12;
diff --git a/mysql-test/suite/rpl/r/rpl_semi_sync.result b/mysql-test/suite/rpl/r/rpl_semi_sync.result
new file mode 100644
index 0000000000000000000000000000000000000000..607b77fbd0439ab3d9b0ed17f1be456fa4e5faea
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_semi_sync.result
@@ -0,0 +1,440 @@
+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;
+#
+# Uninstall semi-sync plugins on master and slave
+#
+include/stop_slave.inc
+reset slave;
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+reset master;
+set sql_log_bin=0;
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+set sql_log_bin=1;
+#
+# Main test of semi-sync replication start here
+#
+[ on master ]
+[ default state of semi-sync on master should be OFF ]
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name	Value
+rpl_semi_sync_master_enabled	OFF
+[ enable semi-sync on master ]
+set global rpl_semi_sync_master_enabled = 1;
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name	Value
+rpl_semi_sync_master_enabled	ON
+[ status of semi-sync on master should be ON even without any semi-sync slaves ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+#
+# BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
+# BUG#45673 Semisynch reports correct operation even if no slave is connected
+#
+[ status of semi-sync on master should be OFF ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+#
+# INSTALL PLUGIN semi-sync on slave
+#
+[ on slave ]
+[ default state of semi-sync on slave should be OFF ]
+show variables like 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+rpl_semi_sync_slave_enabled	OFF
+[ enable semi-sync on slave ]
+set global rpl_semi_sync_slave_enabled = 1;
+show variables like 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+rpl_semi_sync_slave_enabled	ON
+include/start_slave.inc
+[ on master ]
+[ initial master state after the semi-sync slave connected ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+create table t1(a int) engine = ENGINE_TYPE;
+[ master state after CREATE TABLE statement ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	1
+select CONNECTIONS_NORMAL_SLAVE - CONNECTIONS_NORMAL_SLAVE as 'Should be 0';
+Should be 0
+0
+[ insert records to table ]
+[ master status after inserts ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	301
+[ on slave ]
+[ slave status after replicated inserts ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	ON
+select count(distinct a) from t1;
+count(distinct a)
+300
+select min(a) from t1;
+min(a)
+1
+select max(a) from t1;
+max(a)
+300
+#
+# Test semi-sync master will switch OFF after one transacton
+# timeout waiting for slave reply.
+#
+include/stop_slave.inc
+[ on master ]
+[ master status should be ON ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	301
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
+[ semi-sync replication of these transactions will fail ]
+insert into t1 values (500);
+[ master status should be OFF ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	1
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	301
+insert into t1 values (100);
+[ master status should be OFF ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	302
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	301
+#
+# Test semi-sync status on master will be ON again when slave catches up
+#
+[ on slave ]
+[ slave status should be OFF ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+include/start_slave.inc
+[ slave status should be ON ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	ON
+select count(distinct a) from t1;
+count(distinct a)
+2
+select min(a) from t1;
+min(a)
+100
+select max(a) from t1;
+max(a)
+500
+[ on master ]
+[ master status should be ON again after slave catches up ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	302
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	301
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
+#
+# Test disable/enable master semi-sync on the fly.
+#
+drop table t1;
+[ on slave ]
+include/stop_slave.inc
+#
+# Flush status
+#
+[ Semi-sync master status variables before FLUSH STATUS ]
+SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	302
+SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	302
+FLUSH NO_WRITE_TO_BINLOG STATUS;
+[ Semi-sync master status variables after FLUSH STATUS ]
+SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+[ on master ]
+show master logs;
+Log_name	master-bin.000001
+File_size	#
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name	Value
+rpl_semi_sync_master_enabled	ON
+[ disable semi-sync on the fly ]
+set global rpl_semi_sync_master_enabled=0;
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name	Value
+rpl_semi_sync_master_enabled	OFF
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+[ enable semi-sync on the fly ]
+set global rpl_semi_sync_master_enabled=1;
+show variables like 'rpl_semi_sync_master_enabled';
+Variable_name	Value
+rpl_semi_sync_master_enabled	ON
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+#
+# Test RESET MASTER/SLAVE
+#
+[ on slave ]
+include/start_slave.inc
+[ on master ]
+create table t1 (a int) engine = ENGINE_TYPE;
+drop table t1;
+show status like 'Rpl_relay%';
+Variable_name	Value
+[ test reset master ]
+[ on master]
+reset master;
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+[ on slave ]
+include/stop_slave.inc
+reset slave;
+include/start_slave.inc
+[ on master ]
+create table t1 (a int) engine = ENGINE_TYPE;
+insert into t1 values (1);
+insert into t1 values (2), (3);
+[ on slave ]
+select * from t1;
+a
+1
+2
+3
+[ on master ]
+[ master semi-sync status should be ON ]
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	3
+#
+# Start semi-sync replication without SUPER privilege
+#
+include/stop_slave.inc
+reset slave;
+[ on master ]
+reset master;
+set sql_log_bin=0;
+grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl';
+flush privileges;
+set sql_log_bin=1;
+[ on slave ]
+grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl';
+flush privileges;
+change master to master_user='rpl',master_password='rpl';
+include/start_slave.inc
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	ON
+[ on master ]
+[ master semi-sync should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	0
+insert into t1 values (4);
+insert into t1 values (5);
+[ master semi-sync should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+show status like 'Rpl_semi_sync_master_no_tx';
+Variable_name	Value
+Rpl_semi_sync_master_no_tx	0
+show status like 'Rpl_semi_sync_master_yes_tx';
+Variable_name	Value
+Rpl_semi_sync_master_yes_tx	2
+#
+# Test semi-sync slave connect to non-semi-sync master
+#
+[ on slave ]
+include/stop_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+[ on master ]
+[ Semi-sync status on master should be ON ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	0
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	ON
+set global rpl_semi_sync_master_enabled= 0;
+[ on slave ]
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+rpl_semi_sync_slave_enabled	ON
+include/start_slave.inc
+[ on master ]
+insert into t1 values (8);
+[ master semi-sync clients should be 1, status should be OFF ]
+show status like 'Rpl_semi_sync_master_clients';
+Variable_name	Value
+Rpl_semi_sync_master_clients	1
+show status like 'Rpl_semi_sync_master_status';
+Variable_name	Value
+Rpl_semi_sync_master_status	OFF
+[ on slave ]
+show status like 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	ON
+include/stop_slave.inc
+[ on master ]
+set sql_log_bin=0;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+set sql_log_bin=1;
+SHOW VARIABLES LIKE 'rpl_semi_sync_master_enabled';
+Variable_name	Value
+[ on slave ]
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+rpl_semi_sync_slave_enabled	ON
+include/start_slave.inc
+[ on master ]
+insert into t1 values (10);
+[ on slave ]
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+#
+# Test non-semi-sync slave connect to semi-sync master
+#
+set sql_log_bin=0;
+INSTALL PLUGIN rpl_semi_sync_master SONAME 'libsemisync_master.so';
+set global rpl_semi_sync_master_timeout= 5000;
+/* 5s */
+set sql_log_bin=1;
+set global rpl_semi_sync_master_enabled= 1;
+[ on slave ]
+include/stop_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+[ uninstall semi-sync slave plugin ]
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+include/start_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+include/stop_slave.inc
+[ reinstall semi-sync slave plugin and disable semi-sync ]
+INSTALL PLUGIN rpl_semi_sync_slave SONAME 'libsemisync_slave.so';
+set global rpl_semi_sync_slave_enabled= 0;
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+Variable_name	Value
+rpl_semi_sync_slave_enabled	OFF
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+include/start_slave.inc
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+Variable_name	Value
+Rpl_semi_sync_slave_status	OFF
+#
+# Clean up
+#
+include/stop_slave.inc
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+include/start_slave.inc
+drop table t1;
+drop user rpl@127.0.0.1;
+flush privileges;
diff --git a/mysql-test/suite/rpl/r/rpl_server_id_ignore.result b/mysql-test/suite/rpl/r/rpl_server_id_ignore.result
new file mode 100644
index 0000000000000000000000000000000000000000..cba6571eb1afad110dbbf6033b7a0df40aeb8955
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_server_id_ignore.result
@@ -0,0 +1,46 @@
+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;
+master_id: 1
+stop slave;
+*** --replicate-same-server-id and change master option can clash ***
+change master to IGNORE_SERVER_IDS= (2, 1);
+ERROR HY000: The requested server id 2 clashes with the slave startup option --replicate-same-server-id
+*** must be empty due to the error ***
+ignore server id list: 
+change master to IGNORE_SERVER_IDS= (10, 100);
+*** must be 10, 100 ***
+ignore server id list: 10, 100
+reset slave;
+*** must be empty due to reset slave ***
+ignore server id list: 10, 100
+change master to IGNORE_SERVER_IDS= (10, 100);
+*** CHANGE MASTER with IGNORE_SERVER_IDS option overrides (does not increment) the previous setup ***
+change master to IGNORE_SERVER_IDS= (5, 1, 4, 3, 1);
+*** must be 1, 3, 4, 5 due to overriding policy ***
+ignore server id list: 1, 3, 4, 5
+*** ignore master (server 1) queries for a while ***
+start slave;
+create table t1 (n int);
+*** must be empty as the event is to be filtered out ***
+show tables;
+Tables_in_test
+*** allowing events from master ***
+stop slave;
+reset slave;
+change master to IGNORE_SERVER_IDS= (10, 100);
+*** the list must remain (10, 100) after reset slave ***
+change master to IGNORE_SERVER_IDS= ();
+*** must be empty due to IGNORE_SERVER_IDS empty list ***
+ignore server id list: 
+change master to master_host='127.0.0.1', master_port=MASTER_PORT, master_user='root';
+start slave;
+*** must have caught create table ***
+show tables;
+Tables_in_test
+t1
+drop table t1;
+end of the tests
diff --git a/mysql-test/suite/rpl/r/rpl_skip_error.result b/mysql-test/suite/rpl/r/rpl_skip_error.result
index d955859f030e35dbfd267bafb35bd325b7bfdc53..7b2bd48515d814d57b60098c35b2df41a98a6d12 100644
--- a/mysql-test/suite/rpl/r/rpl_skip_error.result
+++ b/mysql-test/suite/rpl/r/rpl_skip_error.result
@@ -70,6 +70,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 ==== Clean Up ====
 drop table t1;
 create table t1(a int primary key);
@@ -123,6 +125,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 ==== Clean Up ====
 drop table t1;
 ==== Using Innodb ====
diff --git a/mysql-test/suite/rpl/r/rpl_slave_load_remove_tmpfile.result b/mysql-test/suite/rpl/r/rpl_slave_load_remove_tmpfile.result
index e2efcf08d7aa5fbe8d5a5808025102a81fb21045..880fc9e8569f76d5428da2648c3b993b8ded0fdb 100644
--- a/mysql-test/suite/rpl/r/rpl_slave_load_remove_tmpfile.result
+++ b/mysql-test/suite/rpl/r/rpl_slave_load_remove_tmpfile.result
@@ -49,6 +49,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	9
 Last_SQL_Error	Error in Begin_load_query event: write to '../../tmp/SQL_LOAD.data' failed
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 drop table t1;
 drop table t1;
 call mtr.add_suppression("Slave: Error writing file 'UNKNOWN' .Errcode: 9. Error_code: 3");
diff --git a/mysql-test/suite/rpl/r/rpl_slave_skip.result b/mysql-test/suite/rpl/r/rpl_slave_skip.result
index 6148de5d954fb5c4c8d9963d1eebf227ab763d4b..5a37344cac68070ac646f7e7765b120268002a17 100644
--- a/mysql-test/suite/rpl/r/rpl_slave_skip.result
+++ b/mysql-test/suite/rpl/r/rpl_slave_skip.result
@@ -50,7 +50,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	1115
+Read_Master_Log_Pos	1116
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000001
@@ -65,7 +65,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	762
+Exec_Master_Log_Pos	763
 Relay_Log_Space	#
 Until_Condition	Master
 Until_Log_File	master-bin.000001
@@ -82,6 +82,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 SELECT * FROM t1;
@@ -114,7 +116,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	248
+Read_Master_Log_Pos	249
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000001
@@ -129,7 +131,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	248
+Exec_Master_Log_Pos	249
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -146,6 +148,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 **** On Master ****
 DROP TABLE t1, t2;
 SET SESSION BINLOG_FORMAT=ROW;
diff --git a/mysql-test/suite/rpl/r/rpl_slow_query_log.result b/mysql-test/suite/rpl/r/rpl_slow_query_log.result
new file mode 100644
index 0000000000000000000000000000000000000000..ced357b21e956c4d8714a54331c4894625711829
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_slow_query_log.result
@@ -0,0 +1,47 @@
+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;
+include/stop_slave.inc
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET @old_long_query_time= @@long_query_time;
+SET GLOBAL long_query_time= 2;
+TRUNCATE mysql.slow_log;
+include/start_slave.inc
+CREATE TABLE t1 (a int, b int);
+INSERT INTO t1 values(1, 1);
+INSERT INTO t1 values(1, sleep(3));
+TRUNCATE mysql.slow_log;
+SELECT 1, sleep(3);
+1	sleep(3)
+1	0
+SELECT 1;
+1
+1
+TRUNCATE mysql.slow_log;
+SET TIMESTAMP= 1;
+SELECT 2, sleep(3);
+2	sleep(3)
+2	0
+SELECT 2;
+2
+2
+TRUNCATE mysql.slow_log;
+SET @old_slow_query_log= @@slow_query_log;
+SET GLOBAL slow_query_log= 'OFF';
+SELECT 3, sleep(3);
+3	sleep(3)
+3	0
+SELECT 3;
+3
+3
+TRUNCATE mysql.slow_log;
+SET GLOBAL slow_query_log= @old_slow_query_log;
+DROP TABLE t1;
+include/stop_slave.inc
+SET GLOBAL long_query_time= @old_long_query_time;
+SET GLOBAL log_output= @old_log_output;
+include/start_slave.inc
diff --git a/mysql-test/suite/rpl/r/rpl_sp.result b/mysql-test/suite/rpl/r/rpl_sp.result
index 90a362c352bf1b098dabdbeb78fe1132707426b0..e2946bb487a8fd3bfac30e385fe2aaa46704ed5c 100644
--- a/mysql-test/suite/rpl/r/rpl_sp.result
+++ b/mysql-test/suite/rpl/r/rpl_sp.result
@@ -409,110 +409,110 @@ return 0;
 end|
 use mysqltest;
 set @a:= mysqltest2.f1();
-show binlog events in 'master-bin.000001' from 106;
+show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	#	Query	1	#	drop database if exists mysqltest1
-master-bin.000001	#	Query	1	#	create database mysqltest1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; create table t1 (a varchar(100))
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo`()
+master-bin.000001	#	Query	#	#	drop database if exists mysqltest1
+master-bin.000001	#	Query	#	#	create database mysqltest1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; create table t1 (a varchar(100))
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo`()
 begin
 declare b int;
 set b = 8;
 insert into t1 values (b);
 insert into t1 values (unix_timestamp());
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values ( NAME_CONST('b',8))
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values (unix_timestamp())
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete from t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo2`()
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values ( NAME_CONST('b',8))
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values (unix_timestamp())
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete from t1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo2`()
 select * from mysqltest1.t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; alter procedure foo2 contains sql
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop table t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; create table t1 (a int)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; create table t2 like t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo3`()
+master-bin.000001	#	Query	#	#	use `mysqltest1`; alter procedure foo2 contains sql
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop table t1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; create table t1 (a int)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; create table t2 like t1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo3`()
     DETERMINISTIC
 insert into t1 values (15)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; grant CREATE ROUTINE, EXECUTE on mysqltest1.* to "zedjzlcsjhd"@127.0.0.1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; grant SELECT on mysqltest1.t1 to "zedjzlcsjhd"@127.0.0.1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; grant SELECT, INSERT on mysqltest1.t2 to "zedjzlcsjhd"@127.0.0.1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`zedjzlcsjhd`@`127.0.0.1` PROCEDURE `foo4`()
+master-bin.000001	#	Query	#	#	use `mysqltest1`; grant CREATE ROUTINE, EXECUTE on mysqltest1.* to "zedjzlcsjhd"@127.0.0.1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; grant SELECT on mysqltest1.t1 to "zedjzlcsjhd"@127.0.0.1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; grant SELECT, INSERT on mysqltest1.t2 to "zedjzlcsjhd"@127.0.0.1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`zedjzlcsjhd`@`127.0.0.1` PROCEDURE `foo4`()
     DETERMINISTIC
 begin
 insert into t2 values(3);
 insert into t1 values (5);
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t2 values(3)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values (15)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t2 values(3)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; alter procedure foo4 sql security invoker
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t2 values(3)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values (5)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete from t2
-master-bin.000001	#	Query	1	#	use `mysqltest1`; alter table t2 add unique (a)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop procedure foo4
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo4`()
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t2 values(3)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values (15)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t2 values(3)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; alter procedure foo4 sql security invoker
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t2 values(3)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values (5)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete from t2
+master-bin.000001	#	Query	#	#	use `mysqltest1`; alter table t2 add unique (a)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop procedure foo4
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo4`()
     DETERMINISTIC
 begin
 insert into t2 values(20),(20);
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t2 values(20),(20)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop procedure foo4
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop procedure foo
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop procedure foo2
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop procedure foo3
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn1`(x int) RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t2 values(20),(20)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop procedure foo4
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop procedure foo
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop procedure foo2
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop procedure foo3
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn1`(x int) RETURNS int(11)
     DETERMINISTIC
 begin
 insert into t1 values (x);
 return x+2;
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete t1,t2 from t1,t2
-master-bin.000001	#	Query	1	#	use `mysqltest1`; SELECT `mysqltest1`.`fn1`(20)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t2 values(fn1(21))
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop function fn1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn1`() RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete t1,t2 from t1,t2
+master-bin.000001	#	Query	#	#	use `mysqltest1`; SELECT `mysqltest1`.`fn1`(20)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t2 values(fn1(21))
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop function fn1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn1`() RETURNS int(11)
     NO SQL
 begin
 return unix_timestamp();
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete from t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values(fn1())
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`zedjzlcsjhd`@`127.0.0.1` FUNCTION `fn2`() RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete from t1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values(fn1())
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`zedjzlcsjhd`@`127.0.0.1` FUNCTION `fn2`() RETURNS int(11)
     NO SQL
 begin
 return unix_timestamp();
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn3`() RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn3`() RETURNS int(11)
     READS SQL DATA
 begin
 return 0;
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete from t2
-master-bin.000001	#	Query	1	#	use `mysqltest1`; alter table t2 add unique (a)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop function fn1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn1`(x int) RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete from t2
+master-bin.000001	#	Query	#	#	use `mysqltest1`; alter table t2 add unique (a)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop function fn1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` FUNCTION `fn1`(x int) RETURNS int(11)
 begin
 insert into t2 values(x),(x);
 return 10;
 end
-master-bin.000001	#	Query	1	#	use `mysqltest1`; SELECT `mysqltest1`.`fn1`(100)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; SELECT `mysqltest1`.`fn1`(20)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete from t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger trg before insert on t1 for each row set new.a= 10
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values (1)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; delete from t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop trigger trg
-master-bin.000001	#	Query	1	#	use `mysqltest1`; insert into t1 values (1)
-master-bin.000001	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo`()
+master-bin.000001	#	Query	#	#	use `mysqltest1`; SELECT `mysqltest1`.`fn1`(100)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; SELECT `mysqltest1`.`fn1`(20)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete from t1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger trg before insert on t1 for each row set new.a= 10
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values (1)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; delete from t1
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop trigger trg
+master-bin.000001	#	Query	#	#	use `mysqltest1`; insert into t1 values (1)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` PROCEDURE `foo`()
     READS SQL DATA
 select * from t1
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop procedure foo
-master-bin.000001	#	Query	1	#	use `mysqltest1`; drop function fn1
-master-bin.000001	#	Query	1	#	drop database mysqltest1
-master-bin.000001	#	Query	1	#	drop user "zedjzlcsjhd"@127.0.0.1
-master-bin.000001	#	Query	1	#	use `test`; drop function if exists f1
-master-bin.000001	#	Query	1	#	use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop procedure foo
+master-bin.000001	#	Query	#	#	use `mysqltest1`; drop function fn1
+master-bin.000001	#	Query	#	#	drop database mysqltest1
+master-bin.000001	#	Query	#	#	drop user "zedjzlcsjhd"@127.0.0.1
+master-bin.000001	#	Query	#	#	use `test`; drop function if exists f1
+master-bin.000001	#	Query	#	#	use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
     READS SQL DATA
 begin
 declare var integer;
@@ -522,41 +522,41 @@ fetch c into var;
 close c;
 return var;
 end
-master-bin.000001	#	Query	1	#	use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 as a
-master-bin.000001	#	Query	1	#	use `test`; create table t1 (a int)
-master-bin.000001	#	Query	1	#	use `test`; insert into t1 (a) values (f1())
-master-bin.000001	#	Query	1	#	use `test`; drop view v1
-master-bin.000001	#	Query	1	#	use `test`; drop function f1
-master-bin.000001	#	Query	1	#	use `test`; DROP PROCEDURE IF EXISTS p1
-master-bin.000001	#	Query	1	#	use `test`; DROP TABLE IF EXISTS t1
-master-bin.000001	#	Query	1	#	use `test`; CREATE TABLE t1(col VARCHAR(10))
-master-bin.000001	#	Query	1	#	use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`(arg VARCHAR(10))
+master-bin.000001	#	Query	#	#	use `test`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 1 as a
+master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int)
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 (a) values (f1())
+master-bin.000001	#	Query	#	#	use `test`; drop view v1
+master-bin.000001	#	Query	#	#	use `test`; drop function f1
+master-bin.000001	#	Query	#	#	use `test`; DROP PROCEDURE IF EXISTS p1
+master-bin.000001	#	Query	#	#	use `test`; DROP TABLE IF EXISTS t1
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1(col VARCHAR(10))
+master-bin.000001	#	Query	#	#	use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`(arg VARCHAR(10))
 INSERT INTO t1 VALUES(arg)
-master-bin.000001	#	Query	1	#	use `test`; INSERT INTO t1 VALUES( NAME_CONST('arg',_latin1'test' COLLATE 'latin1_swedish_ci'))
-master-bin.000001	#	Query	1	#	use `test`; DROP PROCEDURE p1
-master-bin.000001	#	Query	1	#	use `test`; DROP PROCEDURE IF EXISTS p1
-master-bin.000001	#	Query	1	#	use `test`; DROP FUNCTION IF EXISTS f1
-master-bin.000001	#	Query	1	#	use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES( NAME_CONST('arg',_latin1'test' COLLATE 'latin1_swedish_ci'))
+master-bin.000001	#	Query	#	#	use `test`; DROP PROCEDURE p1
+master-bin.000001	#	Query	#	#	use `test`; DROP PROCEDURE IF EXISTS p1
+master-bin.000001	#	Query	#	#	use `test`; DROP FUNCTION IF EXISTS f1
+master-bin.000001	#	Query	#	#	use `test`; CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`()
 SET @a = 1
-master-bin.000001	#	Query	1	#	use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `test`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
 RETURN 0
-master-bin.000001	#	Query	1	#	use `test`; DROP PROCEDURE p1
-master-bin.000001	#	Query	1	#	use `test`; DROP FUNCTION f1
-master-bin.000001	#	Query	1	#	use `test`; drop table t1
-master-bin.000001	#	Query	1	#	drop database if exists mysqltest
-master-bin.000001	#	Query	1	#	drop database if exists mysqltest2
-master-bin.000001	#	Query	1	#	create database mysqltest
-master-bin.000001	#	Query	1	#	create database mysqltest2
-master-bin.000001	#	Query	1	#	use `mysqltest2`; create table t ( t integer )
-master-bin.000001	#	Query	1	#	use `mysqltest2`; CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqltest`.`test`()
+master-bin.000001	#	Query	#	#	use `test`; DROP PROCEDURE p1
+master-bin.000001	#	Query	#	#	use `test`; DROP FUNCTION f1
+master-bin.000001	#	Query	#	#	use `test`; drop table t1
+master-bin.000001	#	Query	#	#	drop database if exists mysqltest
+master-bin.000001	#	Query	#	#	drop database if exists mysqltest2
+master-bin.000001	#	Query	#	#	create database mysqltest
+master-bin.000001	#	Query	#	#	create database mysqltest2
+master-bin.000001	#	Query	#	#	use `mysqltest2`; create table t ( t integer )
+master-bin.000001	#	Query	#	#	use `mysqltest2`; CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqltest`.`test`()
 begin end
-master-bin.000001	#	Query	1	#	use `mysqltest2`; insert into t values ( 1 )
-master-bin.000001	#	Query	1	#	use `mysqltest2`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
+master-bin.000001	#	Query	#	#	use `mysqltest2`; insert into t values ( 1 )
+master-bin.000001	#	Query	#	#	use `mysqltest2`; CREATE DEFINER=`root`@`localhost` FUNCTION `f1`() RETURNS int(11)
 begin
 insert into t values (1);
 return 0;
 end
-master-bin.000001	#	Query	1	#	use `mysqltest`; SELECT `mysqltest2`.`f1`()
+master-bin.000001	#	Query	#	#	use `mysqltest`; SELECT `mysqltest2`.`f1`()
 set @@global.log_bin_trust_routine_creators= @old_log_bin_trust_routine_creators;
 Warnings:
 Warning	1287	The syntax '@@log_bin_trust_routine_creators' is deprecated and will be removed in MySQL 6.0. Please use '@@log_bin_trust_function_creators' instead
diff --git a/mysql-test/suite/rpl/r/rpl_spec_variables.result b/mysql-test/suite/rpl/r/rpl_spec_variables.result
new file mode 100644
index 0000000000000000000000000000000000000000..ea2778bf71c1faab5f3cecf124c8ebb0c6579408
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_spec_variables.result
@@ -0,0 +1,225 @@
+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;
+
+* auto_increment_increment, auto_increment_offset *
+SET @@global.auto_increment_increment=2;
+SET @@session.auto_increment_increment=2;
+SET @@global.auto_increment_offset=10;
+SET @@session.auto_increment_offset=10;
+SET @@global.auto_increment_increment=3;
+SET @@session.auto_increment_increment=3;
+SET @@global.auto_increment_offset=20;
+SET @@session.auto_increment_offset=20;
+CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+INSERT INTO t1 (b) VALUES ('master');
+INSERT INTO t1 (b) VALUES ('master');
+SELECT * FROM t1 ORDER BY a;
+a	b
+2	master
+4	master
+CREATE TABLE t2 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+INSERT INTO t1 (b) VALUES ('slave');
+INSERT INTO t1 (b) VALUES ('slave');
+INSERT INTO t2 (b) VALUES ('slave');
+INSERT INTO t2 (b) VALUES ('slave');
+SELECT * FROM t1 ORDER BY a;
+a	b
+2	master
+4	master
+7	slave
+10	slave
+SELECT * FROM t2 ORDER BY a;
+a	b
+1	slave
+4	slave
+DROP TABLE IF EXISTS t1,t2;
+SET @@global.auto_increment_increment=1;
+SET @@session.auto_increment_increment=1;
+SET @@global.auto_increment_offset=1;
+SET @@session.auto_increment_offset=1;
+SET @@global.auto_increment_increment=1;
+SET @@session.auto_increment_increment=1;
+SET @@global.auto_increment_offset=1;
+SET @@session.auto_increment_offset=1;
+SET auto_increment_increment=1;
+SET auto_increment_offset=1;
+
+* character_set_database, collation_server *
+SET @restore_master_character_set_database=@@global.character_set_database;
+SET @restore_master_collation_server=@@global.collation_server;
+SET @@global.character_set_database=latin1;
+SET @@session.character_set_database=latin1;
+SET @@global.collation_server=latin1_german1_ci;
+SET @@session.collation_server=latin1_german1_ci;
+SET @restore_slave_character_set_database=@@global.character_set_database;
+SET @restore_slave_collation_server=@@global.collation_server;
+SET @@global.character_set_database=utf8;
+SET @@session.character_set_database=utf8;
+SET @@global.collation_server=utf8_bin;
+SET @@session.collation_server=utf8_bin;
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) COLLATE latin1_german1_ci DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci
+CREATE TABLE t2 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) COLLATE latin1_german1_ci DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) COLLATE utf8_bin DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
+SET @@global.collation_server=latin1_swedish_ci;
+SET @@session.collation_server=latin1_swedish_ci;
+SET @@global.collation_server=latin1_swedish_ci;
+SET @@session.collation_server=latin1_swedish_ci;
+DROP TABLE IF EXISTS t1,t2;
+
+* default_week_format *
+SET @@global.default_week_format=0;
+SET @@session.default_week_format=0;
+SET @@global.default_week_format=1;
+SET @@session.default_week_format=1;
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1, 'master ', WEEK('2008-01-07'));
+SELECT * FROM t1 ORDER BY a;
+a	b	c
+1	master 	1
+INSERT INTO t1 VALUES (2, 'slave ', WEEK('2008-01-07'));
+SELECT * FROM t1 ORDER BY a;
+a	b	c
+1	master 	1
+2	slave 	2
+DROP TABLE t1;
+SET @@global.default_week_format=0;
+SET @@session.default_week_format=0;
+
+* local_infile *
+SET @@global.local_infile=0;
+CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(20), c CHAR(254)) ENGINE=MyISAM;
+LOAD DATA LOCAL INFILE 'FILE' INTO TABLE t1 (b);
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+70
+LOAD DATA LOCAL INFILE 'FILE2' INTO TABLE t1 (b);
+ERROR 42000: The used command is not allowed with this MySQL version
+SELECT COUNT(*) FROM t1;
+COUNT(*)
+70
+SET @@global.local_infile=1;
+DROP TABLE t1;
+
+* max_heap_table_size *
+SET @restore_slave_max_heap_table_size=@@global.max_heap_table_size;
+SET @@global.max_heap_table_size=16384;
+SET @@session.max_heap_table_size=16384;
+CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), c CHAR(254)) ENGINE=MEMORY;
+SELECT COUNT(*)=2000 FROM t1;
+COUNT(*)=2000
+1
+SELECT COUNT(*)=2000 FROM t1 WHERE b='master' GROUP BY b ORDER BY b;
+COUNT(*)=2000
+1
+SELECT COUNT(*)<2000 AND COUNT(*)>0 FROM t1 WHERE b='slave' GROUP BY b ORDER BY b;
+COUNT(*)<2000 AND COUNT(*)>0
+1
+SELECT COUNT(*)<2000 AND COUNT(*)>0 FROM t2 WHERE b='slave' GROUP BY b ORDER BY b;
+COUNT(*)<2000 AND COUNT(*)>0
+1
+DROP TABLE IF EXISTS t1,t2;
+
+* storage_engine *
+SET @restore_master_storage_engine=@@global.storage_engine;
+SET @@global.storage_engine=InnoDB;
+SET @@session.storage_engine=InnoDB;
+SET @restore_slave_storage_engine=@@global.storage_engine;
+SET @@global.storage_engine=Memory;
+SET @@session.storage_engine=Memory;
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10));
+CREATE TABLE t2 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
+CREATE TABLE t3 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10));
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t2;
+Table	Create Table
+t2	CREATE TABLE `t2` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE t3;
+Table	Create Table
+t3	CREATE TABLE `t3` (
+  `a` int(11) NOT NULL,
+  `b` varchar(10) DEFAULT NULL,
+  PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SET @@global.storage_engine=InnoDB;
+SET @@session.storage_engine=InnoDB;
+DROP TABLE IF EXISTS t1,t2,t3;
+
+* sql_mode *
+SET @@global.sql_mode=ANSI;
+SET @@session.sql_mode=ANSI;
+SET @@global.sql_mode=TRADITIONAL;
+SET @@session.sql_mode=TRADITIONAL;
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c DATE);
+INSERT INTO t1 VALUES (1, 'master', '0000-00-00');
+SELECT * FROM t1 ORDER BY a;
+a	b	c
+1	master	0000-00-00
+INSERT INTO t1 VALUES (1, 'slave', '0000-00-00');
+ERROR 22007: Incorrect date value: '0000-00-00' for column 'c' at row 1
+SELECT * FROM t1 ORDER BY a;
+a	b	c
+1	master	0000-00-00
+SET @@global.sql_mode='';
+SET @@session.sql_mode='';
+SET @@global.sql_mode='';
+SET @@session.sql_mode='';
+DROP TABLE t1;
+
+*** clean up ***
+SET @@global.character_set_database=@restore_master_character_set_database;
+SET @@global.collation_server=@restore_master_collation_server;
+SET @@global.storage_engine=@restore_master_storage_engine;
+SET @@global.character_set_database=@restore_slave_character_set_database;
+SET @@global.collation_server=@restore_slave_collation_server;
+SET @@global.max_heap_table_size=@restore_slave_max_heap_table_size;
+SET @@global.storage_engine=@restore_slave_storage_engine;
+
+call mtr.add_suppression("The table 't[12]' is full");
diff --git a/mysql-test/suite/rpl/r/rpl_ssl.result b/mysql-test/suite/rpl/r/rpl_ssl.result
index d188dd353ceab77b48e1a4e53de40e70d910bf07..c8e9e1a491186fce0a9ffb874f2310f19fe4f7d8 100644
--- a/mysql-test/suite/rpl/r/rpl_ssl.result
+++ b/mysql-test/suite/rpl/r/rpl_ssl.result
@@ -58,6 +58,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 select * from t1;
 t
@@ -102,6 +104,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 drop user replssl@localhost;
 drop table t1;
 End of 5.0 tests
diff --git a/mysql-test/suite/rpl/r/rpl_ssl1.result b/mysql-test/suite/rpl/r/rpl_ssl1.result
index 74d2550cdafda1f6f3709d7400691f80cd3f7375..de255228affdce3c7e868358f72a15100c05cf53 100644
--- a/mysql-test/suite/rpl/r/rpl_ssl1.result
+++ b/mysql-test/suite/rpl/r/rpl_ssl1.result
@@ -57,6 +57,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 stop slave;
 change master to master_user='root',master_password='', master_ssl=0;
 start slave;
@@ -101,6 +103,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 stop slave;
 change master to
 master_host="localhost",
@@ -155,4 +159,6 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 drop table t1;
diff --git a/mysql-test/suite/rpl/r/rpl_stm_flsh_tbls.result b/mysql-test/suite/rpl/r/rpl_stm_flsh_tbls.result
index 74031af1ddee0cc0c084ea41ab779eb4657e8519..1f6c86768b531ed3a68b1aaf7cf9e6be6435928e 100644
--- a/mysql-test/suite/rpl/r/rpl_stm_flsh_tbls.result
+++ b/mysql-test/suite/rpl/r/rpl_stm_flsh_tbls.result
@@ -12,13 +12,13 @@ create table t4 (a int);
 insert into t4 select * from t3;
 rename table t1 to t5, t2 to t1;
 flush no_write_to_binlog tables;
-SHOW BINLOG EVENTS FROM 656 ;
+SHOW BINLOG EVENTS FROM 657 ;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; rename table t1 to t5, t2 to t1
 select * from t3;
 a
 flush tables;
-SHOW BINLOG EVENTS FROM 656 ;
+SHOW BINLOG EVENTS FROM 657 ;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; rename table t1 to t5, t2 to t1
 master-bin.000001	#	Query	1	#	use `test`; flush tables
diff --git a/mysql-test/suite/rpl/r/rpl_stm_log.result b/mysql-test/suite/rpl/r/rpl_stm_log.result
index d73b8990041089c88d13bec297a1e8f96b6ec5ef..22105f42879215d582444758d4cfd742fd92a101 100644
--- a/mysql-test/suite/rpl/r/rpl_stm_log.result
+++ b/mysql-test/suite/rpl/r/rpl_stm_log.result
@@ -26,14 +26,14 @@ master-bin.000001	#	Query	1	#	use `test`; drop table t1
 master-bin.000001	#	Query	1	#	use `test`; create table t1 (word char(20) not null)ENGINE=MyISAM
 master-bin.000001	#	Begin_load_query	1	#	;file_id=1;block_len=581
 master-bin.000001	#	Execute_load_query	1	#	use `test`; LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE `t1` FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' IGNORE 1 LINES  (word) ;file_id=1
-show binlog events from 106 limit 1;
+show binlog events from 107 limit 1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=MyISAM
-show binlog events from 106 limit 2;
+show binlog events from 107 limit 2;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=MyISAM
 master-bin.000001	#	Intvar	1	#	INSERT_ID=1
-show binlog events from 106 limit 2,1;
+show binlog events from 107 limit 2,1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; insert into t1 values (NULL)
 flush logs;
@@ -233,7 +233,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000002
-Read_Master_Log_Pos	392
+Read_Master_Log_Pos	393
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000002
@@ -248,7 +248,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	392
+Exec_Master_Log_Pos	393
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -265,6 +265,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 show binlog events in 'slave-bin.000005' from 4;
 ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not find target log
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl/r/rpl_stm_max_relay_size.result b/mysql-test/suite/rpl/r/rpl_stm_max_relay_size.result
index 2215b34814e923186b44d84a9378ffad69108f50..c2554218f733b0ab6019d5f5d1ec8b6927d79ef2 100644
--- a/mysql-test/suite/rpl/r/rpl_stm_max_relay_size.result
+++ b/mysql-test/suite/rpl/r/rpl_stm_max_relay_size.result
@@ -60,6 +60,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 2
 #
@@ -108,6 +110,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 3: max_relay_log_size = 0
 #
@@ -156,6 +160,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 4: Tests below are mainly to ensure that we have not coded with wrong assumptions
 #
@@ -201,6 +207,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 5
 #
@@ -247,6 +255,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 #
 # Test 6: one more rotation, to be sure Relay_Log_Space is correctly updated
 #
@@ -291,6 +301,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 flush logs;
 show master status;
 File	Position	Binlog_Do_DB	Binlog_Ignore_DB
diff --git a/mysql-test/suite/rpl/r/rpl_stm_mix_show_relaylog_events.result b/mysql-test/suite/rpl/r/rpl_stm_mix_show_relaylog_events.result
new file mode 100644
index 0000000000000000000000000000000000000000..512a72c304023efa88861c7c2e1bf7143f4db432
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_stm_mix_show_relaylog_events.result
@@ -0,0 +1,148 @@
+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 (a INT);
+INSERT INTO t1 VALUES (1);
+INSERT INTO t1 VALUES (2);
+INSERT INTO t1 VALUES (3);
+INSERT INTO t1 VALUES (4);
+INSERT INTO t1 VALUES (5);
+INSERT INTO t1 VALUES (6);
+[MASTER] ********* SOW BINLOG EVENTS IN ...  *********
+show binlog events in 'master-bin.000001' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+[MASTER] ********* SOW BINLOG EVENTS         *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+[MASTER] ********* SOW BINLOG EVENTS ... LIMIT rows  *********
+show binlog events from <binlog_start> limit 3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+[MASTER] ********* SOW BINLOG EVENTS ... LIMIT offset,rows  *********
+show binlog events from <binlog_start> limit 1,  3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+[SLAVE] ********* SOW BINLOG EVENTS IN ...   *********
+show binlog events in 'slave-bin.000001' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+[SLAVE] ********* SOW BINLOG EVENTS          *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+[SLAVE] ********* SOW BINLOG EVENTS ... LIMIT rows  *********
+show binlog events from <binlog_start> limit 3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+[SLAVE] ********* SOW BINLOG EVENTS ... LIMIT offset,rows  *********
+show binlog events from <binlog_start> limit 1,  3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+[SLAVE] ********* SOW RELAYLOG EVENTS IN ... *********
+show relaylog events in 'slave-relay-bin.000003' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000003	#	Rotate	#	#	master-bin.000001;pos=4
+slave-relay-bin.000003	#	Format_desc	#	#	SERVER_VERSION, BINLOG_VERSION
+slave-relay-bin.000003	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+[SLAVE] ********* SOW RELAYLOG EVENTS        *********
+show relaylog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000002	#	Rotate	#	#	slave-relay-bin.000003;pos=4
+[MASTER] ********* SOW RELAYLOG EVENTS ... LIMIT rows  *********
+show relaylog events in 'slave-relay-bin.000003' from <binlog_start> limit 3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000003	#	Rotate	#	#	master-bin.000001;pos=4
+slave-relay-bin.000003	#	Format_desc	#	#	SERVER_VERSION, BINLOG_VERSION
+slave-relay-bin.000003	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+[MASTER] ********* SOW RELAYLOG EVENTS ... LIMIT offset,rows  *********
+show relaylog events in 'slave-relay-bin.000003' from <binlog_start> limit 1,  3;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000003	#	Format_desc	#	#	SERVER_VERSION, BINLOG_VERSION
+slave-relay-bin.000003	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-relay-bin.000003	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+FLUSH LOGS;
+FLUSH LOGS;
+DROP TABLE t1;
+[MASTER] ********* SOW BINLOG EVENTS IN ...  *********
+show binlog events in 'master-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000002	#	Query	#	#	use `test`; DROP TABLE t1
+[MASTER] ********* SOW BINLOG EVENTS         *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+master-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+master-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+master-bin.000001	#	Rotate	#	#	master-bin.000002;pos=4
+[SLAVE] ********* SOW BINLOG EVENTS IN ...   *********
+show binlog events in 'slave-bin.000002' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000002	#	Query	#	#	use `test`; DROP TABLE t1
+[SLAVE] ********* SOW BINLOG EVENTS          *********
+show binlog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-bin.000001	#	Query	#	#	use `test`; CREATE TABLE t1 (a INT)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (1)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (2)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (3)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (4)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (5)
+slave-bin.000001	#	Query	#	#	use `test`; INSERT INTO t1 VALUES (6)
+slave-bin.000001	#	Rotate	#	#	slave-bin.000002;pos=4
+[SLAVE] ********* SOW RELAYLOG EVENTS IN ... *********
+show relaylog events in 'slave-relay-bin.000005' from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000005	#	Rotate	#	#	master-bin.000002;pos=4
+slave-relay-bin.000005	#	Rotate	#	#	slave-relay-bin.000006;pos=4
+[SLAVE] ********* SOW RELAYLOG EVENTS        *********
+show relaylog events from <binlog_start>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+slave-relay-bin.000005	#	Rotate	#	#	master-bin.000002;pos=4
+slave-relay-bin.000005	#	Rotate	#	#	slave-relay-bin.000006;pos=4
diff --git a/mysql-test/suite/rpl/r/rpl_stm_reset_slave.result b/mysql-test/suite/rpl/r/rpl_stm_reset_slave.result
index 78d9d7c41eba7ea80bcd6248393b1b3afe7d460b..d18ca563b7b8ab827ae33187f5e332628e01869d 100644
--- a/mysql-test/suite/rpl/r/rpl_stm_reset_slave.result
+++ b/mysql-test/suite/rpl/r/rpl_stm_reset_slave.result
@@ -43,6 +43,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 stop slave;
 change master to master_user='test';
 SHOW SLAVE STATUS;
@@ -84,6 +86,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 reset slave;
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -124,6 +128,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave;
 SHOW SLAVE STATUS;
 Slave_IO_State	#
@@ -164,6 +170,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 stop slave;
 reset slave;
 start slave;
diff --git a/mysql-test/suite/rpl/r/rpl_stm_until.result b/mysql-test/suite/rpl/r/rpl_stm_until.result
index 55074f0be0d1a19c4b31e4d8bde568f11d10e601..6af9be0da3be5445f4fd98bf955580a9e62924e6 100644
--- a/mysql-test/suite/rpl/r/rpl_stm_until.result
+++ b/mysql-test/suite/rpl/r/rpl_stm_until.result
@@ -63,6 +63,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave until master_log_file='master-no-such-bin.000001', master_log_pos=291;
 select * from t1;
 n
@@ -109,6 +111,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave until relay_log_file='slave-relay-bin.000004', relay_log_pos=746;
 select * from t2;
 n
@@ -153,6 +157,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 start slave;
 [on master]
 [on slave]
@@ -197,6 +203,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 ==== Test various error conditions ====
 start slave until master_log_file='master-bin', master_log_pos=561;
 ERROR HY000: Incorrect parameter or combination of parameters for START SLAVE UNTIL
diff --git a/mysql-test/suite/rpl/r/rpl_stop_middle_group.result b/mysql-test/suite/rpl/r/rpl_stop_middle_group.result
new file mode 100644
index 0000000000000000000000000000000000000000..0bf0384bf85c9ee2199eb89c1af6fc3f2d80693e
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_stop_middle_group.result
@@ -0,0 +1,61 @@
+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 tm (a int auto_increment primary key) engine=myisam;
+create table ti (a int auto_increment primary key) engine=innodb;
+set @@global.debug="+d,stop_slave_middle_group";
+begin;
+insert into ti set a=null;
+insert into tm set a=null;
+commit;
+SELECT "NO" AS Last_SQL_Error, @check as `true`;
+Last_SQL_Error	true
+NO	1
+select count(*) as one from tm;
+one
+1
+select count(*) as one from ti;
+one
+1
+set @@global.debug="-d";
+include/start_slave.inc
+truncate table tm;
+truncate table ti;
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+begin;
+insert into ti set a=null;
+insert into tm set a=null;
+commit;
+SELECT "Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details)." AS Last_SQL_Error, @check as `true`;
+Last_SQL_Error	true
+Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details).	1
+select count(*) as one  from tm;
+one
+1
+select count(*) as zero from ti;
+zero
+0
+set @@global.debug="-d";
+stop slave;
+truncate table tm;
+include/start_slave.inc
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+update tm as t1, ti as t2 set t1.a=t1.a * 2, t2.a=t2.a * 2;
+SELECT "Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details)." AS Last_SQL_Error, @check as `true`;
+Last_SQL_Error	true
+Fatal error: ... The slave SQL is stopped, leaving the current group of events unfinished with a non-transaction table changed. If the group consists solely of Row-based events, you can try restarting the slave with --slave-exec-mode=IDEMPOTENT, which ignores duplicate key, key not found, and similar errors (see documentation for details).	1
+select max(a) as two from tm;
+two
+2
+select max(a) as one from ti;
+one
+1
+set @@global.debug="-d";
+drop table tm, ti;
+include/stop_slave.inc
+drop table tm, ti;
diff --git a/mysql-test/suite/rpl/r/rpl_sync.result b/mysql-test/suite/rpl/r/rpl_sync.result
new file mode 100644
index 0000000000000000000000000000000000000000..edc20c46140758a0b28ebecaf88599311b382893
--- /dev/null
+++ b/mysql-test/suite/rpl/r/rpl_sync.result
@@ -0,0 +1,40 @@
+=====Configuring the enviroment=======;
+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;
+call mtr.add_suppression('Attempting backtrace');
+call mtr.add_suppression("Recovery from master pos .* and file master-bin.000001");
+CREATE TABLE t1(a INT, PRIMARY KEY(a)) engine=innodb;
+insert into t1(a) values(1);
+insert into t1(a) values(2);
+insert into t1(a) values(3);
+=====Inserting data on the master but without the SQL Thread being running=======;
+stop slave SQL_THREAD;
+insert into t1(a) values(4);
+insert into t1(a) values(5);
+insert into t1(a) values(6);
+=====Removing relay log files and crashing/recoverying the slave=======;
+stop slave IO_THREAD;
+SET SESSION debug="d,crash_before_rotate_relaylog";
+FLUSH LOGS;
+ERROR HY000: Lost connection to MySQL server during query
+=====Dumping and comparing tables=======;
+start slave;
+Comparing tables master:test.t1 and slave:test.t1
+=====Corrupting the master.info=======;
+stop slave;
+FLUSH LOGS;
+insert into t1(a) values(7);
+insert into t1(a) values(8);
+insert into t1(a) values(9);
+SET SESSION debug="d,crash_before_rotate_relaylog";
+FLUSH LOGS;
+ERROR HY000: Lost connection to MySQL server during query
+=====Dumping and comparing tables=======;
+start slave;
+Comparing tables master:test.t1 and slave:test.t1
+=====Clean up=======;
+drop table t1;
diff --git a/mysql-test/suite/rpl/r/rpl_temporary.result b/mysql-test/suite/rpl/r/rpl_temporary.result
index 631eb0677b088c491d07e33b4c04ec4f06b41ac1..b2400a03f6393cd55ae5ef25faae603cbb4577df 100644
--- a/mysql-test/suite/rpl/r/rpl_temporary.result
+++ b/mysql-test/suite/rpl/r/rpl_temporary.result
@@ -27,12 +27,12 @@ Warning	1265	Data truncated for column 'b' at row 1
 DROP TABLE t1;
 SET @save_select_limit=@@session.sql_select_limit;
 SET @@session.sql_select_limit=10, @@session.pseudo_thread_id=100;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 SELECT @@session.sql_select_limit = @save_select_limit;
 @@session.sql_select_limit = @save_select_limit
 1
 SET @@session.sql_select_limit=10, @@session.sql_log_bin=0;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 SELECT @@session.sql_select_limit = @save_select_limit;
 @@session.sql_select_limit = @save_select_limit
 1
diff --git a/mysql-test/suite/rpl/r/rpl_temporary_errors.result b/mysql-test/suite/rpl/r/rpl_temporary_errors.result
index d14380a6369569a6ce1717f519b87dc8137f2f9c..f4626304fc399c432be1a0bffcccaa9d1679bc96 100644
--- a/mysql-test/suite/rpl/r/rpl_temporary_errors.result
+++ b/mysql-test/suite/rpl/r/rpl_temporary_errors.result
@@ -79,6 +79,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 DROP TABLE t1;
 **** On Master ****
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl/t/rpl000017.test b/mysql-test/suite/rpl/t/rpl000017.test
index 2ba321cd8c3074301a4d0a32f4e020f0c8ac4f9e..d6b3e46fa319c328a9c024c74f7511da1c2fa273 100644
--- a/mysql-test/suite/rpl/t/rpl000017.test
+++ b/mysql-test/suite/rpl/t/rpl000017.test
@@ -6,6 +6,7 @@ grant replication slave on *.* to replicate@localhost identified by 'aaaaaaaaaaa
 grant replication slave on *.* to replicate@127.0.0.1 identified by 'aaaaaaaaaaaaaaab';
 connection slave;
 start slave;
+source include/wait_for_slave_to_start.inc;
 connection master;
 --disable_warnings
 drop table if exists t1;
diff --git a/mysql-test/suite/rpl/t/rpl_binlog_grant.test b/mysql-test/suite/rpl/t/rpl_binlog_grant.test
index 31163927ce2b4d609eb12051a07b48f888052bed..da14b45d5c3de07357f035a3e6f9b5832c687e99 100644
--- a/mysql-test/suite/rpl/t/rpl_binlog_grant.test
+++ b/mysql-test/suite/rpl/t/rpl_binlog_grant.test
@@ -25,9 +25,7 @@ grant select on t to x@y;
 #
 rollback;
 show grants for x@y;
---replace_result $VERSION VERSION
---replace_regex /\/\* xid=.* \*\//\/* XID *\//
-show binlog events;
+source include/show_binlog_events.inc;
 start transaction;
 insert into t values (2);
 revoke select on t from x@y;
@@ -37,9 +35,7 @@ revoke select on t from x@y;
 commit;
 select * from t;
 show grants for x@y;
---replace_result $VERSION VERSION
---replace_regex /\/\* xid=.* \*\//\/* XID *\//
-show binlog events;
+source include/show_binlog_events.inc;
 drop user x@y;
 drop database d1;
 --sync_slave_with_master
diff --git a/mysql-test/suite/rpl/t/rpl_change_master.test b/mysql-test/suite/rpl/t/rpl_change_master.test
index d0cd40e2e11e0afd4224259eed2a3e4dd63a6b09..c1ef417ea7899c913dd05f15c16cc21173f29e73 100644
--- a/mysql-test/suite/rpl/t/rpl_change_master.test
+++ b/mysql-test/suite/rpl/t/rpl_change_master.test
@@ -33,3 +33,56 @@ connection slave;
 sync_with_master;
 
 # End of 4.1 tests
+
+#
+# BUG#12190 CHANGE MASTER has differ path requiremts on MASTER_LOG_FILE and RELAY_LOG_FILE
+#
+
+source include/master-slave-reset.inc;
+
+connection master;
+create table t1 (a int);
+insert into t1 values (1);
+flush logs;
+insert into t1 values (2);
+
+# Note: the master positon saved by this will also be used by the
+# 'sync_with_master' below.
+sync_slave_with_master;
+
+# Check if the table t1 and t2 are identical on master and slave;
+let $diff_table_1= master:test.t1
+let $diff_table_2= slave:test.t1
+source include/diff_tables.inc;
+
+connection slave;
+source include/stop_slave.inc;
+delete from t1 where a=2;
+
+# start replication from the second insert, after fix of BUG#12190,
+# relay_log_file does not use absolute path, only the filename is
+# required
+#
+# Note: the follow change master will automatically reset
+# relay_log_purge to false, save the old value to restore
+let $relay_log_purge= `select @@global.relay_log_purge`;
+CHANGE MASTER TO relay_log_file='slave-relay-bin.000005', relay_log_pos=4;
+start slave sql_thread;
+source include/wait_for_slave_sql_to_start.inc;
+
+# Sync to the same position saved by the 'sync_slave_with_master' above.
+sync_with_master;
+
+# Check if the table t1 and t2 are identical on master and slave;
+let $diff_table_1= master:test.t1
+let $diff_table_2= slave:test.t1
+source include/diff_tables.inc;
+
+# clean up
+connection slave;
+start slave io_thread;
+source include/wait_for_slave_io_to_start.inc;
+eval set global relay_log_purge=$relay_log_purge;
+connection master;
+drop table t1;
+sync_slave_with_master;
diff --git a/mysql-test/suite/rpl/t/rpl_empty_master_host.test b/mysql-test/suite/rpl/t/rpl_empty_master_host.test
new file mode 100644
index 0000000000000000000000000000000000000000..7d245b1d5d5478e68643848ed6cef55980fb0d35
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_empty_master_host.test
@@ -0,0 +1,51 @@
+# 
+# BUG
+# ---
+#   BUG#28796: CHANGE MASTER TO MASTER_HOST="" leads to invalid master.info
+#
+# Description
+# -----------
+#
+#   This test aims at: 
+#     i) verifying that an error is thrown when setting MASTER_HOST=''
+#     ii) no error is thrown when setting non empty MASTER_HOST
+#     iii) replication works after setting a correct host name/ip
+#
+#   Implementation is performed by feeding different values (according
+#   to i), ii) and iii) ) to CHANGE MASTER TO MASTER_HOST= x and checking
+#   along the way if error/no error is thrown and/or if replication starts
+#   working when expected.
+
+--source include/master-slave.inc
+
+connection slave;
+STOP SLAVE;
+--source include/wait_for_slave_to_stop.inc
+
+let $master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1);
+--echo Master_Host = '$master_host' (expected '127.0.0.1')
+
+# attempt to change to an empty master host should 
+# result in error ER_WRONG_ARGUMENTS: "Incorrect arguments to ..."
+error ER_WRONG_ARGUMENTS;
+CHANGE MASTER TO MASTER_HOST="";
+
+# show slave status still holds previous information
+let $master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1);
+--echo Master_Host = '$master_host' (expected '127.0.0.1')
+
+# changing master to other than empty master host succeeds
+CHANGE MASTER TO MASTER_HOST="foo";
+
+# show slave status should hold "foo" as master host
+let $master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1);
+--echo Master_Host = '$master_host' (expected 'foo')
+
+# changing back to localhost
+CHANGE MASTER TO MASTER_HOST="127.0.0.1";
+let $master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1);
+--echo Master_Host = '$master_host' (expected '127.0.0.1')
+
+# start slave must succeed.
+START SLAVE;
+--source include/wait_for_slave_to_start.inc
diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat.test b/mysql-test/suite/rpl/t/rpl_heartbeat.test
new file mode 100644
index 0000000000000000000000000000000000000000..3b0d21052ee8226176f56526c8c99616a04f3682
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat.test
@@ -0,0 +1,168 @@
+# Testing master to slave heartbeat protocol
+# 
+# Including:
+# - user interface, grammar, checking the range and warnings about 
+#   unreasonable values for the heartbeat period;
+# - no rotation of relay log if heartbeat is less that slave_net_timeout
+# - SHOW STATUS like 'Slave_received_heartbeats' action
+# - SHOW STATUS like 'Slave_heartbeat_period' report
+
+-- source include/have_log_bin.inc
+
+connect (master,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+connect (slave,localhost,root,,test,$SLAVE_MYPORT,$SLAVE_MYSOCK);
+
+connection master;
+reset master;
+
+connection slave;
+set @restore_slave_net_timeout= @@global.slave_net_timeout;
+set @@global.slave_net_timeout= 10;
+
+###
+### Checking the range
+###
+
+#
+# default period slave_net_timeout/2
+#
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
+--query_vertical show status like 'Slave_heartbeat_period';
+
+#
+# the max for the period is ULONG_MAX/1000; an attempt to exceed it is  denied
+#
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4294968;
+--query_vertical show status like 'Slave_heartbeat_period';
+
+#
+# the min value for the period is 1 millisecond an attempt to assign a
+# lesser will be warned with treating the value as zero
+#
+connection slave;
+--replace_result $MASTER_MYPORT MASTER_PORT
+### 5.1 mtr does not have --warning ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.0009999;
+--query_vertical show status like 'Slave_heartbeat_period';
+
+#
+# the actual max and min must be accepted
+#
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4294967;
+--query_vertical show status like 'Slave_heartbeat_period';
+
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.001;
+--query_vertical show status like 'Slave_heartbeat_period';
+
+reset slave;
+
+#
+# A warning if period greater than slave_net_timeout
+#
+set @@global.slave_net_timeout= 5;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 5.001;
+--query_vertical show status like 'Slave_heartbeat_period';
+
+reset slave;
+
+#
+# A warning if slave_net_timeout is set to less than the current HB period
+#
+set @@global.slave_net_timeout= 5;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 4;
+--query_vertical show status like 'Slave_heartbeat_period';
+set @@global.slave_net_timeout= 3 /* must be a warning */;
+
+reset slave;
+
+
+###
+### checking no rotation
+###
+
+connection master;
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+#
+# Even though master_heartbeat_period= 0.5 is 20 times less than
+# @@global.slave_net_timeout= 10 in some circumstances master will
+# not be able to send any heartbeat during the slave's net timeout
+# and slave's relay log will rotate.
+# The probability for such a scenario is pretty small so the following
+# part is almost deterministic.
+#
+
+connection slave;
+set @@global.slave_net_timeout= 10;
+--replace_result $MASTER_MYPORT MASTER_PORT
+# no error this time but rather a warning
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root', master_heartbeat_period= 0.5;
+--query_vertical show status like 'Slave_heartbeat_period';
+
+start slave;
+
+connection master;
+create table t1 (f1 int);
+
+#connection slave;
+sync_slave_with_master;
+source include/show_slave_status.inc;
+
+# there is an explicit sleep lasting longer than slave_net_timeout
+# to ensure that nothing will come to slave from master for that period.
+# That would cause reconnecting and relaylog rotation w/o the fix i.e
+# without a heartbeat received.
+
+real_sleep 15;
+
+# check (compare with the previous show's results) that no rotation happened
+source include/show_slave_status.inc;
+
+###
+### SHOW STATUS like 'Slave_heartbeat_period' and 'Slave_received_heartbeats'
+###
+
+--query_vertical show status like 'Slave_heartbeat_period';
+
+#
+# proof that there has been received at least one heartbeat;
+# The exact number of received heartbeat is an indeterministic value
+# and therefore it's not recorded into results.
+#
+
+let $slave_wait_param_counter= 300;
+let $slave_value= query_get_value("SHOW STATUS like 'Slave_received_heartbeats'", Value, 1);
+# Checking the fact that at least one heartbeat is received
+while (`select $slave_value = 0`)
+{
+  dec $slave_wait_param_counter;
+  if (!$slave_wait_param_counter)
+  {
+    --echo ERROR: failed while waiting for slave parameter $slave_param: $slave_param_value
+    query_vertical show slave status;
+    SHOW STATUS like 'Slave_received_heartbeats';
+    exit;
+  }
+  sleep 0.1;
+  let $slave_value= query_get_value("SHOW STATUS like 'Slave_received_heartbeats'", Value, 1);
+}
+--echo A heartbeat has been received by the slave
+# cleanup
+
+connection master;
+drop table t1;
+
+#connection slave;
+sync_slave_with_master;
+set @@global.slave_net_timeout= @restore_slave_net_timeout;
+
+
+--echo End of tests
diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat_2slaves.cnf b/mysql-test/suite/rpl/t/rpl_heartbeat_2slaves.cnf
new file mode 100644
index 0000000000000000000000000000000000000000..a3ed77c8bd28625ae43ab0c7abc3f6879b8c8993
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_2slaves.cnf
@@ -0,0 +1,17 @@
+!include ../my.cnf
+
+[mysqld.1]
+server_id=1
+
+[mysqld.2]
+server_id=2
+
+[mysqld.3]
+server_id=3
+
+[ENV]
+SLAVE_MYPORT1=		@mysqld.3.port
+SLAVE_MYSOCK1=		@mysqld.3.socket
+
+
+
diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat_2slaves.test b/mysql-test/suite/rpl/t/rpl_heartbeat_2slaves.test
new file mode 100644
index 0000000000000000000000000000000000000000..81737feea9ecc861b758811e9219e7fdb5f33adc
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_2slaves.test
@@ -0,0 +1,142 @@
+#############################################################
+# Author: Serge Kozlov <Serge.Kozlov@Sun.COM>
+# Date:   02/19/2009
+# Purpose: Testing heartbeat for schema
+# 1 master and 2 slaves
+#############################################################
+--source include/master-slave.inc
+--echo
+
+--echo *** Preparing ***
+--connection master
+let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+--connection slave
+--echo [on slave]
+--source include/stop_slave.inc
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT $binlog_file MASTER_BINLOG
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1, MASTER_LOG_FILE='$binlog_file';
+--source include/start_slave.inc
+--disconnect slave1
+--connect(slave1,127.0.0.1,root,,test,$SLAVE_MYPORT1,)
+--connection slave1
+--echo [on slave1]
+--disable_warnings
+STOP SLAVE;
+--enable_warnings
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT $binlog_file MASTER_BINLOG
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=1, MASTER_LOG_FILE='$binlog_file';
+--source include/start_slave.inc
+--echo
+
+#
+# Testing heartbeat
+#
+
+# Check that heartbeat events sent to both slaves with correct periods
+--echo *** 2 slaves ***
+--connection slave
+let $status_var= slave_received_heartbeats;
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Slave has received heartbeat event
+--connection slave1
+let $status_var= slave_received_heartbeats;
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+let $slave1_rcvd_heartbeats= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--echo Slave1 has received heartbeat event
+--connection slave
+let $slave_rcvd_heartbeats= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($slave_rcvd_heartbeats DIV $slave1_rcvd_heartbeats) > 1 AS Result, Result, 1);
+--echo Slave has received more heartbeats than Slave1 (1 means 'yes'): $result
+--echo
+
+
+# Create topology A->B->C and check that C receives heartbeat while B gets data
+# Slave1 (B) started w/o --log-slave-updates because B should not send data from A to C
+--echo *** Master->data->Slave1->heartbeat->Slave: ***
+--connection slave1
+--echo [on slave1]
+RESET MASTER;
+let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1);
+--connection slave
+--echo [on slave]
+--source include/stop_slave.inc
+RESET SLAVE;
+--replace_result $SLAVE_MYPORT1 SLAVE1_PORT $binlog_file SLAVE1_BINLOG
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SLAVE_MYPORT1, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.2, MASTER_LOG_FILE='$binlog_file';
+--source include/start_slave.inc
+# Check heartbeat for new replication channel slave1->slave
+let $status_var= slave_received_heartbeats;
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Slave has received heartbeat event
+--connection master
+--echo [on master]
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10), c LONGTEXT);
+INSERT INTO t1 VALUES (1, 'on master', '');
+--save_master_pos
+SHOW TABLES;
+--connection slave1
+--sync_with_master 0
+--echo [on slave1]
+SHOW TABLES;
+let $slave_pos_before= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1);
+--save_master_pos
+--connection slave
+--sync_with_master 0
+--echo [on slave]
+SHOW TABLES;
+--connection master
+--echo [on master]
+--echo creating updates on master and send to slave1 during 5 second
+# Generate events on master and send to slave1 during 5 second
+let $i= 1;
+let $j= 1;
+let $k= 1;
+--disable_query_log
+while ($i) {
+  eval SET @c_text=REPEAT('1234567890', $j);
+  eval UPDATE t1 SET a=$j, c=@c_text;
+  --connection slave1
+  let $slave_pos= query_get_value(SHOW SLAVE STATUS, Read_Master_Log_Pos, 1);  
+  if (`SELECT ($k*($slave_pos - $slave_pos_before)) > 0`) {
+    --connection slave
+    let $slave_rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);    
+    let $k= 0;
+    let $time_before = `SELECT NOW()`;
+  }
+  if (`SELECT ((1-$k)*TIMESTAMPDIFF(SECOND,'$time_before',NOW())) > 5`) {
+    --connection slave
+    let $slave_rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);    
+    let $i= 0;
+  }
+  --connection master
+  inc $j;
+  sleep 0.1;
+}
+--enable_query_log
+--connection slave
+--echo [on slave]
+let $result= query_get_value(SELECT ($slave_rcvd_heartbeats_after - $slave_rcvd_heartbeats_before) > 0 AS Result, Result, 1);
+--echo Slave has received heartbeats (1 means 'yes'): $result
+--echo
+
+#
+# Clean up
+#
+--echo *** Clean up ***
+--connection master
+DROP TABLE t1;
+--save_master_pos
+--connection slave1
+--sync_with_master 0
+--echo
+
+# End of 6.0 test
+--echo End of 6.0 test
diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat_basic.cnf b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.cnf
new file mode 100644
index 0000000000000000000000000000000000000000..a4a291bca7919107f7e89f9d2aae38faa5201ca4
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.cnf
@@ -0,0 +1,7 @@
+!include ../my.cnf
+
+[mysqld.1]
+log-slave-updates
+
+[mysqld.2]
+log-slave-updates
diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test
new file mode 100644
index 0000000000000000000000000000000000000000..10d327eece0e9215407ce7fde14eba14f9807cb1
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test
@@ -0,0 +1,541 @@
+#############################################################
+# Author: Serge Kozlov <Serge.Kozlov@Sun.COM>
+# Date:   02/19/2009
+# Purpose: Testing basic functionality of heartbeat.
+# Description:
+# * Testing different values for slave_heartbeat_period.
+# * How to affect various statements to slave_heartbeat_period
+# * Various states of slave and heartbeat
+# * Various states of master and heartbeat
+# * Circular replication
+#############################################################
+--source include/master-slave.inc
+--echo
+
+--echo *** Preparing ***
+--connection slave
+--source include/stop_slave.inc
+RESET SLAVE;
+SET @restore_slave_net_timeout=@@global.slave_net_timeout;
+let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
+--disable_query_log
+eval SET @restore_slave_heartbeat_timeout=$slave_heartbeat_timeout;
+--enable_query_log
+
+--connection master
+RESET MASTER;
+SET @restore_slave_net_timeout=@@global.slave_net_timeout;
+SET @restore_event_scheduler=@@global.event_scheduler;
+--echo
+
+#
+# Test slave_heartbeat_period
+#
+
+--connection slave
+
+# Default value of slave_heartbeat_timeout = slave_net_timeout/2
+--echo *** Default value ***
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root';
+let $slave_net_timeout= query_get_value(SHOW VARIABLES LIKE 'slave_net_timeout', Value, 1);
+let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
+let $result= query_get_value(SELECT $slave_net_timeout/$slave_heartbeat_timeout AS Result, Result, 1);
+--echo slave_net_timeout/slave_heartbeat_timeout=$result
+RESET SLAVE;
+--echo
+
+# Reset slave set slave_heartbeat_timeout = slave_net_timeout/2
+--echo *** Reset slave affect ***
+--disable_warnings
+SET @@global.slave_net_timeout=30;
+--enable_warnings
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=5;
+RESET SLAVE;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+--echo
+
+# Check default value of slave_heartbeat_timeout if slave_net_timeout is changed
+--echo *** Default value if slave_net_timeout changed ***
+--disable_warnings
+SET @@global.slave_net_timeout=50;
+--enable_warnings
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root';
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+RESET SLAVE;
+--echo
+
+# Set slave_net_timeout less than current value of slave_heartbeat_period
+--echo *** Warning if updated slave_net_timeout < slave_heartbeat_timeout ***
+let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
+--replace_result $slave_heartbeat_timeout SLAVE_HEARTBEAT_TIMEOUT
+eval SET @@global.slave_net_timeout=FLOOR($slave_heartbeat_timeout)-1;
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+RESET SLAVE;
+--echo
+
+# Set value of slave_heartbeat_period greater than slave_net_timeout
+--echo *** Warning if updated slave_heartbeat_timeout > slave_net_timeout ***
+let $slave_net_timeout= query_get_value(SHOW VARIABLES LIKE 'slave_net_timeout', Value, 1);
+inc $slave_net_timeout;
+--replace_result $MASTER_MYPORT MASTER_PORT $slave_net_timeout SLAVE_NET_TIMEOUT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=$slave_net_timeout;
+RESET SLAVE;
+--echo 
+
+# Changing of slave_net_timeout shouldn't affect to current value of slave_heartbeat_period
+--echo *** CHANGE MASTER statement only updates slave_heartbeat_period ***
+--disable_warnings
+SET @@global.slave_net_timeout=20;
+--enable_warnings
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=5;
+SHOW VARIABLES LIKE 'slave_net_timeout';
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SET @@global.slave_net_timeout=2*@@global.slave_net_timeout;
+SHOW VARIABLES LIKE 'slave_net_timeout';
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+RESET SLAVE;
+--echo
+
+# Master value of slave_net_timeout shouldn't affect to slave's slave_heartbeat_period
+--echo *** Update slave_net_timeout on master ***
+--connection master
+--disable_warnings
+SET @@global.slave_net_timeout=500;
+--enable_warnings
+--connection slave
+SET @@global.slave_net_timeout=200;
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root';
+--source include/start_slave.inc
+--sync_with_master
+SHOW VARIABLES LIKE 'slave_net_timeout';
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+--source include/stop_slave.inc
+RESET SLAVE;
+--connection master
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+--echo
+
+# Start/stop slave shouldn't change slave_heartbeat_period
+--echo *** Start/stop slave ***
+--connection slave
+--disable_warnings
+SET @@global.slave_net_timeout=100;
+--enable_warnings
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=20;
+--source include/start_slave.inc
+--sync_with_master
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+--source include/stop_slave.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+--echo
+
+# Reload slave shouldn't change slave_heartbeat_period
+--echo *** Reload slave ***
+--connection slave
+--disable_warnings
+SET @@global.slave_net_timeout=50;
+--enable_warnings
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=30;
+--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
+wait
+EOF
+--echo Reload slave
+--shutdown_server 10
+--source include/wait_until_disconnected.inc
+--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
+restart
+EOF
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SET @restore_slave_net_timeout=@@global.slave_net_timeout;
+--echo
+
+# Disable heartbeat
+--echo *** Disable heartbeat ***
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SHOW STATUS LIKE 'slave_received_heartbeats';
+--source include/start_slave.inc
+--sync_with_master
+--sleep 2
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SHOW STATUS LIKE 'slave_received_heartbeats';
+--source include/stop_slave.inc
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+SHOW STATUS LIKE 'slave_received_heartbeats';
+RESET SLAVE;
+let $slave_heartbeat_timeout= query_get_value(SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period', Value, 1);
+--replace_result $slave_heartbeat_timeout SLAVE_HEARTBEAT_TIMEOUT
+--eval SELECT $slave_heartbeat_timeout = 0 AS Result
+--echo 
+
+#
+# Check limits for slave_heartbeat_timeout
+#
+
+--echo *** Min slave_heartbeat_timeout ***
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.001;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.0009;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+RESET SLAVE;
+--echo
+
+--echo *** Max slave_heartbeat_timeout ***
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294967;
+SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period';
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE 
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294968;
+RESET SLAVE;
+# Check double size of max allowed value for master_heartbeat_period
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE 
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=8589935;
+RESET SLAVE;
+# Check 2^32
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE 
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294967296;
+RESET SLAVE;
+--echo
+
+--echo *** Misc incorrect values ***
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_PARSE_ERROR
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD='-1';
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_PARSE_ERROR
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD='123abc';
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+--error ER_PARSE_ERROR
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD='';
+RESET SLAVE;
+--echo
+
+#
+# Testing heartbeat 
+#
+
+# Check received heartbeat events for running slave
+--echo *** Running slave ***
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+--source include/start_slave.inc
+--sync_with_master
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var= slave_received_heartbeats;
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+--echo
+
+# Check received heartbeat events for stopped slave
+--echo *** Stopped slave ***
+--source include/stop_slave.inc
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+sleep 2;
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) AS Result, Result, 1);
+--echo Number of received heartbeat events while slave stopped: $result
+--echo
+
+# Check received heartbeat events for started slave
+--echo *** Started slave ***
+--source include/start_slave.inc
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+--echo
+
+# Check received heartbeat events for stopped IO thread
+--echo *** Stopped IO thread ***
+STOP SLAVE IO_THREAD;
+--source include/wait_for_slave_io_to_stop.inc
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+sleep 2;
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) AS Result, Result, 1);
+--echo Number of received heartbeat events while io thread stopped: $result
+--echo
+
+# Check received heartbeat events for started IO thread
+--echo *** Started IO thread ***
+START SLAVE IO_THREAD;
+--source include/wait_for_slave_io_to_start.inc
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+--echo
+
+# Check received heartbeat events for stopped SQL thread
+--echo *** Stopped SQL thread ***
+STOP SLAVE SQL_THREAD;
+--source include/wait_for_slave_sql_to_stop.inc
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+sleep 2;
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
+--echo Heartbeat events are received while sql thread stopped (1 means 'yes'): $result
+--echo
+
+# Check received heartbeat events for started SQL thread
+--echo *** Started SQL thread ***
+START SLAVE SQL_THREAD;
+--source include/wait_for_slave_sql_to_start.inc
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+--echo
+
+# Check received heartbeat event for stopped SQL thread by error
+--echo *** Stopped SQL thread by error ***
+--connection master
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10), c LONGTEXT);
+--sync_slave_with_master
+INSERT INTO t1 VALUES (1, 'on slave', NULL);
+--connection master
+INSERT INTO t1 VALUES (1, 'on master', NULL);
+--connection slave
+let $slave_errno= ER_DUP_ENTRY
+--source include/wait_for_slave_sql_error.inc
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+sleep 2;
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
+--echo Heartbeat events are received while sql thread stopped (1 means 'yes'): $result
+--source include/stop_slave.inc
+DROP TABLE t1;
+--echo
+
+# Check received heartbeat events while master send events to slave
+--echo *** Master send to slave ***
+--connection master
+# Create the event that will update table t1 every second
+DELIMITER |;
+CREATE EVENT e1 
+  ON SCHEDULE EVERY 1 SECOND
+  DO
+    BEGIN
+      UPDATE test.t1 SET a = a + 1 WHERE a < 10;
+    END|
+DELIMITER ;|
+--connection slave
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=5;
+--source include/start_slave.inc
+--connection master
+# Enable scheduler
+SET @@global.event_scheduler=1;
+--connection slave
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--sync_with_master
+# Wait some updates for table t1 from master
+let $wait_condition= SELECT COUNT(*)=1 FROM t1 WHERE a > 5;
+--source include/wait_condition.inc
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
+--echo Number of received heartbeat events: $result
+--connection master
+DELETE FROM t1;
+DROP EVENT e1;
+--echo
+
+
+
+
+# Check received heartbeat events while logs flushed on slave
+--connection slave
+--echo *** Flush logs on slave ***
+STOP SLAVE;
+RESET SLAVE;
+DROP TABLE t1;
+--connection master
+DROP TABLE t1;
+RESET MASTER;
+--connection slave
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.5;
+let $slave_param_comparison= =;
+--source include/start_slave.inc
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+# Flush logs every 0.1 second during 5 sec
+--disable_query_log
+let $i=50;
+while ($i) {
+  FLUSH LOGS;
+  dec $i;
+  sleep 0.1;
+}
+--enable_query_log
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
+--echo Heartbeat events are received while rotation of relay logs (1 means 'yes'): $result
+--echo
+
+# Use compressed protocol between master and slave
+--echo *** Compressed protocol ***
+--connection master
+SET @@global.slave_compressed_protocol=1;
+--connection slave
+--source include/stop_slave.inc
+RESET SLAVE;
+SET @@global.slave_compressed_protocol=1;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+--source include/start_slave.inc
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var= slave_received_heartbeats;
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+SET @@global.slave_compressed_protocol=0;
+--connection master
+SET @@global.slave_compressed_protocol=0;
+--echo
+
+
+# Check received heartbeat events after reset of master
+--echo *** Reset master ***
+--connection slave
+STOP SLAVE;
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+--source include/start_slave.inc
+let $rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--connection master
+RESET MASTER;
+--enable_query_log
+--sync_slave_with_master
+--sleep 2
+let $rcvd_heartbeats_after= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $result= query_get_value(SELECT ($rcvd_heartbeats_after - $rcvd_heartbeats_before) > 0 AS Result, Result, 1);
+--echo Heartbeat events are received after reset of master (1 means 'yes'): $result
+--echo
+
+# Reloaded master should restore heartbeat
+--echo *** Reload master ***
+--connection slave
+STOP SLAVE;
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1;
+--source include/start_slave.inc
+# Wait until slave_received_heartbeats will be incremented
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var= slave_received_heartbeats;
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+--connection master
+--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+wait
+EOF
+--echo Reload master
+--shutdown_server 10
+--source include/wait_until_disconnected.inc
+--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
+restart
+EOF
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+--connection slave
+# Wait until slave_received_heartbeats will be incremented
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var= slave_received_heartbeats;
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received
+--echo
+
+# Circular replication
+--echo *** Circular replication ***
+# Configure circular replication
+--connection master
+RESET MASTER;
+let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
+CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(10));
+--sync_slave_with_master
+--source include/stop_slave.inc
+RESET MASTER;
+let $slave_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
+RESET SLAVE;
+--replace_result $MASTER_MYPORT MASTER_PORT $master_binlog MASTER_BINLOG
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.1, MASTER_LOG_FILE='$master_binlog';
+--connection master
+RESET SLAVE;
+--replace_result $SLAVE_MYPORT SLAVE_PORT $slave_binlog SLAVE_BINLOG
+eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SLAVE_MYPORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=1, MASTER_LOG_FILE='$slave_binlog';
+--source include/start_slave.inc
+# Insert data on master and on slave and make sure that it replicated for both directions
+INSERT INTO t1 VALUES(1, 'on master');
+--save_master_pos
+--connection slave
+--source include/start_slave.inc
+--sync_with_master
+INSERT INTO t1 VALUES(2, 'on slave');
+--save_master_pos
+--connection master
+--sync_with_master
+SELECT * FROM t1 ORDER BY a;
+let $master_rcvd_heartbeats_before= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+--connection slave
+SELECT * FROM t1 ORDER BY a;
+# Wait heartbeat event on master
+--connection master
+let $status_var= slave_received_heartbeats;
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received on master
+let $master_rcvd_heartbeats= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+# Wait heartbeat event on slave
+--connection slave
+let $status_var= slave_received_heartbeats;
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event received on slave
+let $slave_rcvd_heartbeats= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+# Heartbeat period on slave less than on master therefore number of received events on slave
+# should be greater than on master
+let $result= query_get_value(SELECT ($slave_rcvd_heartbeats DIV $master_rcvd_heartbeats) > 1 AS Result, Result, 1);
+--echo Slave has received more events than master (1 means 'yes'): $result
+--echo
+
+#
+# Clean up and restore system variables
+#
+--echo *** Clean up ***
+--connection master
+--source include/stop_slave.inc
+DROP TABLE t1;
+--sync_slave_with_master
+--source include/stop_slave.inc
+SET @@global.slave_net_timeout=@restore_slave_net_timeout;
+--echo
+
+# End of 6.0 test
+--echo End of 6.0 test
diff --git a/mysql-test/suite/rpl/t/rpl_heartbeat_ssl.test b/mysql-test/suite/rpl/t/rpl_heartbeat_ssl.test
new file mode 100644
index 0000000000000000000000000000000000000000..6460b157b52229d7462d411fd8107f1d0ea26ca9
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_ssl.test
@@ -0,0 +1,54 @@
+#############################################################
+# Author: Serge Kozlov <Serge.Kozlov@Sun.COM>
+# Date:   02/19/2009
+# Purpose: Testing basic functionality of heartbeat over SSL
+#############################################################
+--source include/have_ssl_communication.inc
+--source include/master-slave.inc
+--echo
+
+#
+# Testing heartbeat over SSL
+#
+
+# Heartbeat over SSL 
+--echo *** Heartbeat over SSL ***
+--connection master
+let $master_binlog= query_get_value(SHOW MASTER STATUS, File, 1);
+--connection slave
+--source include/stop_slave.inc
+RESET SLAVE;
+# Connect to master with SSL
+--replace_result $MASTER_MYPORT MASTER_PORT $MYSQL_TEST_DIR MYSQL_TEST_DIR $master_binlog MASTER_BINLOG
+eval CHANGE MASTER TO 
+    MASTER_HOST='127.0.0.1',
+    MASTER_PORT=$MASTER_MYPORT,
+    MASTER_USER='root',
+    MASTER_HEARTBEAT_PERIOD=0.1,
+    MASTER_LOG_FILE='$master_binlog',
+    MASTER_SSL=1,
+    MASTER_SSL_CA='$MYSQL_TEST_DIR/std_data/cacert.pem',
+    MASTER_SSL_CERT='$MYSQL_TEST_DIR/std_data/client-cert.pem',
+    MASTER_SSL_KEY='$MYSQL_TEST_DIR/std_data/client-key.pem';
+--source include/start_slave.inc
+# Check SSL state of slave
+let $slave_ssl_status= query_get_value(SHOW SLAVE STATUS, Master_SSL_Allowed, 1);
+--echo Master_SSL_Allowed: $slave_ssl_status
+# Wait until hearbeat event will received
+let $status_var_value= query_get_value(SHOW STATUS LIKE 'slave_received_heartbeats', Value, 1);
+let $status_var= slave_received_heartbeats;
+let $status_var_comparsion= >;
+--source include/wait_for_status_var.inc
+--echo Heartbeat event has received
+--echo
+
+#
+# Clean up
+#
+--echo *** Clean up ***
+--connection master
+--sync_slave_with_master
+--echo
+
+# End of 6.0 test
+--echo End of 6.0 test
diff --git a/mysql-test/suite/rpl/t/rpl_not_null_innodb.test b/mysql-test/suite/rpl/t/rpl_not_null_innodb.test
new file mode 100644
index 0000000000000000000000000000000000000000..dca0ea6589ca35240ff6855529ffc86f9f61d8ec
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_not_null_innodb.test
@@ -0,0 +1,19 @@
+#################################################################################
+# This test checks if the replication between "null" fields to either "null"
+# fields or "not null" fields works properly. In the first case, the execution
+# should work fine. In the second case, it may fail according to the sql_mode
+# being used.
+#
+# The test is devided in three main parts:
+#
+# 1 - NULL --> NULL (no failures)
+# 2 - NULL --> NOT NULL ( sql-mode  = STRICT and failures)
+# 3 - NULL --> NOT NULL ( sql-mode != STRICT and no failures)
+#
+#################################################################################
+--source include/master-slave.inc
+--source include/have_innodb.inc
+--source include/have_binlog_format_row.inc
+
+let $engine=Innodb;
+--source extra/rpl_tests/rpl_not_null.test
diff --git a/mysql-test/suite/rpl/t/rpl_not_null_myisam.test b/mysql-test/suite/rpl/t/rpl_not_null_myisam.test
new file mode 100644
index 0000000000000000000000000000000000000000..0c036f5bfd73588c49b6934b708a38a77f203b11
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_not_null_myisam.test
@@ -0,0 +1,18 @@
+#################################################################################
+# This test checks if the replication between "null" fields to either "null"
+# fields or "not null" fields works properly. In the first case, the execution
+# should work fine. In the second case, it may fail according to the sql_mode
+# being used.
+#
+# The test is devided in three main parts:
+#
+# 1 - NULL --> NULL (no failures)
+# 2 - NULL --> NOT NULL ( sql-mode  = STRICT and failures)
+# 3 - NULL --> NOT NULL ( sql-mode != STRICT and no failures)
+#
+#################################################################################
+--source include/master-slave.inc
+--source include/have_binlog_format_row.inc
+
+let $engine=MyISAM;
+--source extra/rpl_tests/rpl_not_null.test
diff --git a/mysql-test/suite/rpl/t/rpl_row_create_table.test b/mysql-test/suite/rpl/t/rpl_row_create_table.test
index 319f9546a819ed50b4506bca0664cacf2be2ae00..0d91d855a57f7e455122f5f3b4da8c81ebf72b04 100644
--- a/mysql-test/suite/rpl/t/rpl_row_create_table.test
+++ b/mysql-test/suite/rpl/t/rpl_row_create_table.test
@@ -38,7 +38,7 @@ CREATE TABLE t3 (a INT, b INT) CHARSET=utf8;
 CREATE TABLE t4 (a INT, b INT) ENGINE=Merge CHARSET=utf8;
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
---query_vertical SHOW BINLOG EVENTS FROM 106
+--query_vertical SHOW BINLOG EVENTS FROM 107
 --echo **** On Master ****
 --query_vertical SHOW CREATE TABLE t1
 --query_vertical SHOW CREATE TABLE t2
@@ -76,7 +76,7 @@ CREATE TABLE t7 (UNIQUE(b)) SELECT a,b FROM tt3;
 # Shouldn't be written to the binary log
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 
 # Test that INSERT-SELECT works the same way as for SBR.
 CREATE TABLE t7 (a INT, b INT UNIQUE);
@@ -86,7 +86,7 @@ SELECT * FROM t7 ORDER BY a,b;
 # Should be written to the binary log
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 sync_slave_with_master;
 SELECT * FROM t7 ORDER BY a,b;
 
@@ -100,7 +100,7 @@ INSERT INTO t7 SELECT a,b FROM tt4;
 ROLLBACK;
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 SELECT * FROM t7 ORDER BY a,b;
 sync_slave_with_master;
 SELECT * FROM t7 ORDER BY a,b;
@@ -118,7 +118,7 @@ CREATE TEMPORARY TABLE tt7 SELECT 1;
 --query_vertical SHOW CREATE TABLE t9
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 sync_slave_with_master;
 --echo **** On Slave ****
 --query_vertical SHOW CREATE TABLE t8
@@ -170,7 +170,7 @@ SELECT * FROM t3 ORDER BY a;
 SELECT * FROM t4 ORDER BY a;
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 sync_slave_with_master;
 SHOW TABLES;
 SELECT   TABLE_NAME,ENGINE
@@ -216,7 +216,7 @@ COMMIT;
 SELECT * FROM t2 ORDER BY a;
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 sync_slave_with_master;
 SELECT * FROM t2 ORDER BY a;
 
@@ -239,7 +239,7 @@ ROLLBACK;
 SELECT * FROM t2 ORDER BY a;
 --replace_column 1 # 4 #
 --replace_regex /\/\* xid=.* \*\//\/* XID *\// /Server ver: .*, Binlog ver: .*/Server ver: #, Binlog ver: #/ /table_id: [0-9]+/table_id: #/
-SHOW BINLOG EVENTS FROM 106;
+SHOW BINLOG EVENTS FROM 107;
 sync_slave_with_master;
 SELECT * FROM t2 ORDER BY a;
 
diff --git a/mysql-test/suite/rpl/t/rpl_row_flsh_tbls.test b/mysql-test/suite/rpl/t/rpl_row_flsh_tbls.test
index 667e1d9a1a807327175f4dece1f2853ef739f15f..d2996bbe525231e043bb4e0759f1f751a7e81d6a 100644
--- a/mysql-test/suite/rpl/t/rpl_row_flsh_tbls.test
+++ b/mysql-test/suite/rpl/t/rpl_row_flsh_tbls.test
@@ -1,7 +1,7 @@
 # depends on the binlog output
 -- source include/have_binlog_format_row.inc
 
-let $rename_event_pos= 897;
+let $rename_event_pos= 898;
 
 # Bug#18326: Do not lock table for writing during prepare of statement
 # The use of the ps protocol causes extra table maps in the binlog, so
diff --git a/mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test b/mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test
index 3328d582692aef78f8336f391dbb4ac1fe923407..a7967f6643a9b75166638552e73ab020e445c88a 100644
--- a/mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test
+++ b/mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test
@@ -164,13 +164,13 @@ remove_file $MYSQLTEST_VARDIR/tmp/master.sql;
 
 
 # this test for position option
-# By setting this position to 416, we should only get the create of t3
+# By setting this position to 417, we should only get the create of t3
 --disable_query_log
 select "--- Test 2 position test --" as "";
 --enable_query_log
 let $MYSQLD_DATADIR= `select @@datadir;`;
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
---exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=416 --stop-position=569 $MYSQLD_DATADIR/master-bin.000001
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=417 --stop-position=570 $MYSQLD_DATADIR/master-bin.000001
 
 # These are tests for remote binlog.
 # They should return the same as previous test.
@@ -181,7 +181,7 @@ select "--- Test 3 First Remote test --" as "";
 
 # This is broken now
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
---exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --stop-position=569 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --stop-position=570 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
 
 # This part is disabled due to bug #17654
 
@@ -272,7 +272,7 @@ let $MYSQLD_DATADIR= `select @@datadir;`;
 select "--- Test 7 reading stdin w/position --" as "";
 --enable_query_log
 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
---exec $MYSQL_BINLOG --short-form --position=416 --stop-position=569 - < $MYSQLD_DATADIR/master-bin.000001
+--exec $MYSQL_BINLOG --short-form --position=417 --stop-position=569 - < $MYSQLD_DATADIR/master-bin.000001
 
 # Bug#16217 (mysql client did not know how not switch its internal charset)
 --disable_query_log
diff --git a/mysql-test/suite/rpl/t/rpl_row_show_relaylog_events.test b/mysql-test/suite/rpl/t/rpl_row_show_relaylog_events.test
new file mode 100644
index 0000000000000000000000000000000000000000..6a426efc7ea204af987c24ea6d6dc647c3f949eb
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_row_show_relaylog_events.test
@@ -0,0 +1,18 @@
+# BUG#28777 SHOW BINLOG EVENTS does not work on relay log files
+#
+# GOAL
+# ==== 
+# 
+#   Test that SHOW BINLOG EVENTS and the new SHOW RELAYLOG EVENTS works after
+#   the patch, both on master and slave.
+#
+# HOW
+# ===
+#
+#   This test issues SHOW [BINLOG|RELAYLOG] EVENTS both on master and slave after 
+#   some statements have been issued.
+
+-- source include/master-slave.inc
+-- source include/have_binlog_format_row.inc
+
+-- source extra/rpl_tests/rpl_show_relaylog_events.inc
diff --git a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt b/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt
deleted file mode 100644
index b7db8f97bddff849af078d57915a966b8dea9942..0000000000000000000000000000000000000000
--- a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-master.opt
+++ /dev/null
@@ -1 +0,0 @@
---loose-binlog-row-event-max-size=256
diff --git a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt b/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt
deleted file mode 100644
index ea49a27adf45eab7c55ad04c88898940fc85225b..0000000000000000000000000000000000000000
--- a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update-slave.opt
+++ /dev/null
@@ -1 +0,0 @@
---loose-debug=d,STOP_SLAVE_after_first_Rows_event
diff --git a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test b/mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test
deleted file mode 100644
index 9b24c78e62d6e4372d1f264dfecae94b0fbadfd6..0000000000000000000000000000000000000000
--- a/mysql-test/suite/rpl/t/rpl_row_stop_middle_update.test
+++ /dev/null
@@ -1,32 +0,0 @@
--- source include/have_binlog_format_row.inc
--- source include/have_debug.inc
--- source include/master-slave.inc
-
-# master is asked to create small Rows events: if only one event is
-# created, stopping slave at the end of that one will show no bug, we
-# need at least two (and stop after first); in this test we use three.
-
-connection master;
-create table t1 (words varchar(20)) engine=myisam;
-
-load data infile '../../std_data/words.dat' into table t1 (words);
-select count(*) from t1;
-save_master_pos;
-
-connection slave;
-
-# slave will automatically stop the sql thread thanks to the .opt
-# file; it will initiate the stop request after the first
-# Rows_log_event (out of 3) but should wait until the last one is
-# executed before stopping.
-
-source include/wait_for_slave_sql_to_stop.inc;
-
-# check that we inserted all rows (waited until the last Rows event)
-select count(*) from t1;
-
-connection master;
-drop table t1;
-connection slave; # slave SQL thread is stopped
-source include/stop_slave.inc;
-drop table t1;
diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync-master.opt b/mysql-test/suite/rpl/t/rpl_semi_sync-master.opt
new file mode 100644
index 0000000000000000000000000000000000000000..58029d28acecc4b1833f0b366aa3f45966323c3d
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_semi_sync-master.opt
@@ -0,0 +1 @@
+$SEMISYNC_PLUGIN_OPT
diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync-slave.opt b/mysql-test/suite/rpl/t/rpl_semi_sync-slave.opt
new file mode 100644
index 0000000000000000000000000000000000000000..58029d28acecc4b1833f0b366aa3f45966323c3d
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_semi_sync-slave.opt
@@ -0,0 +1 @@
+$SEMISYNC_PLUGIN_OPT
diff --git a/mysql-test/suite/rpl/t/rpl_semi_sync.test b/mysql-test/suite/rpl/t/rpl_semi_sync.test
new file mode 100644
index 0000000000000000000000000000000000000000..faf961bb580c7254eeb078bbbada83bede4574de
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_semi_sync.test
@@ -0,0 +1,584 @@
+source include/have_semisync_plugin.inc;
+source include/not_embedded.inc;
+source include/not_windows.inc;
+source include/have_innodb.inc;
+source include/master-slave.inc;
+
+let $engine_type= InnoDB;
+#let $engine_type= MyISAM;
+
+# Suppress warnings that might be generated during the test
+disable_query_log;
+connection master;
+call mtr.add_suppression("Timeout waiting for reply of binlog");
+call mtr.add_suppression("Read semi-sync reply");
+connection slave;
+call mtr.add_suppression("Master server does not support semi-sync");
+call mtr.add_suppression("Semi-sync slave .* reply");
+enable_query_log;
+connection master;
+
+# After fix of BUG#45848, semi-sync slave should not create any extra
+# connections on master, save the count of connections before start
+# semi-sync slave for comparison below.
+let $_connections_normal_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1);
+
+--echo #
+--echo # Uninstall semi-sync plugins on master and slave
+--echo #
+connection slave;
+disable_query_log;
+source include/stop_slave.inc;
+reset slave;
+disable_warnings;
+error 0,1305;
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+error 0,1305;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+enable_warnings;
+
+connection master;
+reset master;
+set sql_log_bin=0;
+disable_warnings;
+error 0,1305;
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+error 0,1305;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+enable_warnings;
+set sql_log_bin=1;
+enable_query_log;
+
+--echo #
+--echo # Main test of semi-sync replication start here
+--echo #
+
+connection master;
+echo [ on master ];
+
+disable_query_log;
+let $value = query_get_value(show variables like 'rpl_semi_sync_master_enabled', Value, 1);
+if (`select '$value' = 'No such row'`)
+{
+    set sql_log_bin=0;
+    INSTALL PLUGIN rpl_semi_sync_master SONAME 'libsemisync_master.so';
+    set global rpl_semi_sync_master_timeout= 5000; /* 5s */
+    set sql_log_bin=1;
+}
+enable_query_log;
+
+echo [ default state of semi-sync on master should be OFF ];
+show variables like 'rpl_semi_sync_master_enabled';
+
+echo [ enable semi-sync on master ];
+set global rpl_semi_sync_master_enabled = 1;
+show variables like 'rpl_semi_sync_master_enabled';
+
+echo [ status of semi-sync on master should be ON even without any semi-sync slaves ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+--echo #
+--echo # BUG#45672 Semisync repl: ActiveTranx:insert_tranx_node: transaction node allocation failed
+--echo # BUG#45673 Semisynch reports correct operation even if no slave is connected
+--echo #
+
+# BUG#45672 When semi-sync is enabled on master, it would allocate
+# transaction node even without semi-sync slave connected, and would
+# finally result in transaction node allocation error.
+#
+# Semi-sync master will pre-allocate 'max_connections' transaction
+# nodes, so here we do more than that much transactions to check if it
+# will fail or not.
+# select @@global.max_connections + 1;
+let $i= `select @@global.max_connections + 1`;
+disable_query_log;
+eval create table t1 (a int) engine=$engine_type;
+while ($i)
+{
+  eval insert into t1 values ($i);
+  dec $i;
+}
+drop table t1;
+enable_query_log;
+
+# BUG#45673
+echo [ status of semi-sync on master should be OFF ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+disable_query_log;
+# reset master to make sure the following test will start with a clean environment
+reset master;
+enable_query_log;
+
+--echo #
+--echo # INSTALL PLUGIN semi-sync on slave
+--echo #
+
+connection slave;
+echo [ on slave ];
+
+disable_query_log;
+let $value= query_get_value(show variables like 'rpl_semi_sync_slave_enabled', Value, 1);
+if (`select '$value' = 'No such row'`)
+{
+    set sql_log_bin=0;
+    INSTALL PLUGIN rpl_semi_sync_slave SONAME 'libsemisync_slave.so';
+    set sql_log_bin=1;
+}
+enable_query_log;
+
+echo [ default state of semi-sync on slave should be OFF ];
+show variables like 'rpl_semi_sync_slave_enabled';
+
+echo [ enable semi-sync on slave ];
+set global rpl_semi_sync_slave_enabled = 1;
+show variables like 'rpl_semi_sync_slave_enabled';
+source include/start_slave.inc;
+
+connection master;
+echo [ on master ];
+
+# NOTE: Rpl_semi_sync_master_client will only be updated when
+# semi-sync slave has started binlog dump request
+let $status_var= Rpl_semi_sync_master_clients;
+let $status_var_value= 1;
+source include/wait_for_status_var.inc;
+
+echo [ initial master state after the semi-sync slave connected ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+replace_result $engine_type ENGINE_TYPE;
+eval create table t1(a int) engine = $engine_type;
+
+echo [ master state after CREATE TABLE statement ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+# After fix of BUG#45848, semi-sync slave should not create any extra
+# connections on master.
+let $_connections_semisync_slave= query_get_value(SHOW STATUS LIKE 'Threads_connected', Value, 1);
+replace_result $_connections_semisync_slave CONNECTIONS_SEMISYNC_SLAVE;
+replace_result $_connections_normal_slave CONNECTIONS_NORMAL_SLAVE;
+eval select $_connections_semisync_slave - $_connections_normal_slave as 'Should be 0';
+
+let $i=300;
+echo [ insert records to table ];
+disable_query_log;
+while ($i)
+{
+  eval insert into t1 values ($i);
+  dec $i;
+}
+enable_query_log;
+
+echo [ master status after inserts ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+sync_slave_with_master;
+echo [ on slave ];
+
+echo [ slave status after replicated inserts ];
+show status like 'Rpl_semi_sync_slave_status';
+
+select count(distinct a) from t1;
+select min(a) from t1;
+select max(a) from t1;
+
+--echo #
+--echo # Test semi-sync master will switch OFF after one transacton
+--echo # timeout waiting for slave reply.
+--echo #
+connection slave;
+source include/stop_slave.inc;
+
+connection master;
+echo [ on master ];
+
+# The first semi-sync check should be on because after slave stop,
+# there are no transactions on the master.
+echo [ master status should be ON ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+show status like 'Rpl_semi_sync_master_clients';
+
+echo [ semi-sync replication of these transactions will fail ];
+insert into t1 values (500);
+
+# Wait for the semi-sync replication of this transaction to timeout
+let $status_var= Rpl_semi_sync_master_status;
+let $status_var_value= OFF;
+source include/wait_for_status_var.inc;
+
+# The second semi-sync check should be off because one transaction
+# times out during waiting.
+echo [ master status should be OFF ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+# Semi-sync status on master is now OFF, so all these transactions
+# will be replicated asynchronously.
+let $i=300;
+disable_query_log;
+while ($i)
+{
+  eval delete from t1 where a=$i;
+  dec $i;
+}
+enable_query_log;
+
+insert into t1 values (100);
+
+echo [ master status should be OFF ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+--echo #
+--echo # Test semi-sync status on master will be ON again when slave catches up
+--echo #
+
+# Save the master position for later use.
+save_master_pos;
+
+connection slave;
+echo [ on slave ];
+
+echo [ slave status should be OFF ];
+show status like 'Rpl_semi_sync_slave_status';
+source include/start_slave.inc;
+sync_with_master;
+
+echo [ slave status should be ON ];
+show status like 'Rpl_semi_sync_slave_status';
+
+select count(distinct a) from t1;
+select min(a) from t1;
+select max(a) from t1;
+
+connection master;
+echo [ on master ];
+
+# The master semi-sync status should be on again after slave catches up.
+echo [ master status should be ON again after slave catches up ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+show status like 'Rpl_semi_sync_master_clients';
+
+--echo #
+--echo # Test disable/enable master semi-sync on the fly.
+--echo #
+
+drop table t1;
+sync_slave_with_master;
+echo [ on slave ];
+
+source include/stop_slave.inc;
+
+--echo #
+--echo # Flush status
+--echo #
+connection master;
+echo [ Semi-sync master status variables before FLUSH STATUS ];
+SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
+SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
+# Do not write the FLUSH STATUS to binlog, to make sure we'll get a
+# clean status after this.
+FLUSH NO_WRITE_TO_BINLOG STATUS;
+echo [ Semi-sync master status variables after FLUSH STATUS ];
+SHOW STATUS LIKE 'Rpl_semi_sync_master_no_tx';
+SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
+
+connection master;
+echo [ on master ];
+
+source include/show_master_logs.inc;
+show variables like 'rpl_semi_sync_master_enabled';
+
+echo [ disable semi-sync on the fly ];
+set global rpl_semi_sync_master_enabled=0;
+show variables like 'rpl_semi_sync_master_enabled';
+show status like 'Rpl_semi_sync_master_status';
+
+echo [ enable semi-sync on the fly ];
+set global rpl_semi_sync_master_enabled=1;
+show variables like 'rpl_semi_sync_master_enabled';
+show status like 'Rpl_semi_sync_master_status';
+
+--echo #
+--echo # Test RESET MASTER/SLAVE
+--echo #
+
+connection slave;
+echo [ on slave ];
+
+source include/start_slave.inc;
+
+connection master;
+echo [ on master ];
+
+replace_result $engine_type ENGINE_TYPE;
+eval create table t1 (a int) engine = $engine_type;
+drop table t1;
+
+##show status like 'Rpl_semi_sync_master_status';
+
+sync_slave_with_master;
+--replace_column 2 #
+show status like 'Rpl_relay%';
+
+echo [ test reset master ];
+connection master;
+echo [ on master];
+
+reset master;
+
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+connection slave;
+echo [ on slave ];
+
+source include/stop_slave.inc;
+reset slave;
+
+# Kill the dump thread on master for previous slave connection and
+# wait for it to exit
+connection master;
+let $_tid= `select id from information_schema.processlist where command = 'Binlog Dump' limit 1`;
+if ($_tid)
+{
+  disable_query_log;
+  eval kill query $_tid;
+  enable_query_log;
+
+  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+  let $status_var= Rpl_semi_sync_master_clients;
+  let $status_var_value= 0;
+  source include/wait_for_status_var.inc;
+}
+
+connection slave;
+source include/start_slave.inc;
+
+connection master;
+echo [ on master ];
+
+# Wait for dump thread to start, Rpl_semi_sync_master_clients will be
+# 1 after dump thread started.
+let $status_var= Rpl_semi_sync_master_clients;
+let $status_var_value= 1;
+source include/wait_for_status_var.inc;
+
+replace_result $engine_type ENGINE_TYPE;
+eval create table t1 (a int) engine = $engine_type;
+insert into t1 values (1);
+insert into t1 values (2), (3);
+
+sync_slave_with_master;
+echo [ on slave ];
+
+select * from t1;
+
+connection master;
+echo [ on master ];
+
+echo [ master semi-sync status should be ON ];
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+--echo #
+--echo # Start semi-sync replication without SUPER privilege
+--echo #
+connection slave;
+source include/stop_slave.inc;
+reset slave;
+connection master;
+echo [ on master ];
+reset master;
+
+# Kill the dump thread on master for previous slave connection and wait for it to exit
+let $_tid= `select id from information_schema.processlist where command = 'Binlog Dump' limit 1`;
+if ($_tid)
+{
+  disable_query_log;
+  eval kill query $_tid;
+  enable_query_log;
+
+  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+  let $status_var= Rpl_semi_sync_master_clients;
+  let $status_var_value= 0;
+  source include/wait_for_status_var.inc;
+}
+
+# Do not binlog the following statement because it will generate
+# different events for ROW and STATEMENT format
+set sql_log_bin=0;
+grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl';
+flush privileges;
+set sql_log_bin=1;
+connection slave;
+echo [ on slave ];
+grant replication slave on *.* to rpl@127.0.0.1 identified by 'rpl';
+flush privileges;
+change master to master_user='rpl',master_password='rpl';
+source include/start_slave.inc;
+show status like 'Rpl_semi_sync_slave_status';
+connection master;
+echo [ on master ];
+
+# Wait for the semi-sync binlog dump thread to start
+let $status_var= Rpl_semi_sync_master_clients;
+let $status_var_value= 1;
+source include/wait_for_status_var.inc;
+echo [ master semi-sync should be ON ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+insert into t1 values (4);
+insert into t1 values (5);
+echo [ master semi-sync should be ON ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+show status like 'Rpl_semi_sync_master_no_tx';
+show status like 'Rpl_semi_sync_master_yes_tx';
+
+--echo #
+--echo # Test semi-sync slave connect to non-semi-sync master
+--echo #
+
+# Disable semi-sync on master
+connection slave;
+echo [ on slave ];
+source include/stop_slave.inc;
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+
+connection master;
+echo [ on master ];
+
+# Kill the dump thread on master for previous slave connection and wait for it to exit
+let $_tid= `select id from information_schema.processlist where command = 'Binlog Dump' limit 1`;
+if ($_tid)
+{
+  disable_query_log;
+  eval kill query $_tid;
+  enable_query_log;
+
+  # After dump thread exit, Rpl_semi_sync_master_clients will be 0
+  let $status_var= Rpl_semi_sync_master_clients;
+  let $status_var_value= 0;
+  source include/wait_for_status_var.inc;
+}
+
+echo [ Semi-sync status on master should be ON ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+set global rpl_semi_sync_master_enabled= 0;
+
+connection slave;
+echo [ on slave ];
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+source include/start_slave.inc;
+connection master;
+echo [ on master ];
+insert into t1 values (8);
+let $status_var= Rpl_semi_sync_master_clients;
+let $status_var_value= 1;
+source include/wait_for_status_var.inc;
+echo [ master semi-sync clients should be 1, status should be OFF ];
+show status like 'Rpl_semi_sync_master_clients';
+show status like 'Rpl_semi_sync_master_status';
+sync_slave_with_master;
+echo [ on slave ];
+show status like 'Rpl_semi_sync_slave_status';
+
+# Uninstall semi-sync plugin on master
+connection slave;
+source include/stop_slave.inc;
+connection master;
+echo [ on master ];
+set sql_log_bin=0;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+set sql_log_bin=1;
+enable_query_log;
+SHOW VARIABLES LIKE 'rpl_semi_sync_master_enabled';
+
+connection slave;
+echo [ on slave ];
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+source include/start_slave.inc;
+
+connection master;
+echo [ on master ];
+insert into t1 values (10);
+sync_slave_with_master;
+echo [ on slave ];
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+
+--echo #
+--echo # Test non-semi-sync slave connect to semi-sync master
+--echo #
+
+connection master;
+set sql_log_bin=0;
+INSTALL PLUGIN rpl_semi_sync_master SONAME 'libsemisync_master.so';
+set global rpl_semi_sync_master_timeout= 5000; /* 5s */
+set sql_log_bin=1;
+set global rpl_semi_sync_master_enabled= 1;
+
+connection slave;
+echo [ on slave ];
+source include/stop_slave.inc;
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+
+echo [ uninstall semi-sync slave plugin ];
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+source include/start_slave.inc;
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+source include/stop_slave.inc;
+
+echo [ reinstall semi-sync slave plugin and disable semi-sync ];
+INSTALL PLUGIN rpl_semi_sync_slave SONAME 'libsemisync_slave.so';
+set global rpl_semi_sync_slave_enabled= 0;
+SHOW VARIABLES LIKE 'rpl_semi_sync_slave_enabled';
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+source include/start_slave.inc;
+SHOW STATUS LIKE 'Rpl_semi_sync_slave_status';
+
+--echo #
+--echo # Clean up
+--echo #
+
+connection slave;
+source include/stop_slave.inc;
+UNINSTALL PLUGIN rpl_semi_sync_slave;
+
+connection master;
+UNINSTALL PLUGIN rpl_semi_sync_master;
+
+connection slave;
+source include/start_slave.inc;
+
+connection master;
+drop table t1;
+sync_slave_with_master;
+
+connection master;
+drop user rpl@127.0.0.1;
+flush privileges;
diff --git a/mysql-test/suite/rpl/t/rpl_server_id_ignore-slave.opt b/mysql-test/suite/rpl/t/rpl_server_id_ignore-slave.opt
new file mode 100644
index 0000000000000000000000000000000000000000..302889525ddbcea88aa312af680d71a66ca6d2c5
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_server_id_ignore-slave.opt
@@ -0,0 +1 @@
+--disable-log-slave-updates --replicate-same-server-id
diff --git a/mysql-test/suite/rpl/t/rpl_server_id_ignore.test b/mysql-test/suite/rpl/t/rpl_server_id_ignore.test
new file mode 100644
index 0000000000000000000000000000000000000000..1b38bd34d3d734e5c50b5e797cb649e6d6196085
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_server_id_ignore.test
@@ -0,0 +1,114 @@
+# This test checks that the slave rejects events originating
+# by a server from the list of ignored originators (bug#27808 etc)
+#
+# phases of tests:
+#
+# 0. master_id new line in show slave status
+# 1. syntax related: 
+#    a. error reporting if options clash;
+#    b. overriding the old IGNORE_SERVER_IDS setup by the following 
+#       CHANGE MASTER ... IGNORE_SERVER_IDS= (list);
+#    c. the old setup preserving by CHANGE MASTER w/o IGNORE_SERVER_IDS
+#    d. resetting the ignored server ids with the empty list arg to 
+#       IGNORE_SERVER_IDS=()
+#    e. RESET SLAVE preserves the list
+# 2. run time related: 
+#    a. observing no processing events from a master listed in IGNORE_SERVER_IDS
+#    b. nullifying the list and resuming of taking binlog from the very beginning with
+#       executing events this time
+
+source include/master-slave.inc;
+
+connection slave;
+
+# a new line for master_id
+let $master_id= query_get_value(SHOW SLAVE STATUS, Master_Server_Id, 1);
+echo master_id: $master_id;
+
+stop slave;
+--echo *** --replicate-same-server-id and change master option can clash ***
+--error ER_SLAVE_IGNORE_SERVER_IDS
+change master to IGNORE_SERVER_IDS= (2, 1);
+--echo *** must be empty due to the error ***
+let $ignore_list= query_get_value(SHOW SLAVE STATUS, Replicate_Ignore_Server_Ids, 1);
+echo ignore server id list: $ignore_list;
+
+change master to IGNORE_SERVER_IDS= (10, 100);
+--echo *** must be 10, 100 ***
+let $ignore_list= query_get_value(SHOW SLAVE STATUS, Replicate_Ignore_Server_Ids, 1);
+echo ignore server id list: $ignore_list;
+reset slave;
+--echo *** must be empty due to reset slave ***
+let $ignore_list= query_get_value(SHOW SLAVE STATUS, Replicate_Ignore_Server_Ids, 1);
+echo ignore server id list: $ignore_list;
+change master to IGNORE_SERVER_IDS= (10, 100);
+--echo *** CHANGE MASTER with IGNORE_SERVER_IDS option overrides (does not increment) the previous setup ***
+change master to IGNORE_SERVER_IDS= (5, 1, 4, 3, 1);
+--echo *** must be 1, 3, 4, 5 due to overriding policy ***
+let $ignore_list= query_get_value(SHOW SLAVE STATUS, Replicate_Ignore_Server_Ids, 1);
+echo ignore server id list: $ignore_list;
+--echo *** ignore master (server 1) queries for a while ***
+start slave;
+
+connection master;
+
+#connection slave;
+sync_slave_with_master;
+let $slave_relay_pos0= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1);
+
+connection master;
+create table t1 (n int);
+let $master_binlog_end= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+connection slave;
+let $slave_param= Exec_Master_Log_Pos;
+let $slave_param_value= $master_binlog_end;
+source include/wait_for_slave_param.inc;
+--echo *** must be empty as the event is to be filtered out ***
+show tables;
+--echo *** allowing events from master ***
+let $slave_relay_pos1= query_get_value(SHOW SLAVE STATUS, Relay_Log_Pos, 1);
+#
+# checking stability of relay log pos
+#
+if (`select $slave_relay_pos1 - $slave_relay_pos0`)
+{
+    --echo Error: relay log position changed:  $slave_relay_pos0, $slave_relay_pos1
+    query_vertical show slave status;
+}
+
+stop slave;
+source include/wait_for_slave_to_stop.inc;
+reset slave;
+change master to IGNORE_SERVER_IDS= (10, 100);
+--echo *** the list must remain (10, 100) after reset slave ***
+let $ignore_list= query_get_value(SHOW SLAVE STATUS, Replicate_Ignore_Server_Ids, 1);
+
+change master to IGNORE_SERVER_IDS= ();
+--echo *** must be empty due to IGNORE_SERVER_IDS empty list ***
+let $ignore_list= query_get_value(SHOW SLAVE STATUS, Replicate_Ignore_Server_Ids, 1);
+echo ignore server id list: $ignore_list;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1', master_port=$MASTER_MYPORT, master_user='root';
+start slave;
+
+connection master;
+
+#connection slave;
+sync_slave_with_master;
+--echo *** must have caught create table ***
+show tables;
+
+# cleanup
+connection master;
+drop table t1;
+#connection slave
+sync_slave_with_master;
+
+--echo end of the tests
+
+
+
+
+
+
diff --git a/mysql-test/suite/rpl/t/rpl_slave_skip.test b/mysql-test/suite/rpl/t/rpl_slave_skip.test
index f4cb0f69e9338c2f6efba7dac203bc32bd4ceda7..6336e775af1bd3462141c7691aa2508a5eda308d 100644
--- a/mysql-test/suite/rpl/t/rpl_slave_skip.test
+++ b/mysql-test/suite/rpl/t/rpl_slave_skip.test
@@ -27,7 +27,7 @@ connection slave;
 
 # Stop when reaching the the first table map event.
 START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=762;
-wait_for_slave_to_stop;
+-- source include/wait_for_slave_sql_to_stop.inc
 --replace_result $MASTER_MYPORT MASTER_PORT
 --replace_column 1 # 8 # 9 # 23 # 33 # 35 # 36 #
 query_vertical SHOW SLAVE STATUS;
@@ -59,7 +59,7 @@ source include/show_binlog_events.inc;
 
 connection slave;
 START SLAVE UNTIL MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS=106;
-wait_for_slave_to_stop;
+-- source include/wait_for_slave_sql_to_stop.inc
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 sync_with_master;
diff --git a/mysql-test/suite/rpl/t/rpl_slave_status.test b/mysql-test/suite/rpl/t/rpl_slave_status.test
index 4edf1802a5d163625f4292a86fa607b601584505..02fd555d13cef51b064dff05483d87dc5acf6331 100644
--- a/mysql-test/suite/rpl/t/rpl_slave_status.test
+++ b/mysql-test/suite/rpl/t/rpl_slave_status.test
@@ -54,6 +54,7 @@ sync_slave_with_master;
 source include/stop_slave.inc;
 START SLAVE;
 source include/wait_for_slave_sql_to_start.inc;
+source include/wait_for_slave_io_to_stop.inc;
 
 --echo ==== Verify that Slave_IO_Running = No ====
 let $result= query_get_value("SHOW SLAVE STATUS", Slave_IO_Running, 1);
diff --git a/mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt b/mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt
new file mode 100644
index 0000000000000000000000000000000000000000..a27d3a0f5a74e1419b89de6f1d07d0abb03bacbd
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_slow_query_log-slave.opt
@@ -0,0 +1 @@
+--force-restart --log-slow-slave-statements --log-slow-queries
diff --git a/mysql-test/suite/rpl/t/rpl_slow_query_log.test b/mysql-test/suite/rpl/t/rpl_slow_query_log.test
new file mode 100644
index 0000000000000000000000000000000000000000..1d5fcf950f2e78a3417382d6b16af23193f1b5b2
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_slow_query_log.test
@@ -0,0 +1,187 @@
+#
+# BUG#23300: Slow query log on slave does not log slow replicated statements
+#
+# Description:
+#   The slave should log slow queries replicated from master when
+#   --log-slow-slave-statements is used.
+#
+#   Test is implemented as follows:
+#      i) stop slave
+#     ii) On slave, set long_query_time to a small value.
+#     ii) start slave so that long_query_time variable is picked by sql thread
+#    iii) On master, do one short time query and one long time query, on slave
+#         and check that slow query is logged to slow query log but fast query 
+#         is not.
+#     iv) On slave, check that slow queries go into the slow log and fast dont,
+#         when issued through a regular client connection
+#      v) On slave, check that slow queries go into the slow log and fast dont
+#         when we use SET TIMESTAMP= 1 on a regular client connection.
+#     vi) check that when setting slow_query_log= OFF in a connection 'extra2'
+#         prevents logging slow queries in a connection 'extra'
+#
+# OBS: 
+#   This test only runs for statement and mixed binlogging firmat because on
+#   row format slow queries do not get slow query logged. 
+
+source include/master-slave.inc;
+source include/have_binlog_format_mixed_or_statement.inc;
+
+
+# Prepare slave for different long_query_time we need to stop the slave 
+# and restart it as long_query_time variable is dynamic and, after 
+# setting it, it only takes effect on new connections. 
+#
+# Reference: 
+#   http://dev.mysql.com/doc/refman/6.0/en/set-option.html
+connection slave;
+
+source include/stop_slave.inc;
+
+SET @old_log_output= @@log_output;
+SET GLOBAL log_output= 'TABLE';
+SET @old_long_query_time= @@long_query_time;
+SET GLOBAL long_query_time= 2;
+TRUNCATE mysql.slow_log;
+
+source include/start_slave.inc;
+
+connection master;
+CREATE TABLE t1 (a int, b int); 
+
+# test:
+#   check that slave logs the slow query to the slow log, but not the fast one.
+
+let $slow_query= INSERT INTO t1 values(1, sleep(3));
+let $fast_query= INSERT INTO t1 values(1, 1);
+
+eval $fast_query;
+eval $slow_query;
+sync_slave_with_master;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
+}
+
+if (!$found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# regular checks for slow query log (using a new connection - 'extra' - to slave)
+
+# test: 
+#   when using direct connections to the slave, check that slow query is logged 
+#   but not the fast one.
+
+connect(extra,127.0.0.1,root,,test,$SLAVE_MYPORT);
+connection extra;
+
+let $fast_query= SELECT 1;
+let $slow_query= SELECT 1, sleep(3);
+
+eval $slow_query;
+eval $fast_query;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
+}
+
+if (!$found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# test:
+#   when using direct connections to the slave, check that when setting timestamp to 1 the 
+#   slow query is logged but the fast one is not.
+
+let $fast_query= SELECT 2;
+let $slow_query= SELECT 2, sleep(3);
+
+SET TIMESTAMP= 1;
+eval $slow_query;
+eval $fast_query;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
+}
+
+if (!$found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# test: 
+#   check that when setting the slow_query_log= OFF on connection 'extra2'
+#   prevents connection 'extra' from logging to slow query log.
+
+let $fast_query= SELECT 3;
+let $slow_query= SELECT 3, sleep(3);
+
+connect(extra2,127.0.0.1,root,,test,$SLAVE_MYPORT);
+connection extra2;
+
+SET @old_slow_query_log= @@slow_query_log;
+SET GLOBAL slow_query_log= 'OFF';
+
+connection extra;
+
+eval $slow_query;
+eval $fast_query;
+
+let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
+let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
+
+if ($found_fast_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Fast query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
+}
+
+if ($found_slow_query)
+{
+  SELECT * FROM mysql.slow_log;
+  die "Assertion failed! Slow query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
+}
+TRUNCATE mysql.slow_log;
+
+# clean up: drop tables, reset the variables back to the previous value,
+#           disconnect extra connections
+connection extra2;
+
+SET GLOBAL slow_query_log= @old_slow_query_log;
+
+connection master;
+DROP TABLE t1;
+sync_slave_with_master;
+
+source include/stop_slave.inc;
+
+SET GLOBAL long_query_time= @old_long_query_time;
+SET GLOBAL log_output= @old_log_output;
+
+source include/start_slave.inc;
+
+disconnect extra;
+disconnect extra2;
diff --git a/mysql-test/suite/rpl/t/rpl_sp.test b/mysql-test/suite/rpl/t/rpl_sp.test
index 9be630e9ae86e9eb910a24f4db8985dc661e2cb2..2811db8ef1eee436b67ffa3830c65ff668abcf6f 100644
--- a/mysql-test/suite/rpl/t/rpl_sp.test
+++ b/mysql-test/suite/rpl/t/rpl_sp.test
@@ -568,9 +568,7 @@ connection master;
 
 # Final inspection which verifies how all statements of this test file
 # were written to the binary log.
---replace_column 2 # 5 #
---replace_regex /table_id: [0-9]+/table_id: #/
-show binlog events in 'master-bin.000001' from 106;
+source include/show_binlog_events.inc;
 
 
 # Restore log_bin_trust_function_creators to its original value.
diff --git a/mysql-test/suite/rpl/t/rpl_spec_variables-slave.opt b/mysql-test/suite/rpl/t/rpl_spec_variables-slave.opt
new file mode 100644
index 0000000000000000000000000000000000000000..627becdbfb57cb49e0525c614f7089ec489859aa
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_spec_variables-slave.opt
@@ -0,0 +1 @@
+--innodb
diff --git a/mysql-test/suite/rpl/t/rpl_spec_variables.test b/mysql-test/suite/rpl/t/rpl_spec_variables.test
new file mode 100644
index 0000000000000000000000000000000000000000..a60738316c8e24655ddfa168c1d281c2eb360647
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_spec_variables.test
@@ -0,0 +1,306 @@
+#############################################################
+# Author: Serge Kozlov <skozlov@mysql.com>
+# Date:   07/01/2008
+# Purpose: Testing possible affects of some system dynamic 
+# variables to the replication. 
+# Scenario for each variable:
+# 1) Set different values for master and slave
+# 2) Create and replicate a data from master to slave
+# 3) Check results on master and slave: changes on slave 
+# shouldn't be affected to replicated data.
+#############################################################
+--source include/have_innodb.inc
+--source include/master-slave.inc
+--echo
+
+#
+# AUTO_INCREMENT
+#
+--echo * auto_increment_increment, auto_increment_offset *
+
+--connection master
+SET @@global.auto_increment_increment=2;
+SET @@session.auto_increment_increment=2;
+SET @@global.auto_increment_offset=10;
+SET @@session.auto_increment_offset=10;
+
+--connection slave
+SET @@global.auto_increment_increment=3;
+SET @@session.auto_increment_increment=3;
+SET @@global.auto_increment_offset=20;
+SET @@session.auto_increment_offset=20;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+INSERT INTO t1 (b) VALUES ('master');
+INSERT INTO t1 (b) VALUES ('master');
+SELECT * FROM t1 ORDER BY a;
+
+--sync_slave_with_master
+CREATE TABLE t2 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+INSERT INTO t1 (b) VALUES ('slave');
+INSERT INTO t1 (b) VALUES ('slave');
+INSERT INTO t2 (b) VALUES ('slave');
+INSERT INTO t2 (b) VALUES ('slave');
+SELECT * FROM t1 ORDER BY a;
+SELECT * FROM t2 ORDER BY a;
+
+--connection master
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+SET @@global.auto_increment_increment=1;
+SET @@session.auto_increment_increment=1;
+SET @@global.auto_increment_offset=1;
+SET @@session.auto_increment_offset=1;
+
+--connection slave
+SET @@global.auto_increment_increment=1;
+SET @@session.auto_increment_increment=1;
+SET @@global.auto_increment_offset=1;
+SET @@session.auto_increment_offset=1;
+
+--connection slave
+SET auto_increment_increment=1;
+SET auto_increment_offset=1;
+--echo
+
+#
+# CHARACTER_SET_DATABASE, COLLATION_SERVER
+#
+--echo * character_set_database, collation_server *
+
+--connection master
+SET @restore_master_character_set_database=@@global.character_set_database;
+SET @restore_master_collation_server=@@global.collation_server;
+SET @@global.character_set_database=latin1;
+SET @@session.character_set_database=latin1;
+SET @@global.collation_server=latin1_german1_ci;
+SET @@session.collation_server=latin1_german1_ci;
+
+--connection slave
+SET @restore_slave_character_set_database=@@global.character_set_database;
+SET @restore_slave_collation_server=@@global.collation_server;
+SET @@global.character_set_database=utf8;
+SET @@session.character_set_database=utf8;
+SET @@global.collation_server=utf8_bin;
+SET @@session.collation_server=utf8_bin;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+SHOW CREATE TABLE t1;
+
+--sync_slave_with_master
+CREATE TABLE t2 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10)) ENGINE=MyISAM;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+SET @@global.collation_server=latin1_swedish_ci;
+SET @@session.collation_server=latin1_swedish_ci;
+
+--connection master
+SET @@global.collation_server=latin1_swedish_ci;
+SET @@session.collation_server=latin1_swedish_ci;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+--echo
+
+#
+# DEFAULT_WEEK_FORMAT
+#
+--echo * default_week_format *
+
+--connection master
+SET @@global.default_week_format=0;
+SET @@session.default_week_format=0;
+
+--connection slave
+SET @@global.default_week_format=1;
+SET @@session.default_week_format=1;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c INT) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1, 'master ', WEEK('2008-01-07'));
+SELECT * FROM t1 ORDER BY a;
+
+--sync_slave_with_master
+INSERT INTO t1 VALUES (2, 'slave ', WEEK('2008-01-07'));
+SELECT * FROM t1 ORDER BY a;
+
+--connection master
+DROP TABLE t1;
+
+--connection slave
+SET @@global.default_week_format=0;
+SET @@session.default_week_format=0;
+--echo
+
+#
+# LOCAL_INFILE
+#
+--echo * local_infile *
+
+--connection slave
+SET @@global.local_infile=0;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(20), c CHAR(254)) ENGINE=MyISAM;
+--copy_file ./std_data/words.dat $MYSQLTEST_VARDIR/tmp/words.dat
+--copy_file ./std_data/words2.dat $MYSQLTEST_VARDIR/tmp/words2.dat
+--replace_regex /\'.+\'/'FILE'/
+--eval LOAD DATA LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/words.dat' INTO TABLE t1 (b)
+SELECT COUNT(*) FROM t1;
+--sync_slave_with_master
+--replace_regex /\'.+\'/'FILE2'/
+--error 1148
+--eval LOAD DATA LOCAL INFILE '$MYSQLTEST_VARDIR/tmp/words2.dat' INTO TABLE t1 (b)
+SELECT COUNT(*) FROM t1;
+
+SET @@global.local_infile=1;
+
+--connection master
+DROP TABLE t1;
+--echo
+
+#
+# MAX_HEAP_TABLE_SIZE
+#
+--echo * max_heap_table_size *
+
+--connection slave
+SET @restore_slave_max_heap_table_size=@@global.max_heap_table_size;
+SET @@global.max_heap_table_size=16384;
+SET @@session.max_heap_table_size=16384;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), c CHAR(254)) ENGINE=MEMORY;
+let $counter=2000;
+--disable_query_log
+while ($counter) {
+ INSERT INTO t1 (b,c) VALUES ('master', REPEAT('A', 254));
+ dec $counter;
+}
+--enable_query_log
+SELECT COUNT(*)=2000 FROM t1;
+
+--sync_slave_with_master
+let $counter=2000;
+--disable_query_log
+while ($counter) {
+ --error 0,1114
+ INSERT INTO t1 (b,c) VALUES ('slave', REPEAT('A', 254));
+ dec $counter;
+}
+CREATE TABLE t2 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(10), c CHAR(254)) ENGINE=MEMORY;
+let $counter=2000;
+--disable_query_log
+while ($counter) {
+ --error 0,1114
+ INSERT INTO t2 (b,c) VALUES ('slave', REPEAT('A', 254));
+ dec $counter;
+}
+--enable_query_log
+# We don't know how many memory used and can't check exact values so need to check following 
+# conditions
+SELECT COUNT(*)=2000 FROM t1 WHERE b='master' GROUP BY b ORDER BY b;
+SELECT COUNT(*)<2000 AND COUNT(*)>0 FROM t1 WHERE b='slave' GROUP BY b ORDER BY b;
+SELECT COUNT(*)<2000 AND COUNT(*)>0 FROM t2 WHERE b='slave' GROUP BY b ORDER BY b;
+
+--connection master
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+--echo
+
+#
+# STORAGE_ENGINE
+#
+--echo * storage_engine *
+
+--connection master
+SET @restore_master_storage_engine=@@global.storage_engine;
+SET @@global.storage_engine=InnoDB;
+SET @@session.storage_engine=InnoDB;
+
+--connection slave
+SET @restore_slave_storage_engine=@@global.storage_engine;
+SET @@global.storage_engine=Memory;
+SET @@session.storage_engine=Memory;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10));
+CREATE TABLE t2 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10)) ENGINE=InnoDB;
+
+--sync_slave_with_master
+CREATE TABLE t3 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10));
+
+--connection master
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+
+--connection slave
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE t2;
+SHOW CREATE TABLE t3;
+
+SET @@global.storage_engine=InnoDB;
+SET @@session.storage_engine=InnoDB;
+
+--connection master
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2,t3;
+--enable_warnings
+--echo
+
+#
+# SQL_MODE
+#
+--echo * sql_mode *
+
+--connection master
+SET @@global.sql_mode=ANSI;
+SET @@session.sql_mode=ANSI;
+
+--connection slave
+SET @@global.sql_mode=TRADITIONAL;
+SET @@session.sql_mode=TRADITIONAL;
+
+--connection master
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c DATE);
+INSERT INTO t1 VALUES (1, 'master', '0000-00-00');
+SELECT * FROM t1 ORDER BY a;
+
+--sync_slave_with_master
+--error 1292
+INSERT INTO t1 VALUES (1, 'slave', '0000-00-00');
+SELECT * FROM t1 ORDER BY a;
+SET @@global.sql_mode='';
+SET @@session.sql_mode='';
+
+--connection master
+SET @@global.sql_mode='';
+SET @@session.sql_mode='';
+DROP TABLE t1;
+--echo
+
+
+# Clean up
+--echo *** clean up ***
+--connection master
+SET @@global.character_set_database=@restore_master_character_set_database;
+SET @@global.collation_server=@restore_master_collation_server;
+SET @@global.storage_engine=@restore_master_storage_engine;
+--sync_slave_with_master
+SET @@global.character_set_database=@restore_slave_character_set_database;
+SET @@global.collation_server=@restore_slave_collation_server;
+SET @@global.max_heap_table_size=@restore_slave_max_heap_table_size;
+SET @@global.storage_engine=@restore_slave_storage_engine;
+
+# Put at the end since the test otherwise emptied the table.
+
+--echo
+call mtr.add_suppression("The table 't[12]' is full");
+
+# End of 5.1 test 
diff --git a/mysql-test/suite/rpl/t/rpl_stm_flsh_tbls.test b/mysql-test/suite/rpl/t/rpl_stm_flsh_tbls.test
index a8a33d05e8b48802441223fd026661c7f61c6c14..f3993f80b90f5db1ac22e9aba0ee05c4c693b9b3 100644
--- a/mysql-test/suite/rpl/t/rpl_stm_flsh_tbls.test
+++ b/mysql-test/suite/rpl/t/rpl_stm_flsh_tbls.test
@@ -1,7 +1,7 @@
 # depends on the binlog output
 --source include/have_binlog_format_mixed_or_statement.inc
 
-let $rename_event_pos= 656;
+let $rename_event_pos= 657;
 -- source extra/rpl_tests/rpl_flsh_tbls.test
 
 # End of 4.1 tests
diff --git a/mysql-test/suite/rpl/t/rpl_stm_mix_show_relaylog_events.test b/mysql-test/suite/rpl/t/rpl_stm_mix_show_relaylog_events.test
new file mode 100644
index 0000000000000000000000000000000000000000..523e883d9fac46ad1ae3081b119a03ae333f3447
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_stm_mix_show_relaylog_events.test
@@ -0,0 +1,18 @@
+# BUG#28777 SHOW BINLOG EVENTS does not work on relay log files
+#
+# GOAL
+# ==== 
+# 
+#   Test that SHOW BINLOG EVENTS and the new SHOW RELAYLOG EVENTS works after
+#   the patch, both on master and slave.
+#
+# HOW
+# ===
+#
+#   This test issues SHOW [BINLOG|RELAYLOG] EVENTS both on master and slave after 
+#   some statements have been issued.
+
+-- source include/master-slave.inc
+-- source include/have_binlog_format_mixed_or_statement.inc
+
+-- source extra/rpl_tests/rpl_show_relaylog_events.inc
diff --git a/mysql-test/suite/rpl/t/rpl_stop_middle_group.test b/mysql-test/suite/rpl/t/rpl_stop_middle_group.test
new file mode 100644
index 0000000000000000000000000000000000000000..2cd41b45cf942b970c85fff7851a0e12e7099398
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_stop_middle_group.test
@@ -0,0 +1,149 @@
+-- source include/have_debug.inc
+-- source include/master-slave.inc
+-- source include/have_innodb.inc
+
+# Proving that stopping in the middle of applying a group of events
+# does not have immediate effect if a non-transaction table has been changed.
+# The slave sql thread has to try to finish applying first.
+# The tests rely on simulation of the killed status.
+# The matter of testing correlates to some of `rpl_start_stop_slave' that does
+# not require `have_debug'.
+
+connection master;
+
+create table tm (a int auto_increment primary key) engine=myisam;
+create table ti (a int auto_increment primary key) engine=innodb;
+
+sync_slave_with_master;
+set @@global.debug="+d,stop_slave_middle_group";
+
+connection master;
+
+begin;
+insert into ti set a=null;
+insert into tm set a=null; # to simulate killed status on the slave 
+commit;
+
+connection slave;
+
+# slave will catch the killed status but won't shut down immediately
+# only after the whole group has done (commit)
+
+source include/wait_for_slave_sql_to_stop.inc;
+
+# checking: no error and the group is finished
+
+let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+let $read = query_get_value("SHOW SLAVE STATUS", Read_Master_Log_Pos, 1);
+let $exec = query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1);
+--disable_query_log
+eval SELECT $read = $exec into @check;
+--enable_query_log
+eval SELECT "NO$error" AS Last_SQL_Error, @check as `true`;
+select count(*) as one from tm;
+select count(*) as one from ti;
+
+set @@global.debug="-d";
+
+#
+# bug#45940 issues around rli->last_event_start_time
+# Testing of slave stopped after it had waited (in vain) for
+# the group be finished.
+# It could not be finished because of simulation of failure to
+# receive the terminal part
+# The test relay on simulation of the incomplete group in the relay log
+
+# Two cases are verified: a mixed transacton and a mixed multi-table update.
+#
+# The mixed transacton.
+#
+source include/start_slave.inc;
+
+connection master;
+
+truncate table tm; # cleanup of former tests
+truncate table ti;
+
+#connection slave;
+sync_slave_with_master;
+
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+
+connection master;
+
+begin;
+insert into ti set a=null;
+insert into tm set a=null;
+commit;
+
+connection slave;
+
+# slave will catch the killed status, won't shut down immediately
+# but does it eventually having the whole group unfinished (not committed)
+
+source include/wait_for_slave_sql_to_stop.inc;
+
+# checking: the error and group unfinished
+
+let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+let $read = query_get_value("SHOW SLAVE STATUS", Read_Master_Log_Pos, 1);
+let $exec = query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1);
+--disable_query_log
+eval SELECT $read - $exec > 0 into @check;
+--enable_query_log
+eval SELECT "$error" AS Last_SQL_Error, @check as `true`;
+select count(*) as one  from tm;
+select count(*) as zero from ti;
+
+set @@global.debug="-d";
+
+#
+# The mixed multi-table update
+#
+stop slave;
+truncate table tm;
+source include/start_slave.inc;
+
+connection master;
+
+#connection slave;
+sync_slave_with_master;
+set @@global.debug="+d,stop_slave_middle_group";
+set @@global.debug="+d,incomplete_group_in_relay_log";
+
+connection master;
+update tm as t1, ti as t2 set t1.a=t1.a * 2, t2.a=t2.a * 2;
+
+connection slave;
+
+# slave will catch the killed status, won't shut down immediately
+# but does it eventually having the whole group unfinished (not committed)
+# 
+
+source include/wait_for_slave_sql_to_stop.inc;
+
+# checking: the error and group unfinished 
+
+let $error= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
+let $read = query_get_value("SHOW SLAVE STATUS", Read_Master_Log_Pos, 1);
+let $exec = query_get_value("SHOW SLAVE STATUS", Exec_Master_Log_Pos, 1);
+--disable_query_log
+eval SELECT $read - $exec > 0 into @check;
+--enable_query_log
+eval SELECT "$error" AS Last_SQL_Error, @check as `true`;
+select max(a) as two from tm;
+select max(a) as one from ti;
+
+set @@global.debug="-d";
+
+#
+# clean-up
+#
+
+connection master;
+drop table tm, ti;
+
+connection slave; # slave SQL thread is stopped
+source include/stop_slave.inc;
+drop table tm, ti;
diff --git a/mysql-test/suite/rpl/t/rpl_sync-slave.opt b/mysql-test/suite/rpl/t/rpl_sync-slave.opt
new file mode 100644
index 0000000000000000000000000000000000000000..77809a42c4362a784e0f6cd989305a929bbac070
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_sync-slave.opt
@@ -0,0 +1 @@
+--sync-relay-log-info=1 --relay-log-recovery=1
diff --git a/mysql-test/suite/rpl/t/rpl_sync.test b/mysql-test/suite/rpl/t/rpl_sync.test
new file mode 100644
index 0000000000000000000000000000000000000000..80b6a144187e7a280ae1528c752feb6ba5718883
--- /dev/null
+++ b/mysql-test/suite/rpl/t/rpl_sync.test
@@ -0,0 +1,148 @@
+########################################################################################
+# This test verifies the options --sync-relay-log-info and --relay-log-recovery by 
+# crashing the slave in two different situations:
+#  (case-1) - Corrupt the relay log with changes which were not processed by
+#  the SQL Thread and crashes it.
+#  (case-2) - Corrupt the master.info with wrong coordinates and crashes it.
+#
+#  Case 1:
+#    1 - Stops the SQL Thread
+#    2 - Inserts new records into the master.
+#    3 - Corrupts the relay-log.bin* which most likely has such changes.
+#    4 - Crashes the slave
+#    5 - Verifies if the slave is sync with the master which means that the information
+#    loss was circumvented by the recovery process.
+#
+#  Case 2:
+#    1 - Stops the SQL/IO Threads
+#    2 - Inserts new records into the master.
+#    3 - Corrupts the master.info with wrong coordinates.
+#    4 - Crashes the slave
+#    5 - Verifies if the slave is sync with the master which means that the information
+#    loss was circumvented by the recovery process.
+########################################################################################
+
+########################################################################################
+#                                Configuring the environment
+########################################################################################
+--echo =====Configuring the enviroment=======;
+--source include/master-slave.inc
+--source include/not_embedded.inc
+--source include/not_valgrind.inc
+--source include/have_debug.inc
+--source include/have_innodb.inc
+
+call mtr.add_suppression('Attempting backtrace');
+call mtr.add_suppression("Recovery from master pos .* and file master-bin.000001");
+CREATE TABLE t1(a INT, PRIMARY KEY(a)) engine=innodb;
+
+insert into t1(a) values(1);
+insert into t1(a) values(2);
+insert into t1(a) values(3);
+
+########################################################################################
+#                             Case 1: Corrupt a relay-log.bin*
+########################################################################################
+--echo =====Inserting data on the master but without the SQL Thread being running=======;
+sync_slave_with_master;
+
+connection slave;
+let $MYSQLD_SLAVE_DATADIR= `select @@datadir`;
+--replace_result $MYSQLD_SLAVE_DATADIR MYSQLD_SLAVE_DATADIR
+--copy_file $MYSQLD_SLAVE_DATADIR/master.info $MYSQLD_SLAVE_DATADIR/master.backup
+stop slave SQL_THREAD;
+source include/wait_for_slave_sql_to_stop.inc;
+
+connection master;
+insert into t1(a) values(4);
+insert into t1(a) values(5);
+insert into t1(a) values(6);
+
+--echo =====Removing relay log files and crashing/recoverying the slave=======;
+connection slave;
+stop slave IO_THREAD;
+source include/wait_for_slave_io_to_stop.inc;
+
+let $file= query_get_value("SHOW SLAVE STATUS", Relay_Log_File, 1);
+--replace_result $MYSQLD_SLAVE_DATADIR MYSQLD_SLAVE_DATADIR
+--exec echo "failure" > $MYSQLD_SLAVE_DATADIR/$file
+
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
+SET SESSION debug="d,crash_before_rotate_relaylog";
+--error 2013
+FLUSH LOGS;
+
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+--echo =====Dumping and comparing tables=======;
+start slave;
+source include/wait_for_slave_to_start.inc;
+
+connection master;
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+
+########################################################################################
+#                             Case 2: Corrupt a master.info
+########################################################################################
+--echo =====Corrupting the master.info=======;
+connection slave;
+stop slave;
+source include/wait_for_slave_to_stop.inc;
+
+connection master;
+FLUSH LOGS;
+
+insert into t1(a) values(7);
+insert into t1(a) values(8);
+insert into t1(a) values(9);
+
+connection slave;
+--replace_result $MYSQLD_SLAVE_DATADIR MYSQLD_SLAVE_DATADIR
+--exec cat $MYSQLD_SLAVE_DATADIR/master.backup > $MYSQLD_SLAVE_DATADIR/master.info
+
+let MYSQLD_SLAVE_DATADIR=`select @@datadir`;
+
+--perl
+use strict;
+use warnings;
+my $src= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.backup";
+my $dst= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.info";
+open(FILE, "<", $src) or die;
+my @content= <FILE>;
+close FILE;
+open(FILE, ">", $dst) or die;
+binmode FILE;
+print FILE @content;
+close FILE;
+EOF
+
+--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
+SET SESSION debug="d,crash_before_rotate_relaylog";
+--error 2013
+FLUSH LOGS;
+
+--enable_reconnect
+--source include/wait_until_connected_again.inc
+
+--echo =====Dumping and comparing tables=======;
+start slave;
+source include/wait_for_slave_to_start.inc;
+
+connection master;
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+
+########################################################################################
+#                                      Clean up
+########################################################################################
+--echo =====Clean up=======;
+connection master;
+drop table t1;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_basic.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_basic.result
index b16a63ec5ade4b06b203c8e1680d6c6d66c59203..6680f3fd70fa27faa9ca729e867ca371e771b29c 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_basic.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_basic.result
@@ -179,6 +179,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	<Last_SQL_Errno>
 Last_SQL_Error	<Last_SQL_Error>
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 set GLOBAL slave_transaction_retries=10;
 include/start_slave.inc
 select * from t1 order by nid;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular.result
index 2daacb351a93b2f54071e44d4525a2eb66e26027..aeb9e215d157be2b645e3f9a6b65ac8c982ac768 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular.result
@@ -56,6 +56,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT * FROM t1 ORDER BY a;
 a	b
 1	2
@@ -99,5 +101,7 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	2
 STOP SLAVE;
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular_simplex.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular_simplex.result
index b6f32668c4293f649076129dc392cf08d48e8458..8eb7df3f89041f28803057eaaf1b618bb123d8c8 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular_simplex.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_circular_simplex.result
@@ -53,6 +53,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	2
 SELECT * FROM t1 ORDER BY a;
 a	b
 1	2
@@ -102,4 +104,6 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result
index f812509de6fce5b89e38432ffe86aafa51695fd2..8a32cff0cd3a17ad4af832d95fbbfb6304812523 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result
@@ -93,6 +93,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 size mismatch - master has size 10, test.t2 on slave has size 6. Master's column size should be <= the slave's column size.
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 STOP SLAVE;
 RESET SLAVE;
 SELECT * FROM t2 ORDER BY a;
@@ -160,6 +162,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 252, test.t3 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t3  ***
@@ -222,6 +226,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 246, test.t4 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t4  ***
@@ -284,6 +290,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 5 type mismatch - received type 4, test.t5 has type 246
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t5  ***
@@ -345,6 +353,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 3 type mismatch - received type 16, test.t6 has type 3
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=3;
 *** Drop t6  ***
 DROP TABLE t6;
@@ -400,62 +410,6 @@ set @b1 = concat(@b1,@b1);
 INSERT INTO t8 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
 *** Drop t8  ***
 DROP TABLE t8;
-STOP SLAVE;
-RESET SLAVE;
-CREATE TABLE t9 (a INT KEY, b BLOB, c CHAR(5),
-d TIMESTAMP,
-e INT NOT NULL) ENGINE='NDB';
-*** Create t9 on Master ***
-CREATE TABLE t9 (a INT PRIMARY KEY, b BLOB, c CHAR(5)
-) ENGINE='NDB';
-RESET MASTER;
-*** Start Slave ***
-START SLAVE;
-*** Master Data Insert ***
-set @b1 = 'b1b1b1b1';
-set @b1 = concat(@b1,@b1);
-INSERT INTO t9 () VALUES(1,@b1,'Kyle'),(2,@b1,'JOE'),(3,@b1,'QA');
-SHOW SLAVE STATUS;
-Slave_IO_State	#
-Master_Host	127.0.0.1
-Master_User	root
-Master_Port	#
-Connect_Retry	1
-Master_Log_File	master-bin.000001
-Read_Master_Log_Pos	#
-Relay_Log_File	#
-Relay_Log_Pos	#
-Relay_Master_Log_File	master-bin.000001
-Slave_IO_Running	Yes
-Slave_SQL_Running	No
-Replicate_Do_DB	
-Replicate_Ignore_DB	
-Replicate_Do_Table	
-Replicate_Ignore_Table	#
-Replicate_Wild_Do_Table	
-Replicate_Wild_Ignore_Table	
-Last_Errno	1364
-Last_Error	Could not execute Write_rows event on table test.t9; Field 'e' doesn't have a default value, Error_code: 1364; handler error HA_ERR_ROWS_EVENT_APPLY; the event's master log master-bin.000001, end_log_pos 447
-Skip_Counter	0
-Exec_Master_Log_Pos	#
-Relay_Log_Space	#
-Until_Condition	None
-Until_Log_File	
-Until_Log_Pos	0
-Master_SSL_Allowed	No
-Master_SSL_CA_File	
-Master_SSL_CA_Path	
-Master_SSL_Cert	
-Master_SSL_Cipher	
-Master_SSL_Key	
-Seconds_Behind_Master	#
-Master_SSL_Verify_Server_Cert	No
-Last_IO_Errno	#
-Last_IO_Error	#
-Last_SQL_Errno	1364
-Last_SQL_Error	Could not execute Write_rows event on table test.t9; Field 'e' doesn't have a default value, Error_code: 1364; handler error HA_ERR_ROWS_EVENT_APPLY; the event's master log master-bin.000001, end_log_pos 447
-SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
-START SLAVE;
 *** Create t10 on slave  ***
 STOP SLAVE;
 RESET SLAVE;
@@ -513,6 +467,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 254, test.t10 has type 5
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t10  ***
@@ -574,6 +530,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 2 type mismatch - received type 15, test.t11 has type 252
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 *** Drop t11  ***
@@ -824,6 +782,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1060
 Last_SQL_Error	Error 'Duplicate column name 'c6'' on query. Default database: 'test'. Query: 'ALTER TABLE t15 ADD COLUMN c6 INT AFTER c5'
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
 START SLAVE;
 *** Try to insert in master ****
@@ -964,6 +924,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	1535
 Last_SQL_Error	Table definition on master and slave does not match: Column 0 type mismatch - received type 8, test.t17 has type 2
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SET GLOBAL SQL_SLAVE_SKIP_COUNTER=2;
 START SLAVE;
 ** DROP table t17 ***
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_idempotent.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_idempotent.result
index e2fee391bab9402ea8995c8c15f6a8ec68b098e0..2df70ace0c1d8fd269a43f6966649889930089f6 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_idempotent.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_idempotent.result
@@ -33,15 +33,15 @@ c1	c2	c3
 row3	C	3
 row4	D	4
 SHOW SLAVE STATUS;
-Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error
-<Slave_IO_State>	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	<Read_Master_Log_Pos>	<Relay_Log_File>	<Relay_Log_Pos>	master-bin.000001	Yes	Yes				<Replicate_Ignore_Table>			0		0	<Exec_Master_Log_Pos>	<Relay_Log_Space>	None		0	No						<Seconds_Behind_Master>	No	<Last_IO_Errno>	<Last_IO_Error>	0	
+Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error	Replicate_Ignore_Server_Ids	Master_Server_Id
+<Slave_IO_State>	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	<Read_Master_Log_Pos>	<Relay_Log_File>	<Relay_Log_Pos>	master-bin.000001	Yes	Yes				<Replicate_Ignore_Table>			0		0	<Exec_Master_Log_Pos>	<Relay_Log_Space>	None		0	No						<Seconds_Behind_Master>	No	<Last_IO_Errno>	<Last_IO_Error>	0			1
 STOP SLAVE;
 CHANGE MASTER TO
 master_log_file = 'master-bin.000001',
 master_log_pos = <the_pos> ;
 SHOW SLAVE STATUS;
-Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error
-<Slave_IO_State>	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	<Read_Master_Log_Pos>	<Relay_Log_File>	<Relay_Log_Pos>	master-bin.000001	No	No				<Replicate_Ignore_Table>			0		0	<Exec_Master_Log_Pos>	<Relay_Log_Space>	None		0	No						<Seconds_Behind_Master>	No	<Last_IO_Errno>	<Last_IO_Error>	0	
+Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error	Replicate_Ignore_Server_Ids	Master_Server_Id
+<Slave_IO_State>	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	<Read_Master_Log_Pos>	<Relay_Log_File>	<Relay_Log_Pos>	master-bin.000001	No	No				<Replicate_Ignore_Table>			0		0	<Exec_Master_Log_Pos>	<Relay_Log_Space>	None		0	No						<Seconds_Behind_Master>	No	<Last_IO_Errno>	<Last_IO_Error>	0			1
 START SLAVE;
 SELECT * FROM t1 ORDER BY c3;
 c1	c2	c3
@@ -68,6 +68,6 @@ SELECT * FROM t1;
 c1	c2	c3
 row2	new on slave	2
 SHOW SLAVE STATUS;
-Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error
-<Slave_IO_State>	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	<Read_Master_Log_Pos>	<Relay_Log_File>	<Relay_Log_Pos>	master-bin.000001	Yes	Yes				<Replicate_Ignore_Table>			0		0	<Exec_Master_Log_Pos>	<Relay_Log_Space>	None		0	No						<Seconds_Behind_Master>	<Last_IO_Errno>	<Last_IO_Error>		0	
+Slave_IO_State	Master_Host	Master_User	Master_Port	Connect_Retry	Master_Log_File	Read_Master_Log_Pos	Relay_Log_File	Relay_Log_Pos	Relay_Master_Log_File	Slave_IO_Running	Slave_SQL_Running	Replicate_Do_DB	Replicate_Ignore_DB	Replicate_Do_Table	Replicate_Ignore_Table	Replicate_Wild_Do_Table	Replicate_Wild_Ignore_Table	Last_Errno	Last_Error	Skip_Counter	Exec_Master_Log_Pos	Relay_Log_Space	Until_Condition	Until_Log_File	Until_Log_Pos	Master_SSL_Allowed	Master_SSL_CA_File	Master_SSL_CA_Path	Master_SSL_Cert	Master_SSL_Cipher	Master_SSL_Key	Seconds_Behind_Master	Master_SSL_Verify_Server_Cert	Last_IO_Errno	Last_IO_Error	Last_SQL_Errno	Last_SQL_Error	Replicate_Ignore_Server_Ids	Master_Server_Id
+<Slave_IO_State>	127.0.0.1	root	MASTER_PORT	1	master-bin.000001	<Read_Master_Log_Pos>	<Relay_Log_File>	<Relay_Log_Pos>	master-bin.000001	Yes	Yes				<Replicate_Ignore_Table>			0		0	<Exec_Master_Log_Pos>	<Relay_Log_Space>	None		0	No						<Seconds_Behind_Master>	<Last_IO_Errno>	<Last_IO_Error>		0			1
 DROP TABLE IF EXISTS t1;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_log.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_log.result
index 540c430e75777327ebdb8d9ebd2a55b992c08369..301f4c2e45b28bf25cd93032802c50d1ff5cc6cd 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_log.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_log.result
@@ -34,14 +34,14 @@ master-bin.000001	#	Table_map	1	#	table_id: # (mysql.ndb_apply_status)
 master-bin.000001	#	Write_rows	1	#	table_id: #
 master-bin.000001	#	Write_rows	1	#	table_id: # flags: STMT_END_F
 master-bin.000001	#	Query	1	#	COMMIT
-show binlog events from 106 limit 1;
+show binlog events from 107 limit 1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=NDB
-show binlog events from 106 limit 2;
+show binlog events from 107 limit 2;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	1	#	use `test`; create table t1(n int not null auto_increment primary key)ENGINE=NDB
 master-bin.000001	#	Query	1	#	BEGIN
-show binlog events from 106 limit 2,1;
+show binlog events from 107 limit 2,1;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
 flush logs;
@@ -267,7 +267,7 @@ Master_User	root
 Master_Port	MASTER_PORT
 Connect_Retry	1
 Master_Log_File	master-bin.000002
-Read_Master_Log_Pos	623
+Read_Master_Log_Pos	624
 Relay_Log_File	#
 Relay_Log_Pos	#
 Relay_Master_Log_File	master-bin.000002
@@ -282,7 +282,7 @@ Replicate_Wild_Ignore_Table
 Last_Errno	0
 Last_Error	
 Skip_Counter	0
-Exec_Master_Log_Pos	623
+Exec_Master_Log_Pos	624
 Relay_Log_Space	#
 Until_Condition	None
 Until_Log_File	
@@ -299,6 +299,8 @@ Last_IO_Errno	#
 Last_IO_Error	#
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 show binlog events in 'slave-bin.000005' from 4;
 ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not find target log
 DROP TABLE t1;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_mixed_tables.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_mixed_tables.result
new file mode 100644
index 0000000000000000000000000000000000000000..43efc10c2e131292a0ce61df7f53f131a9f4ca81
--- /dev/null
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_mixed_tables.result
@@ -0,0 +1,246 @@
+==== Initialization ====
+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;
+---- setup master ----
+CREATE TABLE myisam_innodb (a INT) ENGINE=MYISAM;
+CREATE TABLE innodb_myisam (a INT) ENGINE=INNODB;
+CREATE TABLE myisam_ndb    (a INT) ENGINE=MYISAM;
+CREATE TABLE ndb_myisam    (a INT) ENGINE=NDB;
+CREATE TABLE innodb_ndb    (a INT) ENGINE=INNODB;
+CREATE TABLE ndb_innodb    (a INT) ENGINE=NDB;
+SHOW CREATE TABLE myisam_innodb;
+Table	Create Table
+myisam_innodb	CREATE TABLE `myisam_innodb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE innodb_myisam;
+Table	Create Table
+innodb_myisam	CREATE TABLE `innodb_myisam` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE myisam_ndb;
+Table	Create Table
+myisam_ndb	CREATE TABLE `myisam_ndb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE ndb_myisam;
+Table	Create Table
+ndb_myisam	CREATE TABLE `ndb_myisam` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+SHOW CREATE TABLE innodb_ndb;
+Table	Create Table
+innodb_ndb	CREATE TABLE `innodb_ndb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE ndb_innodb;
+Table	Create Table
+ndb_innodb	CREATE TABLE `ndb_innodb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+---- setup slave with different engines ----
+DROP TABLE myisam_innodb, innodb_myisam;
+DROP TABLE myisam_ndb, ndb_myisam;
+DROP TABLE innodb_ndb, ndb_innodb;
+CREATE TABLE myisam_innodb (a INT) ENGINE=INNODB;
+CREATE TABLE innodb_myisam (a INT) ENGINE=MYISAM;
+CREATE TABLE myisam_ndb    (a INT) ENGINE=NDB;
+CREATE TABLE ndb_myisam    (a INT) ENGINE=MYISAM;
+CREATE TABLE innodb_ndb    (a INT) ENGINE=NDB;
+CREATE TABLE ndb_innodb    (a INT) ENGINE=INNODB;
+SHOW CREATE TABLE myisam_innodb;
+Table	Create Table
+myisam_innodb	CREATE TABLE `myisam_innodb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE innodb_myisam;
+Table	Create Table
+innodb_myisam	CREATE TABLE `innodb_myisam` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE myisam_ndb;
+Table	Create Table
+myisam_ndb	CREATE TABLE `myisam_ndb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+SHOW CREATE TABLE ndb_myisam;
+Table	Create Table
+ndb_myisam	CREATE TABLE `ndb_myisam` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE innodb_ndb;
+Table	Create Table
+innodb_ndb	CREATE TABLE `innodb_ndb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+SHOW CREATE TABLE ndb_innodb;
+Table	Create Table
+ndb_innodb	CREATE TABLE `ndb_innodb` (
+  `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+==== AUTOCOMMIT=0, transactions ====
+---- COMMIT ----
+SET AUTOCOMMIT = 0;
+BEGIN;
+INSERT INTO myisam_innodb VALUES (1);
+INSERT INTO myisam_innodb VALUES (2);
+COMMIT;
+BEGIN;
+INSERT INTO innodb_myisam VALUES (3);
+INSERT INTO innodb_myisam VALUES (4);
+COMMIT;
+BEGIN;
+INSERT INTO myisam_ndb VALUES (5);
+INSERT INTO myisam_ndb VALUES (6);
+COMMIT;
+BEGIN;
+INSERT INTO ndb_myisam VALUES (7);
+INSERT INTO ndb_myisam VALUES (8);
+COMMIT;
+BEGIN;
+INSERT INTO ndb_innodb VALUES (9);
+INSERT INTO ndb_innodb VALUES (10);
+COMMIT;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (11);
+INSERT INTO innodb_ndb VALUES (12);
+COMMIT;
+---- ROLLBACK ----
+BEGIN;
+INSERT INTO innodb_myisam VALUES (15);
+INSERT INTO innodb_myisam VALUES (16);
+ROLLBACK;
+BEGIN;
+INSERT INTO ndb_myisam VALUES (19);
+INSERT INTO ndb_myisam VALUES (20);
+ROLLBACK;
+BEGIN;
+INSERT INTO ndb_innodb VALUES (21);
+INSERT INTO ndb_innodb VALUES (22);
+ROLLBACK;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (23);
+INSERT INTO innodb_ndb VALUES (24);
+ROLLBACK;
+==== AUTOCOMMIT=1, transactions ====
+---- COMMIT ----
+SET AUTOCOMMIT = 1;
+BEGIN;
+INSERT INTO myisam_innodb VALUES (25);
+INSERT INTO myisam_innodb VALUES (26);
+COMMIT;
+BEGIN;
+INSERT INTO innodb_myisam VALUES (27);
+INSERT INTO innodb_myisam VALUES (28);
+COMMIT;
+BEGIN;
+INSERT INTO myisam_ndb VALUES (29);
+INSERT INTO myisam_ndb VALUES (30);
+COMMIT;
+BEGIN;
+INSERT INTO ndb_myisam VALUES (31);
+INSERT INTO ndb_myisam VALUES (32);
+COMMIT;
+BEGIN;
+INSERT INTO ndb_innodb VALUES (33);
+INSERT INTO ndb_innodb VALUES (34);
+COMMIT;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (35);
+INSERT INTO innodb_ndb VALUES (36);
+COMMIT;
+---- ROLLBACK ----
+BEGIN;
+INSERT INTO innodb_myisam VALUES (39);
+INSERT INTO innodb_myisam VALUES (40);
+ROLLBACK;
+BEGIN;
+INSERT INTO ndb_myisam VALUES (43);
+INSERT INTO ndb_myisam VALUES (44);
+ROLLBACK;
+BEGIN;
+INSERT INTO ndb_innodb VALUES (45);
+INSERT INTO ndb_innodb VALUES (46);
+ROLLBACK;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (47);
+INSERT INTO innodb_ndb VALUES (48);
+ROLLBACK;
+==== AUTOCOMMIT=1, single statements ====
+INSERT INTO myisam_innodb VALUES (49);
+INSERT INTO myisam_innodb VALUES (50);
+INSERT INTO innodb_myisam VALUES (51);
+INSERT INTO innodb_myisam VALUES (52);
+INSERT INTO myisam_ndb VALUES (53);
+INSERT INTO myisam_ndb VALUES (54);
+INSERT INTO ndb_myisam VALUES (55);
+INSERT INTO ndb_myisam VALUES (56);
+INSERT INTO ndb_innodb VALUES (57);
+INSERT INTO ndb_innodb VALUES (58);
+INSERT INTO innodb_ndb VALUES (59);
+INSERT INTO innodb_ndb VALUES (60);
+==== AUTOCOMMIT=0, single statements, myisam on master ====
+SET AUTOCOMMIT = 0;
+==== Show results ====
+SELECT * FROM myisam_innodb ORDER BY a;
+a
+1
+2
+25
+26
+49
+50
+SELECT * FROM innodb_myisam ORDER BY a;
+a
+3
+4
+27
+28
+51
+52
+SELECT * FROM myisam_ndb    ORDER BY a;
+a
+5
+6
+29
+30
+53
+54
+SELECT * FROM ndb_myisam    ORDER BY a;
+a
+7
+8
+31
+32
+55
+56
+SELECT * FROM innodb_ndb    ORDER BY a;
+a
+11
+12
+35
+36
+59
+60
+SELECT * FROM ndb_innodb    ORDER BY a;
+a
+9
+10
+33
+34
+57
+58
+Comparing tables master:test.myisam_innodb and slave:test.myisam_innodb
+Comparing tables master:test.innodb_myisam and slave:test.innodb_myisam
+Comparing tables master:test.myisam_ndb and slave:test.myisam_ndb
+Comparing tables master:test.ndb_myisam and slave:test.ndb_myisam
+Comparing tables master:test.innodb_ndb and slave:test.innodb_ndb
+Comparing tables master:test.ndb_innodb and slave:test.ndb_innodb
+==== Clean up ====
+drop table myisam_innodb, innodb_myisam;
+drop table myisam_ndb, ndb_myisam;
+drop table innodb_ndb, ndb_innodb;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_multi.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_multi.result
index f8eb5ebdd890eae047bec3a7b861feaec0edaea2..66eeaa6357c555e7806f1f688c7b4939e64f060c 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_multi.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_multi.result
@@ -26,11 +26,11 @@ stop slave;
 SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1)
 FROM mysql.ndb_binlog_index WHERE epoch = <the_epoch> ;
 @the_pos:=Position	@the_file:=SUBSTRING_INDEX(FILE, '/', -1)
-106	master-bin.000001
+107	master-bin.000001
 CHANGE MASTER TO
 master_port=<MASTER_PORT1>,
 master_log_file = 'master-bin.000001',
-master_log_pos = 106 ;
+master_log_pos = 107 ;
 start slave;
 INSERT INTO t1 VALUES ("row2","will go away",2),("row3","will change",3),("row4","D",4);
 DELETE FROM t1 WHERE c3 = 1;
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_ndb_sync.result b/mysql-test/suite/rpl_ndb/r/rpl_ndb_sync.result
index 3ef5e2b7e533ae368e301f3dc73413417ccb7824..b61f5550719b028975c4e7872a9fc854596af72c 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_sync.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_sync.result
@@ -107,6 +107,8 @@ Last_IO_Errno	<Last_IO_Errno>
 Last_IO_Error	<Last_IO_Error>
 Last_SQL_Errno	0
 Last_SQL_Error	
+Replicate_Ignore_Server_Ids	
+Master_Server_Id	1
 SELECT hex(c1),hex(c2),c3 FROM t1 ORDER BY c3;
 hex(c1)	hex(c2)	c3
 1	1	row1
diff --git a/mysql-test/suite/rpl_ndb/r/rpl_truncate_7ndb.result b/mysql-test/suite/rpl_ndb/r/rpl_truncate_7ndb.result
index d6c57aed41b130e1ff1fe1e7ce6d9007ccc89982..6c9e20fd56ae1d9dff4671458aa06d910eec09bb 100644
--- a/mysql-test/suite/rpl_ndb/r/rpl_truncate_7ndb.result
+++ b/mysql-test/suite/rpl_ndb/r/rpl_truncate_7ndb.result
@@ -29,16 +29,16 @@ a	b
 DROP TABLE t1;
 SHOW BINLOG EVENTS;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: SERVER_VERSION, Binlog ver: 4
-master-bin.000001	106	Query	1	223	use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB
-master-bin.000001	223	Query	1	287	BEGIN
-master-bin.000001	287	Table_map	1	330	table_id: # (test.t1)
-master-bin.000001	330	Table_map	1	392	table_id: # (mysql.ndb_apply_status)
-master-bin.000001	392	Write_rows	1	451	table_id: #
-master-bin.000001	451	Write_rows	1	498	table_id: # flags: STMT_END_F
-master-bin.000001	498	Query	1	563	COMMIT
-master-bin.000001	563	Query	1	643	use `test`; TRUNCATE TABLE t1
-master-bin.000001	643	Query	1	719	use `test`; DROP TABLE t1
+master-bin.000001	4	Format_desc	1	107	Server ver: SERVER_VERSION, Binlog ver: 4
+master-bin.000001	107	Query	1	224	use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB
+master-bin.000001	224	Query	1	288	BEGIN
+master-bin.000001	288	Table_map	1	331	table_id: # (test.t1)
+master-bin.000001	331	Table_map	1	393	table_id: # (mysql.ndb_apply_status)
+master-bin.000001	393	Write_rows	1	452	table_id: #
+master-bin.000001	452	Write_rows	1	499	table_id: # flags: STMT_END_F
+master-bin.000001	499	Query	1	564	COMMIT
+master-bin.000001	564	Query	1	644	use `test`; TRUNCATE TABLE t1
+master-bin.000001	644	Query	1	720	use `test`; DROP TABLE t1
 **** On Master ****
 CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB;
 INSERT INTO t1 VALUES (1,1), (2,2);
@@ -65,27 +65,27 @@ a	b
 DROP TABLE t1;
 SHOW BINLOG EVENTS;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
-master-bin.000001	4	Format_desc	1	106	Server ver: SERVER_VERSION, Binlog ver: 4
-master-bin.000001	106	Query	1	223	use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB
-master-bin.000001	223	Query	1	287	BEGIN
-master-bin.000001	287	Table_map	1	330	table_id: # (test.t1)
-master-bin.000001	330	Table_map	1	392	table_id: # (mysql.ndb_apply_status)
-master-bin.000001	392	Write_rows	1	451	table_id: #
-master-bin.000001	451	Write_rows	1	498	table_id: # flags: STMT_END_F
-master-bin.000001	498	Query	1	563	COMMIT
-master-bin.000001	563	Query	1	643	use `test`; TRUNCATE TABLE t1
-master-bin.000001	643	Query	1	719	use `test`; DROP TABLE t1
-master-bin.000001	719	Query	1	836	use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB
-master-bin.000001	836	Query	1	900	BEGIN
-master-bin.000001	900	Table_map	1	943	table_id: # (test.t1)
-master-bin.000001	943	Table_map	1	1005	table_id: # (mysql.ndb_apply_status)
-master-bin.000001	1005	Write_rows	1	1064	table_id: #
-master-bin.000001	1064	Write_rows	1	1111	table_id: # flags: STMT_END_F
-master-bin.000001	1111	Query	1	1176	COMMIT
-master-bin.000001	1176	Query	1	1240	BEGIN
-master-bin.000001	1240	Table_map	1	1283	table_id: # (test.t1)
-master-bin.000001	1283	Table_map	1	1345	table_id: # (mysql.ndb_apply_status)
-master-bin.000001	1345	Write_rows	1	1404	table_id: #
-master-bin.000001	1404	Delete_rows	1	1443	table_id: # flags: STMT_END_F
-master-bin.000001	1443	Query	1	1508	COMMIT
-master-bin.000001	1508	Query	1	1584	use `test`; DROP TABLE t1
+master-bin.000001	4	Format_desc	1	107	Server ver: SERVER_VERSION, Binlog ver: 4
+master-bin.000001	107	Query	1	224	use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB
+master-bin.000001	224	Query	1	288	BEGIN
+master-bin.000001	288	Table_map	1	331	table_id: # (test.t1)
+master-bin.000001	331	Table_map	1	393	table_id: # (mysql.ndb_apply_status)
+master-bin.000001	393	Write_rows	1	452	table_id: #
+master-bin.000001	452	Write_rows	1	499	table_id: # flags: STMT_END_F
+master-bin.000001	499	Query	1	564	COMMIT
+master-bin.000001	564	Query	1	644	use `test`; TRUNCATE TABLE t1
+master-bin.000001	644	Query	1	720	use `test`; DROP TABLE t1
+master-bin.000001	720	Query	1	837	use `test`; CREATE TABLE t1 (a INT PRIMARY KEY, b LONG) ENGINE=NDB
+master-bin.000001	837	Query	1	901	BEGIN
+master-bin.000001	901	Table_map	1	944	table_id: # (test.t1)
+master-bin.000001	944	Table_map	1	1006	table_id: # (mysql.ndb_apply_status)
+master-bin.000001	1006	Write_rows	1	1065	table_id: #
+master-bin.000001	1065	Write_rows	1	1112	table_id: # flags: STMT_END_F
+master-bin.000001	1112	Query	1	1177	COMMIT
+master-bin.000001	1177	Query	1	1241	BEGIN
+master-bin.000001	1241	Table_map	1	1284	table_id: # (test.t1)
+master-bin.000001	1284	Table_map	1	1346	table_id: # (mysql.ndb_apply_status)
+master-bin.000001	1346	Write_rows	1	1405	table_id: #
+master-bin.000001	1405	Delete_rows	1	1444	table_id: # flags: STMT_END_F
+master-bin.000001	1444	Query	1	1509	COMMIT
+master-bin.000001	1509	Query	1	1585	use `test`; DROP TABLE t1
diff --git a/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables-master.opt b/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables-master.opt
new file mode 100644
index 0000000000000000000000000000000000000000..b74354b22e173788d99c6df8246d16d801ed95e6
--- /dev/null
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables-master.opt
@@ -0,0 +1 @@
+--innodb --ndbcluster
diff --git a/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables-slave.opt b/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables-slave.opt
new file mode 100644
index 0000000000000000000000000000000000000000..bbb86b2991b80ded6cad2e8473e18d11443b2585
--- /dev/null
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables-slave.opt
@@ -0,0 +1 @@
+--innodb --ndbcluster --replicate-ignore-table=mysql.ndb_apply_status
diff --git a/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables.test b/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables.test
new file mode 100644
index 0000000000000000000000000000000000000000..a20e42f1b24fa0ad69cce7fc5afee1371696c65c
--- /dev/null
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_mixed_tables.test
@@ -0,0 +1,373 @@
+# ==== Purpose ====
+#
+# Test replication of transactions on tables which have different
+# engines on master and slave.  This tests all combinations of innodb,
+# myisam, and ndb.
+#
+# ==== Method ====
+#
+# Set up six tables, each being innodb, myisam, or innodb on master,
+# and another of innodb, myisam, or innodb on slave.  For each table,
+# do the following:
+#
+#  - committed and rollback'ed transactions, with autocommit on and
+#    off
+#  - non-transactions with autocommit on
+#  - non-transactions with autocommit off, where the master table is
+#    myisam.
+#
+# Note: we are running the slave with
+# --replicate-ignore-table=mysql.ndb_apply_status .  See BUG#34557 for
+# explanation.
+#
+# ==== Related bugs ====
+#
+# BUG#26395: if crash during autocommit update to transactional table on master, slave fails
+# BUG#29288: myisam transactions replicated to a transactional slave leaves slave unstable
+# BUG#34557: Row-based replication from ndb to non-ndb gives error on slave
+# BUG#34600: Rolled-back punch transactions not replicated correctly
+#
+# ==== Todo ====
+#
+# We should eventually try transactions touching two tables which are
+# of different engines on the same server (so that we try, e.g. punch
+# transactions; cf BUG#34600).  However, that will make the test much
+# bigger (9 master-slave engine combinations [myisam->myisam,
+# myisam->ndb, etc].  To try all combinations of one or more such
+# tables means 2^9-1=511 transactions.  We need to multiplied by 5
+# since we want to test committed/rollback'ed transactions
+# with/without AUTOCOMMIT, as well as non-transactions with
+# autocommit).  We'd have to write a script to produce the test case.
+
+
+--echo ==== Initialization ====
+
+--source include/have_ndb.inc
+--source include/have_innodb.inc
+--source include/ndb_master-slave.inc
+
+--echo ---- setup master ----
+
+CREATE TABLE myisam_innodb (a INT) ENGINE=MYISAM;
+CREATE TABLE innodb_myisam (a INT) ENGINE=INNODB;
+CREATE TABLE myisam_ndb    (a INT) ENGINE=MYISAM;
+CREATE TABLE ndb_myisam    (a INT) ENGINE=NDB;
+CREATE TABLE innodb_ndb    (a INT) ENGINE=INNODB;
+CREATE TABLE ndb_innodb    (a INT) ENGINE=NDB;
+
+SHOW CREATE TABLE myisam_innodb;
+SHOW CREATE TABLE innodb_myisam;
+SHOW CREATE TABLE myisam_ndb;
+SHOW CREATE TABLE ndb_myisam;
+SHOW CREATE TABLE innodb_ndb;
+SHOW CREATE TABLE ndb_innodb;
+
+--echo ---- setup slave with different engines ----
+
+sync_slave_with_master;
+
+DROP TABLE myisam_innodb, innodb_myisam;
+DROP TABLE myisam_ndb, ndb_myisam;
+DROP TABLE innodb_ndb, ndb_innodb;
+
+CREATE TABLE myisam_innodb (a INT) ENGINE=INNODB;
+CREATE TABLE innodb_myisam (a INT) ENGINE=MYISAM;
+CREATE TABLE myisam_ndb    (a INT) ENGINE=NDB;
+CREATE TABLE ndb_myisam    (a INT) ENGINE=MYISAM;
+CREATE TABLE innodb_ndb    (a INT) ENGINE=NDB;
+CREATE TABLE ndb_innodb    (a INT) ENGINE=INNODB;
+
+SHOW CREATE TABLE myisam_innodb;
+SHOW CREATE TABLE innodb_myisam;
+SHOW CREATE TABLE myisam_ndb;
+SHOW CREATE TABLE ndb_myisam;
+SHOW CREATE TABLE innodb_ndb;
+SHOW CREATE TABLE ndb_innodb;
+
+connection master;
+
+
+--echo ==== AUTOCOMMIT=0, transactions ====
+
+--echo ---- COMMIT ----
+
+SET AUTOCOMMIT = 0;
+
+BEGIN;
+INSERT INTO myisam_innodb VALUES (1);
+INSERT INTO myisam_innodb VALUES (2);
+COMMIT;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO innodb_myisam VALUES (3);
+INSERT INTO innodb_myisam VALUES (4);
+COMMIT;
+sync_slave_with_master;
+connection master;
+
+BEGIN;
+INSERT INTO myisam_ndb VALUES (5);
+INSERT INTO myisam_ndb VALUES (6);
+COMMIT;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO ndb_myisam VALUES (7);
+INSERT INTO ndb_myisam VALUES (8);
+COMMIT;
+sync_slave_with_master;
+connection master;
+
+BEGIN;
+INSERT INTO ndb_innodb VALUES (9);
+INSERT INTO ndb_innodb VALUES (10);
+COMMIT;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (11);
+INSERT INTO innodb_ndb VALUES (12);
+COMMIT;
+sync_slave_with_master;
+connection master;
+
+--echo ---- ROLLBACK ----
+
+# This test does not work in ROW mode after the changes introduced in
+# BUG#40116. After WL#2687 is pushed, Tests should be added again.
+--disable_parsing
+BEGIN;
+INSERT INTO myisam_innodb VALUES (13);
+INSERT INTO myisam_innodb VALUES (14);
+ROLLBACK;
+sync_slave_with_master;
+--enable_parsing
+connection master;
+BEGIN;
+INSERT INTO innodb_myisam VALUES (15);
+INSERT INTO innodb_myisam VALUES (16);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+
+# This test does not work in ROW mode after the changes introduced in
+# BUG#40116. After WL#2687 is pushed, these tests should be enabled
+# again.
+--disable_parsing
+BEGIN;
+INSERT INTO myisam_ndb VALUES (17);
+INSERT INTO myisam_ndb VALUES (18);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+--enable_parsing
+BEGIN;
+INSERT INTO ndb_myisam VALUES (19);
+INSERT INTO ndb_myisam VALUES (20);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+
+BEGIN;
+INSERT INTO ndb_innodb VALUES (21);
+INSERT INTO ndb_innodb VALUES (22);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (23);
+INSERT INTO innodb_ndb VALUES (24);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+
+
+--echo ==== AUTOCOMMIT=1, transactions ====
+
+--echo ---- COMMIT ----
+
+SET AUTOCOMMIT = 1;
+
+BEGIN;
+INSERT INTO myisam_innodb VALUES (25);
+INSERT INTO myisam_innodb VALUES (26);
+COMMIT;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO innodb_myisam VALUES (27);
+INSERT INTO innodb_myisam VALUES (28);
+COMMIT;
+sync_slave_with_master;
+connection master;
+
+BEGIN;
+INSERT INTO myisam_ndb VALUES (29);
+INSERT INTO myisam_ndb VALUES (30);
+COMMIT;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO ndb_myisam VALUES (31);
+INSERT INTO ndb_myisam VALUES (32);
+COMMIT;
+sync_slave_with_master;
+connection master;
+
+BEGIN;
+INSERT INTO ndb_innodb VALUES (33);
+INSERT INTO ndb_innodb VALUES (34);
+COMMIT;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (35);
+INSERT INTO innodb_ndb VALUES (36);
+COMMIT;
+sync_slave_with_master;
+connection master;
+
+--echo ---- ROLLBACK ----
+
+# This test does not work in ROW mode after the changes introduced in
+# BUG#40116. After WL#2687 is pushed, these tests should be enabled
+# again.
+--disable_parsing
+BEGIN;
+INSERT INTO myisam_innodb VALUES (37);
+INSERT INTO myisam_innodb VALUES (38);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+--enable_parsing
+BEGIN;
+INSERT INTO innodb_myisam VALUES (39);
+INSERT INTO innodb_myisam VALUES (40);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+
+# This test does not work in ROW mode after the changes introduced in
+# BUG#40116. After WL#2687 is pushed, these tests should be enabled
+# again.
+--disable_parsing
+BEGIN;
+INSERT INTO myisam_ndb VALUES (41);
+INSERT INTO myisam_ndb VALUES (42);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+--enable_parsing
+BEGIN;
+INSERT INTO ndb_myisam VALUES (43);
+INSERT INTO ndb_myisam VALUES (44);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+
+BEGIN;
+INSERT INTO ndb_innodb VALUES (45);
+INSERT INTO ndb_innodb VALUES (46);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+BEGIN;
+INSERT INTO innodb_ndb VALUES (47);
+INSERT INTO innodb_ndb VALUES (48);
+ROLLBACK;
+sync_slave_with_master;
+connection master;
+
+
+--echo ==== AUTOCOMMIT=1, single statements ====
+
+INSERT INTO myisam_innodb VALUES (49);
+INSERT INTO myisam_innodb VALUES (50);
+sync_slave_with_master;
+connection master;
+INSERT INTO innodb_myisam VALUES (51);
+INSERT INTO innodb_myisam VALUES (52);
+sync_slave_with_master;
+connection master;
+
+INSERT INTO myisam_ndb VALUES (53);
+INSERT INTO myisam_ndb VALUES (54);
+sync_slave_with_master;
+connection master;
+INSERT INTO ndb_myisam VALUES (55);
+INSERT INTO ndb_myisam VALUES (56);
+sync_slave_with_master;
+connection master;
+
+INSERT INTO ndb_innodb VALUES (57);
+INSERT INTO ndb_innodb VALUES (58);
+sync_slave_with_master;
+connection master;
+INSERT INTO innodb_ndb VALUES (59);
+INSERT INTO innodb_ndb VALUES (60);
+sync_slave_with_master;
+connection master;
+
+
+--echo ==== AUTOCOMMIT=0, single statements, myisam on master ====
+
+SET AUTOCOMMIT = 0;
+
+# These tests do not work in ROW mode after the changes introduced in
+# BUG#40116. After WL#2687 is pushed, these tests should be enabled
+# again.
+--disable_parsing
+# This tests BUG#29288.
+INSERT INTO myisam_innodb VALUES (61);
+INSERT INTO myisam_innodb VALUES (62);
+sync_slave_with_master;
+connection master;
+
+INSERT INTO myisam_ndb VALUES (63);
+INSERT INTO myisam_ndb VALUES (64);
+sync_slave_with_master;
+connection master;
+--enable_parsing
+
+
+--echo ==== Show results ====
+
+SELECT * FROM myisam_innodb ORDER BY a;
+SELECT * FROM innodb_myisam ORDER BY a;
+SELECT * FROM myisam_ndb    ORDER BY a;
+SELECT * FROM ndb_myisam    ORDER BY a;
+SELECT * FROM innodb_ndb    ORDER BY a;
+SELECT * FROM ndb_innodb    ORDER BY a;
+
+let $diff_table_1=master:test.myisam_innodb;
+let $diff_table_2=slave:test.myisam_innodb;
+source include/diff_tables.inc;
+
+let $diff_table_1=master:test.innodb_myisam;
+let $diff_table_2=slave:test.innodb_myisam;
+source include/diff_tables.inc;
+
+let $diff_table_1=master:test.myisam_ndb;
+let $diff_table_2=slave:test.myisam_ndb;
+source include/diff_tables.inc;
+
+let $diff_table_1=master:test.ndb_myisam;
+let $diff_table_2=slave:test.ndb_myisam;
+source include/diff_tables.inc;
+
+let $diff_table_1=master:test.innodb_ndb;
+let $diff_table_2=slave:test.innodb_ndb;
+source include/diff_tables.inc;
+
+let $diff_table_1=master:test.ndb_innodb;
+let $diff_table_2=slave:test.ndb_innodb;
+source include/diff_tables.inc;
+
+
+--echo ==== Clean up ====
+
+drop table myisam_innodb, innodb_myisam;
+drop table myisam_ndb, ndb_myisam;
+drop table innodb_ndb, ndb_innodb;
+sync_slave_with_master;
diff --git a/mysql-test/suite/sys_vars/r/read_only_func.result b/mysql-test/suite/sys_vars/r/read_only_func.result
index 35b42d468d6e5bb76d7e7fe13982adfed9ca3ecd..7e98b7adc5087b4c999c8a056803215b5f100110 100644
--- a/mysql-test/suite/sys_vars/r/read_only_func.result
+++ b/mysql-test/suite/sys_vars/r/read_only_func.result
@@ -20,7 +20,7 @@ id	name
 CREATE user sameea;
 ** Connecting connn using username 'sameea' **
 SET Global read_ONLY=ON;
-ERROR 42000: Access denied; you need the SUPER privilege for this operation
+ERROR 42000: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
 CREATE TABLE t2
 (
 id INT NOT NULL auto_increment,
diff --git a/mysql-test/t/ctype_cp932_binlog_stm.test b/mysql-test/t/ctype_cp932_binlog_stm.test
index 89df33a6df59f3c0b08cf6d425a4eb9a57210c85..af6e6baf92ab76fa725cc3d49103cd7777bd7a13 100644
--- a/mysql-test/t/ctype_cp932_binlog_stm.test
+++ b/mysql-test/t/ctype_cp932_binlog_stm.test
@@ -22,18 +22,18 @@ CALL bug18293("Foo's a Bar", _cp932 0xED40ED41ED42, 47.93)|
 SELECT HEX(s1),HEX(s2),d FROM t4|
 DROP PROCEDURE bug18293|
 DROP TABLE t4|
-SHOW BINLOG EVENTS FROM 370|
+SHOW BINLOG EVENTS FROM 371|
 delimiter ;|
 
 --echo End of 5.0 tests
 
 #
 # #28436: Incorrect position in SHOW BINLOG EVENTS causes server coredump 
-# Note: 364 is a magic position (found experimentally, depends on 
+# Note: 365 is a magic position (found experimentally, depends on 
 # the log's contents) that caused the server crash.
 
 --error 1220
-SHOW BINLOG EVENTS FROM 365;
+SHOW BINLOG EVENTS FROM 366;
 
 --echo Bug#44352 UPPER/LOWER function doesn't work correctly on cp932 and sjis environment.
 CREATE TABLE t1 (a varchar(16)) character set cp932;
diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test
index 78661b1bbc4e5f81f80b0b5329b20e7455c7baab..1e5ce4cb0e118b410d3f6e22c1df38f840432be8 100644
--- a/mysql-test/t/mysqlbinlog.test
+++ b/mysql-test/t/mysqlbinlog.test
@@ -71,8 +71,7 @@ select "--- --position --" as "";
 --enable_query_log
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
---exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=330 $MYSQLD_DATADIR/master-bin.000002
-
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --position=331 $MYSQLD_DATADIR/master-bin.000002
 
 # These are tests for remote binlog.
 # They should return the same as previous test.
@@ -108,7 +107,7 @@ select "--- --position --" as "";
 --enable_query_log
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
 --replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/
---exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --position=330 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002
+--exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ --read-from-remote-server --position=331 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000002
 
 # Bug#7853 mysqlbinlog does not accept input from stdin
 --disable_query_log
@@ -443,3 +442,27 @@ FLUSH LOGS;
 --echo End of 5.0 tests
 
 --echo End of 5.1 tests
+
+#
+# BUG#38468 Memory leak detected when using mysqlbinlog utility;
+#
+disable_query_log;
+RESET MASTER;
+CREATE TABLE t1 SELECT 1;
+FLUSH LOGS;
+DROP TABLE t1;
+enable_query_log;
+
+# Write an empty file for comparison
+write_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
+EOF
+
+# Before fix of BUG#38468, this would generate some warnings
+--exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 >/dev/null 2> $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn
+
+# Make sure the command above does not generate any error or warnings
+diff_files $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
+
+# Cleanup for this part of test
+remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn.empty;
+remove_file $MYSQLTEST_VARDIR/tmp/mysqlbinlog.warn;
diff --git a/mysql-test/t/mysqlbinlog2.test b/mysql-test/t/mysqlbinlog2.test
index d6be029ea56de87fa3555fd47e1fdf03bdacdb98..6089b83e42d4bc48d70b8b35e53891cc205267d6 100644
--- a/mysql-test/t/mysqlbinlog2.test
+++ b/mysql-test/t/mysqlbinlog2.test
@@ -50,15 +50,15 @@ select "--- offset --" as "";
 --disable_query_log
 select "--- start-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --start-position=608 $MYSQLD_DATADIR/master-bin.000001 
+--exec $MYSQL_BINLOG --short-form --start-position=609 $MYSQLD_DATADIR/master-bin.000001 
 --disable_query_log
 select "--- stop-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --stop-position=608 $MYSQLD_DATADIR/master-bin.000001 
+--exec $MYSQL_BINLOG --short-form --stop-position=609 $MYSQLD_DATADIR/master-bin.000001 
 --disable_query_log
 select "--- start and stop positions ---" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --start-position=608 --stop-position 725 $MYSQLD_DATADIR/master-bin.000001 
+--exec $MYSQL_BINLOG --short-form --start-position=609 --stop-position 726 $MYSQLD_DATADIR/master-bin.000001 
 --disable_query_log
 select "--- start-datetime --" as "";
 --enable_query_log
@@ -84,11 +84,11 @@ select "--- offset --" as "";
 --disable_query_log
 select "--- start-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --start-position=608 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
+--exec $MYSQL_BINLOG --short-form --start-position=609 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
 --disable_query_log
 select "--- stop-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --stop-position=134 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
+--exec $MYSQL_BINLOG --short-form --stop-position=135 $MYSQLD_DATADIR/master-bin.000001 $MYSQLD_DATADIR/master-bin.000002
 --disable_query_log
 select "--- start-datetime --" as "";
 --enable_query_log
@@ -111,15 +111,15 @@ select "--- offset --" as "";
 --disable_query_log
 select "--- start-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --start-position=608 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
+--exec $MYSQL_BINLOG --short-form --start-position=609 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
 --disable_query_log
 select "--- stop-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --stop-position=608 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
+--exec $MYSQL_BINLOG --short-form --stop-position=609 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
 --disable_query_log
 select "--- start and stop positions ---" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --start-position=608 --stop-position 725 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
+--exec $MYSQL_BINLOG --short-form --start-position=609 --stop-position 726 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001
 --disable_query_log
 select "--- start-datetime --" as "";
 --enable_query_log
@@ -142,11 +142,11 @@ select "--- offset --" as "";
 --disable_query_log
 select "--- start-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --start-position=608 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
+--exec $MYSQL_BINLOG --short-form --start-position=609 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
 --disable_query_log
 select "--- stop-position --" as "";
 --enable_query_log
---exec $MYSQL_BINLOG --short-form --stop-position=134 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
+--exec $MYSQL_BINLOG --short-form --stop-position=135 --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001  master-bin.000002
 --disable_query_log
 select "--- start-datetime --" as "";
 --enable_query_log
diff --git a/mysql-test/t/sp_trans_log.test b/mysql-test/t/sp_trans_log.test
index 2f2b84a9bef1d89c489de3d4c0fbc8ea23d1f8ad..68467f71ee15faaae361da8b0905289adb38bb90 100644
--- a/mysql-test/t/sp_trans_log.test
+++ b/mysql-test/t/sp_trans_log.test
@@ -35,7 +35,8 @@ reset master|
 --error ER_DUP_ENTRY
 insert into t2 values (bug23333(),1)| 
 --replace_column 2 # 5 # 6 #
-show binlog events from 106 /* with fixes for #23333 will show there is the query */|
+# the following must show there is (are) events after the query */
+source include/show_binlog_events.inc|
 select count(*),@a from t1 /* must be 1,1 */|
 
 delimiter ;|
diff --git a/mysys/default.c b/mysys/default.c
index 1c021b4584f0ac44454529113f69c0595da09346..6468cf2b35d4157158f343e0bb58bbd22daf47ef 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -41,6 +41,29 @@
 #include <winbase.h>
 #endif
 
+/**
+   arguments separator
+
+   load_defaults() loads arguments from config file and put them
+   before the arguments from command line, this separator is used to
+   separate the arguments loaded from config file and arguments user
+   provided on command line.
+
+   Options with value loaded from config file are always in the form
+   '--option=value', while for command line options, the value can be
+   given as the next argument. Thus we used a separator so that
+   handle_options() can distinguish them.
+
+   Note: any other places that does not need to distinguish them
+   should skip the separator.
+
+   The content of arguments separator does not matter, one should only
+   check the pointer, use "----args-separator----" here to ease debug
+   if someone misused it.
+
+   See BUG#25192
+*/
+const char *args_separator= "----args-separator----";
 const char *my_defaults_file=0;
 const char *my_defaults_group_suffix=0;
 char *my_defaults_extra_file=0;
@@ -454,10 +477,11 @@ int my_load_defaults(const char *conf_file, const char **groups,
       goto err;
     res= (char**) (ptr+sizeof(alloc));
     res[0]= **argv;				/* Copy program name */
+    /* set arguments separator */
+    res[1]= (char *)args_separator;
     for (i=2 ; i < (uint) *argc ; i++)
-      res[i-1]=argv[0][i];
-    res[i-1]=0;					/* End pointer */
-    (*argc)--;
+      res[i]=argv[0][i];
+    res[i]=0;					/* End pointer */
     *argv=res;
     *(MEM_ROOT*) ptr= alloc;			/* Save alloc root for free */
     if (default_directories)
@@ -487,7 +511,7 @@ int my_load_defaults(const char *conf_file, const char **groups,
     or a forced default file
   */
   if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+
-			       (args.elements + *argc +1) *sizeof(char*))))
+			       (args.elements + *argc + 1 + 1) *sizeof(char*))))
     goto err;
   res= (char**) (ptr+sizeof(alloc));
 
@@ -508,12 +532,16 @@ int my_load_defaults(const char *conf_file, const char **groups,
     --*argc; ++*argv;				/* skip argument */
   }
 
+  /* set arguments separator for arguments from config file and
+     command line */
+  res[args.elements+1]= (char *)args_separator;
+
   if (*argc)
-    memcpy((uchar*) (res+1+args.elements), (char*) ((*argv)+1),
+    memcpy((uchar*) (res+1+args.elements+1), (char*) ((*argv)+1),
 	   (*argc-1)*sizeof(char*));
-  res[args.elements+ *argc]=0;			/* last null */
+  res[args.elements+ *argc+1]=0;                /* last null */
 
-  (*argc)+=args.elements;
+  (*argc)+=args.elements+1;
   *argv= (char**) res;
   *(MEM_ROOT*) ptr= alloc;			/* Save alloc root for free */
   delete_dynamic(&args);
@@ -523,7 +551,8 @@ int my_load_defaults(const char *conf_file, const char **groups,
     printf("%s would have been started with the following arguments:\n",
 	   **argv);
     for (i=1 ; i < *argc ; i++)
-      printf("%s ", (*argv)[i]);
+      if ((*argv)[i] != args_separator) /* skip arguments separator */
+        printf("%s ", (*argv)[i]);
     puts("");
     exit(0);
   }
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index b6eb6dac54fdb76113176fe2f1334ab2f88aa2d6..22b1216f99c285af67b8aaa614d5c3c090e48533 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -121,6 +121,7 @@ int handle_options(int *argc, char ***argv,
   const struct my_option *optp;
   uchar* *value;
   int error, i;
+  my_bool is_cmdline_arg= 1;
 
   LINT_INIT(opt_found);
   /* handle_options() assumes arg0 (program name) always exists */
@@ -130,10 +131,34 @@ int handle_options(int *argc, char ***argv,
   (*argv)++; /*      --- || ----      */
   init_variables(longopts, init_one_value);
 
+  /*
+    Search for args_separator, if found, then the first part of the
+    arguments are loaded from configs
+  */
+  for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
+  {
+    if (*pos == args_separator)
+    {
+      is_cmdline_arg= 0;
+      break;
+    }
+  }
+
   for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
   {
     char **first= pos;
     char *cur_arg= *pos;
+    if (!is_cmdline_arg && (cur_arg == args_separator))
+    {
+      is_cmdline_arg= 1;
+
+      /* save the separator too if skip unkown options  */
+      if (my_getopt_skip_unknown)
+        (*argv)[argvpos++]= cur_arg;
+      else
+        (*argc)--;
+      continue;
+    }
     if (cur_arg[0] == '-' && cur_arg[1] && !end_of_options) /* must be opt */
     {
       char *argument=    0;
@@ -426,8 +451,12 @@ invalid value '%s'",
 	}
 	else if (optp->arg_type == REQUIRED_ARG && !optend)
 	{
-	  /* Check if there are more arguments after this one */
-	  if (!*++pos)
+	  /* Check if there are more arguments after this one,
+
+             Note: options loaded from config file that requires value
+             should always be in the form '--option=value'.
+           */
+	  if (!is_cmdline_arg || !*++pos)
 	  {
 	    if (my_getopt_print_errors)
               my_getopt_error_reporter(ERROR_LEVEL,
diff --git a/mysys/my_handler_errors.h b/mysys/my_handler_errors.h
index c239cabb168034fb0479f9c2caf6901b49916473..e4e62f47fedcca33f1daa2cbe7c76075db692e8f 100644
--- a/mysys/my_handler_errors.h
+++ b/mysys/my_handler_errors.h
@@ -1,3 +1,5 @@
+#ifndef MYSYS_MY_HANDLER_ERRORS_INCLUDED
+#define MYSYS_MY_HANDLER_ERRORS_INCLUDED
 
 /*
   Errors a handler can give you
@@ -66,3 +68,4 @@ static const char *handler_error_messages[]=
   "Too many active concurrent transactions"
 };
 
+#endif /* MYSYS_MY_HANDLER_ERRORS_INCLUDED */
diff --git a/mysys/my_static.h b/mysys/my_static.h
index 90168b099a879ebe4d35c5cf6c1af395f07fe803..c336115bc35bee370c2456d36d3aa8c0d3881c9d 100644
--- a/mysys/my_static.h
+++ b/mysys/my_static.h
@@ -1,3 +1,6 @@
+#ifndef MYSYS_MY_STATIC_INCLUDED
+#define MYSYS_MY_STATIC_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -72,3 +75,5 @@ extern ulonglong query_performance_frequency, query_performance_offset;
 extern sigset_t my_signals;		/* signals blocked by mf_brkhant */
 #endif
 C_MODE_END
+
+#endif /* MYSYS_MY_STATIC_INCLUDED */
diff --git a/plugin/semisync/Makefile.am b/plugin/semisync/Makefile.am
new file mode 100644
index 0000000000000000000000000000000000000000..dfe539b83868cb8db72145d36d176ac65af36619
--- /dev/null
+++ b/plugin/semisync/Makefile.am
@@ -0,0 +1,36 @@
+# Copyright (C) 2006 MySQL AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+## Makefile.am for semi-synchronous replication
+
+pkgplugindir =		$(pkglibdir)/plugin
+INCLUDES =              -I$(top_srcdir)/include \
+			-I$(top_srcdir)/sql \
+			-I$(top_srcdir)/regex \
+			-I$(srcdir)
+
+noinst_HEADERS = semisync.h semisync_master.h semisync_slave.h
+
+pkgplugin_LTLIBRARIES =	libsemisync_master.la libsemisync_slave.la
+
+libsemisync_master_la_LDFLAGS =	-module
+libsemisync_master_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+libsemisync_master_la_CFLAGS =	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+libsemisync_master_la_SOURCES = semisync.cc semisync_master.cc semisync_master_plugin.cc
+
+libsemisync_slave_la_LDFLAGS =	-module
+libsemisync_slave_la_CXXFLAGS=	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+libsemisync_slave_la_CFLAGS =	$(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+libsemisync_slave_la_SOURCES = semisync.cc semisync_slave.cc semisync_slave_plugin.cc
diff --git a/plugin/semisync/configure.in b/plugin/semisync/configure.in
new file mode 100644
index 0000000000000000000000000000000000000000..894251258db2b063fc2876ddec330c1cc4b2090e
--- /dev/null
+++ b/plugin/semisync/configure.in
@@ -0,0 +1,9 @@
+# configure.in for semi-synchronous replication
+
+AC_INIT(mysql-semi-sync-plugin, 0.2)
+AM_INIT_AUTOMAKE
+AC_DISABLE_STATIC
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+
diff --git a/plugin/semisync/plug.in b/plugin/semisync/plug.in
new file mode 100644
index 0000000000000000000000000000000000000000..917c8950f02c821dcaec58986f7b7a36985ffb01
--- /dev/null
+++ b/plugin/semisync/plug.in
@@ -0,0 +1,3 @@
+MYSQL_PLUGIN(semisync,[Semi-synchronous Replication Plugin],
+        [Semi-synchronous replication plugin.])
+MYSQL_PLUGIN_DYNAMIC(semisync,   [libsemisync_master.la libsemisync_slave.la])
diff --git a/plugin/semisync/semisync.cc b/plugin/semisync/semisync.cc
new file mode 100644
index 0000000000000000000000000000000000000000..83c7791c14b6a60861006e57c20a8df993f5d327
--- /dev/null
+++ b/plugin/semisync/semisync.cc
@@ -0,0 +1,30 @@
+/* Copyright (C) 2007 Google Inc.
+   Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#include "semisync.h"
+
+const unsigned char ReplSemiSyncBase::kPacketMagicNum = 0xef;
+const unsigned char ReplSemiSyncBase::kPacketFlagSync = 0x01;
+
+
+const unsigned long Trace::kTraceGeneral  = 0x0001;
+const unsigned long Trace::kTraceDetail   = 0x0010;
+const unsigned long Trace::kTraceNetWait  = 0x0020;
+const unsigned long Trace::kTraceFunction = 0x0040;
+
+const char  ReplSemiSyncBase::kSyncHeader[2] =
+  {ReplSemiSyncBase::kPacketMagicNum, 0};
diff --git a/plugin/semisync/semisync.h b/plugin/semisync/semisync.h
new file mode 100644
index 0000000000000000000000000000000000000000..ced25c405344f12932d16cb05bf9c5d308fe6302
--- /dev/null
+++ b/plugin/semisync/semisync.h
@@ -0,0 +1,91 @@
+/* Copyright (C) 2007 Google Inc.
+   Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#ifndef SEMISYNC_H
+#define SEMISYNC_H
+
+#define MYSQL_SERVER
+#define HAVE_REPLICATION
+#include <mysql_priv.h>
+#include <my_global.h>
+#include <my_pthread.h>
+#include <mysql/plugin.h>
+#include <replication.h>
+
+typedef struct st_mysql_show_var SHOW_VAR;
+typedef struct st_mysql_sys_var SYS_VAR;
+
+
+/**
+   This class is used to trace function calls and other process
+   information
+*/
+class Trace {
+public:
+  static const unsigned long kTraceFunction;
+  static const unsigned long kTraceGeneral;
+  static const unsigned long kTraceDetail;
+  static const unsigned long kTraceNetWait;
+
+  unsigned long           trace_level_;                      /* the level for tracing */
+
+  inline void function_enter(const char *func_name)
+  {
+    if (trace_level_ & kTraceFunction)
+      sql_print_information("---> %s enter", func_name);
+  }
+  inline int  function_exit(const char *func_name, int exit_code)
+  {
+    if (trace_level_ & kTraceFunction)
+      sql_print_information("<--- %s exit (%d)", func_name, exit_code);
+    return exit_code;
+  }
+
+  Trace()
+    :trace_level_(0L)
+  {}
+  Trace(unsigned long trace_level)
+    :trace_level_(trace_level)
+  {}
+};
+
+/**
+   Base class for semi-sync master and slave classes
+*/
+class ReplSemiSyncBase
+  :public Trace {
+public:
+  static const char  kSyncHeader[2];              /* three byte packet header */
+
+  /* Constants in network packet header. */
+  static const unsigned char kPacketMagicNum;
+  static const unsigned char kPacketFlagSync;
+};
+
+/* The layout of a semisync slave reply packet:
+   1 byte for the magic num
+   8 bytes for the binlog positon
+   n bytes for the binlog filename, terminated with a '\0'
+*/
+#define REPLY_MAGIC_NUM_LEN 1
+#define REPLY_BINLOG_POS_LEN 8
+#define REPLY_BINLOG_NAME_LEN (FN_REFLEN + 1)
+#define REPLY_MAGIC_NUM_OFFSET 0
+#define REPLY_BINLOG_POS_OFFSET (REPLY_MAGIC_NUM_OFFSET + REPLY_MAGIC_NUM_LEN)
+#define REPLY_BINLOG_NAME_OFFSET (REPLY_BINLOG_POS_OFFSET + REPLY_BINLOG_POS_LEN)
+
+#endif /* SEMISYNC_H */
diff --git a/plugin/semisync/semisync_master.cc b/plugin/semisync/semisync_master.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a7106621a433156db088d3afd5d23044ec2ee23
--- /dev/null
+++ b/plugin/semisync/semisync_master.cc
@@ -0,0 +1,1292 @@
+/* Copyright (C) 2007 Google Inc.
+   Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#include "semisync_master.h"
+
+#define TIME_THOUSAND 1000
+#define TIME_MILLION  1000000
+#define TIME_BILLION  1000000000
+
+/* This indicates whether semi-synchronous replication is enabled. */
+char rpl_semi_sync_master_enabled;
+unsigned long rpl_semi_sync_master_timeout;
+unsigned long rpl_semi_sync_master_trace_level;
+char rpl_semi_sync_master_status                    = 0;
+unsigned long rpl_semi_sync_master_yes_transactions = 0;
+unsigned long rpl_semi_sync_master_no_transactions  = 0;
+unsigned long rpl_semi_sync_master_off_times        = 0;
+unsigned long rpl_semi_sync_master_timefunc_fails   = 0;
+unsigned long rpl_semi_sync_master_wait_timeouts     = 0;
+unsigned long rpl_semi_sync_master_wait_sessions    = 0;
+unsigned long rpl_semi_sync_master_wait_pos_backtraverse = 0;
+unsigned long rpl_semi_sync_master_avg_trx_wait_time = 0;
+unsigned long long rpl_semi_sync_master_trx_wait_num = 0;
+unsigned long rpl_semi_sync_master_avg_net_wait_time    = 0;
+unsigned long long rpl_semi_sync_master_net_wait_num = 0;
+unsigned long rpl_semi_sync_master_clients          = 0;
+unsigned long long rpl_semi_sync_master_net_wait_time = 0;
+unsigned long long rpl_semi_sync_master_trx_wait_time = 0;
+char rpl_semi_sync_master_wait_no_slave = 1;
+
+
+static int getWaitTime(const struct timeval& start_tv);
+
+/*******************************************************************************
+ *
+ * <ActiveTranx> class : manage all active transaction nodes
+ *
+ ******************************************************************************/
+
+ActiveTranx::ActiveTranx(int max_connections,
+			 pthread_mutex_t *lock,
+			 unsigned long trace_level)
+  : Trace(trace_level), num_transactions_(max_connections),
+    num_entries_(max_connections << 1),
+    lock_(lock)
+{
+  /* Allocate the memory for the array */
+  node_array_ = new TranxNode[num_transactions_];
+  for (int idx = 0; idx < num_transactions_; ++idx)
+  {
+    node_array_[idx].log_pos_     = 0;
+    node_array_[idx].hash_next_   = NULL;
+    node_array_[idx].next_        = node_array_ + idx + 1;
+
+    node_array_[idx].log_name_    = new char[FN_REFLEN];
+    node_array_[idx].log_name_[0] = '\x0';
+  }
+  node_array_[num_transactions_-1].next_ = NULL;
+
+  /* All nodes in the array go to the pool initially. */
+  free_pool_ = node_array_;
+
+  /* No transactions are in the list initially. */
+  trx_front_ = NULL;
+  trx_rear_  = NULL;
+
+  /* Create the hash table to find a transaction's ending event. */
+  trx_htb_ = new TranxNode *[num_entries_];
+  for (int idx = 0; idx < num_entries_; ++idx)
+    trx_htb_[idx] = NULL;
+
+  sql_print_information("Semi-sync replication initialized for %d "
+                        "transactions.", num_transactions_);
+}
+
+ActiveTranx::~ActiveTranx()
+{
+  for (int idx = 0; idx < num_transactions_; ++idx)
+  {
+    delete [] node_array_[idx].log_name_;
+    node_array_[idx].log_name_ = NULL;
+  }
+
+  delete [] node_array_;
+  delete [] trx_htb_;
+
+  node_array_       = NULL;
+  trx_htb_          = NULL;
+  num_transactions_ = 0;
+  num_entries_      = 0;
+}
+
+unsigned int ActiveTranx::calc_hash(const unsigned char *key,
+                                    unsigned int length)
+{
+  unsigned int nr = 1, nr2 = 4;
+
+  /* The hash implementation comes from calc_hashnr() in mysys/hash.c. */
+  while (length--)
+  {
+    nr  ^= (((nr & 63)+nr2)*((unsigned int) (unsigned char) *key++))+ (nr << 8);
+    nr2 += 3;
+  }
+  return((unsigned int) nr);
+}
+
+unsigned int ActiveTranx::get_hash_value(const char *log_file_name,
+				 my_off_t    log_file_pos)
+{
+  unsigned int hash1 = calc_hash((const unsigned char *)log_file_name,
+                                 strlen(log_file_name));
+  unsigned int hash2 = calc_hash((const unsigned char *)(&log_file_pos),
+                                 sizeof(log_file_pos));
+
+  return (hash1 + hash2) % num_entries_;
+}
+
+ActiveTranx::TranxNode* ActiveTranx::alloc_tranx_node()
+{
+  TranxNode *ptr = free_pool_;
+
+  if (free_pool_)
+  {
+    free_pool_ = free_pool_->next_;
+    ptr->next_ = NULL;
+    ptr->hash_next_ = NULL;
+  }
+  else
+  {
+    /*
+      free_pool should never be NULL here, because we have
+      max_connections number of pre-allocated nodes.
+    */
+    sql_print_error("You have encountered a semi-sync bug (free_pool == NULL), "
+                    "please report to http://bugs.mysql.com");
+    assert(free_pool_);
+  }
+
+  return ptr;
+}
+
+int ActiveTranx::compare(const char *log_file_name1, my_off_t log_file_pos1,
+			 const char *log_file_name2, my_off_t log_file_pos2)
+{
+  int cmp = strcmp(log_file_name1, log_file_name2);
+
+  if (cmp != 0)
+    return cmp;
+
+  if (log_file_pos1 > log_file_pos2)
+    return 1;
+  else if (log_file_pos1 < log_file_pos2)
+    return -1;
+  return 0;
+}
+
+int ActiveTranx::insert_tranx_node(const char *log_file_name,
+				   my_off_t log_file_pos)
+{
+  const char *kWho = "ActiveTranx:insert_tranx_node";
+  TranxNode  *ins_node;
+  int         result = 0;
+  unsigned int        hash_val;
+
+  function_enter(kWho);
+
+  ins_node = alloc_tranx_node();
+  if (!ins_node)
+  {
+    sql_print_error("%s: transaction node allocation failed for: (%s, %lu)",
+                    kWho, log_file_name, (unsigned long)log_file_pos);
+    result = -1;
+    goto l_end;
+  }
+
+  /* insert the binlog position in the active transaction list. */
+  strcpy(ins_node->log_name_, log_file_name);
+  ins_node->log_pos_ = log_file_pos;
+
+  if (!trx_front_)
+  {
+    /* The list is empty. */
+    trx_front_ = trx_rear_ = ins_node;
+  }
+  else
+  {
+    int cmp = compare(ins_node, trx_rear_);
+    if (cmp > 0)
+    {
+      /* Compare with the tail first.  If the transaction happens later in
+       * binlog, then make it the new tail.
+       */
+      trx_rear_->next_ = ins_node;
+      trx_rear_        = ins_node;
+    }
+    else
+    {
+      /* Otherwise, it is an error because the transaction should hold the
+       * mysql_bin_log.LOCK_log when appending events.
+       */
+      sql_print_error("%s: binlog write out-of-order, tail (%s, %lu), "
+                      "new node (%s, %lu)", kWho,
+                      trx_rear_->log_name_, (unsigned long)trx_rear_->log_pos_,
+                      ins_node->log_name_, (unsigned long)ins_node->log_pos_);
+      result = -1;
+      goto l_end;
+    }
+  }
+
+  hash_val = get_hash_value(ins_node->log_name_, ins_node->log_pos_);
+  ins_node->hash_next_ = trx_htb_[hash_val];
+  trx_htb_[hash_val]   = ins_node;
+
+  if (trace_level_ & kTraceDetail)
+    sql_print_information("%s: insert (%s, %lu) in entry(%u)", kWho,
+                          ins_node->log_name_, (unsigned long)ins_node->log_pos_,
+                          hash_val);
+
+ l_end:
+  return function_exit(kWho, result);
+}
+
+bool ActiveTranx::is_tranx_end_pos(const char *log_file_name,
+				   my_off_t    log_file_pos)
+{
+  const char *kWho = "ActiveTranx::is_tranx_end_pos";
+  function_enter(kWho);
+
+  unsigned int hash_val = get_hash_value(log_file_name, log_file_pos);
+  TranxNode *entry = trx_htb_[hash_val];
+
+  while (entry != NULL)
+  {
+    if (compare(entry, log_file_name, log_file_pos) == 0)
+      break;
+
+    entry = entry->hash_next_;
+  }
+
+  if (trace_level_ & kTraceDetail)
+    sql_print_information("%s: probe (%s, %lu) in entry(%u)", kWho,
+                          log_file_name, (unsigned long)log_file_pos, hash_val);
+
+  function_exit(kWho, (entry != NULL));
+  return (entry != NULL);
+}
+
+int ActiveTranx::clear_active_tranx_nodes(const char *log_file_name,
+					  my_off_t log_file_pos)
+{
+  const char *kWho = "ActiveTranx::::clear_active_tranx_nodes";
+  TranxNode *new_front;
+
+  function_enter(kWho);
+
+  if (log_file_name != NULL)
+  {
+    new_front = trx_front_;
+
+    while (new_front)
+    {
+      if (compare(new_front, log_file_name, log_file_pos) > 0)
+        break;
+      new_front = new_front->next_;
+    }
+  }
+  else
+  {
+    /* If log_file_name is NULL, clear everything. */
+    new_front = NULL;
+  }
+
+  if (new_front == NULL)
+  {
+    /* No active transaction nodes after the call. */
+
+    /* Clear the hash table. */
+    memset(trx_htb_, 0, num_entries_ * sizeof(TranxNode *));
+
+    /* Clear the active transaction list. */
+    if (trx_front_ != NULL)
+    {
+      trx_rear_->next_ = free_pool_;
+      free_pool_ = trx_front_;
+      trx_front_ = NULL;
+      trx_rear_  = NULL;
+    }
+
+    if (trace_level_ & kTraceDetail)
+      sql_print_information("%s: free all nodes back to free list", kWho);
+  }
+  else if (new_front != trx_front_)
+  {
+    TranxNode *curr_node, *next_node;
+
+    /* Delete all transaction nodes before the confirmation point. */
+    int n_frees = 0;
+    curr_node = trx_front_;
+    while (curr_node != new_front)
+    {
+      next_node = curr_node->next_;
+
+      /* Put the node in the memory pool. */
+      curr_node->next_ = free_pool_;
+      free_pool_       = curr_node;
+      n_frees++;
+
+      /* Remove the node from the hash table. */
+      unsigned int hash_val = get_hash_value(curr_node->log_name_, curr_node->log_pos_);
+      TranxNode **hash_ptr = &(trx_htb_[hash_val]);
+      while ((*hash_ptr) != NULL)
+      {
+        if ((*hash_ptr) == curr_node)
+	{
+          (*hash_ptr) = curr_node->hash_next_;
+          break;
+        }
+        hash_ptr = &((*hash_ptr)->hash_next_);
+      }
+
+      curr_node = next_node;
+    }
+
+    trx_front_ = new_front;
+
+    if (trace_level_ & kTraceDetail)
+      sql_print_information("%s: free %d nodes back until pos (%s, %lu)",
+                            kWho, n_frees,
+                            trx_front_->log_name_, (unsigned long)trx_front_->log_pos_);
+  }
+
+  return function_exit(kWho, 0);
+}
+
+
+/*******************************************************************************
+ *
+ * <ReplSemiSyncMaster> class: the basic code layer for sync-replication master.
+ * <ReplSemiSyncSlave>  class: the basic code layer for sync-replication slave.
+ *
+ * The most important functions during semi-syn replication listed:
+ *
+ * Master:
+ *  . reportReplyBinlog(): called by the binlog dump thread when it receives
+ *                         the slave's status information.
+ *  . updateSyncHeader():  based on transaction waiting information, decide
+ *                         whether to request the slave to reply.
+ *  . writeTraxInBinlog(): called by the transaction thread when it finishes
+ *                         writing all transaction events in binlog.
+ *  . commitTrx():         transaction thread wait for the slave reply.
+ *
+ * Slave:
+ *  . slaveReadSyncHeader(): read the semi-sync header from the master, get the
+ *                         sync status and get the payload for events.
+ *  . slaveReply():        reply to the master about the replication progress.
+ *
+ ******************************************************************************/
+
+ReplSemiSyncMaster::ReplSemiSyncMaster()
+  : active_tranxs_(NULL),
+    init_done_(false),
+    reply_file_name_inited_(false),
+    reply_file_pos_(0L),
+    wait_file_name_inited_(false),
+    wait_file_pos_(0),
+    master_enabled_(false),
+    wait_timeout_(0L),
+    state_(0),
+    max_transactions_(0L)
+{
+  strcpy(reply_file_name_, "");
+  strcpy(wait_file_name_, "");
+}
+
+int ReplSemiSyncMaster::initObject()
+{
+  int result;
+  const char *kWho = "ReplSemiSyncMaster::initObject";
+
+  if (init_done_)
+  {
+    fprintf(stderr, "%s called twice\n", kWho);
+    return 1;
+  }
+  init_done_ = true;
+
+  /* References to the parameter works after set_options(). */
+  setWaitTimeout(rpl_semi_sync_master_timeout);
+  setTraceLevel(rpl_semi_sync_master_trace_level);
+  max_transactions_ = (int)max_connections;
+
+  /* Mutex initialization can only be done after MY_INIT(). */
+  pthread_mutex_init(&LOCK_binlog_, MY_MUTEX_INIT_FAST);
+  pthread_cond_init(&COND_binlog_send_, NULL);
+
+  if (rpl_semi_sync_master_enabled)
+    result = enableMaster();
+  else
+    result = disableMaster();
+
+  return result;
+}
+
+int ReplSemiSyncMaster::enableMaster()
+{
+  int result = 0;
+
+  /* Must have the lock when we do enable of disable. */
+  lock();
+
+  if (!getMasterEnabled())
+  {
+    active_tranxs_ = new ActiveTranx(max_connections,
+				     &LOCK_binlog_,
+				     trace_level_);
+    if (active_tranxs_ != NULL)
+    {
+      commit_file_name_inited_ = false;
+      reply_file_name_inited_  = false;
+      wait_file_name_inited_   = false;
+
+      set_master_enabled(true);
+      state_ = true;
+      sql_print_information("Semi-sync replication enabled on the master.");
+    }
+    else
+    {
+      sql_print_error("Cannot allocate memory to enable semi-sync on the master.");
+      result = -1;
+    }
+  }
+
+  unlock();
+
+  return result;
+}
+
+int ReplSemiSyncMaster::disableMaster()
+{
+  /* Must have the lock when we do enable of disable. */
+  lock();
+
+  if (getMasterEnabled())
+  {
+    /* Switch off the semi-sync first so that waiting transaction will be
+     * waken up.
+     */
+    switch_off();
+
+    assert(active_tranxs_ != NULL);
+    delete active_tranxs_;
+    active_tranxs_ = NULL;
+
+    reply_file_name_inited_ = false;
+    wait_file_name_inited_  = false;
+    commit_file_name_inited_ = false;
+
+    set_master_enabled(false);
+    sql_print_information("Semi-sync replication disabled on the master.");
+  }
+
+  unlock();
+
+  return 0;
+}
+
+ReplSemiSyncMaster::~ReplSemiSyncMaster()
+{
+  if (init_done_)
+  {
+    pthread_mutex_destroy(&LOCK_binlog_);
+    pthread_cond_destroy(&COND_binlog_send_);
+  }
+
+  delete active_tranxs_;
+}
+
+void ReplSemiSyncMaster::lock()
+{
+  pthread_mutex_lock(&LOCK_binlog_);
+}
+
+void ReplSemiSyncMaster::unlock()
+{
+  pthread_mutex_unlock(&LOCK_binlog_);
+}
+
+void ReplSemiSyncMaster::cond_broadcast()
+{
+  pthread_cond_broadcast(&COND_binlog_send_);
+}
+
+int ReplSemiSyncMaster::cond_timewait(struct timespec *wait_time)
+{
+  const char *kWho = "ReplSemiSyncMaster::cond_timewait()";
+  int wait_res;
+
+  function_enter(kWho);
+  wait_res = pthread_cond_timedwait(&COND_binlog_send_,
+                                    &LOCK_binlog_, wait_time);
+  return function_exit(kWho, wait_res);
+}
+
+void ReplSemiSyncMaster::add_slave()
+{
+  lock();
+  rpl_semi_sync_master_clients++;
+  unlock();
+}
+
+void ReplSemiSyncMaster::remove_slave()
+{
+  lock();
+  rpl_semi_sync_master_clients--;
+
+  /* If user has chosen not to wait if no semi-sync slave available
+     and the last semi-sync slave exits, turn off semi-sync on master
+     immediately.
+   */
+  if (!rpl_semi_sync_master_wait_no_slave &&
+      rpl_semi_sync_master_clients == 0)
+    switch_off();
+  unlock();
+}
+
+bool ReplSemiSyncMaster::is_semi_sync_slave()
+{
+  int null_value;
+  long long val= 0;
+  get_user_var_int("rpl_semi_sync_slave", &val, &null_value);
+  return val;
+}
+
+int ReplSemiSyncMaster::reportReplyBinlog(uint32 server_id,
+					  const char *log_file_name,
+					  my_off_t log_file_pos)
+{
+  const char *kWho = "ReplSemiSyncMaster::reportReplyBinlog";
+  int   cmp;
+  bool  can_release_threads = false;
+  bool  need_copy_send_pos = true;
+
+  if (!(getMasterEnabled()))
+    return 0;
+
+  function_enter(kWho);
+
+  lock();
+
+  /* This is the real check inside the mutex. */
+  if (!getMasterEnabled())
+    goto l_end;
+
+  if (!is_on())
+    /* We check to see whether we can switch semi-sync ON. */
+    try_switch_on(server_id, log_file_name, log_file_pos);
+
+  /* The position should increase monotonically, if there is only one
+   * thread sending the binlog to the slave.
+   * In reality, to improve the transaction availability, we allow multiple
+   * sync replication slaves.  So, if any one of them get the transaction,
+   * the transaction session in the primary can move forward.
+   */
+  if (reply_file_name_inited_)
+  {
+    cmp = ActiveTranx::compare(log_file_name, log_file_pos,
+                               reply_file_name_, reply_file_pos_);
+
+    /* If the requested position is behind the sending binlog position,
+     * would not adjust sending binlog position.
+     * We based on the assumption that there are multiple semi-sync slave,
+     * and at least one of them shou/ld be up to date.
+     * If all semi-sync slaves are behind, at least initially, the primary
+     * can find the situation after the waiting timeout.  After that, some
+     * slaves should catch up quickly.
+     */
+    if (cmp < 0)
+    {
+      /* If the position is behind, do not copy it. */
+      need_copy_send_pos = false;
+    }
+  }
+
+  if (need_copy_send_pos)
+  {
+    strcpy(reply_file_name_, log_file_name);
+    reply_file_pos_ = log_file_pos;
+    reply_file_name_inited_ = true;
+
+    /* Remove all active transaction nodes before this point. */
+    assert(active_tranxs_ != NULL);
+    active_tranxs_->clear_active_tranx_nodes(log_file_name, log_file_pos);
+
+    if (trace_level_ & kTraceDetail)
+      sql_print_information("%s: Got reply at (%s, %lu)", kWho,
+                            log_file_name, (unsigned long)log_file_pos);
+  }
+
+  if (rpl_semi_sync_master_wait_sessions > 0)
+  {
+    /* Let us check if some of the waiting threads doing a trx
+     * commit can now proceed.
+     */
+    cmp = ActiveTranx::compare(reply_file_name_, reply_file_pos_,
+                               wait_file_name_, wait_file_pos_);
+    if (cmp >= 0)
+    {
+      /* Yes, at least one waiting thread can now proceed:
+       * let us release all waiting threads with a broadcast
+       */
+      can_release_threads = true;
+      wait_file_name_inited_ = false;
+    }
+  }
+
+ l_end:
+  unlock();
+
+  if (can_release_threads)
+  {
+    if (trace_level_ & kTraceDetail)
+      sql_print_information("%s: signal all waiting threads.", kWho);
+
+    cond_broadcast();
+  }
+
+  return function_exit(kWho, 0);
+}
+
+int ReplSemiSyncMaster::commitTrx(const char* trx_wait_binlog_name,
+				  my_off_t trx_wait_binlog_pos)
+{
+  const char *kWho = "ReplSemiSyncMaster::commitTrx";
+
+  function_enter(kWho);
+
+  if (getMasterEnabled() && trx_wait_binlog_name)
+  {
+    struct timeval start_tv;
+    struct timespec abstime;
+    int wait_result, start_time_err;
+    const char *old_msg= 0;
+
+    start_time_err = gettimeofday(&start_tv, 0);
+
+    /* Acquire the mutex. */
+    lock();
+
+    /* This must be called after acquired the lock */
+    old_msg= thd_enter_cond(NULL, &COND_binlog_send_, &LOCK_binlog_,
+                            "Waiting for semi-sync ACK from slave");
+
+    /* This is the real check inside the mutex. */
+    if (!getMasterEnabled() || !is_on())
+      goto l_end;
+
+    if (trace_level_ & kTraceDetail)
+    {
+      sql_print_information("%s: wait pos (%s, %lu), repl(%d)\n", kWho,
+                            trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos,
+                            (int)is_on());
+    }
+
+    while (is_on())
+    {
+      if (reply_file_name_inited_)
+      {
+        int cmp = ActiveTranx::compare(reply_file_name_, reply_file_pos_,
+                                       trx_wait_binlog_name, trx_wait_binlog_pos);
+        if (cmp >= 0)
+        {
+          /* We have already sent the relevant binlog to the slave: no need to
+           * wait here.
+           */
+          if (trace_level_ & kTraceDetail)
+            sql_print_information("%s: Binlog reply is ahead (%s, %lu),",
+                                  kWho, reply_file_name_, (unsigned long)reply_file_pos_);
+          break;
+        }
+      }
+
+      /* Let us update the info about the minimum binlog position of waiting
+       * threads.
+       */
+      if (wait_file_name_inited_)
+      {
+        int cmp = ActiveTranx::compare(trx_wait_binlog_name, trx_wait_binlog_pos,
+                                       wait_file_name_, wait_file_pos_);
+        if (cmp <= 0)
+	{
+          /* This thd has a lower position, let's update the minimum info. */
+          strcpy(wait_file_name_, trx_wait_binlog_name);
+          wait_file_pos_ = trx_wait_binlog_pos;
+
+          rpl_semi_sync_master_wait_pos_backtraverse++;
+          if (trace_level_ & kTraceDetail)
+            sql_print_information("%s: move back wait position (%s, %lu),",
+                                  kWho, wait_file_name_, (unsigned long)wait_file_pos_);
+        }
+      }
+      else
+      {
+        strcpy(wait_file_name_, trx_wait_binlog_name);
+        wait_file_pos_ = trx_wait_binlog_pos;
+        wait_file_name_inited_ = true;
+
+        if (trace_level_ & kTraceDetail)
+          sql_print_information("%s: init wait position (%s, %lu),",
+                                kWho, wait_file_name_, (unsigned long)wait_file_pos_);
+      }
+
+      if (start_time_err == 0)
+      {
+        int diff_usecs = start_tv.tv_usec + wait_timeout_ * TIME_THOUSAND;
+
+        /* Calcuate the waiting period. */
+        abstime.tv_sec = start_tv.tv_sec;
+        if (diff_usecs < TIME_MILLION)
+	{
+          abstime.tv_nsec = diff_usecs * TIME_THOUSAND;
+        }
+	else
+	{
+          while (diff_usecs >= TIME_MILLION)
+	  {
+            abstime.tv_sec++;
+            diff_usecs -= TIME_MILLION;
+          }
+          abstime.tv_nsec = diff_usecs * TIME_THOUSAND;
+        }
+
+        /* In semi-synchronous replication, we wait until the binlog-dump
+         * thread has received the reply on the relevant binlog segment from the
+         * replication slave.
+         *
+         * Let us suspend this thread to wait on the condition;
+         * when replication has progressed far enough, we will release
+         * these waiting threads.
+         */
+        rpl_semi_sync_master_wait_sessions++;
+
+        if (trace_level_ & kTraceDetail)
+          sql_print_information("%s: wait %lu ms for binlog sent (%s, %lu)",
+                                kWho, wait_timeout_,
+                                wait_file_name_, (unsigned long)wait_file_pos_);
+
+        wait_result = cond_timewait(&abstime);
+        rpl_semi_sync_master_wait_sessions--;
+
+        if (wait_result != 0)
+	{
+          /* This is a real wait timeout. */
+          sql_print_warning("Timeout waiting for reply of binlog (file: %s, pos: %lu), "
+                            "semi-sync up to file %s, position %lu.",
+                            trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos,
+                            reply_file_name_, (unsigned long)reply_file_pos_);
+          rpl_semi_sync_master_wait_timeouts++;
+
+          /* switch semi-sync off */
+          switch_off();
+        }
+	else
+	{
+          int wait_time;
+
+          wait_time = getWaitTime(start_tv);
+          if (wait_time < 0)
+	  {
+            if (trace_level_ & kTraceGeneral)
+	    {
+              /* This is a time/gettimeofday function call error. */
+              sql_print_error("Replication semi-sync gettimeofday fail1 at "
+                              "wait position (%s, %lu)",
+                              trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos);
+            }
+            rpl_semi_sync_master_timefunc_fails++;
+          }
+	  else
+	  {
+            rpl_semi_sync_master_trx_wait_num++;
+            rpl_semi_sync_master_trx_wait_time += wait_time;
+          }
+        }
+      }
+      else
+      {
+        if (trace_level_ & kTraceGeneral)
+	{
+          /* This is a gettimeofday function call error. */
+          sql_print_error("Replication semi-sync gettimeofday fail2 at "
+                          "wait position (%s, %lu)",
+                          trx_wait_binlog_name, (unsigned long)trx_wait_binlog_pos);
+        }
+        rpl_semi_sync_master_timefunc_fails++;
+
+        /* switch semi-sync off */
+        switch_off();
+      }
+    }
+
+  l_end:
+    /*
+      At this point, the binlog file and position of this transaction
+      must have been removed from ActiveTranx.
+    */
+    assert(!active_tranxs_->is_tranx_end_pos(trx_wait_binlog_name,
+                                             trx_wait_binlog_pos));
+    
+    /* Update the status counter. */
+    if (is_on())
+      rpl_semi_sync_master_yes_transactions++;
+    else
+      rpl_semi_sync_master_no_transactions++;
+
+    /* The lock held will be released by thd_exit_cond, so no need to
+       call unlock() here */
+    thd_exit_cond(NULL, old_msg);
+  }
+
+  return function_exit(kWho, 0);
+}
+
+/* Indicate that semi-sync replication is OFF now.
+ * 
+ * What should we do when it is disabled?  The problem is that we want
+ * the semi-sync replication enabled again when the slave catches up
+ * later.  But, it is not that easy to detect that the slave has caught
+ * up.  This is caused by the fact that MySQL's replication protocol is
+ * asynchronous, meaning that if the master does not use the semi-sync
+ * protocol, the slave would not send anything to the master.
+ * Still, if the master is sending (N+1)-th event, we assume that it is
+ * an indicator that the slave has received N-th event and earlier ones.
+ *
+ * If semi-sync is disabled, all transactions still update the wait
+ * position with the last position in binlog.  But no transactions will
+ * wait for confirmations and the active transaction list would not be
+ * maintained.  In binlog dump thread, updateSyncHeader() checks whether
+ * the current sending event catches up with last wait position.  If it
+ * does match, semi-sync will be switched on again.
+ */
+int ReplSemiSyncMaster::switch_off()
+{
+  const char *kWho = "ReplSemiSyncMaster::switch_off";
+  int result;
+
+  function_enter(kWho);
+  state_ = false;
+
+  /* Clear the active transaction list. */
+  assert(active_tranxs_ != NULL);
+  result = active_tranxs_->clear_active_tranx_nodes(NULL, 0);
+
+  rpl_semi_sync_master_off_times++;
+  wait_file_name_inited_   = false;
+  reply_file_name_inited_  = false;
+  sql_print_information("Semi-sync replication switched OFF.");
+  cond_broadcast();                            /* wake up all waiting threads */
+
+  return function_exit(kWho, result);
+}
+
+int ReplSemiSyncMaster::try_switch_on(int server_id,
+				      const char *log_file_name,
+				      my_off_t log_file_pos)
+{
+  const char *kWho = "ReplSemiSyncMaster::try_switch_on";
+  bool semi_sync_on = false;
+
+  function_enter(kWho);
+
+  /* If the current sending event's position is larger than or equal to the
+   * 'largest' commit transaction binlog position, the slave is already
+   * catching up now and we can switch semi-sync on here.
+   * If commit_file_name_inited_ indicates there are no recent transactions,
+   * we can enable semi-sync immediately.
+   */
+  if (commit_file_name_inited_)
+  {
+    int cmp = ActiveTranx::compare(log_file_name, log_file_pos,
+                                   commit_file_name_, commit_file_pos_);
+    semi_sync_on = (cmp >= 0);
+  }
+  else
+  {
+    semi_sync_on = true;
+  }
+
+  if (semi_sync_on)
+  {
+    /* Switch semi-sync replication on. */
+    state_ = true;
+
+    sql_print_information("Semi-sync replication switched ON with slave (server_id: %d) "
+                          "at (%s, %lu)",
+                          server_id, log_file_name,
+                          (unsigned long)log_file_pos);
+  }
+
+  return function_exit(kWho, 0);
+}
+
+int ReplSemiSyncMaster::reserveSyncHeader(unsigned char *header,
+					  unsigned long size)
+{
+  const char *kWho = "ReplSemiSyncMaster::reserveSyncHeader";
+  function_enter(kWho);
+
+  int hlen=0;
+  if (!is_semi_sync_slave())
+  {
+    hlen= 0;
+  }
+  else
+  {
+    /* No enough space for the extra header, disable semi-sync master */
+    if (sizeof(kSyncHeader) > size)
+    {
+      sql_print_warning("No enough space in the packet "
+                        "for semi-sync extra header, "
+                        "semi-sync replication disabled");
+      disableMaster();
+      return 0;
+    }
+    
+    /* Set the magic number and the sync status.  By default, no sync
+     * is required.
+     */
+    memcpy(header, kSyncHeader, sizeof(kSyncHeader));
+    hlen= sizeof(kSyncHeader);
+  }
+  return function_exit(kWho, hlen);
+}
+
+int ReplSemiSyncMaster::updateSyncHeader(unsigned char *packet,
+					 const char *log_file_name,
+					 my_off_t log_file_pos,
+					 uint32 server_id)
+{
+  const char *kWho = "ReplSemiSyncMaster::updateSyncHeader";
+  int  cmp = 0;
+  bool sync = false;
+
+  /* If the semi-sync master is not enabled, or the slave is not a semi-sync
+   * target, do not request replies from the slave.
+   */
+  if (!getMasterEnabled() || !is_semi_sync_slave())
+  {
+    sync = false;
+    return 0;
+  }
+
+  function_enter(kWho);
+
+  lock();
+
+  /* This is the real check inside the mutex. */
+  if (!getMasterEnabled())
+  {
+    sync = false;
+    goto l_end;
+  }
+
+  if (is_on())
+  {
+    /* semi-sync is ON */
+    sync = false;     /* No sync unless a transaction is involved. */
+
+    if (reply_file_name_inited_)
+    {
+      cmp = ActiveTranx::compare(log_file_name, log_file_pos,
+                                 reply_file_name_, reply_file_pos_);
+      if (cmp <= 0)
+      {
+        /* If we have already got the reply for the event, then we do
+         * not need to sync the transaction again.
+         */
+        goto l_end;
+      }
+    }
+
+    if (wait_file_name_inited_)
+    {
+      cmp = ActiveTranx::compare(log_file_name, log_file_pos,
+                                 wait_file_name_, wait_file_pos_);
+    }
+    else
+    {
+      cmp = 1;
+    }
+    
+    /* If we are already waiting for some transaction replies which
+     * are later in binlog, do not wait for this one event.
+     */
+    if (cmp >= 0)
+    {
+      /* 
+       * We only wait if the event is a transaction's ending event.
+       */
+      assert(active_tranxs_ != NULL);
+      sync = active_tranxs_->is_tranx_end_pos(log_file_name,
+                                               log_file_pos);
+    }
+  }
+  else
+  {
+    if (commit_file_name_inited_)
+    {
+      int cmp = ActiveTranx::compare(log_file_name, log_file_pos,
+                                     commit_file_name_, commit_file_pos_);
+      sync = (cmp >= 0);
+    }
+    else
+    {
+      sync = true;
+    }
+  }
+
+  if (trace_level_ & kTraceDetail)
+    sql_print_information("%s: server(%d), (%s, %lu) sync(%d), repl(%d)",
+                          kWho, server_id, log_file_name,
+                          (unsigned long)log_file_pos, sync, (int)is_on());
+
+ l_end:
+  unlock();
+
+  /* We do not need to clear sync flag because we set it to 0 when we
+   * reserve the packet header.
+   */
+  if (sync)
+  {
+    (packet)[2] = kPacketFlagSync;
+  }
+
+  return function_exit(kWho, 0);
+}
+
+int ReplSemiSyncMaster::writeTranxInBinlog(const char* log_file_name,
+					   my_off_t log_file_pos)
+{
+  const char *kWho = "ReplSemiSyncMaster::writeTranxInBinlog";
+  int result = 0;
+
+  function_enter(kWho);
+
+  lock();
+
+  /* This is the real check inside the mutex. */
+  if (!getMasterEnabled())
+    goto l_end;
+
+  /* Update the 'largest' transaction commit position seen so far even
+   * though semi-sync is switched off.
+   * It is much better that we update commit_file_* here, instead of
+   * inside commitTrx().  This is mostly because updateSyncHeader()
+   * will watch for commit_file_* to decide whether to switch semi-sync
+   * on. The detailed reason is explained in function updateSyncHeader().
+   */
+  if (commit_file_name_inited_)
+  {
+    int cmp = ActiveTranx::compare(log_file_name, log_file_pos,
+                                   commit_file_name_, commit_file_pos_);
+    if (cmp > 0)
+    {
+      /* This is a larger position, let's update the maximum info. */
+      strcpy(commit_file_name_, log_file_name);
+      commit_file_pos_ = log_file_pos;
+    }
+  }
+  else
+  {
+    strcpy(commit_file_name_, log_file_name);
+    commit_file_pos_ = log_file_pos;
+    commit_file_name_inited_ = true;
+  }
+
+  if (is_on())
+  {
+    assert(active_tranxs_ != NULL);
+    if(active_tranxs_->insert_tranx_node(log_file_name, log_file_pos))
+    {
+      /*
+        if insert tranx_node failed, print a warning message
+        and turn off semi-sync
+      */
+      sql_print_warning("Semi-sync failed to insert tranx_node for binlog file: %s, position: %lu",
+                        log_file_name, (ulong)log_file_pos);
+      switch_off();
+    }
+  }
+
+ l_end:
+  unlock();
+
+  return function_exit(kWho, result);
+}
+
+int ReplSemiSyncMaster::readSlaveReply(NET *net, uint32 server_id,
+                                       const char *event_buf)
+{
+  const char *kWho = "ReplSemiSyncMaster::readSlaveReply";
+  const unsigned char *packet;
+  char     log_file_name[FN_REFLEN];
+  my_off_t log_file_pos;
+  ulong    packet_len;
+  int      result = -1;
+
+  struct timeval start_tv;
+  int   start_time_err= 0;
+  ulong trc_level = trace_level_;
+
+  function_enter(kWho);
+
+  assert((unsigned char)event_buf[1] == kPacketMagicNum);
+  if ((unsigned char)event_buf[2] != kPacketFlagSync)
+  {
+    /* current event does not require reply */
+    result = 0;
+    goto l_end;
+  }
+
+  if (trc_level & kTraceNetWait)
+    start_time_err = gettimeofday(&start_tv, 0);
+
+  /* We flush to make sure that the current event is sent to the network,
+   * instead of being buffered in the TCP/IP stack.
+   */
+  if (net_flush(net))
+  {
+    sql_print_error("Semi-sync master failed on net_flush() "
+                    "before waiting for slave reply");
+    goto l_end;
+  }
+
+  net_clear(net, 0);
+  if (trc_level & kTraceDetail)
+    sql_print_information("%s: Wait for replica's reply", kWho);
+
+  /* Wait for the network here.  Though binlog dump thread can indefinitely wait
+   * here, transactions would not wait indefintely.
+   * Transactions wait on binlog replies detected by binlog dump threads.  If
+   * binlog dump threads wait too long, transactions will timeout and continue.
+   */
+  packet_len = my_net_read(net);
+
+  if (trc_level & kTraceNetWait)
+  {
+    if (start_time_err != 0)
+    {
+      sql_print_error("Semi-sync master wait for reply "
+                      "gettimeofday fail to get start time");
+      rpl_semi_sync_master_timefunc_fails++;
+    }
+    else
+    {
+      int wait_time;
+
+      wait_time = getWaitTime(start_tv);
+      if (wait_time < 0)
+      {
+        sql_print_error("Semi-sync master wait for reply "
+                        "gettimeofday fail to get wait time.");
+        rpl_semi_sync_master_timefunc_fails++;
+      }
+      else
+      {
+        rpl_semi_sync_master_net_wait_num++;
+        rpl_semi_sync_master_net_wait_time += wait_time;
+      }
+    }
+  }
+
+  if (packet_len == packet_error || packet_len < REPLY_BINLOG_NAME_OFFSET)
+  {
+    if (packet_len == packet_error)
+      sql_print_error("Read semi-sync reply network error: %s (errno: %d)",
+                      net->last_error, net->last_errno);
+    else
+      sql_print_error("Read semi-sync reply length error: %s (errno: %d)",
+                      net->last_error, net->last_errno);
+    goto l_end;
+  }
+
+  packet = net->read_pos;
+  if (packet[REPLY_MAGIC_NUM_OFFSET] != ReplSemiSyncMaster::kPacketMagicNum)
+  {
+    sql_print_error("Read semi-sync reply magic number error");
+    goto l_end;
+  }
+
+  log_file_pos = uint8korr(packet + REPLY_BINLOG_POS_OFFSET);
+  strcpy(log_file_name, (const char*)packet + REPLY_BINLOG_NAME_OFFSET);
+
+  if (trc_level & kTraceDetail)
+    sql_print_information("%s: Got reply (%s, %lu)",
+                          kWho, log_file_name, (ulong)log_file_pos);
+
+  result = reportReplyBinlog(server_id, log_file_name, log_file_pos);
+
+ l_end:
+  return function_exit(kWho, result);
+}
+
+
+int ReplSemiSyncMaster::resetMaster()
+{
+  const char *kWho = "ReplSemiSyncMaster::resetMaster";
+  int result = 0;
+
+  function_enter(kWho);
+
+
+  lock();
+
+  state_ = getMasterEnabled()? 1 : 0;
+
+  wait_file_name_inited_   = false;
+  reply_file_name_inited_  = false;
+  commit_file_name_inited_ = false;
+
+  rpl_semi_sync_master_yes_transactions = 0;
+  rpl_semi_sync_master_no_transactions = 0;
+  rpl_semi_sync_master_off_times = 0;
+  rpl_semi_sync_master_timefunc_fails = 0;
+  rpl_semi_sync_master_wait_sessions = 0;
+  rpl_semi_sync_master_wait_pos_backtraverse = 0;
+  rpl_semi_sync_master_trx_wait_num = 0;
+  rpl_semi_sync_master_trx_wait_time = 0;
+  rpl_semi_sync_master_net_wait_num = 0;
+  rpl_semi_sync_master_net_wait_time = 0;
+
+  unlock();
+
+  return function_exit(kWho, result);
+}
+
+void ReplSemiSyncMaster::setExportStats()
+{
+  lock();
+
+  rpl_semi_sync_master_status           = state_;
+  rpl_semi_sync_master_avg_trx_wait_time=
+    ((rpl_semi_sync_master_trx_wait_num) ?
+     (unsigned long)((double)rpl_semi_sync_master_trx_wait_time /
+                     ((double)rpl_semi_sync_master_trx_wait_num)) : 0);
+  rpl_semi_sync_master_avg_net_wait_time=
+    ((rpl_semi_sync_master_net_wait_num) ?
+     (unsigned long)((double)rpl_semi_sync_master_net_wait_time /
+                     ((double)rpl_semi_sync_master_net_wait_num)) : 0);
+
+  unlock();
+}
+
+/* Get the waiting time given the wait's staring time.
+ * 
+ * Return:
+ *  >= 0: the waiting time in microsecons(us)
+ *   < 0: error in gettimeofday or time back traverse
+ */
+static int getWaitTime(const struct timeval& start_tv)
+{
+  unsigned long long start_usecs, end_usecs;
+  struct timeval end_tv;
+  int end_time_err;
+
+  /* Starting time in microseconds(us). */
+  start_usecs = start_tv.tv_sec * TIME_MILLION + start_tv.tv_usec;
+
+  /* Get the wait time interval. */
+  end_time_err = gettimeofday(&end_tv, 0);
+
+  /* Ending time in microseconds(us). */
+  end_usecs = end_tv.tv_sec * TIME_MILLION + end_tv.tv_usec;
+
+  if (end_time_err != 0 || end_usecs < start_usecs)
+    return -1;
+
+  return (int)(end_usecs - start_usecs);
+}
diff --git a/plugin/semisync/semisync_master.h b/plugin/semisync/semisync_master.h
new file mode 100644
index 0000000000000000000000000000000000000000..d2b8774560090741a5963fa55d715c1e8b611f3e
--- /dev/null
+++ b/plugin/semisync/semisync_master.h
@@ -0,0 +1,374 @@
+/* Copyright (C) 2007 Google Inc.
+   Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#ifndef SEMISYNC_MASTER_H
+#define SEMISYNC_MASTER_H
+
+#include "semisync.h"
+
+/**
+   This class manages memory for active transaction list.
+
+   We record each active transaction with a TranxNode.  Because each
+   session can only have only one open transaction, the total active
+   transaction nodes can not exceed the maximum sessions.  Currently
+   in MySQL, sessions are the same as connections.
+*/
+class ActiveTranx
+  :public Trace {
+private:
+  struct TranxNode {
+    char             *log_name_;
+    my_off_t          log_pos_;
+    struct TranxNode *next_;            /* the next node in the sorted list */
+    struct TranxNode *hash_next_;    /* the next node during hash collision */
+  };
+
+  /* The following data structure maintains an active transaction list. */
+  TranxNode       *node_array_;
+  TranxNode       *free_pool_;
+
+  /* These two record the active transaction list in sort order. */
+  TranxNode       *trx_front_, *trx_rear_;
+
+  TranxNode      **trx_htb_;        /* A hash table on active transactions. */
+
+  int              num_transactions_;               /* maximum transactions */
+  int              num_entries_;              /* maximum hash table entries */
+  pthread_mutex_t *lock_;                                     /* mutex lock */
+
+  inline void assert_lock_owner();
+
+  inline TranxNode* alloc_tranx_node();
+
+  inline unsigned int calc_hash(const unsigned char *key,unsigned int length);
+  unsigned int get_hash_value(const char *log_file_name, my_off_t log_file_pos);
+
+  int compare(const char *log_file_name1, my_off_t log_file_pos1,
+	      const TranxNode *node2) {
+    return compare(log_file_name1, log_file_pos1,
+		   node2->log_name_, node2->log_pos_);
+  }
+  int compare(const TranxNode *node1,
+	      const char *log_file_name2, my_off_t log_file_pos2) {
+    return compare(node1->log_name_, node1->log_pos_,
+		   log_file_name2, log_file_pos2);
+  }
+  int compare(const TranxNode *node1, const TranxNode *node2) {
+    return compare(node1->log_name_, node1->log_pos_,
+		   node2->log_name_, node2->log_pos_);
+  }
+
+public:
+  ActiveTranx(int max_connections, pthread_mutex_t *lock,
+	      unsigned long trace_level);
+  ~ActiveTranx();
+
+  /* Insert an active transaction node with the specified position.
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int insert_tranx_node(const char *log_file_name, my_off_t log_file_pos);
+
+  /* Clear the active transaction nodes until(inclusive) the specified
+   * position.
+   * If log_file_name is NULL, everything will be cleared: the sorted
+   * list and the hash table will be reset to empty.
+   * 
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int clear_active_tranx_nodes(const char *log_file_name,
+			       my_off_t    log_file_pos);
+
+  /* Given a position, check to see whether the position is an active
+   * transaction's ending position by probing the hash table.
+   */
+  bool is_tranx_end_pos(const char *log_file_name, my_off_t log_file_pos);
+
+  /* Given two binlog positions, compare which one is bigger based on
+   * (file_name, file_position).
+   */
+  static int compare(const char *log_file_name1, my_off_t log_file_pos1,
+		     const char *log_file_name2, my_off_t log_file_pos2);
+
+};
+
+/**
+   The extension class for the master of semi-synchronous replication
+*/
+class ReplSemiSyncMaster
+  :public ReplSemiSyncBase {
+ private:
+  ActiveTranx    *active_tranxs_;  /* active transaction list: the list will
+                                      be cleared when semi-sync switches off. */
+
+  /* True when initObject has been called */
+  bool init_done_;
+
+  /* This cond variable is signaled when enough binlog has been sent to slave,
+   * so that a waiting trx can return the 'ok' to the client for a commit.
+   */
+  pthread_cond_t  COND_binlog_send_;
+
+  /* Mutex that protects the following state variables and the active
+   * transaction list.
+   * Under no cirumstances we can acquire mysql_bin_log.LOCK_log if we are
+   * already holding LOCK_binlog_ because it can cause deadlocks.
+   */
+  pthread_mutex_t LOCK_binlog_;
+
+  /* This is set to true when reply_file_name_ contains meaningful data. */
+  bool            reply_file_name_inited_;
+
+  /* The binlog name up to which we have received replies from any slaves. */
+  char            reply_file_name_[FN_REFLEN];
+
+  /* The position in that file up to which we have the reply from any slaves. */
+  my_off_t        reply_file_pos_;
+
+  /* This is set to true when we know the 'smallest' wait position. */
+  bool            wait_file_name_inited_;
+
+  /* NULL, or the 'smallest' filename that a transaction is waiting for
+   * slave replies.
+   */
+  char            wait_file_name_[FN_REFLEN];
+
+  /* The smallest position in that file that a trx is waiting for: the trx
+   * can proceed and send an 'ok' to the client when the master has got the
+   * reply from the slave indicating that it already got the binlog events.
+   */
+  my_off_t        wait_file_pos_;
+
+  /* This is set to true when we know the 'largest' transaction commit
+   * position in the binlog file.
+   * We always maintain the position no matter whether semi-sync is switched
+   * on switched off.  When a transaction wait timeout occurs, semi-sync will
+   * switch off.  Binlog-dump thread can use the three fields to detect when
+   * slaves catch up on replication so that semi-sync can switch on again.
+   */
+  bool            commit_file_name_inited_;
+
+  /* The 'largest' binlog filename that a commit transaction is seeing.       */
+  char            commit_file_name_[FN_REFLEN];
+
+  /* The 'largest' position in that file that a commit transaction is seeing. */
+  my_off_t        commit_file_pos_;
+
+  /* All global variables which can be set by parameters. */
+  volatile bool            master_enabled_;      /* semi-sync is enabled on the master */
+  unsigned long           wait_timeout_;      /* timeout period(ms) during tranx wait */
+
+  bool            state_;                    /* whether semi-sync is switched */
+
+  /* The number of maximum active transactions.  This should be the same as
+   * maximum connections because MySQL does not do connection sharing now.
+   */
+  int             max_transactions_;
+
+  void lock();
+  void unlock();
+  void cond_broadcast();
+  int  cond_timewait(struct timespec *wait_time);
+
+  /* Is semi-sync replication on? */
+  bool is_on() {
+    return (state_);
+  }
+
+  void set_master_enabled(bool enabled) {
+    master_enabled_ = enabled;
+  }
+
+  /* Switch semi-sync off because of timeout in transaction waiting. */
+  int switch_off();
+
+  /* Switch semi-sync on when slaves catch up. */
+  int try_switch_on(int server_id,
+                    const char *log_file_name, my_off_t log_file_pos);
+
+ public:
+  ReplSemiSyncMaster();
+  ~ReplSemiSyncMaster();
+
+  bool getMasterEnabled() {
+    return master_enabled_;
+  }
+  void setTraceLevel(unsigned long trace_level) {
+    trace_level_ = trace_level;
+    if (active_tranxs_)
+      active_tranxs_->trace_level_ = trace_level;
+  }
+
+  /* Set the transaction wait timeout period, in milliseconds. */
+  void setWaitTimeout(unsigned long wait_timeout) {
+    wait_timeout_ = wait_timeout;
+  }
+
+  /* Initialize this class after MySQL parameters are initialized. this
+   * function should be called once at bootstrap time.
+   */
+  int initObject();
+
+  /* Enable the object to enable semi-sync replication inside the master. */
+  int enableMaster();
+
+  /* Enable the object to enable semi-sync replication inside the master. */
+  int disableMaster();
+
+  /* Add a semi-sync replication slave */
+  void add_slave();
+    
+  /* Remove a semi-sync replication slave */
+  void remove_slave();
+
+  /* Is the slave servered by the thread requested semi-sync */
+  bool is_semi_sync_slave();
+
+  /* In semi-sync replication, reports up to which binlog position we have
+   * received replies from the slave indicating that it already get the events.
+   *
+   * Input:
+   *  server_id     - (IN)  master server id number
+   *  log_file_name - (IN)  binlog file name
+   *  end_offset    - (IN)  the offset in the binlog file up to which we have
+   *                        the replies from the slave
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int reportReplyBinlog(uint32 server_id,
+                        const char* log_file_name,
+                        my_off_t end_offset);
+
+  /* Commit a transaction in the final step.  This function is called from
+   * InnoDB before returning from the low commit.  If semi-sync is switch on,
+   * the function will wait to see whether binlog-dump thread get the reply for
+   * the events of the transaction.  Remember that this is not a direct wait,
+   * instead, it waits to see whether the binlog-dump thread has reached the
+   * point.  If the wait times out, semi-sync status will be switched off and
+   * all other transaction would not wait either.
+   *
+   * Input:  (the transaction events' ending binlog position)
+   *  trx_wait_binlog_name - (IN)  ending position's file name
+   *  trx_wait_binlog_pos  - (IN)  ending position's file offset
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int commitTrx(const char* trx_wait_binlog_name,
+                my_off_t trx_wait_binlog_pos);
+
+  /* Reserve space in the replication event packet header:
+   *  . slave semi-sync off: 1 byte - (0)
+   *  . slave semi-sync on:  3 byte - (0, 0xef, 0/1}
+   * 
+   * Input:
+   *  header   - (IN)  the header buffer
+   *  size     - (IN)  size of the header buffer
+   *
+   * Return:
+   *  size of the bytes reserved for header
+   */
+  int reserveSyncHeader(unsigned char *header, unsigned long size);
+
+  /* Update the sync bit in the packet header to indicate to the slave whether
+   * the master will wait for the reply of the event.  If semi-sync is switched
+   * off and we detect that the slave is catching up, we switch semi-sync on.
+   * 
+   * Input:
+   *  packet        - (IN)  the packet containing the replication event
+   *  log_file_name - (IN)  the event ending position's file name
+   *  log_file_pos  - (IN)  the event ending position's file offset
+   *  server_id     - (IN)  master server id number
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int updateSyncHeader(unsigned char *packet,
+                       const char *log_file_name,
+		       my_off_t log_file_pos,
+		       uint32 server_id);
+
+  /* Called when a transaction finished writing binlog events.
+   *  . update the 'largest' transactions' binlog event position
+   *  . insert the ending position in the active transaction list if
+   *    semi-sync is on
+   * 
+   * Input:  (the transaction events' ending binlog position)
+   *  log_file_name - (IN)  transaction ending position's file name
+   *  log_file_pos  - (IN)  transaction ending position's file offset
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int writeTranxInBinlog(const char* log_file_name, my_off_t log_file_pos);
+
+  /* Read the slave's reply so that we know how much progress the slave makes
+   * on receive replication events.
+   * 
+   * Input:
+   *  net          - (IN)  the connection to master
+   *  server_id    - (IN)  master server id number
+   *  event_buf    - (IN)  pointer to the event packet
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int readSlaveReply(NET *net, uint32 server_id, const char *event_buf);
+
+  /* Export internal statistics for semi-sync replication. */
+  void setExportStats();
+
+  /* 'reset master' command is issued from the user and semi-sync need to
+   * go off for that.
+   */
+  int resetMaster();
+};
+
+/* System and status variables for the master component */
+extern char rpl_semi_sync_master_enabled;
+extern char rpl_semi_sync_master_status;
+extern unsigned long rpl_semi_sync_master_clients;
+extern unsigned long rpl_semi_sync_master_timeout;
+extern unsigned long rpl_semi_sync_master_trace_level;
+extern unsigned long rpl_semi_sync_master_yes_transactions;
+extern unsigned long rpl_semi_sync_master_no_transactions;
+extern unsigned long rpl_semi_sync_master_off_times;
+extern unsigned long rpl_semi_sync_master_wait_timeouts;
+extern unsigned long rpl_semi_sync_master_timefunc_fails;
+extern unsigned long rpl_semi_sync_master_num_timeouts;
+extern unsigned long rpl_semi_sync_master_wait_sessions;
+extern unsigned long rpl_semi_sync_master_wait_pos_backtraverse;
+extern unsigned long rpl_semi_sync_master_avg_trx_wait_time;
+extern unsigned long rpl_semi_sync_master_avg_net_wait_time;
+extern unsigned long long rpl_semi_sync_master_net_wait_num;
+extern unsigned long long rpl_semi_sync_master_trx_wait_num;
+extern unsigned long long rpl_semi_sync_master_net_wait_time;
+extern unsigned long long rpl_semi_sync_master_trx_wait_time;
+
+/*
+  This indicates whether we should keep waiting if no semi-sync slave
+  is available.
+     0           : stop waiting if detected no avaialable semi-sync slave.
+     1 (default) : keep waiting until timeout even no available semi-sync slave.
+*/
+extern char rpl_semi_sync_master_wait_no_slave;
+
+#endif /* SEMISYNC_MASTER_H */
diff --git a/plugin/semisync/semisync_master_plugin.cc b/plugin/semisync/semisync_master_plugin.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2ef500d9320e041082fb01645969ed0ac2bbbeb
--- /dev/null
+++ b/plugin/semisync/semisync_master_plugin.cc
@@ -0,0 +1,393 @@
+/* Copyright (C) 2007 Google Inc.
+   Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#include "semisync_master.h"
+
+ReplSemiSyncMaster repl_semisync;
+
+int repl_semi_report_binlog_update(Binlog_storage_param *param,
+				   const char *log_file,
+				   my_off_t log_pos, uint32 flags)
+{
+  int  error= 0;
+
+  if (repl_semisync.getMasterEnabled())
+  {
+    /*
+      Let us store the binlog file name and the position, so that
+      we know how long to wait for the binlog to the replicated to
+      the slave in synchronous replication.
+    */
+    error= repl_semisync.writeTranxInBinlog(log_file,
+                                            log_pos);
+  }
+
+  return error;
+}
+
+int repl_semi_request_commit(Trans_param *param)
+{
+  return 0;
+}
+
+int repl_semi_report_commit(Trans_param *param)
+{
+
+  bool is_real_trans= param->flags & TRANS_IS_REAL_TRANS;
+
+  if (is_real_trans && param->log_pos)
+  {
+    const char *binlog_name= param->log_file;
+    return repl_semisync.commitTrx(binlog_name, param->log_pos);
+  }
+  return 0;
+}
+
+int repl_semi_report_rollback(Trans_param *param)
+{
+  return repl_semi_report_commit(param);
+}
+
+int repl_semi_binlog_dump_start(Binlog_transmit_param *param,
+				 const char *log_file,
+				 my_off_t log_pos)
+{
+  bool semi_sync_slave= repl_semisync.is_semi_sync_slave();
+  
+  if (semi_sync_slave)
+  {
+    /* One more semi-sync slave */
+    repl_semisync.add_slave();
+    
+    /*
+      Let's assume this semi-sync slave has already received all
+      binlog events before the filename and position it requests.
+    */
+    repl_semisync.reportReplyBinlog(param->server_id, log_file, log_pos);
+  }
+  sql_print_information("Start %s binlog_dump to slave (server_id: %d), pos(%s, %lu)",
+			semi_sync_slave ? "semi-sync" : "asynchronous",
+			param->server_id, log_file, (unsigned long)log_pos);
+  
+  return 0;
+}
+
+int repl_semi_binlog_dump_end(Binlog_transmit_param *param)
+{
+  bool semi_sync_slave= repl_semisync.is_semi_sync_slave();
+  
+  sql_print_information("Stop %s binlog_dump to slave (server_id: %d)",
+                        semi_sync_slave ? "semi-sync" : "asynchronous",
+                        param->server_id);
+  if (semi_sync_slave)
+  {
+    /* One less semi-sync slave */
+    repl_semisync.remove_slave();
+  }
+  return 0;
+}
+
+int repl_semi_reserve_header(Binlog_transmit_param *param,
+			     unsigned char *header,
+			     unsigned long size, unsigned long *len)
+{
+  *len +=  repl_semisync.reserveSyncHeader(header, size);
+  return 0;
+}
+
+int repl_semi_before_send_event(Binlog_transmit_param *param,
+                                unsigned char *packet, unsigned long len,
+                                const char *log_file, my_off_t log_pos)
+{
+  return repl_semisync.updateSyncHeader(packet,
+					log_file,
+					log_pos,
+					param->server_id);
+}
+
+int repl_semi_after_send_event(Binlog_transmit_param *param,
+                               const char *event_buf, unsigned long len)
+{
+  if (repl_semisync.is_semi_sync_slave())
+  {
+    THD *thd= current_thd;
+    /*
+      Possible errors in reading slave reply are ignored deliberately
+      because we do not want dump thread to quit on this. Error
+      messages are already reported.
+    */
+    (void) repl_semisync.readSlaveReply(&thd->net,
+                                        param->server_id, event_buf);
+    thd->clear_error();
+  }
+  return 0;
+}
+
+int repl_semi_reset_master(Binlog_transmit_param *param)
+{
+  if (repl_semisync.resetMaster())
+    return 1;
+  return 0;
+}
+
+/*
+  semisync system variables
+ */
+static void fix_rpl_semi_sync_master_timeout(MYSQL_THD thd,
+				      SYS_VAR *var,
+				      void *ptr,
+				      const void *val);
+
+static void fix_rpl_semi_sync_master_trace_level(MYSQL_THD thd,
+					  SYS_VAR *var,
+					  void *ptr,
+					  const void *val);
+
+static void fix_rpl_semi_sync_master_enabled(MYSQL_THD thd,
+				      SYS_VAR *var,
+				      void *ptr,
+				      const void *val);
+
+static MYSQL_SYSVAR_BOOL(enabled, rpl_semi_sync_master_enabled,
+  PLUGIN_VAR_OPCMDARG,
+ "Enable semi-synchronous replication master (disabled by default). ",
+  NULL, 			// check
+  &fix_rpl_semi_sync_master_enabled,	// update
+  0);
+
+static MYSQL_SYSVAR_ULONG(timeout, rpl_semi_sync_master_timeout,
+  PLUGIN_VAR_OPCMDARG,
+ "The timeout value (in ms) for semi-synchronous replication in the master",
+  NULL, 			// check
+  fix_rpl_semi_sync_master_timeout,	// update
+  10000, 0, ~0L, 1);
+
+static MYSQL_SYSVAR_BOOL(wait_no_slave, rpl_semi_sync_master_wait_no_slave,
+  PLUGIN_VAR_OPCMDARG,
+ "Wait until timeout when no semi-synchronous replication slave available (enabled by default). ",
+  NULL, 			// check
+  NULL,                         // update
+  1);
+
+static MYSQL_SYSVAR_ULONG(trace_level, rpl_semi_sync_master_trace_level,
+  PLUGIN_VAR_OPCMDARG,
+ "The tracing level for semi-sync replication.",
+  NULL,				  // check
+  &fix_rpl_semi_sync_master_trace_level, // update
+  32, 0, ~0L, 1);
+
+static SYS_VAR* semi_sync_master_system_vars[]= {
+  MYSQL_SYSVAR(enabled),
+  MYSQL_SYSVAR(timeout),
+  MYSQL_SYSVAR(wait_no_slave),
+  MYSQL_SYSVAR(trace_level),
+  NULL,
+};
+
+
+static void fix_rpl_semi_sync_master_timeout(MYSQL_THD thd,
+				      SYS_VAR *var,
+				      void *ptr,
+				      const void *val)
+{
+  *(unsigned long *)ptr= *(unsigned long *)val;
+  repl_semisync.setWaitTimeout(rpl_semi_sync_master_timeout);
+  return;
+}
+
+static void fix_rpl_semi_sync_master_trace_level(MYSQL_THD thd,
+					  SYS_VAR *var,
+					  void *ptr,
+					  const void *val)
+{
+  *(unsigned long *)ptr= *(unsigned long *)val;
+  repl_semisync.setTraceLevel(rpl_semi_sync_master_trace_level);
+  return;
+}
+
+static void fix_rpl_semi_sync_master_enabled(MYSQL_THD thd,
+				      SYS_VAR *var,
+				      void *ptr,
+				      const void *val)
+{
+  *(char *)ptr= *(char *)val;
+  if (rpl_semi_sync_master_enabled)
+  {
+    if (repl_semisync.enableMaster() != 0)
+      rpl_semi_sync_master_enabled = false;
+  }
+  else
+  {
+    if (repl_semisync.disableMaster() != 0)
+      rpl_semi_sync_master_enabled = true;
+  }
+
+  return;
+}
+
+Trans_observer trans_observer = {
+  sizeof(Trans_observer),		// len
+
+  repl_semi_report_commit,	// after_commit
+  repl_semi_report_rollback,	// after_rollback
+};
+
+Binlog_storage_observer storage_observer = {
+  sizeof(Binlog_storage_observer), // len
+
+  repl_semi_report_binlog_update, // report_update
+};
+
+Binlog_transmit_observer transmit_observer = {
+  sizeof(Binlog_transmit_observer), // len
+
+  repl_semi_binlog_dump_start,	// start
+  repl_semi_binlog_dump_end,	// stop
+  repl_semi_reserve_header,	// reserve_header
+  repl_semi_before_send_event,	// before_send_event
+  repl_semi_after_send_event,	// after_send_event
+  repl_semi_reset_master,	// reset
+};
+
+
+#define SHOW_FNAME(name)			\
+  rpl_semi_sync_master_show_##name
+
+#define DEF_SHOW_FUNC(name, show_type)					\
+  static  int SHOW_FNAME(name)(MYSQL_THD thd, SHOW_VAR *var, char *buff) \
+  {									\
+    repl_semisync.setExportStats();					\
+    var->type= show_type;						\
+    var->value= (char *)&rpl_semi_sync_master_##name;				\
+    return 0;								\
+  }
+
+DEF_SHOW_FUNC(status, SHOW_BOOL)
+DEF_SHOW_FUNC(clients, SHOW_LONG)
+DEF_SHOW_FUNC(trx_wait_time, SHOW_LONGLONG)
+DEF_SHOW_FUNC(trx_wait_num, SHOW_LONGLONG)
+DEF_SHOW_FUNC(net_wait_time, SHOW_LONGLONG)
+DEF_SHOW_FUNC(net_wait_num, SHOW_LONGLONG)
+DEF_SHOW_FUNC(avg_net_wait_time, SHOW_LONG)
+DEF_SHOW_FUNC(avg_trx_wait_time, SHOW_LONG)
+
+
+/* plugin status variables */
+static SHOW_VAR semi_sync_master_status_vars[]= {
+  {"Rpl_semi_sync_master_status",
+   (char*) &SHOW_FNAME(status),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_clients",
+   (char*) &SHOW_FNAME(clients),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_yes_tx",
+   (char*) &rpl_semi_sync_master_yes_transactions,
+   SHOW_LONG},
+  {"Rpl_semi_sync_master_no_tx",
+   (char*) &rpl_semi_sync_master_no_transactions,
+   SHOW_LONG},
+  {"Rpl_semi_sync_master_wait_sessions",
+   (char*) &rpl_semi_sync_master_wait_sessions,
+   SHOW_LONG},
+  {"Rpl_semi_sync_master_no_times",
+   (char*) &rpl_semi_sync_master_off_times,
+   SHOW_LONG},
+  {"Rpl_semi_sync_master_timefunc_failures",
+   (char*) &rpl_semi_sync_master_timefunc_fails,
+   SHOW_LONG},
+  {"Rpl_semi_sync_master_wait_pos_backtraverse",
+   (char*) &rpl_semi_sync_master_wait_pos_backtraverse,
+   SHOW_LONG},
+  {"Rpl_semi_sync_master_tx_wait_time",
+   (char*) &SHOW_FNAME(trx_wait_time),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_tx_waits",
+   (char*) &SHOW_FNAME(trx_wait_num),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_tx_avg_wait_time",
+   (char*) &SHOW_FNAME(avg_trx_wait_time),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_net_wait_time",
+   (char*) &SHOW_FNAME(net_wait_time),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_net_waits",
+   (char*) &SHOW_FNAME(net_wait_num),
+   SHOW_FUNC},
+  {"Rpl_semi_sync_master_net_avg_wait_time",
+   (char*) &SHOW_FNAME(avg_net_wait_time),
+   SHOW_FUNC},
+  {NULL, NULL, SHOW_LONG},
+};
+
+
+static int semi_sync_master_plugin_init(void *p)
+{
+  if (repl_semisync.initObject())
+    return 1;
+  if (register_trans_observer(&trans_observer, p))
+    return 1;
+  if (register_binlog_storage_observer(&storage_observer, p))
+    return 1;
+  if (register_binlog_transmit_observer(&transmit_observer, p))
+    return 1;
+  return 0;
+}
+
+static int semi_sync_master_plugin_deinit(void *p)
+{
+  if (unregister_trans_observer(&trans_observer, p))
+  {
+    sql_print_error("unregister_trans_observer failed");
+    return 1;
+  }
+  if (unregister_binlog_storage_observer(&storage_observer, p))
+  {
+    sql_print_error("unregister_binlog_storage_observer failed");
+    return 1;
+  }
+  if (unregister_binlog_transmit_observer(&transmit_observer, p))
+  {
+    sql_print_error("unregister_binlog_transmit_observer failed");
+    return 1;
+  }
+  sql_print_information("unregister_replicator OK");
+  return 0;
+}
+
+struct Mysql_replication semi_sync_master_plugin= {
+  MYSQL_REPLICATION_INTERFACE_VERSION
+};
+
+/*
+  Plugin library descriptor
+*/
+mysql_declare_plugin(semi_sync_master)
+{
+  MYSQL_REPLICATION_PLUGIN,
+  &semi_sync_master_plugin,
+  "rpl_semi_sync_master",
+  "He Zhenxing",
+  "Semi-synchronous replication master",
+  PLUGIN_LICENSE_GPL,
+  semi_sync_master_plugin_init, /* Plugin Init */
+  semi_sync_master_plugin_deinit, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+  semi_sync_master_status_vars,	/* status variables */
+  semi_sync_master_system_vars,	/* system variables */
+  NULL                        /* config options                  */
+}
+mysql_declare_plugin_end;
diff --git a/plugin/semisync/semisync_slave.cc b/plugin/semisync/semisync_slave.cc
new file mode 100644
index 0000000000000000000000000000000000000000..109577fb688e5a0a4223c89627275a9e8219513e
--- /dev/null
+++ b/plugin/semisync/semisync_slave.cc
@@ -0,0 +1,138 @@
+/* Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#include "semisync_slave.h"
+
+char rpl_semi_sync_slave_enabled;
+char rpl_semi_sync_slave_status= 0;
+unsigned long rpl_semi_sync_slave_trace_level;
+
+int ReplSemiSyncSlave::initObject()
+{
+  int result= 0;
+  const char *kWho = "ReplSemiSyncSlave::initObject";
+
+  if (init_done_)
+  {
+    fprintf(stderr, "%s called twice\n", kWho);
+    return 1;
+  }
+  init_done_ = true;
+
+  /* References to the parameter works after set_options(). */
+  setSlaveEnabled(rpl_semi_sync_slave_enabled);
+  setTraceLevel(rpl_semi_sync_slave_trace_level);
+
+  return result;
+}
+
+int ReplSemiSyncSlave::slaveReadSyncHeader(const char *header,
+                                      unsigned long total_len,
+                                      bool  *need_reply,
+                                      const char **payload,
+                                      unsigned long *payload_len)
+{
+  const char *kWho = "ReplSemiSyncSlave::slaveReadSyncHeader";
+  int read_res = 0;
+  function_enter(kWho);
+
+  if ((unsigned char)(header[0]) == kPacketMagicNum)
+  {
+    *need_reply  = (header[1] & kPacketFlagSync);
+    *payload_len = total_len - 2;
+    *payload     = header + 2;
+
+    if (trace_level_ & kTraceDetail)
+      sql_print_information("%s: reply - %d", kWho, *need_reply);
+  }
+  else
+  {
+    sql_print_error("Missing magic number for semi-sync packet, packet "
+                    "len: %lu", total_len);
+    read_res = -1;
+  }
+
+  return function_exit(kWho, read_res);
+}
+
+int ReplSemiSyncSlave::slaveStart(Binlog_relay_IO_param *param)
+{
+  bool semi_sync= getSlaveEnabled();
+  
+  sql_print_information("Slave I/O thread: Start %s replication to\
+ master '%s@%s:%d' in log '%s' at position %lu",
+			semi_sync ? "semi-sync" : "asynchronous",
+			param->user, param->host, param->port,
+			param->master_log_name[0] ? param->master_log_name : "FIRST",
+			(unsigned long)param->master_log_pos);
+
+  if (semi_sync && !rpl_semi_sync_slave_status)
+    rpl_semi_sync_slave_status= 1;
+  return 0;
+}
+
+int ReplSemiSyncSlave::slaveStop(Binlog_relay_IO_param *param)
+{
+  if (rpl_semi_sync_slave_status)
+    rpl_semi_sync_slave_status= 0;
+  if (mysql_reply)
+    mysql_close(mysql_reply);
+  mysql_reply= 0;
+  return 0;
+}
+
+int ReplSemiSyncSlave::slaveReply(MYSQL *mysql,
+                                 const char *binlog_filename,
+                                 my_off_t binlog_filepos)
+{
+  const char *kWho = "ReplSemiSyncSlave::slaveReply";
+  NET *net= &mysql->net;
+  uchar reply_buffer[REPLY_MAGIC_NUM_LEN
+                     + REPLY_BINLOG_POS_LEN
+                     + REPLY_BINLOG_NAME_LEN];
+  int  reply_res, name_len = strlen(binlog_filename);
+
+  function_enter(kWho);
+
+  /* Prepare the buffer of the reply. */
+  reply_buffer[REPLY_MAGIC_NUM_OFFSET] = kPacketMagicNum;
+  int8store(reply_buffer + REPLY_BINLOG_POS_OFFSET, binlog_filepos);
+  memcpy(reply_buffer + REPLY_BINLOG_NAME_OFFSET,
+         binlog_filename,
+         name_len + 1 /* including trailing '\0' */);
+
+  if (trace_level_ & kTraceDetail)
+    sql_print_information("%s: reply (%s, %lu)", kWho,
+                          binlog_filename, (ulong)binlog_filepos);
+
+  net_clear(net, 0);
+  /* Send the reply. */
+  reply_res = my_net_write(net, reply_buffer,
+                           name_len + REPLY_BINLOG_NAME_OFFSET);
+  if (!reply_res)
+  {
+    reply_res = net_flush(net);
+    if (reply_res)
+      sql_print_error("Semi-sync slave net_flush() reply failed");
+  }
+  else
+  {
+    sql_print_error("Semi-sync slave send reply failed: %s (%d)",
+                    net->last_error, net->last_errno);
+  }
+
+  return function_exit(kWho, reply_res);
+}
diff --git a/plugin/semisync/semisync_slave.h b/plugin/semisync/semisync_slave.h
new file mode 100644
index 0000000000000000000000000000000000000000..19ea43e26538046d7fd155f882535dcf9dafb555
--- /dev/null
+++ b/plugin/semisync/semisync_slave.h
@@ -0,0 +1,96 @@
+/* Copyright (C) 2006 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#ifndef SEMISYNC_SLAVE_H
+#define SEMISYNC_SLAVE_H
+
+#include "semisync.h"
+
+/**
+   The extension class for the slave of semi-synchronous replication
+*/
+class ReplSemiSyncSlave
+  :public ReplSemiSyncBase {
+public:
+ ReplSemiSyncSlave()
+   :slave_enabled_(false)
+  {}
+  ~ReplSemiSyncSlave() {}
+
+  void setTraceLevel(unsigned long trace_level) {
+    trace_level_ = trace_level;
+  }
+
+  /* Initialize this class after MySQL parameters are initialized. this
+   * function should be called once at bootstrap time.
+   */
+  int initObject();
+
+  bool getSlaveEnabled() {
+    return slave_enabled_;
+  }
+  void setSlaveEnabled(bool enabled) {
+    slave_enabled_ = enabled;
+  }
+
+  /* A slave reads the semi-sync packet header and separate the metadata
+   * from the payload data.
+   * 
+   * Input:
+   *  header      - (IN)  packet header pointer
+   *  total_len   - (IN)  total packet length: metadata + payload
+   *  need_reply  - (IN)  whether the master is waiting for the reply
+   *  payload     - (IN)  payload: the replication event
+   *  payload_len - (IN)  payload length
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int slaveReadSyncHeader(const char *header, unsigned long total_len, bool *need_reply,
+                          const char **payload, unsigned long *payload_len);
+
+  /* A slave replies to the master indicating its replication process.  It
+   * indicates that the slave has received all events before the specified
+   * binlog position.
+   * 
+   * Input:
+   *  mysql            - (IN)  the mysql network connection
+   *  binlog_filename  - (IN)  the reply point's binlog file name
+   *  binlog_filepos   - (IN)  the reply point's binlog file offset
+   *
+   * Return:
+   *  0: success;  non-zero: error
+   */
+  int slaveReply(MYSQL *mysql, const char *binlog_filename,
+                 my_off_t binlog_filepos);
+
+  int slaveStart(Binlog_relay_IO_param *param);
+  int slaveStop(Binlog_relay_IO_param *param);
+
+private:
+  /* True when initObject has been called */
+  bool init_done_;
+  bool slave_enabled_;        /* semi-sycn is enabled on the slave */
+  MYSQL *mysql_reply;         /* connection to send reply */
+};
+
+
+/* System and status variables for the slave component */
+extern char rpl_semi_sync_slave_enabled;
+extern unsigned long rpl_semi_sync_slave_trace_level;
+extern char rpl_semi_sync_slave_status;
+
+#endif /* SEMISYNC_SLAVE_H */
diff --git a/plugin/semisync/semisync_slave_plugin.cc b/plugin/semisync/semisync_slave_plugin.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0bd9e1b8b21576129d3803ae46a90d25e1715f0f
--- /dev/null
+++ b/plugin/semisync/semisync_slave_plugin.cc
@@ -0,0 +1,226 @@
+/* Copyright (C) 2007 Google Inc.
+   Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
+
+
+#include "semisync_slave.h"
+
+ReplSemiSyncSlave repl_semisync;
+
+/*
+  indicate whether or not the slave should send a reply to the master.
+
+  This is set to true in repl_semi_slave_read_event if the current
+  event read is the last event of a transaction. And the value is
+  checked in repl_semi_slave_queue_event.
+*/
+bool semi_sync_need_reply= false;
+
+int repl_semi_reset_slave(Binlog_relay_IO_param *param)
+{
+  // TODO: reset semi-sync slave status here
+  return 0;
+}
+
+int repl_semi_slave_request_dump(Binlog_relay_IO_param *param,
+				 uint32 flags)
+{
+  MYSQL *mysql= param->mysql;
+  MYSQL_RES *res= 0;
+  MYSQL_ROW row;
+  const char *query;
+
+  if (!repl_semisync.getSlaveEnabled())
+    return 0;
+
+  /* Check if master server has semi-sync plugin installed */
+  query= "SHOW VARIABLES LIKE 'rpl_semi_sync_master_enabled'";
+  if (mysql_real_query(mysql, query, strlen(query)) ||
+      !(res= mysql_store_result(mysql)))
+  {
+    mysql_free_result(mysql_store_result(mysql));
+    sql_print_error("Execution failed on master: %s", query);
+    return 1;
+  }
+
+  row= mysql_fetch_row(res);
+  if (!row)
+  {
+    /* Master does not support semi-sync */
+    sql_print_warning("Master server does not support semi-sync, "
+                      "fallback to asynchronous replication");
+    rpl_semi_sync_slave_status= 0;
+    return 0;
+  }
+
+  /*
+    Tell master dump thread that we want to do semi-sync
+    replication
+  */
+  query= "SET @rpl_semi_sync_slave= 1";
+  if (mysql_real_query(mysql, query, strlen(query)))
+  {
+    sql_print_error("Set 'rpl_semi_sync_slave=1' on master failed");
+    mysql_free_result(mysql_store_result(mysql));
+    return 1;
+  }
+  mysql_free_result(mysql_store_result(mysql));
+  rpl_semi_sync_slave_status= 1;
+  return 0;
+}
+
+int repl_semi_slave_read_event(Binlog_relay_IO_param *param,
+			       const char *packet, unsigned long len,
+			       const char **event_buf, unsigned long *event_len)
+{
+  if (rpl_semi_sync_slave_status)
+    return repl_semisync.slaveReadSyncHeader(packet, len,
+					     &semi_sync_need_reply,
+					     event_buf, event_len);
+  *event_buf= packet;
+  *event_len= len;
+  return 0;
+}
+
+int repl_semi_slave_queue_event(Binlog_relay_IO_param *param,
+				const char *event_buf,
+				unsigned long event_len,
+				uint32 flags)
+{
+  if (rpl_semi_sync_slave_status && semi_sync_need_reply)
+  {
+    /*
+      We deliberately ignore the error in slaveReply, such error
+      should not cause the slave IO thread to stop, and the error
+      messages are already reported.
+    */
+    (void) repl_semisync.slaveReply(param->mysql,
+                                    param->master_log_name,
+                                    param->master_log_pos);
+  }
+  return 0;
+}
+
+int repl_semi_slave_io_start(Binlog_relay_IO_param *param)
+{
+  return repl_semisync.slaveStart(param);
+}
+
+int repl_semi_slave_io_end(Binlog_relay_IO_param *param)
+{
+  return repl_semisync.slaveStop(param);
+}
+
+
+static void fix_rpl_semi_sync_slave_enabled(MYSQL_THD thd,
+					    SYS_VAR *var,
+					    void *ptr,
+					    const void *val)
+{
+  *(char *)ptr= *(char *)val;
+  repl_semisync.setSlaveEnabled(rpl_semi_sync_slave_enabled != 0);
+  return;
+}
+
+static void fix_rpl_semi_sync_trace_level(MYSQL_THD thd,
+					  SYS_VAR *var,
+					  void *ptr,
+					  const void *val)
+{
+  *(unsigned long *)ptr= *(unsigned long *)val;
+  repl_semisync.setTraceLevel(rpl_semi_sync_slave_trace_level);
+  return;
+}
+
+/* plugin system variables */
+static MYSQL_SYSVAR_BOOL(enabled, rpl_semi_sync_slave_enabled,
+  PLUGIN_VAR_OPCMDARG,
+ "Enable semi-synchronous replication slave (disabled by default). ",
+  NULL,				   // check
+  &fix_rpl_semi_sync_slave_enabled, // update
+  0);
+
+static MYSQL_SYSVAR_ULONG(trace_level, rpl_semi_sync_slave_trace_level,
+  PLUGIN_VAR_OPCMDARG,
+ "The tracing level for semi-sync replication.",
+  NULL,				  // check
+  &fix_rpl_semi_sync_trace_level, // update
+  32, 0, ~0L, 1);
+
+static SYS_VAR* semi_sync_slave_system_vars[]= {
+  MYSQL_SYSVAR(enabled),
+  MYSQL_SYSVAR(trace_level),
+  NULL,
+};
+
+
+/* plugin status variables */
+static SHOW_VAR semi_sync_slave_status_vars[]= {
+  {"Rpl_semi_sync_slave_status",
+   (char*) &rpl_semi_sync_slave_status,    SHOW_BOOL},
+  {NULL, NULL, SHOW_BOOL},
+};
+
+Binlog_relay_IO_observer relay_io_observer = {
+  sizeof(Binlog_relay_IO_observer), // len
+
+  repl_semi_slave_io_start,	// start
+  repl_semi_slave_io_end,	// stop
+  repl_semi_slave_request_dump,	// request_transmit
+  repl_semi_slave_read_event,	// after_read_event
+  repl_semi_slave_queue_event,	// after_queue_event
+  repl_semi_reset_slave,	// reset
+};
+
+static int semi_sync_slave_plugin_init(void *p)
+{
+  if (repl_semisync.initObject())
+    return 1;
+  if (register_binlog_relay_io_observer(&relay_io_observer, p))
+    return 1;
+  return 0;
+}
+
+static int semi_sync_slave_plugin_deinit(void *p)
+{
+  if (unregister_binlog_relay_io_observer(&relay_io_observer, p))
+    return 1;
+  return 0;
+}
+
+
+struct Mysql_replication semi_sync_slave_plugin= {
+  MYSQL_REPLICATION_INTERFACE_VERSION
+};
+
+/*
+  Plugin library descriptor
+*/
+mysql_declare_plugin(semi_sync_slave)
+{
+  MYSQL_REPLICATION_PLUGIN,
+  &semi_sync_slave_plugin,
+  "rpl_semi_sync_slave",
+  "He Zhenxing",
+  "Semi-synchronous replication slave",
+  PLUGIN_LICENSE_GPL,
+  semi_sync_slave_plugin_init, /* Plugin Init */
+  semi_sync_slave_plugin_deinit, /* Plugin Deinit */
+  0x0100 /* 1.0 */,
+  semi_sync_slave_status_vars,	/* status variables */
+  semi_sync_slave_system_vars,	/* system variables */
+  NULL                        /* config options                  */
+}
+mysql_declare_plugin_end;
diff --git a/sql-common/client.c b/sql-common/client.c
index 3ee6c6003879374ae58e1045540ec4422b0c78d7..30fea433c5018ec9cffb0569b108dc10e17fd001 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1090,6 +1090,8 @@ void mysql_read_default_options(struct st_mysql_options *options,
     char **option=argv;
     while (*++option)
     {
+      if (option[0] == args_separator)          /* skip arguments separator */
+        continue;
       /* DBUG_PRINT("info",("option: %s",option[0])); */
       if (option[0][0] == '-' && option[0][1] == '-')
       {
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index e75ce9080caea0361268adccda70f32f7e6b6acf..3e350144f745750bc295147edfbf8b752530f24b 100755
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -76,7 +76,7 @@ SET (SQL_SOURCE
                rpl_rli.cc rpl_mi.cc sql_servers.cc
                sql_connect.cc scheduler.cc 
                sql_profile.cc event_parse_data.cc
-               sql_signal.cc
+               sql_signal.cc rpl_handler.cc
                ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
                ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h
                ${PROJECT_SOURCE_DIR}/include/mysqld_error.h
diff --git a/sql/Makefile.am b/sql/Makefile.am
index b24d9369f6f4de4230a64fb54bef2ff78da17643..569bb70965e1f085d8af6a557cf62cf7eaf6b65e 100644
--- a/sql/Makefile.am
+++ b/sql/Makefile.am
@@ -111,7 +111,8 @@ noinst_HEADERS =	item.h item_func.h item_sum.h item_cmpfunc.h \
 			sql_plugin.h authors.h event_parse_data.h \
 			event_data_objects.h event_scheduler.h \
 			sql_partition.h partition_info.h partition_element.h \
-			contributors.h sql_servers.h sql_signal.h
+			contributors.h sql_servers.h sql_signal.h \
+			rpl_handler.h replication.h
 
 mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
 			item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -156,7 +157,8 @@ mysqld_SOURCES =	sql_lex.cc sql_handler.cc sql_partition.cc \
                         event_queue.cc event_db_repository.cc events.cc \
 			sql_plugin.cc sql_binlog.cc \
 			sql_builtin.cc sql_tablespace.cc partition_info.cc \
-			sql_servers.cc event_parse_data.cc sql_signal.cc
+			sql_servers.cc event_parse_data.cc sql_signal.cc \
+			rpl_handler.cc
 
 nodist_mysqld_SOURCES =	mini_client_errors.c pack.c client.c my_time.c my_user.c 
 
diff --git a/sql/authors.h b/sql/authors.h
index bb5156742e526a9b5678876d112cdb286b198699..ec46e368f5f0a1420b7b951bcc7b18dace32fe77 100644
--- a/sql/authors.h
+++ b/sql/authors.h
@@ -1,3 +1,6 @@
+#ifndef AUTHORS_INCLUDED
+#define AUTHORS_INCLUDED
+
 /* Copyright (C) 2005-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -151,3 +154,5 @@ struct show_table_authors_st show_table_authors[]= {
     "SHA1(), AES_ENCRYPT(), AES_DECRYPT(), bug fixing" },
   {NULL, NULL, NULL}
 };
+
+#endif /* AUTHORS_INCLUDED */
diff --git a/sql/client_settings.h b/sql/client_settings.h
index 4f06c15a29e54cac28fca1056e7bb152f30cb71f..fd50bfdbb889a2930debe498c2e21ef26fe722f3 100644
--- a/sql/client_settings.h
+++ b/sql/client_settings.h
@@ -14,6 +14,12 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
+#ifndef CLIENT_SETTINGS_INCLUDED
+#define CLIENT_SETTINGS_INCLUDED
+#else
+#error You have already included an client_settings.h and it should not be included twice
+#endif /* CLIENT_SETTINGS_INCLUDED */
+
 #include <thr_alarm.h>
 
 #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG |	  \
diff --git a/sql/contributors.h b/sql/contributors.h
index 87001e29d88cf1f5cb069b4d357119a7151cacc5..6cf8bb88e3b5ec02a9d96cf5623364ce6a902f5d 100644
--- a/sql/contributors.h
+++ b/sql/contributors.h
@@ -1,3 +1,6 @@
+#ifndef CONTRIBUTORS_INCLUDED
+#define CONTRIBUTORS_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -37,3 +40,5 @@ struct show_table_contributors_st show_table_contributors[]= {
   {"Mark Shuttleworth", "London, UK.", "EFF contribution for UC2006 Auction"},
   {NULL, NULL, NULL}
 };
+
+#endif /* CONTRIBUTORS_INCLUDED */
diff --git a/sql/field.h b/sql/field.h
index d8863ef43e62ee139800501aa3bc474a57a9e3e3..8bf641a8649964a650b9abe3d8bb103112aae154 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -1,3 +1,6 @@
+#ifndef FIELD_INCLUDED
+#define FIELD_INCLUDED
+
 /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -2189,3 +2192,5 @@ int set_field_to_null_with_conversions(Field *field, bool no_conversions);
 #define f_no_default(x)		(x & FIELDFLAG_NO_DEFAULT)
 #define f_bit_as_char(x)        ((x) & FIELDFLAG_TREAT_BIT_AS_CHAR)
 #define f_is_hex_escape(x)      ((x) & FIELDFLAG_HEX_ESCAPE)
+
+#endif /* FIELD_INCLUDED */
diff --git a/sql/gstream.h b/sql/gstream.h
index 1ef90ad5bf0b0c6146e4698c8c617822d91c91cb..ea7158ee1a3b76228bc9c656a6bad46f8f95fad3 100644
--- a/sql/gstream.h
+++ b/sql/gstream.h
@@ -1,3 +1,6 @@
+#ifndef GSTREAM_INCLUDED
+#define GSTREAM_INCLUDED
+
 /* Copyright (C) 2000-2004 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -73,3 +76,5 @@ class Gis_read_stream
   char *m_err_msg;
   CHARSET_INFO *m_charset;
 };
+
+#endif /* GSTREAM_INCLUDED */
diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h
index 9106fd6073111dc5c35d0a6bf34b1ca3b3b5cc19..ac3e7329136474680ebaf935c4b0b58d5a1d0fdb 100644
--- a/sql/ha_ndbcluster.h
+++ b/sql/ha_ndbcluster.h
@@ -1,3 +1,6 @@
+#ifndef HA_NDBCLUSTER_INCLUDED
+#define HA_NDBCLUSTER_INCLUDED
+
 /* Copyright (C) 2000-2003 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -582,3 +585,5 @@ static const int ndbcluster_hton_name_length=sizeof(ndbcluster_hton_name)-1;
 extern int ndbcluster_terminating;
 extern int ndb_util_thread_running;
 extern pthread_cond_t COND_ndb_util_ready;
+
+#endif /* HA_NDBCLUSTER_INCLUDED */
diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h
index 1cad643e5ec384a2528b76720c32999cfc457c8c..d80dfe9ee7405b362219d9af71cc35d8a80226bc 100644
--- a/sql/ha_ndbcluster_binlog.h
+++ b/sql/ha_ndbcluster_binlog.h
@@ -1,3 +1,6 @@
+#ifndef HA_NDBCLUSTER_BINLOG_INCLUDED
+#define HA_NDBCLUSTER_BINLOG_INCLUDED
+
 /* Copyright (C) 2000-2003 MySQL AB
 
   This program is free software; you can redistribute it and/or modify
@@ -225,3 +228,5 @@ set_thd_ndb(THD *thd, Thd_ndb *thd_ndb)
 { thd_set_ha_data(thd, ndbcluster_hton, thd_ndb); }
 
 Ndb* check_ndb_in_thd(THD* thd);
+
+#endif /* HA_NDBCLUSTER_BINLOG_INCLUDED */
diff --git a/sql/ha_ndbcluster_cond.h b/sql/ha_ndbcluster_cond.h
index 4401a93c9e1df9ad38a0065b98df2ae01321777b..4ccc7e062ecb06a6c59f459aa1c5f3b8ff1896e2 100644
--- a/sql/ha_ndbcluster_cond.h
+++ b/sql/ha_ndbcluster_cond.h
@@ -1,3 +1,6 @@
+#ifndef HA_NDBCLUSTER_COND_INCLUDED
+#define HA_NDBCLUSTER_COND_INCLUDED
+
 /* Copyright (C) 2000-2007 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -486,3 +489,5 @@ class ha_ndbcluster_cond
 
   Ndb_cond_stack *m_cond_stack;
 };
+
+#endif /* HA_NDBCLUSTER_COND_INCLUDED */
diff --git a/sql/ha_ndbcluster_tables.h b/sql/ha_ndbcluster_tables.h
index c6bc8f577f8344296e5f321e867df0129d07da26..ba2e8ec251b59e5bc90fcba14bbb32b2da295c5b 100644
--- a/sql/ha_ndbcluster_tables.h
+++ b/sql/ha_ndbcluster_tables.h
@@ -1,3 +1,6 @@
+#ifndef HA_NDBCLUSTER_TABLES_INCLUDED
+#define HA_NDBCLUSTER_TABLES_INCLUDED
+
 /* Copyright (C) 2000-2003 MySQL AB
 
   This program is free software; you can redistribute it and/or modify
@@ -21,3 +24,5 @@
 #define OLD_NDB_APPLY_TABLE "apply_status"
 #define NDB_SCHEMA_TABLE "ndb_schema"
 #define OLD_NDB_SCHEMA_TABLE "schema"
+
+#endif /* HA_NDBCLUSTER_TABLES_INCLUDED */
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index fdf1a17d42b4551c9ba63a5606e55c95a3ae63bd..c62318daf84ac5f2e212661353cf76f06e78f79e 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -1,3 +1,6 @@
+#ifndef HA_PARTITION_INCLUDED
+#define HA_PARTITION_INCLUDED
+
 /* Copyright 2005-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
   This program is free software; you can redistribute it and/or modify
@@ -1102,3 +1105,5 @@ class ha_partition :public handler
     virtual void append_create_info(String *packet)
   */
 };
+
+#endif /* HA_PARTITION_INCLUDED */
diff --git a/sql/handler.cc b/sql/handler.cc
index 865fc083e3a1be6a08191efa39bac696d8ada8b5..bc8c627a6ae3b1a69b624ae5a446f815e1a7f772 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -24,6 +24,7 @@
 #endif
 
 #include "mysql_priv.h"
+#include "rpl_handler.h"
 #include "rpl_filter.h"
 #include <myisampack.h>
 #include <errno.h>
@@ -222,6 +223,8 @@ handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
     return NULL;
   }
 
+  RUN_HOOK(transaction, after_rollback, (thd, FALSE));
+
   switch (database_type) {
 #ifndef NO_HASH
   case DB_TYPE_HASH:
@@ -423,7 +426,13 @@ int ha_finalize_handlerton(st_plugin_int *plugin)
     reuse an array slot. Otherwise the number of uninstall/install
     cycles would be limited.
   */
-  hton2plugin[hton->slot]= NULL;
+  if (hton->slot != HA_SLOT_UNDEF)
+  {
+    /* Make sure we are not unpluging another plugin */
+    DBUG_ASSERT(hton2plugin[hton->slot] == plugin);
+    DBUG_ASSERT(hton->slot < MAX_HA);
+    hton2plugin[hton->slot]= NULL;
+  }
 
   my_free((uchar*)hton, MYF(0));
 
@@ -440,6 +449,15 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
 
   hton= (handlerton *)my_malloc(sizeof(handlerton),
                                 MYF(MY_WME | MY_ZEROFILL));
+
+  if (hton == NULL)
+  {
+    sql_print_error("Unable to allocate memory for plugin '%s' handlerton.",
+                    plugin->name.str);
+    goto err_no_hton_memory;
+  }
+
+  hton->slot= HA_SLOT_UNDEF;
   /* Historical Requirement */
   plugin->data= hton; // shortcut for the future
   if (plugin->plugin->init && plugin->plugin->init(hton))
@@ -550,6 +568,7 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
           
 err:
   my_free((uchar*) hton, MYF(0));
+err_no_hton_memory:
   plugin->data= NULL;
   DBUG_RETURN(1);
 }
@@ -1200,6 +1219,7 @@ int ha_commit_trans(THD *thd, bool all)
     if (cookie)
       tc_log->unlog(cookie, xid);
     DBUG_EXECUTE_IF("crash_commit_after", abort(););
+    RUN_HOOK(transaction, after_commit, (thd, FALSE));
 end:
     if (rw_trans)
       start_waiting_global_read_lock(thd);
@@ -1347,6 +1367,7 @@ int ha_rollback_trans(THD *thd, bool all)
     push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                  ER_WARNING_NOT_COMPLETE_ROLLBACK,
                  ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
+  RUN_HOOK(transaction, after_rollback, (thd, FALSE));
   DBUG_RETURN(error);
 }
 
@@ -1381,7 +1402,14 @@ int ha_autocommit_or_rollback(THD *thd, int error)
 
     thd->variables.tx_isolation=thd->session_tx_isolation;
   }
+  else
 #endif
+  {
+    if (!error)
+      RUN_HOOK(transaction, after_commit, (thd, FALSE));
+    else
+      RUN_HOOK(transaction, after_rollback, (thd, FALSE));
+  }
   DBUG_RETURN(error);
 }
 
diff --git a/sql/handler.h b/sql/handler.h
index fe8f7c437ff364c9dc850f7bfb0fa164908bb01c..632c262b59a0d3bf4e23b2a92b70c9c078aff714 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -1,3 +1,6 @@
+#ifndef HANDLER_INCLUDED
+#define HANDLER_INCLUDED
+
 /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -213,6 +216,13 @@
 */
 #define MAX_HA 15
 
+/*
+  Use this instead of 0 as the initial value for the slot number of
+  handlerton, so that we can distinguish uninitialized slot number
+  from slot 0.
+*/
+#define HA_SLOT_UNDEF ((uint)-1)
+
 /*
   Parameters for open() (in register form->filestat)
   HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
@@ -2073,3 +2083,4 @@ int ha_binlog_end(THD *thd);
 #define ha_binlog_wait(a) do {} while (0)
 #define ha_binlog_end(a)  do {} while (0)
 #endif
+#endif /* HANDLER_INCLUDED */
diff --git a/sql/item.h b/sql/item.h
index a2cff3ab3a9d67f84166b88bec1bde14c167b5de..b44e84f4b15329bd9eb6a92fd47ad02c39a19048 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_INCLUDED
+#define ITEM_INCLUDED
+
 /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -3126,3 +3129,5 @@ extern Cached_item *new_Cached_item(THD *thd, Item *item);
 extern Item_result item_cmp_type(Item_result a,Item_result b);
 extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
 extern int stored_field_cmp_to_item(Field *field, Item *item);
+
+#endif /* ITEM_INCLUDED */
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index c2227fa04e04562568a4dea1689face7c4e10a72..3462bed94a2b3a749f3f54bd298b88abe3bc870b 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_CMPFUNC_INCLUDED
+#define ITEM_CMPFUNC_INCLUDED
+
 /* Copyright (C) 2000-2003 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -1721,3 +1724,5 @@ inline Item *and_conds(Item *a, Item *b)
 }
 
 Item *and_expressions(Item *a, Item *b, Item **org_item);
+
+#endif /* ITEM_CMPFUNC_INCLUDED */
diff --git a/sql/item_func.h b/sql/item_func.h
index fdbbff89e60e05d082739b0d63cccff08b03da72..628878bcaed9f56f01334c05e5c9494040a9736c 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_FUNC_INCLUDED
+#define ITEM_FUNC_INCLUDED
+
 /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -1718,3 +1721,4 @@ class Item_func_uuid_short :public Item_int_func
   bool check_partition_func_processor(uchar *int_arg) {return FALSE;}
 };
 
+#endif /* ITEM_FUNC_INCLUDED */
diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h
index edbe104e30781fafdcbd4a1293a6adfa53f72774..9a55ea7d5b13828b9988519f5f9a65de42329cc7 100644
--- a/sql/item_geofunc.h
+++ b/sql/item_geofunc.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_GEOFUNC_INCLUDED
+#define ITEM_GEOFUNC_INCLUDED
+
 /* Copyright (C) 2000-2003 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -386,3 +389,4 @@ class Item_func_srid: public Item_int_func
 
 #endif
 
+#endif /* ITEM_GEOFUNC_INCLUDED */
diff --git a/sql/item_row.h b/sql/item_row.h
index 67441f49603b0f58a887d7e245fe1a94125b9bac..7c08c5888e05faa64cfd0a9a4667430a25f89d4e 100644
--- a/sql/item_row.h
+++ b/sql/item_row.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_ROW_INCLUDED
+#define ITEM_ROW_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -77,3 +80,5 @@ class Item_row: public Item
   bool null_inside() { return with_null; };
   void bring_value();
 };
+
+#endif /* ITEM_ROW_INCLUDED */
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 87d8c7bd438c4e1f0c44b5d8384d0d5c81be67d8..2233679e40c5d863db1f3fdacf783a235a475143 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_STRFUNC_INCLUDED
+#define ITEM_STRFUNC_INCLUDED
+
 /* Copyright (C) 2000-2003 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -847,3 +850,4 @@ class Item_func_uuid: public Item_str_func
   String *val_str(String *);
 };
 
+#endif /* ITEM_STRFUNC_INCLUDED */
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index d4aa621c083b9b87ead0b87c0a88bef49a270511..ea59521aab10ae5ba379444b64912b261405e84f 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_SUBSELECT_INCLUDED
+#define ITEM_SUBSELECT_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -579,4 +582,4 @@ inline bool Item_subselect::is_uncacheable() const
   return engine->uncacheable();
 }
 
-
+#endif /* ITEM_SUBSELECT_INCLUDED */
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 1dd1c5b5dd5c01325b69d777d51f5874bc4647b6..62addf4e0338ff0413f21ca51306d7c87814caab 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_SUM_INCLUDED
+#define ITEM_SUM_INCLUDED
+
 /* Copyright (C) 2000-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -1413,3 +1416,5 @@ class Item_func_group_concat : public Item_sum
   virtual bool change_context_processor(uchar *cntx)
     { context= (Name_resolution_context *)cntx; return FALSE; }
 };
+
+#endif /* ITEM_SUM_INCLUDED */
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 9e3c2e8c89f029ebfff4e8d59fd55f2b5bd9eb22..7f1b2ed3a533aadb1cd91c69a293ed3f0ee0f0f0 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_TIMEFUNC_INCLUDED
+#define ITEM_TIMEFUNC_INCLUDED
+
 /* Copyright (C) 2000-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -1026,3 +1029,5 @@ class Item_func_last_day :public Item_date
   const char *func_name() const { return "last_day"; }
   bool get_date(MYSQL_TIME *res, uint fuzzy_date);
 };
+
+#endif /* ITEM_TIMEFUNC_INCLUDED */
diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h
index dadbb5ccf42c3e1841c79718a57ae0354abab95d..6373bde0aab8857c66e6fc696832d00d90f37129 100644
--- a/sql/item_xmlfunc.h
+++ b/sql/item_xmlfunc.h
@@ -1,3 +1,6 @@
+#ifndef ITEM_XMLFUNC_INCLUDED
+#define ITEM_XMLFUNC_INCLUDED
+
 /* Copyright (C) 2000-2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -61,3 +64,4 @@ class Item_func_xml_update: public Item_xml_str_func
   String *val_str(String *);
 };
 
+#endif /* ITEM_XMLFUNC_INCLUDED */
diff --git a/sql/lex.h b/sql/lex.h
index b4945bbfd1ad8ee23b611a8dcc6135eb47edce84..cd0c042159f7dd50fb0357689db4b49bf3a871de 100644
--- a/sql/lex.h
+++ b/sql/lex.h
@@ -1,3 +1,6 @@
+#ifndef LEX_INCLUDED
+#define LEX_INCLUDED
+
 /* Copyright (C) 2000-2002 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -248,6 +251,7 @@ static SYMBOL symbols[] = {
   { "IDENTIFIED",	SYM(IDENTIFIED_SYM)},
   { "IF",		SYM(IF)},
   { "IGNORE",		SYM(IGNORE_SYM)},
+  { "IGNORE_SERVER_IDS", SYM(IGNORE_SERVER_IDS_SYM)},
   { "IMPORT",		SYM(IMPORT)},
   { "IN",		SYM(IN_SYM)},
   { "INDEX",		SYM(INDEX_SYM)},
@@ -327,6 +331,7 @@ static SYMBOL symbols[] = {
   { "MASTER_SSL_KEY",   SYM(MASTER_SSL_KEY_SYM)},
   { "MASTER_SSL_VERIFY_SERVER_CERT", SYM(MASTER_SSL_VERIFY_SERVER_CERT_SYM)},
   { "MASTER_USER",           SYM(MASTER_USER_SYM)},
+  { "MASTER_HEARTBEAT_PERIOD", SYM(MASTER_HEARTBEAT_PERIOD_SYM)},
   { "MATCH",		SYM(MATCH)},
   { "MAX_CONNECTIONS_PER_HOUR", SYM(MAX_CONNECTIONS_PER_HOUR)},
   { "MAX_QUERIES_PER_HOUR", SYM(MAX_QUERIES_PER_HOUR)},
@@ -435,6 +440,7 @@ static SYMBOL symbols[] = {
   { "REDUNDANT",	SYM(REDUNDANT_SYM)},
   { "REFERENCES",	SYM(REFERENCES)},
   { "REGEXP",		SYM(REGEXP)},
+  { "RELAYLOG",         SYM(RELAYLOG_SYM)},
   { "RELAY_LOG_FILE",   SYM(RELAY_LOG_FILE_SYM)},
   { "RELAY_LOG_POS",    SYM(RELAY_LOG_POS_SYM)},
   { "RELAY_THREAD",     SYM(RELAY_THREAD)},
@@ -649,3 +655,5 @@ static SYMBOL sql_functions[] = {
   { "VAR_POP",		SYM(VARIANCE_SYM)},
   { "VAR_SAMP",		SYM(VAR_SAMP_SYM)},
 };
+
+#endif /* LEX_INCLUDED */
diff --git a/sql/log.cc b/sql/log.cc
index aff5330d93fc0482ad340ba5dc6354f761dcd683..4f5230b82cc908cccf45b1f7f9c15eda60e27036 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -38,6 +38,7 @@
 #endif
 
 #include <mysql/plugin.h>
+#include "rpl_handler.h"
 
 /* max size of the log message */
 #define MAX_LOG_BUFFER_SIZE 1024
@@ -49,8 +50,7 @@
 
 LOGGER logger;
 
-MYSQL_BIN_LOG mysql_bin_log;
-ulong sync_binlog_counter= 0;
+MYSQL_BIN_LOG mysql_bin_log(&sync_binlog_period);
 
 static bool test_if_number(const char *str,
 			   long *res, bool allow_wildcards);
@@ -969,6 +969,7 @@ bool LOGGER::slow_log_print(THD *thd, const char *query, uint query_length,
   uint user_host_len= 0;
   ulonglong query_utime, lock_utime;
 
+  DBUG_ASSERT(thd->enable_slow_log);
   /*
     Print the message to the buffer if we have slow log enabled
   */
@@ -2421,10 +2422,11 @@ const char *MYSQL_LOG::generate_name(const char *log_name,
 
 
 
-MYSQL_BIN_LOG::MYSQL_BIN_LOG()
+MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_period)
   :bytes_written(0), prepared_xids(0), file_id(1), open_count(1),
    need_start_event(TRUE), m_table_map_version(0),
-   is_relay_log(0),
+   sync_period_ptr(sync_period),
+   is_relay_log(0), signal_cnt(0),
    description_event_for_exec(0), description_event_for_queue(0)
 {
   /*
@@ -3654,6 +3656,8 @@ bool MYSQL_BIN_LOG::append(Log_event* ev)
   }
   bytes_written+= ev->data_written;
   DBUG_PRINT("info",("max_size: %lu",max_size));
+  if (flush_and_sync(0))
+    goto err;
   if ((uint) my_b_append_tell(&log_file) > max_size)
     new_file_without_locking();
 
@@ -3684,6 +3688,8 @@ bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...)
     bytes_written += len;
   } while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
   DBUG_PRINT("info",("max_size: %lu",max_size));
+  if (flush_and_sync(0))
+    goto err;
   if ((uint) my_b_append_tell(&log_file) > max_size)
     new_file_without_locking();
 
@@ -3693,17 +3699,21 @@ bool MYSQL_BIN_LOG::appendv(const char* buf, uint len,...)
   DBUG_RETURN(error);
 }
 
-
-bool MYSQL_BIN_LOG::flush_and_sync()
+bool MYSQL_BIN_LOG::flush_and_sync(bool *synced)
 {
   int err=0, fd=log_file.file;
+  if (synced)
+    *synced= 0;
   safe_mutex_assert_owner(&LOCK_log);
   if (flush_io_cache(&log_file))
     return 1;
-  if (++sync_binlog_counter >= sync_binlog_period && sync_binlog_period)
+  uint sync_period= get_sync_period();
+  if (sync_period && ++sync_counter >= sync_period)
   {
-    sync_binlog_counter= 0;
+    sync_counter= 0;
     err=my_sync(fd, MYF(MY_WME));
+    if (synced)
+      *synced= 1;
   }
   return err;
 }
@@ -3994,7 +4004,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd,
 
     if (file == &log_file)
     {
-      error= flush_and_sync();
+      error= flush_and_sync(0);
       if (!error)
       {
         signal_update();
@@ -4180,8 +4190,16 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
 
     if (file == &log_file) // we are writing to the real log (disk)
     {
-      if (flush_and_sync())
+      bool synced= 0;
+      if (flush_and_sync(&synced))
 	goto err;
+
+      if (RUN_HOOK(binlog_storage, after_flush,
+                   (thd, log_file_name, file->pos_in_file, synced))) {
+        sql_print_error("Failed to run 'after_flush' hooks");
+        goto err;
+      }
+
       signal_update();
       rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
     }
@@ -4436,7 +4454,7 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
   DBUG_ASSERT(carry == 0);
 
   if (sync_log)
-    flush_and_sync();
+    return flush_and_sync(0);
 
   return 0;                                     // All OK
 }
@@ -4483,7 +4501,7 @@ bool MYSQL_BIN_LOG::write_incident(THD *thd, bool lock)
   ev.write(&log_file);
   if (lock)
   {
-    if (!error && !(error= flush_and_sync()))
+    if (!error && !(error= flush_and_sync(0)))
     {
       signal_update();
       rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED);
@@ -4571,7 +4589,8 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event,
       if (incident && write_incident(thd, FALSE))
         goto err;
 
-      if (flush_and_sync())
+      bool synced= 0;
+      if (flush_and_sync(&synced))
         goto err;
       DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
       if (cache->error)				// Error on read
@@ -4580,6 +4599,15 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event,
         write_error=1;				// Don't give more errors
         goto err;
       }
+
+      if (RUN_HOOK(binlog_storage, after_flush,
+                   (thd, log_file_name, log_file.pos_in_file, synced)))
+      {
+        sql_print_error("Failed to run 'after_flush' hooks");
+        write_error=1;
+        goto err;
+      }
+
       signal_update();
     }
 
@@ -4616,12 +4644,9 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event,
 
 
 /**
-  Wait until we get a signal that the binary log has been updated.
+  Wait until we get a signal that the relay log has been updated.
 
   @param thd		Thread variable
-  @param is_slave      If 0, the caller is the Binlog_dump thread from master;
-                       if 1, the caller is the SQL thread from the slave. This
-                       influences only thd->proc_info.
 
   @note
     One must have a lock on LOCK_log before calling this function.
@@ -4629,22 +4654,53 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event,
     THD::enter_cond() (see NOTES in sql_class.h).
 */
 
-void MYSQL_BIN_LOG::wait_for_update(THD* thd, bool is_slave)
+void MYSQL_BIN_LOG::wait_for_update_relay_log(THD* thd)
 {
   const char *old_msg;
-  DBUG_ENTER("wait_for_update");
+  DBUG_ENTER("wait_for_update_relay_log");
 
   old_msg= thd->enter_cond(&update_cond, &LOCK_log,
-                           is_slave ?
-                           "Has read all relay log; waiting for the slave I/O "
-                           "thread to update it" :
-                           "Has sent all binlog to slave; waiting for binlog "
-                           "to be updated");
+                           "Slave has read all relay log; " 
+                           "waiting for the slave I/O "
+                           "thread to update it" );
   pthread_cond_wait(&update_cond, &LOCK_log);
   thd->exit_cond(old_msg);
   DBUG_VOID_RETURN;
 }
 
+/**
+  Wait until we get a signal that the binary log has been updated.
+  Applies to master only.
+     
+  NOTES
+  @param[in] thd        a THD struct
+  @param[in] timeout    a pointer to a timespec;
+                        NULL means to wait w/o timeout.
+  @retval    0          if got signalled on update
+  @retval    non-0      if wait timeout elapsed
+  @note
+    LOCK_log must be taken before calling this function.
+    LOCK_log is being released while the thread is waiting.
+    LOCK_log is released by the caller.
+*/
+
+int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd,
+                                           const struct timespec *timeout)
+{
+  int ret= 0;
+  const char* old_msg = thd->proc_info;
+  DBUG_ENTER("wait_for_update_bin_log");
+  old_msg= thd->enter_cond(&update_cond, &LOCK_log,
+                           "Master has sent all binlog to slave; "
+                           "waiting for binlog to be updated");
+  if (!timeout)
+    pthread_cond_wait(&update_cond, &LOCK_log);
+  else
+    ret= pthread_cond_timedwait(&update_cond, &LOCK_log,
+                                const_cast<struct timespec *>(timeout));
+  DBUG_RETURN(ret);
+}
+
 
 /**
   Close the log file.
@@ -4857,6 +4913,7 @@ bool flush_error_log()
 void MYSQL_BIN_LOG::signal_update()
 {
   DBUG_ENTER("MYSQL_BIN_LOG::signal_update");
+  signal_cnt++;
   pthread_cond_broadcast(&update_cond);
   DBUG_VOID_RETURN;
 }
diff --git a/sql/log.h b/sql/log.h
index d306d6f7182b0c08c21117ab28a3f743b2dee658..a31be6dcce6f1def2510d46b8a11a5cce0755326 100644
--- a/sql/log.h
+++ b/sql/log.h
@@ -269,6 +269,18 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
 
   ulonglong m_table_map_version;
 
+  /* pointer to the sync period variable, for binlog this will be
+     sync_binlog_period, for relay log this will be
+     sync_relay_log_period
+  */
+  uint *sync_period_ptr;
+  uint sync_counter;
+
+  inline uint get_sync_period()
+  {
+    return *sync_period_ptr;
+  }
+
   int write_to_file(IO_CACHE *cache);
   /*
     This is used to start writing to a new log file. The difference from
@@ -284,7 +296,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
 
   /* This is relay log */
   bool is_relay_log;
-
+  ulong signal_cnt;  // update of the counter is checked by heartbeat
   /*
     These describe the log's format. This is used only for relay logs.
     _for_exec is used by the SQL thread, _for_queue by the I/O thread. It's
@@ -296,7 +308,7 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
   Format_description_log_event *description_event_for_exec,
     *description_event_for_queue;
 
-  MYSQL_BIN_LOG();
+  MYSQL_BIN_LOG(uint *sync_period);
   /*
     note that there's no destructor ~MYSQL_BIN_LOG() !
     The reason is that we don't want it to be automatically called
@@ -339,7 +351,8 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
   }
   void set_max_size(ulong max_size_arg);
   void signal_update();
-  void wait_for_update(THD* thd, bool master_or_slave);
+  void wait_for_update_relay_log(THD* thd);
+  int  wait_for_update_bin_log(THD* thd, const struct timespec * timeout);
   void set_need_start_event() { need_start_event = 1; }
   void init(bool no_auto_events_arg, ulong max_size);
   void init_pthread_objects();
@@ -378,7 +391,20 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG
   bool is_active(const char* log_file_name);
   int update_log_index(LOG_INFO* linfo, bool need_update_threads);
   void rotate_and_purge(uint flags);
-  bool flush_and_sync();
+  /**
+     Flush binlog cache and synchronize to disk.
+
+     This function flushes events in binlog cache to binary log file,
+     it will do synchronizing according to the setting of system
+     variable 'sync_binlog'. If file is synchronized, @c synced will
+     be set to 1, otherwise 0.
+
+     @param[out] synced if not NULL, set to 1 if file is synchronized, otherwise 0
+
+     @retval 0 Success
+     @retval other Failure
+  */
+  bool flush_and_sync(bool *synced);
   int purge_logs(const char *to_log, bool included,
                  bool need_mutex, bool need_update_threads,
                  ulonglong *decrease_log_space);
diff --git a/sql/log_event.cc b/sql/log_event.cc
index f445cff4758dbb5943902b98695cc0660f289b5f..10a1ee431b4ec2557108bade3536deba05abc683 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -2394,13 +2394,29 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
     charset_database_number= thd_arg->variables.collation_database->number;
   
   /*
-    If we don't use flags2 for anything else than options contained in
-    thd_arg->options, it would be more efficient to flags2=thd_arg->options
-    (OPTIONS_WRITTEN_TO_BIN_LOG would be used only at reading time).
-    But it's likely that we don't want to use 32 bits for 3 bits; in the future
-    we will probably want to reclaim the 29 bits. So we need the &.
+    We only replicate over the bits of flags2 that we need: the rest
+    are masked out by "& OPTIONS_WRITTEN_TO_BINLOG".
+
+    We also force AUTOCOMMIT=1.  Rationale (cf. BUG#29288): After
+    fixing BUG#26395, we always write BEGIN and COMMIT around all
+    transactions (even single statements in autocommit mode).  This is
+    so that replication from non-transactional to transactional table
+    and error recovery from XA to non-XA table should work as
+    expected.  The BEGIN/COMMIT are added in log.cc. However, there is
+    one exception: MyISAM bypasses log.cc and writes directly to the
+    binlog.  So if autocommit is off, master has MyISAM, and slave has
+    a transactional engine, then the slave will just see one long
+    never-ending transaction.  The only way to bypass explicit
+    BEGIN/COMMIT in the binlog is by using a non-transactional table.
+    So setting AUTOCOMMIT=1 will make this work as expected.
+
+    Note: explicitly replicate AUTOCOMMIT=1 from master. We do not
+    assume AUTOCOMMIT=1 on slave; the slave still reads the state of
+    the autocommit flag as written by the master to the binlog. This
+    behavior may change after WL#4162 has been implemented.
   */
-  flags2= (uint32) (thd_arg->options & OPTIONS_WRITTEN_TO_BIN_LOG);
+  flags2= (uint32) (thd_arg->options &
+                    (OPTIONS_WRITTEN_TO_BIN_LOG & ~OPTION_NOT_AUTOCOMMIT));
   DBUG_ASSERT(thd_arg->variables.character_set_client->number < 256*256);
   DBUG_ASSERT(thd_arg->variables.collation_connection->number < 256*256);
   DBUG_ASSERT(thd_arg->variables.collation_server->number < 256*256);
@@ -3261,6 +3277,21 @@ Default database: '%s'. Query: '%s'",
     */
   } /* End of if (db_ok(... */
 
+  {/**
+      The following failure injecion works in cooperation with tests 
+      setting @@global.debug= 'd,stop_slave_middle_group'.
+      The sql thread receives the killed status and will proceed 
+      to shutdown trying to finish incomplete events group.
+   */
+    DBUG_EXECUTE_IF("stop_slave_middle_group",
+                    if (strcmp("COMMIT", query) != 0 &&
+                        strcmp("BEGIN", query) != 0)
+                    {
+                      if (thd->transaction.all.modified_non_trans_table)
+                        const_cast<Relay_log_info*>(rli)->abort_slave= 1;
+                    };);
+  }
+
 end:
   /*
     Probably we have set thd->query, thd->db, thd->catalog to point to places
@@ -3632,6 +3663,7 @@ Format_description_log_event(uint8 binlog_ver, const char* server_ver)
                       post_header_len[UPDATE_ROWS_EVENT-1]=
                       post_header_len[DELETE_ROWS_EVENT-1]= 6;);
       post_header_len[INCIDENT_EVENT-1]= INCIDENT_HEADER_LEN;
+      post_header_len[HEARTBEAT_LOG_EVENT-1]= 0;
 
       // Sanity-check that all post header lengths are initialized.
       IF_DBUG({
@@ -7469,8 +7501,16 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
           thd->transaction.stmt.modified_non_trans_table= TRUE;
     } // row processing loop
 
-    DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
-                    const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
+    {/**
+         The following failure injecion works in cooperation with tests 
+         setting @@global.debug= 'd,stop_slave_middle_group'.
+         The sql thread receives the killed status and will proceed 
+         to shutdown trying to finish incomplete events group.
+     */
+      DBUG_EXECUTE_IF("stop_slave_middle_group",
+                      if (thd->transaction.all.modified_non_trans_table)
+                        const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
+    }
 
     if ((error= do_after_row_operations(rli, error)) &&
         ignored_error_code(convert_handler_error(error, thd, table)))
@@ -7508,32 +7548,6 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli)
     thd->is_slave_error= 1;
     DBUG_RETURN(error);
   }
-  /*
-    This code would ideally be placed in do_update_pos() instead, but
-    since we have no access to table there, we do the setting of
-    last_event_start_time here instead.
-  */
-  else if (table && (table->s->primary_key == MAX_KEY) &&
-           !cache_stmt && get_flags(STMT_END_F) == RLE_NO_FLAGS)
-  {
-    /*
-      ------------ Temporary fix until WL#2975 is implemented ---------
-
-      This event is not the last one (no STMT_END_F). If we stop now
-      (in case of terminate_slave_thread()), how will we restart? We
-      have to restart from Table_map_log_event, but as this table is
-      not transactional, the rows already inserted will still be
-      present, and idempotency is not guaranteed (no PK) so we risk
-      that repeating leads to double insert. So we desperately try to
-      continue, hope we'll eventually leave this buggy situation (by
-      executing the final Rows_log_event). If we are in a hopeless
-      wait (reached end of last relay log and nothing gets appended
-      there), we timeout after one minute, and notify DBA about the
-      problem.  When WL#2975 is implemented, just remove the member
-      Relay_log_info::last_event_start_time and all its occurrences.
-    */
-    const_cast<Relay_log_info*>(rli)->last_event_start_time= my_time(0);
-  }
 
   if (get_flags(STMT_END_F))
     if (error= rows_event_stmt_cleanup(rli, thd))
@@ -8445,13 +8459,17 @@ Rows_log_event::write_row(const Relay_log_info *const rli,
   auto_afree_ptr<char> key(NULL);
 
   /* fill table->record[0] with default values */
-
+  bool abort_on_warnings= (rli->sql_thd->variables.sql_mode &
+                           (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES));
   if ((error= prepare_record(table, m_width,
-                             TRUE /* check if columns have def. values */)))
+                             table->file->ht->db_type != DB_TYPE_NDBCLUSTER,
+                             abort_on_warnings, m_curr_row == m_rows_buf)))
     DBUG_RETURN(error);
   
   /* unpack row into table->record[0] */
-  error= unpack_current_row(rli); // TODO: how to handle errors?
+  if ((error= unpack_current_row(rli, abort_on_warnings)))
+    DBUG_RETURN(error);
+
   if (m_curr_row == m_rows_buf)
   {
     /* this is the first row to be inserted, we estimate the rows with
@@ -9248,8 +9266,12 @@ Update_rows_log_event::do_exec_row(const Relay_log_info *const rli)
 
   store_record(m_table,record[1]);
 
+  bool abort_on_warnings= (rli->sql_thd->variables.sql_mode &
+                           (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES));
   m_curr_row= m_curr_row_end;
-  error= unpack_current_row(rli); // this also updates m_curr_row_end
+  /* this also updates m_curr_row_end */
+  if ((error= unpack_current_row(rli, abort_on_warnings)))
+    return error;
 
   /*
     Now we have the right row to update.  The old row (the one we're
@@ -9428,3 +9450,16 @@ st_print_event_info::st_print_event_info()
   open_cached_file(&body_cache, NULL, NULL, 0, flags);
 }
 #endif
+
+
+#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
+Heartbeat_log_event::Heartbeat_log_event(const char* buf, uint event_len,
+                    const Format_description_log_event* description_event)
+  :Log_event(buf, description_event)
+{
+  uint8 header_size= description_event->common_header_len;
+  ident_len = event_len - header_size;
+  set_if_smaller(ident_len,FN_REFLEN-1);
+  log_ident= buf + header_size;
+}
+#endif
diff --git a/sql/log_event.h b/sql/log_event.h
index 31d4a7480c2fb8129531c1c0830bc69806bcd578..cd5e659c910aa7ce27ab1d591dd4f010d7630019 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -250,6 +250,7 @@ struct sql_ex_info
 #define EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN (4 + 4 + 4 + 1)
 #define EXECUTE_LOAD_QUERY_HEADER_LEN  (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN)
 #define INCIDENT_HEADER_LEN    2
+#define HEARTBEAT_HEADER_LEN   0
 /* 
   Max number of possible extra bytes in a replication event compared to a
   packet (i.e. a query) sent from client to master;
@@ -574,6 +575,12 @@ enum Log_event_type
    */
   INCIDENT_EVENT= 26,
 
+  /*
+    Heartbeat event to be send by master at its idle time 
+    to ensure master's online status to slave 
+  */
+  HEARTBEAT_LOG_EVENT= 27,
+  
   /*
     Add new events here - right above this comment!
     Existing events (except ENUM_END_EVENT) should never change their numbers
@@ -689,6 +696,20 @@ typedef struct st_print_event_info
 } PRINT_EVENT_INFO;
 #endif
 
+/**
+  the struct aggregates two paramenters that identify an event
+  uniquely in scope of communication of a particular master and slave couple.
+  I.e there can not be 2 events from the same staying connected master which
+  have the same coordinates.
+  @note
+  Such identifier is not yet unique generally as the event originating master
+  is resetable. Also the crashed master can be replaced with some other.
+*/
+struct event_coordinates
+{
+  char * file_name; // binlog file name (directories stripped)
+  my_off_t  pos;       // event's position in the binlog file
+};
 
 /**
   @class Log_event
@@ -3541,12 +3562,16 @@ class Rows_log_event : public Log_event
   int write_row(const Relay_log_info *const, const bool);
 
   // Unpack the current row into m_table->record[0]
-  int unpack_current_row(const Relay_log_info *const rli)
+  int unpack_current_row(const Relay_log_info *const rli,
+                         const bool abort_on_warning= TRUE)
   { 
     DBUG_ASSERT(m_table);
+
+    bool first_row= (m_curr_row == m_rows_buf);
     ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
     int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, &m_cols,
-                                   &m_curr_row_end, &m_master_reclength);
+                                   &m_curr_row_end, &m_master_reclength,
+                                   abort_on_warning, first_row);
     if (m_curr_row_end > m_rows_end)
       my_error(ER_SLAVE_CORRUPT_EVENT, MYF(0));
     ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
@@ -3916,6 +3941,42 @@ static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
     reinit_io_cache(cache, WRITE_CACHE, 0, FALSE, TRUE);
 }
 
+#ifndef MYSQL_CLIENT
+/*****************************************************************************
+
+  Heartbeat Log Event class
+
+  Replication event to ensure to slave that master is alive.
+  The event is originated by master's dump thread and sent straight to
+  slave without being logged. Slave itself does not store it in relay log
+  but rather uses a data for immediate checks and throws away the event.
+
+  Two members of the class log_ident and Log_event::log_pos comprise 
+  @see the event_coordinates instance. The coordinates that a heartbeat
+  instance carries correspond to the last event master has sent from
+  its binlog.
+
+ ****************************************************************************/
+class Heartbeat_log_event: public Log_event
+{
+public:
+  Heartbeat_log_event(const char* buf, uint event_len,
+                      const Format_description_log_event* description_event);
+  Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; }
+  bool is_valid() const
+    {
+      return (log_ident != NULL &&
+              log_pos >= BIN_LOG_HEADER_SIZE);
+    }
+  const char * get_log_ident() { return log_ident; }
+  uint get_ident_len() { return ident_len; }
+  
+private:
+  const char* log_ident;
+  uint ident_len;
+};
+#endif
+
 /**
   @} (end of group Replication)
 */
diff --git a/sql/log_event_old.cc b/sql/log_event_old.cc
index f1e5c43b04df345b72adc281f63fcce6bd8127bc..e6888af9cfcf1c6efb2d5108e064e7122001065a 100644
--- a/sql/log_event_old.cc
+++ b/sql/log_event_old.cc
@@ -226,7 +226,7 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
 
       row_start= row_end;
     }
-    DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
+    DBUG_EXECUTE_IF("stop_slave_middle_group",
                     const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
     error= do_after_row_operations(table, error);
     if (!ev->cache_stmt)
@@ -269,34 +269,6 @@ Old_rows_log_event::do_apply_event(Old_rows_log_event *ev, const Relay_log_info
     DBUG_RETURN(error);
   }
 
-  /*
-    This code would ideally be placed in do_update_pos() instead, but
-    since we have no access to table there, we do the setting of
-    last_event_start_time here instead.
-  */
-  if (table && (table->s->primary_key == MAX_KEY) &&
-      !ev->cache_stmt && 
-      ev->get_flags(Old_rows_log_event::STMT_END_F) == Old_rows_log_event::RLE_NO_FLAGS)
-  {
-    /*
-      ------------ Temporary fix until WL#2975 is implemented ---------
-
-      This event is not the last one (no STMT_END_F). If we stop now
-      (in case of terminate_slave_thread()), how will we restart? We
-      have to restart from Table_map_log_event, but as this table is
-      not transactional, the rows already inserted will still be
-      present, and idempotency is not guaranteed (no PK) so we risk
-      that repeating leads to double insert. So we desperately try to
-      continue, hope we'll eventually leave this buggy situation (by
-      executing the final Old_rows_log_event). If we are in a hopeless
-      wait (reached end of last relay log and nothing gets appended
-      there), we timeout after one minute, and notify DBA about the
-      problem.  When WL#2975 is implemented, just remove the member
-      st_relay_log_info::last_event_start_time and all its occurences.
-    */
-    const_cast<Relay_log_info*>(rli)->last_event_start_time= my_time(0);
-  }
-
   DBUG_RETURN(0);
 }
 #endif
@@ -1744,7 +1716,7 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli)
  
     } // row processing loop
 
-    DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
+    DBUG_EXECUTE_IF("stop_slave_middle_group",
                     const_cast<Relay_log_info*>(rli)->abort_slave= 1;);
     error= do_after_row_operations(rli, error);
     if (!cache_stmt)
diff --git a/sql/message.h b/sql/message.h
index 0e7c282d5a1abf9b87ffac49b861a33cd217d14c..97d039352b44a7b7c638477ec749037a844d12c7 100644
--- a/sql/message.h
+++ b/sql/message.h
@@ -1,3 +1,6 @@
+#ifndef MESSAGE_INCLUDED
+#define MESSAGE_INCLUDED
+
 /*
   To change or add messages mysqld writes to the Windows error log, run
    mc.exe message.mc
@@ -6,6 +9,8 @@
   mc.exe can be installed with Windows SDK, some Visual Studio distributions 
   do not include it.
 */
+
+
 //
 //  Values are 32 bit values layed out as follows:
 //
@@ -53,3 +58,5 @@
 //
 #define MSG_DEFAULT                      0xC0000064L
 
+#endif /* MESSAGE_INCLUDED */
+
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 128117e836d88473d029e17fb591184bcd1f7c5b..05a79957963b555311917cd8518847dd1401bdb2 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -963,100 +963,6 @@ struct Query_cache_query_flags
 #define query_cache_is_cacheable_query(L) 0
 #endif /*HAVE_QUERY_CACHE*/
 
-/*
-  Error injector Macros to enable easy testing of recovery after failures
-  in various error cases.
-*/
-#ifndef ERROR_INJECT_SUPPORT
-
-#define ERROR_INJECT(x) 0
-#define ERROR_INJECT_ACTION(x,action) 0
-#define ERROR_INJECT_CRASH(x) 0
-#define ERROR_INJECT_VALUE(x) 0
-#define ERROR_INJECT_VALUE_ACTION(x,action) 0
-#define ERROR_INJECT_VALUE_CRASH(x) 0
-#define SET_ERROR_INJECT_VALUE(x)
-
-#else
-
-inline bool check_and_unset_keyword(const char *dbug_str)
-{
-  const char *extra_str= "-d,";
-  char total_str[200];
-  if (_db_strict_keyword_ (dbug_str))
-  {
-    strxmov(total_str, extra_str, dbug_str, NullS);
-    DBUG_SET(total_str);
-    return 1;
-  }
-  return 0;
-}
-
-
-inline bool
-check_and_unset_inject_value(int value)
-{
-  THD *thd= current_thd;
-  if (thd->error_inject_value == (uint)value)
-  {
-    thd->error_inject_value= 0;
-    return 1;
-  }
-  return 0;
-}
-
-/*
-  ERROR INJECT MODULE:
-  --------------------
-  These macros are used to insert macros from the application code.
-  The event that activates those error injections can be activated
-  from SQL by using:
-  SET SESSION dbug=+d,code;
-
-  After the error has been injected, the macros will automatically
-  remove the debug code, thus similar to using:
-  SET SESSION dbug=-d,code
-  from SQL.
-
-  ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
-  is set when macro is called. ERROR_INJECT_CRASH can be used in
-  if-statements, it will always return FALSE unless of course it
-  crashes in which case it doesn't return at all.
-
-  ERROR_INJECT_ACTION will inject the action specified in the action
-  parameter of the macro, before performing the action the code will
-  be removed such that no more events occur. ERROR_INJECT_ACTION
-  can also be used in if-statements and always returns FALSE.
-  ERROR_INJECT can be used in a normal if-statement, where the action
-  part is performed in the if-block. The macro returns TRUE if the
-  error was activated and otherwise returns FALSE. If activated the
-  code is removed.
-
-  Sometimes it is necessary to perform error inject actions as a serie
-  of events. In this case one can use one variable on the THD object.
-  Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
-  Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
-  ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
-  behaviour as the above described macros except that they use the
-  error inject value instead of a code used by DBUG macros.
-*/
-#define SET_ERROR_INJECT_VALUE(x) \
-  current_thd->error_inject_value= (x)
-#define ERROR_INJECT_CRASH(code) \
-  DBUG_EVALUATE_IF(code, (abort(), 0), 0)
-#define ERROR_INJECT_ACTION(code, action) \
-  (check_and_unset_keyword(code) ? ((action), 0) : 0)
-#define ERROR_INJECT(code) \
-  check_and_unset_keyword(code)
-#define ERROR_INJECT_VALUE(value) \
-  check_and_unset_inject_value(value)
-#define ERROR_INJECT_VALUE_ACTION(value,action) \
-  (check_and_unset_inject_value(value) ? (action) : 0)
-#define ERROR_INJECT_VALUE_CRASH(value) \
-  ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
-
-#endif
-
 void write_bin_log(THD *thd, bool clear_error,
                    char const *query, ulong query_length);
 
@@ -1991,10 +1897,13 @@ extern ulong MYSQL_PLUGIN_IMPORT specialflag;
 #endif /* MYSQL_SERVER || INNODB_COMPATIBILITY_HOOKS */
 #ifdef MYSQL_SERVER
 extern ulong current_pid;
-extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
+extern ulong expire_logs_days;
+extern uint sync_binlog_period, sync_relaylog_period, 
+            sync_relayloginfo_period, sync_masterinfo_period;
 extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
 extern ulong tc_log_page_waits;
 extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
+extern my_bool relay_log_recovery;
 extern uint test_flags,select_errors,ha_open_options;
 extern uint protocol_version, mysqld_port, dropping_tables;
 extern uint delay_key_write_options;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 3aeea9ee5fbc7bbeba8101c196e0ccff75836cbb..608934d68640883c3c2feef2c78ad4aa0701f426 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -33,6 +33,8 @@
 
 #include "rpl_injector.h"
 
+#include "rpl_handler.h"
+
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
 #endif
@@ -490,6 +492,7 @@ extern const char *opt_ndb_distribution;
 extern enum ndb_distribution opt_ndb_distribution_id;
 #endif
 my_bool opt_readonly, use_temp_pool, relay_log_purge;
+my_bool relay_log_recovery;
 my_bool opt_sync_frm, opt_allow_suspicious_udfs;
 my_bool opt_secure_auth= 0;
 char* opt_secure_file_priv= 0;
@@ -569,7 +572,9 @@ ulong max_prepared_stmt_count;
 */
 ulong prepared_stmt_count=0;
 ulong thread_id=1L,current_pid;
-ulong slow_launch_threads = 0, sync_binlog_period;
+ulong slow_launch_threads = 0;
+uint sync_binlog_period= 0, sync_relaylog_period= 0,
+     sync_relayloginfo_period= 0, sync_masterinfo_period= 0;
 ulong expire_logs_days = 0;
 ulong rpl_recovery_rank=0;
 const char *log_output_str= "FILE";
@@ -1317,6 +1322,7 @@ void clean_up(bool print_message)
   ha_end();
   if (tc_log)
     tc_log->close();
+  delegates_destroy();
   xid_cache_free();
   delete_elements(&key_caches, (void (*)(const char*, uchar*)) free_key_cache);
   multi_keycache_free();
@@ -3108,6 +3114,7 @@ SHOW_VAR com_status_vars[]= {
   {"show_processlist",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROCESSLIST]), SHOW_LONG_STATUS},
   {"show_profile",         (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROFILE]), SHOW_LONG_STATUS},
   {"show_profiles",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROFILES]), SHOW_LONG_STATUS},
+  {"show_relaylog_events", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_RELAYLOG_EVENTS]), SHOW_LONG_STATUS},
   {"show_slave_hosts",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
   {"show_slave_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
   {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
@@ -3809,6 +3816,13 @@ static int init_server_components()
     unireg_abort(1);
   }
 
+  /* initialize delegates for extension observers */
+  if (delegates_init())
+  {
+    sql_print_error("Initialize extension delegates failed");
+    unireg_abort(1);
+  }
+
   /* need to configure logging before initializing storage engines */
   if (opt_update_log)
   {
@@ -3867,17 +3881,17 @@ with --log-bin instead.");
   }
   if (opt_log_slave_updates && !opt_bin_log)
   {
-    sql_print_error("You need to use --log-bin to make "
+    sql_print_warning("You need to use --log-bin to make "
                     "--log-slave-updates work.");
-    unireg_abort(1);
   }
   if (!opt_bin_log)
   {
     if (opt_binlog_format_id != BINLOG_FORMAT_UNSPEC)
     {
-      sql_print_error("You need to use --log-bin to make "
-                      "--binlog-format work.");
-      unireg_abort(1);
+      sql_print_warning("You need to use --log-bin to make "
+                        "--binlog-format work.");
+
+      global_system_variables.binlog_format= opt_binlog_format_id;
     }
     else
     {
@@ -3899,11 +3913,17 @@ with --log-bin instead.");
 #ifdef HAVE_REPLICATION
   if (opt_log_slave_updates && replicate_same_server_id)
   {
-    sql_print_error("\
-using --replicate-same-server-id in conjunction with \
+    if (opt_bin_log)
+    {
+      sql_print_error("using --replicate-same-server-id in conjunction with \
 --log-slave-updates is impossible, it would lead to infinite loops in this \
 server.");
-    unireg_abort(1);
+      unireg_abort(1);
+    }
+    else
+      sql_print_warning("using --replicate-same-server-id in conjunction with \
+--log-slave-updates would lead to infinite loops in this server. However this \
+will be ignored as the --log-bin option is not defined.");
   }
 #endif
 
@@ -5643,6 +5663,7 @@ enum options_mysqld
   OPT_QUERY_CACHE_TYPE, OPT_QUERY_CACHE_WLOCK_INVALIDATE, OPT_RECORD_BUFFER,
   OPT_RECORD_RND_BUFFER, OPT_DIV_PRECINCREMENT, OPT_RELAY_LOG_SPACE_LIMIT,
   OPT_RELAY_LOG_PURGE,
+  OPT_RELAY_LOG_RECOVERY,
   OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
   OPT_SLAVE_TRANS_RETRIES, OPT_READONLY, OPT_DEBUGGING,
   OPT_SORT_BUFFER, OPT_TABLE_OPEN_CACHE, OPT_TABLE_DEF_CACHE,
@@ -5711,7 +5732,10 @@ enum options_mysqld
   OPT_SLAVE_EXEC_MODE,
   OPT_GENERAL_LOG_FILE,
   OPT_SLOW_QUERY_LOG_FILE,
-  OPT_IGNORE_BUILTIN_INNODB
+  OPT_IGNORE_BUILTIN_INNODB,
+  OPT_SYNC_RELAY_LOG,
+  OPT_SYNC_RELAY_LOG_INFO,
+  OPT_SYNC_MASTER_INFO
 };
 
 
@@ -6952,6 +6976,13 @@ The minimum value for this variable is 4096.",
    (uchar**) &relay_log_purge,
    (uchar**) &relay_log_purge, 0, GET_BOOL, NO_ARG,
    1, 0, 1, 0, 1, 0},
+  {"relay_log_recovery", OPT_RELAY_LOG_RECOVERY,
+   "Enables automatic relay log recovery right after the database startup, "
+   "which means that the IO Thread starts re-fetching from the master " 
+   "right after the last transaction processed.",
+   (uchar**) &relay_log_recovery,
+   (uchar**) &relay_log_recovery, 0, GET_BOOL, NO_ARG,
+   0, 0, 1, 0, 1, 0},
   {"relay_log_space_limit", OPT_RELAY_LOG_SPACE_LIMIT,
    "Maximum space to use for all relay logs.",
    (uchar**) &relay_log_space_limit,
@@ -6986,8 +7017,23 @@ The minimum value for this variable is 4096.",
   {"sync-binlog", OPT_SYNC_BINLOG,
    "Synchronously flush binary log to disk after every #th event. "
    "Use 0 (default) to disable synchronous flushing.",
-   (uchar**) &sync_binlog_period, (uchar**) &sync_binlog_period, 0, GET_ULONG,
-   REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1, 0},
+   (uchar**) &sync_binlog_period, (uchar**) &sync_binlog_period, 0, GET_UINT,
+   REQUIRED_ARG, 0, 0, (longlong) UINT_MAX, 0, 1, 0},
+  {"sync-relay-log", OPT_SYNC_RELAY_LOG,
+   "Synchronously flush relay log to disk after every #th event. "
+   "Use 0 (default) to disable synchronous flushing.",
+   (uchar**) &sync_relaylog_period, (uchar**) &sync_relaylog_period, 0, GET_UINT,
+   REQUIRED_ARG, 0, 0, (longlong) UINT_MAX, 0, 1, 0},
+  {"sync-relay-log-info", OPT_SYNC_RELAY_LOG_INFO,
+   "Synchronously flush relay log info to disk after #th transaction. "
+   "Use 0 (default) to disable synchronous flushing.",
+   (uchar**) &sync_relayloginfo_period, (uchar**) &sync_relayloginfo_period, 0, GET_UINT,
+   REQUIRED_ARG, 0, 0, (longlong) UINT_MAX, 0, 1, 0},
+  {"sync-master-info", OPT_SYNC_MASTER_INFO,
+   "Synchronously flush master info to disk after every #th event. "
+   "Use 0 (default) to disable synchronous flushing.",
+   (uchar**) &sync_masterinfo_period, (uchar**) &sync_masterinfo_period, 0, GET_UINT,
+   REQUIRED_ARG, 0, 0, (longlong) UINT_MAX, 0, 1, 0},
   {"sync-frm", OPT_SYNC_FRM, "Sync .frm to disk on create. Enabled by default.",
    (uchar**) &opt_sync_frm, (uchar**) &opt_sync_frm, 0, GET_BOOL, NO_ARG, 1, 0,
    0, 0, 0, 0},
@@ -7113,7 +7159,8 @@ static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff)
   var->type= SHOW_MY_BOOL;
   pthread_mutex_lock(&LOCK_active_mi);
   var->value= buff;
-  *((my_bool *)buff)= (my_bool) (active_mi && active_mi->slave_running &&
+  *((my_bool *)buff)= (my_bool) (active_mi && 
+                                 active_mi->slave_running == MYSQL_SLAVE_RUN_CONNECT &&
                                  active_mi->rli.slave_running);
   pthread_mutex_unlock(&LOCK_active_mi);
   return 0;
@@ -7139,6 +7186,40 @@ static int show_slave_retried_trans(THD *thd, SHOW_VAR *var, char *buff)
   pthread_mutex_unlock(&LOCK_active_mi);
   return 0;
 }
+
+static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff)
+{
+  pthread_mutex_lock(&LOCK_active_mi);
+  if (active_mi)
+  {
+    var->type= SHOW_LONGLONG;
+    var->value= buff;
+    pthread_mutex_lock(&active_mi->rli.data_lock);
+    *((longlong *)buff)= active_mi->received_heartbeats;
+    pthread_mutex_unlock(&active_mi->rli.data_lock);
+  }
+  else
+    var->type= SHOW_UNDEF;
+  pthread_mutex_unlock(&LOCK_active_mi);
+  return 0;
+}
+
+static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff)
+{
+  pthread_mutex_lock(&LOCK_active_mi);
+  if (active_mi)
+  {
+    var->type= SHOW_CHAR;
+    var->value= buff;
+    my_sprintf(buff, (buff, "%.3f",active_mi->heartbeat_period));
+  }
+  else
+    var->type= SHOW_UNDEF;
+  pthread_mutex_unlock(&LOCK_active_mi);
+  return 0;
+}
+
+
 #endif /* HAVE_REPLICATION */
 
 static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff)
@@ -7503,6 +7584,8 @@ SHOW_VAR status_vars[]= {
   {"Slave_open_temp_tables",   (char*) &slave_open_temp_tables, SHOW_LONG},
 #ifdef HAVE_REPLICATION
   {"Slave_retried_transactions",(char*) &show_slave_retried_trans, SHOW_FUNC},
+  {"Slave_heartbeat_period",   (char*) &show_heartbeat_period, SHOW_FUNC},
+  {"Slave_received_heartbeats",(char*) &show_slave_received_heartbeats, SHOW_FUNC},
   {"Slave_running",            (char*) &show_slave_running,     SHOW_FUNC},
 #endif
   {"Slow_launch_threads",      (char*) &slow_launch_threads,    SHOW_LONG},
diff --git a/sql/mysqld_suffix.h b/sql/mysqld_suffix.h
index 654d7cf88c1cdb3a9fc9a764eb377aaa4a7f06a7..c7ab212f2a29be479329d03d9f82b6267996d274 100644
--- a/sql/mysqld_suffix.h
+++ b/sql/mysqld_suffix.h
@@ -1,3 +1,6 @@
+#ifndef MYSQLD_SUFFIX_INCLUDED
+#define MYSQLD_SUFFIX_INCLUDED
+
 /* Copyright (C) 2000-2004 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -27,3 +30,4 @@
 #else
 #define MYSQL_SERVER_SUFFIX_STR MYSQL_SERVER_SUFFIX_DEF
 #endif
+#endif /* MYSQLD_SUFFIX_INCLUDED */
diff --git a/sql/nt_servc.h b/sql/nt_servc.h
index 2f0d07df543295f3eddb38eb680faa11ef369265..5bee42dedf00247952337257bcd3485260902344 100644
--- a/sql/nt_servc.h
+++ b/sql/nt_servc.h
@@ -1,3 +1,6 @@
+#ifndef NT_SERVC_INCLUDED
+#define NT_SERVC_INCLUDED
+
 /**
   @file
 
@@ -98,3 +101,5 @@ class NTService
 
 };
 /* ------------------------- the end -------------------------------------- */
+
+#endif /* NT_SERVC_INCLUDED */
diff --git a/sql/partition_element.h b/sql/partition_element.h
index bede5264c71029191ba34c4736e1f81ff94f051f..5575eb93bfb06cf91ee59ab43adf42c64a415c03 100644
--- a/sql/partition_element.h
+++ b/sql/partition_element.h
@@ -1,3 +1,6 @@
+#ifndef PARTITION_ELEMENT_INCLUDED
+#define PARTITION_ELEMENT_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -98,3 +101,5 @@ class partition_element :public Sql_alloc {
   }
   ~partition_element() {}
 };
+
+#endif /* PARTITION_ELEMENT_INCLUDED */
diff --git a/sql/partition_info.h b/sql/partition_info.h
index 9f438e8260bb01c8776dec6ae0ea17f9110e46e2..b5a6c4a0961bea42d75ee92c7666f5b022ce7a0e 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -1,3 +1,6 @@
+#ifndef PARTITION_INFO_INCLUDED
+#define PARTITION_INFO_INCLUDED
+
 /* Copyright 2006-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -314,3 +317,5 @@ void init_all_partitions_iterator(partition_info *part_info,
   part_iter->ret_null_part= part_iter->ret_null_part_orig= FALSE;
   part_iter->get_next= get_next_partition_id_range;
 }
+
+#endif /* PARTITION_INFO_INCLUDED */
diff --git a/sql/procedure.h b/sql/procedure.h
index ceb586766b1ce77260388091bdb1c071835780d7..c6f50493876226846cc0959e5396083497de9050 100644
--- a/sql/procedure.h
+++ b/sql/procedure.h
@@ -1,3 +1,6 @@
+#ifndef PROCEDURE_INCLUDED
+#define PROCEDURE_INCLUDED
+
 /* Copyright (C) 2000-2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -149,3 +152,5 @@ class Procedure {
 
 Procedure *setup_procedure(THD *thd,ORDER *proc_param,select_result *result,
 			   List<Item> &field_list,int *error);
+
+#endif /* PROCEDURE_INCLUDED */
diff --git a/sql/protocol.h b/sql/protocol.h
index 3b6a3bdb863a945c64ddb45877b7f9465f3b152b..2857ee2e3ca777c2615cf543b851c0d33d959271 100644
--- a/sql/protocol.h
+++ b/sql/protocol.h
@@ -1,3 +1,6 @@
+#ifndef PROTOCOL_INCLUDED
+#define PROTOCOL_INCLUDED
+
 /* Copyright (C) 2002-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -184,3 +187,4 @@ uchar *net_store_data(uchar *to,const uchar *from, size_t length);
 uchar *net_store_data(uchar *to,int32 from);
 uchar *net_store_data(uchar *to,longlong from);
 
+#endif /* PROTOCOL_INCLUDED */
diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h
index 6ff78067acac308df3b536e1d36361a1d77dac0f..bce2c7270500183e6707b6eaafd9f5ab56884995 100644
--- a/sql/repl_failsafe.h
+++ b/sql/repl_failsafe.h
@@ -1,3 +1,6 @@
+#ifndef REPL_FAILSAFE_INCLUDED
+#define REPL_FAILSAFE_INCLUDED
+
 /* Copyright (C) 2001-2005 MySQL AB & Sasha
 
    This program is free software; you can redistribute it and/or modify
@@ -49,3 +52,4 @@ int register_slave(THD* thd, uchar* packet, uint packet_length);
 void unregister_slave(THD* thd, bool only_mine, bool need_mutex);
 
 #endif /* HAVE_REPLICATION */
+#endif /* REPL_FAILSAFE_INCLUDED */
diff --git a/sql/replication.h b/sql/replication.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b7be58a5b1cc6a0f44ca51739f182b69c23f8d2
--- /dev/null
+++ b/sql/replication.h
@@ -0,0 +1,490 @@
+/* Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef REPLICATION_H
+#define REPLICATION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+   Transaction observer flags.
+*/
+enum Trans_flags {
+  /** Transaction is a real transaction */
+  TRANS_IS_REAL_TRANS = 1
+};
+
+/**
+   Transaction observer parameter
+*/
+typedef struct Trans_param {
+  uint32 server_id;
+  uint32 flags;
+
+  /*
+    The latest binary log file name and position written by current
+    transaction, if binary log is disabled or no log event has been
+    written into binary log file by current transaction (events
+    written into transaction log cache are not counted), these two
+    member will be zero.
+  */
+  const char *log_file;
+  my_off_t log_pos;
+} Trans_param;
+
+/**
+   Observes and extends transaction execution
+*/
+typedef struct Trans_observer {
+  uint32 len;
+
+  /**
+     This callback is called after transaction commit
+     
+     This callback is called right after commit to storage engines for
+     transactional tables.
+
+     For non-transactional tables, this is called at the end of the
+     statement, before sending statement status, if the statement
+     succeeded.
+
+     @note The return value is currently ignored by the server.
+
+     @param param The parameter for transaction observers
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_commit)(Trans_param *param);
+
+  /**
+     This callback is called after transaction rollback
+
+     This callback is called right after rollback to storage engines
+     for transactional tables.
+
+     For non-transactional tables, this is called at the end of the
+     statement, before sending statement status, if the statement
+     failed.
+
+     @note The return value is currently ignored by the server.
+
+     @param param The parameter for transaction observers
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_rollback)(Trans_param *param);
+} Trans_observer;
+
+/**
+   Binlog storage flags
+*/
+enum Binlog_storage_flags {
+  /** Binary log was sync:ed */
+  BINLOG_STORAGE_IS_SYNCED = 1
+};
+
+/**
+   Binlog storage observer parameters
+ */
+typedef struct Binlog_storage_param {
+  uint32 server_id;
+} Binlog_storage_param;
+
+/**
+   Observe binlog logging storage
+*/
+typedef struct Binlog_storage_observer {
+  uint32 len;
+
+  /**
+     This callback is called after binlog has been flushed
+
+     This callback is called after cached events have been flushed to
+     binary log file. Whether the binary log file is synchronized to
+     disk is indicated by the bit BINLOG_STORAGE_IS_SYNCED in @a flags.
+
+     @param param Observer common parameter
+     @param log_file Binlog file name been updated
+     @param log_pos Binlog position after update
+     @param flags flags for binlog storage
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_flush)(Binlog_storage_param *param,
+                     const char *log_file, my_off_t log_pos,
+                     uint32 flags);
+} Binlog_storage_observer;
+
+/**
+   Replication binlog transmitter (binlog dump) observer parameter.
+*/
+typedef struct Binlog_transmit_param {
+  uint32 server_id;
+  uint32 flags;
+} Binlog_transmit_param;
+
+/**
+   Observe and extends the binlog dumping thread.
+*/
+typedef struct Binlog_transmit_observer {
+  uint32 len;
+  
+  /**
+     This callback is called when binlog dumping starts
+
+
+     @param param Observer common parameter
+     @param log_file Binlog file name to transmit from
+     @param log_pos Binlog position to transmit from
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*transmit_start)(Binlog_transmit_param *param,
+                        const char *log_file, my_off_t log_pos);
+
+  /**
+     This callback is called when binlog dumping stops
+
+     @param param Observer common parameter
+     
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*transmit_stop)(Binlog_transmit_param *param);
+
+  /**
+     This callback is called to reserve bytes in packet header for event transmission
+
+     This callback is called when resetting transmit packet header to
+     reserve bytes for this observer in packet header.
+
+     The @a header buffer is allocated by the server code, and @a size
+     is the size of the header buffer. Each observer can only reserve
+     a maximum size of @a size in the header.
+
+     @param param Observer common parameter
+     @param header Pointer of the header buffer
+     @param size Size of the header buffer
+     @param len Header length reserved by this observer
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*reserve_header)(Binlog_transmit_param *param,
+                        unsigned char *header,
+                        unsigned long size,
+                        unsigned long *len);
+
+  /**
+     This callback is called before sending an event packet to slave
+
+     @param param Observer common parameter
+     @param packet Binlog event packet to send
+     @param len Length of the event packet
+     @param log_file Binlog file name of the event packet to send
+     @param log_pos Binlog position of the event packet to send
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*before_send_event)(Binlog_transmit_param *param,
+                           unsigned char *packet, unsigned long len,
+                           const char *log_file, my_off_t log_pos );
+
+  /**
+     This callback is called after sending an event packet to slave
+
+     @param param Observer common parameter
+     @param event_buf Binlog event packet buffer sent
+     @param len length of the event packet buffer
+
+     @retval 0 Sucess
+     @retval 1 Failure
+   */
+  int (*after_send_event)(Binlog_transmit_param *param,
+                          const char *event_buf, unsigned long len);
+
+  /**
+     This callback is called after resetting master status
+
+     This is called when executing the command RESET MASTER, and is
+     used to reset status variables added by observers.
+
+     @param param Observer common parameter
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_reset_master)(Binlog_transmit_param *param);
+} Binlog_transmit_observer;
+
+/**
+   Binlog relay IO flags
+*/
+enum Binlog_relay_IO_flags {
+  /** Binary relay log was sync:ed */
+  BINLOG_RELAY_IS_SYNCED = 1
+};
+
+
+/**
+  Replication binlog relay IO observer parameter
+*/
+typedef struct Binlog_relay_IO_param {
+  uint32 server_id;
+
+  /* Master host, user and port */
+  char *host;
+  char *user;
+  unsigned int port;
+
+  char *master_log_name;
+  my_off_t master_log_pos;
+
+  MYSQL *mysql;                        /* the connection to master */
+} Binlog_relay_IO_param;
+
+/**
+   Observes and extends the service of slave IO thread.
+*/
+typedef struct Binlog_relay_IO_observer {
+  uint32 len;
+
+  /**
+     This callback is called when slave IO thread starts
+
+     @param param Observer common parameter
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*thread_start)(Binlog_relay_IO_param *param);
+
+  /**
+     This callback is called when slave IO thread stops
+
+     @param param Observer common parameter
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*thread_stop)(Binlog_relay_IO_param *param);
+
+  /**
+     This callback is called before slave requesting binlog transmission from master
+
+     This is called before slave issuing BINLOG_DUMP command to master
+     to request binlog.
+
+     @param param Observer common parameter
+     @param flags binlog dump flags
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*before_request_transmit)(Binlog_relay_IO_param *param, uint32 flags);
+
+  /**
+     This callback is called after read an event packet from master
+
+     @param param Observer common parameter
+     @param packet The event packet read from master
+     @param len Length of the event packet read from master
+     @param event_buf The event packet return after process
+     @param event_len The length of event packet return after process
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_read_event)(Binlog_relay_IO_param *param,
+                          const char *packet, unsigned long len,
+                          const char **event_buf, unsigned long *event_len);
+
+  /**
+     This callback is called after written an event packet to relay log
+
+     @param param Observer common parameter
+     @param event_buf Event packet written to relay log
+     @param event_len Length of the event packet written to relay log
+     @param flags flags for relay log
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_queue_event)(Binlog_relay_IO_param *param,
+                           const char *event_buf, unsigned long event_len,
+                           uint32 flags);
+
+  /**
+     This callback is called after reset slave relay log IO status
+     
+     @param param Observer common parameter
+
+     @retval 0 Sucess
+     @retval 1 Failure
+  */
+  int (*after_reset_slave)(Binlog_relay_IO_param *param);
+} Binlog_relay_IO_observer;
+
+
+/**
+   Register a transaction observer
+
+   @param observer The transaction observer to register
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer already exists
+*/
+int register_trans_observer(Trans_observer *observer, void *p);
+
+/**
+   Unregister a transaction observer
+
+   @param observer The transaction observer to unregister
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer not exists
+*/
+int unregister_trans_observer(Trans_observer *observer, void *p);
+
+/**
+   Register a binlog storage observer
+
+   @param observer The binlog storage observer to register
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer already exists
+*/
+int register_binlog_storage_observer(Binlog_storage_observer *observer, void *p);
+
+/**
+   Unregister a binlog storage observer
+
+   @param observer The binlog storage observer to unregister
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer not exists
+*/
+int unregister_binlog_storage_observer(Binlog_storage_observer *observer, void *p);
+
+/**
+   Register a binlog transmit observer
+
+   @param observer The binlog transmit observer to register
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer already exists
+*/
+int register_binlog_transmit_observer(Binlog_transmit_observer *observer, void *p);
+
+/**
+   Unregister a binlog transmit observer
+
+   @param observer The binlog transmit observer to unregister
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer not exists
+*/
+int unregister_binlog_transmit_observer(Binlog_transmit_observer *observer, void *p);
+
+/**
+   Register a binlog relay IO (slave IO thread) observer
+
+   @param observer The binlog relay IO observer to register
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer already exists
+*/
+int register_binlog_relay_io_observer(Binlog_relay_IO_observer *observer, void *p);
+
+/**
+   Unregister a binlog relay IO (slave IO thread) observer
+
+   @param observer The binlog relay IO observer to unregister
+   @param p pointer to the internal plugin structure
+
+   @retval 0 Sucess
+   @retval 1 Observer not exists
+*/
+int unregister_binlog_relay_io_observer(Binlog_relay_IO_observer *observer, void *p);
+
+/**
+   Connect to master
+
+   This function can only used in the slave I/O thread context, and
+   will use the same master information to do the connection.
+
+   @code
+   MYSQL *mysql = mysql_init(NULL);
+   if (rpl_connect_master(mysql))
+   {
+     // do stuff with the connection
+   }
+   mysql_close(mysql); // close the connection
+   @endcode
+   
+   @param mysql address of MYSQL structure to use, pass NULL will
+   create a new one
+
+   @return address of MYSQL structure on success, NULL on failure
+*/
+MYSQL *rpl_connect_master(MYSQL *mysql);
+
+/**
+   Set thread entering a condition
+
+   This function should be called before putting a thread to wait for
+   a condition. @a mutex should be held before calling this
+   function. After being waken up, @f thd_exit_cond should be called.
+
+   @param thd      The thread entering the condition, NULL means current thread
+   @param cond     The condition the thread is going to wait for
+   @param mutex    The mutex associated with the condition, this must be
+                   held before call this function
+   @param msg      The new process message for the thread
+*/
+const char* thd_enter_cond(MYSQL_THD thd, pthread_cond_t *cond,
+                           pthread_mutex_t *mutex, const char *msg);
+
+/**
+   Set thread leaving a condition
+
+   This function should be called after a thread being waken up for a
+   condition.
+
+   @param thd      The thread entering the condition, NULL means current thread
+   @param old_msg  The process message, ususally this should be the old process
+                   message before calling @f thd_enter_cond
+*/
+void thd_exit_cond(MYSQL_THD thd, const char *old_msg);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* REPLICATION_H */
diff --git a/sql/rpl_handler.cc b/sql/rpl_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..da7aade5b99c645f9107657c8187053ffb919fb6
--- /dev/null
+++ b/sql/rpl_handler.cc
@@ -0,0 +1,493 @@
+/* Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include "mysql_priv.h"
+
+#include "rpl_mi.h"
+#include "sql_repl.h"
+#include "log_event.h"
+#include "rpl_filter.h"
+#include <my_dir.h>
+#include "rpl_handler.h"
+
+Trans_delegate *transaction_delegate;
+Binlog_storage_delegate *binlog_storage_delegate;
+#ifdef HAVE_REPLICATION
+Binlog_transmit_delegate *binlog_transmit_delegate;
+Binlog_relay_IO_delegate *binlog_relay_io_delegate;
+#endif /* HAVE_REPLICATION */
+
+/*
+  structure to save transaction log filename and position
+*/
+typedef struct Trans_binlog_info {
+  my_off_t log_pos;
+  char log_file[FN_REFLEN];
+} Trans_binlog_info;
+
+static pthread_key(Trans_binlog_info*, RPL_TRANS_BINLOG_INFO);
+
+int get_user_var_int(const char *name,
+                     long long int *value, int *null_value)
+{
+  my_bool null_val;
+  user_var_entry *entry= 
+    (user_var_entry*) hash_search(&current_thd->user_vars,
+                                  (uchar*) name, strlen(name));
+  if (!entry)
+    return 1;
+  *value= entry->val_int(&null_val);
+  if (null_value)
+    *null_value= null_val;
+  return 0;
+}
+
+int get_user_var_real(const char *name,
+                      double *value, int *null_value)
+{
+  my_bool null_val;
+  user_var_entry *entry= 
+    (user_var_entry*) hash_search(&current_thd->user_vars,
+                                  (uchar*) name, strlen(name));
+  if (!entry)
+    return 1;
+  *value= entry->val_real(&null_val);
+  if (null_value)
+    *null_value= null_val;
+  return 0;
+}
+
+int get_user_var_str(const char *name, char *value,
+                     size_t len, unsigned int precision, int *null_value)
+{
+  String str;
+  my_bool null_val;
+  user_var_entry *entry= 
+    (user_var_entry*) hash_search(&current_thd->user_vars,
+                                  (uchar*) name, strlen(name));
+  if (!entry)
+    return 1;
+  entry->val_str(&null_val, &str, precision);
+  strncpy(value, str.c_ptr(), len);
+  if (null_value)
+    *null_value= null_val;
+  return 0;
+}
+
+int delegates_init()
+{
+  static unsigned long trans_mem[sizeof(Trans_delegate) / sizeof(unsigned long) + 1];
+  static unsigned long storage_mem[sizeof(Binlog_storage_delegate) / sizeof(unsigned long) + 1];
+#ifdef HAVE_REPLICATION
+  static unsigned long transmit_mem[sizeof(Binlog_transmit_delegate) / sizeof(unsigned long) + 1];
+  static unsigned long relay_io_mem[sizeof(Binlog_relay_IO_delegate)/ sizeof(unsigned long) + 1];
+#endif
+  
+  if (!(transaction_delegate= new (trans_mem) Trans_delegate)
+      || (!transaction_delegate->is_inited())
+      || !(binlog_storage_delegate= new (storage_mem) Binlog_storage_delegate)
+      || (!binlog_storage_delegate->is_inited())
+#ifdef HAVE_REPLICATION
+      || !(binlog_transmit_delegate= new (transmit_mem) Binlog_transmit_delegate)
+      || (!binlog_transmit_delegate->is_inited())
+      || !(binlog_relay_io_delegate= new (relay_io_mem) Binlog_relay_IO_delegate)
+      || (!binlog_relay_io_delegate->is_inited())
+#endif /* HAVE_REPLICATION */
+      )
+    return 1;
+
+  if (pthread_key_create(&RPL_TRANS_BINLOG_INFO, NULL))
+    return 1;
+  return 0;
+}
+
+void delegates_destroy()
+{
+  if (transaction_delegate)
+    transaction_delegate->~Trans_delegate();
+  if (binlog_storage_delegate)
+    binlog_storage_delegate->~Binlog_storage_delegate();
+#ifdef HAVE_REPLICATION
+  if (binlog_transmit_delegate)
+    binlog_transmit_delegate->~Binlog_transmit_delegate();
+  if (binlog_relay_io_delegate)
+    binlog_relay_io_delegate->~Binlog_relay_IO_delegate();
+#endif /* HAVE_REPLICATION */
+}
+
+/*
+  This macro is used by almost all the Delegate methods to iterate
+  over all the observers running given callback function of the
+  delegate .
+  
+  Add observer plugins to the thd->lex list, after each statement, all
+  plugins add to thd->lex will be automatically unlocked.
+ */
+#define FOREACH_OBSERVER(r, f, thd, args)                               \
+  param.server_id= thd->server_id;                                      \
+  read_lock();                                                          \
+  Observer_info_iterator iter= observer_info_iter();                    \
+  Observer_info *info= iter++;                                          \
+  for (; info; info= iter++)                                            \
+  {                                                                     \
+    plugin_ref plugin=                                                  \
+      my_plugin_lock(thd, &info->plugin);                               \
+    if (!plugin)                                                        \
+    {                                                                   \
+      r= 1;                                                             \
+      break;                                                            \
+    }                                                                   \
+    if (((Observer *)info->observer)->f                                 \
+        && ((Observer *)info->observer)->f args)                        \
+    {                                                                   \
+      r= 1;                                                             \
+      plugin_unlock(thd, plugin);                                       \
+      break;                                                            \
+    }                                                                   \
+    plugin_unlock(thd, plugin);                                         \
+  }                                                                     \
+  unlock()
+
+
+int Trans_delegate::after_commit(THD *thd, bool all)
+{
+  Trans_param param;
+  bool is_real_trans= (all || thd->transaction.all.ha_list == 0);
+  if (is_real_trans)
+    param.flags |= TRANS_IS_REAL_TRANS;
+
+  Trans_binlog_info *log_info=
+    my_pthread_getspecific_ptr(Trans_binlog_info*, RPL_TRANS_BINLOG_INFO);
+
+  param.log_file= log_info ? log_info->log_file : 0;
+  param.log_pos= log_info ? log_info->log_pos : 0;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_commit, thd, (&param));
+
+  /*
+    This is the end of a real transaction or autocommit statement, we
+    can free the memory allocated for binlog file and position.
+  */
+  if (is_real_trans && log_info)
+  {
+    my_pthread_setspecific_ptr(RPL_TRANS_BINLOG_INFO, NULL);
+    my_free(log_info, MYF(0));
+  }
+  return ret;
+}
+
+int Trans_delegate::after_rollback(THD *thd, bool all)
+{
+  Trans_param param;
+  bool is_real_trans= (all || thd->transaction.all.ha_list == 0);
+  if (is_real_trans)
+    param.flags |= TRANS_IS_REAL_TRANS;
+
+  Trans_binlog_info *log_info=
+    my_pthread_getspecific_ptr(Trans_binlog_info*, RPL_TRANS_BINLOG_INFO);
+    
+  param.log_file= log_info ? log_info->log_file : 0;
+  param.log_pos= log_info ? log_info->log_pos : 0;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_commit, thd, (&param));
+
+  /*
+    This is the end of a real transaction or autocommit statement, we
+    can free the memory allocated for binlog file and position.
+  */
+  if (is_real_trans && log_info)
+  {
+    my_pthread_setspecific_ptr(RPL_TRANS_BINLOG_INFO, NULL);
+    my_free(log_info, MYF(0));
+  }
+  return ret;
+}
+
+int Binlog_storage_delegate::after_flush(THD *thd,
+                                         const char *log_file,
+                                         my_off_t log_pos,
+                                         bool synced)
+{
+  Binlog_storage_param param;
+  uint32 flags=0;
+  if (synced)
+    flags |= BINLOG_STORAGE_IS_SYNCED;
+
+  Trans_binlog_info *log_info=
+    my_pthread_getspecific_ptr(Trans_binlog_info*, RPL_TRANS_BINLOG_INFO);
+    
+  if (!log_info)
+  {
+    if(!(log_info=
+         (Trans_binlog_info *)my_malloc(sizeof(Trans_binlog_info), MYF(0))))
+      return 1;
+    my_pthread_setspecific_ptr(RPL_TRANS_BINLOG_INFO, log_info);
+  }
+    
+  strcpy(log_info->log_file, log_file+dirname_length(log_file));
+  log_info->log_pos = log_pos;
+  
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_flush, thd,
+                   (&param, log_info->log_file, log_info->log_pos, flags));
+  return ret;
+}
+
+#ifdef HAVE_REPLICATION
+int Binlog_transmit_delegate::transmit_start(THD *thd, ushort flags,
+                                             const char *log_file,
+                                             my_off_t log_pos)
+{
+  Binlog_transmit_param param;
+  param.flags= flags;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, transmit_start, thd, (&param, log_file, log_pos));
+  return ret;
+}
+
+int Binlog_transmit_delegate::transmit_stop(THD *thd, ushort flags)
+{
+  Binlog_transmit_param param;
+  param.flags= flags;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, transmit_stop, thd, (&param));
+  return ret;
+}
+
+int Binlog_transmit_delegate::reserve_header(THD *thd, ushort flags,
+                                             String *packet)
+{
+  /* NOTE2ME: Maximum extra header size for each observer, I hope 32
+     bytes should be enough for each Observer to reserve their extra
+     header. If later found this is not enough, we can increase this
+     /HEZX
+  */
+#define RESERVE_HEADER_SIZE 32
+  unsigned char header[RESERVE_HEADER_SIZE];
+  ulong hlen;
+  Binlog_transmit_param param;
+  param.flags= flags;
+  param.server_id= thd->server_id;
+
+  int ret= 0;
+  read_lock();
+  Observer_info_iterator iter= observer_info_iter();
+  Observer_info *info= iter++;
+  for (; info; info= iter++)
+  {
+    plugin_ref plugin=
+      my_plugin_lock(thd, &info->plugin);
+    if (!plugin)
+    {
+      ret= 1;
+      break;
+    }
+    hlen= 0;
+    if (((Observer *)info->observer)->reserve_header
+        && ((Observer *)info->observer)->reserve_header(&param,
+                                                        header,
+                                                        RESERVE_HEADER_SIZE,
+                                                        &hlen))
+    {
+      ret= 1;
+      plugin_unlock(thd, plugin);
+      break;
+    }
+    plugin_unlock(thd, plugin);
+    if (hlen == 0)
+      continue;
+    if (hlen > RESERVE_HEADER_SIZE || packet->append((char *)header, hlen))
+    {
+      ret= 1;
+      break;
+    }
+  }
+  unlock();
+  return ret;
+}
+
+int Binlog_transmit_delegate::before_send_event(THD *thd, ushort flags,
+                                                String *packet,
+                                                const char *log_file,
+                                                my_off_t log_pos)
+{
+  Binlog_transmit_param param;
+  param.flags= flags;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, before_send_event, thd,
+                   (&param, (uchar *)packet->c_ptr(),
+                    packet->length(),
+                    log_file+dirname_length(log_file), log_pos));
+  return ret;
+}
+
+int Binlog_transmit_delegate::after_send_event(THD *thd, ushort flags,
+                                               String *packet)
+{
+  Binlog_transmit_param param;
+  param.flags= flags;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_send_event, thd,
+                   (&param, packet->c_ptr(), packet->length()));
+  return ret;
+}
+
+int Binlog_transmit_delegate::after_reset_master(THD *thd, ushort flags)
+
+{
+  Binlog_transmit_param param;
+  param.flags= flags;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_reset_master, thd, (&param));
+  return ret;
+}
+
+void Binlog_relay_IO_delegate::init_param(Binlog_relay_IO_param *param,
+                                          Master_info *mi)
+{
+  param->mysql= mi->mysql;
+  param->user= mi->user;
+  param->host= mi->host;
+  param->port= mi->port;
+  param->master_log_name= mi->master_log_name;
+  param->master_log_pos= mi->master_log_pos;
+}
+
+int Binlog_relay_IO_delegate::thread_start(THD *thd, Master_info *mi)
+{
+  Binlog_relay_IO_param param;
+  init_param(&param, mi);
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, thread_start, thd, (&param));
+  return ret;
+}
+
+
+int Binlog_relay_IO_delegate::thread_stop(THD *thd, Master_info *mi)
+{
+
+  Binlog_relay_IO_param param;
+  init_param(&param, mi);
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, thread_stop, thd, (&param));
+  return ret;
+}
+
+int Binlog_relay_IO_delegate::before_request_transmit(THD *thd,
+                                                      Master_info *mi,
+                                                      ushort flags)
+{
+  Binlog_relay_IO_param param;
+  init_param(&param, mi);
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, before_request_transmit, thd, (&param, (uint32)flags));
+  return ret;
+}
+
+int Binlog_relay_IO_delegate::after_read_event(THD *thd, Master_info *mi,
+                                               const char *packet, ulong len,
+                                               const char **event_buf,
+                                               ulong *event_len)
+{
+  Binlog_relay_IO_param param;
+  init_param(&param, mi);
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_read_event, thd,
+                   (&param, packet, len, event_buf, event_len));
+  return ret;
+}
+
+int Binlog_relay_IO_delegate::after_queue_event(THD *thd, Master_info *mi,
+                                                const char *event_buf,
+                                                ulong event_len,
+                                                bool synced)
+{
+  Binlog_relay_IO_param param;
+  init_param(&param, mi);
+
+  uint32 flags=0;
+  if (synced)
+    flags |= BINLOG_STORAGE_IS_SYNCED;
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_queue_event, thd,
+                   (&param, event_buf, event_len, flags));
+  return ret;
+}
+
+int Binlog_relay_IO_delegate::after_reset_slave(THD *thd, Master_info *mi)
+
+{
+  Binlog_relay_IO_param param;
+  init_param(&param, mi);
+
+  int ret= 0;
+  FOREACH_OBSERVER(ret, after_reset_slave, thd, (&param));
+  return ret;
+}
+#endif /* HAVE_REPLICATION */
+
+int register_trans_observer(Trans_observer *observer, void *p)
+{
+  return transaction_delegate->add_observer(observer, (st_plugin_int *)p);
+}
+
+int unregister_trans_observer(Trans_observer *observer, void *p)
+{
+  return transaction_delegate->remove_observer(observer, (st_plugin_int *)p);
+}
+
+int register_binlog_storage_observer(Binlog_storage_observer *observer, void *p)
+{
+  return binlog_storage_delegate->add_observer(observer, (st_plugin_int *)p);
+}
+
+int unregister_binlog_storage_observer(Binlog_storage_observer *observer, void *p)
+{
+  return binlog_storage_delegate->remove_observer(observer, (st_plugin_int *)p);
+}
+
+#ifdef HAVE_REPLICATION
+int register_binlog_transmit_observer(Binlog_transmit_observer *observer, void *p)
+{
+  return binlog_transmit_delegate->add_observer(observer, (st_plugin_int *)p);
+}
+
+int unregister_binlog_transmit_observer(Binlog_transmit_observer *observer, void *p)
+{
+  return binlog_transmit_delegate->remove_observer(observer, (st_plugin_int *)p);
+}
+
+int register_binlog_relay_io_observer(Binlog_relay_IO_observer *observer, void *p)
+{
+  return binlog_relay_io_delegate->add_observer(observer, (st_plugin_int *)p);
+}
+
+int unregister_binlog_relay_io_observer(Binlog_relay_IO_observer *observer, void *p)
+{
+  return binlog_relay_io_delegate->remove_observer(observer, (st_plugin_int *)p);
+}
+#endif /* HAVE_REPLICATION */
diff --git a/sql/rpl_handler.h b/sql/rpl_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..4fb7b4e035bca1374ddc834688506a7cbd6aec28
--- /dev/null
+++ b/sql/rpl_handler.h
@@ -0,0 +1,213 @@
+/* Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef RPL_HANDLER_H
+#define RPL_HANDLER_H
+
+#include "mysql_priv.h"
+#include "rpl_mi.h"
+#include "rpl_rli.h"
+#include "sql_plugin.h"
+#include "replication.h"
+
+class Observer_info {
+public:
+  void *observer;
+  st_plugin_int *plugin_int;
+  plugin_ref plugin;
+
+  Observer_info(void *ob, st_plugin_int *p)
+    :observer(ob), plugin_int(p)
+  {
+    plugin= plugin_int_to_ref(plugin_int);
+  }
+};
+
+class Delegate {
+public:
+  typedef List<Observer_info> Observer_info_list;
+  typedef List_iterator<Observer_info> Observer_info_iterator;
+  
+  int add_observer(void *observer, st_plugin_int *plugin)
+  {
+    int ret= FALSE;
+    if (!inited)
+      return TRUE;
+    write_lock();
+    Observer_info_iterator iter(observer_info_list);
+    Observer_info *info= iter++;
+    while (info && info->observer != observer)
+      info= iter++;
+    if (!info)
+    {
+      info= new Observer_info(observer, plugin);
+      if (!info || observer_info_list.push_back(info, &memroot))
+        ret= TRUE;
+    }
+    else
+      ret= TRUE;
+    unlock();
+    return ret;
+  }
+  
+  int remove_observer(void *observer, st_plugin_int *plugin)
+  {
+    int ret= FALSE;
+    if (!inited)
+      return TRUE;
+    write_lock();
+    Observer_info_iterator iter(observer_info_list);
+    Observer_info *info= iter++;
+    while (info && info->observer != observer)
+      info= iter++;
+    if (info)
+      iter.remove();
+    else
+      ret= TRUE;
+    unlock();
+    return ret;
+  }
+
+  inline Observer_info_iterator observer_info_iter()
+  {
+    return Observer_info_iterator(observer_info_list);
+  }
+
+  inline bool is_empty()
+  {
+    return observer_info_list.is_empty();
+  }
+
+  inline int read_lock()
+  {
+    if (!inited)
+      return TRUE;
+    return rw_rdlock(&lock);
+  }
+
+  inline int write_lock()
+  {
+    if (!inited)
+      return TRUE;
+    return rw_wrlock(&lock);
+  }
+
+  inline int unlock()
+  {
+    if (!inited)
+      return TRUE;
+    return rw_unlock(&lock);
+  }
+
+  inline bool is_inited()
+  {
+    return inited;
+  }
+  
+  Delegate()
+  {
+    inited= FALSE;
+    if (my_rwlock_init(&lock, NULL))
+      return;
+    init_sql_alloc(&memroot, 1024, 0);
+    inited= TRUE;
+  }
+  ~Delegate()
+  {
+    inited= FALSE;
+    rwlock_destroy(&lock);
+    free_root(&memroot, MYF(0));
+  }
+
+private:
+  Observer_info_list observer_info_list;
+  rw_lock_t lock;
+  MEM_ROOT memroot;
+  bool inited;
+};
+
+class Trans_delegate
+  :public Delegate {
+public:
+  typedef Trans_observer Observer;
+  int before_commit(THD *thd, bool all);
+  int before_rollback(THD *thd, bool all);
+  int after_commit(THD *thd, bool all);
+  int after_rollback(THD *thd, bool all);
+};
+
+class Binlog_storage_delegate
+  :public Delegate {
+public:
+  typedef Binlog_storage_observer Observer;
+  int after_flush(THD *thd, const char *log_file,
+                  my_off_t log_pos, bool synced);
+};
+
+#ifdef HAVE_REPLICATION
+class Binlog_transmit_delegate
+  :public Delegate {
+public:
+  typedef Binlog_transmit_observer Observer;
+  int transmit_start(THD *thd, ushort flags,
+                     const char *log_file, my_off_t log_pos);
+  int transmit_stop(THD *thd, ushort flags);
+  int reserve_header(THD *thd, ushort flags, String *packet);
+  int before_send_event(THD *thd, ushort flags,
+                        String *packet, const
+                        char *log_file, my_off_t log_pos );
+  int after_send_event(THD *thd, ushort flags,
+                       String *packet);
+  int after_reset_master(THD *thd, ushort flags);
+};
+
+class Binlog_relay_IO_delegate
+  :public Delegate {
+public:
+  typedef Binlog_relay_IO_observer Observer;
+  int thread_start(THD *thd, Master_info *mi);
+  int thread_stop(THD *thd, Master_info *mi);
+  int before_request_transmit(THD *thd, Master_info *mi, ushort flags);
+  int after_read_event(THD *thd, Master_info *mi,
+                       const char *packet, ulong len,
+                       const char **event_buf, ulong *event_len);
+  int after_queue_event(THD *thd, Master_info *mi,
+                        const char *event_buf, ulong event_len,
+                        bool synced);
+  int after_reset_slave(THD *thd, Master_info *mi);
+private:
+  void init_param(Binlog_relay_IO_param *param, Master_info *mi);
+};
+#endif /* HAVE_REPLICATION */
+
+int delegates_init();
+void delegates_destroy();
+
+extern Trans_delegate *transaction_delegate;
+extern Binlog_storage_delegate *binlog_storage_delegate;
+#ifdef HAVE_REPLICATION
+extern Binlog_transmit_delegate *binlog_transmit_delegate;
+extern Binlog_relay_IO_delegate *binlog_relay_io_delegate;
+#endif /* HAVE_REPLICATION */
+
+/*
+  if there is no observers in the delegate, we can return 0
+  immediately.
+*/
+#define RUN_HOOK(group, hook, args)             \
+  (group ##_delegate->is_empty() ?              \
+   0 : group ##_delegate->hook args)
+
+#endif /* RPL_HANDLER_H */
diff --git a/sql/rpl_mi.cc b/sql/rpl_mi.cc
index 5e46837e948f7fd7d808d52c65567e8d2bb74931..e83e0ad0ba967c58486ac85a831fbe6d916f9b36 100644
--- a/sql/rpl_mi.cc
+++ b/sql/rpl_mi.cc
@@ -26,17 +26,21 @@
 int init_intvar_from_file(int* var, IO_CACHE* f, int default_val);
 int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
 			  const char *default_val);
+int init_floatvar_from_file(float* var, IO_CACHE* f, float default_val);
+int init_dynarray_intvar_from_file(DYNAMIC_ARRAY* arr, IO_CACHE* f);
 
-Master_info::Master_info()
+Master_info::Master_info(bool is_slave_recovery)
   :Slave_reporting_capability("I/O"),
    ssl(0), ssl_verify_server_cert(0), fd(-1), io_thd(0), inited(0),
-   abort_slave(0),slave_running(0),
-   slave_run_id(0)
+   rli(is_slave_recovery), abort_slave(0), slave_running(0),
+   slave_run_id(0), sync_counter(0),
+   heartbeat_period(0), received_heartbeats(0), master_id(0)
 {
   host[0] = 0; user[0] = 0; password[0] = 0;
   ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;
   ssl_cipher[0]= 0; ssl_key[0]= 0;
 
+  my_init_dynamic_array(&ignore_server_ids, sizeof(::server_id), 16, 16);
   bzero((char*) &file, sizeof(file));
   pthread_mutex_init(&run_lock, MY_MUTEX_INIT_FAST);
   pthread_mutex_init(&data_lock, MY_MUTEX_INIT_FAST);
@@ -47,6 +51,7 @@ Master_info::Master_info()
 
 Master_info::~Master_info()
 {
+  delete_dynamic(&ignore_server_ids);
   pthread_mutex_destroy(&run_lock);
   pthread_mutex_destroy(&data_lock);
   pthread_cond_destroy(&data_cond);
@@ -54,6 +59,43 @@ Master_info::~Master_info()
   pthread_cond_destroy(&stop_cond);
 }
 
+/**
+   A comparison function to be supplied as argument to @c sort_dynamic()
+   and @c bsearch()
+
+   @return -1 if first argument is less, 0 if it equal to, 1 if it is greater
+   than the second
+*/
+int change_master_server_id_cmp(ulong *id1, ulong *id2)
+{
+  return *id1 < *id2? -1 : (*id1 > *id2? 1 : 0);
+}
+
+
+/**
+   Reports if the s_id server has been configured to ignore events 
+   it generates with
+
+      CHANGE MASTER IGNORE_SERVER_IDS= ( list of server ids )
+
+   Method is called from the io thread event receiver filtering.
+
+   @param      s_id    the master server identifier
+
+   @retval   TRUE    if s_id is in the list of ignored master  servers,
+   @retval   FALSE   otherwise.
+ */
+bool Master_info::shall_ignore_server_id(ulong s_id)
+{
+  if (likely(ignore_server_ids.elements == 1))
+    return (* (ulong*) dynamic_array_ptr(&ignore_server_ids, 0)) == s_id;
+  else      
+    return bsearch((const ulong *) &s_id,
+                   ignore_server_ids.buffer,
+                   ignore_server_ids.elements, sizeof(ulong),
+                   (int (*) (const void*, const void*)) change_master_server_id_cmp)
+      != NULL;
+}
 
 void init_master_info_with_options(Master_info* mi)
 {
@@ -84,6 +126,17 @@ void init_master_info_with_options(Master_info* mi)
     strmake(mi->ssl_key, master_ssl_key, sizeof(mi->ssl_key)-1);
   /* Intentionally init ssl_verify_server_cert to 0, no option available  */
   mi->ssl_verify_server_cert= 0;
+  /* 
+    always request heartbeat unless master_heartbeat_period is set
+    explicitly zero.  Here is the default value for heartbeat period
+    if CHANGE MASTER did not specify it.  (no data loss in conversion
+    as hb period has a max)
+  */
+  mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
+                                    (slave_net_timeout/2.0));
+  DBUG_ASSERT(mi->heartbeat_period > (float) 0.001
+              || mi->heartbeat_period == 0);
+
   DBUG_VOID_RETURN;
 }
 
@@ -93,9 +146,12 @@ enum {
 
   /* 5.1.16 added value of master_ssl_verify_server_cert */
   LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT= 15,
-
+  /* 6.0 added value of master_heartbeat_period */
+  LINE_FOR_MASTER_HEARTBEAT_PERIOD= 16,
+  /* 6.0 added value of master_ignore_server_id */
+  LINE_FOR_REPLICATE_IGNORE_SERVER_IDS= 17,
   /* Number of lines currently used when saving master info file */
-  LINES_IN_MASTER_INFO= LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT
+  LINES_IN_MASTER_INFO= LINE_FOR_REPLICATE_IGNORE_SERVER_IDS
 };
 
 int init_master_info(Master_info* mi, const char* master_info_fname,
@@ -197,6 +253,7 @@ file '%s')", fname);
     mi->fd = fd;
     int port, connect_retry, master_log_pos, lines;
     int ssl= 0, ssl_verify_server_cert= 0;
+    float master_heartbeat_period= 0.0;
     char *first_non_digit;
 
     /*
@@ -281,7 +338,23 @@ file '%s')", fname);
       if (lines >= LINE_FOR_MASTER_SSL_VERIFY_SERVER_CERT &&
           init_intvar_from_file(&ssl_verify_server_cert, &mi->file, 0))
         goto errwithmsg;
-
+      /*
+        Starting from 6.0 master_heartbeat_period might be
+        in the file
+      */
+      if (lines >= LINE_FOR_MASTER_HEARTBEAT_PERIOD &&
+          init_floatvar_from_file(&master_heartbeat_period, &mi->file, 0.0))
+        goto errwithmsg;
+      /*
+        Starting from 6.0 list of server_id of ignorable servers might be
+        in the file
+      */
+      if (lines >= LINE_FOR_REPLICATE_IGNORE_SERVER_IDS &&
+          init_dynarray_intvar_from_file(&mi->ignore_server_ids, &mi->file))
+      {
+        sql_print_error("Failed to initialize master info ignore_server_ids");
+        goto errwithmsg;
+      }
     }
 
 #ifndef HAVE_OPENSSL
@@ -300,6 +373,7 @@ file '%s')", fname);
     mi->connect_retry= (uint) connect_retry;
     mi->ssl= (my_bool) ssl;
     mi->ssl_verify_server_cert= ssl_verify_server_cert;
+    mi->heartbeat_period= master_heartbeat_period;
   }
   DBUG_PRINT("master_info",("log_file_name: %s  position: %ld",
                             mi->master_log_name,
@@ -310,6 +384,7 @@ file '%s')", fname);
     goto err;
 
   mi->inited = 1;
+  mi->rli.is_relay_log_recovery= FALSE;
   // now change cache READ -> WRITE - must do this before flush_master_info
   reinit_io_cache(&mi->file, WRITE_CACHE, 0L, 0, 1);
   if ((error=test(flush_master_info(mi, 1))))
@@ -342,6 +417,7 @@ int flush_master_info(Master_info* mi, bool flush_relay_log_cache)
 {
   IO_CACHE* file = &mi->file;
   char lbuf[22];
+  int err= 0;
 
   DBUG_ENTER("flush_master_info");
   DBUG_PRINT("enter",("master_pos: %ld", (long) mi->master_log_pos));
@@ -358,9 +434,35 @@ int flush_master_info(Master_info* mi, bool flush_relay_log_cache)
     When we come to this place in code, relay log may or not be initialized;
     the caller is responsible for setting 'flush_relay_log_cache' accordingly.
   */
-  if (flush_relay_log_cache &&
-      flush_io_cache(mi->rli.relay_log.get_log_file()))
-    DBUG_RETURN(2);
+  if (flush_relay_log_cache)
+  {
+    IO_CACHE *log_file= mi->rli.relay_log.get_log_file();
+    if (flush_io_cache(log_file))
+      DBUG_RETURN(2);
+  }
+  
+  /*
+    produce a line listing the total number and all the ignored server_id:s
+  */
+  char* ignore_server_ids_buf;
+  {
+    ignore_server_ids_buf=
+      (char *) my_malloc((sizeof(::server_id) * 3 + 1) *
+                         (1 + mi->ignore_server_ids.elements), MYF(MY_WME));
+    if (!ignore_server_ids_buf)
+      DBUG_RETURN(1);
+    for (ulong i= 0, cur_len= my_sprintf(ignore_server_ids_buf,
+                                         (ignore_server_ids_buf, "%u",
+                                          mi->ignore_server_ids.elements));
+         i < mi->ignore_server_ids.elements; i++)
+    {
+      ulong s_id;
+      get_dynamic(&mi->ignore_server_ids, (uchar*) &s_id, i);
+      cur_len +=my_sprintf(ignore_server_ids_buf + cur_len,
+                           (ignore_server_ids_buf + cur_len,
+                            " %lu", s_id));
+    }
+  }
 
   /*
     We flushed the relay log BEFORE the master.info file, because if we crash
@@ -378,17 +480,27 @@ int flush_master_info(Master_info* mi, bool flush_relay_log_cache)
      contents of file). But because of number of lines in the first line
      of file we don't care about this garbage.
   */
-
+  char heartbeat_buf[sizeof(mi->heartbeat_period) * 4]; // buffer to suffice always
+  my_sprintf(heartbeat_buf, (heartbeat_buf, "%.3f", mi->heartbeat_period));
   my_b_seek(file, 0L);
   my_b_printf(file,
-              "%u\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n%s\n%s\n%s\n%s\n%s\n%d\n",
+              "%u\n%s\n%s\n%s\n%s\n%s\n%d\n%d\n%d\n%s\n%s\n%s\n%s\n%s\n%d\n%s\n%s\n",
               LINES_IN_MASTER_INFO,
               mi->master_log_name, llstr(mi->master_log_pos, lbuf),
               mi->host, mi->user,
               mi->password, mi->port, mi->connect_retry,
               (int)(mi->ssl), mi->ssl_ca, mi->ssl_capath, mi->ssl_cert,
-              mi->ssl_cipher, mi->ssl_key, mi->ssl_verify_server_cert);
-  DBUG_RETURN(-flush_io_cache(file));
+              mi->ssl_cipher, mi->ssl_key, mi->ssl_verify_server_cert,
+              heartbeat_buf, ignore_server_ids_buf);
+  my_free(ignore_server_ids_buf, MYF(0));
+  err= flush_io_cache(file);
+  if (sync_masterinfo_period && !err && 
+      ++(mi->sync_counter) >= sync_masterinfo_period)
+  {
+    err= my_sync(mi->fd, MYF(MY_WME));
+    mi->sync_counter= 0;
+  }
+  DBUG_RETURN(-err);
 }
 
 
diff --git a/sql/rpl_mi.h b/sql/rpl_mi.h
index 93fb0a9819839e251d9c92591bf6908b656e579b..f822a6bc1b18525d69b6f07084d5b61f4bbb7d87 100644
--- a/sql/rpl_mi.h
+++ b/sql/rpl_mi.h
@@ -20,6 +20,7 @@
 
 #include "rpl_rli.h"
 #include "rpl_reporting.h"
+#include "my_sys.h"
 
 
 /*****************************************************************************
@@ -58,8 +59,9 @@
 class Master_info : public Slave_reporting_capability
 {
  public:
-  Master_info();
+  Master_info(bool is_slave_recovery);
   ~Master_info();
+  bool shall_ignore_server_id(ulong s_id);
 
   /* the variables below are needed because we can change masters on the fly */
   char master_log_name[FN_REFLEN];
@@ -100,6 +102,16 @@ class Master_info : public Slave_reporting_capability
 
   */
   long clock_diff_with_master;
+  /*
+    Keeps track of the number of events before fsyncing.
+    The option --sync-master-info determines how many
+    events should happen before fsyncing.
+  */
+  uint sync_counter;
+  float heartbeat_period;         // interface with CHANGE MASTER or master.info
+  ulonglong received_heartbeats;  // counter of received heartbeat events
+  DYNAMIC_ARRAY ignore_server_ids;
+  ulong master_id;
 };
 
 void init_master_info_with_options(Master_info* mi);
@@ -109,6 +121,7 @@ int init_master_info(Master_info* mi, const char* master_info_fname,
 		     int thread_mask);
 void end_master_info(Master_info* mi);
 int flush_master_info(Master_info* mi, bool flush_relay_log_cache);
+int change_master_server_id_cmp(ulong *id1, ulong *id2);
 
 #endif /* HAVE_REPLICATION */
 #endif /* RPL_MI_H */
diff --git a/sql/rpl_record.cc b/sql/rpl_record.cc
index 14a80cbb4b6ee3844a2b1cad33b8ae7775d81ced..8e80620dd2cb83ddbe0720911db26fabe0b44d31 100644
--- a/sql/rpl_record.cc
+++ b/sql/rpl_record.cc
@@ -180,7 +180,8 @@ int
 unpack_row(Relay_log_info const *rli,
            TABLE *table, uint const colcnt,
            uchar const *const row_data, MY_BITMAP const *cols,
-           uchar const **const row_end, ulong *const master_reclength)
+           uchar const **const row_end, ulong *const master_reclength,
+           const bool abort_on_warning, const bool first_row)
 {
   DBUG_ENTER("unpack_row");
   DBUG_ASSERT(row_data);
@@ -224,8 +225,35 @@ unpack_row(Relay_log_info const *rli,
       /* Field...::unpack() cannot return 0 */
       DBUG_ASSERT(pack_ptr != NULL);
 
-      if ((null_bits & null_mask) && f->maybe_null())
-        f->set_null();
+      if (null_bits & null_mask)
+      {
+        if (f->maybe_null())
+        {
+          DBUG_PRINT("debug", ("Was NULL; null mask: 0x%x; null bits: 0x%x",
+                               null_mask, null_bits));
+          f->set_null();
+        }
+        else
+        {
+          MYSQL_ERROR::enum_warning_level error_type=
+            MYSQL_ERROR::WARN_LEVEL_NOTE;
+          if (abort_on_warning && (table->file->has_transactions() ||
+                                   first_row))
+          {
+            error = HA_ERR_ROWS_EVENT_APPLY;
+            error_type= MYSQL_ERROR::WARN_LEVEL_ERROR;
+          }
+          else
+          {
+            f->set_default();
+            error_type= MYSQL_ERROR::WARN_LEVEL_WARN;
+          }
+          push_warning_printf(current_thd, error_type,
+                              ER_BAD_NULL_ERROR,
+                              ER(ER_BAD_NULL_ERROR),
+                              f->field_name);
+        }
+      }
       else
       {
         f->set_notnull();
@@ -305,13 +333,17 @@ unpack_row(Relay_log_info const *rli,
   @param table  Table whose record[0] buffer is prepared. 
   @param skip   Number of columns for which default/nullable check 
                 should be skipped.
-  @param check  Indicates if errors should be raised when checking 
-                default/nullable field properties.
+  @param check  Specifies if lack of default error needs checking.
+  @param abort_on_warning
+                Controls how to react on lack of a field's default.
+                The parameter mimics the master side one for
+                @c check_that_all_fields_are_given_values.
                 
   @returns 0 on success or a handler level error code
  */ 
 int prepare_record(TABLE *const table, 
-                   const uint skip, const bool check)
+                   const uint skip, const bool check,
+                   const bool abort_on_warning, const bool first_row)
 {
   DBUG_ENTER("prepare_record");
 
@@ -326,17 +358,37 @@ int prepare_record(TABLE *const table,
   if (skip >= table->s->fields || !check)
     DBUG_RETURN(0);
 
-  /* Checking if exists default/nullable fields in the default values. */
-
-  for (Field **field_ptr= table->field+skip ; *field_ptr ; ++field_ptr)
+  /*
+    For fields the extra fields on the slave, we check if they have a default.
+    The check follows the same rules as the INSERT query without specifying an
+    explicit value for a field not having the explicit default 
+    (@c check_that_all_fields_are_given_values()).
+  */
+  for (Field **field_ptr= table->field+skip; *field_ptr; ++field_ptr)
   {
     uint32 const mask= NOT_NULL_FLAG | NO_DEFAULT_VALUE_FLAG;
     Field *const f= *field_ptr;
-
-    if (((f->flags & mask) == mask))
+    if ((f->flags &  NO_DEFAULT_VALUE_FLAG) &&
+        (f->real_type() != MYSQL_TYPE_ENUM))
     {
-      my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), f->field_name);
-      error = HA_ERR_ROWS_EVENT_APPLY;
+
+      MYSQL_ERROR::enum_warning_level error_type=
+        MYSQL_ERROR::WARN_LEVEL_NOTE;
+      if (abort_on_warning && (table->file->has_transactions() ||
+                               first_row))
+      {
+        error= HA_ERR_ROWS_EVENT_APPLY;
+        error_type= MYSQL_ERROR::WARN_LEVEL_ERROR;
+      }
+      else
+      {
+        f->set_default();
+        error_type= MYSQL_ERROR::WARN_LEVEL_WARN;
+      }
+      push_warning_printf(current_thd, error_type,
+                          ER_NO_DEFAULT_FOR_FIELD,
+                          ER(ER_NO_DEFAULT_FOR_FIELD),
+                          f->field_name);
     }
   }
 
diff --git a/sql/rpl_record.h b/sql/rpl_record.h
index f9e64f0ab1d5b1d2c0fe89e6693a4ef3bdead2d1..6e8838f82b37d63cbe649a6025f464b7ddaed77a 100644
--- a/sql/rpl_record.h
+++ b/sql/rpl_record.h
@@ -27,10 +27,13 @@ size_t pack_row(TABLE* table, MY_BITMAP const* cols,
 int unpack_row(Relay_log_info const *rli,
                TABLE *table, uint const colcnt,
                uchar const *const row_data, MY_BITMAP const *cols,
-               uchar const **const row_end, ulong *const master_reclength);
+               uchar const **const row_end, ulong *const master_reclength,
+               const bool abort_on_warning= TRUE, const bool first_row= TRUE);
 
 // Fill table's record[0] with default values.
-int prepare_record(TABLE *const, const uint =0, const bool =FALSE);
+int prepare_record(TABLE *const table, const uint skip, const bool check,
+                   const bool abort_on_warning= TRUE,
+                   const bool first_row= TRUE);
 #endif
 
 #endif
diff --git a/sql/rpl_rli.cc b/sql/rpl_rli.cc
index 82bd137b5b078e86d2c57765b1888f5fd565c78d..ae3cbf789a53be4be75a21eb625b05996dd86eeb 100644
--- a/sql/rpl_rli.cc
+++ b/sql/rpl_rli.cc
@@ -28,12 +28,13 @@ int init_intvar_from_file(int* var, IO_CACHE* f, int default_val);
 int init_strvar_from_file(char *var, int max_size, IO_CACHE *f,
 			  const char *default_val);
 
-
-Relay_log_info::Relay_log_info()
+Relay_log_info::Relay_log_info(bool is_slave_recovery)
   :Slave_reporting_capability("SQL"),
    no_storage(FALSE), replicate_same_server_id(::replicate_same_server_id),
-   info_fd(-1), cur_log_fd(-1), save_temporary_tables(0),
-   cur_log_old_open_count(0), group_relay_log_pos(0), event_relay_log_pos(0),
+   info_fd(-1), cur_log_fd(-1), relay_log(&sync_relaylog_period),
+   sync_counter(0), is_relay_log_recovery(is_slave_recovery),
+   save_temporary_tables(0), cur_log_old_open_count(0), group_relay_log_pos(0), 
+   event_relay_log_pos(0),
 #if HAVE_purify
    is_fake(FALSE),
 #endif
@@ -258,6 +259,9 @@ Failed to open the existing relay log info file '%s' (errno %d)",
     rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
     rli->group_master_log_pos= master_log_pos;
 
+    if (rli->is_relay_log_recovery && init_recovery(rli->mi, &msg))
+      goto err;
+
     if (init_relay_log_pos(rli,
                            rli->group_relay_log_name,
                            rli->group_relay_log_pos,
@@ -289,7 +293,10 @@ Failed to open the existing relay log info file '%s' (errno %d)",
   */
   reinit_io_cache(&rli->info_file, WRITE_CACHE,0L,0,1);
   if ((error= flush_relay_log_info(rli)))
-    sql_print_error("Failed to flush relay log info file");
+  {
+    msg= "Failed to flush relay log info file";
+    goto err;
+  }
   if (count_relay_log_space(rli))
   {
     msg="Error counting relay log space";
@@ -1188,7 +1195,6 @@ void Relay_log_info::cleanup_context(THD *thd, bool error)
   */
   thd->options&= ~OPTION_NO_FOREIGN_KEY_CHECKS;
   thd->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
-  last_event_start_time= 0;
   DBUG_VOID_RETURN;
 }
 
diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h
index 171778d967551719b05a48c5361798f8dce46ffd..fd36d18adaebde5c1025726be21f22ab6d67e976 100644
--- a/sql/rpl_rli.h
+++ b/sql/rpl_rli.h
@@ -96,6 +96,19 @@ class Relay_log_info : public Slave_reporting_capability
   LOG_INFO linfo;
   IO_CACHE cache_buf,*cur_log;
 
+  /*
+    Keeps track of the number of transactions that commits
+    before fsyncing. The option --sync-relay-log-info determines 
+    how many transactions should commit before fsyncing.
+  */ 
+  uint sync_counter;
+
+  /*
+    Identifies when the recovery process is going on.
+    See sql/slave.cc:init_recovery for further details.
+  */ 
+  bool is_relay_log_recovery;
+
   /* The following variables are safe to read any time */
 
   /* IO_CACHE of the info file - set only during init or end */
@@ -267,7 +280,7 @@ class Relay_log_info : public Slave_reporting_capability
   char slave_patternload_file[FN_REFLEN]; 
   size_t slave_patternload_file_size;  
 
-  Relay_log_info();
+  Relay_log_info(bool is_slave_recovery);
   ~Relay_log_info();
 
   /*
@@ -336,12 +349,10 @@ class Relay_log_info : public Slave_reporting_capability
   void clear_tables_to_lock();
 
   /*
-    Used by row-based replication to detect that it should not stop at
-    this event, but give it a chance to send more events. The time
-    where the last event inside a group started is stored here. If the
-    variable is zero, we are not in a group (but may be in a
-    transaction).
-   */
+    Used to defer stopping the SQL thread to give it a chance
+    to finish up the current group of events.
+    The timestamp is set and reset in @c sql_slave_killed().
+  */
   time_t last_event_start_time;
 
   /**
diff --git a/sql/scheduler.h b/sql/scheduler.h
index 46bbd300cbb6ca1c426d8e3eba70a1323925caf3..e7916031a274ef8c5787dfb1e90ed387d1b5e57b 100644
--- a/sql/scheduler.h
+++ b/sql/scheduler.h
@@ -1,3 +1,6 @@
+#ifndef SCHEDULER_INCLUDED
+#define SCHEDULER_INCLUDED
+
 /* Copyright (C) 2007 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -58,3 +61,5 @@ enum pool_command_op
 
 class thd_scheduler
 {};
+
+#endif /* SCHEDULER_INCLUDED */
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 8f246caa7581b695e8b60ceefbf5d6c7bf412940..29ed552bfb099e18dab175f9a5978cee22e0c313 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -1546,6 +1546,23 @@ static bool get_unsigned(THD *thd, set_var *var, ulonglong user_max,
 }
 
 
+bool sys_var_uint_ptr::check(THD *thd, set_var *var)
+{
+  var->save_result.ulong_value= (ulong) var->value->val_uint();
+  return 0;
+}
+
+bool sys_var_uint_ptr::update(THD *thd, set_var *var)
+{
+  *value= (uint) var->save_result.ulong_value;
+  return 0;
+}
+
+void sys_var_uint_ptr::set_default(THD *thd, enum_var_type type)
+{
+  *value= (uint) option_limits->def_value;
+}
+
 sys_var_long_ptr::
 sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
                  sys_after_update_func after_update_arg)
@@ -3135,6 +3152,15 @@ static bool set_option_autocommit(THD *thd, set_var *var)
 
   ulonglong org_options= thd->options;
 
+  /*
+    If we are setting AUTOCOMMIT=1 and it was not already 1, then we
+    need to commit any outstanding transactions.
+   */
+  if (var->save_result.ulong_value != 0 &&
+      (thd->options & OPTION_NOT_AUTOCOMMIT) &&
+      ha_commit(thd))
+    return 1;
+
   if (var->save_result.ulong_value != 0)
     thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
   else
@@ -3148,8 +3174,6 @@ static bool set_option_autocommit(THD *thd, set_var *var)
       thd->options&= ~(ulonglong) (OPTION_BEGIN | OPTION_KEEP_LOG);
       thd->transaction.all.modified_non_trans_table= FALSE;
       thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
-      if (ha_commit(thd))
-	return 1;
     }
     else
     {
diff --git a/sql/set_var.h b/sql/set_var.h
index d52679550ab8cd2a6887caf06ac513b4a437d56d..a83de6425aeadbfd19dbf3da8887c8238293ad49 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -1,3 +1,6 @@
+#ifndef SET_VAR_INCLUDED
+#define SET_VAR_INCLUDED
+
 /* Copyright (C) 2002-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -172,6 +175,27 @@ class sys_var_long_ptr_global: public sys_var_global
   { return (uchar*) value; }
 };
 
+/**
+   Unsigned int system variable class
+ */
+class sys_var_uint_ptr :public sys_var
+{
+public:
+  sys_var_uint_ptr(sys_var_chain *chain, const char *name_arg, 
+                  uint *value_ptr_arg,
+                  sys_after_update_func after_update_arg= NULL)
+    :sys_var(name_arg, after_update_arg),
+     value(value_ptr_arg)
+  { chain_sys_var(chain); }
+  bool check(THD *thd, set_var *var);
+  bool update(THD *thd, set_var *var);
+  void set_default(THD *thd, enum_var_type type);
+  SHOW_TYPE show_type() { return SHOW_INT; }
+  uchar *value_ptr(THD *thd, enum_var_type type, LEX_STRING *base)
+  { return (uchar*) value; }
+private:
+  uint *value;
+};
 
 /*
   A global ulong variable that is protected by LOCK_global_system_variables
@@ -1490,3 +1514,5 @@ void free_key_cache(const char *name, KEY_CACHE *key_cache);
 bool process_key_caches(process_key_cache_t func);
 void delete_elements(I_List<NAMED_LIST> *list,
 		     void (*free_element)(const char*, uchar*));
+
+#endif /* SET_VAR_INCLUDED */
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 62f49250a1ac12e7e1a3cb13abf4124d56951541..2b2d60c0657ffde7546b14b2692dfc2de7b73df6 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -4620,7 +4620,7 @@ ER_USER_LIMIT_REACHED 42000
         swe "Användare '%-.64s' har överskridit '%s' (nuvarande värde: %ld)"
 ER_SPECIFIC_ACCESS_DENIED_ERROR 42000 
         nla "Toegang geweigerd. U moet het %-.128s privilege hebben voor deze operatie"
-        eng "Access denied; you need the %-.128s privilege for this operation"
+        eng "Access denied; you need (at least one of) the %-.128s privilege(s) for this operation"
         ger "Kein Zugriff. Hierfür wird die Berechtigung %-.128s benötigt"
         ita "Accesso non consentito. Serve il privilegio %-.128s per questa operazione"
         por "Acesso negado. Você precisa o privilégio %-.128s para essa operação"
@@ -6237,3 +6237,7 @@ ER_COND_ITEM_TOO_LONG
 
 ER_UNKNOWN_LOCALE                                                                                                                                                                    
         eng "Unknown locale: '%-.64s'"
+
+ER_SLAVE_IGNORE_SERVER_IDS
+  eng "The requested server id %d clashes with the slave startup option --replicate-same-server-id"
+
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index bec7536b5d1a0c2cf06ba871fdae1d07064a6f09..317087854c148d3c0376cdc5e914a8e42a13012f 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -4620,7 +4620,7 @@ ER_USER_LIMIT_REACHED 42000
         swe "Användare '%-.64s' har överskridit '%s' (nuvarande värde: %ld)"
 ER_SPECIFIC_ACCESS_DENIED_ERROR 42000 
         nla "Toegang geweigerd. U moet het %-.128s privilege hebben voor deze operatie"
-        eng "Access denied; you need the %-.128s privilege for this operation"
+        eng "Access denied; you need (at least one of) the %-.128s privilege(s) for this operation"
         ger "Kein Zugriff. Hierfür wird die Berechtigung %-.128s benötigt"
         ita "Accesso non consentito. Serve il privilegio %-.128s per questa operazione"
         por "Acesso negado. Você precisa o privilégio %-.128s para essa operação"
@@ -6237,3 +6237,7 @@ ER_COND_ITEM_TOO_LONG
 
 ER_UNKNOWN_LOCALE                                                                                                                                                                    
         eng "Unknown locale: '%-.64s'"
+
+ER_SLAVE_IGNORE_SERVER_IDS
+  eng "The requested server id %d clashes with the slave startup option --replicate-same-server-id"
+
diff --git a/sql/slave.cc b/sql/slave.cc
index 50742817f094c593e7453bf1811f65682cb3ce5d..8c82dcaabe097079ab161aae9c9526054d246963 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -40,6 +40,7 @@
 #include <errmsg.h>
 #include <mysqld_error.h>
 #include <mysys_err.h>
+#include "rpl_handler.h"
 
 #ifdef HAVE_REPLICATION
 
@@ -48,6 +49,10 @@
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
 
 #define MAX_SLAVE_RETRY_PAUSE 5
+/*
+  a parameter of sql_slave_killed() to defer the killed status
+*/
+#define SLAVE_WAIT_GROUP_DONE 60
 bool use_slave_mask = 0;
 MY_BITMAP slave_error_mask;
 char slave_skip_error_names[SHOW_VAR_FUNC_BUFF_SIZE];
@@ -69,6 +74,8 @@ ulonglong relay_log_space_limit = 0;
 int disconnect_slave_event_count = 0, abort_slave_event_count = 0;
 int events_till_abort = -1;
 
+static pthread_key(Master_info*, RPL_MASTER_INFO);
+
 enum enum_slave_reconnect_actions
 {
   SLAVE_RECON_ACT_REG= 0,
@@ -220,6 +227,7 @@ void unlock_slave_threads(Master_info* mi)
 int init_slave()
 {
   DBUG_ENTER("init_slave");
+  int error= 0;
 
   /*
     This is called when mysqld starts. Before client connections are
@@ -231,7 +239,10 @@ int init_slave()
     TODO: re-write this to interate through the list of files
     for multi-master
   */
-  active_mi= new Master_info;
+  active_mi= new Master_info(relay_log_recovery);
+
+  if (pthread_key_create(&RPL_MASTER_INFO, NULL))
+    goto err;
 
   /*
     If --slave-skip-errors=... was not used, the string value for the
@@ -250,6 +261,7 @@ int init_slave()
   if (!active_mi)
   {
     sql_print_error("Failed to allocate memory for the master info structure");
+    error= 1;
     goto err;
   }
 
@@ -257,6 +269,7 @@ int init_slave()
                        !master_host, (SLAVE_IO | SLAVE_SQL)))
   {
     sql_print_error("Failed to initialize the master info structure");
+    error= 1;
     goto err;
   }
 
@@ -275,18 +288,69 @@ int init_slave()
                             SLAVE_IO | SLAVE_SQL))
     {
       sql_print_error("Failed to create slave threads");
+      error= 1;
       goto err;
     }
   }
-  pthread_mutex_unlock(&LOCK_active_mi);
-  DBUG_RETURN(0);
 
 err:
   pthread_mutex_unlock(&LOCK_active_mi);
-  DBUG_RETURN(1);
+  DBUG_RETURN(error);
 }
 
+/*
+  Updates the master info based on the information stored in the
+  relay info and ignores relay logs previously retrieved by the IO 
+  thread, which thus starts fetching again based on to the  
+  group_master_log_pos and group_master_log_name. Eventually, the old
+  relay logs will be purged by the normal purge mechanism.
+
+  In the feature, we should improve this routine in order to avoid throwing
+  away logs that are safely stored in the disk. Note also that this recovery 
+  routine relies on the correctness of the relay-log.info and only tolerates 
+  coordinate problems in master.info.
+  
+  In this function, there is no need for a mutex as the caller 
+  (i.e. init_slave) already has one acquired.
+  
+  Specifically, the following structures are updated:
+ 
+  1 - mi->master_log_pos  <-- rli->group_master_log_pos
+  2 - mi->master_log_name <-- rli->group_master_log_name
+  3 - It moves the relay log to the new relay log file, by
+      rli->group_relay_log_pos  <-- BIN_LOG_HEADER_SIZE;
+      rli->event_relay_log_pos  <-- BIN_LOG_HEADER_SIZE;
+      rli->group_relay_log_name <-- rli->relay_log.get_log_fname();
+      rli->event_relay_log_name <-- rli->relay_log.get_log_fname();
+  
+   If there is an error, it returns (1), otherwise returns (0).
+ */
+int init_recovery(Master_info* mi, const char** errmsg)
+{
+  DBUG_ENTER("init_recovery");
+ 
+  Relay_log_info *rli= &mi->rli;
+  if (rli->group_master_log_name[0])
+  {
+    mi->master_log_pos= max(BIN_LOG_HEADER_SIZE,
+                             rli->group_master_log_pos);
+    strmake(mi->master_log_name, rli->group_master_log_name,
+            sizeof(mi->master_log_name)-1);
+ 
+    sql_print_warning("Recovery from master pos %ld and file %s.",
+                      (ulong) mi->master_log_pos, mi->master_log_name);
+ 
+    strmake(rli->group_relay_log_name, rli->relay_log.get_log_fname(),
+            sizeof(rli->group_relay_log_name)-1);
+    strmake(rli->event_relay_log_name, rli->relay_log.get_log_fname(),
+            sizeof(mi->rli.event_relay_log_name)-1);
+ 
+    rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
+  }
 
+  DBUG_RETURN(0);
+}
+ 
 /**
   Convert slave skip errors bitmap into a printable string.
 */
@@ -730,44 +794,92 @@ static bool io_slave_killed(THD* thd, Master_info* mi)
   DBUG_RETURN(mi->abort_slave || abort_loop || thd->killed);
 }
 
+/**
+   The function analyzes a possible killed status and makes
+   a decision whether to accept it or not.
+   Normally upon accepting the sql thread goes to shutdown.
+   In the event of deffering decision @rli->last_event_start_time waiting
+   timer is set to force the killed status be accepted upon its expiration.
+
+   @param thd   pointer to a THD instance
+   @param rli   pointer to Relay_log_info instance
 
+   @return TRUE the killed status is recognized, FALSE a possible killed
+           status is deferred.
+*/
 static bool sql_slave_killed(THD* thd, Relay_log_info* rli)
 {
+  bool ret= FALSE;
   DBUG_ENTER("sql_slave_killed");
 
   DBUG_ASSERT(rli->sql_thd == thd);
   DBUG_ASSERT(rli->slave_running == 1);// tracking buffer overrun
   if (abort_loop || thd->killed || rli->abort_slave)
   {
-    if (rli->abort_slave && rli->is_in_group() &&
-        thd->transaction.all.modified_non_trans_table)
-      DBUG_RETURN(0);
-    /*
-      If we are in an unsafe situation (stopping could corrupt replication),
-      we give one minute to the slave SQL thread of grace before really
-      terminating, in the hope that it will be able to read more events and
-      the unsafe situation will soon be left. Note that this one minute starts
-      from the last time anything happened in the slave SQL thread. So it's
-      really one minute of idleness, we don't timeout if the slave SQL thread
-      is actively working.
-    */
-    if (rli->last_event_start_time == 0)
-      DBUG_RETURN(1);
-    DBUG_PRINT("info", ("Slave SQL thread is in an unsafe situation, giving "
-                        "it some grace period"));
-    if (difftime(time(0), rli->last_event_start_time) > 60)
+    if (thd->transaction.all.modified_non_trans_table && rli->is_in_group())
     {
-      rli->report(ERROR_LEVEL, 0,
-                  "SQL thread had to stop in an unsafe situation, in "
-                  "the middle of applying updates to a "
-                  "non-transactional table without any primary key. "
-                  "There is a risk of duplicate updates when the slave "
-                  "SQL thread is restarted. Please check your tables' "
-                  "contents after restart.");
-      DBUG_RETURN(1);
+      char msg_stopped[]=
+        "... The slave SQL is stopped, leaving the current group "
+        "of events unfinished with a non-transaction table changed. "
+        "If the group consists solely of Row-based events, you can try "
+        "restarting the slave with --slave-exec-mode=IDEMPOTENT, which "
+        "ignores duplicate key, key not found, and similar errors (see "
+        "documentation for details).";
+
+      if (rli->abort_slave)
+      {
+        DBUG_PRINT("info", ("Slave SQL thread is being stopped in the middle of"
+                            " a group having updated a non-trans table, giving"
+                            " it some grace period"));
+
+        /*
+          Slave sql thread shutdown in face of unfinished group modified 
+          Non-trans table is handled via a timer. The slave may eventually
+          give out to complete the current group and in that case there
+          might be issues at consequent slave restart, see the error message.
+          WL#2975 offers a robust solution requiring to store the last exectuted
+          event's coordinates along with the group's coordianates
+          instead of waiting with @c last_event_start_time the timer.
+        */
+
+        if (rli->last_event_start_time == 0)
+          rli->last_event_start_time= my_time(0);
+        ret= difftime(my_time(0), rli->last_event_start_time) <=
+          SLAVE_WAIT_GROUP_DONE ? FALSE : TRUE;
+
+        DBUG_EXECUTE_IF("stop_slave_middle_group", 
+                        DBUG_EXECUTE_IF("incomplete_group_in_relay_log",
+                                        ret= TRUE;);); // time is over
+
+        if (ret == 0)
+        {
+          rli->report(WARNING_LEVEL, 0,
+                      "slave SQL thread is being stopped in the middle "
+                      "of applying of a group having updated a non-transaction "
+                      "table; waiting for the group completion ... ");
+        }
+        else
+        {
+          rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+                      ER(ER_SLAVE_FATAL_ERROR), msg_stopped);
+        }
+      }
+      else
+      {
+        ret= TRUE;
+        rli->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, ER(ER_SLAVE_FATAL_ERROR),
+                    msg_stopped);
+      }
+    }
+    else
+    {
+      ret= TRUE;
     }
   }
-  DBUG_RETURN(0);
+  if (ret)
+    rli->last_event_start_time= 0;
+  
+  DBUG_RETURN(ret);
 }
 
 
@@ -860,6 +972,126 @@ int init_intvar_from_file(int* var, IO_CACHE* f, int default_val)
   DBUG_RETURN(1);
 }
 
+int init_floatvar_from_file(float* var, IO_CACHE* f, float default_val)
+{
+  char buf[16];
+  DBUG_ENTER("init_floatvar_from_file");
+
+
+  if (my_b_gets(f, buf, sizeof(buf)))
+  {
+    if (sscanf(buf, "%f", var) != 1)
+      DBUG_RETURN(1);
+    else
+      DBUG_RETURN(0);
+  }
+  else if (default_val != 0.0)
+  {
+    *var = default_val;
+    DBUG_RETURN(0);
+  }
+  DBUG_RETURN(1);
+}
+
+
+/**
+   A master info read method
+
+   This function is called from @c init_master_info() along with
+   relatives to restore some of @c active_mi members.
+   Particularly, this function is responsible for restoring
+   IGNORE_SERVER_IDS list of servers whose events the slave is
+   going to ignore (to not log them in the relay log).
+   Items being read are supposed to be decimal output of values of a
+   type shorter or equal of @c long and separated by the single space.
+
+   @param arr         @c DYNAMIC_ARRAY pointer to storage for servers id
+   @param f           @c IO_CACHE pointer to the source file
+
+   @retval 0         All OK
+   @retval non-zero  An error
+*/
+
+int init_dynarray_intvar_from_file(DYNAMIC_ARRAY* arr, IO_CACHE* f)
+{
+  int ret= 0;
+  char buf[16 * (sizeof(long)*4 + 1)]; // static buffer to use most of times
+  char *buf_act= buf; // actual buffer can be dynamic if static is short
+  char *token, *last;
+  uint num_items;     // number of items of `arr'
+  size_t read_size;
+  DBUG_ENTER("init_dynarray_intvar_from_file");
+
+  if ((read_size= my_b_gets(f, buf_act, sizeof(buf))) == 0)
+  {
+    return 0; // no line in master.info
+  }
+  if (read_size + 1 == sizeof(buf) && buf[sizeof(buf) - 2] != '\n')
+  {
+    /*
+      short read happend; allocate sufficient memory and make the 2nd read
+    */
+    char buf_work[(sizeof(long)*3 + 1)*16];
+    memcpy(buf_work, buf, sizeof(buf_work));
+    num_items= atoi(strtok_r(buf_work, " ", &last));
+    size_t snd_size;
+    /*
+      max size lower bound approximate estimation bases on the formula:
+      (the items number + items themselves) * 
+          (decimal size + space) - 1 + `\n' + '\0'
+    */
+    size_t max_size= (1 + num_items) * (sizeof(long)*3 + 1) + 1;
+    buf_act= (char*) my_malloc(max_size, MYF(MY_WME));
+    memcpy(buf_act, buf, read_size);
+    snd_size= my_b_gets(f, buf_act + read_size, max_size - read_size);
+    if (snd_size == 0 ||
+        (snd_size + 1 == max_size - read_size) &&  buf[max_size - 2] != '\n')
+    {
+      /*
+        failure to make the 2nd read or short read again
+      */
+      ret= 1;
+      goto err;
+    }
+  }
+  token= strtok_r(buf_act, " ", &last);
+  if (token == NULL)
+  {
+    ret= 1;
+    goto err;
+  }
+  num_items= atoi(token);
+  for (uint i=0; i < num_items; i++)
+  {
+    token= strtok_r(NULL, " ", &last);
+    if (token == NULL)
+    {
+      ret= 1;
+      goto err;
+    }
+    else
+    {
+      ulong val= atol(token);
+      insert_dynamic(arr, (uchar *) &val);
+    }
+  }
+err:
+  if (buf_act != buf)
+    my_free(buf_act, MYF(0));
+  DBUG_RETURN(ret);
+}
+
+
+static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info)
+{
+  if (io_slave_killed(thd, mi))
+  {
+    if (info && global_system_variables.log_warnings)
+      sql_print_information(info);
+    return TRUE;
+  }
+  return FALSE;
+}
 
 /*
   Check if the error is caused by network.
@@ -1028,7 +1260,7 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi)
       (master_res= mysql_store_result(mysql)) &&
       (master_row= mysql_fetch_row(master_res)))
   {
-    if ((::server_id == strtoul(master_row[1], 0, 10)) &&
+    if ((::server_id == (mi->master_id= strtoul(master_row[1], 0, 10))) &&
         !mi->rli.replicate_same_server_id)
     {
       errmsg= "The slave I/O thread stops because master and slave have equal \
@@ -1066,6 +1298,13 @@ maybe it is a *VERY OLD MASTER*.");
     mysql_free_result(master_res);
     master_res= NULL;
   }
+  if (mi->master_id == 0 && mi->ignore_server_ids.elements > 0)
+  {
+    errmsg= "Slave configured with server id filtering could not detect the master server id.";
+    err_code= ER_SLAVE_FATAL_ERROR;
+    sprintf(err_buff, ER(err_code), errmsg);
+    goto err;
+  }
 
   /*
     Check that the master's global character_set_server and ours are the same.
@@ -1189,6 +1428,31 @@ when it try to get the value of TIME_ZONE global variable from master.";
     }
   }
 
+  if (mi->heartbeat_period != 0.0)
+  {
+    char llbuf[22];
+    const char query_format[]= "SET @master_heartbeat_period= %s";
+    char query[sizeof(query_format) - 2 + sizeof(llbuf)];
+    /* 
+       the period is an ulonglong of nano-secs. 
+    */
+    llstr((ulonglong) (mi->heartbeat_period*1000000000UL), llbuf);
+    my_sprintf(query, (query, query_format, llbuf));
+
+    if (mysql_real_query(mysql, query, strlen(query))
+        && !check_io_slave_killed(mi->io_thd, mi, NULL))
+    {
+      errmsg= "The slave I/O thread stops because SET @master_heartbeat_period "
+        "on master failed.";
+      err_code= ER_SLAVE_FATAL_ERROR;
+      sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql));
+      mysql_free_result(mysql_store_result(mysql));
+      goto err;
+    }
+    mysql_free_result(mysql_store_result(mysql));
+  }
+ 
+
 err:
   if (errmsg)
   {
@@ -1604,6 +1868,10 @@ bool show_master_info(THD* thd, Master_info* mi)
   field_list.push_back(new Item_empty_string("Last_IO_Error", 20));
   field_list.push_back(new Item_return_int("Last_SQL_Errno", 4, MYSQL_TYPE_LONG));
   field_list.push_back(new Item_empty_string("Last_SQL_Error", 20));
+  field_list.push_back(new Item_empty_string("Replicate_Ignore_Server_Ids",
+                                             FN_REFLEN));
+  field_list.push_back(new Item_return_int("Master_Server_Id", sizeof(ulong),
+                                           MYSQL_TYPE_LONG));
 
   if (protocol->send_fields(&field_list,
                             Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
@@ -1639,7 +1907,8 @@ bool show_master_info(THD* thd, Master_info* mi)
     protocol->store((ulonglong) mi->rli.group_relay_log_pos);
     protocol->store(mi->rli.group_master_log_name, &my_charset_bin);
     protocol->store(mi->slave_running == MYSQL_SLAVE_RUN_CONNECT ?
-                    "Yes" : "No", &my_charset_bin);
+                    "Yes" : (mi->slave_running == MYSQL_SLAVE_RUN_NOT_CONNECT ?
+                             "Connecting" : "No"), &my_charset_bin);
     protocol->store(mi->rli.slave_running ? "Yes":"No", &my_charset_bin);
     protocol->store(rpl_filter->get_do_db());
     protocol->store(rpl_filter->get_ignore_db());
@@ -1725,6 +1994,32 @@ bool show_master_info(THD* thd, Master_info* mi)
     protocol->store(mi->rli.last_error().number);
     // Last_SQL_Error
     protocol->store(mi->rli.last_error().message, &my_charset_bin);
+    // Replicate_Ignore_Server_Ids
+    {
+      char buff[FN_REFLEN];
+      ulong i, cur_len;
+      for (i= 0, buff[0]= 0, cur_len= 0;
+           i < mi->ignore_server_ids.elements; i++)
+      {
+        ulong s_id, slen;
+        char sbuff[FN_REFLEN];
+        get_dynamic(&mi->ignore_server_ids, (uchar*) &s_id, i);
+        slen= my_sprintf(sbuff, (sbuff, (i==0? "%lu" : ", %lu"), s_id));
+        if (cur_len + slen + 4 > FN_REFLEN)
+        {
+          /*
+            break the loop whenever remained space could not fit
+            ellipses on the next cycle
+          */
+          my_sprintf(buff + cur_len, (buff + cur_len, "..."));
+          break;
+        }
+        cur_len += my_sprintf(buff + cur_len, (buff + cur_len, "%s", sbuff));
+      }
+      protocol->store(buff, &my_charset_bin);
+    }
+    // Master_Server_id
+    protocol->store((uint32) mi->master_id);
 
     pthread_mutex_unlock(&mi->rli.err_lock);
     pthread_mutex_unlock(&mi->err_lock);
@@ -1868,17 +2163,22 @@ static int safe_sleep(THD* thd, int sec, CHECK_KILLED_FUNC thread_killed,
 }
 
 
-static int request_dump(MYSQL* mysql, Master_info* mi,
-                        bool *suppress_warnings)
+static int request_dump(THD *thd, MYSQL* mysql, Master_info* mi,
+			bool *suppress_warnings)
 {
   uchar buf[FN_REFLEN + 10];
   int len;
-  int binlog_flags = 0; // for now
+  ushort binlog_flags = 0; // for now
   char* logname = mi->master_log_name;
   DBUG_ENTER("request_dump");
   
   *suppress_warnings= FALSE;
 
+  if (RUN_HOOK(binlog_relay_io,
+               before_request_transmit,
+               (thd, mi, binlog_flags)))
+    DBUG_RETURN(1);
+  
   // TODO if big log files: Change next to int8store()
   int4store(buf, (ulong) mi->master_log_pos);
   int2store(buf + 4, binlog_flags);
@@ -2274,6 +2574,27 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli)
       delete ev;
       DBUG_RETURN(1);
     }
+
+    { /**
+         The following failure injecion works in cooperation with tests 
+         setting @@global.debug= 'd,incomplete_group_in_relay_log'.
+         Xid or Commit events are not executed to force the slave sql
+         read hanging if the realy log does not have any more events.
+      */
+      DBUG_EXECUTE_IF("incomplete_group_in_relay_log",
+                      if ((ev->get_type_code() == XID_EVENT) ||
+                          ((ev->get_type_code() == QUERY_EVENT) &&
+                           strcmp("COMMIT", ((Query_log_event *) ev)->query) == 0))
+                      {
+                        DBUG_ASSERT(thd->transaction.all.modified_non_trans_table);
+                        rli->abort_slave= 1;
+                        pthread_mutex_unlock(&rli->data_lock);
+                        delete ev;
+                        rli->inc_event_relay_log_pos();
+                        DBUG_RETURN(0);
+                      };);
+    }
+
     exec_res= apply_event_and_update_pos(ev, thd, rli);
 
     /*
@@ -2377,18 +2698,6 @@ on this slave.\
 }
 
 
-static bool check_io_slave_killed(THD *thd, Master_info *mi, const char *info)
-{
-  if (io_slave_killed(thd, mi))
-  {
-    if (info && global_system_variables.log_warnings)
-      sql_print_information("%s", info);
-    return TRUE;
-  }
-  return FALSE;
-}
-
-
 /**
   @brief Try to reconnect slave IO thread.
 
@@ -2528,6 +2837,16 @@ pthread_handler_t handle_slave_io(void *arg)
                             mi->master_log_name,
                             llstr(mi->master_log_pos,llbuff)));
 
+  /* This must be called before run any binlog_relay_io hooks */
+  my_pthread_setspecific_ptr(RPL_MASTER_INFO, mi);
+
+  if (RUN_HOOK(binlog_relay_io, thread_start, (thd, mi)))
+  {
+    mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+               ER(ER_SLAVE_FATAL_ERROR), "Failed to run 'thread_start' hook");
+    goto err;
+  }
+
   if (!(mi->mysql = mysql = mysql_init(NULL)))
   {
     mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
@@ -2617,7 +2936,7 @@ pthread_handler_t handle_slave_io(void *arg)
   while (!io_slave_killed(thd,mi))
   {
     thd_proc_info(thd, "Requesting binlog dump");
-    if (request_dump(mysql, mi, &suppress_warnings))
+    if (request_dump(thd, mysql, mi, &suppress_warnings))
     {
       sql_print_error("Failed on request_dump()");
       if (check_io_slave_killed(thd, mi, "Slave I/O thread killed while \
@@ -2637,6 +2956,7 @@ requesting master dump") ||
           goto err;
         goto connected;
       });
+    const char *event_buf;
 
     DBUG_ASSERT(mi->last_error().number == 0);
     while (!io_slave_killed(thd,mi))
@@ -2697,14 +3017,37 @@ Stopping slave I/O thread due to out-of-memory error from master");
 
       retry_count=0;                    // ok event, reset retry counter
       thd_proc_info(thd, "Queueing master event to the relay log");
-      if (queue_event(mi,(const char*)mysql->net.read_pos + 1,
-                      event_len))
+      event_buf= (const char*)mysql->net.read_pos + 1;
+      if (RUN_HOOK(binlog_relay_io, after_read_event,
+                   (thd, mi,(const char*)mysql->net.read_pos + 1,
+                    event_len, &event_buf, &event_len)))
+      {
+        mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+                   ER(ER_SLAVE_FATAL_ERROR),
+                   "Failed to run 'after_read_event' hook");
+        goto err;
+      }
+
+      /* XXX: 'synced' should be updated by queue_event to indicate
+         whether event has been synced to disk */
+      bool synced= 0;
+      if (queue_event(mi, event_buf, event_len))
       {
         mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE,
                    ER(ER_SLAVE_RELAY_LOG_WRITE_FAILURE),
                    "could not queue event from master");
         goto err;
       }
+
+      if (RUN_HOOK(binlog_relay_io, after_queue_event,
+                   (thd, mi, event_buf, event_len, synced)))
+      {
+        mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR,
+                   ER(ER_SLAVE_FATAL_ERROR),
+                   "Failed to run 'after_queue_event' hook");
+        goto err;
+      }
+
       if (flush_master_info(mi, 1))
       {
         sql_print_error("Failed to flush master info file");
@@ -2750,6 +3093,7 @@ log space");
   // print the current replication position
   sql_print_information("Slave I/O thread exiting, read up to log '%s', position %s",
                   IO_RPL_LOG_NAME, llstr(mi->master_log_pos,llbuff));
+  RUN_HOOK(binlog_relay_io, thread_stop, (thd, mi));
   thd->set_query(NULL, 0);
   thd->reset_db(NULL, 0);
   if (mysql)
@@ -3555,9 +3899,11 @@ static int queue_old_event(Master_info *mi, const char *buf,
 static int queue_event(Master_info* mi,const char* buf, ulong event_len)
 {
   int error= 0;
+  String error_msg;
   ulong inc_pos;
   Relay_log_info *rli= &mi->rli;
   pthread_mutex_t *log_lock= rli->relay_log.get_log_lock();
+  ulong s_id;
   DBUG_ENTER("queue_event");
 
   LINT_INIT(inc_pos);
@@ -3589,7 +3935,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
     Rotate_log_event rev(buf,event_len,mi->rli.relay_log.description_event_for_queue);
     if (unlikely(process_io_rotate(mi,&rev)))
     {
-      error= 1;
+      error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE;
       goto err;
     }
     /*
@@ -3616,7 +3962,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
           Log_event::read_log_event(buf, event_len, &errmsg,
                                     mi->rli.relay_log.description_event_for_queue)))
     {
-      error= 2;
+      error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE;
       goto err;
     }
     delete mi->rli.relay_log.description_event_for_queue;
@@ -3635,6 +3981,56 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
 
   }
   break;
+
+  case HEARTBEAT_LOG_EVENT:
+  {
+    /*
+      HB (heartbeat) cannot come before RL (Relay)
+    */
+    char  llbuf[22];
+    Heartbeat_log_event hb(buf, event_len, mi->rli.relay_log.description_event_for_queue);
+    if (!hb.is_valid())
+    {
+      error= ER_SLAVE_HEARTBEAT_FAILURE;
+      error_msg.append(STRING_WITH_LEN("inconsistent heartbeat event content;"));
+      error_msg.append(STRING_WITH_LEN("the event's data: log_file_name "));
+      error_msg.append(hb.get_log_ident(), (uint) strlen(hb.get_log_ident()));
+      error_msg.append(STRING_WITH_LEN(" log_pos "));
+      llstr(hb.log_pos, llbuf);
+      error_msg.append(llbuf, strlen(llbuf));
+      goto err;
+    }
+    mi->received_heartbeats++;
+    /* 
+       compare local and event's versions of log_file, log_pos.
+       
+       Heartbeat is sent only after an event corresponding to the corrdinates
+       the heartbeat carries.
+       Slave can not have a difference in coordinates except in the only
+       special case when mi->master_log_name, master_log_pos have never
+       been updated by Rotate event i.e when slave does not have any history
+       with the master (and thereafter mi->master_log_pos is NULL).
+
+       TODO: handling `when' for SHOW SLAVE STATUS' snds behind
+    */
+    if ((memcmp(mi->master_log_name, hb.get_log_ident(), hb.get_ident_len())
+         && mi->master_log_name != NULL)
+        || mi->master_log_pos != hb.log_pos)
+    {
+      /* missed events of heartbeat from the past */
+      error= ER_SLAVE_HEARTBEAT_FAILURE;
+      error_msg.append(STRING_WITH_LEN("heartbeat is not compatible with local info;"));
+      error_msg.append(STRING_WITH_LEN("the event's data: log_file_name "));
+      error_msg.append(hb.get_log_ident(), (uint) strlen(hb.get_log_ident()));
+      error_msg.append(STRING_WITH_LEN(" log_pos "));
+      llstr(hb.log_pos, llbuf);
+      error_msg.append(llbuf, strlen(llbuf));
+      goto err;
+    }
+    goto skip_relay_logging;
+  }
+  break;
+
   default:
     inc_pos= event_len;
     break;
@@ -3654,9 +4050,20 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
   */
 
   pthread_mutex_lock(log_lock);
-
-  if ((uint4korr(buf + SERVER_ID_OFFSET) == ::server_id) &&
-      !mi->rli.replicate_same_server_id)
+  s_id= uint4korr(buf + SERVER_ID_OFFSET);
+  if ((s_id == ::server_id && !mi->rli.replicate_same_server_id) ||
+      /*
+        the following conjunction deals with IGNORE_SERVER_IDS, if set
+        If the master is on the ignore list, execution of
+        format description log events and rotate events is necessary.
+      */
+      (mi->ignore_server_ids.elements > 0 &&
+       mi->shall_ignore_server_id(s_id) &&
+       /* everything is filtered out from non-master */
+       (s_id != mi->master_id ||
+        /* for the master meta information is necessary */
+        buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT &&
+        buf[EVENT_TYPE_OFFSET] != ROTATE_EVENT)))
   {
     /*
       Do not write it to the relay log.
@@ -3671,10 +4078,14 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
       But events which were generated by this slave and which do not exist in
       the master's binlog (i.e. Format_desc, Rotate & Stop) should not increment
       mi->master_log_pos.
+      If the event is originated remotely and is being filtered out by
+      IGNORE_SERVER_IDS it increments mi->master_log_pos
+      as well as rli->group_relay_log_pos.
     */
-    if (buf[EVENT_TYPE_OFFSET]!=FORMAT_DESCRIPTION_EVENT &&
-        buf[EVENT_TYPE_OFFSET]!=ROTATE_EVENT &&
-        buf[EVENT_TYPE_OFFSET]!=STOP_EVENT)
+    if (!(s_id == ::server_id && !mi->rli.replicate_same_server_id) ||
+        buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT &&
+        buf[EVENT_TYPE_OFFSET] != ROTATE_EVENT &&
+        buf[EVENT_TYPE_OFFSET] != STOP_EVENT)
     {
       mi->master_log_pos+= inc_pos;
       memcpy(rli->ign_master_log_name_end, mi->master_log_name, FN_REFLEN);
@@ -3682,8 +4093,8 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
       rli->ign_master_log_pos_end= mi->master_log_pos;
     }
     rli->relay_log.signal_update(); // the slave SQL thread needs to re-check
-    DBUG_PRINT("info", ("master_log_pos: %lu, event originating from the same server, ignored",
-                        (ulong) mi->master_log_pos));
+    DBUG_PRINT("info", ("master_log_pos: %lu, event originating from %u server, ignored",
+                        (ulong) mi->master_log_pos, uint4korr(buf + SERVER_ID_OFFSET)));
   }
   else
   {
@@ -3695,15 +4106,23 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
       rli->relay_log.harvest_bytes_written(&rli->log_space_total);
     }
     else
-      error= 3;
+    {
+      error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE;
+    }
     rli->ign_master_log_name_end[0]= 0; // last event is not ignored
   }
   pthread_mutex_unlock(log_lock);
 
-
+skip_relay_logging:
+  
 err:
   pthread_mutex_unlock(&mi->data_lock);
   DBUG_PRINT("info", ("error: %d", error));
+  if (error)
+    mi->report(ERROR_LEVEL, error, ER(error), 
+               (error == ER_SLAVE_RELAY_LOG_WRITE_FAILURE)?
+               "could not queue event from master" :
+               error_msg.ptr());
   DBUG_RETURN(error);
 }
 
@@ -3909,6 +4328,71 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
 }
 
 
+MYSQL *rpl_connect_master(MYSQL *mysql)
+{
+  THD *thd= current_thd;
+  Master_info *mi= my_pthread_getspecific_ptr(Master_info*, RPL_MASTER_INFO);
+  if (!mi)
+  {
+    sql_print_error("'rpl_connect_master' must be called in slave I/O thread context.");
+    return NULL;
+  }
+
+  bool allocated= false;
+  
+  if (!mysql)
+  {
+    if(!(mysql= mysql_init(NULL)))
+    {
+      sql_print_error("rpl_connect_master: failed in mysql_init()");
+      return NULL;
+    }
+    allocated= true;
+  }
+
+  /*
+    XXX: copied from connect_to_master, this function should not
+    change the slave status, so we cannot use connect_to_master
+    directly
+    
+    TODO: make this part a seperate function to eliminate duplication
+  */
+  mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout);
+  mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout);
+
+#ifdef HAVE_OPENSSL
+  if (mi->ssl)
+  {
+    mysql_ssl_set(mysql,
+                  mi->ssl_key[0]?mi->ssl_key:0,
+                  mi->ssl_cert[0]?mi->ssl_cert:0,
+                  mi->ssl_ca[0]?mi->ssl_ca:0,
+                  mi->ssl_capath[0]?mi->ssl_capath:0,
+                  mi->ssl_cipher[0]?mi->ssl_cipher:0);
+    mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
+                  &mi->ssl_verify_server_cert);
+  }
+#endif
+
+  mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset_info->csname);
+  /* This one is not strictly needed but we have it here for completeness */
+  mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
+
+  if (io_slave_killed(thd, mi)
+      || !mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0,
+                             mi->port, 0, 0))
+  {
+    if (!io_slave_killed(thd, mi))
+      sql_print_error("rpl_connect_master: error connecting to master: %s (server_error: %d)",
+                      mysql_error(mysql), mysql_errno(mysql));
+    
+    if (allocated)
+      mysql_close(mysql);                       // this will free the object
+    return NULL;
+  }
+  return mysql;
+}
+
 /*
   Store the file and position where the execute-slave thread are in the
   relay log.
@@ -3962,7 +4446,14 @@ bool flush_relay_log_info(Relay_log_info* rli)
     error=1;
   if (flush_io_cache(file))
     error=1;
-
+  if (sync_relayloginfo_period &&
+      !error &&
+      ++(rli->sync_counter) >= sync_relayloginfo_period)
+  {
+    if (my_sync(rli->info_fd, MYF(MY_WME)))
+      error=1;
+    rli->sync_counter= 0;
+  }
   /* Flushing the relay log is done by the slave I/O thread */
   DBUG_RETURN(error);
 }
@@ -4211,8 +4702,8 @@ static Log_event* next_event(Relay_log_info* rli)
         */
         pthread_mutex_unlock(&rli->log_space_lock);
         pthread_cond_broadcast(&rli->log_space_cond);
-        // Note that wait_for_update unlocks lock_log !
-        rli->relay_log.wait_for_update(rli->sql_thd, 1);
+        // Note that wait_for_update_relay_log unlocks lock_log !
+        rli->relay_log.wait_for_update_relay_log(rli->sql_thd);
         // re-acquire data lock since we released it earlier
         pthread_mutex_lock(&rli->data_lock);
         rli->last_master_timestamp= save_timestamp;
@@ -4369,6 +4860,8 @@ void rotate_relay_log(Master_info* mi)
   DBUG_ENTER("rotate_relay_log");
   Relay_log_info* rli= &mi->rli;
 
+  DBUG_EXECUTE_IF("crash_before_rotate_relaylog", abort(););
+
   /* We don't lock rli->run_lock. This would lead to deadlocks. */
   pthread_mutex_lock(&mi->run_lock);
 
diff --git a/sql/slave.h b/sql/slave.h
index f356d28b626d51dd865289adbd92443a42d4ab5c..eff0fa49f61760497cd30bc6ebd02a463c4895e5 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -22,6 +22,17 @@
 
   @file
 */
+
+/** 
+   Some of defines are need in parser even though replication is not 
+   compiled in (embedded).
+*/
+
+/**
+   The maximum is defined as (ULONG_MAX/1000) with 4 bytes ulong
+*/
+#define SLAVE_MAX_HEARTBEAT_PERIOD 4294967
+
 #ifdef HAVE_REPLICATION
 
 #include "log.h"
@@ -33,7 +44,6 @@
 
 #define MAX_SLAVE_ERROR    2000
 
-
 // Forward declarations
 class Relay_log_info;
 class Master_info;
@@ -134,6 +144,7 @@ extern ulonglong relay_log_space_limit;
 #define SLAVE_FORCE_ALL 4
 
 int init_slave();
+int init_recovery(Master_info* mi, const char** errmsg);
 void init_slave_skip_errors(const char* arg);
 bool flush_relay_log_info(Relay_log_info* rli);
 int register_slave_on_master(MYSQL* mysql);
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 908f0997be6e1230678d961d5ed74320b1eb226a..a95b27ef9cd90e933de9ccf1f3c468c6ac4a3d50 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -175,6 +175,7 @@ sp_get_flags_for_command(LEX *lex)
   case SQLCOM_SHOW_AUTHORS:
   case SQLCOM_SHOW_BINLOGS:
   case SQLCOM_SHOW_BINLOG_EVENTS:
+  case SQLCOM_SHOW_RELAYLOG_EVENTS:
   case SQLCOM_SHOW_CHARSETS:
   case SQLCOM_SHOW_COLLATIONS:
   case SQLCOM_SHOW_COLUMN_TYPES:
diff --git a/sql/sql_acl.h b/sql/sql_acl.h
index a8090fba2e732d8a38525e0ed5fc893048a120c9..c0622bd747cc26a9efdff71287eb2d3bcda281b7 100644
--- a/sql/sql_acl.h
+++ b/sql/sql_acl.h
@@ -1,3 +1,6 @@
+#ifndef SQL_ACL_INCLUDED
+#define SQL_ACL_INCLUDED
+
 /* Copyright (C) 2000-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -273,3 +276,4 @@ bool is_acl_user(const char *host, const char *user);
 #define check_grant(A,B,C,D,E,F) 0
 #define check_grant_db(A,B) 0
 #endif
+#endif /* SQL_ACL_INCLUDED */
diff --git a/sql/sql_analyse.h b/sql/sql_analyse.h
index 8807b40857ec442d9d636bb7569fd72cb3bdb826..8f52b90c874a4fa6cd8c2433001bd002cc75f148 100644
--- a/sql/sql_analyse.h
+++ b/sql/sql_analyse.h
@@ -1,3 +1,6 @@
+#ifndef SQL_ANALYSE_INCLUDED
+#define SQL_ANALYSE_INCLUDED
+
 /* Copyright (C) 2000-2003, 2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -355,3 +358,5 @@ class analyse: public Procedure
 				      select_result *result,
 				      List<Item> &field_list);
 };
+
+#endif /* SQL_ANALYSE_INCLUDED */
diff --git a/sql/sql_array.h b/sql/sql_array.h
index e1b22921519e4ec365ab9daa92de708fd7fab004..dfaa9b029473526c0208bd63321ce6fe116714b2 100644
--- a/sql/sql_array.h
+++ b/sql/sql_array.h
@@ -1,3 +1,6 @@
+#ifndef SQL_ARRAY_INCLUDED
+#define SQL_ARRAY_INCLUDED
+
 /* Copyright (C) 2003 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -66,3 +69,4 @@ template <class Elem> class Dynamic_array
   }
 };
 
+#endif /* SQL_ARRAY_INCLUDED */
diff --git a/sql/sql_binlog.cc b/sql/sql_binlog.cc
index ee51480411bd0ffb7d0c7ca7eb56c73af205ab65..58c309ef57b7981107b97b9a7ae83ee76427c9f2 100644
--- a/sql/sql_binlog.cc
+++ b/sql/sql_binlog.cc
@@ -61,7 +61,7 @@ void mysql_client_binlog_statement(THD* thd)
   rli= thd->rli_fake;
   if (!rli)
   {
-    rli= thd->rli_fake= new Relay_log_info;
+    rli= thd->rli_fake= new Relay_log_info(FALSE);
 #ifdef HAVE_purify
     rli->is_fake= TRUE;
 #endif
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 4ed25b03ed7a22475b512b8be561cafec07edfdb..757f6abb00b19da05bea63ad89ffd46acf81ed19 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -265,6 +265,42 @@ const char *set_thd_proc_info(THD *thd, const char *info,
   return old_info;
 }
 
+extern "C"
+const char* thd_enter_cond(MYSQL_THD thd, pthread_cond_t *cond,
+                           pthread_mutex_t *mutex, const char *msg)
+{
+  if (!thd)
+    thd= current_thd;
+
+  const char* old_msg = thd->proc_info;
+  safe_mutex_assert_owner(mutex);
+  thd->mysys_var->current_mutex = mutex;
+  thd->mysys_var->current_cond = cond;
+  thd->proc_info = msg;
+  return old_msg;
+}
+
+extern "C"
+void thd_exit_cond(MYSQL_THD thd, const char *old_msg)
+{
+  if (!thd)
+    thd= current_thd;
+
+  /*
+    Putting the mutex unlock in thd_exit_cond() ensures that
+    mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
+    locked (if that would not be the case, you'll get a deadlock if someone
+    does a THD::awake() on you).
+  */
+  pthread_mutex_unlock(thd->mysys_var->current_mutex);
+  pthread_mutex_lock(&thd->mysys_var->mutex);
+  thd->mysys_var->current_mutex = 0;
+  thd->mysys_var->current_cond = 0;
+  thd->proc_info = old_msg;
+  pthread_mutex_unlock(&thd->mysys_var->mutex);
+  return;
+}
+
 extern "C"
 void **thd_ha_data(const THD *thd, const struct handlerton *hton)
 {
@@ -475,9 +511,6 @@ THD::THD()
   limit_found_rows= 0;
   row_count_func= -1;
   statement_id_counter= 0UL;
-#ifdef ERROR_INJECT_SUPPORT
-  error_inject_value= 0UL;
-#endif
   // Must be reset to handle error with THD's created for init of mysqld
   lex->current_select= 0;
   start_time=(time_t) 0;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index ea2c63cdc972ffd0a5a7b9f2a9f3882c4290c9f5..aaa959feae99b8a9e5b5a8572a6321d9f9043f8b 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -14,6 +14,9 @@
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 
+#ifndef SQL_CLASS_INCLUDED
+#define SQL_CLASS_INCLUDED
+
 /* Classes in mysql */
 
 #ifdef USE_PRAGMA_INTERFACE
@@ -22,6 +25,7 @@
 
 #include "log.h"
 #include "rpl_tblmap.h"
+#include "replication.h"
 
 /**
   An interface that is used to take an action when
@@ -1662,9 +1666,6 @@ class THD :public Statement,
   query_id_t query_id;
   ulong      col_access;
 
-#ifdef ERROR_INJECT_SUPPORT
-  ulong      error_inject_value;
-#endif
   /* Statement id is thread-wide. This counter is used to generate ids */
   ulong      statement_id_counter;
   ulong	     rand_saved_seed1, rand_saved_seed2;
@@ -1885,27 +1886,11 @@ class THD :public Statement,
   inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
 			  const char* msg)
   {
-    const char* old_msg = proc_info;
-    safe_mutex_assert_owner(mutex);
-    mysys_var->current_mutex = mutex;
-    mysys_var->current_cond = cond;
-    proc_info = msg;
-    return old_msg;
+    return thd_enter_cond(this, cond, mutex, msg);
   }
   inline void exit_cond(const char* old_msg)
   {
-    /*
-      Putting the mutex unlock in exit_cond() ensures that
-      mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
-      locked (if that would not be the case, you'll get a deadlock if someone
-      does a THD::awake() on you).
-    */
-    pthread_mutex_unlock(mysys_var->current_mutex);
-    pthread_mutex_lock(&mysys_var->mutex);
-    mysys_var->current_mutex = 0;
-    mysys_var->current_cond = 0;
-    proc_info = old_msg;
-    pthread_mutex_unlock(&mysys_var->mutex);
+    thd_exit_cond(this, old_msg);
   }
   inline time_t query_start() { query_start_used=1; return start_time; }
   inline void set_time()
@@ -3088,3 +3073,4 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
 void mark_transaction_to_rollback(THD *thd, bool all);
 
 #endif /* MYSQL_SERVER */
+#endif /* SQL_CLASS_INCLUDED */
diff --git a/sql/sql_crypt.h b/sql/sql_crypt.h
index a5a6bee8a5860ba233acdc54df7aba78a2b8df8a..8d5a761cbdf2847e030b94bddfc1a78e85ce2b89 100644
--- a/sql/sql_crypt.h
+++ b/sql/sql_crypt.h
@@ -1,3 +1,6 @@
+#ifndef SQL_CRYPT_INCLUDED
+#define SQL_CRYPT_INCLUDED
+
 /* Copyright (C) 2000-2001, 2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -35,3 +38,5 @@ class SQL_CRYPT :public Sql_alloc
   void encode(char *str, uint length);
   void decode(char *str, uint length);
 };
+
+#endif /* SQL_CRYPT_INCLUDED */
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 02f337d7015a660b22bf8b9b7ebee2d488ccd2a2..05a4d1d78bfc674d2208e1bb2a4d5c59c09efe09 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -17,6 +17,9 @@
   @defgroup Semantic_Analysis Semantic Analysis
 */
 
+#ifndef SQL_LEX_INCLUDED
+#define SQL_LEX_INCLUDED
+
 /* YACC and LEX Definitions */
 
 /* These may not be declared yet */
@@ -119,7 +122,7 @@ enum enum_sql_command {
   SQLCOM_ALTER_DB_UPGRADE,
   SQLCOM_SHOW_PROFILE, SQLCOM_SHOW_PROFILES,
   SQLCOM_SIGNAL, SQLCOM_RESIGNAL,
-
+  SQLCOM_SHOW_RELAYLOG_EVENTS, 
   /*
     When a command is added here, be sure it's also added in mysqld.cc
     in "struct show_var_st status_vars[]= {" ...
@@ -204,17 +207,19 @@ typedef struct st_lex_master_info
 {
   char *host, *user, *password, *log_file_name;
   uint port, connect_retry;
+  float heartbeat_period;
   ulonglong pos;
   ulong server_id;
   /*
     Enum is used for making it possible to detect if the user
     changed variable or if it should be left at old value
    */
-  enum {SSL_UNCHANGED, SSL_DISABLE, SSL_ENABLE}
-    ssl, ssl_verify_server_cert;
+  enum {LEX_MI_UNCHANGED, LEX_MI_DISABLE, LEX_MI_ENABLE}
+    ssl, ssl_verify_server_cert, heartbeat_opt, repl_ignore_server_ids_opt;
   char *ssl_key, *ssl_cert, *ssl_ca, *ssl_capath, *ssl_cipher;
   char *relay_log_name;
   ulong relay_log_pos;
+  DYNAMIC_ARRAY repl_ignore_server_ids;
 } LEX_MASTER_INFO;
 
 
@@ -2068,3 +2073,4 @@ extern bool is_lex_native_function(const LEX_STRING *name);
 void my_missing_function_error(const LEX_STRING &token, const char *name);
 
 #endif /* MYSQL_SERVER */
+#endif /* SQL_LEX_INCLUDED */
diff --git a/sql/sql_map.h b/sql/sql_map.h
index a1efba0da6f143ccfbc0294d2d7cae6c32bca993..5ae260841e0720a0685ba9ef9525f756df6bf4ca 100644
--- a/sql/sql_map.h
+++ b/sql/sql_map.h
@@ -1,3 +1,6 @@
+#ifndef SQL_MAP_INCLUDED
+#define SQL_MAP_INCLUDED
+
 /* Copyright (C) 2000-2001, 2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -60,3 +63,5 @@ class mapped_file
     return file->map;
   }
 };
+
+#endif /* SQL_MAP_INCLUDED */
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 7b9e31e84f081d0a2d643691364b8bacac4a4c5e..d677414070f407f45451ff48e2b904940d2884eb 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -21,6 +21,7 @@
 #include <m_ctype.h>
 #include <myisam.h>
 #include <my_dir.h>
+#include "rpl_handler.h"
 
 #include "sp_head.h"
 #include "sp.h"
@@ -1677,9 +1678,9 @@ void log_slow_statement(THD *thd)
 
   /*
     Do not log administrative statements unless the appropriate option is
-    set; do not log into slow log if reading from backup.
+    set.
   */
-  if (thd->enable_slow_log && !thd->user_time)
+  if (thd->enable_slow_log)
   {
     ulonglong end_utime_of_query= thd->current_utime();
     thd_proc_info(thd, "logging slow query");
@@ -2387,6 +2388,7 @@ mysql_execute_command(THD *thd)
     res = show_slave_hosts(thd);
     break;
   }
+  case SQLCOM_SHOW_RELAYLOG_EVENTS: /* fall through */
   case SQLCOM_SHOW_BINLOG_EVENTS:
   {
     if (check_global_access(thd, REPL_SLAVE_ACL))
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index 24bb99c97a701e2f5bdc142916ff45a578b3ca89..eb711001ef6878896d56304c4fe68d8877b3d9dd 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -40,6 +40,10 @@
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
 #include "ha_partition.h"
+
+#define ERROR_INJECT_CRASH(code) \
+  DBUG_EVALUATE_IF(code, (abort(), 0), 0)
+
 /*
   Partition related functions declarations and some static constants;
 */
diff --git a/sql/sql_partition.h b/sql/sql_partition.h
index 282e24f18530ccb6c4884dc82a507c6776cb4bae..0c47340016c1891ea00ab3e7f598ca7bd58adcc4 100644
--- a/sql/sql_partition.h
+++ b/sql/sql_partition.h
@@ -1,3 +1,6 @@
+#ifndef SQL_PARTITION_INCLUDED
+#define SQL_PARTITION_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
   This program is free software; you can redistribute it and/or modify
@@ -209,3 +212,4 @@ typedef int (*get_partitions_in_range_iter)(partition_info *part_info,
 
 #include "partition_info.h"
 
+#endif /* SQL_PARTITION_INCLUDED */
diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc
index 831ef778f377968c0a44aa03834315df092e02fc..1278eafce92c2a6376d1e86e0b1438caf784f760 100644
--- a/sql/sql_plugin.cc
+++ b/sql/sql_plugin.cc
@@ -19,14 +19,6 @@
 #define REPORT_TO_LOG  1
 #define REPORT_TO_USER 2
 
-#ifdef DBUG_OFF
-#define plugin_ref_to_int(A) A
-#define plugin_int_to_ref(A) A
-#else
-#define plugin_ref_to_int(A) (A ? A[0] : NULL)
-#define plugin_int_to_ref(A) &(A)
-#endif
-
 extern struct st_mysql_plugin *mysqld_builtins[];
 
 /**
@@ -54,7 +46,8 @@ const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
   { C_STRING_WITH_LEN("STORAGE ENGINE") },
   { C_STRING_WITH_LEN("FTPARSER") },
   { C_STRING_WITH_LEN("DAEMON") },
-  { C_STRING_WITH_LEN("INFORMATION SCHEMA") }
+  { C_STRING_WITH_LEN("INFORMATION SCHEMA") },
+  { C_STRING_WITH_LEN("REPLICATION") },
 };
 
 extern int initialize_schema_table(st_plugin_int *plugin);
@@ -93,7 +86,8 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
   MYSQL_HANDLERTON_INTERFACE_VERSION,
   MYSQL_FTPARSER_INTERFACE_VERSION,
   MYSQL_DAEMON_INTERFACE_VERSION,
-  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
+  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
+  MYSQL_REPLICATION_INTERFACE_VERSION,
 };
 static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
 {
@@ -101,7 +95,8 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
   MYSQL_HANDLERTON_INTERFACE_VERSION,
   MYSQL_FTPARSER_INTERFACE_VERSION,
   MYSQL_DAEMON_INTERFACE_VERSION,
-  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
+  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
+  MYSQL_REPLICATION_INTERFACE_VERSION,
 };
 
 static bool initialized= 0;
diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h
index 004d0d5abb7a3df4eac4d85df50038a502293eff..c6ad846943cc54cbd14b0032408ce4495951c6d2 100644
--- a/sql/sql_plugin.h
+++ b/sql/sql_plugin.h
@@ -18,6 +18,14 @@
 
 class sys_var;
 
+#ifdef DBUG_OFF
+#define plugin_ref_to_int(A) A
+#define plugin_int_to_ref(A) A
+#else
+#define plugin_ref_to_int(A) (A ? A[0] : NULL)
+#define plugin_int_to_ref(A) &(A)
+#endif
+
 /*
   the following flags are valid for plugin_init()
 */
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 84781a3a0aea08ddf066f1e26864bc03ea7a3424..5f07df649050b667b94d9c9e143ef6f0e1cb5cdb 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -21,6 +21,7 @@
 #include "log_event.h"
 #include "rpl_filter.h"
 #include <my_dir.h>
+#include "rpl_handler.h"
 
 int max_binlog_dump_events = 0; // unlimited
 my_bool opt_sporadic_binlog_dump_fail = 0;
@@ -80,6 +81,32 @@ static int fake_rotate_event(NET* net, String* packet, char* log_file_name,
   DBUG_RETURN(0);
 }
 
+/*
+  Reset thread transmit packet buffer for event sending
+
+  This function allocates header bytes for event transmission, and
+  should be called before store the event data to the packet buffer.
+*/
+static int reset_transmit_packet(THD *thd, ushort flags,
+                                 ulong *ev_offset, const char **errmsg)
+{
+  int ret= 0;
+  String *packet= &thd->packet;
+
+  /* reserve and set default header */
+  packet->length(0);
+  packet->set("\0", 1, &my_charset_bin);
+
+  if (RUN_HOOK(binlog_transmit, reserve_header, (thd, flags, packet)))
+  {
+    *errmsg= "Failed to run hook 'reserve_header'";
+    my_errno= ER_UNKNOWN_ERROR;
+    ret= 1;
+  }
+  *ev_offset= packet->length();
+  return ret;
+}
+
 static int send_file(THD *thd)
 {
   NET* net = &thd->net;
@@ -336,6 +363,73 @@ Increase max_allowed_packet on master";
 }
 
 
+/**
+  An auxiliary function for calling in mysql_binlog_send
+  to initialize the heartbeat timeout in waiting for a binlogged event.
+
+  @param[in]    thd  THD to access a user variable
+
+  @return        heartbeat period an ulonglong of nanoseconds
+                 or zero if heartbeat was not demanded by slave
+*/ 
+static ulonglong get_heartbeat_period(THD * thd)
+{
+  my_bool null_value;
+  LEX_STRING name=  { C_STRING_WITH_LEN("master_heartbeat_period")};
+  user_var_entry *entry= 
+    (user_var_entry*) hash_search(&thd->user_vars, (uchar*) name.str,
+                                  name.length);
+  return entry? entry->val_int(&null_value) : 0;
+}
+
+/*
+  Function prepares and sends repliation heartbeat event.
+
+  @param net                net object of THD
+  @param packet             buffer to store the heartbeat instance
+  @param event_coordinates  binlog file name and position of the last
+                            real event master sent from binlog
+
+  @note 
+    Among three essential pieces of heartbeat data Log_event::when
+    is computed locally.
+    The  error to send is serious and should force terminating
+    the dump thread.
+*/
+static int send_heartbeat_event(NET* net, String* packet,
+                                const struct event_coordinates *coord)
+{
+  DBUG_ENTER("send_heartbeat_event");
+  char header[LOG_EVENT_HEADER_LEN];
+  /*
+    'when' (the timestamp) is set to 0 so that slave could distinguish between
+    real and fake Rotate events (if necessary)
+  */
+  memset(header, 0, 4);  // when
+
+  header[EVENT_TYPE_OFFSET] = HEARTBEAT_LOG_EVENT;
+
+  char* p= coord->file_name + dirname_length(coord->file_name);
+
+  uint ident_len = strlen(p);
+  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN;
+  int4store(header + SERVER_ID_OFFSET, server_id);
+  int4store(header + EVENT_LEN_OFFSET, event_len);
+  int2store(header + FLAGS_OFFSET, 0);
+
+  int4store(header + LOG_POS_OFFSET, coord->pos);  // log_pos
+
+  packet->append(header, sizeof(header));
+  packet->append(p, ident_len);             // log_file_name
+
+  if (my_net_write(net, (uchar*) packet->ptr(), packet->length()) ||
+      net_flush(net))
+  {
+    DBUG_RETURN(-1);
+  }
+  DBUG_RETURN(0);
+}
+
 /*
   TODO: Clean up loop to only have one call to send_file()
 */
@@ -346,6 +440,9 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos,
   LOG_INFO linfo;
   char *log_file_name = linfo.log_file_name;
   char search_file_name[FN_REFLEN], *name;
+
+  ulong ev_offset;
+
   IO_CACHE log;
   File file = -1;
   String* packet = &thd->packet;
@@ -361,6 +458,30 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos,
   DBUG_PRINT("enter",("log_ident: '%s'  pos: %ld", log_ident, (long) pos));
 
   bzero((char*) &log,sizeof(log));
+  /* 
+     heartbeat_period from @master_heartbeat_period user variable
+  */
+  ulonglong heartbeat_period= get_heartbeat_period(thd);
+  struct timespec heartbeat_buf;
+  struct event_coordinates coord_buf;
+  struct timespec *heartbeat_ts= NULL;
+  struct event_coordinates *coord= NULL;
+  if (heartbeat_period != LL(0))
+  {
+    heartbeat_ts= &heartbeat_buf;
+    set_timespec_nsec(*heartbeat_ts, 0);
+    coord= &coord_buf;
+    coord->file_name= log_file_name; // initialization basing on what slave remembers
+    coord->pos= pos;
+  }
+  sql_print_information("Start binlog_dump to slave_server(%d), pos(%s, %lu)",
+                        thd->server_id, log_ident, (ulong)pos);
+  if (RUN_HOOK(binlog_transmit, transmit_start, (thd, flags, log_ident, pos)))
+  {
+    errmsg= "Failed to run hook 'transmit_start'";
+    my_errno= ER_UNKNOWN_ERROR;
+    goto err;
+  }
 
 #ifndef DBUG_OFF
   if (opt_sporadic_binlog_dump_fail && (binlog_dump_count++ % 2))
@@ -416,11 +537,9 @@ impossible position";
     goto err;
   }
 
-  /*
-    We need to start a packet with something other than 255
-    to distinguish it from error
-  */
-  packet->set("\0", 1, &my_charset_bin); /* This is the start of a new packet */
+  /* reset transmit packet for the fake rotate event below */
+  if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+    goto err;
 
   /*
     Tell the client about the log name with a fake Rotate event;
@@ -460,7 +579,7 @@ impossible position";
     my_errno= ER_MASTER_FATAL_ERROR_READING_BINLOG;
     goto err;
   }
-  packet->set("\0", 1, &my_charset_bin);
+
   /*
     Adding MAX_LOG_EVENT_HEADER_LEN, since a binlog event can become
     this larger than the corresponding packet (query) sent 
@@ -476,6 +595,11 @@ impossible position";
   log_lock = mysql_bin_log.get_log_lock();
   if (pos > BIN_LOG_HEADER_SIZE)
   {
+    /* reset transmit packet for the event read from binary log
+       file */
+    if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+      goto err;
+
      /*
        Try to find a Format_description_log_event at the beginning of
        the binlog
@@ -483,29 +607,30 @@ impossible position";
      if (!(error = Log_event::read_log_event(&log, packet, log_lock)))
      {
        /*
-         The packet has offsets equal to the normal offsets in a binlog
-         event +1 (the first character is \0).
+         The packet has offsets equal to the normal offsets in a
+         binlog event + ev_offset (the first ev_offset characters are
+         the header (default \0)).
        */
        DBUG_PRINT("info",
                   ("Looked for a Format_description_log_event, found event type %d",
-                   (*packet)[EVENT_TYPE_OFFSET+1]));
-       if ((*packet)[EVENT_TYPE_OFFSET+1] == FORMAT_DESCRIPTION_EVENT)
+                   (*packet)[EVENT_TYPE_OFFSET+ev_offset]));
+       if ((*packet)[EVENT_TYPE_OFFSET+ev_offset] == FORMAT_DESCRIPTION_EVENT)
        {
-         binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+1] &
+         binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+ev_offset] &
                                        LOG_EVENT_BINLOG_IN_USE_F);
-         (*packet)[FLAGS_OFFSET+1] &= ~LOG_EVENT_BINLOG_IN_USE_F;
+         (*packet)[FLAGS_OFFSET+ev_offset] &= ~LOG_EVENT_BINLOG_IN_USE_F;
          /*
            mark that this event with "log_pos=0", so the slave
            should not increment master's binlog position
            (rli->group_master_log_pos)
          */
-         int4store((char*) packet->ptr()+LOG_POS_OFFSET+1, 0);
+         int4store((char*) packet->ptr()+LOG_POS_OFFSET+ev_offset, 0);
          /*
            if reconnect master sends FD event with `created' as 0
            to avoid destroying temp tables.
           */
          int4store((char*) packet->ptr()+LOG_EVENT_MINIMAL_HEADER_LEN+
-                   ST_CREATED_OFFSET+1, (ulong) 0);
+                   ST_CREATED_OFFSET+ev_offset, (ulong) 0);
          /* send it */
          if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
          {
@@ -531,8 +656,6 @@ impossible position";
          Format_description_log_event will be found naturally if it is written.
        */
      }
-     /* reset the packet as we wrote to it in any case */
-     packet->set("\0", 1, &my_charset_bin);
   } /* end of if (pos > BIN_LOG_HEADER_SIZE); */
   else
   {
@@ -544,6 +667,12 @@ impossible position";
 
   while (!net->error && net->vio != 0 && !thd->killed)
   {
+    Log_event_type event_type= UNKNOWN_EVENT;
+
+    /* reset the transmit packet for the event read from binary log
+       file */
+    if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+      goto err;
     while (!(error = Log_event::read_log_event(&log, packet, log_lock)))
     {
 #ifndef DBUG_OFF
@@ -555,16 +684,31 @@ impossible position";
 	goto err;
       }
 #endif
+      /*
+        log's filename does not change while it's active
+      */
+      if (coord)
+        coord->pos= uint4korr(packet->ptr() + ev_offset + LOG_POS_OFFSET);
 
-      if ((*packet)[EVENT_TYPE_OFFSET+1] == FORMAT_DESCRIPTION_EVENT)
+      event_type= (Log_event_type)((*packet)[LOG_EVENT_OFFSET+ev_offset]);
+      if (event_type == FORMAT_DESCRIPTION_EVENT)
       {
-        binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+1] &
+        binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+ev_offset] &
                                       LOG_EVENT_BINLOG_IN_USE_F);
-        (*packet)[FLAGS_OFFSET+1] &= ~LOG_EVENT_BINLOG_IN_USE_F;
+        (*packet)[FLAGS_OFFSET+ev_offset] &= ~LOG_EVENT_BINLOG_IN_USE_F;
       }
-      else if ((*packet)[EVENT_TYPE_OFFSET+1] == STOP_EVENT)
+      else if (event_type == STOP_EVENT)
         binlog_can_be_corrupted= FALSE;
 
+      pos = my_b_tell(&log);
+      if (RUN_HOOK(binlog_transmit, before_send_event,
+                   (thd, flags, packet, log_file_name, pos)))
+      {
+        my_errno= ER_UNKNOWN_ERROR;
+        errmsg= "run 'before_send_event' hook failed";
+        goto err;
+      }
+
       if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
       {
 	errmsg = "Failed on my_net_write()";
@@ -572,9 +716,8 @@ impossible position";
 	goto err;
       }
 
-      DBUG_PRINT("info", ("log event code %d",
-			  (*packet)[LOG_EVENT_OFFSET+1] ));
-      if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT)
+      DBUG_PRINT("info", ("log event code %d", event_type));
+      if (event_type == LOAD_EVENT)
       {
 	if (send_file(thd))
 	{
@@ -583,7 +726,17 @@ impossible position";
 	  goto err;
 	}
       }
-      packet->set("\0", 1, &my_charset_bin);
+
+      if (RUN_HOOK(binlog_transmit, after_send_event, (thd, flags, packet)))
+      {
+        errmsg= "Failed to run hook 'after_send_event'";
+        my_errno= ER_UNKNOWN_ERROR;
+        goto err;
+      }
+
+      /* reset transmit packet for next loop */
+      if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+        goto err;
     }
 
     /*
@@ -634,6 +787,11 @@ impossible position";
 	}
 #endif
 
+        /* reset the transmit packet for the event read from binary log
+           file */
+        if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+          goto err;
+        
 	/*
 	  No one will update the log while we are reading
 	  now, but we'll be quick and just read one record
@@ -650,34 +808,86 @@ impossible position";
 	  /* we read successfully, so we'll need to send it to the slave */
 	  pthread_mutex_unlock(log_lock);
 	  read_packet = 1;
+          if (coord)
+            coord->pos= uint4korr(packet->ptr() + ev_offset + LOG_POS_OFFSET);
+          event_type= (Log_event_type)((*packet)[LOG_EVENT_OFFSET+ev_offset]);
 	  break;
 
 	case LOG_READ_EOF:
+        {
+          int ret;
+          ulong signal_cnt;
 	  DBUG_PRINT("wait",("waiting for data in binary log"));
 	  if (thd->server_id==0) // for mysqlbinlog (mysqlbinlog.server_id==0)
 	  {
 	    pthread_mutex_unlock(log_lock);
 	    goto end;
 	  }
-	  if (!thd->killed)
-	  {
-	    /* Note that the following call unlocks lock_log */
-	    mysql_bin_log.wait_for_update(thd, 0);
-	  }
-	  else
-	    pthread_mutex_unlock(log_lock);
-	  DBUG_PRINT("wait",("binary log received update"));
-	  break;
 
-	default:
+#ifndef DBUG_OFF
+          ulong hb_info_counter= 0;
+#endif
+          signal_cnt= mysql_bin_log.signal_cnt;
+          do 
+          {
+            if (coord)
+            {
+              DBUG_ASSERT(heartbeat_ts && heartbeat_period != LL(0));
+              set_timespec_nsec(*heartbeat_ts, heartbeat_period);
+            }
+            ret= mysql_bin_log.wait_for_update_bin_log(thd, heartbeat_ts);
+            DBUG_ASSERT(ret == 0 || heartbeat_period != LL(0) && coord != NULL);
+            if (ret == ETIMEDOUT || ret == ETIME)
+            {
+#ifndef DBUG_OFF
+              if (hb_info_counter < 3)
+              {
+                sql_print_information("master sends heartbeat message");
+                hb_info_counter++;
+                if (hb_info_counter == 3)
+                  sql_print_information("the rest of heartbeat info skipped ...");
+              }
+#endif
+              /* reset transmit packet for the heartbeat event */
+              if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+                goto err;
+              if (send_heartbeat_event(net, packet, coord))
+              {
+                errmsg = "Failed on my_net_write()";
+                my_errno= ER_UNKNOWN_ERROR;
+                pthread_mutex_unlock(log_lock);
+                goto err;
+              }
+            }
+            else
+            {
+              DBUG_ASSERT(ret == 0 && signal_cnt != mysql_bin_log.signal_cnt ||
+                          thd->killed);
+              DBUG_PRINT("wait",("binary log received update"));
+            }
+          } while (signal_cnt == mysql_bin_log.signal_cnt && !thd->killed);
+          pthread_mutex_unlock(log_lock);
+        }
+        break;
+            
+        default:
 	  pthread_mutex_unlock(log_lock);
           test_for_non_eof_log_read_errors(error, &errmsg);
           goto err;
 	}
 
 	if (read_packet)
-	{
-	  thd_proc_info(thd, "Sending binlog event to slave");
+        {
+          thd_proc_info(thd, "Sending binlog event to slave");
+          pos = my_b_tell(&log);
+          if (RUN_HOOK(binlog_transmit, before_send_event,
+                       (thd, flags, packet, log_file_name, pos)))
+          {
+            my_errno= ER_UNKNOWN_ERROR;
+            errmsg= "run 'before_send_event' hook failed";
+            goto err;
+          }
+	  
 	  if (my_net_write(net, (uchar*) packet->ptr(), packet->length()) )
 	  {
 	    errmsg = "Failed on my_net_write()";
@@ -685,7 +895,7 @@ impossible position";
 	    goto err;
 	  }
 
-	  if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT)
+	  if (event_type == LOAD_EVENT)
 	  {
 	    if (send_file(thd))
 	    {
@@ -694,11 +904,13 @@ impossible position";
 	      goto err;
 	    }
 	  }
-	  packet->set("\0", 1, &my_charset_bin);
-	  /*
-	    No need to net_flush because we will get to flush later when
-	    we hit EOF pretty quick
-	  */
+
+          if (RUN_HOOK(binlog_transmit, after_send_event, (thd, flags, packet)))
+          {
+            my_errno= ER_UNKNOWN_ERROR;
+            errmsg= "Failed to run hook 'after_send_event'";
+            goto err;
+          }
 	}
 
 	log.error=0;
@@ -728,6 +940,10 @@ impossible position";
       end_io_cache(&log);
       (void) my_close(file, MYF(MY_WME));
 
+      /* reset transmit packet for the possible fake rotate event */
+      if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
+        goto err;
+      
       /*
         Call fake_rotate_event() in case the previous log (the one which
         we have just finished reading) did not contain a Rotate event
@@ -745,8 +961,8 @@ impossible position";
 	goto err;
       }
 
-      packet->length(0);
-      packet->append('\0');
+      if (coord)
+        coord->file_name= log_file_name; // reset to the next
     }
   }
 
@@ -754,6 +970,7 @@ impossible position";
   end_io_cache(&log);
   (void)my_close(file, MYF(MY_WME));
 
+  RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags));
   my_eof(thd);
   thd_proc_info(thd, "Waiting to finalize termination");
   pthread_mutex_lock(&LOCK_thread_count);
@@ -764,6 +981,7 @@ impossible position";
 err:
   thd_proc_info(thd, "Waiting to finalize termination");
   end_io_cache(&log);
+  RUN_HOOK(binlog_transmit, transmit_stop, (thd, flags));
   /*
     Exclude  iteration through thread list
     this is needed for purge_logs() - it will iterate through
@@ -1058,6 +1276,7 @@ int reset_slave(THD *thd, Master_info* mi)
     goto err;
   }
 
+  RUN_HOOK(binlog_relay_io, after_reset_slave, (thd, mi));
 err:
   unlock_slave_threads(mi);
   if (error)
@@ -1131,26 +1350,40 @@ bool change_master(THD* thd, Master_info* mi)
   int thread_mask;
   const char* errmsg= 0;
   bool need_relay_log_purge= 1;
+  bool ret= FALSE;
   DBUG_ENTER("change_master");
 
   lock_slave_threads(mi);
   init_thread_mask(&thread_mask,mi,0 /*not inverse*/);
+  LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
   if (thread_mask) // We refuse if any slave thread is running
   {
     my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
-    unlock_slave_threads(mi);
-    DBUG_RETURN(TRUE);
+    ret= TRUE;
+    goto err;
   }
 
   thd_proc_info(thd, "Changing master");
-  LEX_MASTER_INFO* lex_mi= &thd->lex->mi;
+  /* 
+    We need to check if there is an empty master_host. Otherwise
+    change master succeeds, a master.info file is created containing 
+    empty master_host string and when issuing: start slave; an error
+    is thrown stating that the server is not configured as slave.
+    (See BUG#28796).
+  */
+  if(lex_mi->host && !*lex_mi->host) 
+  {
+    my_error(ER_WRONG_ARGUMENTS, MYF(0), "MASTER_HOST");
+    unlock_slave_threads(mi);
+    DBUG_RETURN(TRUE);
+  }
   // TODO: see if needs re-write
   if (init_master_info(mi, master_info_file, relay_log_info_file, 0,
 		       thread_mask))
   {
     my_message(ER_MASTER_INFO, ER(ER_MASTER_INFO), MYF(0));
-    unlock_slave_threads(mi);
-    DBUG_RETURN(TRUE);
+    ret= TRUE;
+    goto err;
   }
 
   /*
@@ -1189,13 +1422,46 @@ bool change_master(THD* thd, Master_info* mi)
     mi->port = lex_mi->port;
   if (lex_mi->connect_retry)
     mi->connect_retry = lex_mi->connect_retry;
+  if (lex_mi->heartbeat_opt != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
+    mi->heartbeat_period = lex_mi->heartbeat_period;
+  else
+    mi->heartbeat_period= (float) min(SLAVE_MAX_HEARTBEAT_PERIOD,
+                                      (slave_net_timeout/2.0));
+  mi->received_heartbeats= LL(0); // counter lives until master is CHANGEd
+  /*
+    reset the last time server_id list if the current CHANGE MASTER 
+    is mentioning IGNORE_SERVER_IDS= (...)
+  */
+  if (lex_mi->repl_ignore_server_ids_opt == LEX_MASTER_INFO::LEX_MI_ENABLE)
+    reset_dynamic(&mi->ignore_server_ids);
+  for (uint i= 0; i < lex_mi->repl_ignore_server_ids.elements; i++)
+  {
+    ulong s_id;
+    get_dynamic(&lex_mi->repl_ignore_server_ids, (uchar*) &s_id, i);
+    if (s_id == ::server_id && replicate_same_server_id)
+    {
+      my_error(ER_SLAVE_IGNORE_SERVER_IDS, MYF(0), s_id);
+      ret= TRUE;
+      goto err;
+    }
+    else
+    {
+      if (bsearch((const ulong *) &s_id,
+                  mi->ignore_server_ids.buffer,
+                  mi->ignore_server_ids.elements, sizeof(ulong),
+                  (int (*) (const void*, const void*))
+                  change_master_server_id_cmp) == NULL)
+        insert_dynamic(&mi->ignore_server_ids, (uchar*) &s_id);
+    }
+  }
+  sort_dynamic(&mi->ignore_server_ids, (qsort_cmp) change_master_server_id_cmp);
 
-  if (lex_mi->ssl != LEX_MASTER_INFO::SSL_UNCHANGED)
-    mi->ssl= (lex_mi->ssl == LEX_MASTER_INFO::SSL_ENABLE);
+  if (lex_mi->ssl != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
+    mi->ssl= (lex_mi->ssl == LEX_MASTER_INFO::LEX_MI_ENABLE);
 
-  if (lex_mi->ssl_verify_server_cert != LEX_MASTER_INFO::SSL_UNCHANGED)
+  if (lex_mi->ssl_verify_server_cert != LEX_MASTER_INFO::LEX_MI_UNCHANGED)
     mi->ssl_verify_server_cert=
-      (lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::SSL_ENABLE);
+      (lex_mi->ssl_verify_server_cert == LEX_MASTER_INFO::LEX_MI_ENABLE);
 
   if (lex_mi->ssl_ca)
     strmake(mi->ssl_ca, lex_mi->ssl_ca, sizeof(mi->ssl_ca)-1);
@@ -1218,9 +1484,11 @@ bool change_master(THD* thd, Master_info* mi)
   if (lex_mi->relay_log_name)
   {
     need_relay_log_purge= 0;
-    strmake(mi->rli.group_relay_log_name,lex_mi->relay_log_name,
+    char relay_log_name[FN_REFLEN];
+    mi->rli.relay_log.make_log_name(relay_log_name, lex_mi->relay_log_name);
+    strmake(mi->rli.group_relay_log_name, relay_log_name,
 	    sizeof(mi->rli.group_relay_log_name)-1);
-    strmake(mi->rli.event_relay_log_name,lex_mi->relay_log_name,
+    strmake(mi->rli.event_relay_log_name, relay_log_name,
 	    sizeof(mi->rli.event_relay_log_name)-1);
   }
 
@@ -1267,8 +1535,8 @@ bool change_master(THD* thd, Master_info* mi)
   if (flush_master_info(mi, 0))
   {
     my_error(ER_RELAY_LOG_INIT, MYF(0), "Failed to flush master info file");
-    unlock_slave_threads(mi);
-    DBUG_RETURN(TRUE);
+    ret= TRUE;
+    goto err;
   }
   if (need_relay_log_purge)
   {
@@ -1279,8 +1547,8 @@ bool change_master(THD* thd, Master_info* mi)
 			 &errmsg))
     {
       my_error(ER_RELAY_LOG_FAIL, MYF(0), errmsg);
-      unlock_slave_threads(mi);
-      DBUG_RETURN(TRUE);
+      ret= TRUE;
+      goto err;
     }
   }
   else
@@ -1295,8 +1563,8 @@ bool change_master(THD* thd, Master_info* mi)
 			   &msg, 0))
     {
       my_error(ER_RELAY_LOG_INIT, MYF(0), msg);
-      unlock_slave_threads(mi);
-      DBUG_RETURN(TRUE);
+      ret= TRUE;
+      goto err;
     }
   }
   /*
@@ -1333,10 +1601,13 @@ bool change_master(THD* thd, Master_info* mi)
   pthread_cond_broadcast(&mi->data_cond);
   pthread_mutex_unlock(&mi->rli.data_lock);
 
+err:
   unlock_slave_threads(mi);
   thd_proc_info(thd, 0);
-  my_ok(thd);
-  DBUG_RETURN(FALSE);
+  if (ret == FALSE)
+    my_ok(thd);
+  delete_dynamic(&lex_mi->repl_ignore_server_ids); //freeing of parser-time alloc
+  DBUG_RETURN(ret);
 }
 
 
@@ -1357,7 +1628,11 @@ int reset_master(THD* thd)
                ER(ER_FLUSH_MASTER_BINLOG_CLOSED), MYF(ME_BELL+ME_WAITTANG));
     return 1;
   }
-  return mysql_bin_log.reset_logs(thd);
+
+  if (mysql_bin_log.reset_logs(thd))
+    return 1;
+  RUN_HOOK(binlog_transmit, after_reset_master, (thd, 0 /* flags */));
+  return 0;
 }
 
 int cmp_master_pos(const char* log_file_name1, ulonglong log_pos1,
@@ -1395,6 +1670,7 @@ bool mysql_show_binlog_events(THD* thd)
   bool ret = TRUE;
   IO_CACHE log;
   File file = -1;
+  MYSQL_BIN_LOG *binary_log= NULL;
   DBUG_ENTER("mysql_show_binlog_events");
 
   Log_event::init_show_field_list(&field_list);
@@ -1405,14 +1681,30 @@ bool mysql_show_binlog_events(THD* thd)
   Format_description_log_event *description_event= new
     Format_description_log_event(3); /* MySQL 4.0 by default */
 
-  /*
-    Wait for handlers to insert any pending information
-    into the binlog.  For e.g. ndb which updates the binlog asynchronously
-    this is needed so that the uses sees all its own commands in the binlog
-  */
-  ha_binlog_wait(thd);
+  DBUG_ASSERT(thd->lex->sql_command == SQLCOM_SHOW_BINLOG_EVENTS ||
+              thd->lex->sql_command == SQLCOM_SHOW_RELAYLOG_EVENTS);
 
-  if (mysql_bin_log.is_open())
+  /* select wich binary log to use: binlog or relay */
+  if ( thd->lex->sql_command == SQLCOM_SHOW_BINLOG_EVENTS )
+  {
+    /*
+      Wait for handlers to insert any pending information
+      into the binlog.  For e.g. ndb which updates the binlog asynchronously
+      this is needed so that the uses sees all its own commands in the binlog
+    */
+    ha_binlog_wait(thd);
+
+    binary_log= &mysql_bin_log;
+  }
+  else  /* showing relay log contents */
+  {
+    if (!active_mi)
+      DBUG_RETURN(TRUE);
+
+    binary_log= &(active_mi->rli.relay_log);
+  }
+
+  if (binary_log->is_open())
   {
     LEX_MASTER_INFO *lex_mi= &thd->lex->mi;
     SELECT_LEX_UNIT *unit= &thd->lex->unit;
@@ -1420,7 +1712,7 @@ bool mysql_show_binlog_events(THD* thd)
     my_off_t pos = max(BIN_LOG_HEADER_SIZE, lex_mi->pos); // user-friendly
     char search_file_name[FN_REFLEN], *name;
     const char *log_file_name = lex_mi->log_file_name;
-    pthread_mutex_t *log_lock = mysql_bin_log.get_log_lock();
+    pthread_mutex_t *log_lock = binary_log->get_log_lock();
     LOG_INFO linfo;
     Log_event* ev;
 
@@ -1430,13 +1722,13 @@ bool mysql_show_binlog_events(THD* thd)
 
     name= search_file_name;
     if (log_file_name)
-      mysql_bin_log.make_log_name(search_file_name, log_file_name);
+      binary_log->make_log_name(search_file_name, log_file_name);
     else
       name=0;					// Find first log
 
     linfo.index_file_offset = 0;
 
-    if (mysql_bin_log.find_log_pos(&linfo, name, 1))
+    if (binary_log->find_log_pos(&linfo, name, 1))
     {
       errmsg = "Could not find target log";
       goto err;
@@ -1739,6 +2031,26 @@ class sys_var_sync_binlog_period :public sys_var_long_ptr
   bool update(THD *thd, set_var *var);
 };
 
+static void fix_slave_net_timeout(THD *thd, enum_var_type type)
+{
+  DBUG_ENTER("fix_slave_net_timeout");
+#ifdef HAVE_REPLICATION
+  pthread_mutex_lock(&LOCK_active_mi);
+  DBUG_PRINT("info",("slave_net_timeout=%lu mi->heartbeat_period=%.3f",
+                     slave_net_timeout,
+                     (active_mi? active_mi->heartbeat_period : 0.0)));
+  if (active_mi && slave_net_timeout < active_mi->heartbeat_period)
+    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                        ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
+                        "The currect value for master_heartbeat_period"
+                        " exceeds the new value of `slave_net_timeout' sec."
+                        " A sensible value for the period should be"
+                        " less than the timeout.");
+  pthread_mutex_unlock(&LOCK_active_mi);
+#endif
+  DBUG_VOID_RETURN;
+}
+
 static sys_var_chain vars = { NULL, NULL };
 
 static sys_var_const    sys_log_slave_updates(&vars, "log_slave_updates",
@@ -1755,6 +2067,16 @@ static sys_var_const    sys_relay_log_info_file(&vars, "relay_log_info_file",
                                       (uchar*) &relay_log_info_file);
 static sys_var_bool_ptr	sys_relay_log_purge(&vars, "relay_log_purge",
 					    &relay_log_purge);
+static sys_var_bool_ptr sys_relay_log_recovery(&vars, "relay_log_recovery",
+                                               &relay_log_recovery);
+static sys_var_uint_ptr sys_sync_binlog_period(&vars, "sync_binlog",
+                                              &sync_binlog_period);
+static sys_var_uint_ptr sys_sync_relaylog_period(&vars, "sync_relay_log",
+                                                &sync_relaylog_period);
+static sys_var_uint_ptr sys_sync_relayloginfo_period(&vars, "sync_relay_log_info",
+                                                    &sync_relayloginfo_period);
+static sys_var_uint_ptr sys_sync_masterinfo_period(&vars, "sync_master_info",
+                                                  &sync_masterinfo_period);
 static sys_var_const    sys_relay_log_space_limit(&vars,
                                                   "relay_log_space_limit",
                                                   OPT_GLOBAL, SHOW_LONGLONG,
@@ -1764,13 +2086,13 @@ static sys_var_const    sys_slave_load_tmpdir(&vars, "slave_load_tmpdir",
                                               OPT_GLOBAL, SHOW_CHAR_PTR,
                                               (uchar*) &slave_load_tmpdir);
 static sys_var_long_ptr	sys_slave_net_timeout(&vars, "slave_net_timeout",
-					      &slave_net_timeout);
+					      &slave_net_timeout,
+                                              fix_slave_net_timeout);
 static sys_var_const    sys_slave_skip_errors(&vars, "slave_skip_errors",
                                               OPT_GLOBAL, SHOW_CHAR,
                                               (uchar*) slave_skip_error_names);
 static sys_var_long_ptr	sys_slave_trans_retries(&vars, "slave_transaction_retries",
 						&slave_trans_retries);
-static sys_var_sync_binlog_period sys_sync_binlog_period(&vars, "sync_binlog", &sync_binlog_period);
 static sys_var_slave_skip_counter sys_slave_skip_counter(&vars, "sql_slave_skip_counter");
 
 
@@ -1812,12 +2134,6 @@ bool sys_var_slave_skip_counter::update(THD *thd, set_var *var)
 }
 
 
-bool sys_var_sync_binlog_period::update(THD *thd, set_var *var)
-{
-  sync_binlog_period= (ulong) var->save_result.ulonglong_value;
-  return 0;
-}
-
 int init_replication_sys_vars()
 {
   if (mysql_add_sys_var_chain(vars.first, my_long_options))
@@ -1829,6 +2145,5 @@ int init_replication_sys_vars()
   return 0;
 }
 
-#endif /* HAVE_REPLICATION */
-
 
+#endif /* HAVE_REPLICATION */
diff --git a/sql/sql_repl.h b/sql/sql_repl.h
index d5c9040f8dcd6c847ec0c6622ed738ee0e4d8229..aa71ac96ff8d576f089869b2eb8c6648d4a2ac2e 100644
--- a/sql/sql_repl.h
+++ b/sql/sql_repl.h
@@ -13,6 +13,9 @@
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
+#ifndef SQL_REPL_INCLUDED
+#define SQL_REPL_INCLUDED
+
 #include "rpl_filter.h"
 
 #ifdef HAVE_REPLICATION
@@ -65,3 +68,4 @@ int init_replication_sys_vars();
 
 #endif /* HAVE_REPLICATION */
 
+#endif /* SQL_REPL_INCLUDED */
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 4eb6548d23b034c29b0a3fba8d0de50c7fb11415..f7dc09ddc62037231ab91e89ecc70dada25c3296 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1,3 +1,6 @@
+#ifndef SQL_SELECT_INCLUDED
+#define SQL_SELECT_INCLUDED
+
 /* Copyright (C) 2000-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -758,3 +761,4 @@ inline bool optimizer_flag(THD *thd, uint flag)
   return (thd->variables.optimizer_switch & flag);
 }
 
+#endif /* SQL_SELECT_INCLUDED */
diff --git a/sql/sql_servers.h b/sql/sql_servers.h
index 63c691893d1ec39ab1c7711775a8d3b82925d9ae..12855f8473c5e0c6454d3908b5b84624aa1abd4e 100644
--- a/sql/sql_servers.h
+++ b/sql/sql_servers.h
@@ -1,3 +1,6 @@
+#ifndef SQL_SERVERS_INCLUDED
+#define SQL_SERVERS_INCLUDED
+
 /* Copyright (C) 2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -41,3 +44,5 @@ int alter_server(THD *thd, LEX_SERVER_OPTIONS *server_options);
 /* lookup functions */
 FOREIGN_SERVER *get_server_by_name(MEM_ROOT *mem, const char *server_name,
                                    FOREIGN_SERVER *server_buffer);
+
+#endif /* SQL_SERVERS_INCLUDED */
diff --git a/sql/sql_sort.h b/sql/sql_sort.h
index 1e9322f7f5b4f4f2849747b4040df5505c108f6f..102b3ef0a11de8194b8a66c1b155138cd344e602 100644
--- a/sql/sql_sort.h
+++ b/sql/sql_sort.h
@@ -1,3 +1,6 @@
+#ifndef SQL_SORT_INCLUDED
+#define SQL_SORT_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -87,3 +90,5 @@ int merge_buffers(SORTPARAM *param,IO_CACHE *from_file,
 		  BUFFPEK *lastbuff,BUFFPEK *Fb,
 		  BUFFPEK *Tb,int flag);
 void reuse_freed_buff(QUEUE *queue, BUFFPEK *reuse, uint key_length);
+
+#endif /* SQL_SORT_INCLUDED */
diff --git a/sql/sql_string.h b/sql/sql_string.h
index d62908e5d66d9a4053b072797678d43550d10f4e..7b10aafbff15464ebb31fcfd7c765ffa71aac530 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -1,3 +1,6 @@
+#ifndef SQL_STRING_INCLUDED
+#define SQL_STRING_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -389,3 +392,5 @@ static inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str,
 {
   return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
 }
+
+#endif /* SQL_STRING_INCLUDED */
diff --git a/sql/sql_trigger.h b/sql/sql_trigger.h
index f6754a75284f41e8d2f34d3032f84c07ae9cbdab..b411acf2ac5b59ca889374211dc6296db0cad8be 100644
--- a/sql/sql_trigger.h
+++ b/sql/sql_trigger.h
@@ -1,3 +1,6 @@
+#ifndef SQL_TRIGGER_INCLUDED
+#define SQL_TRIGGER_INCLUDED
+
 /* Copyright (C) 2004-2005 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -174,3 +177,4 @@ bool load_table_name_for_trigger(THD *thd,
                                  const LEX_STRING *trn_path,
                                  LEX_STRING *tbl_name);
 
+#endif /* SQL_TRIGGER_INCLUDED */
diff --git a/sql/sql_udf.h b/sql/sql_udf.h
index 4b8b492698e4792be57b6501a78a0e7b18270d2f..95cb167869ebab87fe8d5ea2d311d53a1bb25fcc 100644
--- a/sql/sql_udf.h
+++ b/sql/sql_udf.h
@@ -1,3 +1,6 @@
+#ifndef SQL_UDF_INCLUDED
+#define SQL_UDF_INCLUDED
+
 /* Copyright (C) 2000-2001, 2003-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -140,3 +143,4 @@ void free_udf(udf_func *udf);
 int mysql_create_function(THD *thd,udf_func *udf);
 int mysql_drop_function(THD *thd,const LEX_STRING *name);
 #endif
+#endif /* SQL_UDF_INCLUDED */
diff --git a/sql/sql_view.h b/sql/sql_view.h
index e08c2168e1401e57698e87224de4b859319cef0b..3de51c3264e8bb5533a62583e9fb42952e10946e 100644
--- a/sql/sql_view.h
+++ b/sql/sql_view.h
@@ -1,3 +1,6 @@
+#ifndef SQL_VIEW_INCLUDED
+#define SQL_VIEW_INCLUDED
+
 /* -*- C++ -*- */
 /* Copyright (C) 2004 MySQL AB
 
@@ -42,3 +45,4 @@ bool mysql_rename_view(THD *thd, const char *new_db, const char *new_name,
 
 #define VIEW_ANY_ACL (SELECT_ACL | UPDATE_ACL | INSERT_ACL | DELETE_ACL)
 
+#endif /* SQL_VIEW_INCLUDED */
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 66ce6479500065725273d4a6c0d8485028fb0cc5..bf8f7a0ebe7d4a4bcc095bd64f0940b3d9b40f86 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -753,6 +753,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 %token  IDENT_QUOTED
 %token  IF
 %token  IGNORE_SYM
+%token  IGNORE_SERVER_IDS_SYM
 %token  IMPORT
 %token  INDEXES
 %token  INDEX_SYM
@@ -827,6 +828,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 %token  MASTER_SSL_VERIFY_SERVER_CERT_SYM
 %token  MASTER_SYM
 %token  MASTER_USER_SYM
+%token  MASTER_HEARTBEAT_PERIOD_SYM
 %token  MATCH                         /* SQL-2003-R */
 %token  MAX_CONNECTIONS_PER_HOUR
 %token  MAX_QUERIES_PER_HOUR
@@ -945,6 +947,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 %token  REDUNDANT_SYM
 %token  REFERENCES                    /* SQL-2003-R */
 %token  REGEXP
+%token  RELAYLOG_SYM
 %token  RELAY_LOG_FILE_SYM
 %token  RELAY_LOG_POS_SYM
 %token  RELAY_THREAD
@@ -1588,6 +1591,12 @@ change:
             LEX *lex = Lex;
             lex->sql_command = SQLCOM_CHANGE_MASTER;
             bzero((char*) &lex->mi, sizeof(lex->mi));
+            /*
+              resetting flags that can left from the previous CHANGE MASTER
+            */
+            lex->mi.repl_ignore_server_ids_opt= LEX_MASTER_INFO::LEX_MI_UNCHANGED;
+            my_init_dynamic_array(&Lex->mi.repl_ignore_server_ids,
+                                  sizeof(::server_id), 16, 16);
           }
           master_defs
           {}
@@ -1622,7 +1631,7 @@ master_def:
         | MASTER_SSL_SYM EQ ulong_num
           {
             Lex->mi.ssl= $3 ? 
-              LEX_MASTER_INFO::SSL_ENABLE : LEX_MASTER_INFO::SSL_DISABLE;
+              LEX_MASTER_INFO::LEX_MI_ENABLE : LEX_MASTER_INFO::LEX_MI_DISABLE;
           }
         | MASTER_SSL_CA_SYM EQ TEXT_STRING_sys
           {
@@ -1647,11 +1656,69 @@ master_def:
         | MASTER_SSL_VERIFY_SERVER_CERT_SYM EQ ulong_num
           {
             Lex->mi.ssl_verify_server_cert= $3 ?
-              LEX_MASTER_INFO::SSL_ENABLE : LEX_MASTER_INFO::SSL_DISABLE;
+              LEX_MASTER_INFO::LEX_MI_ENABLE : LEX_MASTER_INFO::LEX_MI_DISABLE;
           }
-        | master_file_def
+
+        | MASTER_HEARTBEAT_PERIOD_SYM EQ NUM_literal
+          {
+            Lex->mi.heartbeat_period= (float) $3->val_real();
+           if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD ||
+               Lex->mi.heartbeat_period < 0.0)
+           {
+             const char format[]= "%d seconds";
+             char buf[4*sizeof(SLAVE_MAX_HEARTBEAT_PERIOD) + sizeof(format)];
+             my_sprintf(buf, (buf, format, SLAVE_MAX_HEARTBEAT_PERIOD));
+             my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
+                      MYF(0),
+                      " is negative or exceeds the maximum ",
+                       buf); 
+              MYSQL_YYABORT;
+            }
+            if (Lex->mi.heartbeat_period > slave_net_timeout)
+            {
+              push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
+                                  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
+                                  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
+                                  " exceeds the value of `slave_net_timeout' sec.",
+                                  " A sensible value for the period should be"
+                                  " less than the timeout.");
+            }
+            if (Lex->mi.heartbeat_period < 0.001)
+            {
+              if (Lex->mi.heartbeat_period != 0.0)
+              {
+                push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,
+                                    ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE,
+                                    ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE),
+                                    " is less than 1 msec.",
+                                    " The period is reset to zero which means"
+                                    " no heartbeats will be sending");
+                Lex->mi.heartbeat_period= 0.0;
+              }
+              Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_DISABLE;
+            }
+            Lex->mi.heartbeat_opt=  LEX_MASTER_INFO::LEX_MI_ENABLE;
+          }
+        | IGNORE_SERVER_IDS_SYM EQ '(' ignore_server_id_list ')'
+          {
+            Lex->mi.repl_ignore_server_ids_opt= LEX_MASTER_INFO::LEX_MI_ENABLE;
+           }
+        |
+        master_file_def
         ;
 
+ignore_server_id_list:
+          /* Empty */
+          | ignore_server_id
+          | ignore_server_id_list ',' ignore_server_id
+        ;
+
+ignore_server_id:
+          ulong_num
+          {
+            insert_dynamic(&Lex->mi.repl_ignore_server_ids, (uchar*) &($1));
+          }
+
 master_file_def:
           MASTER_LOG_FILE_SYM EQ TEXT_STRING_sys
           {
@@ -10201,6 +10268,11 @@ show_param:
             LEX *lex= Lex;
             lex->sql_command= SQLCOM_SHOW_BINLOG_EVENTS;
           } opt_limit_clause_init
+        | RELAYLOG_SYM EVENTS_SYM binlog_in binlog_from
+          {
+            LEX *lex= Lex;
+            lex->sql_command= SQLCOM_SHOW_RELAYLOG_EVENTS;
+          } opt_limit_clause_init
         | keys_or_index from_or_in table_ident opt_db where_clause
           {
             LEX *lex= Lex;
@@ -11867,6 +11939,7 @@ keyword_sp:
         | REDO_BUFFER_SIZE_SYM     {}
         | REDOFILE_SYM             {}
         | REDUNDANT_SYM            {}
+        | RELAYLOG_SYM             {}
         | RELAY_LOG_FILE_SYM       {}
         | RELAY_LOG_POS_SYM        {}
         | RELAY_THREAD             {}
diff --git a/sql/structs.h b/sql/structs.h
index a58c18f97c5c4301f74894e58fa92c30ef1d58b7..bcda7b1e78714d6fc80dff3957ec203a03b9f888 100644
--- a/sql/structs.h
+++ b/sql/structs.h
@@ -1,3 +1,6 @@
+#ifndef STRUCTS_INCLUDED
+#define STRUCTS_INCLUDED
+
 /* Copyright (C) 2000-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -380,3 +383,5 @@ class Discrete_intervals_list {
   Discrete_interval* get_tail() const { return tail; };
   Discrete_interval* get_current() const { return current; };
 };
+
+#endif /* STRUCTS_INCLUDED */
diff --git a/sql/table.h b/sql/table.h
index e4a382c799fbf4922c7eb1ebfbacd73fa39234ff..f9da0637b4b8e193e83bad432eae73044880a12c 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1,3 +1,6 @@
+#ifndef TABLE_INCLUDED
+#define TABLE_INCLUDED
+
 /* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -1741,3 +1744,4 @@ static inline void dbug_tmp_restore_column_maps(MY_BITMAP *read_set,
 
 size_t max_row_length(TABLE *table, const uchar *data);
 
+#endif /* TABLE_INCLUDED */
diff --git a/sql/tzfile.h b/sql/tzfile.h
index 1ff82d62329b0986d3bac6ac108b6d347e096b4a..1c1800ba1ed96698b26a74ebb1a7e48c73806e0f 100644
--- a/sql/tzfile.h
+++ b/sql/tzfile.h
@@ -1,3 +1,6 @@
+#ifndef TZFILE_INCLUDED
+#define TZFILE_INCLUDED
+
 /* Copyright (C) 2004 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -134,3 +137,5 @@ struct tzhead {
 */
 
 #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+
+#endif
diff --git a/sql/tztime.h b/sql/tztime.h
index 9bf103519c41e7e973207b7d81511afb3b1b0dd3..9990e91f17b82f1efded1340c4916c458d1728e4 100644
--- a/sql/tztime.h
+++ b/sql/tztime.h
@@ -1,3 +1,6 @@
+#ifndef TZTIME_INCLUDED
+#define TZTIME_INCLUDED
+
 /* Copyright (C) 2004 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -79,3 +82,4 @@ static const int MY_TZ_TABLES_COUNT= 4;
 
 
 #endif /* !defined(TESTTIME) && !defined(TZINFO2SQL) */
+#endif /* TZTIME_INCLUDED */
diff --git a/sql/unireg.h b/sql/unireg.h
index f22be19495214d187d0974200b8632b32af2989c..a390b755772649e216dfb984fbdc9b1acc53548d 100644
--- a/sql/unireg.h
+++ b/sql/unireg.h
@@ -1,3 +1,6 @@
+#ifndef UNIREG_INCLUDED
+#define UNIREG_INCLUDED
+
 /* Copyright (C) 2000-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -16,8 +19,6 @@
 
 /*  Extra functions used by unireg library */
 
-#ifndef _unireg_h
-
 #ifndef NO_ALARM_LOOP
 #define NO_ALARM_LOOP		/* lib5 and popen can't use alarm */
 #endif
diff --git a/storage/ndb/test/run-test/setup.cpp b/storage/ndb/test/run-test/setup.cpp
index cbb7a34f171ec0758f1983f2a6c5745f203cdab7..60f8285888cfd82fa9f5f32530b159ef36b18de9 100644
--- a/storage/ndb/test/run-test/setup.cpp
+++ b/storage/ndb/test/run-test/setup.cpp
@@ -105,6 +105,8 @@ setup_config(atrt_config& config)
      */
     for (j = 0; j<(size_t)argc; j++)
     {
+      if (tmp[j] == args_separator)             /* skip arguments separator */
+        continue;
       for (k = 0; proc_args[k].name; k++)
       {
 	if (!strncmp(tmp[j], proc_args[k].name, strlen(proc_args[k].name)))
@@ -369,6 +371,12 @@ load_options(int argc, char** argv, int type, atrt_options& opts)
 {
   for (size_t i = 0; i<(size_t)argc; i++)
   {
+    /**
+     *  Skip the separator for arguments from config file and command
+     *  line
+     */
+    if (argv[i] == args_separator)
+      continue;
     for (size_t j = 0; f_options[j].name; j++)
     {
       const char * name = f_options[j].name;
diff --git a/strings/strings-not-used.h b/strings/strings-not-used.h
index 3efaa8ab6eb55fb6a1d1e72db67f41ad5a4caf47..8311545f22ff52c02845d4f1059910fbec376c91 100644
--- a/strings/strings-not-used.h
+++ b/strings/strings-not-used.h
@@ -1,3 +1,6 @@
+#ifndef STRINGS_NOT_USED_INCLUDED
+#define STRINGS_NOT_USED_INCLUDED
+
 /* Copyright (C) 2000 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -35,3 +38,4 @@
 #define _AlphabetSize	256
 
 #endif	/* NullS */
+#endif /* STRINGS_NOT_USED_INCLUDED */
diff --git a/vio/vio_priv.h b/vio/vio_priv.h
index b9f5dd0c9c46fa13c9d7b3137af142e0d3354c10..792fad4cc660638f69732ef983462ebd0de83f7d 100644
--- a/vio/vio_priv.h
+++ b/vio/vio_priv.h
@@ -1,3 +1,6 @@
+#ifndef VIO_PRIV_INCLUDED
+#define VIO_PRIV_INCLUDED
+
 /* Copyright (C) 2003 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
@@ -38,3 +41,4 @@ void vio_ssl_delete(Vio *vio);
 int vio_ssl_blocking(Vio *vio, my_bool set_blocking_mode, my_bool *old_mode);
 
 #endif /* HAVE_OPENSSL */
+#endif /* VIO_PRIV_INCLUDED */