1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/trx0sys.h
29 Transaction system
30 
31 Created 3/26/1996 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef trx0sys_h
35 #define trx0sys_h
36 
37 #include "univ.i"
38 
39 #include "trx0types.h"
40 #include "fsp0types.h"
41 #include "fil0fil.h"
42 #include "buf0buf.h"
43 #ifndef UNIV_HOTBACKUP
44 #include "mtr0mtr.h"
45 #include "ut0byte.h"
46 #include "mem0mem.h"
47 #include "sync0sync.h"
48 #include "ut0lst.h"
49 #include "ut0bh.h"
50 #include "read0types.h"
51 #include "page0types.h"
52 #include "ut0bh.h"
53 
54 typedef UT_LIST_BASE_NODE_T(trx_t) trx_list_t;
55 
56 /** In a MySQL replication slave, in crash recovery we store the master log
57 file name and position here. */
58 /* @{ */
59 /** Master binlog file name */
60 extern char		trx_sys_mysql_master_log_name[];
61 /** Master binlog file position.  We have successfully got the updates
62 up to this position.  -1 means that no crash recovery was needed, or
63 there was no master log position info inside InnoDB.*/
64 extern ib_int64_t	trx_sys_mysql_master_log_pos;
65 /* @} */
66 
67 /** If this MySQL server uses binary logging, after InnoDB has been inited
68 and if it has done a crash recovery, we store the binlog file name and position
69 here. */
70 /* @{ */
71 /** Binlog file name */
72 extern char		trx_sys_mysql_bin_log_name[];
73 /** Binlog file position, or -1 if unknown */
74 extern ib_int64_t	trx_sys_mysql_bin_log_pos;
75 /* @} */
76 
77 /** The transaction system */
78 extern trx_sys_t*	trx_sys;
79 
80 /***************************************************************//**
81 Checks if a page address is the trx sys header page.
82 @return	TRUE if trx sys header page */
83 UNIV_INLINE
84 ibool
85 trx_sys_hdr_page(
86 /*=============*/
87 	ulint	space,	/*!< in: space */
88 	ulint	page_no);/*!< in: page number */
89 /*****************************************************************//**
90 Creates and initializes the central memory structures for the transaction
91 system. This is called when the database is started.
92 @return min binary heap of rsegs to purge */
93 UNIV_INTERN
94 ib_bh_t*
95 trx_sys_init_at_db_start(void);
96 /*==========================*/
97 /*****************************************************************//**
98 Creates the trx_sys instance and initializes ib_bh and mutex. */
99 UNIV_INTERN
100 void
101 trx_sys_create(void);
102 /*================*/
103 /*****************************************************************//**
104 Creates and initializes the transaction system at the database creation. */
105 UNIV_INTERN
106 void
107 trx_sys_create_sys_pages(void);
108 /*==========================*/
109 /****************************************************************//**
110 Looks for a free slot for a rollback segment in the trx system file copy.
111 @return	slot index or ULINT_UNDEFINED if not found */
112 UNIV_INTERN
113 ulint
114 trx_sysf_rseg_find_free(
115 /*====================*/
116 	mtr_t*		mtr);		/*!< in: mtr */
117 /***************************************************************//**
118 Gets the pointer in the nth slot of the rseg array.
119 @return	pointer to rseg object, NULL if slot not in use */
120 UNIV_INLINE
121 trx_rseg_t*
122 trx_sys_get_nth_rseg(
123 /*=================*/
124 	trx_sys_t*	sys,	/*!< in: trx system */
125 	ulint		n);	/*!< in: index of slot */
126 /**********************************************************************//**
127 Gets a pointer to the transaction system file copy and x-locks its page.
128 @return	pointer to system file copy, page x-locked */
129 UNIV_INLINE
130 trx_sysf_t*
131 trx_sysf_get(
132 /*=========*/
133 	mtr_t*	mtr);	/*!< in: mtr */
134 /*****************************************************************//**
135 Gets the space of the nth rollback segment slot in the trx system
136 file copy.
137 @return	space id */
138 UNIV_INLINE
139 ulint
140 trx_sysf_rseg_get_space(
141 /*====================*/
142 	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
143 	ulint		i,		/*!< in: slot index == rseg id */
144 	mtr_t*		mtr);		/*!< in: mtr */
145 /*****************************************************************//**
146 Gets the page number of the nth rollback segment slot in the trx system
147 file copy.
148 @return	page number, FIL_NULL if slot unused */
149 UNIV_INLINE
150 ulint
151 trx_sysf_rseg_get_page_no(
152 /*======================*/
153 	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
154 	ulint		i,		/*!< in: slot index == rseg id */
155 	mtr_t*		mtr);		/*!< in: mtr */
156 /*****************************************************************//**
157 Sets the space id of the nth rollback segment slot in the trx system
158 file copy. */
159 UNIV_INLINE
160 void
161 trx_sysf_rseg_set_space(
162 /*====================*/
163 	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
164 	ulint		i,		/*!< in: slot index == rseg id */
165 	ulint		space,		/*!< in: space id */
166 	mtr_t*		mtr);		/*!< in: mtr */
167 /*****************************************************************//**
168 Sets the page number of the nth rollback segment slot in the trx system
169 file copy. */
170 UNIV_INLINE
171 void
172 trx_sysf_rseg_set_page_no(
173 /*======================*/
174 	trx_sysf_t*	sys_header,	/*!< in: trx sys file copy */
175 	ulint		i,		/*!< in: slot index == rseg id */
176 	ulint		page_no,	/*!< in: page number, FIL_NULL if
177 					the slot is reset to unused */
178 	mtr_t*		mtr);		/*!< in: mtr */
179 /*****************************************************************//**
180 Allocates a new transaction id.
181 @return	new, allocated trx id */
182 UNIV_INLINE
183 trx_id_t
184 trx_sys_get_new_trx_id(void);
185 /*========================*/
186 /*****************************************************************//**
187 Determines the maximum transaction id.
188 @return maximum currently allocated trx id; will be stale after the
189 next call to trx_sys_get_new_trx_id() */
190 UNIV_INLINE
191 trx_id_t
192 trx_sys_get_max_trx_id(void);
193 /*========================*/
194 
195 /*************************************************************//**
196 Find a slot for a given trx ID in a descriptors array.
197 @return: slot pointer */
198 UNIV_INLINE
199 trx_id_t*
200 trx_find_descriptor(
201 /*================*/
202 	const trx_id_t*	descriptors,	/*!< in: descriptors array */
203 	ulint		n_descr,	/*!< in: array size */
204 	trx_id_t	trx_id);	/*!< in: trx pointer */
205 
206 #ifdef UNIV_DEBUG
207 /* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */
208 extern uint			trx_rseg_n_slots_debug;
209 #endif
210 
211 /*****************************************************************//**
212 Writes a trx id to an index page. In case that the id size changes in
213 some future version, this function should be used instead of
214 mach_write_... */
215 UNIV_INLINE
216 void
217 trx_write_trx_id(
218 /*=============*/
219 	byte*		ptr,	/*!< in: pointer to memory where written */
220 	trx_id_t	id);	/*!< in: id */
221 /*****************************************************************//**
222 Reads a trx id from an index page. In case that the id size changes in
223 some future version, this function should be used instead of
224 mach_read_...
225 @return	id */
226 UNIV_INLINE
227 trx_id_t
228 trx_read_trx_id(
229 /*============*/
230 	const byte*	ptr);	/*!< in: pointer to memory from where to read */
231 /****************************************************************//**
232 Looks for the trx instance with the given id in the rw trx_list.
233 The caller must be holding trx_sys->mutex.
234 @return	the trx handle or NULL if not found;
235 the pointer must not be dereferenced unless lock_sys->mutex was
236 acquired before calling this function and is still being held */
237 UNIV_INLINE
238 trx_t*
239 trx_get_rw_trx_by_id(
240 /*=================*/
241 	trx_id_t	trx_id);/*!< in: trx id to search for */
242 /****************************************************************//**
243 Returns the minimum trx id in rw trx list. This is the smallest id for which
244 the trx can possibly be active. (But, you must look at the trx->state to
245 find out if the minimum trx id transaction itself is active, or already
246 committed.)
247 @return	the minimum trx id, or trx_sys->max_trx_id if the trx list is empty */
248 UNIV_INLINE
249 trx_id_t
250 trx_rw_min_trx_id(void);
251 /*===================*/
252 /****************************************************************//**
253 Returns pointer to a transaction instance if a rw transaction with the given id
254 is active. Caller must hold trx_sys->mutex. If the caller is not holding
255 lock_sys->mutex, the transaction may already have been committed.
256 @return transaction instance if active, or NULL;
257 the pointer must not be dereferenced unless lock_sys->mutex was
258 acquired before calling this function and is still being held */
259 UNIV_INLINE
260 trx_t*
261 trx_rw_get_active_trx_by_id(
262 /*========================*/
263 	trx_id_t	trx_id,		/*!< in: trx id of the transaction */
264 	ibool*		corrupt);	/*!< in: NULL or pointer to a flag
265 					that will be set if corrupt */
266 /****************************************************************//**
267 Checks if a rw transaction with the given id is active. Caller must hold
268 trx_sys->mutex. If the caller is not holding lock_sys->mutex, the
269 transaction may already have been committed.
270 @return	true if rw transaction it with a given id is active. */
271 UNIV_INLINE
272 bool
273 trx_rw_is_active_low(
274 /*=================*/
275 	trx_id_t	trx_id,		/*!< in: trx id of the transaction */
276 	ibool*		corrupt);	/*!< in: NULL or pointer to a flag
277 					that will be set if corrupt */
278 /****************************************************************//**
279 Checks if a rw transaction with the given id is active. If the caller is
280 not holding lock_sys->mutex, the transaction may already have been
281 committed.
282 @return	true if rw transaction it with a given id is active. */
283 UNIV_INLINE
284 bool
285 trx_rw_is_active(
286 /*=============*/
287 	trx_id_t	trx_id,		/*!< in: trx id of the transaction */
288 	ibool*		corrupt);	/*!< in: NULL or pointer to a flag
289 					that will be set if corrupt */
290 #ifdef UNIV_DEBUG
291 /****************************************************************//**
292 Checks whether a trx is in one of rw_trx_list or ro_trx_list.
293 @return	TRUE if is in */
294 UNIV_INTERN
295 ibool
296 trx_in_trx_list(
297 /*============*/
298 	const trx_t*	in_trx)		/*!< in: transaction */
299 	MY_ATTRIBUTE((nonnull, warn_unused_result));
300 #endif /* UNIV_DEBUG */
301 #if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
302 /***********************************************************//**
303 Assert that a transaction has been recovered.
304 @return TRUE */
305 UNIV_INLINE
306 ibool
307 trx_assert_recovered(
308 /*=================*/
309 	trx_id_t	trx_id)		/*!< in: transaction identifier */
310 	MY_ATTRIBUTE((warn_unused_result));
311 #endif /* UNIV_DEBUG || UNIV_BLOB_LIGHT_DEBUG */
312 /*****************************************************************//**
313 Updates the offset information about the end of the MySQL binlog entry
314 which corresponds to the transaction just being committed. In a MySQL
315 replication slave updates the latest master binlog position up to which
316 replication has proceeded. */
317 UNIV_INTERN
318 void
319 trx_sys_update_mysql_binlog_offset(
320 /*===============================*/
321 	const char*	file_name,/*!< in: MySQL log file name */
322 	ib_int64_t	offset,	/*!< in: position in that log file */
323 	ulint		field,	/*!< in: offset of the MySQL log info field in
324 				the trx sys header */
325 	mtr_t*		mtr);	/*!< in: mtr */
326 /*****************************************************************//**
327 Prints to stderr the MySQL binlog offset info in the trx system header if
328 the magic number shows it valid. */
329 UNIV_INTERN
330 void
331 trx_sys_print_mysql_binlog_offset(void);
332 /*===================================*/
333 /*****************************************************************//**
334 Prints to stderr the MySQL master log offset info in the trx system header if
335 the magic number shows it valid. */
336 UNIV_INTERN
337 void
338 trx_sys_print_mysql_master_log_pos(void);
339 /*====================================*/
340 /*****************************************************************//**
341 Initializes the tablespace tag system. */
342 UNIV_INTERN
343 void
344 trx_sys_file_format_init(void);
345 /*==========================*/
346 /*****************************************************************//**
347 Closes the tablespace tag system. */
348 UNIV_INTERN
349 void
350 trx_sys_file_format_close(void);
351 /*===========================*/
352 /********************************************************************//**
353 Tags the system table space with minimum format id if it has not been
354 tagged yet.
355 WARNING: This function is only called during the startup and AFTER the
356 redo log application during recovery has finished. */
357 UNIV_INTERN
358 void
359 trx_sys_file_format_tag_init(void);
360 /*==============================*/
361 /*****************************************************************//**
362 Shutdown/Close the transaction system. */
363 UNIV_INTERN
364 void
365 trx_sys_close(void);
366 /*===============*/
367 /*****************************************************************//**
368 Get the name representation of the file format from its id.
369 @return	pointer to the name */
370 UNIV_INTERN
371 const char*
372 trx_sys_file_format_id_to_name(
373 /*===========================*/
374 	const ulint	id);		/*!< in: id of the file format */
375 /*****************************************************************//**
376 Set the file format id unconditionally except if it's already the
377 same value.
378 @return	TRUE if value updated */
379 UNIV_INTERN
380 ibool
381 trx_sys_file_format_max_set(
382 /*========================*/
383 	ulint		format_id,	/*!< in: file format id */
384 	const char**	name);		/*!< out: max file format name or
385 					NULL if not needed. */
386 /*********************************************************************
387 Creates the rollback segments
388 @return number of rollback segments that are active. */
389 UNIV_INTERN
390 ulint
391 trx_sys_create_rsegs(
392 /*=================*/
393 	ulint	n_spaces,	/*!< number of tablespaces for UNDO logs */
394 	ulint	n_rsegs);	/*!< number of rollback segments to create */
395 /*****************************************************************//**
396 Get the number of transaction in the system, independent of their state.
397 @return count of transactions in trx_sys_t::trx_list */
398 UNIV_INLINE
399 ulint
400 trx_sys_get_n_rw_trx(void);
401 /*======================*/
402 
403 /*********************************************************************
404 Check if there are any active (non-prepared) transactions.
405 @return total number of active transactions or 0 if none */
406 UNIV_INTERN
407 ulint
408 trx_sys_any_active_transactions(void);
409 /*=================================*/
410 #else /* !UNIV_HOTBACKUP */
411 /*****************************************************************//**
412 Prints to stderr the MySQL binlog info in the system header if the
413 magic number shows it valid. */
414 UNIV_INTERN
415 void
416 trx_sys_print_mysql_binlog_offset_from_page(
417 /*========================================*/
418 	const byte*	page);	/*!< in: buffer containing the trx
419 				system header page, i.e., page number
420 				TRX_SYS_PAGE_NO in the tablespace */
421 /*****************************************************************//**
422 Reads the file format id from the first system table space file.
423 Even if the call succeeds and returns TRUE, the returned format id
424 may be ULINT_UNDEFINED signalling that the format id was not present
425 in the data file.
426 @return TRUE if call succeeds */
427 UNIV_INTERN
428 ibool
429 trx_sys_read_file_format_id(
430 /*========================*/
431 	const char *pathname,	/*!< in: pathname of the first system
432 				table space file */
433 	ulint *format_id);	/*!< out: file format of the system table
434 				space */
435 /*****************************************************************//**
436 Reads the file format id from the given per-table data file.
437 @return TRUE if call succeeds */
438 UNIV_INTERN
439 ibool
440 trx_sys_read_pertable_file_format_id(
441 /*=================================*/
442 	const char *pathname,	/*!< in: pathname of a per-table
443 				datafile */
444 	ulint *format_id);	/*!< out: file format of the per-table
445 				data file */
446 #endif /* !UNIV_HOTBACKUP */
447 /*****************************************************************//**
448 Get the name representation of the file format from its id.
449 @return	pointer to the max format name */
450 UNIV_INTERN
451 const char*
452 trx_sys_file_format_max_get(void);
453 /*=============================*/
454 /*****************************************************************//**
455 Check for the max file format tag stored on disk.
456 @return	DB_SUCCESS or error code */
457 UNIV_INTERN
458 dberr_t
459 trx_sys_file_format_max_check(
460 /*==========================*/
461 	ulint		max_format_id);	/*!< in: the max format id to check */
462 /********************************************************************//**
463 Update the file format tag in the system tablespace only if the given
464 format id is greater than the known max id.
465 @return	TRUE if format_id was bigger than the known max id */
466 UNIV_INTERN
467 ibool
468 trx_sys_file_format_max_upgrade(
469 /*============================*/
470 	const char**	name,		/*!< out: max file format name */
471 	ulint		format_id);	/*!< in: file format identifier */
472 /*****************************************************************//**
473 Get the name representation of the file format from its id.
474 @return	pointer to the name */
475 UNIV_INTERN
476 const char*
477 trx_sys_file_format_id_to_name(
478 /*===========================*/
479 	const ulint	id);	/*!< in: id of the file format */
480 
481 #ifdef UNIV_DEBUG
482 /*************************************************************//**
483 Validate the trx_sys_t::trx_list. */
484 UNIV_INTERN
485 ibool
486 trx_sys_validate_trx_list(void);
487 /*===========================*/
488 #endif /* UNIV_DEBUG */
489 
490 /* The automatically created system rollback segment has this id */
491 #define TRX_SYS_SYSTEM_RSEG_ID	0
492 
493 /* Space id and page no where the trx system file copy resides */
494 #define	TRX_SYS_SPACE	0	/* the SYSTEM tablespace */
495 #include "fsp0fsp.h"
496 #define	TRX_SYS_PAGE_NO	FSP_TRX_SYS_PAGE_NO
497 
498 /* The offset of the transaction system header on the page */
499 #define	TRX_SYS		FSEG_PAGE_DATA
500 
501 /** Transaction system header */
502 /*------------------------------------------------------------- @{ */
503 #define	TRX_SYS_TRX_ID_STORE	0	/*!< the maximum trx id or trx
504 					number modulo
505 					TRX_SYS_TRX_ID_UPDATE_MARGIN
506 					written to a file page by any
507 					transaction; the assignment of
508 					transaction ids continues from
509 					this number rounded up by
510 					TRX_SYS_TRX_ID_UPDATE_MARGIN
511 					plus
512 					TRX_SYS_TRX_ID_UPDATE_MARGIN
513 					when the database is
514 					started */
515 #define TRX_SYS_FSEG_HEADER	8	/*!< segment header for the
516 					tablespace segment the trx
517 					system is created into */
518 #define	TRX_SYS_RSEGS		(8 + FSEG_HEADER_SIZE)
519 					/*!< the start of the array of
520 					rollback segment specification
521 					slots */
522 /*------------------------------------------------------------- @} */
523 
524 /* Max number of rollback segments: the number of segment specification slots
525 in the transaction system array; rollback segment id must fit in one (signed)
526 byte, therefore 128; each slot is currently 8 bytes in size. If you want
527 to raise the level to 256 then you will need to fix some assertions that
528 impose the 7 bit restriction. e.g., mach_write_to_3() */
529 #define	TRX_SYS_N_RSEGS			128
530 /* Originally, InnoDB defined TRX_SYS_N_RSEGS as 256 but created only one
531 rollback segment.  It initialized some arrays with this number of entries.
532 We must remember this limit in order to keep file compatibility. */
533 #define TRX_SYS_OLD_N_RSEGS		256
534 
535 /** Maximum length of MySQL binlog file name, in bytes.
536 @see trx_sys_mysql_master_log_name
537 @see trx_sys_mysql_bin_log_name */
538 #define TRX_SYS_MYSQL_LOG_NAME_LEN	512
539 /** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
540 #define TRX_SYS_MYSQL_LOG_MAGIC_N	873422344
541 
542 #if UNIV_PAGE_SIZE_MIN < 4096
543 # error "UNIV_PAGE_SIZE_MIN < 4096"
544 #endif
545 /** The offset of the MySQL replication info in the trx system header;
546 this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
547 #define TRX_SYS_MYSQL_MASTER_LOG_INFO	(UNIV_PAGE_SIZE - 2000)
548 
549 /** The offset of the MySQL binlog offset info in the trx system header */
550 #define TRX_SYS_MYSQL_LOG_INFO		(UNIV_PAGE_SIZE - 1000)
551 #define	TRX_SYS_MYSQL_LOG_MAGIC_N_FLD	0	/*!< magic number which is
552 						TRX_SYS_MYSQL_LOG_MAGIC_N
553 						if we have valid data in the
554 						MySQL binlog info */
555 #define TRX_SYS_MYSQL_LOG_OFFSET_HIGH	4	/*!< high 4 bytes of the offset
556 						within that file */
557 #define TRX_SYS_MYSQL_LOG_OFFSET_LOW	8	/*!< low 4 bytes of the offset
558 						within that file */
559 #define TRX_SYS_MYSQL_LOG_NAME		12	/*!< MySQL log file name */
560 
561 /** Doublewrite buffer */
562 /* @{ */
563 /** The offset of the doublewrite buffer header on the trx system header page */
564 #define TRX_SYS_DOUBLEWRITE		(UNIV_PAGE_SIZE - 200)
565 /*-------------------------------------------------------------*/
566 #define TRX_SYS_DOUBLEWRITE_FSEG	0	/*!< fseg header of the fseg
567 						containing the doublewrite
568 						buffer */
569 #define TRX_SYS_DOUBLEWRITE_MAGIC	FSEG_HEADER_SIZE
570 						/*!< 4-byte magic number which
571 						shows if we already have
572 						created the doublewrite
573 						buffer */
574 #define TRX_SYS_DOUBLEWRITE_BLOCK1	(4 + FSEG_HEADER_SIZE)
575 						/*!< page number of the
576 						first page in the first
577 						sequence of 64
578 						(= FSP_EXTENT_SIZE) consecutive
579 						pages in the doublewrite
580 						buffer */
581 #define TRX_SYS_DOUBLEWRITE_BLOCK2	(8 + FSEG_HEADER_SIZE)
582 						/*!< page number of the
583 						first page in the second
584 						sequence of 64 consecutive
585 						pages in the doublewrite
586 						buffer */
587 #define TRX_SYS_DOUBLEWRITE_REPEAT	12	/*!< we repeat
588 						TRX_SYS_DOUBLEWRITE_MAGIC,
589 						TRX_SYS_DOUBLEWRITE_BLOCK1,
590 						TRX_SYS_DOUBLEWRITE_BLOCK2
591 						so that if the trx sys
592 						header is half-written
593 						to disk, we still may
594 						be able to recover the
595 						information */
596 /** If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
597 we must reset the doublewrite buffer, because starting from 4.1.x the
598 space id of a data page is stored into
599 FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
600 #define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED (24 + FSEG_HEADER_SIZE)
601 
602 /*-------------------------------------------------------------*/
603 /** Contents of TRX_SYS_DOUBLEWRITE_MAGIC */
604 #define TRX_SYS_DOUBLEWRITE_MAGIC_N	536853855
605 /** Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED */
606 #define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N 1783657386
607 
608 /** Size of the doublewrite block in pages */
609 #define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE	FSP_EXTENT_SIZE
610 /* @} */
611 
612 /** File format tag */
613 /* @{ */
614 /** The offset of the file format tag on the trx system header page
615 (TRX_SYS_PAGE_NO of TRX_SYS_SPACE) */
616 #define TRX_SYS_FILE_FORMAT_TAG		(UNIV_PAGE_SIZE - 16)
617 
618 /** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
619 identifier is added to this constant. */
620 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW	3645922177UL
621 /** Contents of TRX_SYS_FILE_FORMAT_TAG+4 when valid */
622 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH	2745987765UL
623 /** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
624 identifier is added to this 64-bit constant. */
625 #define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N					\
626 	((ib_uint64_t) TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH << 32	\
627 	 | TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW)
628 /* @} */
629 
630 #define TRX_DESCR_ARRAY_INITIAL_SIZE 	1000
631 
632 #ifndef UNIV_HOTBACKUP
633 /** The transaction system central memory data structure. */
634 struct trx_sys_t{
635 
636 	ib_mutex_t		mutex;		/*!< mutex protecting most fields in
637 					this structure except when noted
638 					otherwise */
639 	ulint		n_prepared_trx;	/*!< Number of transactions currently
640 					in the XA PREPARED state */
641 	ulint		n_prepared_recovered_trx; /*!< Number of transactions
642 					currently in XA PREPARED state that are
643 					also recovered. Such transactions cannot
644 					be added during runtime. They can only
645 					occur after recovery if mysqld crashed
646 					while there were XA PREPARED
647 					transactions. We disable query cache
648 					if such transactions exist. */
649 	trx_id_t	max_trx_id;	/*!< The smallest number not yet
650 					assigned as a transaction id or
651 					transaction number */
652 	char		pad1[64];	/*!< Ensure max_trx_id does not share
653 					cache line with other fields. */
654 	trx_id_t*	descriptors;	/*!< Array of trx descriptors */
655 	ulint		descr_n_max;	/*!< The current size of the descriptors
656 					array. */
657 	char		pad2[64];	/*!< Ensure static descriptor fields
658 					do not share cache lines with
659 					descr_n_used */
660 	ulint		descr_n_used;	/*!< Number of used elements in the
661 					descriptors array. */
662 	char		pad3[64];	/*!< Ensure descriptors do not share
663 					cache line with other fields */
664 #ifdef UNIV_DEBUG
665 	trx_id_t	rw_max_trx_id;	/*!< Max trx id of read-write transactions
666 					which exist or existed */
667 #endif
668 	trx_list_t	rw_trx_list;	/*!< List of active and committed in
669 					memory read-write transactions, sorted
670 					on trx id, biggest first. Recovered
671 					transactions are always on this list. */
672 	char		pad4[64];	/*!< Ensure list base nodes do not
673 					share cache line with other fields */
674 	trx_list_t	ro_trx_list;	/*!< List of active and committed in
675 					memory read-only transactions, sorted
676 					on trx id, biggest first. NOTE:
677 					The order for read-only transactions
678 					is not necessary. We should exploit
679 					this and increase concurrency during
680 					add/remove. */
681 	char		pad5[64];	/*!< Ensure list base nodes do not
682 					share cache line with other fields */
683 	trx_list_t	mysql_trx_list;	/*!< List of transactions created
684 					for MySQL. All transactions on
685 					ro_trx_list are on mysql_trx_list. The
686 					rw_trx_list can contain system
687 					transactions and recovered transactions
688 					that will not be in the mysql_trx_list.
689 					There can be active non-locking
690 					auto-commit read only transactions that
691 					are on this list but not on ro_trx_list.
692 					mysql_trx_list may additionally contain
693 					transactions that have not yet been
694 					started in InnoDB. */
695 	char		pad6[64];	/*!< Ensure list base nodes do not
696 					share cache line with other fields */
697 	trx_list_t	trx_serial_list;
698 					/*!< trx->no ordered List of
699 					transactions in either TRX_PREPARED or
700 					TRX_ACTIVE which have already been
701 					assigned a serialization number */
702 	char		pad7[64];	/*!< Ensure list base nodes do not
703 					share cache line with other fields */
704 	trx_rseg_t*	const rseg_array[TRX_SYS_N_RSEGS];
705 					/*!< Pointer array to rollback
706 					segments; NULL if slot not in use;
707 					created and destroyed in
708 					single-threaded mode; not protected
709 					by any mutex, because it is read-only
710 					during multi-threaded operation */
711 	ulint		rseg_history_len;/*!< Length of the TRX_RSEG_HISTORY
712 					list (update undo logs for committed
713 					transactions), protected by
714 					rseg->mutex */
715 	UT_LIST_BASE_NODE_T(read_view_t) view_list;
716 					/*!< List of read views sorted
717 					on trx no, biggest first */
718 };
719 
720 /** When a trx id which is zero modulo this number (which must be a power of
721 two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system
722 page is updated */
723 #define TRX_SYS_TRX_ID_WRITE_MARGIN	256
724 #endif /* !UNIV_HOTBACKUP */
725 
726 #ifndef UNIV_NONINL
727 #include "trx0sys.ic"
728 #endif
729 
730 #endif
731