MySQL 8.0.31
Source Code Documentation
read0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/read0types.h
28 Cursor read
29
30 Created 2/16/1997 Heikki Tuuri
31 *******************************************************/
32
33#ifndef read0types_h
34#define read0types_h
35
36#include <algorithm>
37#include "dict0mem.h"
38
39#include "trx0types.h"
40
41// Friend declaration
42class MVCC;
43
44/** Read view lists the trx ids of those transactions for which a consistent
45read should not see the modifications to the database. */
46
47class ReadView {
48 /** This is similar to a std::vector but it is not a drop
49 in replacement. It is specific to ReadView. */
50 class ids_t {
52
53 /**
54 Constructor */
56
57 /**
58 Destructor */
60
61 /** Try and increase the size of the array. Old elements are copied across.
62 It is a no-op if n is < current size.
63 @param n Make space for n elements */
64 void reserve(ulint n);
65
66 /**
67 Resize the array, sets the current element count.
68 @param n new size of the array, in elements */
69 void resize(ulint n) {
70 ut_ad(n <= capacity());
71
72 m_size = n;
73 }
74
75 /**
76 Reset the size to 0 */
77 void clear() { resize(0); }
78
79 /**
80 @return the capacity of the array in elements */
81 ulint capacity() const { return (m_reserved); }
82
83 /**
84 Copy and overwrite the current array contents
85
86 @param start Source array
87 @param end Pointer to end of array */
88 void assign(const value_type *start, const value_type *end);
89
90 /**
91 Insert the value in the correct slot, preserving the order.
92 Doesn't check for duplicates. */
93 void insert(value_type value);
94
95 /**
96 @return the value of the first element in the array */
97 value_type front() const {
98 ut_ad(!empty());
99
100 return (m_ptr[0]);
101 }
102
103 /**
104 @return the value of the last element in the array */
105 value_type back() const {
106 ut_ad(!empty());
107
108 return (m_ptr[m_size - 1]);
109 }
110
111 /**
112 Append a value to the array.
113 @param value the value to append */
114 void push_back(value_type value);
115
116 /**
117 @return a pointer to the start of the array */
118 trx_id_t *data() { return (m_ptr); }
119
120 /**
121 @return a const pointer to the start of the array */
122 const trx_id_t *data() const { return (m_ptr); }
123
124 /**
125 @return the number of elements in the array */
126 ulint size() const { return (m_size); }
127
128 /**
129 @return true if size() == 0 */
130 bool empty() const { return (size() == 0); }
131
132 private:
133 // Prevent copying
134 ids_t(const ids_t &);
136
137 private:
138 /** Memory for the array */
140
141 /** Number of active elements in the array */
143
144 /** Size of m_ptr in elements */
146
147 friend class ReadView;
148 };
149
150 public:
151 ReadView();
152 ~ReadView();
153 /** Check whether transaction id is valid.
154 @param[in] id transaction id to check
155 @param[in] name table name */
156 static void check_trx_id_sanity(trx_id_t id, const table_name_t &name);
157
158 /** Check whether the changes by id are visible.
159 @param[in] id transaction id to check against the view
160 @param[in] name table name
161 @return whether the view sees the modifications of id. */
162 [[nodiscard]] bool changes_visible(trx_id_t id,
163 const table_name_t &name) const {
164 ut_ad(id > 0);
165
166 if (id < m_up_limit_id || id == m_creator_trx_id) {
167 return (true);
168 }
169
171
172 if (id >= m_low_limit_id) {
173 return (false);
174
175 } else if (m_ids.empty()) {
176 return (true);
177 }
178
179 const ids_t::value_type *p = m_ids.data();
180
181 return (!std::binary_search(p, p + m_ids.size(), id));
182 }
183
184 /**
185 @param id transaction to check
186 @return true if view sees transaction id */
187 bool sees(trx_id_t id) const { return (id < m_up_limit_id); }
188
189 /**
190 Mark the view as closed */
191 void close() {
194 }
195
196 /**
197 @return true if the view is closed */
198 bool is_closed() const { return (m_closed); }
199
200 /**
201 Write the limits to the file.
202 @param file file to write to */
203 void print_limits(FILE *file) const {
204 fprintf(file,
205 "Trx read view will not see trx with"
206 " id >= " TRX_ID_FMT ", sees < " TRX_ID_FMT "\n",
208 }
209
210 /** Check and reduce low limit number for read view. Used to
211 block purge till GTID is persisted on disk table.
212 @param[in] trx_no transaction number to check with */
214 if (trx_no < m_low_limit_no) {
215 /* Save low limit number set for Read View for MVCC. */
217 m_low_limit_no = trx_no;
218 }
219 }
220
221 /**
222 @return the low limit no */
224
225 /**
226 @return the low limit id */
228
229 /**
230 @return true if there are no transaction ids in the snapshot */
231 bool empty() const { return (m_ids.empty()); }
232
233#ifdef UNIV_DEBUG
234 /**
235 @return the view low limit number */
237
238 /**
239 @param rhs view to compare with
240 @return truen if this view is less than or equal rhs */
241 bool le(const ReadView *rhs) const {
242 return (m_low_limit_no <= rhs->m_low_limit_no);
243 }
244#endif /* UNIV_DEBUG */
245 private:
246 /**
247 Copy the transaction ids from the source vector */
248 inline void copy_trx_ids(const trx_ids_t &trx_ids);
249
250 /**
251 Opens a read view where exactly the transactions serialized before this
252 point in time are seen in the view.
253 @param id Creator transaction id */
254 inline void prepare(trx_id_t id);
255
256 /**
257 Copy state from another view. Must call copy_complete() to finish.
258 @param other view to copy from */
259 inline void copy_prepare(const ReadView &other);
260
261 /**
262 Complete the copy, insert the creator transaction id into the
263 m_trx_ids too and adjust the m_up_limit_id *, if required */
264 inline void copy_complete();
265
266 /**
267 Set the creator transaction id, existing id must be 0 */
271 }
272
273 friend class MVCC;
274
275 private:
276 // Disable copying
279
280 private:
281 /** The read should not see any transaction with trx id >= this
282 value. In other words, this is the "high water mark". */
284
285 /** The read should see all trx ids which are strictly
286 smaller (<) than this value. In other words, this is the
287 low water mark". */
289
290 /** trx id of creating transaction, set to TRX_ID_MAX for free
291 views. */
293
294 /** Set of RW transactions that was active when this snapshot
295 was taken */
297
298 /** The view does not need to see the undo logs for transactions
299 whose transaction number is strictly smaller (<) than this value:
300 they can be removed in purge if not needed by other views */
302
303#ifdef UNIV_DEBUG
304 /** The low limit number up to which read views don't need to access
305 undo log records for MVCC. This could be higher than m_low_limit_no
306 if purge is blocked for GTID persistence. Currently used for debug
307 variable INNODB_PURGE_VIEW_TRX_ID_AGE. */
309#endif /* UNIV_DEBUG */
310
311 /** AC-NL-RO transaction view that has been "closed". */
313
314 typedef UT_LIST_NODE_T(ReadView) node_t;
315
316 /** List of read views in trx_sys */
317 byte pad1[64 - sizeof(node_t)];
319};
320
321#endif
The MVCC read view manager.
Definition: read0read.h:43
This is similar to a std::vector but it is not a drop in replacement.
Definition: read0types.h:50
ulint m_size
Number of active elements in the array.
Definition: read0types.h:142
const trx_id_t * data() const
Definition: read0types.h:122
value_type * m_ptr
Memory for the array.
Definition: read0types.h:139
trx_ids_t::value_type value_type
Definition: read0types.h:51
void push_back(value_type value)
Append a value to the array.
Definition: read0read.cc:269
ids_t & operator=(const ids_t &)
value_type front() const
Definition: read0types.h:97
~ids_t()
Destructor.
Definition: read0types.h:59
ulint size() const
Definition: read0types.h:126
ids_t()
Constructor.
Definition: read0types.h:55
void insert(value_type value)
Insert the value in the correct slot, preserving the order.
Definition: read0read.cc:282
void reserve(ulint n)
Try and increase the size of the array.
Definition: read0read.cc:216
bool empty() const
Definition: read0types.h:130
value_type back() const
Definition: read0types.h:105
void clear()
Reset the size to 0.
Definition: read0types.h:77
trx_id_t * data()
Definition: read0types.h:118
ulint m_reserved
Size of m_ptr in elements.
Definition: read0types.h:145
void resize(ulint n)
Resize the array, sets the current element count.
Definition: read0types.h:69
void assign(const value_type *start, const value_type *end)
Copy and overwrite the current array contents.
Definition: read0read.cc:247
ids_t(const ids_t &)
ulint capacity() const
Definition: read0types.h:81
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
void print_limits(FILE *file) const
Write the limits to the file.
Definition: read0types.h:203
~ReadView()
ReadView destructor.
Definition: read0read.cc:326
void copy_prepare(const ReadView &other)
Copy state from another view.
Definition: read0read.cc:623
ReadView()
ReadView constructor.
Definition: read0read.cc:314
trx_id_t m_view_low_limit_no
The low limit number up to which read views don't need to access undo log records for MVCC.
Definition: read0types.h:308
bool le(const ReadView *rhs) const
Definition: read0types.h:241
node_t m_view_list
Definition: read0types.h:318
byte pad1[64 - sizeof(node_t)]
List of read views in trx_sys.
Definition: read0types.h:317
void copy_complete()
Complete the copy, insert the creator transaction id into the m_trx_ids too and adjust the m_up_limit...
Definition: read0read.cc:649
void creator_trx_id(trx_id_t id)
Set the creator transaction id, existing id must be 0.
Definition: read0types.h:268
trx_id_t low_limit_no() const
Definition: read0types.h:223
bool changes_visible(trx_id_t id, const table_name_t &name) const
Check whether the changes by id are visible.
Definition: read0types.h:162
trx_id_t m_low_limit_id
The read should not see any transaction with trx id >= this value.
Definition: read0types.h:283
bool is_closed() const
Definition: read0types.h:198
void reduce_low_limit(trx_id_t trx_no)
Check and reduce low limit number for read view.
Definition: read0types.h:213
typedef UT_LIST_NODE_T(ReadView) node_t
bool sees(trx_id_t id) const
Definition: read0types.h:187
trx_id_t m_up_limit_id
The read should see all trx ids which are strictly smaller (<) than this value.
Definition: read0types.h:288
void close()
Mark the view as closed.
Definition: read0types.h:191
ids_t m_ids
Set of RW transactions that was active when this snapshot was taken.
Definition: read0types.h:296
trx_id_t m_creator_trx_id
trx id of creating transaction, set to TRX_ID_MAX for free views.
Definition: read0types.h:292
bool m_closed
AC-NL-RO transaction view that has been "closed".
Definition: read0types.h:312
trx_id_t view_low_limit_no() const
Definition: read0types.h:236
void copy_trx_ids(const trx_ids_t &trx_ids)
Copy the transaction ids from the source vector.
Definition: read0read.cc:353
void prepare(trx_id_t id)
Opens a read view where exactly the transactions serialized before this point in time are seen in the...
Definition: read0read.cc:446
ReadView & operator=(const ReadView &)
bool empty() const
Definition: read0types.h:231
trx_id_t m_low_limit_no
The view does not need to see the undo logs for transactions whose transaction number is strictly sma...
Definition: read0types.h:301
ReadView(const ReadView &)
static void check_trx_id_sanity(trx_id_t id, const table_name_t &name)
Check whether transaction id is valid.
Definition: trx0sys.cc:62
trx_id_t low_limit_id() const
Definition: read0types.h:227
const char * p
Definition: ctype-mb.cc:1236
Data dictionary memory object creation.
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:176
uint16_t value_type
Definition: vt100.h:183
const std::string FILE("FILE")
Definition: os0file.h:85
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
void delete_arr(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new_arr*() variants.
Definition: ut0new.h:1107
case opt name
Definition: sslopt-case.h:32
Table name wrapper for pretty-printing.
Definition: dict0mem.h:455
Transaction system global type definitions.
constexpr trx_id_t TRX_ID_MAX
Maximum transaction identifier.
Definition: trx0types.h:144
#define TRX_ID_FMT
printf(3) format used for printing DB_TRX_ID and other system fields
Definition: trx0types.h:48
std::vector< trx_id_t, ut::allocator< trx_id_t > > trx_ids_t
Definition: trx0types.h:595
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
unsigned long int ulint
Definition: univ.i:407
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:70
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:506
int n
Definition: xcom_base.cc:505