1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00
Files
Thirunarayanan Balathandayuthapani d81edfdb40 MDEV-41207 Acquire metadata locks for recovered transaction
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.
2026-10-12 14:28:05 +05:30
..
…
…
…

This directory contains test suites for the MariaDB server. To run
currently existing test cases, execute ./mysql-test-run in this directory.

Some tests are known to fail on some platforms or be otherwise unreliable.
In the file collections/smoke_test there is a list of tests that are
expected to be stable.

In general you do not have to have to do "make install", and you can have
a co-existing MariaDB installation, the tests will not conflict with it.
To run the tests in a source directory, you must do "make" first.

In Red Hat distributions, you should run the script as user "mysql".
The user is created with nologin shell, so the best bet is something like
  # su -
  # cd /usr/share/mysql-test
  # su -s /bin/bash mysql -c ./mysql-test-run

This will use the installed MariaDB executables, but will run a private
copy of the server process (using data files within /usr/share/mysql-test),
so you need not start the mysqld service beforehand.

You can omit --skip-test-list option if you want to check whether
the listed failures occur for you.

To clean up afterwards, remove the created "var" subdirectory, e.g.
  # su -s /bin/bash - mysql -c "rm -rf /usr/share/mysql-test/var"

If tests fail on your system, please read the following manual section
for instructions on how to report the problem:

https://mariadb.com/docs/general-resources/community/community/bug-tracking/reporting-bugs

If you want to use an already running MySQL server for specific tests,
use the --extern option to mysql-test-run. Please note that in this mode,
you are expected to provide names of the tests to run.

For example, here is the command to run the "alias" and "analyze" tests
with an external server:

  # mysql-test-run --extern socket=/tmp/mysql.sock alias analyze

To match your setup, you might need to provide other relevant options.

With no test names on the command line, mysql-test-run will attempt
to execute the default set of tests, which will certainly fail, because
many tests cannot run with an external server (they need to control the
options with which the server is started, restart the server during
execution, etc.)

You can create your own test cases. To create a test case, create a new
file in the main subdirectory using a text editor. The file should have a .test
extension. For example:

  # xemacs t/test_case_name.test

In the file, put a set of SQL statements that create some tables,
load test data, and run some queries to manipulate it.

Your test should begin by dropping the tables you are going to create and
end by dropping them again. This ensures that you can run the test over
and over again.

If you are using mysqltest commands in your test case, you should create
the result file as follows:

  # mysql-test-run --record test_case_name

  or

  # mysqltest --record < t/test_case_name.test

If you only have a simple test case consisting of SQL statements and
comments, you can create the result file in one of the following ways:

  # mysql-test-run --record test_case_name

  # mysql test < t/test_case_name.test > r/test_case_name.result

  # mysqltest --record --database test --result-file=r/test_case_name.result < t/test_case_name.test

When this is done, take a look at r/test_case_name.result.
If the result is incorrect, you have found a bug. In this case, you should
edit the test result to the correct results so that we can verify that
the bug is corrected in future releases.

If you want to submit your test case you can send it
to developers@lists.mariadb.org or attach it to a bug report on
http://mariadb.org/jira/.

If the test case is really big or if it contains 'not public' data,
then put your .test file and .result file(s) into a tar.gz archive,
add a README that explains the problem, ftp the archive to
ftp://ftp.mariadb.org/private and submit a report to
https://mariadb.org/jira about it.

The latest information about mysql-test-run can be found at:
https://mariadb.com/docs/server/clients-and-utilities/testing-tools/mariadb-test

If you want to create .rdiff files, check
https://mariadb.com/docs/server/clients-and-utilities/testing-tools/mariadb-test/mariadb-test-auxiliary-files