Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #pragma once
00034 #ifndef log0log_h
00035 #define log0log_h
00036
00037 #include "univ.i"
00038 #include "ut0byte.h"
00039 #include "ut0lst.h"
00040 #ifndef UNIV_HOTBACKUP
00041 #include "sync0sync.h"
00042 #include "sync0rw.h"
00043 #endif
00044
00046 typedef struct log_struct log_t;
00048 typedef struct log_group_struct log_group_t;
00049
00050 #ifdef UNIV_DEBUG
00051
00052 extern ibool log_do_write;
00054 extern ibool log_debug_writes;
00055 #else
00056
00057 # define log_do_write TRUE
00058 #endif
00059
00061 #define LOG_NO_WAIT 91
00062 #define LOG_WAIT_ONE_GROUP 92
00063 #define LOG_WAIT_ALL_GROUPS 93
00064
00066 #define LOG_MAX_N_GROUPS 32
00067
00068 #ifndef UNIV_HOTBACKUP
00069
00073 UNIV_INTERN
00074 void
00075 log_fsp_current_free_limit_set_and_checkpoint(
00076
00077 ulint limit);
00078 #endif
00079
00082 UNIV_INTERN
00083 ulint
00084 log_calc_where_lsn_is(
00085
00086 ib_int64_t* log_file_offset,
00088 ib_uint64_t first_header_lsn,
00090 ib_uint64_t lsn,
00092 ulint n_log_files,
00094 ib_int64_t log_file_size);
00096 #ifndef UNIV_HOTBACKUP
00097
00101 UNIV_INLINE
00102 ib_uint64_t
00103 log_reserve_and_write_fast(
00104
00105 const void* str,
00106 ulint len,
00107 ib_uint64_t* start_lsn);
00108
00110 UNIV_INLINE
00111 void
00112 log_release(void);
00113
00114
00119 UNIV_INLINE
00120 void
00121 log_free_check(void);
00122
00123
00127 UNIV_INTERN
00128 ib_uint64_t
00129 log_reserve_and_open(
00130
00131 ulint len);
00132
00135 UNIV_INTERN
00136 void
00137 log_write_low(
00138
00139 byte* str,
00140 ulint str_len);
00141
00144 UNIV_INTERN
00145 ib_uint64_t
00146 log_close(void);
00147
00148
00151 UNIV_INLINE
00152 ib_uint64_t
00153 log_get_lsn(void);
00154
00155
00156
00157
00158
00159 UNIV_INLINE
00160 ulint
00161 log_get_capacity(void);
00162
00163
00165 UNIV_INTERN
00166 void
00167 log_init(void);
00168
00169
00171 UNIV_INTERN
00172 void
00173 log_group_init(
00174
00175 ulint id,
00176 ulint n_files,
00177 ulint file_size,
00178 ulint space_id,
00181 ulint archive_space_id);
00186
00188 UNIV_INTERN
00189 void
00190 log_io_complete(
00191
00192 log_group_t* group);
00193
00198 UNIV_INTERN
00199 void
00200 log_write_up_to(
00201
00202 ib_uint64_t lsn,
00205 ulint wait,
00207 ibool flush_to_disk);
00210
00212 UNIV_INTERN
00213 void
00214 log_buffer_flush_to_disk(void);
00215
00216
00221 UNIV_INTERN
00222 void
00223 log_buffer_sync_in_background(
00224
00225 ibool flush);
00226
00232 UNIV_INTERN
00233 ibool
00234 log_preflush_pool_modified_pages(
00235
00236 ib_uint64_t new_oldest,
00239 ibool sync);
00241
00247 UNIV_INTERN
00248 ibool
00249 log_checkpoint(
00250
00251 ibool sync,
00253 ibool write_always);
00259
00261 UNIV_INTERN
00262 void
00263 log_make_checkpoint_at(
00264
00265 ib_uint64_t lsn,
00268 ibool write_always);
00275
00280 UNIV_INTERN
00281 void
00282 logs_empty_and_mark_files_at_shutdown(void);
00283
00284
00286 UNIV_INTERN
00287 void
00288 log_group_read_checkpoint_info(
00289
00290 log_group_t* group,
00291 ulint field);
00292
00294 UNIV_INTERN
00295 void
00296 log_checkpoint_get_nth_group_info(
00297
00298 const byte* buf,
00299 ulint n,
00300 ulint* file_no,
00301 ulint* offset);
00302
00304 UNIV_INTERN
00305 void
00306 log_groups_write_checkpoint_info(void);
00307
00308
00311 UNIV_INTERN
00312 ibool
00313 log_archive_do(
00314
00315 ibool sync,
00316 ulint* n_bytes);
00318
00325 UNIV_INTERN
00326 ulint
00327 log_archive_stop(void);
00328
00329
00332 UNIV_INTERN
00333 ulint
00334 log_archive_start(void);
00335
00336
00339 UNIV_INTERN
00340 ulint
00341 log_archive_noarchivelog(void);
00342
00343
00346 UNIV_INTERN
00347 ulint
00348 log_archive_archivelog(void);
00349
00350
00352 UNIV_INTERN
00353 void
00354 log_archived_file_name_gen(
00355
00356 char* buf,
00357 ulint id,
00358 ulint file_no);
00359 #else
00360
00363 UNIV_INTERN
00364 void
00365 log_reset_first_header_and_checkpoint(
00366
00367 byte* hdr_buf,
00369 ib_uint64_t start);
00372 #endif
00373
00378 UNIV_INTERN
00379 void
00380 log_check_margins(void);
00381
00382 #ifndef UNIV_HOTBACKUP
00383
00385 UNIV_INTERN
00386 void
00387 log_group_read_log_seg(
00388
00389 ulint type,
00390 byte* buf,
00391 log_group_t* group,
00392 ib_uint64_t start_lsn,
00393 ib_uint64_t end_lsn);
00394
00396 UNIV_INTERN
00397 void
00398 log_group_write_buf(
00399
00400 log_group_t* group,
00401 byte* buf,
00402 ulint len,
00404 ib_uint64_t start_lsn,
00407 ulint new_data_offset);
00411
00415 UNIV_INTERN
00416 void
00417 log_group_set_fields(
00418
00419 log_group_t* group,
00420 ib_uint64_t lsn);
00422
00426 UNIV_INTERN
00427 ulint
00428 log_group_get_capacity(
00429
00430 const log_group_t* group);
00431 #endif
00432
00435 UNIV_INLINE
00436 ibool
00437 log_block_get_flush_bit(
00438
00439 const byte* log_block);
00440
00443 UNIV_INLINE
00444 ulint
00445 log_block_get_hdr_no(
00446
00447 const byte* log_block);
00448
00451 UNIV_INLINE
00452 ulint
00453 log_block_get_data_len(
00454
00455 const byte* log_block);
00456
00458 UNIV_INLINE
00459 void
00460 log_block_set_data_len(
00461
00462 byte* log_block,
00463 ulint len);
00464
00467 UNIV_INLINE
00468 ulint
00469 log_block_calc_checksum(
00470
00471 const byte* block);
00472
00475 UNIV_INLINE
00476 ulint
00477 log_block_get_checksum(
00478
00479 const byte* log_block);
00480
00482 UNIV_INLINE
00483 void
00484 log_block_set_checksum(
00485
00486 byte* log_block,
00487 ulint checksum);
00488
00492 UNIV_INLINE
00493 ulint
00494 log_block_get_first_rec_group(
00495
00496 const byte* log_block);
00497
00499 UNIV_INLINE
00500 void
00501 log_block_set_first_rec_group(
00502
00503 byte* log_block,
00504 ulint offset);
00505
00508 UNIV_INLINE
00509 ulint
00510 log_block_get_checkpoint_no(
00511
00512 const byte* log_block);
00513
00515 UNIV_INLINE
00516 void
00517 log_block_init(
00518
00519 byte* log_block,
00520 ib_uint64_t lsn);
00521
00524 UNIV_INLINE
00525 void
00526 log_block_init_in_old_format(
00527
00528 byte* log_block,
00529 ib_uint64_t lsn);
00530
00533 UNIV_INLINE
00534 ulint
00535 log_block_convert_lsn_to_no(
00536
00537 ib_uint64_t lsn);
00538
00540 UNIV_INTERN
00541 void
00542 log_print(
00543
00544 FILE* file);
00545
00548 UNIV_INTERN
00549 ibool
00550 log_peek_lsn(
00551
00552 ib_uint64_t* lsn);
00553
00555 UNIV_INTERN
00556 void
00557 log_refresh_stats(void);
00558
00559
00560
00561 UNIV_INTERN
00562 void
00563 log_shutdown(void);
00564
00565
00566
00567 UNIV_INTERN
00568 void
00569 log_mem_free(void);
00570
00571
00572 extern log_t* log_sys;
00573
00574
00575 #define LOG_FLUSH 7652559
00576 #define LOG_CHECKPOINT 78656949
00577 #ifdef UNIV_LOG_ARCHIVE
00578 # define LOG_ARCHIVE 11122331
00579 #endif
00580 #define LOG_RECOVER 98887331
00581
00582
00583 #define LOG_START_LSN ((ib_uint64_t) (16 * OS_FILE_LOG_BLOCK_SIZE))
00584
00585 #define LOG_BUFFER_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE)
00586 #define LOG_ARCHIVE_BUF_SIZE (srv_log_buffer_size * UNIV_PAGE_SIZE / 4)
00587
00588
00589 #define LOG_BLOCK_HDR_NO 0
00590
00591
00592
00593
00594 #define LOG_BLOCK_FLUSH_BIT_MASK 0x80000000UL
00595
00596
00597 #define LOG_BLOCK_HDR_DATA_LEN 4
00598
00599 #define LOG_BLOCK_FIRST_REC_GROUP 6
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 #define LOG_BLOCK_CHECKPOINT_NO 8
00611
00612
00613
00614
00615
00616 #define LOG_BLOCK_HDR_SIZE 12
00617
00618
00619
00620 #define LOG_BLOCK_CHECKSUM 4
00621
00622
00623
00624
00625 #define LOG_BLOCK_TRL_SIZE 4
00626
00627
00628 #define LOG_CHECKPOINT_NO 0
00629 #define LOG_CHECKPOINT_LSN 8
00630 #define LOG_CHECKPOINT_OFFSET 16
00631 #define LOG_CHECKPOINT_LOG_BUF_SIZE 20
00632 #define LOG_CHECKPOINT_ARCHIVED_LSN 24
00633 #define LOG_CHECKPOINT_GROUP_ARRAY 32
00634
00635
00636
00637 #define LOG_CHECKPOINT_ARCHIVED_FILE_NO 0
00638 #define LOG_CHECKPOINT_ARCHIVED_OFFSET 4
00639
00640 #define LOG_CHECKPOINT_ARRAY_END (LOG_CHECKPOINT_GROUP_ARRAY\
00641 + LOG_MAX_N_GROUPS * 8)
00642 #define LOG_CHECKPOINT_CHECKSUM_1 LOG_CHECKPOINT_ARRAY_END
00643 #define LOG_CHECKPOINT_CHECKSUM_2 (4 + LOG_CHECKPOINT_ARRAY_END)
00644 #define LOG_CHECKPOINT_FSP_FREE_LIMIT (8 + LOG_CHECKPOINT_ARRAY_END)
00645
00646
00647
00648
00649
00650
00651
00652 #define LOG_CHECKPOINT_FSP_MAGIC_N (12 + LOG_CHECKPOINT_ARRAY_END)
00653
00654
00655
00656
00657 #define LOG_CHECKPOINT_SIZE (16 + LOG_CHECKPOINT_ARRAY_END)
00658
00659 #define LOG_CHECKPOINT_FSP_MAGIC_N_VAL 1441231243
00660
00661
00662 #define LOG_GROUP_ID 0
00663 #define LOG_FILE_START_LSN 4
00664
00665 #define LOG_FILE_NO 12
00666
00667
00668 #define LOG_FILE_WAS_CREATED_BY_HOT_BACKUP 16
00669
00670
00671
00672
00673
00674
00675
00676 #define LOG_FILE_ARCH_COMPLETED OS_FILE_LOG_BLOCK_SIZE
00677
00678
00679
00680
00681 #define LOG_FILE_END_LSN (OS_FILE_LOG_BLOCK_SIZE + 4)
00682
00683
00684
00685
00686
00687
00688
00689 #define LOG_CHECKPOINT_1 OS_FILE_LOG_BLOCK_SIZE
00690
00691
00692
00693
00694
00695 #define LOG_CHECKPOINT_2 (3 * OS_FILE_LOG_BLOCK_SIZE)
00696
00697
00698 #define LOG_FILE_HDR_SIZE (4 * OS_FILE_LOG_BLOCK_SIZE)
00699
00700 #define LOG_GROUP_OK 301
00701 #define LOG_GROUP_CORRUPTED 302
00702
00705 struct log_group_struct{
00706
00707 ulint id;
00708 ulint n_files;
00709 ulint file_size;
00711 ulint space_id;
00713 ulint state;
00715 ib_uint64_t lsn;
00717 ulint lsn_offset;
00718 ulint n_pending_writes;
00720 byte** file_header_bufs_ptr;
00721 byte** file_header_bufs;
00723 #ifdef UNIV_LOG_ARCHIVE
00724
00725 byte** archive_file_header_bufs_ptr;
00726 byte** archive_file_header_bufs;
00728 ulint archive_space_id;
00731 ulint archived_file_no;
00733 ulint archived_offset;
00737 ulint next_archived_file_no;
00743 ulint next_archived_offset;
00744 #endif
00745
00746 ib_uint64_t scanned_lsn;
00749 byte* checkpoint_buf_ptr;
00750 byte* checkpoint_buf;
00752 UT_LIST_NODE_T(log_group_t)
00753 log_groups;
00754 };
00755
00757 struct log_struct{
00758 byte pad[64];
00761 ib_uint64_t lsn;
00762 ulint buf_free;
00764 #ifndef UNIV_HOTBACKUP
00765 mutex_t mutex;
00766 #endif
00767
00768 mutex_t log_flush_order_mutex;
00776 byte* buf_ptr;
00777 byte* buf;
00778 ulint buf_size;
00779 ulint max_buf_free;
00782 ulint old_buf_free;
00785 ib_uint64_t old_lsn;
00788 ibool check_flush_or_checkpoint;
00797 UT_LIST_BASE_NODE_T(log_group_t)
00798 log_groups;
00800 #ifndef UNIV_HOTBACKUP
00801
00803 ulint buf_next_to_write;
00810 ib_uint64_t written_to_some_lsn;
00816 ib_uint64_t written_to_all_lsn;
00832 ib_uint64_t write_lsn;
00834 ulint write_end_offset;
00839 ib_uint64_t current_flush_lsn;
00841 ib_uint64_t flushed_to_disk_lsn;
00844 ulint n_pending_writes;
00846
00847
00848
00849
00850 os_event_t no_flush_event;
00856 ibool one_flushed;
00860 os_event_t one_flushed_event;
00869 ulint n_log_ios;
00871 ulint n_log_ios_old;
00873 time_t last_printout_time;
00875
00876
00878 ulint log_group_capacity;
00883 ulint max_modified_age_async;
00889 ulint max_modified_age_sync;
00895 ulint adm_checkpoint_interval;
00900 ulint max_checkpoint_age_async;
00905 ulint max_checkpoint_age;
00909 ib_uint64_t next_checkpoint_no;
00911 ib_uint64_t last_checkpoint_lsn;
00913 ib_uint64_t next_checkpoint_lsn;
00915 ulint n_pending_checkpoint_writes;
00918 rw_lock_t checkpoint_lock;
00922 #endif
00923 byte* checkpoint_buf_ptr;
00924 byte* checkpoint_buf;
00926
00927 #ifdef UNIV_LOG_ARCHIVE
00928
00929 ulint archiving_state;
00931 ib_uint64_t archived_lsn;
00933 ulint max_archived_lsn_age_async;
00937 ulint max_archived_lsn_age;
00940 ib_uint64_t next_archived_lsn;
00946 ulint archiving_phase;
00948 ulint n_pending_archive_ios;
00951 rw_lock_t archive_lock;
00955 ulint archive_buf_size;
00956 byte* archive_buf;
00958 os_event_t archiving_on;
00961
00962 #endif
00963 };
00964
00966 #define log_flush_order_mutex_own() \
00967 mutex_own(&log_sys->log_flush_order_mutex)
00968
00970 #define log_flush_order_mutex_enter() do { \
00971 mutex_enter(&log_sys->log_flush_order_mutex); \
00972 } while (0)
00973
00974 # define log_flush_order_mutex_exit() do { \
00975 mutex_exit(&log_sys->log_flush_order_mutex); \
00976 } while (0)
00977
00978 #ifdef UNIV_LOG_ARCHIVE
00979
00980 #define LOG_ARCH_ON 71
00981 #define LOG_ARCH_STOPPING 72
00982 #define LOG_ARCH_STOPPING2 73
00983 #define LOG_ARCH_STOPPED 74
00984 #define LOG_ARCH_OFF 75
00985
00986 #endif
00987
00988 #ifndef UNIV_NONINL
00989 #include "log0log.ic"
00990 #endif
00991
00992 #endif