~stewart/haildb/trunk

« back to all changes in this revision

Viewing changes to include/log0log.h

  • Committer: Stewart Smith
  • Date: 2010-04-09 07:57:43 UTC
  • Revision ID: stewart@flamingspork.com-20100409075743-jfh1oml3el1uouvh
Embedded InnoDB 1.0.0 released

2009-04-21      The InnoDB Team

        Embedded InnoDB 1.0.0 released

Show diffs side-by-side

added added

removed removed

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