~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/lock0lock.h

Merged vcol stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1996, 2010, 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., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 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 lock_clust_rec_read_check_and_lock(), but reads a
344
 
secondary index record.
345
 
@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK,
346
 
or DB_QUE_THR_SUSPENDED */
347
 
UNIV_INTERN
348
 
enum db_err
349
 
lock_sec_rec_read_check_and_lock(
350
 
/*=============================*/
351
 
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
352
 
                                        bit is set, does nothing */
353
 
        const buf_block_t*      block,  /*!< in: buffer block of rec */
354
 
        const rec_t*            rec,    /*!< in: user record or page
355
 
                                        supremum record which should
356
 
                                        be read or passed over by a
357
 
                                        read cursor */
358
 
        dict_index_t*           index,  /*!< in: secondary index */
359
 
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
360
 
        enum lock_mode          mode,   /*!< in: mode of the lock which
361
 
                                        the read cursor should set on
362
 
                                        records: LOCK_S or LOCK_X; the
363
 
                                        latter is possible in
364
 
                                        SELECT FOR UPDATE */
365
 
        ulint                   gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
366
 
                                        LOCK_REC_NOT_GAP */
367
 
        que_thr_t*              thr);   /*!< in: query thread */
368
 
/*********************************************************************//**
369
 
Checks if locks of other transactions prevent an immediate read, or passing
370
 
over by a read cursor, of a clustered index record. If they do, first tests
371
 
if the query thread should anyway be suspended for some reason; if not, then
372
 
puts the transaction and the query thread to the lock wait state and inserts a
373
 
waiting request for a record lock to the lock queue. Sets the requested mode
374
 
lock on the record.
375
 
@return DB_SUCCESS, DB_SUCCESS_LOCKED_REC, DB_LOCK_WAIT, DB_DEADLOCK,
376
 
or DB_QUE_THR_SUSPENDED */
377
 
UNIV_INTERN
378
 
enum db_err
379
 
lock_clust_rec_read_check_and_lock(
380
 
/*===============================*/
381
 
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
382
 
                                        bit is set, does nothing */
383
 
        const buf_block_t*      block,  /*!< in: buffer block of rec */
384
 
        const rec_t*            rec,    /*!< in: user record or page
385
 
                                        supremum record which should
386
 
                                        be read or passed over by a
387
 
                                        read cursor */
388
 
        dict_index_t*           index,  /*!< in: clustered index */
389
 
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
390
 
        enum lock_mode          mode,   /*!< in: mode of the lock which
391
 
                                        the read cursor should set on
392
 
                                        records: LOCK_S or LOCK_X; the
393
 
                                        latter is possible in
394
 
                                        SELECT FOR UPDATE */
395
 
        ulint                   gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
396
 
                                        LOCK_REC_NOT_GAP */
397
 
        que_thr_t*              thr);   /*!< in: query thread */
398
 
/*********************************************************************//**
399
 
Checks if locks of other transactions prevent an immediate read, or passing
400
 
over by a read cursor, of a clustered index record. If they do, first tests
401
 
if the query thread should anyway be suspended for some reason; if not, then
402
 
puts the transaction and the query thread to the lock wait state and inserts a
403
 
waiting request for a record lock to the lock queue. Sets the requested mode
404
 
lock on the record. This is an alternative version of
405
 
lock_clust_rec_read_check_and_lock() that does not require the parameter
406
 
"offsets".
407
 
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
408
 
UNIV_INTERN
409
 
ulint
410
 
lock_clust_rec_read_check_and_lock_alt(
411
 
/*===================================*/
412
 
        ulint                   flags,  /*!< in: if BTR_NO_LOCKING_FLAG
413
 
                                        bit is set, does nothing */
414
 
        const buf_block_t*      block,  /*!< in: buffer block of rec */
415
 
        const rec_t*            rec,    /*!< in: user record or page
416
 
                                        supremum record which should
417
 
                                        be read or passed over by a
418
 
                                        read cursor */
419
 
        dict_index_t*           index,  /*!< in: clustered index */
420
 
        enum lock_mode          mode,   /*!< in: mode of the lock which
421
 
                                        the read cursor should set on
422
 
                                        records: LOCK_S or LOCK_X; the
423
 
                                        latter is possible in
424
 
                                        SELECT FOR UPDATE */
425
 
        ulint                   gap_mode,/*!< in: LOCK_ORDINARY, LOCK_GAP, or
426
 
                                        LOCK_REC_NOT_GAP */
427
 
        que_thr_t*              thr);   /*!< in: query thread */
428
 
/*********************************************************************//**
429
 
Checks that a record is seen in a consistent read.
430
 
@return TRUE if sees, or FALSE if an earlier version of the record
431
 
should be retrieved */
432
 
UNIV_INTERN
433
 
ibool
434
 
lock_clust_rec_cons_read_sees(
435
 
/*==========================*/
436
 
        const rec_t*    rec,    /*!< in: user record which should be read or
437
 
                                passed over by a read cursor */
438
 
        dict_index_t*   index,  /*!< in: clustered index */
439
 
        const ulint*    offsets,/*!< in: rec_get_offsets(rec, index) */
440
 
        read_view_t*    view);  /*!< in: consistent read view */
441
 
/*********************************************************************//**
442
 
Checks that a non-clustered index record is seen in a consistent read.
443
 
 
444
 
NOTE that a non-clustered index page contains so little information on
445
 
its modifications that also in the case FALSE, the present version of
446
 
rec may be the right, but we must check this from the clustered index
447
 
record.
448
 
 
449
 
@return TRUE if certainly sees, or FALSE if an earlier version of the
450
 
clustered index record might be needed */
451
 
UNIV_INTERN
452
 
ulint
453
 
lock_sec_rec_cons_read_sees(
454
 
/*========================*/
455
 
        const rec_t*            rec,    /*!< in: user record which
456
 
                                        should be read or passed over
457
 
                                        by a read cursor */
458
 
        const read_view_t*      view);  /*!< in: consistent read view */
459
 
/*********************************************************************//**
460
 
Locks the specified database table in the mode given. If the lock cannot
461
 
be granted immediately, the query thread is put to wait.
462
 
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
463
 
UNIV_INTERN
464
 
ulint
465
 
lock_table(
466
 
/*=======*/
467
 
        ulint           flags,  /*!< in: if BTR_NO_LOCKING_FLAG bit is set,
468
 
                                does nothing */
469
 
        dict_table_t*   table,  /*!< in: database table in dictionary cache */
470
 
        enum lock_mode  mode,   /*!< in: lock mode */
471
 
        que_thr_t*      thr);   /*!< in: query thread */
472
 
/*************************************************************//**
473
 
Removes a granted record lock of a transaction from the queue and grants
474
 
locks to other transactions waiting in the queue if they now are entitled
475
 
to a lock. */
476
 
UNIV_INTERN
477
 
void
478
 
lock_rec_unlock(
479
 
/*============*/
480
 
        trx_t*                  trx,    /*!< in: transaction that has
481
 
                                        set a record lock */
482
 
        const buf_block_t*      block,  /*!< in: buffer block containing rec */
483
 
        const rec_t*            rec,    /*!< in: record */
484
 
        enum lock_mode          lock_mode);/*!< in: LOCK_S or LOCK_X */
485
 
/*********************************************************************//**
486
 
Releases transaction locks, and releases possible other transactions waiting
487
 
because of these locks. */
488
 
UNIV_INTERN
489
 
void
490
 
lock_release_off_kernel(
491
 
/*====================*/
492
 
        trx_t*  trx);   /*!< in: transaction */
493
 
/*********************************************************************//**
494
 
Cancels a waiting lock request and releases possible other transactions
495
 
waiting behind it. */
496
 
UNIV_INTERN
497
 
void
498
 
lock_cancel_waiting_and_release(
499
 
/*============================*/
500
 
        lock_t* lock);  /*!< in: waiting lock request */
501
 
 
502
 
/*********************************************************************//**
503
 
Removes locks on a table to be dropped or truncated.
504
 
If remove_also_table_sx_locks is TRUE then table-level S and X locks are
505
 
also removed in addition to other table-level and record-level locks.
506
 
No lock, that is going to be removed, is allowed to be a wait lock. */
507
 
UNIV_INTERN
508
 
void
509
 
lock_remove_all_on_table(
510
 
/*=====================*/
511
 
        dict_table_t*   table,                  /*!< in: table to be dropped
512
 
                                                or truncated */
513
 
        ibool           remove_also_table_sx_locks);/*!< in: also removes
514
 
                                                table S and X locks */
515
 
 
516
 
/*********************************************************************//**
517
 
Calculates the fold value of a page file address: used in inserting or
518
 
searching for a lock in the hash table.
519
 
@return folded value */
520
 
UNIV_INLINE
521
 
ulint
522
 
lock_rec_fold(
523
 
/*==========*/
524
 
        ulint   space,  /*!< in: space */
525
 
        ulint   page_no)/*!< in: page number */
526
 
        __attribute__((const));
527
 
/*********************************************************************//**
528
 
Calculates the hash value of a page file address: used in inserting or
529
 
searching for a lock in the hash table.
530
 
@return hashed value */
531
 
UNIV_INLINE
532
 
ulint
533
 
lock_rec_hash(
534
 
/*==========*/
535
 
        ulint   space,  /*!< in: space */
536
 
        ulint   page_no);/*!< in: page number */
537
 
 
538
 
/**********************************************************************//**
539
 
Looks for a set bit in a record lock bitmap. Returns ULINT_UNDEFINED,
540
 
if none found.
541
 
@return bit index == heap number of the record, or ULINT_UNDEFINED if
542
 
none found */
543
 
UNIV_INTERN
544
 
ulint
545
 
lock_rec_find_set_bit(
546
 
/*==================*/
547
 
        const lock_t*   lock);  /*!< in: record lock with at least one
548
 
                                bit set */
549
 
 
550
 
/*********************************************************************//**
551
 
Gets the source table of an ALTER TABLE transaction.  The table must be
552
 
covered by an IX or IS table lock.
553
 
@return the source table of transaction, if it is covered by an IX or
554
 
IS table lock; dest if there is no source table, and NULL if the
555
 
transaction is locking more than two tables or an inconsistency is
556
 
found */
557
 
UNIV_INTERN
558
 
dict_table_t*
559
 
lock_get_src_table(
560
 
/*===============*/
561
 
        trx_t*          trx,    /*!< in: transaction */
562
 
        dict_table_t*   dest,   /*!< in: destination of ALTER TABLE */
563
 
        enum lock_mode* mode);  /*!< out: lock mode of the source table */
564
 
/*********************************************************************//**
565
 
Determine if the given table is exclusively "owned" by the given
566
 
transaction, i.e., transaction holds LOCK_IX and possibly LOCK_AUTO_INC
567
 
on the table.
568
 
@return TRUE if table is only locked by trx, with LOCK_IX, and
569
 
possibly LOCK_AUTO_INC */
570
 
UNIV_INTERN
571
 
ibool
572
 
lock_is_table_exclusive(
573
 
/*====================*/
574
 
        dict_table_t*   table,  /*!< in: table */
575
 
        trx_t*          trx);   /*!< in: transaction */
576
 
/*********************************************************************//**
577
 
Checks if a lock request lock1 has to wait for request lock2.
578
 
@return TRUE if lock1 has to wait for lock2 to be removed */
579
 
UNIV_INTERN
580
 
ibool
581
 
lock_has_to_wait(
582
 
/*=============*/
583
 
        const lock_t*   lock1,  /*!< in: waiting lock */
584
 
        const lock_t*   lock2); /*!< in: another lock; NOTE that it is
585
 
                                assumed that this has a lock bit set
586
 
                                on the same record as in lock1 if the
587
 
                                locks are record locks */
588
 
/*********************************************************************//**
589
 
Checks that a transaction id is sensible, i.e., not in the future.
590
 
@return TRUE if ok */
591
 
UNIV_INTERN
592
 
ibool
593
 
lock_check_trx_id_sanity(
594
 
/*=====================*/
595
 
        trx_id_t        trx_id,         /*!< in: trx id */
596
 
        const rec_t*    rec,            /*!< in: user record */
597
 
        dict_index_t*   index,          /*!< in: clustered index */
598
 
        const ulint*    offsets,        /*!< in: rec_get_offsets(rec, index) */
599
 
        ibool           has_kernel_mutex);/*!< in: TRUE if the caller owns the
600
 
                                        kernel mutex */
601
 
/*********************************************************************//**
602
 
Prints info of a table lock. */
603
 
UNIV_INTERN
604
 
void
605
 
lock_table_print(
606
 
/*=============*/
607
 
        FILE*           file,   /*!< in: file where to print */
608
 
        const lock_t*   lock);  /*!< in: table type lock */
609
 
/*********************************************************************//**
610
 
Prints info of a record lock. */
611
 
UNIV_INTERN
612
 
void
613
 
lock_rec_print(
614
 
/*===========*/
615
 
        FILE*           file,   /*!< in: file where to print */
616
 
        const lock_t*   lock);  /*!< in: record type lock */
617
 
/*********************************************************************//**
618
 
Prints info of locks for all transactions.
619
 
@return FALSE if not able to obtain kernel mutex
620
 
and exits without printing info */
621
 
UNIV_INTERN
622
 
ibool
623
 
lock_print_info_summary(
624
 
/*====================*/
625
 
        FILE*   file,   /*!< in: file where to print */
626
 
        ibool   nowait);/*!< in: whether to wait for the kernel mutex */
627
 
/*************************************************************************
628
 
Prints info of locks for each transaction. */
629
 
UNIV_INTERN
630
 
void
631
 
lock_print_info_all_transactions(
632
 
/*=============================*/
633
 
        FILE*   file);  /*!< in: file where to print */
634
 
/*********************************************************************//**
635
 
Return approximate number or record locks (bits set in the bitmap) for
636
 
this transaction. Since delete-marked records may be removed, the
637
 
record count will not be precise. */
638
 
UNIV_INTERN
639
 
ulint
640
 
lock_number_of_rows_locked(
641
 
/*=======================*/
642
 
        const trx_t*    trx);   /*!< in: transaction */
643
 
/*******************************************************************//**
644
 
Check if a transaction holds any autoinc locks.
645
 
@return TRUE if the transaction holds any AUTOINC locks. */
646
 
UNIV_INTERN
647
 
ibool
648
 
lock_trx_holds_autoinc_locks(
649
 
/*=========================*/
650
 
        const trx_t*    trx);           /*!< in: transaction */
651
 
/*******************************************************************//**
652
 
Release all the transaction's autoinc locks. */
653
 
UNIV_INTERN
654
 
void
655
 
lock_release_autoinc_locks(
656
 
/*=======================*/
657
 
        trx_t*          trx);           /*!< in/out: transaction */
658
 
 
659
 
/*******************************************************************//**
660
 
Gets the type of a lock. Non-inline version for using outside of the
661
 
lock module.
662
 
@return LOCK_TABLE or LOCK_REC */
663
 
UNIV_INTERN
664
 
ulint
665
 
lock_get_type(
666
 
/*==========*/
667
 
        const lock_t*   lock);  /*!< in: lock */
668
 
 
669
 
/*******************************************************************//**
670
 
Gets the id of the transaction owning a lock.
671
 
@return transaction id */
672
 
UNIV_INTERN
673
 
trx_id_t
674
 
lock_get_trx_id(
675
 
/*============*/
676
 
        const lock_t*   lock);  /*!< in: lock */
677
 
 
678
 
/*******************************************************************//**
679
 
Gets the mode of a lock in a human readable string.
680
 
The string should not be free()'d or modified.
681
 
@return lock mode */
682
 
UNIV_INTERN
683
 
const char*
684
 
lock_get_mode_str(
685
 
/*==============*/
686
 
        const lock_t*   lock);  /*!< in: lock */
687
 
 
688
 
/*******************************************************************//**
689
 
Gets the type of a lock in a human readable string.
690
 
The string should not be free()'d or modified.
691
 
@return lock type */
692
 
UNIV_INTERN
693
 
const char*
694
 
lock_get_type_str(
695
 
/*==============*/
696
 
        const lock_t*   lock);  /*!< in: lock */
697
 
 
698
 
/*******************************************************************//**
699
 
Gets the id of the table on which the lock is.
700
 
@return id of the table */
701
 
UNIV_INTERN
702
 
table_id_t
703
 
lock_get_table_id(
704
 
/*==============*/
705
 
        const lock_t*   lock);  /*!< in: lock */
706
 
 
707
 
/*******************************************************************//**
708
 
Gets the name of the table on which the lock is.
709
 
The string should not be free()'d or modified.
710
 
@return name of the table */
711
 
UNIV_INTERN
712
 
const char*
713
 
lock_get_table_name(
714
 
/*================*/
715
 
        const lock_t*   lock);  /*!< in: lock */
716
 
 
717
 
/*******************************************************************//**
718
 
For a record lock, gets the index on which the lock is.
719
 
@return index */
720
 
UNIV_INTERN
721
 
const dict_index_t*
722
 
lock_rec_get_index(
723
 
/*===============*/
724
 
        const lock_t*   lock);  /*!< in: lock */
725
 
 
726
 
/*******************************************************************//**
727
 
For a record lock, gets the name of the index on which the lock is.
728
 
The string should not be free()'d or modified.
729
 
@return name of the index */
730
 
UNIV_INTERN
731
 
const char*
732
 
lock_rec_get_index_name(
733
 
/*====================*/
734
 
        const lock_t*   lock);  /*!< in: lock */
735
 
 
736
 
/*******************************************************************//**
737
 
For a record lock, gets the tablespace number on which the lock is.
738
 
@return tablespace number */
739
 
UNIV_INTERN
740
 
ulint
741
 
lock_rec_get_space_id(
742
 
/*==================*/
743
 
        const lock_t*   lock);  /*!< in: lock */
744
 
 
745
 
/*******************************************************************//**
746
 
For a record lock, gets the page number on which the lock is.
747
 
@return page number */
748
 
UNIV_INTERN
749
 
ulint
750
 
lock_rec_get_page_no(
751
 
/*=================*/
752
 
        const lock_t*   lock);  /*!< in: lock */
753
 
 
754
 
/** Lock modes and types */
755
 
/* @{ */
756
 
#define LOCK_MODE_MASK  0xFUL   /*!< mask used to extract mode from the
757
 
                                type_mode field in a lock */
758
 
/** Lock types */
759
 
/* @{ */
760
 
#define LOCK_TABLE      16      /*!< table lock */
761
 
#define LOCK_REC        32      /*!< record lock */
762
 
#define LOCK_TYPE_MASK  0xF0UL  /*!< mask used to extract lock type from the
763
 
                                type_mode field in a lock */
764
 
#if LOCK_MODE_MASK & LOCK_TYPE_MASK
765
 
# error "LOCK_MODE_MASK & LOCK_TYPE_MASK"
766
 
#endif
767
 
 
768
 
#define LOCK_WAIT       256     /*!< Waiting lock flag; when set, it
769
 
                                means that the lock has not yet been
770
 
                                granted, it is just waiting for its
771
 
                                turn in the wait queue */
772
 
/* Precise modes */
773
 
#define LOCK_ORDINARY   0       /*!< this flag denotes an ordinary
774
 
                                next-key lock in contrast to LOCK_GAP
775
 
                                or LOCK_REC_NOT_GAP */
776
 
#define LOCK_GAP        512     /*!< when this bit is set, it means that the
777
 
                                lock holds only on the gap before the record;
778
 
                                for instance, an x-lock on the gap does not
779
 
                                give permission to modify the record on which
780
 
                                the bit is set; locks of this type are created
781
 
                                when records are removed from the index chain
782
 
                                of records */
783
 
#define LOCK_REC_NOT_GAP 1024   /*!< this bit means that the lock is only on
784
 
                                the index record and does NOT block inserts
785
 
                                to the gap before the index record; this is
786
 
                                used in the case when we retrieve a record
787
 
                                with a unique key, and is also used in
788
 
                                locking plain SELECTs (not part of UPDATE
789
 
                                or DELETE) when the user has set the READ
790
 
                                COMMITTED isolation level */
791
 
#define LOCK_INSERT_INTENTION 2048 /*!< this bit is set when we place a waiting
792
 
                                gap type record lock request in order to let
793
 
                                an insert of an index record to wait until
794
 
                                there are no conflicting locks by other
795
 
                                transactions on the gap; note that this flag
796
 
                                remains set when the waiting lock is granted,
797
 
                                or if the lock is inherited to a neighboring
798
 
                                record */
799
 
#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION)&LOCK_MODE_MASK
800
 
# error
801
 
#endif
802
 
#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION)&LOCK_TYPE_MASK
803
 
# error
804
 
#endif
805
 
/* @} */
806
 
 
807
 
/** Lock operation struct */
808
 
typedef struct lock_op_struct   lock_op_t;
809
 
/** Lock operation struct */
810
 
struct lock_op_struct{
811
 
        dict_table_t*   table;  /*!< table to be locked */
812
 
        enum lock_mode  mode;   /*!< lock mode */
813
 
};
814
 
 
815
 
/** The lock system struct */
816
 
struct lock_sys_struct{
817
 
        hash_table_t*   rec_hash;       /*!< hash table of the record locks */
818
 
};
819
 
 
820
 
/** The lock system */
821
 
extern lock_sys_t*      lock_sys;
822
 
 
823
 
 
824
 
#ifndef UNIV_NONINL
825
 
#include "lock0lock.ic"
826
 
#endif
827
 
 
828
 
#endif