Commit 5ba4fc82 authored by marko's avatar marko

Define UNIV_BTR_DEBUG for enabling consistency checks of

FIL_PAGE_NEXT and FIL_PAGE_PREV when accessing sibling pages
of B-tree indexes.

btr_validate_level(): Check the validity of the doubly linked list
formed by FIL_PAGE_NEXT and FIL_PAGE_PREV.
parent 0c532d75
...@@ -190,6 +190,10 @@ btr_get_prev_user_rec( ...@@ -190,6 +190,10 @@ btr_get_prev_user_rec(
|| (mtr_memo_contains(mtr, buf_block_align(prev_page), || (mtr_memo_contains(mtr, buf_block_align(prev_page),
MTR_MEMO_PAGE_X_FIX))); MTR_MEMO_PAGE_X_FIX)));
ut_a(page_is_comp(prev_page) == page_is_comp(page)); 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))); return(page_rec_get_prev(page_get_supremum_rec(prev_page)));
} }
...@@ -237,6 +241,10 @@ btr_get_next_user_rec( ...@@ -237,6 +241,10 @@ btr_get_next_user_rec(
MTR_MEMO_PAGE_S_FIX)) MTR_MEMO_PAGE_S_FIX))
|| (mtr_memo_contains(mtr, buf_block_align(next_page), || (mtr_memo_contains(mtr, buf_block_align(next_page),
MTR_MEMO_PAGE_X_FIX))); 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)); ut_a(page_is_comp(next_page) == page_is_comp(page));
return(page_rec_get_next(page_get_infimum_rec(next_page))); return(page_rec_get_next(page_get_infimum_rec(next_page)));
...@@ -1518,6 +1526,10 @@ btr_attach_half_pages( ...@@ -1518,6 +1526,10 @@ btr_attach_half_pages(
prev_page = btr_page_get(space, prev_page_no, RW_X_LATCH, mtr); prev_page = btr_page_get(space, prev_page_no, RW_X_LATCH, mtr);
ut_a(page_is_comp(prev_page) == page_is_comp(page)); 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); btr_page_set_next(prev_page, lower_page_no, mtr);
} }
...@@ -1805,6 +1817,10 @@ btr_level_list_remove( ...@@ -1805,6 +1817,10 @@ btr_level_list_remove(
prev_page = btr_page_get(space, prev_page_no, RW_X_LATCH, mtr); prev_page = btr_page_get(space, prev_page_no, RW_X_LATCH, mtr);
ut_a(page_is_comp(prev_page) == page_is_comp(page)); 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); btr_page_set_next(prev_page, next_page_no, mtr);
} }
...@@ -1813,6 +1829,10 @@ btr_level_list_remove( ...@@ -1813,6 +1829,10 @@ btr_level_list_remove(
next_page = btr_page_get(space, next_page_no, RW_X_LATCH, mtr); next_page = btr_page_get(space, next_page_no, RW_X_LATCH, mtr);
ut_a(page_is_comp(next_page) == page_is_comp(page)); 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); btr_page_set_prev(next_page, prev_page_no, mtr);
} }
...@@ -2032,16 +2052,24 @@ btr_compress( ...@@ -2032,16 +2052,24 @@ btr_compress(
/* Decide the page to which we try to merge and which will inherit /* Decide the page to which we try to merge and which will inherit
the locks */ 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, merge_page = btr_page_get(space, left_page_no, RW_X_LATCH,
mtr); 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) { } else if (right_page_no != FIL_NULL) {
is_left = FALSE;
merge_page = btr_page_get(space, right_page_no, RW_X_LATCH, merge_page = btr_page_get(space, right_page_no, RW_X_LATCH,
mtr); 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 { } else {
/* The page is the only one on the level, lift the records /* The page is the only one on the level, lift the records
to the father */ to the father */
...@@ -2203,7 +2231,6 @@ btr_discard_page( ...@@ -2203,7 +2231,6 @@ btr_discard_page(
ulint left_page_no; ulint left_page_no;
ulint right_page_no; ulint right_page_no;
page_t* merge_page; page_t* merge_page;
ibool is_left;
page_t* page; page_t* page;
rec_t* node_ptr; rec_t* node_ptr;
...@@ -2223,13 +2250,19 @@ btr_discard_page( ...@@ -2223,13 +2250,19 @@ btr_discard_page(
right_page_no = btr_page_get_next(page, mtr); right_page_no = btr_page_get_next(page, mtr);
if (left_page_no != FIL_NULL) { if (left_page_no != FIL_NULL) {
is_left = TRUE;
merge_page = btr_page_get(space, left_page_no, RW_X_LATCH, merge_page = btr_page_get(space, left_page_no, RW_X_LATCH,
mtr); 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) { } else if (right_page_no != FIL_NULL) {
is_left = FALSE;
merge_page = btr_page_get(space, right_page_no, RW_X_LATCH, merge_page = btr_page_get(space, right_page_no, RW_X_LATCH,
mtr); 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 { } else {
btr_discard_only_page_on_level(tree, page, mtr); btr_discard_only_page_on_level(tree, page, mtr);
...@@ -2256,11 +2289,11 @@ btr_discard_page( ...@@ -2256,11 +2289,11 @@ btr_discard_page(
/* Remove the page from the level list */ /* Remove the page from the level list */
btr_level_list_remove(tree, page, mtr); 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); lock_update_discard(page_get_supremum_rec(merge_page), page);
} else { } else {
lock_update_discard(page_rec_get_next( 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 */ /* Free the file page */
...@@ -2745,7 +2778,29 @@ btr_validate_level( ...@@ -2745,7 +2778,29 @@ btr_validate_level(
rec_t* right_rec; rec_t* right_rec;
right_page = btr_page_get(space, right_page_no, RW_X_LATCH, right_page = btr_page_get(space, right_page_no, RW_X_LATCH,
&mtr); &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)); rec = page_rec_get_prev(page_get_supremum_rec(page));
right_rec = page_rec_get_next( right_rec = page_rec_get_next(
page_get_infimum_rec(right_page)); page_get_infimum_rec(right_page));
...@@ -2753,8 +2808,8 @@ btr_validate_level( ...@@ -2753,8 +2808,8 @@ btr_validate_level(
offsets, ULINT_UNDEFINED, &heap); offsets, ULINT_UNDEFINED, &heap);
offsets2 = rec_get_offsets(right_rec, index, offsets2 = rec_get_offsets(right_rec, index,
offsets2, ULINT_UNDEFINED, &heap); offsets2, ULINT_UNDEFINED, &heap);
if (cmp_rec_rec(rec, right_rec, offsets, offsets2, index) if (UNIV_UNLIKELY(cmp_rec_rec(rec, right_rec,
>= 0) { offsets, offsets2, index) >= 0)) {
btr_validate_report2(index, level, page, right_page); btr_validate_report2(index, level, page, right_page);
...@@ -2869,10 +2924,7 @@ btr_validate_level( ...@@ -2869,10 +2924,7 @@ btr_validate_level(
ut_a(node_ptr == page_rec_get_prev( ut_a(node_ptr == page_rec_get_prev(
page_get_supremum_rec(father_page))); page_get_supremum_rec(father_page)));
ut_a(btr_page_get_next(father_page, &mtr) == FIL_NULL); ut_a(btr_page_get_next(father_page, &mtr) == FIL_NULL);
} } else {
if (right_page_no != FIL_NULL) {
right_node_ptr = btr_page_get_father_node_ptr(tree, right_node_ptr = btr_page_get_father_node_ptr(tree,
right_page, &mtr); right_page, &mtr);
if (page_rec_get_next(node_ptr) != if (page_rec_get_next(node_ptr) !=
...@@ -2934,14 +2986,15 @@ btr_validate_level( ...@@ -2934,14 +2986,15 @@ btr_validate_level(
} }
node_ptr_fails: 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); mtr_commit(&mtr);
if (right_page_no != FIL_NULL) { if (right_page_no != FIL_NULL) {
ulint comp = page_is_comp(page);
mtr_start(&mtr); mtr_start(&mtr);
page = btr_page_get(space, right_page_no, RW_X_LATCH, &mtr); page = btr_page_get(space, right_page_no, RW_X_LATCH, &mtr);
ut_a(page_is_comp(page) == comp);
goto loop; goto loop;
} }
......
...@@ -157,6 +157,10 @@ btr_cur_latch_leaves( ...@@ -157,6 +157,10 @@ btr_cur_latch_leaves(
if (left_page_no != FIL_NULL) { if (left_page_no != FIL_NULL) {
get_page = btr_page_get(space, left_page_no, get_page = btr_page_get(space, left_page_no,
RW_X_LATCH, mtr); 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)); ut_a(page_is_comp(get_page) == page_is_comp(page));
buf_block_align(get_page)->check_index_page_at_flush = buf_block_align(get_page)->check_index_page_at_flush =
TRUE; TRUE;
...@@ -171,6 +175,10 @@ btr_cur_latch_leaves( ...@@ -171,6 +175,10 @@ btr_cur_latch_leaves(
if (right_page_no != FIL_NULL) { if (right_page_no != FIL_NULL) {
get_page = btr_page_get(space, right_page_no, get_page = btr_page_get(space, right_page_no,
RW_X_LATCH, mtr); 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 = buf_block_align(get_page)->check_index_page_at_flush =
TRUE; TRUE;
} }
...@@ -183,6 +191,10 @@ btr_cur_latch_leaves( ...@@ -183,6 +191,10 @@ btr_cur_latch_leaves(
if (left_page_no != FIL_NULL) { if (left_page_no != FIL_NULL) {
cursor->left_page = btr_page_get(space, left_page_no, cursor->left_page = btr_page_get(space, left_page_no,
RW_S_LATCH, mtr); 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) == ut_a(page_is_comp(cursor->left_page) ==
page_is_comp(page)); page_is_comp(page));
buf_block_align( buf_block_align(
...@@ -201,6 +213,10 @@ btr_cur_latch_leaves( ...@@ -201,6 +213,10 @@ btr_cur_latch_leaves(
if (left_page_no != FIL_NULL) { if (left_page_no != FIL_NULL) {
cursor->left_page = btr_page_get(space, left_page_no, cursor->left_page = btr_page_get(space, left_page_no,
RW_X_LATCH, mtr); 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) == ut_a(page_is_comp(cursor->left_page) ==
page_is_comp(page)); page_is_comp(page));
buf_block_align( buf_block_align(
...@@ -1731,6 +1747,10 @@ btr_cur_pess_upd_restore_supremum( ...@@ -1731,6 +1747,10 @@ btr_cur_pess_upd_restore_supremum(
ut_ad(prev_page_no != FIL_NULL); ut_ad(prev_page_no != FIL_NULL);
prev_page = buf_page_get_with_no_latch(space, prev_page_no, mtr); 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! */ /* We must already have an x-latch to prev_page! */
ut_ad(mtr_memo_contains(mtr, buf_block_align(prev_page), ut_ad(mtr_memo_contains(mtr, buf_block_align(prev_page),
......
...@@ -397,6 +397,9 @@ btr_pcur_move_to_next_page( ...@@ -397,6 +397,9 @@ btr_pcur_move_to_next_page(
ut_ad(next_page_no != FIL_NULL); ut_ad(next_page_no != FIL_NULL);
next_page = btr_page_get(space, next_page_no, cursor->latch_mode, mtr); 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)); ut_a(page_is_comp(next_page) == page_is_comp(page));
buf_block_align(next_page)->check_index_page_at_flush = TRUE; buf_block_align(next_page)->check_index_page_at_flush = TRUE;
......
...@@ -2345,6 +2345,10 @@ ibuf_get_volume_buffered( ...@@ -2345,6 +2345,10 @@ ibuf_get_volume_buffered(
} }
prev_page = buf_page_get(0, prev_page_no, RW_X_LATCH, mtr); 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 #ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(prev_page, SYNC_TREE_NODE); buf_page_dbg_add_level(prev_page, SYNC_TREE_NODE);
...@@ -2408,6 +2412,10 @@ ibuf_get_volume_buffered( ...@@ -2408,6 +2412,10 @@ ibuf_get_volume_buffered(
} }
next_page = buf_page_get(0, next_page_no, RW_X_LATCH, mtr); 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 #ifdef UNIV_SYNC_DEBUG
buf_page_dbg_add_level(next_page, SYNC_TREE_NODE); buf_page_dbg_add_level(next_page, SYNC_TREE_NODE);
......
...@@ -93,6 +93,7 @@ memory is read outside the allocated blocks. */ ...@@ -93,6 +93,7 @@ memory is read outside the allocated blocks. */
#define UNIV_SRV_PRINT_LATCH_WAITS #define UNIV_SRV_PRINT_LATCH_WAITS
#endif #endif
#define UNIV_BTR_DEBUG
#define UNIV_LIGHT_MEM_DEBUG #define UNIV_LIGHT_MEM_DEBUG
#define YYDEBUG 1 #define YYDEBUG 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment