Skip to content

Commit c2e16b3

Browse files
committed
MDEV-32803 Assertion `total == 0' failed in Event_log::write_cache_raw
A second DML in a transaction for a table of non-rollbackable engine leads to a cache corruption, because the cache wasn't reset after a statement end, but also wasn't destroyed. This patch resets the cache for a reuse by subsequent statements in current transaction.
1 parent 985e3df commit c2e16b3

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

mysql-test/main/alter_table_online_debug.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,28 @@ a d
17851785
0 qwe
17861786
0 qwe
17871787
drop table t;
1788+
#
1789+
# MDEV-32803 Assertion `total == 0' failed in Event_log::write_cache_raw
1790+
#
1791+
create or replace table t1 (a int) engine=aria;
1792+
insert t1 values (5);
1793+
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
1794+
alter table t1 add b int NULL, algorithm= copy, lock= none;
1795+
connection con2;
1796+
set debug_sync= 'now WAIT_FOR ended';
1797+
begin;
1798+
insert into t1 values (123);
1799+
insert into t1 values (456), (789);
1800+
commit;
1801+
set debug_sync= 'now SIGNAL end';
1802+
connection default;
1803+
select * from t1;
1804+
a b
1805+
5 NULL
1806+
123 NULL
1807+
456 NULL
1808+
789 NULL
1809+
drop table t1;
17881810
set global default_storage_engine= MyISAM;
17891811
disconnect con1;
17901812
disconnect con2;

mysql-test/main/alter_table_online_debug.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,6 +2041,31 @@ select * from t;
20412041
drop table t;
20422042

20432043

2044+
--echo #
2045+
--echo # MDEV-32803 Assertion `total == 0' failed in Event_log::write_cache_raw
2046+
--echo #
2047+
2048+
create or replace table t1 (a int) engine=aria;
2049+
insert t1 values (5);
2050+
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
2051+
2052+
send alter table t1 add b int NULL, algorithm= copy, lock= none;
2053+
2054+
--connection con2
2055+
set debug_sync= 'now WAIT_FOR ended';
2056+
begin;
2057+
insert into t1 values (123);
2058+
insert into t1 values (456), (789);
2059+
commit;
2060+
set debug_sync= 'now SIGNAL end';
2061+
2062+
--connection default
2063+
--reap
2064+
select * from t1;
2065+
2066+
drop table t1;
2067+
2068+
20442069
eval set global default_storage_engine= $default_storage_engine;
20452070

20462071
--disconnect con1

sql/online_alter.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ int online_alter_log_row(TABLE* table, const uchar *before_record,
152152
if (!table->online_alter_cache)
153153
{
154154
table->online_alter_cache= get_cache_data(thd, table);
155+
DBUG_ASSERT(table->online_alter_cache->cache_log.type == WRITE_CACHE);
155156
trans_register_ha(thd, false, online_alter_hton, 0);
156157
if (thd->in_multi_stmt_transaction_mode())
157158
trans_register_ha(thd, true, online_alter_hton, 0);
@@ -237,6 +238,8 @@ int online_alter_end_trans(Online_alter_cache_list &cache_list, THD *thd,
237238
mysql_mutex_lock(binlog->get_log_lock());
238239
error= binlog->write_cache_raw(thd, &cache.cache_log);
239240
mysql_mutex_unlock(binlog->get_log_lock());
241+
if (!is_ending_transaction)
242+
cache.reset();
240243
}
241244
}
242245
else if (!commit) // rollback

0 commit comments

Comments
 (0)