MySQL 8.0.39
Source Code Documentation
read0read.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2024, 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 /**
67 Release a view that is inactive but not closed. Caller must own
68 the trx_sys_t::mutex.
69 @param view View to release */
70 void view_release(ReadView *&view);
71
72 /** Clones the oldest view and stores it in view. No need to
73 call view_close(). The caller owns the view that is passed in.
74 It will also move the closed views from the m_views list to the
75 m_free list. This function is called by Purge to determine whether it should
76 purge the delete marked record or not.
77 @param view Preallocated view, owned by the caller */
78 void clone_oldest_view(ReadView *view);
79
80 /**
81 @return the number of active views */
82 ulint size() const;
83
84 /**
85 @return true if the view is active and valid */
86 static bool is_view_active(ReadView *view) {
87 ut_a(view != reinterpret_cast<ReadView *>(0x1));
88
89 return (view != nullptr && !(intptr_t(view) & 0x1));
90 }
91
92 /**
93 Set the view creator transaction id. Note: This should be set only
94 for views created by RW transactions.
95 @param view Set the creator trx id for this view
96 @param id Transaction id to set */
97 static void set_view_creator_trx_id(ReadView *view, trx_id_t id) {
98 ut_ad(id > 0);
99
100 view->creator_trx_id(id);
101 }
102
103 private:
104 /**
105 Validates a read view list. */
106 bool validate() const;
107
108 /**
109 Find a free view from the active list, if none found then allocate
110 a new view. This function will also attempt to move delete marked
111 views from the active list to the freed list.
112 @return a view to use */
113 inline ReadView *get_view();
114
115 /**
116 Get the oldest view in the system. It will also move the delete
117 marked read views from the views list to the freed list.
118 @return oldest view if found or NULL */
119 inline ReadView *get_oldest_view() const;
121
122 private:
123 // Prevent copying
124 MVCC(const MVCC &);
125 MVCC &operator=(const MVCC &);
126
127 private:
128 typedef UT_LIST_BASE_NODE_T(ReadView, m_view_list) view_list_t;
129
130 /** Free views ready for reuse. */
131 view_list_t m_free;
132
133 /** Active and closed views, the closed views will have the
134 creator trx id set to TRX_ID_MAX */
135 view_list_t m_views;
136};
137
138#endif /* read0read_h */
The MVCC read view manager.
Definition: read0read.h:44
static bool is_view_active(ReadView *view)
Definition: read0read.h:86
void view_open(ReadView *&view, trx_t *trx)
Allocate and create a view.
Definition: read0read.cc:529
~MVCC()
Destructor.
Definition: read0read.cc:341
ulint size() const
Definition: read0read.cc:700
view_list_t m_free
Free views ready for reuse.
Definition: read0read.h:131
ReadView * get_view()
Find a free view from the active list, if none found then allocate a new view.
Definition: read0read.cc:478
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:135
ReadView * get_view_created_by_trx_id(trx_id_t trx_id) const
Definition: read0read.cc:582
static void set_view_creator_trx_id(ReadView *view, trx_id_t id)
Set the view creator transaction id.
Definition: read0read.h:97
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 and stores it in view.
Definition: read0read.cc:674
void view_close(ReadView *&view, bool own_mutex)
Close a view created by the above function.
Definition: read0read.cc:721
void view_release(ReadView *&view)
Release a view that is inactive but not closed.
Definition: read0read.cc:501
bool validate() const
Validates a read view list.
Definition: read0read.cc:203
ReadView * get_oldest_view() const
Get the oldest view in the system.
Definition: read0read.cc:605
MVCC(ulint size)
Constructor.
Definition: read0read.cc:333
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:269
Cursor read.
Definition: trx0trx.h:684
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:69
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:57