MySQL 8.4.3
Source Code Documentation
|
Tables that were locked with LOCK TABLES statement. More...
#include <locked_tables_list.h>
Classes | |
struct | MDL_ticket_pair |
Public Member Functions | |
Locked_tables_list () | |
void | unlock_locked_tables (THD *thd) |
Leave LTM_LOCK_TABLES mode if it's been entered. More... | |
~Locked_tables_list () | |
bool | init_locked_tables (THD *thd) |
Enter LTM_LOCK_TABLES mode. More... | |
Table_ref * | locked_tables () const |
void | unlink_from_list (const THD *thd, Table_ref *table_list, bool remove_from_locked_tables) |
Unlink a locked table from the locked tables list, either temporarily or permanently. More... | |
void | unlink_all_closed_tables (THD *thd, MYSQL_LOCK *lock, size_t reopen_count) |
This is an attempt to recover (somewhat) in case of an error. More... | |
bool | reopen_tables (THD *thd) |
Reopen the tables locked with LOCK TABLES and temporarily closed by a DDL statement or FLUSH TABLES. More... | |
void | rename_locked_table (Table_ref *old_table_list, const char *new_db, const char *new_table_name, MDL_ticket *target_mdl_ticket) |
Update database and table names of table locked with LOCK TABLES after table rename. More... | |
void | add_rename_tablespace_mdls (MDL_ticket *src, MDL_ticket *dst) |
void | adjust_renamed_tablespace_mdls (MDL_context *mctx) |
void | discard_renamed_tablespace_mdls () |
Private Types | |
using | MDL_ticket_pairs = std::vector< MDL_ticket_pair > |
Private Attributes | |
MEM_ROOT | m_locked_tables_root |
Table_ref * | m_locked_tables |
Table_ref ** | m_locked_tables_last |
TABLE ** | m_reopen_array |
An auxiliary array used only in reopen_tables(). More... | |
size_t | m_locked_tables_count |
Count the number of tables in m_locked_tables list. More... | |
MDL_ticket_pairs | m_rename_tablespace_mdls |
Tables that were locked with LOCK TABLES statement.
Encapsulates a list of Table_ref instances for tables locked by LOCK TABLES statement, memory root for metadata locks, and, generally, the context of LOCK TABLES statement.
In LOCK TABLES mode, the locked tables are kept open between statements. Therefore, we can't allocate metadata locks on execution memory root – as well as tables, the locks need to stay around till UNLOCK TABLES is called. The locks are allocated in the memory root encapsulated in this class.
Some SQL commands, like FLUSH TABLE or ALTER TABLE, demand that the tables they operate on are closed, at least temporarily. This class encapsulates a list of Table_ref instances, one for each base table from LOCK TABLES list, which helps conveniently close the TABLEs when it's necessary and later reopen them.
|
private |
Locked_tables_list::Locked_tables_list | ( | ) |
|
inline |
void Locked_tables_list::add_rename_tablespace_mdls | ( | MDL_ticket * | src, |
MDL_ticket * | dst | ||
) |
void Locked_tables_list::adjust_renamed_tablespace_mdls | ( | MDL_context * | mctx | ) |
|
inline |
bool Locked_tables_list::init_locked_tables | ( | THD * | thd | ) |
Enter LTM_LOCK_TABLES mode.
Enter the LOCK TABLES mode using all the tables that are currently open and locked in this connection. Initializes a Table_ref instance for every locked table.
thd | thread handle |
Sic: remember the actual table level lock type taken, to acquire the exact same type in reopen_tables(). E.g. if the table was locked for write, src_table_list->lock_type is TL_WRITE_DEFAULT, whereas reginfo.lock_type has been updated from thd->update_lock_default.
Allocate an auxiliary array to pass to mysql_lock_tables() in reopen_tables(). reopen_tables() is a critical path and we don't want to complicate it with extra allocations.
|
inline |
void Locked_tables_list::rename_locked_table | ( | Table_ref * | old_table_list, |
const char * | new_db, | ||
const char * | new_table_name, | ||
MDL_ticket * | target_mdl_ticket | ||
) |
Update database and table names of table locked with LOCK TABLES after table rename.
old_table_list | Table list element representing old db/table name. |
new_db | Table's new database. |
new_table_name | Table's new name. |
target_mdl_ticket | Ticket representing metadata lock acquired on new table name. |
bool Locked_tables_list::reopen_tables | ( | THD * | thd | ) |
Reopen the tables locked with LOCK TABLES and temporarily closed by a DDL statement or FLUSH TABLES.
void Locked_tables_list::unlink_all_closed_tables | ( | THD * | thd, |
MYSQL_LOCK * | lock, | ||
size_t | reopen_count | ||
) |
This is an attempt to recover (somewhat) in case of an error.
If we failed to reopen a closed table, let's unlink it from the list and forget about it. From a user perspective that would look as if the server "lost" the lock on one of the locked tables.
void Locked_tables_list::unlink_from_list | ( | const THD * | thd, |
Table_ref * | table_list, | ||
bool | remove_from_locked_tables | ||
) |
Unlink a locked table from the locked tables list, either temporarily or permanently.
thd | thread handle |
table_list | the element of locked tables list. The implementation assumes that this argument points to a Table_ref element linked into the locked tables list. Passing a Table_ref instance that is not part of locked tables list will lead to a crash. |
remove_from_locked_tables | true if the table is removed from the list permanently. |
This function is a no-op if we're not under LOCK TABLES.
void Locked_tables_list::unlock_locked_tables | ( | THD * | thd | ) |
Leave LTM_LOCK_TABLES mode if it's been entered.
Close all locked tables, free memory, and leave the mode.
|
private |
|
private |
Count the number of tables in m_locked_tables list.
We can't rely on thd->lock->table_count because it excludes non-transactional temporary tables. We need to know an exact number of TABLE objects.
|
private |
|
private |
|
private |
|
private |
An auxiliary array used only in reopen_tables().