~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2010-02-11 22:43:58 UTC
  • Revision ID: brian@gaz-20100211224358-y0gdvnat2ahg4c1e
Disabling support for memcached plugins until we can test for version of
memcached.

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