List:Commits« Previous MessageNext Message »
From:Luis Soares Date:November 29 2010 11:23am
Subject:bzr commit into mysql-trunk-bugfixing branch (luis.soares:3407)
View as plain text  
#At file:///home/lsoares/Workspace/bzr/work/MC/merge/mysql-trunk-bugfixing/ based on revid:dao-gang.qu@stripped

 3407 Luis Soares	2010-11-29 [merge]
      Manual merge: mysql-trunk --> mysql-trunk-bugfixing
      
      Conflicts
      =========
      
      Contents conflict in libmysqld/Makefile.am  **
      Text conflict in mysql-test/suite/binlog/t/disabled.def
      
      ** Resolved by removing the file (autotools were removed
      from trunk-bugfixing some time ago and the changes were
      not yet in trunk)

    added:
      mysql-test/collections/mysql-next-mr-wl2540.push
      mysql-test/collections/mysql-trunk.daily
      mysql-test/collections/mysql-trunk.weekly
      mysql-test/include/have_binlog_checksum_off.inc
      mysql-test/suite/binlog/r/binlog_checksum.result
      mysql-test/suite/binlog/t/binlog_checksum.test
      mysql-test/suite/rpl/extension/README.checksum
      mysql-test/suite/rpl/extension/checksum.pl
      mysql-test/suite/rpl/r/rpl_checksum.result
      mysql-test/suite/rpl/r/rpl_checksum_cache.result
      mysql-test/suite/rpl/r/rpl_corruption.result
      mysql-test/suite/rpl/t/rpl_checksum-master.opt
      mysql-test/suite/rpl/t/rpl_checksum.test
      mysql-test/suite/rpl/t/rpl_checksum_cache.test
      mysql-test/suite/rpl/t/rpl_corruption-master.opt
      mysql-test/suite/rpl/t/rpl_corruption-slave.opt
      mysql-test/suite/rpl/t/rpl_corruption.test
      mysql-test/suite/sys_vars/r/binlog_checksum_basic.result
      mysql-test/suite/sys_vars/r/master_verify_checksum_basic.result
      mysql-test/suite/sys_vars/r/slave_sql_verify_checksum_basic.result
      mysql-test/suite/sys_vars/t/binlog_checksum_basic.test
      mysql-test/suite/sys_vars/t/master_verify_checksum_basic.test
      mysql-test/suite/sys_vars/t/slave_sql_verify_checksum_basic.test
    modified:
      client/mysqlbinlog.cc
      libmysqld/CMakeLists.txt
      mysql-test/collections/default.experimental
      mysql-test/extra/binlog_tests/binlog.test
      mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test
      mysql-test/extra/rpl_tests/rpl_change_master.test
      mysql-test/extra/rpl_tests/rpl_conflicts.test
      mysql-test/extra/rpl_tests/rpl_flsh_tbls.test
      mysql-test/extra/rpl_tests/rpl_reset_slave.test
      mysql-test/extra/rpl_tests/rpl_start_stop_slave.test
      mysql-test/include/mtr_warnings.sql
      mysql-test/r/mysqld--help-notwin.result
      mysql-test/r/mysqld--help-win.result
      mysql-test/suite/binlog/r/binlog_killed.result
      mysql-test/suite/binlog/r/binlog_old_versions.result
      mysql-test/suite/binlog/r/binlog_row_binlog.result
      mysql-test/suite/binlog/r/binlog_stm_binlog.result
      mysql-test/suite/binlog/t/binlog_killed.test
      mysql-test/suite/binlog/t/binlog_old_versions.test
      mysql-test/suite/rpl/r/rpl_change_master.result
      mysql-test/suite/rpl/r/rpl_change_master_crash_safe.result
      mysql-test/suite/rpl/r/rpl_heartbeat_basic.result
      mysql-test/suite/rpl/r/rpl_rotate_logs.result
      mysql-test/suite/rpl/r/rpl_row_conflicts.result
      mysql-test/suite/rpl/r/rpl_server_uuid.result
      mysql-test/suite/rpl/t/disabled.def
      mysql-test/suite/rpl/t/rpl_change_master.test
      mysql-test/suite/rpl/t/rpl_heartbeat_basic.test
      mysql-test/suite/rpl/t/rpl_known_bugs_detection.test
      mysql-test/suite/rpl/t/rpl_rotate_logs.test
      mysql-test/suite/rpl/t/rpl_row_ignorable_event.test
      mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test
      mysql-test/suite/rpl/t/rpl_server_uuid.test
      mysql-test/suite/rpl_ndb/t/rpl_ndb_multi.test
      mysql-test/suite/sys_vars/t/all_vars.test
      mysql-test/t/mysqlbinlog2.test
      sql/binlog.cc
      sql/binlog.h
      sql/log.cc
      sql/log_event.cc
      sql/log_event.h
      sql/mysqld.cc
      sql/mysqld.h
      sql/rpl_master.cc
      sql/rpl_mi.cc
      sql/rpl_mi.h
      sql/rpl_rli.cc
      sql/rpl_slave.cc
      sql/rpl_utility.cc
      sql/share/errmsg-utf8.txt
      sql/sql_binlog.cc
      sql/sql_class.h
      sql/sys_vars.cc
      sql/sys_vars.h
=== modified file 'client/mysqlbinlog.cc'
--- a/client/mysqlbinlog.cc	2010-11-26 13:46:21 +0000
+++ b/client/mysqlbinlog.cc	2010-11-29 11:23:33 +0000
@@ -80,6 +80,7 @@ static my_bool force_opt= 0, short_form=
 static my_bool debug_info_flag, debug_check_flag;
 static my_bool force_if_open_opt= 1, raw_mode= 0;
 static my_bool to_last_remote_log= 0, stop_never= 0;
+static my_bool opt_verify_binlog_checksum= 1;
 static ulonglong offset = 0;
 static uint stop_never_server_id= 1;
 static char* host = 0;
@@ -1149,6 +1150,9 @@ static struct my_option my_long_options[
    "Used to reserve file descriptors for use by this program.",
    &open_files_limit, &open_files_limit, 0, GET_ULONG,
    REQUIRED_ARG, MY_NFILE, 8, OS_FILE_LIMIT, 0, 1, 0},
+  {"verify-binlog-checksum", 'c', "Verify checksum binlog events.",
+   (uchar**) &opt_verify_binlog_checksum, (uchar**) &opt_verify_binlog_checksum,
+   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
   {"binlog-row-event-max-size", OPT_BINLOG_ROWS_EVENT_MAX_SIZE,
    "The maximum size of a row-based binary log event in bytes. Rows will be "
    "grouped into events smaller than this size if possible. "
@@ -1495,7 +1499,18 @@ static Exit_status check_master_version(
           "Master reported NULL for the version.");
     goto err;
   }
-
+  /* 
+     Make a notice to the server that this client
+     is checksum-aware. It does not need the first fake Rotate
+     necessary checksummed. 
+     That preference is specified below.
+  */
+  if (mysql_query(mysql, "SET @master_binlog_checksum='NONE'"))
+  {
+    error("Could not notify master about checksum awareness."
+          "Master returned '%s'", mysql_error(mysql));
+    goto err;
+  }
   delete glob_description_event;
   switch (*version) {
   case '3':
@@ -1631,7 +1646,8 @@ static Exit_status dump_remote_log_entri
     {
       if (!(ev= Log_event::read_log_event((const char*) net->read_pos + 1 ,
                                           len - 1, &error_msg,
-                                          glob_description_event)))
+                                          glob_description_event,
+                                          opt_verify_binlog_checksum)))
       {
         error("Could not construct log event object: %s", error_msg);
         DBUG_RETURN(ERROR_STOP);
@@ -1906,7 +1922,8 @@ static Exit_status check_header(IO_CACHE
         Format_description_log_event *new_description_event;
         my_b_seek(file, tmp_pos); /* seek back to event's start */
         if (!(new_description_event= (Format_description_log_event*) 
-              Log_event::read_log_event(file, glob_description_event)))
+              Log_event::read_log_event(file, glob_description_event,
+                                        opt_verify_binlog_checksum)))
           /* EOF can't be hit here normally, so it's a real error */
         {
           error("Could not read a Format_description_log_event event at "
@@ -1938,7 +1955,8 @@ static Exit_status check_header(IO_CACHE
       {
         Log_event *ev;
         my_b_seek(file, tmp_pos); /* seek back to event's start */
-        if (!(ev= Log_event::read_log_event(file, glob_description_event)))
+        if (!(ev= Log_event::read_log_event(file, glob_description_event,
+                                            opt_verify_binlog_checksum)))
         {
           /* EOF can't be hit here normally, so it's a real error */
           error("Could not read a Rotate_log_event event at offset %llu;"
@@ -2051,7 +2069,8 @@ static Exit_status dump_local_log_entrie
     char llbuff[21];
     my_off_t old_off = my_b_tell(file);
 
-    Log_event* ev = Log_event::read_log_event(file, glob_description_event);
+    Log_event* ev = Log_event::read_log_event(file, glob_description_event,
+                                              opt_verify_binlog_checksum);
     if (!ev)
     {
       /*

=== modified file 'libmysqld/CMakeLists.txt'
--- a/libmysqld/CMakeLists.txt	2010-11-24 10:50:17 +0000
+++ b/libmysqld/CMakeLists.txt	2010-11-29 11:23:33 +0000
@@ -85,8 +85,8 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc l
            ../sql/sql_alter.cc ../sql/sql_partition_admin.cc
            ../sql/event_parse_data.cc
            ../sql/sql_signal.cc ../sql/rpl_handler.cc
-           ../sql/rpl_utility.cc ../sql/binlog.cc ../sql/sys_vars.cc
-           ../sql/gcalc_slicescan.cc ../sql/gcalc_tools.cc
+           ../sql/rpl_utility.cc ../sql/rpl_reporting.cc ../sql/binlog.cc 
+           ../sql/sys_vars.cc ../sql/gcalc_slicescan.cc ../sql/gcalc_tools.cc
            ${CMAKE_BINARY_DIR}/sql/sql_builtin.cc
            ../sql/mdl.cc ../sql/transaction.cc ../sql/sql_bootstrap.cc
            ${GEN_SOURCES}

=== modified file 'mysql-test/collections/default.experimental'
--- a/mysql-test/collections/default.experimental	2010-11-27 22:36:33 +0000
+++ b/mysql-test/collections/default.experimental	2010-11-29 11:23:33 +0000
@@ -35,6 +35,7 @@ rpl.rpl_row_sp011* @solaris
 rpl.rpl_delayed_slave*                   # BUG#57514 rpl_delayed_slave fails sporadically in pb
 rpl.rpl_change_master                    # Bug#57482 2010-11-16 alfranio fails on PB2
 rpl.rpl_change_master_crash_safe         # Bug#57482 2010-11-16 alfranio fails on PB2
+rpl.rpl_seconds_behind_master            # BUG#58053 2010-11-24 luis fails sporadically on pb2
 
 sys_vars.max_sp_recursion_depth_func @solaris # Bug#47791 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun
 sys_vars.slow_query_log_func @solaris         # Bug#54819 2010-06-26 alik sys_vars.slow_query_log_func fails sporadically on Solaris 10

=== added file 'mysql-test/collections/mysql-next-mr-wl2540.push'
--- a/mysql-test/collections/mysql-next-mr-wl2540.push	1970-01-01 00:00:00 +0000
+++ b/mysql-test/collections/mysql-next-mr-wl2540.push	2010-11-11 23:33:21 +0000
@@ -0,0 +1,6 @@
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=rpl_binlog_checksum  --mysqld=--binlog-checksum=CRC32  --vardir=var-rpl_binlog_checksum --suite=binlog,rpl --skip-test-list=collections/disabled-per-push.list
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=n_mix          --vardir=var-n_mix                        --mysqld=--binlog-format=mixed  --suite=main,binlog,innodb,federated,rpl,sys_vars,perfschema --skip-test-list=collections/disabled-per-push.list
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=ps_row         --vardir=var-ps_row         --ps-protocol --mysqld=--binlog-format=row    --suite=main,binlog,innodb,federated,rpl,sys_vars,perfschema --skip-test-list=collections/disabled-per-push.list
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=embedded       --vardir=var-emebbed        --embedded                                    --suite=main,binlog,innodb,federated,rpl,sys_vars,perfschema
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=rpl_binlog_row --vardir=var-rpl_binlog_row               --mysqld=--binlog-format=row    --suite=rpl,binlog --skip-test-list=collections/disabled-per-push.list
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=funcs_1        --vardir=var-funcs_1                                                      --suite=funcs_1

=== added file 'mysql-test/collections/mysql-trunk.daily'
--- a/mysql-test/collections/mysql-trunk.daily	1970-01-01 00:00:00 +0000
+++ b/mysql-test/collections/mysql-trunk.daily	2010-11-16 11:34:55 +0000
@@ -0,0 +1,7 @@
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=n_mix          --vardir=var-n_mix                  --mysqld=--binlog-format=mixed
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=ps_row         --vardir=var-ps_row   --ps-protocol --mysqld=--binlog-format=row
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=embedded       --vardir=var-emebbed  --embedded
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=funcs_1        --vardir=var-funcs_1                                              --suite=funcs_1
+perl mysql-test-run.pl --timer --force --parallel=auto                                                 --comment=rpl_ndb_row    --vardir=var-rpl_ndb_row            --mysqld=--binlog-format=row  --suite=rpl_ndb,ndb
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=rpl_binlog_row --vardir=var-rpl_binlog_row --mysqld=--binlog-format=row --suite=rpl,binlog --skip-ndb
+perl mysql-test-run.pl --timer --force --parallel=auto --experimental=collections/default.experimental --comment=rpl_binlog_checksum  --mysqld=--binlog-checksum=CRC32  --vardir=var-rpl_binlog_checksum --suite=binlog,rpl

=== added file 'mysql-test/collections/mysql-trunk.weekly'
--- a/mysql-test/collections/mysql-trunk.weekly	1970-01-01 00:00:00 +0000
+++ b/mysql-test/collections/mysql-trunk.weekly	2010-11-16 11:34:55 +0000
@@ -0,0 +1,2 @@
+perl mysql-test-run.pl --timer --force --comment=1st --experimental=collections/default.experimental 1st
+perl mysql-test-run.pl --timer --force --comment=all_binlog_checksum --experimental=collections/default.experimental --mysqld=--binlog-checksum=CRC32 --vardir=var-all_binlog_checksum --suite=main,binlog,innodb,federated,rpl,sys_vars,perfschema

=== modified file 'mysql-test/extra/binlog_tests/binlog.test'
--- a/mysql-test/extra/binlog_tests/binlog.test	2010-11-28 10:39:14 +0000
+++ b/mysql-test/extra/binlog_tests/binlog.test	2010-11-29 11:23:33 +0000
@@ -83,17 +83,22 @@ set @bcs = @@binlog_cache_size;
 set global binlog_cache_size=4096;
 reset master;
 
-create table t1 (a int) engine=innodb;
+create table t1 (a int, b char(255)) engine=innodb;
 
-let $1=400;
+flush status;
+show status like "binlog_cache_use";
+
+let $1=100;
 disable_query_log;
 begin;
 while ($1)
 {
- eval insert into t1 values( $1 );
+ eval insert into t1 values( $1, 'just to fill void to make transaction occupying at least two buffers of the trans cache' );
  dec $1;
 }
 commit;
+--echo *** the following must show the counter value > 1 ***
+show status like "binlog_cache_use";
 enable_query_log;
 
 --source include/show_binlog_events.inc

=== modified file 'mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test'
--- a/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test	2010-11-17 10:23:22 +0000
+++ b/mysql-test/extra/binlog_tests/mix_innodb_myisam_binlog.test	2010-11-29 11:23:33 +0000
@@ -311,6 +311,7 @@ select get_lock("a",10);
 begin;
 insert into t1 values(8);
 insert into t2 select * from t1;
+
 disconnect con3;
 
 connection con4;

=== modified file 'mysql-test/extra/rpl_tests/rpl_change_master.test'
--- a/mysql-test/extra/rpl_tests/rpl_change_master.test	2010-11-27 11:34:31 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_change_master.test	2010-11-29 11:23:33 +0000
@@ -2,6 +2,8 @@
 # thread) restart from where SQL thread left, not from where
 # I/O thread left (some old bug fixed in 4.0.17)
 
+call mtr.add_suppression("Slave I/O: The slave I/O thread stops because a fatal error is encountered when it tried to SET @master_binlog_checksum");
+
 connection master;
 # Make SQL slave thread advance a bit
 create table t1(n int);

=== modified file 'mysql-test/extra/rpl_tests/rpl_conflicts.test'
--- a/mysql-test/extra/rpl_tests/rpl_conflicts.test	2010-08-05 17:45:25 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_conflicts.test	2010-10-25 19:02:24 +0000
@@ -146,7 +146,10 @@ if (`SELECT @@global.binlog_format = 'RO
   source include/wait_for_slave_sql_error.inc;
   let $err= query_get_value("SHOW SLAVE STATUS", Last_SQL_Error, 1);
   let $err= `SELECT SUBSTRING("$err" FROM 17)`;
-  --echo Last_SQL_Error = $err (expected "can't find record" error)
+  --replace_regex /end_log_pos [0-9]+/end_log_pos END_LOG_POS/
+  --disable_query_log
+  --eval SELECT "$err" as 'Last_SQL_Error (expected "duplicate key" error)'
+  --enable_query_log
   SELECT * FROM t1;
 
   --echo ---- Resolve the conflict on the slave and restart SQL thread ----

=== modified file 'mysql-test/extra/rpl_tests/rpl_flsh_tbls.test'
--- a/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test	2010-10-25 10:39:01 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test	2010-11-23 23:10:22 +0000
@@ -16,6 +16,7 @@ create table t3 (a int) engine=merge uni
 create table t4 (a int);
 # We force the slave to open t3 (because we want to try confusing him) with this :
 insert into t4 select * from t3;
+--let $rename_event_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
 rename table t1 to t5, t2 to t1;
 # RENAME may have confused the master (this is a known bug): so FLUSH tables,
 # first don't write it to the binlog, to test the NO_WRITE_TO_BINLOG keyword.

=== modified file 'mysql-test/extra/rpl_tests/rpl_reset_slave.test'
--- a/mysql-test/extra/rpl_tests/rpl_reset_slave.test	2010-06-19 09:24:34 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_reset_slave.test	2010-09-28 17:19:47 +0000
@@ -10,6 +10,9 @@
 
 -- source include/master-slave.inc
 sync_slave_with_master;
+--disable_query_log
+call mtr.add_suppression('Slave I/O: Get master BINLOG_CHECKSUM failed with error');
+--enable_query_log
 let $status_items= Master_User, Master_Host;
 source include/show_slave_status.inc;
 

=== modified file 'mysql-test/extra/rpl_tests/rpl_start_stop_slave.test'
--- a/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test	2010-10-14 01:54:07 +0000
+++ b/mysql-test/extra/rpl_tests/rpl_start_stop_slave.test	2010-11-16 12:14:06 +0000
@@ -15,7 +15,7 @@ sync_slave_with_master;
 stop slave;
 --source include/wait_for_slave_to_stop.inc
 connection master;
-let $1=5000;
+let $1=2500;
 disable_query_log;
 while ($1)
 {

=== added file 'mysql-test/include/have_binlog_checksum_off.inc'
--- a/mysql-test/include/have_binlog_checksum_off.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/have_binlog_checksum_off.inc	2010-06-14 10:04:20 +0000
@@ -0,0 +1,4 @@
+if (`select variable_value not like 'NONE' from information_schema.GLOBAL_VARIABLES
+       where variable_name='binlog_checksum'`){
+   skip Can not run the test when server activated checksumming;
+}

=== modified file 'mysql-test/include/mtr_warnings.sql'
--- a/mysql-test/include/mtr_warnings.sql	2010-11-18 15:57:46 +0000
+++ b/mysql-test/include/mtr_warnings.sql	2010-11-29 11:23:33 +0000
@@ -233,6 +233,9 @@ INSERT INTO global_suppressions VALUES
  ("Slave I/O: Get master clock failed with error:.*"),
  ("Slave I/O: Get master COLLATION_SERVER failed with error:.*"),
  ("Slave I/O: Get master TIME_ZONE failed with error:.*"),
+ ("Slave I/O: The slave I/O thread stops because a fatal error is encountered when it tried to SET @master_binlog_checksum on master.*"),
+ ("Slave I/O: Get master BINLOG_CHECKSUM failed with error.*"),
+ ("Slave I/O: Notifying master by SET @master_binlog_checksum= @@global.binlog_checksum failed with error.*"),
  /*
    BUG#42147 - Concurrent DML and LOCK TABLE ... READ for InnoDB 
    table cause warnings in errlog

=== modified file 'mysql-test/r/mysqld--help-notwin.result'
--- a/mysql-test/r/mysqld--help-notwin.result	2010-11-26 13:46:21 +0000
+++ b/mysql-test/r/mysqld--help-notwin.result	2010-11-29 11:23:33 +0000
@@ -36,6 +36,10 @@ The following options may be given as th
  binary log during a transaction. If you often use big,
  multi-statement transactions you can increase this to get
  more performance
+ --binlog-checksum=name 
+ Type of BINLOG_CHECKSUM_ALG. Include checksum for log
+ events in the binary log. Possible values are NONE and
+ CRC32; default is NONE.
  --binlog-direct-non-transactional-updates 
  Causes updates to non-transactional engines using
  statement format to be written directly to binary log.
@@ -278,6 +282,10 @@ The following options may be given as th
  The number of tries the slave will make to connect to the
  master before giving up. Deprecated option, use 'CHANGE
  MASTER TO master_retry_count = <num>' instead.
+ --master-verify-checksum 
+ Force checksum verification of logged events in binary
+ log before sending them to slaves or printing them in
+ output of SHOW BINLOG EVENTS. Disabled by default.
  --max-allowed-packet=# 
  Max packet length to send to or receive from the server
  --max-binlog-cache-size=# 
@@ -627,6 +635,13 @@ The following options may be given as th
  --slave-skip-errors=name 
  Tells the slave thread to continue replication when a
  query event returns an error from the provided list
+ --slave-sql-verify-checksum 
+ Force checksum verification of replication events after
+ reading them from relay log. Note: Events are always
+ checksum-verified by slave on receiving them from the
+ network before writing them to the relay log. Enabled by
+ default.
+ (Defaults to on; use --skip-slave-sql-verify-checksum to disable.)
  --slave-transaction-retries=# 
  Number of times the slave SQL thread will retry a
  transaction in case it failed with a deadlock or elapsed
@@ -731,6 +746,7 @@ back-log 50
 big-tables FALSE
 bind-address (No default value)
 binlog-cache-size 32768
+binlog-checksum NONE
 binlog-direct-non-transactional-updates FALSE
 binlog-format STATEMENT
 binlog-row-event-max-size 1024
@@ -810,6 +826,7 @@ lower-case-table-names 1
 master-info-file master.info
 master-info-repository FILE
 master-retry-count 86400
+master-verify-checksum FALSE
 max-allowed-packet 1048576
 max-binlog-cache-size 18446744073709547520
 max-binlog-dump-events 0
@@ -913,6 +930,7 @@ slave-compressed-protocol FALSE
 slave-exec-mode STRICT
 slave-net-timeout 3600
 slave-skip-errors (No default value)
+slave-sql-verify-checksum TRUE
 slave-transaction-retries 10
 slave-type-conversions 
 slow-launch-time 2

=== modified file 'mysql-test/r/mysqld--help-win.result'
--- a/mysql-test/r/mysqld--help-win.result	2010-11-26 13:46:21 +0000
+++ b/mysql-test/r/mysqld--help-win.result	2010-11-29 11:23:33 +0000
@@ -36,6 +36,10 @@ The following options may be given as th
  binary log during a transaction. If you often use big,
  multi-statement transactions you can increase this to get
  more performance
+ --binlog-checksum=name 
+ Type of BINLOG_CHECKSUM_ALG. Include checksum for log
+ events in the binary log. Possible values are NONE and
+ CRC32; default is NONE.
  --binlog-direct-non-transactional-updates 
  Causes updates to non-transactional engines using
  statement format to be written directly to binary log.
@@ -277,6 +281,10 @@ The following options may be given as th
  The number of tries the slave will make to connect to the
  master before giving up. Deprecated option, use 'CHANGE
  MASTER TO master_retry_count = <num>' instead.
+ --master-verify-checksum 
+ Force checksum verification of logged events in binary
+ log before sending them to slaves or printing them in
+ output of SHOW BINLOG EVENTS. Disabled by default.
  --max-allowed-packet=# 
  Max packet length to send to or receive from the server
  --max-binlog-cache-size=# 
@@ -630,6 +638,13 @@ The following options may be given as th
  --slave-skip-errors=name 
  Tells the slave thread to continue replication when a
  query event returns an error from the provided list
+ --slave-sql-verify-checksum 
+ Force checksum verification of replication events after
+ reading them from relay log. Note: Events are always
+ checksum-verified by slave on receiving them from the
+ network before writing them to the relay log. Enabled by
+ default.
+ (Defaults to on; use --skip-slave-sql-verify-checksum to disable.)
  --slave-transaction-retries=# 
  Number of times the slave SQL thread will retry a
  transaction in case it failed with a deadlock or elapsed
@@ -735,6 +750,7 @@ back-log 50
 big-tables FALSE
 bind-address (No default value)
 binlog-cache-size 32768
+binlog-checksum NONE
 binlog-direct-non-transactional-updates FALSE
 binlog-format STATEMENT
 binlog-row-event-max-size 1024
@@ -813,6 +829,7 @@ lower-case-table-names 1
 master-info-file master.info
 master-info-repository FILE
 master-retry-count 86400
+master-verify-checksum FALSE
 max-allowed-packet 1048576
 max-binlog-cache-size 18446744073709547520
 max-binlog-dump-events 0
@@ -919,6 +936,7 @@ slave-compressed-protocol FALSE
 slave-exec-mode STRICT
 slave-net-timeout 3600
 slave-skip-errors (No default value)
+slave-sql-verify-checksum TRUE
 slave-transaction-retries 10
 slave-type-conversions 
 slow-launch-time 2

=== added file 'mysql-test/suite/binlog/r/binlog_checksum.result'
--- a/mysql-test/suite/binlog/r/binlog_checksum.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/r/binlog_checksum.result	2010-06-18 10:45:52 +0000
@@ -0,0 +1,23 @@
+set @save_binlog_checksum = @@global.binlog_checksum;
+set @save_master_verify_checksum = @@global.master_verify_checksum;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 1;
+reset master;
+must be master-bin.000001 
+show binary logs;
+Log_name	File_size
+master-bin.000001	#
+create table t1 (a int);
+flush logs;
+drop table t1;
+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	#	Rotate	#	#	master-bin.000002;pos=4
+show tables;
+Tables_in_test
+t1
+drop table t1;
+set @@global.binlog_checksum = @save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+End of the tests

=== modified file 'mysql-test/suite/binlog/r/binlog_killed.result'
--- a/mysql-test/suite/binlog/r/binlog_killed.result	2010-04-28 12:47:49 +0000
+++ b/mysql-test/suite/binlog/r/binlog_killed.result	2010-07-07 17:27:55 +0000
@@ -7,6 +7,11 @@ get_lock("a", 20)
 1
 reset master;
 insert into t2 values (null, null), (null, get_lock("a", 10));
+kill query ID;
+select
+(@a:=load_file("MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
+is not null;
+set @result= 2 - 1 - 1;
 select @result /* must be zero either way */;
 @result
 0
@@ -85,20 +90,21 @@ a	b
 select @b  /* must be 1 at the end of a stmt calling bug27563() */;
 @b
 1
-must have the update query event more to FD
+must have the update query event on the 4th line
 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	#	User var	#	#	@`b`=0
 master-bin.000001	#	Query	#	#	use `test`; update t4 set b=b + bug27563(b)
 master-bin.000001	#	Query	#	#	COMMIT
+*** a proof the query is binlogged with an error ***
 select
 (@a:=load_file("MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
 is not null;
 (@a:=load_file("MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
 is not null
 1
-select 0 /* must return 0 to mean the killed query is in */;
+select 0 /* must return 0 to mean the killed update is in */;
 0
 0
 select RELEASE_LOCK("a");
@@ -123,7 +129,7 @@ count(*)
 select @b  /* must be 1 at the end of a stmt calling bug27563() */;
 @b
 1
-must have the delete query event more to FD
+must have the delete query event on the 4th line
 show binlog events from <binlog_start>;
 Log_name	Pos	Event_type	Server_id	End_log_pos	Info
 master-bin.000001	#	Query	#	#	BEGIN
@@ -136,7 +142,7 @@ is not null;
 (@a:=load_file("MYSQLTEST_VARDIR/tmp/binlog_killed_bug27571.binlog"))
 is not null
 1
-select 0 /* must return 0 to mean the killed query is in */;
+select 0 /* must return 0 to mean the killed delete is in */;
 0
 0
 select RELEASE_LOCK("a");

=== modified file 'mysql-test/suite/binlog/r/binlog_old_versions.result'
--- a/mysql-test/suite/binlog/r/binlog_old_versions.result	2008-01-30 13:12:40 +0000
+++ b/mysql-test/suite/binlog/r/binlog_old_versions.result	2010-06-14 10:04:20 +0000
@@ -39,21 +39,11 @@ SELECT COUNT(*) FROM t3;
 COUNT(*)
 17920
 DROP TABLE t1, t3;
+*** wl#2540 Replication events checksum is not yet defined 
+*** its born-version. One that is temporarily chosen conflicts with 
+*** the version in the following pre-recorded binlogs
+*** TODO: uncomment this snippet when the WL patches will be about to push
 ==== Read binlog from alcatel tree (mysql-5.1-wl2325-5.0-drop6) ====
-SELECT * FROM t1 ORDER BY a;
-a	b
-0	last_insert_id
-1	one
-3	last stm in trx: next event should be xid
-4	four
-781729	random
-SELECT * FROM t2 ORDER BY a;
-a	b
-3	first stm in trx
-SELECT COUNT(*) FROM t3;
-COUNT(*)
-17920
-DROP TABLE t1, t2, t3;
 ==== Read binlog from ndb tree (mysql-5.1-telco-6.1) ====
 SELECT * FROM t1 ORDER BY a;
 a	b

=== modified file 'mysql-test/suite/binlog/r/binlog_row_binlog.result'
--- a/mysql-test/suite/binlog/r/binlog_row_binlog.result	2010-11-29 03:17:40 +0000
+++ b/mysql-test/suite/binlog/r/binlog_row_binlog.result	2010-11-29 11:23:33 +0000
@@ -282,614 +282,22 @@ master-bin.000001	#	Query	#	#	use `test`
 set @bcs = @@binlog_cache_size;
 set global binlog_cache_size=4096;
 reset master;
-create table t1 (a int) engine=innodb;
+create table t1 (a int, b char(255)) engine=innodb;
+flush status;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	0
+*** the following must show the counter value > 1 ***
+Variable_name	Value
+Binlog_cache_use	2
 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) engine=innodb
+master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int, b char(255)) engine=innodb
+master-bin.000001	#	Query	#	#	use `test`; flush status
 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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	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	#	Table_map	#	#	table_id: # (test.t1)
 master-bin.000001	#	Write_rows	#	#	table_id: # flags: STMT_END_F

=== modified file 'mysql-test/suite/binlog/r/binlog_stm_binlog.result'
--- a/mysql-test/suite/binlog/r/binlog_stm_binlog.result	2010-11-29 03:17:40 +0000
+++ b/mysql-test/suite/binlog/r/binlog_stm_binlog.result	2010-11-29 11:23:33 +0000
@@ -166,411 +166,119 @@ master-bin.000001	#	Query	#	#	use `test`
 set @bcs = @@binlog_cache_size;
 set global binlog_cache_size=4096;
 reset master;
-create table t1 (a int) engine=innodb;
+create table t1 (a int, b char(255)) engine=innodb;
+flush status;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	0
+*** the following must show the counter value > 1 ***
+Variable_name	Value
+Binlog_cache_use	2
 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) engine=innodb
+master-bin.000001	#	Query	#	#	use `test`; create table t1 (a int, b char(255)) engine=innodb
+master-bin.000001	#	Query	#	#	use `test`; flush status
 master-bin.000001	#	Query	#	#	BEGIN
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 400 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 399 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 398 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 397 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 396 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 395 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 394 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 393 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 392 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 391 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 390 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 389 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 388 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 387 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 386 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 385 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 384 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 383 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 382 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 381 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 380 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 379 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 378 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 377 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 376 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 375 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 374 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 373 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 372 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 371 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 370 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 369 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 368 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 367 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 366 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 365 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 364 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 363 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 362 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 361 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 360 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 359 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 358 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 357 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 356 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 355 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 354 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 353 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 352 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 351 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 350 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 349 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 348 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 347 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 346 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 345 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 344 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 343 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 342 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 341 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 340 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 339 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 338 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 337 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 336 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 335 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 334 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 333 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 332 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 331 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 330 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 329 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 328 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 327 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 326 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 325 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 324 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 323 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 322 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 321 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 320 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 319 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 318 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 317 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 316 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 315 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 314 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 313 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 312 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 311 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 310 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 309 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 308 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 307 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 306 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 305 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 304 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 303 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 302 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 301 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 300 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 299 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 298 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 297 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 296 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 295 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 294 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 293 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 292 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 291 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 290 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 289 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 288 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 287 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 286 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 285 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 284 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 283 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 282 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 281 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 280 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 279 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 278 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 277 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 276 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 275 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 274 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 273 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 272 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 271 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 270 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 269 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 268 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 267 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 266 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 265 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 264 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 263 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 262 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 261 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 260 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 259 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 258 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 257 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 256 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 255 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 254 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 253 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 252 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 251 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 250 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 249 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 248 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 247 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 246 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 245 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 244 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 243 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 242 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 241 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 240 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 239 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 238 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 237 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 236 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 235 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 234 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 233 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 232 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 231 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 230 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 229 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 228 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 227 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 226 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 225 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 224 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 223 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 222 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 221 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 220 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 219 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 218 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 217 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 216 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 215 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 214 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 213 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 212 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 211 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 210 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 209 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 208 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 207 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 206 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 205 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 204 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 203 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 202 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 201 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 200 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 199 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 198 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 197 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 196 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 195 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 194 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 193 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 192 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 191 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 190 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 189 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 188 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 187 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 186 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 185 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 184 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 183 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 182 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 181 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 180 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 179 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 178 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 177 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 176 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 175 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 174 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 173 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 172 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 171 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 170 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 169 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 168 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 167 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 166 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 165 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 164 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 163 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 162 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 161 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 160 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 159 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 158 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 157 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 156 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 155 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 154 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 153 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 152 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 151 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 150 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 149 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 148 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 147 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 146 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 145 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 144 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 143 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 142 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 141 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 140 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 139 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 138 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 137 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 136 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 135 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 134 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 133 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 132 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 131 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 130 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 129 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 128 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 127 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 126 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 125 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 124 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 123 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 122 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 121 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 120 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 119 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 118 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 117 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 116 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 115 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 114 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 113 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 112 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 111 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 110 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( <binlog_start> )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 108 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 107 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 106 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 105 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 104 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 103 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 102 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 101 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 100 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 99 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 98 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 97 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 96 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 95 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 94 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 93 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 92 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 91 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 90 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 89 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 88 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 87 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 86 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 85 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 84 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 83 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 82 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 81 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 80 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 79 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 78 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 77 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 76 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 75 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 74 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 73 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 72 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 71 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 70 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 69 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 68 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 67 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 66 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 65 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 64 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 63 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 62 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 61 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 60 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 59 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 58 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 57 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 56 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 55 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 54 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 53 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 52 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 51 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 50 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 49 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 48 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 47 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 46 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 45 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 44 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 43 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 42 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 41 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 40 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 39 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 38 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 37 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 36 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 35 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 34 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 33 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 32 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 31 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 30 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 29 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 28 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 27 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 26 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 25 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 24 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 23 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 22 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 21 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 20 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 19 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 18 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 17 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 16 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 15 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 14 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 13 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 12 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 11 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 10 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 9 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 8 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 7 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 6 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 5 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 4 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 3 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 2 )
-master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 1 )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 100, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 99, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 98, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 97, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 96, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 95, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 94, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 93, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 92, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 91, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 90, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 89, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 88, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 87, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 86, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 85, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 84, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 83, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 82, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 81, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 80, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 79, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 78, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 77, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 76, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 75, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 74, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 73, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 72, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 71, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 70, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 69, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 68, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 67, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 66, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 65, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 64, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 63, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 62, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 61, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 60, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 59, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 58, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 57, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 56, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 55, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 54, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 53, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 52, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 51, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 50, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 49, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 48, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 47, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 46, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 45, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 44, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 43, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 42, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 41, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 40, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 39, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 38, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 37, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 36, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 35, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 34, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 33, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 32, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 31, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 30, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 29, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 28, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 27, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 26, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 25, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 24, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 23, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 22, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 21, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 20, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 19, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 18, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 17, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 16, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 15, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 14, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 13, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 12, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 11, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 10, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 9, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 8, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 7, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 6, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 5, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 4, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 3, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 2, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
+master-bin.000001	#	Query	#	#	use `test`; insert into t1 values( 1, 'just to fill void to make transaction occupying at least two buffers of the trans cache' )
 master-bin.000001	#	Xid	#	#	COMMIT /* XID */
 master-bin.000001	#	Rotate	#	#	master-bin.000002;pos=4
 drop table t1;

=== added file 'mysql-test/suite/binlog/t/binlog_checksum.test'
--- a/mysql-test/suite/binlog/t/binlog_checksum.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/binlog/t/binlog_checksum.test	2010-06-18 10:45:52 +0000
@@ -0,0 +1,37 @@
+source include/have_innodb.inc;
+source include/have_log_bin.inc;
+
+#
+# WL#2540 replication event checksum
+#
+# Objectives of the test are:
+# to demo binlog events with CRC32 checksum in them and 
+# to prove show binlog events and mysqlbinlog are capable to handle 
+# the checksum.
+#
+
+set @save_binlog_checksum = @@global.binlog_checksum;
+set @save_master_verify_checksum = @@global.master_verify_checksum;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 1;
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+reset master; 
+--echo must be master-bin.000001 
+--source include/show_binary_logs.inc
+
+create table t1 (a int);
+flush logs;
+drop table t1;
+
+--source include/show_binlog_events.inc
+--exec $MYSQL_BINLOG -c $MYSQLD_DATADIR/master-bin.000001 | $MYSQL
+show tables;
+
+# clean-up 
+
+drop table t1;
+set @@global.binlog_checksum = @save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+
+--echo End of the tests

=== modified file 'mysql-test/suite/binlog/t/binlog_killed.test'
--- a/mysql-test/suite/binlog/t/binlog_killed.test	2010-09-26 23:06:44 +0000
+++ b/mysql-test/suite/binlog/t/binlog_killed.test	2010-10-25 19:02:24 +0000
@@ -36,16 +36,20 @@ let $ID= `select connection_id()`;
 # `reset master' problem is to be addressed by bug#15580 fixes.
 #
 reset master;
-let $start_pos= query_get_value("SHOW MASTER STATUS", Position, 1);
 send insert into t2 values (null, null), (null, get_lock("a", 10));
 
 
 connection con1;
 
-disable_abort_on_error;
-disable_query_log;
-disable_result_log;
+--disable_abort_on_error
+--disable_warnings
+
+let $wait_condition=
+  select count(*) = 1 from information_schema.processlist
+  where info like "%insert into t2 values%" and state like 'User lock';
+--source include/wait_condition.inc
 
+--replace_regex /[0-9]+/ID/
 eval kill query $ID;
 
 connection con2;
@@ -53,19 +57,23 @@ connection con2;
 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=$start_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
+
+--let $binlog_killed_pos=query_get_value(SHOW BINLOG EVENTS, Pos, 4)
+--let $binlog_killed_end_log_pos=query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
+--exec $MYSQL_BINLOG --force-if-open --start-position=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--disable_result_log
 eval select
 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/kill_query_calling_sp.binlog"))
 is not null;
+--enable_result_log
 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
 let $error_code= `select @a like "%#%error_code=0%" /* must return 1 or 0*/`;
 let $insert_binlogged= `select @a like "%insert into%" /* must return 1 or 0 */`;
-eval set @result= $rows- $error_code - $insert_binlogged;
+eval set @result= $rows - $error_code - $insert_binlogged;
 
-enable_abort_on_error;
-enable_query_log;
-enable_result_log;
+--enable_warnings
+--enable_abort_on_error
 
 if (`SELECT @result != 0`)
 {
@@ -267,19 +275,21 @@ connection con2;
 reap;
 select * from t4 order by b /* must be (1,1), (1,2) */;
 select @b  /* must be 1 at the end of a stmt calling bug27563() */;
---echo must have the update query event more to FD
+--echo must have the update query event on the 4th line
 source include/show_binlog_events.inc;
+--let $binlog_killed_pos= query_get_value(SHOW BINLOG EVENTS, Pos, 4)
+--let $binlog_killed_end_log_pos= query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
 
-# a proof the query is binlogged with an error
+--echo *** a proof the query is binlogged with an error ***
 
---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=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $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"))
 is not null;
 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
 let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
-eval select $error_code /* must return 0 to mean the killed query is in */;
+eval select $error_code /* must return 0 to mean the killed update is in */;
 
 # cleanup for the sub-case
 connection con1;
@@ -313,19 +323,21 @@ connection con2;
 reap;
 select count(*) from t4 /* must be 1 */;
 select @b  /* must be 1 at the end of a stmt calling bug27563() */;
---echo must have the delete query event more to FD
+--echo must have the delete query event on the 4th line
 source include/show_binlog_events.inc;
+--let $binlog_killed_pos= query_get_value(SHOW BINLOG EVENTS, Pos, 4)
+--let $binlog_killed_end_log_pos= query_get_value(SHOW BINLOG EVENTS, End_log_pos, 4)
 
 # a proof the query is binlogged with an error
 
---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=$binlog_killed_pos --stop-position=$binlog_killed_end_log_pos $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"))
 is not null;
 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
 let $error_code= `select @a like "%#%error_code=0%" /* must return 0*/`;
-eval select $error_code /* must return 0 to mean the killed query is in */;
+eval select $error_code /* must return 0 to mean the killed delete is in */;
 
 # cleanup for the sub-case
 connection con1;

=== modified file 'mysql-test/suite/binlog/t/binlog_old_versions.test'
--- a/mysql-test/suite/binlog/t/binlog_old_versions.test	2008-02-07 11:38:13 +0000
+++ b/mysql-test/suite/binlog/t/binlog_old_versions.test	2010-06-14 10:04:20 +0000
@@ -67,6 +67,11 @@ SELECT COUNT(*) FROM t3;
 DROP TABLE t1, t3;
 
 
+--echo *** wl#2540 Replication events checksum is not yet defined 
+--echo *** its born-version. One that is temporarily chosen conflicts with 
+--echo *** the version in the following pre-recorded binlogs
+--echo *** TODO: uncomment this snippet when the WL patches will be about to push
+
 --echo ==== Read binlog from alcatel tree (mysql-5.1-wl2325-5.0-drop6) ====
 
 # In this version, it was not possible to switch between row-based and
@@ -75,15 +80,15 @@ DROP TABLE t1, t3;
 # replication.
 
 # Read rbr binlog.
---exec $MYSQL_BINLOG --local-load=$MYSQLTEST_VARDIR/tmp/ suite/binlog/std_data/ver_5_1-wl2325_r.001 | $MYSQL --local-infile=1
-# Read stm binlog.
---exec $MYSQL_BINLOG --local-load=$MYSQLTEST_VARDIR/tmp/ suite/binlog/std_data/ver_5_1-wl2325_s.001 | $MYSQL --local-infile=1
-# Show result.
-SELECT * FROM t1 ORDER BY a;
-SELECT * FROM t2 ORDER BY a;
-SELECT COUNT(*) FROM t3;
-# Reset.
-DROP TABLE t1, t2, t3;
+# --exec $MYSQL_BINLOG --local-load=$MYSQLTEST_VARDIR/tmp/ suite/binlog/std_data/ver_5_1-wl2325_r.001 | $MYSQL --local-infile=1
+# # Read stm binlog.
+# --exec $MYSQL_BINLOG --local-load=$MYSQLTEST_VARDIR/tmp/ suite/binlog/std_data/ver_5_1-wl2325_s.001 | $MYSQL --local-infile=1
+# # Show result.
+# SELECT * FROM t1 ORDER BY a;
+# SELECT * FROM t2 ORDER BY a;
+# SELECT COUNT(*) FROM t3;
+# # Reset.
+# DROP TABLE t1, t2, t3;
 
 
 --echo ==== Read binlog from ndb tree (mysql-5.1-telco-6.1) ====

=== added file 'mysql-test/suite/rpl/extension/README.checksum'
--- a/mysql-test/suite/rpl/extension/README.checksum	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/extension/README.checksum	2010-10-27 10:47:25 +0000
@@ -0,0 +1,23 @@
+Binlog checksum testing
+=======================
+
+1. How it works.
+The script copies a <suite> to directory <suite>_checksum, 
+collects test case names for t/ directory (except tests from
+disabled def), randomly choose 90% of tests and add them 
+to disabled.def.
+It means that mtr will run only 10% of random tests from each 
+suite.
+At end the script run mtr:
+./mysql-test-run.pl --suite=aaa_checksum,bbb_checksum \
+    --mysqld=--binlog-checksum=CRC32 arg1 ... argN
+
+aaa,bbb 	- suite names from --suite option
+arg1,argN	- other command-line arguments of checksum.pl
+
+2. The options:
+
+--suite=suite1,suite2.  Mandatory option. The list of suites for 
+    binlog checksum testing.
+
+--percent=N, where N is 1..99. Percent of running tests. 

=== added file 'mysql-test/suite/rpl/extension/checksum.pl'
--- a/mysql-test/suite/rpl/extension/checksum.pl	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/extension/checksum.pl	2010-10-27 10:47:25 +0000
@@ -0,0 +1,164 @@
+#!/usr/bin/perl
+
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# 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
+
+use File::Basename;
+use File::Copy qw(copy);
+use File::Spec qw(catdir);
+use File::Path;
+use IO::File;
+use strict;
+
+# Constants and variables with default values
+my $suites;
+my $suffix = "_checksum";
+my $percent_random_test = 10;
+my $mtr_script;
+my @mtr_argv;
+my @mtr_suites;
+
+# Check some arguments
+foreach my $arg ( @ARGV )
+{
+    if ($arg =~ m/\-\-suite\=(.+)/i)
+    {
+        $suites = $1;
+    }
+    elsif ($arg =~ m/\-\-percent\=(\d{1,2})/i)
+    {
+	$percent_random_test= $1;
+    }
+    else
+    {
+	push(@mtr_argv, $arg);
+    }
+    
+}
+if (! defined( $suites ) )
+{
+    die("The script requires --suite argument");
+}
+
+print "#################################################################\n";
+print "# Binlog checksum testing\n";
+print "# Run randomly $percent_random_test\% of tests from following suites: $suites\n";
+print "#################################################################\n";
+
+# Set extension directory
+my $ext_dir= dirname(File::Spec->rel2abs($0));
+# Set mysql-test directory
+my $mysql_test_dir= $ext_dir;
+$mysql_test_dir =~ s/(\/|\\)suite(\/|\\)rpl(\/|\\)extension$//;
+
+# Main loop
+foreach my $src_suite (split(",", $suites))
+{
+    $src_suite=~ s/ //g;
+    my $dest_suite= $src_suite . $suffix;
+    push( @mtr_suites, $dest_suite);
+    print "Creating suite $dest_suite\n";
+    # *** Set platform-independent pathes ***
+    # Set source directory of suite
+    my $src_suite_dir = File::Spec->catdir($mysql_test_dir, "suite", $src_suite);
+    # Set destination directory of suite
+    my $dest_suite_dir = File::Spec->catdir($mysql_test_dir, "suite", $dest_suite);
+    print "Copying files\n\tfrom '$src_suite_dir'\n\tto '$dest_suite_dir'\n";
+    dircopy($src_suite_dir, $dest_suite_dir);
+    my $test_case_dir= File::Spec->catdir($dest_suite_dir, "t");
+    # Read disabled.def
+    my %disabled = ();
+    print "Read disabled.def\n";
+    my $fh = new IO::File File::Spec->catdir($test_case_dir, "disabled.def"), "r";
+    if ( defined $fh ) 
+    {
+	my @lines = <$fh>;
+	undef $fh;
+	foreach my $line ( @lines )
+	{
+	    if ($line =~ m/^([a-zA-Z0-9_]+).+\:.+/i)
+	    {
+		$disabled{$1}= 1;
+	    }
+	}
+    }
+    # Read test case list
+    my %tests = ();
+    print "Generate test case list\n";
+    opendir my ($dh), $test_case_dir or die "Could not open dir '$test_case_dir': $!";
+    for my $entry (readdir $dh) 
+    {
+	if ( $entry =~ m/^([a-zA-Z0-9_]+)\.test$/i )
+	{
+	    my $test= $1;
+	    if ( ! defined( $disabled{$test}) )
+	    {
+		$tests{$test}= 1;
+	    }
+	}
+    }
+    closedir($dh);
+    # 
+    my @excluded = ();
+    my $excluded_test= int((((100 - $percent_random_test)/100) * scalar( keys %tests )));
+    while  ( $excluded_test > 0 )
+    {
+	my @cases = keys %tests;
+	my $test = $cases[int(rand(scalar(@cases)))];
+	push ( @excluded, $test . "\t\t: Excluded for $dest_suite\n" );
+	delete $tests{$test};		
+	$excluded_test--;
+    }
+    my $fh = new IO::File File::Spec->catdir($test_case_dir, "disabled.def"), O_WRONLY|O_APPEND;
+    if (defined $fh) {
+	print $fh join ("", sort @excluded);
+	undef $fh;
+    }
+    print "\t" . join("\n\t", sort keys %tests) . "\n";
+    
+}
+
+# Set path to mtr with arguments
+my $mtr_script = "perl " . File::Spec->catdir($mysql_test_dir, "mysql-test-run.pl") . 
+    " --suite=" . join(",", @mtr_suites) . " " . 
+    " --mysqld=--binlog-checksum=CRC32 " . 
+    join (" ", @mtr_argv);
+
+print "Run $mtr_script\n";
+system( $mtr_script );
+
+sub dircopy
+{
+    my ($from_dir, $to_dir)= @_;
+    mkdir $to_dir if (! -e $to_dir);
+    opendir my($dh), $from_dir or die "Could not open dir '$from_dir': $!";
+    for my $entry (readdir $dh) 
+    {
+	next if $entry =~ /^(\.|\.\.)$/;
+        my $source = File::Spec->catdir($from_dir, $entry);
+        my $destination = File::Spec->catdir($to_dir, $entry);
+        if (-d $source) 
+        {
+    	    mkdir $destination or die "mkdir '$destination' failed: $!" if not -e $destination;
+            dircopy($source, $destination);
+        } 
+        else 
+        {
+    	    copy($source, $destination) or die "copy '$source' to '$destination' failed: $!";
+        }
+    }
+    closedir $dh;
+    return;                                                                                                  
+}

=== modified file 'mysql-test/suite/rpl/r/rpl_change_master.result'
--- a/mysql-test/suite/rpl/r/rpl_change_master.result	2010-11-26 14:02:14 +0000
+++ b/mysql-test/suite/rpl/r/rpl_change_master.result	2010-11-29 11:23:33 +0000
@@ -4,6 +4,7 @@ reset master;
 reset slave;
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
 start slave;
+call mtr.add_suppression("Slave I/O: The slave I/O thread stops because a fatal error is encountered when it tried to SET @master_binlog_checksum");
 create table t1(n int);
 select * from t1;
 n

=== modified file 'mysql-test/suite/rpl/r/rpl_change_master_crash_safe.result'
--- a/mysql-test/suite/rpl/r/rpl_change_master_crash_safe.result	2010-11-26 14:02:14 +0000
+++ b/mysql-test/suite/rpl/r/rpl_change_master_crash_safe.result	2010-11-29 11:23:33 +0000
@@ -4,6 +4,7 @@ reset master;
 reset slave;
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
 start slave;
+call mtr.add_suppression("Slave I/O: The slave I/O thread stops because a fatal error is encountered when it tried to SET @master_binlog_checksum");
 create table t1(n int);
 select * from t1;
 n

=== added file 'mysql-test/suite/rpl/r/rpl_checksum.result'
--- a/mysql-test/suite/rpl/r/rpl_checksum.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_checksum.result	2010-10-28 10:45:52 +0000
@@ -0,0 +1,124 @@
+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('Slave can not handle replication events with the checksum that master is configured to log');
+call mtr.add_suppression('Replication event checksum verification failed');
+call mtr.add_suppression('Relay log write failure: could not queue event from master');
+set @master_save_binlog_checksum= @@global.binlog_checksum;
+set @save_master_verify_checksum =  @@global.master_verify_checksum;
+select @@global.binlog_checksum as 'must be CRC32 because of the command line option';
+must be CRC32 because of the command line option
+CRC32
+select @@session.binlog_checksum as 'no session var';
+ERROR HY000: Variable 'binlog_checksum' is a GLOBAL variable
+select @@global.master_verify_checksum  as 'must be zero because of default';
+must be zero because of default
+0
+select @@session.master_verify_checksum  as 'no session var';
+ERROR HY000: Variable 'master_verify_checksum' is a GLOBAL variable
+set @slave_save_binlog_checksum= @@global.binlog_checksum;
+set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum;
+select @@global.slave_sql_verify_checksum  as 'must be one because of default';
+must be one because of default
+1
+select @@session.slave_sql_verify_checksum  as 'no session var';
+ERROR HY000: Variable 'slave_sql_verify_checksum' is a GLOBAL variable
+show binary logs;
+Log_name	File_size
+master-bin.000001	#
+set @@global.binlog_checksum = NONE;
+*** must be rotations seen ***
+show binary logs;
+Log_name	File_size
+master-bin.000001	#
+master-bin.000002	#
+set @@global.binlog_checksum = default;
+set @@global.binlog_checksum = CRC32;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+set @@global.binlog_checksum = ADLER32;
+ERROR 42000: Variable 'binlog_checksum' can't be set to the value of 'ADLER32'
+set @@global.master_verify_checksum = 2;
+ERROR 42000: Variable 'master_verify_checksum' can't be set to the value of '2'
+set @@global.slave_sql_verify_checksum = 0;
+set @@global.slave_sql_verify_checksum = default;
+set @@global.slave_sql_verify_checksum = 2;
+ERROR 42000: Variable 'slave_sql_verify_checksum' can't be set to the value of '2'
+set @@global.binlog_checksum = NONE;
+create table t1 (a int);
+flush logs;
+flush logs;
+flush logs;
+flush logs;
+flush logs;
+flush logs;
+select count(*) as zero from t1;
+zero
+0
+include/stop_slave.inc
+set @@global.binlog_checksum = CRC32;
+insert into t1 values (1) /* will not be applied on slave due to simulation */;
+set @@global.debug='d,simulate_slave_unaware_checksum';
+start slave;
+*** Got IO thread error code: 1236, text: Got fatal error 1236 from master when reading data from binary log: 'Slave can not handle replication events with the checksum that master is configured to log' ***
+select count(*) as zero from t1;
+zero
+0
+set @@global.debug='';
+include/start_slave.inc
+set @@global.master_verify_checksum = 1;
+set @@session.debug='d,simulate_checksum_test_failure';
+show binlog events;
+ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
+set @@session.debug='';
+set @@global.master_verify_checksum = default;
+include/stop_slave.inc
+create table t2 (a int);
+set @@global.debug='d,simulate_checksum_test_failure';
+start slave io_thread;
+*** Got IO thread error code: 1595, text: Relay log write failure: could not queue event from master ***
+set @@global.debug='';
+start slave io_thread;
+set @@global.slave_sql_verify_checksum = 1;
+set @@global.debug='d,simulate_checksum_test_failure';
+start slave sql_thread;
+*** Got SQL thread error code: 1593, text: Error initializing relay log position: I/O error reading event at position 4 ***
+set @@global.debug='';
+include/start_slave.inc
+select count(*) as 'must be zero' from t2;
+must be zero
+0
+stop slave;
+reset slave;
+set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE");
+flush logs;
+set @@global.binlog_checksum= CRC32;
+reset master;
+flush logs;
+create table t3 (a int, b char(5));
+include/start_slave.inc
+select count(*) as 'must be zero' from t3;
+must be zero
+0
+include/stop_slave.inc
+change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root';
+flush logs;
+reset master;
+insert into t3 value (1, @@global.binlog_checksum);
+include/start_slave.inc
+flush logs;
+select count(*) as 'must be one' from t3;
+must be one
+1
+set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE");
+insert into t3 value (1, @@global.binlog_checksum);
+drop table t1, t2, t3;
+set @@global.binlog_checksum = @master_save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+set @@global.binlog_checksum = @slave_save_binlog_checksum;
+set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum;
+End of tests

=== added file 'mysql-test/suite/rpl/r/rpl_checksum_cache.result'
--- a/mysql-test/suite/rpl/r/rpl_checksum_cache.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_checksum_cache.result	2010-11-11 02:11:10 +0000
@@ -0,0 +1,123 @@
+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("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement: insert into t2 set data=repeat.*'a', @act_size.*");
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement: insert into t1 values.* NAME_CONST.*'n',.*, @data .*");
+set @save_binlog_cache_size = @@global.binlog_cache_size;
+set @save_binlog_checksum = @@global.binlog_checksum;
+set @save_master_verify_checksum = @@global.master_verify_checksum;
+set @@global.binlog_cache_size = 4096;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 1;
+include/stop_slave.inc
+include/start_slave.inc
+flush status;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	0
+show status like "binlog_cache_disk_use";
+Variable_name	Value
+Binlog_cache_disk_use	0
+drop table if exists t1;
+create table t1 (a int PRIMARY KEY, b CHAR(32)) engine=innodb;
+create procedure test.p_init (n int, size int) 
+begin
+while n > 0 do
+select round(RAND() * size) into @act_size;
+set @data = repeat('a', @act_size);
+insert into t1 values(n, @data );
+set n= n-1;
+end while;
+end|
+begin;
+call test.p_init(4000, 32);
+commit;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	2
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name	Value
+Binlog_cache_disk_use	1
+Comparing tables master:test.t1 and slave:test.t1
+begin;
+delete from t1;
+commit;
+flush status;
+create table t2(a int auto_increment primary key, data VARCHAR(12288)) ENGINE=Innodb;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	2
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name	Value
+Binlog_cache_disk_use	1
+Comparing tables master:test.t2 and slave:test.t2
+begin;
+delete from t2;
+commit;
+flush status;
+create table t3(a int auto_increment primary key, data VARCHAR(8192)) engine=innodb;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	2
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name	Value
+Binlog_cache_disk_use	1
+Comparing tables master:test.t3 and slave:test.t3
+begin;
+delete from t3;
+commit;
+flush status;
+create procedure test.p1 (n int) 
+begin
+while n > 0 do
+case (select (round(rand()*100) % 3) + 1)
+when 1 then
+select round(RAND() * 32) into @act_size;
+set @data = repeat('a', @act_size);
+insert into t1 values(n, @data);
+when 2 then
+begin
+select round(8192 + RAND() * 4096) into @act_size;
+insert into t2 set data=repeat('a', @act_size);
+end;
+when 3 then
+begin
+select round(3686.4000 + RAND() * 819.2000) into @act_size;
+insert into t3 set data= repeat('a', @act_size);
+end;
+end case;
+set n= n-1;
+end while;
+end|
+set autocommit= 0;
+begin;
+call test.p1(1000);
+commit;
+show status like "binlog_cache_use";
+Variable_name	Value
+Binlog_cache_use	2
+*** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+Variable_name	Value
+Binlog_cache_disk_use	1
+Comparing tables master:test.t1 and slave:test.t1
+Comparing tables master:test.t2 and slave:test.t2
+Comparing tables master:test.t3 and slave:test.t3
+begin;
+delete from t1;
+delete from t2;
+delete from t3;
+commit;
+drop table t1, t2, t3;
+set @@global.binlog_cache_size = @save_binlog_cache_size;
+set @@global.binlog_checksum = @save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+drop procedure test.p_init;
+drop procedure test.p1;
+End of tests

=== added file 'mysql-test/suite/rpl/r/rpl_corruption.result'
--- a/mysql-test/suite/rpl/r/rpl_corruption.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_corruption.result	2010-11-11 02:11:10 +0000
@@ -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;
+call mtr.add_suppression('Found invalid event in binary log');
+call mtr.add_suppression('Slave I/O: Relay log write failure: could not queue event from master');
+call mtr.add_suppression('event read from binlog did not pass crc check');
+call mtr.add_suppression('Replication event checksum verification failed');
+SET @old_master_verify_checksum = @@master_verify_checksum;
+# 1. Creating test table/data and set corruption position for testing
+* insert/update/delete rows in table t1 *
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c VARCHAR(100));
+include/stop_slave.inc
+# 2. Corruption in master binlog and SHOW BINLOG EVENTS
+SET GLOBAL debug="+d,corrupt_read_log_event_char";
+SHOW BINLOG EVENTS;
+ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
+SET GLOBAL debug="-d,corrupt_read_log_event_char";
+# 3. Master read a corrupted event from binlog and send the error to slave
+SET GLOBAL debug="+d,corrupt_read_log_event";
+START SLAVE IO_THREAD;
+SET GLOBAL debug="-d,corrupt_read_log_event";
+# 4. Master read a corrupted event from binlog and send it to slave
+SET GLOBAL master_verify_checksum=0;
+SET GLOBAL debug="+d,corrupt_read_log_event";
+START SLAVE IO_THREAD;
+SET GLOBAL debug="-d,corrupt_read_log_event";
+SET GLOBAL master_verify_checksum=1;
+# 5. Slave. Corruption in network
+SET GLOBAL debug="+d,corrupt_queue_event";
+START SLAVE IO_THREAD;
+SET GLOBAL debug="-d,corrupt_queue_event";
+# 6. Slave. Corruption in relay log
+SET GLOBAL debug="+d,corrupt_read_log_event_char";
+START SLAVE;
+SET GLOBAL debug="-d,corrupt_read_log_event_char";
+# 7. Seek diff for tables on master and slave
+include/start_slave.inc
+Comparing tables master:test.t1 and slave:test.t1
+# 8. Clean up
+SET GLOBAL debug= "";
+SET GLOBAL master_verify_checksum = @old_master_verify_checksum;
+DROP TABLE t1;
+SET GLOBAL debug= "";

=== modified file 'mysql-test/suite/rpl/r/rpl_heartbeat_basic.result'
--- a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result	2010-10-21 11:34:17 +0000
+++ b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result	2010-11-16 12:14:06 +0000
@@ -4,6 +4,7 @@ reset master;
 reset slave;
 drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
 start slave;
+call mtr.add_suppression("Slave I/O: The slave I/O thread stops because a fatal error is encountered when it tried to SET @master_binlog_checksum");
 
 *** Preparing ***
 include/stop_slave.inc

=== modified file 'mysql-test/suite/rpl/r/rpl_rotate_logs.result'
--- a/mysql-test/suite/rpl/r/rpl_rotate_logs.result	2010-08-05 17:45:25 +0000
+++ b/mysql-test/suite/rpl/r/rpl_rotate_logs.result	2010-10-25 19:02:24 +0000
@@ -74,7 +74,7 @@ insert into temp_table values ("testing
 create table t3 (n int);
 select count(*) from t3 where n >= 4;
 count(*)
-100
+90
 create table t4 select * from temp_table;
 show binary logs;
 Log_name	File_size
@@ -96,7 +96,7 @@ Checking that both slave threads are run
 lock tables t3 read;
 select count(*) from t3 where n >= 4;
 count(*)
-100
+90
 unlock tables;
 drop table if exists t1,t2,t3,t4;
 End of 4.1 tests

=== modified file 'mysql-test/suite/rpl/r/rpl_row_conflicts.result'
--- a/mysql-test/suite/rpl/r/rpl_row_conflicts.result	2010-09-01 02:51:08 +0000
+++ b/mysql-test/suite/rpl/r/rpl_row_conflicts.result	2010-10-25 19:02:24 +0000
@@ -51,7 +51,8 @@ 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 985 (expected "can't find record" error)
+Last_SQL_Error (expected "duplicate key" 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 END_LOG_POS
 SELECT * FROM t1;
 a
 ---- Resolve the conflict on the slave and restart SQL thread ----

=== modified file 'mysql-test/suite/rpl/r/rpl_server_uuid.result'
--- a/mysql-test/suite/rpl/r/rpl_server_uuid.result	2010-10-08 14:23:55 +0000
+++ b/mysql-test/suite/rpl/r/rpl_server_uuid.result	2010-10-25 19:02:24 +0000
@@ -8,6 +8,8 @@ call mtr.add_suppression("Slave I/O thre
 call mtr.add_suppression("Slave I/O: Master command COM_REGISTER_SLAVE failed: .*");
 CALL mtr.add_suppression(".*master and slave have equal MySQL server UUIDs.*");
 CALL mtr.add_suppression("Master's UUID has changed, its old UUID is.*");
+CALL mtr.add_suppression("Slave I/O: SET @master_heartbeat_period to master failed with error: Lost connection to MySQL server during query");
+CALL mtr.add_suppression("Notifying master by SET @master_binlog_checksum= @@global.binlog_checksum failed with error");
 
 # Case 1:
 # Master's UUID appears in the result of 'SHOW SLAVE STATUS'.

=== modified file 'mysql-test/suite/rpl/t/disabled.def'
--- a/mysql-test/suite/rpl/t/disabled.def	2010-11-25 10:56:45 +0000
+++ b/mysql-test/suite/rpl/t/disabled.def	2010-11-29 11:23:33 +0000
@@ -12,5 +12,7 @@
 
 rpl_row_create_table      : Bug#51574 2010-02-27 andrei failed different way than earlier with bug#45576
 rpl_spec_variables        : BUG#47661 2009-10-27 jasonh rpl_spec_variables fails on PB2 hpux
+rpl_row_event_max_size    : Bug#55675 2010-10-25 andrei mysql_binlog_send attempts to read events partly
+rpl_delayed_slave         : Bug#57514 2010-11-09 andrei rpl_delayed_slave fails sporadically in pb
 rpl_log_pos               : BUG#55675 2010-09-10 alfranio rpl.rpl_log_pos fails sporadically with error binlog truncated in the middle
 rpl_trigger               : BUG#58258 2010-11-17 VasilDimov Valgrind: possibly lost from ib_bh_create()

=== modified file 'mysql-test/suite/rpl/t/rpl_change_master.test'
--- a/mysql-test/suite/rpl/t/rpl_change_master.test	2010-11-27 11:34:31 +0000
+++ b/mysql-test/suite/rpl/t/rpl_change_master.test	2010-11-29 11:23:33 +0000
@@ -1,4 +1,4 @@
-#
+
 # This test calls CHANGE MASTER in order to check if replication can
 # restart from where SQL thread left, not from where I/O thread left.
 #  

=== added file 'mysql-test/suite/rpl/t/rpl_checksum-master.opt'
--- a/mysql-test/suite/rpl/t/rpl_checksum-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_checksum-master.opt	2010-06-14 10:04:20 +0000
@@ -0,0 +1 @@
+--binlog-checksum=CRC32

=== added file 'mysql-test/suite/rpl/t/rpl_checksum.test'
--- a/mysql-test/suite/rpl/t/rpl_checksum.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_checksum.test	2010-09-28 15:42:48 +0000
@@ -0,0 +1,247 @@
+# WL2540 replication events checksum
+# Testing configuration parameters
+
+--source include/master-slave.inc
+--source include/have_debug.inc
+--source include/have_binlog_format_mixed.inc
+
+call mtr.add_suppression('Slave can not handle replication events with the checksum that master is configured to log');
+call mtr.add_suppression('Replication event checksum verification failed');
+# due to C failure simulation
+call mtr.add_suppression('Relay log write failure: could not queue event from master');
+
+# A. read/write access to the global vars:
+# binlog_checksum master_verify_checksum slave_sql_verify_checksum
+
+connection master;
+
+set @master_save_binlog_checksum= @@global.binlog_checksum;
+set @save_master_verify_checksum =  @@global.master_verify_checksum;
+
+select @@global.binlog_checksum as 'must be CRC32 because of the command line option';
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.binlog_checksum as 'no session var';
+
+select @@global.master_verify_checksum  as 'must be zero because of default';
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.master_verify_checksum  as 'no session var';
+
+connection slave;
+
+set @slave_save_binlog_checksum= @@global.binlog_checksum;
+set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum;
+
+select @@global.slave_sql_verify_checksum  as 'must be one because of default';
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.slave_sql_verify_checksum  as 'no session var';
+
+connection master;
+
+source include/show_binary_logs.inc;
+set @@global.binlog_checksum = NONE;
+--echo  *** must be rotations seen ***
+source include/show_binary_logs.inc;
+
+set @@global.binlog_checksum = default;
+
+# testing lack of side-effects in non-effective update of binlog_checksum:
+set @@global.binlog_checksum = CRC32;
+set @@global.binlog_checksum = CRC32; 
+
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+
+--error ER_WRONG_VALUE_FOR_VAR
+set @@global.binlog_checksum = ADLER32;
+--error ER_WRONG_VALUE_FOR_VAR
+set @@global.master_verify_checksum = 2; # the var is of bool type
+
+connection slave;
+
+set @@global.slave_sql_verify_checksum = 0;
+set @@global.slave_sql_verify_checksum = default;
+--error ER_WRONG_VALUE_FOR_VAR
+set @@global.slave_sql_verify_checksum = 2; # the var is of bool type
+
+#
+# B. Old Slave to New master conditions
+#
+# while master does not send a checksum-ed binlog the Old Slave can
+# work with the New Master
+
+connection master;
+
+set @@global.binlog_checksum = NONE;
+create table t1 (a int);
+
+# testing that binlog rotation preserves opt_binlog_checksum value
+flush logs;
+flush logs;
+flush logs;
+
+sync_slave_with_master;
+#connection slave;
+# checking that rotation on the slave side leaves slave stable
+flush logs;
+flush logs;
+flush logs;
+select count(*) as zero from t1;
+
+source include/stop_slave.inc;
+
+connection master;
+set @@global.binlog_checksum = CRC32;
+insert into t1 values (1) /* will not be applied on slave due to simulation */;
+
+# instruction to the dump thread
+### set @@global.debug='d,simulate_slave_unaware_checksum'; # merge todo: +/- d syntax fails in my clone
+
+connection slave;
+set @@global.debug='d,simulate_slave_unaware_checksum'; # merge todo: +/- d syntax fails in my clone
+start slave;
+source include/wait_for_slave_io_to_stop.inc;
+
+let $errno= query_get_value(SHOW SLAVE STATUS, Last_IO_Errno, 1);
+let $error= query_get_value(SHOW SLAVE STATUS, Last_IO_Error, 1);
+let $error= `select substring("$error", 17)`;  # todo:  declare a global const let $slave_error_date_col= 17
+--echo *** Got IO thread error code: $errno, text: $error ***
+
+select count(*) as zero from t1;
+
+###connection master;
+set @@global.debug=''; # merge todo: +/- d syntax fails in my clone
+
+connection slave;
+source include/start_slave.inc;
+
+# 
+# C. checksum failure simulations
+#
+
+# C1. Failure by a client thread
+connection master;
+set @@global.master_verify_checksum = 1;
+set @@session.debug='d,simulate_checksum_test_failure'; # merge todo deploy +/- syntax
+--error ER_ERROR_WHEN_EXECUTING_COMMAND
+show binlog events;
+set @@session.debug=''; # merge todo: +/- d syntax fails in my clone
+set @@global.master_verify_checksum = default;
+
+#connection master;
+sync_slave_with_master;
+
+connection slave;
+source include/stop_slave.inc;
+
+connection master;
+create table t2 (a int);
+let $pos_master= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+connection slave;
+
+# C2. Failure by IO thread
+# instruction to io thread
+set @@global.debug='d,simulate_checksum_test_failure'; # merge todo deploy +/- syntax
+start slave io_thread;
+source include/wait_for_slave_io_to_stop.inc;
+let $errno= query_get_value(SHOW SLAVE STATUS, Last_IO_Errno, 1);
+let $error= query_get_value(SHOW SLAVE STATUS, Last_IO_Error, 1);
+let $error= `select substring("$error", 17)`;
+--echo *** Got IO thread error code: $errno, text: $error ***
+set @@global.debug=''; # todo: merge
+
+# to make IO thread re-read it again w/o the failure
+start slave io_thread;
+let $slave_param= Read_Master_Log_Pos;
+let $slave_param_value= $pos_master;
+source include/wait_for_slave_param.inc;
+
+# C3. Failure by SQL thread
+# instruction to sql thread;
+set @@global.slave_sql_verify_checksum = 1;
+
+set @@global.debug='d,simulate_checksum_test_failure'; # merge todo deploy +/- syntax
+
+start slave sql_thread;
+source include/wait_for_slave_sql_to_stop.inc;
+let $errno= query_get_value(SHOW SLAVE STATUS, Last_SQL_Errno, 1);
+let $error= query_get_value(SHOW SLAVE STATUS, Last_SQL_Error, 1);
+let $error= `select substring("$error", 17)`;
+--echo *** Got SQL thread error code: $errno, text: $error ***
+
+# resuming SQL thread to parse out the event w/o the failure
+
+set @@global.debug=''; 
+source include/start_slave.inc;
+
+connection master;
+sync_slave_with_master;
+
+#connection slave;
+select count(*) as 'must be zero' from t2;
+
+#
+# D. Reset slave, Change-Master, Binlog & Relay-log rotations with 
+#    random value on binlog_checksum on both master and slave
+#
+connection slave;
+stop slave;
+reset slave;
+
+# randomize slave server's own checksum policy
+set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE");
+flush logs;
+
+connection master;
+set @@global.binlog_checksum= CRC32;
+reset master;
+flush logs;
+create table t3 (a int, b char(5));
+
+connection slave;
+source include/start_slave.inc;
+
+connection master;
+sync_slave_with_master;
+
+#connection slave;
+select count(*) as 'must be zero' from t3;
+source include/stop_slave.inc;
+--replace_result $MASTER_MYPORT MASTER_PORT
+eval change master to master_host='127.0.0.1',master_port=$MASTER_MYPORT, master_user='root';
+
+connection master;
+flush logs;
+reset master;
+insert into t3 value (1, @@global.binlog_checksum);
+
+connection slave;
+source include/start_slave.inc;
+flush logs;
+
+connection master;
+sync_slave_with_master;
+
+#connection slave;
+select count(*) as 'must be one' from t3;
+
+connection master;
+set @@global.binlog_checksum= IF(floor((rand()*1000)%2), "CRC32", "NONE");
+insert into t3 value (1, @@global.binlog_checksum);
+sync_slave_with_master;
+
+#connection slave;
+
+#clean-up
+
+connection master;
+drop table t1, t2, t3;
+set @@global.binlog_checksum = @master_save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+
+#connection slave;
+sync_slave_with_master;
+set @@global.binlog_checksum = @slave_save_binlog_checksum;
+set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum;
+
+--echo End of tests

=== added file 'mysql-test/suite/rpl/t/rpl_checksum_cache.test'
--- a/mysql-test/suite/rpl/t/rpl_checksum_cache.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_checksum_cache.test	2010-11-11 02:11:10 +0000
@@ -0,0 +1,264 @@
+-- source include/have_innodb.inc
+-- source include/master-slave.inc
+
+--disable_warnings
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement: insert into t2 set data=repeat.*'a', @act_size.*");
+call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement: insert into t1 values.* NAME_CONST.*'n',.*, @data .*");
+--enable_warnings
+
+connection master;
+set @save_binlog_cache_size = @@global.binlog_cache_size;
+set @save_binlog_checksum = @@global.binlog_checksum;
+set @save_master_verify_checksum = @@global.master_verify_checksum;
+set @@global.binlog_cache_size = 4096;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 1;
+
+# restart slave to force the dump thread to verify events (on master side)
+connection slave;
+source include/stop_slave.inc;
+source include/start_slave.inc;
+
+connection master;
+
+#
+# Testing a critical part of checksum handling dealing with transaction cache.
+# The cache's buffer size is set to be less than the transaction's footprint
+# in binlog.
+#
+# To verify combined buffer-by-buffer read out of the file and fixing crc per event
+# there are the following parts:
+#
+# 1. the event size is much less than the cache's buffer
+# 2. the event size is bigger than the cache's buffer
+# 3. the event size if approximately the same as the cache's buffer
+# 4. all in above
+
+#
+# 1. the event size is much less than the cache's buffer
+#
+
+flush status;
+show status like "binlog_cache_use";
+show status like "binlog_cache_disk_use";
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+#
+# parameter to ensure the test slightly varies binlog content
+# between different invocations
+#
+let $deviation_size=32;
+eval create table t1 (a int PRIMARY KEY, b CHAR($deviation_size)) engine=innodb;
+
+# Now we are going to create transaction which is long enough so its 
+# transaction binlog will be flushed to disk...
+
+delimiter |;
+create procedure test.p_init (n int, size int) 
+begin
+  while n > 0 do
+    select round(RAND() * size) into @act_size;
+    set @data = repeat('a', @act_size);
+    insert into t1 values(n, @data );
+    set n= n-1;
+  end while;
+end|
+
+delimiter ;|
+
+let $1 = 4000; # PB2 can run it slow to time out on following sync_slave_with_master:s
+
+begin;
+--disable_warnings
+# todo: check if it is really so.
+#+Note   1592    Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT. Reason for unsafeness: Statement uses a system function whose value may differ on slave.
+eval call test.p_init($1, $deviation_size);
+--enable_warnings
+commit;
+
+show status like "binlog_cache_use";
+--echo *** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t1;
+let $diff_table_2=slave:test.t1;
+source include/diff_tables.inc;
+
+# undoing changes with verifying the above once again
+connection master;
+
+begin;
+delete from t1;
+commit;
+
+sync_slave_with_master;
+
+
+#
+# 2. the event size is bigger than the cache's buffer
+#
+connection master;
+
+flush status;
+let $t2_data_size= `select 3 * @@global.binlog_cache_size`;
+let $t2_aver_size= `select 2 * @@global.binlog_cache_size`;
+let $t2_max_rand=  `select 1 * @@global.binlog_cache_size`;
+
+eval create table t2(a int auto_increment primary key, data VARCHAR($t2_data_size)) ENGINE=Innodb;
+let $1=100;
+--disable_query_log
+begin;
+while ($1)
+{
+ eval select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size;
+ set @data = repeat('a', @act_size);
+ insert into t2 set data = @data;
+ dec $1;
+}
+commit;
+--enable_query_log
+show status like "binlog_cache_use";
+--echo *** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t2;
+let $diff_table_2=slave:test.t2;
+source include/diff_tables.inc;
+
+# undoing changes with verifying the above once again
+connection master;
+
+begin;
+delete from t2;
+commit;
+
+sync_slave_with_master;
+
+#
+# 3. the event size if approximately the same as the cache's buffer
+#
+
+connection master;
+
+flush status;
+let $t3_data_size= `select 2 * @@global.binlog_cache_size`;
+let $t3_aver_size= `select (9 * @@global.binlog_cache_size) / 10`;
+let $t3_max_rand=  `select (2 * @@global.binlog_cache_size) / 10`;
+
+eval create table t3(a int auto_increment primary key, data VARCHAR($t3_data_size)) engine=innodb;
+
+let $1= 300;
+--disable_query_log
+begin;
+while ($1)
+{
+ eval select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size;
+ insert into t3 set data= repeat('a', @act_size);
+ dec $1;
+}
+commit;
+--enable_query_log
+show status like "binlog_cache_use";
+--echo *** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+
+sync_slave_with_master;
+
+let $diff_table_1=master:test.t3;
+let $diff_table_2=slave:test.t3;
+source include/diff_tables.inc;
+
+# undoing changes with verifying the above once again
+connection master;
+
+begin;
+delete from t3;
+commit;
+
+sync_slave_with_master;
+
+
+#
+# 4. all in above
+#
+
+connection master;
+flush status;
+
+delimiter |;
+eval create procedure test.p1 (n int) 
+begin
+  while n > 0 do
+    case (select (round(rand()*100) % 3) + 1)
+    when 1 then
+      select round(RAND() * $deviation_size) into @act_size;
+      set @data = repeat('a', @act_size);
+      insert into t1 values(n, @data);
+    when 2 then
+      begin
+        select round($t2_aver_size + RAND() * $t2_max_rand) into @act_size;
+	insert into t2 set data=repeat('a', @act_size);
+      end;
+    when 3 then
+      begin
+        select round($t3_aver_size + RAND() * $t3_max_rand) into @act_size;
+	insert into t3 set data= repeat('a', @act_size);
+      end;
+    end case;
+    set n= n-1;
+  end while;
+end|
+delimiter ;|
+
+let $1= 1000;
+set autocommit= 0;
+begin;
+--disable_warnings
+eval call test.p1($1);
+--enable_warnings
+commit;
+
+show status like "binlog_cache_use";
+--echo *** binlog_cache_disk_use must be non-zero ***
+show status like "binlog_cache_disk_use";
+
+sync_slave_with_master;
+
+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;
+
+let $diff_table_1=master:test.t3;
+let $diff_table_2=slave:test.t3;
+source include/diff_tables.inc;
+
+
+connection master;
+
+begin;
+delete from t1;
+delete from t2;
+delete from t3;
+commit;
+
+drop table t1, t2, t3;
+set @@global.binlog_cache_size = @save_binlog_cache_size;
+set @@global.binlog_checksum = @save_binlog_checksum;
+set @@global.master_verify_checksum = @save_master_verify_checksum;
+drop procedure test.p_init;
+drop procedure test.p1;
+
+sync_slave_with_master;
+
+--echo End of tests
+

=== added file 'mysql-test/suite/rpl/t/rpl_corruption-master.opt'
--- a/mysql-test/suite/rpl/t/rpl_corruption-master.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_corruption-master.opt	2010-11-02 12:43:13 +0000
@@ -0,0 +1 @@
+--binlog-checksum=CRC32 --master-verify-checksum=1

=== added file 'mysql-test/suite/rpl/t/rpl_corruption-slave.opt'
--- a/mysql-test/suite/rpl/t/rpl_corruption-slave.opt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_corruption-slave.opt	2010-11-02 12:43:13 +0000
@@ -0,0 +1 @@
+--binlog-checksum=CRC32 --slave-sql-verify-checksum=1

=== added file 'mysql-test/suite/rpl/t/rpl_corruption.test'
--- a/mysql-test/suite/rpl/t/rpl_corruption.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_corruption.test	2010-11-11 02:11:10 +0000
@@ -0,0 +1,128 @@
+############################################################
+# Author: Serge Kozlov <serge.kozlov@stripped>
+# Date:	17 Oct 2010
+# Purpose: WL#5064 Testing with corrupted events.
+# The test emulates the corruption at the vary stages
+# of replication:
+#  - in binlog file
+#  - in network
+#  - in relay log
+############################################################
+
+--source include/have_debug.inc
+--source include/master-slave.inc
+
+# Block legal errors for MTR 
+call mtr.add_suppression('Found invalid event in binary log');
+call mtr.add_suppression('Slave I/O: Relay log write failure: could not queue event from master');
+call mtr.add_suppression('event read from binlog did not pass crc check');
+call mtr.add_suppression('Replication event checksum verification failed');
+
+SET @old_master_verify_checksum = @@master_verify_checksum;
+
+# Creating test table/data and set corruption position for testing
+--echo # 1. Creating test table/data and set corruption position for testing
+--connection master
+--echo * insert/update/delete rows in table t1 *
+# Corruption algorithm modifies only the first event and 
+# then will be reset. To avoid checking always the first event 
+# from binlog (usually it is FD) we randomly execute different 
+# statements and set position for corruption inside events.
+
+CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b VARCHAR(10), c VARCHAR(100));
+--disable_query_log
+let $i=`SELECT 3+CEILING(10*RAND())`;
+let $j=1;
+let $pos=0;
+while ($i) {  
+  eval INSERT INTO t1 VALUES ($j, 'a', NULL);
+  if (`SELECT RAND() > 0.7`)
+  {
+    eval UPDATE t1 SET c = REPEAT('a', 20) WHERE a = $j;
+  }
+  if (`SELECT RAND() > 0.8`)
+  {
+    eval DELETE FROM t1 WHERE a = $j;
+  }
+  if (!$pos) {
+    let $pos= query_get_value(SHOW MASTER STATUS, Position, 1);
+    --sync_slave_with_master
+    --source include/stop_slave.inc
+    --disable_query_log
+    --connection master
+  }
+  dec $i;
+  inc $j;
+}
+--enable_query_log
+
+# Emulate corruption in binlog file when SHOW BINLOG EVENTS is executing
+--echo # 2. Corruption in master binlog and SHOW BINLOG EVENTS
+SET GLOBAL debug="+d,corrupt_read_log_event_char";
+--echo SHOW BINLOG EVENTS;
+--disable_query_log
+send_eval SHOW BINLOG EVENTS FROM $pos;
+--enable_query_log
+--error ER_ERROR_WHEN_EXECUTING_COMMAND
+reap;
+SET GLOBAL debug="-d,corrupt_read_log_event_char";
+
+# Emulate corruption on master with crc checking on master
+--echo # 3. Master read a corrupted event from binlog and send the error to slave
+SET GLOBAL debug="+d,corrupt_read_log_event";
+--connection slave
+START SLAVE IO_THREAD;
+let $slave_io_errno= 1236;
+--source include/wait_for_slave_io_error.inc
+--connection master
+SET GLOBAL debug="-d,corrupt_read_log_event";
+
+# Emulate corruption on master without crc checking on master
+--echo # 4. Master read a corrupted event from binlog and send it to slave
+--connection master
+SET GLOBAL master_verify_checksum=0;
+SET GLOBAL debug="+d,corrupt_read_log_event";
+--connection slave
+START SLAVE IO_THREAD;
+let $slave_io_errno= 1595;
+--source include/wait_for_slave_io_error.inc
+--connection master
+SET GLOBAL debug="-d,corrupt_read_log_event";
+SET GLOBAL master_verify_checksum=1;
+
+# Emulate corruption in network
+--echo # 5. Slave. Corruption in network
+--connection slave
+SET GLOBAL debug="+d,corrupt_queue_event";
+START SLAVE IO_THREAD;
+let $slave_io_errno= 1595;
+--source include/wait_for_slave_io_error.inc
+SET GLOBAL debug="-d,corrupt_queue_event";
+
+# Emulate corruption in relay log
+--echo # 6. Slave. Corruption in relay log
+SET GLOBAL debug="+d,corrupt_read_log_event_char";
+START SLAVE;
+let $slave_sql_errno= 1593;
+--source include/wait_for_slave_sql_error.inc
+SET GLOBAL debug="-d,corrupt_read_log_event_char";
+
+# Start normal replication and compare same table on master
+# and slave
+--echo # 7. Seek diff for tables on master and slave
+--connection slave
+--source include/start_slave.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 # 8. Clean up
+--connection master
+SET GLOBAL debug= "";
+SET GLOBAL master_verify_checksum = @old_master_verify_checksum;
+DROP TABLE t1;
+--sync_slave_with_master
+SET GLOBAL debug= "";

=== modified file 'mysql-test/suite/rpl/t/rpl_heartbeat_basic.test'
--- a/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test	2010-11-26 13:39:15 +0000
+++ b/mysql-test/suite/rpl/t/rpl_heartbeat_basic.test	2010-11-29 11:23:33 +0000
@@ -16,10 +16,14 @@
 # in order to not slow down much `make test'.
 #
 --source include/have_binlog_format_mixed.inc
+
+call mtr.add_suppression("Slave I/O: The slave I/O thread stops because a fatal error is encountered when it tried to SET @master_binlog_checksum");
+
 --echo
 
 --echo *** Preparing ***
 --connection slave
+
 --source include/stop_slave.inc
 RESET SLAVE;
 SET @restore_slave_net_timeout=@@global.slave_net_timeout;

=== modified file 'mysql-test/suite/rpl/t/rpl_known_bugs_detection.test'
--- a/mysql-test/suite/rpl/t/rpl_known_bugs_detection.test	2010-08-05 17:45:25 +0000
+++ b/mysql-test/suite/rpl/t/rpl_known_bugs_detection.test	2010-10-25 19:02:24 +0000
@@ -4,11 +4,14 @@
 # imitate the bug, so it has to stop).
 
 source include/have_debug.inc;
+# because of pretend_version_50034_in_binlog the test can't run with checksum
+source include/have_binlog_checksum_off.inc;
 source include/master-slave.inc;
 
 # Currently only statement-based-specific bugs are here
 -- source include/have_binlog_format_mixed_or_statement.inc
 
+
 #
 # This is to test that slave properly detects if
 # master may suffer from:

=== modified file 'mysql-test/suite/rpl/t/rpl_rotate_logs.test'
--- a/mysql-test/suite/rpl/t/rpl_rotate_logs.test	2010-10-25 10:39:01 +0000
+++ b/mysql-test/suite/rpl/t/rpl_rotate_logs.test	2010-11-23 23:10:22 +0000
@@ -156,7 +156,10 @@ select * from t2;
 connection master;
 create temporary table temp_table (a char(80) not null);
 insert into temp_table values ("testing temporary tables part 2");
-let $1=100;
+
+# the nummber of produced logs is sensitive to whether checksum is NONE or CRC32
+# the value of 90 makes it even
+let $1=90;
 
 create table t3 (n int);
 disable_query_log;

=== modified file 'mysql-test/suite/rpl/t/rpl_row_ignorable_event.test'
--- a/mysql-test/suite/rpl/t/rpl_row_ignorable_event.test	2010-10-19 08:51:50 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_ignorable_event.test	2010-11-16 12:14:06 +0000
@@ -80,7 +80,7 @@ source include/show_binlog_events.inc;
 --echo # MYSQL_BINLOG output base on master-bin.000001
 let $MYSQLD_DATADIR= `select @@datadir`;
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
---replace_regex /TIMESTAMP=[0-9]*/TIMESTAMP=t/ /#[0-9]*[ ]*[0-9]*:[0-9]*:[0-9]* server id [0-9]*/#server id #/ /exec_time=[0-9]*/exec_time=#/ /error_code=[0-9]*/error_code=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /Xid = [0-9]*/Xid = #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /Start: binlog v [0-9]*/Start: binlog v#/ /created [0-9]*[ ]*[0-9]*:[0-9]*:[0-9]* at startup/created # #:#:# at startup/
+--replace_regex /TIMESTAMP=[0-9]*/TIMESTAMP=t/ /#[0-9]*[ ]*[0-9]*:[0-9]*:[0-9]* server id [0-9]*/#server id #/ /exec_time=[0-9]*/exec_time=#/ /error_code=[0-9]*/error_code=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /Xid = [0-9]*/Xid = #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /Start: binlog v [0-9]*/Start: binlog v#/ /created [0-9]*[ ]*[0-9]*:[0-9]*:[0-9]* at startup/created # #:#:# at startup/ /[	 ]CRC32 0x[abcdef0-9]+//
 --exec $MYSQL_BINLOG --base64-output=decode-rows -v -v $MYSQLD_DATADIR/$master_binlog
 
 let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1);

=== modified file 'mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test'
--- a/mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test	2010-09-01 02:51:08 +0000
+++ b/mysql-test/suite/rpl/t/rpl_row_mysqlbinlog.test	2010-10-25 19:02:24 +0000
@@ -248,6 +248,7 @@ connection master;
 # transactions. /Matz
 
 # LOAD DATA
+
 --disable_query_log
 select "--- Test 5 LOAD DATA --" as "";
 --enable_query_log

=== modified file 'mysql-test/suite/rpl/t/rpl_server_uuid.test'
--- a/mysql-test/suite/rpl/t/rpl_server_uuid.test	2010-11-17 12:21:45 +0000
+++ b/mysql-test/suite/rpl/t/rpl_server_uuid.test	2010-11-29 11:23:33 +0000
@@ -17,6 +17,8 @@ call mtr.add_suppression("Slave I/O thre
 call mtr.add_suppression("Slave I/O: Master command COM_REGISTER_SLAVE failed: .*");
 CALL mtr.add_suppression(".*master and slave have equal MySQL server UUIDs.*");
 CALL mtr.add_suppression("Master's UUID has changed, its old UUID is.*");
+CALL mtr.add_suppression("Slave I/O: SET @master_heartbeat_period to master failed with error: Lost connection to MySQL server during query");
+CALL mtr.add_suppression("Notifying master by SET @master_binlog_checksum= @@global.binlog_checksum failed with error");
 
 --let $uuid_file= auto.cnf
 

=== modified file 'mysql-test/suite/rpl_ndb/t/rpl_ndb_multi.test'
--- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_multi.test	2010-07-17 11:07:36 +0000
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_multi.test	2010-09-28 13:58:50 +0000
@@ -32,8 +32,10 @@ stop slave;
 # get the master binlog pos from the epoch, from the _other_ "master", server2
 connection server2;
 --replace_result $the_epoch <the_epoch>
+--disable_result_log
 eval SELECT @the_pos:=Position,@the_file:=SUBSTRING_INDEX(FILE, '/', -1)
    FROM mysql.ndb_binlog_index WHERE epoch = $the_epoch ;
+--enable_result_log
 let $the_pos= `SELECT @the_pos` ;
 let $the_file= `SELECT @the_file` ;
 

=== added file 'mysql-test/suite/sys_vars/r/binlog_checksum_basic.result'
--- a/mysql-test/suite/sys_vars/r/binlog_checksum_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/binlog_checksum_basic.result	2010-11-01 18:00:28 +0000
@@ -0,0 +1,14 @@
+set @save_binlog_checksum= @@global.binlog_checksum;
+set @@global.binlog_checksum = default;
+select @@global.binlog_checksum as 'must be NONE by default';
+must be NONE by default
+NONE
+select @@session.binlog_checksum as 'no session var';
+ERROR HY000: Variable 'binlog_checksum' is a GLOBAL variable
+set @@global.binlog_checksum = CRC32;
+set @@global.binlog_checksum = CRC32;
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+set @@global.binlog_checksum = ADLER32;
+ERROR 42000: Variable 'binlog_checksum' can't be set to the value of 'ADLER32'
+set @@global.binlog_checksum = @save_binlog_checksum;

=== added file 'mysql-test/suite/sys_vars/r/master_verify_checksum_basic.result'
--- a/mysql-test/suite/sys_vars/r/master_verify_checksum_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/master_verify_checksum_basic.result	2010-10-28 17:09:41 +0000
@@ -0,0 +1,11 @@
+set @save_master_verify_checksum =  @@global.master_verify_checksum;
+select @@global.master_verify_checksum  as 'must be zero because of default';
+must be zero because of default
+0
+select @@session.master_verify_checksum  as 'no session var';
+ERROR HY000: Variable 'master_verify_checksum' is a GLOBAL variable
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+set @@global.master_verify_checksum = 2;
+ERROR 42000: Variable 'master_verify_checksum' can't be set to the value of '2'
+set @@global.master_verify_checksum = @save_master_verify_checksum;

=== added file 'mysql-test/suite/sys_vars/r/slave_sql_verify_checksum_basic.result'
--- a/mysql-test/suite/sys_vars/r/slave_sql_verify_checksum_basic.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/r/slave_sql_verify_checksum_basic.result	2010-10-28 17:09:41 +0000
@@ -0,0 +1,11 @@
+set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum;
+select @@global.slave_sql_verify_checksum  as 'must be one because of default';
+must be one because of default
+1
+select @@session.slave_sql_verify_checksum  as 'no session var';
+ERROR HY000: Variable 'slave_sql_verify_checksum' is a GLOBAL variable
+set @@global.slave_sql_verify_checksum = 0;
+set @@global.slave_sql_verify_checksum = default;
+set @@global.slave_sql_verify_checksum = 2;
+ERROR 42000: Variable 'slave_sql_verify_checksum' can't be set to the value of '2'
+set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum;

=== modified file 'mysql-test/suite/sys_vars/t/all_vars.test'
--- a/mysql-test/suite/sys_vars/t/all_vars.test	2010-10-21 08:30:43 +0000
+++ b/mysql-test/suite/sys_vars/t/all_vars.test	2010-11-16 12:14:06 +0000
@@ -53,6 +53,11 @@ perl;
   print F join "\n", sort map { s/_basic(_32|_64)?\.test$//; basename $_ } @all_tests;
 EOF
 
+#
+# todo: fix Bug #55080 mysql-next-mr requires a specic to new added global variables test file
+# to get rid of unxpected and probited following SELECT results
+#
+
 create table t1 (test_name text);
 create table t2 (variable_name text);
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR

=== added file 'mysql-test/suite/sys_vars/t/binlog_checksum_basic.test'
--- a/mysql-test/suite/sys_vars/t/binlog_checksum_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/binlog_checksum_basic.test	2010-11-01 18:00:28 +0000
@@ -0,0 +1,25 @@
+--source include/not_embedded.inc
+
+# suite/rpl/t/rpl_checksum.test contains similar testing of 
+# all checksum related system variables.
+
+set @save_binlog_checksum= @@global.binlog_checksum;
+set @@global.binlog_checksum = default;
+
+select @@global.binlog_checksum as 'must be NONE by default';
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.binlog_checksum as 'no session var';
+
+
+# testing lack of side-effects in non-effective update of binlog_checksum:
+set @@global.binlog_checksum = CRC32;
+set @@global.binlog_checksum = CRC32; 
+
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+
+--error ER_WRONG_VALUE_FOR_VAR
+set @@global.binlog_checksum = ADLER32;
+
+# cleanup
+set @@global.binlog_checksum = @save_binlog_checksum;

=== added file 'mysql-test/suite/sys_vars/t/master_verify_checksum_basic.test'
--- a/mysql-test/suite/sys_vars/t/master_verify_checksum_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/master_verify_checksum_basic.test	2010-10-28 17:09:41 +0000
@@ -0,0 +1,19 @@
+--source include/not_embedded.inc
+
+# suite/rpl/t/rpl_checksum.test contains similar testing of 
+# all checksum related system variables.
+
+set @save_master_verify_checksum =  @@global.master_verify_checksum;
+
+select @@global.master_verify_checksum  as 'must be zero because of default';
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.master_verify_checksum  as 'no session var';
+
+set @@global.master_verify_checksum = 0;
+set @@global.master_verify_checksum = default;
+
+--error ER_WRONG_VALUE_FOR_VAR
+set @@global.master_verify_checksum = 2; # the var is of bool type
+
+# cleanup
+set @@global.master_verify_checksum = @save_master_verify_checksum;

=== added file 'mysql-test/suite/sys_vars/t/slave_sql_verify_checksum_basic.test'
--- a/mysql-test/suite/sys_vars/t/slave_sql_verify_checksum_basic.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/sys_vars/t/slave_sql_verify_checksum_basic.test	2010-10-28 17:09:41 +0000
@@ -0,0 +1,18 @@
+--source include/not_embedded.inc
+
+# suite/rpl/t/rpl_checksum.test contains similar testing of 
+# all checksum related system variables.
+
+set @save_slave_sql_verify_checksum = @@global.slave_sql_verify_checksum;
+
+select @@global.slave_sql_verify_checksum  as 'must be one because of default';
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+select @@session.slave_sql_verify_checksum  as 'no session var';
+
+set @@global.slave_sql_verify_checksum = 0;
+set @@global.slave_sql_verify_checksum = default;
+--error ER_WRONG_VALUE_FOR_VAR
+set @@global.slave_sql_verify_checksum = 2; # the var is of bool type
+
+# cleanup
+set @@global.slave_sql_verify_checksum = @save_slave_sql_verify_checksum;

=== modified file 'mysql-test/t/mysqlbinlog2.test'
--- a/mysql-test/t/mysqlbinlog2.test	2010-09-01 02:51:08 +0000
+++ b/mysql-test/t/mysqlbinlog2.test	2010-10-25 19:02:24 +0000
@@ -105,7 +105,6 @@ select "--- stop-datetime --" as "";
 --disable_query_log
 select "--- Remote --" as "";
 --enable_query_log
-
 --exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.000001 
 
 --disable_query_log

=== modified file 'sql/binlog.cc'
--- a/sql/binlog.cc	2010-11-16 12:38:17 +0000
+++ b/sql/binlog.cc	2010-11-29 11:23:33 +0000
@@ -512,7 +512,7 @@ binlog_flush_stmt_cache(THD *thd, binlog
   if (thd->binlog_flush_pending_rows_event(TRUE, is_transactional))
     DBUG_RETURN(1);
 
-  Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE, TRUE, 0);
+  Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, TRUE, TRUE, 0);
   if ((error= mysql_bin_log.write(thd, cache_log, &qev,
                                   cache_mngr->stmt_cache.has_incident())))
     DBUG_RETURN(error);
@@ -575,7 +575,7 @@ static int binlog_commit(handlerton *hto
   */
   if (ending_trans(thd, all))
   {
-    Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE, TRUE, 0);
+    Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, TRUE, TRUE, 0);
     error= binlog_flush_trx_cache(thd, cache_mngr, &qev);
   }
 
@@ -671,7 +671,7 @@ static int binlog_rollback(handlerton *h
           ending_single_stmt_trans(thd,all) &&
           thd->variables.binlog_format == BINLOG_FORMAT_MIXED)))
     {
-      Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, FALSE, TRUE, 0);
+      Query_log_event qev(thd, STRING_WITH_LEN("ROLLBACK"), TRUE, TRUE, TRUE, 0);
       error= binlog_flush_trx_cache(thd, cache_mngr, &qev);
     }
     /*
@@ -1315,7 +1315,8 @@ bool show_binlog_events(THD *thd, MYSQL_
       This code will fail on a mixed relay log (one which has Format_desc then
       Rotate then Format_desc).
     */
-    ev= Log_event::read_log_event(&log, (mysql_mutex_t*)0, description_event);
+    ev= Log_event::read_log_event(&log, (mysql_mutex_t*)0, description_event,
+                                   opt_master_verify_checksum);
     if (ev)
     {
       if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT)
@@ -1337,8 +1338,12 @@ bool show_binlog_events(THD *thd, MYSQL_
 
     for (event_count = 0;
          (ev = Log_event::read_log_event(&log, (mysql_mutex_t*) 0,
-                                         description_event)); )
+                                         description_event,
+                                         opt_master_verify_checksum)); )
     {
+      if (ev->get_type_code() == FORMAT_DESCRIPTION_EVENT)
+        description_event->checksum_alg= ev->checksum_alg;
+
       if (event_count >= limit_start &&
 	  ev->net_send(protocol, linfo.log_file_name, pos))
       {
@@ -1428,6 +1433,8 @@ MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_
    need_start_event(TRUE),
    sync_period_ptr(sync_period),
    is_relay_log(0), signal_cnt(0),
+   checksum_alg_reset(BINLOG_CHECKSUM_ALG_UNDEF),
+   relay_log_checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF),
    description_event_for_exec(0), description_event_for_queue(0)
 {
   /*
@@ -1642,7 +1649,19 @@ bool MYSQL_BIN_LOG::open(const char *log
         as we won't be able to reset it later
       */
       if (io_cache_type == WRITE_CACHE)
-        s.flags|= LOG_EVENT_BINLOG_IN_USE_F;
+        s.flags |= LOG_EVENT_BINLOG_IN_USE_F;
+      s.checksum_alg= is_relay_log ?
+        /* relay-log */
+        /* inherit master's A descriptor if one has been received */
+        (relay_log_checksum_alg= 
+         (relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF) ?
+         relay_log_checksum_alg :
+         /* otherwise use slave's local preference of RL events verification */
+         (opt_slave_sql_verify_checksum == 0) ?
+         (uint8) BINLOG_CHECKSUM_ALG_OFF : binlog_checksum_options):
+        /* binlog */
+        binlog_checksum_options;
+      DBUG_ASSERT(s.checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF);
       if (!s.is_valid())
         goto err;
       s.dont_set_created= null_created_arg;
@@ -2802,8 +2821,15 @@ void MYSQL_BIN_LOG::new_file_impl(bool n
         We log the whole file name for log file as the user may decide
         to change base names at some point.
       */
-      Rotate_log_event r(new_name+dirname_length(new_name),
-                         0, LOG_EVENT_OFFSET, is_relay_log ? Rotate_log_event::RELAY_LOG : 0);
+      Rotate_log_event r(new_name+dirname_length(new_name), 0, LOG_EVENT_OFFSET,
+                         is_relay_log ? Rotate_log_event::RELAY_LOG : 0);
+      /* 
+         The current relay-log's closing Rotate event must have checksum
+         value computed with an algorithm of the last relay-logged FD event.
+      */
+      if (is_relay_log)
+        r.checksum_alg= relay_log_checksum_alg;
+      DBUG_ASSERT(!is_relay_log || relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF);
       r.write(&log_file);
       bytes_written += r.data_written;
     }
@@ -2817,7 +2843,12 @@ void MYSQL_BIN_LOG::new_file_impl(bool n
   old_name=name;
   name=0;				// Don't free name
   close(LOG_CLOSE_TO_BE_OPENED | LOG_CLOSE_INDEX);
-
+  if (log_type == LOG_BIN && checksum_alg_reset != BINLOG_CHECKSUM_ALG_UNDEF)
+  {
+    DBUG_ASSERT(!is_relay_log);
+    DBUG_ASSERT(binlog_checksum_options != checksum_alg_reset);
+    binlog_checksum_options= checksum_alg_reset;
+  }
   /*
      Note that at this point, log_state != LOG_CLOSED (important for is_open()).
   */
@@ -3127,10 +3158,16 @@ bool MYSQL_BIN_LOG::write(Log_event *eve
     {
       if (!thd->is_current_stmt_binlog_format_row())
       {
+        /* three possibility for cache_type at this point */
+        DBUG_ASSERT(event_info->cache_type == Log_event::EVENT_TRANSACTIONAL_CACHE ||
+                    event_info->cache_type == Log_event::EVENT_STMT_CACHE ||
+                    event_info->cache_type == Log_event::EVENT_NO_CACHE);
+ 
         if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt)
         {
           Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
-                             thd->first_successful_insert_id_in_prev_stmt_for_binlog);
+                             thd->first_successful_insert_id_in_prev_stmt_for_binlog,
+                             event_info->cache_type);
           if (e.write(file))
             goto err;
         }
@@ -3141,13 +3178,14 @@ bool MYSQL_BIN_LOG::write(Log_event *eve
                              nb_elements()));
           Intvar_log_event e(thd, (uchar) INSERT_ID_EVENT,
                              thd->auto_inc_intervals_in_cur_stmt_for_binlog.
-                             minimum());
+                             minimum(), event_info->cache_type);
           if (e.write(file))
             goto err;
         }
         if (thd->rand_used)
         {
-          Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
+          Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2,
+                           event_info->cache_type);
           if (e.write(file))
             goto err;
         }
@@ -3168,8 +3206,8 @@ bool MYSQL_BIN_LOG::write(Log_event *eve
                                  user_var_event->value,
                                  user_var_event->length,
                                  user_var_event->type,
-                                 user_var_event->charset_number,
-                                 flags);
+                                 user_var_event->charset_number, flags,
+                                 event_info->cache_type);
             if (e.write(file))
               goto err;
           }
@@ -3235,6 +3273,8 @@ void MYSQL_BIN_LOG::rotate_and_purge(uin
 #ifdef HAVE_REPLICATION
     check_purge= true;
 #endif
+    if (flags & RP_BINLOG_CHECKSUM_ALG_CHANGE)
+      checksum_alg_reset= BINLOG_CHECKSUM_ALG_UNDEF; // done
   }
   if (!(flags & RP_LOCK_LOG_IS_ALREADY_LOCKED))
     mysql_mutex_unlock(&LOCK_log);
@@ -3263,6 +3303,36 @@ uint MYSQL_BIN_LOG::next_file_id()
 }
 
 
+/**
+  Calculate checksum of possibly a part of an event containing at least
+  the whole common header.
+
+  @param    buf       the pointer to trans cache's buffer
+  @param    off       the offset of the beginning of the event in the buffer
+  @param    event_len no-checksum length of the event
+  @param    length    the current size of the buffer
+
+  @param    crc       [in-out] the checksum
+
+  Event size in incremented by @c BINLOG_CHECKSUM_LEN.
+
+  @return 0 or number of unprocessed yet bytes of the event excluding 
+            the checksum part.
+*/
+  static ulong fix_log_event_crc(uchar *buf, uint off, uint event_len,
+                                 uint length, ha_checksum *crc)
+{
+  ulong ret;
+  uchar *event_begin= buf + off;
+  uint16 flags= uint2korr(event_begin + FLAGS_OFFSET);
+
+  DBUG_ASSERT(length >= off + LOG_EVENT_HEADER_LEN); //at least common header in
+  int2store(event_begin + FLAGS_OFFSET, flags);
+  ret= length >= off + event_len ? 0 : off + event_len - length;
+  *crc= my_checksum(*crc, event_begin, event_len - ret); 
+  return ret;
+}
+
 /*
   Write the contents of a cache to the binary log.
 
@@ -3275,7 +3345,11 @@ uint MYSQL_BIN_LOG::next_file_id()
   DESCRIPTION
     Write the contents of the cache to the binary log. The cache will
     be reset as a READ_CACHE to be able to read the contents from it.
- */
+
+    Reading from the trans cache with possible (per @c binlog_checksum_options) 
+    adding checksum value  and then fixing the length and the end_log_pos of 
+    events prior to fill in the binlog cache.
+*/
 
 int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
 {
@@ -3284,8 +3358,17 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
   if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0))
     return ER_ERROR_ON_WRITE;
   uint length= my_b_bytes_in_cache(cache), group, carry, hdr_offs;
+  ulong remains= 0; // part of unprocessed yet netto length of the event
   long val;
+  ulong end_log_pos_inc= 0; // each event processed adds BINLOG_CHECKSUM_LEN 2 t
   uchar header[LOG_EVENT_HEADER_LEN];
+  ha_checksum crc= 0, crc_0= 0; // assignments to keep compiler happy
+  my_bool do_checksum= (binlog_checksum_options != BINLOG_CHECKSUM_ALG_OFF);
+  uchar buf[BINLOG_CHECKSUM_LEN];
+
+  // while there is just one alg the following must hold:
+  DBUG_ASSERT(!do_checksum ||
+              binlog_checksum_options == BINLOG_CHECKSUM_ALG_CRC32);
 
   /*
     The events in the buffer have incorrect end_log_pos data
@@ -3303,6 +3386,8 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
 
   group= (uint)my_b_tell(&log_file);
   hdr_offs= carry= 0;
+  if (do_checksum)
+    crc= crc_0= my_checksum(0L, NULL, 0);
 
   do
   {
@@ -3315,12 +3400,21 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
       DBUG_ASSERT(carry < LOG_EVENT_HEADER_LEN);
 
       /* assemble both halves */
-      memcpy(&header[carry], (char *)cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
+      memcpy(&header[carry], (char *)cache->read_pos,
+             LOG_EVENT_HEADER_LEN - carry);
 
       /* fix end_log_pos */
-      val= uint4korr(&header[LOG_POS_OFFSET]) + group;
+      val= uint4korr(&header[LOG_POS_OFFSET]) + group +
+        (end_log_pos_inc+= (do_checksum ? BINLOG_CHECKSUM_LEN : 0));
       int4store(&header[LOG_POS_OFFSET], val);
 
+      if (do_checksum)
+      {
+        ulong len= uint4korr(&header[EVENT_LEN_OFFSET]);
+        /* fix len */
+        int4store(&header[EVENT_LEN_OFFSET], len + BINLOG_CHECKSUM_LEN);
+      }
+
       /* write the first half of the split header */
       if (my_b_write(&log_file, header, carry))
         return ER_ERROR_ON_WRITE;
@@ -3329,11 +3423,20 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
         copy fixed second half of header to cache so the correct
         version will be written later.
       */
-      memcpy((char *)cache->read_pos, &header[carry], LOG_EVENT_HEADER_LEN - carry);
+      memcpy((char *)cache->read_pos, &header[carry],
+             LOG_EVENT_HEADER_LEN - carry);
 
       /* next event header at ... */
-      hdr_offs = uint4korr(&header[EVENT_LEN_OFFSET]) - carry;
+      hdr_offs= uint4korr(&header[EVENT_LEN_OFFSET]) - carry -
+        (do_checksum ? BINLOG_CHECKSUM_LEN : 0);
 
+      if (do_checksum)
+      {
+        DBUG_ASSERT(crc == crc_0 && remains == 0);
+        crc= my_checksum(crc, header, carry);
+        remains= uint4korr(header + EVENT_LEN_OFFSET) - carry -
+          BINLOG_CHECKSUM_LEN;
+      }
       carry= 0;
     }
 
@@ -3348,6 +3451,25 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
         very next iteration, just "eventually").
       */
 
+      /* crc-calc the whole buffer */
+      if (do_checksum && hdr_offs >= length)
+      {
+
+        DBUG_ASSERT(remains != 0 && crc != crc_0);
+
+        crc= my_checksum(crc, cache->read_pos, length); 
+        remains -= length;
+        if (my_b_write(&log_file, cache->read_pos, length))
+          return ER_ERROR_ON_WRITE;
+        if (remains == 0)
+        {
+          int4store(buf, crc);
+          if (my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN))
+            return ER_ERROR_ON_WRITE;
+          crc= crc_0;
+        }
+      }
+
       while (hdr_offs < length)
       {
         /*
@@ -3355,6 +3477,26 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
           we get the rest.
         */
 
+        if (do_checksum)
+        {
+          if (remains != 0)
+          {
+            /*
+              finish off with remains of the last event that crawls
+              from previous into the current buffer
+            */
+            DBUG_ASSERT(crc != crc_0);
+            crc= my_checksum(crc, cache->read_pos, hdr_offs);
+            int4store(buf, crc);
+            remains -= hdr_offs;
+            DBUG_ASSERT(remains == 0);
+            if (my_b_write(&log_file, cache->read_pos, hdr_offs) ||
+                my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN))
+              return ER_ERROR_ON_WRITE;
+            crc= crc_0;
+          }
+        }
+
         if (hdr_offs + LOG_EVENT_HEADER_LEN > length)
         {
           carry= length - hdr_offs;
@@ -3364,17 +3506,38 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
         else
         {
           /* we've got a full event-header, and it came in one piece */
-
-          uchar *log_pos= (uchar *)cache->read_pos + hdr_offs + LOG_POS_OFFSET;
+          uchar *ev= (uchar *)cache->read_pos + hdr_offs;
+          uint event_len= uint4korr(ev + EVENT_LEN_OFFSET); // netto len
+          uchar *log_pos= ev + LOG_POS_OFFSET;
 
           /* fix end_log_pos */
-          val= uint4korr(log_pos) + group;
+          val= uint4korr(log_pos) + group +
+            (end_log_pos_inc += (do_checksum ? BINLOG_CHECKSUM_LEN : 0));
           int4store(log_pos, val);
 
+	  /* fix CRC */
+	  if (do_checksum)
+          {
+            /* fix length */
+            int4store(ev + EVENT_LEN_OFFSET, event_len + BINLOG_CHECKSUM_LEN);
+            remains= fix_log_event_crc(cache->read_pos, hdr_offs, event_len,
+                                       length, &crc);
+            if (my_b_write(&log_file, ev, 
+                           remains == 0 ? event_len : length - hdr_offs))
+              return ER_ERROR_ON_WRITE;
+            if (remains == 0)
+            {
+              int4store(buf, crc);
+              if (my_b_write(&log_file, buf, BINLOG_CHECKSUM_LEN))
+                return ER_ERROR_ON_WRITE;
+              crc= crc_0; // crc is complete
+            }
+          }
+
           /* next event header at ... */
-          log_pos= (uchar *)cache->read_pos + hdr_offs + EVENT_LEN_OFFSET;
-          hdr_offs += uint4korr(log_pos);
+          hdr_offs += event_len; // incr by the netto len
 
+          DBUG_ASSERT(!do_checksum || remains == 0 || hdr_offs >= length);
         }
       }
 
@@ -3389,17 +3552,20 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE
       hdr_offs -= length;
     }
 
-    /* Write data to the binary log file */
-    if (my_b_write(&log_file, cache->read_pos, length))
-      return ER_ERROR_ON_WRITE;
+    /* Write the entire buf to the binary log file */
+    if (!do_checksum)
+      if (my_b_write(&log_file, cache->read_pos, length))
+        return ER_ERROR_ON_WRITE;
     cache->read_pos=cache->read_end;		// Mark buffer used up
   } while ((length= my_b_fill(cache)));
 
-  DBUG_ASSERT(carry == 0);
-
   if (sync_log)
     return flush_and_sync(0);
 
+  DBUG_ASSERT(carry == 0);
+  DBUG_ASSERT(!do_checksum || remains == 0);
+  DBUG_ASSERT(!do_checksum || crc == crc_0);
+
   return 0;                                     // All OK
 }
 
@@ -3470,7 +3636,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_C
         transaction is either a BEGIN..COMMIT block or a single
         statement in autocommit mode.
       */
-      Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE, TRUE, 0);
+      Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, TRUE, TRUE, 0);
       if (qinfo.write(&log_file))
         goto err;
       DBUG_EXECUTE_IF("crash_before_writing_xid",
@@ -3626,6 +3792,11 @@ void MYSQL_BIN_LOG::close(uint exiting)
 	(exiting & LOG_CLOSE_STOP_EVENT))
     {
       Stop_log_event s;
+      // the checksumming rule for relay-log case is similar to Rotate
+        s.checksum_alg= is_relay_log ?
+          relay_log_checksum_alg : binlog_checksum_options;
+      DBUG_ASSERT(!is_relay_log ||
+                  relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF);
       s.write(&log_file);
       bytes_written+= s.data_written;
       signal_update();
@@ -3773,7 +3944,8 @@ int MYSQL_BIN_LOG::open(const char *opt_
       goto err;
     }
 
-    if ((ev= Log_event::read_log_event(&log, 0, &fdle)) &&
+    if ((ev= Log_event::read_log_event(&log, 0, &fdle,
+                                       opt_master_verify_checksum)) &&
         ev->get_type_code() == FORMAT_DESCRIPTION_EVENT &&
         ev->flags & LOG_EVENT_BINLOG_IN_USE_F)
     {
@@ -3853,7 +4025,9 @@ int MYSQL_BIN_LOG::recover(IO_CACHE *log
 
   fdle->flags&= ~LOG_EVENT_BINLOG_IN_USE_F; // abort on the first error
 
-  while ((ev= Log_event::read_log_event(log,0,fdle)) && ev->is_valid())
+  while ((ev= Log_event::read_log_event(log, 0, fdle,
+                                        opt_master_verify_checksum))
+         && ev->is_valid())
   {
     if (ev->get_type_code() == XID_EVENT)
     {

=== modified file 'sql/binlog.h'
--- a/sql/binlog.h	2010-11-16 09:38:43 +0000
+++ b/sql/binlog.h	2010-11-29 11:23:33 +0000
@@ -96,6 +96,41 @@ public:
   /* This is relay log */
   bool is_relay_log;
   ulong signal_cnt;  // update of the counter is checked by heartbeat
+  uint8 checksum_alg_reset; // to contain a new value when binlog is rotated
+  /*
+    Holds the last seen in Relay-Log FD's checksum alg value.
+    The initial value comes from the slave's local FD that heads
+    the very first Relay-Log file. In the following the value may change
+    with each received master's FD_m.
+    Besides to be used in verification events that IO thread receives
+    (except the 1st fake Rotate, see @c Master_info:: checksum_alg_before_fd), 
+    the value specifies if/how to compute checksum for slave's local events
+    and the first fake Rotate (R_f^1) coming from the master.
+    R_f^1 needs logging checksum-compatibly with the RL's heading FD_s.
+
+    Legends for the checksum related comments:
+
+    FD     - Format-Description event,
+    R      - Rotate event
+    R_f    - the fake Rotate event
+    E      - an arbirary event
+
+    The underscore indexes for any event
+    `_s'   indicates the event is generated by Slave
+    `_m'   - by Master
+
+    Two special underscore indexes of FD:
+    FD_q   - Format Description event for queuing   (relay-logging)
+    FD_e   - Format Description event for executing (relay-logging)
+
+    Upper indexes:
+    E^n    - n:th event is a sequence
+
+    RL     - Relay Log
+    (A)    - checksum algorithm descriptor value
+    FD.(A) - the value of (A) in FD
+  */
+  uint8 relay_log_checksum_alg;
   /*
     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

=== modified file 'sql/log.cc'
--- a/sql/log.cc	2010-11-16 12:38:17 +0000
+++ b/sql/log.cc	2010-11-29 11:23:33 +0000
@@ -1945,8 +1945,6 @@ bool general_log_write(THD *thd, enum en
   return FALSE;
 }
 
-
-
 /**
   Check if a string is a valid number.
 

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-11-23 22:37:59 +0000
+++ b/sql/log_event.cc	2010-11-29 11:23:33 +0000
@@ -51,6 +51,31 @@
 #include <my_bitmap.h>
 #include "rpl_utility.h"
 
+
+/**
+  BINLOG_CHECKSUM variable.
+*/
+const char *binlog_checksum_type_names[]= {
+  "NONE",
+  "CRC32",
+  NullS
+};
+
+unsigned int binlog_checksum_type_length[]= {
+  sizeof("NONE") - 1,
+  sizeof("CRC32") - 1,
+  0
+};
+
+TYPELIB binlog_checksum_typelib=
+{
+  array_elements(binlog_checksum_type_names) - 1, "",
+  binlog_checksum_type_names,
+  binlog_checksum_type_length
+};
+
+
+
 #define log_cs	&my_charset_latin1
 
 #define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
@@ -64,6 +89,18 @@
 */
 #define FMT_G_BUFSIZE(PREC) (3 + (PREC) + 5 + 1)
 
+/* 
+   replication event checksum is introduced in the following "checksum-home" version.
+   The checksum-aware servers extract FD's version to decide whether the FD event
+   carries checksum info.
+
+   TODO: correct the constant when it has been determined 
+   (which main tree to push and when) 
+*/
+const uchar checksum_version_split[3]= {5, 1, 46};
+const ulong checksum_version_product=
+  (checksum_version_split[0] * 256 + checksum_version_split[1]) * 256 +
+  checksum_version_split[2];
 
 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
 static int rows_event_stmt_cleanup(Relay_log_info const *rli, THD* thd);
@@ -574,7 +611,6 @@ static void print_set_option(IO_CACHE* f
   }
 }
 #endif
-
 /**************************************************************************
 	Log_event methods (= the parent class of all events)
 **************************************************************************/
@@ -631,7 +667,8 @@ const char* Log_event::get_type_str()
 #ifndef MYSQL_CLIENT
 Log_event::Log_event(THD* thd_arg, uint16 flags_arg, bool using_trans)
   :log_pos(0), temp_buf(0), exec_time(0), flags(flags_arg),
-  cache_type(Log_event::EVENT_INVALID_CACHE), thd(thd_arg)
+   cache_type(Log_event::EVENT_INVALID_CACHE), crc(0), thd(thd_arg),
+   checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF)
 {
   server_id=	thd->server_id;
   when=		thd->start_time;
@@ -650,8 +687,8 @@ Log_event::Log_event(THD* thd_arg, uint1
 */
 
 Log_event::Log_event()
-  :temp_buf(0), exec_time(0), flags(0),
-  cache_type(Log_event::EVENT_INVALID_CACHE), thd(0)
+  :temp_buf(0), exec_time(0), flags(0),  crc(0), thd(0),
+   checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF)
 {
   server_id=	::server_id;
   /*
@@ -670,7 +707,8 @@ Log_event::Log_event()
 
 Log_event::Log_event(const char* buf,
                      const Format_description_log_event* description_event)
-  :temp_buf(0), exec_time(0), cache_type(Log_event::EVENT_INVALID_CACHE)
+  :temp_buf(0), exec_time(0), cache_type(Log_event::EVENT_INVALID_CACHE),
+    crc(0), checksum_alg(BINLOG_CHECKSUM_ALG_UNDEF)
 {
 #ifndef MYSQL_CLIENT
   thd = 0;
@@ -832,6 +870,105 @@ void Log_event::init_show_field_list(Lis
   field_list->push_back(new Item_empty_string("Info", 20));
 }
 
+/**
+   A decider of whether to trigger checksum computation or not.
+   To be invoked in Log_event::write() stack.
+   The decision is positive 
+
+    S,M) if it's been marked for checksumming with @c checksum_alg
+    
+    M) otherwise, if @@global.binlog_checksum is not NONE and the event is 
+       directly written to the binlog file.
+       The to-be-cached event decides at @c write_cache() time.
+
+   Otherwise the decision is negative.
+
+   @note   A side effect of the method is altering Log_event::checksum_alg
+           it the latter was undefined at calling.
+
+   @return true (positive) or false (negative)
+*/
+my_bool Log_event::need_checksum()
+{
+  DBUG_ENTER("Log_event::need_checksum");
+  my_bool ret;
+  /* 
+     few callers of Log_event::write 
+     (incl FD::write, FD constructing code on the slave side, Rotate relay log
+     and Stop event) 
+     provides their checksum alg preference through Log_event::checksum_alg.
+  */
+  ret= (checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF) ?
+    (checksum_alg != BINLOG_CHECKSUM_ALG_OFF) :
+    ((binlog_checksum_options != BINLOG_CHECKSUM_ALG_OFF) &&
+     (cache_type == Log_event::EVENT_NO_CACHE))? binlog_checksum_options :
+    FALSE;
+
+  /*
+    FD calls the methods before data_written has been calculated.
+    The following invariant claims if the current is not the first
+    call (and therefore data_written is not zero) then `ret' must be
+    TRUE. It may not be null because FD is always checksummed.
+  */
+  
+  DBUG_ASSERT(get_type_code() != FORMAT_DESCRIPTION_EVENT || ret ||
+              data_written == 0);
+
+  if (checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF)
+    checksum_alg= ret ? // calculated value stored
+      binlog_checksum_options : (uint8) BINLOG_CHECKSUM_ALG_OFF;
+
+  DBUG_ASSERT(!ret || 
+              ((checksum_alg == binlog_checksum_options ||
+               /* 
+                  Stop event closes the relay-log and its checksum alg
+                  preference is set by the caller can be different
+                  from the server's binlog_checksum_options.
+               */
+               get_type_code() == STOP_EVENT ||
+               /* 
+                  Rotate:s can be checksummed regardless of the server's
+                  binlog_checksum_options. That applies to both
+                  the local RL's Rotate and the master's Rotate
+                  which IO thread instantiates via queue_binlog_ver_3_event.
+               */
+               get_type_code() == ROTATE_EVENT
+               ||  /* FD is always checksummed */
+               get_type_code() == FORMAT_DESCRIPTION_EVENT) && 
+               checksum_alg != BINLOG_CHECKSUM_ALG_OFF));
+
+  DBUG_ASSERT(checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF);
+
+  DBUG_ASSERT(((get_type_code() != ROTATE_EVENT &&
+                get_type_code() != STOP_EVENT) ||
+               get_type_code() != FORMAT_DESCRIPTION_EVENT) ||
+              cache_type == Log_event::EVENT_NO_CACHE);
+
+  DBUG_RETURN(ret);
+}
+
+bool Log_event::wrapper_my_b_safe_write(IO_CACHE* file, const uchar* buf, ulong size)
+{
+  if (need_checksum() && size != 0)
+    crc= my_checksum(crc, buf, size);
+
+  return my_b_safe_write(file, buf, size);
+}
+
+bool Log_event::write_footer(IO_CACHE* file) 
+{
+  /*
+     footer contains the checksum-algorithm descriptor 
+     followed by the checksum value
+  */
+  if (need_checksum())
+  {
+    uchar buf[BINLOG_CHECKSUM_LEN];
+    int4store(buf, crc);
+    return (my_b_safe_write(file, (uchar*) buf, sizeof(buf)));
+  }
+  return 0;
+}
 
 /*
   Log_event::write()
@@ -841,11 +978,18 @@ bool Log_event::write_header(IO_CACHE* f
 {
   uchar header[LOG_EVENT_HEADER_LEN];
   ulong now;
+  bool ret;
   DBUG_ENTER("Log_event::write_header");
 
   /* Store number of bytes that will be written by this event */
   data_written= event_data_length + sizeof(header);
 
+  if (need_checksum())
+  {
+    crc= my_checksum(0L, NULL, 0);
+    data_written += BINLOG_CHECKSUM_LEN;
+  }
+
   /*
     log_pos != 0 if this is relay-log event. In this case we should not
     change the position
@@ -918,9 +1062,36 @@ bool Log_event::write_header(IO_CACHE* f
   int4store(header+ SERVER_ID_OFFSET, server_id);
   int4store(header+ EVENT_LEN_OFFSET, data_written);
   int4store(header+ LOG_POS_OFFSET, log_pos);
-  int2store(header+ FLAGS_OFFSET, flags);
-
-  DBUG_RETURN(my_b_safe_write(file, header, sizeof(header)) != 0);
+  /*
+    recording checksum of FD event computed with dropped
+    possibly active LOG_EVENT_BINLOG_IN_USE_F flag.
+    Similar step at verication: the active flag is dropped before
+    checksum computing.
+  */
+  if (header[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT ||
+      !need_checksum() || !(flags & LOG_EVENT_BINLOG_IN_USE_F))
+  {
+    int2store(header+ FLAGS_OFFSET, flags);
+    ret= wrapper_my_b_safe_write(file, header, sizeof(header)) != 0;
+  }
+  else
+  {
+    ret= (wrapper_my_b_safe_write(file, header, FLAGS_OFFSET) != 0);
+    if (!ret)
+    {
+      flags &= ~LOG_EVENT_BINLOG_IN_USE_F;
+      int2store(header + FLAGS_OFFSET, flags);
+      crc= my_checksum(crc, header + FLAGS_OFFSET, sizeof(flags));
+      flags |= LOG_EVENT_BINLOG_IN_USE_F;    
+      int2store(header + FLAGS_OFFSET, flags);
+      ret= (my_b_safe_write(file, header + FLAGS_OFFSET, sizeof(flags)) != 0);
+    }
+    if (!ret)
+      ret= (wrapper_my_b_safe_write(file, header + FLAGS_OFFSET + sizeof(flags),
+                                    sizeof(header)
+                                    - (FLAGS_OFFSET + sizeof(flags))) != 0);
+  }
+  DBUG_RETURN( ret);
 }
 
 
@@ -930,11 +1101,13 @@ bool Log_event::write_header(IO_CACHE* f
 */
 
 int Log_event::read_log_event(IO_CACHE* file, String* packet,
-                              mysql_mutex_t* log_lock)
+                              mysql_mutex_t* log_lock,
+                              uint8 checksum_alg_arg)
 {
   ulong data_len;
   int result=0;
   char buf[LOG_EVENT_MINIMAL_HEADER_LEN];
+  uchar ev_offset= packet->length();
   DBUG_ENTER("Log_event::read_log_event");
 
   if (log_lock)
@@ -993,6 +1166,31 @@ int Log_event::read_log_event(IO_CACHE*
                (file->error >= 0 ? LOG_READ_TRUNC: LOG_READ_IO));
       /* Implicit goto end; */
     }
+    else
+    {
+      /* Corrupt the event for Dump thread*/
+      DBUG_EXECUTE_IF("corrupt_read_log_event",
+	uchar *debug_event_buf_c = (uchar*) packet->ptr() + ev_offset;
+        if (debug_event_buf_c[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT)
+        {
+          int debug_cor_pos = rand() % (data_len + sizeof(buf) - BINLOG_CHECKSUM_LEN);
+          debug_event_buf_c[debug_cor_pos] =~ debug_event_buf_c[debug_cor_pos];
+          DBUG_PRINT("info", ("Corrupt the event at Log_event::read_log_event: byte on position %d", debug_cor_pos));
+          DBUG_SET("-d,corrupt_read_log_event");
+	}
+      );                                                                                           
+      /*
+        CRC verification of the Dump thread
+      */
+      if (opt_master_verify_checksum &&
+          event_checksum_test((uchar*) packet->ptr() + ev_offset,
+                              data_len + sizeof(buf),
+                              checksum_alg_arg))
+      {
+        result= LOG_READ_CHECKSUM_FAILURE;
+        goto end;
+      }
+    }
   }
 
 end:
@@ -1018,11 +1216,13 @@ end:
 Log_event* Log_event::read_log_event(IO_CACHE* file,
                                      mysql_mutex_t* log_lock,
                                      const Format_description_log_event
-                                     *description_event)
+                                     *description_event,
+                                     my_bool crc_check)
 #else
 Log_event* Log_event::read_log_event(IO_CACHE* file,
                                      const Format_description_log_event
-                                     *description_event)
+                                     *description_event,
+                                     my_bool crc_check)
 #endif
 {
   DBUG_ENTER("Log_event::read_log_event");
@@ -1087,7 +1287,7 @@ failed my_b_read"));
     error = "read error";
     goto err;
   }
-  if ((res= read_log_event(buf, data_len, &error, description_event)))
+  if ((res= read_log_event(buf, data_len, &error, description_event, crc_check)))
     res->register_temp_buf(buf);
 
 err:
@@ -1120,9 +1320,11 @@ err:
 
 Log_event* Log_event::read_log_event(const char* buf, uint event_len,
 				     const char **error,
-                                     const Format_description_log_event *description_event)
+                                     const Format_description_log_event *description_event,
+                                     my_bool crc_check)
 {
   Log_event* ev;
+  uint8 alg;
   DBUG_ENTER("Log_event::read_log_event(char*,...)");
   DBUG_ASSERT(description_event != 0);
   DBUG_PRINT("info", ("binlog_version: %d", description_event->binlog_version));
@@ -1138,6 +1340,60 @@ Log_event* Log_event::read_log_event(con
   }
 
   uint event_type= buf[EVENT_TYPE_OFFSET];
+  // all following START events in the current file are without checksum
+  if (event_type == START_EVENT_V3)
+    (const_cast< Format_description_log_event *>(description_event))->checksum_alg= BINLOG_CHECKSUM_ALG_OFF;
+  /*
+    CRC verification by SQL and Show-Binlog-Events master side.
+    The caller has to provide @description_event->checksum_alg to
+    be the last seen FD's (A) descriptor.
+    If event is FD the descriptor is in it.
+    Notice, FD of the binlog can be only in one instance and therefore
+    Show-Binlog-Events executing master side thread needs just to know
+    the only FD's (A) value -  whereas RL can contain more.
+    In the RL case, the alg is kept in FD_e (@description_event) which is reset 
+    to the newer read-out event after its execution with possibly new alg descriptor.
+    Therefore in a typical sequence of RL:
+    {FD_s^0, FD_m, E_m^1} E_m^1 
+    will be verified with (A) of FD_m.
+
+    See legends definition on MYSQL_BIN_LOG::relay_log_checksum_alg docs
+    lines (log.h).
+
+    Notice, a pre-checksum FD version forces alg := BINLOG_CHECKSUM_ALG_UNDEF.
+  */
+  alg= (event_type != FORMAT_DESCRIPTION_EVENT) ?
+    description_event->checksum_alg : get_checksum_alg(buf, event_len);
+  // Emulate the corruption during reading an event
+  DBUG_EXECUTE_IF("corrupt_read_log_event_char",
+    if (event_type != FORMAT_DESCRIPTION_EVENT)
+    {
+      char *debug_event_buf_c = (char *)buf;
+      int debug_cor_pos = rand() % (event_len - BINLOG_CHECKSUM_LEN);
+      debug_event_buf_c[debug_cor_pos] =~ debug_event_buf_c[debug_cor_pos];
+      DBUG_PRINT("info", ("Corrupt the event at Log_event::read_log_event(char*,...): byte on position %d", debug_cor_pos));
+      DBUG_SET("-d,corrupt_read_log_event_char");
+    }
+  );                                                 
+  if (crc_check &&
+      event_checksum_test((uchar *) buf, event_len, alg))
+  {
+#ifdef MYSQL_CLIENT
+    *error= "Event crc check failed! Most likely there is event corruption.";
+    if (force_opt)
+    {
+      ev= new Unknown_log_event(buf, description_event);
+      DBUG_RETURN(ev);
+    }
+    else
+      DBUG_RETURN(NULL);
+#else
+    *error= ER(ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE);
+    sql_print_error("%s", ER(ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE));
+    DBUG_RETURN(NULL);
+#endif
+  }
+
   if (event_type > description_event->number_of_event_types &&
       event_type != FORMAT_DESCRIPTION_EVENT)
   {
@@ -1172,6 +1428,11 @@ Log_event* Log_event::read_log_event(con
       event_type= new_event_type;
     }
 
+    if (alg != BINLOG_CHECKSUM_ALG_UNDEF &&
+        (event_type == FORMAT_DESCRIPTION_EVENT ||
+         alg != BINLOG_CHECKSUM_ALG_OFF))
+      event_len= event_len - BINLOG_CHECKSUM_LEN;
+    
     switch(event_type) {
     case QUERY_EVENT:
       ev  = new Query_log_event(buf, event_len, description_event, QUERY_EVENT);
@@ -1272,6 +1533,14 @@ Log_event* Log_event::read_log_event(con
     }
   }
 
+  if (ev)
+  {
+    ev->checksum_alg= alg;
+    if (ev->checksum_alg != BINLOG_CHECKSUM_ALG_OFF &&
+        ev->checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF)
+      ev->crc= uint4korr(buf + (event_len));
+  }
+
   DBUG_PRINT("read_event", ("%s(type_code: %d; event_len: %d)",
                             ev ? ev->get_type_str() : "<unknown>",
                             buf[EVENT_TYPE_OFFSET],
@@ -1326,6 +1595,18 @@ void Log_event::print_header(IO_CACHE* f
   my_b_printf(file, " server id %lu  end_log_pos %s ", (ulong) server_id,
               llstr(log_pos,llbuff));
 
+  /* print the checksum */
+
+  if (checksum_alg != BINLOG_CHECKSUM_ALG_OFF &&
+      checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF)
+  {
+    char checksum_buf[BINLOG_CHECKSUM_LEN * 2 + 4]; // to fit to "0x%lx "
+    size_t const bytes_written=
+      my_snprintf(checksum_buf, sizeof(checksum_buf), "0x%08lx ", (ulong) crc);
+    my_b_printf(file, "%s ", get_type(&binlog_checksum_typelib, checksum_alg));
+    my_b_printf(file, checksum_buf, bytes_written);
+  }
+
   /* mysqlbinlog --hexdump */
   if (print_event_info->hexdump_from)
   {
@@ -2003,6 +2284,9 @@ void Log_event::print_base64(IO_CACHE* f
   if (print_event_info->verbose)
   {
     Rows_log_event *ev= NULL;
+    if (checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF &&
+        checksum_alg != BINLOG_CHECKSUM_ALG_OFF)
+      size-= BINLOG_CHECKSUM_LEN; // checksum is displayed through the header
     
     if (ptr[4] == TABLE_MAP_EVENT)
     {
@@ -2365,12 +2649,13 @@ bool Query_log_event::write(IO_CACHE* fi
   event_length= (uint) (start-buf) + get_post_header_size_for_derived() + db_len + 1 + q_len;
 
   return (write_header(file, event_length) ||
-          my_b_safe_write(file, (uchar*) buf, QUERY_HEADER_LEN) ||
+          wrapper_my_b_safe_write(file, (uchar*) buf, QUERY_HEADER_LEN) ||
           write_post_header_for_derived(file) ||
-          my_b_safe_write(file, (uchar*) start_of_status,
+          wrapper_my_b_safe_write(file, (uchar*) start_of_status,
                           (uint) (start-start_of_status)) ||
-          my_b_safe_write(file, (db) ? (uchar*) db : (uchar*)"", db_len + 1) ||
-          my_b_safe_write(file, (uchar*) query, q_len)) ? 1 : 0;
+          wrapper_my_b_safe_write(file, (db) ? (uchar*) db : (uchar*)"", db_len + 1) ||
+          wrapper_my_b_safe_write(file, (uchar*) query, q_len) ||
+	  write_footer(file)) ? 1 : 0;
 }
 
 /**
@@ -3673,7 +3958,8 @@ bool Start_log_event_v3::write(IO_CACHE*
     created= when= get_time();
   int4store(buff + ST_CREATED_OFFSET,created);
   return (write_header(file, sizeof(buff)) ||
-          my_b_safe_write(file, (uchar*) buff, sizeof(buff)));
+          wrapper_my_b_safe_write(file, (uchar*) buff, sizeof(buff)) ||
+	  write_footer(file));
 }
 #endif
 
@@ -3776,6 +4062,7 @@ int Start_log_event_v3::do_apply_event(R
                                 old 4.0 (binlog version 2) is not supported;
                                 it should not be used for replication with
                                 5.0.
+  @param server_ver             a string containing the server version.
 */
 
 Format_description_log_event::
@@ -3791,9 +4078,9 @@ Format_description_log_event(uint8 binlo
     common_header_len= LOG_EVENT_HEADER_LEN;
     number_of_event_types= LOG_EVENT_TYPES;
     /* we'll catch my_malloc() error in is_valid() */
-    post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8),
+    post_header_len=(uint8*) my_malloc(number_of_event_types*sizeof(uint8)
+                                       + BINLOG_CHECKSUM_ALG_DESC_LEN,
                                        MYF(0));
-
     /*
       This long list of assignments is not beautiful, but I see no way to
       make it nicer, as the right members are #defines, not array members, so
@@ -3912,6 +4199,7 @@ Format_description_log_event(uint8 binlo
     break;
   }
   calc_server_version_split();
+  checksum_alg= (uint8) BINLOG_CHECKSUM_ALG_UNDEF;
 }
 
 
@@ -3941,19 +4229,39 @@ Format_description_log_event(const char*
                              description_event)
   :Start_log_event_v3(buf, description_event), event_type_permutation(0)
 {
+  ulong ver_calc;
   DBUG_ENTER("Format_description_log_event::Format_description_log_event(char*,...)");
   buf+= LOG_EVENT_MINIMAL_HEADER_LEN;
   if ((common_header_len=buf[ST_COMMON_HEADER_LEN_OFFSET]) < OLD_HEADER_LEN)
     DBUG_VOID_RETURN; /* sanity check */
   number_of_event_types=
-    event_len-(LOG_EVENT_MINIMAL_HEADER_LEN+ST_COMMON_HEADER_LEN_OFFSET+1);
+    event_len - (LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET + 1);
   DBUG_PRINT("info", ("common_header_len=%d number_of_event_types=%d",
                       common_header_len, number_of_event_types));
   /* If alloc fails, we'll detect it in is_valid() */
+
   post_header_len= (uint8*) my_memdup((uchar*)buf+ST_COMMON_HEADER_LEN_OFFSET+1,
                                       number_of_event_types*
-                                      sizeof(*post_header_len), MYF(0));
+                                      sizeof(*post_header_len),
+                                      MYF(0));
   calc_server_version_split();
+  if ((ver_calc= get_version_product()) >= checksum_version_product)
+  {
+    /* the last bytes are the checksum alg desc and value (or value's room) */
+    number_of_event_types -= BINLOG_CHECKSUM_ALG_DESC_LEN;
+    /*
+      FD from the checksum-home version server (ver_calc ==
+      checksum_version_product) must have 
+      number_of_event_types == LOG_EVENT_TYPES.
+    */
+    DBUG_ASSERT(ver_calc != checksum_version_product ||
+                number_of_event_types == LOG_EVENT_TYPES);
+    checksum_alg= post_header_len[number_of_event_types];
+  }
+  else
+  {
+    checksum_alg= (uint8) BINLOG_CHECKSUM_ALG_UNDEF;
+  }
 
   /*
     In some previous versions, the events were given other event type
@@ -4064,21 +4372,59 @@ Format_description_log_event(const char*
 #ifndef MYSQL_CLIENT
 bool Format_description_log_event::write(IO_CACHE* file)
 {
+  bool ret;
+  bool no_checksum;
   /*
     We don't call Start_log_event_v3::write() because this would make 2
     my_b_safe_write().
   */
-  uchar buff[FORMAT_DESCRIPTION_HEADER_LEN];
+  uchar buff[FORMAT_DESCRIPTION_HEADER_LEN + BINLOG_CHECKSUM_ALG_DESC_LEN];
+  size_t rec_size= sizeof(buff);
   int2store(buff + ST_BINLOG_VER_OFFSET,binlog_version);
   memcpy((char*) buff + ST_SERVER_VER_OFFSET,server_version,ST_SERVER_VER_LEN);
   if (!dont_set_created)
     created= when= get_time();
   int4store(buff + ST_CREATED_OFFSET,created);
   buff[ST_COMMON_HEADER_LEN_OFFSET]= LOG_EVENT_HEADER_LEN;
-  memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET+1, (uchar*) post_header_len,
+  memcpy((char*) buff+ST_COMMON_HEADER_LEN_OFFSET + 1, (uchar*) post_header_len,
          LOG_EVENT_TYPES);
-  return (write_header(file, sizeof(buff)) ||
-          my_b_safe_write(file, buff, sizeof(buff)));
+  /*
+    if checksum is requested
+    record the checksum-algorithm descriptor next to
+    post_header_len vector which will be followed by the checksum value.
+    Master is supposed to trigger checksum computing by binlog_checksum_options,
+    slave does it via marking the event according to
+    FD_queue checksum_alg value.
+  */
+  compile_time_assert(sizeof(BINLOG_CHECKSUM_ALG_DESC_LEN == 1));
+#ifndef DBUG_OFF
+  data_written= 0; // to prepare for need_checksum assert
+#endif
+  buff[FORMAT_DESCRIPTION_HEADER_LEN]= need_checksum() ?
+    checksum_alg : (uint8) BINLOG_CHECKSUM_ALG_OFF;
+  /* 
+     FD of checksum-aware server is always checksum-equipped, (V) is in,
+     regardless of @@global.binlog_checksum policy.
+     Thereby a combination of (A) == 0, (V) != 0 means
+     it's the checksum-aware server's FD event that heads checksum-free binlog
+     file. 
+     Here 0 stands for checksumming OFF to evaluate (V) as 0 is that case.
+     A combination of (A) != 0, (V) != 0 denotes FD of the checksum-aware server
+     heading the checksummed binlog.
+     (A), (V) presence in FD of the checksum-aware server makes the event
+     1 + 4 bytes bigger comparing to the former FD.
+  */
+
+  if ((no_checksum= (checksum_alg == BINLOG_CHECKSUM_ALG_OFF)))
+  {
+    checksum_alg= BINLOG_CHECKSUM_ALG_CRC32;  // Forcing (V) room to fill anyway
+  }
+  ret= (write_header(file, rec_size) ||
+        wrapper_my_b_safe_write(file, buff, rec_size) ||
+        write_footer(file));
+  if (no_checksum)
+    checksum_alg= BINLOG_CHECKSUM_ALG_OFF;
+  return ret;
 }
 #endif
 
@@ -4173,6 +4519,22 @@ Format_description_log_event::do_shall_s
 
 #endif
 
+inline void do_server_version_split(char* version, uchar split_versions[3])
+{
+  char *p= version, *r;
+  ulong number;
+  for (uint i= 0; i<=2; i++)
+  {
+    number= strtoul(p, &r, 10);
+    split_versions[i]= (uchar) number;
+    DBUG_ASSERT(number < 256); // fit in uchar
+    p= r;
+    DBUG_ASSERT(!((i == 0) && (*r != '.'))); // should be true in practice
+    if (*r == '.')
+      p++; // skip the dot
+  }
+}
+
 
 /**
    Splits the event's 'server_version' string into three numeric pieces stored
@@ -4185,24 +4547,71 @@ Format_description_log_event::do_shall_s
 */
 void Format_description_log_event::calc_server_version_split()
 {
-  char *p= server_version, *r;
-  ulong number;
-  for (uint i= 0; i<=2; i++)
-  {
-    number= strtoul(p, &r, 10);
-    server_version_split[i]= (uchar)number;
-    DBUG_ASSERT(number < 256); // fit in uchar
-    p= r;
-    DBUG_ASSERT(!((i == 0) && (*r != '.'))); // should be true in practice
-    if (*r == '.')
-      p++; // skip the dot
-  }
+  do_server_version_split(server_version, server_version_split);
+
   DBUG_PRINT("info",("Format_description_log_event::server_version_split:"
                      " '%s' %d %d %d", server_version,
                      server_version_split[0],
                      server_version_split[1], server_version_split[2]));
 }
 
+inline ulong version_product(const uchar* version_split)
+{
+  return ((version_split[0] * 256 + version_split[1]) * 256
+          + version_split[2]);
+}
+
+/**
+   @return integer representing the version of server that originated
+   the current FD instance.
+*/
+ulong Format_description_log_event::get_version_product() const
+{ 
+  return version_product(server_version_split);
+}
+
+/**
+   @return TRUE is the event's version is earlier than one that introduced
+   the replication event checksum. FALSE otherwise.
+*/
+bool Format_description_log_event::is_version_before_checksum() const
+{
+  return get_version_product() < checksum_version_product;
+}
+
+/**
+   @param buf buffer holding serialized FD event
+   @param len netto (possible checksum is stripped off) length of the event buf
+   
+   @return  the version-safe checksum alg descriptor where zero
+            designates no checksum, 255 - the orginator is
+            checksum-unaware (effectively no checksum) and the actuall
+            [1-254] range alg descriptor.
+*/
+uint8 get_checksum_alg(const char* buf, ulong len)
+{
+  uint8 ret;
+  char version[ST_SERVER_VER_LEN];
+  uchar version_split[3];
+
+  DBUG_ENTER("get_checksum_alg");
+  DBUG_ASSERT(buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);
+
+  memcpy(version, buf +
+         buf[LOG_EVENT_MINIMAL_HEADER_LEN + ST_COMMON_HEADER_LEN_OFFSET]
+         + ST_SERVER_VER_OFFSET, ST_SERVER_VER_LEN);
+  version[ST_SERVER_VER_LEN - 1]= 0;
+  
+  do_server_version_split(version, version_split);
+  ret= (version_product(version_split) < checksum_version_product) ?
+    (uint8) BINLOG_CHECKSUM_ALG_UNDEF :
+    * (uint8*) (buf + len - BINLOG_CHECKSUM_LEN - BINLOG_CHECKSUM_ALG_DESC_LEN);
+  DBUG_ASSERT(ret == BINLOG_CHECKSUM_ALG_OFF ||
+              ret == BINLOG_CHECKSUM_ALG_UNDEF ||
+              ret == BINLOG_CHECKSUM_ALG_CRC32);
+  DBUG_RETURN(ret);
+}
+  
 
   /**************************************************************************
         Load_log_event methods
@@ -5059,6 +5468,7 @@ Rotate_log_event::Rotate_log_event(const
   DBUG_PRINT("enter",("new_log_ident: %s  pos: %s  flags: %lu", new_log_ident_arg,
                       llstr(pos_arg, buff), (ulong) flags));
 #endif
+  cache_type= EVENT_NO_CACHE;
   if (flags & DUP_NAME)
     new_log_ident= my_strndup(new_log_ident_arg, ident_len, MYF(MY_WME));
   if (flags & RELAY_LOG)
@@ -5100,9 +5510,11 @@ bool Rotate_log_event::write(IO_CACHE* f
 {
   char buf[ROTATE_HEADER_LEN];
   int8store(buf + R_POS_OFFSET, pos);
-  return (write_header(file, ROTATE_HEADER_LEN + ident_len) ||
-          my_b_safe_write(file, (uchar*)buf, ROTATE_HEADER_LEN) ||
-          my_b_safe_write(file, (uchar*)new_log_ident, (uint) ident_len));
+  return (write_header(file, ROTATE_HEADER_LEN + ident_len) || 
+          wrapper_my_b_safe_write(file, (uchar*) buf, ROTATE_HEADER_LEN) ||
+          wrapper_my_b_safe_write(file, (uchar*) new_log_ident,
+                                     (uint) ident_len) ||
+          write_footer(file));
 }
 #endif
 
@@ -5276,7 +5688,8 @@ bool Intvar_log_event::write(IO_CACHE* f
   buf[I_TYPE_OFFSET]= (uchar) type;
   int8store(buf + I_VAL_OFFSET, val);
   return (write_header(file, sizeof(buf)) ||
-          my_b_safe_write(file, buf, sizeof(buf)));
+          wrapper_my_b_safe_write(file, buf, sizeof(buf)) ||
+	  write_footer(file));
 }
 #endif
 
@@ -5403,7 +5816,8 @@ bool Rand_log_event::write(IO_CACHE* fil
   int8store(buf + RAND_SEED1_OFFSET, seed1);
   int8store(buf + RAND_SEED2_OFFSET, seed2);
   return (write_header(file, sizeof(buf)) ||
-          my_b_safe_write(file, buf, sizeof(buf)));
+          wrapper_my_b_safe_write(file, buf, sizeof(buf)) ||
+	  write_footer(file));
 }
 #endif
 
@@ -5504,8 +5918,9 @@ Xid_log_event(const char* buf,
 bool Xid_log_event::write(IO_CACHE* file)
 {
   DBUG_EXECUTE_IF("do_not_write_xid", return 0;);
-  return write_header(file, sizeof(xid)) ||
-         my_b_safe_write(file, (uchar*) &xid, sizeof(xid));
+  return (write_header(file, sizeof(xid)) ||
+	  wrapper_my_b_safe_write(file, (uchar*) &xid, sizeof(xid)) ||
+	  write_footer(file));
 }
 #endif
 
@@ -5747,8 +6162,20 @@ User_var_log_event(const char* buf,
       we keep the flags set to UNDEF_F.
     */
     uint bytes_read= ((val + val_len) - start);
-    DBUG_ASSERT(bytes_read==data_written || 
-                bytes_read==(data_written-1));
+#ifndef DBUG_OFF
+    bool old_pre_checksum_fd= description_event->is_version_before_checksum();
+#endif
+    DBUG_ASSERT((bytes_read == data_written -
+                 (old_pre_checksum_fd ||
+                  (description_event->checksum_alg ==
+                   BINLOG_CHECKSUM_ALG_OFF)) ?
+                 0 : BINLOG_CHECKSUM_LEN)
+                ||
+                (bytes_read == data_written -1 -
+                 (old_pre_checksum_fd ||
+                  (description_event->checksum_alg ==
+                   BINLOG_CHECKSUM_ALG_OFF)) ?
+                 0 : BINLOG_CHECKSUM_LEN));
     if ((data_written - bytes_read) > 0)
     {
       flags= (uint) *(buf + UV_VAL_IS_NULL + UV_VAL_TYPE_SIZE +
@@ -5816,11 +6243,12 @@ bool User_var_log_event::write(IO_CACHE*
   event_length= sizeof(buf)+ name_len + buf1_length + val_len + unsigned_len;
 
   return (write_header(file, event_length) ||
-          my_b_safe_write(file, (uchar*) buf, sizeof(buf))   ||
-          my_b_safe_write(file, (uchar*) name, name_len)     ||
-          my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
-          my_b_safe_write(file, pos, val_len) ||
-          my_b_safe_write(file, &flags, unsigned_len));
+          wrapper_my_b_safe_write(file, (uchar*) buf, sizeof(buf))   ||
+	  wrapper_my_b_safe_write(file, (uchar*) name, name_len)     ||
+	  wrapper_my_b_safe_write(file, (uchar*) buf1, buf1_length) ||
+	  wrapper_my_b_safe_write(file, pos, val_len) ||
+          wrapper_my_b_safe_write(file, &flags, unsigned_len) ||
+	  write_footer(file));
 }
 #endif
 
@@ -6436,8 +6864,9 @@ bool Append_block_log_event::write(IO_CA
   uchar buf[APPEND_BLOCK_HEADER_LEN];
   int4store(buf + AB_FILE_ID_OFFSET, file_id);
   return (write_header(file, APPEND_BLOCK_HEADER_LEN + block_len) ||
-          my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
-	  my_b_safe_write(file, (uchar*) block, block_len));
+          wrapper_my_b_safe_write(file, buf, APPEND_BLOCK_HEADER_LEN) ||
+	  wrapper_my_b_safe_write(file, (uchar*) block, block_len) ||
+	  write_footer(file));
 }
 #endif
 
@@ -6595,7 +7024,8 @@ bool Delete_file_log_event::write(IO_CAC
  uchar buf[DELETE_FILE_HEADER_LEN];
  int4store(buf + DF_FILE_ID_OFFSET, file_id);
  return (write_header(file, sizeof(buf)) ||
-         my_b_safe_write(file, buf, sizeof(buf)));
+         wrapper_my_b_safe_write(file, buf, sizeof(buf)) ||
+	 write_footer(file));
 }
 #endif
 
@@ -6691,7 +7121,8 @@ bool Execute_load_log_event::write(IO_CA
   uchar buf[EXEC_LOAD_HEADER_LEN];
   int4store(buf + EL_FILE_ID_OFFSET, file_id);
   return (write_header(file, sizeof(buf)) || 
-          my_b_safe_write(file, buf, sizeof(buf)));
+          wrapper_my_b_safe_write(file, buf, sizeof(buf)) ||
+	  write_footer(file));
 }
 #endif
 
@@ -6751,16 +7182,17 @@ int Execute_load_log_event::do_apply_eve
                 fname);
     goto err;
   }
-  if (!(lev = (Load_log_event*)Log_event::read_log_event(&file,
-                                                         (mysql_mutex_t*)0,
-                                                         rli->relay_log.description_event_for_exec)) ||
+  if (!(lev= (Load_log_event*)
+        Log_event::read_log_event(&file,
+                                  (mysql_mutex_t*) 0,
+                                  rli->relay_log.description_event_for_exec,
+                                  opt_slave_sql_verify_checksum)) ||
       lev->get_type_code() != NEW_LOAD_EVENT)
   {
     rli->report(ERROR_LEVEL, 0, "Error in Exec_load event: "
                     "file '%s' appears corrupted", fname);
     goto err;
   }
-
   lev->thd = thd;
   /*
     lev->do_apply_event should use rli only for errors i.e. should
@@ -6922,7 +7354,7 @@ Execute_load_query_log_event::write_post
   int4store(buf + 4, fn_pos_start);
   int4store(buf + 4 + 4, fn_pos_end);
   *(buf + 4 + 4 + 4)= (uchar) dup_handling;
-  return my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
+  return wrapper_my_b_safe_write(file, buf, EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN);
 }
 #endif
 
@@ -7899,11 +8331,11 @@ bool Rows_log_event::write_data_header(I
                   {
                     int4store(buf + 0, m_table_id);
                     int2store(buf + 4, m_flags);
-                    return (my_b_safe_write(file, buf, 6));
+                    return (wrapper_my_b_safe_write(file, buf, 6));
                   });
   int6store(buf + RW_MAPID_OFFSET, (ulonglong)m_table_id);
   int2store(buf + RW_FLAGS_OFFSET, m_flags);
-  return (my_b_safe_write(file, buf, ROWS_HEADER_LEN));
+  return (wrapper_my_b_safe_write(file, buf, ROWS_HEADER_LEN));
 }
 
 bool Rows_log_event::write_data_body(IO_CACHE*file)
@@ -7919,10 +8351,10 @@ bool Rows_log_event::write_data_body(IO_
   DBUG_ASSERT(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
 
   DBUG_DUMP("m_width", sbuf, (size_t) (sbuf_end - sbuf));
-  res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
+  res= res || wrapper_my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
 
   DBUG_DUMP("m_cols", (uchar*) m_cols.bitmap, no_bytes_in_map(&m_cols));
-  res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
+  res= res || wrapper_my_b_safe_write(file, (uchar*) m_cols.bitmap,
                               no_bytes_in_map(&m_cols));
   /*
     TODO[refactor write]: Remove the "down cast" here (and elsewhere).
@@ -7931,11 +8363,11 @@ bool Rows_log_event::write_data_body(IO_
   {
     DBUG_DUMP("m_cols_ai", (uchar*) m_cols_ai.bitmap,
               no_bytes_in_map(&m_cols_ai));
-    res= res || my_b_safe_write(file, (uchar*) m_cols_ai.bitmap,
+    res= res || wrapper_my_b_safe_write(file, (uchar*) m_cols_ai.bitmap,
                                 no_bytes_in_map(&m_cols_ai));
   }
   DBUG_DUMP("rows", m_rows_buf, data_size);
-  res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
+  res= res || wrapper_my_b_safe_write(file, m_rows_buf, (size_t) data_size);
 
   return res;
 
@@ -8367,11 +8799,11 @@ bool Table_map_log_event::write_data_hea
                   {
                     int4store(buf + 0, m_table_id);
                     int2store(buf + 4, m_flags);
-                    return (my_b_safe_write(file, buf, 6));
+                    return (wrapper_my_b_safe_write(file, buf, 6));
                   });
   int6store(buf + TM_MAPID_OFFSET, (ulonglong)m_table_id);
   int2store(buf + TM_FLAGS_OFFSET, m_flags);
-  return (my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
+  return (wrapper_my_b_safe_write(file, buf, TABLE_MAP_HEADER_LEN));
 }
 
 bool Table_map_log_event::write_data_body(IO_CACHE *file)
@@ -8395,15 +8827,15 @@ bool Table_map_log_event::write_data_bod
   uchar mbuf[sizeof(m_field_metadata_size)];
   uchar *const mbuf_end= net_store_length(mbuf, m_field_metadata_size);
 
-  return (my_b_safe_write(file, dbuf,      sizeof(dbuf)) ||
-          my_b_safe_write(file, (const uchar*)m_dbnam,   m_dblen+1) ||
-          my_b_safe_write(file, tbuf,      sizeof(tbuf)) ||
-          my_b_safe_write(file, (const uchar*)m_tblnam,  m_tbllen+1) ||
-          my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
-          my_b_safe_write(file, m_coltype, m_colcnt) ||
-          my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
-          my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
-          my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
+  return (wrapper_my_b_safe_write(file, dbuf,      sizeof(dbuf)) ||
+          wrapper_my_b_safe_write(file, (const uchar*)m_dbnam,   m_dblen+1) ||
+          wrapper_my_b_safe_write(file, tbuf,      sizeof(tbuf)) ||
+          wrapper_my_b_safe_write(file, (const uchar*)m_tblnam,  m_tbllen+1) ||
+          wrapper_my_b_safe_write(file, cbuf, (size_t) (cbuf_end - cbuf)) ||
+          wrapper_my_b_safe_write(file, m_coltype, m_colcnt) ||
+          wrapper_my_b_safe_write(file, mbuf, (size_t) (mbuf_end - mbuf)) ||
+          wrapper_my_b_safe_write(file, m_field_metadata, m_field_metadata_size),
+          wrapper_my_b_safe_write(file, m_null_bits, (m_colcnt + 7) / 8));
  }
 #endif
 
@@ -9948,13 +10380,25 @@ Incident_log_event::write_data_header(IO
   DBUG_PRINT("enter", ("m_incident: %d", m_incident));
   uchar buf[sizeof(int16)];
   int2store(buf, (int16) m_incident);
-  DBUG_RETURN(my_b_safe_write(file, buf, sizeof(buf)));
+#ifndef MYSQL_CLIENT
+  DBUG_RETURN(wrapper_my_b_safe_write(file, buf, sizeof(buf)));
+#else
+   DBUG_RETURN(my_b_safe_write(file, buf, sizeof(buf)));
+#endif
 }
 
 bool
 Incident_log_event::write_data_body(IO_CACHE *file)
 {
+  uchar tmp[1];
   DBUG_ENTER("Incident_log_event::write_data_body");
+  tmp[0]= (uchar) m_message.length;
+  crc= my_checksum(crc, (uchar*) tmp, 1);
+  if (m_message.length > 0)
+  {
+    crc= my_checksum(crc, (uchar*) m_message.str, m_message.length);
+    // todo: report a bug on write_str accepts uint but treats it as uchar
+  }
   DBUG_RETURN(write_str(file, m_message.str, (uint) m_message.length));
 }
 

=== modified file 'sql/log_event.h'
--- a/sql/log_event.h	2010-11-08 02:49:16 +0000
+++ b/sql/log_event.h	2010-11-16 12:14:06 +0000
@@ -77,6 +77,7 @@ class String;
 #define LOG_READ_MEM    -5
 #define LOG_READ_TRUNC  -6
 #define LOG_READ_TOO_LARGE -7
+#define LOG_READ_CHECKSUM_FAILURE -8
 
 #define LOG_EVENT_OFFSET 4
 
@@ -541,6 +542,22 @@ struct sql_ex_info
 #endif
 #undef EXPECTED_OPTIONS         /* You shouldn't use this one */
 
+enum enum_binlog_checksum_alg {
+  BINLOG_CHECKSUM_ALG_OFF= 0,    // Events are without checksum though its generator
+                                 // is checksum-capable New Master (NM).
+  BINLOG_CHECKSUM_ALG_CRC32= 1,  // CRC32 of zlib algorithm.
+  BINLOG_CHECKSUM_ALG_ENUM_END,  // the cut line: valid alg range is [1, 0x7f].
+  BINLOG_CHECKSUM_ALG_UNDEF= 255 // special value to tag undetermined yet checksum
+                                 // or events from checksum-unaware servers
+};
+
+#define CHECKSUM_CRC32_SIGNATURE_LEN 4
+/**
+   defined statically while there is just one alg implemented
+*/
+#define BINLOG_CHECKSUM_LEN CHECKSUM_CRC32_SIGNATURE_LEN
+#define BINLOG_CHECKSUM_ALG_DESC_LEN 1  /* 1 byte checksum alg descriptor */
+
 /**
   @enum Log_event_type
 
@@ -990,6 +1007,10 @@ public:
   */
   ulong slave_exec_mode;
 
+  /**
+    Placeholder for event checksum while writing to binlog.
+   */
+  ha_checksum crc;
 #ifdef MYSQL_SERVER
   THD* thd;
 
@@ -1009,9 +1030,10 @@ public:
   static Log_event* read_log_event(IO_CACHE* file,
                                    mysql_mutex_t* log_lock,
                                    const Format_description_log_event
-                                   *description_event);
+                                   *description_event,
+                                   my_bool crc_check);
   static int read_log_event(IO_CACHE* file, String* packet,
-                            mysql_mutex_t* log_lock);
+                            mysql_mutex_t* log_lock, uint8 checksum_alg_arg);
   /*
     init_show_field_list() prepares the column names and types for the
     output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
@@ -1038,7 +1060,7 @@ public:
     /* avoid having to link mysqlbinlog against libpthread */
   static Log_event* read_log_event(IO_CACHE* file,
                                    const Format_description_log_event
-                                   *description_event);
+                                   *description_event, my_bool crc_check);
   /* print*() functions are used by mysqlbinlog */
   virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
   void print_timestamp(IO_CACHE* file, time_t *ts = 0);
@@ -1047,6 +1069,15 @@ public:
   void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
                     bool is_more);
 #endif
+  /* 
+     The value is set by caller of FD constructor and
+     Log_event::write_header() for the rest.
+     In the FD case it's propagated into the last byte 
+     of post_header_len[] at FD::write().
+     On the slave side the value is assigned from post_header_len[last] 
+     of the last seen FD event.
+  */
+  uint8 checksum_alg;
 
   static void *operator new(size_t size)
   {
@@ -1061,14 +1092,19 @@ public:
   /* Placement version of the above operators */
   static void *operator new(size_t, void* ptr) { return ptr; }
   static void operator delete(void*, void*) { }
+  bool wrapper_my_b_safe_write(IO_CACHE* file, const uchar* buf, ulong data_length);
 
 #ifdef MYSQL_SERVER
   bool write_header(IO_CACHE* file, ulong data_length);
+  bool write_footer(IO_CACHE* file);
+  my_bool need_checksum();
+
   virtual bool write(IO_CACHE* file)
   {
-    return (write_header(file, get_data_size()) ||
-            write_data_header(file) ||
-            write_data_body(file));
+    return(write_header(file, get_data_size()) ||
+	   write_data_header(file) ||
+	   write_data_body(file) ||
+	   write_footer(file));
   }
   virtual bool write_data_header(IO_CACHE* file)
   { return 0; }
@@ -1125,7 +1161,7 @@ public:
   static Log_event* read_log_event(const char* buf, uint event_len,
 				   const char **error,
                                    const Format_description_log_event
-                                   *description_event);
+                                   *description_event, my_bool crc_check);
   /**
     Returns the human readable name of the given event type.
   */
@@ -2227,7 +2263,10 @@ public:
   */
   uint8 common_header_len;
   uint8 number_of_event_types;
-  /* The list of post-headers' lengthes */
+  /* 
+     The list of post-headers' lengths followed 
+     by the checksum alg decription byte
+  */
   uint8 *post_header_len;
   uchar server_version_split[3];
   const uint8 *event_type_permutation;
@@ -2261,7 +2300,8 @@ public:
   }
 
   void calc_server_version_split();
-
+  ulong get_version_product() const;
+  bool is_version_before_checksum() const;
 protected:
 #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
   virtual int do_apply_event(Relay_log_info const *rli);
@@ -2316,9 +2356,10 @@ public:
   uchar type;
 
 #ifdef MYSQL_SERVER
-  Intvar_log_event(THD* thd_arg,uchar type_arg, ulonglong val_arg)
-    :Log_event(thd_arg,0,0),val(val_arg),type(type_arg)
-  {}
+  Intvar_log_event(THD* thd_arg, uchar type_arg, ulonglong val_arg,
+                   uint16 cache_type_arg)
+    :Log_event(thd_arg, 0, 0), val(val_arg), type(type_arg)
+  { cache_type= cache_type_arg; }
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
 #endif /* HAVE_REPLICATION */
@@ -2392,9 +2433,10 @@ class Rand_log_event: public Log_event
   ulonglong seed2;
 
 #ifdef MYSQL_SERVER
-  Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg)
-    :Log_event(thd_arg,0,0),seed1(seed1_arg),seed2(seed2_arg)
-  {}
+  Rand_log_event(THD* thd_arg, ulonglong seed1_arg, ulonglong seed2_arg,
+                 uint16 cache_type_arg)
+    :Log_event(thd_arg, 0, 0), seed1(seed1_arg), seed2(seed2_arg)
+    { cache_type= cache_type_arg; }
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
 #endif /* HAVE_REPLICATION */
@@ -2438,7 +2480,8 @@ class Xid_log_event: public Log_event
    my_xid xid;
 
 #ifdef MYSQL_SERVER
-  Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
+  Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg, 0, 0), xid(x)
+  { cache_type= EVENT_NO_CACHE; }
 #ifdef HAVE_REPLICATION
   void pack_info(Protocol* protocol);
 #endif /* HAVE_REPLICATION */
@@ -2490,11 +2533,12 @@ public:
 #ifdef MYSQL_SERVER
   User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg,
                      char *val_arg, ulong val_len_arg, Item_result type_arg,
-		     uint charset_number_arg, uchar flags_arg)
-    :Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg),
-    val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg),
-    flags(flags_arg)
-    { is_null= !val; }
+		     uint charset_number_arg, uchar flags_arg,
+                     uint16 cache_type_arg)
+    :Log_event(thd_arg, 0, 0), name(name_arg), name_len(name_len_arg), val(val_arg),
+     val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg),
+     flags(flags_arg)
+    { is_null= !val; cache_type= cache_type_arg; }
   void pack_info(Protocol* protocol);
 #else
   void print(FILE* file, PRINT_EVENT_INFO* print_event_info);
@@ -4154,6 +4198,10 @@ int append_query_string(CHARSET_INFO *cs
 bool sqlcom_can_generate_row_events(const THD *thd);
 void handle_rows_query_log_event(Log_event *ev, Relay_log_info *rli);
 
+bool event_checksum_test(uchar *buf, ulong event_len, uint8 alg);
+uint8 get_checksum_alg(const char* buf, ulong len);
+extern TYPELIB binlog_checksum_typelib;
+
 /**
   @} (end of group Replication)
 */

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2010-11-26 13:46:21 +0000
+++ b/sql/mysqld.cc	2010-11-29 11:23:33 +0000
@@ -435,6 +435,10 @@ my_bool opt_noacl;
 my_bool sp_automatic_privileges= 1;
 
 ulong opt_binlog_rows_event_max_size;
+const char *binlog_checksum_default= "NONE";
+ulong binlog_checksum_options;
+my_bool opt_master_verify_checksum= 0;
+my_bool opt_slave_sql_verify_checksum= 1;
 const char *binlog_format_names[]= {"MIXED", "STATEMENT", "ROW", NullS};
 #ifdef HAVE_INITGROUPS
 static bool calling_initgroups= FALSE; /**< Used in SIGSEGV handler. */
@@ -4626,6 +4630,7 @@ int mysqld_main(int argc, char **argv)
 
 #ifndef DBUG_OFF
   test_lc_time_sz();
+  srand(time(NULL)); 
 #endif
 
   /*

=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h	2010-11-18 16:34:56 +0000
+++ b/sql/mysqld.h	2010-11-29 11:23:33 +0000
@@ -180,6 +180,10 @@ extern ulong binlog_cache_size, open_fil
 extern ulonglong max_binlog_cache_size;
 extern ulong max_binlog_size, max_relay_log_size;
 extern ulong opt_binlog_rows_event_max_size;
+extern ulong binlog_checksum_options;
+extern const char *binlog_checksum_type_names[];
+extern my_bool opt_master_verify_checksum;
+extern my_bool opt_slave_sql_verify_checksum;
 extern ulong thread_cache_size;
 extern ulong back_log;
 extern char language[FN_REFLEN];
@@ -355,6 +359,7 @@ enum options_mysqld
 {
   OPT_to_set_the_start_number=256,
   OPT_BIND_ADDRESS,
+  OPT_BINLOG_CHECKSUM,
   OPT_BINLOG_DO_DB,
   OPT_BINLOG_FORMAT,
   OPT_BINLOG_IGNORE_DB,
@@ -371,6 +376,7 @@ enum options_mysqld
   OPT_LC_MESSAGES_DIRECTORY,
   OPT_LOWER_CASE_TABLE_NAMES,
   OPT_MASTER_RETRY_COUNT,
+  OPT_MASTER_VERIFY_CHECKSUM,
   OPT_POOL_OF_THREADS,
   OPT_REPLICATE_DO_DB,
   OPT_REPLICATE_DO_TABLE,
@@ -387,6 +393,7 @@ enum options_mysqld
   OPT_SKIP_RESOLVE,
   OPT_SKIP_STACK_TRACE,
   OPT_SKIP_SYMLINKS,
+  OPT_SLAVE_SQL_VERIFY_CHECKSUM,
   OPT_SSL_CA,
   OPT_SSL_CAPATH,
   OPT_SSL_CERT,

=== modified file 'sql/rpl_master.cc'
--- a/sql/rpl_master.cc	2010-09-28 15:17:29 +0000
+++ b/sql/rpl_master.cc	2010-10-27 14:51:07 +0000
@@ -36,6 +36,8 @@ static int binlog_dump_count = 0;
 #define SLAVE_LIST_CHUNK 128
 #define SLAVE_ERRMSG_SIZE (FN_REFLEN+64)
 HASH slave_list;
+extern TYPELIB binlog_checksum_typelib;
+
 
 #define get_object(p, obj, msg) \
 {\
@@ -242,6 +244,86 @@ bool show_slave_hosts(THD* thd)
 }
 
 
+/**
+   Internal to mysql_binlog_send() routine that recalculates checksum for
+   a FD event (asserted) that needs additional arranment prior sending to slave.
+*/
+inline void fix_checksum(String *packet, ulong ev_offset)
+{
+  /* recalculate the crc for this event */
+  uint data_len = uint4korr(packet->ptr() + ev_offset + EVENT_LEN_OFFSET);
+  ha_checksum crc= my_checksum(0L, NULL, 0);
+  DBUG_ASSERT(data_len == 
+              LOG_EVENT_MINIMAL_HEADER_LEN + FORMAT_DESCRIPTION_HEADER_LEN +
+              BINLOG_CHECKSUM_ALG_DESC_LEN + BINLOG_CHECKSUM_LEN);
+  crc= my_checksum(crc, (uchar *)packet->ptr() + ev_offset, data_len -
+                   BINLOG_CHECKSUM_LEN);
+  int4store(packet->ptr() + ev_offset + data_len - BINLOG_CHECKSUM_LEN, crc);
+}
+
+
+static user_var_entry * get_binlog_checksum_uservar(THD * thd)
+{
+  LEX_STRING name=  { C_STRING_WITH_LEN("master_binlog_checksum")};
+  user_var_entry *entry= 
+    (user_var_entry*) my_hash_search(&thd->user_vars, (uchar*) name.str,
+                                  name.length);
+  return entry;
+}
+
+/**
+  Function for calling in mysql_binlog_send
+  to check if slave initiated checksum-handshake.
+
+  @param[in]    thd  THD to access a user variable
+
+  @return        TRUE if handshake took place, FALSE otherwise
+*/
+
+static bool is_slave_checksum_aware(THD * thd)
+{
+  DBUG_ENTER("is_slave_checksum_aware");
+  user_var_entry *entry= get_binlog_checksum_uservar(thd);
+  DBUG_RETURN(entry? true  : false);
+}
+
+/**
+  Function for calling in mysql_binlog_send
+  to get the value of @@binlog_checksum of the master at
+  time of checksum-handshake.
+
+  The value tells the master whether to compute or not, and the slave
+  to verify or not the first artificial Rotate event's checksum.
+
+  @param[in]    thd  THD to access a user variable
+
+  @return       value of @@binlog_checksum alg according to
+                @c enum enum_binlog_checksum_alg
+*/
+
+static uint8 get_binlog_checksum_value_at_connect(THD * thd)
+{
+  uint8 ret;
+
+  DBUG_ENTER("get_binlog_checksum_value_at_connect");
+  user_var_entry *entry= get_binlog_checksum_uservar(thd);
+  if (!entry)
+  {
+    ret= BINLOG_CHECKSUM_ALG_UNDEF;
+  }
+  else
+  {
+    DBUG_ASSERT(entry->type == STRING_RESULT);
+    String str;
+    uint dummy_errors;
+    str.copy(entry->value, entry->length, &my_charset_bin, &my_charset_bin,
+             &dummy_errors);
+    ret= (uint8) find_type ((char*) str.ptr(), &binlog_checksum_typelib, 1) - 1;
+    DBUG_ASSERT(ret <= BINLOG_CHECKSUM_ALG_CRC32); // while it's just on CRC32 alg
+  }
+  DBUG_RETURN(ret);
+}
+
 /*
     fake_rotate_event() builds a fake (=which does not exist physically in any
     binlog) Rotate event, which contains the name of the binlog we are going to
@@ -261,10 +343,21 @@ bool show_slave_hosts(THD* thd)
 */
 
 static int fake_rotate_event(NET* net, String* packet, char* log_file_name,
-                             ulonglong position, const char** errmsg)
+                             ulonglong position, const char** errmsg,
+                             uint8 checksum_alg_arg)
 {
   DBUG_ENTER("fake_rotate_event");
   char header[LOG_EVENT_HEADER_LEN], buf[ROTATE_HEADER_LEN+100];
+
+  /*
+    this Rotate is to be sent with checksum if and only if
+    slave's get_master_version_and_clock time handshake value 
+    of master's @@global.binlog_checksum was TRUE
+  */
+
+  my_bool do_checksum= checksum_alg_arg != BINLOG_CHECKSUM_ALG_OFF &&
+    checksum_alg_arg != BINLOG_CHECKSUM_ALG_UNDEF;
+
   /*
     'when' (the timestamp) is set to 0 so that slave could distinguish between
     real and fake Rotate events (if necessary)
@@ -274,7 +367,8 @@ static int fake_rotate_event(NET* net, S
 
   char* p = log_file_name+dirname_length(log_file_name);
   uint ident_len = (uint) strlen(p);
-  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN + ROTATE_HEADER_LEN;
+  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN + ROTATE_HEADER_LEN +
+    (do_checksum ? BINLOG_CHECKSUM_LEN : 0);
   int4store(header + SERVER_ID_OFFSET, server_id);
   int4store(header + EVENT_LEN_OFFSET, event_len);
   int2store(header + FLAGS_OFFSET, LOG_EVENT_ARTIFICIAL_F);
@@ -285,7 +379,19 @@ static int fake_rotate_event(NET* net, S
   packet->append(header, sizeof(header));
   int8store(buf+R_POS_OFFSET,position);
   packet->append(buf, ROTATE_HEADER_LEN);
-  packet->append(p,ident_len);
+  packet->append(p, ident_len);
+
+  if (do_checksum)
+  {
+    char b[BINLOG_CHECKSUM_LEN];
+    ha_checksum crc= my_checksum(0L, NULL, 0);
+    crc= my_checksum(crc, (uchar*)header, sizeof(header));
+    crc= my_checksum(crc, (uchar*)buf, ROTATE_HEADER_LEN);
+    crc= my_checksum(crc, (uchar*)p, ident_len);
+    int4store(b, crc);
+    packet->append(b, sizeof(b));
+  }
+
   if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
   {
     *errmsg = "failed on my_net_write()";
@@ -416,6 +522,9 @@ Increase max_allowed_packet on master";
   case LOG_READ_TRUNC:
     *errmsg = "binlog truncated in the middle of event";
     break;
+  case LOG_READ_CHECKSUM_FAILURE:
+    *errmsg = "event read from binlog did not pass crc check";
+    break;
   default:
     *errmsg = "unknown error reading log event on the master";
     break;
@@ -458,10 +567,13 @@ static ulonglong get_heartbeat_period(TH
     the dump thread.
 */
 static int send_heartbeat_event(NET* net, String* packet,
-                                const struct event_coordinates *coord)
+                                const struct event_coordinates *coord,
+                                uint8 checksum_alg_arg)
 {
   DBUG_ENTER("send_heartbeat_event");
   char header[LOG_EVENT_HEADER_LEN];
+  my_bool do_checksum= checksum_alg_arg != BINLOG_CHECKSUM_ALG_OFF &&
+    checksum_alg_arg != BINLOG_CHECKSUM_ALG_UNDEF;
   /*
     'when' (the timestamp) is set to 0 so that slave could distinguish between
     real and fake Rotate events (if necessary)
@@ -473,7 +585,8 @@ static int send_heartbeat_event(NET* net
   char* p= coord->file_name + dirname_length(coord->file_name);
 
   uint ident_len = strlen(p);
-  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN;
+  ulong event_len = ident_len + LOG_EVENT_HEADER_LEN +
+    (do_checksum ? BINLOG_CHECKSUM_LEN : 0);
   int4store(header + SERVER_ID_OFFSET, server_id);
   int4store(header + EVENT_LEN_OFFSET, event_len);
   int2store(header + FLAGS_OFFSET, 0);
@@ -483,6 +596,16 @@ static int send_heartbeat_event(NET* net
   packet->append(header, sizeof(header));
   packet->append(p, ident_len);             // log_file_name
 
+  if (do_checksum)
+  {
+    char b[BINLOG_CHECKSUM_LEN];
+    ha_checksum crc= my_checksum(0L, NULL, 0);
+    crc= my_checksum(crc, (uchar*) header, sizeof(header));
+    crc= my_checksum(crc, (uchar*) p, ident_len);
+    int4store(b, crc);
+    packet->append(b, sizeof(b));
+  }
+
   if (my_net_write(net, (uchar*) packet->ptr(), packet->length()) ||
       net_flush(net))
   {
@@ -513,6 +636,8 @@ void mysql_binlog_send(THD* thd, char* l
   mysql_mutex_t *log_lock;
   mysql_cond_t *log_cond;
   bool binlog_can_be_corrupted= FALSE;
+  uint8 current_checksum_alg= BINLOG_CHECKSUM_ALG_UNDEF;
+
 #ifndef DBUG_OFF
   int left_events = max_binlog_dump_events;
 #endif
@@ -632,7 +757,8 @@ impossible position";
     given that we want minimum modification of 4.0, we send the normal
     and fake Rotates.
   */
-  if (fake_rotate_event(net, packet, log_file_name, pos, &errmsg))
+  if (fake_rotate_event(net, packet, log_file_name, pos, &errmsg,
+                        get_binlog_checksum_value_at_connect(current_thd)))
   {
     /*
        This error code is not perfect, as fake_rotate_event() does not
@@ -668,8 +794,8 @@ impossible position";
        Try to find a Format_description_log_event at the beginning of
        the binlog
      */
-     if (!(error = Log_event::read_log_event(&log, packet, log_lock)))
-     {
+    if (!(error = Log_event::read_log_event(&log, packet, log_lock, 0)))
+    { 
        /*
          The packet has offsets equal to the normal offsets in a
          binlog event + ev_offset (the first ev_offset characters are
@@ -677,9 +803,26 @@ impossible position";
        */
        DBUG_PRINT("info",
                   ("Looked for a Format_description_log_event, found event type %d",
-                   (*packet)[EVENT_TYPE_OFFSET+ev_offset]));
-       if ((*packet)[EVENT_TYPE_OFFSET+ev_offset] == FORMAT_DESCRIPTION_EVENT)
+                   (*packet)[EVENT_TYPE_OFFSET + ev_offset]));
+       if ((*packet)[EVENT_TYPE_OFFSET + ev_offset] == FORMAT_DESCRIPTION_EVENT)
        {
+         current_checksum_alg= get_checksum_alg(packet->ptr() + ev_offset,
+                                                packet->length() - ev_offset);
+         DBUG_ASSERT(current_checksum_alg == BINLOG_CHECKSUM_ALG_OFF ||
+                     current_checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF ||
+                     current_checksum_alg == BINLOG_CHECKSUM_ALG_CRC32);
+         if (!is_slave_checksum_aware(thd) &&
+             current_checksum_alg != BINLOG_CHECKSUM_ALG_OFF &&
+             current_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF)
+         {
+           my_errno= ER_MASTER_FATAL_ERROR_READING_BINLOG;
+           errmsg= "Slave can not handle replication events with the checksum "
+             "that master is configured to log";
+           sql_print_warning("Master is configured to log replication events "
+                             "with checksum, but will not send such events to "
+                             "slaves that cannot process them");
+           goto err;
+         }
          binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+ev_offset] &
                                        LOG_EVENT_BINLOG_IN_USE_F);
          (*packet)[FLAGS_OFFSET+ev_offset] &= ~LOG_EVENT_BINLOG_IN_USE_F;
@@ -695,6 +838,12 @@ impossible position";
           */
          int4store((char*) packet->ptr()+LOG_EVENT_MINIMAL_HEADER_LEN+
                    ST_CREATED_OFFSET+ev_offset, (ulong) 0);
+
+	 /* fix the checksum due to latest changes in header */
+	 if (current_checksum_alg != BINLOG_CHECKSUM_ALG_OFF &&
+             current_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF)
+           fix_checksum(packet, ev_offset);
+
          /* send it */
          if (my_net_write(net, (uchar*) packet->ptr(), packet->length()))
          {
@@ -737,7 +886,8 @@ impossible position";
        file */
     if (reset_transmit_packet(thd, flags, &ev_offset, &errmsg))
       goto err;
-    while (!(error = Log_event::read_log_event(&log, packet, log_lock)))
+    while (!(error = Log_event::read_log_event(&log, packet, log_lock,
+                                               current_checksum_alg)))
     {
 #ifndef DBUG_OFF
       if (max_binlog_dump_events && !left_events--)
@@ -757,6 +907,23 @@ impossible position";
       event_type= (Log_event_type)((*packet)[LOG_EVENT_OFFSET+ev_offset]);
       if (event_type == FORMAT_DESCRIPTION_EVENT)
       {
+        current_checksum_alg= get_checksum_alg(packet->ptr() + ev_offset,
+                                               packet->length() - ev_offset);
+        DBUG_ASSERT(current_checksum_alg == BINLOG_CHECKSUM_ALG_OFF ||
+                    current_checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF ||
+                    current_checksum_alg == BINLOG_CHECKSUM_ALG_CRC32);
+        if (!is_slave_checksum_aware(thd) &&
+            current_checksum_alg != BINLOG_CHECKSUM_ALG_OFF &&
+            current_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF)
+        {
+          my_errno= ER_MASTER_FATAL_ERROR_READING_BINLOG;
+          errmsg= "Slave can not handle replication events with the checksum "
+            "that master is configured to log";
+          sql_print_warning("Master is configured to log replication events "
+                            "with checksum, but will not send such events to "
+                            "slaves that cannot process them");
+          goto err;
+        }
         binlog_can_be_corrupted= test((*packet)[FLAGS_OFFSET+ev_offset] &
                                       LOG_EVENT_BINLOG_IN_USE_F);
         (*packet)[FLAGS_OFFSET+ev_offset] &= ~LOG_EVENT_BINLOG_IN_USE_F;
@@ -807,7 +974,8 @@ impossible position";
       here we were reading binlog that was not closed properly (as a result
       of a crash ?). treat any corruption as EOF
     */
-    if (binlog_can_be_corrupted && error != LOG_READ_MEM)
+    if (binlog_can_be_corrupted &&
+        (error != LOG_READ_MEM && error != LOG_READ_CHECKSUM_FAILURE))
       error=LOG_READ_EOF;
     /*
       TODO: now that we are logging the offset, check to make sure
@@ -867,7 +1035,8 @@ impossible position";
 	*/
 
         mysql_mutex_lock(log_lock);
-        switch (error= Log_event::read_log_event(&log, packet, (mysql_mutex_t*) 0)) {
+        switch (error= Log_event::read_log_event(&log, packet, (mysql_mutex_t*) 0,
+                                                 current_checksum_alg)) {
 	case 0:
 	  /* we read successfully, so we'll need to send it to the slave */
           mysql_mutex_unlock(log_lock);
@@ -875,6 +1044,7 @@ impossible position";
           if (coord)
             coord->pos= uint4korr(packet->ptr() + ev_offset + LOG_POS_OFFSET);
           event_type= (Log_event_type)((*packet)[LOG_EVENT_OFFSET+ev_offset]);
+          DBUG_ASSERT(event_type != FORMAT_DESCRIPTION_EVENT);
 	  break;
 
 	case LOG_READ_EOF:
@@ -922,7 +1092,7 @@ impossible position";
                 thd->exit_cond(old_msg);
                 goto err;
               }
-              if (send_heartbeat_event(net, packet, coord))
+              if (send_heartbeat_event(net, packet, coord, current_checksum_alg))
               {
                 errmsg = "Failed on my_net_write()";
                 my_errno= ER_UNKNOWN_ERROR;
@@ -1027,7 +1197,7 @@ impossible position";
       */
       if ((file=open_binlog(&log, log_file_name, &errmsg)) < 0 ||
 	  fake_rotate_event(net, packet, log_file_name, BIN_LOG_HEADER_SIZE,
-                            &errmsg))
+                            &errmsg, current_checksum_alg))
       {
 	my_errno= ER_MASTER_FATAL_ERROR_READING_BINLOG;
 	goto err;

=== modified file 'sql/rpl_mi.cc'
--- a/sql/rpl_mi.cc	2010-11-26 13:59:07 +0000
+++ b/sql/rpl_mi.cc	2010-11-29 11:23:33 +0000
@@ -87,7 +87,9 @@ Master_info::Master_info(PSI_mutex_key *
    ssl(0), ssl_verify_server_cert(0),
    port(MYSQL_PORT), connect_retry(DEFAULT_CONNECT_RETRY),
    clock_diff_with_master(0), heartbeat_period(0),
-   received_heartbeats(0), master_id(0), retry_count(master_retry_count)
+   received_heartbeats(0), master_id(0),
+   checksum_alg_before_fd(BINLOG_CHECKSUM_ALG_UNDEF),
+   retry_count(master_retry_count)
 {
   host[0] = 0; user[0] = 0; password[0] = 0; bind_addr[0] = 0;
   ssl_ca[0]= 0; ssl_capath[0]= 0; ssl_cert[0]= 0;

=== modified file 'sql/rpl_mi.h'
--- a/sql/rpl_mi.h	2010-11-26 07:32:00 +0000
+++ b/sql/rpl_mi.h	2010-11-29 11:23:33 +0000
@@ -98,6 +98,12 @@ class Master_info : public Rpl_info
   ulonglong received_heartbeats;  // counter of received heartbeat events
   Server_ids *ignore_server_ids;
   ulong master_id;
+  /*
+    to hold checksum alg in use until IO thread has received FD.
+    Initialized to novalue, then set to the queried from master
+    @@global.binlog_checksum and deactivated once FD has been received.
+  */
+  uint8 checksum_alg_before_fd;
   ulong retry_count;
   char master_uuid[UUID_LENGTH+1];
   char bind_addr[HOSTNAME_LENGTH+1];

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2010-11-18 16:34:56 +0000
+++ b/sql/rpl_rli.cc	2010-11-29 11:23:33 +0000
@@ -286,8 +286,9 @@ int Relay_log_info::init_relay_log_pos(c
         Because of we have data_lock and log_lock, we can safely read an
         event
       */
-      if (!(ev=Log_event::read_log_event(cur_log,0,
-                                         relay_log.description_event_for_exec)))
+      if (!(ev= Log_event::read_log_event(cur_log, 0,
+                                          relay_log.description_event_for_exec,
+                                          opt_slave_sql_verify_checksum)))
       {
         DBUG_PRINT("info",("could not read event, cur_log->error=%d",
                            cur_log->error));
@@ -1152,6 +1153,9 @@ a file name for --relay-log-index option
                         "use '--relay-log=%s' to avoid this problem.", ln);
       name_warning_sent= 1;
     }
+
+    relay_log.is_relay_log= TRUE;
+
     /*
       note, that if open() fails, we'll still have index file open
       but a destructor will take care of that
@@ -1164,7 +1168,6 @@ a file name for --relay-log-index option
       sql_print_error("Failed in open_log() called from Relay_log_info::init_info()");
       DBUG_RETURN(1);
     }
-    relay_log.is_relay_log= TRUE;
   }
 
   /*

=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc	2010-11-28 09:11:02 +0000
+++ b/sql/rpl_slave.cc	2010-11-29 11:23:33 +0000
@@ -1373,6 +1373,48 @@ static int get_master_version_and_clock(
   }
 
   /*
+    FD_q's (A) is set initially from RL's (A): FD_q.(A) := RL.(A).
+    It's necessary to adjust FD_q.(A) at this point because in the following
+    course FD_q is going to be dumped to RL.
+    Generally FD_q is derived from a received FD_m (roughly FD_q := FD_m) 
+    in queue_event and the master's (A) is installed.
+    At one step with the assignment the Relay-Log's checksum alg is set to 
+    a new value: RL.(A) := FD_q.(A). If the slave service is stopped
+    the last time assigned RL.(A) will be passed over to the restarting
+    service (to the current execution point).
+    RL.A is a "codec" to verify checksum in queue_event() almost all the time
+    the first fake Rotate event.
+    Starting from this point IO thread will executes the following checksum
+    warmup sequence  of actions:
+
+    FD_q.A := RL.A,
+    A_m^0 := master.@@global.binlog_checksum,
+    {queue_event(R_f): verifies(R_f, A_m^0)},
+    {queue_event(FD_m): verifies(FD_m, FD_m.A), dump(FD_q), rotate(RL),
+                        FD_q := FD_m, RL.A := FD_q.A)}
+
+    See legends definition on MYSQL_BIN_LOG::relay_log_checksum_alg
+    docs lines (binlog.h).
+    In above A_m^0 - the value of master's
+    @@binlog_checksum determined in the upcoming handshake (stored in
+    mi->checksum_alg_before_fd).
+
+
+    After the warm-up sequence IO gets to "normal" checksum verification mode
+    to use RL.A in 
+    
+    {queue_event(E_m): verifies(E_m, RL.A)}
+
+    until it has received a new FD_m.
+  */
+  mi->rli->relay_log.description_event_for_queue->checksum_alg=
+    mi->rli->relay_log.relay_log_checksum_alg;
+
+  DBUG_ASSERT(mi->rli->relay_log.description_event_for_queue->checksum_alg !=
+              BINLOG_CHECKSUM_ALG_UNDEF);
+  DBUG_ASSERT(mi->rli->relay_log.relay_log_checksum_alg !=
+              BINLOG_CHECKSUM_ALG_UNDEF); 
+  /*
     Compare the master and slave's clock. Do not die if master's clock is
     unavailable (very old master not supporting UNIX_TIMESTAMP()?).
   */
@@ -1632,20 +1674,130 @@ when it try to get the value of TIME_ZON
     llstr((ulonglong) (mi->heartbeat_period*1000000000UL), llbuf);
     sprintf(query, query_format, llbuf);
 
-    if (mysql_real_query(mysql, query, strlen(query))
-        && !check_io_slave_killed(mi->info_thd, mi, NULL))
+    if (mysql_real_query(mysql, query, strlen(query)))
     {
-      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;
+      if (check_io_slave_killed(mi->info_thd, mi, NULL))
+        goto slave_killed_err;
+
+      if (is_network_error(mysql_errno(mysql)))
+      {
+        mi->report(WARNING_LEVEL, mysql_errno(mysql),
+                   "SET @master_heartbeat_period to master failed with error: %s",
+                   mysql_error(mysql));
+        mysql_free_result(mysql_store_result(mysql));
+        goto network_err;
+      }
+      else
+      {
+        /* Fatal error */
+        errmsg= "The slave I/O thread stops because a fatal error is encountered "
+          " when it tries to SET @master_heartbeat_period on master.";
+        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));
   }
- 
 
+  /*
+    Querying if master is capable to checksum and notifying it about own
+    CRC-awareness. The master's side instant value of @@global.binlog_checksum 
+    is stored in the dump thread's uservar area as well as cached locally
+    to become known in consensus by master and slave.
+  */
+  DBUG_EXECUTE_IF("simulate_slave_unaware_checksum",
+                  mi->checksum_alg_before_fd= BINLOG_CHECKSUM_ALG_OFF;
+                  goto past_checksum;);
+  {
+    int rc;
+    const char query[]= "SET @master_binlog_checksum= @@global.binlog_checksum";
+    master_res= NULL;
+    mi->checksum_alg_before_fd= BINLOG_CHECKSUM_ALG_UNDEF; //initially undefined
+    /*
+      @c checksum_alg_before_fd is queried from master in this block.
+      If master is old checksum-unaware the value stays undefined.
+      Once the first FD will be received its alg descriptor will replace
+      the being queried one.
+    */
+    rc= mysql_real_query(mysql, query, strlen(query));
+    if (rc != 0)
+    {
+      if (check_io_slave_killed(mi->info_thd, mi, NULL))
+        goto slave_killed_err;
+
+      if (mysql_errno(mysql) == ER_UNKNOWN_SYSTEM_VARIABLE)
+      {
+        // this is tolerable as OM -> NS is supported
+        mi->report(WARNING_LEVEL, mysql_errno(mysql),
+                   "Notifying master by %s failed with "
+                   "error: %s", query, mysql_error(mysql));
+      }
+      else
+      {
+        if (is_network_error(mysql_errno(mysql)))
+        {
+          mi->report(WARNING_LEVEL, mysql_errno(mysql),
+                     "Notifying master by %s failed with "
+                     "error: %s", query, mysql_error(mysql));
+          mysql_free_result(mysql_store_result(mysql));
+          goto network_err;
+        }
+        else
+        {
+          errmsg= "The slave I/O thread stops because a fatal error is encountered "
+            "when it tried to SET @master_binlog_checksum on master.";
+          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;
+        }
+      }
+    }
+    else
+    {
+      mysql_free_result(mysql_store_result(mysql));
+      if (!mysql_real_query(mysql,
+                            STRING_WITH_LEN("SELECT @master_binlog_checksum")) &&
+          (master_res= mysql_store_result(mysql)) &&
+          (master_row= mysql_fetch_row(master_res)) &&
+          (master_row[0] != NULL))
+      {
+        mi->checksum_alg_before_fd= (uint8)
+          find_type(master_row[0], &binlog_checksum_typelib, 1) - 1;
+        // valid outcome is either of
+        DBUG_ASSERT(mi->checksum_alg_before_fd == BINLOG_CHECKSUM_ALG_OFF ||
+                    mi->checksum_alg_before_fd == BINLOG_CHECKSUM_ALG_CRC32);
+      }
+      else if (check_io_slave_killed(mi->info_thd, mi, NULL))
+        goto slave_killed_err;
+      else if (is_network_error(mysql_errno(mysql)))
+      {
+        mi->report(WARNING_LEVEL, mysql_errno(mysql),
+                   "Get master BINLOG_CHECKSUM failed with error: %s", mysql_error(mysql));
+        goto network_err;
+      }
+      else
+      {
+        errmsg= "The slave I/O thread stops because a fatal error is encountered "
+          "when it tried to SELECT @master_binlog_checksum.";
+        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;
+      }
+    }
+    if (master_res)
+    {
+      mysql_free_result(master_res);
+      master_res= NULL;
+    }
+  }
+
+#ifndef DBUG_OFF
+past_checksum:
+#endif
 err:
   if (errmsg)
   {
@@ -3937,10 +4089,15 @@ static int process_io_rotate(Master_info
   */
   if (mi->rli->relay_log.description_event_for_queue->binlog_version >= 4)
   {
+    DBUG_ASSERT(mi->rli->relay_log.description_event_for_queue->checksum_alg ==
+                mi->rli->relay_log.relay_log_checksum_alg);
+    
     delete mi->rli->relay_log.description_event_for_queue;
     /* start from format 3 (MySQL 4.0) again */
     mi->rli->relay_log.description_event_for_queue= new
       Format_description_log_event(3);
+    mi->rli->relay_log.description_event_for_queue->checksum_alg=
+      mi->rli->relay_log.relay_log_checksum_alg;    
   }
   /*
     Rotate the relay log makes binlog format detection easier (at next slave
@@ -3994,8 +4151,9 @@ static int queue_binlog_ver_1_event(Mast
     Append_block/Exec_load (the SQL thread needs the data, as that thread is not
     connected to the master).
   */
-  Log_event *ev = Log_event::read_log_event(buf,event_len, &errmsg,
-                                            mi->rli->relay_log.description_event_for_queue);
+  Log_event *ev=
+    Log_event::read_log_event(buf, event_len, &errmsg,
+                              mi->rli->relay_log.description_event_for_queue, 0);
   if (unlikely(!ev))
   {
     sql_print_error("Read invalid event from master: '%s',\
@@ -4082,8 +4240,9 @@ static int queue_binlog_ver_3_event(Mast
   DBUG_ENTER("queue_binlog_ver_3_event");
 
   /* read_log_event() will adjust log_pos to be end_log_pos */
-  Log_event *ev = Log_event::read_log_event(buf,event_len, &errmsg,
-                                            mi->rli->relay_log.description_event_for_queue);
+  Log_event *ev=
+    Log_event::read_log_event(buf, event_len, &errmsg,
+                              mi->rli->relay_log.description_event_for_queue, 0);
   if (unlikely(!ev))
   {
     sql_print_error("Read invalid event from master: '%s',\
@@ -4109,6 +4268,7 @@ static int queue_binlog_ver_3_event(Mast
     inc_pos= event_len;
     break;
   }
+
   if (unlikely(rli->relay_log.append(ev)))
   {
     delete ev;
@@ -4172,7 +4332,68 @@ static int queue_event(Master_info* mi,c
   Relay_log_info *rli= mi->rli;
   mysql_mutex_t *log_lock= rli->relay_log.get_log_lock();
   ulong s_id;
+  bool unlock_data_lock= TRUE;
+  /*
+    FD_q must have been prepared for the first R_a event
+    inside get_master_version_and_clock()
+    Show-up of FD:s affects checksum_alg at once because
+    that changes FD_queue.
+  */
+  uint8 checksum_alg= mi->checksum_alg_before_fd != BINLOG_CHECKSUM_ALG_UNDEF ? 
+    mi->checksum_alg_before_fd :
+    mi->rli->relay_log.relay_log_checksum_alg;
+
+  char *save_buf= NULL; // needed for checksumming the fake Rotate event
+  char rot_buf[LOG_EVENT_HEADER_LEN + ROTATE_HEADER_LEN + FN_REFLEN];
+
+  DBUG_ASSERT(checksum_alg == BINLOG_CHECKSUM_ALG_OFF || 
+              checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF || 
+              checksum_alg == BINLOG_CHECKSUM_ALG_CRC32); 
+
   DBUG_ENTER("queue_event");
+  /*
+    FD_queue checksum alg description does not apply in a case of
+    FD itself. The one carries both parts of the checksum data.
+  */
+  if (buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT)
+  {
+    checksum_alg= get_checksum_alg(buf, event_len);
+  }
+  else if (buf[EVENT_TYPE_OFFSET] == START_EVENT_V3)
+  {
+    // checksum behaviour is similar to the pre-checksum FD handling
+    mi->checksum_alg_before_fd= BINLOG_CHECKSUM_ALG_UNDEF;
+    mi->rli->relay_log.description_event_for_queue->checksum_alg=
+      mi->rli->relay_log.relay_log_checksum_alg= checksum_alg=
+      BINLOG_CHECKSUM_ALG_OFF;
+  }
+
+  // does not hold always because of old binlog can work with NM 
+  // DBUG_ASSERT(checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF);
+
+  // should hold unless manipulations with RL. Tests that do that
+  // will have to refine the clause.
+  DBUG_ASSERT(mi->rli->relay_log.relay_log_checksum_alg !=
+              BINLOG_CHECKSUM_ALG_UNDEF);
+              
+  // Emulate the network corruption
+  DBUG_EXECUTE_IF("corrupt_queue_event",
+    if (buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT)
+    {
+      char *debug_event_buf_c = (char*) buf;
+      int debug_cor_pos = rand() % (event_len - BINLOG_CHECKSUM_LEN);
+      debug_event_buf_c[debug_cor_pos] =~ debug_event_buf_c[debug_cor_pos];
+      DBUG_PRINT("info", ("Corrupt the event at queue_event: byte on position %d", debug_cor_pos));
+      DBUG_SET("-d,corrupt_queue_event");
+    }
+  );
+                                              
+  if (event_checksum_test((uchar *) buf, event_len, checksum_alg))
+  {
+    error= ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE;
+    unlock_data_lock= FALSE;
+    goto err;
+  }
 
   LINT_INIT(inc_pos);
 
@@ -4200,12 +4421,67 @@ static int queue_event(Master_info* mi,c
     goto err;
   case ROTATE_EVENT:
   {
-    Rotate_log_event rev(buf,event_len,mi->rli->relay_log.description_event_for_queue);
-    if (unlikely(process_io_rotate(mi,&rev)))
+    Rotate_log_event rev(buf, checksum_alg != BINLOG_CHECKSUM_ALG_OFF ?
+                         event_len - BINLOG_CHECKSUM_LEN : event_len,
+                         mi->rli->relay_log.description_event_for_queue);
+
+    if (unlikely(process_io_rotate(mi, &rev)))
     {
       error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE;
       goto err;
     }
+    /* 
+       Checksum special cases for the fake Rotate (R_f) event caused by the protocol
+       of events generation and serialization in RL where Rotate of master is 
+       queued right next to FD of slave.
+       Since it's only FD that carries the alg desc of FD_s has to apply to R_m.
+       Two special rules apply only to the first R_f which comes in before any FD_m.
+       The 2nd R_f should be compatible with the FD_s that must have taken over
+       the last seen FD_m's (A).
+       
+       RSC_1: If OM \and fake Rotate \and slave is configured to
+              to compute checksum for its first FD event for RL
+              the fake Rotate gets checksummed here.
+    */
+    if (uint4korr(&buf[0]) == 0 && checksum_alg == BINLOG_CHECKSUM_ALG_OFF &&
+        mi->rli->relay_log.relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_OFF)
+    {
+      ha_checksum rot_crc= my_checksum(0L, NULL, 0);
+      event_len += BINLOG_CHECKSUM_LEN;
+      memcpy(rot_buf, buf, event_len - BINLOG_CHECKSUM_LEN);
+      int4store(&rot_buf[EVENT_LEN_OFFSET],
+                uint4korr(&rot_buf[EVENT_LEN_OFFSET]) + BINLOG_CHECKSUM_LEN);
+      rot_crc= my_checksum(rot_crc, (const uchar *) rot_buf,
+                           event_len - BINLOG_CHECKSUM_LEN);
+      int4store(&rot_buf[event_len - BINLOG_CHECKSUM_LEN], rot_crc);
+      DBUG_ASSERT(event_len == uint4korr(&rot_buf[EVENT_LEN_OFFSET]));
+      DBUG_ASSERT(mi->rli->relay_log.description_event_for_queue->checksum_alg ==
+                  mi->rli->relay_log.relay_log_checksum_alg);
+      /* the first one */
+      DBUG_ASSERT(mi->checksum_alg_before_fd != BINLOG_CHECKSUM_ALG_UNDEF);
+      save_buf= (char *) buf;
+      buf= rot_buf;
+    }
+    else
+      /*
+        RSC_2: If NM \and fake Rotate \and slave does not compute checksum
+        the fake Rotate's checksum is stripped off before relay-logging.
+      */
+      if (uint4korr(&buf[0]) == 0 && checksum_alg != BINLOG_CHECKSUM_ALG_OFF &&
+          mi->rli->relay_log.relay_log_checksum_alg == BINLOG_CHECKSUM_ALG_OFF)
+      {
+        event_len -= BINLOG_CHECKSUM_LEN;
+        memcpy(rot_buf, buf, event_len);
+        int4store(&rot_buf[EVENT_LEN_OFFSET],
+                  uint4korr(&rot_buf[EVENT_LEN_OFFSET]) - BINLOG_CHECKSUM_LEN);
+        DBUG_ASSERT(event_len == uint4korr(&rot_buf[EVENT_LEN_OFFSET]));
+        DBUG_ASSERT(mi->rli->relay_log.description_event_for_queue->checksum_alg ==
+                    mi->rli->relay_log.relay_log_checksum_alg);
+        /* the first one */
+        DBUG_ASSERT(mi->checksum_alg_before_fd != BINLOG_CHECKSUM_ALG_UNDEF);
+        save_buf= (char *) buf;
+        buf= rot_buf;
+      }
     /*
       Now the I/O thread has just changed its mi->get_master_log_name(), so
       incrementing mi->get_master_log_pos() is nonsense.
@@ -4226,15 +4502,24 @@ static int queue_event(Master_info* mi,c
     */
     Format_description_log_event* tmp;
     const char* errmsg;
+    // mark it as undefined that is irrelevant anymore
+    mi->checksum_alg_before_fd= BINLOG_CHECKSUM_ALG_UNDEF;
     if (!(tmp= (Format_description_log_event*)
           Log_event::read_log_event(buf, event_len, &errmsg,
-                                    mi->rli->relay_log.description_event_for_queue)))
+                                    mi->rli->relay_log.description_event_for_queue,
+                                    1)))
     {
       error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE;
       goto err;
     }
     delete mi->rli->relay_log.description_event_for_queue;
     mi->rli->relay_log.description_event_for_queue= tmp;
+    if (tmp->checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF)
+      tmp->checksum_alg= BINLOG_CHECKSUM_ALG_OFF;
+
+    /* installing new value of checksum Alg for relay log */
+    mi->rli->relay_log.relay_log_checksum_alg= tmp->checksum_alg;
+
     /*
        Though this does some conversion to the slave's format, this will
        preserve the master's binlog format version, and number of event types.
@@ -4256,7 +4541,11 @@ static int queue_event(Master_info* mi,c
       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);
+    Heartbeat_log_event hb(buf,
+                           mi->rli->relay_log.relay_log_checksum_alg
+                           != BINLOG_CHECKSUM_ALG_OFF ?
+                           event_len - BINLOG_CHECKSUM_LEN : event_len,
+                           mi->rli->relay_log.description_event_for_queue);
     if (!hb.is_valid())
     {
       error= ER_SLAVE_HEARTBEAT_FAILURE;
@@ -4379,13 +4668,16 @@ static int queue_event(Master_info* mi,c
       error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE;
     }
     rli->ign_master_log_name_end[0]= 0; // last event is not ignored
+    if (save_buf != NULL)
+      buf= save_buf;
   }
   mysql_mutex_unlock(log_lock);
 
 skip_relay_logging:
   
 err:
-  mysql_mutex_unlock(&mi->data_lock);
+  if (unlock_data_lock)
+    mysql_mutex_unlock(&mi->data_lock);
   DBUG_PRINT("info", ("error: %d", error));
   if (error)
     mi->report(ERROR_LEVEL, error, ER(error), 
@@ -4777,8 +5069,9 @@ static Log_event* next_event(Relay_log_i
       But if the relay log is created by new_file(): then the solution is:
       MYSQL_BIN_LOG::open() will write the buffered description event.
     */
-    if ((ev=Log_event::read_log_event(cur_log,0,
-                                      rli->relay_log.description_event_for_exec)))
+    if ((ev= Log_event::read_log_event(cur_log, 0,
+                                       rli->relay_log.description_event_for_exec,
+                                       opt_slave_sql_verify_checksum)))
     {
       DBUG_ASSERT(thd==rli->info_thd);
       /*
@@ -5733,9 +6026,9 @@ bool change_master(THD* thd, Master_info
       need_relay_log_purge)
    {
      /*
-       Sometimes mi->rli.master_log_pos == 0 (it happens when the SQL thread is
+       Sometimes mi->rli->master_log_pos == 0 (it happens when the SQL thread is
        not initialized), so we use a max().
-       What happens to mi->rli.master_log_pos during the initialization stages
+       What happens to mi->rli->master_log_pos during the initialization stages
        of replication is not 100% clear, so we guard against problems using
        max().
       */

=== modified file 'sql/rpl_utility.cc'
--- a/sql/rpl_utility.cc	2010-11-05 07:58:42 +0000
+++ b/sql/rpl_utility.cc	2010-11-16 12:14:06 +0000
@@ -1057,3 +1057,58 @@ table_def::~table_def()
 #endif
 }
 
+/**
+   @param   even_buf    point to the buffer containing serialized event
+   @param   event_len   length of the event accounting possible checksum alg
+
+   @return  TRUE        if test fails
+            FALSE       as success
+*/
+bool event_checksum_test(uchar *event_buf, ulong event_len, uint8 alg)
+{
+  bool res= FALSE;
+  uint16 flags= 0; // to store in FD's buffer flags orig value
+
+  if (alg != BINLOG_CHECKSUM_ALG_OFF && alg != BINLOG_CHECKSUM_ALG_UNDEF)
+  {
+    ha_checksum incoming;
+    ha_checksum computed;
+
+    if (event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT)
+    {
+#ifndef DBUG_OFF
+      int8 fd_alg= event_buf[event_len - BINLOG_CHECKSUM_LEN - 
+                             BINLOG_CHECKSUM_ALG_DESC_LEN];
+#endif
+      /*
+        FD event is checksummed and therefore verified w/o the binlog-in-use flag
+      */
+      flags= uint2korr(event_buf + FLAGS_OFFSET);
+      if (flags & LOG_EVENT_BINLOG_IN_USE_F)
+        event_buf[FLAGS_OFFSET] &= ~LOG_EVENT_BINLOG_IN_USE_F;
+      /* 
+         The only algorithm currently is CRC32. Zero indicates 
+         the binlog file is checksum-free *except* the FD-event.
+      */
+      DBUG_ASSERT(fd_alg == BINLOG_CHECKSUM_ALG_CRC32 || fd_alg == 0);
+      DBUG_ASSERT(alg == BINLOG_CHECKSUM_ALG_CRC32);
+      /*
+        Complile time guard to watch over  the max number of alg
+      */
+      compile_time_assert(BINLOG_CHECKSUM_ALG_ENUM_END <= 0x80);
+    }
+    incoming= uint4korr(event_buf + event_len - BINLOG_CHECKSUM_LEN);
+    computed= my_checksum(0L, NULL, 0);
+    /* checksum the event content but the checksum part itself */
+    computed= my_checksum(computed, (const uchar*) event_buf, 
+                          event_len - BINLOG_CHECKSUM_LEN);
+    if (flags != 0)
+    {
+      /* restoring the orig value of flags of FD */
+      DBUG_ASSERT(event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);
+      event_buf[FLAGS_OFFSET]= flags;
+    }
+    res= !(computed == incoming);
+  }
+  return DBUG_EVALUATE_IF("simulate_checksum_test_failure", TRUE, res);
+}

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2010-11-15 16:43:41 +0000
+++ b/sql/share/errmsg-utf8.txt	2010-11-23 23:10:22 +0000
@@ -6439,10 +6439,14 @@ ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MA
 ER_PARTITION_EXCHANGE_FOREIGN_KEY
   eng "Table to exchange with partition has foreign key references: '%-.64s'"
   swe "Tabellen att byta ut mot partition har foreign key referenser: '%-.64s'"
-
 ER_NO_SUCH_KEY_VALUE
   eng "Key value '%-.192s' was not found in table '%-.192s.%-.192s'"
 ER_RPL_INFO_DATA_TOO_LONG
   eng "Data for column '%s' too long"
 ER_CANT_LOCK_RPL_INFO_TABLE
         eng "You can't use locks with rpl info tables."
+ER_NETWORK_READ_EVENT_CHECKSUM_FAILURE
+  eng "Replication event checksum verification failed while reading from network."
+ER_BINLOG_READ_EVENT_CHECKSUM_FAILURE
+  eng "Replication event checksum verification failed while reading from a log file."
+

=== modified file 'sql/sql_binlog.cc'
--- a/sql/sql_binlog.cc	2010-11-28 10:39:14 +0000
+++ b/sql/sql_binlog.cc	2010-11-29 11:23:33 +0000
@@ -248,7 +248,8 @@ void mysql_client_binlog_statement(THD*
         goto end;
 
       ev= Log_event::read_log_event(bufptr, event_len, &error,
-                                    rli->relay_log.description_event_for_exec);
+                                    rli->relay_log.description_event_for_exec,
+                                    0);
 
       DBUG_PRINT("info",("binlog base64 err=%s", error));
       if (!ev)

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2010-11-23 22:37:59 +0000
+++ b/sql/sql_class.h	2010-11-29 11:23:33 +0000
@@ -162,7 +162,7 @@ typedef struct st_user_var_events
 
 #define RP_LOCK_LOG_IS_ALREADY_LOCKED 1
 #define RP_FORCE_ROTATE               2
-
+#define RP_BINLOG_CHECKSUM_ALG_CHANGE 4
 /*
   The COPY_INFO structure is used by INSERT/REPLACE code.
   The schema of the row counting by the INSERT/INSERT ... ON DUPLICATE KEY

=== modified file 'sql/sys_vars.cc'
--- a/sql/sys_vars.cc	2010-11-26 13:46:21 +0000
+++ b/sql/sys_vars.cc	2010-11-29 11:23:33 +0000
@@ -1878,8 +1878,52 @@ static Sys_var_set Slave_type_conversion
        GLOBAL_VAR(slave_type_conversions_options), CMD_LINE(REQUIRED_ARG),
        slave_type_conversions_name,
        DEFAULT(0));
+
+static Sys_var_mybool Sys_slave_sql_verify_checksum(
+       "slave_sql_verify_checksum",
+       "Force checksum verification of replication events after reading them "
+       "from relay log. Note: Events are always checksum-verified by slave on "
+       "receiving them from the network before writing them to the relay "
+       "log. Enabled by default.",
+       GLOBAL_VAR(opt_slave_sql_verify_checksum), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
 #endif
 
+bool Sys_var_enum_binlog_checksum::global_update(THD *thd, set_var *var)
+{
+  mysql_mutex_lock(mysql_bin_log.get_log_lock());
+  if(mysql_bin_log.is_open())
+  {
+    uint flags= RP_FORCE_ROTATE | RP_LOCK_LOG_IS_ALREADY_LOCKED |
+      (binlog_checksum_options != (uint) var->save_result.ulonglong_value?
+       RP_BINLOG_CHECKSUM_ALG_CHANGE : 0);
+    if (flags & RP_BINLOG_CHECKSUM_ALG_CHANGE)
+      mysql_bin_log.checksum_alg_reset= (uint8) var->save_result.ulonglong_value;
+    mysql_bin_log.rotate_and_purge(flags);
+  }
+  else
+  {
+    binlog_checksum_options= var->save_result.ulonglong_value;
+  }
+  DBUG_ASSERT((ulong) binlog_checksum_options == var->save_result.ulonglong_value);
+  DBUG_ASSERT(mysql_bin_log.checksum_alg_reset == BINLOG_CHECKSUM_ALG_UNDEF);
+  mysql_mutex_unlock(mysql_bin_log.get_log_lock());
+  return 0;
+}
+
+static Sys_var_enum_binlog_checksum Binlog_checksum_enum(
+       "binlog_checksum", "Type of BINLOG_CHECKSUM_ALG. Include checksum for "
+       "log events in the binary log. Possible values are NONE and CRC32; "
+       "default is NONE.",
+       GLOBAL_VAR(binlog_checksum_options), CMD_LINE(REQUIRED_ARG),
+       binlog_checksum_type_names, DEFAULT(BINLOG_CHECKSUM_ALG_OFF),
+       NO_MUTEX_GUARD, NOT_IN_BINLOG);
+
+static Sys_var_mybool Sys_master_verify_checksum(
+       "master_verify_checksum",
+       "Force checksum verification of logged events in binary log before "
+       "sending them to slaves or printing them in output of SHOW BINLOG EVENTS. "
+       "Disabled by default.",
+       GLOBAL_VAR(opt_master_verify_checksum), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
 
 static Sys_var_ulong Sys_slow_launch_time(
        "slow_launch_time",

=== modified file 'sql/sys_vars.h'
--- a/sql/sys_vars.h	2010-10-26 09:10:59 +0000
+++ b/sql/sys_vars.h	2010-11-16 12:14:06 +0000
@@ -1674,6 +1674,24 @@ public:
   virtual bool session_update(THD *thd, set_var *var);
 };
 
+/**
+   A class for @@global.binlog_checksum that has
+   a specialized update method.
+*/
+class Sys_var_enum_binlog_checksum: public Sys_var_enum
+{
+public:
+  Sys_var_enum_binlog_checksum(const char *name_arg,
+          const char *comment, int flag_args, ptrdiff_t off, size_t size,
+          CMD_LINE getopt,
+          const char *values[], uint def_val, PolyLock *lock,
+          enum binlog_status_enum binlog_status_arg)
+    :Sys_var_enum(name_arg, comment, flag_args, off, size, getopt,
+                  values, def_val, lock, binlog_status_arg, NULL)
+  {}
+  virtual bool global_update(THD *thd, set_var *var);
+};
+
 /****************************************************************************
   Used templates
 ****************************************************************************/

No bundle (reason: revision is a merge).
Thread
bzr commit into mysql-trunk-bugfixing branch (luis.soares:3407) Luis Soares29 Nov