MySQL 9.1.0
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 /** Clones the oldest view and stores it in view. No need to
67 call view_close(). The caller owns the view that is passed in.
68 It will also move the closed views from the m_views list to the
69 m_free list. This function is called by Purge to determine whether it should
70 purge the delete marked record or not.
71 @param view Preallocated view, owned by the caller */
72 void clone_oldest_view(ReadView *view);
73
74 /**
75 @return the number of active views */
76 ulint size() const;
77
78 /**
79 @return true if the view is active and valid */
80 static bool is_view_active(ReadView *view) {
81 ut_a(view != reinterpret_cast<ReadView *>(0x1));
82
83 return (view != nullptr && !(intptr_t(view) & 0x1));
84 }
85
86 /**
87 Set the view creator transaction id. Note: This should be set only
88 for views created by RW transactions.
89 @param view Set the creator trx id for this view
90 @param id Transaction id to set */
91 static void set_view_creator_trx_id(ReadView *view, trx_id_t id) {
92 ut_ad(id > 0);
93
94 view->creator_trx_id(id);
95 }
96
97 private:
98 /**
99 Validates a read view list. */
100 bool validate() const;
101
102 /**
103 Find a free view from the active list, if none found then allocate
104 a new view. This function will also attempt to move delete marked
105 views from the active list to the freed list.
106 @return a view to use */
107 inline ReadView *get_view();
108
109 /**
110 Get the oldest view in the system. It will also move the delete
111 marked read views from the views list to the freed list.
112 @return oldest view if found or NULL */
113 inline ReadView *get_oldest_view() const;
114
115 private:
116 // Prevent copying
117 MVCC(const MVCC &);
118 MVCC &operator=(const MVCC &);
119
120 private:
121 typedef UT_LIST_BASE_NODE_T(ReadView, m_view_list) view_list_t;
122
123 /** Free views ready for reuse. */
124 view_list_t m_free;
125
126 /** Active and closed views, the closed views will have the
127 creator trx id set to TRX_ID_MAX */
128 view_list_t m_views;
129};
130
131#endif /* read0read_h */
The MVCC read view manager.
Definition: read0read.h:44
static bool is_view_active(ReadView *view)
Definition: read0read.h:80
void view_open(ReadView *&view, trx_t *trx)
Allocate and create a view.
Definition: read0read.cc:501
~MVCC()
Destructor.
Definition: read0read.cc:341
ulint size() const
Definition: read0read.cc:653
view_list_t m_free
Free views ready for reuse.
Definition: read0read.h:124
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:128
static void set_view_creator_trx_id(ReadView *view, trx_id_t id)
Set the view creator transaction id.
Definition: read0read.h:91
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:627
void view_close(ReadView *&view, bool own_mutex)
Close a view created by the above function.
Definition: read0read.cc:674
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:558
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: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