trx0sys.h 25.6 KB
Newer Older
1 2
/*****************************************************************************

3
Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved.
4 5 6 7 8 9 10 11 12 13

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
14 15
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 17 18

*****************************************************************************/

19 20
/**************************************************//**
@file include/trx0sys.h
osku's avatar
osku committed
21 22 23 24 25 26 27 28 29 30 31
Transaction system

Created 3/26/1996 Heikki Tuuri
*******************************************************/

#ifndef trx0sys_h
#define trx0sys_h

#include "univ.i"

#include "trx0types.h"
32
#include "fsp0types.h"
33 34 35
#include "fil0fil.h"
#include "buf0buf.h"
#ifndef UNIV_HOTBACKUP
osku's avatar
osku committed
36 37 38 39 40
#include "mtr0mtr.h"
#include "ut0byte.h"
#include "mem0mem.h"
#include "sync0sync.h"
#include "ut0lst.h"
41
#include "ut0bh.h"
osku's avatar
osku committed
42
#include "read0types.h"
marko's avatar
marko committed
43
#include "page0types.h"
44
#include "ut0bh.h"
45 46 47
#ifdef WITH_WSREP
#include "trx0xa.h"
#endif /* WITH_WSREP */
48 49

typedef UT_LIST_BASE_NODE_T(trx_t) trx_list_t;
osku's avatar
osku committed
50

51 52 53 54
/** In a MySQL replication slave, in crash recovery we store the master log
file name and position here. */
/* @{ */
/** Master binlog file name */
55
extern char		trx_sys_mysql_master_log_name[];
56 57 58
/** Master binlog file position.  We have successfully got the updates
up to this position.  -1 means that no crash recovery was needed, or
there was no master log position info inside InnoDB.*/
59
extern ib_int64_t	trx_sys_mysql_master_log_pos;
60
/* @} */
osku's avatar
osku committed
61

62
/** If this MySQL server uses binary logging, after InnoDB has been inited
osku's avatar
osku committed
63
and if it has done a crash recovery, we store the binlog file name and position
64 65 66
here. */
/* @{ */
/** Binlog file name */
67
extern char		trx_sys_mysql_bin_log_name[];
68
/** Binlog file position, or -1 if unknown */
69
extern ib_int64_t	trx_sys_mysql_bin_log_pos;
70
/* @} */
osku's avatar
osku committed
71

72
/** The transaction system */
osku's avatar
osku committed
73 74
extern trx_sys_t*	trx_sys;

75
/***************************************************************//**
76 77
Checks if a page address is the trx sys header page.
@return	TRUE if trx sys header page */
osku's avatar
osku committed
78 79 80 81
UNIV_INLINE
ibool
trx_sys_hdr_page(
/*=============*/
82 83
	ulint	space,	/*!< in: space */
	ulint	page_no);/*!< in: page number */
84
/*****************************************************************//**
osku's avatar
osku committed
85
Creates and initializes the central memory structures for the transaction
86 87
system. This is called when the database is started.
@return min binary heap of rsegs to purge */
88
UNIV_INTERN
89
ib_bh_t*
osku's avatar
osku committed
90 91
trx_sys_init_at_db_start(void);
/*==========================*/
92
/*****************************************************************//**
93
Creates the trx_sys instance and initializes ib_bh and mutex. */
94
UNIV_INTERN
osku's avatar
osku committed
95 96 97
void
trx_sys_create(void);
/*================*/
98 99 100 101 102 103
/*****************************************************************//**
Creates and initializes the transaction system at the database creation. */
UNIV_INTERN
void
trx_sys_create_sys_pages(void);
/*==========================*/
104
/****************************************************************//**
105 106
Looks for a free slot for a rollback segment in the trx system file copy.
@return	slot index or ULINT_UNDEFINED if not found */
107
UNIV_INTERN
osku's avatar
osku committed
108 109 110
ulint
trx_sysf_rseg_find_free(
/*====================*/
111
	mtr_t*		mtr);		/*!< in: mtr */
112
/***************************************************************//**
113 114
Gets the pointer in the nth slot of the rseg array.
@return	pointer to rseg object, NULL if slot not in use */
osku's avatar
osku committed
115 116 117 118
UNIV_INLINE
trx_rseg_t*
trx_sys_get_nth_rseg(
/*=================*/
119 120
	trx_sys_t*	sys,	/*!< in: trx system */
	ulint		n);	/*!< in: index of slot */
121
/**********************************************************************//**
122 123
Gets a pointer to the transaction system file copy and x-locks its page.
@return	pointer to system file copy, page x-locked */
osku's avatar
osku committed
124 125 126 127
UNIV_INLINE
trx_sysf_t*
trx_sysf_get(
/*=========*/
128
	mtr_t*	mtr);	/*!< in: mtr */
129
/*****************************************************************//**
osku's avatar
osku committed
130
Gets the space of the nth rollback segment slot in the trx system
131 132
file copy.
@return	space id */
osku's avatar
osku committed
133 134 135 136
UNIV_INLINE
ulint
trx_sysf_rseg_get_space(
/*====================*/
137 138 139
	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
	ulint		i,		/*!< in: slot index == rseg id */
	mtr_t*		mtr);		/*!< in: mtr */
140
/*****************************************************************//**
osku's avatar
osku committed
141
Gets the page number of the nth rollback segment slot in the trx system
142 143
file copy.
@return	page number, FIL_NULL if slot unused */
osku's avatar
osku committed
144 145 146 147
UNIV_INLINE
ulint
trx_sysf_rseg_get_page_no(
/*======================*/
148 149 150
	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
	ulint		i,		/*!< in: slot index == rseg id */
	mtr_t*		mtr);		/*!< in: mtr */
151
/*****************************************************************//**
osku's avatar
osku committed
152 153 154 155 156 157
Sets the space id of the nth rollback segment slot in the trx system
file copy. */
UNIV_INLINE
void
trx_sysf_rseg_set_space(
/*====================*/
158 159 160 161
	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
	ulint		i,		/*!< in: slot index == rseg id */
	ulint		space,		/*!< in: space id */
	mtr_t*		mtr);		/*!< in: mtr */
162
/*****************************************************************//**
osku's avatar
osku committed
163 164 165 166 167 168
Sets the page number of the nth rollback segment slot in the trx system
file copy. */
UNIV_INLINE
void
trx_sysf_rseg_set_page_no(
/*======================*/
169 170 171
	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
	ulint		i,		/*!< in: slot index == rseg id */
	ulint		page_no,	/*!< in: page number, FIL_NULL if
osku's avatar
osku committed
172
					the slot is reset to unused */
173
	mtr_t*		mtr);		/*!< in: mtr */
174
/*****************************************************************//**
175 176
Allocates a new transaction id.
@return	new, allocated trx id */
osku's avatar
osku committed
177
UNIV_INLINE
178
trx_id_t
osku's avatar
osku committed
179 180
trx_sys_get_new_trx_id(void);
/*========================*/
181 182 183 184 185 186 187 188
/*****************************************************************//**
Determines the maximum transaction id.
@return maximum currently allocated trx id; will be stale after the
next call to trx_sys_get_new_trx_id() */
UNIV_INLINE
trx_id_t
trx_sys_get_max_trx_id(void);
/*========================*/
189 190 191 192 193 194

#ifdef UNIV_DEBUG
/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */
extern uint			trx_rseg_n_slots_debug;
#endif

195
/*****************************************************************//**
osku's avatar
osku committed
196 197 198 199 200 201 202
Writes a trx id to an index page. In case that the id size changes in
some future version, this function should be used instead of
mach_write_... */
UNIV_INLINE
void
trx_write_trx_id(
/*=============*/
203 204
	byte*		ptr,	/*!< in: pointer to memory where written */
	trx_id_t	id);	/*!< in: id */
205
/*****************************************************************//**
osku's avatar
osku committed
206 207
Reads a trx id from an index page. In case that the id size changes in
some future version, this function should be used instead of
208 209
mach_read_...
@return	id */
osku's avatar
osku committed
210
UNIV_INLINE
211
trx_id_t
osku's avatar
osku committed
212 213
trx_read_trx_id(
/*============*/
214
	const byte*	ptr);	/*!< in: pointer to memory from where to read */
215
/****************************************************************//**
216 217 218 219 220
Looks for the trx instance with the given id in the rw trx_list.
The caller must be holding trx_sys->mutex.
@return	the trx handle or NULL if not found;
the pointer must not be dereferenced unless lock_sys->mutex was
acquired before calling this function and is still being held */
osku's avatar
osku committed
221 222
UNIV_INLINE
trx_t*
223 224
trx_get_rw_trx_by_id(
/*=================*/
225
	trx_id_t	trx_id);/*!< in: trx id to search for */
226
/****************************************************************//**
227 228
Returns the minimum trx id in rw trx list. This is the smallest id for which
the trx can possibly be active. (But, you must look at the trx->state to
osku's avatar
osku committed
229
find out if the minimum trx id transaction itself is active, or already
230 231
committed.)
@return	the minimum trx id, or trx_sys->max_trx_id if the trx list is empty */
osku's avatar
osku committed
232
UNIV_INLINE
233
trx_id_t
234 235
trx_rw_min_trx_id(void);
/*===================*/
236
/****************************************************************//**
237 238 239 240 241 242
Checks if a rw transaction with the given id is active. Caller must hold
trx_sys->mutex in shared mode. If the caller is not holding
lock_sys->mutex, the transaction may already have been committed.
@return	transaction instance if active, or NULL;
the pointer must not be dereferenced unless lock_sys->mutex was
acquired before calling this function and is still being held */
osku's avatar
osku committed
243
UNIV_INLINE
244 245 246 247 248 249
trx_t*
trx_rw_is_active_low(
/*=================*/
	trx_id_t	trx_id,		/*!< in: trx id of the transaction */
	ibool*		corrupt);	/*!< in: NULL or pointer to a flag
					that will be set if corrupt */
250
/****************************************************************//**
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
Checks if a rw transaction with the given id is active. If the caller is
not holding lock_sys->mutex, the transaction may already have been
committed.
@return	transaction instance if active, or NULL;
the pointer must not be dereferenced unless lock_sys->mutex was
acquired before calling this function and is still being held */
UNIV_INLINE
trx_t*
trx_rw_is_active(
/*=============*/
	trx_id_t	trx_id,		/*!< in: trx id of the transaction */
	ibool*		corrupt);	/*!< in: NULL or pointer to a flag
					that will be set if corrupt */
#ifdef UNIV_DEBUG
/****************************************************************//**
Checks whether a trx is in one of rw_trx_list or ro_trx_list.
267
@return	TRUE if is in */
268
UNIV_INTERN
osku's avatar
osku committed
269 270 271
ibool
trx_in_trx_list(
/*============*/
272 273 274
	const trx_t*	in_trx)		/*!< in: transaction */
	__attribute__((nonnull, warn_unused_result));
#endif /* UNIV_DEBUG */
275
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
276 277 278
/***********************************************************//**
Assert that a transaction has been recovered.
@return TRUE */
279 280
UNIV_INLINE
ibool
281 282 283 284
trx_assert_recovered(
/*=================*/
	trx_id_t	trx_id)		/*!< in: transaction identifier */
	__attribute__((warn_unused_result));
285
#endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
286
/*****************************************************************//**
osku's avatar
osku committed
287 288 289 290
Updates the offset information about the end of the MySQL binlog entry
which corresponds to the transaction just being committed. In a MySQL
replication slave updates the latest master binlog position up to which
replication has proceeded. */
291
UNIV_INTERN
osku's avatar
osku committed
292 293 294
void
trx_sys_update_mysql_binlog_offset(
/*===============================*/
295 296 297
	const char*	file_name,/*!< in: MySQL log file name */
	ib_int64_t	offset,	/*!< in: position in that log file */
	ulint		field,	/*!< in: offset of the MySQL log info field in
osku's avatar
osku committed
298
				the trx sys header */
299 300 301
#ifdef WITH_WSREP
        trx_sysf_t*     sys_header, /*!< in: trx sys header */
#endif /* WITH_WSREP */
302
	mtr_t*		mtr);	/*!< in: mtr */
303
/*****************************************************************//**
osku's avatar
osku committed
304 305
Prints to stderr the MySQL binlog offset info in the trx system header if
the magic number shows it valid. */
306
UNIV_INTERN
osku's avatar
osku committed
307 308 309
void
trx_sys_print_mysql_binlog_offset(void);
/*===================================*/
310 311 312 313 314 315 316 317 318 319 320 321 322
#ifdef WITH_WSREP
/** Update WSREP checkpoint XID in sys header. */
void
trx_sys_update_wsrep_checkpoint(
        const XID*      xid,         /*!< in: WSREP XID */
        trx_sysf_t*     sys_header,  /*!< in: sys_header */
        mtr_t*          mtr);        /*!< in: mtr       */

void
/** Read WSREP checkpoint XID from sys header. */
trx_sys_read_wsrep_checkpoint(
        XID* xid); /*!< out: WSREP XID */
#endif /* WITH_WSREP */
323
/*****************************************************************//**
osku's avatar
osku committed
324 325
Prints to stderr the MySQL master log offset info in the trx system header if
the magic number shows it valid. */
326
UNIV_INTERN
osku's avatar
osku committed
327 328 329
void
trx_sys_print_mysql_master_log_pos(void);
/*====================================*/
330
/*****************************************************************//**
331 332 333 334 335
Initializes the tablespace tag system. */
UNIV_INTERN
void
trx_sys_file_format_init(void);
/*==========================*/
336
/*****************************************************************//**
337 338 339 340 341
Closes the tablespace tag system. */
UNIV_INTERN
void
trx_sys_file_format_close(void);
/*===========================*/
342
/********************************************************************//**
343 344 345 346 347 348 349 350
Tags the system table space with minimum format id if it has not been
tagged yet.
WARNING: This function is only called during the startup and AFTER the
redo log application during recovery has finished. */
UNIV_INTERN
void
trx_sys_file_format_tag_init(void);
/*==============================*/
351
/*****************************************************************//**
352 353 354 355 356 357
Shutdown/Close the transaction system. */
UNIV_INTERN
void
trx_sys_close(void);
/*===============*/
/*****************************************************************//**
358 359
Get the name representation of the file format from its id.
@return	pointer to the name */
360 361 362 363
UNIV_INTERN
const char*
trx_sys_file_format_id_to_name(
/*===========================*/
364
	const ulint	id);		/*!< in: id of the file format */
365
/*****************************************************************//**
366
Set the file format id unconditionally except if it's already the
367 368
same value.
@return	TRUE if value updated */
369 370 371
UNIV_INTERN
ibool
trx_sys_file_format_max_set(
372
/*========================*/
373 374
	ulint		format_id,	/*!< in: file format id */
	const char**	name);		/*!< out: max file format name or
375
					NULL if not needed. */
376 377 378
/*********************************************************************
Creates the rollback segments
@return number of rollback segments that are active. */
379
UNIV_INTERN
380 381 382 383 384
ulint
trx_sys_create_rsegs(
/*=================*/
	ulint	n_spaces,	/*!< number of tablespaces for UNDO logs */
	ulint	n_rsegs);	/*!< number of rollback segments to create */
385
/*****************************************************************//**
386 387 388
Get the number of transaction in the system, independent of their state.
@return count of transactions in trx_sys_t::trx_list */
UNIV_INLINE
389
ulint
390 391 392 393 394 395
trx_sys_get_n_rw_trx(void);
/*======================*/

/*********************************************************************
Check if there are any active (non-prepared) transactions.
@return total number of active transactions or 0 if none */
396
UNIV_INTERN
397 398 399
ulint
trx_sys_any_active_transactions(void);
/*=================================*/
400
#else /* !UNIV_HOTBACKUP */
401
/*****************************************************************//**
402 403 404 405 406 407
Prints to stderr the MySQL binlog info in the system header if the
magic number shows it valid. */
UNIV_INTERN
void
trx_sys_print_mysql_binlog_offset_from_page(
/*========================================*/
408
	const byte*	page);	/*!< in: buffer containing the trx
409 410
				system header page, i.e., page number
				TRX_SYS_PAGE_NO in the tablespace */
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
/*****************************************************************//**
Reads the file format id from the first system table space file.
Even if the call succeeds and returns TRUE, the returned format id
may be ULINT_UNDEFINED signalling that the format id was not present
in the data file.
@return TRUE if call succeeds */
UNIV_INTERN
ibool
trx_sys_read_file_format_id(
/*========================*/
	const char *pathname,	/*!< in: pathname of the first system
				table space file */
	ulint *format_id);	/*!< out: file format of the system table
				space */
/*****************************************************************//**
Reads the file format id from the given per-table data file.
@return TRUE if call succeeds */
UNIV_INTERN
ibool
trx_sys_read_pertable_file_format_id(
/*=================================*/
	const char *pathname,	/*!< in: pathname of a per-table
				datafile */
	ulint *format_id);	/*!< out: file format of the per-table
				data file */
436 437 438 439 440 441 442 443 444 445 446 447
#endif /* !UNIV_HOTBACKUP */
/*****************************************************************//**
Get the name representation of the file format from its id.
@return	pointer to the max format name */
UNIV_INTERN
const char*
trx_sys_file_format_max_get(void);
/*=============================*/
/*****************************************************************//**
Check for the max file format tag stored on disk.
@return	DB_SUCCESS or error code */
UNIV_INTERN
448
dberr_t
449 450 451 452 453 454 455 456 457 458 459 460 461
trx_sys_file_format_max_check(
/*==========================*/
	ulint		max_format_id);	/*!< in: the max format id to check */
/********************************************************************//**
Update the file format tag in the system tablespace only if the given
format id is greater than the known max id.
@return	TRUE if format_id was bigger than the known max id */
UNIV_INTERN
ibool
trx_sys_file_format_max_upgrade(
/*============================*/
	const char**	name,		/*!< out: max file format name */
	ulint		format_id);	/*!< in: file format identifier */
462 463 464 465 466 467 468 469 470
/*****************************************************************//**
Get the name representation of the file format from its id.
@return	pointer to the name */
UNIV_INTERN
const char*
trx_sys_file_format_id_to_name(
/*===========================*/
	const ulint	id);	/*!< in: id of the file format */

471 472 473
#ifdef UNIV_DEBUG
/*************************************************************//**
Validate the trx_sys_t::trx_list. */
474
UNIV_INTERN
475 476 477 478
ibool
trx_sys_validate_trx_list(void);
/*===========================*/
#endif /* UNIV_DEBUG */
479

osku's avatar
osku committed
480 481 482 483 484
/* The automatically created system rollback segment has this id */
#define TRX_SYS_SYSTEM_RSEG_ID	0

/* Space id and page no where the trx system file copy resides */
#define	TRX_SYS_SPACE	0	/* the SYSTEM tablespace */
485
#include "fsp0fsp.h"
osku's avatar
osku committed
486 487 488 489 490
#define	TRX_SYS_PAGE_NO	FSP_TRX_SYS_PAGE_NO

/* The offset of the transaction system header on the page */
#define	TRX_SYS		FSEG_PAGE_DATA

491 492 493 494 495
/** Transaction system header */
/*------------------------------------------------------------- @{ */
#define	TRX_SYS_TRX_ID_STORE	0	/*!< the maximum trx id or trx
					number modulo
					TRX_SYS_TRX_ID_UPDATE_MARGIN
osku's avatar
osku committed
496 497
					written to a file page by any
					transaction; the assignment of
498 499 500 501 502 503
					transaction ids continues from
					this number rounded up by
					TRX_SYS_TRX_ID_UPDATE_MARGIN
					plus
					TRX_SYS_TRX_ID_UPDATE_MARGIN
					when the database is
osku's avatar
osku committed
504
					started */
505 506 507
#define TRX_SYS_FSEG_HEADER	8	/*!< segment header for the
					tablespace segment the trx
					system is created into */
508
#define	TRX_SYS_RSEGS		(8 + FSEG_HEADER_SIZE)
509 510 511 512 513
					/*!< the start of the array of
					rollback segment specification
					slots */
/*------------------------------------------------------------- @} */

514 515 516 517 518 519 520 521 522 523
/* Max number of rollback segments: the number of segment specification slots
in the transaction system array; rollback segment id must fit in one (signed)
byte, therefore 128; each slot is currently 8 bytes in size. If you want
to raise the level to 256 then you will need to fix some assertions that
impose the 7 bit restriction. e.g., mach_write_to_3() */
#define	TRX_SYS_N_RSEGS			128
/* Originally, InnoDB defined TRX_SYS_N_RSEGS as 256 but created only one
rollback segment.  It initialized some arrays with this number of entries.
We must remember this limit in order to keep file compatibility. */
#define TRX_SYS_OLD_N_RSEGS		256
osku's avatar
osku committed
524

525 526 527
/** Maximum length of MySQL binlog file name, in bytes.
@see trx_sys_mysql_master_log_name
@see trx_sys_mysql_bin_log_name */
osku's avatar
osku committed
528
#define TRX_SYS_MYSQL_LOG_NAME_LEN	512
529
/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
osku's avatar
osku committed
530 531
#define TRX_SYS_MYSQL_LOG_MAGIC_N	873422344

532 533
#if UNIV_PAGE_SIZE_MIN < 4096
# error "UNIV_PAGE_SIZE_MIN < 4096"
534
#endif
535
/** The offset of the MySQL replication info in the trx system header;
osku's avatar
osku committed
536 537 538
this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
#define TRX_SYS_MYSQL_MASTER_LOG_INFO	(UNIV_PAGE_SIZE - 2000)

539
/** The offset of the MySQL binlog offset info in the trx system header */
osku's avatar
osku committed
540
#define TRX_SYS_MYSQL_LOG_INFO		(UNIV_PAGE_SIZE - 1000)
541 542
#define	TRX_SYS_MYSQL_LOG_MAGIC_N_FLD	0	/*!< magic number which is
						TRX_SYS_MYSQL_LOG_MAGIC_N
osku's avatar
osku committed
543
						if we have valid data in the
544 545
						MySQL binlog info */
#define TRX_SYS_MYSQL_LOG_OFFSET_HIGH	4	/*!< high 4 bytes of the offset
osku's avatar
osku committed
546
						within that file */
547
#define TRX_SYS_MYSQL_LOG_OFFSET_LOW	8	/*!< low 4 bytes of the offset
osku's avatar
osku committed
548
						within that file */
549
#define TRX_SYS_MYSQL_LOG_NAME		12	/*!< MySQL log file name */
osku's avatar
osku committed
550

551 552 553 554 555 556 557 558 559 560 561 562 563 564
#ifdef WITH_WSREP
/* The offset to WSREP XID headers */
#define TRX_SYS_WSREP_XID_INFO (UNIV_PAGE_SIZE - 3500)
#define TRX_SYS_WSREP_XID_MAGIC_N_FLD 0
#define TRX_SYS_WSREP_XID_MAGIC_N 0x77737265

/* XID field: formatID, gtrid_len, bqual_len, xid_data */
#define TRX_SYS_WSREP_XID_LEN        (4 + 4 + 4 + XIDDATASIZE)
#define TRX_SYS_WSREP_XID_FORMAT     4
#define TRX_SYS_WSREP_XID_GTRID_LEN  8
#define TRX_SYS_WSREP_XID_BQUAL_LEN 12
#define TRX_SYS_WSREP_XID_DATA      16
#endif /* WITH_WSREP*/

565 566 567
/** Doublewrite buffer */
/* @{ */
/** The offset of the doublewrite buffer header on the trx system header page */
osku's avatar
osku committed
568 569
#define TRX_SYS_DOUBLEWRITE		(UNIV_PAGE_SIZE - 200)
/*-------------------------------------------------------------*/
570
#define TRX_SYS_DOUBLEWRITE_FSEG	0	/*!< fseg header of the fseg
osku's avatar
osku committed
571 572
						containing the doublewrite
						buffer */
573
#define TRX_SYS_DOUBLEWRITE_MAGIC	FSEG_HEADER_SIZE
574
						/*!< 4-byte magic number which
osku's avatar
osku committed
575 576 577 578
						shows if we already have
						created the doublewrite
						buffer */
#define TRX_SYS_DOUBLEWRITE_BLOCK1	(4 + FSEG_HEADER_SIZE)
579
						/*!< page number of the
osku's avatar
osku committed
580 581 582 583 584 585
						first page in the first
						sequence of 64
						(= FSP_EXTENT_SIZE) consecutive
						pages in the doublewrite
						buffer */
#define TRX_SYS_DOUBLEWRITE_BLOCK2	(8 + FSEG_HEADER_SIZE)
586
						/*!< page number of the
osku's avatar
osku committed
587 588 589 590
						first page in the second
						sequence of 64 consecutive
						pages in the doublewrite
						buffer */
591 592 593 594 595 596 597 598 599 600 601 602
#define TRX_SYS_DOUBLEWRITE_REPEAT	12	/*!< we repeat
						TRX_SYS_DOUBLEWRITE_MAGIC,
						TRX_SYS_DOUBLEWRITE_BLOCK1,
						TRX_SYS_DOUBLEWRITE_BLOCK2
						so that if the trx sys
						header is half-written
						to disk, we still may
						be able to recover the
						information */
/** If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
we must reset the doublewrite buffer, because starting from 4.1.x the
space id of a data page is stored into
603
FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
osku's avatar
osku committed
604
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED (24 + FSEG_HEADER_SIZE)
605

osku's avatar
osku committed
606
/*-------------------------------------------------------------*/
607
/** Contents of TRX_SYS_DOUBLEWRITE_MAGIC */
osku's avatar
osku committed
608
#define TRX_SYS_DOUBLEWRITE_MAGIC_N	536853855
609
/** Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED */
osku's avatar
osku committed
610 611
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N 1783657386

612
/** Size of the doublewrite block in pages */
613
#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE	FSP_EXTENT_SIZE
614
/* @} */
osku's avatar
osku committed
615

616 617 618 619
/** File format tag */
/* @{ */
/** The offset of the file format tag on the trx system header page
(TRX_SYS_PAGE_NO of TRX_SYS_SPACE) */
620 621
#define TRX_SYS_FILE_FORMAT_TAG		(UNIV_PAGE_SIZE - 16)

622
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
623
identifier is added to this constant. */
624
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW	3645922177UL
625
/** Contents of TRX_SYS_FILE_FORMAT_TAG+4 when valid */
626
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH	2745987765UL
627
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
628 629 630 631
identifier is added to this 64-bit constant. */
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N					\
	((ib_uint64_t) TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH << 32	\
	 | TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW)
632
/* @} */
633

634 635
#ifndef UNIV_HOTBACKUP
/** The transaction system central memory data structure. */
636
struct trx_sys_t{
637

638
	ib_mutex_t		mutex;		/*!< mutex protecting most fields in
639 640 641 642
					this structure except when noted
					otherwise */
	ulint		n_prepared_trx;	/*!< Number of transactions currently
					in the XA PREPARED state */
643 644 645 646 647 648 649 650
	ulint		n_prepared_recovered_trx; /*!< Number of transactions
					currently in XA PREPARED state that are
					also recovered. Such transactions cannot
					be added during runtime. They can only
					occur after recovery if mysqld crashed
					while there were XA PREPARED
					transactions. We disable query cache
					if such transactions exist. */
651
	trx_id_t	max_trx_id;	/*!< The smallest number not yet
osku's avatar
osku committed
652 653
					assigned as a transaction id or
					transaction number */
654 655 656 657
#ifdef UNIV_DEBUG
	trx_id_t	rw_max_trx_id;	/*!< Max trx id of read-write transactions
					which exist or existed */
#endif
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
	trx_list_t	rw_trx_list;	/*!< List of active and committed in
					memory read-write transactions, sorted
					on trx id, biggest first. Recovered
					transactions are always on this list. */
	trx_list_t	ro_trx_list;	/*!< List of active and committed in
					memory read-only transactions, sorted
					on trx id, biggest first. NOTE:
					The order for read-only transactions
					is not necessary. We should exploit
					this and increase concurrency during
					add/remove. */
	trx_list_t	mysql_trx_list;	/*!< List of transactions created
					for MySQL. All transactions on
					ro_trx_list are on mysql_trx_list. The
					rw_trx_list can contain system
					transactions and recovered transactions
					that will not be in the mysql_trx_list.
					There can be active non-locking
					auto-commit read only transactions that
					are on this list but not on ro_trx_list.
					mysql_trx_list may additionally contain
					transactions that have not yet been
					started in InnoDB. */
	trx_rseg_t*	const rseg_array[TRX_SYS_N_RSEGS];
682
					/*!< Pointer array to rollback
683 684 685 686 687
					segments; NULL if slot not in use;
					created and destroyed in
					single-threaded mode; not protected
					by any mutex, because it is read-only
					during multi-threaded operation */
688
	ulint		rseg_history_len;/*!< Length of the TRX_RSEG_HISTORY
osku's avatar
osku committed
689 690 691 692
					list (update undo logs for committed
					transactions), protected by
					rseg->mutex */
	UT_LIST_BASE_NODE_T(read_view_t) view_list;
693 694
					/*!< List of read views sorted
					on trx no, biggest first */
osku's avatar
osku committed
695 696
};

697
/** When a trx id which is zero modulo this number (which must be a power of
osku's avatar
osku committed
698 699 700
two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system
page is updated */
#define TRX_SYS_TRX_ID_WRITE_MARGIN	256
701
#endif /* !UNIV_HOTBACKUP */
osku's avatar
osku committed
702 703 704 705 706

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

707
#endif