1
/*****************************************************************************
3
Copyright (c) 1997, 2010, 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., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 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
Initiates the rollback of active transactions. */
183
recv_recovery_rollback_active(void);
184
/*===============================*/
185
/*******************************************************//**
186
Scans log from a buffer and stores new log data to the parsing buffer.
187
Parses and hashes the log records if new data found. Unless
188
UNIV_HOTBACKUP is defined, this function will apply log records
189
automatically when the hash table becomes full.
190
@return TRUE if limit_lsn has been reached, or not able to scan any
191
more in this log group */
196
ulint available_memory,/*!< in: we let the hash table of recs
197
to grow to this size, at the maximum */
198
ibool store_to_hash, /*!< in: TRUE if the records should be
199
stored to the hash table; this is set
200
to FALSE if just debug checking is
202
const byte* buf, /*!< in: buffer containing a log
203
segment or garbage */
204
ulint len, /*!< in: buffer length */
205
ib_uint64_t start_lsn, /*!< in: buffer start lsn */
206
ib_uint64_t* contiguous_lsn, /*!< in/out: it is known that all log
207
groups contain contiguous log data up
209
ib_uint64_t* group_scanned_lsn);/*!< out: scanning succeeded up to
211
/******************************************************//**
212
Resets the logs. The contents of log files will be lost! */
217
ib_uint64_t lsn, /*!< in: reset to this lsn
218
rounded up to be divisible by
219
OS_FILE_LOG_BLOCK_SIZE, after
221
LOG_BLOCK_HDR_SIZE */
222
#ifdef UNIV_LOG_ARCHIVE
223
ulint arch_log_no, /*!< in: next archived log file number */
224
#endif /* UNIV_LOG_ARCHIVE */
225
ibool new_logs_created);/*!< in: TRUE if resetting logs
226
is done at the log creation;
227
FALSE if it is done after
229
#ifdef UNIV_HOTBACKUP
230
/******************************************************//**
231
Creates new log files after a backup has been restored. */
234
recv_reset_log_files_for_backup(
235
/*============================*/
236
const char* log_dir, /*!< in: log file directory path */
237
ulint n_log_files, /*!< in: number of log files */
238
ulint log_file_size, /*!< in: log file size */
239
ib_uint64_t lsn); /*!< in: new start lsn, must be
240
divisible by OS_FILE_LOG_BLOCK_SIZE */
241
#endif /* UNIV_HOTBACKUP */
242
/********************************************************//**
243
Creates the recovery system. */
246
recv_sys_create(void);
247
/*=================*/
248
/**********************************************************//**
249
Release recovery system mutexes. */
252
recv_sys_close(void);
254
/********************************************************//**
255
Frees the recovery system memory. */
258
recv_sys_mem_free(void);
259
/*===================*/
260
/********************************************************//**
261
Inits the recovery system for a recovery operation. */
266
ulint available_memory); /*!< in: available memory in bytes */
267
#ifndef UNIV_HOTBACKUP
268
/********************************************************//**
269
Reset the state of the recovery system variables. */
272
recv_sys_var_init(void);
273
/*===================*/
274
#endif /* !UNIV_HOTBACKUP */
275
/*******************************************************************//**
276
Empties the hash table of stored log records, applying them to appropriate
280
recv_apply_hashed_log_recs(
281
/*=======================*/
282
ibool allow_ibuf); /*!< in: if TRUE, also ibuf operations are
283
allowed during the application; if FALSE,
284
no ibuf operations are allowed, and after
285
the application all file pages are flushed to
286
disk and invalidated in buffer pool: this
287
alternative means that no new log records
288
can be generated during the application */
289
#ifdef UNIV_HOTBACKUP
290
/*******************************************************************//**
291
Applies log records in the hash table to a backup. */
294
recv_apply_log_recs_for_backup(void);
295
/*================================*/
297
#ifdef UNIV_LOG_ARCHIVE
298
/********************************************************//**
299
Recovers from archived log files, and also from log files, if they exist.
300
@return error code or DB_SUCCESS */
303
recv_recovery_from_archive_start(
304
/*=============================*/
305
ib_uint64_t min_flushed_lsn,/*!< in: min flushed lsn field from the
307
ib_uint64_t limit_lsn, /*!< in: recover up to this lsn if
309
ulint first_log_no); /*!< in: number of the first archived
310
log file to use in the recovery; the
311
file will be searched from
312
INNOBASE_LOG_ARCH_DIR specified in
313
server config file */
314
/********************************************************//**
315
Completes recovery from archive. */
318
recv_recovery_from_archive_finish(void);
319
/*===================================*/
320
#endif /* UNIV_LOG_ARCHIVE */
322
/** Block of log record data */
323
typedef struct recv_data_struct recv_data_t;
324
/** Block of log record data */
325
struct recv_data_struct{
326
recv_data_t* next; /*!< pointer to the next block or NULL */
327
/*!< the log record data is stored physically
328
immediately after this struct, max amount
329
RECV_DATA_BLOCK_SIZE bytes of it */
332
/** Stored log record struct */
333
typedef struct recv_struct recv_t;
334
/** Stored log record struct */
336
byte type; /*!< log record type */
337
ulint len; /*!< log record body length in bytes */
338
recv_data_t* data; /*!< chain of blocks containing the log record
340
ib_uint64_t start_lsn;/*!< start lsn of the log segment written by
341
the mtr which generated this log record: NOTE
342
that this is not necessarily the start lsn of
344
ib_uint64_t end_lsn;/*!< end lsn of the log segment written by
345
the mtr which generated this log record: NOTE
346
that this is not necessarily the end lsn of
348
UT_LIST_NODE_T(recv_t)
349
rec_list;/*!< list of log records for this page */
352
/** States of recv_addr_struct */
353
enum recv_addr_state {
354
/** not yet processed */
356
/** page is being read */
358
/** log records are being applied on the page */
359
RECV_BEING_PROCESSED,
360
/** log records have been applied on the page, or they have
361
been discarded because the tablespace does not exist */
365
/** Hashed page file address struct */
366
typedef struct recv_addr_struct recv_addr_t;
367
/** Hashed page file address struct */
368
struct recv_addr_struct{
369
enum recv_addr_state state;
370
/*!< recovery state of the page */
371
unsigned space:32;/*!< space id */
372
unsigned page_no:32;/*!< page number */
373
UT_LIST_BASE_NODE_T(recv_t)
374
rec_list;/*!< list of log records for this page */
375
hash_node_t addr_hash;/*!< hash node in the hash bucket chain */
378
/** Recovery system data structure */
379
typedef struct recv_sys_struct recv_sys_t;
380
/** Recovery system data structure */
381
struct recv_sys_struct{
382
#ifndef UNIV_HOTBACKUP
383
mutex_t mutex; /*!< mutex protecting the fields apply_log_recs,
384
n_addrs, and the state field in each recv_addr
386
#endif /* !UNIV_HOTBACKUP */
387
ibool apply_log_recs;
388
/*!< this is TRUE when log rec application to
389
pages is allowed; this flag tells the
390
i/o-handler if it should do log record
392
ibool apply_batch_on;
393
/*!< this is TRUE when a log rec application
395
ib_uint64_t lsn; /*!< log sequence number */
396
ulint last_log_buf_size;
397
/*!< size of the log buffer when the database
398
last time wrote to the log */
400
/*!< possible incomplete last recovered log
402
byte* last_block_buf_start;
403
/*!< the nonaligned start address of the
405
byte* buf; /*!< buffer for parsing log records */
406
ulint len; /*!< amount of data in buf */
407
ib_uint64_t parse_start_lsn;
408
/*!< this is the lsn from which we were able to
409
start parsing log records and adding them to
410
the hash table; zero if a suitable
411
start point not found yet */
412
ib_uint64_t scanned_lsn;
413
/*!< the log data has been scanned up to this
415
ulint scanned_checkpoint_no;
416
/*!< the log data has been scanned up to this
417
checkpoint number (lowest 4 bytes) */
418
ulint recovered_offset;
419
/*!< start offset of non-parsed log records in
421
ib_uint64_t recovered_lsn;
422
/*!< the log records have been parsed up to
424
ib_uint64_t limit_lsn;/*!< recovery should be made at most
426
ibool found_corrupt_log;
427
/*!< this is set to TRUE if we during log
428
scan find a corrupt log block, or a corrupt
429
log record, or there is a log parsing
431
#ifdef UNIV_LOG_ARCHIVE
432
log_group_t* archive_group;
433
/*!< in archive recovery: the log group whose
435
#endif /* !UNIV_LOG_ARCHIVE */
436
mem_heap_t* heap; /*!< memory heap of log records and file
438
hash_table_t* addr_hash;/*!< hash table of file addresses of pages */
439
ulint n_addrs;/*!< number of not processed hashed file
440
addresses in the hash table */
443
/** The recovery system */
444
extern recv_sys_t* recv_sys;
446
/** TRUE when applying redo log records during crash recovery; FALSE
447
otherwise. Note that this is FALSE while a background thread is
448
rolling back incomplete transactions. */
449
extern ibool recv_recovery_on;
450
/** If the following is TRUE, the buffer pool file pages must be invalidated
451
after recovery and no ibuf operations are allowed; this becomes TRUE if
452
the log record hash table becomes too full, and log records must be merged
453
to file pages already before the recovery is finished: in this case no
454
ibuf operations are allowed, as they could modify the pages read in the
455
buffer pool before the pages have been recovered to the up-to-date state.
457
TRUE means that recovery is running and no operations on the log files
458
are allowed yet: the variable name is misleading. */
459
extern ibool recv_no_ibuf_operations;
460
/** TRUE when recv_init_crash_recovery() has been called. */
461
extern ibool recv_needed_recovery;
463
/** TRUE if writing to the redo log (mtr_commit) is forbidden.
464
Protected by log_sys->mutex. */
465
extern ibool recv_no_log_write;
466
#endif /* UNIV_DEBUG */
468
/** TRUE if buf_page_is_corrupted() should check if the log sequence
469
number (FIL_PAGE_LSN) is in the future. Initially FALSE, and set by
470
recv_recovery_from_checkpoint_start_func(). */
471
extern ibool recv_lsn_checks_on;
472
#ifdef UNIV_HOTBACKUP
473
/** TRUE when the redo log is being backed up */
474
extern ibool recv_is_making_a_backup;
475
#endif /* UNIV_HOTBACKUP */
476
/** Maximum page number encountered in the redo log */
477
extern ulint recv_max_parsed_page_no;
479
/** Size of the parsing buffer; it must accommodate RECV_SCAN_SIZE many
481
#define RECV_PARSING_BUF_SIZE (2 * 1024 * 1024)
483
/** Size of block reads when the log groups are scanned forward to do a
485
#define RECV_SCAN_SIZE (4 * UNIV_PAGE_SIZE)
487
/** This many frames must be left free in the buffer pool when we scan
488
the log and store the scanned log records in the buffer pool: we will
489
use these free frames to read in pages when we start applying the
490
log records to the database. */
491
extern ulint recv_n_pool_free_frames;
494
#include "log0recv.ic"