📄 lock0lock.h
字号:
/*************************************************************************Checks if locks of other transactions prevent an immediate read, or passingover by a read cursor, of a clustered index record. If they do, first testsif the query thread should anyway be suspended for some reason; if not, thenputs the transaction and the query thread to the lock wait state and inserts awaiting request for a record lock to the lock queue. Sets the requested modelock on the record. This is an alternative version oflock_clust_rec_read_check_and_lock() that does not require the parameter"offsets". */ulintlock_clust_rec_read_check_and_lock_alt(/*===================================*/ /* out: DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, does nothing */ rec_t* rec, /* in: user record or page supremum record which should be read or passed over by a read cursor */ dict_index_t* index, /* in: clustered index */ ulint mode, /* in: mode of the lock which the read cursor should set on records: LOCK_S or LOCK_X; the latter is possible in SELECT FOR UPDATE */ ulint gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or LOCK_REC_NOT_GAP */ que_thr_t* thr); /* in: query thread *//*************************************************************************Checks that a record is seen in a consistent read. */iboollock_clust_rec_cons_read_sees(/*==========================*/ /* out: TRUE if sees, or FALSE if an earlier version of the record should be retrieved */ rec_t* rec, /* in: user record which should be read or passed over by a read cursor */ dict_index_t* index, /* in: clustered index */ const ulint* offsets,/* in: rec_get_offsets(rec, index) */ read_view_t* view); /* in: consistent read view *//*************************************************************************Checks that a non-clustered index record is seen in a consistent read. */ulintlock_sec_rec_cons_read_sees(/*========================*/ /* out: TRUE if certainly sees, or FALSE if an earlier version of the clustered index record might be needed: NOTE that a non-clustered index page contains so little information on its modifications that also in the case FALSE, the present version of rec may be the right, but we must check this from the clustered index record */ rec_t* rec, /* in: user record which should be read or passed over by a read cursor */ dict_index_t* index, /* in: non-clustered index */ read_view_t* view); /* in: consistent read view *//*************************************************************************Locks the specified database table in the mode given. If the lock cannotbe granted immediately, the query thread is put to wait. */ulintlock_table(/*=======*/ /* out: DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, does nothing */ dict_table_t* table, /* in: database table in dictionary cache */ ulint mode, /* in: lock mode */ que_thr_t* thr); /* in: query thread *//*************************************************************************Checks if there are any locks set on the table. */iboollock_is_on_table(/*=============*/ /* out: TRUE if there are lock(s) */ dict_table_t* table); /* in: database table in dictionary cache *//*****************************************************************Removes a granted record lock of a transaction from the queue and grantslocks to other transactions waiting in the queue if they now are entitledto a lock. */voidlock_rec_unlock(/*============*/ trx_t* trx, /* in: transaction that has set a record lock */ rec_t* rec, /* in: record */ ulint lock_mode); /* in: LOCK_S or LOCK_X *//*************************************************************************Releases a table lock.Releases possible other transactions waiting for this lock. */voidlock_table_unlock(/*==============*/ lock_t* lock); /* in: lock *//*************************************************************************Releases an auto-inc lock a transaction possibly has on a table.Releases possible other transactions waiting for this lock. */voidlock_table_unlock_auto_inc(/*=======================*/ trx_t* trx); /* in: transaction *//*************************************************************************Releases transaction locks, and releases possible other transactions waitingbecause of these locks. */voidlock_release_off_kernel(/*====================*/ trx_t* trx); /* in: transaction *//*************************************************************************Cancels a waiting lock request and releases possible other transactionswaiting behind it. */voidlock_cancel_waiting_and_release(/*============================*/ lock_t* lock); /* in: waiting lock request *//*************************************************************************Resets all locks, both table and record locks, on a table to be dropped.No lock is allowed to be a wait lock. */voidlock_reset_all_on_table(/*====================*/ dict_table_t* table); /* in: table to be dropped *//*************************************************************************Calculates the fold value of a page file address: used in inserting orsearching for a lock in the hash table. */UNIV_INLINEulintlock_rec_fold(/*===========*/ /* out: folded value */ ulint space, /* in: space */ ulint page_no);/* in: page number *//*************************************************************************Calculates the hash value of a page file address: used in inserting orsearching for a lock in the hash table. */UNIV_INLINEulintlock_rec_hash(/*==========*/ /* out: hashed value */ ulint space, /* in: space */ ulint page_no);/* in: page number *//*************************************************************************Gets the source table of an ALTER TABLE transaction. The table must becovered by an IX or IS table lock. */dict_table_t*lock_get_src_table(/*===============*/ /* out: the source table of transaction, if it is covered by an IX or IS table lock; dest if there is no source table, and NULL if the transaction is locking more than two tables or an inconsistency is found */ trx_t* trx, /* in: transaction */ dict_table_t* dest, /* in: destination of ALTER TABLE */ ulint* mode); /* out: lock mode of the source table *//*************************************************************************Determine if the given table is exclusively "owned" by the giventransaction, i.e., transaction holds LOCK_IX and possibly LOCK_AUTO_INCon the table. */iboollock_is_table_exclusive(/*====================*/ /* out: TRUE if table is only locked by trx, with LOCK_IX, and possibly LOCK_AUTO_INC */ dict_table_t* table, /* in: table */ trx_t* trx); /* in: transaction *//*************************************************************************Checks that a transaction id is sensible, i.e., not in the future. */iboollock_check_trx_id_sanity(/*=====================*/ /* out: TRUE if ok */ dulint trx_id, /* in: trx id */ rec_t* rec, /* in: user record */ dict_index_t* index, /* in: clustered index */ const ulint* offsets, /* in: rec_get_offsets(rec, index) */ ibool has_kernel_mutex);/* in: TRUE if the caller owns the kernel mutex *//*************************************************************************Validates the lock queue on a single record. */iboollock_rec_queue_validate(/*====================*/ /* out: TRUE if ok */ rec_t* rec, /* in: record to look at */ dict_index_t* index, /* in: index, or NULL if not known */ const ulint* offsets);/* in: rec_get_offsets(rec, index) *//*************************************************************************Prints info of a table lock. */voidlock_table_print(/*=============*/ FILE* file, /* in: file where to print */ lock_t* lock); /* in: table type lock *//*************************************************************************Prints info of a record lock. */voidlock_rec_print(/*===========*/ FILE* file, /* in: file where to print */ lock_t* lock); /* in: record type lock *//*************************************************************************Prints info of locks for all transactions. */voidlock_print_info_summary(/*====================*/ FILE* file); /* in: file where to print *//*************************************************************************Prints info of locks for each transaction. */voidlock_print_info_all_transactions(/*=============================*/ FILE* file); /* in: file where to print *//*************************************************************************Validates the lock queue on a table. */iboollock_table_queue_validate(/*======================*/ /* out: TRUE if ok */ dict_table_t* table); /* in: table *//*************************************************************************Validates the record lock queues on a page. */iboollock_rec_validate_page(/*===================*/ /* out: TRUE if ok */ ulint space, /* in: space id */ ulint page_no);/* in: page number *//*************************************************************************Validates the lock system. */iboollock_validate(void);/*===============*/ /* out: TRUE if ok *//* The lock system */extern lock_sys_t* lock_sys;/* Lock modes and types *//* Basic modes */#define LOCK_NONE 0 /* this flag is used elsewhere to note consistent read */#define LOCK_IS 2 /* intention shared */#define LOCK_IX 3 /* intention exclusive */#define LOCK_S 4 /* shared */#define LOCK_X 5 /* exclusive */#define LOCK_AUTO_INC 6 /* locks the auto-inc counter of a table in an exclusive mode */#define LOCK_MODE_MASK 0xFUL /* mask used to extract mode from the type_mode field in a lock *//* Lock types */#define LOCK_TABLE 16 /* these type values should be so high that */#define LOCK_REC 32 /* they can be ORed to the lock mode */#define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the type_mode field in a lock *//* Waiting lock flag */#define LOCK_WAIT 256 /* this wait bit should be so high that it can be ORed to the lock mode and type; when this bit is set, it means that the lock has not yet been granted, it is just waiting for its turn in the wait queue *//* Precise modes */#define LOCK_ORDINARY 0 /* this flag denotes an ordinary next-key lock in contrast to LOCK_GAP or LOCK_REC_NOT_GAP */ #define LOCK_GAP 512 /* this gap bit should be so high that it can be ORed to the other flags; when this bit is set, it means that the lock holds only on the gap before the record; for instance, an x-lock on the gap does not give permission to modify the record on which the bit is set; locks of this type are created when records are removed from the index chain of records */#define LOCK_REC_NOT_GAP 1024 /* this bit means that the lock is only on the index record and does NOT block inserts to the gap before the index record; this is used in the case when we retrieve a record with a unique key, and is also used in locking plain SELECTs (not part of UPDATE or DELETE) when the user has set the READ COMMITTED isolation level */#define LOCK_INSERT_INTENTION 2048 /* this bit is set when we place a waiting gap type record lock request in order to let an insert of an index record to wait until there are no conflicting locks by other transactions on the gap; note that this flag remains set when the waiting lock is granted, or if the lock is inherited to a neighboring record */ /* When lock bits are reset, the following flags are available: */#define LOCK_RELEASE_WAIT 1#define LOCK_NOT_RELEASE_WAIT 2/* Lock operation struct */typedef struct lock_op_struct lock_op_t;struct lock_op_struct{ dict_table_t* table; /* table to be locked */ ulint mode; /* lock mode */};#define LOCK_OP_START 1#define LOCK_OP_COMPLETE 2/* The lock system struct */struct lock_sys_struct{ hash_table_t* rec_hash; /* hash table of the record locks */};/* The lock system */extern lock_sys_t* lock_sys;#ifndef UNIV_NONINL#include "lock0lock.ic"#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -