96
68
trx_sys_doublewrite_init_or_restore_pages(
97
69
/*======================================*/
98
ibool restore_corrupt_pages); /*!< in: TRUE=restore pages */
99
/****************************************************************//**
70
ibool restore_corrupt_pages);
71
/********************************************************************
100
72
Marks the trx sys header when we have successfully upgraded to the >= 4.1.x
101
73
multiple tablespace format. */
104
76
trx_sys_mark_upgraded_to_multiple_tablespaces(void);
105
77
/*===============================================*/
106
/****************************************************************//**
107
Determines if a page number is located inside the doublewrite buffer.
108
@return TRUE if the location is inside the two blocks of the
109
doublewrite buffer */
78
/********************************************************************
79
Determines if a page number is located inside the doublewrite buffer. */
112
82
trx_doublewrite_page_inside(
113
83
/*========================*/
114
ulint page_no); /*!< in: page number */
115
/***************************************************************//**
116
Checks if a page address is the trx sys header page.
117
@return TRUE if trx sys header page */
84
/* out: TRUE if the location is inside
85
the two blocks of the doublewrite buffer */
86
ulint page_no); /* in: page number */
87
/*******************************************************************
88
Checks if a page address is the trx sys header page. */
122
ulint space, /*!< in: space */
123
ulint page_no);/*!< in: page number */
124
/*****************************************************************//**
93
/* out: TRUE if trx sys header page */
94
ulint space, /* in: space */
95
ulint page_no);/* in: page number */
96
/*********************************************************************
125
97
Creates and initializes the central memory structures for the transaction
126
98
system. This is called when the database is started. */
129
101
trx_sys_init_at_db_start(void);
130
102
/*==========================*/
131
/*****************************************************************//**
103
/*********************************************************************
132
104
Creates and initializes the transaction system at the database creation. */
135
107
trx_sys_create(void);
136
108
/*================*/
137
/****************************************************************//**
138
Looks for a free slot for a rollback segment in the trx system file copy.
139
@return slot index or ULINT_UNDEFINED if not found */
109
/********************************************************************
110
Looks for a free slot for a rollback segment in the trx system file copy. */
142
113
trx_sysf_rseg_find_free(
143
114
/*====================*/
144
mtr_t* mtr); /*!< in: mtr */
145
/***************************************************************//**
146
Gets the pointer in the nth slot of the rseg array.
147
@return pointer to rseg object, NULL if slot not in use */
115
/* out: slot index or ULINT_UNDEFINED
117
mtr_t* mtr); /* in: mtr */
118
/*******************************************************************
119
Gets the pointer in the nth slot of the rseg array. */
150
122
trx_sys_get_nth_rseg(
151
123
/*=================*/
152
trx_sys_t* sys, /*!< in: trx system */
153
ulint n); /*!< in: index of slot */
154
/***************************************************************//**
124
/* out: pointer to rseg object, NULL if slot
126
trx_sys_t* sys, /* in: trx system */
127
ulint n); /* in: index of slot */
128
/*******************************************************************
155
129
Sets the pointer in the nth slot of the rseg array. */
158
132
trx_sys_set_nth_rseg(
159
133
/*=================*/
160
trx_sys_t* sys, /*!< in: trx system */
161
ulint n, /*!< in: index of slot */
162
trx_rseg_t* rseg); /*!< in: pointer to rseg object, NULL if slot
134
trx_sys_t* sys, /* in: trx system */
135
ulint n, /* in: index of slot */
136
trx_rseg_t* rseg); /* in: pointer to rseg object, NULL if slot
164
/**********************************************************************//**
165
Gets a pointer to the transaction system file copy and x-locks its page.
166
@return pointer to system file copy, page x-locked */
138
/**************************************************************************
139
Gets a pointer to the transaction system file copy and x-locks its page. */
171
mtr_t* mtr); /*!< in: mtr */
172
/*****************************************************************//**
144
/* out: pointer to system file copy, page x-locked */
145
mtr_t* mtr); /* in: mtr */
146
/*********************************************************************
173
147
Gets the space of the nth rollback segment slot in the trx system
178
151
trx_sysf_rseg_get_space(
179
152
/*====================*/
180
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
181
ulint i, /*!< in: slot index == rseg id */
182
mtr_t* mtr); /*!< in: mtr */
183
/*****************************************************************//**
154
trx_sysf_t* sys_header, /* in: trx sys file copy */
155
ulint i, /* in: slot index == rseg id */
156
mtr_t* mtr); /* in: mtr */
157
/*********************************************************************
184
158
Gets the page number of the nth rollback segment slot in the trx system
186
@return page number, FIL_NULL if slot unused */
189
162
trx_sysf_rseg_get_page_no(
190
163
/*======================*/
191
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
192
ulint i, /*!< in: slot index == rseg id */
193
mtr_t* mtr); /*!< in: mtr */
194
/*****************************************************************//**
164
/* out: page number, FIL_NULL
166
trx_sysf_t* sys_header, /* in: trx sys file copy */
167
ulint i, /* in: slot index == rseg id */
168
mtr_t* mtr); /* in: mtr */
169
/*********************************************************************
195
170
Sets the space id of the nth rollback segment slot in the trx system
199
174
trx_sysf_rseg_set_space(
200
175
/*====================*/
201
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
202
ulint i, /*!< in: slot index == rseg id */
203
ulint space, /*!< in: space id */
204
mtr_t* mtr); /*!< in: mtr */
205
/*****************************************************************//**
176
trx_sysf_t* sys_header, /* in: trx sys file copy */
177
ulint i, /* in: slot index == rseg id */
178
ulint space, /* in: space id */
179
mtr_t* mtr); /* in: mtr */
180
/*********************************************************************
206
181
Sets the page number of the nth rollback segment slot in the trx system
210
185
trx_sysf_rseg_set_page_no(
211
186
/*======================*/
212
trx_sysf_t* sys_header, /*!< in: trx sys file copy */
213
ulint i, /*!< in: slot index == rseg id */
214
ulint page_no, /*!< in: page number, FIL_NULL if
187
trx_sysf_t* sys_header, /* in: trx sys file copy */
188
ulint i, /* in: slot index == rseg id */
189
ulint page_no, /* in: page number, FIL_NULL if
215
190
the slot is reset to unused */
216
mtr_t* mtr); /*!< in: mtr */
217
/*****************************************************************//**
218
Allocates a new transaction id.
219
@return new, allocated trx id */
191
mtr_t* mtr); /* in: mtr */
192
/*********************************************************************
193
Allocates a new transaction id. */
222
196
trx_sys_get_new_trx_id(void);
223
197
/*========================*/
224
/*****************************************************************//**
225
Allocates a new transaction number.
226
@return new, allocated trx number */
198
/* out: new, allocated trx id */
199
/*********************************************************************
200
Allocates a new transaction number. */
229
203
trx_sys_get_new_trx_no(void);
230
204
/*========================*/
231
#endif /* !UNIV_HOTBACKUP */
232
/*****************************************************************//**
205
/* out: new, allocated trx number */
206
/*********************************************************************
233
207
Writes a trx id to an index page. In case that the id size changes in
234
208
some future version, this function should be used instead of
235
209
mach_write_... */
334
320
trx_sys_file_format_tag_init(void);
335
321
/*==============================*/
336
#ifndef UNIV_HOTBACKUP
337
/*****************************************************************//**
338
Shutdown/Close the transaction system. */
343
#endif /* !UNIV_HOTBACKUP */
344
/*****************************************************************//**
345
Get the name representation of the file format from its id.
346
@return pointer to the name */
322
/*********************************************************************
323
Get the name representation of the file format from its id. */
349
326
trx_sys_file_format_id_to_name(
350
327
/*===========================*/
351
const ulint id); /*!< in: id of the file format */
352
/*****************************************************************//**
328
/* out: pointer to the name */
329
const ulint id); /* in: id of the file format */
330
/*********************************************************************
353
331
Set the file format id unconditionally except if it's already the
355
@return TRUE if value updated */
358
335
trx_sys_file_format_max_set(
359
336
/*========================*/
360
ulint format_id, /*!< in: file format id */
361
const char** name); /*!< out: max file format name or
337
/* out: TRUE if value updated */
338
ulint format_id, /* in: file format id */
339
const char** name); /* out: max file format name or
362
340
NULL if not needed. */
363
/*****************************************************************//**
364
Get the name representation of the file format from its id.
365
@return pointer to the max format name */
341
/*********************************************************************
342
Get the name representation of the file format from its id. */
368
345
trx_sys_file_format_max_get(void);
369
346
/*=============================*/
370
/*****************************************************************//**
371
Check for the max file format tag stored on disk.
372
@return DB_SUCCESS or error code */
347
/* out: pointer to the max format name */
348
/*********************************************************************
349
Check for the max file format tag stored on disk. */
375
352
trx_sys_file_format_max_check(
376
353
/*==========================*/
377
ulint max_format_id); /*!< in: the max format id to check */
378
/********************************************************************//**
354
/* out: DB_SUCCESS or error code */
355
ulint max_format_id); /* in: the max format id to check */
356
/************************************************************************
379
357
Update the file format tag in the system tablespace only if the given
380
format id is greater than the known max id.
381
@return TRUE if format_id was bigger than the known max id */
358
format id is greater than the known max id. */
384
361
trx_sys_file_format_max_upgrade(
385
362
/*============================*/
386
const char** name, /*!< out: max file format name */
387
ulint format_id); /*!< in: file format identifier */
388
#else /* !UNIV_HOTBACKUP */
389
/*****************************************************************//**
390
Prints to stderr the MySQL binlog info in the system header if the
391
magic number shows it valid. */
394
trx_sys_print_mysql_binlog_offset_from_page(
395
/*========================================*/
396
const byte* page); /*!< in: buffer containing the trx
397
system header page, i.e., page number
398
TRX_SYS_PAGE_NO in the tablespace */
399
/*****************************************************************//**
400
Reads the file format id from the first system table space file.
401
Even if the call succeeds and returns TRUE, the returned format id
402
may be ULINT_UNDEFINED signalling that the format id was not present
404
@return TRUE if call succeeds */
407
trx_sys_read_file_format_id(
408
/*========================*/
409
const char *pathname, /*!< in: pathname of the first system
411
ulint *format_id); /*!< out: file format of the system table
413
/*****************************************************************//**
414
Reads the file format id from the given per-table data file.
415
@return TRUE if call succeeds */
418
trx_sys_read_pertable_file_format_id(
419
/*=================================*/
420
const char *pathname, /*!< in: pathname of a per-table
422
ulint *format_id); /*!< out: file format of the per-table
424
/*****************************************************************//**
425
Get the name representation of the file format from its id.
426
@return pointer to the name */
429
trx_sys_file_format_id_to_name(
430
/*===========================*/
431
const ulint id); /*!< in: id of the file format */
433
#endif /* !UNIV_HOTBACKUP */
434
/*********************************************************************
435
Creates the rollback segments */
438
trx_sys_create_rsegs(
439
/*=================*/
440
ulint n_rsegs); /*!< number of rollback segments to create */
363
/* out: TRUE if format_id was
364
bigger than the known max id */
365
const char** name, /* out: max file format name */
366
ulint format_id); /* in: file format identifier */
442
367
/* The automatically created system rollback segment has this id */
443
368
#define TRX_SYS_SYSTEM_RSEG_ID 0
445
370
/* Space id and page no where the trx system file copy resides */
446
371
#define TRX_SYS_SPACE 0 /* the SYSTEM tablespace */
448
372
#define TRX_SYS_PAGE_NO FSP_TRX_SYS_PAGE_NO
450
374
/* The offset of the transaction system header on the page */
451
375
#define TRX_SYS FSEG_PAGE_DATA
453
/** Transaction system header */
454
/*------------------------------------------------------------- @{ */
455
#define TRX_SYS_TRX_ID_STORE 0 /*!< the maximum trx id or trx
457
TRX_SYS_TRX_ID_UPDATE_MARGIN
377
/* Transaction system header */
378
/*-------------------------------------------------------------*/
379
#define TRX_SYS_TRX_ID_STORE 0 /* the maximum trx id or trx number
380
modulo TRX_SYS_TRX_ID_UPDATE_MARGIN
458
381
written to a file page by any
459
382
transaction; the assignment of
460
transaction ids continues from
461
this number rounded up by
462
TRX_SYS_TRX_ID_UPDATE_MARGIN
464
TRX_SYS_TRX_ID_UPDATE_MARGIN
383
transaction ids continues from this
384
number rounded up by .._MARGIN plus
385
.._MARGIN when the database is
467
#define TRX_SYS_FSEG_HEADER 8 /*!< segment header for the
468
tablespace segment the trx
469
system is created into */
387
#define TRX_SYS_FSEG_HEADER 8 /* segment header for the tablespace
388
segment the trx system is created
470
390
#define TRX_SYS_RSEGS (8 + FSEG_HEADER_SIZE)
471
/*!< the start of the array of
472
rollback segment specification
474
/*------------------------------------------------------------- @} */
391
/* the start of the array of rollback
392
segment specification slots */
393
/*-------------------------------------------------------------*/
476
395
/* Max number of rollback segments: the number of segment specification slots
477
in the transaction system array; rollback segment id must fit in one (signed)
478
byte, therefore 128; each slot is currently 8 bytes in size. If you want
479
to raise the level to 256 then you will need to fix some assertions that
480
impose the 7 bit restriction. e.g., mach_write_to_3() */
481
#define TRX_SYS_N_RSEGS 128
482
/* Originally, InnoDB defined TRX_SYS_N_RSEGS as 256 but created only one
483
rollback segment. It initialized some arrays with this number of entries.
484
We must remember this limit in order to keep file compatibility. */
485
#define TRX_SYS_OLD_N_RSEGS 256
396
in the transaction system array; rollback segment id must fit in one byte,
397
therefore 256; each slot is currently 8 bytes in size */
398
#define TRX_SYS_N_RSEGS 256
487
/** Maximum length of MySQL binlog file name, in bytes.
488
@see trx_sys_mysql_master_log_name
489
@see trx_sys_mysql_bin_log_name */
490
400
#define TRX_SYS_MYSQL_LOG_NAME_LEN 512
491
/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
492
401
#define TRX_SYS_MYSQL_LOG_MAGIC_N 873422344
494
403
#if UNIV_PAGE_SIZE < 4096
495
404
# error "UNIV_PAGE_SIZE < 4096"
497
/** The offset of the MySQL replication info in the trx system header;
406
/* The offset of the MySQL replication info in the trx system header;
498
407
this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
499
408
#define TRX_SYS_MYSQL_MASTER_LOG_INFO (UNIV_PAGE_SIZE - 2000)
501
/** The offset of the MySQL binlog offset info in the trx system header */
410
/* The offset of the MySQL binlog offset info in the trx system header */
502
411
#define TRX_SYS_MYSQL_LOG_INFO (UNIV_PAGE_SIZE - 1000)
503
#define TRX_SYS_MYSQL_LOG_MAGIC_N_FLD 0 /*!< magic number which is
504
TRX_SYS_MYSQL_LOG_MAGIC_N
412
#define TRX_SYS_MYSQL_LOG_MAGIC_N_FLD 0 /* magic number which shows
505
413
if we have valid data in the
507
#define TRX_SYS_MYSQL_LOG_OFFSET_HIGH 4 /*!< high 4 bytes of the offset
509
#define TRX_SYS_MYSQL_LOG_OFFSET_LOW 8 /*!< low 4 bytes of the offset
511
#define TRX_SYS_MYSQL_LOG_NAME 12 /*!< MySQL log file name */
414
MySQL binlog info; the value
415
is ..._MAGIC_N if yes */
416
#define TRX_SYS_MYSQL_LOG_OFFSET_HIGH 4 /* high 4 bytes of the offset
418
#define TRX_SYS_MYSQL_LOG_OFFSET_LOW 8 /* low 4 bytes of the offset
420
#define TRX_SYS_MYSQL_LOG_NAME 12 /* MySQL log file name */
513
/** Doublewrite buffer */
515
/** The offset of the doublewrite buffer header on the trx system header page */
422
/* The offset of the doublewrite buffer header on the trx system header page */
516
423
#define TRX_SYS_DOUBLEWRITE (UNIV_PAGE_SIZE - 200)
517
424
/*-------------------------------------------------------------*/
518
#define TRX_SYS_DOUBLEWRITE_FSEG 0 /*!< fseg header of the fseg
425
#define TRX_SYS_DOUBLEWRITE_FSEG 0 /* fseg header of the fseg
519
426
containing the doublewrite
521
428
#define TRX_SYS_DOUBLEWRITE_MAGIC FSEG_HEADER_SIZE
522
/*!< 4-byte magic number which
429
/* 4-byte magic number which
523
430
shows if we already have
524
431
created the doublewrite
526
433
#define TRX_SYS_DOUBLEWRITE_BLOCK1 (4 + FSEG_HEADER_SIZE)
527
/*!< page number of the
434
/* page number of the
528
435
first page in the first
530
437
(= FSP_EXTENT_SIZE) consecutive
531
438
pages in the doublewrite
533
440
#define TRX_SYS_DOUBLEWRITE_BLOCK2 (8 + FSEG_HEADER_SIZE)
534
/*!< page number of the
441
/* page number of the
535
442
first page in the second
536
443
sequence of 64 consecutive
537
444
pages in the doublewrite
539
#define TRX_SYS_DOUBLEWRITE_REPEAT 12 /*!< we repeat
540
TRX_SYS_DOUBLEWRITE_MAGIC,
541
TRX_SYS_DOUBLEWRITE_BLOCK1,
542
TRX_SYS_DOUBLEWRITE_BLOCK2
543
so that if the trx sys
544
header is half-written
545
to disk, we still may
546
be able to recover the
548
/** If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
549
we must reset the doublewrite buffer, because starting from 4.1.x the
550
space id of a data page is stored into
551
FIL_PAGE_ARCH_LOG_NO_OR_SPACE_NO. */
446
#define TRX_SYS_DOUBLEWRITE_REPEAT 12 /* we repeat the above 3
447
numbers so that if the trx
448
sys header is half-written
449
to disk, we still may be able
450
to recover the information */
552
451
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED (24 + FSEG_HEADER_SIZE)
452
/* If this is not yet set to
453
.._N, we must reset the
454
doublewrite buffer, because
455
starting from 4.1.x the space
456
id of a data page is stored to
457
FIL_PAGE_ARCH_LOG_NO_OR_SPACE_NO */
554
458
/*-------------------------------------------------------------*/
555
/** Contents of TRX_SYS_DOUBLEWRITE_MAGIC */
556
459
#define TRX_SYS_DOUBLEWRITE_MAGIC_N 536853855
557
/** Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED */
558
460
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N 1783657386
560
/** Size of the doublewrite block in pages */
561
463
#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE FSP_EXTENT_SIZE
564
#ifndef UNIV_HOTBACKUP
565
/** File format tag */
567
/** The offset of the file format tag on the trx system header page
568
(TRX_SYS_PAGE_NO of TRX_SYS_SPACE) */
465
/* The offset of the file format tag on the trx system header page */
569
466
#define TRX_SYS_FILE_FORMAT_TAG (UNIV_PAGE_SIZE - 16)
571
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
572
identifier is added to this constant. */
468
/* We use these random constants to reduce the probability of reading
469
garbage (from previous versions) that maps to an actual format id. We
470
use these as bit masks at the time of reading and writing from/to disk. */
573
471
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW 3645922177UL
574
/** Contents of TRX_SYS_FILE_FORMAT_TAG+4 when valid */
575
472
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH 2745987765UL
576
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
577
identifier is added to this 64-bit constant. */
578
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N \
579
((ib_uint64_t) TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH << 32 \
580
| TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW)
583
/** Doublewrite control struct */
474
/* Doublewrite control struct */
584
475
struct trx_doublewrite_struct{
585
mutex_t mutex; /*!< mutex protecting the first_free field and
476
mutex_t mutex; /* mutex protecting the first_free field and
587
ulint block1; /*!< the page number of the first
478
ulint block1; /* the page number of the first
588
479
doublewrite block (64 pages) */
589
ulint block2; /*!< page number of the second block */
590
ulint first_free; /*!< first free position in write_buf measured
480
ulint block2; /* page number of the second block */
481
ulint first_free; /* first free position in write_buf measured
591
482
in units of UNIV_PAGE_SIZE */
592
byte* write_buf; /*!< write buffer used in writing to the
483
byte* write_buf; /* write buffer used in writing to the
593
484
doublewrite buffer, aligned to an
594
485
address divisible by UNIV_PAGE_SIZE
595
486
(which is required by Windows aio) */
596
byte* write_buf_unaligned;
597
/*!< pointer to write_buf, but unaligned */
487
byte* write_buf_unaligned; /* pointer to write_buf, but unaligned */
599
buf_block_arr; /*!< array to store pointers to the buffer
489
buf_block_arr; /* array to store pointers to the buffer
600
490
blocks which have been cached to write_buf */
603
/** The transaction system central memory data structure; protected by the
493
/* The transaction system central memory data structure; protected by the
605
495
struct trx_sys_struct{
606
trx_id_t max_trx_id; /*!< The smallest number not yet
496
dulint max_trx_id; /* The smallest number not yet
607
497
assigned as a transaction id or
608
498
transaction number */
609
499
UT_LIST_BASE_NODE_T(trx_t) trx_list;
610
/*!< List of active and committed in
500
/* List of active and committed in
611
501
memory transactions, sorted on trx id,
613
503
UT_LIST_BASE_NODE_T(trx_t) mysql_trx_list;
614
/*!< List of transactions created
504
/* List of transactions created
616
506
UT_LIST_BASE_NODE_T(trx_rseg_t) rseg_list;
617
/*!< List of rollback segment
619
trx_rseg_t* latest_rseg; /*!< Latest rollback segment in the
507
/* List of rollback segment objects */
508
trx_rseg_t* latest_rseg; /* Latest rollback segment in the
620
509
round-robin assignment of rollback
621
510
segments to transactions */
622
511
trx_rseg_t* rseg_array[TRX_SYS_N_RSEGS];
623
/*!< Pointer array to rollback
624
segments; NULL if slot not in use */
625
ulint rseg_history_len;/*!< Length of the TRX_RSEG_HISTORY
512
/* Pointer array to rollback segments;
513
NULL if slot not in use */
514
ulint rseg_history_len;/* Length of the TRX_RSEG_HISTORY
626
515
list (update undo logs for committed
627
516
transactions), protected by
629
518
UT_LIST_BASE_NODE_T(read_view_t) view_list;
630
/*!< List of read views sorted
631
on trx no, biggest first */
519
/* List of read views sorted on trx no,
634
/** When a trx id which is zero modulo this number (which must be a power of
523
/* When a trx id which is zero modulo this number (which must be a power of
635
524
two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system
636
525
page is updated */
637
526
#define TRX_SYS_TRX_ID_WRITE_MARGIN 256
638
#endif /* !UNIV_HOTBACKUP */
640
528
#ifndef UNIV_NONINL
641
529
#include "trx0sys.ic"