diff --git a/btr/btr0btr.c b/btr/btr0btr.c index 5e338f97982..48cc1504b52 100644 --- a/btr/btr0btr.c +++ b/btr/btr0btr.c @@ -190,6 +190,10 @@ btr_get_prev_user_rec( || (mtr_memo_contains(mtr, buf_block_align(prev_page), MTR_MEMO_PAGE_X_FIX))); ut_a(page_is_comp(prev_page) == page_is_comp(page)); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(prev_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ return(page_rec_get_prev(page_get_supremum_rec(prev_page))); } @@ -237,6 +241,10 @@ btr_get_next_user_rec( MTR_MEMO_PAGE_S_FIX)) || (mtr_memo_contains(mtr, buf_block_align(next_page), MTR_MEMO_PAGE_X_FIX))); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(next_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ ut_a(page_is_comp(next_page) == page_is_comp(page)); return(page_rec_get_next(page_get_infimum_rec(next_page))); @@ -1518,6 +1526,10 @@ btr_attach_half_pages( prev_page = btr_page_get(space, prev_page_no, RW_X_LATCH, mtr); ut_a(page_is_comp(prev_page) == page_is_comp(page)); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(prev_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ btr_page_set_next(prev_page, lower_page_no, mtr); } @@ -1805,6 +1817,10 @@ btr_level_list_remove( prev_page = btr_page_get(space, prev_page_no, RW_X_LATCH, mtr); ut_a(page_is_comp(prev_page) == page_is_comp(page)); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(prev_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ btr_page_set_next(prev_page, next_page_no, mtr); } @@ -1813,6 +1829,10 @@ btr_level_list_remove( next_page = btr_page_get(space, next_page_no, RW_X_LATCH, mtr); ut_a(page_is_comp(next_page) == page_is_comp(page)); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(next_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ btr_page_set_prev(next_page, prev_page_no, mtr); } @@ -2032,16 +2052,24 @@ btr_compress( /* Decide the page to which we try to merge and which will inherit the locks */ - if (left_page_no != FIL_NULL) { + is_left = left_page_no != FIL_NULL; + + if (is_left) { - is_left = TRUE; merge_page = btr_page_get(space, left_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(merge_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ } else if (right_page_no != FIL_NULL) { - is_left = FALSE; merge_page = btr_page_get(space, right_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(merge_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ } else { /* The page is the only one on the level, lift the records to the father */ @@ -2203,7 +2231,6 @@ btr_discard_page( ulint left_page_no; ulint right_page_no; page_t* merge_page; - ibool is_left; page_t* page; rec_t* node_ptr; @@ -2223,13 +2250,19 @@ btr_discard_page( right_page_no = btr_page_get_next(page, mtr); if (left_page_no != FIL_NULL) { - is_left = TRUE; merge_page = btr_page_get(space, left_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(merge_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ } else if (right_page_no != FIL_NULL) { - is_left = FALSE; merge_page = btr_page_get(space, right_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(merge_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ } else { btr_discard_only_page_on_level(tree, page, mtr); @@ -2256,11 +2289,11 @@ btr_discard_page( /* Remove the page from the level list */ btr_level_list_remove(tree, page, mtr); - if (is_left) { + if (left_page_no != FIL_NULL) { lock_update_discard(page_get_supremum_rec(merge_page), page); } else { lock_update_discard(page_rec_get_next( - page_get_infimum_rec(merge_page)), page); + page_get_infimum_rec(merge_page)), page); } /* Free the file page */ @@ -2745,7 +2778,29 @@ loop: rec_t* right_rec; right_page = btr_page_get(space, right_page_no, RW_X_LATCH, &mtr); - ut_a(page_is_comp(right_page) == page_is_comp(page)); + if (UNIV_UNLIKELY(btr_page_get_prev(right_page, &mtr) + != buf_frame_get_page_no(page))) { + btr_validate_report2(index, level, page, right_page); + fputs("InnoDB: broken FIL_PAGE_NEXT" + " or FIL_PAGE_PREV links\n", stderr); + buf_page_print(page); + buf_page_print(right_page); + + ret = FALSE; + } + + if (UNIV_UNLIKELY(page_is_comp(right_page) + != page_is_comp(page))) { + btr_validate_report2(index, level, page, right_page); + fputs("InnoDB: 'compact' flag mismatch\n", stderr); + buf_page_print(page); + buf_page_print(right_page); + + ret = FALSE; + + goto node_ptr_fails; + } + rec = page_rec_get_prev(page_get_supremum_rec(page)); right_rec = page_rec_get_next( page_get_infimum_rec(right_page)); @@ -2753,8 +2808,8 @@ loop: offsets, ULINT_UNDEFINED, &heap); offsets2 = rec_get_offsets(right_rec, index, offsets2, ULINT_UNDEFINED, &heap); - if (cmp_rec_rec(rec, right_rec, offsets, offsets2, index) - >= 0) { + if (UNIV_UNLIKELY(cmp_rec_rec(rec, right_rec, + offsets, offsets2, index) >= 0)) { btr_validate_report2(index, level, page, right_page); @@ -2869,10 +2924,7 @@ loop: ut_a(node_ptr == page_rec_get_prev( page_get_supremum_rec(father_page))); ut_a(btr_page_get_next(father_page, &mtr) == FIL_NULL); - } - - if (right_page_no != FIL_NULL) { - + } else { right_node_ptr = btr_page_get_father_node_ptr(tree, right_page, &mtr); if (page_rec_get_next(node_ptr) != @@ -2934,14 +2986,15 @@ loop: } node_ptr_fails: + /* Commit the mini-transaction to release the latch on 'page'. + Re-acquire the latch on right_page, which will become 'page' + on the next loop. The page has already been checked. */ mtr_commit(&mtr); if (right_page_no != FIL_NULL) { - ulint comp = page_is_comp(page); mtr_start(&mtr); page = btr_page_get(space, right_page_no, RW_X_LATCH, &mtr); - ut_a(page_is_comp(page) == comp); goto loop; } diff --git a/btr/btr0cur.c b/btr/btr0cur.c index deba3e23487..503a897dfb4 100644 --- a/btr/btr0cur.c +++ b/btr/btr0cur.c @@ -157,6 +157,10 @@ btr_cur_latch_leaves( if (left_page_no != FIL_NULL) { get_page = btr_page_get(space, left_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(get_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ ut_a(page_is_comp(get_page) == page_is_comp(page)); buf_block_align(get_page)->check_index_page_at_flush = TRUE; @@ -171,6 +175,10 @@ btr_cur_latch_leaves( if (right_page_no != FIL_NULL) { get_page = btr_page_get(space, right_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(get_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ buf_block_align(get_page)->check_index_page_at_flush = TRUE; } @@ -183,6 +191,10 @@ btr_cur_latch_leaves( if (left_page_no != FIL_NULL) { cursor->left_page = btr_page_get(space, left_page_no, RW_S_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(cursor->left_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ ut_a(page_is_comp(cursor->left_page) == page_is_comp(page)); buf_block_align( @@ -201,6 +213,10 @@ btr_cur_latch_leaves( if (left_page_no != FIL_NULL) { cursor->left_page = btr_page_get(space, left_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(cursor->left_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ ut_a(page_is_comp(cursor->left_page) == page_is_comp(page)); buf_block_align( @@ -1731,6 +1747,10 @@ btr_cur_pess_upd_restore_supremum( ut_ad(prev_page_no != FIL_NULL); prev_page = buf_page_get_with_no_latch(space, prev_page_no, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(prev_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ /* We must already have an x-latch to prev_page! */ ut_ad(mtr_memo_contains(mtr, buf_block_align(prev_page), diff --git a/btr/btr0pcur.c b/btr/btr0pcur.c index 85a6577bafb..c739930ce04 100644 --- a/btr/btr0pcur.c +++ b/btr/btr0pcur.c @@ -397,6 +397,9 @@ btr_pcur_move_to_next_page( ut_ad(next_page_no != FIL_NULL); next_page = btr_page_get(space, next_page_no, cursor->latch_mode, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(next_page, mtr) == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ ut_a(page_is_comp(next_page) == page_is_comp(page)); buf_block_align(next_page)->check_index_page_at_flush = TRUE; diff --git a/ibuf/ibuf0ibuf.c b/ibuf/ibuf0ibuf.c index 4508469fd7f..369fbd61c04 100644 --- a/ibuf/ibuf0ibuf.c +++ b/ibuf/ibuf0ibuf.c @@ -2345,6 +2345,10 @@ ibuf_get_volume_buffered( } prev_page = buf_page_get(0, prev_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_next(prev_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ #ifdef UNIV_SYNC_DEBUG buf_page_dbg_add_level(prev_page, SYNC_TREE_NODE); @@ -2408,6 +2412,10 @@ count_later: } next_page = buf_page_get(0, next_page_no, RW_X_LATCH, mtr); +#ifdef UNIV_BTR_DEBUG + ut_a(btr_page_get_prev(next_page, mtr) + == buf_frame_get_page_no(page)); +#endif /* UNIV_BTR_DEBUG */ #ifdef UNIV_SYNC_DEBUG buf_page_dbg_add_level(next_page, SYNC_TREE_NODE); diff --git a/include/univ.i b/include/univ.i index 7b0bb89b23e..f2dafbc3a70 100644 --- a/include/univ.i +++ b/include/univ.i @@ -93,6 +93,7 @@ memory is read outside the allocated blocks. */ #define UNIV_SRV_PRINT_LATCH_WAITS #endif +#define UNIV_BTR_DEBUG #define UNIV_LIGHT_MEM_DEBUG #define YYDEBUG 1