Commit afa96081 authored by unknown's avatar unknown

Bug #22540: Incorrect value in column End_log_pos of SHOW BINLOG EVENTS using InnoDB

fix binlog-writing so that end_log_pos is given correctly even
within transactions for both SHOW BINLOG and SHOW MASTER STATUS,
that is as absolute values (from log start) rather than relative
values (from transaction's start).
---
Merge sin.intern.azundris.com:/home/tnurnberg/22540/50-22540
into  sin.intern.azundris.com:/home/tnurnberg/22540/51-22540
---
Merge tnurnberg@bk-internal.mysql.com:/home/bk/mysql-5.1-maint
into  sin.intern.azundris.com:/home/tnurnberg/22540/51-22540


mysql-test/extra/binlog_tests/binlog.test:
  Bug #22540: Incorrect value in column End_log_pos of SHOW BINLOG EVENTS using InnoDB
  
  show that end_log_pos in SHOW BINLOG EVENTS is correct even in transactions.
  show that SHOW MASTER STATUS returns correct values while in transactions
  (so that mysqldump --master-data will work correctly).
  also remove bdb dependency.
  
  manual merge
mysql-test/r/binlog_stm_binlog.result:
  Bug #22540: Incorrect value in column End_log_pos of SHOW BINLOG EVENTS using InnoDB
  
  show that end_log_pos in SHOW BINLOG EVENTS is correct even in transactions.
  show that SHOW MASTER STATUS returns correct values while in transactions
  (so that mysqldump --master-data will work correctly).
  also remove bdb dependency.
  
  manual merge
sql/log.cc:
  Bug #22540: Incorrect value in column End_log_pos of SHOW BINLOG EVENTS using InnoDB
  
  fix output for SHOW BINLOG EVENTS so that end_log_pos is given correctly
  even within transactions. do this by rewriting the commit-buffer in place.
  
  manual merge
parent 70e5e339
......@@ -49,6 +49,98 @@ show binlog events in 'master-bin.000001' from 106;
--replace_regex /table_id: [0-9]+/table_id: #/ /\/\* xid=.* \*\//\/* xid= *\//
show binlog events in 'master-bin.000002' from 106;
#
# Bug#22540 - Incorrect value in column End_log_pos of
# SHOW BINLOG EVENTS using InnoDB
#
# the following tests will show that certain queries now return
# absolute offsets (from binlog start, rather than relative to
# the beginning of the current transaction). under what
# conditions it should be allowed / is sensible to put the
# slider into the middle of a transaction is not our concern
# here; we just guarantee that if and when it's done, the
# user has valid offsets to use. if the setter function still
# wants to throw a "positioning into middle of transaction"
# warning, that's its prerogative and handled elsewhere.
set @ac = @@autocommit;
# first show this to work for SHOW BINLOG EVENTS
set autocommit= 0;
reset master;
create table t1(n int) engine=innodb;
begin;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
commit;
drop table t1;
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /Server ver: [^,]*,/Server version,/
show binlog events from 0;
set autocommit= 1;
reset master;
create table t1(n int) engine=innodb;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
commit;
drop table t1;
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /Server ver: [^,]*,/Server version,/
show binlog events from 0;
reset master;
create table t1(n int) engine=myisam;
begin;
insert into t1 values (4);
insert into t1 values (5);
insert into t1 values (6);
commit;
drop table t1;
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /Server ver: [^,]*,/Server version,/
show binlog events from 0;
# now show this also works for SHOW MASTER STATUS
# as this is what "mysqldump --master-data=1" uses.
set autocommit= 1;
reset master;
create table t1(n int) engine=innodb;
show master status;
insert into t1 values (1);
show master status;
insert into t1 values (2);
insert into t1 values (3);
show master status;
commit;
show master status;
drop table t1;
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /Server ver: [^,]*,/Server version,/
show binlog events from 0;
set autocommit= 0;
reset master;
create table t1(n int) engine=myisam;
show master status;
insert into t1 values (4);
show master status;
insert into t1 values (5);
insert into t1 values (6);
show master status;
commit;
show master status;
drop table t1;
--replace_regex /\/\* xid=.* \*\//\/* XID *\// /table_id: [0-9]+/table_id: #/ /Server ver: [^,]*,/Server version,/
show binlog events from 0;
set session autocommit = @ac;
--echo End of 5.0 tests
# Test of a too big SET INSERT_ID: see if the truncated value goes
# into binlog (right), or the too big value (wrong); we look at the
# binlog further down with SHOW BINLOG EVENTS.
......
......@@ -7,7 +7,7 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 106 Server ver: #, Binlog ver: #
master-bin.000001 106 Query 1 213 use `test`; create table t1 (a int, b int) engine=innodb
master-bin.000001 213 Query 1 281 use `test`; BEGIN
master-bin.000001 281 Query 1 90 use `test`; insert into t1 values (1,2)
master-bin.000001 281 Query 1 371 use `test`; insert into t1 values (1,2)
master-bin.000001 371 Xid 1 398 COMMIT /* XID */
drop table t1;
drop table if exists t1, t2;
......@@ -145,6 +145,122 @@ master-bin.000001 # Rotate 1 # master-bin.000002;pos=4
show binlog events in 'master-bin.000002' from 106;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000002 # Query 1 # use `test`; drop table t1
set @ac = @@autocommit;
set autocommit= 0;
reset master;
create table t1(n int) engine=innodb;
begin;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
commit;
drop table t1;
show binlog events from 0;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 106 Server version, Binlog ver: 4
master-bin.000001 106 Query 1 205 use `test`; create table t1(n int) engine=innodb
master-bin.000001 205 Query 1 273 use `test`; BEGIN
master-bin.000001 273 Query 1 361 use `test`; insert into t1 values (1)
master-bin.000001 361 Query 1 449 use `test`; insert into t1 values (2)
master-bin.000001 449 Query 1 537 use `test`; insert into t1 values (3)
master-bin.000001 537 Xid 1 564 COMMIT /* XID */
master-bin.000001 564 Query 1 640 use `test`; drop table t1
set autocommit= 1;
reset master;
create table t1(n int) engine=innodb;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
commit;
drop table t1;
show binlog events from 0;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 106 Server version, Binlog ver: 4
master-bin.000001 106 Query 1 205 use `test`; create table t1(n int) engine=innodb
master-bin.000001 205 Query 1 293 use `test`; insert into t1 values (1)
master-bin.000001 293 Xid 1 320 COMMIT /* XID */
master-bin.000001 320 Query 1 408 use `test`; insert into t1 values (2)
master-bin.000001 408 Xid 1 435 COMMIT /* XID */
master-bin.000001 435 Query 1 523 use `test`; insert into t1 values (3)
master-bin.000001 523 Xid 1 550 COMMIT /* XID */
master-bin.000001 550 Query 1 626 use `test`; drop table t1
reset master;
create table t1(n int) engine=myisam;
begin;
insert into t1 values (4);
insert into t1 values (5);
insert into t1 values (6);
commit;
drop table t1;
show binlog events from 0;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 106 Server version, Binlog ver: 4
master-bin.000001 106 Query 1 205 use `test`; create table t1(n int) engine=myisam
master-bin.000001 205 Query 1 293 use `test`; insert into t1 values (4)
master-bin.000001 293 Query 1 381 use `test`; insert into t1 values (5)
master-bin.000001 381 Query 1 469 use `test`; insert into t1 values (6)
master-bin.000001 469 Query 1 545 use `test`; drop table t1
set autocommit= 1;
reset master;
create table t1(n int) engine=innodb;
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 205
insert into t1 values (1);
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 320
insert into t1 values (2);
insert into t1 values (3);
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 550
commit;
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 550
drop table t1;
show binlog events from 0;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 106 Server version, Binlog ver: 4
master-bin.000001 106 Query 1 205 use `test`; create table t1(n int) engine=innodb
master-bin.000001 205 Query 1 293 use `test`; insert into t1 values (1)
master-bin.000001 293 Xid 1 320 COMMIT /* XID */
master-bin.000001 320 Query 1 408 use `test`; insert into t1 values (2)
master-bin.000001 408 Xid 1 435 COMMIT /* XID */
master-bin.000001 435 Query 1 523 use `test`; insert into t1 values (3)
master-bin.000001 523 Xid 1 550 COMMIT /* XID */
master-bin.000001 550 Query 1 626 use `test`; drop table t1
set autocommit= 0;
reset master;
create table t1(n int) engine=myisam;
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 205
insert into t1 values (4);
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 293
insert into t1 values (5);
insert into t1 values (6);
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 469
commit;
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
master-bin.000001 469
drop table t1;
show binlog events from 0;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 4 Format_desc 1 106 Server version, Binlog ver: 4
master-bin.000001 106 Query 1 205 use `test`; create table t1(n int) engine=myisam
master-bin.000001 205 Query 1 293 use `test`; insert into t1 values (4)
master-bin.000001 293 Query 1 381 use `test`; insert into t1 values (5)
master-bin.000001 381 Query 1 469 use `test`; insert into t1 values (6)
master-bin.000001 469 Query 1 545 use `test`; drop table t1
set session autocommit = @ac;
End of 5.0 tests
reset master;
create table t1 (id tinyint auto_increment primary key);
set insert_id=128;
......
......@@ -3945,9 +3945,65 @@ int MYSQL_BIN_LOG::write_cache(IO_CACHE *cache, bool lock_log, bool sync_log)
if (reinit_io_cache(cache, READ_CACHE, 0, 0, 0))
return ER_ERROR_ON_WRITE;
uint bytes= my_b_bytes_in_cache(cache);
uint bytes= my_b_bytes_in_cache(cache), group, carry, hdr_offs;
long val;
uchar header[LOG_EVENT_HEADER_LEN];
group= my_b_tell(&log_file);
hdr_offs= carry= 0;
do
{
if (likely(carry > 0))
{
DBUG_ASSERT(carry < LOG_EVENT_HEADER_LEN);
memcpy(&header[carry], (char *)cache->read_pos, LOG_EVENT_HEADER_LEN - carry);
val= uint4korr(&header[LOG_POS_OFFSET]) + group;
int4store(&header[LOG_POS_OFFSET], val);
if (my_b_write(&log_file, header, carry))
return ER_ERROR_ON_WRITE;
memcpy((char *)cache->read_pos, &header[carry], LOG_EVENT_HEADER_LEN - carry);
hdr_offs = LOG_EVENT_HEADER_LEN - carry +
uint4korr(&header[EVENT_LEN_OFFSET]);
carry= 0;
}
if(likely(bytes > 0))
{
do {
DBUG_ASSERT((hdr_offs + max(EVENT_LEN_OFFSET, LOG_POS_OFFSET) + 4) <= bytes);
val= uint4korr((char *)cache->read_pos + hdr_offs + LOG_POS_OFFSET) + group;
int4store((char *)cache->read_pos + hdr_offs + LOG_POS_OFFSET, val);
hdr_offs += uint4korr((char *)cache->read_pos + hdr_offs + EVENT_LEN_OFFSET);
/* header beyond current read-buffer? */
if (hdr_offs >= bytes)
{
hdr_offs -= bytes;
break;
}
/* split header? */
if (hdr_offs + LOG_EVENT_HEADER_LEN > bytes)
{
carry= bytes - hdr_offs;
memcpy(header, (char *)cache->read_pos + hdr_offs, carry);
bytes -= carry;
}
} while (hdr_offs < bytes);
}
/* Write data to the binary log file */
if (my_b_write(&log_file, cache->read_pos, bytes))
return ER_ERROR_ON_WRITE;
cache->read_pos= cache->read_end;
......@@ -4028,7 +4084,7 @@ bool MYSQL_BIN_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
if ((write_error= write_cache(cache, false, false)))
goto err;
if (commit_event && commit_event->write(&log_file))
goto err;
if (flush_and_sync())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment