MySQL 8.0.40
Source Code Documentation
lock0types.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 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/lock0types.h
29 The transaction lock system global types
30
31 Created 5/7/1996 Heikki Tuuri
32 *******************************************************/
33
34#include "univ.i"
35
36#ifndef lock0types_h
37#define lock0types_h
38
39#define lock_t ib_lock_t
40
41#include "trx0types.h"
42
43struct lock_t;
44struct lock_sys_t;
45struct lock_table_t;
46
48 SELECT_ORDINARY, /* default behaviour */
49 SELECT_SKIP_LOCKED, /* skip the row if row is locked */
50 SELECT_NOWAIT /* return immediately if row is locked */
51};
52
53/* Basic lock modes */
55 LOCK_IS = 0, /* intention shared */
56 LOCK_IX, /* intention exclusive */
57 LOCK_S, /* shared */
58 LOCK_X, /* exclusive */
59 LOCK_AUTO_INC, /* locks the auto-inc counter of a table
60 in an exclusive mode */
61 LOCK_NONE, /* this is used elsewhere to note consistent read */
62 LOCK_NUM = LOCK_NONE, /* number of lock modes */
63 LOCK_NONE_UNSET = 255
64};
65
66/** Convert the given enum value into string.
67@param[in] mode the lock mode
68@return human readable string of the given enum value */
69inline const char *lock_mode_string(enum lock_mode mode) {
70 switch (mode) {
71 case LOCK_IS:
72 return ("LOCK_IS");
73 case LOCK_IX:
74 return ("LOCK_IX");
75 case LOCK_S:
76 return ("LOCK_S");
77 case LOCK_X:
78 return ("LOCK_X");
79 case LOCK_AUTO_INC:
80 return ("LOCK_AUTO_INC");
81 case LOCK_NONE:
82 return ("LOCK_NONE");
83 case LOCK_NONE_UNSET:
84 return ("LOCK_NONE_UNSET");
85 default:
87 }
88}
89typedef UT_LIST_BASE_NODE_T_EXTERN(lock_t, trx_locks) trx_lock_list_t;
90
91typedef uint32_t trx_schedule_weight_t;
92
93/** Used to represent locks requests uniquely over time.
94Please note that in case of LOCK_REC there might be actually multiple
95"sub-requests" for many different heap_no associated with the same lock_t object
96which we ignore here and use same guid for all of them.
97Also, the lock mode and status and other properties of the lock can change over
98time and/or represent more than one actual request. This is also ignored here.
99What we try to achieve is some way to identify lock_t struct such that:
100(1) we can serialize and deserialize it
101(2) we don't have to be afraid of dangling pointers
102(3) if the same lock_t gets deallocated and then allocated again, or otherwise
103reused by a different transaction, we will have a different guid for it. Note,
104that a single transaction never dealloactes a lock_t and allocates it again, as
105all deallocations happen during commit (lock_trx_release_locks). */
107 /** The guid of lock->trx. Used to identify ABA problems when the same lock_t
108 struct gets reused by a new transaction. */
110
111 /** Id of the lock_t struct such that it does not change over time, and two
112 different lock_t structs never have the same id. However it may happen that
113 two "different" locks at different points in time actually reuse the same
114 lock_t struct and thus have the same immutable id - this is why we also store
115 the transaction's guid */
116 uint64_t m_immutable_id{};
117
118 /** Initializes the lock_guid_t object to a value which doesn't match any real
119 lock. */
120 lock_guid_t() = default;
121
122 /** Initializes lock_guid_t with data uniquely identifying the lock request(s)
123 represented by lock_t object.
124 @param[in] lock the object representing the lock request(s) */
125 lock_guid_t(const lock_t &lock);
126
127 /** Checks if two guids represent the same lock (conceptually):
128 they represent the same lock_t struct in memory and it was not reused.
129 @param[in] rhs another guid to compare against
130 @return true iff the two guids are equal and thus represent same lock*/
131 bool operator==(const lock_guid_t &rhs) const {
132 return m_trx_guid == rhs.m_trx_guid && m_immutable_id == rhs.m_immutable_id;
133 }
134
135 /** Checks if two guids represent two different locks (conceptually):
136 they represent two different lock_t structs in memory or struct was reused.
137 @param[in] rhs another guid to compare against
138 @return true iff the two guids are different and thus represent different
139 locks */
140 bool operator!=(const lock_guid_t &rhs) const { return !(*this == rhs); }
141
142 /** Checks if the instance is non-empty, i.e. was not default-constructed,
143 but rather initialized to correspond to a real lock_t.
144 @return true iff this guid was initialized to match a real lock*/
145 operator bool() const { return m_immutable_id != 0; }
146};
147#endif /* lock0types_h */
uint32_t trx_schedule_weight_t
Definition: lock0types.h:91
const char * lock_mode_string(enum lock_mode mode)
Convert the given enum value into string.
Definition: lock0types.h:69
typedef UT_LIST_BASE_NODE_T_EXTERN(lock_t, trx_locks) trx_lock_list_t
select_mode
Definition: lock0types.h:47
@ SELECT_SKIP_LOCKED
Definition: lock0types.h:49
@ SELECT_NOWAIT
Definition: lock0types.h:50
@ SELECT_ORDINARY
Definition: lock0types.h:48
lock_mode
Definition: lock0types.h:54
@ LOCK_NONE
Definition: lock0types.h:61
@ LOCK_IX
Definition: lock0types.h:56
@ LOCK_AUTO_INC
Definition: lock0types.h:59
@ LOCK_IS
Definition: lock0types.h:55
@ LOCK_S
Definition: lock0types.h:57
@ LOCK_NONE_UNSET
Definition: lock0types.h:63
@ LOCK_X
Definition: lock0types.h:58
@ LOCK_NUM
Definition: lock0types.h:62
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
mode
Definition: file_handle.h:60
Used to represent locks requests uniquely over time.
Definition: lock0types.h:106
bool operator==(const lock_guid_t &rhs) const
Checks if two guids represent the same lock (conceptually): they represent the same lock_t struct in ...
Definition: lock0types.h:131
uint64_t m_immutable_id
Id of the lock_t struct such that it does not change over time, and two different lock_t structs neve...
Definition: lock0types.h:116
lock_guid_t()=default
Initializes the lock_guid_t object to a value which doesn't match any real lock.
trx_guid_t m_trx_guid
The guid of lock->trx.
Definition: lock0types.h:109
bool operator!=(const lock_guid_t &rhs) const
Checks if two guids represent two different locks (conceptually): they represent two different lock_t...
Definition: lock0types.h:140
The lock system struct.
Definition: lock0lock.h:1069
Lock struct; protected by lock_sys latches.
Definition: lock0priv.h:137
A table lock.
Definition: lock0priv.h:54
Used to identify trx uniquely over time.
Definition: trx0types.h:177
Transaction system global type definitions.
Version control for database, common definitions, and include files.
#define ut_error
Abort execution.
Definition: ut0dbg.h:65