MySQL  8.0.19
Source Code Documentation
read0read.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2018, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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 */
43 class 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  /**
54  Allocate and create a view.
55  @param view view owned by this class created for the
56  caller. Must be freed by calling close()
57  @param trx transaction creating the view */
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 create it view.
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 != NULL && !(intptr_t(view) & 0x1));
89  }
90 
91  /**
92  Set the view creator transaction id. Note: This shouldbe set only
93  for views created by RW transactions. */
94  static void set_view_creator_trx_id(ReadView *view, trx_id_t id);
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;
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) 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 */
MVCC::m_free
view_list_t m_free
Free views ready for reuse.
Definition: read0read.h:124
read0types.h
NULL
#define NULL
Definition: types.h:55
trx_id_t
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
ut_a
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:53
MVCC::is_view_active
static bool is_view_active(ReadView *view)
Definition: read0read.h:85
MVCC::get_view_created_by_trx_id
ReadView * get_view_created_by_trx_id(trx_id_t trx_id) const
Definition: read0read.cc:567
MVCC::set_view_creator_trx_id
static void set_view_creator_trx_id(ReadView *view, trx_id_t id)
Set the view creator transaction id.
Definition: read0read.cc:742
MVCC::UT_LIST_BASE_NODE_T
typedef UT_LIST_BASE_NODE_T(ReadView) view_list_t
MVCC
The MVCC read view manager.
Definition: read0read.h:43
MVCC::MVCC
MVCC(ulint size)
Constructor.
Definition: read0read.cc:333
MVCC::size
ulint size() const
Definition: read0read.cc:685
MVCC::validate
bool validate() const
Validates a read view list.
Definition: read0read.cc:202
ReadView
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
MVCC::get_view
ReadView * get_view()
Find a free view from the active list, if none found then allocate a new view.
Definition: read0read.cc:462
MVCC::m_views
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
MVCC::view_close
void view_close(ReadView *&view, bool own_mutex)
Close a view created by the above function.
Definition: read0read.cc:707
MVCC::clone_oldest_view
void clone_oldest_view(ReadView *view)
Clones the oldest view and stores it in view.
Definition: read0read.cc:659
MVCC::view_open
void view_open(ReadView *&view, trx_t *trx)
Allocate and create a view.
Definition: read0read.cc:514
MVCC::get_oldest_view
ReadView * get_oldest_view() const
Get the oldest view in the system.
Definition: read0read.cc:590
MVCC::operator=
MVCC & operator=(const MVCC &)
trx_t
Definition: trx0trx.h:780
MVCC::~MVCC
~MVCC()
Destructor.
Definition: read0read.cc:344
MVCC::view_release
void view_release(ReadView *&view)
Release a view that is inactive but not closed.
Definition: read0read.cc:485