MySQL 8.4.2
Source Code Documentation
locked_tables_list.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef LOCKED_TABLES_LIST_INCLUDED
25#define LOCKED_TABLES_LIST_INCLUDED
26
27#include <sys/types.h>
28#include <vector>
29#include "my_alloc.h"
30#include "sql/psi_memory_key.h"
31#include "sql/sql_const.h"
32
33struct MYSQL_LOCK;
34class MDL_context;
35class MDL_ticket;
36struct TABLE;
37class Table_ref;
38class THD;
39
40/**
41 Type of locked tables mode.
42 See comment for THD::locked_tables_mode for complete description.
43 While adding new enum values add them to the getter method for this enum
44 declared below and defined in binlog.cc as well.
45*/
46
52};
53
54#ifndef NDEBUG
55/**
56 Getter for the enum enum_locked_tables_mode
57 @param locked_tables_mode enum for types of locked tables mode
58
59 @return The string representation of that enum value
60*/
63#endif
64
65/**
66 Tables that were locked with LOCK TABLES statement.
67
68 Encapsulates a list of Table_ref instances for tables
69 locked by LOCK TABLES statement, memory root for metadata locks,
70 and, generally, the context of LOCK TABLES statement.
71
72 In LOCK TABLES mode, the locked tables are kept open between
73 statements.
74 Therefore, we can't allocate metadata locks on execution memory
75 root -- as well as tables, the locks need to stay around till
76 UNLOCK TABLES is called.
77 The locks are allocated in the memory root encapsulated in this
78 class.
79
80 Some SQL commands, like FLUSH TABLE or ALTER TABLE, demand that
81 the tables they operate on are closed, at least temporarily.
82 This class encapsulates a list of Table_ref instances, one
83 for each base table from LOCK TABLES list,
84 which helps conveniently close the TABLEs when it's necessary
85 and later reopen them.
86
87*/
88
90 private:
95 /** An auxiliary array used only in reopen_tables(). */
97 /**
98 Count the number of tables in m_locked_tables list. We can't
99 rely on thd->lock->table_count because it excludes
100 non-transactional temporary tables. We need to know
101 an exact number of TABLE objects.
102 */
104
108 };
109 using MDL_ticket_pairs = std::vector<MDL_ticket_pair>;
110
112
113 public:
115
116 void unlock_locked_tables(THD *thd);
118 unlock_locked_tables(nullptr);
119 assert(m_rename_tablespace_mdls.empty());
120 }
121 bool init_locked_tables(THD *thd);
123 void unlink_from_list(const THD *thd, Table_ref *table_list,
124 bool remove_from_locked_tables);
126 size_t reopen_count);
127 bool reopen_tables(THD *thd);
128 void rename_locked_table(Table_ref *old_table_list, const char *new_db,
129 const char *new_table_name,
130 MDL_ticket *target_mdl_ticket);
131
135};
136
137#endif /*not defined LOCK_TABLES_LIST_INCLUDED */
Tables that were locked with LOCK TABLES statement.
Definition: locked_tables_list.h:89
bool init_locked_tables(THD *thd)
Enter LTM_LOCK_TABLES mode.
Definition: locked_tables_list.cc:52
void add_rename_tablespace_mdls(MDL_ticket *src, MDL_ticket *dst)
Definition: locked_tables_list.cc:428
MEM_ROOT m_locked_tables_root
Definition: locked_tables_list.h:91
Table_ref ** m_locked_tables_last
Definition: locked_tables_list.h:94
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.
Definition: locked_tables_list.cc:237
Locked_tables_list()
Definition: locked_tables_list.cc:34
MDL_ticket_pairs m_rename_tablespace_mdls
Definition: locked_tables_list.h:111
void adjust_renamed_tablespace_mdls(MDL_context *mctx)
Definition: locked_tables_list.cc:453
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.
Definition: locked_tables_list.cc:194
bool reopen_tables(THD *thd)
Reopen the tables locked with LOCK TABLES and temporarily closed by a DDL statement or FLUSH TABLES.
Definition: locked_tables_list.cc:288
Table_ref * locked_tables() const
Definition: locked_tables_list.h:122
size_t m_locked_tables_count
Count the number of tables in m_locked_tables list.
Definition: locked_tables_list.h:103
std::vector< MDL_ticket_pair > MDL_ticket_pairs
Definition: locked_tables_list.h:109
void discard_renamed_tablespace_mdls()
Definition: locked_tables_list.h:134
Table_ref * m_locked_tables
Definition: locked_tables_list.h:93
TABLE ** m_reopen_array
An auxiliary array used only in reopen_tables().
Definition: locked_tables_list.h:96
void unlock_locked_tables(THD *thd)
Leave LTM_LOCK_TABLES mode if it's been entered.
Definition: locked_tables_list.cc:127
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.
Definition: locked_tables_list.cc:371
~Locked_tables_list()
Definition: locked_tables_list.h:117
Context of the owner of metadata locks.
Definition: mdl.h:1412
A granted metadata lock.
Definition: mdl.h:985
enum enum_locked_tables_mode locked_tables_mode
Definition: sql_class.h:662
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2864
const char * get_locked_tables_mode_name(enum_locked_tables_mode locked_tables_mode)
Getter for the enum enum_locked_tables_mode.
Definition: binlog.cc:9871
enum_locked_tables_mode
Type of locked tables mode.
Definition: locked_tables_list.h:47
@ LTM_PRELOCKED
Definition: locked_tables_list.h:50
@ LTM_LOCK_TABLES
Definition: locked_tables_list.h:49
@ LTM_PRELOCKED_UNDER_LOCK_TABLES
Definition: locked_tables_list.h:51
@ LTM_NONE
Definition: locked_tables_list.h:48
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
PSI_memory_key key_memory_locked_table_list
Definition: psi_memory_key.cc:119
File containing constants that can be used throughout the server.
constexpr const size_t MEM_ROOT_BLOCK_SIZE
Memory allocated when parsing a statement.
Definition: sql_const.h:128
Definition: locked_tables_list.h:105
MDL_ticket * m_dst
Definition: locked_tables_list.h:107
MDL_ticket * m_src
Definition: locked_tables_list.h:106
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: lock.h:39
Definition: table.h:1406