~jaypipes/drizzle/new-test-runner

« back to all changes in this revision

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

  • Committer: Jay Pipes
  • Date: 2008-12-11 17:52:34 UTC
  • mfrom: (482.16.152 testable)
  • Revision ID: jpipes@serialcoder-20081211175234-uqsfvmgxejvmellq
merge with trunk

Show diffs side-by-side

added added

removed removed

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