diff options
Diffstat (limited to 'storage/innobase/include/lock0lock.h')
-rw-r--r-- | storage/innobase/include/lock0lock.h | 389 |
1 files changed, 260 insertions, 129 deletions
diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index a6fafd95754..84050f374fb 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -34,38 +34,41 @@ Created 5/7/1996 Heikki Tuuri #include "dict0types.h" #include "que0types.h" #include "lock0types.h" -#include "read0types.h" #include "hash0hash.h" #include "srv0srv.h" #include "ut0vec.h" +#include "gis0rtree.h" +#include "lock0prdt.h" -#ifdef UNIV_DEBUG -extern ibool lock_print_waits; -#endif /* UNIV_DEBUG */ +// Forward declaration +class ReadView; /*********************************************************************//** Gets the size of a lock struct. -@return size in bytes */ -UNIV_INTERN +@return size in bytes */ ulint lock_get_size(void); /*===============*/ /*********************************************************************//** Creates the lock system at database start. */ -UNIV_INTERN void lock_sys_create( /*============*/ ulint n_cells); /*!< in: number of slots in lock hash table */ +/** Resize the lock hash table. +@param[in] n_cells number of slots in lock hash table */ +void +lock_sys_resize( + ulint n_cells); + /*********************************************************************//** Closes the lock system at database shutdown. */ -UNIV_INTERN void lock_sys_close(void); /*================*/ /*********************************************************************//** Gets the heap_no of the smallest user record on a page. -@return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */ +@return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */ UNIV_INLINE ulint lock_get_min_heap_no( @@ -76,7 +79,6 @@ 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. */ -UNIV_INTERN void lock_move_reorganize_page( /*======================*/ @@ -87,7 +89,6 @@ lock_move_reorganize_page( /*************************************************************//** Moves the explicit locks on user records to another page if a record list end is moved to another page. */ -UNIV_INTERN void lock_move_rec_list_end( /*===================*/ @@ -98,7 +99,6 @@ lock_move_rec_list_end( /*************************************************************//** Moves the explicit locks on user records to another page if a record list start is moved to another page. */ -UNIV_INTERN void lock_move_rec_list_start( /*=====================*/ @@ -114,7 +114,6 @@ lock_move_rec_list_start( were copied */ /*************************************************************//** Updates the lock table when a page is split to the right. */ -UNIV_INTERN void lock_update_split_right( /*====================*/ @@ -122,7 +121,6 @@ lock_update_split_right( const buf_block_t* left_block); /*!< in: left page */ /*************************************************************//** Updates the lock table when a page is merged to the right. */ -UNIV_INTERN void lock_update_merge_right( /*====================*/ @@ -142,7 +140,6 @@ root page, even though they do not make sense on other than leaf pages: the reason is that in a pessimistic update the infimum record of the root page will act as a dummy carrier of the locks of the record to be updated. */ -UNIV_INTERN void lock_update_root_raise( /*===================*/ @@ -151,7 +148,6 @@ lock_update_root_raise( /*************************************************************//** Updates the lock table when a page is copied to another and the original page is removed from the chain of leaf pages, except if page is the root! */ -UNIV_INTERN void lock_update_copy_and_discard( /*=========================*/ @@ -161,7 +157,6 @@ lock_update_copy_and_discard( NOT the root! */ /*************************************************************//** Updates the lock table when a page is split to the left. */ -UNIV_INTERN void lock_update_split_left( /*===================*/ @@ -169,7 +164,6 @@ lock_update_split_left( const buf_block_t* left_block); /*!< in: left page */ /*************************************************************//** Updates the lock table when a page is merged to the left. */ -UNIV_INTERN void lock_update_merge_left( /*===================*/ @@ -193,7 +187,6 @@ lock_update_split_and_merge( /*************************************************************//** Resets the original locks on heir and replaces them with gap type locks inherited from rec. */ -UNIV_INTERN void lock_rec_reset_and_inherit_gap_locks( /*=================================*/ @@ -209,7 +202,6 @@ lock_rec_reset_and_inherit_gap_locks( donating record */ /*************************************************************//** Updates the lock table when a page is discarded. */ -UNIV_INTERN void lock_update_discard( /*================*/ @@ -221,7 +213,6 @@ lock_update_discard( which will be discarded */ /*************************************************************//** Updates the lock table when a new user record is inserted. */ -UNIV_INTERN void lock_update_insert( /*===============*/ @@ -229,7 +220,6 @@ lock_update_insert( const rec_t* rec); /*!< in: the inserted record */ /*************************************************************//** Updates the lock table when a record is removed. */ -UNIV_INTERN void lock_update_delete( /*===============*/ @@ -242,7 +232,6 @@ 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. */ -UNIV_INTERN void lock_rec_store_on_page_infimum( /*===========================*/ @@ -255,7 +244,6 @@ lock_rec_store_on_page_infimum( /*********************************************************************//** Restores the state of explicit lock requests on a single record, where the state was stored on the infimum of the page. */ -UNIV_INTERN void lock_rec_restore_from_page_infimum( /*===============================*/ @@ -269,8 +257,7 @@ lock_rec_restore_from_page_infimum( the infimum */ /*********************************************************************//** Determines if there are explicit record locks on a page. -@return an explicit record lock on the page, or NULL if there are none */ -UNIV_INTERN +@return an explicit record lock on the page, or NULL if there are none */ lock_t* lock_rec_expl_exist_on_page( /*========================*/ @@ -283,8 +270,7 @@ a record. If they do, first tests if the query thread should anyway be suspended for some reason; if not, 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, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN +@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ dberr_t lock_rec_insert_check_and_lock( /*===========================*/ @@ -300,6 +286,82 @@ lock_rec_insert_check_and_lock( LOCK_GAP type locks from the successor record */ MY_ATTRIBUTE((nonnull(2,3,4,6,7), warn_unused_result)); + +/*********************************************************************//** +Enqueues a waiting request for a lock which cannot be granted immediately. +Checks for deadlocks. +@return DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED, or +DB_SUCCESS_LOCKED_REC; DB_SUCCESS_LOCKED_REC means that +there was a deadlock, but another transaction was chosen as a victim, +and we got the lock immediately: no need to wait then */ +dberr_t +lock_rec_enqueue_waiting( +/*=====================*/ + ulint type_mode,/*!< in: lock mode this + transaction is requesting: + LOCK_S or LOCK_X, possibly + ORed with LOCK_GAP or + LOCK_REC_NOT_GAP, ORed with + LOCK_INSERT_INTENTION if this + waiting lock request is set + when performing an insert of + an index record */ + const buf_block_t* block, /*!< in: buffer block containing + the record */ + ulint heap_no,/*!< in: heap number of the record */ + dict_index_t* index, /*!< in: index of record */ + que_thr_t* thr, /*!< in: query thread */ + lock_prdt_t* prdt); /*!< in: Minimum Bounding Box */ + +/*************************************************************//** +Removes a record lock request, waiting or granted, from the queue and +grants locks to other transactions in the queue if they now are entitled +to a lock. NOTE: all record locks contained in in_lock are removed. */ +void +lock_rec_dequeue_from_page( +/*=======================*/ + lock_t* in_lock); /*!< in: record lock object: all + record locks which are contained in + this lock object are removed; + transactions waiting behind will + get their lock requests granted, + if they are now qualified to it */ + +/*************************************************************//** +Moves the locks of a record to another record and resets the lock bits of +the donating record. */ +UNIV_INLINE +void +lock_rec_move( +/*==========*/ + const buf_block_t* receiver, /*!< in: buffer block containing + the receiving record */ + const buf_block_t* donator, /*!< in: buffer block containing + the donating record */ + ulint receiver_heap_no,/*!< in: heap_no of the record + which gets the locks; there + must be no lock requests + on it! */ + ulint donator_heap_no);/*!< in: heap_no of the record + which gives the locks */ + +/*************************************************************//** +Moves the locks of a record to another record and resets the lock bits of +the donating record. */ +void +lock_rec_move_low( +/*==============*/ + hash_table_t* lock_hash, /*!< in: hash table to use */ + const buf_block_t* receiver, /*!< in: buffer block containing + the receiving record */ + const buf_block_t* donator, /*!< in: buffer block containing + the donating record */ + ulint receiver_heap_no,/*!< in: heap_no of the record + which gets the locks; there + must be no lock requests + on it! */ + ulint donator_heap_no);/*!< in: heap_no of the record + which gives the locks */ /*********************************************************************//** Checks if locks of other transactions prevent an immediate modify (update, delete mark, or delete unmark) of a clustered index record. If they do, @@ -307,8 +369,7 @@ first tests if the query thread should anyway be suspended for some reason; if not, 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, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN +@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ dberr_t lock_clust_rec_modify_check_and_lock( /*=================================*/ @@ -324,8 +385,7 @@ lock_clust_rec_modify_check_and_lock( /*********************************************************************//** Checks if locks of other transactions prevent an immediate modify (delete mark or delete unmark) of a secondary index record. -@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN +@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ dberr_t lock_sec_rec_modify_check_and_lock( /*===============================*/ @@ -345,9 +405,8 @@ lock_sec_rec_modify_check_and_lock( /*********************************************************************//** Like lock_clust_rec_read_check_and_lock(), but reads a secondary index record. -@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK, +@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN dberr_t lock_sec_rec_read_check_and_lock( /*=============================*/ @@ -360,7 +419,7 @@ lock_sec_rec_read_check_and_lock( read cursor */ dict_index_t* index, /*!< in: secondary index */ const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */ - enum lock_mode mode, /*!< in: mode of the lock which + lock_mode mode, /*!< in: mode of the lock which the read cursor should set on records: LOCK_S or LOCK_X; the latter is possible in @@ -375,9 +434,8 @@ if the query thread should anyway be suspended for some reason; if not, 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, DB_DEADLOCK, +@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN dberr_t lock_clust_rec_read_check_and_lock( /*===============================*/ @@ -390,7 +448,7 @@ lock_clust_rec_read_check_and_lock( read cursor */ dict_index_t* index, /*!< in: clustered index */ const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */ - enum lock_mode mode, /*!< in: mode of the lock which + lock_mode mode, /*!< in: mode of the lock which the read cursor should set on records: LOCK_S or LOCK_X; the latter is possible in @@ -407,8 +465,7 @@ 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, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN +@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ dberr_t lock_clust_rec_read_check_and_lock_alt( /*===================================*/ @@ -420,7 +477,7 @@ lock_clust_rec_read_check_and_lock_alt( be read or passed over by a read cursor */ dict_index_t* index, /*!< in: clustered index */ - enum lock_mode mode, /*!< in: mode of the lock which + lock_mode mode, /*!< in: mode of the lock which the read cursor should set on records: LOCK_S or LOCK_X; the latter is possible in @@ -433,7 +490,6 @@ lock_clust_rec_read_check_and_lock_alt( Checks that a record is seen in a consistent read. @return true if sees, or false if an earlier version of the record should be retrieved */ -UNIV_INTERN bool lock_clust_rec_cons_read_sees( /*==========================*/ @@ -441,7 +497,7 @@ lock_clust_rec_cons_read_sees( 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 */ + ReadView* view); /*!< in: consistent read view */ /*********************************************************************//** Checks that a non-clustered index record is seen in a consistent read. @@ -452,20 +508,18 @@ record. @return true if certainly sees, or false if an earlier version of the clustered index record might be needed */ -UNIV_INTERN bool lock_sec_rec_cons_read_sees( /*========================*/ - const rec_t* rec, /*!< in: user record which - should be read or passed over - by a read cursor */ - const read_view_t* view) /*!< in: consistent read view */ - MY_ATTRIBUTE((nonnull, warn_unused_result)); + const rec_t* rec, /*!< in: user record which should be read or + passed over by a read cursor */ + const dict_index_t* index, /*!< in: clustered index */ + const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */ + const ReadView* view); /*!< in: consistent read view */ /*********************************************************************//** Locks the specified database table in the mode given. If the lock cannot be granted immediately, the query thread is put to wait. -@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ -UNIV_INTERN +@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ dberr_t lock_table( /*=======*/ @@ -473,12 +527,11 @@ lock_table( does nothing */ dict_table_t* table, /*!< in/out: database table in dictionary cache */ - enum lock_mode mode, /*!< in: lock mode */ + lock_mode mode, /*!< in: lock mode */ que_thr_t* thr) /*!< in: query thread */ MY_ATTRIBUTE((nonnull, warn_unused_result)); /*********************************************************************//** Creates a table IX lock object for a resurrected transaction. */ -UNIV_INTERN void lock_table_ix_resurrect( /*====================*/ @@ -488,7 +541,6 @@ lock_table_ix_resurrect( 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. */ -UNIV_INTERN void lock_rec_unlock( /*============*/ @@ -496,12 +548,11 @@ lock_rec_unlock( set a record lock */ const buf_block_t* block, /*!< in: buffer block containing rec */ const rec_t* rec, /*!< in: record */ - enum lock_mode lock_mode);/*!< in: LOCK_S or LOCK_X */ + lock_mode lock_mode);/*!< in: LOCK_S or LOCK_X */ /*********************************************************************//** Releases a transaction's locks, and releases possible other transactions waiting because of these locks. Change the state of the transaction to TRX_STATE_COMMITTED_IN_MEMORY. */ -UNIV_INTERN void lock_trx_release_locks( /*===================*/ @@ -511,7 +562,6 @@ Removes locks on a table to be dropped or truncated. If remove_also_table_sx_locks is TRUE then table-level S and X locks are also removed in addition to other table-level and record-level locks. No lock, that is going to be removed, is allowed to be a wait lock. */ -UNIV_INTERN void lock_remove_all_on_table( /*=====================*/ @@ -523,7 +573,7 @@ lock_remove_all_on_table( /*********************************************************************//** Calculates the fold value of a page file address: used in inserting or searching for a lock in the hash table. -@return folded value */ +@return folded value */ UNIV_INLINE ulint lock_rec_fold( @@ -534,7 +584,7 @@ lock_rec_fold( /*********************************************************************//** Calculates the hash value of a page file address: used in inserting or searching for a lock in the hash table. -@return hashed value */ +@return hashed value */ UNIV_INLINE ulint lock_rec_hash( @@ -542,12 +592,19 @@ lock_rec_hash( ulint space, /*!< in: space */ ulint page_no);/*!< in: page number */ +/*************************************************************//** +Get the lock hash table */ +UNIV_INLINE +hash_table_t* +lock_hash_get( +/*==========*/ + ulint mode); /*!< in: lock mode */ + /**********************************************************************//** 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 */ -UNIV_INTERN ulint lock_rec_find_set_bit( /*==================*/ @@ -561,20 +618,18 @@ covered by an IX or IS table lock. 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 */ -UNIV_INTERN dict_table_t* lock_get_src_table( /*===============*/ trx_t* trx, /*!< in: transaction */ dict_table_t* dest, /*!< in: destination of ALTER TABLE */ - enum lock_mode* mode); /*!< out: lock mode of the source table */ + lock_mode* mode); /*!< out: lock mode of the source table */ /*********************************************************************//** Determine if the given table is exclusively "owned" by the given transaction, i.e., transaction holds LOCK_IX and possibly LOCK_AUTO_INC on the table. @return TRUE if table is only locked by trx, with LOCK_IX, and possibly LOCK_AUTO_INC */ -UNIV_INTERN ibool lock_is_table_exclusive( /*====================*/ @@ -583,8 +638,7 @@ lock_is_table_exclusive( MY_ATTRIBUTE((nonnull)); /*********************************************************************//** Checks if a lock request lock1 has to wait for request lock2. -@return TRUE if lock1 has to wait for lock2 to be removed */ -UNIV_INTERN +@return TRUE if lock1 has to wait for lock2 to be removed */ ibool lock_has_to_wait( /*=============*/ @@ -595,7 +649,6 @@ lock_has_to_wait( locks are record locks */ /*********************************************************************//** Reports that a transaction id is insensible, i.e., in the future. */ -UNIV_INTERN void lock_report_trx_id_insanity( /*========================*/ @@ -603,11 +656,9 @@ lock_report_trx_id_insanity( const rec_t* rec, /*!< in: user record */ dict_index_t* index, /*!< in: index */ const ulint* offsets, /*!< in: rec_get_offsets(rec, index) */ - trx_id_t max_trx_id) /*!< in: trx_sys_get_max_trx_id() */ - MY_ATTRIBUTE((nonnull)); + trx_id_t max_trx_id); /*!< in: trx_sys_get_max_trx_id() */ /*********************************************************************//** Prints info of a table lock. */ -UNIV_INTERN void lock_table_print( /*=============*/ @@ -615,7 +666,6 @@ lock_table_print( const lock_t* lock); /*!< in: table type lock */ /*********************************************************************//** Prints info of a record lock. */ -UNIV_INTERN void lock_rec_print( /*===========*/ @@ -625,18 +675,25 @@ lock_rec_print( Prints info of locks for all transactions. @return FALSE if not able to obtain lock mutex and exits without printing info */ -UNIV_INTERN ibool lock_print_info_summary( /*====================*/ FILE* file, /*!< in: file where to print */ ibool nowait) /*!< in: whether to wait for the lock mutex */ MY_ATTRIBUTE((nonnull, warn_unused_result)); + +/** Prints transaction lock wait and MVCC state. +@param[in,out] file file where to print +@param[in] trx transaction */ +void +lock_trx_print_wait_and_mvcc_state( + FILE* file, + const trx_t* trx); + /*********************************************************************//** Prints info of locks for each transaction. This function assumes that the caller holds the lock mutex and more importantly it will release the lock mutex on behalf of the caller. (This should be fixed in the future). */ -UNIV_INTERN void lock_print_info_all_transactions( /*=============================*/ @@ -646,18 +703,25 @@ Return approximate number or record locks (bits set in the bitmap) for this transaction. Since delete-marked records may be removed, the record count will not be precise. The caller must be holding lock_sys->mutex. */ -UNIV_INTERN ulint lock_number_of_rows_locked( /*=======================*/ const trx_lock_t* trx_lock) /*!< in: transaction locks */ MY_ATTRIBUTE((nonnull, warn_unused_result)); +/*********************************************************************//** +Return the number of table locks for a transaction. +The caller must be holding lock_sys->mutex. */ +ulint +lock_number_of_tables_locked( +/*=========================*/ + const trx_lock_t* trx_lock) /*!< in: transaction locks */ + __attribute__((warn_unused_result)); + /*******************************************************************//** Gets the type of a lock. Non-inline version for using outside of the lock module. -@return LOCK_TABLE or LOCK_REC */ -UNIV_INTERN +@return LOCK_TABLE or LOCK_REC */ ulint lock_get_type( /*==========*/ @@ -675,8 +739,7 @@ lock_get_trx( /*******************************************************************//** Gets the id of the transaction owning a lock. -@return transaction id */ -UNIV_INTERN +@return transaction id */ trx_id_t lock_get_trx_id( /*============*/ @@ -685,8 +748,7 @@ lock_get_trx_id( /*******************************************************************//** Gets the mode of a lock in a human readable string. The string should not be free()'d or modified. -@return lock mode */ -UNIV_INTERN +@return lock mode */ const char* lock_get_mode_str( /*==============*/ @@ -695,8 +757,7 @@ lock_get_mode_str( /*******************************************************************//** Gets the type of a lock in a human readable string. The string should not be free()'d or modified. -@return lock type */ -UNIV_INTERN +@return lock type */ const char* lock_get_type_str( /*==============*/ @@ -704,27 +765,22 @@ lock_get_type_str( /*******************************************************************//** Gets the id of the table on which the lock is. -@return id of the table */ -UNIV_INTERN +@return id of the table */ table_id_t lock_get_table_id( /*==============*/ const lock_t* lock); /*!< in: lock */ -/*******************************************************************//** -Gets the name of the table on which the lock is. -The string should not be free()'d or modified. -@return name of the table */ -UNIV_INTERN -const char* +/** Determine which table a lock is associated with. +@param[in] lock the lock +@return name of the table */ +const table_name_t& lock_get_table_name( -/*================*/ - const lock_t* lock); /*!< in: lock */ + const lock_t* lock); /*******************************************************************//** For a record lock, gets the index on which the lock is. -@return index */ -UNIV_INTERN +@return index */ const dict_index_t* lock_rec_get_index( /*===============*/ @@ -733,8 +789,7 @@ lock_rec_get_index( /*******************************************************************//** For a record lock, gets the name of the index on which the lock is. The string should not be free()'d or modified. -@return name of the index */ -UNIV_INTERN +@return name of the index */ const char* lock_rec_get_index_name( /*====================*/ @@ -742,8 +797,7 @@ lock_rec_get_index_name( /*******************************************************************//** For a record lock, gets the tablespace number on which the lock is. -@return tablespace number */ -UNIV_INTERN +@return tablespace number */ ulint lock_rec_get_space_id( /*==================*/ @@ -751,17 +805,15 @@ lock_rec_get_space_id( /*******************************************************************//** For a record lock, gets the page number on which the lock is. -@return page number */ -UNIV_INTERN +@return page number */ ulint lock_rec_get_page_no( /*=================*/ const lock_t* lock); /*!< in: lock */ /*******************************************************************//** Check if there are any locks (table or rec) against table. -@return TRUE if locks exist */ -UNIV_INTERN -ibool +@return TRUE if locks exist */ +bool lock_table_has_locks( /*=================*/ const dict_table_t* table); /*!< in: check if there are any locks @@ -770,8 +822,8 @@ lock_table_has_locks( /*********************************************************************//** A thread which wakes up threads whose lock wait may have lasted too long. -@return a dummy parameter */ -extern "C" UNIV_INTERN +@return a dummy parameter */ +extern "C" os_thread_ret_t DECLARE_THREAD(lock_wait_timeout_thread)( /*=====================================*/ @@ -781,7 +833,6 @@ DECLARE_THREAD(lock_wait_timeout_thread)( /********************************************************************//** Releases a user OS thread waiting for a lock to be released, if the thread is already suspended. */ -UNIV_INTERN void lock_wait_release_thread_if_suspended( /*==================================*/ @@ -794,7 +845,6 @@ occurs during the wait trx->error_state associated with thr is != DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK are possible errors. DB_DEADLOCK is returned if selective deadlock resolution chose this transaction as a victim. */ -UNIV_INTERN void lock_wait_suspend_thread( /*=====================*/ @@ -804,7 +854,6 @@ lock_wait_suspend_thread( 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). */ -UNIV_INTERN void lock_unlock_table_autoinc( /*======================*/ @@ -814,26 +863,36 @@ Check whether the transaction has already been rolled back because it was selected as a deadlock victim, or if it has to wait then cancel the wait lock. @return DB_DEADLOCK, DB_LOCK_WAIT or DB_SUCCESS */ -UNIV_INTERN dberr_t lock_trx_handle_wait( /*=================*/ - trx_t* trx) /*!< in/out: trx lock state */ - MY_ATTRIBUTE((nonnull)); + trx_t* trx, /*!< in/out: trx lock state */ + bool lock_mutex_taken, + bool trx_mutex_taken) + MY_ATTRIBUTE((nonnull(1), warn_unused_result)); /*********************************************************************//** Get the number of locks on a table. @return number of locks */ -UNIV_INTERN ulint lock_table_get_n_locks( /*===================*/ - const dict_table_t* table) /*!< in: table */ - MY_ATTRIBUTE((nonnull)); + const dict_table_t* table); /*!< in: table */ +/*******************************************************************//** +Initialise the trx lock list. */ +void +lock_trx_lock_list_init( +/*====================*/ + trx_lock_list_t* lock_list); /*!< List to initialise */ + +/*******************************************************************//** +Set the lock system timeout event. */ +void +lock_set_timeout_event(); +/*====================*/ #ifdef UNIV_DEBUG /*********************************************************************//** Checks that a transaction id is sensible, i.e., not in the future. -@return true if ok */ -UNIV_INTERN +@return true if ok */ bool lock_check_trx_id_sanity( /*=====================*/ @@ -845,8 +904,7 @@ lock_check_trx_id_sanity( /*******************************************************************//** Check if the transaction holds any locks on the sys tables or its records. -@return the strongest lock found on any sys table or 0 for none */ -UNIV_INTERN +@return the strongest lock found on any sys table or 0 for none */ const lock_t* lock_trx_has_sys_table_locks( /*=========================*/ @@ -855,8 +913,7 @@ lock_trx_has_sys_table_locks( /*******************************************************************//** Check if the transaction holds an exclusive lock on a record. -@return whether the locks are held */ -UNIV_INTERN +@return whether the locks are held */ bool lock_trx_has_rec_x_lock( /*====================*/ @@ -867,6 +924,12 @@ lock_trx_has_rec_x_lock( MY_ATTRIBUTE((nonnull, warn_unused_result)); #endif /* UNIV_DEBUG */ +/** +Allocate cached locks for the transaction. +@param trx allocate cached record locks for this transaction */ +void +lock_trx_alloc_locks(trx_t* trx); + /** Lock modes and types */ /* @{ */ #define LOCK_MODE_MASK 0xFUL /*!< mask used to extract mode from the @@ -912,11 +975,14 @@ lock_trx_has_rec_x_lock( remains set when the waiting lock is granted, or if the lock is inherited to a neighboring record */ +#define LOCK_PREDICATE 8192 /*!< Predicate lock */ +#define LOCK_PRDT_PAGE 16384 /*!< Page lock */ + -#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION)&LOCK_MODE_MASK +#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_MODE_MASK # error #endif -#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION)&LOCK_TYPE_MASK +#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_TYPE_MASK # error #endif /* @} */ @@ -924,16 +990,28 @@ lock_trx_has_rec_x_lock( /** Lock operation struct */ struct lock_op_t{ dict_table_t* table; /*!< table to be locked */ - enum lock_mode mode; /*!< lock mode */ + lock_mode mode; /*!< lock mode */ }; +typedef ib_mutex_t LockMutex; + /** The lock system struct */ struct lock_sys_t{ - ib_mutex_t mutex; /*!< Mutex protecting the + char pad1[CACHE_LINE_SIZE]; /*!< padding to prevent other + memory update hotspots from + residing on the same memory + cache line */ + LockMutex mutex; /*!< Mutex protecting the locks */ hash_table_t* rec_hash; /*!< hash table of the record locks */ - ib_mutex_t wait_mutex; /*!< Mutex protecting the + hash_table_t* prdt_hash; /*!< hash table of the predicate + lock */ + hash_table_t* prdt_page_hash; /*!< hash table of the page + lock */ + + char pad2[CACHE_LINE_SIZE]; /*!< Padding */ + LockMutex wait_mutex; /*!< Mutex protecting the next two fields */ srv_slot_t* waiting_threads; /*!< Array of user threads suspended while waiting for @@ -960,14 +1038,56 @@ struct lock_sys_t{ is running */ }; +/*************************************************************//** +Removes a record lock request, waiting or granted, from the queue. */ +void +lock_rec_discard( +/*=============*/ + lock_t* in_lock); /*!< in: record lock object: all + record locks which are contained + in this lock object are removed */ + +/*************************************************************//** +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 */ + +/*************************************************************//** +Removes record lock objects set on an index page which is discarded. This +function does not move locks, or check for waiting locks, therefore the +lock bitmaps must already be reset when this function is called. */ +void +lock_rec_free_all_from_discard_page( +/*================================*/ + const buf_block_t* block); /*!< in: page to be discarded */ + +/** Reset the nth bit of a record lock. +@param[in,out] lock record lock +@param[in] i index of the bit that will be reset +@param[in] type whether the lock is in wait mode */ +void +lock_rec_trx_wait( + lock_t* lock, + ulint i, + ulint type); + /** The lock system */ extern lock_sys_t* lock_sys; /** Test if lock_sys->mutex can be acquired without waiting. */ -#define lock_mutex_enter_nowait() mutex_enter_nowait(&lock_sys->mutex) +#define lock_mutex_enter_nowait() \ + (lock_sys->mutex.trylock(__FILE__, __LINE__)) /** Test if lock_sys->mutex is owned. */ -#define lock_mutex_own() mutex_own(&lock_sys->mutex) +#define lock_mutex_own() (lock_sys->mutex.is_owned()) /** Acquire the lock_sys->mutex. */ #define lock_mutex_enter() do { \ @@ -976,11 +1096,11 @@ extern lock_sys_t* lock_sys; /** Release the lock_sys->mutex. */ #define lock_mutex_exit() do { \ - mutex_exit(&lock_sys->mutex); \ + lock_sys->mutex.exit(); \ } while (0) /** Test if lock_sys->wait_mutex is owned. */ -#define lock_wait_mutex_own() mutex_own(&lock_sys->wait_mutex) +#define lock_wait_mutex_own() (lock_sys->wait_mutex.is_owned()) /** Acquire the lock_sys->wait_mutex. */ #define lock_wait_mutex_enter() do { \ @@ -989,7 +1109,7 @@ extern lock_sys_t* lock_sys; /** Release the lock_sys->wait_mutex. */ #define lock_wait_mutex_exit() do { \ - mutex_exit(&lock_sys->wait_mutex); \ + lock_sys->wait_mutex.exit(); \ } while (0) #ifdef WITH_WSREP @@ -1009,6 +1129,17 @@ std::string lock_get_info( const lock_t*); +/*************************************************************//** +Updates the lock table when a page is split and merged to +two pages. */ +UNIV_INTERN +void +lock_update_split_and_merge( + const buf_block_t* left_block, /*!< in: left page to which merged */ + const rec_t* orig_pred, /*!< in: original predecessor of + supremum on the left page before merge*/ + const buf_block_t* right_block);/*!< in: right page from which merged */ + #endif /* WITH_WSREP */ #ifndef UNIV_NONINL #include "lock0lock.ic" |