~drizzle-trunk/drizzle/development

641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
1
/*****************************************************************************
2
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
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
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
16
17
*****************************************************************************/
18
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
19
/******************************************************
20
Database log
21
22
Created 12/9/1995 Heikki Tuuri
23
*******************************************************/
24
25
#ifndef log0log_h
26
#define log0log_h
27
28
#include "univ.i"
29
#include "ut0byte.h"
30
#include "sync0sync.h"
31
#include "sync0rw.h"
32
33
typedef struct log_struct	log_t;
34
typedef struct log_group_struct	log_group_t;
35
36
#ifdef UNIV_DEBUG
37
extern	ibool	log_do_write;
38
extern	ibool	log_debug_writes;
39
#else /* UNIV_DEBUG */
40
# define log_do_write TRUE
41
#endif /* UNIV_DEBUG */
42
43
/* Wait modes for log_write_up_to */
44
#define LOG_NO_WAIT		91
45
#define LOG_WAIT_ONE_GROUP	92
46
#define	LOG_WAIT_ALL_GROUPS	93
47
#define LOG_MAX_N_GROUPS	32
48
49
/********************************************************************
50
Sets the global variable log_fsp_current_free_limit. Also makes a checkpoint,
51
so that we know that the limit has been written to a log checkpoint field
52
on disk. */
53
UNIV_INTERN
54
void
55
log_fsp_current_free_limit_set_and_checkpoint(
56
/*==========================================*/
57
	ulint	limit);	/* in: limit to set */
58
/***********************************************************************
59
Calculates where in log files we find a specified lsn. */
60
UNIV_INTERN
61
ulint
62
log_calc_where_lsn_is(
63
/*==================*/
64
						/* out: log file number */
65
	ib_int64_t*	log_file_offset,	/* out: offset in that file
66
						(including the header) */
67
	ib_uint64_t	first_header_lsn,	/* in: first log file start
68
						lsn */
69
	ib_uint64_t	lsn,			/* in: lsn whose position to
70
						determine */
71
	ulint		n_log_files,		/* in: total number of log
72
						files */
73
	ib_int64_t	log_file_size);		/* in: log file size
74
						(including the header) */
75
/****************************************************************
76
Writes to the log the string given. The log must be released with
77
log_release. */
78
UNIV_INLINE
79
ib_uint64_t
80
log_reserve_and_write_fast(
81
/*=======================*/
82
				/* out: end lsn of the log record,
83
				zero if did not succeed */
84
	byte*		str,	/* in: string */
85
	ulint		len,	/* in: string length */
86
	ib_uint64_t*	start_lsn,/* out: start lsn of the log record */
87
	ibool*		success);/* out: TRUE if success */
88
/***************************************************************************
89
Releases the log mutex. */
90
UNIV_INLINE
91
void
92
log_release(void);
93
/*=============*/
94
/***************************************************************************
95
Checks if there is need for a log buffer flush or a new checkpoint, and does
96
this if yes. Any database operation should call this when it has modified
97
more than about 4 pages. NOTE that this function may only be called when the
98
OS thread owns no synchronization objects except the dictionary mutex. */
99
UNIV_INLINE
100
void
101
log_free_check(void);
102
/*================*/
103
/****************************************************************
104
Opens the log for log_write_low. The log must be closed with log_close and
105
released with log_release. */
106
UNIV_INTERN
107
ib_uint64_t
108
log_reserve_and_open(
109
/*=================*/
110
			/* out: start lsn of the log record */
111
	ulint	len);	/* in: length of data to be catenated */
112
/****************************************************************
113
Writes to the log the string given. It is assumed that the caller holds the
114
log mutex. */
115
UNIV_INTERN
116
void
117
log_write_low(
118
/*==========*/
119
	byte*	str,		/* in: string */
120
	ulint	str_len);	/* in: string length */
121
/****************************************************************
122
Closes the log. */
123
UNIV_INTERN
124
ib_uint64_t
125
log_close(void);
126
/*===========*/
127
			/* out: lsn */
128
/****************************************************************
129
Gets the current lsn. */
130
UNIV_INLINE
131
ib_uint64_t
132
log_get_lsn(void);
133
/*=============*/
134
			/* out: current lsn */
135
/**********************************************************
136
Initializes the log. */
137
UNIV_INTERN
138
void
139
log_init(void);
140
/*==========*/
141
/**********************************************************************
142
Inits a log group to the log system. */
143
UNIV_INTERN
144
void
145
log_group_init(
146
/*===========*/
147
	ulint	id,			/* in: group id */
148
	ulint	n_files,		/* in: number of log files */
149
	ulint	file_size,		/* in: log file size in bytes */
150
	ulint	space_id,		/* in: space id of the file space
151
					which contains the log files of this
152
					group */
153
	ulint	archive_space_id);	/* in: space id of the file space
154
					which contains some archived log
155
					files for this group; currently, only
156
					for the first log group this is
157
					used */
158
/**********************************************************
159
Completes an i/o to a log file. */
160
UNIV_INTERN
161
void
162
log_io_complete(
163
/*============*/
164
	log_group_t*	group);	/* in: log group */
165
/**********************************************************
166
This function is called, e.g., when a transaction wants to commit. It checks
167
that the log has been written to the log file up to the last log entry written
168
by the transaction. If there is a flush running, it waits and checks if the
169
flush flushed enough. If not, starts a new flush. */
170
UNIV_INTERN
171
void
172
log_write_up_to(
173
/*============*/
174
	ib_uint64_t	lsn,	/* in: log sequence number up to which
175
				the log should be written,
176
				IB_ULONGLONG_MAX if not specified */
177
	ulint		wait,	/* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP,
178
				or LOG_WAIT_ALL_GROUPS */
179
	ibool		flush_to_disk);
180
				/* in: TRUE if we want the written log
181
				also to be flushed to disk */
182
/********************************************************************
183
Does a syncronous flush of the log buffer to disk. */
184
UNIV_INTERN
185
void
186
log_buffer_flush_to_disk(void);
187
/*==========================*/
188
/********************************************************************
189
Advances the smallest lsn for which there are unflushed dirty blocks in the
190
buffer pool and also may make a new checkpoint. NOTE: this function may only
191
be called if the calling thread owns no synchronization objects! */
192
UNIV_INTERN
193
ibool
194
log_preflush_pool_modified_pages(
195
/*=============================*/
196
					/* out: FALSE if there was a
197
					flush batch of the same type
198
					running, which means that we
199
					could not start this flush
200
					batch */
201
	ib_uint64_t	new_oldest,	/* in: try to advance
202
					oldest_modified_lsn at least
203
					to this lsn */
204
	ibool		sync);		/* in: TRUE if synchronous
205
					operation is desired */
206
/**********************************************************
207
Makes a checkpoint. Note that this function does not flush dirty
208
blocks from the buffer pool: it only checks what is lsn of the oldest
209
modification in the pool, and writes information about the lsn in
210
log files. Use log_make_checkpoint_at to flush also the pool. */
211
UNIV_INTERN
212
ibool
213
log_checkpoint(
214
/*===========*/
215
				/* out: TRUE if success, FALSE if a checkpoint
216
				write was already running */
217
	ibool	sync,		/* in: TRUE if synchronous operation is
218
				desired */
219
	ibool	write_always);	/* in: the function normally checks if the
220
				the new checkpoint would have a greater
221
				lsn than the previous one: if not, then no
222
				physical write is done; by setting this
223
				parameter TRUE, a physical write will always be
224
				made to log files */
225
/********************************************************************
226
Makes a checkpoint at a given lsn or later. */
227
UNIV_INTERN
228
void
229
log_make_checkpoint_at(
230
/*===================*/
231
	ib_uint64_t	lsn,		/* in: make a checkpoint at this or a
232
					later lsn, if IB_ULONGLONG_MAX, makes
233
					a checkpoint at the latest lsn */
234
	ibool		write_always);	/* in: the function normally checks if
235
					the the new checkpoint would have a
236
					greater lsn than the previous one: if
237
					not, then no physical write is done;
238
					by setting this parameter TRUE, a
239
					physical write will always be made to
240
					log files */
241
/********************************************************************
242
Makes a checkpoint at the latest lsn and writes it to first page of each
243
data file in the database, so that we know that the file spaces contain
244
all modifications up to that lsn. This can only be called at database
245
shutdown. This function also writes all log in log files to the log archive. */
246
UNIV_INTERN
247
void
248
logs_empty_and_mark_files_at_shutdown(void);
249
/*=======================================*/
250
/**********************************************************
251
Reads a checkpoint info from a log group header to log_sys->checkpoint_buf. */
252
UNIV_INTERN
253
void
254
log_group_read_checkpoint_info(
255
/*===========================*/
256
	log_group_t*	group,	/* in: log group */
257
	ulint		field);	/* in: LOG_CHECKPOINT_1 or LOG_CHECKPOINT_2 */
258
/***********************************************************************
259
Gets info from a checkpoint about a log group. */
260
UNIV_INTERN
261
void
262
log_checkpoint_get_nth_group_info(
263
/*==============================*/
264
	byte*	buf,	/* in: buffer containing checkpoint info */
265
	ulint	n,	/* in: nth slot */
266
	ulint*	file_no,/* out: archived file number */
267
	ulint*	offset);/* out: archived file offset */
268
/**********************************************************
269
Writes checkpoint info to groups. */
270
UNIV_INTERN
271
void
272
log_groups_write_checkpoint_info(void);
273
/*==================================*/
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
274
#ifdef UNIV_HOTBACKUP
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
275
/**********************************************************
276
Writes info to a buffer of a log group when log files are created in
277
backup restoration. */
278
UNIV_INTERN
279
void
280
log_reset_first_header_and_checkpoint(
281
/*==================================*/
282
	byte*		hdr_buf,/* in: buffer which will be written to the
283
				start of the first log file */
284
	ib_uint64_t	start);	/* in: lsn of the start of the first log file;
285
				we pretend that there is a checkpoint at
286
				start + LOG_BLOCK_HDR_SIZE */
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
287
#endif /* UNIV_HOTBACKUP */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
288
/************************************************************************
289
Starts an archiving operation. */
290
UNIV_INTERN
291
ibool
292
log_archive_do(
293
/*===========*/
294
			/* out: TRUE if succeed, FALSE if an archiving
295
			operation was already running */
296
	ibool	sync,	/* in: TRUE if synchronous operation is desired */
297
	ulint*	n_bytes);/* out: archive log buffer size, 0 if nothing to
298
			archive */
299
/********************************************************************
300
Writes the log contents to the archive up to the lsn when this function was
301
called, and stops the archiving. When archiving is started again, the archived
302
log file numbers start from a number one higher, so that the archiving will
303
not write again to the archived log files which exist when this function
304
returns. */
305
UNIV_INTERN
306
ulint
307
log_archive_stop(void);
308
/*==================*/
309
				/* out: DB_SUCCESS or DB_ERROR */
310
/********************************************************************
311
Starts again archiving which has been stopped. */
312
UNIV_INTERN
313
ulint
314
log_archive_start(void);
315
/*===================*/
316
			/* out: DB_SUCCESS or DB_ERROR */
317
/********************************************************************
318
Stop archiving the log so that a gap may occur in the archived log files. */
319
UNIV_INTERN
320
ulint
321
log_archive_noarchivelog(void);
322
/*==========================*/
323
			/* out: DB_SUCCESS or DB_ERROR */
324
/********************************************************************
325
Start archiving the log so that a gap may occur in the archived log files. */
326
UNIV_INTERN
327
ulint
328
log_archive_archivelog(void);
329
/*========================*/
330
			/* out: DB_SUCCESS or DB_ERROR */
331
/**********************************************************
332
Generates an archived log file name. */
333
UNIV_INTERN
334
void
335
log_archived_file_name_gen(
336
/*=======================*/
337
	char*	buf,	/* in: buffer where to write */
338
	ulint	id,	/* in: group id */
339
	ulint	file_no);/* in: file number */
340
/************************************************************************
341
Checks that there is enough free space in the log to start a new query step.
342
Flushes the log buffer or makes a new checkpoint if necessary. NOTE: this
343
function may only be called if the calling thread owns no synchronization
344
objects! */
345
UNIV_INTERN
346
void
347
log_check_margins(void);
348
/*===================*/
349
/**********************************************************
350
Reads a specified log segment to a buffer. */
351
UNIV_INTERN
352
void
353
log_group_read_log_seg(
354
/*===================*/
355
	ulint		type,		/* in: LOG_ARCHIVE or LOG_RECOVER */
356
	byte*		buf,		/* in: buffer where to read */
357
	log_group_t*	group,		/* in: log group */
358
	ib_uint64_t	start_lsn,	/* in: read area start */
359
	ib_uint64_t	end_lsn);	/* in: read area end */
360
/**********************************************************
361
Writes a buffer to a log file group. */
362
UNIV_INTERN
363
void
364
log_group_write_buf(
365
/*================*/
366
	log_group_t*	group,		/* in: log group */
367
	byte*		buf,		/* in: buffer */
368
	ulint		len,		/* in: buffer len; must be divisible
369
					by OS_FILE_LOG_BLOCK_SIZE */
370
	ib_uint64_t	start_lsn,	/* in: start lsn of the buffer; must
371
					be divisible by
372
					OS_FILE_LOG_BLOCK_SIZE */
373
	ulint		new_data_offset);/* in: start offset of new data in
374
					buf: this parameter is used to decide
375
					if we have to write a new log file
376
					header */
377
/************************************************************
378
Sets the field values in group to correspond to a given lsn. For this function
379
to work, the values must already be correctly initialized to correspond to
380
some lsn, for instance, a checkpoint lsn. */
381
UNIV_INTERN
382
void
383
log_group_set_fields(
384
/*=================*/
385
	log_group_t*	group,	/* in: group */
386
	ib_uint64_t	lsn);	/* in: lsn for which the values should be
387
				set */
388
/**********************************************************
389
Calculates the data capacity of a log group, when the log file headers are not
390
included. */
391
UNIV_INTERN
392
ulint
393
log_group_get_capacity(
394
/*===================*/
395
				/* out: capacity in bytes */
396
	log_group_t*	group);	/* in: log group */
397
/****************************************************************
398
Gets a log block flush bit. */
399
UNIV_INLINE
400
ibool
401
log_block_get_flush_bit(
402
/*====================*/
403
				/* out: TRUE if this block was the first
404
				to be written in a log flush */
405
	byte*	log_block);	/* in: log block */
406
/****************************************************************
407
Gets a log block number stored in the header. */
408
UNIV_INLINE
409
ulint
410
log_block_get_hdr_no(
411
/*=================*/
412
				/* out: log block number stored in the block
413
				header */
414
	byte*	log_block);	/* in: log block */
415
/****************************************************************
416
Gets a log block data length. */
417
UNIV_INLINE
418
ulint
419
log_block_get_data_len(
420
/*===================*/
421
				/* out: log block data length measured as a
422
				byte offset from the block start */
423
	byte*	log_block);	/* in: log block */
424
/****************************************************************
425
Sets the log block data length. */
426
UNIV_INLINE
427
void
428
log_block_set_data_len(
429
/*===================*/
430
	byte*	log_block,	/* in: log block */
431
	ulint	len);		/* in: data length */
432
/****************************************************************
433
Calculates the checksum for a log block. */
434
UNIV_INLINE
435
ulint
436
log_block_calc_checksum(
437
/*====================*/
438
				/* out: checksum */
439
	const byte*	block);	/* in: log block */
440
/****************************************************************
441
Gets a log block checksum field value. */
442
UNIV_INLINE
443
ulint
444
log_block_get_checksum(
445
/*===================*/
446
					/* out: checksum */
447
	const byte*	log_block);	/* in: log block */
448
/****************************************************************
449
Sets a log block checksum field value. */
450
UNIV_INLINE
451
void
452
log_block_set_checksum(
453
/*===================*/
454
	byte*	log_block,	/* in: log block */
455
	ulint	checksum);	/* in: checksum */
456
/****************************************************************
457
Gets a log block first mtr log record group offset. */
458
UNIV_INLINE
459
ulint
460
log_block_get_first_rec_group(
461
/*==========================*/
462
				/* out: first mtr log record group byte offset
463
				from the block start, 0 if none */
464
	byte*	log_block);	/* in: log block */
465
/****************************************************************
466
Sets the log block first mtr log record group offset. */
467
UNIV_INLINE
468
void
469
log_block_set_first_rec_group(
470
/*==========================*/
471
	byte*	log_block,	/* in: log block */
472
	ulint	offset);	/* in: offset, 0 if none */
473
/****************************************************************
474
Gets a log block checkpoint number field (4 lowest bytes). */
475
UNIV_INLINE
476
ulint
477
log_block_get_checkpoint_no(
478
/*========================*/
479
				/* out: checkpoint no (4 lowest bytes) */
480
	byte*	log_block);	/* in: log block */
481
/****************************************************************
482
Initializes a log block in the log buffer. */
483
UNIV_INLINE
484
void
485
log_block_init(
486
/*===========*/
487
	byte*		log_block,	/* in: pointer to the log buffer */
488
	ib_uint64_t	lsn);		/* in: lsn within the log block */
489
/****************************************************************
490
Initializes a log block in the log buffer in the old, < 3.23.52 format, where
491
there was no checksum yet. */
492
UNIV_INLINE
493
void
494
log_block_init_in_old_format(
495
/*=========================*/
496
	byte*		log_block,	/* in: pointer to the log buffer */
497
	ib_uint64_t	lsn);		/* in: lsn within the log block */
498
/****************************************************************
499
Converts a lsn to a log block number. */
500
UNIV_INLINE
501
ulint
502
log_block_convert_lsn_to_no(
503
/*========================*/
504
				/* out: log block number,
505
				it is > 0 and <= 1G */
506
	ib_uint64_t	lsn);	/* in: lsn of a byte within the block */
507
/**********************************************************
508
Prints info of the log. */
509
UNIV_INTERN
510
void
511
log_print(
512
/*======*/
513
	FILE*	file);	/* in: file where to print */
514
/**********************************************************
515
Peeks the current lsn. */
516
UNIV_INTERN
517
ibool
518
log_peek_lsn(
519
/*=========*/
520
				/* out: TRUE if success, FALSE if
521
				could not get the log system mutex */
522
	ib_uint64_t*	lsn);	/* out: if returns TRUE, current lsn is here */
523
/**************************************************************************
524
Refreshes the statistics used to print per-second averages. */
525
UNIV_INTERN
526
void
527
log_refresh_stats(void);
528
/*===================*/
529
530
extern log_t*	log_sys;
531
532
/* Values used as flags */
533
#define LOG_FLUSH	7652559
534
#define LOG_CHECKPOINT	78656949
641.2.2 by Monty Taylor
InnoDB Plugin 1.0.3
535
#ifdef UNIV_LOG_ARCHIVE
536
# define LOG_ARCHIVE	11122331
537
#endif /* UNIV_LOG_ARCHIVE */
641.1.2 by Monty Taylor
Imported 1.0.1 with clean - with no changes.
538
#define LOG_RECOVER	98887331
539
540
/* The counting of lsn's starts from this value: this must be non-zero */
541
#define LOG_START_LSN	((ib_uint64_t) (16 * OS_FILE_LOG_BLOCK_SIZE))
542
543
#define LOG_BUFFER_SIZE		(srv_log_buffer_size * UNIV_PAGE_SIZE)
544
#define LOG_ARCHIVE_BUF_SIZE	(srv_log_buffer_size * UNIV_PAGE_SIZE / 4)
545
546
/* Offsets of a log block header */
547
#define	LOG_BLOCK_HDR_NO	0	/* block number which must be > 0 and
548
					is allowed to wrap around at 2G; the
549
					highest bit is set to 1 if this is the
550
					first log block in a log flush write
551
					segment */
552
#define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL
553
					/* mask used to get the highest bit in
554
					the preceding field */
555
#define	LOG_BLOCK_HDR_DATA_LEN	4	/* number of bytes of log written to
556
					this block */
557
#define	LOG_BLOCK_FIRST_REC_GROUP 6	/* offset of the first start of an
558
					mtr log record group in this log block,
559
					0 if none; if the value is the same
560
					as LOG_BLOCK_HDR_DATA_LEN, it means
561
					that the first rec group has not yet
562
					been catenated to this log block, but
563
					if it will, it will start at this
564
					offset; an archive recovery can
565
					start parsing the log records starting
566
					from this offset in this log block,
567
					if value not 0 */
568
#define LOG_BLOCK_CHECKPOINT_NO	8	/* 4 lower bytes of the value of
569
					log_sys->next_checkpoint_no when the
570
					log block was last written to: if the
571
					block has not yet been written full,
572
					this value is only updated before a
573
					log buffer flush */
574
#define LOG_BLOCK_HDR_SIZE	12	/* size of the log block header in
575
					bytes */
576
577
/* Offsets of a log block trailer from the end of the block */
578
#define	LOG_BLOCK_CHECKSUM	4	/* 4 byte checksum of the log block
579
					contents; in InnoDB versions
580
					< 3.23.52 this did not contain the
581
					checksum but the same value as
582
					.._HDR_NO */
583
#define	LOG_BLOCK_TRL_SIZE	4	/* trailer size in bytes */
584
585
/* Offsets for a checkpoint field */
586
#define LOG_CHECKPOINT_NO		0
587
#define LOG_CHECKPOINT_LSN		8
588
#define LOG_CHECKPOINT_OFFSET		16
589
#define LOG_CHECKPOINT_LOG_BUF_SIZE	20
590
#define	LOG_CHECKPOINT_ARCHIVED_LSN	24
591
#define	LOG_CHECKPOINT_GROUP_ARRAY	32
592
593
/* For each value < LOG_MAX_N_GROUPS the following 8 bytes: */
594
595
#define LOG_CHECKPOINT_ARCHIVED_FILE_NO	0
596
#define LOG_CHECKPOINT_ARCHIVED_OFFSET	4
597
598
#define	LOG_CHECKPOINT_ARRAY_END	(LOG_CHECKPOINT_GROUP_ARRAY\
599
							+ LOG_MAX_N_GROUPS * 8)
600
#define LOG_CHECKPOINT_CHECKSUM_1	LOG_CHECKPOINT_ARRAY_END
601
#define LOG_CHECKPOINT_CHECKSUM_2	(4 + LOG_CHECKPOINT_ARRAY_END)
602
#define LOG_CHECKPOINT_FSP_FREE_LIMIT	(8 + LOG_CHECKPOINT_ARRAY_END)
603
					/* current fsp free limit in
604
					tablespace 0, in units of one
605
					megabyte; this information is only used
606
					by ibbackup to decide if it can
607
					truncate unused ends of
608
					non-auto-extending data files in space
609
					0 */
610
#define LOG_CHECKPOINT_FSP_MAGIC_N	(12 + LOG_CHECKPOINT_ARRAY_END)
611
					/* this magic number tells if the
612
					checkpoint contains the above field:
613
					the field was added to
614
					InnoDB-3.23.50 */
615
#define LOG_CHECKPOINT_SIZE		(16 + LOG_CHECKPOINT_ARRAY_END)
616
617
#define LOG_CHECKPOINT_FSP_MAGIC_N_VAL	1441231243
618
619
/* Offsets of a log file header */
620
#define LOG_GROUP_ID		0	/* log group number */
621
#define LOG_FILE_START_LSN	4	/* lsn of the start of data in this
622
					log file */
623
#define LOG_FILE_NO		12	/* 4-byte archived log file number;
624
					this field is only defined in an
625
					archived log file */
626
#define LOG_FILE_WAS_CREATED_BY_HOT_BACKUP 16
627
					/* a 32-byte field which contains
628
					the string 'ibbackup' and the
629
					creation time if the log file was
630
					created by ibbackup --restore;
631
					when mysqld is first time started
632
					on the restored database, it can
633
					print helpful info for the user */
634
#define	LOG_FILE_ARCH_COMPLETED	OS_FILE_LOG_BLOCK_SIZE
635
					/* this 4-byte field is TRUE when
636
					the writing of an archived log file
637
					has been completed; this field is
638
					only defined in an archived log file */
639
#define LOG_FILE_END_LSN	(OS_FILE_LOG_BLOCK_SIZE + 4)
640
					/* lsn where the archived log file
641
					at least extends: actually the
642
					archived log file may extend to a
643
					later lsn, as long as it is within the
644
					same log block as this lsn; this field
645
					is defined only when an archived log
646
					file has been completely written */
647
#define LOG_CHECKPOINT_1	OS_FILE_LOG_BLOCK_SIZE
648
					/* first checkpoint field in the log
649
					header; we write alternately to the
650
					checkpoint fields when we make new
651
					checkpoints; this field is only defined
652
					in the first log file of a log group */
653
#define LOG_CHECKPOINT_2	(3 * OS_FILE_LOG_BLOCK_SIZE)
654
					/* second checkpoint field in the log
655
					header */
656
#define LOG_FILE_HDR_SIZE	(4 * OS_FILE_LOG_BLOCK_SIZE)
657
658
#define LOG_GROUP_OK		301
659
#define LOG_GROUP_CORRUPTED	302
660
661
/* Log group consists of a number of log files, each of the same size; a log
662
group is implemented as a space in the sense of the module fil0fil. */
663
664
struct log_group_struct{
665
	/* The following fields are protected by log_sys->mutex */
666
	ulint		id;		/* log group id */
667
	ulint		n_files;	/* number of files in the group */
668
	ulint		file_size;	/* individual log file size in bytes,
669
					including the log file header */
670
	ulint		space_id;	/* file space which implements the log
671
					group */
672
	ulint		state;		/* LOG_GROUP_OK or
673
					LOG_GROUP_CORRUPTED */
674
	ib_uint64_t	lsn;		/* lsn used to fix coordinates within
675
					the log group */
676
	ulint		lsn_offset;	/* the offset of the above lsn */
677
	ulint		n_pending_writes;/* number of currently pending flush
678
					writes for this log group */
679
	byte**		file_header_bufs;/* buffers for each file header in the
680
					group */
681
	/*-----------------------------*/
682
	byte**		archive_file_header_bufs;/* buffers for each file
683
					header in the group */
684
	ulint		archive_space_id;/* file space which implements the log
685
					group archive */
686
	ulint		archived_file_no;/* file number corresponding to
687
					log_sys->archived_lsn */
688
	ulint		archived_offset;/* file offset corresponding to
689
					log_sys->archived_lsn, 0 if we have
690
					not yet written to the archive file
691
					number archived_file_no */
692
	ulint		next_archived_file_no;/* during an archive write,
693
					until the write is completed, we
694
					store the next value for
695
					archived_file_no here: the write
696
					completion function then sets the new
697
					value to ..._file_no */
698
	ulint		next_archived_offset; /* like the preceding field */
699
	/*-----------------------------*/
700
	ib_uint64_t	scanned_lsn;	/* used only in recovery: recovery scan
701
					succeeded up to this lsn in this log
702
					group */
703
	byte*		checkpoint_buf;	/* checkpoint header is written from
704
					this buffer to the group */
705
	UT_LIST_NODE_T(log_group_t)
706
			log_groups;	/* list of log groups */
707
};
708
709
struct log_struct{
710
	byte		pad[64];	/* padding to prevent other memory
711
					update hotspots from residing on the
712
					same memory cache line */
713
	ib_uint64_t	lsn;		/* log sequence number */
714
	ulint		buf_free;	/* first free offset within the log
715
					buffer */
716
	mutex_t		mutex;		/* mutex protecting the log */
717
	byte*		buf;		/* log buffer */
718
	ulint		buf_size;	/* log buffer size in bytes */
719
	ulint		max_buf_free;	/* recommended maximum value of
720
					buf_free, after which the buffer is
721
					flushed */
722
	ulint		old_buf_free;	/* value of buf free when log was
723
					last time opened; only in the debug
724
					version */
725
	ib_uint64_t	old_lsn;	/* value of lsn when log was last time
726
					opened; only in the debug version */
727
	ibool		check_flush_or_checkpoint;
728
					/* this is set to TRUE when there may
729
					be need to flush the log buffer, or
730
					preflush buffer pool pages, or make
731
					a checkpoint; this MUST be TRUE when
732
					lsn - last_checkpoint_lsn >
733
					max_checkpoint_age; this flag is
734
					peeked at by log_free_check(), which
735
					does not reserve the log mutex */
736
	UT_LIST_BASE_NODE_T(log_group_t)
737
			log_groups;	/* log groups */
738
739
	/* The fields involved in the log buffer flush */
740
741
	ulint		buf_next_to_write;/* first offset in the log buffer
742
					where the byte content may not exist
743
					written to file, e.g., the start
744
					offset of a log record catenated
745
					later; this is advanced when a flush
746
					operation is completed to all the log
747
					groups */
748
	ib_uint64_t	written_to_some_lsn;
749
					/* first log sequence number not yet
750
					written to any log group; for this to
751
					be advanced, it is enough that the
752
					write i/o has been completed for any
753
					one log group */
754
	ib_uint64_t	written_to_all_lsn;
755
					/* first log sequence number not yet
756
					written to some log group; for this to
757
					be advanced, it is enough that the
758
					write i/o has been completed for all
759
					log groups */
760
	ib_uint64_t	write_lsn;	/* end lsn for the current running
761
					write */
762
	ulint		write_end_offset;/* the data in buffer has been written
763
					up to this offset when the current
764
					write ends: this field will then
765
					be copied to buf_next_to_write */
766
	ib_uint64_t	current_flush_lsn;/* end lsn for the current running
767
					write + flush operation */
768
	ib_uint64_t	flushed_to_disk_lsn;
769
					/* how far we have written the log
770
					AND flushed to disk */
771
	ulint		n_pending_writes;/* number of currently pending flushes
772
					or writes */
773
	/* NOTE on the 'flush' in names of the fields below: starting from
774
	4.0.14, we separate the write of the log file and the actual fsync()
775
	or other method to flush it to disk. The names below shhould really
776
	be 'flush_or_write'! */
777
	os_event_t	no_flush_event;	/* this event is in the reset state
778
					when a flush or a write is running;
779
					a thread should wait for this without
780
					owning the log mutex, but NOTE that
781
					to set or reset this event, the
782
					thread MUST own the log mutex! */
783
	ibool		one_flushed;	/* during a flush, this is first FALSE
784
					and becomes TRUE when one log group
785
					has been written or flushed */
786
	os_event_t	one_flushed_event;/* this event is reset when the
787
					flush or write has not yet completed
788
					for any log group; e.g., this means
789
					that a transaction has been committed
790
					when this is set; a thread should wait
791
					for this without owning the log mutex,
792
					but NOTE that to set or reset this
793
					event, the thread MUST own the log
794
					mutex! */
795
	ulint		n_log_ios;	/* number of log i/os initiated thus
796
					far */
797
	ulint		n_log_ios_old;	/* number of log i/o's at the
798
					previous printout */
799
	time_t		last_printout_time;/* when log_print was last time
800
					called */
801
802
	/* Fields involved in checkpoints */
803
	ulint		log_group_capacity; /* capacity of the log group; if
804
					the checkpoint age exceeds this, it is
805
					a serious error because it is possible
806
					we will then overwrite log and spoil
807
					crash recovery */
808
	ulint		max_modified_age_async;
809
					/* when this recommended value for lsn
810
					- buf_pool_get_oldest_modification()
811
					is exceeded, we start an asynchronous
812
					preflush of pool pages */
813
	ulint		max_modified_age_sync;
814
					/* when this recommended value for lsn
815
					- buf_pool_get_oldest_modification()
816
					is exceeded, we start a synchronous
817
					preflush of pool pages */
818
	ulint		adm_checkpoint_interval;
819
					/* administrator-specified checkpoint
820
					interval in terms of log growth in
821
					bytes; the interval actually used by
822
					the database can be smaller */
823
	ulint		max_checkpoint_age_async;
824
					/* when this checkpoint age is exceeded
825
					we start an asynchronous writing of a
826
					new checkpoint */
827
	ulint		max_checkpoint_age;
828
					/* this is the maximum allowed value
829
					for lsn - last_checkpoint_lsn when a
830
					new query step is started */
831
	ib_uint64_t	next_checkpoint_no;
832
					/* next checkpoint number */
833
	ib_uint64_t	last_checkpoint_lsn;
834
					/* latest checkpoint lsn */
835
	ib_uint64_t	next_checkpoint_lsn;
836
					/* next checkpoint lsn */
837
	ulint		n_pending_checkpoint_writes;
838
					/* number of currently pending
839
					checkpoint writes */
840
	rw_lock_t	checkpoint_lock;/* this latch is x-locked when a
841
					checkpoint write is running; a thread
842
					should wait for this without owning
843
					the log mutex */
844
	byte*		checkpoint_buf;	/* checkpoint header is read to this
845
					buffer */
846
#ifdef UNIV_LOG_ARCHIVE
847
	/* Fields involved in archiving */
848
	ulint		archiving_state;/* LOG_ARCH_ON, LOG_ARCH_STOPPING
849
					LOG_ARCH_STOPPED, LOG_ARCH_OFF */
850
	ib_uint64_t	archived_lsn;	/* archiving has advanced to this
851
					lsn */
852
	ulint		max_archived_lsn_age_async;
853
					/* recommended maximum age of
854
					archived_lsn, before we start
855
					asynchronous copying to the archive */
856
	ulint		max_archived_lsn_age;
857
					/* maximum allowed age for
858
					archived_lsn */
859
	ib_uint64_t	next_archived_lsn;/* during an archive write,
860
					until the write is completed, we
861
					store the next value for
862
					archived_lsn here: the write
863
					completion function then sets the new
864
					value to archived_lsn */
865
	ulint		archiving_phase;/* LOG_ARCHIVE_READ or
866
					LOG_ARCHIVE_WRITE */
867
	ulint		n_pending_archive_ios;
868
					/* number of currently pending reads
869
					or writes in archiving */
870
	rw_lock_t	archive_lock;	/* this latch is x-locked when an
871
					archive write is running; a thread
872
					should wait for this without owning
873
					the log mutex */
874
	ulint		archive_buf_size;/* size of archive_buf */
875
	byte*		archive_buf;	/* log segment is written to the
876
					archive from this buffer */
877
	os_event_t	archiving_on;	/* if archiving has been stopped,
878
					a thread can wait for this event to
879
					become signaled */
880
#endif /* UNIV_LOG_ARCHIVE */
881
};
882
883
#define LOG_ARCH_ON		71
884
#define LOG_ARCH_STOPPING	72
885
#define LOG_ARCH_STOPPING2	73
886
#define LOG_ARCH_STOPPED	74
887
#define LOG_ARCH_OFF		75
888
889
#ifndef UNIV_NONINL
890
#include "log0log.ic"
891
#endif
892
893
#endif