Skip to content

Commit f0b6510

Browse files
temeoJan Lindström
authored andcommitted
MDEV-18585 Avoid excessive Annotate_rows_log_events in binlog
Make sure that the Annotate_rows_log_events is written into binlog only for the first fragment of the current statement. Also avoid flusing pending rows event when calculating bytes generated by the transaction. Added and recorded a test which verifies that the binlog contains only one Annotate_rows_log_event per statement with various SR settings. Recrded mysql-wsrep-features#136 which produced different output with excession log events suppressed.
1 parent 33fd399 commit f0b6510

File tree

8 files changed

+101
-6
lines changed

8 files changed

+101
-6
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
connection node_2;
2+
connection node_1;
3+
CREATE TABLE t1 (f1 INT PRIMARY KEY);
4+
SET SESSION wsrep_trx_fragment_unit='ROWS';
5+
SET SESSION wsrep_trx_fragment_size=1;
6+
INSERT INTO t1 VALUES (1), (2);
7+
SET SESSION wsrep_trx_fragment_unit='BYTES';
8+
SET SESSION wsrep_trx_fragment_size=1;
9+
INSERT INTO t1 VALUES (3), (4);
10+
SET SESSION wsrep_trx_fragment_unit='STATEMENTS';
11+
SET SESSION wsrep_trx_fragment_size=1;
12+
INSERT INTO t1 VALUES (5), (6);
13+
SET SESSION wsrep_trx_fragment_unit=default;
14+
SET SESSION wsrep_trx_fragment_size=default;
15+
SHOW BINLOG EVENTS IN 'mysqld-bin.000002' FROM 518;
16+
Log_name Pos Event_type Server_id End_log_pos Info
17+
mysqld-bin.000002 518 Gtid 1 560 BEGIN GTID 0-1-2
18+
mysqld-bin.000002 560 Annotate_rows 1 613 INSERT INTO t1 VALUES (1), (2)
19+
mysqld-bin.000002 613 Table_map 1 658 table_id: # (test.t1)
20+
mysqld-bin.000002 658 Write_rows_v1 1 696 table_id: # flags: STMT_END_F
21+
mysqld-bin.000002 696 Table_map 1 741 table_id: # (test.t1)
22+
mysqld-bin.000002 741 Write_rows_v1 1 779 table_id: # flags: STMT_END_F
23+
mysqld-bin.000002 779 Xid 1 810 COMMIT /* xid=# */
24+
mysqld-bin.000002 810 Gtid 1 852 BEGIN GTID 0-1-3
25+
mysqld-bin.000002 852 Annotate_rows 1 905 INSERT INTO t1 VALUES (3), (4)
26+
mysqld-bin.000002 905 Table_map 1 950 table_id: # (test.t1)
27+
mysqld-bin.000002 950 Write_rows_v1 1 988 table_id: # flags: STMT_END_F
28+
mysqld-bin.000002 988 Table_map 1 1033 table_id: # (test.t1)
29+
mysqld-bin.000002 1033 Write_rows_v1 1 1071 table_id: # flags: STMT_END_F
30+
mysqld-bin.000002 1071 Xid 1 1102 COMMIT /* xid=# */
31+
mysqld-bin.000002 1102 Gtid 1 1144 BEGIN GTID 0-1-4
32+
mysqld-bin.000002 1144 Annotate_rows 1 1197 INSERT INTO t1 VALUES (5), (6)
33+
mysqld-bin.000002 1197 Table_map 1 1242 table_id: # (test.t1)
34+
mysqld-bin.000002 1242 Write_rows_v1 1 1285 table_id: # flags: STMT_END_F
35+
mysqld-bin.000002 1285 Xid 1 1316 COMMIT /* xid=# */
36+
DROP TABLE t1;

mysql-test/suite/galera_sr/r/mysql-wsrep-features#136.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ mysqld-bin.000001 <Pos> Gtid 1 <End_log_pos> BEGIN GTID 0-1-2
2929
mysqld-bin.000001 <Pos> Annotate_rows 1 <End_log_pos> INSERT INTO t1 VALUES (1),(2)
3030
mysqld-bin.000001 <Pos> Table_map 1 <End_log_pos> table_id: ### (test.t1)
3131
mysqld-bin.000001 <Pos> Write_rows_v1 1 <End_log_pos> table_id: ### flags: STMT_END_F
32-
mysqld-bin.000001 <Pos> Annotate_rows 1 <End_log_pos> INSERT INTO t1 VALUES (1),(2)
3332
mysqld-bin.000001 <Pos> Table_map 1 <End_log_pos> table_id: ### (test.t1)
3433
mysqld-bin.000001 <Pos> Write_rows_v1 1 <End_log_pos> table_id: ### flags: STMT_END_F
3534
mysqld-bin.000001 <Pos> Xid 1 <End_log_pos> COMMIT /* xid=### */
@@ -52,7 +51,6 @@ mysqld-bin.000001 <Pos> Gtid 1 <End_log_pos> BEGIN GTID 0-1-2
5251
mysqld-bin.000001 <Pos> Annotate_rows 1 <End_log_pos> INSERT INTO t1 VALUES (1),(2)
5352
mysqld-bin.000001 <Pos> Table_map 1 <End_log_pos> table_id: ### (test.t1)
5453
mysqld-bin.000001 <Pos> Write_rows_v1 1 <End_log_pos> table_id: ### flags: STMT_END_F
55-
mysqld-bin.000001 <Pos> Annotate_rows 1 <End_log_pos> INSERT INTO t1 VALUES (1),(2)
5654
mysqld-bin.000001 <Pos> Table_map 1 <End_log_pos> table_id: ### (test.t1)
5755
mysqld-bin.000001 <Pos> Write_rows_v1 1 <End_log_pos> table_id: ### flags: STMT_END_F
5856
mysqld-bin.000001 <Pos> Xid 1 <End_log_pos> COMMIT /* xid=### */
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
!include ../galera_2nodes.cnf
2+
3+
[mysqld.1]
4+
log-bin
5+
log-slave-updates
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# MDEV-18686 Verify that the Annotate_rows_log_event is written only
3+
# once per statement into binlog.
4+
#
5+
--source include/galera_cluster.inc
6+
7+
CREATE TABLE t1 (f1 INT PRIMARY KEY);
8+
9+
#
10+
# Unit ROW
11+
#
12+
SET SESSION wsrep_trx_fragment_unit='ROWS';
13+
SET SESSION wsrep_trx_fragment_size=1;
14+
15+
INSERT INTO t1 VALUES (1), (2);
16+
17+
#
18+
# Unit BYTE
19+
#
20+
SET SESSION wsrep_trx_fragment_unit='BYTES';
21+
SET SESSION wsrep_trx_fragment_size=1;
22+
23+
INSERT INTO t1 VALUES (3), (4);
24+
25+
#
26+
# Unit STATEMENT
27+
#
28+
SET SESSION wsrep_trx_fragment_unit='STATEMENTS';
29+
SET SESSION wsrep_trx_fragment_size=1;
30+
31+
INSERT INTO t1 VALUES (5), (6);
32+
33+
#
34+
# Reset to default settings
35+
#
36+
SET SESSION wsrep_trx_fragment_unit=default;
37+
SET SESSION wsrep_trx_fragment_size=default;
38+
39+
--replace_regex /table_id: [0-9]+/table_id: #/ /xid=[0-9]+/xid=#/
40+
SHOW BINLOG EVENTS IN 'mysqld-bin.000002' FROM 518;
41+
42+
DROP TABLE t1;

sql/handler.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6256,7 +6256,9 @@ static int write_locked_table_maps(THD *thd)
62566256
MYSQL_LOCK *locks[2];
62576257
locks[0]= thd->extra_lock;
62586258
locks[1]= thd->lock;
6259-
my_bool with_annotate= thd->variables.binlog_annotate_row_events &&
6259+
my_bool with_annotate= IF_WSREP(!wsrep_fragments_certified_for_stmt(thd),
6260+
true) &&
6261+
thd->variables.binlog_annotate_row_events &&
62606262
thd->query() && thd->query_length();
62616263

62626264
for (uint i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )

sql/wsrep_client_service.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,12 @@ size_t Wsrep_client_service::bytes_generated() const
229229
IO_CACHE* cache= wsrep_get_trans_cache(m_thd);
230230
if (cache)
231231
{
232-
m_thd->binlog_flush_pending_rows_event(true);
233-
return my_b_tell(cache);
232+
size_t pending_rows_event_length= 0;
233+
if (Rows_log_event* ev= m_thd->binlog_get_pending_rows_event(true))
234+
{
235+
pending_rows_event_length= ev->get_data_size();
236+
}
237+
return my_b_tell(cache) + pending_rows_event_length;
234238
}
235239
return 0;
236240
}

sql/wsrep_trans_observer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ static inline bool wsrep_streaming_enabled(THD* thd)
8383
return (thd->wsrep_sr().fragment_size() > 0);
8484
}
8585

86+
/*
87+
Return number of fragments succesfully certified for the
88+
current statement.
89+
*/
90+
static inline size_t wsrep_fragments_certified_for_stmt(THD* thd)
91+
{
92+
return thd->wsrep_trx().fragments_certified_for_statement();
93+
}
8694

8795
static inline int wsrep_start_transaction(THD* thd, wsrep_trx_id_t trx_id)
8896
{

0 commit comments

Comments
 (0)