37#ifndef LOCK_MODULE_IMPLEMENTATION
41#error Do not include lock0priv.h outside of the lock/ module
70 out <<
"[lock_table_t: name=" <<
table->
name <<
"]";
80 return (
lock.print(out));
96 std::ostream &
print(std::ostream &out)
const;
103 return out <<
"[lock_rec_t: page_id=" << page_id <<
", n_bits=" << n_bits
108 return (
lock.print(out));
120 static_assert(
LOCK_ORDINARY == 0,
"LOCK_ORDINARY must be 0 (no flags)");
159#ifdef HAVE_PSI_THREAD_INTERFACE
160#ifdef HAVE_PSI_DATA_LOCK_INTERFACE
173#if defined(UNIV_DEBUG)
181 ut_ad(!is_insert_intention());
182 ut_ad(is_next_key_lock());
239 std::ostream &
print(std::ostream &out)
const;
243 std::string type_mode_string()
const;
251 return (
"LOCK_TABLE");
258 ut_ad(is_record_lock());
261 static_assert(8 <=
alignof(
lock_t),
262 "lock_t and thus the bitmap after lock_t should be aligned "
263 "for efficient 64-bit access");
264 const byte *bitmap = (
const byte *)&
this[1];
267 ut_ad(
reinterpret_cast<uintptr_t
>(bitmap) % 8 == 0);
268 ut_ad(rec_lock.n_bits % 8 == 0);
269 return {bitmap, rec_lock.n_bits / 8};
278 auto immutable =
const_cast<const ib_lock_t *
>(
this)->bitset();
279 return {
const_cast<byte *
>(immutable.data()), immutable.size_bytes()};
286 return lock.tab_lock.locks;
296 sout << type_string();
299 if (is_record_not_gap()) {
300 sout <<
" | LOCK_REC_NOT_GAP";
304 sout <<
" | LOCK_WAIT";
308 sout <<
" | LOCK_GAP";
311 if (is_insert_intention()) {
312 sout <<
" | LOCK_INSERT_INTENTION";
318 out <<
"[lock_t: type_mode=" << type_mode <<
"(" << type_mode_string() <<
")";
320 if (is_record_lock()) {
331 return (
lock.print(out));
595 {
true,
true,
true,
false,
true},
596 {
true,
true,
false,
false,
true},
597 {
true,
false,
true,
false,
false},
598 {
false,
false,
false,
false,
false},
599 {
true,
true,
false,
false,
false}};
612 {
true,
false,
false,
false,
false},
613 {
true,
true,
false,
false,
false},
614 {
true,
false,
true,
false,
false},
615 {
true,
true,
true,
true,
true},
616 {
false,
false,
false,
false,
true}};
639 :
RecID(
lock->rec_lock.page_id, heap_no) {
647 : m_page_id(page_id),
659 :
RecID(block->get_page_id(), heap_no) {}
671 inline bool matches(
const lock_t *
lock)
const;
704 ut_ad(is_predicate_lock(m_mode));
722 m_rec_id(block, heap_no) {
733 : m_thr(), m_trx(), m_mode(
mode), m_index(index), m_rec_id(rec_id) {
734 ut_ad(is_predicate_lock(m_mode));
750 m_rec_id(block, heap_no) {
818 m_size = is_predicate_lock(m_mode) ? lock_size(m_mode) : lock_size(
page);
853 n_bytes = (1 +
sizeof(
lock_prdt_t) + align) & ~align;
1005 const trx_t *victim_trx);
1031template <
typename F>
1034 const trx_t *trx = peeked_lock->
trx;
1044 DEBUG_SYNC_C(
"try_relatch_trx_and_shard_and_do_noted_expected_version");
1047 return std::forward<F>(f)();
1056 return std::forward<F>(f)();
1072template <
typename F>
1109 return peeked_wait_lock->is_record_lock();
1111 std::forward<F>(f)();
1125template <
typename F>
1128 while (
lock !=
nullptr) {
1132 if (std::forward<F>(f)(
lock)) {
1140template <
typename F>
1145 return (lock->rec_lock.page_id == page_id) &&
1146 std::forward<F>(f)(lock);
1150template <
typename F>
1152 return find_on_page(block->
get_page_id(), std::forward<F>(f));
1155template <
typename F>
1159 return rec_id.matches(lock) && std::forward<F>(f)(lock);
1163template <
typename F>
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
void btr_assert_not_corrupted(const buf_block_t *block, const dict_index_t *index)
Assert that a B-tree page is not corrupted.
Definition: btr0btr.h:152
A simple bitset wrapper class, which lets you access an existing range of bytes (not owned by it!...
Definition: ut0bitset.h:54
Create record locks.
Definition: lock0priv.h:690
ulint m_mode
Lock mode requested.
Definition: lock0priv.h:895
RecLock(dict_index_t *index, const buf_block_t *block, ulint heap_no, ulint mode)
Definition: lock0priv.h:744
RecID m_rec_id
The record lock tuple {space, page_no, heap_no}.
Definition: lock0priv.h:907
RecLock(que_thr_t *thr, dict_index_t *index, const RecID &rec_id, ulint mode)
Definition: lock0priv.h:698
static bool is_predicate_lock(ulint mode)
Definition: lock0priv.h:881
size_t lock_size() const
Definition: lock0priv.h:793
static size_t lock_size(const page_t *page)
Calculate the record lock physical size required, non-predicate lock.
Definition: lock0priv.h:870
RecLock(que_thr_t *thr, dict_index_t *index, const buf_block_t *block, ulint heap_no, ulint mode)
Definition: lock0priv.h:716
static size_t lock_size(ulint mode)
Calculate the record lock physical size required for a predicate lock.
Definition: lock0priv.h:835
size_t m_size
Size of the record lock in bytes.
Definition: lock0priv.h:899
trx_t * m_trx
Transaction requesting the record lock.
Definition: lock0priv.h:891
void init(const page_t *page)
Setup the context from the requirements.
Definition: lock0priv.h:812
que_thr_t * m_thr
The query thread of the transaction.
Definition: lock0priv.h:887
dict_index_t * m_index
Index on which the record lock is required.
Definition: lock0priv.h:903
RecLock(dict_index_t *index, const RecID &rec_id, ulint mode)
Definition: lock0priv.h:732
A RAII helper which latches global_latch in shared mode during constructor, and unlatches it during d...
Definition: lock0guards.h:71
void x_lock(ut::Location location)
Definition: lock0latches.h:141
void x_unlock()
Definition: lock0latches.h:142
Unique_sharded_rw_lock global_latch
Definition: lock0latches.h:264
A RAII helper which latches the mutex protecting given shard during constructor, and unlatches it dur...
Definition: lock0guards.h:91
Definition: lock0priv.h:1010
static void exclusive_latch(ut::Location location)
Definition: lock0priv.h:1013
static void exclusive_unlatch()
Definition: lock0priv.h:1012
Page identifier.
Definition: buf0types.h:207
int page
Definition: ctype-mb.cc:1236
dberr_t
Definition: db0err.h:39
static bool dict_index_is_online_ddl(const dict_index_t *index)
Determines if a secondary index is being or has been created online, or if the table is being rebuilt...
Data dictionary global types.
#define DEBUG_SYNC_C(_sync_point_name_)
Definition: my_sys.h:209
The simple hash table utility.
static void *& hash_get_first(hash_table_t *table, size_t cell_id)
Gets the first struct in a hash chain, NULL if none.
Definition: hash0hash.h:159
static uint64_t hash_calc_cell_id(uint64_t hash_value, hash_table_t const *table)
Calculates the cell index from a hashed value for a specified hash table.
#define UINT32_MAX
Definition: lexyy.cc:86
constexpr uint32_t LOCK_PRDT_PAGE
Page lock.
Definition: lock0lock.h:987
constexpr uint32_t LOCK_MODE_MASK
Lock modes and types.
Definition: lock0lock.h:949
constexpr uint32_t LOCK_PREDICATE
Predicate lock.
Definition: lock0lock.h:985
constexpr uint32_t LOCK_WAIT
Waiting lock flag; when set, it means that the lock has not yet been granted, it is just waiting for ...
Definition: lock0lock.h:962
static uint64_t lock_rec_hash_value(const page_id_t &page_id)
Calculates the hash value of a page file address: used in inserting or searching for a lock in the ha...
constexpr uint32_t LOCK_ORDINARY
this flag denotes an ordinary next-key lock in contrast to LOCK_GAP or LOCK_REC_NOT_GAP
Definition: lock0lock.h:966
constexpr uint32_t LOCK_TYPE_MASK
mask used to extract lock type from the type_mode field in a lock
Definition: lock0lock.h:956
constexpr uint32_t LOCK_INSERT_INTENTION
this bit is set when we place a waiting gap type record lock request in order to let an insert of an ...
Definition: lock0lock.h:983
constexpr uint32_t LOCK_TABLE
Lock types.
Definition: lock0lock.h:952
lock_sys_t * lock_sys
The lock system.
Definition: lock0lock.cc:197
constexpr uint32_t LOCK_GAP
when this bit is set, it means that the lock holds only on the gap before the record; for instance,...
Definition: lock0lock.h:971
constexpr uint32_t LOCK_REC_NOT_GAP
this bit means that the lock is only on the index record and does NOT block inserts to the gap before...
Definition: lock0lock.h:977
constexpr uint32_t LOCK_REC
record lock
Definition: lock0lock.h:954
static Locks_hashtable & lock_hash_get(ulint mode)
Get the lock hash table.
Definition: lock0lock.ic:69
struct lock_prdt lock_prdt_t
static ulint lock_mode_compatible(enum lock_mode mode1, enum lock_mode mode2)
Calculates if lock mode 1 is compatible with lock mode 2.
static const byte lock_strength_matrix[5][5]
Definition: lock0priv.h:610
static bool lock_mode_is_next_key_lock(ulint mode)
Checks if the mode is LOCK_S or LOCK_X (possibly ORed with LOCK_WAIT or LOCK_REC) which means the loc...
Definition: lock0priv.h:119
constexpr uint32_t MAX_STACK_SIZE
Maximum depth of the DFS stack.
Definition: lock0priv.h:619
void lock_reset_wait_and_release_thread_if_suspended(lock_t *lock)
This function is a wrapper around several functions which need to be called in particular order to wa...
Definition: lock0wait.cc:421
static const ulint lock_types
The count of the types of locks.
Definition: lock0priv.h:912
static const byte lock_compatibility_matrix[5][5]
Definition: lock0priv.h:593
constexpr uint32_t PRDT_HEAPNO
Definition: lock0priv.h:621
static bool lock_mode_stronger_or_eq(enum lock_mode mode1, enum lock_mode mode2)
Calculates if lock mode 1 is stronger or equal to lock mode 2.
void lock_notify_about_deadlock(const ut::vector< const trx_t * > &trxs_on_cycle, const trx_t *victim_trx)
Handles writing the information about found deadlock to the log files and caches it for future lock_l...
Definition: lock0lock.cc:6310
static const ulint LOCK_PAGE_BITMAP_MARGIN
Definition: lock0priv.h:342
static enum lock_mode lock_get_mode(const lock_t *lock)
Gets the mode of a lock.
std::ostream & operator<<(std::ostream &out, const lock_table_t &lock)
The global output operator is overloaded to conveniently print the lock_table_t object into the given...
Definition: lock0priv.h:79
static ulint lock_get_wait(const lock_t *lock)
Gets the wait flag of a lock.
static trx_id_t lock_clust_rec_some_has_impl(const rec_t *rec, const dict_index_t *index, const ulint *offsets)
Checks if some transaction has an implicit x-lock on a record in a clustered index.
static bool lock_rec_get_nth_bit(const lock_t *lock, ulint i)
Gets the nth bit of a record lock.
void lock_cancel_waiting_and_release(trx_t *trx)
Cancels a waiting lock request and releases possible other transactions waiting behind it.
Definition: lock0lock.cc:5855
static uint32_t lock_get_type_low(const lock_t *lock)
Gets the type of a lock.
static bool lock_table_has(const trx_t *trx, const dict_table_t *table, enum lock_mode mode)
Checks if a transaction has the specified table lock, or stronger.
lock_rec_req_status
Record locking request status.
Definition: lock0priv.h:623
@ LOCK_REC_FAIL
Failed to acquire a lock.
Definition: lock0priv.h:625
@ LOCK_REC_SUCCESS
Succeeded in acquiring a lock (implicit or already acquired)
Definition: lock0priv.h:627
@ LOCK_REC_SUCCESS_CREATED
Explicitly created a new lock.
Definition: lock0priv.h:629
static void lock_rec_set_nth_bit(lock_t *lock, ulint i)
Sets the nth bit of a record lock to true.
static uint32_t lock_rec_get_n_bits(const lock_t *lock)
Gets the number of bits in a record lock bitmap.
Lock module internal inline methods.
const char * lock_mode_string(enum lock_mode mode)
Convert the given enum value into string.
Definition: lock0types.h:69
lock_mode
Definition: lock0types.h:54
@ LOCK_S
Definition: lock0types.h:57
@ LOCK_X
Definition: lock0types.h:58
#define lock_t
Definition: lock0types.h:39
unsigned long long int ulonglong
Definition: my_inttypes.h:56
static HashTable ht
Definition: mysql.cc:148
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
Definition: lock0guards.h:34
bool owns_page_shard(const page_id_t &page_id)
Tests if given page shard can be safely accessed by the current thread.
Definition: lock0lock.cc:171
auto latch_peeked_shard_and_do(const lock_t *peeked_lock, F &&f)
Temporarily releases trx->mutex, latches the lock-sys shard containing peeked_lock and latches trx->m...
Definition: lock0priv.h:1032
void run_if_waiting(const TrxVersion trx_version, F &&f)
Given a pointer to trx (which the caller guarantees will not be freed) and the expected value of trx-...
Definition: lock0priv.h:1073
bool owns_shared_global_latch()
Tests if lock_sys latch is owned in shared mode by the current thread.
Definition: lock0lock.cc:167
bool owns_lock_shard(const lock_t *lock)
Checks if shard which contains lock is latched (or that an exclusive latch on whole lock_sys is held)...
Definition: lock0lock.cc:179
bool owns_exclusive_global_latch()
Tests if lock_sys latch is exclusively owned by the current thread.
Definition: lock0lock.cc:163
static mysql_service_status_t create(const char *service_names[], reference_caching_channel *out_channel) noexcept
Definition: component.cc:36
Definition: gcs_xcom_synode.h:64
mode
Definition: file_handle.h:60
bool wait_for(TCondition cond, std::chrono::steady_clock::duration max_wait)
Delays execution for at most max_wait or returns earlier if cond becomes true.
Definition: ut0ut.ic:131
std::basic_ostringstream< char, std::char_traits< char >, ut::allocator< char > > ostringstream
Specialization of basic_ostringstream which uses ut::allocator.
Definition: ut0new.h:2871
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2875
static std::mutex lock
Definition: net_ns.cc:56
static uint16_t page_dir_get_n_heap(const page_t *page)
Gets the number of records in the heap.
constexpr ulint PAGE_HEAP_NO_INFIMUM
Page infimum.
Definition: page0types.h:131
constexpr ulint PAGE_HEAP_NO_SUPREMUM
Page supremum.
Definition: page0types.h:133
byte page_t
Type of the index page.
Definition: page0types.h:152
static trx_t * thr_get_trx(que_thr_t *thr)
Gets the trx of a query thread.
byte rec_t
Definition: rem0types.h:41
required string type
Definition: replication_group_member_actions.proto:34
Scope_guard< TLambda > create_scope_guard(const TLambda rollback_lambda)
Create a scope guard object.
Definition: scope_guard.h:113
bool srv_read_only_mode
Set if InnoDB must operate in read-only mode.
Definition: srv0srv.cc:198
A hashmap used by lock sys, to organize locks by page (block), so that it is easy to maintain a list ...
Definition: lock0lock.h:1018
lock_t * find_on_block(const buf_block_t *block, F &&f)
Definition: lock0priv.h:1151
lock_t * find(F &&f)
Definition: lock0priv.h:1164
lock_t * find_on_page(page_id_t page_id, F &&f)
Definition: lock0priv.h:1141
size_t get_n_cells()
Definition: lock0lock.h:1047
lock_t * find_on_record(const struct RecID &rec_id, F &&f)
Definition: lock0priv.h:1156
lock_t * find_in_cell(size_t cell_id, F &&f)
Definition: lock0priv.h:1126
Record lock ID.
Definition: lock0priv.h:634
bool is_supremum() const
Definition: lock0priv.h:666
uint64_t m_hash_value
Hash generated from record's location which will be used to get lock queue for this record.
Definition: lock0priv.h:685
uint64_t hash_value() const
Definition: lock0priv.h:663
const page_id_t & get_page_id() const
Definition: lock0priv.h:673
RecID(page_id_t page_id, uint32_t heap_no)
Constructor.
Definition: lock0priv.h:646
RecID(const buf_block_t *block, ulint heap_no)
Constructor.
Definition: lock0priv.h:658
uint32_t m_heap_no
Heap number within the page.
Definition: lock0priv.h:680
page_id_t m_page_id
Tablespace ID and page number within space
Definition: lock0priv.h:676
RecID(const lock_t *lock, ulint heap_no)
Constructor.
Definition: lock0priv.h:638
Definition: lock0priv.h:283
static const ut_list_node< lock_t > & get_node(const lock_t &lock)
Functor for accessing the embedded node within a table lock.
Definition: lock0priv.h:285
Definition: trx0types.h:635
uint64_t m_version
Definition: trx0types.h:639
trx_t * m_trx
Definition: trx0types.h:638
The buffer control block structure.
Definition: buf0buf.h:1690
const page_id_t & get_page_id() const
Get the page number and space id of the current buffer block.
Definition: buf0buf.h:1864
byte * frame
pointer to buffer frame which is of size UNIV_PAGE_SIZE, and aligned to an address divisible by UNIV_...
Definition: buf0buf.h:1706
Data structure for an index.
Definition: dict0mem.h:1046
Data structure for a database table.
Definition: dict0mem.h:1909
table_id_t id
Id of the table.
Definition: dict0mem.h:1964
table_name_t name
Table name.
Definition: dict0mem.h:1978
Definition: lock0prdt.h:40
Record lock for a page.
Definition: lock0priv.h:84
std::ostream & print(std::ostream &out) const
Print the record lock into the given output stream.
Definition: lock0priv.h:102
uint32_t n_bits
number of bits in the lock bitmap; Must be divisible by 8.
Definition: lock0priv.h:91
page_id_t page_id
The id of the page on which records referenced by this lock's bitmap are located.
Definition: lock0priv.h:87
locksys::Latches latches
The latches protecting queues of record and table locks.
Definition: lock0lock.h:1071
Locks_hashtable rec_hash
The hash table of the record (LOCK_REC) locks, except for predicate (LOCK_PREDICATE) and predicate pa...
Definition: lock0lock.h:1075
Lock struct; protected by lock_sys latches.
Definition: lock0priv.h:137
bool is_record_not_gap() const
Definition: lock0priv.h:204
Bitset< const byte > bitset() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: lock0priv.h:257
dict_index_t * index
Index for a record lock.
Definition: lock0priv.h:145
lock_table_t tab_lock
Table lock.
Definition: lock0priv.h:153
Bitset< byte > bitset()
Gets access to the LOCK_REC's bitmap, which indicates heap_no-s, which are the subject of this lock r...
Definition: lock0priv.h:277
Locks_hashtable & hash_table() const
Get lock hash table.
Definition: lock0priv.h:231
lock_mode mode() const
Definition: lock0priv.h:225
const char * type_string() const
Definition: lock0priv.h:246
lock_rec_t rec_lock
Record lock.
Definition: lock0priv.h:156
bool includes_supremum() const
Definition: lock0priv.h:217
bool is_gap() const
Definition: lock0priv.h:201
ulonglong m_psi_internal_thread_id
Performance schema thread that created the lock.
Definition: lock0priv.h:162
bool is_insert_intention() const
Definition: lock0priv.h:212
bool is_record_lock() const
Determine if the lock object is a record lock.
Definition: lock0priv.h:189
trx_que_t trx_que_state() const
Definition: lock0priv.h:234
std::ostream & print(std::ostream &out) const
Print the lock object into the given output stream.
Definition: lock0priv.h:317
bool is_waiting() const
Definition: lock0priv.h:198
lock_t * hash
Hash chain node for a record lock.
Definition: lock0priv.h:149
ulonglong m_psi_event_id
Performance schema event that created the lock.
Definition: lock0priv.h:165
uint32_t type_mode
The lock type and mode bit flags.
Definition: lock0priv.h:171
trx_t * trx
transaction owning the lock
Definition: lock0priv.h:139
uint64_t m_seq
Timestamp when it was created.
Definition: lock0priv.h:175
bool is_next_key_lock() const
Definition: lock0priv.h:207
bool is_predicate() const
Determine if it is predicate lock.
Definition: lock0priv.h:193
uint32_t type() const
Definition: lock0priv.h:222
UT_LIST_NODE_T(lock_t) trx_locks
list of the locks of the transaction
void unlock_gap_lock()
Unlock the GAP Lock part of this Next Key Lock.
Definition: lock0priv.h:179
A table lock.
Definition: lock0priv.h:54
std::ostream & print(std::ostream &out) const
Print the table lock into the given output stream.
Definition: lock0priv.h:69
dict_table_t * table
database table in dictionary cache
Definition: lock0priv.h:55
locks
list of locks on the same table
Definition: lock0priv.h:58
Definition: que0que.h:242
std::atomic< trx_t * > blocking_trx
If this transaction is waiting for a lock, then blocking_trx points to a transaction which holds a co...
Definition: trx0trx.h:439
std::atomic< lock_t * > wait_lock
The lock request of this transaction is waiting for.
Definition: trx0trx.h:460
trx_que_t que_state
valid when trx->state == TRX_STATE_ACTIVE: TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT, ...
Definition: trx0trx.h:407
Definition: trx0trx.h:675
std::atomic_uint64_t version
Version of this instance.
Definition: trx0trx.h:1074
trx_lock_t lock
Information about the transaction locks and state.
Definition: trx0trx.h:822
The two way list node.
Definition: ut0lst.h:50
#define trx_mutex_enter_first_of_two(t)
Acquire the trx->mutex (and indicate we might request one more).
Definition: trx0trx.h:1385
#define trx_mutex_exit(t)
Release the trx->mutex.
Definition: trx0trx.h:1388
#define trx_mutex_enter(t)
Acquire the trx->mutex (and promise not to request any more).
Definition: trx0trx.h:1382
bool trx_mutex_own(const trx_t *trx)
Test if trx->mutex is owned by the current thread.
Definition: trx0trx.h:1345
Transaction system global type definitions.
trx_que_t
Transaction execution states when trx->state == TRX_STATE_ACTIVE.
Definition: trx0types.h:71
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.
constexpr size_t UNIV_WORD_SIZE
MySQL config.h generated by CMake will define SIZEOF_LONG in Posix.
Definition: univ.i:278
unsigned long int ulint
Definition: univ.i:406
#define UT_ARR_SIZE(a)
Definition: univ.i:524
Utilities for bitset operations.
#define UT_LOCATION_HERE
Definition: ut0core.h:47
#define ut_error
Abort execution.
Definition: ut0dbg.h:65
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69
#define UT_LIST_NODE_GETTER_DEFINITION(t, m)
A helper for the UT_LIST_BASE_NODE_T_EXTERN which declares a node getter struct which extracts member...
Definition: ut0lst.h:270
#define UT_LIST_NODE_T(t)
Macro used for legacy reasons.
Definition: ut0lst.h:64
ulint ut_delay(ulint delay)
Runs an idle loop on CPU.
Definition: ut0ut.cc:99
static task_env * retry
Definition: xcom_base.cc:436
static void prepare(pax_msg *p, pax_op op)
Definition: xcom_base.cc:1587