diff options
Diffstat (limited to 'storage/innobase/buf/buf0buf.cc')
-rw-r--r-- | storage/innobase/buf/buf0buf.cc | 445 |
1 files changed, 178 insertions, 267 deletions
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index a6ed277a90e..754b2cd1c25 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -2,7 +2,7 @@ Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2008, Google Inc. -Copyright (c) 2013, 2017, MariaDB Corporation. All Rights Reserved. +Copyright (c) 2013, 2017, MariaDB Corporation. Portions of this file contain modifications contributed and copyrighted by Google, Inc. Those modifications are gratefully acknowledged and are described @@ -347,7 +347,7 @@ typedef std::map< const byte*, buf_chunk_t*, std::less<const byte*>, - ut_allocator<std::pair<const byte*, buf_chunk_t*> > > + ut_allocator<std::pair<const byte* const, buf_chunk_t*> > > buf_pool_chunk_map_t; static buf_pool_chunk_map_t* buf_chunk_map_reg; @@ -405,10 +405,22 @@ buf_pool_register_chunk( /** Decrypt a page. @param[in,out] bpage Page control block +@param[in,out] space tablespace @return whether the operation was successful */ static bool -buf_page_decrypt_after_read(buf_page_t* bpage); +buf_page_decrypt_after_read(buf_page_t* bpage, fil_space_t* space) + MY_ATTRIBUTE((nonnull)); + +/** Check if page is maybe compressed, encrypted or both when we encounter +corrupted page. Note that we can't be 100% sure if page is corrupted +or decrypt/decompress just failed. +@param[in,out] bpage Page +@return true if page corrupted, false if not */ +static +bool +buf_page_check_corrupt(buf_page_t* bpage) + MY_ATTRIBUTE((nonnull, warn_unused_result)); /* prototypes for new functions added to ha_innodb.cc */ trx_t* innobase_get_trx(); @@ -600,10 +612,6 @@ buf_page_is_zeroes( @param[in] read_buf database page @param[in] checksum_field1 new checksum field @param[in] checksum_field2 old checksum field -@param[in] page_no page number of given read_buf -@param[in] is_log_enabled true if log option is enabled -@param[in] log_file file pointer to log_file -@param[in] curr_algo current checksum algorithm @param[in] use_legacy_big_endian use legacy big endian algorithm @return true if the page is in crc32 checksum format. */ bool @@ -611,24 +619,18 @@ buf_page_is_checksum_valid_crc32( const byte* read_buf, ulint checksum_field1, ulint checksum_field2, -#ifdef UNIV_INNOCHECKSUM - uintmax_t page_no, - bool is_log_enabled, - FILE* log_file, - const srv_checksum_algorithm_t curr_algo, -#endif /* UNIV_INNOCHECKSUM */ bool use_legacy_big_endian) { const uint32_t crc32 = buf_calc_page_crc32(read_buf, use_legacy_big_endian); #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled - && curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) { + if (log_file + && srv_checksum_algorithm == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) { fprintf(log_file, "page::%lu;" " crc32 calculated = %u;" " recorded checksum field1 = %lu recorded" - " checksum field2 =%lu\n", page_no, + " checksum field2 =%lu\n", cur_page_num, crc32, checksum_field1, checksum_field2); } #endif /* UNIV_INNOCHECKSUM */ @@ -659,23 +661,12 @@ invalid: @param[in] read_buf database page @param[in] checksum_field1 new checksum field @param[in] checksum_field2 old checksum field -@param[in] page_no page number of given read_buf -@param[in] is_log_enabled true if log option is enabled -@param[in] log_file file pointer to log_file -@param[in] curr_algo current checksum algorithm @return true if the page is in innodb checksum format. */ bool buf_page_is_checksum_valid_innodb( const byte* read_buf, ulint checksum_field1, - ulint checksum_field2 -#ifdef UNIV_INNOCHECKSUM - ,uintmax_t page_no, - bool is_log_enabled, - FILE* log_file, - const srv_checksum_algorithm_t curr_algo -#endif /* UNIV_INNOCHECKSUM */ - ) + ulint checksum_field2) { /* There are 2 valid formulas for checksum_field2 (old checksum field) which algo=innodb could have @@ -691,31 +682,31 @@ buf_page_is_checksum_valid_innodb( ulint new_checksum = buf_calc_page_new_checksum(read_buf); #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled - && curr_algo == SRV_CHECKSUM_ALGORITHM_INNODB) { + if (log_file + && srv_checksum_algorithm == SRV_CHECKSUM_ALGORITHM_INNODB) { fprintf(log_file, "page::%lu;" " old style: calculated =" " %lu; recorded = %lu\n", - page_no, old_checksum, + cur_page_num, old_checksum, checksum_field2); fprintf(log_file, "page::%lu;" " new style: calculated =" " %lu; crc32 = %u; recorded = %lu\n", - page_no, new_checksum, + cur_page_num, new_checksum, buf_calc_page_crc32(read_buf), checksum_field1); } - if (is_log_enabled - && curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) { + if (log_file + && srv_checksum_algorithm == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) { fprintf(log_file, "page::%lu;" " old style: calculated =" " %lu; recorded checksum = %lu\n", - page_no, old_checksum, + cur_page_num, old_checksum, checksum_field2); fprintf(log_file, "page::%lu;" " new style: calculated =" " %lu; recorded checksum = %lu\n", - page_no, new_checksum, + cur_page_num, new_checksum, checksum_field1); } #endif /* UNIV_INNOCHECKSUM */ @@ -755,23 +746,12 @@ buf_page_is_checksum_valid_innodb( @param[in] read_buf database page @param[in] checksum_field1 new checksum field @param[in] checksum_field2 old checksum field -@param[in] page_no page number of given read_buf -@param[in] is_log_enabled true if log option is enabled -@param[in] log_file file pointer to log_file -@param[in] curr_algo current checksum algorithm @return true if the page is in none checksum format. */ bool buf_page_is_checksum_valid_none( const byte* read_buf, ulint checksum_field1, - ulint checksum_field2 -#ifdef UNIV_INNOCHECKSUM - ,uintmax_t page_no, - bool is_log_enabled, - FILE* log_file, - const srv_checksum_algorithm_t curr_algo -#endif /* UNIV_INNOCHECKSUM */ - ) + ulint checksum_field2) { #ifndef DBUG_OFF if (checksum_field1 != checksum_field2 @@ -787,13 +767,13 @@ buf_page_is_checksum_valid_none( #endif /* DBUG_OFF */ #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled - && curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_NONE) { + if (log_file + && srv_checksum_algorithm == SRV_CHECKSUM_ALGORITHM_STRICT_NONE) { fprintf(log_file, "page::%lu; none checksum: calculated" " = %lu; recorded checksum_field1 = %lu" " recorded checksum_field2 = %lu\n", - page_no, BUF_NO_CHECKSUM_MAGIC, + cur_page_num, BUF_NO_CHECKSUM_MAGIC, checksum_field1, checksum_field2); } #endif /* UNIV_INNOCHECKSUM */ @@ -808,10 +788,6 @@ the LSN @param[in] read_buf database page @param[in] page_size page size @param[in] space tablespace -@param[in] page_no page number of given read_buf -@param[in] strict_check true if strict-check option is enabled -@param[in] is_log_enabled true if log option is enabled -@param[in] log_file file pointer to log_file @return TRUE if corrupted */ bool buf_page_is_corrupted( @@ -819,12 +795,6 @@ buf_page_is_corrupted( const byte* read_buf, const page_size_t& page_size, const fil_space_t* space -#ifdef UNIV_INNOCHECKSUM - ,uintmax_t page_no, - bool strict_check, - bool is_log_enabled, - FILE* log_file -#endif /* UNIV_INNOCHECKSUM */ ) { ulint checksum_field1; @@ -914,15 +884,8 @@ buf_page_is_corrupted( } if (page_size.is_compressed()) { -#ifdef UNIV_INNOCHECKSUM - return(!page_zip_verify_checksum(read_buf, - page_size.physical(), - page_no, strict_check, - is_log_enabled, log_file)); -#else return(!page_zip_verify_checksum(read_buf, page_size.physical())); -#endif /* UNIV_INNOCHECKSUM */ } checksum_field1 = mach_read_from_4( @@ -964,10 +927,10 @@ buf_page_is_corrupted( } #ifdef UNIV_INNOCHECKSUM if (i >= page_size.logical()) { - if (is_log_enabled) { + if (log_file) { fprintf(log_file, "Page::%lu" " is empty and uncorrupted\n", - page_no); + cur_page_num); } return(false); } @@ -993,20 +956,13 @@ buf_page_is_corrupted( case SRV_CHECKSUM_ALGORITHM_STRICT_CRC32: if (buf_page_is_checksum_valid_crc32(read_buf, - checksum_field1, checksum_field2, -#ifdef UNIV_INNOCHECKSUM - page_no, is_log_enabled, log_file, curr_algo, -#endif /* UNIV_INNOCHECKSUM */ - false)) { + checksum_field1, checksum_field2, false)) { return(false); } if (buf_page_is_checksum_valid_none(read_buf, - checksum_field1, checksum_field2 -#ifdef UNIV_INNOCHECKSUM - , page_no, is_log_enabled, log_file, curr_algo)) { -#else /* UNIV_INNOCHECKSUM */ - )) { + checksum_field1, checksum_field2)) { +#ifndef UNIV_INNOCHECKSUM if (curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) { page_warn_strict_checksum( @@ -1014,20 +970,20 @@ buf_page_is_corrupted( SRV_CHECKSUM_ALGORITHM_NONE, page_id); } -#endif /* UNIV_INNOCHECKSUM */ +#endif /* !UNIV_INNOCHECKSUM */ #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled) { + if (log_file) { fprintf(log_file, "page::%lu;" " old style: calculated = " ULINTPF ";" - " recorded = " ULINTPF "\n", page_no, + " recorded = " ULINTPF "\n", cur_page_num, buf_calc_page_old_checksum(read_buf), checksum_field2); fprintf(log_file, "page::%lu;" " new style: calculated = " ULINTPF ";" " crc32 = %u; recorded = " ULINTPF "\n", - page_no, + cur_page_num, buf_calc_page_new_checksum(read_buf), buf_calc_page_crc32(read_buf), checksum_field1); @@ -1043,11 +999,7 @@ buf_page_is_corrupted( Otherwise we check innodb checksum first. */ if (legacy_big_endian_checksum) { if (buf_page_is_checksum_valid_crc32(read_buf, - checksum_field1, checksum_field2, -#ifdef UNIV_INNOCHECKSUM - page_no, is_log_enabled, log_file, curr_algo, -#endif /* UNIV_INNOCHECKSUM */ - true)) { + checksum_field1, checksum_field2, true)) { return(false); } @@ -1055,11 +1007,8 @@ buf_page_is_corrupted( } if (buf_page_is_checksum_valid_innodb(read_buf, - checksum_field1, checksum_field2 -#ifdef UNIV_INNOCHECKSUM - , page_no, is_log_enabled, log_file, curr_algo)) { -#else /* UNIV_INNOCHECKSUM */ - )) { + checksum_field1, checksum_field2)) { +#ifndef UNIV_INNOCHECKSUM if (curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_CRC32) { page_warn_strict_checksum( @@ -1067,27 +1016,23 @@ buf_page_is_corrupted( SRV_CHECKSUM_ALGORITHM_INNODB, page_id); } -#endif /* UNIV_INNOCHECKSUM */ +#endif /* !UNIV_INNOCHECKSUM */ return(false); } /* If legacy checksum is not checked, do it now. */ if (!legacy_checksum_checked && buf_page_is_checksum_valid_crc32( - read_buf, checksum_field1, checksum_field2, -#ifdef UNIV_INNOCHECKSUM - page_no, is_log_enabled, log_file, curr_algo, -#endif /* UNIV_INNOCHECKSUM */ - true)) { + read_buf, checksum_field1, checksum_field2, true)) { legacy_big_endian_checksum = true; return(false); } #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled) { + if (log_file) { fprintf(log_file, "Fail; page %lu" " invalid (fails crc32 checksum)\n", - page_no); + cur_page_num); } #endif /* UNIV_INNOCHECKSUM */ return(true); @@ -1096,20 +1041,13 @@ buf_page_is_corrupted( case SRV_CHECKSUM_ALGORITHM_STRICT_INNODB: if (buf_page_is_checksum_valid_innodb(read_buf, - checksum_field1, checksum_field2 -#ifdef UNIV_INNOCHECKSUM - , page_no, is_log_enabled, log_file, curr_algo -#endif /* UNIV_INNOCHECKSUM */ - )) { + checksum_field1, checksum_field2)) { return(false); } if (buf_page_is_checksum_valid_none(read_buf, - checksum_field1, checksum_field2 -#ifdef UNIV_INNOCHECKSUM - , page_no, is_log_enabled, log_file, curr_algo)) { -#else /* UNIV_INNOCHECKSUM */ - )) { + checksum_field1, checksum_field2)) { +#ifndef UNIV_INNOCHECKSUM if (curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) { page_warn_strict_checksum( @@ -1117,19 +1055,19 @@ buf_page_is_corrupted( SRV_CHECKSUM_ALGORITHM_NONE, page_id); } -#endif /* UNIV_INNOCHECKSUM */ +#endif /* !UNIV_INNOCHECKSUM */ #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled) { + if (log_file) { fprintf(log_file, "page::%lu;" " old style: calculated = %lu;" - " recorded = %lu\n", page_no, + " recorded = %lu\n", cur_page_num, buf_calc_page_old_checksum(read_buf), checksum_field2); fprintf(log_file, "page::%lu;" " new style: calculated = %lu;" " crc32 = %u; recorded = %lu\n", - page_no, + cur_page_num, buf_calc_page_new_checksum(read_buf), buf_calc_page_crc32(read_buf), checksum_field1); @@ -1138,19 +1076,11 @@ buf_page_is_corrupted( return(false); } -#ifdef UNIV_INNOCHECKSUM - if (buf_page_is_checksum_valid_crc32(read_buf, - checksum_field1, checksum_field2, - page_no, is_log_enabled, log_file, curr_algo, false) - || buf_page_is_checksum_valid_crc32(read_buf, - checksum_field1, checksum_field2, - page_no, is_log_enabled, log_file, curr_algo, true)) { -#else /* UNIV_INNOCHECKSUM */ if (buf_page_is_checksum_valid_crc32(read_buf, checksum_field1, checksum_field2, false) || buf_page_is_checksum_valid_crc32(read_buf, checksum_field1, checksum_field2, true)) { - +#ifndef UNIV_INNOCHECKSUM if (curr_algo == SRV_CHECKSUM_ALGORITHM_STRICT_INNODB) { page_warn_strict_checksum( @@ -1158,16 +1088,16 @@ buf_page_is_corrupted( SRV_CHECKSUM_ALGORITHM_CRC32, page_id); } -#endif /* UNIV_INNOCHECKSUM */ +#endif /* !UNIV_INNOCHECKSUM */ return(false); } #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled) { + if (log_file) { fprintf(log_file, "Fail; page %lu" " invalid (fails innodb checksum)\n", - page_no); + cur_page_num); } #endif /* UNIV_INNOCHECKSUM */ return(true); @@ -1175,54 +1105,39 @@ buf_page_is_corrupted( case SRV_CHECKSUM_ALGORITHM_STRICT_NONE: if (buf_page_is_checksum_valid_none(read_buf, - checksum_field1, checksum_field2 -#ifdef UNIV_INNOCHECKSUM - , page_no, is_log_enabled, log_file, curr_algo -#endif /* UNIV_INNOCHECKSUM */ - )) { + checksum_field1, checksum_field2)) { return(false); } -#ifdef UNIV_INNOCHECKSUM - if (buf_page_is_checksum_valid_crc32(read_buf, - checksum_field1, checksum_field2, - page_no, is_log_enabled, log_file, curr_algo, false) - || buf_page_is_checksum_valid_crc32(read_buf, - checksum_field1, checksum_field2, - page_no, is_log_enabled, log_file, curr_algo, true)) { -#else /* UNIV_INNOCHECKSUM */ if (buf_page_is_checksum_valid_crc32(read_buf, checksum_field1, checksum_field2, false) || buf_page_is_checksum_valid_crc32(read_buf, checksum_field1, checksum_field2, true)) { - +#ifndef UNIV_INNOCHECKSUM page_warn_strict_checksum( curr_algo, SRV_CHECKSUM_ALGORITHM_CRC32, page_id); -#endif /* UNIV_INNOCHECKSUM */ +#endif /* !UNIV_INNOCHECKSUM */ return(false); } if (buf_page_is_checksum_valid_innodb(read_buf, - checksum_field1, checksum_field2 -#ifdef UNIV_INNOCHECKSUM - , page_no, is_log_enabled, log_file, curr_algo)) { -#else /* UNIV_INNOCHECKSUM */ - )) { + checksum_field1, checksum_field2)) { +#ifndef UNIV_INNOCHECKSUM page_warn_strict_checksum( curr_algo, SRV_CHECKSUM_ALGORITHM_INNODB, page_id); -#endif /* UNIV_INNOCHECKSUM */ +#endif /* !UNIV_INNOCHECKSUM */ return(false); } #ifdef UNIV_INNOCHECKSUM - if (is_log_enabled) { + if (log_file) { fprintf(log_file, "Fail; page %lu" " invalid (fails none checksum)\n", - page_no); + cur_page_num); } #endif /* UNIV_INNOCHECKSUM */ return(true); @@ -1496,6 +1411,10 @@ buf_block_init( { UNIV_MEM_DESC(frame, UNIV_PAGE_SIZE); + /* This function should only be executed at database startup or by + buf_pool_resize(). Either way, adaptive hash index must not exist. */ + assert_block_ahi_empty_on_init(block); + block->frame = frame; block->page.buf_pool_index = buf_pool_index(buf_pool); @@ -1526,11 +1445,6 @@ buf_block_init( ut_d(block->in_unzip_LRU_list = FALSE); ut_d(block->in_withdraw_list = FALSE); -#ifdef BTR_CUR_HASH_ADAPT -# if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG - block->n_pointers = 0; -# endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ -#endif /* BTR_CUR_HASH_ADAPT */ page_zip_des_init(&block->page.zip); mutex_create(LATCH_ID_BUF_BLOCK_MUTEX, &block->mutex); @@ -1763,7 +1677,9 @@ buf_chunk_not_freed( == block->page.newest_modification); ut_ad(block->page.oldest_modification == 0 || block->page.oldest_modification - == recv_sys->recovered_lsn); + == recv_sys->recovered_lsn + || srv_force_recovery + == SRV_FORCE_NO_LOG_REDO); ut_ad(block->page.buf_fix_count == 0); ut_ad(block->page.io_fix == BUF_IO_NONE); break; @@ -2244,6 +2160,10 @@ buf_page_realloc( /* set other flags of buf_block_t */ #ifdef BTR_CUR_HASH_ADAPT + /* This code should only be executed by buf_pool_resize(), + while the adaptive hash index is disabled. */ + assert_block_ahi_empty(block); + assert_block_ahi_empty_on_init(new_block); ut_ad(!block->index); new_block->index = NULL; new_block->n_hash_helps = 0; @@ -3210,20 +3130,23 @@ buf_pool_clear_hash_index() for (; i--; block++) { dict_index_t* index = block->index; + assert_block_ahi_valid(block); /* We can set block->index = NULL - when we have an x-latch on search latch; - see the comment in buf0buf.h */ + and block->n_pointers = 0 + when btr_search_own_all(RW_LOCK_X); + see the comments in buf0buf.h */ if (!index) { - /* Not hashed */ continue; } - block->index = NULL; + ut_ad(buf_block_get_state(block) + == BUF_BLOCK_FILE_PAGE); # if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG block->n_pointers = 0; # endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ + block->index = NULL; } } } @@ -3915,6 +3838,9 @@ buf_block_init_low( { block->skip_flush_check = false; #ifdef BTR_CUR_HASH_ADAPT + /* No adaptive hash index entries may point to a previously + unused (and now freshly allocated) block. */ + assert_block_ahi_empty_on_init(block); block->index = NULL; block->n_hash_helps = 0; @@ -5266,7 +5192,7 @@ buf_page_init( ut_d(buf_LRU_print()); ut_d(buf_validate()); ut_d(buf_LRU_validate()); - ut_ad(0); + ut_error; } ut_ad(!block->page.in_zip_hash); @@ -5833,16 +5759,14 @@ buf_mark_space_corrupt( return(ret); } -/********************************************************************//** -Check if page is maybe compressed, encrypted or both when we encounter +/** Check if page is maybe compressed, encrypted or both when we encounter corrupted page. Note that we can't be 100% sure if page is corrupted or decrypt/decompress just failed. @param[in,out] bpage Page @return true if page corrupted, false if not */ -UNIV_INTERN +static bool -buf_page_check_corrupt( - buf_page_t* bpage) +buf_page_check_corrupt(buf_page_t* bpage) { byte* dst_frame = (bpage->zip.data) ? bpage->zip.data : ((buf_block_t*) bpage)->frame; @@ -5945,8 +5869,13 @@ buf_page_io_complete( ulint read_space_id; ut_ad(bpage->zip.data != NULL || ((buf_block_t*)bpage)->frame != NULL); + fil_space_t* space = fil_space_acquire_for_io( + bpage->id.space()); + if (!space) { + return false; + } - buf_page_decrypt_after_read(bpage); + buf_page_decrypt_after_read(bpage, space); if (bpage->size.is_compressed()) { frame = bpage->zip.data; @@ -6020,21 +5949,17 @@ database_corrupted: && buf_mark_space_corrupt(bpage)) { ib::info() << "Simulated IMPORT " "corruption"; + fil_space_release_for_io(space); return(true); } goto page_not_corrupt; ); if (!bpage->encrypted) { - fil_system_enter(); - fil_space_t* space = fil_space_get_by_id(bpage->id.space()); - fil_system_exit(); - ib::error() << "Database page corruption on disk" " or a failed file read of tablespace " - << (space->name ? space->name : "NULL") - << " page " << bpage->id + << space->name << " page " << bpage->id << ". You may have to recover from " << "a backup."; @@ -6063,6 +5988,7 @@ database_corrupted: if (bpage->id.space() > TRX_SYS_SPACE && buf_mark_space_corrupt(bpage)) { + fil_space_release_for_io(space); return(false); } else { if (!bpage->encrypted) { @@ -6076,7 +6002,7 @@ database_corrupted: } ib_push_warning(innobase_get_trx(), DB_DECRYPTION_FAILED, - "Table in tablespace %lu encrypted." + "Table in tablespace %u encrypted." "However key management plugin or used key_id %lu is not found or" " used encryption algorithm or method does not match." " Can't continue opening the table.", @@ -6088,6 +6014,7 @@ database_corrupted: ut_error; } + fil_space_release_for_io(space); return(false); } } @@ -6131,6 +6058,8 @@ database_corrupted: } } + + fil_space_release_for_io(space); } else { /* io_type == BUF_IO_WRITE */ if (bpage->slot) { @@ -7066,15 +6995,16 @@ buf_print_io_instance( ut_ad(pool_info); fprintf(file, - "Buffer pool size %lu\n" - "Free buffers %lu\n" - "Database pages %lu\n" - "Old database pages %lu\n" - "Modified db pages %lu\n" + "Buffer pool size " ULINTPF "\n" + "Free buffers " ULINTPF "\n" + "Database pages " ULINTPF "\n" + "Old database pages " ULINTPF "\n" + "Modified db pages " ULINTPF "\n" "Percent of dirty pages(LRU & free pages): %.3f\n" "Max dirty pages percent: %.3f\n" - "Pending reads %lu\n" - "Pending writes: LRU %lu, flush list %lu, single page %lu\n", + "Pending reads " ULINTPF "\n" + "Pending writes: LRU " ULINTPF ", flush list " ULINTPF + ", single page " ULINTPF "\n", pool_info->pool_size, pool_info->free_list_len, pool_info->lru_len, @@ -7089,9 +7019,10 @@ buf_print_io_instance( pool_info->n_pending_flush_single_page); fprintf(file, - "Pages made young %lu, not young %lu\n" + "Pages made young " ULINTPF ", not young " ULINTPF "\n" "%.2f youngs/s, %.2f non-youngs/s\n" - "Pages read %lu, created %lu, written %lu\n" + "Pages read " ULINTPF ", created " ULINTPF + ", written " ULINTPF "\n" "%.2f reads/s, %.2f creates/s, %.2f writes/s\n", pool_info->n_pages_made_young, pool_info->n_pages_not_made_young, @@ -7105,23 +7036,22 @@ buf_print_io_instance( pool_info->pages_written_rate); if (pool_info->n_page_get_delta) { - double hit_rate = ((1000 * pool_info->page_read_delta) - / pool_info->n_page_get_delta); + double hit_rate = double(pool_info->page_read_delta) + / pool_info->n_page_get_delta; - if (hit_rate > 1000) { - hit_rate = 1000; + if (hit_rate > 1) { + hit_rate = 1; } - hit_rate = 1000 - hit_rate; - fprintf(file, - "Buffer pool hit rate %lu / 1000," - " young-making rate %lu / 1000 not %lu / 1000\n", - (ulint) hit_rate, - (ulint) (1000 * pool_info->young_making_delta - / pool_info->n_page_get_delta), - (ulint) (1000 * pool_info->not_young_making_delta - / pool_info->n_page_get_delta)); + "Buffer pool hit rate " ULINTPF " / 1000," + " young-making rate " ULINTPF " / 1000 not " + ULINTPF " / 1000\n", + ulint(1000 * (1 - hit_rate)), + ulint(1000 * double(pool_info->young_making_delta) + / pool_info->n_page_get_delta), + ulint(1000 * double(pool_info->not_young_making_delta) + / pool_info->n_page_get_delta)); } else { fputs("No buffer pool page gets since the last printout\n", file); @@ -7372,72 +7302,55 @@ buf_pool_reserve_tmp_slot( return (free_slot); } -/********************************************************************//** -Encrypts a buffer page right before it's flushed to disk -@param[in,out] bpage Page control block -@param[in,out] src_frame Source page -@param[in] space_id Tablespace id -@return either unencrypted source page or decrypted page. -*/ +/** Encryption and page_compression hook that is called just before +a page is written to disk. +@param[in,out] space tablespace +@param[in,out] bpage buffer page +@param[in] src_frame physical page frame that is being encrypted +@return page frame to be written to file +(may be src_frame or an encrypted/compressed copy of it) */ UNIV_INTERN byte* buf_page_encrypt_before_write( + fil_space_t* space, buf_page_t* bpage, - byte* src_frame, - ulint space_id) + byte* src_frame) { + ut_ad(space->id == bpage->id.space()); bpage->real_size = UNIV_PAGE_SIZE; fil_page_type_validate(src_frame); - if (bpage->id.page_no() == 0) { + switch (bpage->id.page_no()) { + case 0: /* Page 0 of a tablespace is not encrypted/compressed */ ut_ad(bpage->key_version == 0); return src_frame; - } - - if (space_id == TRX_SYS_SPACE && bpage->id.page_no() == TRX_SYS_PAGE_NO) { - /* don't encrypt/compress page as it contains address to dblwr buffer */ - bpage->key_version = 0; - return src_frame; - } - - fil_space_t* space = fil_space_acquire_silent(space_id); - - /* Tablespace must exist during write operation */ - if (!space) { - /* This could be true on discard if we have injected a error - case e.g. in innodb.innodb-wl5522-debug-zip so that space - is already marked as stop_new_ops = true. */ - return src_frame; + case TRX_SYS_PAGE_NO: + if (bpage->id.space() == TRX_SYS_SPACE) { + /* don't encrypt/compress page as it contains + address to dblwr buffer */ + bpage->key_version = 0; + return src_frame; + } } const page_size_t page_size(space->flags); fil_space_crypt_t* crypt_data = space->crypt_data; - bool encrypted = true; - - if (space->crypt_data != NULL && space->crypt_data->not_encrypted()) { - /* Encryption is disabled */ - encrypted = false; - } - - if (!srv_encrypt_tables && (crypt_data == NULL || crypt_data->is_default_encryption())) { - /* Encryption is disabled */ - encrypted = false; - } + const bool encrypted = crypt_data + && !crypt_data->not_encrypted() + && crypt_data->type != CRYPT_SCHEME_UNENCRYPTED + && (!crypt_data->is_default_encryption() + || srv_encrypt_tables); - /* Is encryption needed? */ - if (crypt_data == NULL || crypt_data->type == CRYPT_SCHEME_UNENCRYPTED) { - /* An unencrypted table */ + if (!encrypted) { bpage->key_version = 0; - encrypted = false; } - bool page_compressed = fil_space_is_page_compressed(bpage->id.space()); + bool page_compressed = FSP_FLAGS_HAS_PAGE_COMPRESSION(space->flags); if (!encrypted && !page_compressed) { /* No need to encrypt or page compress the page */ - fil_space_release(space); return src_frame; } @@ -7464,25 +7377,21 @@ buf_page_encrypt_before_write( bpage->real_size = page_size.physical(); slot->out_buf = dst_frame = tmp; -#ifdef UNIV_DEBUG - fil_page_type_validate(tmp); -#endif - + ut_d(fil_page_type_validate(tmp)); } else { /* First we compress the page content */ ulint out_len = 0; - ulint block_size = fil_space_get_block_size(space_id, bpage->id.page_no(), page_size.logical()); - - byte *tmp = fil_compress_page(space_id, - (byte *)src_frame, - slot->comp_buf, - page_size.logical(), - fil_space_get_page_compression_level(space_id), - block_size, - encrypted, - &out_len, - IF_LZO(slot->lzo_mem, NULL) - ); + + byte *tmp = fil_compress_page( + space, + (byte *)src_frame, + slot->comp_buf, + page_size.logical(), + fsp_flags_get_page_compression_level(space->flags), + fil_space_get_block_size(space, bpage->id.page_no()), + encrypted, + &out_len, + IF_LZO(slot->lzo_mem, NULL)); bpage->real_size = out_len; @@ -7505,18 +7414,21 @@ buf_page_encrypt_before_write( ut_d(fil_page_type_validate(dst_frame)); - fil_space_release(space); // return dst_frame which will be written return dst_frame; } /** Decrypt a page. @param[in,out] bpage Page control block +@param[in,out] space tablespace @return whether the operation was successful */ static bool -buf_page_decrypt_after_read(buf_page_t* bpage) +buf_page_decrypt_after_read(buf_page_t* bpage, fil_space_t* space) { + ut_ad(space->n_pending_ios > 0); + ut_ad(space->id == bpage->id.space()); + bool compressed = bpage->size.is_compressed(); const page_size_t& size = bpage->size; byte* dst_frame = compressed ? bpage->zip.data : @@ -7535,12 +7447,10 @@ buf_page_decrypt_after_read(buf_page_t* bpage) return (true); } - FilSpace space(bpage->id.space(), true); - /* Page is encrypted if encryption information is found from tablespace and page contains used key_version. This is true also for pages first compressed and then encrypted. */ - if (!space() || !space()->crypt_data) { + if (!space->crypt_data) { key_version = 0; } @@ -7553,9 +7463,9 @@ buf_page_decrypt_after_read(buf_page_t* bpage) /* decompress using comp_buf to dst_frame */ fil_decompress_page(slot->comp_buf, - dst_frame, - size.logical(), - &bpage->write_size); + dst_frame, + ulong(size.logical()), + &bpage->write_size); /* Mark this slot as free */ slot->reserved = false; @@ -7600,9 +7510,9 @@ buf_page_decrypt_after_read(buf_page_t* bpage) ut_d(fil_page_type_validate(dst_frame)); /* decompress using comp_buf to dst_frame */ fil_decompress_page(slot->comp_buf, - dst_frame, - size.logical(), - &bpage->write_size); + dst_frame, + ulong(size.logical()), + &bpage->write_size); ut_d(fil_page_type_validate(dst_frame)); } @@ -7612,6 +7522,7 @@ buf_page_decrypt_after_read(buf_page_t* bpage) } } + ut_ad(space->n_pending_ios > 0); return (success); } |