MySQL 8.3.0
Source Code Documentation
read0read.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2023, 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/read0read.h
28 Cursor read
29
30 Created 2/16/1997 Heikki Tuuri
31 *******************************************************/
32
33#ifndef read0read_h
34#define read0read_h
35
36#include <stddef.h>
37#include <algorithm>
38
39#include "read0types.h"
40#include "univ.i"
41
42/** The MVCC read view manager */
43class MVCC {
44 public:
45 /** Constructor
46 @param size Number of views to pre-allocate */
47 explicit MVCC(ulint size);
48
49 /** Destructor.
50 Free all the views in the m_free list */
51 ~MVCC();
52
53 /** Allocate and create a view.
54 @param view View owned by this class created for the caller. Must be
55 freed by calling view_close()
56 @param trx Transaction instance of caller */
57 void view_open(ReadView *&view, trx_t *trx);
58
59 /**
60 Close a view created by the above function.
61 @param view view allocated by trx_open.
62 @param own_mutex true if caller owns trx_sys_t::mutex */
63 void view_close(ReadView *&view, bool own_mutex);
64
65 /** Clones the oldest view and stores it in view. No need to
66 call view_close(). The caller owns the view that is passed in.
67 It will also move the closed views from the m_views list to the
68 m_free list. This function is called by Purge to determine whether it should
69 purge the delete marked record or not.
70 @param view Preallocated view, owned by the caller */
71 void clone_oldest_view(ReadView *view);
72
73 /**
74 @return the number of active views */
75 ulint size() const;
76
77 /**
78 @return true if the view is active and valid */
79 static bool is_view_active(ReadView *view) {
80 ut_a(view != reinterpret_cast<ReadView *>(0x1));
81
82 return (view != nullptr && !(intptr_t(view) & 0x1));
83 }
84
85 /**
86 Set the view creator transaction id. Note: This should be set only
87 for views created by RW transactions.
88 @param view Set the creator trx id for this view
89 @param id Transaction id to set */
90 static void set_view_creator_trx_id(ReadView *view, trx_id_t id) {
91 ut_ad(id > 0);
92
93 view->creator_trx_id(id);
94 }
95
96 private:
97 /**
98 Validates a read view list. */
99 bool validate() const;
100
101 /**
102 Find a free view from the active list, if none found then allocate
103 a new view. This function will also attempt to move delete marked
104 views from the active list to the freed list.
105 @return a view to use */
106 inline ReadView *get_view();
107
108 /**
109 Get the oldest view in the system. It will also move the delete
110 marked read views from the views list to the freed list.
111 @return oldest view if found or NULL */
112 inline ReadView *get_oldest_view() const;
113
114 private:
115 // Prevent copying
116 MVCC(const MVCC &);
117 MVCC &operator=(const MVCC &);
118
119 private:
120 typedef UT_LIST_BASE_NODE_T(ReadView, m_view_list) view_list_t;
121
122 /** Free views ready for reuse. */
123 view_list_t m_free;
124
125 /** Active and closed views, the closed views will have the
126 creator trx id set to TRX_ID_MAX */
127 view_list_t m_views;
128};
129
130#endif /* read0read_h */
The MVCC read view manager.
Definition: read0read.h:43
static bool is_view_active(ReadView *view)
Definition: read0read.h:79
void view_open(ReadView *&view, trx_t *trx)
Allocate and create a view.
Definition: read0read.cc:500
~MVCC()
Destructor.
Definition: read0read.cc:340
ulint size() const
Definition: read0read.cc:652
view_list_t m_free
Free views ready for reuse.
Definition: read0read.h:123
ReadView * get_view()
Find a free view from the active list, if none found then allocate a new view.
Definition: read0read.cc:477
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:127
static void set_view_creator_trx_id(ReadView *view, trx_id_t id)
Set the view creator transaction id.
Definition: read0read.h:90
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:626
void view_close(ReadView *&view, bool own_mutex)
Close a view created by the above function.
Definition: read0read.cc:673
bool validate() const
Validates a read view list.
Definition: read0read.cc:202
ReadView * get_oldest_view() const
Get the oldest view in the system.
Definition: read0read.cc:557
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:47
void creator_trx_id(trx_id_t id)
Set the creator transaction id, existing id must be 0.
Definition: read0types.h:268
Cursor read.
Definition: trx0trx.h:683
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:405
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:104
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:92