mariadb/storage/mroonga
Thirunarayanan Balathandayuthapani e5fed9eaf4 MDEV-36436 Assertion "unexpected references" == 0 after ALTER IGNORE TABLE
Problem:
=========
An assertion failure occurs in InnoDB during consecutive
ALTER TABLE operations using the COPY algorithm. The crash
happens during the table rename phase because the
source table (dict_table_t::n_ref_count) is non-zero, despite
the thread holding an exclusive Metadata Lock (MDL).

Reason:
========
When ALTER IGNORE TABLE is executed via the COPY algorithm,
it generates undo logs for every row inserted into the
intermediate table (e.g., #sql-alter-...). The background Purge
Thread, responsible for cleaning up these undo logs, attempts
to take an MDL on the table to prevent the table from
being dropped while in use.

Race condition:
==================
First ALTER: Creates #sql-alter-, copies data, and renames it to t1.

Purge Activation: The Purge thread picks up the undo logs from step 1.
It takes an MDL on the temporary name (#sql-alter-) and increments
the table's n_ref_count.

Identity Shift: InnoDB renames the physical table object to t1, but
the Purge thread still holds a reference to this object.

Second ALTER: Starts a new copy process. When it attempts to rename
the "new" t1 to a backup name, it checks if n_ref_count == 0.
Because the Purge thread is still "pinning" the object to
clean up logs from the first ALTER, the count is > 0,
triggering the assertion failure.

Solution:
========
ALTER IGNORE TABLE needs row-level undo logging to easily
roll back the last inserted row in case of duplicate key errors.
By discarding the last undo log record after inserting each row,
purge will not process any log records generated by
ALTER IGNORE TABLE, preventing unexpected access from the purge
subsystem during subsequent DDL operations.

Make skip_alter_undo (1-bit) to (2-bit enum)
to support different ALTER operation modes:

- NO_UNDO (0): Normal mode with standard undo logging
- SKIP_UNDO (1): ALTER mode that skips undo logging
- IGNORE_UNDO (2): ALTER IGNORE mode that rewrites undo blocks

trx_undo_report_row_operation(): Add ALTER IGNORE undo
rewriting logic. Store old undo record info before writing
new records for IGNORE_UNDO mode. Reset undo top_offset
to maintain only latest insert undo

row_ins_clust_index_entry_low(): Prevent ALTER IGNORE from
using bulk insert optimization. since it requires to write
undo log for each row operation that's incompatible with
existing bulk operation.
2026-02-26 13:18:23 +05:30
..
build
data
lib Merge 10.5 into 10.6 2024-11-29 12:37:46 +02:00
mysql-test Merge 10.6 into 10.11 2026-02-19 09:46:55 +02:00
packages
test
tools MDEV-23024 Remove Cassandra Storage Engine 2020-07-14 16:24:50 +03:00
udf MDEV-36337: mroonga_* udf correct ptr types for is_null/error 2025-05-21 09:47:55 +02:00
vendor/groonga Fix compiler warnings 2025-09-30 12:06:31 +03:00
appveyor.yml MDEV-23024 Remove Cassandra Storage Engine 2020-07-14 16:24:50 +03:00
AUTHORS
autogen.sh
ChangeLog
CMakeLists.txt Replace deprecated CMAKE_COMPILER_IS_GNU(CC|CXX) with CMAKE_(C|CXX)_COMPILER_ID 2025-06-03 18:16:35 +10:00
config.sh.in
configure.ac
COPYING
gpg_uid
ha_mroonga.cpp MDEV-36436 Assertion "unexpected references" == 0 after ALTER IGNORE TABLE 2026-02-26 13:18:23 +05:30
ha_mroonga.def
ha_mroonga.hpp Merge 10.5 into 10.6 2024-10-03 09:31:39 +03:00
Makefile.am
mrn.hpp MDEV-21166 Add Mroonga initialized check to Mroonga UDFs 2024-07-17 15:52:58 +10:00
mrn_constants.hpp
mrn_err.h
mrn_macro.hpp
mrn_mysql.h MDEV-36542: remove _lint macro which is unused 2025-07-29 13:15:02 +10:00
mrn_mysql_compat.h Merge 10.4 into 10.5 2022-10-13 17:05:30 +03:00
mrn_table.cpp MDEV-11412 Ensure that table is truly dropped when using DROP TABLE 2020-06-14 19:39:42 +03:00
mrn_table.hpp
mrn_variables.hpp perfschema compilation, test and misc fixes 2020-03-10 19:24:23 +01:00
mrn_version.h.in
NEWS
plugin_version
README
required_groonga_normalizer_mysql_version
required_groonga_version
sources.am MDEV-21166 Add Mroonga initialized check to Mroonga UDFs 2024-07-17 15:52:58 +10:00
version_full MDEV-7209 mroonga storage engine fails to build on OpenBSD 2021-07-27 20:44:46 +02:00
version_in_hex
version_major
version_micro
version_minor

See doc/locale/en/html/index.html or doc/locale/ja/html/index.html