MySQL 8.0.30
Source Code Documentation
locked_tables_list.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 2022, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef LOCKED_TABLES_LIST_INCLUDED
24#define LOCKED_TABLES_LIST_INCLUDED
25
26#include <sys/types.h>
27#include <vector>
28#include "my_alloc.h"
29#include "sql/psi_memory_key.h"
30#include "sql/sql_const.h"
31
32struct MYSQL_LOCK;
33class MDL_context;
34class MDL_ticket;
35struct TABLE;
36struct TABLE_LIST;
37class THD;
38
39/**
40 Type of locked tables mode.
41 See comment for THD::locked_tables_mode for complete description.
42 While adding new enum values add them to the getter method for this enum
43 declared below and defined in binlog.cc as well.
44*/
45
51};
52
53#ifndef NDEBUG
54/**
55 Getter for the enum enum_locked_tables_mode
56 @param locked_tables_mode enum for types of locked tables mode
57
58 @return The string representation of that enum value
59*/
62#endif
63
64/**
65 Tables that were locked with LOCK TABLES statement.
66
67 Encapsulates a list of TABLE_LIST instances for tables
68 locked by LOCK TABLES statement, memory root for metadata locks,
69 and, generally, the context of LOCK TABLES statement.
70
71 In LOCK TABLES mode, the locked tables are kept open between
72 statements.
73 Therefore, we can't allocate metadata locks on execution memory
74 root -- as well as tables, the locks need to stay around till
75 UNLOCK TABLES is called.
76 The locks are allocated in the memory root encapsulated in this
77 class.
78
79 Some SQL commands, like FLUSH TABLE or ALTER TABLE, demand that
80 the tables they operate on are closed, at least temporarily.
81 This class encapsulates a list of TABLE_LIST instances, one
82 for each base table from LOCK TABLES list,
83 which helps conveniently close the TABLEs when it's necessary
84 and later reopen them.
85
86*/
87
89 private:
94 /** An auxiliary array used only in reopen_tables(). */
96 /**
97 Count the number of tables in m_locked_tables list. We can't
98 rely on thd->lock->table_count because it excludes
99 non-transactional temporary tables. We need to know
100 an exact number of TABLE objects.
101 */
103
107 };
108 using MDL_ticket_pairs = std::vector<MDL_ticket_pair>;
109
111
112 public:
114
115 void unlock_locked_tables(THD *thd);
117 unlock_locked_tables(nullptr);
118 assert(m_rename_tablespace_mdls.empty());
119 }
120 bool init_locked_tables(THD *thd);
122 void unlink_from_list(const THD *thd, TABLE_LIST *table_list,
123 bool remove_from_locked_tables);
125 size_t reopen_count);
126 bool reopen_tables(THD *thd);
127 void rename_locked_table(TABLE_LIST *old_table_list, const char *new_db,
128 const char *new_table_name,
129 MDL_ticket *target_mdl_ticket);
130
134};
135
136#endif /*not defined LOCK_TABLES_LIST_INCLUDED */
Tables that were locked with LOCK TABLES statement.
Definition: locked_tables_list.h:88
bool init_locked_tables(THD *thd)
Enter LTM_LOCK_TABLES mode.
Definition: locked_tables_list.cc:49
void add_rename_tablespace_mdls(MDL_ticket *src, MDL_ticket *dst)
Definition: locked_tables_list.cc:426
MEM_ROOT m_locked_tables_root
Definition: locked_tables_list.h:90
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:235
void rename_locked_table(TABLE_LIST *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:369
Locked_tables_list()
Definition: locked_tables_list.cc:31
TABLE_LIST * locked_tables() const
Definition: locked_tables_list.h:121
TABLE_LIST * m_locked_tables
Definition: locked_tables_list.h:92
MDL_ticket_pairs m_rename_tablespace_mdls
Definition: locked_tables_list.h:110
void adjust_renamed_tablespace_mdls(MDL_context *mctx)
Definition: locked_tables_list.cc:451
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:286
TABLE_LIST ** m_locked_tables_last
Definition: locked_tables_list.h:93
size_t m_locked_tables_count
Count the number of tables in m_locked_tables list.
Definition: locked_tables_list.h:102
std::vector< MDL_ticket_pair > MDL_ticket_pairs
Definition: locked_tables_list.h:108
void discard_renamed_tablespace_mdls()
Definition: locked_tables_list.h:133
TABLE ** m_reopen_array
An auxiliary array used only in reopen_tables().
Definition: locked_tables_list.h:95
void unlock_locked_tables(THD *thd)
Leave LTM_LOCK_TABLES mode if it's been entered.
Definition: locked_tables_list.cc:124
~Locked_tables_list()
Definition: locked_tables_list.h:116
void unlink_from_list(const THD *thd, TABLE_LIST *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:191
Context of the owner of metadata locks.
Definition: mdl.h:1409
A granted metadata lock.
Definition: mdl.h:982
enum enum_locked_tables_mode locked_tables_mode
Definition: sql_class.h:649
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
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:9741
enum_locked_tables_mode
Type of locked tables mode.
Definition: locked_tables_list.h:46
@ LTM_PRELOCKED
Definition: locked_tables_list.h:49
@ LTM_LOCK_TABLES
Definition: locked_tables_list.h:48
@ LTM_PRELOCKED_UNDER_LOCK_TABLES
Definition: locked_tables_list.h:50
@ LTM_NONE
Definition: locked_tables_list.h:47
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:78
PSI_memory_key key_memory_locked_table_list
Definition: psi_memory_key.cc:114
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:127
Definition: locked_tables_list.h:104
MDL_ticket * m_dst
Definition: locked_tables_list.h:106
MDL_ticket * m_src
Definition: locked_tables_list.h:105
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: lock.h:38
Definition: table.h:2684
Definition: table.h:1394