00001 /****************************************************** 00002 Recovery 00003 00004 (c) 1997 Innobase Oy 00005 00006 Created 9/20/1997 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef log0recv_h 00010 #define log0recv_h 00011 00012 #include "univ.i" 00013 #include "ut0byte.h" 00014 #include "page0types.h" 00015 #include "hash0hash.h" 00016 #include "log0log.h" 00017 00018 #ifdef UNIV_HOTBACKUP 00019 extern ibool recv_replay_file_ops; 00020 #endif /* UNIV_HOTBACKUP */ 00021 00022 /*********************************************************************** 00023 Reads the checkpoint info needed in hot backup. */ 00024 00025 ibool 00026 recv_read_cp_info_for_backup( 00027 /*=========================*/ 00028 /* out: TRUE if success */ 00029 byte* hdr, /* in: buffer containing the log group header */ 00030 dulint* lsn, /* out: checkpoint lsn */ 00031 ulint* offset, /* out: checkpoint offset in the log group */ 00032 ulint* fsp_limit,/* out: fsp limit of space 0, 1000000000 if the 00033 database is running with < version 3.23.50 of InnoDB */ 00034 dulint* cp_no, /* out: checkpoint number */ 00035 dulint* first_header_lsn); 00036 /* out: lsn of of the start of the first log file */ 00037 /*********************************************************************** 00038 Scans the log segment and n_bytes_scanned is set to the length of valid 00039 log scanned. */ 00040 00041 void 00042 recv_scan_log_seg_for_backup( 00043 /*=========================*/ 00044 byte* buf, /* in: buffer containing log data */ 00045 ulint buf_len, /* in: data length in that buffer */ 00046 dulint* scanned_lsn, /* in/out: lsn of buffer start, 00047 we return scanned lsn */ 00048 ulint* scanned_checkpoint_no, 00049 /* in/out: 4 lowest bytes of the 00050 highest scanned checkpoint number so 00051 far */ 00052 ulint* n_bytes_scanned);/* out: how much we were able to 00053 scan, smaller than buf_len if log 00054 data ended here */ 00055 /*********************************************************************** 00056 Returns TRUE if recovery is currently running. */ 00057 UNIV_INLINE 00058 ibool 00059 recv_recovery_is_on(void); 00060 /*=====================*/ 00061 /*********************************************************************** 00062 Returns TRUE if recovery from backup is currently running. */ 00063 UNIV_INLINE 00064 ibool 00065 recv_recovery_from_backup_is_on(void); 00066 /*=================================*/ 00067 /**************************************************************************** 00068 Applies the hashed log records to the page, if the page lsn is less than the 00069 lsn of a log record. This can be called when a buffer page has just been 00070 read in, or also for a page already in the buffer pool. */ 00071 00072 void 00073 recv_recover_page( 00074 /*==============*/ 00075 ibool recover_backup, /* in: TRUE if we are recovering a backup 00076 page: then we do not acquire any latches 00077 since the page was read in outside the 00078 buffer pool */ 00079 ibool just_read_in, /* in: TRUE if the i/o-handler calls this for 00080 a freshly read page */ 00081 page_t* page, /* in: buffer page */ 00082 ulint space, /* in: space id */ 00083 ulint page_no); /* in: page number */ 00084 /************************************************************ 00085 Recovers from a checkpoint. When this function returns, the database is able 00086 to start processing of new user transactions, but the function 00087 recv_recovery_from_checkpoint_finish should be called later to complete 00088 the recovery and free the resources used in it. */ 00089 00090 ulint 00091 recv_recovery_from_checkpoint_start( 00092 /*================================*/ 00093 /* out: error code or DB_SUCCESS */ 00094 ulint type, /* in: LOG_CHECKPOINT or LOG_ARCHIVE */ 00095 dulint limit_lsn, /* in: recover up to this lsn if possible */ 00096 dulint min_flushed_lsn,/* in: min flushed lsn from data files */ 00097 dulint max_flushed_lsn);/* in: max flushed lsn from data files */ 00098 /************************************************************ 00099 Completes recovery from a checkpoint. */ 00100 00101 void 00102 recv_recovery_from_checkpoint_finish(void); 00103 /*======================================*/ 00104 /*********************************************************** 00105 Scans log from a buffer and stores new log data to the parsing buffer. Parses 00106 and hashes the log records if new data found. */ 00107 00108 ibool 00109 recv_scan_log_recs( 00110 /*===============*/ 00111 /* out: TRUE if limit_lsn has been reached, or 00112 not able to scan any more in this log group */ 00113 ibool apply_automatically,/* in: TRUE if we want this function to 00114 apply log records automatically when the 00115 hash table becomes full; in the hot backup tool 00116 the tool does the applying, not this 00117 function */ 00118 ulint available_memory,/* in: we let the hash table of recs to grow 00119 to this size, at the maximum */ 00120 ibool store_to_hash, /* in: TRUE if the records should be stored 00121 to the hash table; this is set to FALSE if just 00122 debug checking is needed */ 00123 byte* buf, /* in: buffer containing a log segment or 00124 garbage */ 00125 ulint len, /* in: buffer length */ 00126 dulint start_lsn, /* in: buffer start lsn */ 00127 dulint* contiguous_lsn, /* in/out: it is known that all log groups 00128 contain contiguous log data up to this lsn */ 00129 dulint* group_scanned_lsn);/* out: scanning succeeded up to this lsn */ 00130 /********************************************************** 00131 Resets the logs. The contents of log files will be lost! */ 00132 00133 void 00134 recv_reset_logs( 00135 /*============*/ 00136 dulint lsn, /* in: reset to this lsn rounded up to 00137 be divisible by OS_FILE_LOG_BLOCK_SIZE, 00138 after which we add LOG_BLOCK_HDR_SIZE */ 00139 #ifdef UNIV_LOG_ARCHIVE 00140 ulint arch_log_no, /* in: next archived log file number */ 00141 #endif /* UNIV_LOG_ARCHIVE */ 00142 ibool new_logs_created);/* in: TRUE if resetting logs is done 00143 at the log creation; FALSE if it is done 00144 after archive recovery */ 00145 #ifdef UNIV_HOTBACKUP 00146 /********************************************************** 00147 Creates new log files after a backup has been restored. */ 00148 00149 void 00150 recv_reset_log_files_for_backup( 00151 /*============================*/ 00152 const char* log_dir, /* in: log file directory path */ 00153 ulint n_log_files, /* in: number of log files */ 00154 ulint log_file_size, /* in: log file size */ 00155 dulint lsn); /* in: new start lsn, must be 00156 divisible by OS_FILE_LOG_BLOCK_SIZE */ 00157 #endif /* UNIV_HOTBACKUP */ 00158 /************************************************************ 00159 Creates the recovery system. */ 00160 00161 void 00162 recv_sys_create(void); 00163 /*=================*/ 00164 /************************************************************ 00165 Inits the recovery system for a recovery operation. */ 00166 00167 void 00168 recv_sys_init( 00169 /*==========*/ 00170 ibool recover_from_backup, /* in: TRUE if this is called 00171 to recover from a hot backup */ 00172 ulint available_memory); /* in: available memory in bytes */ 00173 /*********************************************************************** 00174 Empties the hash table of stored log records, applying them to appropriate 00175 pages. */ 00176 00177 void 00178 recv_apply_hashed_log_recs( 00179 /*=======================*/ 00180 ibool allow_ibuf); /* in: if TRUE, also ibuf operations are 00181 allowed during the application; if FALSE, 00182 no ibuf operations are allowed, and after 00183 the application all file pages are flushed to 00184 disk and invalidated in buffer pool: this 00185 alternative means that no new log records 00186 can be generated during the application */ 00187 #ifdef UNIV_HOTBACKUP 00188 /*********************************************************************** 00189 Applies log records in the hash table to a backup. */ 00190 00191 void 00192 recv_apply_log_recs_for_backup(void); 00193 /*================================*/ 00194 #endif 00195 #ifdef UNIV_LOG_ARCHIVE 00196 /************************************************************ 00197 Recovers from archived log files, and also from log files, if they exist. */ 00198 00199 ulint 00200 recv_recovery_from_archive_start( 00201 /*=============================*/ 00202 /* out: error code or DB_SUCCESS */ 00203 dulint min_flushed_lsn,/* in: min flushed lsn field from the 00204 data files */ 00205 dulint limit_lsn, /* in: recover up to this lsn if possible */ 00206 ulint first_log_no); /* in: number of the first archived log file 00207 to use in the recovery; the file will be 00208 searched from INNOBASE_LOG_ARCH_DIR specified 00209 in server config file */ 00210 /************************************************************ 00211 Completes recovery from archive. */ 00212 00213 void 00214 recv_recovery_from_archive_finish(void); 00215 /*===================================*/ 00216 #endif /* UNIV_LOG_ARCHIVE */ 00217 /*********************************************************************** 00218 Checks that a replica of a space is identical to the original space. */ 00219 00220 void 00221 recv_compare_spaces( 00222 /*================*/ 00223 ulint space1, /* in: space id */ 00224 ulint space2, /* in: space id */ 00225 ulint n_pages);/* in: number of pages */ 00226 /*********************************************************************** 00227 Checks that a replica of a space is identical to the original space. Disables 00228 ibuf operations and flushes and invalidates the buffer pool pages after the 00229 test. This function can be used to check the recovery before dict or trx 00230 systems are initialized. */ 00231 00232 void 00233 recv_compare_spaces_low( 00234 /*====================*/ 00235 ulint space1, /* in: space id */ 00236 ulint space2, /* in: space id */ 00237 ulint n_pages);/* in: number of pages */ 00238 00239 /* Block of log record data */ 00240 typedef struct recv_data_struct recv_data_t; 00241 struct recv_data_struct{ 00242 recv_data_t* next; /* pointer to the next block or NULL */ 00243 /* the log record data is stored physically 00244 immediately after this struct, max amount 00245 RECV_DATA_BLOCK_SIZE bytes of it */ 00246 }; 00247 00248 /* Stored log record struct */ 00249 typedef struct recv_struct recv_t; 00250 struct recv_struct{ 00251 byte type; /* log record type */ 00252 ulint len; /* log record body length in bytes */ 00253 recv_data_t* data; /* chain of blocks containing the log record 00254 body */ 00255 dulint start_lsn;/* start lsn of the log segment written by 00256 the mtr which generated this log record: NOTE 00257 that this is not necessarily the start lsn of 00258 this log record */ 00259 dulint end_lsn;/* end lsn of the log segment written by 00260 the mtr which generated this log record: NOTE 00261 that this is not necessarily the end lsn of 00262 this log record */ 00263 UT_LIST_NODE_T(recv_t) 00264 rec_list;/* list of log records for this page */ 00265 }; 00266 00267 /* Hashed page file address struct */ 00268 typedef struct recv_addr_struct recv_addr_t; 00269 struct recv_addr_struct{ 00270 ulint state; /* RECV_NOT_PROCESSED, RECV_BEING_PROCESSED, 00271 or RECV_PROCESSED */ 00272 ulint space; /* space id */ 00273 ulint page_no;/* page number */ 00274 UT_LIST_BASE_NODE_T(recv_t) 00275 rec_list;/* list of log records for this page */ 00276 hash_node_t addr_hash; 00277 }; 00278 00279 /* Recovery system data structure */ 00280 typedef struct recv_sys_struct recv_sys_t; 00281 struct recv_sys_struct{ 00282 mutex_t mutex; /* mutex protecting the fields apply_log_recs, 00283 n_addrs, and the state field in each recv_addr 00284 struct */ 00285 ibool apply_log_recs; 00286 /* this is TRUE when log rec application to 00287 pages is allowed; this flag tells the 00288 i/o-handler if it should do log record 00289 application */ 00290 ibool apply_batch_on; 00291 /* this is TRUE when a log rec application 00292 batch is running */ 00293 dulint lsn; /* log sequence number */ 00294 ulint last_log_buf_size; 00295 /* size of the log buffer when the database 00296 last time wrote to the log */ 00297 byte* last_block; 00298 /* possible incomplete last recovered log 00299 block */ 00300 byte* last_block_buf_start; 00301 /* the nonaligned start address of the 00302 preceding buffer */ 00303 byte* buf; /* buffer for parsing log records */ 00304 ulint len; /* amount of data in buf */ 00305 dulint parse_start_lsn; 00306 /* this is the lsn from which we were able to 00307 start parsing log records and adding them to 00308 the hash table; ut_dulint_zero if a suitable 00309 start point not found yet */ 00310 dulint scanned_lsn; 00311 /* the log data has been scanned up to this 00312 lsn */ 00313 ulint scanned_checkpoint_no; 00314 /* the log data has been scanned up to this 00315 checkpoint number (lowest 4 bytes) */ 00316 ulint recovered_offset; 00317 /* start offset of non-parsed log records in 00318 buf */ 00319 dulint recovered_lsn; 00320 /* the log records have been parsed up to 00321 this lsn */ 00322 dulint limit_lsn;/* recovery should be made at most up to this 00323 lsn */ 00324 ibool found_corrupt_log; 00325 /* this is set to TRUE if we during log 00326 scan find a corrupt log block, or a corrupt 00327 log record, or there is a log parsing 00328 buffer overflow */ 00329 log_group_t* archive_group; 00330 /* in archive recovery: the log group whose 00331 archive is read */ 00332 mem_heap_t* heap; /* memory heap of log records and file 00333 addresses*/ 00334 hash_table_t* addr_hash;/* hash table of file addresses of pages */ 00335 ulint n_addrs;/* number of not processed hashed file 00336 addresses in the hash table */ 00337 }; 00338 00339 extern recv_sys_t* recv_sys; 00340 extern ibool recv_recovery_on; 00341 extern ibool recv_no_ibuf_operations; 00342 extern ibool recv_needed_recovery; 00343 00344 extern ibool recv_lsn_checks_on; 00345 #ifdef UNIV_HOTBACKUP 00346 extern ibool recv_is_making_a_backup; 00347 #endif /* UNIV_HOTBACKUP */ 00348 extern ulint recv_max_parsed_page_no; 00349 00350 /* Size of the parsing buffer; it must accommodate RECV_SCAN_SIZE many 00351 times! */ 00352 #define RECV_PARSING_BUF_SIZE (2 * 1024 * 1024) 00353 00354 /* Size of block reads when the log groups are scanned forward to do a 00355 roll-forward */ 00356 #define RECV_SCAN_SIZE (4 * UNIV_PAGE_SIZE) 00357 00358 /* States of recv_addr_struct */ 00359 #define RECV_NOT_PROCESSED 71 00360 #define RECV_BEING_READ 72 00361 #define RECV_BEING_PROCESSED 73 00362 #define RECV_PROCESSED 74 00363 00364 /* The number which is added to a space id to obtain the replicate space 00365 in the debug version: spaces with an odd number as the id are replicate 00366 spaces */ 00367 #define RECV_REPLICA_SPACE_ADD 1 00368 00369 extern ulint recv_n_pool_free_frames; 00370 00371 #ifndef UNIV_NONINL 00372 #include "log0recv.ic" 00373 #endif 00374 00375 #endif
1.4.7

