MySQL  8.0.27
Source Code Documentation
rpl_table_access.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2021, 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 RPL_TABLE_ACCESS_H_
24 #define RPL_TABLE_ACCESS_H_
25 
26 #include <sys/types.h>
27 
28 #include "lex_string.h"
29 #include "thr_lock.h" // thr_lock_type
30 
31 class Open_tables_backup;
32 class THD;
33 struct TABLE;
34 
35 /**
36  A base class for accessing a system table.
37 */
38 
40  public:
41  virtual ~System_table_access() = default;
42 
43  /**
44  Opens and locks a system table.
45 
46  It's assumed that the caller knows what they are doing:
47  - whether it was necessary to reset-and-backup the open tables state
48  - whether the requested lock does not lead to a deadlock
49  - whether this open mode would work under LOCK TABLES, or inside a
50  stored function or trigger.
51 
52  Note that if the table can't be locked successfully this operation will
53  close it. Therefore it provides guarantee that it either opens and locks
54  table or fails without leaving any tables open.
55 
56  @param[in] thd Thread requesting to open the table
57  @param[in] dbstr Database where the table resides
58  @param[in] tbstr Table to be openned
59  @param[in] max_num_field Maximum number of fields
60  @param[in] lock_type How to lock the table
61  @param[out] table We will store the open table here
62  @param[out] backup Save the lock info. here
63 
64  @retval true open and lock failed - an error message is pushed into the
65  stack
66  @retval false success
67  */
68  bool open_table(THD *thd, const LEX_CSTRING dbstr, const LEX_CSTRING tbstr,
69  uint max_num_field, enum thr_lock_type lock_type,
70  TABLE **table, Open_tables_backup *backup);
71 
72  /**
73  Opens and locks a system table.
74 
75  It's assumed that the caller knows what they are doing:
76  - whether it was necessary to reset-and-backup the open tables state
77  - whether the requested lock does not lead to a deadlock
78  - whether this open mode would work under LOCK TABLES, or inside a
79  stored function or trigger.
80 
81  Note that if the table can't be locked successfully this operation will
82  close it. Therefore it provides guarantee that it either opens and locks
83  table or fails without leaving any tables open.
84 
85  @param[in] thd Thread requesting to open the table
86  @param[in] dbstr Database where the table resides
87  @param[in] tbstr Table to be openned
88  @param[in] max_num_field Maximum number of fields
89  @param[in] lock_type How to lock the table
90  @param[out] table We will store the open table here
91  @param[out] backup Save the lock info. here
92 
93  @retval true open and lock failed - an error message is pushed into the
94  stack
95  @retval false success
96  */
97  bool open_table(THD *thd, std::string dbstr, std::string tbstr,
98  uint max_num_field, enum thr_lock_type lock_type,
99  TABLE **table, Open_tables_backup *backup);
100 
101  /**
102  Prepares before opening table.
103 
104  @param[in] thd Thread requesting to open the table
105  */
106  virtual void before_open(THD *thd) = 0;
107  /**
108  Commits the changes, unlocks the table and closes it. This method
109  needs to be called even if the open_table fails, in order to ensure
110  the lock info is properly restored.
111 
112  @param[in] thd Thread requesting to close the table
113  @param[in] table Table to be closed
114  @param[in] backup Restore the lock info from here
115  @param[in] error If there was an error while updating
116  the table
117  @param[in] need_commit Need to commit current transaction
118  if it is true.
119 
120  @retval true failed
121  @retval false success
122 
123  If there is an error, rolls back the current statement. Otherwise,
124  commits it. However, if a new thread was created and there is an
125  error, the transaction must be rolled back. Otherwise, it must be
126  committed. In this case, the changes were not done on behalf of
127  any user transaction and if not finished, there would be pending
128  changes.
129  */
130  bool close_table(THD *thd, TABLE *table, Open_tables_backup *backup,
131  bool error, bool need_commit);
132  /**
133  Creates a new thread in the bootstrap process or in the mysqld startup,
134  a thread is created in order to be able to access a table.
135 
136  @return THD* Pointer to thread structure
137  */
138  THD *create_thd();
139  /**
140  Destroys the created thread and restores the
141  system_thread information.
142 
143  @param thd Thread requesting to be destroyed
144  */
145  void drop_thd(THD *thd);
146 
147  /* Flags for opening table */
149 };
150 
151 #endif /* RPL_TABLE_ACCESS_H_ */
Storage for backup of Open_tables_state.
Definition: sql_class.h:579
A base class for accessing a system table.
Definition: rpl_table_access.h:39
bool open_table(THD *thd, const LEX_CSTRING dbstr, const LEX_CSTRING tbstr, uint max_num_field, enum thr_lock_type lock_type, TABLE **table, Open_tables_backup *backup)
Opens and locks a system table.
Definition: rpl_table_access.cc:43
void drop_thd(THD *thd)
Destroys the created thread and restores the system_thread information.
Definition: rpl_table_access.cc:176
bool close_table(THD *thd, TABLE *table, Open_tables_backup *backup, bool error, bool need_commit)
Commits the changes, unlocks the table and closes it.
Definition: rpl_table_access.cc:115
virtual void before_open(THD *thd)=0
Prepares before opening table.
virtual ~System_table_access()=default
THD * create_thd()
Creates a new thread in the bootstrap process or in the mysqld startup, a thread is created in order ...
Definition: rpl_table_access.cc:166
uint m_flags
Definition: rpl_table_access.h:148
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
static bool backup
Definition: myisampack.cc:194
Definition: mysql_lex_string.h:39
Definition: table.h:1394
thr_lock_type
Definition: thr_lock.h:50
unsigned int uint
Definition: uca-dump.cc:29