42 #ifndef UNIV_HOTBACKUP
55 #include "buf0checksum.h"
245 #ifndef UNIV_HOTBACKUP
247 static const int WAIT_FOR_READ = 100;
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
301 #define MONITOR_RW_COUNTER(io_type, counter) \
302 ((io_type == BUF_IO_READ) \
304 : (counter##_WRITTEN))
318 lsn_t oldest_lsn = 0;
324 for (i = 0; i < srv_buf_pool_instances; i++) {
334 ut_ad(bpage->in_flush_list);
340 if (!oldest_lsn || oldest_lsn > lsn) {
361 ulint* flush_list_len)
369 for (i = 0; i < srv_buf_pool_instances; i++) {
389 ut_ad(buf_pools_list_size);
390 memset(buf_pools_list_size, 0,
sizeof(*buf_pools_list_size));
392 for (ulint
i = 0;
i < srv_buf_pool_instances;
i++) {
416 memset(tot_stat, 0,
sizeof(*tot_stat));
418 for (i = 0; i < srv_buf_pool_instances; i++) {
424 buf_stat = &buf_pool->
stat;
454 if (buf_pool == NULL) {
457 index = buf_pool_index++ % srv_buf_pool_instances;
478 const byte* read_buf,
482 ulint checksum_field1;
483 ulint checksum_field2;
484 ibool crc32_inited = FALSE;
485 ib_uint32_t crc32 = ULINT32_UNDEFINED;
489 read_buf + UNIV_PAGE_SIZE
498 #ifndef UNIV_HOTBACKUP
511 " InnoDB: Error: page %lu log sequence number"
513 "InnoDB: is in the future! Current system "
514 "log sequence number " LSN_PF
".\n"
515 "InnoDB: Your database may be corrupt or "
516 "you may have copied the InnoDB\n"
517 "InnoDB: tablespace but not the InnoDB "
520 "forcing-innodb-recovery.html\n"
521 "InnoDB: for more information.\n",
548 if (checksum_field1 == 0 && checksum_field2 == 0
551 ut_d(
for (ulint
i = 0;
i < UNIV_PAGE_SIZE;
i++) {
552 ut_a(read_buf[
i] == 0); });
562 return(checksum_field1 != crc32 || checksum_field2 != crc32);
566 return(checksum_field1
608 if (checksum_field2 != crc32
624 if (checksum_field2 != crc32) {
636 if (checksum_field1 != 0
652 if (checksum_field1 != crc32
671 if (checksum_field1 != crc32) {
681 && ((checksum_field1 == crc32
682 && checksum_field2 != crc32)
683 || (checksum_field1 != crc32
684 && checksum_field2 == crc32))) {
697 DBUG_EXECUTE_IF(
"buf_page_is_corrupt_failure",
return(TRUE); );
708 const byte* read_buf,
716 #ifndef UNIV_HOTBACKUP
722 size = UNIV_PAGE_SIZE;
728 " InnoDB: Page dump in ascii and hex (%lu bytes):\n",
731 fputs(
"\nInnoDB: End of page dump\n", stderr);
738 " InnoDB: Compressed page type (" ULINTPF
"); "
739 "stored checksum in field1 " ULINTPF
"; "
740 "calculated checksums for field1: "
744 "page LSN " LSN_PF
"; "
745 "page number (if stored to page already) " ULINTPF
"; "
746 "space id (if stored to page already) " ULINTPF
"\n",
767 fprintf(stderr,
" InnoDB: uncompressed page, "
768 "stored checksum in field1 " ULINTPF
", "
769 "calculated checksums for field1: "
774 "stored checksum in field2 " ULINTPF
", "
775 "calculated checksums for field2: "
780 "page LSN " ULINTPF
" " ULINTPF
", "
781 "low 4 bytes of LSN at page end " ULINTPF
", "
782 "page number (if stored to page already) " ULINTPF
", "
783 "space id (if created with >= MySQL-4.1.1 "
784 "and stored already) %lu\n",
811 #ifndef UNIV_HOTBACKUP
813 == TRX_UNDO_INSERT) {
815 "InnoDB: Page may be an insert undo log page\n");
818 == TRX_UNDO_UPDATE) {
820 "InnoDB: Page may be an update undo log page\n");
829 "InnoDB: Page may be an index page where"
830 " index id is %llu\n",
832 #ifndef UNIV_HOTBACKUP
835 fputs(
"InnoDB: (", stderr);
837 fputs(
")\n", stderr);
842 fputs(
"InnoDB: Page may be an 'inode' page\n", stderr);
845 fputs(
"InnoDB: Page may be an insert buffer free list page\n",
849 fputs(
"InnoDB: Page may be a freshly allocated page\n",
853 fputs(
"InnoDB: Page may be an insert buffer bitmap page\n",
857 fputs(
"InnoDB: Page may be a system page\n",
861 fputs(
"InnoDB: Page may be a transaction system page\n",
865 fputs(
"InnoDB: Page may be a file space header page\n",
869 fputs(
"InnoDB: Page may be an extent descriptor page\n",
873 fputs(
"InnoDB: Page may be a BLOB page\n",
878 fputs(
"InnoDB: Page may be a compressed BLOB page\n",
886 #ifndef UNIV_HOTBACKUP
888 # ifdef PFS_GROUP_BUFFER_SYNC
897 pfs_register_buffer_block(
902 ulint num_to_register;
905 block = chunk->blocks;
907 num_to_register =
ut_min(chunk->size,
908 PFS_MAX_BUFFER_MUTEX_LOCK_REGISTER);
910 for (i = 0; i < num_to_register; i++) {
914 # ifdef UNIV_PFS_MUTEX
915 mutex = &block->
mutex;
916 ut_a(!mutex->pfs_psi);
918 ?
PSI_server->init_mutex(buffer_block_mutex_key, mutex)
922 # ifdef UNIV_PFS_RWLOCK
923 rwlock = &block->
lock;
924 ut_a(!rwlock->pfs_psi);
926 ?
PSI_server->init_rwlock(buf_block_lock_key, rwlock)
929 # ifdef UNIV_SYNC_DEBUG
930 rwlock = &block->debug_latch;
931 ut_a(!rwlock->pfs_psi);
933 ?
PSI_server->init_rwlock(buf_block_debug_latch_key,
954 UNIV_MEM_DESC(frame, UNIV_PAGE_SIZE);
956 block->
frame = frame;
965 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
966 block->
page.file_page_was_freed = FALSE;
973 block->
page.in_page_hash = FALSE;
974 block->
page.in_zip_hash = FALSE;
975 block->
page.in_flush_list = FALSE;
976 block->
page.in_free_list = FALSE;
977 block->
page.in_LRU_list = FALSE;
978 block->in_unzip_LRU_list = FALSE;
980 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
981 block->n_pointers = 0;
985 #if defined PFS_SKIP_BUFFER_MUTEX_RWLOCK || defined PFS_GROUP_BUFFER_SYNC
992 mutex_create(PFS_NOT_INSTRUMENTED, &block->
mutex, SYNC_BUF_BLOCK);
995 # ifdef UNIV_SYNC_DEBUG
997 &block->debug_latch, SYNC_NO_ORDER_CHECK);
1001 mutex_create(buffer_block_mutex_key, &block->
mutex, SYNC_BUF_BLOCK);
1004 # ifdef UNIV_SYNC_DEBUG
1006 &block->debug_latch, SYNC_NO_ORDER_CHECK);
1010 ut_ad(rw_lock_validate(&(block->
lock)));
1032 mem_size +=
ut_2pow_round((mem_size / UNIV_PAGE_SIZE) * (
sizeof *block)
1033 + (UNIV_PAGE_SIZE - 1), UNIV_PAGE_SIZE);
1035 chunk->mem_size = mem_size;
1038 if (UNIV_UNLIKELY(chunk->mem == NULL)) {
1052 frame = (byte*)
ut_align(chunk->mem, UNIV_PAGE_SIZE);
1053 chunk->size = chunk->mem_size / UNIV_PAGE_SIZE
1054 - (frame != chunk->mem);
1058 ulint
size = chunk->size;
1060 while (frame < (byte*) (chunk->blocks +
size)) {
1061 frame += UNIV_PAGE_SIZE;
1072 block = chunk->blocks;
1074 for (i = chunk->size; i--; ) {
1076 buf_block_init(buf_pool, block, frame);
1077 UNIV_MEM_INVALID(block->
frame, UNIV_PAGE_SIZE);
1082 ut_d(block->
page.in_free_list = TRUE);
1086 frame += UNIV_PAGE_SIZE;
1089 #ifdef PFS_GROUP_BUFFER_SYNC
1090 pfs_register_buffer_block(chunk);
1102 buf_chunk_contains_zip(
1110 block = chunk->blocks;
1112 for (i = chunk->size; i--; block++) {
1128 buf_pool_contains_zip(
1134 buf_chunk_t* chunk = buf_pool->
chunks;
1138 for (n = buf_pool->
n_chunks; n--; chunk++) {
1140 buf_block_t* block = buf_chunk_contains_zip(chunk, data);
1156 buf_chunk_not_freed(
1163 block = chunk->blocks;
1165 for (i = chunk->size; i--; block++) {
1184 mutex_enter(&block->
mutex);
1186 mutex_exit(&block->
mutex);
1204 buf_pool_set_sizes(
void)
1208 ulint curr_size = 0;
1212 for (i = 0; i < srv_buf_pool_instances; i++) {
1219 srv_buf_pool_curr_size = curr_size;
1233 ulint buf_pool_size,
1241 mutex_create(buf_pool_mutex_key,
1242 &buf_pool->
mutex, SYNC_BUF_POOL);
1243 mutex_create(buf_pool_zip_mutex_key,
1248 if (buf_pool_size > 0) {
1251 buf_pool->
chunks = chunk =
1256 if (!buf_chunk_init(buf_pool, chunk, buf_pool_size)) {
1279 MEM_HEAP_FOR_PAGE_HASH,
1280 SYNC_BUF_PAGE_HASH);
1290 SYNC_BUF_FLUSH_LIST);
1312 buf_pool_free_instance(
1318 buf_chunk_t* chunks;
1322 while (bpage != NULL) {
1327 ut_ad(bpage->in_LRU_list);
1341 buf_pool->
watch = NULL;
1343 chunks = buf_pool->
chunks;
1344 chunk = chunks + buf_pool->
n_chunks;
1346 while (--chunk >= chunks) {
1367 const ulint size = total_size / n_instances;
1369 ut_ad(n_instances > 0);
1371 ut_ad(n_instances == srv_buf_pool_instances);
1376 for (i = 0; i < n_instances; i++) {
1388 buf_pool_set_sizes();
1407 for (i = 0; i < n_instances; i++) {
1424 #ifdef UNIV_SYNC_DEBUG
1429 for (p = 0; p < srv_buf_pool_instances; p++) {
1431 buf_chunk_t* chunks = buf_pool->
chunks;
1432 buf_chunk_t* chunk = chunks + buf_pool->
n_chunks;
1434 while (--chunk >= chunks) {
1436 ulint i = chunk->size;
1438 for (; i--; block++) {
1450 block->
index = NULL;
1451 # if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1452 block->n_pointers = 0;
1479 ut_ad(buf_page_hash_lock_held_x(buf_pool, bpage));
1483 ut_ad(bpage->in_LRU_list);
1484 ut_ad(!bpage->in_zip_hash);
1485 ut_ad(bpage->in_page_hash);
1507 memcpy(dpage, bpage,
sizeof *dpage);
1509 ut_d(bpage->in_LRU_list = FALSE);
1510 ut_d(bpage->in_page_hash = FALSE);
1522 if (UNIV_UNLIKELY(buf_pool->
LRU_old == bpage)) {
1524 #ifdef UNIV_LRU_DEBUG
1540 LRU,
buf_page_t, buf_pool->LRU, CheckInLRUList()));
1558 ut_ad(buf_page_hash_lock_held_s_or_x(buf_pool, bpage));
1561 if (bpage < &buf_pool->watch[0]
1571 ut_ad(!bpage->in_zip_hash);
1572 ut_ad(bpage->in_page_hash);
1598 #ifdef UNIV_SYNC_DEBUG
1599 ut_ad(rw_lock_own(hash_lock, RW_LOCK_EX));
1604 if (UNIV_LIKELY_NULL(bpage)) {
1625 rw_lock_x_unlock(hash_lock);
1637 if (UNIV_LIKELY_NULL(bpage)) {
1644 bpage = &buf_pool->
watch[
i];
1650 ut_ad(!bpage->in_zip_hash);
1652 switch (bpage->
state) {
1654 ut_ad(!bpage->in_page_hash);
1667 ut_d(bpage->in_page_hash = TRUE);
1680 ut_ad(bpage->in_page_hash);
1705 buf_pool_watch_remove(
1712 #ifdef UNIV_SYNC_DEBUG
1715 ut_ad(rw_lock_own(hash_lock, RW_LOCK_EX));
1721 ut_d(watch->in_page_hash = FALSE);
1749 rw_lock_x_lock(hash_lock);
1767 buf_pool_watch_remove(buf_pool, fold, bpage);
1772 rw_lock_x_unlock(hash_lock);
1801 rw_lock_s_unlock(hash_lock);
1833 buf_page_make_young_if_needed(
1864 block = (
buf_block_t*) buf_page_hash_get(buf_pool, space, offset);
1874 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
1883 buf_page_set_file_page_was_freed(
1892 bpage = buf_page_hash_get_s_locked(buf_pool, space, offset,
1898 mutex_enter(block_mutex);
1899 rw_lock_s_unlock(hash_lock);
1902 bpage->file_page_was_freed = TRUE;
1903 mutex_exit(block_mutex);
1917 buf_page_reset_file_page_was_freed(
1926 bpage = buf_page_hash_get_s_locked(buf_pool, space, offset,
1931 mutex_enter(block_mutex);
1932 rw_lock_s_unlock(hash_lock);
1933 bpage->file_page_was_freed = FALSE;
1934 mutex_exit(block_mutex);
1947 buf_block_try_discard_uncompressed(
1963 bpage = buf_page_hash_get(buf_pool, space, offset);
1992 ibool discard_attempted = FALSE;
2003 bpage = buf_page_hash_get_s_locked(buf_pool, space,
2004 offset, &hash_lock);
2015 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2016 ut_a(++buf_dbg_counter % 5771 || buf_validate());
2020 ut_ad(buf_page_hash_lock_held_s(buf_pool, bpage));
2025 rw_lock_s_unlock(hash_lock);
2041 mutex_enter(block_mutex);
2046 if (!discard_attempted) {
2047 rw_lock_s_unlock(hash_lock);
2048 buf_block_try_discard_uncompressed(space,
2050 discard_attempted = TRUE;
2055 mutex_enter(block_mutex);
2057 __FILE__, __LINE__);
2067 rw_lock_s_unlock(hash_lock);
2068 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
2069 ut_a(!bpage->file_page_was_freed);
2074 mutex_exit(block_mutex);
2076 buf_page_make_young_if_needed(bpage);
2078 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2079 ut_a(++buf_dbg_counter % 5771 || buf_validate());
2091 mutex_enter(block_mutex);
2093 mutex_exit(block_mutex);
2104 #ifdef UNIV_IBUF_COUNT_DEBUG
2120 block->
index = NULL;
2149 " InnoDB: compressed page checksum mismatch"
2150 " (space %u page %u): stored: %lu, crc32: %lu "
2151 "innodb: %lu, none: %lu\n",
2166 block->
frame, TRUE)) {
2171 "InnoDB: unable to decompress space %lu page %lu\n",
2184 memcpy(block->
frame, frame,
2191 " InnoDB: unknown compressed page"
2197 #ifndef UNIV_HOTBACKUP
2215 for (chunk = buf_pool->
chunks, i = buf_pool->
n_chunks; i--; chunk++) {
2218 if (UNIV_UNLIKELY(ptr < chunk->blocks->frame)) {
2224 offs = ptr - chunk->blocks->frame;
2226 offs >>= UNIV_PAGE_SIZE_SHIFT;
2228 if (UNIV_LIKELY(offs < chunk->size)) {
2239 mutex_enter(&block->
mutex);
2279 mutex_exit(&block->
mutex);
2300 for (i = 0; i < srv_buf_pool_instances; i++) {
2322 buf_pointer_is_block_field_instance(
2327 const buf_chunk_t* chunk = buf_pool->
chunks;
2328 const buf_chunk_t*
const echunk = chunk + buf_pool->
n_chunks;
2332 while (chunk < echunk) {
2333 if (ptr >= (
void*) chunk->blocks
2334 && ptr < (
void*) (chunk->blocks + chunk->size)) {
2357 for (i = 0; i < srv_buf_pool_instances; i++) {
2360 found = buf_pointer_is_block_field_instance(
2375 buf_block_is_uncompressed(
2381 if (UNIV_UNLIKELY((((ulint) block) %
sizeof *block) != 0)) {
2386 return(buf_pointer_is_block_field_instance(buf_pool, (
void*) block));
2389 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
2395 buf_debug_execute_is_force_flush()
2398 DBUG_EXECUTE_IF(
"ib_buf_force_flush",
return(
true); );
2403 if (srv_ibuf_disable_background_merge) {
2433 unsigned access_time;
2442 ut_ad(mtr->state == MTR_ACTIVE);
2443 ut_ad((rw_latch == RW_S_LATCH)
2444 || (rw_latch == RW_X_LATCH)
2445 || (rw_latch == RW_NO_LATCH));
2449 ut_ad(rw_latch == RW_NO_LATCH);
2463 #ifndef UNIV_LOG_DEBUG
2466 FALSE, file, line, NULL));
2480 if (!buf_block_is_uncompressed(buf_pool, block)
2487 block = guess = NULL;
2493 if (block == NULL) {
2495 buf_pool, space, offset, fold);
2499 rw_lock_s_unlock(hash_lock);
2503 if (block == NULL) {
2507 rw_lock_x_lock(hash_lock);
2509 space, offset, fold);
2511 if (UNIV_LIKELY_NULL(block)) {
2516 mutex_enter(block_mutex);
2519 rw_lock_x_unlock(hash_lock);
2523 rw_lock_x_unlock(hash_lock);
2529 #ifdef UNIV_SYNC_DEBUG
2530 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_EX));
2531 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_SHARED));
2541 }
else if (retries < BUF_PAGE_READ_MAX_RETRIES) {
2544 "innodb_page_corruption_retries",
2545 retries = BUF_PAGE_READ_MAX_RETRIES;
2548 fprintf(stderr,
"InnoDB: Error: Unable"
2549 " to read tablespace %lu page no"
2550 " %lu into the buffer pool after"
2552 "InnoDB: The most probable cause"
2553 " of this error may be that the"
2554 " table has been corrupted.\n"
2555 "InnoDB: You can try to fix this"
2557 " innodb_force_recovery.\n"
2558 "InnoDB: Please see reference manual"
2559 " for more details.\n"
2560 "InnoDB: Aborting...\n",
2562 BUF_PAGE_READ_MAX_RETRIES);
2567 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2568 ut_a(++buf_dbg_counter % 5771 || buf_validate());
2577 mutex_enter(block_mutex);
2580 rw_lock_s_unlock(hash_lock);
2584 ut_ad(mutex_own(block_mutex));
2595 mutex_exit(block_mutex);
2616 bpage = &block->
page;
2623 mutex_exit(block_mutex);
2638 mutex_exit(block_mutex);
2644 rw_lock_x_lock(hash_lock);
2647 buf_pool, space, offset, fold));
2649 mutex_enter(&block->
mutex);
2664 rw_lock_x_unlock(hash_lock);
2665 mutex_exit(&block->
mutex);
2667 goto wait_until_unfixed;
2682 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2703 rw_lock_x_lock_inline(&block->
lock, 0, file, line);
2705 UNIV_MEM_INVALID(bpage,
sizeof *bpage);
2707 rw_lock_x_unlock(hash_lock);
2713 mutex_exit(&block->
mutex);
2728 #ifdef UNIV_IBUF_COUNT_DEBUG
2729 ut_a(ibuf_count_get(space, offset) == 0);
2733 block, space, offset, zip_size, TRUE);
2739 mutex_enter(&block->
mutex);
2744 rw_lock_x_unlock(&block->
lock);
2757 #ifdef UNIV_SYNC_DEBUG
2758 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_EX));
2759 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_SHARED));
2764 #if UNIV_WORD_SIZE == 4
2768 UNIV_MEM_ASSERT_RW(&block->
page,
sizeof block->
page);
2770 #if defined UNIV_DEBUG || defined UNIV_IBUF_DEBUG
2773 && (ibuf_debug || buf_debug_execute_is_force_flush())) {
2782 mutex_exit(&block->
mutex);
2784 mutex_enter(&block->
mutex);
2785 buf_block_buf_fix_dec(block);
2786 mutex_exit(&block->
mutex);
2795 rw_lock_x_lock(hash_lock);
2802 space, offset, fold);
2805 buf_pool, space, offset, fold);
2808 rw_lock_x_unlock(hash_lock);
2810 if (UNIV_LIKELY_NULL(block)) {
2821 "innodb_change_buffering_debug evict %u %u\n",
2822 (
unsigned) space, (
unsigned) offset);
2826 mutex_enter(&block->
mutex);
2828 if (buf_flush_page_try(buf_pool, block)) {
2830 "innodb_change_buffering_debug flush %u %u\n",
2831 (
unsigned) space, (
unsigned) offset);
2843 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
2845 || !block->
page.file_page_was_freed);
2852 mutex_exit(&block->
mutex);
2855 buf_page_make_young_if_needed(&block->
page);
2858 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2859 ut_a(++buf_dbg_counter % 5771 || buf_validate());
2873 mutex_enter(&block->
mutex);
2875 mutex_exit(&block->
mutex);
2880 rw_lock_s_unlock(&(block->
lock));
2887 fix_type = MTR_MEMO_BUF_FIX;
2891 rw_lock_s_lock_inline(&(block->
lock), 0, file, line);
2893 fix_type = MTR_MEMO_PAGE_S_FIX;
2897 ut_ad(rw_latch == RW_X_LATCH);
2898 rw_lock_x_lock_inline(&(block->
lock), 0, file, line);
2900 fix_type = MTR_MEMO_PAGE_X_FIX;
2914 #ifdef UNIV_IBUF_COUNT_DEBUG
2918 #ifdef UNIV_SYNC_DEBUG
2919 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_EX));
2920 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_SHARED));
2935 ib_uint64_t modify_clock,
2941 unsigned access_time;
2947 ut_ad(mtr->state == MTR_ACTIVE);
2948 ut_ad((rw_latch == RW_S_LATCH) || (rw_latch == RW_X_LATCH));
2950 mutex_enter(&block->
mutex);
2954 mutex_exit(&block->
mutex);
2965 mutex_exit(&block->
mutex);
2967 buf_page_make_young_if_needed(&block->
page);
2974 if (rw_latch == RW_S_LATCH) {
2975 success = rw_lock_s_lock_nowait(&(block->
lock),
2977 fix_type = MTR_MEMO_PAGE_S_FIX;
2979 success = rw_lock_x_lock_func_nowait_inline(&(block->
lock),
2981 fix_type = MTR_MEMO_PAGE_X_FIX;
2984 if (UNIV_UNLIKELY(!success)) {
2985 mutex_enter(&block->
mutex);
2986 buf_block_buf_fix_dec(block);
2987 mutex_exit(&block->
mutex);
2992 if (UNIV_UNLIKELY(modify_clock != block->
modify_clock)) {
2993 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
2995 if (rw_latch == RW_S_LATCH) {
2996 rw_lock_s_unlock(&(block->
lock));
2998 rw_lock_x_unlock(&(block->
lock));
3001 mutex_enter(&block->
mutex);
3002 buf_block_buf_fix_dec(block);
3003 mutex_exit(&block->
mutex);
3010 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3011 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3016 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
3017 mutex_enter(&block->
mutex);
3018 ut_a(!block->
page.file_page_was_freed);
3019 mutex_exit(&block->
mutex);
3032 #ifdef UNIV_IBUF_COUNT_DEBUG
3063 ut_ad(mtr->state == MTR_ACTIVE);
3064 ut_ad((rw_latch == RW_S_LATCH) || (rw_latch == RW_X_LATCH));
3066 mutex_enter(&block->
mutex);
3076 mutex_exit(&block->
mutex);
3087 mutex_exit(&block->
mutex);
3092 buf_page_make_young_if_needed(&block->
page);
3097 if (rw_latch == RW_S_LATCH) {
3098 success = rw_lock_s_lock_nowait(&(block->
lock),
3100 fix_type = MTR_MEMO_PAGE_S_FIX;
3102 success = rw_lock_x_lock_func_nowait_inline(&(block->
lock),
3104 fix_type = MTR_MEMO_PAGE_X_FIX;
3108 mutex_enter(&block->
mutex);
3109 buf_block_buf_fix_dec(block);
3110 mutex_exit(&block->
mutex);
3117 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3118 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3122 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
3131 mutex_enter(&block->
mutex);
3132 ut_a(!block->
page.file_page_was_freed);
3133 mutex_exit(&block->
mutex);
3137 #ifdef UNIV_IBUF_COUNT_DEBUG
3169 ut_ad(mtr->state == MTR_ACTIVE);
3171 block = buf_block_hash_get_s_locked(buf_pool, space_id,
3172 page_no, &hash_lock);
3176 rw_lock_s_unlock(hash_lock);
3183 mutex_enter(&block->
mutex);
3184 rw_lock_s_unlock(hash_lock);
3186 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3193 mutex_exit(&block->
mutex);
3195 fix_type = MTR_MEMO_PAGE_S_FIX;
3196 success = rw_lock_s_lock_nowait(&block->
lock, file, line);
3203 fix_type = MTR_MEMO_PAGE_X_FIX;
3204 success = rw_lock_x_lock_func_nowait_inline(&block->
lock,
3209 mutex_enter(&block->
mutex);
3210 buf_block_buf_fix_dec(block);
3211 mutex_exit(&block->
mutex);
3217 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3218 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3222 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
3223 mutex_enter(&block->
mutex);
3224 ut_a(!block->
page.file_page_was_freed);
3225 mutex_exit(&block->
mutex);
3227 buf_block_dbg_add_level(block, SYNC_NO_ORDER_CHECK);
3231 #ifdef UNIV_IBUF_COUNT_DEBUG
3254 HASH_INVALIDATE(bpage, hash);
3255 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
3256 bpage->file_page_was_freed = FALSE;
3262 static __attribute__((nonnull))
3279 ut_ad(mutex_own(&(block->mutex)));
3282 #ifdef UNIV_SYNC_DEBUG
3290 #ifdef UNIV_DEBUG_VALGRIND
3295 UNIV_MEM_VALID(block->frame, UNIV_PAGE_SIZE);
3309 if (UNIV_LIKELY(!hash_page)) {
3314 ut_a(buf_fix_count > 0);
3315 block->page.buf_fix_count += buf_fix_count;
3316 buf_pool_watch_remove(buf_pool, fold, hash_page);
3319 "InnoDB: Error: page %lu %lu already found"
3320 " in the hash table: %p, %p\n",
3323 (
const void*) hash_page, (
const void*) block);
3324 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3325 mutex_exit(&block->mutex);
3335 ut_ad(!block->page.in_zip_hash);
3336 ut_ad(!block->page.in_page_hash);
3337 ut_d(block->page.in_page_hash = TRUE);
3339 fold, &block->page);
3364 ib_int64_t tablespace_version,
3392 && !
ibuf_page(space, zip_size, offset, &mtr)) {
3414 rw_lock_x_lock(hash_lock);
3421 rw_lock_x_unlock(hash_lock);
3423 mutex_enter(&block->
mutex);
3425 mutex_exit(&block->
mutex);
3433 space, tablespace_version)) {
3442 bpage = &block->
page;
3444 mutex_enter(&block->
mutex);
3448 buf_page_init(buf_pool, space, offset, fold, zip_size, block);
3449 rw_lock_x_unlock(hash_lock);
3475 mutex_exit(&block->
mutex);
3477 mutex_enter(&block->
mutex);
3489 mutex_exit(&block->
mutex);
3491 rw_lock_x_unlock(hash_lock);
3499 rw_lock_x_lock(hash_lock);
3504 if (UNIV_UNLIKELY(lru)) {
3507 buf_pool, space, offset, fold);
3509 if (UNIV_UNLIKELY(watch_page
3514 rw_lock_x_unlock(hash_lock);
3533 UNIV_MEM_DESC(bpage->
zip.
data,
3543 bpage->in_page_hash = FALSE;
3544 bpage->in_zip_hash = FALSE;
3545 bpage->in_flush_list = FALSE;
3546 bpage->in_free_list = FALSE;
3547 bpage->in_LRU_list = FALSE;
3550 ut_d(bpage->in_page_hash = TRUE);
3552 if (UNIV_LIKELY_NULL(watch_page)) {
3556 ut_a(buf_fix_count > 0);
3559 buf_pool_watch_remove(buf_pool, fold, watch_page);
3565 rw_lock_x_unlock(hash_lock);
3570 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3571 buf_LRU_insert_zip_clean(bpage);
3589 #ifdef UNIV_SYNC_DEBUG
3590 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_EX));
3591 ut_ad(!rw_lock_own(hash_lock, RW_LOCK_SHARED));
3622 ut_ad(mtr->state == MTR_ACTIVE);
3623 ut_ad(space || !zip_size);
3631 rw_lock_x_lock(hash_lock);
3634 buf_pool, space, offset, fold);
3639 #ifdef UNIV_IBUF_COUNT_DEBUG
3640 ut_a(ibuf_count_get(space, offset) == 0);
3642 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
3643 block->
page.file_page_was_freed = FALSE;
3648 rw_lock_x_unlock(hash_lock);
3659 if (buf_debug_prints) {
3660 fprintf(stderr,
"Creating space %lu page %lu to buffer\n",
3661 (ulong) space, (ulong) offset);
3667 mutex_enter(&block->
mutex);
3669 buf_page_init(buf_pool, space, offset, fold, zip_size, block);
3671 rw_lock_x_unlock(hash_lock);
3688 rw_lock_x_lock(&block->
lock);
3690 mutex_exit(&block->
mutex);
3698 mutex_enter(&block->
mutex);
3710 rw_lock_x_unlock(&block->
lock);
3719 mutex_exit(&block->
mutex);
3726 frame = block->
frame;
3740 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
3741 ut_a(++buf_dbg_counter % 5771 || buf_validate());
3743 #ifdef UNIV_IBUF_COUNT_DEBUG
3783 == (index_id_t)(DICT_IBUF_ID_MIN + IBUF_SPACE_ID)) {
3786 io_type, MONITOR_INDEX_IBUF_LEAF_PAGE);
3790 MONITOR_INDEX_IBUF_NON_LEAF_PAGE);
3795 io_type, MONITOR_INDEX_LEAF_PAGE);
3798 io_type, MONITOR_INDEX_NON_LEAF_PAGE);
3813 MONITOR_IBUF_FREELIST_PAGE);
3818 MONITOR_IBUF_BITMAP_PAGE);
3853 MONITOR_INC_NOCHECK(counter);
3862 buf_mark_space_corrupt(
3869 ulint space = bpage->
space;
3882 rw_lock_x_unlock_gen(
3932 ulint read_space_id;
3958 if (bpage->
space == TRX_SYS_SPACE
3963 " InnoDB: Error: reading page %lu\n"
3964 "InnoDB: which is in the"
3965 " doublewrite buffer!\n",
3967 }
else if (!read_space_id && !read_page_no) {
3969 }
else if ((bpage->
space
3970 && bpage->
space != read_space_id)
3971 || bpage->
offset != read_page_no) {
3979 " InnoDB: Error: space id and page n:o"
3980 " stored in the page\n"
3981 "InnoDB: read in are %lu:%lu,"
3982 " should be %lu:%lu!\n",
3983 (ulong) read_space_id, (ulong) read_page_no,
3984 (ulong) bpage->
space,
3996 DBUG_EXECUTE_IF(
"buf_page_is_corrupt_failure",
3997 if (bpage->
space > TRX_SYS_SPACE
3998 && buf_mark_space_corrupt(bpage)) {
4000 "Simulated page corruption");
4003 goto page_not_corrupt;
4007 "InnoDB: Database page corruption on disk"
4009 "InnoDB: file read of page %lu.\n"
4010 "InnoDB: You may have to recover"
4011 " from a backup.\n",
4016 "InnoDB: Database page corruption on disk"
4018 "InnoDB: file read of page %lu.\n"
4019 "InnoDB: You may have to recover"
4020 " from a backup.\n",
4022 fputs(
"InnoDB: It is also possible that"
4024 "InnoDB: system has corrupted its"
4026 "InnoDB: and rebooting your computer"
4029 "InnoDB: If the corrupt page is an index page\n"
4030 "InnoDB: you can also try to"
4031 " fix the corruption\n"
4032 "InnoDB: by dumping, dropping,"
4033 " and reimporting\n"
4034 "InnoDB: the corrupt table."
4035 " You can use CHECK\n"
4036 "InnoDB: TABLE to scan your"
4037 " table for corruption.\n"
4039 REFMAN
"forcing-innodb-recovery.html\n"
4040 "InnoDB: about forcing recovery.\n", stderr);
4046 if (bpage->
space > TRX_SYS_SPACE
4047 && buf_mark_space_corrupt(bpage)) {
4050 fputs(
"InnoDB: Ending processing"
4052 " a corrupt database page.\n",
4059 DBUG_EXECUTE_IF(
"buf_page_is_corrupt_failure",
4060 page_not_corrupt: bpage = bpage; );
4079 #ifdef UNIV_IBUF_COUNT_DEBUG
4105 rw_lock_x_unlock_gen(&((
buf_block_t*) bpage)->lock,
4118 rw_lock_s_unlock_gen(&((
buf_block_t*) bpage)->lock,
4130 buf_page_monitor(bpage, io_type);
4133 if (buf_debug_prints) {
4134 fprintf(stderr,
"Has %s page space %lu page no %lu\n",
4152 buf_all_freed_instance(
4163 chunk = buf_pool->
chunks;
4165 for (i = buf_pool->
n_chunks; i--; chunk++) {
4167 const buf_block_t* block = buf_chunk_not_freed(chunk);
4169 if (UNIV_LIKELY_NULL(block)) {
4171 "Page %lu %lu still fixed or dirty\n",
4187 buf_pool_invalidate_instance(
4208 if (buf_pool->
n_flush[i] > 0) {
4219 ut_ad(buf_all_freed_instance(buf_pool));
4233 memset(&buf_pool->
stat, 0x00,
sizeof(buf_pool->
stat));
4250 for (i = 0; i < srv_buf_pool_instances; i++) {
4255 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
4261 buf_pool_validate_instance(
4268 ulint n_lru_flush = 0;
4269 ulint n_page_flush = 0;
4270 ulint n_list_flush = 0;
4284 chunk = buf_pool->
chunks;
4288 for (i = buf_pool->
n_chunks; i--; chunk++) {
4293 for (j = chunk->size; j--; block++) {
4295 mutex_enter(&block->
mutex);
4316 #ifdef UNIV_IBUF_COUNT_DEBUG
4333 goto assert_s_latched;
4374 mutex_exit(&block->
mutex);
4417 ut_ad(b->in_flush_list);
4471 if (n_lru + n_free > buf_pool->
curr_size + n_zip) {
4472 fprintf(stderr,
"n LRU %lu, n free %lu, pool %lu zip %lu\n",
4473 (ulong) n_lru, (ulong) n_free,
4474 (ulong) buf_pool->
curr_size, (ulong) n_zip);
4480 fprintf(stderr,
"Free list len %lu, free blocks %lu\n",
4492 ut_a(buf_LRU_validate());
4493 ut_a(buf_flush_validate(buf_pool));
4508 for (i = 0; i < srv_buf_pool_instances; i++) {
4513 buf_pool_validate_instance(buf_pool);
4520 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
4529 index_id_t* index_ids;
4543 index_ids =
static_cast<index_id_t*
>(
4544 mem_alloc(size *
sizeof *index_ids));
4546 counts =
static_cast<ulint*
>(mem_alloc(
sizeof(ulint) * size));
4552 "buf_pool size %lu\n"
4553 "database pages %lu\n"
4555 "modified database pages %lu\n"
4556 "n pending decompressions %lu\n"
4557 "n pending reads %lu\n"
4558 "n pending flush LRU %lu list %lu single page %lu\n"
4559 "pages made young %lu, not young %lu\n"
4560 "pages read %lu, created %lu, written %lu\n",
4582 chunk = buf_pool->
chunks;
4584 for (i = buf_pool->
n_chunks; i--; chunk++) {
4586 ulint n_blocks = chunk->size;
4588 for (; n_blocks--; block++) {
4598 while (j < n_found) {
4600 if (index_ids[j] ==
id) {
4619 for (i = 0; i < n_found; i++) {
4620 index = dict_index_get_if_in_cache(index_ids[i]);
4623 "Block count for index %llu in buffer is about %lu",
4624 (ullint) index_ids[i],
4638 ut_a(buf_pool_validate_instance(buf_pool));
4650 for (i = 0; i < srv_buf_pool_instances; i++) {
4654 buf_print_instance(buf_pool);
4665 buf_get_latched_pages_number_instance(
4672 ulint fixed_pages_number = 0;
4676 chunk = buf_pool->
chunks;
4678 for (i = buf_pool->
n_chunks; i--; chunk++) {
4682 block = chunk->blocks;
4684 for (j = chunk->size; j--; block++) {
4691 mutex_enter(&block->
mutex);
4696 fixed_pages_number++;
4699 mutex_exit(&block->
mutex);
4714 fixed_pages_number++;
4721 ut_ad(b->in_flush_list);
4727 fixed_pages_number++;
4748 return(fixed_pages_number);
4756 buf_get_latched_pages_number(
void)
4760 ulint total_latched_pages = 0;
4762 for (i = 0; i < srv_buf_pool_instances; i++) {
4767 total_latched_pages += buf_get_latched_pages_number_instance(
4771 return(total_latched_pages);
4787 for (i = 0; i < srv_buf_pool_instances; i++) {
4806 ulint flush_list_len = 0;
4810 ratio = (100 * flush_list_len) / (1 + lru_len + free_len);
4821 buf_stats_aggregate_pool_info(
4829 ut_a(total_info && pool_info);
4832 if (total_info == pool_info) {
4887 time_t current_time;
4888 double time_elapsed;
4891 pool_info = &all_pool_info[pool_id];
4926 current_time = time(NULL);
4927 time_elapsed = 0.001 + difftime(current_time,
5014 buf_print_io_instance(
5022 "Buffer pool size %lu\n"
5023 "Free buffers %lu\n"
5024 "Database pages %lu\n"
5025 "Old database pages %lu\n"
5026 "Modified db pages %lu\n"
5027 "Pending reads %lu\n"
5028 "Pending writes: LRU %lu, flush list %lu, single page %lu\n",
5040 "Pages made young %lu, not young %lu\n"
5041 "%.2f youngs/s, %.2f non-youngs/s\n"
5042 "Pages read %lu, created %lu, written %lu\n"
5043 "%.2f reads/s, %.2f creates/s, %.2f writes/s\n",
5057 "Buffer pool hit rate %lu / 1000,"
5058 " young-making rate %lu / 1000 not %lu / 1000\n",
5066 fputs(
"No buffer pool page gets since the last printout\n",
5071 fprintf(file,
"Pages read ahead %.2f/s,"
5072 " evicted without access %.2f/s,"
5073 " Random read ahead %.2f/s\n",
5082 "LRU len: %lu, unzip_LRU len: %lu\n"
5083 "I/O sum[%lu]:cur[%lu], unzip sum[%lu]:cur[%lu]\n",
5104 if (srv_buf_pool_instances > 1) {
5106 srv_buf_pool_instances + 1) *
sizeof *pool_info);
5108 pool_info_total = &pool_info[srv_buf_pool_instances];
5110 ut_a(srv_buf_pool_instances == 1);
5112 pool_info_total = pool_info =
5117 for (i = 0; i < srv_buf_pool_instances; i++) {
5128 if (srv_buf_pool_instances > 1) {
5129 buf_stats_aggregate_pool_info(pool_info_total,
5135 buf_print_io_instance(pool_info_total, file);
5139 if (srv_buf_pool_instances > 1) {
5140 fputs(
"----------------------\n"
5141 "INDIVIDUAL BUFFER POOL INFO\n"
5142 "----------------------\n", file);
5144 for (i = 0; i < srv_buf_pool_instances; i++) {
5145 fprintf(file,
"---BUFFER POOL %lu\n", i);
5146 buf_print_io_instance(&pool_info[i], file);
5172 for (ulint i = 0; i < srv_buf_pool_instances; i++) {
5189 for (ulint i = 0; i < srv_buf_pool_instances; i++) {
5194 if (!buf_all_freed_instance(buf_pool)) {
5212 ulint pending_io = 0;
5216 for (i = 0; i < srv_buf_pool_instances; i++) {
5234 Code currently not used
5260 buf_page_init_for_backup_restore(
5277 ut_ad(zip_size <= UNIV_ZIP_SIZE_MAX);