Commit da13ab08 authored by serg@serg.mylan's avatar serg@serg.mylan

write "COMMIT" into binlog if there's no Xid at the end of transaction

new tests
parent 41043bb3
drop table if exists t1, t2;
create table t1 (a int) engine=bdb;
create table t2 (a int) engine=innodb;
begin;
insert t1 values (5);
commit;
begin;
insert t2 values (5);
commit;
show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 187 use `test`; drop table if exists t1, t2
master-bin.000001 187 Query 1 285 use `test`; create table t1 (a int) engine=bdb
master-bin.000001 285 Query 1 386 use `test`; create table t2 (a int) engine=innodb
master-bin.000001 386 Query 1 455 use `test`; BEGIN
master-bin.000001 455 Query 1 84 use `test`; insert t1 values (5)
master-bin.000001 539 Query 1 154 use `test`; COMMIT
master-bin.000001 609 Query 1 678 use `test`; BEGIN
master-bin.000001 678 Query 1 84 use `test`; insert t2 values (5)
master-bin.000001 762 Xid 1 111 COMMIT /* xid=10 */
reset master;
drop table t1,t2;
......@@ -272,6 +272,10 @@ n
7
rollback to savepoint `my_savepoint`;
ERROR 42000: SAVEPOINT my_savepoint does not exist
insert into t1 values (8);
savepoint sv;
commit;
savepoint sv;
set autocommit=1;
rollback;
drop table t1;
......@@ -1717,7 +1721,7 @@ Variable_name Value
Innodb_rows_deleted 2070
show status like "Innodb_rows_inserted";
Variable_name Value
Innodb_rows_inserted 31708
Innodb_rows_inserted 31709
show status like "Innodb_rows_updated";
Variable_name Value
Innodb_rows_updated 29530
......
#
# misc binlogging tests that do not require a slave running
#
-- source include/have_bdb.inc
-- source include/have_innodb.inc
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
create table t1 (a int) engine=bdb;
create table t2 (a int) engine=innodb;
begin;
insert t1 values (5);
commit;
begin;
insert t2 values (5);
commit;
# first COMMIT must be Query_log_event, second - Xid_log_event
show binlog events from 96;
reset master;
drop table t1,t2;
......@@ -141,6 +141,10 @@ release savepoint `my_savepoint`;
select n from t1;
-- error 1305
rollback to savepoint `my_savepoint`;
insert into t1 values (8);
savepoint sv;
commit;
savepoint sv;
set autocommit=1;
# nop
rollback;
......
......@@ -103,11 +103,21 @@ static int binlog_prepare(THD *thd, bool all)
return 0;
}
static int binlog_commit(THD *thd, bool all)
static int binlog_real_commit(THD *thd, IO_CACHE *trans_log)
{
int error;
DBUG_ENTER("binlog_real_commit");
/* Update the binary log as we have cached some queries */
error= mysql_bin_log.write(thd, trans_log);
binlog_cleanup_trans(trans_log);
DBUG_RETURN(error);
}
static int binlog_commit(THD *thd, bool all)
{
IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot];
DBUG_ENTER("binlog_commit");
DBUG_ENTER("binlog_real_commit");
DBUG_ASSERT(mysql_bin_log.is_open() &&
(all || !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))));
......@@ -116,11 +126,10 @@ static int binlog_commit(THD *thd, bool all)
// we're here because trans_log was flushed in MYSQL_LOG::log()
DBUG_RETURN(0);
}
Query_log_event qev(thd, "COMMIT", 6, TRUE, FALSE);
qev.write(trans_log);
/* Update the binary log as we have cached some queries */
error= mysql_bin_log.write(thd, trans_log);
binlog_cleanup_trans(trans_log);
DBUG_RETURN(error);
DBUG_RETURN(binlog_real_commit(thd, trans_log));
}
static int binlog_rollback(THD *thd, bool all)
......@@ -2985,10 +2994,11 @@ void TC_LOG_BINLOG::close()
int TC_LOG_BINLOG::log(THD *thd, my_xid xid)
{
Xid_log_event xle(thd, xid);
if (xle.write((IO_CACHE*)thd->ha_data[binlog_hton.slot]))
IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot];
if (xle.write(trans_log))
return 0;
thread_safe_increment(prepared_xids, &LOCK_prep_xids);
return !binlog_commit(thd,1); // invert return value
return !binlog_real_commit(thd, trans_log); // invert return value
}
void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid)
......
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