lock0lock.h 24.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/******************************************************
The transaction lock system

(c) 1996 Innobase Oy

Created 5/7/1996 Heikki Tuuri
*******************************************************/

#ifndef lock0lock_h
#define lock0lock_h

#include "univ.i"
#include "trx0types.h"
#include "rem0types.h"
#include "dict0types.h"
#include "que0types.h"
#include "page0types.h"
#include "lock0types.h"
#include "read0types.h"
#include "hash0hash.h"

extern ibool	lock_print_waits;
23 24
/* Buffer for storing information about the most recent deadlock error */
extern FILE*	lock_latest_err_file;
25

26 27
/*************************************************************************
Gets the size of a lock struct. */
28

29 30 31 32
ulint
lock_get_size(void);
/*===============*/
			/* out: size in bytes */
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/*************************************************************************
Creates the lock system at database start. */

void
lock_sys_create(
/*============*/
	ulint	n_cells);	/* in: number of slots in lock hash table */
/*************************************************************************
Checks if some transaction has an implicit x-lock on a record in a secondary
index. */

trx_t*
lock_sec_rec_some_has_impl_off_kernel(
/*==================================*/
				/* out: transaction which has the x-lock, or
				NULL */
	rec_t*		rec,	/* in: user record */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
50 51
	dict_index_t*	index,	/* in: secondary index */
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
52 53 54 55 56 57 58 59 60 61
/*************************************************************************
Checks if some transaction has an implicit x-lock on a record in a clustered
index. */
UNIV_INLINE
trx_t*
lock_clust_rec_some_has_impl(
/*=========================*/
				/* out: transaction which has the x-lock, or
				NULL */
	rec_t*		rec,	/* in: user record */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
62 63
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
/*****************************************************************
Resets the lock bits for a single record. Releases transactions
waiting for lock requests here. */

void
lock_rec_reset_and_release_wait(
/*============================*/
	rec_t*	rec);	/* in: record whose locks bits should be reset */
/*****************************************************************
Makes a record to inherit the locks of another record as gap type
locks, but does not reset the lock bits of the other record. Also
waiting lock requests on rec are inherited as GRANTED gap locks. */

void
lock_rec_inherit_to_gap(
/*====================*/
	rec_t*	heir,	/* in: record which inherits */
	rec_t*	rec);	/* in: record from which inherited; does NOT reset
			the locks on this record */
/*****************************************************************
Updates the lock table when we have reorganized a page. NOTE: we copy
also the locks set on the infimum of the page; the infimum may carry
locks if an update of a record is occurring on the page, and its locks
were temporarily stored on the infimum. */

void
lock_move_reorganize_page(
/*======================*/
	page_t*	page,		/* in: old index page */
	page_t*	new_page);	/* in: reorganized page */
/*****************************************************************
Moves the explicit locks on user records to another page if a record
list end is moved to another page. */

void
lock_move_rec_list_end(
/*===================*/
	page_t*	new_page,	/* in: index page to move to */
	page_t*	page,		/* in: index page */
	rec_t*	rec);		/* in: record on page: this is the
				first record moved */
/*****************************************************************
Moves the explicit locks on user records to another page if a record
list start is moved to another page. */

void
lock_move_rec_list_start(
/*=====================*/
	page_t*	new_page,	/* in: index page to move to */
	page_t*	page,		/* in: index page */
	rec_t*	rec,		/* in: record on page: this is the
				first record NOT copied */
	rec_t*	old_end);	/* in: old previous-to-last record on
				new_page before the records were copied */
/*****************************************************************
Updates the lock table when a page is split to the right. */

void
lock_update_split_right(
/*====================*/
	page_t*	right_page,	/* in: right page */
	page_t*	left_page);	/* in: left page */
/*****************************************************************
Updates the lock table when a page is merged to the right. */

void
lock_update_merge_right(
/*====================*/
	rec_t*	orig_succ,	/* in: original successor of infimum
				on the right page before merge */
	page_t*	left_page);	/* in: merged index page which will be
				discarded */
/*****************************************************************
Updates the lock table when the root page is copied to another in
btr_root_raise_and_insert. Note that we leave lock structs on the
root page, even though they do not make sense on other than leaf
pages: the reason is that in a pessimistic update the infimum record
of the root page will act as a dummy carrier of the locks of the record
to be updated. */

void
lock_update_root_raise(
/*===================*/
	page_t*	new_page,	/* in: index page to which copied */
	page_t*	root);		/* in: root page */
/*****************************************************************
Updates the lock table when a page is copied to another and the original page
is removed from the chain of leaf pages, except if page is the root! */

void
lock_update_copy_and_discard(
/*=========================*/
	page_t*	new_page,	/* in: index page to which copied */
	page_t*	page);		/* in: index page; NOT the root! */
/*****************************************************************
Updates the lock table when a page is split to the left. */

void
lock_update_split_left(
/*===================*/
	page_t*	right_page,	/* in: right page */
	page_t*	left_page);	/* in: left page */
/*****************************************************************
Updates the lock table when a page is merged to the left. */

void
lock_update_merge_left(
/*===================*/
	page_t*	left_page,	/* in: left page to which merged */
	rec_t*	orig_pred,	/* in: original predecessor of supremum
				on the left page before merge */
	page_t*	right_page);	/* in: merged index page which will be
				discarded */
/*****************************************************************
Resets the original locks on heir and replaces them with gap type locks
inherited from rec. */

void
lock_rec_reset_and_inherit_gap_locks(
/*=================================*/
	rec_t*	heir,	/* in: heir record */
	rec_t*	rec);	/* in: record */
/*****************************************************************
Updates the lock table when a page is discarded. */

void
lock_update_discard(
/*================*/
	rec_t*	heir,	/* in: record which will inherit the locks */
	page_t*	page);	/* in: index page which will be discarded */
/*****************************************************************
Updates the lock table when a new user record is inserted. */

void
lock_update_insert(
/*===============*/
	rec_t*	rec);	/* in: the inserted record */
/*****************************************************************
Updates the lock table when a record is removed. */

void
lock_update_delete(
/*===============*/
	rec_t*	rec);	/* in: the record to be removed */
/*************************************************************************
Stores on the page infimum record the explicit locks of another record.
This function is used to store the lock state of a record when it is
updated and the size of the record changes in the update. The record
is in such an update moved, perhaps to another page. The infimum record
acts as a dummy carrier record, taking care of lock releases while the
actual record is being moved. */

void
lock_rec_store_on_page_infimum(
/*===========================*/
219
	page_t*	page,	/* in: page containing the record */
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
	rec_t*	rec);	/* in: record whose lock state is stored
			on the infimum record of the same page; lock
			bits are reset on the record */
/*************************************************************************
Restores the state of explicit lock requests on a single record, where the
state was stored on the infimum of the page. */

void
lock_rec_restore_from_page_infimum(
/*===============================*/
	rec_t*	rec,	/* in: record whose lock state is restored */
	page_t*	page);	/* in: page (rec is not necessarily on this page)
			whose infimum stored the lock state; lock bits are
			reset on the infimum */ 
/*************************************************************************
Returns TRUE if there are explicit record locks on a page. */

ibool
lock_rec_expl_exist_on_page(
/*========================*/
			/* out: TRUE if there are explicit record locks on
			the page */
	ulint	space,	/* in: space id */
	ulint	page_no);/* in: page number */
/*************************************************************************
Checks if locks of other transactions prevent an immediate insert of
a record. If they do, first tests if the query thread should anyway
be suspended for some reason; if not, then puts the transaction and
the query thread to the lock wait state and inserts a waiting request
for a gap x-lock to the lock queue. */

ulint
lock_rec_insert_check_and_lock(
/*===========================*/
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
				does nothing */
	rec_t*		rec,	/* in: record after which to insert */
	dict_index_t*	index,	/* in: index */
	que_thr_t*	thr,	/* in: query thread */
	ibool*		inherit);/* out: set to TRUE if the new inserted
				record maybe should inherit LOCK_GAP type
				locks from the successor record */
/*************************************************************************
Checks if locks of other transactions prevent an immediate modify (update,
delete mark, or delete unmark) of a clustered index record. If they do,
first tests if the query thread should anyway be suspended for some
reason; if not, then puts the transaction and the query thread to the
lock wait state and inserts a waiting request for a record x-lock to the
lock queue. */

ulint
lock_clust_rec_modify_check_and_lock(
/*=================================*/
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
				does nothing */
	rec_t*		rec,	/* in: record which should be modified */
	dict_index_t*	index,	/* in: clustered index */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
281
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
	que_thr_t*	thr);	/* in: query thread */
/*************************************************************************
Checks if locks of other transactions prevent an immediate modify
(delete mark or delete unmark) of a secondary index record. */

ulint
lock_sec_rec_modify_check_and_lock(
/*===============================*/
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
				does nothing */
	rec_t*		rec,	/* in: record which should be modified;
				NOTE: as this is a secondary index, we
				always have to modify the clustered index
				record first: see the comment below */
	dict_index_t*	index,	/* in: secondary index */
	que_thr_t*	thr);	/* in: query thread */
/*************************************************************************
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
301 302
Like the counterpart for a clustered index below, but now we read a
secondary index record. */
303 304

ulint
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
305 306
lock_sec_rec_read_check_and_lock(
/*=============================*/
307 308 309 310 311 312 313
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
				does nothing */
	rec_t*		rec,	/* in: user record or page supremum record
				which should be read or passed over by a read
				cursor */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
314
	dict_index_t*	index,	/* in: secondary index */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
315
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
316 317 318
	ulint		mode,	/* in: mode of the lock which the read cursor
				should set on records: LOCK_S or LOCK_X; the
				latter is possible in SELECT FOR UPDATE */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
319 320
	ulint		gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or
				LOCK_REC_NOT_GAP */
321 322
	que_thr_t*	thr);	/* in: query thread */
/*************************************************************************
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
323 324 325 326 327 328
Checks if locks of other transactions prevent an immediate read, or passing
over by a read cursor, of a clustered index record. If they do, first tests
if the query thread should anyway be suspended for some reason; if not, then
puts the transaction and the query thread to the lock wait state and inserts a
waiting request for a record lock to the lock queue. Sets the requested mode
lock on the record. */
329 330

ulint
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
331 332
lock_clust_rec_read_check_and_lock(
/*===============================*/
333 334 335 336 337 338 339
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
				does nothing */
	rec_t*		rec,	/* in: user record or page supremum record
				which should be read or passed over by a read
				cursor */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
340
	dict_index_t*	index,	/* in: clustered index */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
341
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
342 343 344
	ulint		mode,	/* in: mode of the lock which the read cursor
				should set on records: LOCK_S or LOCK_X; the
				latter is possible in SELECT FOR UPDATE */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
345 346
	ulint		gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or
				LOCK_REC_NOT_GAP */
347 348
	que_thr_t*	thr);	/* in: query thread */
/*************************************************************************
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
Checks if locks of other transactions prevent an immediate read, or passing
over by a read cursor, of a clustered index record. If they do, first tests
if the query thread should anyway be suspended for some reason; if not, then
puts the transaction and the query thread to the lock wait state and inserts a
waiting request for a record lock to the lock queue. Sets the requested mode
lock on the record. This is an alternative version of
lock_clust_rec_read_check_and_lock() that does not require the parameter
"offsets". */

ulint
lock_clust_rec_read_check_and_lock_alt(
/*===================================*/
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
				does nothing */
	rec_t*		rec,	/* in: user record or page supremum record
				which should be read or passed over by a read
				cursor */
	dict_index_t*	index,	/* in: clustered index */
	ulint		mode,	/* in: mode of the lock which the read cursor
				should set on records: LOCK_S or LOCK_X; the
				latter is possible in SELECT FOR UPDATE */
	ulint		gap_mode,/* in: LOCK_ORDINARY, LOCK_GAP, or
				LOCK_REC_NOT_GAP */
	que_thr_t*	thr);	/* in: query thread */
/*************************************************************************
376 377 378 379 380 381 382 383 384 385
Checks that a record is seen in a consistent read. */

ibool
lock_clust_rec_cons_read_sees(
/*==========================*/
				/* out: TRUE if sees, or FALSE if an earlier
				version of the record should be retrieved */
	rec_t*		rec,	/* in: user record which should be read or
				passed over by a read cursor */
	dict_index_t*	index,	/* in: clustered index */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
386
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
	read_view_t*	view);	/* in: consistent read view */
/*************************************************************************
Checks that a non-clustered index record is seen in a consistent read. */

ulint
lock_sec_rec_cons_read_sees(
/*========================*/
				/* out: TRUE if certainly sees, or FALSE if an
				earlier version of the clustered index record
				might be needed: NOTE that a non-clustered
				index page contains so little information on
				its modifications that also in the case FALSE,
				the present version of rec may be the right,
				but we must check this from the clustered
				index record */
	rec_t*		rec,	/* in: user record which should be read or
				passed over by a read cursor */
	dict_index_t*	index,	/* in: non-clustered index */
	read_view_t*	view);	/* in: consistent read view */
/*************************************************************************
Locks the specified database table in the mode given. If the lock cannot
be granted immediately, the query thread is put to wait. */

ulint
lock_table(
/*=======*/
				/* out: DB_SUCCESS, DB_LOCK_WAIT,
				DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
	ulint		flags,	/* in: if BTR_NO_LOCKING_FLAG bit is set,
416
				does nothing */
417 418 419 420 421 422 423 424 425 426 427 428
	dict_table_t*	table,	/* in: database table in dictionary cache */
	ulint		mode,	/* in: lock mode */
	que_thr_t*	thr);	/* in: query thread */
/*************************************************************************
Checks if there are any locks set on the table. */

ibool
lock_is_on_table(
/*=============*/
				/* out: TRUE if there are lock(s) */
	dict_table_t*	table);	/* in: database table in dictionary cache */
/*************************************************************************
429 430 431 432 433 434 435 436
Releases a table lock.
Releases possible other transactions waiting for this lock. */

void
lock_table_unlock(
/*==============*/
	lock_t*	lock);	/* in: lock */
/*************************************************************************
437 438 439 440 441 442 443 444
Releases an auto-inc lock a transaction possibly has on a table.
Releases possible other transactions waiting for this lock. */

void
lock_table_unlock_auto_inc(
/*=======================*/
	trx_t*	trx);	/* in: transaction */
/*************************************************************************
445 446 447 448 449 450 451 452
Releases transaction locks, and releases possible other transactions waiting
because of these locks. */

void
lock_release_off_kernel(
/*====================*/
	trx_t*	trx);	/* in: transaction */
/*************************************************************************
453 454 455 456 457 458 459 460
Cancels a waiting lock request and releases possible other transactions
waiting behind it. */

void
lock_cancel_waiting_and_release(
/*============================*/
	lock_t*	lock);	/* in: waiting lock request */
/*************************************************************************
461 462 463 464 465 466 467 468
Resets all locks, both table and record locks, on a table to be dropped.
No lock is allowed to be a wait lock. */

void
lock_reset_all_on_table(
/*====================*/
	dict_table_t*	table);	/* in: table to be dropped */
/*************************************************************************
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
Calculates the fold value of a page file address: used in inserting or
searching for a lock in the hash table. */
UNIV_INLINE
ulint
lock_rec_fold(
/*===========*/
			/* out: folded value */
	ulint	space,	/* in: space */
	ulint	page_no);/* in: page number */
/*************************************************************************
Calculates the hash value of a page file address: used in inserting or
searching for a lock in the hash table. */
UNIV_INLINE
ulint
lock_rec_hash(
/*==========*/
			/* out: hashed value */
	ulint	space,	/* in: space */
	ulint	page_no);/* in: page number */
/*************************************************************************
489 490
Gets the source table of an ALTER TABLE transaction.  The table must be
covered by an IX or IS table lock. */
491 492

dict_table_t*
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
lock_get_src_table(
/*===============*/
				/* out: the source table of transaction,
				if it is covered by an IX or IS table lock;
				dest if there is no source table, and
				NULL if the transaction is locking more than
				two tables or an inconsistency is found */
	trx_t*		trx,	/* in: transaction */
	dict_table_t*	dest,	/* in: destination of ALTER TABLE */
	ulint*		mode);	/* out: lock mode of the source table */
/*************************************************************************
Determine if the given table is exclusively "owned" by the given
transaction, i.e., transaction holds LOCK_IX and possibly LOCK_AUTO_INC
on the table. */

ibool
serg@serg.mylan's avatar
serg@serg.mylan committed
509
lock_is_table_exclusive(
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
510
/*====================*/
511 512 513 514
				/* out: TRUE if table is only locked by trx,
				with LOCK_IX, and possibly LOCK_AUTO_INC */
	dict_table_t*	table,	/* in: table */
	trx_t*		trx);	/* in: transaction */
515
/*************************************************************************
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
516 517 518 519 520 521 522 523 524
Checks that a transaction id is sensible, i.e., not in the future. */

ibool
lock_check_trx_id_sanity(
/*=====================*/
					/* out: TRUE if ok */
	dulint		trx_id,		/* in: trx id */
	rec_t*		rec,		/* in: user record */
	dict_index_t*	index,		/* in: clustered index */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
525
	const ulint*	offsets,	/* in: rec_get_offsets(rec, index) */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
526 527 528
	ibool		has_kernel_mutex);/* in: TRUE if the caller owns the
					kernel mutex */
/*************************************************************************
529 530 531 532 533 534 535
Validates the lock queue on a single record. */

ibool
lock_rec_queue_validate(
/*====================*/
				/* out: TRUE if ok */
	rec_t*		rec,	/* in: record to look at */
marko@hundin.mysql.fi's avatar
marko@hundin.mysql.fi committed
536 537
	dict_index_t*	index,	/* in: index, or NULL if not known */
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
538 539 540 541 542 543
/*************************************************************************
Prints info of a table lock. */

void
lock_table_print(
/*=============*/
544
	FILE*	file,	/* in: file where to print */
545 546 547 548 549 550 551
	lock_t*	lock);	/* in: table type lock */
/*************************************************************************
Prints info of a record lock. */

void
lock_rec_print(
/*===========*/
552
	FILE*	file,	/* in: file where to print */
553 554 555 556 557
	lock_t*	lock);	/* in: record type lock */
/*************************************************************************
Prints info of locks for all transactions. */

void
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
558 559
lock_print_info(
/*============*/
560
	FILE*	file);	/* in: file where to print */
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
/*************************************************************************
Validates the lock queue on a table. */

ibool
lock_table_queue_validate(
/*======================*/
				/* out: TRUE if ok */
	dict_table_t*	table);	/* in: table */
/*************************************************************************
Validates the record lock queues on a page. */

ibool
lock_rec_validate_page(
/*===================*/
			/* out: TRUE if ok */
	ulint	space,	/* in: space id */
	ulint	page_no);/* in: page number */
/*************************************************************************
Validates the lock system. */

ibool
lock_validate(void);
/*===============*/
			/* out: TRUE if ok */

/* The lock system */
extern lock_sys_t*	lock_sys;

/* Lock modes and types */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
590
/* Basic modes */
591 592 593 594 595 596
#define	LOCK_NONE	0	/* this flag is used elsewhere to note
				consistent read */
#define	LOCK_IS		2	/* intention shared */
#define	LOCK_IX		3	/* intention exclusive */
#define	LOCK_S		4	/* shared */
#define	LOCK_X		5	/* exclusive */
597 598
#define	LOCK_AUTO_INC	6	/* locks the auto-inc counter of a table
				in an exclusive mode */
599
#define LOCK_MODE_MASK	0xFUL	/* mask used to extract mode from the
600
				type_mode field in a lock */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
601
/* Lock types */
602 603
#define LOCK_TABLE	16	/* these type values should be so high that */
#define	LOCK_REC	32	/* they can be ORed to the lock mode */
604
#define LOCK_TYPE_MASK	0xF0UL	/* mask used to extract lock type from the
605
				type_mode field in a lock */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
606
/* Waiting lock flag */
607 608 609 610 611
#define LOCK_WAIT	256	/* this wait bit should be so high that
				it can be ORed to the lock mode and type;
				when this bit is set, it means that the
				lock has not yet been granted, it is just
				waiting for its turn in the wait queue */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
612 613 614
/* Precise modes */
#define LOCK_ORDINARY	0	/* this flag denotes an ordinary next-key lock
				in contrast to LOCK_GAP or LOCK_REC_NOT_GAP */ 
615 616 617 618 619 620 621 622 623
#define LOCK_GAP	512	/* this gap bit should be so high that
				it can be ORed to the other flags;
				when this bit is set, it means that the
				lock holds only on the gap before the record;
				for instance, an x-lock on the gap does not
				give permission to modify the record on which
				the bit is set; locks of this type are created
				when records are removed from the index chain
				of records */
heikki@hundin.mysql.fi's avatar
heikki@hundin.mysql.fi committed
624 625 626 627 628 629 630 631 632
#define LOCK_REC_NOT_GAP 1024 	/* this bit means that the lock is only on
				the index record and does NOT block inserts
				to the gap before the index record; this is
				used in the case when we retrieve a record
				with a unique key, and is also used in
				locking plain SELECTs (not part of UPDATE
				or DELETE) when the user has set the READ
				COMMITTED isolation level */
#define LOCK_INSERT_INTENTION 2048 /* this bit is set when we place a waiting
633 634 635 636 637 638 639 640
				gap type record lock request in order to let
				an insert of an index record to wait until
				there are no conflicting locks by other
				transactions on the gap; note that this flag
				remains set when the waiting lock is granted,
				or if the lock is inherited to a neighboring
				record */
				
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
/* When lock bits are reset, the following flags are available: */
#define LOCK_RELEASE_WAIT	1
#define LOCK_NOT_RELEASE_WAIT	2

/* Lock operation struct */
typedef struct lock_op_struct	lock_op_t;
struct lock_op_struct{
	dict_table_t*	table;	/* table to be locked */
	ulint		mode;	/* lock mode */
};

#define LOCK_OP_START		1
#define LOCK_OP_COMPLETE	2

/* The lock system struct */
struct lock_sys_struct{
	hash_table_t*	rec_hash;	/* hash table of the record locks */
};

/* The lock system */
extern lock_sys_t*	lock_sys;


#ifndef UNIV_NONINL
#include "lock0lock.ic"
#endif

#endif