1
/******************************************************
6
Created 9/20/1997 Heikki Tuuri
7
*******************************************************/
14
#include "buf0types.h"
15
#include "hash0hash.h"
19
extern ibool recv_replay_file_ops;
20
#endif /* UNIV_HOTBACKUP */
22
/***********************************************************************
23
Reads the checkpoint info needed in hot backup. */
26
recv_read_cp_info_for_backup(
27
/*=========================*/
28
/* out: TRUE if success */
29
byte* hdr, /* in: buffer containing the log group
31
ib_uint64_t* lsn, /* out: checkpoint lsn */
32
ulint* offset, /* out: checkpoint offset in the log group */
33
ulint* fsp_limit,/* out: fsp limit of space 0,
34
1000000000 if the database is running
35
with < version 3.23.50 of InnoDB */
36
ib_uint64_t* cp_no, /* out: checkpoint number */
37
ib_uint64_t* first_header_lsn);
38
/* out: lsn of of the start of the
40
/***********************************************************************
41
Scans the log segment and n_bytes_scanned is set to the length of valid
45
recv_scan_log_seg_for_backup(
46
/*=========================*/
47
byte* buf, /* in: buffer containing log data */
48
ulint buf_len, /* in: data length in that buffer */
49
ib_uint64_t* scanned_lsn, /* in/out: lsn of buffer start,
50
we return scanned lsn */
51
ulint* scanned_checkpoint_no,
52
/* in/out: 4 lowest bytes of the
53
highest scanned checkpoint number so
55
ulint* n_bytes_scanned);/* out: how much we were able to
56
scan, smaller than buf_len if log
58
/***********************************************************************
59
Returns TRUE if recovery is currently running. */
62
recv_recovery_is_on(void);
63
/*=====================*/
64
/***********************************************************************
65
Returns TRUE if recovery from backup is currently running. */
68
recv_recovery_from_backup_is_on(void);
69
/*=================================*/
70
/****************************************************************************
71
Applies the hashed log records to the page, if the page lsn is less than the
72
lsn of a log record. This can be called when a buffer page has just been
73
read in, or also for a page already in the buffer pool. */
79
/* in: TRUE if we are recovering a backup
80
page: then we do not acquire any latches
81
since the page was read in outside the
84
/* in: TRUE if the i/o-handler calls this for
85
a freshly read page */
86
buf_block_t* block); /* in: buffer block */
87
/************************************************************
88
Recovers from a checkpoint. When this function returns, the database is able
89
to start processing of new user transactions, but the function
90
recv_recovery_from_checkpoint_finish should be called later to complete
91
the recovery and free the resources used in it. */
94
recv_recovery_from_checkpoint_start(
95
/*================================*/
96
/* out: error code or DB_SUCCESS */
97
ulint type, /* in: LOG_CHECKPOINT or LOG_ARCHIVE */
98
ib_uint64_t limit_lsn, /* in: recover up to this lsn
100
ib_uint64_t min_flushed_lsn,/* in: min flushed lsn from
102
ib_uint64_t max_flushed_lsn);/* in: max flushed lsn from
104
/************************************************************
105
Completes recovery from a checkpoint. */
108
recv_recovery_from_checkpoint_finish(void);
109
/*======================================*/
110
/***********************************************************
111
Scans log from a buffer and stores new log data to the parsing buffer. Parses
112
and hashes the log records if new data found. */
117
/* out: TRUE if limit_lsn has been
118
reached, or not able to scan any more
120
ibool apply_automatically,/* in: TRUE if we want this
121
function to apply log records
122
automatically when the hash table
123
becomes full; in the hot backup tool
124
the tool does the applying, not this
126
ulint available_memory,/* in: we let the hash table of recs
127
to grow to this size, at the maximum */
128
ibool store_to_hash, /* in: TRUE if the records should be
129
stored to the hash table; this is set
130
to FALSE if just debug checking is
132
byte* buf, /* in: buffer containing a log segment
134
ulint len, /* in: buffer length */
135
ib_uint64_t start_lsn, /* in: buffer start lsn */
136
ib_uint64_t* contiguous_lsn, /* in/out: it is known that all log
137
groups contain contiguous log data up
139
ib_uint64_t* group_scanned_lsn);/* out: scanning succeeded up to
141
/**********************************************************
142
Resets the logs. The contents of log files will be lost! */
147
ib_uint64_t lsn, /* in: reset to this lsn
148
rounded up to be divisible by
149
OS_FILE_LOG_BLOCK_SIZE, after
151
LOG_BLOCK_HDR_SIZE */
152
#ifdef UNIV_LOG_ARCHIVE
153
ulint arch_log_no, /* in: next archived log file number */
154
#endif /* UNIV_LOG_ARCHIVE */
155
ibool new_logs_created);/* in: TRUE if resetting logs
156
is done at the log creation;
157
FALSE if it is done after
159
#ifdef UNIV_HOTBACKUP
160
/**********************************************************
161
Creates new log files after a backup has been restored. */
164
recv_reset_log_files_for_backup(
165
/*============================*/
166
const char* log_dir, /* in: log file directory path */
167
ulint n_log_files, /* in: number of log files */
168
ulint log_file_size, /* in: log file size */
169
ib_uint64_t lsn); /* in: new start lsn, must be
170
divisible by OS_FILE_LOG_BLOCK_SIZE */
171
#endif /* UNIV_HOTBACKUP */
172
/************************************************************
173
Creates the recovery system. */
176
recv_sys_create(void);
177
/*=================*/
178
/************************************************************
179
Inits the recovery system for a recovery operation. */
184
ibool recover_from_backup, /* in: TRUE if this is called
185
to recover from a hot backup */
186
ulint available_memory); /* in: available memory in bytes */
187
/***********************************************************************
188
Empties the hash table of stored log records, applying them to appropriate
192
recv_apply_hashed_log_recs(
193
/*=======================*/
194
ibool allow_ibuf); /* in: if TRUE, also ibuf operations are
195
allowed during the application; if FALSE,
196
no ibuf operations are allowed, and after
197
the application all file pages are flushed to
198
disk and invalidated in buffer pool: this
199
alternative means that no new log records
200
can be generated during the application */
201
#ifdef UNIV_HOTBACKUP
202
/***********************************************************************
203
Applies log records in the hash table to a backup. */
206
recv_apply_log_recs_for_backup(void);
207
/*================================*/
209
#ifdef UNIV_LOG_ARCHIVE
210
/************************************************************
211
Recovers from archived log files, and also from log files, if they exist. */
214
recv_recovery_from_archive_start(
215
/*=============================*/
216
/* out: error code or DB_SUCCESS */
217
ib_uint64_t min_flushed_lsn,/* in: min flushed lsn field from the
219
ib_uint64_t limit_lsn, /* in: recover up to this lsn if
221
ulint first_log_no); /* in: number of the first archived
222
log file to use in the recovery; the
223
file will be searched from
224
INNOBASE_LOG_ARCH_DIR specified in
225
server config file */
226
/************************************************************
227
Completes recovery from archive. */
230
recv_recovery_from_archive_finish(void);
231
/*===================================*/
232
#endif /* UNIV_LOG_ARCHIVE */
234
/* Block of log record data */
235
typedef struct recv_data_struct recv_data_t;
236
struct recv_data_struct{
237
recv_data_t* next; /* pointer to the next block or NULL */
238
/* the log record data is stored physically
239
immediately after this struct, max amount
240
RECV_DATA_BLOCK_SIZE bytes of it */
243
/* Stored log record struct */
244
typedef struct recv_struct recv_t;
246
byte type; /* log record type */
247
ulint len; /* log record body length in bytes */
248
recv_data_t* data; /* chain of blocks containing the log record
250
ib_uint64_t start_lsn;/* start lsn of the log segment written by
251
the mtr which generated this log record: NOTE
252
that this is not necessarily the start lsn of
254
ib_uint64_t end_lsn;/* end lsn of the log segment written by
255
the mtr which generated this log record: NOTE
256
that this is not necessarily the end lsn of
258
UT_LIST_NODE_T(recv_t)
259
rec_list;/* list of log records for this page */
262
/* Hashed page file address struct */
263
typedef struct recv_addr_struct recv_addr_t;
264
struct recv_addr_struct{
265
ulint state; /* RECV_NOT_PROCESSED, RECV_BEING_PROCESSED,
267
ulint space; /* space id */
268
ulint page_no;/* page number */
269
UT_LIST_BASE_NODE_T(recv_t)
270
rec_list;/* list of log records for this page */
271
hash_node_t addr_hash;
274
/* Recovery system data structure */
275
typedef struct recv_sys_struct recv_sys_t;
276
struct recv_sys_struct{
277
mutex_t mutex; /* mutex protecting the fields apply_log_recs,
278
n_addrs, and the state field in each recv_addr
280
ibool apply_log_recs;
281
/* this is TRUE when log rec application to
282
pages is allowed; this flag tells the
283
i/o-handler if it should do log record
285
ibool apply_batch_on;
286
/* this is TRUE when a log rec application
288
ib_uint64_t lsn; /* log sequence number */
289
ulint last_log_buf_size;
290
/* size of the log buffer when the database
291
last time wrote to the log */
293
/* possible incomplete last recovered log
295
byte* last_block_buf_start;
296
/* the nonaligned start address of the
298
byte* buf; /* buffer for parsing log records */
299
ulint len; /* amount of data in buf */
300
ib_uint64_t parse_start_lsn;
301
/* this is the lsn from which we were able to
302
start parsing log records and adding them to
303
the hash table; zero if a suitable
304
start point not found yet */
305
ib_uint64_t scanned_lsn;
306
/* the log data has been scanned up to this
308
ulint scanned_checkpoint_no;
309
/* the log data has been scanned up to this
310
checkpoint number (lowest 4 bytes) */
311
ulint recovered_offset;
312
/* start offset of non-parsed log records in
314
ib_uint64_t recovered_lsn;
315
/* the log records have been parsed up to
317
ib_uint64_t limit_lsn;/* recovery should be made at most up to this
319
ibool found_corrupt_log;
320
/* this is set to TRUE if we during log
321
scan find a corrupt log block, or a corrupt
322
log record, or there is a log parsing
324
log_group_t* archive_group;
325
/* in archive recovery: the log group whose
327
mem_heap_t* heap; /* memory heap of log records and file
329
hash_table_t* addr_hash;/* hash table of file addresses of pages */
330
ulint n_addrs;/* number of not processed hashed file
331
addresses in the hash table */
334
extern recv_sys_t* recv_sys;
335
extern ibool recv_recovery_on;
336
extern ibool recv_no_ibuf_operations;
337
extern ibool recv_needed_recovery;
339
extern ibool recv_lsn_checks_on;
340
#ifdef UNIV_HOTBACKUP
341
extern ibool recv_is_making_a_backup;
342
#endif /* UNIV_HOTBACKUP */
343
extern ulint recv_max_parsed_page_no;
345
/* Size of the parsing buffer; it must accommodate RECV_SCAN_SIZE many
347
#define RECV_PARSING_BUF_SIZE (2 * 1024 * 1024)
349
/* Size of block reads when the log groups are scanned forward to do a
351
#define RECV_SCAN_SIZE (4 * UNIV_PAGE_SIZE)
353
/* States of recv_addr_struct */
354
#define RECV_NOT_PROCESSED 71
355
#define RECV_BEING_READ 72
356
#define RECV_BEING_PROCESSED 73
357
#define RECV_PROCESSED 74
359
extern ulint recv_n_pool_free_frames;
362
#include "log0recv.ic"