42 #ifndef UNIV_HOTBACKUP
55 #include <drizzled/errmsg_print.h>
245 #ifndef UNIV_HOTBACKUP
247 static const int WAIT_FOR_READ = 5000;
249 static const ulint BUF_PAGE_READ_MAX_RETRIES = 100;
254 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
255 static ulint buf_dbg_counter = 0;
262 UNIV_INTERN ibool buf_debug_prints = FALSE;
265 #ifdef UNIV_PFS_RWLOCK
268 UNIV_INTERN mysql_pfs_key_t buf_block_lock_key;
269 # ifdef UNIV_SYNC_DEBUG
270 UNIV_INTERN mysql_pfs_key_t buf_block_debug_latch_key;
274 #ifdef UNIV_PFS_MUTEX
275 UNIV_INTERN mysql_pfs_key_t buffer_block_mutex_key;
276 UNIV_INTERN mysql_pfs_key_t buf_pool_mutex_key;
277 UNIV_INTERN mysql_pfs_key_t buf_pool_zip_mutex_key;
278 UNIV_INTERN mysql_pfs_key_t flush_list_mutex_key;
281 #if defined UNIV_PFS_MUTEX || defined UNIV_PFS_RWLOCK
282 # ifndef PFS_SKIP_BUFFER_MUTEX_RWLOCK
288 # define PFS_GROUP_BUFFER_SYNC
294 # define PFS_MAX_BUFFER_MUTEX_LOCK_REGISTER ULINT_MAX
315 buf_pool_get_oldest_modification(
void)
321 ib_uint64_t oldest_lsn = 0;
338 ut_ad(bpage->in_flush_list);
344 if (!oldest_lsn || oldest_lsn > lsn) {
361 buf_get_total_list_len(
365 ulint* flush_list_len)
393 memset(tot_stat, 0,
sizeof(*tot_stat));
401 buf_stat = &buf_pool->
stat;
430 if (buf_pool == NULL) {
437 block = buf_LRU_get_free_block(buf_pool, zip_size);
451 buf_calc_page_new_checksum(
470 checksum = checksum & 0xFFFFFFFFUL;
485 buf_calc_page_old_checksum(
493 checksum = checksum & 0xFFFFFFFFUL;
503 buf_page_is_corrupted(
505 const byte* read_buf,
509 ulint checksum_field;
510 ulint old_checksum_field;
512 if (UNIV_LIKELY(!zip_size)
514 read_buf + UNIV_PAGE_SIZE
523 #ifndef UNIV_HOTBACKUP
525 ib_uint64_t current_lsn;
533 drizzled::errmsg_printf(drizzled::error::INFO,
534 "InnoDB: Error: page %lu log sequence number %"PRIu64
". "
535 "InnoDB: is in the future! Current system log sequence number %"PRIu64
". "
536 "Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. See "
537 " " REFMAN
"forcing-recovery.html for more information. ",
551 if (UNIV_LIKELY(srv_use_checksums)) {
555 if (UNIV_UNLIKELY(zip_size)) {
562 read_buf + UNIV_PAGE_SIZE
576 && old_checksum_field
577 != buf_calc_page_old_checksum(read_buf)) {
585 if (checksum_field != 0
588 != buf_calc_page_new_checksum(read_buf)) {
603 const byte* read_buf,
607 #ifndef UNIV_HOTBACKUP
612 ulint size = zip_size;
615 size = UNIV_PAGE_SIZE;
619 fprintf(stderr,
" InnoDB: Page dump in ascii and hex (%lu bytes):\n",
622 fputs(
"\nInnoDB: End of page dump\n", stderr);
627 switch (fil_page_get_type(read_buf)) {
630 checksum = srv_use_checksums
635 " InnoDB: Compressed BLOB page"
636 " checksum %lu, stored %lu\n"
637 "InnoDB: Page lsn %lu %lu\n"
638 "InnoDB: Page number (if stored"
639 " to page already) %lu,\n"
640 "InnoDB: space id (if stored"
641 " to page already) %lu\n",
658 " InnoDB: unknown page type %lu,"
659 " assuming FIL_PAGE_INDEX\n",
660 fil_page_get_type(read_buf));
663 checksum = srv_use_checksums
664 ? page_zip_calc_checksum(read_buf, zip_size)
669 " InnoDB: Compressed page checksum %lu,"
671 "InnoDB: Page lsn %lu %lu\n"
672 "InnoDB: Page number (if stored"
673 " to page already) %lu,\n"
674 "InnoDB: space id (if stored"
675 " to page already) %lu\n",
695 checksum = srv_use_checksums
697 old_checksum = srv_use_checksums
702 " InnoDB: Page checksum %lu, prior-to-4.0.14-form"
704 "InnoDB: stored checksum %lu, prior-to-4.0.14-form"
705 " stored checksum %lu\n"
706 "InnoDB: Page lsn %lu %lu, low 4 bytes of lsn"
708 "InnoDB: Page number (if stored to page already) %lu,\n"
709 "InnoDB: space id (if created with >= MySQL-4.1.1"
710 " and stored already) %lu\n",
711 (ulong) checksum, (ulong) old_checksum,
723 #ifndef UNIV_HOTBACKUP
725 == TRX_UNDO_INSERT) {
727 "InnoDB: Page may be an insert undo log page\n");
730 == TRX_UNDO_UPDATE) {
732 "InnoDB: Page may be an update undo log page\n");
736 switch (fil_page_get_type(read_buf)) {
741 "InnoDB: Page may be an index page where"
742 " index id is %llu\n",
744 #ifndef UNIV_HOTBACKUP
745 index = dict_index_find_on_id_low(index_id);
747 fputs(
"InnoDB: (", stderr);
748 dict_index_name_print(stderr, NULL, index);
749 fputs(
")\n", stderr);
754 fputs(
"InnoDB: Page may be an 'inode' page\n", stderr);
757 fputs(
"InnoDB: Page may be an insert buffer free list page\n",
761 fputs(
"InnoDB: Page may be a freshly allocated page\n",
765 fputs(
"InnoDB: Page may be an insert buffer bitmap page\n",
769 fputs(
"InnoDB: Page may be a system page\n",
773 fputs(
"InnoDB: Page may be a transaction system page\n",
777 fputs(
"InnoDB: Page may be a file space header page\n",
781 fputs(
"InnoDB: Page may be an extent descriptor page\n",
785 fputs(
"InnoDB: Page may be a BLOB page\n",
790 fputs(
"InnoDB: Page may be a compressed BLOB page\n",
796 #ifndef UNIV_HOTBACKUP
798 # ifdef PFS_GROUP_BUFFER_SYNC
807 pfs_register_buffer_block(
812 ulint num_to_register;
818 PFS_MAX_BUFFER_MUTEX_LOCK_REGISTER);
820 for (i = 0; i < num_to_register; i++) {
824 # ifdef UNIV_PFS_MUTEX
825 mutex = &block->
mutex;
826 ut_a(!mutex->pfs_psi);
827 mutex->pfs_psi = (PSI_server)
828 ? PSI_server->init_mutex(buffer_block_mutex_key, mutex)
832 # ifdef UNIV_PFS_RWLOCK
833 rwlock = &block->
lock;
834 ut_a(!rwlock->pfs_psi);
835 rwlock->pfs_psi = (PSI_server)
836 ? PSI_server->init_rwlock(buf_block_lock_key, rwlock)
854 UNIV_MEM_DESC(frame, UNIV_PAGE_SIZE, block);
856 block->
frame = frame;
865 #ifdef UNIV_DEBUG_FILE_ACCESSES
866 block->
page.file_page_was_freed = FALSE;
875 block->
page.in_page_hash = FALSE;
876 block->
page.in_zip_hash = FALSE;
877 block->
page.in_flush_list = FALSE;
878 block->
page.in_free_list = FALSE;
879 block->
page.in_LRU_list = FALSE;
880 block->in_unzip_LRU_list = FALSE;
882 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
883 block->n_pointers = 0;
887 #if defined PFS_SKIP_BUFFER_MUTEX_RWLOCK || defined PFS_GROUP_BUFFER_SYNC
894 mutex_create(PFS_NOT_INSTRUMENTED, &block->
mutex, SYNC_BUF_BLOCK);
897 mutex_create(buffer_block_mutex_key, &block->
mutex, SYNC_BUF_BLOCK);
903 #ifdef UNIV_SYNC_DEBUG
905 &block->debug_latch, SYNC_NO_ORDER_CHECK);
928 mem_size +=
ut_2pow_round((mem_size / UNIV_PAGE_SIZE) * (
sizeof *block)
929 + (UNIV_PAGE_SIZE - 1), UNIV_PAGE_SIZE);
934 if (UNIV_UNLIKELY(chunk->
mem == NULL)) {
948 frame =
static_cast<unsigned char *
>(
ut_align(chunk->
mem, UNIV_PAGE_SIZE));
950 - (frame != chunk->
mem);
954 ulint size = chunk->
size;
956 while (frame < (byte*) (chunk->
blocks + size)) {
957 frame += UNIV_PAGE_SIZE;
970 for (i = chunk->
size; i--; ) {
972 buf_block_init(buf_pool, block, frame);
976 memset(block->
frame,
'\0', UNIV_PAGE_SIZE);
981 ut_d(block->
page.in_free_list = TRUE);
985 frame += UNIV_PAGE_SIZE;
988 #ifdef PFS_GROUP_BUFFER_SYNC
989 pfs_register_buffer_block(chunk);
1001 buf_chunk_contains_zip(
1011 for (i = chunk->
size; i--; block++) {
1027 buf_pool_contains_zip(
1037 for (n = buf_pool->
n_chunks; n--; chunk++) {
1039 buf_block_t* block = buf_chunk_contains_zip(chunk, data);
1055 buf_chunk_not_freed(
1064 for (i = chunk->
size; i--; block++) {
1083 mutex_enter(&block->
mutex);
1084 ready = buf_flush_ready_for_replace(&block->
page);
1085 mutex_exit(&block->
mutex);
1113 for (i = chunk->
size; i--; block++) {
1140 for (block = chunk->
blocks; block < block_end; block++) {
1145 ut_ad(!block->in_unzip_LRU_list);
1152 mutex_free(&block->
mutex);
1153 rw_lock_free(&block->
lock);
1154 #ifdef UNIV_SYNC_DEBUG
1155 rw_lock_free(&block->debug_latch);
1157 UNIV_MEM_UNDESC(block);
1167 buf_pool_set_sizes(
void)
1171 ulint curr_size = 0;
1193 buf_pool_init_instance(
1196 ulint buf_pool_size,
1204 mutex_create(buf_pool_mutex_key,
1205 &buf_pool->
mutex, SYNC_BUF_POOL);
1206 mutex_create(buf_pool_zip_mutex_key,
1211 if (buf_pool_size > 0) {
1213 void *chunk_ptr=
mem_zalloc((
sizeof *chunk));
1218 if (!buf_chunk_init(buf_pool, chunk, buf_pool_size)) {
1241 SYNC_BUF_FLUSH_LIST);
1261 buf_pool_free_instance(
1269 chunks = buf_pool->
chunks;
1270 chunk = chunks + buf_pool->
n_chunks;
1272 while (--chunk >= chunks) {
1280 hash_table_free(buf_pool->
zip_hash);
1294 const ulint size = total_size / n_instances;
1296 ut_ad(n_instances > 0);
1303 void *buf_pool_void_ptr=
mem_zalloc(n_instances *
sizeof *buf_pool_ptr);
1306 for (i = 0; i < n_instances; i++) {
1309 if (buf_pool_init_instance(ptr, size, i) != DB_SUCCESS) {
1318 buf_pool_set_sizes();
1319 buf_LRU_old_ratio_update(100 * 3/ 8, FALSE);
1337 for (i = 0; i < n_instances; i++) {
1342 buf_pool_ptr = NULL;
1349 buf_pool_drop_hash_index_instance(
1352 ibool* released_search_latch)
1359 while (--chunk >= chunks) {
1363 for (i = chunk->
size; i--; block++) {
1379 *released_search_latch = TRUE;
1381 rw_lock_x_lock(&block->
lock);
1386 ut_ad(!btr_search_enabled);
1406 btr_search_drop_page_hash_index(block);
1408 rw_lock_x_unlock(&block->
lock);
1412 ut_ad(!btr_search_enabled);
1423 buf_pool_drop_hash_index(
void)
1426 ibool released_search_latch;
1428 #ifdef UNIV_SYNC_DEBUG
1431 ut_ad(!btr_search_enabled);
1436 released_search_latch = FALSE;
1443 buf_pool_drop_hash_index_instance(
1444 buf_pool, &released_search_latch);
1447 }
while (released_search_latch);
1471 ut_ad(bpage->in_LRU_list);
1472 ut_ad(!bpage->in_zip_hash);
1473 ut_ad(bpage->in_page_hash);
1476 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, bpage));
1492 memcpy(dpage, bpage,
sizeof *dpage);
1494 ut_d(bpage->in_LRU_list = FALSE);
1495 ut_d(bpage->in_page_hash = FALSE);
1507 if (UNIV_UNLIKELY(buf_pool->
LRU_old == bpage)) {
1509 #ifdef UNIV_LRU_DEBUG
1525 ut_ad(ut_list_node_313->in_LRU_list)));
1538 buf_pool_shrink_instance(
1546 ulint max_free_size;
1553 btr_search_disable();
1565 chunks = buf_pool->
chunks;
1566 chunk = chunks + buf_pool->
n_chunks;
1567 max_size = max_free_size = 0;
1568 max_chunk = max_free_chunk = NULL;
1570 while (--chunk >= chunks) {
1571 if (chunk->
size <= chunk_size
1572 && chunk->
size > max_free_size) {
1573 if (chunk->
size > max_size) {
1574 max_size = chunk->
size;
1578 if (buf_chunk_all_free(chunk)) {
1579 max_free_size = chunk->
size;
1580 max_free_chunk = chunk;
1585 if (!max_free_size) {
1599 block = max_chunk->
blocks;
1600 bend = block + max_chunk->
size;
1604 for (; block < bend; block++) {
1615 mutex_enter(&block->
mutex);
1621 if (!buf_flush_ready_for_replace(&block->
page)) {
1623 buf_LRU_make_block_old(&block->
page);
1625 }
else if (buf_LRU_free_block(&block->
page, TRUE, NULL)
1630 mutex_exit(&block->
mutex);
1642 && buf_flush_LRU(buf_pool, dirty)
1643 == ULINT_UNDEFINED) {
1651 max_size = max_free_size;
1652 max_chunk = max_free_chunk;
1657 chunks =
static_cast<buf_chunk_t *
>(mem_alloc((buf_pool->
n_chunks - 1) *
sizeof *chunks));
1658 memcpy(chunks, buf_pool->
chunks,
1659 (max_chunk - buf_pool->
chunks) *
sizeof *chunks);
1660 memcpy(chunks + (max_chunk - buf_pool->
chunks),
1667 chunk_size -= max_chunk->
size;
1668 buf_chunk_free(buf_pool, max_chunk);
1670 buf_pool->
chunks = chunks;
1674 if (chunk_size > 1048576 / UNIV_PAGE_SIZE) {
1684 btr_search_enable();
1699 ulint instance_chunk_size;
1701 instance_chunk_size = chunk_size / srv_buf_pool_instances;
1703 buf_pool_shrink_instance(buf_pool, instance_chunk_size);
1706 buf_pool_set_sizes();
1713 buf_pool_page_hash_rebuild_instance(
1729 zip_hash = hash_create(2 * buf_pool->
curr_size);
1732 BUF_POOL_ZIP_FOLD_BPAGE);
1734 hash_table_free(buf_pool->
zip_hash);
1739 chunk = buf_pool->
chunks;
1742 for (i = 0; i < n_chunks; i++, chunk++) {
1746 for (j = 0; j < chunk->
size; j++, block++) {
1768 ut_ad(!b->in_flush_list);
1769 ut_ad(b->in_LRU_list);
1770 ut_ad(b->in_page_hash);
1771 ut_ad(!b->in_zip_hash);
1780 ut_ad(b->in_flush_list);
1781 ut_ad(b->in_LRU_list);
1782 ut_ad(b->in_page_hash);
1783 ut_ad(!b->in_zip_hash);
1814 buf_pool_watch_is_sentinel(
1821 if (bpage < &buf_pool->watch[0]
1831 ut_ad(!bpage->in_zip_hash);
1832 ut_ad(bpage->in_page_hash);
1858 if (UNIV_LIKELY_NULL(bpage)) {
1859 if (!buf_pool_watch_is_sentinel(buf_pool, bpage)) {
1869 bpage = &buf_pool->
watch[i];
1875 ut_ad(!bpage->in_zip_hash);
1877 switch (bpage->
state) {
1879 ut_ad(!bpage->in_page_hash);
1888 bpage->
space = space;
1892 ut_d(bpage->in_page_hash = TRUE);
1897 ut_ad(bpage->in_page_hash);
1919 buf_pool_page_hash_rebuild(
void)
1933 buf_pool_increase_instance(
1942 chunks =
static_cast<buf_chunk_t *
>(mem_alloc((buf_pool->
n_chunks + 1) *
sizeof *chunks));
1944 memcpy(chunks, buf_pool->
chunks, buf_pool->
n_chunks *
sizeof *chunks);
1946 chunk = &chunks[buf_pool->
n_chunks];
1948 if (!buf_chunk_init(buf_pool, chunk, change_size)) {
1955 buf_pool->
chunks = chunks;
1972 for (i = 0; i < srv_buf_pool_instances; i++) {
1973 buf_pool_increase_instance(
1975 change_size / srv_buf_pool_instances);
1978 buf_pool_set_sizes();
1985 buf_pool_resize(
void)
1989 ulint min_change_size = 1048576 * srv_buf_pool_instances;
2009 buf_pool_shrink(change_size);
2020 buf_pool_increase(change_size);
2029 buf_pool_page_hash_rebuild();
2039 buf_pool_watch_remove(
2049 ut_d(watch->in_page_hash = FALSE);
2059 buf_pool_watch_unset(
2074 if (UNIV_UNLIKELY(!buf_pool_watch_is_sentinel(buf_pool, bpage))) {
2085 buf_pool_watch_remove(buf_pool, fold, bpage);
2099 buf_pool_watch_occurred(
2115 ret = !buf_pool_watch_is_sentinel(buf_pool, bpage);
2127 buf_page_make_young(
2137 buf_LRU_make_block_young(bpage);
2149 buf_page_set_accessed_make_young(
2153 unsigned access_time)
2164 buf_LRU_make_block_young(bpage);
2166 }
else if (!access_time) {
2179 buf_reset_check_index_page_at_flush(
2192 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, &block->
page));
2206 buf_page_peek_if_search_hashed(
2222 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, &block->
page));
2231 #ifdef UNIV_DEBUG_FILE_ACCESSES
2240 buf_page_set_file_page_was_freed(
2253 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, bpage));
2254 bpage->file_page_was_freed = TRUE;
2270 buf_page_reset_file_page_was_freed(
2283 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, bpage));
2284 bpage->file_page_was_freed = FALSE;
2313 unsigned access_time;
2316 #ifndef UNIV_LOG_DEBUG
2317 ut_ad(!ibuf_inside());
2326 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, bpage));
2334 buf_read_page(space, zip_size, offset);
2336 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2337 ut_a(++buf_dbg_counter % 37 || buf_validate());
2341 if (UNIV_UNLIKELY(!bpage->
zip.
data)) {
2348 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, bpage));
2360 mutex_enter(block_mutex);
2365 mutex_enter(block_mutex);
2368 if (buf_LRU_free_block(bpage, FALSE, NULL)
2371 mutex_exit(block_mutex);
2376 __FILE__, __LINE__);
2389 mutex_exit(block_mutex);
2391 buf_page_set_accessed_make_young(bpage, access_time);
2393 #ifdef UNIV_DEBUG_FILE_ACCESSES
2394 ut_a(!bpage->file_page_was_freed);
2397 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2398 ut_a(++buf_dbg_counter % 5771 || buf_validate());
2410 mutex_enter(block_mutex);
2412 mutex_exit(block_mutex);
2423 #ifdef UNIV_IBUF_COUNT_DEBUG
2439 block->
index = NULL;
2470 if (UNIV_UNLIKELY(stamp_checksum != calc_checksum)) {
2473 " InnoDB: compressed page checksum mismatch"
2474 " (space %u page %u): %lu != %lu\n",
2476 stamp_checksum, calc_checksum);
2481 switch (fil_page_get_type(frame)) {
2484 block->
frame, TRUE)) {
2489 "InnoDB: unable to decompress space %lu page %lu\n",
2502 memcpy(block->
frame, frame,
2509 " InnoDB: unknown compressed page"
2511 fil_page_get_type(frame));
2515 #ifndef UNIV_HOTBACKUP
2522 buf_block_align_instance(
2533 for (chunk = buf_pool->
chunks, i = buf_pool->
n_chunks; i--; chunk++) {
2536 if (UNIV_UNLIKELY(offs < 0)) {
2541 offs >>= UNIV_PAGE_SIZE_SHIFT;
2543 if (UNIV_LIKELY((ulint) offs < chunk->size)) {
2554 mutex_enter(&block->
mutex);
2594 mutex_exit(&block->
mutex);
2615 for (i = 0; i < srv_buf_pool_instances; i++) {
2618 block = buf_block_align_instance(
2637 buf_pointer_is_block_field_instance(
2647 while (chunk < echunk) {
2648 if (ptr >= (
void *)chunk->
blocks
2649 && ptr < (
void *)(chunk->
blocks + chunk->
size)) {
2666 buf_pointer_is_block_field(
2672 for (i = 0; i < srv_buf_pool_instances; i++) {
2675 found = buf_pointer_is_block_field_instance(
2690 buf_block_is_uncompressed(
2698 if (UNIV_UNLIKELY((((ulint) block) %
sizeof *block) != 0)) {
2703 return(buf_pointer_is_block_field_instance(buf_pool, (
void *)block));
2728 unsigned access_time;
2735 ut_ad(mtr->state == MTR_ACTIVE);
2736 ut_ad((rw_latch == RW_S_LATCH)
2737 || (rw_latch == RW_X_LATCH)
2738 || (rw_latch == RW_NO_LATCH));
2744 ut_ad(zip_size == fil_space_get_zip_size(space));
2746 #ifndef UNIV_LOG_DEBUG
2747 ut_ad(!ibuf_inside() || ibuf_page(space, zip_size, offset, NULL));
2764 if (!buf_block_is_uncompressed(buf_pool, block)
2769 block = guess = NULL;
2776 if (block == NULL) {
2778 buf_pool, space, offset, fold);
2782 if (block && buf_pool_watch_is_sentinel(buf_pool, &block->
page)) {
2786 if (block == NULL) {
2791 space, offset, fold);
2793 if (UNIV_LIKELY_NULL(block)) {
2807 if (buf_read_page(space, zip_size, offset)) {
2809 }
else if (retries < BUF_PAGE_READ_MAX_RETRIES) {
2812 fprintf(stderr,
"InnoDB: Error: Unable"
2813 " to read tablespace %lu page no"
2814 " %lu into the buffer pool after"
2816 "InnoDB: The most probable cause"
2817 " of this error may be that the"
2818 " table has been corrupted.\n"
2819 "InnoDB: You can try to fix this"
2821 " innodb_force_recovery.\n"
2822 "InnoDB: Please see reference manual"
2823 " for more details.\n"
2824 "InnoDB: Aborting...\n",
2826 BUF_PAGE_READ_MAX_RETRIES);
2831 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2832 ut_a(++buf_dbg_counter % 37 || buf_validate());
2861 bpage = &block->
page;
2884 block = buf_LRU_get_free_block(buf_pool, 0);
2888 mutex_enter(&block->
mutex);
2894 buf_pool, space, offset, fold);
2896 if (UNIV_UNLIKELY(bpage != hash_bpage)) {
2901 buf_LRU_block_free_non_file_page(block);
2902 mutex_exit(&block->
mutex);
2918 buf_LRU_block_free_non_file_page(block);
2919 mutex_exit(&block->
mutex);
2921 goto wait_until_unfixed;
2929 buf_relocate(bpage, &block->
page);
2930 buf_block_init_low(block);
2943 buf_flush_relocate_on_flush_list(bpage,
2953 buf_unzip_LRU_add_block(block, FALSE);
2959 UNIV_MEM_INVALID(bpage,
sizeof *bpage);
2961 mutex_exit(&block->
mutex);
2971 success = buf_zip_decompress(block, srv_use_checksums);
2975 ibuf_merge_or_delete_for_page(block, space, offset,
2981 mutex_enter(&block->
mutex);
2984 mutex_exit(&block->
mutex);
2986 rw_lock_x_unlock(&block->
lock);
3001 mutex_enter(&block->
mutex);
3002 #if UNIV_WORD_SIZE == 4
3006 UNIV_MEM_ASSERT_RW(&block->
page,
sizeof block->
page);
3008 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
3014 if (buf_LRU_free_block(&block->
page, TRUE, NULL)
3016 mutex_exit(&block->
mutex);
3022 space, offset, fold);
3024 if (UNIV_LIKELY_NULL(block)) {
3034 "innodb_change_buffering_debug evict %u %u\n",
3035 (
unsigned) space, (
unsigned) offset);
3037 }
else if (buf_flush_page_try(buf_pool, block)) {
3039 "innodb_change_buffering_debug flush %u %u\n",
3040 (
unsigned) space, (
unsigned) offset);
3049 buf_block_buf_fix_inc(block, file, line);
3051 mutex_exit(&block->
mutex);
3059 buf_page_set_accessed_make_young(&block->
page, access_time);
3061 #ifdef UNIV_DEBUG_FILE_ACCESSES
3062 ut_a(!block->
page.file_page_was_freed);
3065 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3066 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3080 mutex_enter(&block->
mutex);
3082 mutex_exit(&block->
mutex);
3093 fix_type = MTR_MEMO_BUF_FIX;
3099 fix_type = MTR_MEMO_PAGE_S_FIX;
3103 ut_ad(rw_latch == RW_X_LATCH);
3106 fix_type = MTR_MEMO_PAGE_X_FIX;
3116 buf_read_ahead_linear(space, zip_size, offset);
3119 #ifdef UNIV_IBUF_COUNT_DEBUG
3132 buf_page_optimistic_get(
3136 ib_uint64_t modify_clock,
3143 unsigned access_time;
3149 ut_ad(mtr->state == MTR_ACTIVE);
3150 ut_ad((rw_latch == RW_S_LATCH) || (rw_latch == RW_X_LATCH));
3152 mutex_enter(&block->
mutex);
3156 mutex_exit(&block->
mutex);
3161 buf_block_buf_fix_inc(block, file, line);
3163 mutex_exit(&block->
mutex);
3171 buf_page_set_accessed_make_young(&block->
page, access_time);
3173 ut_ad(!ibuf_inside()
3178 if (rw_latch == RW_S_LATCH) {
3179 success = rw_lock_s_lock_nowait(&(block->
lock),
3181 fix_type = MTR_MEMO_PAGE_S_FIX;
3185 fix_type = MTR_MEMO_PAGE_X_FIX;
3188 if (UNIV_UNLIKELY(!success)) {
3189 mutex_enter(&block->
mutex);
3190 buf_block_buf_fix_dec(block);
3191 mutex_exit(&block->
mutex);
3196 if (UNIV_UNLIKELY(modify_clock != block->
modify_clock)) {
3197 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
3199 if (rw_latch == RW_S_LATCH) {
3200 rw_lock_s_unlock(&(block->
lock));
3202 rw_lock_x_unlock(&(block->
lock));
3205 mutex_enter(&block->
mutex);
3206 buf_block_buf_fix_dec(block);
3207 mutex_exit(&block->
mutex);
3214 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3215 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3220 #ifdef UNIV_DEBUG_FILE_ACCESSES
3221 ut_a(block->
page.file_page_was_freed == FALSE);
3223 if (UNIV_UNLIKELY(!access_time)) {
3232 #ifdef UNIV_IBUF_COUNT_DEBUG
3249 buf_page_get_known_nowait(
3263 ut_ad(mtr->state == MTR_ACTIVE);
3264 ut_ad((rw_latch == RW_S_LATCH) || (rw_latch == RW_X_LATCH));
3266 mutex_enter(&block->
mutex);
3276 mutex_exit(&block->
mutex);
3283 buf_block_buf_fix_inc(block, file, line);
3285 mutex_exit(&block->
mutex);
3291 buf_LRU_make_block_young(&block->
page);
3307 if (rw_latch == RW_S_LATCH) {
3308 success = rw_lock_s_lock_nowait(&(block->
lock),
3310 fix_type = MTR_MEMO_PAGE_S_FIX;
3314 fix_type = MTR_MEMO_PAGE_X_FIX;
3318 mutex_enter(&block->
mutex);
3319 buf_block_buf_fix_dec(block);
3320 mutex_exit(&block->
mutex);
3327 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3328 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3332 #ifdef UNIV_DEBUG_FILE_ACCESSES
3333 ut_a(block->
page.file_page_was_freed == FALSE);
3336 #ifdef UNIV_IBUF_COUNT_DEBUG
3353 buf_page_try_get_func(
3367 ut_ad(mtr->state == MTR_ACTIVE);
3377 ut_ad(!buf_pool_watch_is_sentinel(buf_pool, &block->
page));
3379 mutex_enter(&block->
mutex);
3382 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3388 buf_block_buf_fix_inc(block, file, line);
3389 mutex_exit(&block->
mutex);
3391 fix_type = MTR_MEMO_PAGE_S_FIX;
3392 success = rw_lock_s_lock_nowait(&block->
lock, file, line);
3399 fix_type = MTR_MEMO_PAGE_X_FIX;
3405 mutex_enter(&block->
mutex);
3406 buf_block_buf_fix_dec(block);
3407 mutex_exit(&block->
mutex);
3413 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3414 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3418 #ifdef UNIV_DEBUG_FILE_ACCESSES
3419 ut_a(block->
page.file_page_was_freed == FALSE);
3421 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
3425 #ifdef UNIV_IBUF_COUNT_DEBUG
3448 HASH_INVALIDATE(bpage, hash);
3449 #ifdef UNIV_DEBUG_FILE_ACCESSES
3450 bpage->file_page_was_freed = FALSE;
3476 #ifdef UNIV_DEBUG_VALGRIND
3481 UNIV_MEM_VALID(block->
frame, UNIV_PAGE_SIZE);
3485 buf_block_init_low(block);
3489 buf_page_init_low(&block->
page);
3495 if (UNIV_LIKELY(!hash_page)) {
3496 }
else if (buf_pool_watch_is_sentinel(buf_pool, hash_page)) {
3500 ut_a(buf_fix_count > 0);
3502 buf_pool_watch_remove(buf_pool, fold, hash_page);
3505 "InnoDB: Error: page %lu %lu already found"
3506 " in the hash table: %p, %p\n",
3509 (
const void*) hash_page, (
const void*) block);
3510 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3511 mutex_exit(&block->
mutex);
3523 ut_d(block->
page.in_page_hash = TRUE);
3525 fold, &block->
page);
3540 buf_page_init_for_read(
3547 ib_int64_t tablespace_version,
3570 ut_ad(ibuf_inside());
3575 && !ibuf_page(space, zip_size, offset, &mtr)) {
3585 if (zip_size && UNIV_LIKELY(!unzip)
3589 block = buf_LRU_get_free_block(buf_pool, 0);
3599 if (watch_page && !buf_pool_watch_is_sentinel(buf_pool, watch_page)) {
3604 mutex_enter(&block->
mutex);
3605 buf_LRU_block_free_non_file_page(block);
3606 mutex_exit(&block->
mutex);
3613 if (fil_tablespace_deleted_or_being_deleted_in_mem(
3614 space, tablespace_version)) {
3617 *err = DB_TABLESPACE_DELETED;
3623 bpage = &block->
page;
3624 mutex_enter(&block->
mutex);
3628 buf_page_init(space, offset, fold, block);
3631 buf_LRU_add_block(bpage, TRUE);
3645 if (UNIV_UNLIKELY(zip_size)) {
3656 mutex_exit(&block->
mutex);
3658 mutex_enter(&block->
mutex);
3659 block->
page.
zip.
data =
static_cast<unsigned char *
>(data);
3667 buf_unzip_LRU_add_block(block, TRUE);
3670 mutex_exit(&block->
mutex);
3690 if (UNIV_UNLIKELY(lru)) {
3693 buf_pool, space, offset, fold);
3696 && !buf_pool_watch_is_sentinel(buf_pool,
3711 bpage->
zip.
data =
static_cast<unsigned char *
>(data);
3714 UNIV_MEM_DESC(bpage->
zip.
data,
3717 buf_page_init_low(bpage);
3720 bpage->
space = space;
3725 bpage->in_page_hash = FALSE;
3726 bpage->in_zip_hash = FALSE;
3727 bpage->in_flush_list = FALSE;
3728 bpage->in_free_list = FALSE;
3729 bpage->in_LRU_list = FALSE;
3732 ut_d(bpage->in_page_hash = TRUE);
3734 if (UNIV_LIKELY_NULL(watch_page)) {
3737 ut_a(buf_fix_count > 0);
3739 ut_ad(buf_pool_watch_is_sentinel(buf_pool, watch_page));
3740 buf_pool_watch_remove(buf_pool, fold, watch_page);
3747 buf_LRU_add_block(bpage, TRUE);
3748 buf_LRU_insert_zip_clean(bpage);
3792 ut_ad(mtr->state == MTR_ACTIVE);
3793 ut_ad(space || !zip_size);
3795 free_block = buf_LRU_get_free_block(buf_pool, 0);
3802 buf_pool, space, offset, fold);
3806 && !buf_pool_watch_is_sentinel(buf_pool, &block->
page)) {
3807 #ifdef UNIV_IBUF_COUNT_DEBUG
3808 ut_a(ibuf_count_get(space, offset) == 0);
3810 #ifdef UNIV_DEBUG_FILE_ACCESSES
3811 block->
page.file_page_was_freed = FALSE;
3826 if (buf_debug_prints) {
3827 fprintf(stderr,
"Creating space %lu page %lu to buffer\n",
3828 (ulong) space, (ulong) offset);
3834 mutex_enter(&block->
mutex);
3836 buf_page_init(space, offset, fold, block);
3839 buf_LRU_add_block(&block->
page, FALSE);
3841 buf_block_buf_fix_inc(block, __FILE__, __LINE__);
3853 rw_lock_x_lock(&block->
lock);
3856 mutex_exit(&block->
mutex);
3864 mutex_enter(&block->
mutex);
3865 block->
page.
zip.
data =
static_cast<unsigned char *
>(data);
3873 buf_unzip_LRU_add_block(block, FALSE);
3876 rw_lock_x_unlock(&block->
lock);
3885 mutex_exit(&block->
mutex);
3890 ibuf_merge_or_delete_for_page(NULL, space, offset, zip_size, TRUE);
3893 buf_flush_free_margin(buf_pool);
3895 frame = block->
frame;
3909 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3910 ut_a(++buf_dbg_counter % 357 || buf_validate());
3912 #ifdef UNIV_IBUF_COUNT_DEBUG
3924 buf_page_io_complete(
3946 ulint read_space_id;
3972 if (bpage->
space == TRX_SYS_SPACE
3977 " InnoDB: Error: reading page %lu\n"
3978 "InnoDB: which is in the"
3979 " doublewrite buffer!\n",
3981 }
else if (!read_space_id && !read_page_no) {
3983 }
else if ((bpage->
space
3984 && bpage->
space != read_space_id)
3985 || bpage->
offset != read_page_no) {
3993 " InnoDB: Error: space id and page n:o"
3994 " stored in the page\n"
3995 "InnoDB: read in are %lu:%lu,"
3996 " should be %lu:%lu!\n",
3997 (ulong) read_space_id, (ulong) read_page_no,
3998 (ulong) bpage->
space,
4005 if (buf_page_is_corrupted(frame,
4009 "InnoDB: Database page corruption on disk"
4011 "InnoDB: file read of page %lu.\n"
4012 "InnoDB: You may have to recover"
4013 " from a backup.\n",
4017 "InnoDB: Database page corruption on disk"
4019 "InnoDB: file read of page %lu.\n"
4020 "InnoDB: You may have to recover"
4021 " from a backup.\n",
4023 fputs(
"InnoDB: It is also possible that"
4025 "InnoDB: system has corrupted its"
4027 "InnoDB: and rebooting your computer"
4030 "InnoDB: If the corrupt page is an index page\n"
4031 "InnoDB: you can also try to"
4032 " fix the corruption\n"
4033 "InnoDB: by dumping, dropping,"
4034 " and reimporting\n"
4035 "InnoDB: the corrupt table."
4036 " You can use CHECK\n"
4037 "InnoDB: TABLE to scan your"
4038 " table for corruption.\n"
4040 REFMAN
"forcing-recovery.html\n"
4041 "InnoDB: about forcing recovery.\n", stderr);
4044 fputs(
"InnoDB: Ending processing because of"
4045 " a corrupt database page.\n",
4058 ibuf_merge_or_delete_for_page(
4068 #ifdef UNIV_IBUF_COUNT_DEBUG
4094 rw_lock_x_unlock_gen(&((
buf_block_t*) bpage)->lock,
4104 buf_flush_write_complete(bpage);
4107 rw_lock_s_unlock_gen(&((
buf_block_t*) bpage)->lock,
4120 if (buf_debug_prints) {
4121 fprintf(stderr,
"Has %s page space %lu page no %lu\n",
4137 buf_all_freed_instance(
4148 chunk = buf_pool->
chunks;
4150 for (i = buf_pool->
n_chunks; i--; chunk++) {
4152 const buf_block_t* block = buf_chunk_not_freed(chunk);
4154 if (UNIV_LIKELY_NULL(block)) {
4156 "Page %lu %lu still fixed or dirty\n",
4172 buf_pool_invalidate_instance(
4194 if (buf_pool->
n_flush[i] > 0) {
4196 buf_flush_wait_batch_end(buf_pool, static_cast<buf_flush>(i));
4203 ut_ad(buf_all_freed_instance(buf_pool));
4208 freed = buf_LRU_search_and_free_block(buf_pool, 100);
4221 memset(&buf_pool->
stat, 0x00,
sizeof(buf_pool->
stat));
4222 buf_refresh_io_stats(buf_pool);
4233 buf_pool_invalidate(
void)
4238 for (i = 0; i < srv_buf_pool_instances; i++) {
4243 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
4249 buf_pool_validate_instance(
4256 ulint n_single_flush = 0;
4257 ulint n_lru_flush = 0;
4258 ulint n_list_flush = 0;
4268 chunk = buf_pool->
chunks;
4272 for (i = buf_pool->
n_chunks; i--; chunk++) {
4277 for (j = chunk->
size; j--; block++) {
4279 mutex_enter(&block->
mutex);
4298 #ifdef UNIV_IBUF_COUNT_DEBUG
4352 mutex_exit(&block->
mutex);
4393 ut_ad(b->in_flush_list);
4443 if (n_lru + n_free > buf_pool->
curr_size + n_zip) {
4444 fprintf(stderr,
"n LRU %lu, n free %lu, pool %lu zip %lu\n",
4445 (ulong) n_lru, (ulong) n_free,
4446 (ulong) buf_pool->
curr_size, (ulong) n_zip);
4452 fprintf(stderr,
"Free list len %lu, free blocks %lu\n",
4464 ut_a(buf_LRU_validate());
4465 ut_a(buf_flush_validate(buf_pool));
4480 for (i = 0; i < srv_buf_pool_instances; i++) {
4485 buf_pool_validate_instance(buf_pool);
4492 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
4501 index_id_t* index_ids;
4515 index_ids = mem_alloc(size *
sizeof *index_ids);
4516 counts = mem_alloc(
sizeof(ulint) * size);
4522 "buf_pool size %lu\n"
4523 "database pages %lu\n"
4525 "modified database pages %lu\n"
4526 "n pending decompressions %lu\n"
4527 "n pending reads %lu\n"
4528 "n pending flush LRU %lu list %lu single page %lu\n"
4529 "pages made young %lu, not young %lu\n"
4530 "pages read %lu, created %lu, written %lu\n",
4552 chunk = buf_pool->
chunks;
4554 for (i = buf_pool->
n_chunks; i--; chunk++) {
4556 ulint n_blocks = chunk->
size;
4558 for (; n_blocks--; block++) {
4568 while (j < n_found) {
4570 if (index_ids[j] ==
id) {
4589 for (i = 0; i < n_found; i++) {
4590 index = dict_index_get_if_in_cache(index_ids[i]);
4593 "Block count for index %llu in buffer is about %lu",
4594 (ullint) index_ids[i],
4599 dict_index_name_print(stderr, NULL, index);
4608 ut_a(buf_pool_validate_instance(buf_pool));
4620 for (i = 0; i < srv_buf_pool_instances; i++) {
4624 buf_print_instance(buf_pool);
4635 buf_get_latched_pages_number_instance(
4642 ulint fixed_pages_number = 0;
4646 chunk = buf_pool->
chunks;
4648 for (i = buf_pool->
n_chunks; i--; chunk++) {
4654 for (j = chunk->
size; j--; block++) {
4661 mutex_enter(&block->
mutex);
4666 fixed_pages_number++;
4669 mutex_exit(&block->
mutex);
4684 fixed_pages_number++;
4691 ut_ad(b->in_flush_list);
4697 fixed_pages_number++;
4718 return(fixed_pages_number);
4726 buf_get_latched_pages_number(
void)
4730 ulint total_latched_pages = 0;
4732 for (i = 0; i < srv_buf_pool_instances; i++) {
4737 total_latched_pages += buf_get_latched_pages_number_instance(
4741 return(total_latched_pages);
4751 buf_get_n_pending_ios(
void)
4757 for (i = 0; i < srv_buf_pool_instances; i++) {
4778 buf_get_modified_ratio_pct(
void)
4784 ulint flush_list_len = 0;
4786 buf_get_total_list_len(&lru_len, &free_len, &flush_list_len);
4788 ratio = (100 * flush_list_len) / (1 + lru_len + free_len);
4799 buf_print_io_instance(
4804 time_t current_time;
4805 double time_elapsed;
4814 "Buffer pool size %lu\n"
4815 "Free buffers %lu\n"
4816 "Database pages %lu\n"
4817 "Old database pages %lu\n"
4818 "Modified db pages %lu\n"
4819 "Pending reads %lu\n"
4820 "Pending writes: LRU %lu, flush list %lu, single page %lu\n",
4835 current_time = time(NULL);
4836 time_elapsed = 0.001 + difftime(current_time,
4840 "Pages made young %lu, not young %lu\n"
4841 "%.2f youngs/s, %.2f non-youngs/s\n"
4842 "Pages read %lu, created %lu, written %lu\n"
4843 "%.2f reads/s, %.2f creates/s, %.2f writes/s\n",
4870 "Buffer pool hit rate %lu / 1000,"
4871 " young-making rate %lu / 1000 not %lu / 1000\n",
4886 fputs(
"No buffer pool page gets since the last printout\n",
4891 fprintf(file,
"Pages read ahead %.2f/s,"
4892 " evicted without access %.2f/s\n",
4903 "LRU len: %lu, unzip_LRU len: %lu\n"
4904 "I/O sum[%lu]:cur[%lu], unzip sum[%lu]:cur[%lu]\n",
4907 buf_LRU_stat_sum.
io, buf_LRU_stat_cur.
io,
4908 buf_LRU_stat_sum.
unzip, buf_LRU_stat_cur.
unzip);
4910 buf_refresh_io_stats(buf_pool);
4924 for (i = 0; i < srv_buf_pool_instances; i++) {
4928 buf_print_io_instance(buf_pool, file);
4936 buf_refresh_io_stats(
4948 buf_refresh_io_stats_all(
void)
4953 for (i = 0; i < srv_buf_pool_instances; i++) {
4958 buf_refresh_io_stats(buf_pool);
4972 for (i = 0; i < srv_buf_pool_instances; i++) {
4977 if (!buf_all_freed_instance(buf_pool)) {
4991 buf_pool_check_no_pending_io(
void)
4999 for (i = 0; i < srv_buf_pool_instances && ret; i++) {
5019 Code currently not used
5045 buf_page_init_for_backup_restore(
5062 ut_ad(zip_size <= UNIV_PAGE_SIZE);