00001 /****************************************************** 00002 Database log 00003 00004 (c) 1995 Innobase Oy 00005 00006 Created 12/9/1995 Heikki Tuuri 00007 *******************************************************/ 00008 00009 #ifndef log0log_h 00010 #define log0log_h 00011 00012 #include "univ.i" 00013 #include "ut0byte.h" 00014 #include "sync0sync.h" 00015 #include "sync0rw.h" 00016 00017 typedef struct log_struct log_t; 00018 typedef struct log_group_struct log_group_t; 00019 00020 #ifdef UNIV_DEBUG 00021 extern ibool log_do_write; 00022 extern ibool log_debug_writes; 00023 #else /* UNIV_DEBUG */ 00024 # define log_do_write TRUE 00025 #endif /* UNIV_DEBUG */ 00026 00027 /* Wait modes for log_write_up_to */ 00028 #define LOG_NO_WAIT 91 00029 #define LOG_WAIT_ONE_GROUP 92 00030 #define LOG_WAIT_ALL_GROUPS 93 00031 #define LOG_MAX_N_GROUPS 32 00032 00033 /******************************************************************** 00034 Sets the global variable log_fsp_current_free_limit. Also makes a checkpoint, 00035 so that we know that the limit has been written to a log checkpoint field 00036 on disk. */ 00037 00038 void 00039 log_fsp_current_free_limit_set_and_checkpoint( 00040 /*==========================================*/ 00041 ulint limit); /* in: limit to set */ 00042 /*********************************************************************** 00043 Calculates where in log files we find a specified lsn. */ 00044 00045 ulint 00046 log_calc_where_lsn_is( 00047 /*==================*/ 00048 /* out: log file number */ 00049 ib_longlong* log_file_offset, /* out: offset in that file 00050 (including the header) */ 00051 dulint first_header_lsn, /* in: first log file start 00052 lsn */ 00053 dulint lsn, /* in: lsn whose position to 00054 determine */ 00055 ulint n_log_files, /* in: total number of log 00056 files */ 00057 ib_longlong log_file_size); /* in: log file size 00058 (including the header) */ 00059 /**************************************************************** 00060 Writes to the log the string given. The log must be released with 00061 log_release. */ 00062 UNIV_INLINE 00063 dulint 00064 log_reserve_and_write_fast( 00065 /*=======================*/ 00066 /* out: end lsn of the log record, ut_dulint_zero if 00067 did not succeed */ 00068 byte* str, /* in: string */ 00069 ulint len, /* in: string length */ 00070 dulint* start_lsn,/* out: start lsn of the log record */ 00071 ibool* success);/* out: TRUE if success */ 00072 /*************************************************************************** 00073 Releases the log mutex. */ 00074 UNIV_INLINE 00075 void 00076 log_release(void); 00077 /*=============*/ 00078 /*************************************************************************** 00079 Checks if there is need for a log buffer flush or a new checkpoint, and does 00080 this if yes. Any database operation should call this when it has modified 00081 more than about 4 pages. NOTE that this function may only be called when the 00082 OS thread owns no synchronization objects except the dictionary mutex. */ 00083 UNIV_INLINE 00084 void 00085 log_free_check(void); 00086 /*================*/ 00087 /**************************************************************** 00088 Opens the log for log_write_low. The log must be closed with log_close and 00089 released with log_release. */ 00090 00091 dulint 00092 log_reserve_and_open( 00093 /*=================*/ 00094 /* out: start lsn of the log record */ 00095 ulint len); /* in: length of data to be catenated */ 00096 /**************************************************************** 00097 Writes to the log the string given. It is assumed that the caller holds the 00098 log mutex. */ 00099 00100 void 00101 log_write_low( 00102 /*==========*/ 00103 byte* str, /* in: string */ 00104 ulint str_len); /* in: string length */ 00105 /**************************************************************** 00106 Closes the log. */ 00107 00108 dulint 00109 log_close(void); 00110 /*===========*/ 00111 /* out: lsn */ 00112 /**************************************************************** 00113 Gets the current lsn. */ 00114 UNIV_INLINE 00115 dulint 00116 log_get_lsn(void); 00117 /*=============*/ 00118 /* out: current lsn */ 00119 /********************************************************** 00120 Initializes the log. */ 00121 00122 void 00123 log_init(void); 00124 /*==========*/ 00125 /********************************************************************** 00126 Inits a log group to the log system. */ 00127 00128 void 00129 log_group_init( 00130 /*===========*/ 00131 ulint id, /* in: group id */ 00132 ulint n_files, /* in: number of log files */ 00133 ulint file_size, /* in: log file size in bytes */ 00134 ulint space_id, /* in: space id of the file space 00135 which contains the log files of this 00136 group */ 00137 ulint archive_space_id); /* in: space id of the file space 00138 which contains some archived log 00139 files for this group; currently, only 00140 for the first log group this is 00141 used */ 00142 /********************************************************** 00143 Completes an i/o to a log file. */ 00144 00145 void 00146 log_io_complete( 00147 /*============*/ 00148 log_group_t* group); /* in: log group */ 00149 /********************************************************** 00150 This function is called, e.g., when a transaction wants to commit. It checks 00151 that the log has been written to the log file up to the last log entry written 00152 by the transaction. If there is a flush running, it waits and checks if the 00153 flush flushed enough. If not, starts a new flush. */ 00154 00155 void 00156 log_write_up_to( 00157 /*============*/ 00158 dulint lsn, /* in: log sequence number up to which the log should 00159 be written, ut_dulint_max if not specified */ 00160 ulint wait, /* in: LOG_NO_WAIT, LOG_WAIT_ONE_GROUP, 00161 or LOG_WAIT_ALL_GROUPS */ 00162 ibool flush_to_disk); 00163 /* in: TRUE if we want the written log also to be 00164 flushed to disk */ 00165 /******************************************************************** 00166 Does a syncronous flush of the log buffer to disk. */ 00167 00168 void 00169 log_buffer_flush_to_disk(void); 00170 /*==========================*/ 00171 /******************************************************************** 00172 Advances the smallest lsn for which there are unflushed dirty blocks in the 00173 buffer pool and also may make a new checkpoint. NOTE: this function may only 00174 be called if the calling thread owns no synchronization objects! */ 00175 00176 ibool 00177 log_preflush_pool_modified_pages( 00178 /*=============================*/ 00179 /* out: FALSE if there was a flush batch of 00180 the same type running, which means that we 00181 could not start this flush batch */ 00182 dulint new_oldest, /* in: try to advance oldest_modified_lsn 00183 at least to this lsn */ 00184 ibool sync); /* in: TRUE if synchronous operation is 00185 desired */ 00186 /********************************************************** 00187 Makes a checkpoint. Note that this function does not flush dirty 00188 blocks from the buffer pool: it only checks what is lsn of the oldest 00189 modification in the pool, and writes information about the lsn in 00190 log files. Use log_make_checkpoint_at to flush also the pool. */ 00191 00192 ibool 00193 log_checkpoint( 00194 /*===========*/ 00195 /* out: TRUE if success, FALSE if a checkpoint 00196 write was already running */ 00197 ibool sync, /* in: TRUE if synchronous operation is 00198 desired */ 00199 ibool write_always); /* in: the function normally checks if the 00200 the new checkpoint would have a greater 00201 lsn than the previous one: if not, then no 00202 physical write is done; by setting this 00203 parameter TRUE, a physical write will always be 00204 made to log files */ 00205 /******************************************************************** 00206 Makes a checkpoint at a given lsn or later. */ 00207 00208 void 00209 log_make_checkpoint_at( 00210 /*===================*/ 00211 dulint lsn, /* in: make a checkpoint at this or a later 00212 lsn, if ut_dulint_max, makes a checkpoint at 00213 the latest lsn */ 00214 ibool write_always); /* in: the function normally checks if the 00215 the new checkpoint would have a greater 00216 lsn than the previous one: if not, then no 00217 physical write is done; by setting this 00218 parameter TRUE, a physical write will always be 00219 made to log files */ 00220 /******************************************************************** 00221 Makes a checkpoint at the latest lsn and writes it to first page of each 00222 data file in the database, so that we know that the file spaces contain 00223 all modifications up to that lsn. This can only be called at database 00224 shutdown. This function also writes all log in log files to the log archive. */ 00225 00226 void 00227 logs_empty_and_mark_files_at_shutdown(void); 00228 /*=======================================*/ 00229 /********************************************************** 00230 Reads a checkpoint info from a log group header to log_sys->checkpoint_buf. */ 00231 00232 void 00233 log_group_read_checkpoint_info( 00234 /*===========================*/ 00235 log_group_t* group, /* in: log group */ 00236 ulint field); /* in: LOG_CHECKPOINT_1 or LOG_CHECKPOINT_2 */ 00237 /*********************************************************************** 00238 Gets info from a checkpoint about a log group. */ 00239 00240 void 00241 log_checkpoint_get_nth_group_info( 00242 /*==============================*/ 00243 byte* buf, /* in: buffer containing checkpoint info */ 00244 ulint n, /* in: nth slot */ 00245 ulint* file_no,/* out: archived file number */ 00246 ulint* offset);/* out: archived file offset */ 00247 /********************************************************** 00248 Writes checkpoint info to groups. */ 00249 00250 void 00251 log_groups_write_checkpoint_info(void); 00252 /*==================================*/ 00253 /********************************************************** 00254 Writes info to a buffer of a log group when log files are created in 00255 backup restoration. */ 00256 00257 void 00258 log_reset_first_header_and_checkpoint( 00259 /*==================================*/ 00260 byte* hdr_buf,/* in: buffer which will be written to the start 00261 of the first log file */ 00262 dulint start); /* in: lsn of the start of the first log file; 00263 we pretend that there is a checkpoint at 00264 start + LOG_BLOCK_HDR_SIZE */ 00265 /************************************************************************ 00266 Starts an archiving operation. */ 00267 00268 ibool 00269 log_archive_do( 00270 /*===========*/ 00271 /* out: TRUE if succeed, FALSE if an archiving 00272 operation was already running */ 00273 ibool sync, /* in: TRUE if synchronous operation is desired */ 00274 ulint* n_bytes);/* out: archive log buffer size, 0 if nothing to 00275 archive */ 00276 /******************************************************************** 00277 Writes the log contents to the archive up to the lsn when this function was 00278 called, and stops the archiving. When archiving is started again, the archived 00279 log file numbers start from a number one higher, so that the archiving will 00280 not write again to the archived log files which exist when this function 00281 returns. */ 00282 00283 ulint 00284 log_archive_stop(void); 00285 /*==================*/ 00286 /* out: DB_SUCCESS or DB_ERROR */ 00287 /******************************************************************** 00288 Starts again archiving which has been stopped. */ 00289 00290 ulint 00291 log_archive_start(void); 00292 /*===================*/ 00293 /* out: DB_SUCCESS or DB_ERROR */ 00294 /******************************************************************** 00295 Stop archiving the log so that a gap may occur in the archived log files. */ 00296 00297 ulint 00298 log_archive_noarchivelog(void); 00299 /*==========================*/ 00300 /* out: DB_SUCCESS or DB_ERROR */ 00301 /******************************************************************** 00302 Start archiving the log so that a gap may occur in the archived log files. */ 00303 00304 ulint 00305 log_archive_archivelog(void); 00306 /*========================*/ 00307 /* out: DB_SUCCESS or DB_ERROR */ 00308 /********************************************************** 00309 Generates an archived log file name. */ 00310 00311 void 00312 log_archived_file_name_gen( 00313 /*=======================*/ 00314 char* buf, /* in: buffer where to write */ 00315 ulint id, /* in: group id */ 00316 ulint file_no);/* in: file number */ 00317 /************************************************************************ 00318 Checks that there is enough free space in the log to start a new query step. 00319 Flushes the log buffer or makes a new checkpoint if necessary. NOTE: this 00320 function may only be called if the calling thread owns no synchronization 00321 objects! */ 00322 00323 void 00324 log_check_margins(void); 00325 /*===================*/ 00326 /********************************************************** 00327 Reads a specified log segment to a buffer. */ 00328 00329 void 00330 log_group_read_log_seg( 00331 /*===================*/ 00332 ulint type, /* in: LOG_ARCHIVE or LOG_RECOVER */ 00333 byte* buf, /* in: buffer where to read */ 00334 log_group_t* group, /* in: log group */ 00335 dulint start_lsn, /* in: read area start */ 00336 dulint end_lsn); /* in: read area end */ 00337 /********************************************************** 00338 Writes a buffer to a log file group. */ 00339 00340 void 00341 log_group_write_buf( 00342 /*================*/ 00343 log_group_t* group, /* in: log group */ 00344 byte* buf, /* in: buffer */ 00345 ulint len, /* in: buffer len; must be divisible 00346 by OS_FILE_LOG_BLOCK_SIZE */ 00347 dulint start_lsn, /* in: start lsn of the buffer; must 00348 be divisible by 00349 OS_FILE_LOG_BLOCK_SIZE */ 00350 ulint new_data_offset);/* in: start offset of new data in 00351 buf: this parameter is used to decide 00352 if we have to write a new log file 00353 header */ 00354 /************************************************************ 00355 Sets the field values in group to correspond to a given lsn. For this function 00356 to work, the values must already be correctly initialized to correspond to 00357 some lsn, for instance, a checkpoint lsn. */ 00358 00359 void 00360 log_group_set_fields( 00361 /*=================*/ 00362 log_group_t* group, /* in: group */ 00363 dulint lsn); /* in: lsn for which the values should be 00364 set */ 00365 /********************************************************** 00366 Calculates the data capacity of a log group, when the log file headers are not 00367 included. */ 00368 00369 ulint 00370 log_group_get_capacity( 00371 /*===================*/ 00372 /* out: capacity in bytes */ 00373 log_group_t* group); /* in: log group */ 00374 /**************************************************************** 00375 Gets a log block flush bit. */ 00376 UNIV_INLINE 00377 ibool 00378 log_block_get_flush_bit( 00379 /*====================*/ 00380 /* out: TRUE if this block was the first 00381 to be written in a log flush */ 00382 byte* log_block); /* in: log block */ 00383 /**************************************************************** 00384 Gets a log block number stored in the header. */ 00385 UNIV_INLINE 00386 ulint 00387 log_block_get_hdr_no( 00388 /*=================*/ 00389 /* out: log block number stored in the block 00390 header */ 00391 byte* log_block); /* in: log block */ 00392 /**************************************************************** 00393 Gets a log block data length. */ 00394 UNIV_INLINE 00395 ulint 00396 log_block_get_data_len( 00397 /*===================*/ 00398 /* out: log block data length measured as a 00399 byte offset from the block start */ 00400 byte* log_block); /* in: log block */ 00401 /**************************************************************** 00402 Sets the log block data length. */ 00403 UNIV_INLINE 00404 void 00405 log_block_set_data_len( 00406 /*===================*/ 00407 byte* log_block, /* in: log block */ 00408 ulint len); /* in: data length */ 00409 /**************************************************************** 00410 Calculates the checksum for a log block. */ 00411 UNIV_INLINE 00412 ulint 00413 log_block_calc_checksum( 00414 /*====================*/ 00415 /* out: checksum */ 00416 byte* block); /* in: log block */ 00417 /**************************************************************** 00418 Gets a log block checksum field value. */ 00419 UNIV_INLINE 00420 ulint 00421 log_block_get_checksum( 00422 /*===================*/ 00423 /* out: checksum */ 00424 byte* log_block); /* in: log block */ 00425 /**************************************************************** 00426 Sets a log block checksum field value. */ 00427 UNIV_INLINE 00428 void 00429 log_block_set_checksum( 00430 /*===================*/ 00431 byte* log_block, /* in: log block */ 00432 ulint checksum); /* in: checksum */ 00433 /**************************************************************** 00434 Gets a log block first mtr log record group offset. */ 00435 UNIV_INLINE 00436 ulint 00437 log_block_get_first_rec_group( 00438 /*==========================*/ 00439 /* out: first mtr log record group byte offset 00440 from the block start, 0 if none */ 00441 byte* log_block); /* in: log block */ 00442 /**************************************************************** 00443 Sets the log block first mtr log record group offset. */ 00444 UNIV_INLINE 00445 void 00446 log_block_set_first_rec_group( 00447 /*==========================*/ 00448 byte* log_block, /* in: log block */ 00449 ulint offset); /* in: offset, 0 if none */ 00450 /**************************************************************** 00451 Gets a log block checkpoint number field (4 lowest bytes). */ 00452 UNIV_INLINE 00453 ulint 00454 log_block_get_checkpoint_no( 00455 /*========================*/ 00456 /* out: checkpoint no (4 lowest bytes) */ 00457 byte* log_block); /* in: log block */ 00458 /**************************************************************** 00459 Initializes a log block in the log buffer. */ 00460 UNIV_INLINE 00461 void 00462 log_block_init( 00463 /*===========*/ 00464 byte* log_block, /* in: pointer to the log buffer */ 00465 dulint lsn); /* in: lsn within the log block */ 00466 /**************************************************************** 00467 Initializes a log block in the log buffer in the old, < 3.23.52 format, where 00468 there was no checksum yet. */ 00469 UNIV_INLINE 00470 void 00471 log_block_init_in_old_format( 00472 /*=========================*/ 00473 byte* log_block, /* in: pointer to the log buffer */ 00474 dulint lsn); /* in: lsn within the log block */ 00475 /**************************************************************** 00476 Converts a lsn to a log block number. */ 00477 UNIV_INLINE 00478 ulint 00479 log_block_convert_lsn_to_no( 00480 /*========================*/ 00481 /* out: log block number, it is > 0 and <= 1G */ 00482 dulint lsn); /* in: lsn of a byte within the block */ 00483 /********************************************************** 00484 Prints info of the log. */ 00485 00486 void 00487 log_print( 00488 /*======*/ 00489 FILE* file); /* in: file where to print */ 00490 /********************************************************** 00491 Peeks the current lsn. */ 00492 00493 ibool 00494 log_peek_lsn( 00495 /*=========*/ 00496 /* out: TRUE if success, FALSE if could not get the 00497 log system mutex */ 00498 dulint* lsn); /* out: if returns TRUE, current lsn is here */ 00499 /************************************************************************** 00500 Refreshes the statistics used to print per-second averages. */ 00501 00502 void 00503 log_refresh_stats(void); 00504 /*===================*/ 00505 00506 extern log_t* log_sys; 00507 00508 /* Values used as flags */ 00509 #define LOG_FLUSH 7652559 00510 #define LOG_CHECKPOINT 78656949 00511 #define LOG_ARCHIVE 11122331 00512 #define LOG_RECOVER 98887331 00513 00514 /* The counting of lsn's starts from this value: this must be non-zero */ 00515 #define LOG_START_LSN ut_dulint_create(0, 16 * OS_FILE_LOG_BLOCK_SIZE) 00516 00517 #define LOG_BUFFER_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE) 00518 #define LOG_ARCHIVE_BUF_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE / 4) 00519 00520 /* Offsets of a log block header */ 00521 #define LOG_BLOCK_HDR_NO 0 /* block number which must be > 0 and 00522 is allowed to wrap around at 2G; the 00523 highest bit is set to 1 if this is the 00524 first log block in a log flush write 00525 segment */ 00526 #define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL 00527 /* mask used to get the highest bit in 00528 the preceding field */ 00529 #define LOG_BLOCK_HDR_DATA_LEN 4 /* number of bytes of log written to 00530 this block */ 00531 #define LOG_BLOCK_FIRST_REC_GROUP 6 /* offset of the first start of an 00532 mtr log record group in this log block, 00533 0 if none; if the value is the same 00534 as LOG_BLOCK_HDR_DATA_LEN, it means 00535 that the first rec group has not yet 00536 been catenated to this log block, but 00537 if it will, it will start at this 00538 offset; an archive recovery can 00539 start parsing the log records starting 00540 from this offset in this log block, 00541 if value not 0 */ 00542 #define LOG_BLOCK_CHECKPOINT_NO 8 /* 4 lower bytes of the value of 00543 log_sys->next_checkpoint_no when the 00544 log block was last written to: if the 00545 block has not yet been written full, 00546 this value is only updated before a 00547 log buffer flush */ 00548 #define LOG_BLOCK_HDR_SIZE 12 /* size of the log block header in 00549 bytes */ 00550 00551 /* Offsets of a log block trailer from the end of the block */ 00552 #define LOG_BLOCK_CHECKSUM 4 /* 4 byte checksum of the log block 00553 contents; in InnoDB versions 00554 < 3.23.52 this did not contain the 00555 checksum but the same value as 00556 .._HDR_NO */ 00557 #define LOG_BLOCK_TRL_SIZE 4 /* trailer size in bytes */ 00558 00559 /* Offsets for a checkpoint field */ 00560 #define LOG_CHECKPOINT_NO 0 00561 #define LOG_CHECKPOINT_LSN 8 00562 #define LOG_CHECKPOINT_OFFSET 16 00563 #define LOG_CHECKPOINT_LOG_BUF_SIZE 20 00564 #define LOG_CHECKPOINT_ARCHIVED_LSN 24 00565 #define LOG_CHECKPOINT_GROUP_ARRAY 32 00566 00567 /* For each value < LOG_MAX_N_GROUPS the following 8 bytes: */ 00568 00569 #define LOG_CHECKPOINT_ARCHIVED_FILE_NO 0 00570 #define LOG_CHECKPOINT_ARCHIVED_OFFSET 4 00571 00572 #define LOG_CHECKPOINT_ARRAY_END (LOG_CHECKPOINT_GROUP_ARRAY\ 00573 + LOG_MAX_N_GROUPS * 8) 00574 #define LOG_CHECKPOINT_CHECKSUM_1 LOG_CHECKPOINT_ARRAY_END 00575 #define LOG_CHECKPOINT_CHECKSUM_2 (4 + LOG_CHECKPOINT_ARRAY_END) 00576 #define LOG_CHECKPOINT_FSP_FREE_LIMIT (8 + LOG_CHECKPOINT_ARRAY_END) 00577 /* current fsp free limit in 00578 tablespace 0, in units of one 00579 megabyte; this information is only used 00580 by ibbackup to decide if it can 00581 truncate unused ends of 00582 non-auto-extending data files in space 00583 0 */ 00584 #define LOG_CHECKPOINT_FSP_MAGIC_N (12 + LOG_CHECKPOINT_ARRAY_END) 00585 /* this magic number tells if the 00586 checkpoint contains the above field: 00587 the field was added to 00588 InnoDB-3.23.50 */ 00589 #define LOG_CHECKPOINT_SIZE (16 + LOG_CHECKPOINT_ARRAY_END) 00590 00591 #define LOG_CHECKPOINT_FSP_MAGIC_N_VAL 1441231243 00592 00593 /* Offsets of a log file header */ 00594 #define LOG_GROUP_ID 0 /* log group number */ 00595 #define LOG_FILE_START_LSN 4 /* lsn of the start of data in this 00596 log file */ 00597 #define LOG_FILE_NO 12 /* 4-byte archived log file number; 00598 this field is only defined in an 00599 archived log file */ 00600 #define LOG_FILE_WAS_CREATED_BY_HOT_BACKUP 16 00601 /* a 32-byte field which contains 00602 the string 'ibbackup' and the 00603 creation time if the log file was 00604 created by ibbackup --restore; 00605 when mysqld is first time started 00606 on the restored database, it can 00607 print helpful info for the user */ 00608 #define LOG_FILE_ARCH_COMPLETED OS_FILE_LOG_BLOCK_SIZE 00609 /* this 4-byte field is TRUE when 00610 the writing of an archived log file 00611 has been completed; this field is 00612 only defined in an archived log file */ 00613 #define LOG_FILE_END_LSN (OS_FILE_LOG_BLOCK_SIZE + 4) 00614 /* lsn where the archived log file 00615 at least extends: actually the 00616 archived log file may extend to a 00617 later lsn, as long as it is within the 00618 same log block as this lsn; this field 00619 is defined only when an archived log 00620 file has been completely written */ 00621 #define LOG_CHECKPOINT_1 OS_FILE_LOG_BLOCK_SIZE 00622 /* first checkpoint field in the log 00623 header; we write alternately to the 00624 checkpoint fields when we make new 00625 checkpoints; this field is only defined 00626 in the first log file of a log group */ 00627 #define LOG_CHECKPOINT_2 (3 * OS_FILE_LOG_BLOCK_SIZE) 00628 /* second checkpoint field in the log 00629 header */ 00630 #define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE) 00631 00632 #define LOG_GROUP_OK 301 00633 #define LOG_GROUP_CORRUPTED 302 00634 00635 /* Log group consists of a number of log files, each of the same size; a log 00636 group is implemented as a space in the sense of the module fil0fil. */ 00637 00638 struct log_group_struct{ 00639 /* The following fields are protected by log_sys->mutex */ 00640 ulint id; /* log group id */ 00641 ulint n_files; /* number of files in the group */ 00642 ulint file_size; /* individual log file size in bytes, 00643 including the log file header */ 00644 ulint space_id; /* file space which implements the log 00645 group */ 00646 ulint state; /* LOG_GROUP_OK or 00647 LOG_GROUP_CORRUPTED */ 00648 dulint lsn; /* lsn used to fix coordinates within 00649 the log group */ 00650 ulint lsn_offset; /* the offset of the above lsn */ 00651 ulint n_pending_writes;/* number of currently pending flush 00652 writes for this log group */ 00653 byte** file_header_bufs;/* buffers for each file header in the 00654 group */ 00655 /*-----------------------------*/ 00656 byte** archive_file_header_bufs;/* buffers for each file 00657 header in the group */ 00658 ulint archive_space_id;/* file space which implements the log 00659 group archive */ 00660 ulint archived_file_no;/* file number corresponding to 00661 log_sys->archived_lsn */ 00662 ulint archived_offset;/* file offset corresponding to 00663 log_sys->archived_lsn, 0 if we have 00664 not yet written to the archive file 00665 number archived_file_no */ 00666 ulint next_archived_file_no;/* during an archive write, 00667 until the write is completed, we 00668 store the next value for 00669 archived_file_no here: the write 00670 completion function then sets the new 00671 value to ..._file_no */ 00672 ulint next_archived_offset; /* like the preceding field */ 00673 /*-----------------------------*/ 00674 dulint scanned_lsn; /* used only in recovery: recovery scan 00675 succeeded up to this lsn in this log 00676 group */ 00677 byte* checkpoint_buf; /* checkpoint header is written from 00678 this buffer to the group */ 00679 UT_LIST_NODE_T(log_group_t) 00680 log_groups; /* list of log groups */ 00681 }; 00682 00683 struct log_struct{ 00684 byte pad[64]; /* padding to prevent other memory 00685 update hotspots from residing on the 00686 same memory cache line */ 00687 dulint lsn; /* log sequence number */ 00688 ulint buf_free; /* first free offset within the log 00689 buffer */ 00690 mutex_t mutex; /* mutex protecting the log */ 00691 byte* buf; /* log buffer */ 00692 ulint buf_size; /* log buffer size in bytes */ 00693 ulint max_buf_free; /* recommended maximum value of 00694 buf_free, after which the buffer is 00695 flushed */ 00696 ulint old_buf_free; /* value of buf free when log was 00697 last time opened; only in the debug 00698 version */ 00699 dulint old_lsn; /* value of lsn when log was last time 00700 opened; only in the debug version */ 00701 ibool check_flush_or_checkpoint; 00702 /* this is set to TRUE when there may 00703 be need to flush the log buffer, or 00704 preflush buffer pool pages, or make 00705 a checkpoint; this MUST be TRUE when 00706 lsn - last_checkpoint_lsn > 00707 max_checkpoint_age; this flag is 00708 peeked at by log_free_check(), which 00709 does not reserve the log mutex */ 00710 UT_LIST_BASE_NODE_T(log_group_t) 00711 log_groups; /* log groups */ 00712 00713 /* The fields involved in the log buffer flush */ 00714 00715 ulint buf_next_to_write;/* first offset in the log buffer 00716 where the byte content may not exist 00717 written to file, e.g., the start 00718 offset of a log record catenated 00719 later; this is advanced when a flush 00720 operation is completed to all the log 00721 groups */ 00722 dulint written_to_some_lsn; 00723 /* first log sequence number not yet 00724 written to any log group; for this to 00725 be advanced, it is enough that the 00726 write i/o has been completed for any 00727 one log group */ 00728 dulint written_to_all_lsn; 00729 /* first log sequence number not yet 00730 written to some log group; for this to 00731 be advanced, it is enough that the 00732 write i/o has been completed for all 00733 log groups */ 00734 dulint write_lsn; /* end lsn for the current running 00735 write */ 00736 ulint write_end_offset;/* the data in buffer has been written 00737 up to this offset when the current 00738 write ends: this field will then 00739 be copied to buf_next_to_write */ 00740 dulint current_flush_lsn;/* end lsn for the current running 00741 write + flush operation */ 00742 dulint flushed_to_disk_lsn; 00743 /* how far we have written the log 00744 AND flushed to disk */ 00745 ulint n_pending_writes;/* number of currently pending flushes 00746 or writes */ 00747 /* NOTE on the 'flush' in names of the fields below: starting from 00748 4.0.14, we separate the write of the log file and the actual fsync() 00749 or other method to flush it to disk. The names below shhould really 00750 be 'flush_or_write'! */ 00751 os_event_t no_flush_event; /* this event is in the reset state 00752 when a flush or a write is running; 00753 a thread should wait for this without 00754 owning the log mutex, but NOTE that 00755 to set or reset this event, the 00756 thread MUST own the log mutex! */ 00757 ibool one_flushed; /* during a flush, this is first FALSE 00758 and becomes TRUE when one log group 00759 has been written or flushed */ 00760 os_event_t one_flushed_event;/* this event is reset when the 00761 flush or write has not yet completed 00762 for any log group; e.g., this means 00763 that a transaction has been committed 00764 when this is set; a thread should wait 00765 for this without owning the log mutex, 00766 but NOTE that to set or reset this 00767 event, the thread MUST own the log 00768 mutex! */ 00769 ulint n_log_ios; /* number of log i/os initiated thus 00770 far */ 00771 ulint n_log_ios_old; /* number of log i/o's at the 00772 previous printout */ 00773 time_t last_printout_time;/* when log_print was last time 00774 called */ 00775 00776 /* Fields involved in checkpoints */ 00777 ulint log_group_capacity; /* capacity of the log group; if 00778 the checkpoint age exceeds this, it is 00779 a serious error because it is possible 00780 we will then overwrite log and spoil 00781 crash recovery */ 00782 ulint max_modified_age_async; 00783 /* when this recommended value for lsn 00784 - buf_pool_get_oldest_modification() 00785 is exceeded, we start an asynchronous 00786 preflush of pool pages */ 00787 ulint max_modified_age_sync; 00788 /* when this recommended value for lsn 00789 - buf_pool_get_oldest_modification() 00790 is exceeded, we start a synchronous 00791 preflush of pool pages */ 00792 ulint adm_checkpoint_interval; 00793 /* administrator-specified checkpoint 00794 interval in terms of log growth in 00795 bytes; the interval actually used by 00796 the database can be smaller */ 00797 ulint max_checkpoint_age_async; 00798 /* when this checkpoint age is exceeded 00799 we start an asynchronous writing of a 00800 new checkpoint */ 00801 ulint max_checkpoint_age; 00802 /* this is the maximum allowed value 00803 for lsn - last_checkpoint_lsn when a 00804 new query step is started */ 00805 dulint next_checkpoint_no; 00806 /* next checkpoint number */ 00807 dulint last_checkpoint_lsn; 00808 /* latest checkpoint lsn */ 00809 dulint next_checkpoint_lsn; 00810 /* next checkpoint lsn */ 00811 ulint n_pending_checkpoint_writes; 00812 /* number of currently pending 00813 checkpoint writes */ 00814 rw_lock_t checkpoint_lock;/* this latch is x-locked when a 00815 checkpoint write is running; a thread 00816 should wait for this without owning 00817 the log mutex */ 00818 byte* checkpoint_buf; /* checkpoint header is read to this 00819 buffer */ 00820 /* Fields involved in archiving */ 00821 ulint archiving_state;/* LOG_ARCH_ON, LOG_ARCH_STOPPING 00822 LOG_ARCH_STOPPED, LOG_ARCH_OFF */ 00823 dulint archived_lsn; /* archiving has advanced to this 00824 lsn */ 00825 ulint max_archived_lsn_age_async; 00826 /* recommended maximum age of 00827 archived_lsn, before we start 00828 asynchronous copying to the archive */ 00829 ulint max_archived_lsn_age; 00830 /* maximum allowed age for 00831 archived_lsn */ 00832 dulint next_archived_lsn;/* during an archive write, 00833 until the write is completed, we 00834 store the next value for 00835 archived_lsn here: the write 00836 completion function then sets the new 00837 value to archived_lsn */ 00838 ulint archiving_phase;/* LOG_ARCHIVE_READ or 00839 LOG_ARCHIVE_WRITE */ 00840 ulint n_pending_archive_ios; 00841 /* number of currently pending reads 00842 or writes in archiving */ 00843 rw_lock_t archive_lock; /* this latch is x-locked when an 00844 archive write is running; a thread 00845 should wait for this without owning 00846 the log mutex */ 00847 ulint archive_buf_size;/* size of archive_buf */ 00848 byte* archive_buf; /* log segment is written to the 00849 archive from this buffer */ 00850 os_event_t archiving_on; /* if archiving has been stopped, 00851 a thread can wait for this event to 00852 become signaled */ 00853 }; 00854 00855 #define LOG_ARCH_ON 71 00856 #define LOG_ARCH_STOPPING 72 00857 #define LOG_ARCH_STOPPING2 73 00858 #define LOG_ARCH_STOPPED 74 00859 #define LOG_ARCH_OFF 75 00860 00861 #ifndef UNIV_NONINL 00862 #include "log0log.ic" 00863 #endif 00864 00865 #endif
1.4.7

