MySQL  8.0.18
Source Code Documentation
locked_tables_list.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
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 
30 struct MYSQL_LOCK;
31 class MDL_context;
32 class MDL_ticket;
33 struct TABLE;
34 struct TABLE_LIST;
35 class THD;
36 
37 /**
38  Type of locked tables mode.
39  See comment for THD::locked_tables_mode for complete description.
40  While adding new enum values add them to the getter method for this enum
41  declared below and defined in binlog.cc as well.
42 */
43 
45  LTM_NONE = 0,
49 };
50 
51 #ifndef DBUG_OFF
52 /**
53  Getter for the enum enum_locked_tables_mode
54  @param locked_tables_mode enum for types of locked tables mode
55 
56  @return The string represantation of that enum value
57 */
58 const char *get_locked_tables_mode_name(
60 #endif
61 
62 /**
63  Tables that were locked with LOCK TABLES statement.
64 
65  Encapsulates a list of TABLE_LIST instances for tables
66  locked by LOCK TABLES statement, memory root for metadata locks,
67  and, generally, the context of LOCK TABLES statement.
68 
69  In LOCK TABLES mode, the locked tables are kept open between
70  statements.
71  Therefore, we can't allocate metadata locks on execution memory
72  root -- as well as tables, the locks need to stay around till
73  UNLOCK TABLES is called.
74  The locks are allocated in the memory root encapsulated in this
75  class.
76 
77  Some SQL commands, like FLUSH TABLE or ALTER TABLE, demand that
78  the tables they operate on are closed, at least temporarily.
79  This class encapsulates a list of TABLE_LIST instances, one
80  for each base table from LOCK TABLES list,
81  which helps conveniently close the TABLEs when it's necessary
82  and later reopen them.
83 
84 */
85 
87  private:
91  /** An auxiliary array used only in reopen_tables(). */
93  /**
94  Count the number of tables in m_locked_tables list. We can't
95  rely on thd->lock->table_count because it excludes
96  non-transactional temporary tables. We need to know
97  an exact number of TABLE objects.
98  */
100 
104  };
105  using MDL_ticket_pairs = std::vector<MDL_ticket_pair>;
106 
108 
109  public:
111 
112  void unlock_locked_tables(THD *thd);
116  }
117  bool init_locked_tables(THD *thd);
119  void unlink_from_list(const THD *thd, TABLE_LIST *table_list,
120  bool remove_from_locked_tables);
121  void unlink_all_closed_tables(THD *thd, MYSQL_LOCK *lock,
122  size_t reopen_count);
123  bool reopen_tables(THD *thd);
124  void rename_locked_table(TABLE_LIST *old_table_list, const char *new_db,
125  const char *new_table_name,
126  MDL_ticket *target_mdl_ticket);
127 
131 };
132 
133 #endif /*not defined LOCK_TABLES_LIST_INCLUDED */
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:242
A granted metadata lock.
Definition: mdl.h:963
TABLE_LIST * m_locked_tables
Definition: locked_tables_list.h:89
Definition: locked_tables_list.h:101
MDL_ticket * m_dst
Definition: locked_tables_list.h:103
MDL_ticket * m_src
Definition: locked_tables_list.h:102
TABLE_LIST * locked_tables() const
Definition: locked_tables_list.h:118
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:198
Locked_tables_list()
Definition: locked_tables_list.cc:31
TABLE_LIST ** m_locked_tables_last
Definition: locked_tables_list.h:90
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:293
enum enum_locked_tables_mode locked_tables_mode
Definition: sql_class.h:534
Tables that were locked with LOCK TABLES statement.
Definition: locked_tables_list.h:86
void add_rename_tablespace_mdls(MDL_ticket *src, MDL_ticket *dst)
Definition: locked_tables_list.cc:433
TABLE ** m_reopen_array
An auxiliary array used only in reopen_tables().
Definition: locked_tables_list.h:92
size_t m_locked_tables_count
Count the number of tables in m_locked_tables list.
Definition: locked_tables_list.h:99
Definition: table.h:1301
~Locked_tables_list()
Definition: locked_tables_list.h:113
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
void adjust_renamed_tablespace_mdls(MDL_context *mctx)
Definition: locked_tables_list.cc:458
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:9602
Context of the owner of metadata locks.
Definition: mdl.h:1390
Definition: locked_tables_list.h:48
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:376
MDL_ticket_pairs m_rename_tablespace_mdls
Definition: locked_tables_list.h:107
MEM_ROOT m_locked_tables_root
Definition: locked_tables_list.h:88
bool init_locked_tables(THD *thd)
Enter LTM_LOCK_TABLES mode.
Definition: locked_tables_list.cc:52
void discard_renamed_tablespace_mdls()
Definition: locked_tables_list.h:130
enum_locked_tables_mode
Type of locked tables mode.
Definition: locked_tables_list.h:44
Definition: locked_tables_list.h:46
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
Definition: table.h:2468
Definition: locked_tables_list.h:45
Definition: lock.h:38
std::vector< MDL_ticket_pair > MDL_ticket_pairs
Definition: locked_tables_list.h:105
Definition: locked_tables_list.h:47
void unlock_locked_tables(THD *thd)
Leave LTM_LOCK_TABLES mode if it&#39;s been entered.
Definition: locked_tables_list.cc:130
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778