~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/log0log.h

Reverted 1103

Show diffs side-by-side

added added

removed removed

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