Problem: ======= A transaction being rolled back during recovery holds LOCK_IX on the table(not the metadata locks), and the rollback thread holds a reference on it. An online ALTER TABLE on that table falls back to acquiring LOCK_S, which conflicts and fails. prepare_inplace_alter_table_dict() asserted that the reference count is 1 before checking whether the table lock was acquired, so the reference still held by the rollback thread makes the assertion fail. Solution: ======== recovery_mdl: New class that holds the metadata locks which trx_resurrect_table_locks() acquires for recovered transactions, together with the background connection that owns them. One MDL_ticket is acquired per table and shared by every recovered transaction that modified the table, with a reference count, so that the lock is released once the last of those transactions has been completed. trx_sys_t::recovery: Pointer to recovery_mdl, wrapped in std::atomic, next to rw_trx_hash, which trx_t::free() accesses anyway. Null pointer means that no recovered transaction holds metadata locks, which is the normal state once the recovered transaction have been completed. trx_lists_init_at_db_start(): Create recovery_mdl and publish it in trx_sys.recovery before any metadata lock can be acquired, and delete it again if no recovered transaction acquired any. recovery_mdl::release(): Drop the references of a transaction, releasing each metadata lock whose last reference is dropped. This is the only place that releases them, so that a transaction which was rolled back by trx_rollback_recovered(false) will not keep its locks until shutdown. trx_resurrect_table_locks(): Acquire a shared metadata lock on each table that the recovered transaction had modified, unless a lock on the table was acquired for an earlier one, and reference it for this transaction. Record every table in trx_t::mod_tables, so that trx_t::commit_in_memory() will find it. This includes transactions that were recovered in the XA PREPARED state. They are completed by a user connection, which may issue XA COMMIT or XA ROLLBACK at any time, or not at all before the next shutdown. Until then, DDL must be blocked on the tables that they had modified. trx_resurrect_table_lock(): Resurrect one table lock and record the table in trx_t::mod_tables. trx_sys_t::recovery_release(): Release the metadata locks that were acquired for a recovered transaction, and delete trx_sys.recovery if this was the last recovered transaction that held any. It is invoked by trx_t::commit_in_memory(), while trx_t::mod_tables and trx_t::is_recovered are still valid. This is the only place that releases the locks of a transaction, so that a transaction which was rolled back by trx_rollback_recovered(false) will not keep its locks until shutdown. trx_sys_t::recovery_release_table(): Drop the reference that a recovered transaction holds on the metadata lock of a table, because its trx_t::mod_tables entry is being removed by lock_release_on_rollback(). trx_sys_t::recovery_prune_low(): Detach trx_sys.recovery once no recovered transaction holds metadata locks any longer, so that neither the locks nor the connection will outlive the recovered transactions. The caller will delete the object outside recovery_mutex. This is skipped when the caller has a current_thd, such as a user connection that is completing a transaction which was recovered in the XA PREPARED state, and during shutdown, because destroy_background_thd() would clear the current_thd of the caller. trx_sys_t::recovery_shutdown(): Destroy trx_sys.recovery, releasing anything that is left. It is invoked at the end of trx_sys_t::close() only, after every transaction has been freed. No other thread can be accessing trx_sys.recovery, and therefore recovery_mutex need not be acquired. trx_sys_t::recovery_thd(): Return the background connection, for the rollback_wait debug injection in row_undo_mod(). prepare_inplace_alter_table_dict(): Remove the acquisition of an InnoDB table lock for online ADD INDEX when a recovered transaction holds a lock on the table.
Code status:
MariaDB: The innovative open source database
MariaDB was designed as a drop-in replacement of MySQL(R) with more features, new storage engines, fewer bugs, and better performance.
MariaDB is brought to you by the MariaDB Foundation and the MariaDB Corporation. Please read the CREDITS file for details about the MariaDB Foundation, and who is developing MariaDB.
MariaDB is developed by many of the original developers of MySQL who now work for the MariaDB Corporation, the MariaDB Foundation and by many people in the community.
MySQL, which is the base of MariaDB, is a product and trademark of Oracle Corporation, Inc. For a list of developers and other contributors, see the Credits appendix. You can also run 'SHOW authors' to get a list of active contributors.
A description of the MariaDB project and a manual can be found at:
https://mariadb.com/docs/release-notes
Getting the code, building it and testing it
Refer to the following guide: https://mariadb.org/get-involved/getting-started-for-developers/get-code-build-test/ which outlines how to build the source code correctly and run the MariaDB testing framework, as well as which branch to target for your contributions.
Help
More help is available from the Maria Discuss mailing list https://lists.mariadb.org/postorius/lists/discuss.lists.mariadb.org/ and MariaDB's Zulip instance, https://mariadb.zulipchat.com/
Licensing
MariaDB is specifically available only under version 2 of the GNU General Public License (GPLv2). (I.e. Without the "any later version" clause.) This is inherited from MySQL. Please see the README file in the MySQL distribution for more information.
License information can be found in the COPYING file. Third party license information can be found in the THIRDPARTY file.
Bug Reports
Bug and/or error reports regarding MariaDB should be submitted at: https://jira.mariadb.org
For reporting security vulnerabilities see: https://mariadb.org/about/security-policy/
The code for MariaDB, including all revision history, can be found at: https://github.com/MariaDB/server