Commit 0be27d8f authored by Alfranio Correia's avatar Alfranio Correia

BUG#56343 binlog_cache_use status is bigger than expected

The binlog_cache_use is incremented twice when changes to a transactional table
are committed, i.e. TC_LOG_BINLOG::log_xid calls is called. The problem happens
because log_xid calls both binlog_flush_stmt_cache and binlog_flush_trx_cache
without checking if such caches are empty thus unintentionally increasing the
binlog_cache_use value twice.

To fix the problem we avoided incrementing the binlog_cache_use if the cache is
empty. We also decided to increment binlog_cache_use when the cache is truncated
as the cache is used although its content is discarded and is not written to the
binary log.

Note that binlog_cache_use is incremented for both types of cache, transactional
and non-transactional and that the behavior presented in this patch also applies
to the binlog_cache_disk_use.

Finally, we re-organized the code around the functions binlog_flush_trx_cache and
binlog_flush_stmt_cache.
parent 48ac52a8
# Embedded server doesn't support binlog
-- source include/not_embedded.inc
-- source include/have_innodb.inc
# Creating tables
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
#
# Let us test binlog_cache_use and binlog_cache_disk_use status vars.
# Actually this test has nothing to do with innodb per se, it just
# requires transactional table.
#
# This test checks binlog_cache_use and binlog_cache_disk_use when
# transactions are committed and after when they are aborted.
#
#
# Checking commit.
#
--echo **** Preparing the enviroment to check commit and its effect on
--echo **** the binlog_cache_use and binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Now we are going to create transactional changes which are long enough so
--echo **** they will be flushed to disk...
--echo **** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
let $1=2000;
disable_query_log;
begin;
while ($1)
{
eval insert into t1 values( $1 );
dec $1;
}
commit;
enable_query_log;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Transactional changes which should not be flushed to disk and so should not
--echo **** increase binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
commit;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Non-Transactional changes which should not be flushed to disk and so should not
--echo **** increase binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Mixed changes which should not be flushed to disk and so should not
--echo **** increase binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
#
# Checking abort.
#
--echo **** Preparing the enviroment to check abort and its effect on
--echo **** the binlog_cache_use and binlog_cache_disk_use
--echo **** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Now we are going to create transactional changes which are long enough so
--echo **** they will be flushed to disk...
--echo **** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
let $1=2000;
disable_query_log;
begin;
while ($1)
{
eval insert into t1 values( $1 );
dec $1;
}
rollback;
enable_query_log;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Transactional changes which should not be flushed to disk and so should not
--echo **** increase binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
rollback;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Non-Transactional changes which should not be flushed to disk and so should not
--echo **** increase binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
rollback;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--echo **** Mixed changes which should not be flushed to disk and so should not
--echo **** increase binlog_cache_disk_use.
--echo **** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
rollback;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
drop table t1, t2;
# Embedded server doesn't support binlog
-- source include/not_embedded.inc
-- source include/have_innodb.inc
#
# Let us test binlog_cache_use and binlog_cache_disk_use status vars.
# Actually this test has nothing to do with innodb per se, it just requires
# transactional table.
#
flush status;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1 (a int) engine=innodb;
# Now we are going to create transaction which is long enough so its
# transaction binlog will be flushed to disk...
let $1=2000;
disable_query_log;
begin;
while ($1)
{
eval insert into t1 values( $1 );
dec $1;
}
commit;
enable_query_log;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
# Transaction which should not be flushed to disk and so should not
# increase binlog_cache_disk_use.
begin;
delete from t1;
commit;
show status like "binlog_cache_use";
show status like "binlog_cache_disk_use";
drop table t1;
......@@ -123,7 +123,7 @@ Binlog_cache_disk_use 0
create table t1 (a int) engine=innodb;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
......@@ -132,7 +132,7 @@ delete from t1;
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 4
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
......
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
drop table if exists t1;
create table t1 (a int) engine=innodb;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
begin;
delete from t1;
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 4
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
drop table t1;
drop table if exists t1, t2;
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
**** Preparing the enviroment to check commit and its effect on
**** the binlog_cache_use and binlog_cache_disk_use.
**** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
**** Now we are going to create transactional changes which are long enough so
**** they will be flushed to disk...
**** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Non-Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 3
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Mixed changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 5
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Preparing the enviroment to check abort and its effect on
**** the binlog_cache_use and binlog_cache_disk_use
**** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
**** Now we are going to create transactional changes which are long enough so
**** they will be flushed to disk...
**** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
rollback;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Non-Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
rollback;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 3
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Mixed changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
rollback;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 5
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
drop table t1, t2;
drop table if exists t1, t2;
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
**** Preparing the enviroment to check commit and its effect on
**** the binlog_cache_use and binlog_cache_disk_use.
**** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
**** Now we are going to create transactional changes which are long enough so
**** they will be flushed to disk...
**** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Non-Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 3
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Mixed changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 5
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Preparing the enviroment to check abort and its effect on
**** the binlog_cache_use and binlog_cache_disk_use
**** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
**** Now we are going to create transactional changes which are long enough so
**** they will be flushed to disk...
**** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
rollback;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Non-Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
rollback;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 3
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Mixed changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
rollback;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 5
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
drop table t1, t2;
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
drop table if exists t1;
create table t1 (a int) engine=innodb;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
begin;
delete from t1;
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 4
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
drop table t1;
drop table if exists t1, t2;
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
**** Preparing the enviroment to check commit and its effect on
**** the binlog_cache_use and binlog_cache_disk_use.
**** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
**** Now we are going to create transactional changes which are long enough so
**** they will be flushed to disk...
**** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Non-Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 3
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Mixed changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 5
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Preparing the enviroment to check abort and its effect on
**** the binlog_cache_use and binlog_cache_disk_use
**** Expected: binlog_cache_use = 0, binlog_cache_disk_use = 0.
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
**** Now we are going to create transactional changes which are long enough so
**** they will be flushed to disk...
**** Expected: binlog_cache_use = 1, binlog_cache_disk_use = 1.
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 1
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 2, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
rollback;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Non-Transactional changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 3, binlog_cache_disk_use = 1.
begin;
insert into t2 values( 1 );
rollback;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 3
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
**** Mixed changes which should not be flushed to disk and so should not
**** increase binlog_cache_disk_use.
**** Expected: binlog_cache_use = 5, binlog_cache_disk_use = 1.
begin;
insert into t1 values( 1 );
insert into t2 values( 1 );
rollback;
Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 5
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
drop table t1, t2;
flush status;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 0
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 0
drop table if exists t1;
create table t1 (a int) engine=innodb;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 2
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
begin;
delete from t1;
commit;
show status like "binlog_cache_use";
Variable_name Value
Binlog_cache_use 4
show status like "binlog_cache_disk_use";
Variable_name Value
Binlog_cache_disk_use 1
drop table t1;
......@@ -2,4 +2,4 @@
# For both statement and row based bin logs 9/19/2005 [jbm]
-- source include/have_binlog_format_mixed.inc
-- source extra/binlog_tests/innodb_stat.test
-- source extra/binlog_tests/binlog_cache_stat.test
......@@ -2,4 +2,4 @@
# For both statement and row based bin logs 9/19/2005 [jbm]
-- source include/have_binlog_format_row.inc
-- source extra/binlog_tests/innodb_stat.test
-- source extra/binlog_tests/binlog_cache_stat.test
......@@ -2,4 +2,4 @@
# For both statement and row based bin logs 9/19/2005 [jbm]
-- source include/have_binlog_format_statement.inc
-- source extra/binlog_tests/innodb_stat.test
-- source extra/binlog_tests/binlog_cache_stat.test
This diff is collapsed.
......@@ -2537,6 +2537,22 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
bool trx_cache= FALSE;
cache_type= Log_event::EVENT_INVALID_CACHE;
#ifndef DBUG_OFF
/*
If debug is enabled, we make sure that begin, commit and rollback
have the cache_type exclusively defined by the param using_trans.
as this is important while checking if the correct cache is used.
Note this is the only way to accurately set the type of the cache
when a begin, commit or rollback event is created because such
events may be artificially produced to compose the binary log.
*/
if (strncmp("BEGIN", query_arg, query_length) &&
strncmp("COMMIT", query_arg, query_length) &&
strncmp("ROLLBACK", query_arg, query_length))
{
#endif
switch (lex->sql_command)
{
case SQLCOM_DROP_TABLE:
......@@ -2574,6 +2590,15 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg,
cache_type= Log_event::EVENT_TRANSACTIONAL_CACHE;
else
cache_type= Log_event::EVENT_STMT_CACHE;
#ifndef DBUG_OFF
}
else if (using_trans)
cache_type= Log_event::EVENT_TRANSACTIONAL_CACHE;
else
cache_type= Log_event::EVENT_STMT_CACHE;
#endif
DBUG_ASSERT(cache_type != Log_event::EVENT_INVALID_CACHE);
DBUG_PRINT("info",("Query_log_event has flags2: %lu sql_mode: %lu",
(ulong) flags2, sql_mode));
......
......@@ -2504,7 +2504,7 @@ class Xid_log_event: public Log_event
my_xid xid;
#ifdef MYSQL_SERVER
Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg,0,0), xid(x) {}
Xid_log_event(THD* thd_arg, my_xid x): Log_event(thd_arg, 0, TRUE), xid(x) {}
#ifdef HAVE_REPLICATION
void pack_info(Protocol* protocol);
#endif /* HAVE_REPLICATION */
......
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