MySQL 9.5.0
Source Code Documentation
read0read.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2025, 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 designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/read0read.h
29 Cursor read
30
31 Created 2/16/1997 Heikki Tuuri
32 *******************************************************/
33
34#ifndef read0read_h
35#define read0read_h
36
37#include <stddef.h>
38#include <algorithm>
39
40#include "read0types.h"
41#include "univ.i"
42
43/** The MVCC read view manager */
44class MVCC {
45 public:
46 /** Constructor
47 @param size Number of views to pre-allocate */
48 explicit MVCC(ulint size);
49
50 /** Destructor.
51 Free all the views in the m_free list */
52 ~MVCC();
53
54 /** Allocate and create a view.
55 @param view View owned by this class created for the caller. Must be
56 freed by calling view_close()
57 @param trx Transaction instance of caller */
58 void view_open(ReadView *&view, trx_t *trx);
59
60 /**
61 Close a view created by the above function.
62 @param view view allocated by trx_open.
63 @param own_mutex true if caller owns trx_sys_t::mutex */
64 void view_close(ReadView *&view, bool own_mutex);
65
66 /** Clones the oldest view into the provided view, unless the function
67 determines that the provided view is already a good enough lower bound.
68 The caller owns the view that is passed in, which is interpreted to be a
69 previous lower bound known to the caller.
70 No need to call view_close(view,..).
71
72 Note: This function is called by Purge to determine the purge_sys->view used
73 to distinguish which transactions are considered committed by everybody, and
74 thus their undo logs can be purged.
75 Purge mainly uses purge_sys->view->low_limit_no(), which is a safe
76 lower-bound on what can be purged based on NO, and further limits it to the
77 lowest needed NO reported by GTID Persistor. But other places like ROLLBACK
78 use purge_sys->view->changes_visible(ID,..).
79 @param[in,out] view Preallocated view, owned by the caller. Can be either
80 default constructed (m_low_limit_no is 0) or a fully
81 initialized ReadView object. */
82 void clone_oldest_view(ReadView *view);
83
84 /**
85 @return the number of active views */
86 ulint size() const;
87
88 /**
89 @return true if the view is active and valid */
90 static bool is_view_active(ReadView *view) {
91 ut_a(view != reinterpret_cast<ReadView *>(0x1));
92
93 return (view != nullptr && !(intptr_t(view) & 0x1));
94 }
95
96 /**
97 Set the view creator transaction id. Note: This should be set only
98 for views created by RW transactions.
99 @param view Set the creator trx id for this view
100 @param id Transaction id to set */
102 ut_ad(id > 0);
103
104 view->creator_trx_id(id);
105 }
106
107 private:
108 /**
109 Validates a read view list. */
110 bool validate() const;
111
112 /**
113 Find a free view from the active list, if none found then allocate
114 a new view. This function will also attempt to move delete marked
115 views from the active list to the freed list.
116 @return a view to use */
117 inline ReadView *get_view();
118
119 private:
120 // Prevent copying
121 MVCC(const MVCC &);
122 MVCC &operator=(const MVCC &);
123
124 private:
125 typedef UT_LIST_BASE_NODE_T(ReadView, m_view_list) view_list_t;
126
127 /** Free views ready for reuse. */
128 view_list_t m_free;
129
130 /** Active and closed views, the closed views will have the
131 creator trx id set to TRX_ID_MAX */
132 view_list_t m_views;
133};
134
135#endif /* read0read_h */
The MVCC read view manager.
Definition: read0read.h:44
static bool is_view_active(ReadView *view)
Definition: read0read.h:90
void view_open(ReadView *&view, trx_t *trx)
Allocate and create a view.
Definition: read0read.cc:499
~MVCC()
Destructor.
Definition: read0read.cc:340
ulint size() const
Definition: read0read.cc:725
view_list_t m_free
Free views ready for reuse.
Definition: read0read.h:128
ReadView * get_view()
Find a free view from the active list, if none found then allocate a new view.
Definition: read0read.cc:476
view_list_t m_views
Active and closed views, the closed views will have the creator trx id set to TRX_ID_MAX.
Definition: read0read.h:132
static void set_view_creator_trx_id(ReadView *view, trx_id_t id)
Set the view creator transaction id.
Definition: read0read.h:101
MVCC & operator=(const MVCC &)
MVCC(const MVCC &)
typedef UT_LIST_BASE_NODE_T(ReadView, m_view_list) view_list_t
void clone_oldest_view(ReadView *view)
Clones the oldest view into the provided view, unless the function determines that the provided view ...
Definition: read0read.cc:685
void view_close(ReadView *&view, bool own_mutex)
Close a view created by the above function.
Definition: read0read.cc:746
bool validate() const
Validates a read view list.
Definition: read0read.cc:203
MVCC(ulint size)
Constructor.
Definition: read0read.cc:332
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:48
void creator_trx_id(trx_id_t id)
Set the creator transaction id, existing id must be 0.
Definition: read0types.h:254
Cursor read.
Definition: trx0trx.h:675
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:93