~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/include/lock0lock.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1996, 2009, Innobase Oy. 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 as published by the Free Software
 
7
Foundation; version 2 of the License.
 
8
 
 
9
This program is distributed in the hope that it will be useful, but WITHOUT
 
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
12
 
 
13
You should have received a copy of the GNU General Public License along with
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/lock0lock.h
 
21
The transaction lock system
 
22
 
 
23
Created 5/7/1996 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef lock0lock_h
 
27
#define lock0lock_h
 
28
 
 
29
#include "univ.i"
 
30
#include "buf0types.h"
 
31
#include "trx0types.h"
 
32
#include "mtr0types.h"
 
33
#include "rem0types.h"
 
34
#include "dict0types.h"
 
35
#include "que0types.h"
 
36
#include "lock0types.h"
 
37
#include "read0types.h"
 
38
#include "hash0hash.h"
 
39
#include "ut0vec.h"
 
40
 
 
41
#ifdef UNIV_DEBUG
 
42
extern ibool    lock_print_waits;
 
43
#endif /* UNIV_DEBUG */
 
44
/* Buffer for storing information about the most recent deadlock error */
 
45
extern FILE*    lock_latest_err_file;
 
46
 
 
47
/*********************************************************************//**
 
48
Gets the size of a lock struct.
 
49
@return size in bytes */
 
50
UNIV_INTERN
 
51
ulint
 
52
lock_get_size(void);
 
53
/*===============*/
 
54
/*********************************************************************//**
 
55
Creates the lock system at database start. */
 
56
UNIV_INTERN
 
57
void
 
58
lock_sys_create(
 
59
/*============*/
 
60
        ulint   n_cells);       /*!< in: number of slots in lock hash table */
 
61
/*********************************************************************//**
 
62
Closes the lock system at database shutdown. */
 
63
UNIV_INTERN
 
64
void
 
65
lock_sys_close(void);
 
66
/*================*/
 
67
/*********************************************************************//**
 
68
Checks if some transaction has an implicit x-lock on a record in a clustered
 
69
index.
 
70
@return transaction which has the x-lock, or NULL */
 
71
UNIV_INLINE
 
72
trx_t*
 
73
lock_clust_rec_some_has_impl(
 
74
/*=========================*/
 
75
        const rec_t*    rec,    /*!< in: user record */
 
76
        dict_index_t*   index,  /*!< in: clustered index */
 
77
        const ulint*    offsets);/*!< in: rec_get_offsets(rec, index) */
 
78
/*********************************************************************//**
 
79
Gets the heap_no of the smallest user record on a page.
 
80
@return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */
 
81
UNIV_INLINE
 
82
ulint
 
83
lock_get_min_heap_no(
 
84
/*=================*/
 
85
        const buf_block_t*      block); /*!< in: buffer block */
 
86
/*************************************************************//**
 
87
Updates the lock table when we have reorganized a page. NOTE: we copy
 
88
also the locks set on the infimum of the page; the infimum may carry
 
89
locks if an update of a record is occurring on the page, and its locks
 
90
were temporarily stored on the infimum. */
 
91
UNIV_INTERN
 
92
void
 
93
lock_move_reorganize_page(
 
94
/*======================*/
 
95
        const buf_block_t*      block,  /*!< in: old index page, now
 
96
                                        reorganized */
 
97
        const buf_block_t*      oblock);/*!< in: copy of the old, not
 
98
                                        reorganized page */
 
99
/*************************************************************//**
 
100
Moves the explicit locks on user records to another page if a record
 
101
list end is moved to another page. */
 
102
UNIV_INTERN
 
103
void
 
104
lock_move_rec_list_end(
 
105
/*===================*/
 
106
        const buf_block_t*      new_block,      /*!< in: index page to move to */
 
107
        const buf_block_t*      block,          /*!< in: index page */
 
108
        const rec_t*            rec);           /*!< in: record on page: this
 
109
                                                is the first record moved */
 
110
/*************************************************************//**
 
111
Moves the explicit locks on user records to another page if a record
 
112
list start is moved to another page. */
 
113
UNIV_INTERN
 
114
void
 
115
lock_move_rec_list_start(
 
116
/*=====================*/
 
117
        const buf_block_t*      new_block,      /*!< in: index page to move to */
 
118
        const buf_block_t*      block,          /*!< in: index page */
 
119
        const rec_t*            rec,            /*!< in: record on page:
 
120
                                                this is the first
 
121
                                                record NOT copied */
 
122
        const rec_t*            old_end);       /*!< in: old
 
123
                                                previous-to-last
 
124
                                                record on new_page
 
125
                                                before the records
 
126
                                                were copied */
 
127
/*************************************************************//**
 
128
Updates the lock table when a page is split to the right. */
 
129
UNIV_INTERN
 
130
void
 
131
lock_update_split_right(
 
132
/*====================*/
 
133
        const buf_block_t*      right_block,    /*!< in: right page */
 
134
        const buf_block_t*      left_block);    /*!< in: left page */
 
135
/*************************************************************//**
 
136
Updates the lock table when a page is merged to the right. */
 
137
UNIV_INTERN
 
138
void
 
139
lock_update_merge_right(
 
140
/*====================*/
 
141
        const buf_block_t*      right_block,    /*!< in: right page to
 
142
                                                which merged */
 
143
        const rec_t*            orig_succ,      /*!< in: original
 
144
                                                successor of infimum
 
145
                                                on the right page
 
146
                                                before merge */
 
147
        const buf_block_t*      left_block);    /*!< in: merged index
 
148
                                                page which will be
 
149
                                                discarded */
 
150
/*************************************************************//**
 
151
Updates the lock table when the root page is copied to another in
 
152
btr_root_raise_and_insert. Note that we leave lock structs on the
 
153
root page, even though they do not make sense on other than leaf
 
154
pages: the reason is that in a pessimistic update the infimum record
 
155
of the root page will act as a dummy carrier of the locks of the record
 
156
to be updated. */
 
157
UNIV_INTERN
 
158
void
 
159
lock_update_root_raise(
 
160
/*===================*/
 
161
        const buf_block_t*      block,  /*!< in: index page to which copied */
 
162
        const buf_block_t*      root);  /*!< in: root page */
 
163
/*************************************************************//**
 
164
Updates the lock table when a page is copied to another and the original page
 
165
is removed from the chain of leaf pages, except if page is the root! */
 
166
UNIV_INTERN
 
167
void
 
168
lock_update_copy_and_discard(
 
169
/*=========================*/
 
170
        const buf_block_t*      new_block,      /*!< in: index page to
 
171
                                                which copied */
 
172
        const buf_block_t*      block);         /*!< in: index page;
 
173
                                                NOT the root! */
 
174
/*************************************************************//**
 
175
Updates the lock table when a page is split to the left. */
 
176
UNIV_INTERN
 
177
void
 
178
lock_update_split_left(
 
179
/*===================*/
 
180
        const buf_block_t*      right_block,    /*!< in: right page */
 
181
        const buf_block_t*      left_block);    /*!< in: left page */
 
182
/*************************************************************//**
 
183
Updates the lock table when a page is merged to the left. */
 
184
UNIV_INTERN
 
185
void
 
186
lock_update_merge_left(
 
187
/*===================*/
 
188
        const buf_block_t*      left_block,     /*!< in: left page to
 
189
                                                which merged */
 
190
        const rec_t*            orig_pred,      /*!< in: original predecessor
 
191
                                                of supremum on the left page
 
192
                                                before merge */
 
193
        const buf_block_t*      right_block);   /*!< in: merged index page
 
194
                                                which will be discarded */
 
195
/*************************************************************//**
 
196
Resets the original locks on heir and replaces them with gap type locks
 
197
inherited from rec. */
 
198
UNIV_INTERN
 
199
void
 
200
lock_rec_reset_and_inherit_gap_locks(
 
201
/*=================================*/
 
202
        const buf_block_t*      heir_block,     /*!< in: block containing the
 
203
                                                record which inherits */
 
204
        const buf_block_t*      block,          /*!< in: block containing the
 
205
                                                record from which inherited;
 
206
                                                does NOT reset the locks on
 
207
                                                this record */
 
208
        ulint                   heir_heap_no,   /*!< in: heap_no of the
 
209
                                                inheriting record */
 
210
        ulint                   heap_no);       /*!< in: heap_no of the
 
211
                                                donating record */
 
212
/*************************************************************//**
 
213
Updates the lock table when a page is discarded. */
 
214
UNIV_INTERN
 
215
void
 
216
lock_update_discard(
 
217
/*================*/
 
218
        const buf_block_t*      heir_block,     /*!< in: index page
 
219
                                                which will inherit the locks */
 
220
        ulint                   heir_heap_no,   /*!< in: heap_no of the record
 
221
                                                which will inherit the locks */
 
222
        const buf_block_t*      block);         /*!< in: index page
 
223
                                                which will be discarded */
 
224
/*************************************************************//**
 
225
Updates the lock table when a new user record is inserted. */
 
226
UNIV_INTERN
 
227
void
 
228
lock_update_insert(
 
229
/*===============*/
 
230
        const buf_block_t*      block,  /*!< in: buffer block containing rec */
 
231
        const rec_t*            rec);   /*!< in: the inserted record */
 
232
/*************************************************************//**
 
233
Updates the lock table when a record is removed. */
 
234
UNIV_INTERN
 
235
void
 
236
lock_update_delete(
 
237
/*===============*/
 
238
        const buf_block_t*      block,  /*!< in: buffer block containing rec */
 
239
        const rec_t*            rec);   /*!< in: the record to be removed */
 
240
/*********************************************************************//**
 
241
Stores on the page infimum record the explicit locks of another record.
 
242
This function is used to store the lock state of a record when it is
 
243
updated and the size of the record changes in the update. The record
 
244
is in such an update moved, perhaps to another page. The infimum record
 
245
acts as a dummy carrier record, taking care of lock releases while the
 
246
actual record is being moved. */
 
247
UNIV_INTERN
 
248
void
 
249
lock_rec_store_on_page_infimum(
 
250
/*===========================*/
 
251
        const buf_block_t*      block,  /*!< in: buffer block containing rec */
 
252
        const rec_t*            rec);   /*!< in: record whose lock state
 
253
                                        is stored on the infimum
 
254
                                        record of the same page; lock
 
255
                                        bits are reset on the
 
256
                                        record */
 
257
/*********************************************************************//**
 
258
Restores the state of explicit lock requests on a single record, where the
 
259
state was stored on the infimum of the page. */
 
260
UNIV_INTERN
 
261
void
 
262
lock_rec_restore_from_page_infimum(
 
263
/*===============================*/
 
264
        const buf_block_t*      block,  /*!< in: buffer block containing rec */
 
265
        const rec_t*            rec,    /*!< in: record whose lock state
 
266
                                        is restored */
 
267
        const buf_block_t*      donator);/*!< in: page (rec is not
 
268
                                        necessarily on this page)
 
269
                                        whose infimum stored the lock
 
270
                                        state; lock bits are reset on
 
271
                                        the infimum */
 
272
/*********************************************************************//**
 
273
Returns TRUE if there are explicit record locks on a page.
 
274
@return TRUE if there are explicit record locks on the page */
 
275
UNIV_INTERN
 
276
ibool
 
277
lock_rec_expl_exist_on_page(
 
278
/*========================*/
 
279
        ulint   space,  /*!< in: space id */
 
280
        ulint   page_no);/*!< in: page number */
 
281
/*********************************************************************//**
 
282
Checks if locks of other transactions prevent an immediate insert of
 
283
a record. If they do, first tests if the query thread should anyway
 
284
be suspended for some reason; if not, then puts the transaction and
 
285
the query thread to the lock wait state and inserts a waiting request
 
286
for a gap x-lock to the lock queue.
 
287
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
288
UNIV_INTERN
 
289
ulint
 
290
lock_rec_insert_check_and_lock(
 
291
/*===========================*/
 
292
        ulint           flags,  /*!< in: if BTR_NO_LOCKING_FLAG bit is
 
293
                                set, does nothing */
 
294
        const rec_t*    rec,    /*!< in: record after which to insert */
 
295
        buf_block_t*    block,  /*!< in/out: buffer block of rec */
 
296
        dict_index_t*   index,  /*!< in: index */
 
297
        que_thr_t*      thr,    /*!< in: query thread */
 
298
        mtr_t*          mtr,    /*!< in/out: mini-transaction */
 
299
        ibool*          inherit);/*!< out: set to TRUE if the new
 
300
                                inserted record maybe should inherit
 
301
                                LOCK_GAP type locks from the successor
 
302
                                record */
 
303
/*********************************************************************//**
 
304
Checks if locks of other transactions prevent an immediate modify (update,
 
305
delete mark, or delete unmark) of a clustered index record. If they do,
 
306
first tests if the query thread should anyway be suspended for some
 
307
reason; if not, then puts the transaction and the query thread to the
 
308
lock wait state and inserts a waiting request for a record x-lock to the
 
309
lock queue.
 
310
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
311
UNIV_INTERN
 
312
ulint
 
313
lock_clust_rec_modify_check_and_lock(
 
314
/*=================================*/
 
315
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
 
316
                                        bit is set, does nothing */
 
317
        const buf_block_t*      block,  /*!< in: buffer block of rec */
 
318
        const rec_t*            rec,    /*!< in: record which should be
 
319
                                        modified */
 
320
        dict_index_t*           index,  /*!< in: clustered index */
 
321
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
 
322
        que_thr_t*              thr);   /*!< in: query thread */
 
323
/*********************************************************************//**
 
324
Checks if locks of other transactions prevent an immediate modify
 
325
(delete mark or delete unmark) of a secondary index record.
 
326
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
327
UNIV_INTERN
 
328
ulint
 
329
lock_sec_rec_modify_check_and_lock(
 
330
/*===============================*/
 
331
        ulint           flags,  /*!< in: if BTR_NO_LOCKING_FLAG
 
332
                                bit is set, does nothing */
 
333
        buf_block_t*    block,  /*!< in/out: buffer block of rec */
 
334
        const rec_t*    rec,    /*!< in: record which should be
 
335
                                modified; NOTE: as this is a secondary
 
336
                                index, we always have to modify the
 
337
                                clustered index record first: see the
 
338
                                comment below */
 
339
        dict_index_t*   index,  /*!< in: secondary index */
 
340
        que_thr_t*      thr,    /*!< in: query thread */
 
341
        mtr_t*          mtr);   /*!< in/out: mini-transaction */
 
342
/*********************************************************************//**
 
343
Like the counterpart for a clustered index below, but now we read a
 
344
secondary index record.
 
345
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
346
UNIV_INTERN
 
347
ulint
 
348
lock_sec_rec_read_check_and_lock(
 
349
/*=============================*/
 
350
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
 
351
                                        bit is set, does nothing */
 
352
        const buf_block_t*      block,  /*!< in: buffer block of rec */
 
353
        const rec_t*            rec,    /*!< in: user record or page
 
354
                                        supremum record which should
 
355
                                        be read or passed over by a
 
356
                                        read cursor */
 
357
        dict_index_t*           index,  /*!< in: secondary index */
 
358
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
 
359
        enum lock_mode          mode,   /*!< in: mode of the lock which
 
360
                                        the read cursor should set on
 
361
                                        records: LOCK_S or LOCK_X; the
 
362
                                        latter is possible in
 
363
                                        SELECT FOR UPDATE */
 
364
        ulint                   gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
 
365
                                        LOCK_REC_NOT_GAP */
 
366
        que_thr_t*              thr);   /*!< in: query thread */
 
367
/*********************************************************************//**
 
368
Checks if locks of other transactions prevent an immediate read, or passing
 
369
over by a read cursor, of a clustered index record. If they do, first tests
 
370
if the query thread should anyway be suspended for some reason; if not, then
 
371
puts the transaction and the query thread to the lock wait state and inserts a
 
372
waiting request for a record lock to the lock queue. Sets the requested mode
 
373
lock on the record.
 
374
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
375
UNIV_INTERN
 
376
ulint
 
377
lock_clust_rec_read_check_and_lock(
 
378
/*===============================*/
 
379
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
 
380
                                        bit is set, does nothing */
 
381
        const buf_block_t*      block,  /*!< in: buffer block of rec */
 
382
        const rec_t*            rec,    /*!< in: user record or page
 
383
                                        supremum record which should
 
384
                                        be read or passed over by a
 
385
                                        read cursor */
 
386
        dict_index_t*           index,  /*!< in: clustered index */
 
387
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
 
388
        enum lock_mode          mode,   /*!< in: mode of the lock which
 
389
                                        the read cursor should set on
 
390
                                        records: LOCK_S or LOCK_X; the
 
391
                                        latter is possible in
 
392
                                        SELECT FOR UPDATE */
 
393
        ulint                   gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
 
394
                                        LOCK_REC_NOT_GAP */
 
395
        que_thr_t*              thr);   /*!< in: query thread */
 
396
/*********************************************************************//**
 
397
Checks if locks of other transactions prevent an immediate read, or passing
 
398
over by a read cursor, of a clustered index record. If they do, first tests
 
399
if the query thread should anyway be suspended for some reason; if not, then
 
400
puts the transaction and the query thread to the lock wait state and inserts a
 
401
waiting request for a record lock to the lock queue. Sets the requested mode
 
402
lock on the record. This is an alternative version of
 
403
lock_clust_rec_read_check_and_lock() that does not require the parameter
 
404
"offsets".
 
405
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
406
UNIV_INTERN
 
407
ulint
 
408
lock_clust_rec_read_check_and_lock_alt(
 
409
/*===================================*/
 
410
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
 
411
                                        bit is set, does nothing */
 
412
        const buf_block_t*      block,  /*!< in: buffer block of rec */
 
413
        const rec_t*            rec,    /*!< in: user record or page
 
414
                                        supremum record which should
 
415
                                        be read or passed over by a
 
416
                                        read cursor */
 
417
        dict_index_t*           index,  /*!< in: clustered index */
 
418
        enum lock_mode          mode,   /*!< in: mode of the lock which
 
419
                                        the read cursor should set on
 
420
                                        records: LOCK_S or LOCK_X; the
 
421
                                        latter is possible in
 
422
                                        SELECT FOR UPDATE */
 
423
        ulint                   gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
 
424
                                        LOCK_REC_NOT_GAP */
 
425
        que_thr_t*              thr);   /*!< in: query thread */
 
426
/*********************************************************************//**
 
427
Checks that a record is seen in a consistent read.
 
428
@return TRUE if sees, or FALSE if an earlier version of the record
 
429
should be retrieved */
 
430
UNIV_INTERN
 
431
ibool
 
432
lock_clust_rec_cons_read_sees(
 
433
/*==========================*/
 
434
        const rec_t*    rec,    /*!< in: user record which should be read or
 
435
                                passed over by a read cursor */
 
436
        dict_index_t*   index,  /*!< in: clustered index */
 
437
        const ulint*    offsets,/*!< in: rec_get_offsets(rec, index) */
 
438
        read_view_t*    view);  /*!< in: consistent read view */
 
439
/*********************************************************************//**
 
440
Checks that a non-clustered index record is seen in a consistent read.
 
441
 
 
442
NOTE that a non-clustered index page contains so little information on
 
443
its modifications that also in the case FALSE, the present version of
 
444
rec may be the right, but we must check this from the clustered index
 
445
record.
 
446
 
 
447
@return TRUE if certainly sees, or FALSE if an earlier version of the
 
448
clustered index record might be needed */
 
449
UNIV_INTERN
 
450
ulint
 
451
lock_sec_rec_cons_read_sees(
 
452
/*========================*/
 
453
        const rec_t*            rec,    /*!< in: user record which
 
454
                                        should be read or passed over
 
455
                                        by a read cursor */
 
456
        const read_view_t*      view);  /*!< in: consistent read view */
 
457
/*********************************************************************//**
 
458
Locks the specified database table in the mode given. If the lock cannot
 
459
be granted immediately, the query thread is put to wait.
 
460
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
 
461
UNIV_INTERN
 
462
ulint
 
463
lock_table(
 
464
/*=======*/
 
465
        ulint           flags,  /*!< in: if BTR_NO_LOCKING_FLAG bit is set,
 
466
                                does nothing */
 
467
        dict_table_t*   table,  /*!< in: database table in dictionary cache */
 
468
        enum lock_mode  mode,   /*!< in: lock mode */
 
469
        que_thr_t*      thr);   /*!< in: query thread */
 
470
/*************************************************************//**
 
471
Removes a granted record lock of a transaction from the queue and grants
 
472
locks to other transactions waiting in the queue if they now are entitled
 
473
to a lock. */
 
474
UNIV_INTERN
 
475
void
 
476
lock_rec_unlock(
 
477
/*============*/
 
478
        trx_t*                  trx,    /*!< in: transaction that has
 
479
                                        set a record lock */
 
480
        const buf_block_t*      block,  /*!< in: buffer block containing rec */
 
481
        const rec_t*            rec,    /*!< in: record */
 
482
        enum lock_mode          lock_mode);/*!< in: LOCK_S or LOCK_X */
 
483
/*********************************************************************//**
 
484
Releases transaction locks, and releases possible other transactions waiting
 
485
because of these locks. */
 
486
UNIV_INTERN
 
487
void
 
488
lock_release_off_kernel(
 
489
/*====================*/
 
490
        trx_t*  trx);   /*!< in: transaction */
 
491
/*********************************************************************//**
 
492
Cancels a waiting lock request and releases possible other transactions
 
493
waiting behind it. */
 
494
UNIV_INTERN
 
495
void
 
496
lock_cancel_waiting_and_release(
 
497
/*============================*/
 
498
        lock_t* lock);  /*!< in: waiting lock request */
 
499
 
 
500
/*********************************************************************//**
 
501
Removes locks on a table to be dropped or truncated.
 
502
If remove_also_table_sx_locks is TRUE then table-level S and X locks are
 
503
also removed in addition to other table-level and record-level locks.
 
504
No lock, that is going to be removed, is allowed to be a wait lock. */
 
505
UNIV_INTERN
 
506
void
 
507
lock_remove_all_on_table(
 
508
/*=====================*/
 
509
        dict_table_t*   table,                  /*!< in: table to be dropped
 
510
                                                or truncated */
 
511
        ibool           remove_also_table_sx_locks);/*!< in: also removes
 
512
                                                table S and X locks */
 
513
 
 
514
/*********************************************************************//**
 
515
Calculates the fold value of a page file address: used in inserting or
 
516
searching for a lock in the hash table.
 
517
@return folded value */
 
518
UNIV_INLINE
 
519
ulint
 
520
lock_rec_fold(
 
521
/*==========*/
 
522
        ulint   space,  /*!< in: space */
 
523
        ulint   page_no)/*!< in: page number */
 
524
        __attribute__((const));
 
525
/*********************************************************************//**
 
526
Calculates the hash value of a page file address: used in inserting or
 
527
searching for a lock in the hash table.
 
528
@return hashed value */
 
529
UNIV_INLINE
 
530
ulint
 
531
lock_rec_hash(
 
532
/*==========*/
 
533
        ulint   space,  /*!< in: space */
 
534
        ulint   page_no);/*!< in: page number */
 
535
 
 
536
/**********************************************************************//**
 
537
Looks for a set bit in a record lock bitmap. Returns ULINT_UNDEFINED,
 
538
if none found.
 
539
@return bit index == heap number of the record, or ULINT_UNDEFINED if
 
540
none found */
 
541
UNIV_INTERN
 
542
ulint
 
543
lock_rec_find_set_bit(
 
544
/*==================*/
 
545
        const lock_t*   lock);  /*!< in: record lock with at least one
 
546
                                bit set */
 
547
 
 
548
/*********************************************************************//**
 
549
Gets the source table of an ALTER TABLE transaction.  The table must be
 
550
covered by an IX or IS table lock.
 
551
@return the source table of transaction, if it is covered by an IX or
 
552
IS table lock; dest if there is no source table, and NULL if the
 
553
transaction is locking more than two tables or an inconsistency is
 
554
found */
 
555
UNIV_INTERN
 
556
dict_table_t*
 
557
lock_get_src_table(
 
558
/*===============*/
 
559
        trx_t*          trx,    /*!< in: transaction */
 
560
        dict_table_t*   dest,   /*!< in: destination of ALTER TABLE */
 
561
        enum lock_mode* mode);  /*!< out: lock mode of the source table */
 
562
/*********************************************************************//**
 
563
Determine if the given table is exclusively "owned" by the given
 
564
transaction, i.e., transaction holds LOCK_IX and possibly LOCK_AUTO_INC
 
565
on the table.
 
566
@return TRUE if table is only locked by trx, with LOCK_IX, and
 
567
possibly LOCK_AUTO_INC */
 
568
UNIV_INTERN
 
569
ibool
 
570
lock_is_table_exclusive(
 
571
/*====================*/
 
572
        dict_table_t*   table,  /*!< in: table */
 
573
        trx_t*          trx);   /*!< in: transaction */
 
574
/*********************************************************************//**
 
575
Checks if a lock request lock1 has to wait for request lock2.
 
576
@return TRUE if lock1 has to wait for lock2 to be removed */
 
577
UNIV_INTERN
 
578
ibool
 
579
lock_has_to_wait(
 
580
/*=============*/
 
581
        const lock_t*   lock1,  /*!< in: waiting lock */
 
582
        const lock_t*   lock2); /*!< in: another lock; NOTE that it is
 
583
                                assumed that this has a lock bit set
 
584
                                on the same record as in lock1 if the
 
585
                                locks are record locks */
 
586
/*********************************************************************//**
 
587
Checks that a transaction id is sensible, i.e., not in the future.
 
588
@return TRUE if ok */
 
589
UNIV_INTERN
 
590
ibool
 
591
lock_check_trx_id_sanity(
 
592
/*=====================*/
 
593
        trx_id_t        trx_id,         /*!< in: trx id */
 
594
        const rec_t*    rec,            /*!< in: user record */
 
595
        dict_index_t*   index,          /*!< in: clustered index */
 
596
        const ulint*    offsets,        /*!< in: rec_get_offsets(rec, index) */
 
597
        ibool           has_kernel_mutex);/*!< in: TRUE if the caller owns the
 
598
                                        kernel mutex */
 
599
/*********************************************************************//**
 
600
Prints info of a table lock. */
 
601
UNIV_INTERN
 
602
void
 
603
lock_table_print(
 
604
/*=============*/
 
605
        FILE*           file,   /*!< in: file where to print */
 
606
        const lock_t*   lock);  /*!< in: table type lock */
 
607
/*********************************************************************//**
 
608
Prints info of a record lock. */
 
609
UNIV_INTERN
 
610
void
 
611
lock_rec_print(
 
612
/*===========*/
 
613
        FILE*           file,   /*!< in: file where to print */
 
614
        const lock_t*   lock);  /*!< in: record type lock */
 
615
/*********************************************************************//**
 
616
Prints info of locks for all transactions. */
 
617
UNIV_INTERN
 
618
void
 
619
lock_print_info_summary(
 
620
/*====================*/
 
621
        FILE*   file);  /*!< in: file where to print */
 
622
/*********************************************************************//**
 
623
Prints info of locks for each transaction. */
 
624
UNIV_INTERN
 
625
void
 
626
lock_print_info_all_transactions(
 
627
/*=============================*/
 
628
        FILE*   file);  /*!< in: file where to print */
 
629
/*********************************************************************//**
 
630
Return approximate number or record locks (bits set in the bitmap) for
 
631
this transaction. Since delete-marked records may be removed, the
 
632
record count will not be precise. */
 
633
UNIV_INTERN
 
634
ulint
 
635
lock_number_of_rows_locked(
 
636
/*=======================*/
 
637
        trx_t*  trx);   /*!< in: transaction */
 
638
/*******************************************************************//**
 
639
Check if a transaction holds any autoinc locks.
 
640
@return TRUE if the transaction holds any AUTOINC locks. */
 
641
UNIV_INTERN
 
642
ibool
 
643
lock_trx_holds_autoinc_locks(
 
644
/*=========================*/
 
645
        const trx_t*    trx);           /*!< in: transaction */
 
646
/*******************************************************************//**
 
647
Release all the transaction's autoinc locks. */
 
648
UNIV_INTERN
 
649
void
 
650
lock_release_autoinc_locks(
 
651
/*=======================*/
 
652
        trx_t*          trx);           /*!< in/out: transaction */
 
653
 
 
654
/*******************************************************************//**
 
655
Gets the type of a lock. Non-inline version for using outside of the
 
656
lock module.
 
657
@return LOCK_TABLE or LOCK_REC */
 
658
UNIV_INTERN
 
659
ulint
 
660
lock_get_type(
 
661
/*==========*/
 
662
        const lock_t*   lock);  /*!< in: lock */
 
663
 
 
664
/*******************************************************************//**
 
665
Gets the id of the transaction owning a lock.
 
666
@return transaction id */
 
667
UNIV_INTERN
 
668
ullint
 
669
lock_get_trx_id(
 
670
/*============*/
 
671
        const lock_t*   lock);  /*!< in: lock */
 
672
 
 
673
/*******************************************************************//**
 
674
Gets the mode of a lock in a human readable string.
 
675
The string should not be free()'d or modified.
 
676
@return lock mode */
 
677
UNIV_INTERN
 
678
const char*
 
679
lock_get_mode_str(
 
680
/*==============*/
 
681
        const lock_t*   lock);  /*!< in: lock */
 
682
 
 
683
/*******************************************************************//**
 
684
Gets the type of a lock in a human readable string.
 
685
The string should not be free()'d or modified.
 
686
@return lock type */
 
687
UNIV_INTERN
 
688
const char*
 
689
lock_get_type_str(
 
690
/*==============*/
 
691
        const lock_t*   lock);  /*!< in: lock */
 
692
 
 
693
/*******************************************************************//**
 
694
Gets the id of the table on which the lock is.
 
695
@return id of the table */
 
696
UNIV_INTERN
 
697
ullint
 
698
lock_get_table_id(
 
699
/*==============*/
 
700
        const lock_t*   lock);  /*!< in: lock */
 
701
 
 
702
/*******************************************************************//**
 
703
Gets the name of the table on which the lock is.
 
704
The string should not be free()'d or modified.
 
705
@return name of the table */
 
706
UNIV_INTERN
 
707
const char*
 
708
lock_get_table_name(
 
709
/*================*/
 
710
        const lock_t*   lock);  /*!< in: lock */
 
711
 
 
712
/*******************************************************************//**
 
713
For a record lock, gets the index on which the lock is.
 
714
@return index */
 
715
UNIV_INTERN
 
716
const dict_index_t*
 
717
lock_rec_get_index(
 
718
/*===============*/
 
719
        const lock_t*   lock);  /*!< in: lock */
 
720
 
 
721
/*******************************************************************//**
 
722
For a record lock, gets the name of the index on which the lock is.
 
723
The string should not be free()'d or modified.
 
724
@return name of the index */
 
725
UNIV_INTERN
 
726
const char*
 
727
lock_rec_get_index_name(
 
728
/*====================*/
 
729
        const lock_t*   lock);  /*!< in: lock */
 
730
 
 
731
/*******************************************************************//**
 
732
For a record lock, gets the tablespace number on which the lock is.
 
733
@return tablespace number */
 
734
UNIV_INTERN
 
735
ulint
 
736
lock_rec_get_space_id(
 
737
/*==================*/
 
738
        const lock_t*   lock);  /*!< in: lock */
 
739
 
 
740
/*******************************************************************//**
 
741
For a record lock, gets the page number on which the lock is.
 
742
@return page number */
 
743
UNIV_INTERN
 
744
ulint
 
745
lock_rec_get_page_no(
 
746
/*=================*/
 
747
        const lock_t*   lock);  /*!< in: lock */
 
748
 
 
749
/** Lock modes and types */
 
750
/* @{ */
 
751
#define LOCK_MODE_MASK  0xFUL   /*!< mask used to extract mode from the
 
752
                                type_mode field in a lock */
 
753
/** Lock types */
 
754
/* @{ */
 
755
#define LOCK_TABLE      16      /*!< table lock */
 
756
#define LOCK_REC        32      /*!< record lock */
 
757
#define LOCK_TYPE_MASK  0xF0UL  /*!< mask used to extract lock type from the
 
758
                                type_mode field in a lock */
 
759
#if LOCK_MODE_MASK & LOCK_TYPE_MASK
 
760
# error "LOCK_MODE_MASK & LOCK_TYPE_MASK"
 
761
#endif
 
762
 
 
763
#define LOCK_WAIT       256     /*!< Waiting lock flag; when set, it
 
764
                                means that the lock has not yet been
 
765
                                granted, it is just waiting for its
 
766
                                turn in the wait queue */
 
767
/* Precise modes */
 
768
#define LOCK_ORDINARY   0       /*!< this flag denotes an ordinary
 
769
                                next-key lock in contrast to LOCK_GAP
 
770
                                or LOCK_REC_NOT_GAP */
 
771
#define LOCK_GAP        512     /*!< when this bit is set, it means that the
 
772
                                lock holds only on the gap before the record;
 
773
                                for instance, an x-lock on the gap does not
 
774
                                give permission to modify the record on which
 
775
                                the bit is set; locks of this type are created
 
776
                                when records are removed from the index chain
 
777
                                of records */
 
778
#define LOCK_REC_NOT_GAP 1024   /*!< this bit means that the lock is only on
 
779
                                the index record and does NOT block inserts
 
780
                                to the gap before the index record; this is
 
781
                                used in the case when we retrieve a record
 
782
                                with a unique key, and is also used in
 
783
                                locking plain SELECTs (not part of UPDATE
 
784
                                or DELETE) when the user has set the READ
 
785
                                COMMITTED isolation level */
 
786
#define LOCK_INSERT_INTENTION 2048 /*!< this bit is set when we place a waiting
 
787
                                gap type record lock request in order to let
 
788
                                an insert of an index record to wait until
 
789
                                there are no conflicting locks by other
 
790
                                transactions on the gap; note that this flag
 
791
                                remains set when the waiting lock is granted,
 
792
                                or if the lock is inherited to a neighboring
 
793
                                record */
 
794
#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION)&LOCK_MODE_MASK
 
795
# error
 
796
#endif
 
797
#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION)&LOCK_TYPE_MASK
 
798
# error
 
799
#endif
 
800
/* @} */
 
801
 
 
802
/** Lock operation struct */
 
803
typedef struct lock_op_struct   lock_op_t;
 
804
/** Lock operation struct */
 
805
struct lock_op_struct{
 
806
        dict_table_t*   table;  /*!< table to be locked */
 
807
        enum lock_mode  mode;   /*!< lock mode */
 
808
};
 
809
 
 
810
/** The lock system struct */
 
811
struct lock_sys_struct{
 
812
        hash_table_t*   rec_hash;       /*!< hash table of the record locks */
 
813
};
 
814
 
 
815
/** The lock system */
 
816
extern lock_sys_t*      lock_sys;
 
817
 
 
818
 
 
819
#ifndef UNIV_NONINL
 
820
#include "lock0lock.ic"
 
821
#endif
 
822
 
 
823
#endif