~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
3
Copyright (c) 1996, 2010, Innobase Oy. All Rights Reserved.
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
4
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
8
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13
You should have received a copy of the GNU General Public License along with
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
16
17
*****************************************************************************/
18
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
19
/**************************************************//**
20
@file include/trx0sys.h
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
21
Transaction system
22
23
Created 3/26/1996 Heikki Tuuri
24
*******************************************************/
25
26
#ifndef trx0sys_h
27
#define trx0sys_h
28
29
#include "univ.i"
30
31
#include "trx0types.h"
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
32
#include "fsp0types.h"
33
#include "fil0fil.h"
34
#include "buf0buf.h"
35
#ifndef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
36
#include "mtr0mtr.h"
37
#include "ut0byte.h"
38
#include "mem0mem.h"
39
#include "sync0sync.h"
40
#include "ut0lst.h"
41
#include "read0types.h"
42
#include "page0types.h"
43
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
48
extern char		trx_sys_mysql_master_log_name[];
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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.*/
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
52
extern ib_int64_t	trx_sys_mysql_master_log_pos;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
53
/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
54
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
55
/** If this MySQL server uses binary logging, after InnoDB has been inited
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
56
and if it has done a crash recovery, we store the binlog file name and position
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
57
here. */
58
/* @{ */
59
/** Binlog file name */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
60
extern char		trx_sys_mysql_bin_log_name[];
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
61
/** Binlog file position, or -1 if unknown */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
62
extern ib_int64_t	trx_sys_mysql_bin_log_pos;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
63
/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
64
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
65
/** The transaction system */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
66
extern trx_sys_t*	trx_sys;
67
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
68
/** Doublewrite system */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
69
extern trx_doublewrite_t*	trx_doublewrite;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
72
extern ibool			trx_doublewrite_must_reset_space_ids;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
78
extern ibool			trx_sys_multiple_tablespace_format;
79
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
80
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
81
Creates the doublewrite buffer to a new InnoDB installation. The header of the
82
doublewrite buffer is placed on the trx system header page. */
83
UNIV_INTERN
84
void
85
trx_sys_create_doublewrite_buf(void);
86
/*================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
87
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
88
At a database startup initializes the doublewrite buffer memory structure if
89
we already have a doublewrite buffer created in the data files. If we are
90
upgrading to an InnoDB version which supports multiple tablespaces, then this
91
function performs the necessary update operations. If we are in a crash
92
recovery, this function uses a possible doublewrite buffer to restore
93
half-written pages in the data files. */
94
UNIV_INTERN
95
void
96
trx_sys_doublewrite_init_or_restore_pages(
97
/*======================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
98
	ibool	restore_corrupt_pages);	/*!< in: TRUE=restore pages */
99
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
100
Marks the trx sys header when we have successfully upgraded to the >= 4.1.x
101
multiple tablespace format. */
102
UNIV_INTERN
103
void
104
trx_sys_mark_upgraded_to_multiple_tablespaces(void);
105
/*===============================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
110
UNIV_INTERN
111
ibool
112
trx_doublewrite_page_inside(
113
/*========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
118
UNIV_INLINE
119
ibool
120
trx_sys_hdr_page(
121
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
122
	ulint	space,	/*!< in: space */
123
	ulint	page_no);/*!< in: page number */
124
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
125
Creates and initializes the central memory structures for the transaction
126
system. This is called when the database is started. */
127
UNIV_INTERN
128
void
129
trx_sys_init_at_db_start(void);
130
/*==========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
131
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
132
Creates and initializes the transaction system at the database creation. */
133
UNIV_INTERN
134
void
135
trx_sys_create(void);
136
/*================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
140
UNIV_INTERN
141
ulint
142
trx_sysf_rseg_find_free(
143
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
148
UNIV_INLINE
149
trx_rseg_t*
150
trx_sys_get_nth_rseg(
151
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
152
	trx_sys_t*	sys,	/*!< in: trx system */
153
	ulint		n);	/*!< in: index of slot */
154
/***************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
155
Sets the pointer in the nth slot of the rseg array. */
156
UNIV_INLINE
157
void
158
trx_sys_set_nth_rseg(
159
/*=================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
163
				not in use */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
167
UNIV_INLINE
168
trx_sysf_t*
169
trx_sysf_get(
170
/*=========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
171
	mtr_t*	mtr);	/*!< in: mtr */
172
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
173
Gets the space of the nth rollback segment slot in the trx system
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
174
file copy.
175
@return	space id */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
176
UNIV_INLINE
177
ulint
178
trx_sysf_rseg_get_space(
179
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
184
Gets the page number of the nth rollback segment slot in the trx system
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
185
file copy.
186
@return	page number, FIL_NULL if slot unused */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
187
UNIV_INLINE
188
ulint
189
trx_sysf_rseg_get_page_no(
190
/*======================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
195
Sets the space id of the nth rollback segment slot in the trx system
196
file copy. */
197
UNIV_INLINE
198
void
199
trx_sysf_rseg_set_space(
200
/*====================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
206
Sets the page number of the nth rollback segment slot in the trx system
207
file copy. */
208
UNIV_INLINE
209
void
210
trx_sysf_rseg_set_page_no(
211
/*======================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
215
					the slot is reset to unused */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
216
	mtr_t*		mtr);		/*!< in: mtr */
217
/*****************************************************************//**
218
Allocates a new transaction id.
219
@return	new, allocated trx id */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
220
UNIV_INLINE
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
221
trx_id_t
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
222
trx_sys_get_new_trx_id(void);
223
/*========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
224
/*****************************************************************//**
225
Allocates a new transaction number.
226
@return	new, allocated trx number */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
227
UNIV_INLINE
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
228
trx_id_t
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
229
trx_sys_get_new_trx_no(void);
230
/*========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
231
#endif /* !UNIV_HOTBACKUP */
232
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
233
Writes a trx id to an index page. In case that the id size changes in
234
some future version, this function should be used instead of
235
mach_write_... */
236
UNIV_INLINE
237
void
238
trx_write_trx_id(
239
/*=============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
240
	byte*		ptr,	/*!< in: pointer to memory where written */
241
	trx_id_t	id);	/*!< in: id */
242
#ifndef UNIV_HOTBACKUP
243
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
244
Reads a trx id from an index page. In case that the id size changes in
245
some future version, this function should be used instead of
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
246
mach_read_...
247
@return	id */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
248
UNIV_INLINE
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
249
trx_id_t
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
250
trx_read_trx_id(
251
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
256
UNIV_INLINE
257
trx_t*
258
trx_get_on_id(
259
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
260
	trx_id_t	trx_id);/*!< in: trx id to search for */
261
/****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
262
Returns the minumum trx id in trx list. This is the smallest id for which
263
the trx can possibly be active. (But, you must look at the trx->conc_state to
264
find out if the minimum trx id transaction itself is active, or already
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
265
committed.)
266
@return	the minimum trx id, or trx_sys->max_trx_id if the trx list is empty */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
267
UNIV_INLINE
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
268
trx_id_t
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
269
trx_list_get_min_trx_id(void);
270
/*=========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
271
/****************************************************************//**
272
Checks if a transaction with the given id is active.
273
@return	TRUE if active */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
274
UNIV_INLINE
275
ibool
276
trx_is_active(
277
/*==========*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
282
UNIV_INTERN
283
ibool
284
trx_in_trx_list(
285
/*============*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
286
	trx_t*	in_trx);/*!< in: trx */
287
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
288
Updates the offset information about the end of the MySQL binlog entry
289
which corresponds to the transaction just being committed. In a MySQL
290
replication slave updates the latest master binlog position up to which
291
replication has proceeded. */
292
UNIV_INTERN
293
void
294
trx_sys_update_mysql_binlog_offset(
295
/*===============================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
299
				the trx sys header */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
300
	mtr_t*		mtr);	/*!< in: mtr */
301
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
302
Prints to stderr the MySQL binlog offset info in the trx system header if
303
the magic number shows it valid. */
304
UNIV_INTERN
305
void
306
trx_sys_print_mysql_binlog_offset(void);
307
/*===================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
308
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
309
Prints to stderr the MySQL master log offset info in the trx system header if
310
the magic number shows it valid. */
311
UNIV_INTERN
312
void
313
trx_sys_print_mysql_master_log_pos(void);
314
/*====================================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
315
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
316
Initializes the tablespace tag system. */
317
UNIV_INTERN
318
void
319
trx_sys_file_format_init(void);
320
/*==========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
321
/*****************************************************************//**
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
322
Closes the tablespace tag system. */
323
UNIV_INTERN
324
void
325
trx_sys_file_format_close(void);
326
/*===========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
327
/********************************************************************//**
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
328
Tags the system table space with minimum format id if it has not been
329
tagged yet.
330
WARNING: This function is only called during the startup and AFTER the
331
redo log application during recovery has finished. */
332
UNIV_INTERN
333
void
334
trx_sys_file_format_tag_init(void);
335
/*==============================*/
1819.5.149 by pekka
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6275 from MySQL InnoDB
336
#ifndef UNIV_HOTBACKUP
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
337
/*****************************************************************//**
1819.5.106 by stewart at flamingspork
[patch 106/129] Merge patch for revision 1915 from InnoDB SVN:
338
Shutdown/Close the transaction system. */
339
UNIV_INTERN
340
void
341
trx_sys_close(void);
342
/*===============*/
1819.5.149 by pekka
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6275 from MySQL InnoDB
343
#endif /* !UNIV_HOTBACKUP */
1819.5.106 by stewart at flamingspork
[patch 106/129] Merge patch for revision 1915 from InnoDB SVN:
344
/*****************************************************************//**
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
345
Get the name representation of the file format from its id.
346
@return	pointer to the name */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
347
UNIV_INTERN
348
const char*
349
trx_sys_file_format_id_to_name(
350
/*===========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
351
	const ulint	id);		/*!< in: id of the file format */
352
/*****************************************************************//**
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
353
Set the file format id unconditionally except if it's already the
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
354
same value.
355
@return	TRUE if value updated */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
356
UNIV_INTERN
357
ibool
358
trx_sys_file_format_max_set(
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
359
/*========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
360
	ulint		format_id,	/*!< in: file format id */
361
	const char**	name);		/*!< out: max file format name or
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
362
					NULL if not needed. */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
363
/*****************************************************************//**
364
Get the name representation of the file format from its id.
365
@return	pointer to the max format name */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
366
UNIV_INTERN
367
const char*
368
trx_sys_file_format_max_get(void);
369
/*=============================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
370
/*****************************************************************//**
371
Check for the max file format tag stored on disk.
372
@return	DB_SUCCESS or error code */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
373
UNIV_INTERN
374
ulint
375
trx_sys_file_format_max_check(
376
/*==========================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
377
	ulint		max_format_id);	/*!< in: the max format id to check */
378
/********************************************************************//**
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
379
Update the file format tag in the system tablespace only if the given
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
380
format id is greater than the known max id.
381
@return	TRUE if format_id was bigger than the known max id */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
382
UNIV_INTERN
383
ibool
641.2.1 by Monty Taylor
InnoDB Plugin 1.0.2
384
trx_sys_file_format_max_upgrade(
385
/*============================*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
442
/* The automatically created system rollback segment has this id */
443
#define TRX_SYS_SYSTEM_RSEG_ID	0
444
445
/* Space id and page no where the trx system file copy resides */
446
#define	TRX_SYS_SPACE	0	/* the SYSTEM tablespace */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
447
#include "fsp0fsp.h"
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
448
#define	TRX_SYS_PAGE_NO	FSP_TRX_SYS_PAGE_NO
449
450
/* The offset of the transaction system header on the page */
451
#define	TRX_SYS		FSEG_PAGE_DATA
452
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
458
					written to a file page by any
459
					transaction; the assignment of
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
466
					started */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
467
#define TRX_SYS_FSEG_HEADER	8	/*!< segment header for the
468
					tablespace segment the trx
469
					system is created into */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
470
#define	TRX_SYS_RSEGS		(8 + FSEG_HEADER_SIZE)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
471
					/*!< the start of the array of
472
					rollback segment specification
473
					slots */
474
/*------------------------------------------------------------- @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
475
1819.7.68 by Stewart Smith
Merge initial InnoDB+ import.
476
/* 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
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
486
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
490
#define TRX_SYS_MYSQL_LOG_NAME_LEN	512
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
491
/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
492
#define TRX_SYS_MYSQL_LOG_MAGIC_N	873422344
493
494
#if UNIV_PAGE_SIZE < 4096
495
# error "UNIV_PAGE_SIZE < 4096"
496
#endif
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
497
/** The offset of the MySQL replication info in the trx system header;
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
498
this contains the same fields as TRX_SYS_MYSQL_LOG_INFO below */
499
#define TRX_SYS_MYSQL_MASTER_LOG_INFO	(UNIV_PAGE_SIZE - 2000)
500
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
501
/** The offset of the MySQL binlog offset info in the trx system header */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
502
#define TRX_SYS_MYSQL_LOG_INFO		(UNIV_PAGE_SIZE - 1000)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
503
#define	TRX_SYS_MYSQL_LOG_MAGIC_N_FLD	0	/*!< magic number which is
504
						TRX_SYS_MYSQL_LOG_MAGIC_N
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
505
						if we have valid data in the
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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 */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
512
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
513
/** Doublewrite buffer */
514
/* @{ */
515
/** The offset of the doublewrite buffer header on the trx system header page */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
516
#define TRX_SYS_DOUBLEWRITE		(UNIV_PAGE_SIZE - 200)
517
/*-------------------------------------------------------------*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
518
#define TRX_SYS_DOUBLEWRITE_FSEG	0	/*!< fseg header of the fseg
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
519
						containing the doublewrite
520
						buffer */
521
#define TRX_SYS_DOUBLEWRITE_MAGIC	FSEG_HEADER_SIZE
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
522
						/*!< 4-byte magic number which
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
523
						shows if we already have
524
						created the doublewrite
525
						buffer */
526
#define TRX_SYS_DOUBLEWRITE_BLOCK1	(4 + FSEG_HEADER_SIZE)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
527
						/*!< page number of the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
528
						first page in the first
529
						sequence of 64
530
						(= FSP_EXTENT_SIZE) consecutive
531
						pages in the doublewrite
532
						buffer */
533
#define TRX_SYS_DOUBLEWRITE_BLOCK2	(8 + FSEG_HEADER_SIZE)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
534
						/*!< page number of the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
535
						first page in the second
536
						sequence of 64 consecutive
537
						pages in the doublewrite
538
						buffer */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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. */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
552
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED (24 + FSEG_HEADER_SIZE)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
553
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
554
/*-------------------------------------------------------------*/
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
555
/** Contents of TRX_SYS_DOUBLEWRITE_MAGIC */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
556
#define TRX_SYS_DOUBLEWRITE_MAGIC_N	536853855
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
557
/** Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
558
#define TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N 1783657386
559
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
560
/** Size of the doublewrite block in pages */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
561
#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE	FSP_EXTENT_SIZE
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
562
/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
563
1819.5.149 by pekka
Merge Revision revid:svn-v4:16c675df-0fcb-4bc9-8058-dcc011a37293:branches/zip:6275 from MySQL InnoDB
564
#ifndef UNIV_HOTBACKUP
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
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) */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
569
#define TRX_SYS_FILE_FORMAT_TAG		(UNIV_PAGE_SIZE - 16)
570
1819.9.34 by Marko Mäkelä
Merge Revision revid:marko.makela@oracle.com-20100624060929-z7dj4btnkyhqm229 from MySQL InnoDB
571
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
572
identifier is added to this constant. */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
573
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW	3645922177UL
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
574
/** Contents of TRX_SYS_FILE_FORMAT_TAG+4 when valid */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
575
#define TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_HIGH	2745987765UL
1819.9.34 by Marko Mäkelä
Merge Revision revid:marko.makela@oracle.com-20100624060929-z7dj4btnkyhqm229 from MySQL InnoDB
576
/** Contents of TRX_SYS_FILE_FORMAT_TAG when valid. The file format
1819.9.31 by Marko Mäkelä, Stewart Smith
Merge Revision revid:marko.makela@oracle.com-20100623110659-pk5bqnmo0j7hj6md from MySQL InnoDB
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)
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
581
/* @} */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
582
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
583
/** Doublewrite control struct */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
584
struct trx_doublewrite_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
585
	mutex_t	mutex;		/*!< mutex protecting the first_free field and
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
586
				write_buf */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
587
	ulint	block1;		/*!< the page number of the first
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
588
				doublewrite block (64 pages) */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
589
	ulint	block2;		/*!< page number of the second block */
590
	ulint	first_free;	/*!< first free position in write_buf measured
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
591
				in units of UNIV_PAGE_SIZE */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
592
	byte*	write_buf;	/*!< write buffer used in writing to the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
593
				doublewrite buffer, aligned to an
594
				address divisible by UNIV_PAGE_SIZE
595
				(which is required by Windows aio) */
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
596
	byte*	write_buf_unaligned;
597
				/*!< pointer to write_buf, but unaligned */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
598
	buf_page_t**
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
599
		buf_block_arr;	/*!< array to store pointers to the buffer
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
600
				blocks which have been cached to write_buf */
601
};
602
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
603
/** The transaction system central memory data structure; protected by the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
604
kernel mutex */
605
struct trx_sys_struct{
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
606
	trx_id_t	max_trx_id;	/*!< The smallest number not yet
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
607
					assigned as a transaction id or
608
					transaction number */
609
	UT_LIST_BASE_NODE_T(trx_t) trx_list;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
610
					/*!< List of active and committed in
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
611
					memory transactions, sorted on trx id,
612
					biggest first */
613
	UT_LIST_BASE_NODE_T(trx_t) mysql_trx_list;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
614
					/*!< List of transactions created
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
615
					for MySQL */
616
	UT_LIST_BASE_NODE_T(trx_rseg_t) rseg_list;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
617
					/*!< List of rollback segment
618
					objects */
619
	trx_rseg_t*	latest_rseg;	/*!< Latest rollback segment in the
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
620
					round-robin assignment of rollback
621
					segments to transactions */
622
	trx_rseg_t*	rseg_array[TRX_SYS_N_RSEGS];
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
623
					/*!< Pointer array to rollback
624
					segments; NULL if slot not in use */
625
	ulint		rseg_history_len;/*!< Length of the TRX_RSEG_HISTORY
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
626
					list (update undo logs for committed
627
					transactions), protected by
628
					rseg->mutex */
629
	UT_LIST_BASE_NODE_T(read_view_t) view_list;
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
630
					/*!< List of read views sorted
631
					on trx no, biggest first */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
632
};
633
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
634
/** When a trx id which is zero modulo this number (which must be a power of
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
635
two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system
636
page is updated */
637
#define TRX_SYS_TRX_ID_WRITE_MARGIN	256
641.2.3 by Monty Taylor
InnoDB Plugin 1.0.4
638
#endif /* !UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
639
640
#ifndef UNIV_NONINL
641
#include "trx0sys.ic"
642
#endif
643
644
#endif