diff options
Diffstat (limited to 'innobase/page/page0page.c')
-rw-r--r-- | innobase/page/page0page.c | 256 |
1 files changed, 238 insertions, 18 deletions
diff --git a/innobase/page/page0page.c b/innobase/page/page0page.c index ed74736c8da..7d240bdd5b0 100644 --- a/innobase/page/page0page.c +++ b/innobase/page/page0page.c @@ -1299,12 +1299,16 @@ page_rec_validate( heap_no = rec_get_heap_no(rec); if (!(n_owned <= PAGE_DIR_SLOT_MAX_N_OWNED)) { - fprintf(stderr, "Dir slot n owned too big %lu\n", n_owned); + fprintf(stderr, + "InnoDB: Dir slot of rec %lu, n owned too big %lu\n", + (ulint)(rec - page), n_owned); return(FALSE); } if (!(heap_no < page_header_get_field(page, PAGE_N_HEAP))) { - fprintf(stderr, "Heap no too big %lu %lu\n", heap_no, + fprintf(stderr, + "InnoDB: Heap no of rec %lu too big %lu %lu\n", + (ulint)(rec - page), heap_no, page_header_get_field(page, PAGE_N_HEAP)); return(FALSE); } @@ -1313,6 +1317,194 @@ page_rec_validate( } /******************************************************************* +This function checks the consistency of an index page when we do not +know the index. This is also resilient so that this should never crash +even if the page is total garbage. */ + +ibool +page_simple_validate( +/*=================*/ + /* out: TRUE if ok */ + page_t* page) /* in: index page */ +{ + page_cur_t cur; + page_dir_slot_t* slot; + ulint slot_no; + ulint n_slots; + rec_t* rec; + byte* rec_heap_top; + ulint count; + ulint own_count; + ibool ret = FALSE; + + /* Check first that the record heap and the directory do not + overlap. */ + + n_slots = page_dir_get_n_slots(page); + + if (n_slots > UNIV_PAGE_SIZE / 4) { + fprintf(stderr, + "InnoDB: Nonsensical number %lu of page dir slots\n", n_slots); + + goto func_exit; + } + + rec_heap_top = page_header_get_ptr(page, PAGE_HEAP_TOP); + + if (rec_heap_top > page_dir_get_nth_slot(page, n_slots - 1)) { + + fprintf(stderr, + "InnoDB: Record heap and dir overlap on a page, heap top %lu, dir %lu\n", + (ulint)(page_header_get_ptr(page, PAGE_HEAP_TOP) - page), + (ulint)(page_dir_get_nth_slot(page, n_slots - 1) - page)); + + goto func_exit; + } + + /* Validate the record list in a loop checking also that it is + consistent with the page record directory. */ + + count = 0; + own_count = 1; + slot_no = 0; + slot = page_dir_get_nth_slot(page, slot_no); + + page_cur_set_before_first(page, &cur); + + for (;;) { + rec = (&cur)->rec; + + if (rec > rec_heap_top) { + fprintf(stderr, + "InnoDB: Record %lu is above rec heap top %lu\n", + (ulint)(rec - page), (ulint)(rec_heap_top - page)); + + goto func_exit; + } + + if (rec_get_n_owned(rec) != 0) { + /* This is a record pointed to by a dir slot */ + if (rec_get_n_owned(rec) != own_count) { + + fprintf(stderr, + "InnoDB: Wrong owned count %lu, %lu, rec %lu\n", + rec_get_n_owned(rec), own_count, + (ulint)(rec - page)); + + goto func_exit; + } + + if (page_dir_slot_get_rec(slot) != rec) { + fprintf(stderr, + "InnoDB: Dir slot does not point to right rec %lu\n", + (ulint)(rec - page)); + + goto func_exit; + } + + own_count = 0; + + if (!page_cur_is_after_last(&cur)) { + slot_no++; + slot = page_dir_get_nth_slot(page, slot_no); + } + } + + if (page_cur_is_after_last(&cur)) { + + break; + } + + if (rec_get_next_offs(rec) < FIL_PAGE_DATA + || rec_get_next_offs(rec) >= UNIV_PAGE_SIZE) { + fprintf(stderr, + "InnoDB: Next record offset nonsensical %lu for rec %lu\n", + rec_get_next_offs(rec), + (ulint)(rec - page)); + + goto func_exit; + } + + count++; + + if (count > UNIV_PAGE_SIZE) { + fprintf(stderr, + "InnoDB: Page record list appears to be circular %lu\n", + count); + goto func_exit; + } + + page_cur_move_to_next(&cur); + own_count++; + } + + if (rec_get_n_owned(rec) == 0) { + fprintf(stderr, "InnoDB: n owned is zero in a supremum rec\n"); + + goto func_exit; + } + + if (slot_no != n_slots - 1) { + fprintf(stderr, "InnoDB: n slots wrong %lu, %lu\n", + slot_no, n_slots - 1); + goto func_exit; + } + + if (page_header_get_field(page, PAGE_N_RECS) + 2 != count + 1) { + fprintf(stderr, "InnoDB: n recs wrong %lu %lu\n", + page_header_get_field(page, PAGE_N_RECS) + 2, count + 1); + + goto func_exit; + } + + /* Check then the free list */ + rec = page_header_get_ptr(page, PAGE_FREE); + + while (rec != NULL) { + if (rec < page + FIL_PAGE_DATA + || rec >= page + UNIV_PAGE_SIZE) { + fprintf(stderr, + "InnoDB: Free list record has a nonsensical offset %lu\n", + (ulint)(rec - page)); + + goto func_exit; + } + + if (rec > rec_heap_top) { + fprintf(stderr, + "InnoDB: Free list record %lu is above rec heap top %lu\n", + (ulint)(rec - page), (ulint)(rec_heap_top - page)); + + goto func_exit; + } + + count++; + + if (count > UNIV_PAGE_SIZE) { + fprintf(stderr, + "InnoDB: Page free list appears to be circular %lu\n", + count); + goto func_exit; + } + + rec = page_rec_get_next(rec); + } + + if (page_header_get_field(page, PAGE_N_HEAP) != count + 1) { + + fprintf(stderr, "InnoDB: N heap is wrong %lu, %lu\n", + page_header_get_field(page, PAGE_N_HEAP), count + 1); + + goto func_exit; + } + + ret = TRUE; + +func_exit: + return(ret); +} + +/******************************************************************* This function checks the consistency of an index page. */ ibool @@ -1339,6 +1531,17 @@ page_validate( ulint i; char err_buf[1000]; + if (!page_simple_validate(page)) { + fprintf(stderr, +"InnoDB: Apparent corruption in page %lu in index %s in table %s\n", + buf_frame_get_page_no(page), index->name, + index->table_name); + + buf_page_print(page); + + return(FALSE); + } + heap = mem_heap_create(UNIV_PAGE_SIZE); /* The following buffer is used to check that the @@ -1357,7 +1560,7 @@ page_validate( if (!(page_header_get_ptr(page, PAGE_HEAP_TOP) <= page_dir_get_nth_slot(page, n_slots - 1))) { fprintf(stderr, - "Record heap and dir overlap on a page in index %s, %lu, %lu\n", +"InnoDB: Record heap and dir overlap on a page in index %s, %lu, %lu\n", index->name, (ulint)page_header_get_ptr(page, PAGE_HEAP_TOP), (ulint)page_dir_get_nth_slot(page, n_slots - 1)); @@ -1385,10 +1588,14 @@ page_validate( if ((count >= 2) && (!page_cur_is_after_last(&cur))) { if (!(1 == cmp_rec_rec(rec, old_rec, index))) { fprintf(stderr, - "Records in wrong order in index %s\n", - index->name); +"InnoDB: Records in wrong order on page %lu index %s table %s\n", + buf_frame_get_page_no(page), + index->name, + index->table_name); + rec_sprintf(err_buf, 900, old_rec); - fprintf(stderr, "InnoDB: record %s\n", err_buf); + fprintf(stderr, + "InnoDB: previous record %s\n", err_buf); rec_sprintf(err_buf, 900, rec); fprintf(stderr, "InnoDB: record %s\n", err_buf); @@ -1410,7 +1617,7 @@ page_validate( /* No other record may overlap this */ fprintf(stderr, - "Record overlaps another in index %s \n", + "InnoDB: Record overlaps another in index %s \n", index->name); goto func_exit; @@ -1423,7 +1630,7 @@ page_validate( /* This is a record pointed to by a dir slot */ if (rec_get_n_owned(rec) != own_count) { fprintf(stderr, - "Wrong owned count %lu, %lu, in index %s\n", + "InnoDB: Wrong owned count %lu, %lu, in index %s\n", rec_get_n_owned(rec), own_count, index->name); @@ -1432,7 +1639,7 @@ page_validate( if (page_dir_slot_get_rec(slot) != rec) { fprintf(stderr, - "Dir slot does not point to right rec in %s\n", + "InnoDB: Dir slot does not point to right rec in %s\n", index->name); goto func_exit; @@ -1454,7 +1661,7 @@ page_validate( if (rec_get_next_offs(rec) < FIL_PAGE_DATA || rec_get_next_offs(rec) >= UNIV_PAGE_SIZE) { fprintf(stderr, - "Next record offset wrong %lu in index %s\n", + "InnoDB: Next record offset wrong %lu in index %s\n", rec_get_next_offs(rec), index->name); goto func_exit; @@ -1467,19 +1674,20 @@ page_validate( } if (rec_get_n_owned(rec) == 0) { - fprintf(stderr, "n owned is zero in index %s\n", index->name); + fprintf(stderr, + "InnoDB: n owned is zero in index %s\n", index->name); goto func_exit; } if (slot_no != n_slots - 1) { - fprintf(stderr, "n slots wrong %lu %lu in index %s\n", + fprintf(stderr, "InnoDB: n slots wrong %lu %lu in index %s\n", slot_no, n_slots - 1, index->name); goto func_exit; } if (page_header_get_field(page, PAGE_N_RECS) + 2 != count + 1) { - fprintf(stderr, "n recs wrong %lu %lu in index %s\n", + fprintf(stderr, "InnoDB: n recs wrong %lu %lu in index %s\n", page_header_get_field(page, PAGE_N_RECS) + 2, count + 1, index->name); @@ -1487,7 +1695,8 @@ page_validate( } if (data_size != page_get_data_size(page)) { - fprintf(stderr, "Summed data size %lu, returned by func %lu\n", + fprintf(stderr, + "InnoDB: Summed data size %lu, returned by func %lu\n", data_size, page_get_data_size(page)); goto func_exit; } @@ -1508,7 +1717,7 @@ page_validate( if (buf[offs + i] != 0) { fprintf(stderr, - "Record overlaps another in free list, index %s \n", + "InnoDB: Record overlaps another in free list, index %s \n", index->name); goto func_exit; @@ -1522,9 +1731,11 @@ page_validate( if (page_header_get_field(page, PAGE_N_HEAP) != count + 1) { - fprintf(stderr, "N heap is wrong %lu %lu in index %s\n", - page_header_get_field(page, PAGE_N_HEAP), count + 1, - index->name); + fprintf(stderr, + "InnoDB: N heap is wrong %lu %lu in index %s\n", + page_header_get_field(page, PAGE_N_HEAP), count + 1, + index->name); + goto func_exit; } ret = TRUE; @@ -1532,6 +1743,15 @@ page_validate( func_exit: mem_heap_free(heap); + if (ret == FALSE) { + fprintf(stderr, +"InnoDB: Apparent corruption in page %lu in index %s in table %s\n", + buf_frame_get_page_no(page), index->name, + index->table_name); + + buf_page_print(page); + } + return(ret); } |