mariadb/mysql-test/suite/binlog/t/binlog_mdev22915.test
Kristian Nielsen db20a99587 MDEV-22915: Assertion 'binlog_table_maps == 0 || locked_tables_mode == LTM_LOCK_TABLES' failed in THD::reset_for_next_command
close_thread_tables() would not flush pending row events to the binlog cache
in certain conditions if LOCK TABLES was active. This could result in the
row events being binlogged without STMT_END_F flag, and eventually leave the
THD in an invalid state that triggered assertions later.

Reviewed-by: Monty <monty@mariadb.org>
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-10-07 09:40:36 +02:00

33 lines
996 B
Text

--source include/have_innodb.inc
--source include/have_binlog_format_row.inc
RESET MASTER;
# This sequence of statements triggered a bug, where the pending LOCK TABLES
# would skip flusing the pending row event for INSERT to the trx cache. And
# Then the pending event would be overwritten by the SAVEPOINT, leaving an
# invalid state in the THD. And then a later connection would pick the THD
# with invalid state and trigger an assertion.
--connect (con1,localhost,root,,)
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
CREATE TRIGGER tr BEFORE UPDATE ON t1 FOR EACH ROW BEGIN END;
LOCK TABLES t1 WRITE;
--error ER_TABLE_NOT_LOCKED
LOAD DATA INFILE 'x' INTO TABLE x;
SET AUTOCOMMIT= OFF;
INSERT INTO t1 VALUES (1);
SAVEPOINT A;
COMMIT;
--disconnect con1
--connect (con2,localhost,root,,)
SELECT 1;
# Cleanup
--disconnect con2
--connection default
# Show the binlog events.
# When the bug occurs, the Write_rows event is missing STMT_END_F.
--source include/show_binlog_events.inc
DROP TABLE t1;