diff --git a/mysql-test/main/alter_table_online_debug.result b/mysql-test/main/alter_table_online_debug.result index 1d20d40e7e4..c987ff4d2f6 100644 --- a/mysql-test/main/alter_table_online_debug.result +++ b/mysql-test/main/alter_table_online_debug.result @@ -1785,6 +1785,28 @@ a d 0 qwe 0 qwe drop table t; +# +# MDEV-32803 Assertion `total == 0' failed in Event_log::write_cache_raw +# +create or replace table t1 (a int) engine=aria; +insert t1 values (5); +set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end'; +alter table t1 add b int NULL, algorithm= copy, lock= none; +connection con2; +set debug_sync= 'now WAIT_FOR ended'; +begin; +insert into t1 values (123); +insert into t1 values (456), (789); +commit; +set debug_sync= 'now SIGNAL end'; +connection default; +select * from t1; +a b +5 NULL +123 NULL +456 NULL +789 NULL +drop table t1; set global default_storage_engine= MyISAM; disconnect con1; disconnect con2; diff --git a/mysql-test/main/alter_table_online_debug.test b/mysql-test/main/alter_table_online_debug.test index cf0062da269..2a37f6a0c46 100644 --- a/mysql-test/main/alter_table_online_debug.test +++ b/mysql-test/main/alter_table_online_debug.test @@ -2041,6 +2041,31 @@ select * from t; drop table t; +--echo # +--echo # MDEV-32803 Assertion `total == 0' failed in Event_log::write_cache_raw +--echo # + +create or replace table t1 (a int) engine=aria; +insert t1 values (5); +set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end'; + +send alter table t1 add b int NULL, algorithm= copy, lock= none; + +--connection con2 +set debug_sync= 'now WAIT_FOR ended'; +begin; +insert into t1 values (123); +insert into t1 values (456), (789); +commit; +set debug_sync= 'now SIGNAL end'; + +--connection default +--reap +select * from t1; + +drop table t1; + + eval set global default_storage_engine= $default_storage_engine; --disconnect con1 diff --git a/sql/online_alter.cc b/sql/online_alter.cc index e0afe602ca8..5f418d8ec29 100644 --- a/sql/online_alter.cc +++ b/sql/online_alter.cc @@ -152,6 +152,7 @@ int online_alter_log_row(TABLE* table, const uchar *before_record, if (!table->online_alter_cache) { table->online_alter_cache= get_cache_data(thd, table); + DBUG_ASSERT(table->online_alter_cache->cache_log.type == WRITE_CACHE); trans_register_ha(thd, false, online_alter_hton, 0); if (thd->in_multi_stmt_transaction_mode()) 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, mysql_mutex_lock(binlog->get_log_lock()); error= binlog->write_cache_raw(thd, &cache.cache_log); mysql_mutex_unlock(binlog->get_log_lock()); + if (!is_ending_transaction) + cache.reset(); } } else if (!commit) // rollback