1
/*****************************************************************************
3
Copyright (c) 1997, 2009, Innobase Oy. All Rights Reserved.
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.
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.
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
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/log0recv.h
23
Created 9/20/1997 Heikki Tuuri
24
*******************************************************/
31
#include "buf0types.h"
32
#include "hash0hash.h"
36
extern ibool recv_replay_file_ops;
38
/*******************************************************************//**
39
Reads the checkpoint info needed in hot backup.
40
@return TRUE if success */
43
recv_read_cp_info_for_backup(
44
/*=========================*/
45
const byte* hdr, /*!< in: buffer containing the log group
47
ib_uint64_t* lsn, /*!< out: checkpoint lsn */
48
ulint* offset, /*!< out: checkpoint offset in the log group */
49
ulint* fsp_limit,/*!< out: fsp limit of space 0,
50
1000000000 if the database is running
51
with < version 3.23.50 of InnoDB */
52
ib_uint64_t* cp_no, /*!< out: checkpoint number */
53
ib_uint64_t* first_header_lsn);
54
/*!< out: lsn of of the start of the
56
/*******************************************************************//**
57
Scans the log segment and n_bytes_scanned is set to the length of valid
61
recv_scan_log_seg_for_backup(
62
/*=========================*/
63
byte* buf, /*!< in: buffer containing log data */
64
ulint buf_len, /*!< in: data length in that buffer */
65
ib_uint64_t* scanned_lsn, /*!< in/out: lsn of buffer start,
66
we return scanned lsn */
67
ulint* scanned_checkpoint_no,
68
/*!< in/out: 4 lowest bytes of the
69
highest scanned checkpoint number so
71
ulint* n_bytes_scanned);/*!< out: how much we were able to
72
scan, smaller than buf_len if log
74
#endif /* UNIV_HOTBACKUP */
75
/*******************************************************************//**
76
Returns TRUE if recovery is currently running.
77
@return recv_recovery_on */
80
recv_recovery_is_on(void);
81
/*=====================*/
82
#ifdef UNIV_LOG_ARCHIVE
83
/*******************************************************************//**
84
Returns TRUE if recovery from backup is currently running.
85
@return recv_recovery_from_backup_on */
88
recv_recovery_from_backup_is_on(void);
89
/*=================================*/
90
#endif /* UNIV_LOG_ARCHIVE */
91
/************************************************************************//**
92
Applies the hashed log records to the page, if the page lsn is less than the
93
lsn of a log record. This can be called when a buffer page has just been
94
read in, or also for a page already in the buffer pool. */
97
recv_recover_page_func(
98
/*===================*/
99
#ifndef UNIV_HOTBACKUP
101
/*!< in: TRUE if the i/o handler calls
102
this for a freshly read page */
103
#endif /* !UNIV_HOTBACKUP */
104
buf_block_t* block); /*!< in/out: buffer block */
105
#ifndef UNIV_HOTBACKUP
106
/** Wrapper for recv_recover_page_func().
107
Applies the hashed log records to the page, if the page lsn is less than the
108
lsn of a log record. This can be called when a buffer page has just been
109
read in, or also for a page already in the buffer pool.
110
@param jri in: TRUE if just read in (the i/o handler calls this for
112
@param block in/out: the buffer block
114
# define recv_recover_page(jri, block) recv_recover_page_func(jri, block)
115
#else /* !UNIV_HOTBACKUP */
116
/** Wrapper for recv_recover_page_func().
117
Applies the hashed log records to the page, if the page lsn is less than the
118
lsn of a log record. This can be called when a buffer page has just been
119
read in, or also for a page already in the buffer pool.
120
@param jri in: TRUE if just read in (the i/o handler calls this for
122
@param block in/out: the buffer block
124
# define recv_recover_page(jri, block) recv_recover_page_func(block)
125
#endif /* !UNIV_HOTBACKUP */
126
/********************************************************//**
127
Recovers from a checkpoint. When this function returns, the database is able
128
to start processing of new user transactions, but the function
129
recv_recovery_from_checkpoint_finish should be called later to complete
130
the recovery and free the resources used in it.
131
@return error code or DB_SUCCESS */
134
recv_recovery_from_checkpoint_start_func(
135
/*=====================================*/
136
#ifdef UNIV_LOG_ARCHIVE
137
ulint type, /*!< in: LOG_CHECKPOINT or
139
ib_uint64_t limit_lsn, /*!< in: recover up to this lsn
141
#endif /* UNIV_LOG_ARCHIVE */
142
ib_uint64_t min_flushed_lsn,/*!< in: min flushed lsn from
144
ib_uint64_t max_flushed_lsn);/*!< in: max flushed lsn from
146
#ifdef UNIV_LOG_ARCHIVE
147
/** Wrapper for recv_recovery_from_checkpoint_start_func().
148
Recovers from a checkpoint. When this function returns, the database is able
149
to start processing of new user transactions, but the function
150
recv_recovery_from_checkpoint_finish should be called later to complete
151
the recovery and free the resources used in it.
152
@param type in: LOG_CHECKPOINT or LOG_ARCHIVE
153
@param lim in: recover up to this log sequence number if possible
154
@param min in: minimum flushed log sequence number from data files
155
@param max in: maximum flushed log sequence number from data files
156
@return error code or DB_SUCCESS */
157
# define recv_recovery_from_checkpoint_start(type,lim,min,max) \
158
recv_recovery_from_checkpoint_start_func(type,lim,min,max)
159
#else /* UNIV_LOG_ARCHIVE */
160
/** Wrapper for recv_recovery_from_checkpoint_start_func().
161
Recovers from a checkpoint. When this function returns, the database is able
162
to start processing of new user transactions, but the function
163
recv_recovery_from_checkpoint_finish should be called later to complete
164
the recovery and free the resources used in it.
165
@param type ignored: LOG_CHECKPOINT or LOG_ARCHIVE
166
@param lim ignored: recover up to this log sequence number if possible
167
@param min in: minimum flushed log sequence number from data files
168
@param max in: maximum flushed log sequence number from data files
169
@return error code or DB_SUCCESS */
170
# define recv_recovery_from_checkpoint_start(type,lim,min,max) \
171
recv_recovery_from_checkpoint_start_func(min,max)
172
#endif /* UNIV_LOG_ARCHIVE */
173
/********************************************************//**
174
Completes recovery from a checkpoint. */
177
recv_recovery_from_checkpoint_finish(void);
178
/*======================================*/
179
/*******************************************************//**
180
Scans log from a buffer and stores new log data to the parsing buffer.
181
Parses and hashes the log records if new data found. Unless
182
UNIV_HOTBACKUP is defined, this function will apply log records
183
automatically when the hash table becomes full.
184
@return TRUE if limit_lsn has been reached, or not able to scan any
185
more in this log group */
190
ulint available_memory,/*!< in: we let the hash table of recs
191
to grow to this size, at the maximum */
192
ibool store_to_hash, /*!< in: TRUE if the records should be
193
stored to the hash table; this is set
194
to FALSE if just debug checking is
196
const byte* buf, /*!< in: buffer containing a log
197
segment or garbage */
198
ulint len, /*!< in: buffer length */
199
ib_uint64_t start_lsn, /*!< in: buffer start lsn */
200
ib_uint64_t* contiguous_lsn, /*!< in/out: it is known that all log
201
groups contain contiguous log data up
203
ib_uint64_t* group_scanned_lsn);/*!< out: scanning succeeded up to
205
/******************************************************//**
206
Resets the logs. The contents of log files will be lost! */
211
ib_uint64_t lsn, /*!< in: reset to this lsn
212
rounded up to be divisible by
213
OS_FILE_LOG_BLOCK_SIZE, after
215
LOG_BLOCK_HDR_SIZE */
216
#ifdef UNIV_LOG_ARCHIVE
217
ulint arch_log_no, /*!< in: next archived log file number */
218
#endif /* UNIV_LOG_ARCHIVE */
219
ibool new_logs_created);/*!< in: TRUE if resetting logs
220
is done at the log creation;
221
FALSE if it is done after
223
#ifdef UNIV_HOTBACKUP
224
/******************************************************//**
225
Creates new log files after a backup has been restored. */
228
recv_reset_log_files_for_backup(
229
/*============================*/
230
const char* log_dir, /*!< in: log file directory path */
231
ulint n_log_files, /*!< in: number of log files */
232
ulint log_file_size, /*!< in: log file size */
233
ib_uint64_t lsn); /*!< in: new start lsn, must be
234
divisible by OS_FILE_LOG_BLOCK_SIZE */
235
#endif /* UNIV_HOTBACKUP */
236
/********************************************************//**
237
Creates the recovery system. */
240
recv_sys_create(void);
241
/*=================*/
242
/********************************************************//**
243
Inits the recovery system for a recovery operation. */
248
ulint available_memory); /*!< in: available memory in bytes */
249
/*******************************************************************//**
250
Empties the hash table of stored log records, applying them to appropriate
254
recv_apply_hashed_log_recs(
255
/*=======================*/
256
ibool allow_ibuf); /*!< in: if TRUE, also ibuf operations are
257
allowed during the application; if FALSE,
258
no ibuf operations are allowed, and after
259
the application all file pages are flushed to
260
disk and invalidated in buffer pool: this
261
alternative means that no new log records
262
can be generated during the application */
263
#ifdef UNIV_HOTBACKUP
264
/*******************************************************************//**
265
Applies log records in the hash table to a backup. */
268
recv_apply_log_recs_for_backup(void);
269
/*================================*/
271
#ifdef UNIV_LOG_ARCHIVE
272
/********************************************************//**
273
Recovers from archived log files, and also from log files, if they exist.
274
@return error code or DB_SUCCESS */
277
recv_recovery_from_archive_start(
278
/*=============================*/
279
ib_uint64_t min_flushed_lsn,/*!< in: min flushed lsn field from the
281
ib_uint64_t limit_lsn, /*!< in: recover up to this lsn if
283
ulint first_log_no); /*!< in: number of the first archived
284
log file to use in the recovery; the
285
file will be searched from
286
INNOBASE_LOG_ARCH_DIR specified in
287
server config file */
288
/********************************************************//**
289
Completes recovery from archive. */
292
recv_recovery_from_archive_finish(void);
293
/*===================================*/
294
#endif /* UNIV_LOG_ARCHIVE */
296
/** Block of log record data */
297
typedef struct recv_data_struct recv_data_t;
298
/** Block of log record data */
299
struct recv_data_struct{
300
recv_data_t* next; /*!< pointer to the next block or NULL */
301
/*!< the log record data is stored physically
302
immediately after this struct, max amount
303
RECV_DATA_BLOCK_SIZE bytes of it */
306
/** Stored log record struct */
307
typedef struct recv_struct recv_t;
308
/** Stored log record struct */
310
byte type; /*!< log record type */
311
ulint len; /*!< log record body length in bytes */
312
recv_data_t* data; /*!< chain of blocks containing the log record
314
ib_uint64_t start_lsn;/*!< start lsn of the log segment written by
315
the mtr which generated this log record: NOTE
316
that this is not necessarily the start lsn of
318
ib_uint64_t end_lsn;/*!< end lsn of the log segment written by
319
the mtr which generated this log record: NOTE
320
that this is not necessarily the end lsn of
322
UT_LIST_NODE_T(recv_t)
323
rec_list;/*!< list of log records for this page */
326
/** States of recv_addr_struct */
327
enum recv_addr_state {
328
/** not yet processed */
330
/** page is being read */
332
/** log records are being applied on the page */
333
RECV_BEING_PROCESSED,
334
/** log records have been applied on the page, or they have
335
been discarded because the tablespace does not exist */
339
/** Hashed page file address struct */
340
typedef struct recv_addr_struct recv_addr_t;
341
/** Hashed page file address struct */
342
struct recv_addr_struct{
343
enum recv_addr_state state;
344
/*!< recovery state of the page */
345
ulint space; /*!< space id */
346
ulint page_no;/*!< page number */
347
UT_LIST_BASE_NODE_T(recv_t)
348
rec_list;/*!< list of log records for this page */
349
hash_node_t addr_hash;/*!< hash node in the hash bucket chain */
352
/** Recovery system data structure */
353
typedef struct recv_sys_struct recv_sys_t;
354
/** Recovery system data structure */
355
struct recv_sys_struct{
356
#ifndef UNIV_HOTBACKUP
357
mutex_t mutex; /*!< mutex protecting the fields apply_log_recs,
358
n_addrs, and the state field in each recv_addr
360
#endif /* !UNIV_HOTBACKUP */
361
ibool apply_log_recs;
362
/*!< this is TRUE when log rec application to
363
pages is allowed; this flag tells the
364
i/o-handler if it should do log record
366
ibool apply_batch_on;
367
/*!< this is TRUE when a log rec application
369
ib_uint64_t lsn; /*!< log sequence number */
370
ulint last_log_buf_size;
371
/*!< size of the log buffer when the database
372
last time wrote to the log */
374
/*!< possible incomplete last recovered log
376
byte* last_block_buf_start;
377
/*!< the nonaligned start address of the
379
byte* buf; /*!< buffer for parsing log records */
380
ulint len; /*!< amount of data in buf */
381
ib_uint64_t parse_start_lsn;
382
/*!< this is the lsn from which we were able to
383
start parsing log records and adding them to
384
the hash table; zero if a suitable
385
start point not found yet */
386
ib_uint64_t scanned_lsn;
387
/*!< the log data has been scanned up to this
389
ulint scanned_checkpoint_no;
390
/*!< the log data has been scanned up to this
391
checkpoint number (lowest 4 bytes) */
392
ulint recovered_offset;
393
/*!< start offset of non-parsed log records in
395
ib_uint64_t recovered_lsn;
396
/*!< the log records have been parsed up to
398
ib_uint64_t limit_lsn;/*!< recovery should be made at most
400
ibool found_corrupt_log;
401
/*!< this is set to TRUE if we during log
402
scan find a corrupt log block, or a corrupt
403
log record, or there is a log parsing
405
#ifdef UNIV_LOG_ARCHIVE
406
log_group_t* archive_group;
407
/*!< in archive recovery: the log group whose
409
#endif /* !UNIV_LOG_ARCHIVE */
410
mem_heap_t* heap; /*!< memory heap of log records and file
412
hash_table_t* addr_hash;/*!< hash table of file addresses of pages */
413
ulint n_addrs;/*!< number of not processed hashed file
414
addresses in the hash table */
417
/** The recovery system */
418
extern recv_sys_t* recv_sys;
420
/** TRUE when applying redo log records during crash recovery; FALSE
421
otherwise. Note that this is FALSE while a background thread is
422
rolling back incomplete transactions. */
423
extern ibool recv_recovery_on;
424
/** If the following is TRUE, the buffer pool file pages must be invalidated
425
after recovery and no ibuf operations are allowed; this becomes TRUE if
426
the log record hash table becomes too full, and log records must be merged
427
to file pages already before the recovery is finished: in this case no
428
ibuf operations are allowed, as they could modify the pages read in the
429
buffer pool before the pages have been recovered to the up-to-date state.
431
TRUE means that recovery is running and no operations on the log files
432
are allowed yet: the variable name is misleading. */
433
extern ibool recv_no_ibuf_operations;
434
/** TRUE when recv_init_crash_recovery() has been called. */
435
extern ibool recv_needed_recovery;
437
/** TRUE if buf_page_is_corrupted() should check if the log sequence
438
number (FIL_PAGE_LSN) is in the future. Initially FALSE, and set by
439
recv_recovery_from_checkpoint_start_func(). */
440
extern ibool recv_lsn_checks_on;
441
#ifdef UNIV_HOTBACKUP
442
/** TRUE when the redo log is being backed up */
443
extern ibool recv_is_making_a_backup;
444
#endif /* UNIV_HOTBACKUP */
445
/** Maximum page number encountered in the redo log */
446
extern ulint recv_max_parsed_page_no;
448
/** Size of the parsing buffer; it must accommodate RECV_SCAN_SIZE many
450
#define RECV_PARSING_BUF_SIZE (2 * 1024 * 1024)
452
/** Size of block reads when the log groups are scanned forward to do a
454
#define RECV_SCAN_SIZE (4 * UNIV_PAGE_SIZE)
456
/** This many frames must be left free in the buffer pool when we scan
457
the log and store the scanned log records in the buffer pool: we will
458
use these free frames to read in pages when we start applying the
459
log records to the database. */
460
extern ulint recv_n_pool_free_frames;
463
#include "log0recv.ic"