MySQL  8.0.19
Source Code Documentation
lock0lock.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/lock0lock.h
28  The transaction lock system
29 
30  Created 5/7/1996 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef lock0lock_h
34 #define lock0lock_h
35 
36 #include "buf0types.h"
37 #include "dict0types.h"
38 #include "hash0hash.h"
39 #include "lock0types.h"
40 #include "mtr0types.h"
41 #include "que0types.h"
42 #include "rem0types.h"
43 #include "srv0srv.h"
44 #include "trx0types.h"
45 #include "univ.i"
46 #include "ut0vec.h"
47 #ifndef UNIV_HOTBACKUP
48 #include "gis0rtree.h"
49 #endif /* UNIV_HOTBACKUP */
50 #include "lock0prdt.h"
51 
52 // Forward declaration
53 class ReadView;
54 
55 extern bool innobase_deadlock_detect;
56 
57 /** Gets the size of a lock struct.
58  @return size in bytes */
59 ulint lock_get_size(void);
60 /** Creates the lock system at database start. */
61 void lock_sys_create(
62  ulint n_cells); /*!< in: number of slots in lock hash table */
63 /** Resize the lock hash table.
64 @param[in] n_cells number of slots in lock hash table */
65 void lock_sys_resize(ulint n_cells);
66 
67 /** Closes the lock system at database shutdown. */
68 void lock_sys_close(void);
69 /** Gets the heap_no of the smallest user record on a page.
70  @return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */
71 UNIV_INLINE
72 ulint lock_get_min_heap_no(const buf_block_t *block); /*!< in: buffer block */
73 /** Updates the lock table when we have reorganized a page. NOTE: we copy
74  also the locks set on the infimum of the page; the infimum may carry
75  locks if an update of a record is occurring on the page, and its locks
76  were temporarily stored on the infimum. */
78  const buf_block_t *block, /*!< in: old index page, now
79  reorganized */
80  const buf_block_t *oblock); /*!< in: copy of the old, not
81  reorganized page */
82 /** Moves the explicit locks on user records to another page if a record
83  list end is moved to another page. */
85  const buf_block_t *new_block, /*!< in: index page to move to */
86  const buf_block_t *block, /*!< in: index page */
87  const rec_t *rec); /*!< in: record on page: this
88  is the first record moved */
89 /** Moves the explicit locks on user records to another page if a record
90  list start is moved to another page. */
92  const buf_block_t *new_block, /*!< in: index page to move to */
93  const buf_block_t *block, /*!< in: index page */
94  const rec_t *rec, /*!< in: record on page:
95  this is the first
96  record NOT copied */
97  const rec_t *old_end); /*!< in: old
98  previous-to-last
99  record on new_page
100  before the records
101  were copied */
102 /** Updates the lock table when a page is split to the right. */
104  const buf_block_t *right_block, /*!< in: right page */
105  const buf_block_t *left_block); /*!< in: left page */
106 /** Updates the lock table when a page is merged to the right. */
108  const buf_block_t *right_block, /*!< in: right page to
109  which merged */
110  const rec_t *orig_succ, /*!< in: original
111  successor of infimum
112  on the right page
113  before merge */
114  const buf_block_t *left_block); /*!< in: merged index
115  page which will be
116  discarded */
117 /** Updates the lock table when the root page is copied to another in
118  btr_root_raise_and_insert. Note that we leave lock structs on the
119  root page, even though they do not make sense on other than leaf
120  pages: the reason is that in a pessimistic update the infimum record
121  of the root page will act as a dummy carrier of the locks of the record
122  to be updated. */
124  const buf_block_t *block, /*!< in: index page to which copied */
125  const buf_block_t *root); /*!< in: root page */
126 /** Updates the lock table when a page is copied to another and the original
127  page is removed from the chain of leaf pages, except if page is the root! */
129  const buf_block_t *new_block, /*!< in: index page to
130  which copied */
131  const buf_block_t *block); /*!< in: index page;
132  NOT the root! */
133 /** Updates the lock table when a page is split to the left. */
135  const buf_block_t *right_block, /*!< in: right page */
136  const buf_block_t *left_block); /*!< in: left page */
137 /** Updates the lock table when a page is merged to the left. */
139  const buf_block_t *left_block, /*!< in: left page to
140  which merged */
141  const rec_t *orig_pred, /*!< in: original predecessor
142  of supremum on the left page
143  before merge */
144  const buf_block_t *right_block); /*!< in: merged index page
145  which will be discarded */
146 /** Resets the original locks on heir and replaces them with gap type locks
147  inherited from rec. */
149  const buf_block_t *heir_block, /*!< in: block containing the
150  record which inherits */
151  const buf_block_t *block, /*!< in: block containing the
152  record from which inherited;
153  does NOT reset the locks on
154  this record */
155  ulint heir_heap_no, /*!< in: heap_no of the
156  inheriting record */
157  ulint heap_no); /*!< in: heap_no of the
158  donating record */
159 /** Updates the lock table when a page is discarded. */
161  const buf_block_t *heir_block, /*!< in: index page
162  which will inherit the locks */
163  ulint heir_heap_no, /*!< in: heap_no of the record
164  which will inherit the locks */
165  const buf_block_t *block); /*!< in: index page
166  which will be discarded */
167 /** Updates the lock table when a new user record is inserted. */
168 void lock_update_insert(
169  const buf_block_t *block, /*!< in: buffer block containing rec */
170  const rec_t *rec); /*!< in: the inserted record */
171 /** Updates the lock table when a record is removed. */
172 void lock_update_delete(
173  const buf_block_t *block, /*!< in: buffer block containing rec */
174  const rec_t *rec); /*!< in: the record to be removed */
175 /** Stores on the page infimum record the explicit locks of another record.
176  This function is used to store the lock state of a record when it is
177  updated and the size of the record changes in the update. The record
178  is in such an update moved, perhaps to another page. The infimum record
179  acts as a dummy carrier record, taking care of lock releases while the
180  actual record is being moved. */
182  const buf_block_t *block, /*!< in: buffer block containing rec */
183  const rec_t *rec); /*!< in: record whose lock state
184  is stored on the infimum
185  record of the same page; lock
186  bits are reset on the
187  record */
188 /** Restores the state of explicit lock requests on a single record, where the
189  state was stored on the infimum of the page. */
191  const buf_block_t *block, /*!< in: buffer block containing rec */
192  const rec_t *rec, /*!< in: record whose lock state
193  is restored */
194  const buf_block_t *donator); /*!< in: page (rec is not
195  necessarily on this page)
196  whose infimum stored the lock
197  state; lock bits are reset on
198  the infimum */
199 
200 /** Determines if there are explicit record locks on a page.
201  @return an explicit record lock on the page, or NULL if there are none */
202 lock_t *lock_rec_expl_exist_on_page(space_id_t space, /*!< in: space id */
203  page_no_t page_no) /*!< in: page number */
204  MY_ATTRIBUTE((warn_unused_result));
205 /** Checks if locks of other transactions prevent an immediate insert of
206  a record. If they do, first tests if the query thread should anyway
207  be suspended for some reason; if not, then puts the transaction and
208  the query thread to the lock wait state and inserts a waiting request
209  for a gap x-lock to the lock queue.
210  @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
212  ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG bit is
213  set, does nothing */
214  const rec_t *rec, /*!< in: record after which to insert */
215  buf_block_t *block, /*!< in/out: buffer block of rec */
216  dict_index_t *index, /*!< in: index */
217  que_thr_t *thr, /*!< in: query thread */
218  mtr_t *mtr, /*!< in/out: mini-transaction */
219  ibool *inherit) /*!< out: set to TRUE if the new
220  inserted record maybe should inherit
221  LOCK_GAP type locks from the successor
222  record */
223  MY_ATTRIBUTE((warn_unused_result));
224 
225 /** Checks if locks of other transactions prevent an immediate modify (update,
226  delete mark, or delete unmark) of a clustered index record. If they do,
227  first tests if the query thread should anyway be suspended for some
228  reason; if not, then puts the transaction and the query thread to the
229  lock wait state and inserts a waiting request for a record x-lock to the
230  lock queue.
231  @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
233  ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG
234  bit is set, does nothing */
235  const buf_block_t *block, /*!< in: buffer block of rec */
236  const rec_t *rec, /*!< in: record which should be
237  modified */
238  dict_index_t *index, /*!< in: clustered index */
239  const ulint *offsets, /*!< in: rec_get_offsets(rec, index) */
240  que_thr_t *thr) /*!< in: query thread */
241  MY_ATTRIBUTE((warn_unused_result));
242 /** Checks if locks of other transactions prevent an immediate modify
243  (delete mark or delete unmark) of a secondary index record.
244  @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
246  ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG
247  bit is set, does nothing */
248  buf_block_t *block, /*!< in/out: buffer block of rec */
249  const rec_t *rec, /*!< in: record which should be
250  modified; NOTE: as this is a secondary
251  index, we always have to modify the
252  clustered index record first: see the
253  comment below */
254  dict_index_t *index, /*!< in: secondary index */
255  que_thr_t *thr, /*!< in: query thread
256  (can be NULL if BTR_NO_LOCKING_FLAG) */
257  mtr_t *mtr) /*!< in/out: mini-transaction */
258  MY_ATTRIBUTE((warn_unused_result));
259 
260 /** Called to inform lock-sys that a statement processing for a trx has just
261 finished.
262 @param[in] trx transaction which has finished processing a statement */
263 void lock_on_statement_end(trx_t *trx);
264 
265 /** Used to specify the intended duration of a record lock. */
266 enum class lock_duration_t {
267  /** Keep the lock according to the rules of particular isolation level, in
268  particular in case of READ COMMITTED or less restricive modes, do not inherit
269  the lock if the record is purged. */
270  REGULAR = 0,
271  /** Keep the lock around for at least the duration of the current statement,
272  in particular make sure it is inherited as gap lock if the record is purged.*/
273  AT_LEAST_STATEMENT = 1,
274 };
275 
276 /** Like lock_clust_rec_read_check_and_lock(), but reads a
277 secondary index record.
278 @param[in] duration If equal to AT_LEAST_STATEMENT, then makes sure
279  that the lock will be kept around and inherited
280  for at least the duration of current statement.
281  If equal to REGULAR the life-cycle of the lock
282  will depend on isolation level rules.
283 @param[in] block buffer block of rec
284 @param[in] rec user record or page supremum record which should
285  be read or passed over by a read cursor
286 @param[in] index secondary index
287 @param[in] offsets rec_get_offsets(rec, index)
288 @param[in] sel_mode select mode: SELECT_ORDINARY,
289  SELECT_SKIP_LOKCED, or SELECT_NO_WAIT
290 @param[in] mode mode of the lock which the read cursor should
291  set on records: LOCK_S or LOCK_X; the latter is
292  possible in SELECT FOR UPDATE
293 @param[in] gap_mode LOCK_ORDINARY, LOCK_GAP, or LOCK_REC_NOT_GAP
294 @param[in,out] thr query thread
295 @return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK,
296 DB_SKIP_LOCKED, or DB_LOCK_NOWAIT */
298  const buf_block_t *block,
299  const rec_t *rec, dict_index_t *index,
300  const ulint *offsets,
301  select_mode sel_mode, lock_mode mode,
302  ulint gap_mode, que_thr_t *thr);
303 
304 /** Checks if locks of other transactions prevent an immediate read, or passing
305 over by a read cursor, of a clustered index record. If they do, first tests
306 if the query thread should anyway be suspended for some reason; if not, then
307 puts the transaction and the query thread to the lock wait state and inserts a
308 waiting request for a record lock to the lock queue. Sets the requested mode
309 lock on the record.
310 @param[in] duration If equal to AT_LEAST_STATEMENT, then makes sure
311  that the lock will be kept around and inherited
312  for at least the duration of current statement.
313  If equal to REGULAR the life-cycle of the lock
314  will depend on isolation level rules.
315 @param[in] block buffer block of rec
316 @param[in] rec user record or page supremum record which should
317  be read or passed over by a read cursor
318 @param[in] index secondary index
319 @param[in] offsets rec_get_offsets(rec, index)
320 @param[in] sel_mode select mode: SELECT_ORDINARY,
321  SELECT_SKIP_LOKCED, or SELECT_NO_WAIT
322 @param[in] mode mode of the lock which the read cursor should
323  set on records: LOCK_S or LOCK_X; the latter is
324  possible in SELECT FOR UPDATE
325 @param[in] gap_mode LOCK_ORDINARY, LOCK_GAP, or LOCK_REC_NOT_GAP
326 @param[in,out] thr query thread
327 @return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK,
328 DB_SKIP_LOCKED, or DB_LOCK_NOWAIT */
330  lock_duration_t duration, const buf_block_t *block, const rec_t *rec,
331  dict_index_t *index, const ulint *offsets, select_mode sel_mode,
332  lock_mode mode, ulint gap_mode, que_thr_t *thr);
333 
334 /** Checks if locks of other transactions prevent an immediate read, or passing
335  over by a read cursor, of a clustered index record. If they do, first tests
336  if the query thread should anyway be suspended for some reason; if not, then
337  puts the transaction and the query thread to the lock wait state and inserts a
338  waiting request for a record lock to the lock queue. Sets the requested mode
339  lock on the record. This is an alternative version of
340  lock_clust_rec_read_check_and_lock() that does not require the parameter
341  "offsets".
342  @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
344  const buf_block_t *block, /*!< in: buffer block of rec */
345  const rec_t *rec, /*!< in: user record or page
346  supremum record which should
347  be read or passed over by a
348  read cursor */
349  dict_index_t *index, /*!< in: clustered index */
350  lock_mode mode, /*!< in: mode of the lock which
351  the read cursor should set on
352  records: LOCK_S or LOCK_X; the
353  latter is possible in
354  SELECT FOR UPDATE */
355  ulint gap_mode, /*!< in: LOCK_ORDINARY, LOCK_GAP, or
356  LOCK_REC_NOT_GAP */
357  que_thr_t *thr) /*!< in: query thread */
358  MY_ATTRIBUTE((warn_unused_result));
359 /** Checks that a record is seen in a consistent read.
360  @return true if sees, or false if an earlier version of the record
361  should be retrieved */
363  const rec_t *rec, /*!< in: user record which should be read or
364  passed over by a read cursor */
365  dict_index_t *index, /*!< in: clustered index */
366  const ulint *offsets, /*!< in: rec_get_offsets(rec, index) */
367  ReadView *view); /*!< in: consistent read view */
368 /** Checks that a non-clustered index record is seen in a consistent read.
369 
370  NOTE that a non-clustered index page contains so little information on
371  its modifications that also in the case false, the present version of
372  rec may be the right, but we must check this from the clustered index
373  record.
374 
375  @return true if certainly sees, or false if an earlier version of the
376  clustered index record might be needed */
378  const rec_t *rec, /*!< in: user record which
379  should be read or passed over
380  by a read cursor */
381  const dict_index_t *index, /*!< in: index */
382  const ReadView *view) /*!< in: consistent read view */
383  MY_ATTRIBUTE((warn_unused_result));
384 /** Locks the specified database table in the mode given. If the lock cannot
385  be granted immediately, the query thread is put to wait.
386  @return DB_SUCCESS, DB_LOCK_WAIT, or DB_DEADLOCK */
387 dberr_t lock_table(ulint flags, /*!< in: if BTR_NO_LOCKING_FLAG bit is set,
388  does nothing */
389  dict_table_t *table, /*!< in/out: database table
390  in dictionary cache */
391  lock_mode mode, /*!< in: lock mode */
392  que_thr_t *thr) /*!< in: query thread */
393  MY_ATTRIBUTE((warn_unused_result));
394 /** Creates a table IX lock object for a resurrected transaction. */
395 void lock_table_ix_resurrect(dict_table_t *table, /*!< in/out: table */
396  trx_t *trx); /*!< in/out: transaction */
397 
398 /** Sets a lock on a table based on the given mode.
399 @param[in] table table to lock
400 @param[in,out] trx transaction
401 @param[in] mode LOCK_X or LOCK_S
402 @return error code or DB_SUCCESS. */
403 dberr_t lock_table_for_trx(dict_table_t *table, trx_t *trx, enum lock_mode mode)
404  MY_ATTRIBUTE((nonnull, warn_unused_result));
405 
406 /** Removes a granted record lock of a transaction from the queue and grants
407  locks to other transactions waiting in the queue if they now are entitled
408  to a lock. */
409 void lock_rec_unlock(
410  trx_t *trx, /*!< in/out: transaction that has
411  set a record lock */
412  const buf_block_t *block, /*!< in: buffer block containing rec */
413  const rec_t *rec, /*!< in: record */
414  lock_mode lock_mode); /*!< in: LOCK_S or LOCK_X */
415 /** Releases a transaction's locks, and releases possible other transactions
416  waiting because of these locks. Change the state of the transaction to
417  TRX_STATE_COMMITTED_IN_MEMORY. */
418 void lock_trx_release_locks(trx_t *trx); /*!< in/out: transaction */
419 
420 /** Release read locks of a transacion. It is called during XA
421 prepare to release locks early.
422 @param[in,out] trx transaction
423 @param[in] only_gap release only GAP locks */
424 void lock_trx_release_read_locks(trx_t *trx, bool only_gap);
425 
426 /** Iterate over the granted locks which conflict with trx->lock.wait_lock and
427 prepare the hit list for ASYNC Rollback.
428 
429 If the transaction is waiting for some other lock then wake up
430 with deadlock error. Currently we don't mark following transactions
431 for ASYNC Rollback.
432 
433 1. Read only transactions
434 2. Background transactions
435 3. Other High priority transactions
436 @param[in] trx High Priority transaction
437 @param[in,out] hit_list List of transactions which need to be rolled back */
438 void lock_make_trx_hit_list(trx_t *trx, hit_list_t &hit_list);
439 
440 /** Removes locks on a table to be dropped.
441  If remove_also_table_sx_locks is TRUE then table-level S and X locks are
442  also removed in addition to other table-level and record-level locks.
443  No lock, that is going to be removed, is allowed to be a wait lock. */
445  dict_table_t *table, /*!< in: table to be dropped
446  or discarded */
447  ibool remove_also_table_sx_locks); /*!< in: also removes
448  table S and X locks */
449 
450 /** Calculates the fold value of a page file address: used in inserting or
451  searching for a lock in the hash table.
452  @return folded value */
453 UNIV_INLINE
454 ulint lock_rec_fold(space_id_t space, /*!< in: space */
455  page_no_t page_no) /*!< in: page number */
456  MY_ATTRIBUTE((const));
457 
458 /** Calculates the hash value of a page file address: used in inserting or
459 searching for a lock in the hash table.
460 @param[in] space space
461 @param[in] page_no page number
462 @return hashed value */
463 UNIV_INLINE
464 ulint lock_rec_hash(space_id_t space, page_no_t page_no);
465 
466 /** Get the lock hash table */
467 UNIV_INLINE
468 hash_table_t *lock_hash_get(ulint mode); /*!< in: lock mode */
469 
470 /** Looks for a set bit in a record lock bitmap. Returns ULINT_UNDEFINED,
471  if none found.
472  @return bit index == heap number of the record, or ULINT_UNDEFINED if
473  none found */
474 ulint lock_rec_find_set_bit(const lock_t *lock); /*!< in: record lock with at
475  least one bit set */
476 
477 /** Looks for the next set bit in the record lock bitmap.
478 @param[in] lock record lock with at least one bit set
479 @param[in] heap_no current set bit
480 @return The next bit index == heap number following heap_no, or ULINT_UNDEFINED
481 if none found */
482 ulint lock_rec_find_next_set_bit(const lock_t *lock, ulint heap_no);
483 
484 /** Checks if a lock request lock1 has to wait for request lock2.
485  @return TRUE if lock1 has to wait for lock2 to be removed */
486 bool lock_has_to_wait(const lock_t *lock1, /*!< in: waiting lock */
487  const lock_t *lock2); /*!< in: another lock; NOTE that it
488  is assumed that this has a lock bit
489  set on the same record as in lock1
490  if the locks are record locks */
491 /** Reports that a transaction id is insensible, i.e., in the future. */
493  trx_id_t trx_id, /*!< in: trx id */
494  const rec_t *rec, /*!< in: user record */
495  const dict_index_t *index, /*!< in: index */
496  const ulint *offsets, /*!< in: rec_get_offsets(rec, index) */
497  trx_id_t max_trx_id); /*!< in: trx_sys_get_max_trx_id() */
498 
499 /** Prints info of locks for all transactions.
500 @return false if not able to obtain lock mutex and exits without
501 printing info */
503  FILE *file, /*!< in: file where to print */
504  ibool nowait) /*!< in: whether to wait for the lock mutex */
505  MY_ATTRIBUTE((warn_unused_result));
506 
507 /** Prints transaction lock wait and MVCC state.
508 @param[in,out] file file where to print
509 @param[in] trx transaction */
510 void lock_trx_print_wait_and_mvcc_state(FILE *file, const trx_t *trx);
511 
512 /** Prints info of locks for each transaction. This function assumes that the
513  caller holds the lock mutex and more importantly it will release the lock
514  mutex on behalf of the caller. (This should be fixed in the future). */
516  FILE *file); /*!< in: file where to print */
517 /** Return approximate number or record locks (bits set in the bitmap) for
518  this transaction. Since delete-marked records may be removed, the
519  record count will not be precise.
520  The caller must be holding lock_sys->mutex. */
522  const trx_lock_t *trx_lock) /*!< in: transaction locks */
523  MY_ATTRIBUTE((warn_unused_result));
524 
525 /** Return the number of table locks for a transaction.
526  The caller must be holding trx->mutex.
527 @param[in] trx the transaction for which we want the number of table locks */
528 ulint lock_number_of_tables_locked(const trx_t *trx)
529  MY_ATTRIBUTE((warn_unused_result));
530 
531 /** Gets the type of a lock. Non-inline version for using outside of the
532  lock module.
533  @return LOCK_TABLE or LOCK_REC */
534 uint32_t lock_get_type(const lock_t *lock); /*!< in: lock */
535 
536 /** Gets the id of the transaction owning a lock.
537 @param[in] lock A lock of the transaction we are interested in
538 @return the transaction's id */
539 trx_id_t lock_get_trx_id(const lock_t *lock);
540 
541 /** Gets the immutable id of the transaction owning a lock
542 @param[in] lock A lock of the transaction we are interested in
543 @return the transaction's immutable id */
544 uint64_t lock_get_trx_immutable_id(const lock_t *lock);
545 
546 /** Gets the immutable id of this lock.
547 @param[in] lock The lock we are interested in
548 @return The lock's immutable id */
549 uint64_t lock_get_immutable_id(const lock_t *lock);
550 
551 /** Get the performance schema event (thread_id, event_id)
552 that created the lock.
553 @param[in] lock Lock
554 @param[out] thread_id Thread ID that created the lock
555 @param[out] event_id Event ID that created the lock
556 */
557 void lock_get_psi_event(const lock_t *lock, ulonglong *thread_id,
558  ulonglong *event_id);
559 
560 /** Get the first lock of a trx lock list.
561 @param[in] trx_lock the trx lock
562 @return The first lock
563 */
564 const lock_t *lock_get_first_trx_locks(const trx_lock_t *trx_lock);
565 
566 /** Get the next lock of a trx lock list.
567 @param[in] lock the current lock
568 @return The next lock
569 */
570 const lock_t *lock_get_next_trx_locks(const lock_t *lock);
571 
572 /** Gets the mode of a lock in a human readable string.
573  The string should not be free()'d or modified.
574  @return lock mode */
575 const char *lock_get_mode_str(const lock_t *lock); /*!< in: lock */
576 
577 /** Gets the type of a lock in a human readable string.
578  The string should not be free()'d or modified.
579  @return lock type */
580 const char *lock_get_type_str(const lock_t *lock); /*!< in: lock */
581 
582 /** Gets the id of the table on which the lock is.
583  @return id of the table */
584 table_id_t lock_get_table_id(const lock_t *lock); /*!< in: lock */
585 
586 /** Determine which table a lock is associated with.
587 @param[in] lock the lock
588 @return name of the table */
589 const table_name_t &lock_get_table_name(const lock_t *lock);
590 
591 /** For a record lock, gets the index on which the lock is.
592  @return index */
593 const dict_index_t *lock_rec_get_index(const lock_t *lock); /*!< in: lock */
594 
595 /** For a record lock, gets the name of the index on which the lock is.
596  The string should not be free()'d or modified.
597  @return name of the index */
598 const char *lock_rec_get_index_name(const lock_t *lock); /*!< in: lock */
599 
600 /** For a record lock, gets the tablespace number on which the lock is.
601  @return tablespace number */
602 space_id_t lock_rec_get_space_id(const lock_t *lock); /*!< in: lock */
603 
604 /** For a record lock, gets the page number on which the lock is.
605  @return page number */
606 page_no_t lock_rec_get_page_no(const lock_t *lock); /*!< in: lock */
607 /** Check if there are any locks (table or rec) against table.
608  @return true if locks exist */
610  const dict_table_t *table); /*!< in: check if there are any locks
611  held on records in this table or on the
612  table itself */
613 
614 /** A thread which wakes up threads whose lock wait may have lasted too long. */
616 
617 /** Notifies the thread which analyzes wait-for-graph that there was
618  at least one new edge added or modified ( trx->blocking_trx has changed ),
619  so that the thread will know it has to analyze it. */
621 
622 /** Puts a user OS thread to wait for a lock to be released. If an error
623  occurs during the wait trx->error_state associated with thr is
624  != DB_SUCCESS when we return. DB_LOCK_WAIT_TIMEOUT and DB_DEADLOCK
625  are possible errors. DB_DEADLOCK is returned if selective deadlock
626  resolution chose this transaction as a victim. */
627 void lock_wait_suspend_thread(que_thr_t *thr); /*!< in: query thread associated
628  with the user OS thread */
629 /** Unlocks AUTO_INC type locks that were possibly reserved by a trx. This
630  function should be called at the the end of an SQL statement, by the
631  connection thread that owns the transaction (trx->mysql_thd). */
632 void lock_unlock_table_autoinc(trx_t *trx); /*!< in/out: transaction */
633 /** Check whether the transaction has already been rolled back because it
634  was selected as a deadlock victim, or if it has to wait then cancel
635  the wait lock.
636  @return DB_DEADLOCK, DB_LOCK_WAIT or DB_SUCCESS */
637 dberr_t lock_trx_handle_wait(trx_t *trx); /*!< in/out: trx lock state */
638 /** Initialise the trx lock list. */
640  trx_lock_list_t *lock_list); /*!< List to initialise */
641 
642 /** Set the lock system timeout event. */
644 #ifdef UNIV_DEBUG
645 /** Checks that a transaction id is sensible, i.e., not in the future.
646  @return true if ok */
648  trx_id_t trx_id, /*!< in: trx id */
649  const rec_t *rec, /*!< in: user record */
650  const dict_index_t *index, /*!< in: index */
651  const ulint *offsets) /*!< in: rec_get_offsets(rec, index) */
652  MY_ATTRIBUTE((warn_unused_result));
653 /** Check if the transaction holds an exclusive lock on a record.
654 @param[in] thr query thread of the transaction
655 @param[in] table table to check
656 @param[in] block buffer block of the record
657 @param[in] heap_no record heap number
658 @return whether the locks are held */
659 bool lock_trx_has_rec_x_lock(que_thr_t *thr, const dict_table_t *table,
660  const buf_block_t *block, ulint heap_no)
661  MY_ATTRIBUTE((warn_unused_result));
662 #endif /* UNIV_DEBUG */
663 
664 /**
665 Allocate cached locks for the transaction.
666 @param trx allocate cached record locks for this transaction */
667 void lock_trx_alloc_locks(trx_t *trx);
668 
669 /** Lock modes and types */
670 /* @{ */
671 #define LOCK_MODE_MASK \
672  0xFUL /*!< mask used to extract mode from the \
673  type_mode field in a lock */
674 /** Lock types */
675 /* @{ */
676 #define LOCK_TABLE 16 /*!< table lock */
677 #define LOCK_REC 32 /*!< record lock */
678 #define LOCK_TYPE_MASK \
679  0xF0UL /*!< mask used to extract lock type from the \
680  type_mode field in a lock */
681 #if LOCK_MODE_MASK & LOCK_TYPE_MASK
682 #error "LOCK_MODE_MASK & LOCK_TYPE_MASK"
683 #endif
684 
685 #define LOCK_WAIT \
686  256 /*!< Waiting lock flag; when set, it \
687  means that the lock has not yet been \
688  granted, it is just waiting for its \
689  turn in the wait queue */
690 /* Precise modes */
691 #define LOCK_ORDINARY \
692  0 /*!< this flag denotes an ordinary \
693  next-key lock in contrast to LOCK_GAP \
694  or LOCK_REC_NOT_GAP */
695 #define LOCK_GAP \
696  512 /*!< when this bit is set, it means that the \
697  lock holds only on the gap before the record; \
698  for instance, an x-lock on the gap does not \
699  give permission to modify the record on which \
700  the bit is set; locks of this type are created \
701  when records are removed from the index chain \
702  of records */
703 #define LOCK_REC_NOT_GAP \
704  1024 /*!< this bit means that the lock is only on \
705  the index record and does NOT block inserts \
706  to the gap before the index record; this is \
707  used in the case when we retrieve a record \
708  with a unique key, and is also used in \
709  locking plain SELECTs (not part of UPDATE \
710  or DELETE) when the user has set the READ \
711  COMMITTED isolation level */
712 #define LOCK_INSERT_INTENTION \
713  2048 /*!< this bit is set when we place a waiting \
714  gap type record lock request in order to let \
715  an insert of an index record to wait until \
716  there are no conflicting locks by other \
717  transactions on the gap; note that this flag \
718  remains set when the waiting lock is granted, \
719  or if the lock is inherited to a neighboring \
720  record */
721 #define LOCK_PREDICATE 8192 /*!< Predicate lock */
722 #define LOCK_PRDT_PAGE 16384 /*!< Page lock */
723 
724 #if (LOCK_WAIT | LOCK_GAP | LOCK_REC_NOT_GAP | LOCK_INSERT_INTENTION | \
725  LOCK_PREDICATE | LOCK_PRDT_PAGE) & \
726  LOCK_MODE_MASK
727 #error
728 #endif
729 #if (LOCK_WAIT | LOCK_GAP | LOCK_REC_NOT_GAP | LOCK_INSERT_INTENTION | \
730  LOCK_PREDICATE | LOCK_PRDT_PAGE) & \
731  LOCK_TYPE_MASK
732 #error
733 #endif
734 /* @} */
735 
736 /** Lock operation struct */
737 struct lock_op_t {
738  dict_table_t *table; /*!< table to be locked */
739  lock_mode mode; /*!< lock mode */
740 };
741 
742 typedef ib_mutex_t LockMutex;
743 
744 /** The lock system struct */
745 struct lock_sys_t {
747  /*!< padding to prevent other
748  memory update hotspots from
749  residing on the same memory
750  cache line */
751  LockMutex mutex; /*!< Mutex protecting the
752  locks */
753  hash_table_t *rec_hash; /*!< hash table of the record
754  locks */
755  hash_table_t *prdt_hash; /*!< hash table of the predicate
756  lock */
757  hash_table_t *prdt_page_hash; /*!< hash table of the page
758  lock */
759 
760  char pad2[INNOBASE_CACHE_LINE_SIZE]; /*!< Padding */
761  LockMutex wait_mutex; /*!< Mutex protecting the
762  next two fields */
763  srv_slot_t *waiting_threads; /*!< Array of user threads
764  suspended while waiting for
765  locks within InnoDB, protected
766  by the lock_sys->wait_mutex */
767  srv_slot_t *last_slot; /*!< highest slot ever used
768  in the waiting_threads array,
769  protected by
770  lock_sys->wait_mutex */
771 
772  /** Number of slots in use. Writes are protected by lock_sys->wait_mutex, but
773  we read this without any latch in the lock_use_fcfs() heuristic. Also, we use
774  relaxed memory ordering for both writes and reads, because this is just a
775  counter field which does not "acquire" or "release" anything, and
776  lock_use_fcfs is just a heuristic anyway, so even if it reads a value not
777  synchronized with other fields/variables it is not a big deal. OTOH this field
778  is accessed pretty often during trx->age updating, so we try to minimize the
779  chance of performance issues. One can say that the only reason it is atomic
780  is to avoid torn reads in lock_use_fcfs(). */
781  std::atomic<int> n_waiting{0};
782 
784  /*!< TRUE if rollback of all
785  recovered transactions is
786  complete. Protected by
787  lock_sys->mutex */
788 
789  ulint n_lock_max_wait_time; /*!< Max wait time */
790 
791  os_event_t timeout_event; /*!< Set to the event that is
792  created in the lock wait monitor
793  thread. A value of 0 means the
794  thread is not active */
795 
796  /** Marker value before trx_t::age. */
798 
799 #ifdef UNIV_DEBUG
800  /** Lock timestamp counter */
801  uint64_t m_seq;
802 #endif /* UNIV_DEBUG */
803 };
804 
805 /*********************************************************************/ /**
806 This function is kind of wrapper to lock_rec_convert_impl_to_expl_for_trx()
807 function with functionailty added to facilitate lock conversion from implicit
808 to explicit for partial rollback cases
809 @param[in] block buffer block of rec
810 @param[in] rec user record on page
811 @param[in] index index of record
812 @param[in] offsets rec_get_offsets(rec, index)
813 @param[in,out] trx active transaction
814 @param[in] heap_no rec heap number to lock */
816  const rec_t *rec, dict_index_t *index,
817  const ulint *offsets, trx_t *trx,
818  ulint heap_no);
819 
820 /** Removes a record lock request, waiting or granted, from the queue. */
821 void lock_rec_discard(lock_t *in_lock); /*!< in: record lock object: all
822  record locks which are contained
823  in this lock object are removed */
824 
825 /** Moves the explicit locks on user records to another page if a record
826  list start is moved to another page. */
827 void lock_rtr_move_rec_list(const buf_block_t *new_block, /*!< in: index page to
828  move to */
829  const buf_block_t *block, /*!< in: index page */
830  rtr_rec_move_t *rec_move, /*!< in: recording records
831  moved */
832  ulint num_move); /*!< in: num of rec to move */
833 
834 /** Removes record lock objects set on an index page which is discarded. This
835  function does not move locks, or check for waiting locks, therefore the
836  lock bitmaps must already be reset when this function is called. */
838  const buf_block_t *block); /*!< in: page to be discarded */
839 
840 /** Reset the nth bit of a record lock.
841 @param[in,out] lock record lock
842 @param[in] i index of the bit that will be reset
843 @param[in] type whether the lock is in wait mode */
844 void lock_rec_trx_wait(lock_t *lock, ulint i, ulint type);
845 
846 /** The lock system */
847 extern lock_sys_t *lock_sys;
848 
849 /** Test if lock_sys->mutex can be acquired without waiting. */
850 #define lock_mutex_enter_nowait() (lock_sys->mutex.trylock(__FILE__, __LINE__))
851 
852 /** Test if lock_sys->mutex is owned by the current thread. */
853 #define lock_mutex_own() (lock_sys->mutex.is_owned())
854 
855 /** Acquire the lock_sys->mutex. */
856 #define lock_mutex_enter() \
857  do { \
858  mutex_enter(&lock_sys->mutex); \
859  } while (0)
860 
861 /** Release the lock_sys->mutex. */
862 #define lock_mutex_exit() \
863  do { \
864  lock_sys->mutex.exit(); \
865  } while (0)
866 
867 /** Test if lock_sys->wait_mutex is owned. */
868 #define lock_wait_mutex_own() (lock_sys->wait_mutex.is_owned())
869 
870 /** Acquire the lock_sys->wait_mutex. */
871 #define lock_wait_mutex_enter() \
872  do { \
873  mutex_enter(&lock_sys->wait_mutex); \
874  } while (0)
875 
876 /** Release the lock_sys->wait_mutex. */
877 #define lock_wait_mutex_exit() \
878  do { \
879  lock_sys->wait_mutex.exit(); \
880  } while (0)
881 
882 #include "lock0lock.ic"
883 
884 #endif
lock0prdt.h
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
lock_get_min_heap_no
UNIV_INLINE ulint lock_get_min_heap_no(const buf_block_t *block)
Gets the heap_no of the smallest user record on a page.
lock_rec_expl_exist_on_page
lock_t * lock_rec_expl_exist_on_page(space_id_t space, page_no_t page_no)
Determines if there are explicit record locks on a page.
Definition: lock0lock.cc:632
lock_rec_restore_from_page_infimum
void lock_rec_restore_from_page_infimum(const buf_block_t *block, const rec_t *rec, const buf_block_t *donator)
Restores the state of explicit lock requests on a single record, where the state was stored on the in...
Definition: lock0lock.cc:3479
lock_sec_rec_cons_read_sees
bool lock_sec_rec_cons_read_sees(const rec_t *rec, const dict_index_t *index, const ReadView *view)
Checks that a non-clustered index record is seen in a consistent read.
Definition: lock0lock.cc:259
lock_update_merge_right
void lock_update_merge_right(const buf_block_t *right_block, const rec_t *orig_succ, const buf_block_t *left_block)
Updates the lock table when a page is merged to the right.
Definition: lock0lock.cc:3164
lock_rec_get_page_no
page_no_t lock_rec_get_page_no(const lock_t *lock)
For a record lock, gets the page number on which the lock is.
Definition: lock0lock.cc:6315
lock_rec_get_space_id
space_id_t lock_rec_get_space_id(const lock_t *lock)
For a record lock, gets the tablespace number on which the lock is.
Definition: lock0lock.cc:6306
dict0types.h
lock_get_psi_event
void lock_get_psi_event(const lock_t *lock, ulonglong *thread_id, ulonglong *event_id)
Get the performance schema event (thread_id, event_id) that created the lock.
Definition: lock0lock.cc:6131
lock_rec_fold
UNIV_INLINE ulint lock_rec_fold(space_id_t space, page_no_t page_no)
Calculates the fold value of a page file address: used in inserting or searching for a lock in the ha...
lock_print_info_summary
bool lock_print_info_summary(FILE *file, ibool nowait)
Prints info of locks for all transactions.
Definition: lock0lock.cc:4677
thread_id
static my_thread_id thread_id
Definition: my_thr_init.cc:62
lock_trx_alloc_locks
void lock_trx_alloc_locks(trx_t *trx)
Allocate cached locks for the transaction.
Definition: lock0lock.cc:6791
trx_id_t
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
lock_wait_timeout_thread
void lock_wait_timeout_thread()
A thread which wakes up threads whose lock wait may have lasted too long.
Definition: lock0wait.cc:1085
lock_has_to_wait
bool lock_has_to_wait(const lock_t *lock1, const lock_t *lock2)
Checks if a lock request lock1 has to wait for request lock2.
Definition: lock0lock.cc:531
trx_lock_t
Latching protocol for trx_lock_t::que_state.
Definition: trx0trx.h:545
lock_sys_t::rollback_complete
ibool rollback_complete
TRUE if rollback of all recovered transactions is complete.
Definition: lock0lock.h:783
lock_sys_t::pad2
char pad2[INNOBASE_CACHE_LINE_SIZE]
Padding.
Definition: lock0lock.h:760
lock_clust_rec_cons_read_sees
bool lock_clust_rec_cons_read_sees(const rec_t *rec, dict_index_t *index, const ulint *offsets, ReadView *view)
Checks that a record is seen in a consistent read.
Definition: lock0lock.cc:222
dict_index_t
Data structure for an index.
Definition: dict0mem.h:869
lock_trx_release_locks
void lock_trx_release_locks(trx_t *trx)
Releases a transaction's locks, and releases possible other transactions waiting because of these loc...
Definition: lock0lock.cc:6402
mtr_t
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
lock_sys_t::n_waiting
std::atomic< int > n_waiting
Number of slots in use.
Definition: lock0lock.h:781
os_event
InnoDB condition variable.
Definition: os0event.cc:66
lock_rec_get_index
const dict_index_t * lock_rec_get_index(const lock_t *lock)
For a record lock, gets the index on which the lock is.
Definition: lock0lock.cc:6285
lock_rec_reset_and_inherit_gap_locks
void lock_rec_reset_and_inherit_gap_locks(const buf_block_t *heir_block, const buf_block_t *block, ulint heir_heap_no, ulint heap_no)
Resets the original locks on heir and replaces them with gap type locks inherited from rec.
Definition: lock0lock.cc:3317
lock_sys_t::timeout_event
os_event_t timeout_event
Set to the event that is created in the lock wait monitor thread.
Definition: lock0lock.h:791
hit_list_t
std::vector< TrxVersion, ut_allocator< TrxVersion > > hit_list_t
Definition: trx0types.h:581
lock_get_trx_id
trx_id_t lock_get_trx_id(const lock_t *lock)
Gets the id of the transaction owning a lock.
Definition: lock0lock.cc:6117
lock_op_t::table
dict_table_t * table
table to be locked
Definition: lock0lock.h:738
lock_get_type
uint32_t lock_get_type(const lock_t *lock)
Gets the type of a lock.
Definition: lock0lock.cc:6108
lock_sys_t::prdt_hash
hash_table_t * prdt_hash
hash table of the predicate lock
Definition: lock0lock.h:755
lock_trx_release_read_locks
void lock_trx_release_read_locks(trx_t *trx, bool only_gap)
Release read locks of a transacion.
Definition: lock0lock.cc:4250
dberr_t
dberr_t
Definition: db0err.h:38
lock_sec_rec_modify_check_and_lock
dberr_t lock_sec_rec_modify_check_and_lock(ulint flags, buf_block_t *block, const rec_t *rec, dict_index_t *index, que_thr_t *thr, mtr_t *mtr)
Checks if locks of other transactions prevent an immediate modify (delete mark or delete unmark) of a...
Definition: lock0lock.cc:5814
lock_sys_t::wait_mutex
LockMutex wait_mutex
Mutex protecting the next two fields.
Definition: lock0lock.h:761
lock_trx_has_rec_x_lock
bool lock_trx_has_rec_x_lock(que_thr_t *thr, const dict_table_t *table, const buf_block_t *block, ulint heap_no)
Check if the transaction holds an exclusive lock on a record.
Definition: lock0lock.cc:6587
lock_update_merge_left
void lock_update_merge_left(const buf_block_t *left_block, const rec_t *orig_pred, const buf_block_t *right_block)
Updates the lock table when a page is merged to the left.
Definition: lock0lock.cc:3262
lock_get_table_name
const table_name_t & lock_get_table_name(const lock_t *lock)
Determine which table a lock is associated with.
Definition: lock0lock.cc:6279
dict_table_t
Data structure for a database table.
Definition: dict0mem.h:1510
lock_update_split_left
void lock_update_split_left(const buf_block_t *right_block, const buf_block_t *left_block)
Updates the lock table when a page is split to the left.
Definition: lock0lock.cc:3244
innobase_deadlock_detect
bool innobase_deadlock_detect
Definition: lock0lock.cc:67
buf_block_t
The buffer control block structure.
Definition: buf0buf.h:1318
lock_rec_trx_wait
void lock_rec_trx_wait(lock_t *lock, ulint i, ulint type)
Reset the nth bit of a record lock.
Definition: lock0lock.cc:622
lock_sec_rec_read_check_and_lock
dberr_t lock_sec_rec_read_check_and_lock(lock_duration_t duration, const buf_block_t *block, const rec_t *rec, dict_index_t *index, const ulint *offsets, select_mode sel_mode, lock_mode mode, ulint gap_mode, que_thr_t *thr)
Like lock_clust_rec_read_check_and_lock(), but reads a secondary index record.
Definition: lock0lock.cc:5888
LockMutex
ib_mutex_t LockMutex
Definition: lock0lock.h:742
lock_get_first_trx_locks
const lock_t * lock_get_first_trx_locks(const trx_lock_t *trx_lock)
Get the first lock of a trx lock list.
Definition: lock0lock.cc:6146
lock_get_immutable_id
uint64_t lock_get_immutable_id(const lock_t *lock)
Gets the immutable id of this lock.
Definition: lock0lock.cc:6121
lock_trx_handle_wait
dberr_t lock_trx_handle_wait(trx_t *trx)
Check whether the transaction has already been rolled back because it was selected as a deadlock vict...
Definition: lock0lock.cc:6474
rec_t
byte rec_t
Definition: rem0types.h:39
lock_check_trx_id_sanity
bool lock_check_trx_id_sanity(trx_id_t trx_id, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
Checks that a transaction id is sensible, i.e., not in the future.
Definition: lock0lock.cc:201
que0types.h
lock_rec_discard
void lock_rec_discard(lock_t *in_lock)
Removes a record lock request, waiting or granted, from the queue.
Definition: lock0lock.cc:2439
lock_table_ix_resurrect
void lock_table_ix_resurrect(dict_table_t *table, trx_t *trx)
Creates a table IX lock object for a resurrected transaction.
Definition: lock0lock.cc:3904
lock_mode
lock_mode
Definition: lock0types.h:51
lock_move_rec_list_end
void lock_move_rec_list_end(const buf_block_t *new_block, const buf_block_t *block, const rec_t *rec)
Moves the explicit locks on user records to another page if a record list end is moved to another pag...
Definition: lock0lock.cc:2883
lock_move_reorganize_page
void lock_move_reorganize_page(const buf_block_t *block, const buf_block_t *oblock)
Updates the lock table when we have reorganized a page.
Definition: lock0lock.cc:2760
srv0srv.h
lock_rec_find_next_set_bit
ulint lock_rec_find_next_set_bit(const lock_t *lock, ulint heap_no)
Looks for the next set bit in the record lock bitmap.
Definition: lock0lock.cc:584
hash0hash.h
table_name_t
Table name wrapper for pretty-printing.
Definition: dict0mem.h:439
lock_duration_t::AT_LEAST_STATEMENT
@ AT_LEAST_STATEMENT
Keep the lock around for at least the duration of the current statement, in particular make sure it i...
lock_sys_t
The lock system struct.
Definition: lock0lock.h:745
lock_op_t::mode
lock_mode mode
lock mode
Definition: lock0lock.h:739
hash_table_t
Definition: hash0hash.h:399
lock_rec_store_on_page_infimum
void lock_rec_store_on_page_infimum(const buf_block_t *block, const rec_t *rec)
Stores on the page infimum record the explicit locks of another record.
Definition: lock0lock.cc:3458
lock_on_statement_end
void lock_on_statement_end(trx_t *trx)
Called to inform lock-sys that a statement processing for a trx has just finished.
Definition: lock0lock.cc:2557
lock_get_type_str
const char * lock_get_type_str(const lock_t *lock)
Gets the type of a lock in a human readable string.
Definition: lock0lock.cc:6236
lock_trx_lock_list_init
void lock_trx_lock_list_init(trx_lock_list_t *lock_list)
Initialise the trx lock list.
Definition: lock0lock.cc:6576
lock_rec_unlock
void lock_rec_unlock(trx_t *trx, const buf_block_t *block, const rec_t *rec, lock_mode lock_mode)
Removes a granted record lock of a transaction from the queue and grants locks to other transactions ...
Definition: lock0lock.cc:4120
lock_sys_t::rec_hash
hash_table_t * rec_hash
hash table of the record locks
Definition: lock0lock.h:753
lock_t
Lock struct; protected by lock_sys->mutex.
Definition: lock0priv.h:125
select_mode
select_mode
Definition: lock0types.h:44
table_id_t
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:215
lock_update_delete
void lock_update_delete(const buf_block_t *block, const rec_t *rec)
Updates the lock table when a record is removed.
Definition: lock0lock.cc:3421
lock_sys_t::last_slot
srv_slot_t * last_slot
highest slot ever used in the waiting_threads array, protected by lock_sys->wait_mutex
Definition: lock0lock.h:767
lock_sys_t::mark_age_updated
uint64_t mark_age_updated
Marker value before trx_t::age.
Definition: lock0lock.h:797
lock_report_trx_id_insanity
void lock_report_trx_id_insanity(trx_id_t trx_id, const rec_t *rec, const dict_index_t *index, const ulint *offsets, trx_id_t max_trx_id)
Reports that a transaction id is insensible, i.e., in the future.
Definition: lock0lock.cc:179
lock_make_trx_hit_list
void lock_make_trx_hit_list(trx_t *trx, hit_list_t &hit_list)
Iterate over the granted locks which conflict with trx->lock.wait_lock and prepare the hit list for A...
Definition: lock0lock.cc:2016
lock_op_t
Lock operation struct.
Definition: lock0lock.h:737
lock_sys_t::pad1
char pad1[INNOBASE_CACHE_LINE_SIZE]
padding to prevent other memory update hotspots from residing on the same memory cache line
Definition: lock0lock.h:746
lock_move_rec_list_start
void lock_move_rec_list_start(const buf_block_t *new_block, const buf_block_t *block, const rec_t *rec, const rec_t *old_end)
Moves the explicit locks on user records to another page if a record list start is moved to another p...
Definition: lock0lock.cc:2973
lock_sys
lock_sys_t * lock_sys
The lock system.
Definition: lock0lock.cc:168
lock_rec_free_all_from_discard_page
void lock_rec_free_all_from_discard_page(const buf_block_t *block)
Removes record lock objects set on an index page which is discarded.
Definition: lock0lock.cc:2501
lock_sys_t::prdt_page_hash
hash_table_t * prdt_page_hash
hash table of the page lock
Definition: lock0lock.h:757
lock_update_discard
void lock_update_discard(const buf_block_t *heir_block, ulint heir_heap_no, const buf_block_t *block)
Updates the lock table when a page is discarded.
Definition: lock0lock.cc:3339
trx0types.h
lock_table
dberr_t lock_table(ulint flags, dict_table_t *table, lock_mode mode, que_thr_t *thr)
Locks the specified database table in the mode given.
Definition: lock0lock.cc:3798
lock_duration_t
lock_duration_t
Used to specify the intended duration of a record lock.
Definition: lock0lock.h:266
lock_table_has_locks
bool lock_table_has_locks(const dict_table_t *table)
Check if there are any locks (table or rec) against table.
Definition: lock0lock.cc:6542
lock_sys_close
void lock_sys_close(void)
Closes the lock system at database shutdown.
Definition: lock0lock.cc:377
gis0rtree.h
lock_rtr_move_rec_list
void lock_rtr_move_rec_list(const buf_block_t *new_block, const buf_block_t *block, rtr_rec_move_t *rec_move, ulint num_move)
Moves the explicit locks on user records to another page if a record list start is moved to another p...
Definition: lock0lock.cc:3067
consts::FILE
const std::string FILE("FILE")
buf0types.h
lock_number_of_rows_locked
ulint lock_number_of_rows_locked(const trx_lock_t *trx_lock)
Return approximate number or record locks (bits set in the bitmap) for this transaction.
Definition: lock0lock.cc:913
lock_print_info_all_transactions
void lock_print_info_all_transactions(FILE *file)
Prints info of locks for each transaction.
Definition: lock0lock.cc:5026
ut0vec.h
ReadView
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
lock_hash_get
UNIV_INLINE hash_table_t * lock_hash_get(ulint mode)
Get the lock hash table.
lock_rec_get_index_name
const char * lock_rec_get_index_name(const lock_t *lock)
For a record lock, gets the name of the index on which the lock is.
Definition: lock0lock.cc:6296
lock_clust_rec_read_check_and_lock_alt
dberr_t lock_clust_rec_read_check_and_lock_alt(const buf_block_t *block, const rec_t *rec, dict_index_t *index, lock_mode mode, ulint gap_mode, que_thr_t *thr)
Checks if locks of other transactions prevent an immediate read, or passing over by a read cursor,...
Definition: lock0lock.cc:6004
rtr_rec_move
Definition: gis0type.h:166
lock_get_next_trx_locks
const lock_t * lock_get_next_trx_locks(const lock_t *lock)
Get the next lock of a trx lock list.
Definition: lock0lock.cc:6158
lock_sys_t::n_lock_max_wait_time
ulint n_lock_max_wait_time
Max wait time.
Definition: lock0lock.h:789
lock_get_mode_str
const char * lock_get_mode_str(const lock_t *lock)
Gets the mode of a lock in a human readable string.
Definition: lock0lock.cc:6179
lock_update_insert
void lock_update_insert(const buf_block_t *block, const rec_t *rec)
Updates the lock table when a new user record is inserted.
Definition: lock0lock.cc:3397
lock_clust_rec_modify_check_and_lock
dberr_t lock_clust_rec_modify_check_and_lock(ulint flags, const buf_block_t *block, const rec_t *rec, dict_index_t *index, const ulint *offsets, que_thr_t *thr)
Checks if locks of other transactions prevent an immediate modify (update, delete mark,...
Definition: lock0lock.cc:5761
lock_get_table_id
table_id_t lock_get_table_id(const lock_t *lock)
Gets the id of the table on which the lock is.
Definition: lock0lock.cc:6267
lock_sys_create
void lock_sys_create(ulint n_cells)
Creates the lock system at database start.
Definition: lock0lock.cc:291
HttpMethod::type
int type
Definition: http_common.h:411
lock_rec_find_set_bit
ulint lock_rec_find_set_bit(const lock_t *lock)
Looks for a set bit in a record lock bitmap.
Definition: lock0lock.cc:567
lock_get_trx_immutable_id
uint64_t lock_get_trx_immutable_id(const lock_t *lock)
Gets the immutable id of the transaction owning a lock.
Definition: lock0lock.cc:6113
lock_update_root_raise
void lock_update_root_raise(const buf_block_t *block, const buf_block_t *root)
Updates the lock table when the root page is copied to another in btr_root_raise_and_insert.
Definition: lock0lock.cc:3211
lock_clust_rec_read_check_and_lock
dberr_t lock_clust_rec_read_check_and_lock(lock_duration_t duration, const buf_block_t *block, const rec_t *rec, dict_index_t *index, const ulint *offsets, select_mode sel_mode, lock_mode mode, ulint gap_mode, que_thr_t *thr)
Checks if locks of other transactions prevent an immediate read, or passing over by a read cursor,...
Definition: lock0lock.cc:5944
INNOBASE_CACHE_LINE_SIZE
#define INNOBASE_CACHE_LINE_SIZE
CPU cache line size.
Definition: ut0counter.h:52
lock_trx_print_wait_and_mvcc_state
void lock_trx_print_wait_and_mvcc_state(FILE *file, const trx_t *trx)
Prints transaction lock wait and MVCC state.
Definition: lock0lock.cc:4882
lock_rec_hash
UNIV_INLINE ulint lock_rec_hash(space_id_t space, page_no_t page_no)
Calculates the hash value of a page file address: used in inserting or searching for a lock in the ha...
lock_update_copy_and_discard
void lock_update_copy_and_discard(const buf_block_t *new_block, const buf_block_t *block)
Updates the lock table when a page is copied to another and the original page is removed from the cha...
Definition: lock0lock.cc:3226
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
lock_update_split_right
void lock_update_split_right(const buf_block_t *right_block, const buf_block_t *left_block)
Updates the lock table when a page is split to the right.
Definition: lock0lock.cc:3140
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
lock_sys_t::m_seq
uint64_t m_seq
Lock timestamp counter.
Definition: lock0lock.h:801
lock_sys_t::mutex
LockMutex mutex
Mutex protecting the locks.
Definition: lock0lock.h:751
lock_duration_t::REGULAR
@ REGULAR
Keep the lock according to the rules of particular isolation level, in particular in case of READ COM...
lock_sys_t::waiting_threads
srv_slot_t * waiting_threads
Array of user threads suspended while waiting for locks within InnoDB, protected by the lock_sys->wai...
Definition: lock0lock.h:763
srv_slot_t
Thread slot in the thread table.
Definition: srv0srv.h:1164
lock_rec_insert_check_and_lock
dberr_t lock_rec_insert_check_and_lock(ulint flags, const rec_t *rec, buf_block_t *block, dict_index_t *index, que_thr_t *thr, mtr_t *mtr, ibool *inherit)
Checks if locks of other transactions prevent an immediate insert of a record.
Definition: lock0lock.cc:5491
lock_get_size
ulint lock_get_size(void)
Gets the size of a lock struct.
Definition: lock0lock.cc:410
lock_sys_resize
void lock_sys_resize(ulint n_cells)
Resize the lock hash table.
Definition: lock0lock.cc:331
lock_table_for_trx
dberr_t lock_table_for_trx(dict_table_t *table, trx_t *trx, enum lock_mode mode)
Sets a lock on a table based on the given mode.
Definition: lock0lock.cc:4040
que_thr_t
Definition: que0que.h:246
lock_rec_convert_active_impl_to_expl
void lock_rec_convert_active_impl_to_expl(const buf_block_t *block, const rec_t *rec, dict_index_t *index, const ulint *offsets, trx_t *trx, ulint heap_no)
This function is kind of wrapper to lock_rec_convert_impl_to_expl_for_trx() function with functionail...
Definition: lock0lock.cc:5745
lock_set_timeout_event
void lock_set_timeout_event()
Set the lock system timeout event.
Definition: lock0lock.cc:6583
index
char * index(const char *, int c)
Definition: mysql.cc:2875
mtr0types.h
trx_t
Definition: trx0trx.h:780
lock_remove_all_on_table
void lock_remove_all_on_table(dict_table_t *table, ibool remove_also_table_sx_locks)
Removes locks on a table to be dropped.
Definition: lock0lock.cc:4460
lock_wait_request_check_for_cycles
void lock_wait_request_check_for_cycles()
Notifies the thread which analyzes wait-for-graph that there was at least one new edge added or modif...
Definition: lock0wait.cc:190
lock_unlock_table_autoinc
void lock_unlock_table_autoinc(trx_t *trx)
Unlocks AUTO_INC type locks that were possibly reserved by a trx.
Definition: lock0lock.cc:6350
lock_number_of_tables_locked
ulint lock_number_of_tables_locked(const trx_t *trx)
Return the number of table locks for a transaction.
Definition: lock0lock.cc:921
lock_wait_suspend_thread
void lock_wait_suspend_thread(que_thr_t *thr)
Puts a user OS thread to wait for a lock to be released.
Definition: lock0wait.cc:197
flags
static int flags[50]
Definition: hp_test1.cc:39
lock0types.h
rem0types.h