/** The value of innodb_deadlock_detect */ extern my_bool innodb_deadlock_detect; /** The value of innodb_deadlock_report */ extern ulong innodb_deadlock_report;
namespace Deadlock
{ /** The allowed values of innodb_deadlock_report */ enum report { REPORT_OFF, REPORT_BASIC, REPORT_FULL };
}
/** Conflicting lock info */ struct conflicting_lock_info { /** Conflicting lock */ const lock_t *conflicting; /** If some lock was bypassed, points to the lock after which bypassing lockmustbeinsertedintolinkedlistoflocksforthecertaincellof
record locks hash table. */
lock_t *insert_after; /** First bypassed lock */
ut_d(const lock_t *bypassed;)
};
/*********************************************************************//**
Gets the heap_no of the smallest user record on a page.
@return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */
UNIV_INLINE
ulint
lock_get_min_heap_no( /*=================*/ const buf_block_t* block); /*!< in: buffer block */
/** Discard locks for an index when purging DELETE FROM SYS_INDEXES afteranabortedCREATEINDEXoperation.
@param index a stale index on which ADD INDEX operation was aborted */
ATTRIBUTE_COLD void lock_discard_for_index(const dict_index_t &index);
/*************************************************************//**
Updates the lock table when we have reorganized a page. NOTE: we copy
also the locks set on the infimum of the page; the infimum may carry
locks if an update of a record is occurring on the page, and its locks
were temporarily stored on the infimum. */ void
lock_move_reorganize_page( /*======================*/ const buf_block_t* block, /*!< in: old index page, now
reorganized */ const buf_block_t* oblock);/*!< in: copy of the old, not
reorganized page */ /*************************************************************//**
Moves the explicit locks on user records to another page if a record
list end is moved to another page. */ void
lock_move_rec_list_end( /*===================*/ const buf_block_t* new_block, /*!< in: index page to move to */ const buf_block_t* block, /*!< in: index page */ const rec_t* rec); /*!< in: record on page: this
is the first record moved */ /*************************************************************//**
Moves the explicit locks on user records to another page if a record
list start is moved to another page. */ void
lock_move_rec_list_start( /*=====================*/ const buf_block_t* new_block, /*!< in: index page to move to */ const buf_block_t* block, /*!< in: index page */ const rec_t* rec, /*!< in: record on page: thisisthefirst
record NOT copied */ const rec_t* old_end); /*!< in: old previous-to-last recordonnew_page beforetherecords
were copied */ /*************************************************************//**
Updates the lock table when a page is split to the right. */ void
lock_update_split_right( /*====================*/ const buf_block_t* right_block, /*!< in: right page */ const buf_block_t* left_block); /*!< in: left page */ /*************************************************************//**
Updates the lock table when a page is merged to the right. */ void
lock_update_merge_right( /*====================*/ const buf_block_t* right_block, /*!< in: right page to
which merged */ const rec_t* orig_succ, /*!< in: original successorofinfimum ontherightpage
before merge */ const buf_block_t* left_block); /*!< in: merged index pagewhichwillbe
discarded */ /** Update locks when the root page is copied to another in btr_root_raise_and_insert().Notethatweleavelockstructsonthe rootpage,eventhoughtheydonotmakesenseonotherthanleaf pages:thereasonisthatinapessimisticupdatetheinfimumrecord oftherootpagewillactasadummycarrierofthelocksoftherecord
to be updated. */ void lock_update_root_raise(const buf_block_t &block, const page_id_t root); /** Update the lock table when a page is copied to another. @paramnew_blockthetargetpage
@param old old page (not index root page) */ void lock_update_copy_and_discard(const buf_block_t &new_block, page_id_t old);
/** Update gap locks between the last record of the left_block and the firstrecordoftheright_blockwhenarecordisabouttobeinserted atthestartoftheright_block,eventhoughitshould"naturally"be insertedasthelastrecordoftheleft_blockaccordingtothe currentnodepointerintheparentpage.
Thus,insertingthenewrecord,andsubsequentlyadjustingthenode pointersinparentpagestovaluessmallerorequaltothenew records'key,willmeanthatgapwillbeslicedatadifferentplace ("movedtotheleft"):fragmentofthe1stgapwillnowbecometreated as2nd.Therefore,wemustcopyanyGRANTEDlocksfrom1stgaptothe 2ndgap.AnyWAITINGlocksmustbeofINSERT_INTENTIONtype(asno otherGAPlockseverwaitforanything)andcanstayat1stgap,as theironlypurposeistonotifytherequestertheycanretry insertion,andthere'snocorrectnessrequirementtoavoidwakingthem uptoosoon. @paramleft_blockleftpage
@param right_block right page */ void lock_update_node_pointer(const buf_block_t *left_block, const buf_block_t *right_block); /*************************************************************//**
Updates the lock table when a page is split to the left. */ void
lock_update_split_left( /*===================*/ const buf_block_t* right_block, /*!< in: right page */ const buf_block_t* left_block); /*!< in: left page */ /** Update the lock table when a page is merged to the left. @paramleftleftpage @paramorig_predoriginalpredecessorofsupremumontheleftpagebeforemerge
@param right merged, to-be-discarded right page */ void lock_update_merge_left(const buf_block_t& left, const rec_t *orig_pred, const page_id_t right);
/*************************************************************//**
Resets the original locks on heir and replaces them with gap type locks
inherited from rec. */ void
lock_rec_reset_and_inherit_gap_locks( /*=================================*/ const buf_block_t& heir_block, /*!< in: block containing the
record which inherits */ const page_id_t donor, /*!< in: page containing the recordfromwhichinherited; doesNOTresetthelockson
this record */
ulint heir_heap_no, /*!< in: heap_no of the
inheriting record */
ulint heap_no); /*!< in: heap_no of the
donating record */ /*************************************************************//**
Updates the lock table when a page is discarded. */ void
lock_update_discard( /*================*/ const buf_block_t* heir_block, /*!< in: index page
which will inherit the locks */
ulint heir_heap_no, /*!< in: heap_no of the record
which will inherit the locks */ const buf_block_t* block); /*!< in: index page
which will be discarded */ /*************************************************************//**
Updates the lock table when a new user record is inserted. */ void
lock_update_insert( /*===============*/ const buf_block_t* block, /*!< in: buffer block containing rec */ const rec_t* rec); /*!< in: the inserted record */ /*************************************************************//**
Updates the lock table when a record is removed. */ void
lock_update_delete( /*===============*/ const buf_block_t* block, /*!< in: buffer block containing rec */ const rec_t* rec); /*!< in: the record to be removed */ /*********************************************************************//**
Stores on the page infimum record the explicit locks of another record. This function is used to store the lock state of a record when it is
updated and the size of the record changes in the update. The record
is in such an update moved, perhaps to another page. The infimum record
acts as a dummy carrier record, taking care of lock releases while the
actual record is being moved. */ void
lock_rec_store_on_page_infimum( /*===========================*/ const buf_block_t* block, /*!< in: buffer block containing rec */ const rec_t* rec); /*!< in: record whose lock state isstoredontheinfimum recordofthesamepage;lock bitsareresetonthe
record */ /** Restore the explicit lock requests on a single record, where the statewasstoredontheinfimumofapage. @paramblockbufferblockcontainingrec @paramrecrecordwhoselockstateisrestored @paramdonatorpage(recisnotnecessarilyonthispage)
whose infimum stored the lock state; lock bits are reset on the infimum */ void lock_rec_restore_from_page_infimum(const buf_block_t &block, const rec_t *rec, page_id_t donator);
/*********************************************************************//**
Checks if locks of other transactions prevent an immediate insert of
a record. If they do, first tests if the query thread should anyway
be suspended for some reason; ifnot, then puts the transaction and
the query thread to the lock wait state and inserts a waiting request for a gap x-lock to the lock queue.
@return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
dberr_t
lock_rec_insert_check_and_lock( /*===========================*/ const rec_t* rec, /*!< in: record after which to insert */
buf_block_t* block, /*!< in/out: buffer block of rec */
dict_index_t* index, /*!< in: index */
que_thr_t* thr, /*!< in: query thread */
mtr_t* mtr, /*!< in/out: mini-transaction */ bool* inherit)/*!< out: set to true if the new insertedrecordmaybeshouldinherit LOCK_GAPtypelocksfromthesuccessor
record */
MY_ATTRIBUTE((warn_unused_result));
/*********************************************************************//**
Checks if locks of other transactions prevent an immediate modify (update, delete mark, ordelete unmark) of a clustered index record. If they do,
first tests if the query thread should anyway be suspended for some
reason; ifnot, then puts the transaction and the query thread to the
lock wait state and inserts a waiting request for a record x-lock to the
lock queue.
@return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
dberr_t
lock_clust_rec_modify_check_and_lock( /*=================================*/ const buf_block_t* block, /*!< in: buffer block of rec */ const rec_t* rec, /*!< in: record which should be
modified */
dict_index_t* index, /*!< in: clustered index */ const rec_offs* offsets,/*!< in: rec_get_offsets(rec, index) */
que_thr_t* thr) /*!< in: query thread */
MY_ATTRIBUTE((warn_unused_result)); /*********************************************************************//**
Checks if locks of other transactions prevent an immediate modify
(delete mark ordelete unmark) of a secondary index record.
@return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
dberr_t
lock_sec_rec_modify_check_and_lock( /*===============================*/
ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG
bit is set, does nothing */
buf_block_t* block, /*!< in/out: buffer block of rec */ const rec_t* rec, /*!< in: record which should be modified;NOTE:asthisisasecondary index,wealwayshavetomodifythe clusteredindexrecordfirst:seethe
comment below */
dict_index_t* index, /*!< in: secondary index */
que_thr_t* thr, /*!< in: query thread
(can be NULL if BTR_NO_LOCKING_FLAG) */
mtr_t* mtr) /*!< in/out: mini-transaction */
MY_ATTRIBUTE((warn_unused_result)); /*********************************************************************//**
Like lock_clust_rec_read_check_and_lock(), but reads a
secondary index record.
@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, or DB_DEADLOCK */
dberr_t
lock_sec_rec_read_check_and_lock( /*=============================*/
ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG
bit is set, does nothing */ const buf_block_t* block, /*!< in: buffer block of rec */ const rec_t* rec, /*!< in: user record or page supremumrecordwhichshould bereadorpassedoverbya
read cursor */
dict_index_t* index, /*!< in: secondary index */ const rec_offs* offsets,/*!< in: rec_get_offsets(rec, index) */
lock_mode mode, /*!< in: mode of the lock which thereadcursorshouldseton records:LOCK_SorLOCK_X;the latterispossiblein
SELECT FOR UPDATE */ unsigned gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
LOCK_REC_NOT_GAP */
que_thr_t* thr); /*!< in: query thread */ /*********************************************************************//**
Checks if locks of other transactions prevent an immediate read, or passing
over by a read cursor, of a clustered index record. If they do, first tests if the query thread should anyway be suspended for some reason; ifnot, then
puts the transaction and the query thread to the lock wait state and inserts a
waiting request for a record lock to the lock queue. Sets the requested mode
lock on the record.
@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, or DB_DEADLOCK */
dberr_t
lock_clust_rec_read_check_and_lock( /*===============================*/
ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG
bit is set, does nothing */ const buf_block_t* block, /*!< in: buffer block of rec */ const rec_t* rec, /*!< in: user record or page supremumrecordwhichshould bereadorpassedoverbya
read cursor */
dict_index_t* index, /*!< in: clustered index */ const rec_offs* offsets,/*!< in: rec_get_offsets(rec, index) */
lock_mode mode, /*!< in: mode of the lock which thereadcursorshouldseton records:LOCK_SorLOCK_X;the latterispossiblein
SELECT FOR UPDATE */ unsigned gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
LOCK_REC_NOT_GAP */
que_thr_t* thr); /*!< in: query thread */ /*********************************************************************//**
Checks if locks of other transactions prevent an immediate read, or passing
over by a read cursor, of a clustered index record. If they do, first tests if the query thread should anyway be suspended for some reason; ifnot, then
puts the transaction and the query thread to the lock wait state and inserts a
waiting request for a record lock to the lock queue. Sets the requested mode
lock on the record. This is an alternative version of
lock_clust_rec_read_check_and_lock() that does not require the parameter "offsets".
@return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
dberr_t
lock_clust_rec_read_check_and_lock_alt( /*===================================*/
ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG
bit is set, does nothing */ const buf_block_t* block, /*!< in: buffer block of rec */ const rec_t* rec, /*!< in: user record or page supremumrecordwhichshould bereadorpassedoverbya
read cursor */
dict_index_t* index, /*!< in: clustered index */
lock_mode mode, /*!< in: mode of the lock which thereadcursorshouldseton records:LOCK_SorLOCK_X;the latterispossiblein
SELECT FOR UPDATE */ unsigned gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
LOCK_REC_NOT_GAP */
que_thr_t* thr) /*!< in: query thread */
MY_ATTRIBUTE((warn_unused_result));
/** Acquire a table lock. @paramtabletabletobelocked @paramfktablepointertotable,incaseofaFOREIGNkeycheck @parammodelockmode @paramthrSQLexecutionthread @retvalDB_SUCCESSifthelockwasacquired @retvalDB_DEADLOCKifadeadlockoccurred,orfktable&&*fktable!=table
@retval DB_LOCK_WAIT if lock_wait() must be invoked */
dberr_t lock_table(dict_table_t *table, dict_table_t *const*fktable,
lock_mode mode, que_thr_t *thr)
MY_ATTRIBUTE((warn_unused_result));
/** Create a table lock object for a resurrected transaction. @paramtabletabletobeX-locked @paramtrxtransaction
@param mode LOCK_X or LOCK_IX */ void lock_table_resurrect(dict_table_t *table, trx_t *trx, lock_mode mode);
/** Sets a lock on a table based on the given mode. @paramtabletabletolock @paramtrxtransaction @parammodeLOCK_XorLOCK_S @paramno_waitwhethertoskiphandlingDB_LOCK_WAIT
@return error code */
dberr_t lock_table_for_trx(dict_table_t *table, trx_t *trx, lock_mode mode, bool no_wait= false)
MY_ATTRIBUTE((nonnull, warn_unused_result));
/** Lock the child tables of a table. @paramtableparenttable @paramtrxtransaction
@return error code */
dberr_t lock_table_children(dict_table_t *table, trx_t *trx)
MY_ATTRIBUTE((nonnull, warn_unused_result));
/** Exclusively lock the data dictionary tables. @paramtrxdictionarytransaction @returnerrorcode
@retval DB_SUCCESS on success */
dberr_t lock_sys_tables(trx_t *trx);
/*************************************************************//**
Removes a granted record lock of a transaction from the queue and grants
locks to other transactions waiting in the queue if they now are entitled
to a lock. */ void
lock_rec_unlock( /*============*/
trx_t* trx, /*!< in/out: transaction that has
set a record lock */ const buf_block_t& block, /*!< in: page containing rec */ const rec_t* rec, /*!< in: record */
lock_mode lock_mode);/*!< in: LOCK_S or LOCK_X */
/** Release the explicit locks of a committing transaction,
and release possible other transactions waiting because of these locks. */ void lock_release(trx_t* trx);
/** Release the explicit locks of a committing transaction while dict_sys.latchisexclusivelylocked,
and release possible other transactions waiting because of these locks. */ void lock_release_on_drop(trx_t *trx);
/** Release non-exclusive locks on XA PREPARE,
and release possible other transactions waiting because of these locks. */ void lock_release_on_prepare(trx_t *trx);
/** Release locks on a table whose creation is being rolled back */
ATTRIBUTE_COLD void lock_release_on_rollback(trx_t *trx, dict_table_t *table);
/**********************************************************************//**
Looks for a set bit in a record lock bitmap. Returns ULINT_UNDEFINED, if none found.
@return bit index == heap number of the record, or ULINT_UNDEFINED if
none found */
ulint
lock_rec_find_set_bit( /*==================*/ const lock_t* lock); /*!< in: record lock with at least one
bit set */
/*********************************************************************//**
Checks if a lock request lock1 has to wait for request lock2.
@return whether lock1 has to wait for lock2 to be removed */ bool
lock_has_to_wait( /*=============*/ const lock_t* lock1, /*!< in: waiting lock */ const lock_t* lock2); /*!< in: another lock; NOTE that it is assumedthatthishasalockbitset onthesamerecordasinlock1ifthe
locks are record locks */ /*********************************************************************//**
Reports that a transaction id is insensible, i.e., in the future. */
ATTRIBUTE_COLD void
lock_report_trx_id_insanity( /*========================*/
trx_id_t trx_id, /*!< in: trx id */ const rec_t* rec, /*!< in: user record */
dict_index_t* index, /*!< in: index */ const rec_offs* offsets, /*!< in: rec_get_offsets(rec, index) */
trx_id_t max_trx_id); /*!< in: trx_sys.get_max_trx_id() */ /*********************************************************************//**
Prints info of locks for all transactions.
@returnFALSEifnot able to acquire lock_sys.latch (and display info) */
ibool
lock_print_info_summary( /*====================*/
FILE* file, /*!< in: file where to print */
ibool nowait) /*!< in: whether to wait for lock_sys.latch */
MY_ATTRIBUTE((warn_unused_result));
/** Prints transaction lock wait and MVCC state. @param[in,out]filefilewheretoprint @param[in]trxtransaction
@param[in] now current my_hrtime_coarse() */ void lock_trx_print_wait_and_mvcc_state(FILE *file, const trx_t *trx,
my_hrtime_t now);
/*********************************************************************//**
Prints info of locks for each transaction. This function will release
lock_sys.latch, which the caller must be holding in exclusive mode. */ void
lock_print_info_all_transactions( /*=============================*/
FILE* file); /*!< in: file where to print */
/*********************************************************************//** Return the number of table locks for a transaction.
The caller must be holding lock_sys.latch. */
ulint
lock_number_of_tables_locked( /*=========================*/ const trx_lock_t* trx_lock) /*!< in: transaction locks */
MY_ATTRIBUTE((warn_unused_result));
/** Check if there are any locks on a table.
@return true if table has either table or record locks. */ bool lock_table_has_locks(dict_table_t *table);
/** Wait for a lock to be released. @retvalDB_DEADLOCKifthistransactionwaschosenasthedeadlockvictim @retvalDB_INTERRUPTEDiftheexecutionwasinterruptedbytheuser @retvalDB_LOCK_WAIT_TIMEOUTifthelockwaittimedout
@retval DB_SUCCESS if the lock was granted */
dberr_t lock_wait(que_thr_t *thr); /*********************************************************************//**
Unlocks AUTO_INC type locks that were possibly reserved by a trx. This
function should be called at the the end of an SQL statement, by the
connection thread that owns the transaction (trx->mysql_thd). */ void
lock_unlock_table_autoinc( /*======================*/
trx_t* trx); /*!< in/out: transaction */
/** Handle a pending lock wait (DB_LOCK_WAIT) in a semi-consistent read whileholdingaclusteredindexleafpagelatch. @paramtrxtransactionthatisorwaswaitingforalock @retvalDB_SUCCESSifthelockwasgranted @retvalDB_DEADLOCKifthetransactionmustbeabortedduetoadeadlock @retvalDB_LOCK_WAITifalockwaitwouldbenecessary;thepending
lock request was released */
dberr_t lock_trx_handle_wait(trx_t *trx);
/*********************************************************************//**
Checks that a transaction id is sensible, i.e., not in the future.
@returntrueif ok */ bool
lock_check_trx_id_sanity( /*=====================*/
trx_id_t trx_id, /*!< in: trx id */ const rec_t* rec, /*!< in: user record */
dict_index_t* index, /*!< in: index */ const rec_offs* offsets); /*!< in: rec_get_offsets(rec, index) */ #ifdef UNIV_DEBUG /*******************************************************************//**
Check if the transaction holds any locks on the sys tables or its records.
@return the strongest lock found on any sys table or0for none */ const lock_t*
lock_trx_has_sys_table_locks( /*=========================*/ const trx_t* trx) /*!< in: transaction to check */
MY_ATTRIBUTE((nonnull, warn_unused_result));
/** Check if the transaction holds an explicit exclusive lock on a record. @param[in]trxtransaction @param[in]tabletable @param[in]idleafpageidentifier @param[in]heap_noheapnumberidentifyingtherecord
@return whether an explicit X-lock is held */ bool lock_trx_has_expl_x_lock(const trx_t &trx, const dict_table_t &table,
page_id_t id, ulint heap_no); #endif/* UNIV_DEBUG */
/** The lock system struct */ class lock_sys_t
{ friendstruct LockGuard; friendstruct LockMultiGuard; friendstruct TMLockGuard; friendstruct TMLockMutexGuard; friendstruct TMLockTrxGuard;
/** Hash table latch */ struct hash_latch #ifdef SUX_LOCK_GENERIC
: private rw_lock
{ /** Wait for an exclusive lock */ void wait(); /** Try to acquire a lock */ bool try_acquire() { return write_trylock(); } /** Acquire a lock */ void acquire() { if (!try_acquire()) wait(); } /** Release a lock */ void release(); /** @return whether any lock is being held or waited for by any thread */ bool is_locked_or_waiting() const
{ return rw_lock::is_locked_or_waiting(); } /** @return whether this latch is possibly held by any thread */ bool is_locked() const { return rw_lock::is_locked(); } #else
{ private:
srw_spin_lock_low lock; public: /** Try to acquire a lock */ bool try_acquire() { return lock.wr_lock_try(); } /** Acquire a lock */ void acquire() { lock.wr_lock(); } /** Release a lock */ void release() { lock.wr_unlock(); } /** @return whether any lock may be held by any thread */ bool is_locked_or_waiting() const noexcept
{ return lock.is_locked_or_waiting(); } /** @return whether this latch is possibly held by any thread */ bool is_locked() const noexcept { return lock.is_locked(); } #endif /** Try to acquire the latch with a bounded spin (no syscall, no blocking),forthelock-releasefastpathsthatholdtrx->mutex.
@return whether the latch was acquired */ bool try_acquire_spin() noexcept;
};
public: struct hash_table
{ /** Number of consecutive array[] elements occupied by a hash_latch */ static constexpr size_t LATCH= sizeof(void*) >= sizeof(hash_latch) ? 1 : 2;
static_assert(sizeof(hash_latch) <= LATCH * sizeof(void*), "allocation");
/** Number of array[] elements per hash_latch.
Must be LATCH less than a power of 2. */ static constexpr size_t ELEMENTS_PER_LATCH= (64 / sizeof(void*)) - LATCH; static constexpr size_t EMPTY_SLOTS_PER_LATCH=
((CPU_LEVEL1_DCACHE_LINESIZE / 64) - 1) * (64 / sizeof(void*));
/** number of payload elements in array[]. Protected by lock_sys.latch. */
ulint n_cells; /** the hash table, with pad(n_cells) elements, aligned to L1 cache size; inanyhashchain,lock_t::is_waiting()entriesmustnotprecede
granted locks */
hash_cell_t *array;
/** Create the hash table.
@param n the lower bound of n_cells */ void create(ulint n);
/** Resize the hash table.
@param n the lower bound of n_cells */ void resize(ulint n);
private: /** @return the index of an array element */ static ulint calc_hash(ulint fold, ulint n_cells) noexcept
{ return pad(fold % n_cells);
}
};
private: bool m_initialised;
/** mutex protecting the locks */
alignas(CPU_LEVEL1_DCACHE_LINESIZE)
IF_DBUG(srw_lock_debug,srw_spin_lock) latch; #ifdef SUX_LOCK_GENERIC protected: /** mutex for hash_latch::wait() */
pthread_mutex_t hash_mutex; /** condition variable for hash_latch::wait() */
pthread_cond_t hash_cond; #endif public: /** record locks */
hash_table rec_hash; /** predicate locks for SPATIAL INDEX */
hash_table prdt_hash; /** page locks for SPATIAL INDEX */
hash_table prdt_page_hash;
/** mutex covering lock waits; @see trx_lock_t::wait_lock */
alignas(CPU_LEVEL1_DCACHE_LINESIZE) mysql_mutex_t wait_mutex; private: /** The increment of wait_count for a wait. Anything smaller is a
pending wait count. */ static constexpr uint64_t WAIT_COUNT_STEP= 1U << 19; /** waits and total number of lock waits; protected by wait_mutex */
uint64_t wait_count; /** Cumulative wait time; protected by wait_mutex */
uint64_t wait_time; /** Longest wait time; protected by wait_mutex */
uint64_t wait_time_max; public: /** number of deadlocks detected; protected by wait_mutex */
ulint deadlocks; /** number of lock wait timeouts; protected by wait_mutex */
ulint timeouts; /** Constructor.
/** Assert that wr_lock() has been invoked by this thread */ void assert_locked() const { ut_ad(latch.have_wr()); } /** Assert that wr_lock() has not been invoked by this thread */ void assert_unlocked() const { ut_ad(!latch.have_wr()); } #ifdef UNIV_DEBUG /** @return whether the current thread is the lock_sys.latch writer */ bool is_writer() const { return latch.have_wr(); } /** @return whether the current thread is holding lock_sys.latch */ bool is_holder() const { return latch.have_any(); } /** Returns whether a cell of hash table where the lock is stored is latched. @paramlockthelockwhichcellischecked
@return whether the lock's cell is latched */ bool is_cell_locked(const lock_t &lock) { return hash_table::latch(
hash_get(lock.type_mode)
.cell_get(lock.un_member.rec_lock.page_id.fold()))
->is_locked();
} /** Assert that a lock shard is exclusively latched (by some thread) */ void assert_locked(const lock_t &lock) const; /** Assert that a table lock shard is exclusively latched by this thread */ void assert_locked(const dict_table_t &table) const; /** Assert that a hash table cell is exclusively latched (by some thread) */ void assert_locked(const hash_cell_t &cell) const; #else void assert_locked(const lock_t &) const {} void assert_locked(const dict_table_t &) const {} void assert_locked(const hash_cell_t &) const {} #endif
/** Get the lock hash table for a mode */
hash_table &hash_get(ulint mode)
{ if (UNIV_LIKELY(!(mode & (LOCK_PREDICATE | LOCK_PRDT_PAGE)))) return rec_hash; return (mode & LOCK_PREDICATE) ? prdt_hash : prdt_page_hash;
}
/** Get the lock hash table for predicate a mode */
hash_table &prdt_hash_get(bool page)
{ return page ? prdt_page_hash : prdt_hash; }
/** Get the first lock on a page. @paramcellhashtablecell @paramidpagenumber @returnfirstlock
@retval nullptr if none exists */ staticinline lock_t *get_first(const hash_cell_t &cell, page_id_t id);
/** Get the first explicit lock request on a record. @paramcellfirstlockhashtablecell @paramidpageidentifier @paramheap_norecordidentifierinpage @returnfirstlock
@retval nullptr if none exists */ staticinline lock_t *get_first(const hash_cell_t &cell, page_id_t id,
ulint heap_no);
/** Remove locks on a discarded SPATIAL INDEX page. @paramidpagetobediscarded
@param page whether to discard also from lock_sys.prdt_hash */ void prdt_page_free_from_discard(const page_id_t id, bool all= false);
/** Cancel possible lock waiting for a transaction */ inlinevoid cancel_lock_wait_for_trx(trx_t *trx) noexcept; #ifdef WITH_WSREP /** Cancel lock waiting for a wsrep BF abort. */ staticvoid cancel_lock_wait_for_wsrep_bf_abort(trx_t *trx); #endif/* WITH_WSREP */
};
/** The lock system */ extern lock_sys_t lock_sys;
/** @return the index of an array element */ inline ulint lock_sys_t::hash_table::calc_hash(ulint fold) const
{
ut_ad(lock_sys.is_holder()); return calc_hash(fold, n_cells);
}
/** Get a hash table cell. */ inline hash_cell_t *lock_sys_t::hash_table::cell_get(ulint fold) const
{
ut_ad(lock_sys.is_holder()); return &array[calc_hash(fold)];
}
/** Get the first lock on a page. @paramcellhashtablecell @paramidpagenumber @returnfirstlock
@retval nullptr if none exists */ inline lock_t *lock_sys_t::get_first(const hash_cell_t &cell, page_id_t id)
{
lock_sys.assert_locked(cell); for (auto lock= static_cast<lock_t*>(cell.node); lock; lock= lock->hash)
{
ut_ad(!lock->is_table()); if (lock->un_member.rec_lock.page_id == id) return lock;
} return nullptr;
}
/** Remove a record lock request, waiting or granted, on a discarded page @paramin_locklockobject
@param cell hash table cell containing in_lock */ void lock_rec_discard(lock_t *in_lock, hash_cell_t &cell) noexcept;
/** Create a new record lock and inserts it to the lock queue, withoutcheckingfordeadlocksorconflicts. @paramc_lock_infoconflictinglockinfo @param[in]type_modelockmodeandwaitflag @param[in]page_idindexpagenumber @param[in]pageR-treeindexpage,orNULL @param[in]heap_norecordheapnumberintheindexpage @param[in]indextheindextree @param[in,out]trxtransaction @param[in]holds_trx_mutexwhetherthecallerholdstrx->mutex
@return created lock */
lock_t*
lock_rec_create( const conflicting_lock_info &c_lock_info, unsigned type_mode, const page_id_t page_id, const page_t* page,
ulint heap_no,
dict_index_t* index,
trx_t* trx, bool holds_trx_mutex);
/** Enqueue a waiting request for a lock which cannot be granted immediately. Checkfordeadlocks. @paramc_lock_infoconflictinglockinfo @param[in]type_modetherequestedlockmode(LOCK_SorLOCK_X) possiblyORedwithLOCK_GAPor LOCK_REC_NOT_GAP,ORedwith LOCK_INSERT_INTENTIONifthis waitinglockrequestisset whenperforminganinsertof anindexrecord @param[in]idpageidentifier @param[in]pageleafpageintheindex @param[in]heap_norecordheapnumberintheblock @param[in]indexindextree @param[in,out]thrquerythread @param[in]prdtminimumboundingbox(spatialindex) @retvalDB_LOCK_WAITifthewaitinglockwasenqueued
@retval DB_DEADLOCK if this transaction was chosen as the victim */
dberr_t
lock_rec_enqueue_waiting( const conflicting_lock_info &c_lock_info, unsigned type_mode, const page_id_t id, const page_t* page,
ulint heap_no,
dict_index_t* index,
que_thr_t* thr,
lock_prdt_t* prdt); /*************************************************************//**
Moves the explicit locks on user records to another page if a record
list start is moved to another page. */ void
lock_rtr_move_rec_list( /*===================*/ const buf_block_t* new_block, /*!< in: index page to
move to */ const buf_block_t* block, /*!< in: index page */
rtr_rec_move_t* rec_move, /*!< in: recording records
moved */
ulint num_move); /*!< in: num of rec to move */
#include"lock0lock.inl"
#endif
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.27Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.