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