37#ifndef LOCK_MODULE_IMPLEMENTATION
41#error Do not include lock0priv.h outside of the lock/ module
69 out <<
"[lock_table_t: name=" <<
table->
name <<
"]";
79 return (
lock.print(out));
95 std::ostream &
print(std::ostream &out)
const;
102 return out <<
"[lock_rec_t: page_id=" << page_id <<
", n_bits=" << n_bits
107 return (
lock.print(out));
119 static_assert(
LOCK_ORDINARY == 0,
"LOCK_ORDINARY must be 0 (no flags)");
158#ifdef HAVE_PSI_THREAD_INTERFACE
159#ifdef HAVE_PSI_DATA_LOCK_INTERFACE
172#if defined(UNIV_DEBUG)
180 ut_ad(!is_insert_intention());
181 ut_ad(is_next_key_lock());
238 std::ostream &
print(std::ostream &out)
const;
242 std::string type_mode_string()
const;
250 return (
"LOCK_TABLE");
263 sout << type_string();
266 if (is_record_not_gap()) {
267 sout <<
" | LOCK_REC_NOT_GAP";
271 sout <<
" | LOCK_WAIT";
275 sout <<
" | LOCK_GAP";
278 if (is_insert_intention()) {
279 sout <<
" | LOCK_INSERT_INTENTION";
285 out <<
"[lock_t: type_mode=" << type_mode <<
"(" << type_mode_string() <<
")";
287 if (is_record_lock()) {
298 return (
lock.print(out));
562 {
true,
true,
true,
false,
true},
563 {
true,
true,
false,
false,
true},
564 {
true,
false,
true,
false,
false},
565 {
false,
false,
false,
false,
false},
566 {
true,
true,
false,
false,
false}};
579 {
true,
false,
false,
false,
false},
580 {
true,
true,
false,
false,
false},
581 {
true,
false,
true,
false,
false},
582 {
true,
true,
true,
true,
true},
583 {
false,
false,
false,
false,
true}};
606 :
RecID(
lock->rec_lock.page_id, heap_no) {
614 : m_page_id(page_id),
626 :
RecID(block->get_page_id(), heap_no) {}
638 inline bool matches(
const lock_t *
lock)
const;
671 ut_ad(is_predicate_lock(m_mode));
689 m_rec_id(block, heap_no) {
700 : m_thr(), m_trx(), m_mode(
mode), m_index(index), m_rec_id(rec_id) {
701 ut_ad(is_predicate_lock(m_mode));
717 m_rec_id(block, heap_no) {
785 m_size = is_predicate_lock(m_mode) ? lock_size(m_mode) : lock_size(
page);
820 n_bytes = (1 +
sizeof(
lock_prdt_t) + align) & ~align;
1026 const trx_t *victim_trx);
1076 template <
typename F>
1088 if (!std::forward<F>(f)(
lock)) {
1119template <
typename F>
1122 const trx_t *trx = peeked_lock->
trx;
1132 DEBUG_SYNC_C(
"try_relatch_trx_and_shard_and_do_noted_expected_version");
1135 return std::forward<F>(f)();
1144 return std::forward<F>(f)();
1160template <
typename F>
1197 return peeked_wait_lock->is_record_lock();
1199 std::forward<F>(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
Create record locks.
Definition: lock0priv.h:657
ulint m_mode
Lock mode requested.
Definition: lock0priv.h:862
RecLock(dict_index_t *index, const buf_block_t *block, ulint heap_no, ulint mode)
Definition: lock0priv.h:711
RecID m_rec_id
The record lock tuple {space, page_no, heap_no}.
Definition: lock0priv.h:874
RecLock(que_thr_t *thr, dict_index_t *index, const RecID &rec_id, ulint mode)
Definition: lock0priv.h:665
static bool is_predicate_lock(ulint mode)
Definition: lock0priv.h:848
size_t lock_size() const
Definition: lock0priv.h:760
static size_t lock_size(const page_t *page)
Calculate the record lock physical size required, non-predicate lock.
Definition: lock0priv.h:837
RecLock(que_thr_t *thr, dict_index_t *index, const buf_block_t *block, ulint heap_no, ulint mode)
Definition: lock0priv.h:683
static size_t lock_size(ulint mode)
Calculate the record lock physical size required for a predicate lock.
Definition: lock0priv.h:802
size_t m_size
Size of the record lock in bytes.
Definition: lock0priv.h:866
trx_t * m_trx
Transaction requesting the record lock.
Definition: lock0priv.h:858
void init(const page_t *page)
Setup the context from the requirements.
Definition: lock0priv.h:779
que_thr_t * m_thr
The query thread of the transaction.
Definition: lock0priv.h:854
dict_index_t * m_index
Index on which the record lock is required.
Definition: lock0priv.h:870
RecLock(dict_index_t *index, const RecID &rec_id, ulint mode)
Definition: lock0priv.h:699
Definition: hash0hash.h:374
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:254
A RAII helper which latches the mutex protecting given shard during constructor, and unlatches it dur...
Definition: lock0guards.h:91
Definition: lock0priv.h:1098
static void exclusive_latch(ut::Location location)
Definition: lock0priv.h:1101
static void exclusive_unlatch()
Definition: lock0priv.h:1100
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 hash_cell_t * hash_get_nth_cell(hash_table_t *table, size_t n)
Gets the nth cell in a hash table.
static uint64_t hash_calc_cell_id(uint64_t hash_value, hash_table_t *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:1001
constexpr uint32_t LOCK_MODE_MASK
Lock modes and types.
Definition: lock0lock.h:963
constexpr uint32_t LOCK_PREDICATE
Predicate lock.
Definition: lock0lock.h:999
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:976
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:980
constexpr uint32_t LOCK_TYPE_MASK
mask used to extract lock type from the type_mode field in a lock
Definition: lock0lock.h:970
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:997
constexpr uint32_t LOCK_TABLE
Lock types.
Definition: lock0lock.h:966
lock_sys_t * lock_sys
The lock system.
Definition: lock0lock.cc:192
static hash_table_t * lock_hash_get(ulint mode)
Get the lock hash table.
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:985
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:991
constexpr uint32_t LOCK_REC
record lock
Definition: lock0lock.h:968
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 lock_t * lock_rec_get_first_on_page(hash_table_t *lock_hash, const buf_block_t *block)
Gets the first record lock on a page, where the page is identified by a pointer to it.
static const byte lock_strength_matrix[5][5]
Definition: lock0priv.h:577
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:118
constexpr uint32_t MAX_STACK_SIZE
Maximum depth of the DFS stack.
Definition: lock0priv.h:586
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:879
static const byte lock_compatibility_matrix[5][5]
Definition: lock0priv.h:560
constexpr uint32_t PRDT_HEAPNO
Definition: lock0priv.h:588
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:6529
static const lock_t * lock_rec_get_next_const(ulint heap_no, const lock_t *lock)
Gets the next explicit lock request on a record.
static const ulint LOCK_PAGE_BITMAP_MARGIN
Definition: lock0priv.h:309
static const lock_t * lock_rec_get_next_on_page_const(const lock_t *lock)
Gets the first or next record lock on a page.
static lock_t * lock_rec_get_next_on_page(lock_t *lock)
Gets the first or next record lock on a page.
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:78
static ulint lock_get_wait(const lock_t *lock)
Gets the wait flag of a lock.
static lock_t * lock_rec_get_first(hash_table_t *hash, const buf_block_t *block, ulint heap_no)
Gets the first explicit lock request on a record.
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.
static lock_t * lock_rec_get_first_on_page_addr(hash_table_t *lock_hash, const page_id_t &page_id)
Gets the first record lock on a page, where the page is identified by its file address.
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:6074
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:590
@ LOCK_REC_FAIL
Failed to acquire a lock.
Definition: lock0priv.h:592
@ LOCK_REC_SUCCESS
Succeeded in acquiring a lock (implicit or already acquired)
Definition: lock0priv.h:594
@ LOCK_REC_SUCCESS_CREATED
Explicitly created a new lock.
Definition: lock0priv.h:596
static void lock_rec_set_nth_bit(lock_t *lock, ulint i)
Sets the nth bit of a record lock to true.
static lock_t * lock_rec_get_next(ulint heap_no, lock_t *lock)
Gets the next explicit lock request on a record.
static uint32_t lock_rec_get_n_bits(const lock_t *lock)
Gets the number of bits in a record lock bitmap.
const lock_t * lock_rec_get_prev(const lock_t *in_lock, ulint heap_no)
Gets the previous record lock set on a record.
Definition: lock0lock.cc:771
Lock module internal inline methods.
const char * lock_mode_string(enum lock_mode mode)
Convert the given enum value into string.
Definition: lock0types.h:67
lock_mode
Definition: lock0types.h:52
@ LOCK_S
Definition: lock0types.h:55
@ LOCK_X
Definition: lock0types.h:56
unsigned long long int ulonglong
Definition: my_inttypes.h:56
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:168
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:1120
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:1161
bool owns_shared_global_latch()
Tests if lock_sys latch is owned in shared mode by the current thread.
Definition: lock0lock.cc:164
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:2870
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2874
std::list< T, ut::allocator< T > > list
Specialization of list which uses ut_allocator.
Definition: ut0new.h:2878
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)
Definition: scope_guard.h:61
bool srv_read_only_mode
Set if InnoDB must operate in read-only mode.
Definition: srv0srv.cc:198
Iterate over record locks matching <space, page_no, heap_no>
Definition: lock0priv.h:1031
static lock_t * advance(const RecID &rec_id, lock_t *lock)
Gets the next record lock on a page.
Definition: lock0priv.h:1037
static lock_t * first(hash_cell_t *list, const RecID &rec_id)
Gets the first explicit lock request on a record.
Definition: lock0priv.h:1057
static const lock_t * for_each(const RecID &rec_id, F &&f, hash_table_t *hash_table=lock_sys->rec_hash)
Iterate over all the locks on a specific row.
Definition: lock0priv.h:1077
Record lock ID.
Definition: lock0priv.h:601
bool is_supremum() const
Definition: lock0priv.h:633
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:652
uint64_t hash_value() const
Definition: lock0priv.h:630
const page_id_t & get_page_id() const
Definition: lock0priv.h:640
RecID(page_id_t page_id, uint32_t heap_no)
Constructor.
Definition: lock0priv.h:613
RecID(const buf_block_t *block, ulint heap_no)
Constructor.
Definition: lock0priv.h:625
uint32_t m_heap_no
Heap number within the page.
Definition: lock0priv.h:647
bool matches(const lock_t *lock) const
Definition: lock0priv.ic:296
page_id_t m_page_id
Tablespace ID and page number within space
Definition: lock0priv.h:643
RecID(const lock_t *lock, ulint heap_no)
Constructor.
Definition: lock0priv.h:605
Definition: trx0types.h:598
uint64_t m_version
Definition: trx0types.h:602
trx_t * m_trx
Definition: trx0types.h:601
The buffer control block structure.
Definition: buf0buf.h:1690
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: hash0hash.h:61
Definition: lock0prdt.h:40
Record lock for a page.
Definition: lock0priv.h:83
std::ostream & print(std::ostream &out) const
Print the record lock into the given output stream.
Definition: lock0priv.h:101
uint32_t n_bits
number of bits in the lock bitmap; Must be divisible by 8.
Definition: lock0priv.h:90
page_id_t page_id
The id of the page on which records referenced by this lock's bitmap are located.
Definition: lock0priv.h:86
locksys::Latches latches
The latches protecting queues of record and table locks.
Definition: lock0lock.h:1022
hash_table_t * rec_hash
The hash table of the record (LOCK_REC) locks, except for predicate (LOCK_PREDICATE) and predicate pa...
Definition: lock0lock.h:1026
Lock struct; protected by lock_sys latches.
Definition: lock0priv.h:136
bool is_record_not_gap() const
Definition: lock0priv.h:203
dict_index_t * index
Index for a record lock.
Definition: lock0priv.h:144
lock_table_t tab_lock
Table lock.
Definition: lock0priv.h:152
lock_mode mode() const
Definition: lock0priv.h:224
const char * type_string() const
Definition: lock0priv.h:245
lock_rec_t rec_lock
Record lock.
Definition: lock0priv.h:155
bool includes_supremum() const
Definition: lock0priv.h:216
bool is_gap() const
Definition: lock0priv.h:200
ulonglong m_psi_internal_thread_id
Performance schema thread that created the lock.
Definition: lock0priv.h:161
bool is_insert_intention() const
Definition: lock0priv.h:211
bool is_record_lock() const
Determine if the lock object is a record lock.
Definition: lock0priv.h:188
trx_que_t trx_que_state() const
Definition: lock0priv.h:233
std::ostream & print(std::ostream &out) const
Print the lock object into the given output stream.
Definition: lock0priv.h:284
bool is_waiting() const
Definition: lock0priv.h:197
lock_t * hash
Hash chain node for a record lock.
Definition: lock0priv.h:148
ulonglong m_psi_event_id
Performance schema event that created the lock.
Definition: lock0priv.h:164
uint32_t type_mode
The lock type and mode bit flags.
Definition: lock0priv.h:170
trx_t * trx
transaction owning the lock
Definition: lock0priv.h:138
uint64_t m_seq
Timestamp when it was created.
Definition: lock0priv.h:174
bool is_next_key_lock() const
Definition: lock0priv.h:206
bool is_predicate() const
Determine if it is predicate lock.
Definition: lock0priv.h:192
uint32_t type() const
Definition: lock0priv.h:221
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:178
hash_table_t * hash_table() const
Get lock hash table.
Definition: lock0priv.h:230
A table lock.
Definition: lock0priv.h:53
std::ostream & print(std::ostream &out) const
Print the table lock into the given output stream.
Definition: lock0priv.h:68
dict_table_t * table
database table in dictionary cache
Definition: lock0priv.h:54
locks
list of locks on the same table
Definition: lock0priv.h:57
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:448
std::atomic< lock_t * > wait_lock
The lock request of this transaction is waiting for.
Definition: trx0trx.h:469
trx_que_t que_state
valid when trx->state == TRX_STATE_ACTIVE: TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT, ...
Definition: trx0trx.h:416
Definition: trx0trx.h:684
std::atomic_uint64_t version
Version of this instance.
Definition: trx0trx.h:1083
trx_lock_t lock
Information about the transaction locks and state.
Definition: trx0trx.h:831
#define trx_mutex_enter_first_of_two(t)
Acquire the trx->mutex (and indicate we might request one more).
Definition: trx0trx.h:1394
#define trx_mutex_exit(t)
Release the trx->mutex.
Definition: trx0trx.h:1397
#define trx_mutex_enter(t)
Acquire the trx->mutex (and promise not to request any more).
Definition: trx0trx.h:1391
bool trx_mutex_own(const trx_t *trx)
Test if trx->mutex is owned by the current thread.
Definition: trx0trx.h:1354
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
#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