~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

Show diffs side-by-side

added added

removed removed

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