Skip to content

Commit

Permalink
MDEV-20591 Wrong Number of rows in mysqlbinlog output
Browse files Browse the repository at this point in the history
calc_field_event_length should accurately calculate the size of BLOB type
fields, Instead of returning just the bytes taken by length it should return
length bytes + actual length.
  • Loading branch information
mariadb-SachinSetiya committed Oct 8, 2019
1 parent 5b2fa07 commit 01bf9f8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
55 changes: 52 additions & 3 deletions mysql-test/suite/binlog/r/binlog_mysqlbinlog_row.result
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ INSERT INTO t2 SET a=1;
INSERT INTO t2 SET b=1;
UPDATE t1, t2 SET t1.a=10, t2.a=20;
DROP TABLE t1,t2;
#
# MDEV-20591 Wrong Number of rows in mysqlbinlog output.
#
CREATE TABLE t1(c_char_utf8 CHAR(10) ,
c_varchar_utf8 char(10) ,
c_text_utf8 blob );
INSERT into t1 values("B", "B", REPEAT("#", 2000));
drop table t1;
flush logs;
INSERT INTO t1dec102 VALUES (-999.99);
INSERT INTO t1dec102 VALUES (0);
Expand Down Expand Up @@ -5274,6 +5282,47 @@ SET TIMESTAMP=1000000000/*!*/;
DROP TABLE `t1`,`t2` /* generated by server */
/*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX GTID 0-1-317 ddl
/*!100001 SET @@session.gtid_seq_no=317*//*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Query thread_id=# exec_time=# error_code=0
SET TIMESTAMP=1000000000/*!*/;
CREATE TABLE t1(c_char_utf8 CHAR(10) ,
c_varchar_utf8 char(10) ,
c_text_utf8 blob )
/*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX GTID 0-1-318
/*!100001 SET @@session.gtid_seq_no=318*//*!*/;
BEGIN
/*!*/;
# at #
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Annotate_rows:
#Q> INSERT into t1 values("B", "B", REPEAT("#", 2000))
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Table_map: `test`.`t1` mapped to number #
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Write_rows: table id # flags: STMT_END_F
### INSERT INTO `test`.`t1`
### SET
### @1='B' /* STRING(10) meta=65034 nullable=1 is_null=0 */
### @2='B' /* STRING(10) meta=65034 nullable=1 is_null=0 */
### @3='################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################' /* BLOB/TEXT meta=2 nullable=1 is_null=0 */
# Number of rows: 1
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Query thread_id=# exec_time=# error_code=0
SET TIMESTAMP=1000000000/*!*/;
COMMIT
/*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX GTID 0-1-319 ddl
/*!100001 SET @@session.gtid_seq_no=319*//*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Query thread_id=# exec_time=# error_code=0
SET TIMESTAMP=1000000000/*!*/;
DROP TABLE `t1` /* generated by server */
/*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Rotate to master-bin.000002 pos: 4
DELIMITER ;
# End of log file
Expand All @@ -5287,17 +5336,17 @@ DELIMITER /*!*/;
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Start: binlog v 4, server v #.##.## created 010909 4:46:40
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Gtid list [0-1-316]
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Gtid list [0-1-319]
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Binlog checkpoint master-bin.000001
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX Binlog checkpoint master-bin.000002
# at #
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX GTID 0-1-317
#010909 4:46:40 server id 1 end_log_pos # CRC32 XXX GTID 0-1-320
/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
/*!100001 SET @@session.server_id=1*//*!*/;
/*!100001 SET @@session.gtid_seq_no=317*//*!*/;
/*!100001 SET @@session.gtid_seq_no=320*//*!*/;
BEGIN
/*!*/;
# at #
Expand Down
13 changes: 13 additions & 0 deletions mysql-test/suite/binlog/t/binlog_mysqlbinlog_row.test
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,18 @@ INSERT INTO t2 SET b=1;
UPDATE t1, t2 SET t1.a=10, t2.a=20;
DROP TABLE t1,t2;

--echo #
--echo # MDEV-20591 Wrong Number of rows in mysqlbinlog output.
--echo #

CREATE TABLE t1(c_char_utf8 CHAR(10) ,
c_varchar_utf8 char(10) ,
c_text_utf8 blob );

INSERT into t1 values("B", "B", REPEAT("#", 2000));

drop table t1;

flush logs;

let $MYSQLD_DATADIR= `select @@datadir`;
Expand All @@ -462,3 +474,4 @@ flush logs;
--replace_regex /SQL_LOAD_MB-[0-9]-[0-9]/SQL_LOAD_MB-#-#/ /exec_time=[0-9]*/exec_time=#/ /end_log_pos [0-9]*/end_log_pos #/ /# at [0-9]*/# at #/ /thread_id=[0-9]*/thread_id=#/ /table id [0-9]*/table id #/ /mapped to number [0-9]*/mapped to number #/ /server v [^ ]*/server v #.##.##/ /(@[0-9]*=[0-9]*[.][0-9]{1,3})[0-9e+-]*[^ ]*(.*(FLOAT|DOUBLE).*[*].)/\1...\2/ /CRC32 0x[0-9a-f]*/CRC32 XXX/
--error 1
--exec $MYSQL_BINLOG --base64-output=decode-rows -v -v $MYSQLD_DATADIR/master-bin.000002 2>&1

11 changes: 10 additions & 1 deletion sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3423,7 +3423,16 @@ static size_t calc_field_event_length(const uchar *ptr, uint type, uint meta)
case MYSQL_TYPE_SET:
return meta & 0xFF;
case MYSQL_TYPE_BLOB:
return (meta <= 4 ? meta : 0);
if (meta > 4 )
return 0;
if (meta == 1)
return *ptr + 1;
if (meta == 2)
return uint2korr(ptr) + 2;
if (meta == 3)
return uint3korr(ptr) + 3;
if (meta == 4)
return uint4korr(ptr) + 4;
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_VAR_STRING:
length= meta;
Expand Down

0 comments on commit 01bf9f8

Please sign in to comment.