/**************************************************//**
@file include/lock0priv.h
Lock module internal structures and methods.
Created July 12, 2007 Vasil Dimov
*******************************************************/
#ifndef lock0priv_h #define lock0priv_h
#ifndef LOCK_MODULE_IMPLEMENTATION /* If you need to access members of the structures defined in this file,pleasewriteappropriatefunctionsthatretrievethemandput
those functions in lock/ */ #errorDonot include lock0priv.h outside of the lock/ module #endif
/** Print the table lock into the given output stream @param[in,out]outtheoutputstream
@return the given output stream. */ inline
std::ostream& lock_table_t::print(std::ostream& out) const
{
out << "[lock_table_t: name=" << table->name << "]"; return(out);
}
/** The global output operator is overloaded to conveniently printthelock_table_tobjectintothegivenoutputstream. @param[in,out]outtheoutputstream @param[in]lockthetablelock
@return the given output stream */ inline
std::ostream& operator<<(std::ostream& out, const lock_table_t& lock)
{ return(lock.print(out));
}
/* An explicit record lock affects both the record and the gap before it. Animplicitx-lockdoesnotaffectthegap,itonlylockstheindex recordfromreadorupdate.
PROBLEM:Whenarecordisinserted,whatlocksshoulditinheritfromthe ------------------------------------------------------------------------- upperneighbor?Aninsertofanewsupremumrecordinapagesplitis alwayspossible,butaninsertofanewuserrecordrequiresthattheupper neighbordoesnothaveanylockrequestsbyothertransactions,grantedor waiting,initslockqueue.Solution:Wecancopythelocksasgaptype locks,sothatalsothewaitinglocksaretransformedtograntedgaptype
locks on the inserted record. */
/* LOCK COMPATIBILITY MATRIX *ISIXSXAI *IS+++-+ *IX++--+ *S+-+-- *X----- *AI++--- * *Notethatforrows,InnoDBonlyacquiresSorXlocks. *Fortables,InnoDBnormallyacquiresISorIXlocks. *SorXtablelocksareonlyacquiredforLOCKTABLES. *Auto-increment(AI)locksareneededbecauseof *statement-levelMySQLbinlog. *Seealsolock_mode_compatible().
*/ staticconst byte lock_compatibility_matrix[5][5] = { /** IS IX S X AI */ /* IS */ { TRUE, TRUE, TRUE, FALSE, TRUE}, /* IX */ { TRUE, TRUE, FALSE, FALSE, TRUE}, /* S */ { TRUE, FALSE, TRUE, FALSE, FALSE}, /* X */ { FALSE, FALSE, FALSE, FALSE, FALSE}, /* AI */ { TRUE, TRUE, FALSE, FALSE, FALSE}
};
/* STRONGER-OR-EQUAL RELATION (mode1=row, mode2=column) *ISIXSXAI *IS+---- *IX++--- *S+-+-- *X+++++ *AI----+ *Seelock_mode_stronger_or_eq().
*/ staticconst byte lock_strength_matrix[5][5] = { /** IS IX S X AI */ /* IS */ { TRUE, FALSE, FALSE, FALSE, FALSE}, /* IX */ { TRUE, TRUE, FALSE, FALSE, FALSE}, /* S */ { TRUE, FALSE, TRUE, FALSE, FALSE}, /* X */ { TRUE, TRUE, TRUE, TRUE, TRUE}, /* AI */ { FALSE, FALSE, FALSE, FALSE, TRUE}
};
#define PRDT_HEAPNO PAGE_HEAP_NO_INFIMUM /** Record locking request status */ enum lock_rec_req_status { /** Failed to acquire a lock */
LOCK_REC_FAIL, /** Succeeded in acquiring a lock (implicit or already acquired) */
LOCK_REC_SUCCESS, /** Explicitly created a new lock */
LOCK_REC_SUCCESS_CREATED
};
#ifdef UNIV_DEBUG /** The count of the types of locks. */ staticconst ulint lock_types = UT_ARR_SIZE(lock_compatibility_matrix); #endif/* UNIV_DEBUG */
/*********************************************************************//**
Gets the previous record lock set on a record.
@return previous lock on the same record, NULL if none exists */ const lock_t*
lock_rec_get_prev( /*==============*/ const lock_t* in_lock,/*!< in: record lock */
ulint heap_no);/*!< in: heap number of the record */
/*********************************************************************//**
Checks if some transaction has an implicit x-lock on a record in a clustered
index.
@return transaction id of the transaction which has the x-lock, or0 */
UNIV_INLINE
trx_id_t
lock_clust_rec_some_has_impl( /*=========================*/ const rec_t* rec, /*!< in: user record */ const dict_index_t* index, /*!< in: clustered index */ const rec_offs* offsets)/*!< in: rec_get_offsets(rec, index) */
MY_ATTRIBUTE((warn_unused_result));
/*********************************************************************//**
Gets the first or next record lock on a page.
@return next lock, NULL if none exists */
UNIV_INLINE const lock_t*
lock_rec_get_next_on_page_const( /*============================*/ const lock_t* lock); /*!< in: a record lock */
/*********************************************************************//**
Gets the nth bit of a record lock.
@returnTRUEif bit set also if i == ULINT_UNDEFINED returnFALSE*/
UNIV_INLINE
ibool
lock_rec_get_nth_bit( /*=================*/ const lock_t* lock, /*!< in: record lock */
ulint i); /*!< in: index of the bit */
/*********************************************************************//**
Gets the number of bits in a record lock bitmap.
@return number of bits */
UNIV_INLINE
ulint
lock_rec_get_n_bits( /*================*/ const lock_t* lock); /*!< in: record lock */
/**********************************************************************//**
Sets the nth bit of a record lock to TRUE. */ inline void
lock_rec_set_nth_bit( /*=================*/
lock_t* lock, /*!< in: record lock */
ulint i); /*!< in: index of the bit */
/** Reset the nth bit of a record lock. @param[in,out]lockrecordlock @param[in]iindexofthebitthatwillbereset
@return previous value of the bit */ inline byte lock_rec_reset_nth_bit(lock_t* lock, ulint i)
{
ut_ad(!lock->is_table()); #ifdef SUX_LOCK_GENERIC
ut_ad(lock_sys.is_writer() || lock->trx->mutex_is_owner()
|| lock_sys.is_cell_locked(*lock)); #else
ut_ad(lock_sys.is_writer() || lock->trx->mutex_is_owner()
|| lock_sys.is_cell_locked(*lock)
|| (xtest() && !lock->trx->mutex_is_locked())); #endif
ut_ad(i < lock->un_member.rec_lock.n_bits);
byte* b = reinterpret_cast<byte*>(&lock[1]) + (i >> 3);
byte mask = byte(1U << (i & 7));
byte bit = *b & mask;
*b &= byte(~mask);
if (bit != 0) {
ut_d(auto n=)
lock->trx->lock.n_rec_locks--;
ut_ad(n);
}
return(bit);
}
/** Gets the first or next record lock on a page. @paramlockarecordlock
@return next lock, NULL if none exists */
UNIV_INLINE
lock_t *lock_rec_get_next_on_page(const lock_t *lock);
/*********************************************************************//**
Gets the next explicit lock request on a record.
@return next lock, NULL if none exists orif heap_no == ULINT_UNDEFINED */
UNIV_INLINE
lock_t*
lock_rec_get_next( /*==============*/
ulint heap_no,/*!< in: heap number of the record */
lock_t* lock); /*!< in: lock */
/*********************************************************************//**
Gets the next explicit lock request on a record.
@return next lock, NULL if none exists orif heap_no == ULINT_UNDEFINED */
UNIV_INLINE const lock_t*
lock_rec_get_next_const( /*====================*/
ulint heap_no,/*!< in: heap number of the record */ const lock_t* lock); /*!< in: lock */
/** Get the first explicit lock request on a record. @paramcellfirstlockhashtablecell @paramidpageidentifier @paramheap_norecordidentifierinpage @returnfirstlock
@retval nullptr if none exists */ inline lock_t *lock_sys_t::get_first(const hash_cell_t &cell, page_id_t id,
ulint heap_no)
{
lock_sys.assert_locked(cell);
for (lock_t *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 &&
lock_rec_get_nth_bit(lock, heap_no)) return lock;
} return nullptr;
}
/*********************************************************************//**
Calculates if lock mode 1 is compatible with lock mode 2.
@return nonzero if mode1 compatible with mode2 */
UNIV_INLINE
ulint
lock_mode_compatible( /*=================*/ enum lock_mode mode1, /*!< in: lock mode */ enum lock_mode mode2); /*!< in: lock mode */
/*********************************************************************//**
Calculates if lock mode 1 is stronger or equal to lock mode 2.
@return nonzero if mode1 stronger or equal to mode2 */
UNIV_INLINE
ulint
lock_mode_stronger_or_eq( /*=====================*/ enum lock_mode mode1, /*!< in: lock mode */ enum lock_mode mode2); /*!< in: lock mode */
/*********************************************************************//**
Checks if a transaction has the specified table lock, or stronger. This
function should only be called by the thread that owns the transaction.
@return lock or NULL */
UNIV_INLINE const lock_t*
lock_table_has( /*===========*/ const trx_t* trx, /*!< in: transaction */ const dict_table_t* table, /*!< in: table */ enum lock_mode mode); /*!< in: lock mode */
#include"lock0priv.inl"
#endif/* lock0priv_h */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.19 Sekunden
(vorverarbeitet am 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.