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