[Commits] 9af42db: MDEV-7192: binlog_annotate_row_events not completely compatible with galera

Nirbhay Choubey nirbhay at mariadb.com
Thu Mar 5 21:14:00 EET 2015


revision-id: 9af42db6138a555454b7631761b81f8d259f014e
parent(s): 73a143ab34be0007cc0fc17cf5fda00fef063c1c
committer: Nirbhay Choubey
branch nick: 10.0-galera
timestamp: 2015-03-05 14:14:00 -0500
message:

MDEV-7192: binlog_annotate_row_events not completely compatible with galera

Annotate_rows event needs to be preserved until the last Rows event has
been applied because after it has been applied thd->query points to the
query stored inside this event.

---
 mysql-test/suite/galera/r/rpl_row_annotate.result | 66 +++++++++++++++++++++++
 mysql-test/suite/galera/t/rpl_row_annotate.cnf    |  6 +++
 mysql-test/suite/galera/t/rpl_row_annotate.test   | 42 +++++++++++++++
 sql/wsrep_applier.cc                              |  8 +--
 sql/wsrep_thd.cc                                  | 11 ++--
 5 files changed, 127 insertions(+), 6 deletions(-)

diff --git a/mysql-test/suite/galera/r/rpl_row_annotate.result b/mysql-test/suite/galera/r/rpl_row_annotate.result
new file mode 100644
index 0000000..ff8d497
--- /dev/null
+++ b/mysql-test/suite/galera/r/rpl_row_annotate.result
@@ -0,0 +1,66 @@
+# On node_2
+RESET MASTER;
+# On node_1
+RESET MASTER;
+CREATE TABLE t1(i INT)ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+DELETE FROM t1 WHERE i = 1;
+# On node_2
+INSERT INTO t1 VALUES(2);
+DELETE FROM t1 WHERE i = 2;
+# On node_1
+SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM <start_pos>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+mysqld-bin.000001	#	Gtid_list	1	#	[]
+mysqld-bin.000001	#	Binlog_checkpoint	1	#	mysqld-bin.000001
+mysqld-bin.000001	#	Gtid	1	#	GTID 0-1-1
+mysqld-bin.000001	#	Query	1	#	use `test`; CREATE TABLE t1(i INT)ENGINE=INNODB
+mysqld-bin.000001	#	Gtid	1	#	BEGIN GTID 0-1-2
+mysqld-bin.000001	#	Annotate_rows	1	#	INSERT INTO t1 VALUES(1)
+mysqld-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Write_rows_v1	1	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	1	#	COMMIT /* xid= */
+mysqld-bin.000001	#	Gtid	1	#	BEGIN GTID 0-1-3
+mysqld-bin.000001	#	Annotate_rows	1	#	DELETE FROM t1 WHERE i = 1
+mysqld-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Delete_rows_v1	1	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	1	#	COMMIT /* xid= */
+mysqld-bin.000001	#	Gtid	2	#	BEGIN GTID 0-2-4
+mysqld-bin.000001	#	Annotate_rows	2	#	INSERT INTO t1 VALUES(2)
+mysqld-bin.000001	#	Table_map	2	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Write_rows_v1	2	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	2	#	COMMIT /* xid= */
+mysqld-bin.000001	#	Gtid	2	#	BEGIN GTID 0-2-5
+mysqld-bin.000001	#	Annotate_rows	2	#	DELETE FROM t1 WHERE i = 2
+mysqld-bin.000001	#	Table_map	2	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Delete_rows_v1	2	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	2	#	COMMIT /* xid= */
+# On node_2
+SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM <start_pos>;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+mysqld-bin.000001	#	Gtid_list	2	#	[]
+mysqld-bin.000001	#	Binlog_checkpoint	2	#	mysqld-bin.000001
+mysqld-bin.000001	#	Gtid	1	#	GTID 0-1-1
+mysqld-bin.000001	#	Query	1	#	use `test`; CREATE TABLE t1(i INT)ENGINE=INNODB
+mysqld-bin.000001	#	Gtid	1	#	BEGIN GTID 0-1-2
+mysqld-bin.000001	#	Annotate_rows	1	#	INSERT INTO t1 VALUES(1)
+mysqld-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Write_rows_v1	1	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	1	#	COMMIT /* xid= */
+mysqld-bin.000001	#	Gtid	1	#	BEGIN GTID 0-1-3
+mysqld-bin.000001	#	Annotate_rows	1	#	DELETE FROM t1 WHERE i = 1
+mysqld-bin.000001	#	Table_map	1	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Delete_rows_v1	1	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	1	#	COMMIT /* xid= */
+mysqld-bin.000001	#	Gtid	2	#	BEGIN GTID 0-2-4
+mysqld-bin.000001	#	Annotate_rows	2	#	INSERT INTO t1 VALUES(2)
+mysqld-bin.000001	#	Table_map	2	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Write_rows_v1	2	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	2	#	COMMIT /* xid= */
+mysqld-bin.000001	#	Gtid	2	#	BEGIN GTID 0-2-5
+mysqld-bin.000001	#	Annotate_rows	2	#	DELETE FROM t1 WHERE i = 2
+mysqld-bin.000001	#	Table_map	2	#	table_id: # (test.t1)
+mysqld-bin.000001	#	Delete_rows_v1	2	#	table_id: # flags: STMT_END_F
+mysqld-bin.000001	#	Xid	2	#	COMMIT /* xid= */
+DROP TABLE t1;
+# End of test
diff --git a/mysql-test/suite/galera/t/rpl_row_annotate.cnf b/mysql-test/suite/galera/t/rpl_row_annotate.cnf
new file mode 100644
index 0000000..1f1d83d
--- /dev/null
+++ b/mysql-test/suite/galera/t/rpl_row_annotate.cnf
@@ -0,0 +1,6 @@
+!include ../galera_2nodes.cnf
+
+[mysqld]
+log-bin
+log-slave-updates
+binlog-annotate-row-events=ON
diff --git a/mysql-test/suite/galera/t/rpl_row_annotate.test b/mysql-test/suite/galera/t/rpl_row_annotate.test
new file mode 100644
index 0000000..b1cfdb3
--- /dev/null
+++ b/mysql-test/suite/galera/t/rpl_row_annotate.test
@@ -0,0 +1,42 @@
+--source include/galera_cluster.inc
+--source include/have_innodb.inc
+
+--echo # On node_2
+--connection node_2
+RESET MASTER;
+
+--echo # On node_1
+--connection node_1
+RESET MASTER;
+CREATE TABLE t1(i INT)ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+DELETE FROM t1 WHERE i = 1;
+
+--echo # On node_2
+--connection node_2
+INSERT INTO t1 VALUES(2);
+DELETE FROM t1 WHERE i = 2;
+
+--echo # On node_1
+--connection node_1
+--source include/binlog_start_pos.inc
+let $start_pos= `select @binlog_start_pos`;
+--replace_column 2 # 5 #
+--replace_result $start_pos <start_pos>
+--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
+--eval SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM $start_pos
+
+--echo # On node_2
+--connection node_2
+--source include/binlog_start_pos.inc
+let $start_pos= `select @binlog_start_pos`;
+--replace_column 2 # 5 #
+--replace_result $start_pos <start_pos>
+--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
+--eval SHOW BINLOG EVENTS IN 'mysqld-bin.000001' FROM $start_pos
+
+# Cleanup
+DROP TABLE t1;
+
+--source include/galera_end.inc
+--echo # End of test
diff --git a/sql/wsrep_applier.cc b/sql/wsrep_applier.cc
index 03d356a..6f1ead8 100644
--- a/sql/wsrep_applier.cc
+++ b/sql/wsrep_applier.cc
@@ -92,6 +92,7 @@ static wsrep_cb_status_t wsrep_apply_events(THD*        thd,
   char *buf= (char *)events_buf;
   int rcode= 0;
   int event= 1;
+  Log_event_type typ;
 
   DBUG_ENTER("wsrep_apply_events");
 
@@ -126,7 +127,9 @@ static wsrep_cb_status_t wsrep_apply_events(THD*        thd,
       goto error;
     }
 
-    switch (ev->get_type_code()) {
+    typ= ev->get_type_code();
+
+    switch (typ) {
     case FORMAT_DESCRIPTION_EVENT:
       wsrep_set_apply_format(thd, (Format_description_log_event*)ev);
       continue;
@@ -160,7 +163,6 @@ static wsrep_cb_status_t wsrep_apply_events(THD*        thd,
     }
 
     ev->thd = thd;
-    //exec_res = ev->apply_event(thd->wsrep_rli);
     exec_res = ev->apply_event(thd->wsrep_rgi);
     DBUG_PRINT("info", ("exec_event result: %d", exec_res));
 
@@ -192,7 +194,7 @@ static wsrep_cb_status_t wsrep_apply_events(THD*        thd,
       DBUG_RETURN(WSREP_CB_FAILURE);
     }
 
-    delete ev;
+    delete_or_keep_event_post_apply(thd->wsrep_rgi, typ, ev);
   }
 
  error:
diff --git a/sql/wsrep_thd.cc b/sql/wsrep_thd.cc
index b01737d..81999d1 100644
--- a/sql/wsrep_thd.cc
+++ b/sql/wsrep_thd.cc
@@ -121,10 +121,13 @@ static rpl_group_info* wsrep_relay_group_init(const char* log_fname)
   */
   rli->mi = new Master_info(&connection_name, false);
 
-  rli->sql_driver_thd= current_thd;
-
   struct rpl_group_info *rgi= new rpl_group_info(rli);
-  rgi->thd= current_thd;
+  rgi->thd= rli->sql_driver_thd= current_thd;
+
+  if ((rgi->deferred_events_collecting= rli->mi->rpl_filter->is_on()))
+  {
+    rgi->deferred_events= new Deferred_log_events(rli);
+  }
 
   return rgi;
 }
@@ -172,6 +175,8 @@ static void wsrep_return_from_bf_mode(THD *thd, struct wsrep_thd_shadow* shadow)
   delete thd->system_thread_info.rpl_sql_info;
   delete thd->wsrep_rgi->rli->mi;
   delete thd->wsrep_rgi->rli;
+
+  thd->wsrep_rgi->cleanup_after_session();
   delete thd->wsrep_rgi;
   thd->wsrep_rgi = NULL;
 }


More information about the commits mailing list