~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2009-04-12 08:14:18 UTC
  • mto: (992.1.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 990.
  • Revision ID: mordred@inaugust.com-20090412081418-dc6gh3g3awkrhwov
Merged compress, uncompress and uncompressed_length into one plugin lib. Yay new plugin registration!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
 
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
 
St, Fifth Floor, Boston, MA 02110-1301 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
19
 
/**************************************************//**
20
 
@file include/trx0sys.h
 
19
/******************************************************
21
20
Transaction system
22
21
 
23
22
Created 3/26/1996 Heikki Tuuri
29
28
#include "univ.i"
30
29
 
31
30
#include "trx0types.h"
32
 
#include "fsp0types.h"
33
 
#include "fil0fil.h"
34
 
#include "buf0buf.h"
35
 
#ifndef UNIV_HOTBACKUP
36
31
#include "mtr0mtr.h"
 
32
#include "mtr0log.h"
37
33
#include "ut0byte.h"
38
34
#include "mem0mem.h"
39
35
#include "sync0sync.h"
40
36
#include "ut0lst.h"
 
37
#include "buf0buf.h"
 
38
#include "fil0fil.h"
 
39
#include "fut0lst.h"
 
40
#include "fsp0fsp.h"
41
41
#include "read0types.h"
42
42
#include "page0types.h"
43
43
 
44
 
/** In a MySQL replication slave, in crash recovery we store the master log
45
 
file name and position here. */
46
 
/* @{ */
47
 
/** Master binlog file name */
 
44
/* In a MySQL replication slave, in crash recovery we store the master log
 
45
file name and position here. We have successfully got the updates to InnoDB
 
46
up to this position. If .._pos is -1, it means no crash recovery was needed,
 
47
or there was no master log position info inside InnoDB. */
 
48
 
48
49
extern char             trx_sys_mysql_master_log_name[];
49
 
/** Master binlog file position.  We have successfully got the updates
50
 
up to this position.  -1 means that no crash recovery was needed, or
51
 
there was no master log position info inside InnoDB.*/
52
50
extern ib_int64_t       trx_sys_mysql_master_log_pos;
53
 
/* @} */
54
51
 
55
 
/** If this MySQL server uses binary logging, after InnoDB has been inited
 
52
/* If this MySQL server uses binary logging, after InnoDB has been inited
56
53
and if it has done a crash recovery, we store the binlog file name and position
57
 
here. */
58
 
/* @{ */
59
 
/** Binlog file name */
 
54
here. If .._pos is -1, it means there was no binlog position info inside
 
55
InnoDB. */
 
56
 
60
57
extern char             trx_sys_mysql_bin_log_name[];
61
 
/** Binlog file position, or -1 if unknown */
62
58
extern ib_int64_t       trx_sys_mysql_bin_log_pos;
63
 
/* @} */
64
59
 
65
 
/** The transaction system */
 
60
/* The transaction system */
66
61
extern trx_sys_t*       trx_sys;
67
62
 
68
 
/** Doublewrite system */
 
63
/* Doublewrite system */
69
64
extern trx_doublewrite_t*       trx_doublewrite;
70
 
/** The following is set to TRUE when we are upgrading from pre-4.1
71
 
format data files to the multiple tablespaces format data files */
72
65
extern ibool                    trx_doublewrite_must_reset_space_ids;
73
 
/** Set to TRUE when the doublewrite buffer is being created */
74
 
extern ibool                    trx_doublewrite_buf_is_being_created;
75
 
/** The following is TRUE when we are using the database in the
76
 
post-4.1 format, i.e., we have successfully upgraded, or have created
77
 
a new database installation */
78
66
extern ibool                    trx_sys_multiple_tablespace_format;
79
67
 
80
 
/****************************************************************//**
 
68
/********************************************************************
81
69
Creates the doublewrite buffer to a new InnoDB installation. The header of the
82
70
doublewrite buffer is placed on the trx system header page. */
83
71
UNIV_INTERN
84
72
void
85
73
trx_sys_create_doublewrite_buf(void);
86
74
/*================================*/
87
 
/****************************************************************//**
 
75
/********************************************************************
88
76
At a database startup initializes the doublewrite buffer memory structure if
89
77
we already have a doublewrite buffer created in the data files. If we are
90
78
upgrading to an InnoDB version which supports multiple tablespaces, then this
95
83
void
96
84
trx_sys_doublewrite_init_or_restore_pages(
97
85
/*======================================*/
98
 
        ibool   restore_corrupt_pages); /*!< in: TRUE=restore pages */
99
 
/****************************************************************//**
 
86
        ibool   restore_corrupt_pages);
 
87
/********************************************************************
100
88
Marks the trx sys header when we have successfully upgraded to the >= 4.1.x
101
89
multiple tablespace format. */
102
90
UNIV_INTERN
103
91
void
104
92
trx_sys_mark_upgraded_to_multiple_tablespaces(void);
105
93
/*===============================================*/
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 */
 
94
/********************************************************************
 
95
Determines if a page number is located inside the doublewrite buffer. */
110
96
UNIV_INTERN
111
97
ibool
112
98
trx_doublewrite_page_inside(
113
99
/*========================*/
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 */
 
100
                                /* out: TRUE if the location is inside
 
101
                                the two blocks of the doublewrite buffer */
 
102
        ulint   page_no);       /* in: page number */
 
103
/*******************************************************************
 
104
Checks if a page address is the trx sys header page. */
118
105
UNIV_INLINE
119
106
ibool
120
107
trx_sys_hdr_page(
121
108
/*=============*/
122
 
        ulint   space,  /*!< in: space */
123
 
        ulint   page_no);/*!< in: page number */
124
 
/*****************************************************************//**
 
109
                        /* out: TRUE if trx sys header page */
 
110
        ulint   space,  /* in: space */
 
111
        ulint   page_no);/* in: page number */
 
112
/*********************************************************************
125
113
Creates and initializes the central memory structures for the transaction
126
114
system. This is called when the database is started. */
127
115
UNIV_INTERN
128
116
void
129
117
trx_sys_init_at_db_start(void);
130
118
/*==========================*/
131
 
/*****************************************************************//**
 
119
/*********************************************************************
132
120
Creates and initializes the transaction system at the database creation. */
133
121
UNIV_INTERN
134
122
void
135
123
trx_sys_create(void);
136
124
/*================*/
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 */
 
125
/********************************************************************
 
126
Looks for a free slot for a rollback segment in the trx system file copy. */
140
127
UNIV_INTERN
141
128
ulint
142
129
trx_sysf_rseg_find_free(
143
130
/*====================*/
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 */
 
131
                                        /* out: slot index or ULINT_UNDEFINED
 
132
                                        if not found */
 
133
        mtr_t*          mtr);           /* in: mtr */
 
134
/*******************************************************************
 
135
Gets the pointer in the nth slot of the rseg array. */
148
136
UNIV_INLINE
149
137
trx_rseg_t*
150
138
trx_sys_get_nth_rseg(
151
139
/*=================*/
152
 
        trx_sys_t*      sys,    /*!< in: trx system */
153
 
        ulint           n);     /*!< in: index of slot */
154
 
/***************************************************************//**
 
140
                                /* out: pointer to rseg object, NULL if slot
 
141
                                not in use */
 
142
        trx_sys_t*      sys,    /* in: trx system */
 
143
        ulint           n);     /* in: index of slot */
 
144
/*******************************************************************
155
145
Sets the pointer in the nth slot of the rseg array. */
156
146
UNIV_INLINE
157
147
void
158
148
trx_sys_set_nth_rseg(
159
149
/*=================*/
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
 
150
        trx_sys_t*      sys,    /* in: trx system */
 
151
        ulint           n,      /* in: index of slot */
 
152
        trx_rseg_t*     rseg);  /* in: pointer to rseg object, NULL if slot
163
153
                                not in use */
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 */
 
154
/**************************************************************************
 
155
Gets a pointer to the transaction system file copy and x-locks its page. */
167
156
UNIV_INLINE
168
157
trx_sysf_t*
169
158
trx_sysf_get(
170
159
/*=========*/
171
 
        mtr_t*  mtr);   /*!< in: mtr */
172
 
/*****************************************************************//**
 
160
                        /* out: pointer to system file copy, page x-locked */
 
161
        mtr_t*  mtr);   /* in: mtr */
 
162
/*********************************************************************
173
163
Gets the space of the nth rollback segment slot in the trx system
174
 
file copy.
175
 
@return space id */
 
164
file copy. */
176
165
UNIV_INLINE
177
166
ulint
178
167
trx_sysf_rseg_get_space(
179
168
/*====================*/
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
 
/*****************************************************************//**
 
169
                                        /* out: space id */
 
170
        trx_sysf_t*     sys_header,     /* in: trx sys file copy */
 
171
        ulint           i,              /* in: slot index == rseg id */
 
172
        mtr_t*          mtr);           /* in: mtr */
 
173
/*********************************************************************
184
174
Gets the page number of the nth rollback segment slot in the trx system
185
 
file copy.
186
 
@return page number, FIL_NULL if slot unused */
 
175
file copy. */
187
176
UNIV_INLINE
188
177
ulint
189
178
trx_sysf_rseg_get_page_no(
190
179
/*======================*/
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
 
/*****************************************************************//**
 
180
                                        /* out: page number, FIL_NULL
 
181
                                        if slot unused */
 
182
        trx_sysf_t*     sys_header,     /* in: trx sys file copy */
 
183
        ulint           i,              /* in: slot index == rseg id */
 
184
        mtr_t*          mtr);           /* in: mtr */
 
185
/*********************************************************************
195
186
Sets the space id of the nth rollback segment slot in the trx system
196
187
file copy. */
197
188
UNIV_INLINE
198
189
void
199
190
trx_sysf_rseg_set_space(
200
191
/*====================*/
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
 
/*****************************************************************//**
 
192
        trx_sysf_t*     sys_header,     /* in: trx sys file copy */
 
193
        ulint           i,              /* in: slot index == rseg id */
 
194
        ulint           space,          /* in: space id */
 
195
        mtr_t*          mtr);           /* in: mtr */
 
196
/*********************************************************************
206
197
Sets the page number of the nth rollback segment slot in the trx system
207
198
file copy. */
208
199
UNIV_INLINE
209
200
void
210
201
trx_sysf_rseg_set_page_no(
211
202
/*======================*/
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
 
203
        trx_sysf_t*     sys_header,     /* in: trx sys file copy */
 
204
        ulint           i,              /* in: slot index == rseg id */
 
205
        ulint           page_no,        /* in: page number, FIL_NULL if
215
206
                                        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 */
 
207
        mtr_t*          mtr);           /* in: mtr */
 
208
/*********************************************************************
 
209
Allocates a new transaction id. */
220
210
UNIV_INLINE
221
 
trx_id_t
 
211
dulint
222
212
trx_sys_get_new_trx_id(void);
223
213
/*========================*/
224
 
/*****************************************************************//**
225
 
Allocates a new transaction number.
226
 
@return new, allocated trx number */
 
214
                        /* out: new, allocated trx id */
 
215
/*********************************************************************
 
216
Allocates a new transaction number. */
227
217
UNIV_INLINE
228
 
trx_id_t
 
218
dulint
229
219
trx_sys_get_new_trx_no(void);
230
220
/*========================*/
231
 
#endif /* !UNIV_HOTBACKUP */
232
 
/*****************************************************************//**
 
221
                        /* out: new, allocated trx number */
 
222
/*********************************************************************
233
223
Writes a trx id to an index page. In case that the id size changes in
234
224
some future version, this function should be used instead of
235
225
mach_write_... */
237
227
void
238
228
trx_write_trx_id(
239
229
/*=============*/
240
 
        byte*           ptr,    /*!< in: pointer to memory where written */
241
 
        trx_id_t        id);    /*!< in: id */
242
 
#ifndef UNIV_HOTBACKUP
243
 
/*****************************************************************//**
 
230
        byte*   ptr,    /* in: pointer to memory where written */
 
231
        dulint  id);    /* in: id */
 
232
/*********************************************************************
244
233
Reads a trx id from an index page. In case that the id size changes in
245
234
some future version, this function should be used instead of
246
 
mach_read_...
247
 
@return id */
 
235
mach_read_... */
248
236
UNIV_INLINE
249
 
trx_id_t
 
237
dulint
250
238
trx_read_trx_id(
251
239
/*============*/
252
 
        const byte*     ptr);   /*!< in: pointer to memory from where to read */
253
 
/****************************************************************//**
254
 
Looks for the trx handle with the given id in trx_list.
255
 
@return the trx handle or NULL if not found */
 
240
                                /* out: id */
 
241
        const byte*     ptr);   /* in: pointer to memory from where to read */
 
242
/********************************************************************
 
243
Looks for the trx handle with the given id in trx_list. */
256
244
UNIV_INLINE
257
245
trx_t*
258
246
trx_get_on_id(
259
247
/*==========*/
260
 
        trx_id_t        trx_id);/*!< in: trx id to search for */
261
 
/****************************************************************//**
 
248
                        /* out: the trx handle or NULL if not found */
 
249
        dulint  trx_id);        /* in: trx id to search for */
 
250
/********************************************************************
262
251
Returns the minumum trx id in trx list. This is the smallest id for which
263
252
the trx can possibly be active. (But, you must look at the trx->conc_state to
264
253
find out if the minimum trx id transaction itself is active, or already
265
 
committed.)
266
 
@return the minimum trx id, or trx_sys->max_trx_id if the trx list is empty */
 
254
committed.) */
267
255
UNIV_INLINE
268
 
trx_id_t
 
256
dulint
269
257
trx_list_get_min_trx_id(void);
270
258
/*=========================*/
271
 
/****************************************************************//**
272
 
Checks if a transaction with the given id is active.
273
 
@return TRUE if active */
 
259
                        /* out: the minimum trx id, or trx_sys->max_trx_id
 
260
                        if the trx list is empty */
 
261
/********************************************************************
 
262
Checks if a transaction with the given id is active. */
274
263
UNIV_INLINE
275
264
ibool
276
265
trx_is_active(
277
266
/*==========*/
278
 
        trx_id_t        trx_id);/*!< in: trx id of the transaction */
279
 
/****************************************************************//**
280
 
Checks that trx is in the trx list.
281
 
@return TRUE if is in */
 
267
                        /* out: TRUE if active */
 
268
        dulint  trx_id);/* in: trx id of the transaction */
 
269
/********************************************************************
 
270
Checks that trx is in the trx list. */
282
271
UNIV_INTERN
283
272
ibool
284
273
trx_in_trx_list(
285
274
/*============*/
286
 
        trx_t*  in_trx);/*!< in: trx */
287
 
/*****************************************************************//**
 
275
                        /* out: TRUE if is in */
 
276
        trx_t*  in_trx);/* in: trx */
 
277
/*********************************************************************
288
278
Updates the offset information about the end of the MySQL binlog entry
289
279
which corresponds to the transaction just being committed. In a MySQL
290
280
replication slave updates the latest master binlog position up to which
293
283
void
294
284
trx_sys_update_mysql_binlog_offset(
295
285
/*===============================*/
296
 
        const char*     file_name,/*!< in: MySQL log file name */
297
 
        ib_int64_t      offset, /*!< in: position in that log file */
298
 
        ulint           field,  /*!< in: offset of the MySQL log info field in
 
286
        const char*     file_name,/* in: MySQL log file name */
 
287
        ib_int64_t      offset, /* in: position in that log file */
 
288
        ulint           field,  /* in: offset of the MySQL log info field in
299
289
                                the trx sys header */
300
 
        mtr_t*          mtr);   /*!< in: mtr */
301
 
/*****************************************************************//**
 
290
        mtr_t*          mtr);   /* in: mtr */
 
291
/*********************************************************************
302
292
Prints to stderr the MySQL binlog offset info in the trx system header if
303
293
the magic number shows it valid. */
304
294
UNIV_INTERN
305
295
void
306
296
trx_sys_print_mysql_binlog_offset(void);
307
297
/*===================================*/
308
 
/*****************************************************************//**
 
298
#ifdef UNIV_HOTBACKUP
 
299
/*********************************************************************
 
300
Prints to stderr the MySQL binlog info in the system header if the
 
301
magic number shows it valid. */
 
302
UNIV_INTERN
 
303
void
 
304
trx_sys_print_mysql_binlog_offset_from_page(
 
305
/*========================================*/
 
306
        const byte*     page);  /* in: buffer containing the trx
 
307
                                system header page, i.e., page number
 
308
                                TRX_SYS_PAGE_NO in the tablespace */
 
309
#endif /* UNIV_HOTBACKUP */
 
310
/*********************************************************************
309
311
Prints to stderr the MySQL master log offset info in the trx system header if
310
312
the magic number shows it valid. */
311
313
UNIV_INTERN
312
314
void
313
315
trx_sys_print_mysql_master_log_pos(void);
314
316
/*====================================*/
315
 
/*****************************************************************//**
 
317
/*********************************************************************
316
318
Initializes the tablespace tag system. */
317
319
UNIV_INTERN
318
320
void
319
321
trx_sys_file_format_init(void);
320
322
/*==========================*/
321
 
/*****************************************************************//**
 
323
/*********************************************************************
322
324
Closes the tablespace tag system. */
323
325
UNIV_INTERN
324
326
void
325
327
trx_sys_file_format_close(void);
326
328
/*===========================*/
327
 
/********************************************************************//**
 
329
/************************************************************************
328
330
Tags the system table space with minimum format id if it has not been
329
331
tagged yet.
330
332
WARNING: This function is only called during the startup and AFTER the
333
335
void
334
336
trx_sys_file_format_tag_init(void);
335
337
/*==============================*/
336
 
#ifndef UNIV_HOTBACKUP
337
 
/*****************************************************************//**
338
 
Shutdown/Close the transaction system. */
339
 
UNIV_INTERN
340
 
void
341
 
trx_sys_close(void);
342
 
/*===============*/
343
 
#endif /* !UNIV_HOTBACKUP */
344
 
/*****************************************************************//**
345
 
Get the name representation of the file format from its id.
346
 
@return pointer to the name */
 
338
/*********************************************************************
 
339
Get the name representation of the file format from its id. */
347
340
UNIV_INTERN
348
341
const char*
349
342
trx_sys_file_format_id_to_name(
350
343
/*===========================*/
351
 
        const ulint     id);            /*!< in: id of the file format */
352
 
/*****************************************************************//**
 
344
                                        /* out: pointer to the name */
 
345
        const ulint     id);            /* in: id of the file format */
 
346
/*********************************************************************
353
347
Set the file format id unconditionally except if it's already the
354
 
same value.
355
 
@return TRUE if value updated */
 
348
same value. */
356
349
UNIV_INTERN
357
350
ibool
358
351
trx_sys_file_format_max_set(
359
352
/*========================*/
360
 
        ulint           format_id,      /*!< in: file format id */
361
 
        const char**    name);          /*!< out: max file format name or
 
353
                                        /* out: TRUE if value updated */
 
354
        ulint           format_id,      /* in: file format id */
 
355
        const char**    name);          /* out: max file format name or
362
356
                                        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 */
 
357
/*********************************************************************
 
358
Get the name representation of the file format from its id. */
366
359
UNIV_INTERN
367
360
const char*
368
361
trx_sys_file_format_max_get(void);
369
362
/*=============================*/
370
 
/*****************************************************************//**
371
 
Check for the max file format tag stored on disk.
372
 
@return DB_SUCCESS or error code */
 
363
                                /* out: pointer to the max format name */
 
364
/*********************************************************************
 
365
Check for the max file format tag stored on disk. */
373
366
UNIV_INTERN
374
367
ulint
375
368
trx_sys_file_format_max_check(
376
369
/*==========================*/
377
 
        ulint           max_format_id); /*!< in: the max format id to check */
378
 
/********************************************************************//**
 
370
                                        /* out: DB_SUCCESS or error code */
 
371
        ulint           max_format_id); /* in: the max format id to check */
 
372
/************************************************************************
379
373
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 */
 
374
format id is greater than the known max id. */
382
375
UNIV_INTERN
383
376
ibool
384
377
trx_sys_file_format_max_upgrade(
385
378
/*============================*/
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. */
392
 
UNIV_INTERN
393
 
void
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
403
 
in the data file.
404
 
@return TRUE if call succeeds */
405
 
UNIV_INTERN
406
 
ibool
407
 
trx_sys_read_file_format_id(
408
 
/*========================*/
409
 
        const char *pathname,   /*!< in: pathname of the first system
410
 
                                table space file */
411
 
        ulint *format_id);      /*!< out: file format of the system table
412
 
                                space */
413
 
/*****************************************************************//**
414
 
Reads the file format id from the given per-table data file.
415
 
@return TRUE if call succeeds */
416
 
UNIV_INTERN
417
 
ibool
418
 
trx_sys_read_pertable_file_format_id(
419
 
/*=================================*/
420
 
        const char *pathname,   /*!< in: pathname of a per-table
421
 
                                datafile */
422
 
        ulint *format_id);      /*!< out: file format of the per-table
423
 
                                data file */
424
 
/*****************************************************************//**
425
 
Get the name representation of the file format from its id.
426
 
@return pointer to the name */
427
 
UNIV_INTERN
428
 
const char*
429
 
trx_sys_file_format_id_to_name(
430
 
/*===========================*/
431
 
        const ulint     id);    /*!< in: id of the file format */
432
 
 
433
 
#endif /* !UNIV_HOTBACKUP */
434
 
/*********************************************************************
435
 
Creates the rollback segments */
436
 
UNIV_INTERN
437
 
void
438
 
trx_sys_create_rsegs(
439
 
/*=================*/
440
 
        ulint   n_rsegs);       /*!< number of rollback segments to create */
441
 
 
 
379
                                        /* out: TRUE if format_id was
 
380
                                        bigger than the known max id */
 
381
        const char**    name,           /* out: max file format name */
 
382
        ulint           format_id);     /* in: file format identifier */
442
383
/* The automatically created system rollback segment has this id */
443
384
#define TRX_SYS_SYSTEM_RSEG_ID  0
444
385
 
445
386
/* Space id and page no where the trx system file copy resides */
446
387
#define TRX_SYS_SPACE   0       /* the SYSTEM tablespace */
447
 
#include "fsp0fsp.h"
448
388
#define TRX_SYS_PAGE_NO FSP_TRX_SYS_PAGE_NO
449
389
 
450
390
/* The offset of the transaction system header on the page */
451
391
#define TRX_SYS         FSEG_PAGE_DATA
452
392
 
453
 
/** Transaction system header */
454
 
/*------------------------------------------------------------- @{ */
455
 
#define TRX_SYS_TRX_ID_STORE    0       /*!< the maximum trx id or trx
456
 
                                        number modulo
457
 
                                        TRX_SYS_TRX_ID_UPDATE_MARGIN
 
393
/* Transaction system header */
 
394
/*-------------------------------------------------------------*/
 
395
#define TRX_SYS_TRX_ID_STORE    0       /* the maximum trx id or trx number
 
396
                                        modulo TRX_SYS_TRX_ID_UPDATE_MARGIN
458
397
                                        written to a file page by any
459
398
                                        transaction; the assignment of
460
 
                                        transaction ids continues from
461
 
                                        this number rounded up by
462
 
                                        TRX_SYS_TRX_ID_UPDATE_MARGIN
463
 
                                        plus
464
 
                                        TRX_SYS_TRX_ID_UPDATE_MARGIN
465
 
                                        when the database is
 
399
                                        transaction ids continues from this
 
400
                                        number rounded up by .._MARGIN plus
 
401
                                        .._MARGIN when the database is
466
402
                                        started */
467
 
#define TRX_SYS_FSEG_HEADER     8       /*!< segment header for the
468
 
                                        tablespace segment the trx
469
 
                                        system is created into */
 
403
#define TRX_SYS_FSEG_HEADER     8       /* segment header for the tablespace
 
404
                                        segment the trx system is created
 
405
                                        into */
470
406
#define TRX_SYS_RSEGS           (8 + FSEG_HEADER_SIZE)
471
 
                                        /*!< the start of the array of
472
 
                                        rollback segment specification
473
 
                                        slots */
474
 
/*------------------------------------------------------------- @} */
 
407
                                        /* the start of the array of rollback
 
408
                                        segment specification slots */
 
409
/*-------------------------------------------------------------*/
475
410
 
476
411
/* 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
 
412
in the transaction system array; rollback segment id must fit in one byte,
 
413
therefore 256; each slot is currently 8 bytes in size */
 
414
#define TRX_SYS_N_RSEGS         256
486
415
 
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
416
#define TRX_SYS_MYSQL_LOG_NAME_LEN      512
491
 
/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
492
417
#define TRX_SYS_MYSQL_LOG_MAGIC_N       873422344
493
418
 
494
419
#if UNIV_PAGE_SIZE < 4096
495
420
# error "UNIV_PAGE_SIZE < 4096"
496
421
#endif
497
 
/** The offset of the MySQL replication info in the trx system header;
 
422
/* The offset of the MySQL replication info in the trx system header;
498
423
this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
499
424
#define TRX_SYS_MYSQL_MASTER_LOG_INFO   (UNIV_PAGE_SIZE - 2000)
500
425
 
501
 
/** The offset of the MySQL binlog offset info in the trx system header */
 
426
/* The offset of the MySQL binlog offset info in the trx system header */
502
427
#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
 
428
#define TRX_SYS_MYSQL_LOG_MAGIC_N_FLD   0       /* magic number which shows
505
429
                                                if we have valid data in the
506
 
                                                MySQL binlog info */
507
 
#define TRX_SYS_MYSQL_LOG_OFFSET_HIGH   4       /*!< high 4 bytes of the offset
508
 
                                                within that file */
509
 
#define TRX_SYS_MYSQL_LOG_OFFSET_LOW    8       /*!< low 4 bytes of the offset
510
 
                                                within that file */
511
 
#define TRX_SYS_MYSQL_LOG_NAME          12      /*!< MySQL log file name */
 
430
                                                MySQL binlog info; the value
 
431
                                                is ..._MAGIC_N if yes */
 
432
#define TRX_SYS_MYSQL_LOG_OFFSET_HIGH   4       /* high 4 bytes of the offset
 
433
                                                within that file */
 
434
#define TRX_SYS_MYSQL_LOG_OFFSET_LOW    8       /* low 4 bytes of the offset
 
435
                                                within that file */
 
436
#define TRX_SYS_MYSQL_LOG_NAME          12      /* MySQL log file name */
512
437
 
513
 
/** Doublewrite buffer */
514
 
/* @{ */
515
 
/** The offset of the doublewrite buffer header on the trx system header page */
 
438
/* The offset of the doublewrite buffer header on the trx system header page */
516
439
#define TRX_SYS_DOUBLEWRITE             (UNIV_PAGE_SIZE - 200)
517
440
/*-------------------------------------------------------------*/
518
 
#define TRX_SYS_DOUBLEWRITE_FSEG        0       /*!< fseg header of the fseg
 
441
#define TRX_SYS_DOUBLEWRITE_FSEG        0       /* fseg header of the fseg
519
442
                                                containing the doublewrite
520
443
                                                buffer */
521
444
#define TRX_SYS_DOUBLEWRITE_MAGIC       FSEG_HEADER_SIZE
522
 
                                                /*!< 4-byte magic number which
 
445
                                                /* 4-byte magic number which
523
446
                                                shows if we already have
524
447
                                                created the doublewrite
525
448
                                                buffer */
526
449
#define TRX_SYS_DOUBLEWRITE_BLOCK1      (4 + FSEG_HEADER_SIZE)
527
 
                                                /*!< page number of the
 
450
                                                /* page number of the
528
451
                                                first page in the first
529
452
                                                sequence of 64
530
453
                                                (= FSP_EXTENT_SIZE) consecutive
531
454
                                                pages in the doublewrite
532
455
                                                buffer */
533
456
#define TRX_SYS_DOUBLEWRITE_BLOCK2      (8 + FSEG_HEADER_SIZE)
534
 
                                                /*!< page number of the
 
457
                                                /* page number of the
535
458
                                                first page in the second
536
459
                                                sequence of 64 consecutive
537
460
                                                pages in the doublewrite
538
461
                                                buffer */
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
547
 
                                                information */
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. */
 
462
#define TRX_SYS_DOUBLEWRITE_REPEAT      12      /* we repeat the above 3
 
463
                                                numbers so that if the trx
 
464
                                                sys header is half-written
 
465
                                                to disk, we still may be able
 
466
                                                to recover the information */
552
467
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED (24 + FSEG_HEADER_SIZE)
553
 
 
 
468
                                                /* If this is not yet set to
 
469
                                                .._N, we must reset the
 
470
                                                doublewrite buffer, because
 
471
                                                starting from 4.1.x the space
 
472
                                                id of a data page is stored to
 
473
                                        FIL_PAGE_ARCH_LOG_NO_OR_SPACE_NO */
554
474
/*-------------------------------------------------------------*/
555
 
/** Contents of TRX_SYS_DOUBLEWRITE_MAGIC */
556
475
#define TRX_SYS_DOUBLEWRITE_MAGIC_N     536853855
557
 
/** Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED */
558
476
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N 1783657386
559
477
 
560
 
/** Size of the doublewrite block in pages */
 
478
 
561
479
#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE  FSP_EXTENT_SIZE
562
 
/* @} */
563
480
 
564
 
#ifndef UNIV_HOTBACKUP
565
 
/** File format tag */
566
 
/* @{ */
567
 
/** The offset of the file format tag on the trx system header page
568
 
(TRX_SYS_PAGE_NO of TRX_SYS_SPACE) */
 
481
/* The offset of the file format tag on the trx system header page */
569
482
#define TRX_SYS_FILE_FORMAT_TAG         (UNIV_PAGE_SIZE - 16)
570
483
 
571
 
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
572
 
identifier is added to this constant. */
 
484
/* We use these random constants to reduce the probability of reading
 
485
garbage (from previous versions) that maps to an actual format id. We
 
486
use these as bit masks at the time of  reading and writing from/to disk. */
573
487
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW     3645922177UL
574
 
/** Contents of TRX_SYS_FILE_FORMAT_TAG+4 when valid */
575
488
#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)
581
 
/* @} */
582
489
 
583
 
/** Doublewrite control struct */
 
490
/* Doublewrite control struct */
584
491
struct trx_doublewrite_struct{
585
 
        mutex_t mutex;          /*!< mutex protecting the first_free field and
 
492
        mutex_t mutex;          /* mutex protecting the first_free field and
586
493
                                write_buf */
587
 
        ulint   block1;         /*!< the page number of the first
 
494
        ulint   block1;         /* the page number of the first
588
495
                                doublewrite block (64 pages) */
589
 
        ulint   block2;         /*!< page number of the second block */
590
 
        ulint   first_free;     /*!< first free position in write_buf measured
 
496
        ulint   block2;         /* page number of the second block */
 
497
        ulint   first_free;     /* first free position in write_buf measured
591
498
                                in units of UNIV_PAGE_SIZE */
592
 
        byte*   write_buf;      /*!< write buffer used in writing to the
 
499
        byte*   write_buf;      /* write buffer used in writing to the
593
500
                                doublewrite buffer, aligned to an
594
501
                                address divisible by UNIV_PAGE_SIZE
595
502
                                (which is required by Windows aio) */
596
 
        byte*   write_buf_unaligned;
597
 
                                /*!< pointer to write_buf, but unaligned */
 
503
        byte*   write_buf_unaligned; /* pointer to write_buf, but unaligned */
598
504
        buf_page_t**
599
 
                buf_block_arr;  /*!< array to store pointers to the buffer
 
505
                buf_block_arr;  /* array to store pointers to the buffer
600
506
                                blocks which have been cached to write_buf */
601
507
};
602
508
 
603
 
/** The transaction system central memory data structure; protected by the
 
509
/* The transaction system central memory data structure; protected by the
604
510
kernel mutex */
605
511
struct trx_sys_struct{
606
 
        trx_id_t        max_trx_id;     /*!< The smallest number not yet
 
512
        dulint          max_trx_id;     /* The smallest number not yet
607
513
                                        assigned as a transaction id or
608
514
                                        transaction number */
609
515
        UT_LIST_BASE_NODE_T(trx_t) trx_list;
610
 
                                        /*!< List of active and committed in
 
516
                                        /* List of active and committed in
611
517
                                        memory transactions, sorted on trx id,
612
518
                                        biggest first */
613
519
        UT_LIST_BASE_NODE_T(trx_t) mysql_trx_list;
614
 
                                        /*!< List of transactions created
 
520
                                        /* List of transactions created
615
521
                                        for MySQL */
616
522
        UT_LIST_BASE_NODE_T(trx_rseg_t) rseg_list;
617
 
                                        /*!< List of rollback segment
618
 
                                        objects */
619
 
        trx_rseg_t*     latest_rseg;    /*!< Latest rollback segment in the
 
523
                                        /* List of rollback segment objects */
 
524
        trx_rseg_t*     latest_rseg;    /* Latest rollback segment in the
620
525
                                        round-robin assignment of rollback
621
526
                                        segments to transactions */
622
527
        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
 
528
                                        /* Pointer array to rollback segments;
 
529
                                        NULL if slot not in use */
 
530
        ulint           rseg_history_len;/* Length of the TRX_RSEG_HISTORY
626
531
                                        list (update undo logs for committed
627
532
                                        transactions), protected by
628
533
                                        rseg->mutex */
629
534
        UT_LIST_BASE_NODE_T(read_view_t) view_list;
630
 
                                        /*!< List of read views sorted
631
 
                                        on trx no, biggest first */
 
535
                                        /* List of read views sorted on trx no,
 
536
                                        biggest first */
632
537
};
633
538
 
634
 
/** When a trx id which is zero modulo this number (which must be a power of
 
539
/* When a trx id which is zero modulo this number (which must be a power of
635
540
two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system
636
541
page is updated */
637
542
#define TRX_SYS_TRX_ID_WRITE_MARGIN     256
638
 
#endif /* !UNIV_HOTBACKUP */
639
543
 
640
544
#ifndef UNIV_NONINL
641
545
#include "trx0sys.ic"