~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Tags: innodb-plugin-1.0.1
Imported 1.0.1 with clean - with no changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************
 
2
Recovery
 
3
 
 
4
(c) 1997 Innobase Oy
 
5
 
 
6
Created 9/20/1997 Heikki Tuuri
 
7
*******************************************************/
 
8
 
 
9
#ifndef log0recv_h
 
10
#define log0recv_h
 
11
 
 
12
#include "univ.i"
 
13
#include "ut0byte.h"
 
14
#include "buf0types.h"
 
15
#include "hash0hash.h"
 
16
#include "log0log.h"
 
17
 
 
18
#ifdef UNIV_HOTBACKUP
 
19
extern ibool    recv_replay_file_ops;
 
20
#endif /* UNIV_HOTBACKUP */
 
21
 
 
22
/***********************************************************************
 
23
Reads the checkpoint info needed in hot backup. */
 
24
UNIV_INTERN
 
25
ibool
 
26
recv_read_cp_info_for_backup(
 
27
/*=========================*/
 
28
                                /* out: TRUE if success */
 
29
        byte*           hdr,    /* in: buffer containing the log group
 
30
                                header */
 
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
 
39
                                first log file */
 
40
/***********************************************************************
 
41
Scans the log segment and n_bytes_scanned is set to the length of valid
 
42
log scanned. */
 
43
UNIV_INTERN
 
44
void
 
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
 
54
                                        far */
 
55
        ulint*          n_bytes_scanned);/* out: how much we were able to
 
56
                                        scan, smaller than buf_len if log
 
57
                                        data ended here */
 
58
/***********************************************************************
 
59
Returns TRUE if recovery is currently running. */
 
60
UNIV_INLINE
 
61
ibool
 
62
recv_recovery_is_on(void);
 
63
/*=====================*/
 
64
/***********************************************************************
 
65
Returns TRUE if recovery from backup is currently running. */
 
66
UNIV_INLINE
 
67
ibool
 
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. */
 
74
UNIV_INTERN
 
75
void
 
76
recv_recover_page(
 
77
/*==============*/
 
78
        ibool           recover_backup,
 
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
 
82
                                buffer pool */
 
83
        ibool           just_read_in,
 
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. */
 
92
UNIV_INTERN
 
93
ulint
 
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
 
99
                                        if possible */
 
100
        ib_uint64_t     min_flushed_lsn,/* in: min flushed lsn from
 
101
                                        data files */
 
102
        ib_uint64_t     max_flushed_lsn);/* in: max flushed lsn from
 
103
                                         data files */
 
104
/************************************************************
 
105
Completes recovery from a checkpoint. */
 
106
UNIV_INTERN
 
107
void
 
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. */
 
113
UNIV_INTERN
 
114
ibool
 
115
recv_scan_log_recs(
 
116
/*===============*/
 
117
                                        /* out: TRUE if limit_lsn has been
 
118
                                        reached, or not able to scan any more
 
119
                                        in this log group */
 
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
 
125
                                        function */
 
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
 
131
                                        needed */
 
132
        byte*           buf,            /* in: buffer containing a log segment
 
133
                                        or garbage */
 
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
 
138
                                        to this lsn */
 
139
        ib_uint64_t*    group_scanned_lsn);/* out: scanning succeeded up to
 
140
                                        this lsn */
 
141
/**********************************************************
 
142
Resets the logs. The contents of log files will be lost! */
 
143
UNIV_INTERN
 
144
void
 
145
recv_reset_logs(
 
146
/*============*/
 
147
        ib_uint64_t     lsn,            /* in: reset to this lsn
 
148
                                        rounded up to be divisible by
 
149
                                        OS_FILE_LOG_BLOCK_SIZE, after
 
150
                                        which we add
 
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
 
158
                                        archive recovery */
 
159
#ifdef UNIV_HOTBACKUP
 
160
/**********************************************************
 
161
Creates new log files after a backup has been restored. */
 
162
UNIV_INTERN
 
163
void
 
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. */
 
174
UNIV_INTERN
 
175
void
 
176
recv_sys_create(void);
 
177
/*=================*/
 
178
/************************************************************
 
179
Inits the recovery system for a recovery operation. */
 
180
UNIV_INTERN
 
181
void
 
182
recv_sys_init(
 
183
/*==========*/
 
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
 
189
pages. */
 
190
UNIV_INTERN
 
191
void
 
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. */
 
204
UNIV_INTERN
 
205
void
 
206
recv_apply_log_recs_for_backup(void);
 
207
/*================================*/
 
208
#endif
 
209
#ifdef UNIV_LOG_ARCHIVE
 
210
/************************************************************
 
211
Recovers from archived log files, and also from log files, if they exist. */
 
212
UNIV_INTERN
 
213
ulint
 
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
 
218
                                        data files */
 
219
        ib_uint64_t     limit_lsn,      /* in: recover up to this lsn if
 
220
                                        possible */
 
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. */
 
228
UNIV_INTERN
 
229
void
 
230
recv_recovery_from_archive_finish(void);
 
231
/*===================================*/
 
232
#endif /* UNIV_LOG_ARCHIVE */
 
233
 
 
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 */
 
241
};
 
242
 
 
243
/* Stored log record struct */
 
244
typedef struct recv_struct      recv_t;
 
245
struct recv_struct{
 
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
 
249
                                body */
 
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
 
253
                                this log record */
 
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
 
257
                                this log record */
 
258
        UT_LIST_NODE_T(recv_t)
 
259
                        rec_list;/* list of log records for this page */
 
260
};
 
261
 
 
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,
 
266
                                or RECV_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;
 
272
};
 
273
 
 
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
 
279
                                struct */
 
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
 
284
                                application */
 
285
        ibool           apply_batch_on;
 
286
                                /* this is TRUE when a log rec application
 
287
                                batch is running */
 
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 */
 
292
        byte*           last_block;
 
293
                                /* possible incomplete last recovered log
 
294
                                block */
 
295
        byte*           last_block_buf_start;
 
296
                                /* the nonaligned start address of the
 
297
                                preceding buffer */
 
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
 
307
                                lsn */
 
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
 
313
                                buf */
 
314
        ib_uint64_t     recovered_lsn;
 
315
                                /* the log records have been parsed up to
 
316
                                this lsn */
 
317
        ib_uint64_t     limit_lsn;/* recovery should be made at most up to this
 
318
                                lsn */
 
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
 
323
                                buffer overflow */
 
324
        log_group_t*    archive_group;
 
325
                                /* in archive recovery: the log group whose
 
326
                                archive is read */
 
327
        mem_heap_t*     heap;   /* memory heap of log records and file
 
328
                                addresses*/
 
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 */
 
332
};
 
333
 
 
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;
 
338
 
 
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;
 
344
 
 
345
/* Size of the parsing buffer; it must accommodate RECV_SCAN_SIZE many
 
346
times! */
 
347
#define RECV_PARSING_BUF_SIZE   (2 * 1024 * 1024)
 
348
 
 
349
/* Size of block reads when the log groups are scanned forward to do a
 
350
roll-forward */
 
351
#define RECV_SCAN_SIZE          (4 * UNIV_PAGE_SIZE)
 
352
 
 
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
 
358
 
 
359
extern ulint    recv_n_pool_free_frames;
 
360
 
 
361
#ifndef UNIV_NONINL
 
362
#include "log0recv.ic"
 
363
#endif
 
364
 
 
365
#endif