00001 /****************************************************** 00002 The transaction lock system 00003 00004 (c) 1996 Innobase Oy 00005 00006 Created 5/7/1996 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef lock0lock_h 00010 #define lock0lock_h 00011 00012 #include "univ.i" 00013 #include "trx0types.h" 00014 #include "rem0types.h" 00015 #include "dict0types.h" 00016 #include "que0types.h" 00017 #include "page0types.h" 00018 #include "lock0types.h" 00019 #include "read0types.h" 00020 #include "hash0hash.h" 00021 00022 #ifdef UNIV_DEBUG 00023 extern ibool lock_print_waits; 00024 #endif /* UNIV_DEBUG */ 00025 /* Buffer for storing information about the most recent deadlock error */ 00026 extern FILE* lock_latest_err_file; 00027 00028 /************************************************************************* 00029 Gets the size of a lock struct. */ 00030 00031 ulint 00032 lock_get_size(void); 00033 /*===============*/ 00034 /* out: size in bytes */ 00035 /************************************************************************* 00036 Creates the lock system at database start. */ 00037 00038 void 00039 lock_sys_create( 00040 /*============*/ 00041 ulint n_cells); /* in: number of slots in lock hash table */ 00042 /************************************************************************* 00043 Checks if some transaction has an implicit x-lock on a record in a secondary 00044 index. */ 00045 00046 trx_t* 00047 lock_sec_rec_some_has_impl_off_kernel( 00048 /*==================================*/ 00049 /* out: transaction which has the x-lock, or 00050 NULL */ 00051 rec_t* rec, /* in: user record */ 00052 dict_index_t* index, /* in: secondary index */ 00053 const ulint* offsets);/* in: rec_get_offsets(rec, index) */ 00054 /************************************************************************* 00055 Checks if some transaction has an implicit x-lock on a record in a clustered 00056 index. */ 00057 UNIV_INLINE 00058 trx_t* 00059 lock_clust_rec_some_has_impl( 00060 /*=========================*/ 00061 /* out: transaction which has the x-lock, or 00062 NULL */ 00063 rec_t* rec, /* in: user record */ 00064 dict_index_t* index, /* in: clustered index */ 00065 const ulint* offsets);/* in: rec_get_offsets(rec, index) */ 00066 /***************************************************************** 00067 Makes a record to inherit the locks of another record as gap type 00068 locks, but does not reset the lock bits of the other record. Also 00069 waiting lock requests on rec are inherited as GRANTED gap locks. */ 00070 00071 void 00072 lock_rec_inherit_to_gap( 00073 /*====================*/ 00074 rec_t* heir, /* in: record which inherits */ 00075 rec_t* rec); /* in: record from which inherited; does NOT reset 00076 the locks on this record */ 00077 /***************************************************************** 00078 Updates the lock table when we have reorganized a page. NOTE: we copy 00079 also the locks set on the infimum of the page; the infimum may carry 00080 locks if an update of a record is occurring on the page, and its locks 00081 were temporarily stored on the infimum. */ 00082 00083 void 00084 lock_move_reorganize_page( 00085 /*======================*/ 00086 page_t* page, /* in: old index page */ 00087 page_t* new_page); /* in: reorganized page */ 00088 /***************************************************************** 00089 Moves the explicit locks on user records to another page if a record 00090 list end is moved to another page. */ 00091 00092 void 00093 lock_move_rec_list_end( 00094 /*===================*/ 00095 page_t* new_page, /* in: index page to move to */ 00096 page_t* page, /* in: index page */ 00097 rec_t* rec); /* in: record on page: this is the 00098 first record moved */ 00099 /***************************************************************** 00100 Moves the explicit locks on user records to another page if a record 00101 list start is moved to another page. */ 00102 00103 void 00104 lock_move_rec_list_start( 00105 /*=====================*/ 00106 page_t* new_page, /* in: index page to move to */ 00107 page_t* page, /* in: index page */ 00108 rec_t* rec, /* in: record on page: this is the 00109 first record NOT copied */ 00110 rec_t* old_end); /* in: old previous-to-last record on 00111 new_page before the records were copied */ 00112 /***************************************************************** 00113 Updates the lock table when a page is split to the right. */ 00114 00115 void 00116 lock_update_split_right( 00117 /*====================*/ 00118 page_t* right_page, /* in: right page */ 00119 page_t* left_page); /* in: left page */ 00120 /***************************************************************** 00121 Updates the lock table when a page is merged to the right. */ 00122 00123 void 00124 lock_update_merge_right( 00125 /*====================*/ 00126 rec_t* orig_succ, /* in: original successor of infimum 00127 on the right page before merge */ 00128 page_t* left_page); /* in: merged index page which will be 00129 discarded */ 00130 /***************************************************************** 00131 Updates the lock table when the root page is copied to another in 00132 btr_root_raise_and_insert. Note that we leave lock structs on the 00133 root page, even though they do not make sense on other than leaf 00134 pages: the reason is that in a pessimistic update the infimum record 00135 of the root page will act as a dummy carrier of the locks of the record 00136 to be updated. */ 00137 00138 void 00139 lock_update_root_raise( 00140 /*===================*/ 00141 page_t* new_page, /* in: index page to which copied */ 00142 page_t* root); /* in: root page */ 00143 /***************************************************************** 00144 Updates the lock table when a page is copied to another and the original page 00145 is removed from the chain of leaf pages, except if page is the root! */ 00146 00147 void 00148 lock_update_copy_and_discard( 00149 /*=========================*/ 00150 page_t* new_page, /* in: index page to which copied */ 00151 page_t* page); /* in: index page; NOT the root! */ 00152 /***************************************************************** 00153 Updates the lock table when a page is split to the left. */ 00154 00155 void 00156 lock_update_split_left( 00157 /*===================*/ 00158 page_t* right_page, /* in: right page */ 00159 page_t* left_page); /* in: left page */ 00160 /***************************************************************** 00161 Updates the lock table when a page is merged to the left. */ 00162 00163 void 00164 lock_update_merge_left( 00165 /*===================*/ 00166 page_t* left_page, /* in: left page to which merged */ 00167 rec_t* orig_pred, /* in: original predecessor of supremum 00168 on the left page before merge */ 00169 page_t* right_page); /* in: merged index page which will be 00170 discarded */ 00171 /***************************************************************** 00172 Resets the original locks on heir and replaces them with gap type locks 00173 inherited from rec. */ 00174 00175 void 00176 lock_rec_reset_and_inherit_gap_locks( 00177 /*=================================*/ 00178 rec_t* heir, /* in: heir record */ 00179 rec_t* rec); /* in: record */ 00180 /***************************************************************** 00181 Updates the lock table when a page is discarded. */ 00182 00183 void 00184 lock_update_discard( 00185 /*================*/ 00186 rec_t* heir, /* in: record which will inherit the locks */ 00187 page_t* page); /* in: index page which will be discarded */ 00188 /***************************************************************** 00189 Updates the lock table when a new user record is inserted. */ 00190 00191 void 00192 lock_update_insert( 00193 /*===============*/ 00194 rec_t* rec); /* in: the inserted record */ 00195 /***************************************************************** 00196 Updates the lock table when a record is removed. */ 00197 00198 void 00199 lock_update_delete( 00200 /*===============*/ 00201 rec_t* rec); /* in: the record to be removed */ 00202 /************************************************************************* 00203 Stores on the page infimum record the explicit locks of another record. 00204 This function is used to store the lock state of a record when it is 00205 updated and the size of the record changes in the update. The record 00206 is in such an update moved, perhaps to another page. The infimum record 00207 acts as a dummy carrier record, taking care of lock releases while the 00208 actual record is being moved. */ 00209 00210 void 00211 lock_rec_store_on_page_infimum( 00212 /*===========================*/ 00213 page_t* page, /* in: page containing the record */ 00214 rec_t* rec); /* in: record whose lock state is stored 00215 on the infimum record of the same page; lock 00216 bits are reset on the record */ 00217 /************************************************************************* 00218 Restores the state of explicit lock requests on a single record, where the 00219 state was stored on the infimum of the page. */ 00220 00221 void 00222 lock_rec_restore_from_page_infimum( 00223 /*===============================*/ 00224 rec_t* rec, /* in: record whose lock state is restored */ 00225 page_t* page); /* in: page (rec is not necessarily on this page) 00226 whose infimum stored the lock state; lock bits are 00227 reset on the infimum */ 00228 /************************************************************************* 00229 Returns TRUE if there are explicit record locks on a page. */ 00230 00231 ibool 00232 lock_rec_expl_exist_on_page( 00233 /*========================*/ 00234 /* out: TRUE if there are explicit record locks on 00235 the page */ 00236 ulint space, /* in: space id */ 00237 ulint page_no);/* in: page number */ 00238 /************************************************************************* 00239 Checks if locks of other transactions prevent an immediate insert of 00240 a record. If they do, first tests if the query thread should anyway 00241 be suspended for some reason; if not, then puts the transaction and 00242 the query thread to the lock wait state and inserts a waiting request 00243 for a gap x-lock to the lock queue. */ 00244 00245 ulint 00246 lock_rec_insert_check_and_lock( 00247 /*===========================*/ 00248 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00249 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00250 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00251 does nothing */ 00252 rec_t* rec, /* in: record after which to insert */ 00253 dict_index_t* index, /* in: index */ 00254 que_thr_t* thr, /* in: query thread */ 00255 ibool* inherit);/* out: set to TRUE if the new inserted 00256 record maybe should inherit LOCK_GAP type 00257 locks from the successor record */ 00258 /************************************************************************* 00259 Checks if locks of other transactions prevent an immediate modify (update, 00260 delete mark, or delete unmark) of a clustered index record. If they do, 00261 first tests if the query thread should anyway be suspended for some 00262 reason; if not, then puts the transaction and the query thread to the 00263 lock wait state and inserts a waiting request for a record x-lock to the 00264 lock queue. */ 00265 00266 ulint 00267 lock_clust_rec_modify_check_and_lock( 00268 /*=================================*/ 00269 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00270 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00271 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00272 does nothing */ 00273 rec_t* rec, /* in: record which should be modified */ 00274 dict_index_t* index, /* in: clustered index */ 00275 const ulint* offsets,/* in: rec_get_offsets(rec, index) */ 00276 que_thr_t* thr); /* in: query thread */ 00277 /************************************************************************* 00278 Checks if locks of other transactions prevent an immediate modify 00279 (delete mark or delete unmark) of a secondary index record. */ 00280 00281 ulint 00282 lock_sec_rec_modify_check_and_lock( 00283 /*===============================*/ 00284 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00285 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00286 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00287 does nothing */ 00288 rec_t* rec, /* in: record which should be modified; 00289 NOTE: as this is a secondary index, we 00290 always have to modify the clustered index 00291 record first: see the comment below */ 00292 dict_index_t* index, /* in: secondary index */ 00293 que_thr_t* thr); /* in: query thread */ 00294 /************************************************************************* 00295 Like the counterpart for a clustered index below, but now we read a 00296 secondary index record. */ 00297 00298 ulint 00299 lock_sec_rec_read_check_and_lock( 00300 /*=============================*/ 00301 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00302 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00303 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00304 does nothing */ 00305 rec_t* rec, /* in: user record or page supremum record 00306 which should be read or passed over by a read 00307 cursor */ 00308 dict_index_t* index, /* in: secondary index */ 00309 const ulint* offsets,/* in: rec_get_offsets(rec, index) */ 00310 ulint mode, /* in: mode of the lock which the read cursor 00311 should set on records: LOCK_S or LOCK_X; the 00312 latter is possible in SELECT FOR UPDATE */ 00313 ulint gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or 00314 LOCK_REC_NOT_GAP */ 00315 que_thr_t* thr); /* in: query thread */ 00316 /************************************************************************* 00317 Checks if locks of other transactions prevent an immediate read, or passing 00318 over by a read cursor, of a clustered index record. If they do, first tests 00319 if the query thread should anyway be suspended for some reason; if not, then 00320 puts the transaction and the query thread to the lock wait state and inserts a 00321 waiting request for a record lock to the lock queue. Sets the requested mode 00322 lock on the record. */ 00323 00324 ulint 00325 lock_clust_rec_read_check_and_lock( 00326 /*===============================*/ 00327 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00328 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00329 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00330 does nothing */ 00331 rec_t* rec, /* in: user record or page supremum record 00332 which should be read or passed over by a read 00333 cursor */ 00334 dict_index_t* index, /* in: clustered index */ 00335 const ulint* offsets,/* in: rec_get_offsets(rec, index) */ 00336 ulint mode, /* in: mode of the lock which the read cursor 00337 should set on records: LOCK_S or LOCK_X; the 00338 latter is possible in SELECT FOR UPDATE */ 00339 ulint gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or 00340 LOCK_REC_NOT_GAP */ 00341 que_thr_t* thr); /* in: query thread */ 00342 /************************************************************************* 00343 Checks if locks of other transactions prevent an immediate read, or passing 00344 over by a read cursor, of a clustered index record. If they do, first tests 00345 if the query thread should anyway be suspended for some reason; if not, then 00346 puts the transaction and the query thread to the lock wait state and inserts a 00347 waiting request for a record lock to the lock queue. Sets the requested mode 00348 lock on the record. This is an alternative version of 00349 lock_clust_rec_read_check_and_lock() that does not require the parameter 00350 "offsets". */ 00351 00352 ulint 00353 lock_clust_rec_read_check_and_lock_alt( 00354 /*===================================*/ 00355 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00356 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00357 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00358 does nothing */ 00359 rec_t* rec, /* in: user record or page supremum record 00360 which should be read or passed over by a read 00361 cursor */ 00362 dict_index_t* index, /* in: clustered index */ 00363 ulint mode, /* in: mode of the lock which the read cursor 00364 should set on records: LOCK_S or LOCK_X; the 00365 latter is possible in SELECT FOR UPDATE */ 00366 ulint gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or 00367 LOCK_REC_NOT_GAP */ 00368 que_thr_t* thr); /* in: query thread */ 00369 /************************************************************************* 00370 Checks that a record is seen in a consistent read. */ 00371 00372 ibool 00373 lock_clust_rec_cons_read_sees( 00374 /*==========================*/ 00375 /* out: TRUE if sees, or FALSE if an earlier 00376 version of the record should be retrieved */ 00377 rec_t* rec, /* in: user record which should be read or 00378 passed over by a read cursor */ 00379 dict_index_t* index, /* in: clustered index */ 00380 const ulint* offsets,/* in: rec_get_offsets(rec, index) */ 00381 read_view_t* view); /* in: consistent read view */ 00382 /************************************************************************* 00383 Checks that a non-clustered index record is seen in a consistent read. */ 00384 00385 ulint 00386 lock_sec_rec_cons_read_sees( 00387 /*========================*/ 00388 /* out: TRUE if certainly sees, or FALSE if an 00389 earlier version of the clustered index record 00390 might be needed: NOTE that a non-clustered 00391 index page contains so little information on 00392 its modifications that also in the case FALSE, 00393 the present version of rec may be the right, 00394 but we must check this from the clustered 00395 index record */ 00396 rec_t* rec, /* in: user record which should be read or 00397 passed over by a read cursor */ 00398 dict_index_t* index, /* in: non-clustered index */ 00399 read_view_t* view); /* in: consistent read view */ 00400 /************************************************************************* 00401 Locks the specified database table in the mode given. If the lock cannot 00402 be granted immediately, the query thread is put to wait. */ 00403 00404 ulint 00405 lock_table( 00406 /*=======*/ 00407 /* out: DB_SUCCESS, DB_LOCK_WAIT, 00408 DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ 00409 ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, 00410 does nothing */ 00411 dict_table_t* table, /* in: database table in dictionary cache */ 00412 ulint mode, /* in: lock mode */ 00413 que_thr_t* thr); /* in: query thread */ 00414 /************************************************************************* 00415 Checks if there are any locks set on the table. */ 00416 00417 ibool 00418 lock_is_on_table( 00419 /*=============*/ 00420 /* out: TRUE if there are lock(s) */ 00421 dict_table_t* table); /* in: database table in dictionary cache */ 00422 /***************************************************************** 00423 Removes a granted record lock of a transaction from the queue and grants 00424 locks to other transactions waiting in the queue if they now are entitled 00425 to a lock. */ 00426 00427 void 00428 lock_rec_unlock( 00429 /*============*/ 00430 trx_t* trx, /* in: transaction that has set a record 00431 lock */ 00432 rec_t* rec, /* in: record */ 00433 ulint lock_mode); /* in: LOCK_S or LOCK_X */ 00434 /************************************************************************* 00435 Releases a table lock. 00436 Releases possible other transactions waiting for this lock. */ 00437 00438 void 00439 lock_table_unlock( 00440 /*==============*/ 00441 lock_t* lock); /* in: lock */ 00442 /************************************************************************* 00443 Releases an auto-inc lock a transaction possibly has on a table. 00444 Releases possible other transactions waiting for this lock. */ 00445 00446 void 00447 lock_table_unlock_auto_inc( 00448 /*=======================*/ 00449 trx_t* trx); /* in: transaction */ 00450 /************************************************************************* 00451 Releases transaction locks, and releases possible other transactions waiting 00452 because of these locks. */ 00453 00454 void 00455 lock_release_off_kernel( 00456 /*====================*/ 00457 trx_t* trx); /* in: transaction */ 00458 /************************************************************************* 00459 Cancels a waiting lock request and releases possible other transactions 00460 waiting behind it. */ 00461 00462 void 00463 lock_cancel_waiting_and_release( 00464 /*============================*/ 00465 lock_t* lock); /* in: waiting lock request */ 00466 /************************************************************************* 00467 Resets all locks, both table and record locks, on a table to be dropped. 00468 No lock is allowed to be a wait lock. */ 00469 00470 void 00471 lock_reset_all_on_table( 00472 /*====================*/ 00473 dict_table_t* table); /* in: table to be dropped */ 00474 /************************************************************************* 00475 Calculates the fold value of a page file address: used in inserting or 00476 searching for a lock in the hash table. */ 00477 UNIV_INLINE 00478 ulint 00479 lock_rec_fold( 00480 /*==========*/ 00481 /* out: folded value */ 00482 ulint space, /* in: space */ 00483 ulint page_no);/* in: page number */ 00484 /************************************************************************* 00485 Calculates the hash value of a page file address: used in inserting or 00486 searching for a lock in the hash table. */ 00487 UNIV_INLINE 00488 ulint 00489 lock_rec_hash( 00490 /*==========*/ 00491 /* out: hashed value */ 00492 ulint space, /* in: space */ 00493 ulint page_no);/* in: page number */ 00494 /************************************************************************* 00495 Gets the source table of an ALTER TABLE transaction. The table must be 00496 covered by an IX or IS table lock. */ 00497 00498 dict_table_t* 00499 lock_get_src_table( 00500 /*===============*/ 00501 /* out: the source table of transaction, 00502 if it is covered by an IX or IS table lock; 00503 dest if there is no source table, and 00504 NULL if the transaction is locking more than 00505 two tables or an inconsistency is found */ 00506 trx_t* trx, /* in: transaction */ 00507 dict_table_t* dest, /* in: destination of ALTER TABLE */ 00508 ulint* mode); /* out: lock mode of the source table */ 00509 /************************************************************************* 00510 Determine if the given table is exclusively "owned" by the given 00511 transaction, i.e., transaction holds LOCK_IX and possibly LOCK_AUTO_INC 00512 on the table. */ 00513 00514 ibool 00515 lock_is_table_exclusive( 00516 /*====================*/ 00517 /* out: TRUE if table is only locked by trx, 00518 with LOCK_IX, and possibly LOCK_AUTO_INC */ 00519 dict_table_t* table, /* in: table */ 00520 trx_t* trx); /* in: transaction */ 00521 /************************************************************************* 00522 Checks that a transaction id is sensible, i.e., not in the future. */ 00523 00524 ibool 00525 lock_check_trx_id_sanity( 00526 /*=====================*/ 00527 /* out: TRUE if ok */ 00528 dulint trx_id, /* in: trx id */ 00529 rec_t* rec, /* in: user record */ 00530 dict_index_t* index, /* in: clustered index */ 00531 const ulint* offsets, /* in: rec_get_offsets(rec, index) */ 00532 ibool has_kernel_mutex);/* in: TRUE if the caller owns the 00533 kernel mutex */ 00534 /************************************************************************* 00535 Validates the lock queue on a single record. */ 00536 00537 ibool 00538 lock_rec_queue_validate( 00539 /*====================*/ 00540 /* out: TRUE if ok */ 00541 rec_t* rec, /* in: record to look at */ 00542 dict_index_t* index, /* in: index, or NULL if not known */ 00543 const ulint* offsets);/* in: rec_get_offsets(rec, index) */ 00544 /************************************************************************* 00545 Prints info of a table lock. */ 00546 00547 void 00548 lock_table_print( 00549 /*=============*/ 00550 FILE* file, /* in: file where to print */ 00551 lock_t* lock); /* in: table type lock */ 00552 /************************************************************************* 00553 Prints info of a record lock. */ 00554 00555 void 00556 lock_rec_print( 00557 /*===========*/ 00558 FILE* file, /* in: file where to print */ 00559 lock_t* lock); /* in: record type lock */ 00560 /************************************************************************* 00561 Prints info of locks for all transactions. */ 00562 00563 void 00564 lock_print_info_summary( 00565 /*====================*/ 00566 FILE* file); /* in: file where to print */ 00567 /************************************************************************* 00568 Prints info of locks for each transaction. */ 00569 00570 void 00571 lock_print_info_all_transactions( 00572 /*=============================*/ 00573 FILE* file); /* in: file where to print */ 00574 /************************************************************************* 00575 Validates the lock queue on a table. */ 00576 00577 ibool 00578 lock_table_queue_validate( 00579 /*======================*/ 00580 /* out: TRUE if ok */ 00581 dict_table_t* table); /* in: table */ 00582 /************************************************************************* 00583 Validates the record lock queues on a page. */ 00584 00585 ibool 00586 lock_rec_validate_page( 00587 /*===================*/ 00588 /* out: TRUE if ok */ 00589 ulint space, /* in: space id */ 00590 ulint page_no);/* in: page number */ 00591 /************************************************************************* 00592 Validates the lock system. */ 00593 00594 ibool 00595 lock_validate(void); 00596 /*===============*/ 00597 /* out: TRUE if ok */ 00598 /************************************************************************* 00599 Return approximate number or record locks (bits set in the bitmap) for 00600 this transaction. Since delete-marked records ma ybe removed, the 00601 record count will not be precise. */ 00602 00603 ulint 00604 lock_number_of_rows_locked( 00605 /*=======================*/ 00606 trx_t* trx); /* in: transaction */ 00607 00608 /* The lock system */ 00609 extern lock_sys_t* lock_sys; 00610 00611 /* Lock modes and types */ 00612 /* Basic modes */ 00613 #define LOCK_NONE 0 /* this flag is used elsewhere to note 00614 consistent read */ 00615 #define LOCK_IS 2 /* intention shared */ 00616 #define LOCK_IX 3 /* intention exclusive */ 00617 #define LOCK_S 4 /* shared */ 00618 #define LOCK_X 5 /* exclusive */ 00619 #define LOCK_AUTO_INC 6 /* locks the auto-inc counter of a table 00620 in an exclusive mode */ 00621 #define LOCK_MODE_MASK 0xFUL /* mask used to extract mode from the 00622 type_mode field in a lock */ 00623 /* Lock types */ 00624 #define LOCK_TABLE 16 /* these type values should be so high that */ 00625 #define LOCK_REC 32 /* they can be ORed to the lock mode */ 00626 #define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the 00627 type_mode field in a lock */ 00628 /* Waiting lock flag */ 00629 #define LOCK_WAIT 256 /* this wait bit should be so high that 00630 it can be ORed to the lock mode and type; 00631 when this bit is set, it means that the 00632 lock has not yet been granted, it is just 00633 waiting for its turn in the wait queue */ 00634 /* Precise modes */ 00635 #define LOCK_ORDINARY 0 /* this flag denotes an ordinary next-key lock 00636 in contrast to LOCK_GAP or LOCK_REC_NOT_GAP */ 00637 #define LOCK_GAP 512 /* this gap bit should be so high that 00638 it can be ORed to the other flags; 00639 when this bit is set, it means that the 00640 lock holds only on the gap before the record; 00641 for instance, an x-lock on the gap does not 00642 give permission to modify the record on which 00643 the bit is set; locks of this type are created 00644 when records are removed from the index chain 00645 of records */ 00646 #define LOCK_REC_NOT_GAP 1024 /* this bit means that the lock is only on 00647 the index record and does NOT block inserts 00648 to the gap before the index record; this is 00649 used in the case when we retrieve a record 00650 with a unique key, and is also used in 00651 locking plain SELECTs (not part of UPDATE 00652 or DELETE) when the user has set the READ 00653 COMMITTED isolation level */ 00654 #define LOCK_INSERT_INTENTION 2048 /* this bit is set when we place a waiting 00655 gap type record lock request in order to let 00656 an insert of an index record to wait until 00657 there are no conflicting locks by other 00658 transactions on the gap; note that this flag 00659 remains set when the waiting lock is granted, 00660 or if the lock is inherited to a neighboring 00661 record */ 00662 00663 /* When lock bits are reset, the following flags are available: */ 00664 #define LOCK_RELEASE_WAIT 1 00665 #define LOCK_NOT_RELEASE_WAIT 2 00666 00667 /* Lock operation struct */ 00668 typedef struct lock_op_struct lock_op_t; 00669 struct lock_op_struct{ 00670 dict_table_t* table; /* table to be locked */ 00671 ulint mode; /* lock mode */ 00672 }; 00673 00674 #define LOCK_OP_START 1 00675 #define LOCK_OP_COMPLETE 2 00676 00677 /* The lock system struct */ 00678 struct lock_sys_struct{ 00679 hash_table_t* rec_hash; /* hash table of the record locks */ 00680 }; 00681 00682 /* The lock system */ 00683 extern lock_sys_t* lock_sys; 00684 00685 00686 #ifndef UNIV_NONINL 00687 #include "lock0lock.ic" 00688 #endif 00689 00690 #endif
1.4.7

