Commit e63bbb3f authored by marko's avatar marko

branches/zip: Introduce the function page_zip_fail_func() and

the wrapper macro page_zip_fail() for displaying error messages.
When the error output is enabled (at compile-time), a breakpoint
may be set in page_zip_fail_func to easily debug all decompression
errors in the context where they occur.
parent 83e20f90
...@@ -59,6 +59,35 @@ static const byte supremum_extra_data[] = { ...@@ -59,6 +59,35 @@ static const byte supremum_extra_data[] = {
static const byte zero[BTR_EXTERN_FIELD_REF_SIZE] = { 0, }; static const byte zero[BTR_EXTERN_FIELD_REF_SIZE] = { 0, };
#endif #endif
/* Enable some extra debugging output. This code can be enabled
independently of any UNIV_ debugging conditions. */
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
# include <stdarg.h>
__attribute__((format (printf, 1, 2)))
/**************************************************************************
Report a failure to decompress or compress. */
static
int
page_zip_fail_func(
/*===============*/
/* out: number of characters printed */
const char* fmt, /* in: printf(3) format string */
...) /* in: arguments corresponding to fmt */
{
int res;
va_list ap;
va_start(ap, fmt);
res = vfprintf(stderr, fmt, ap);
va_end(ap);
return(res);
}
# define page_zip_fail(fmt_args) page_zip_fail_func fmt_args
#else /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
# define page_zip_fail(fmt_args) /* empty */
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
/************************************************************************** /**************************************************************************
Determine the guaranteed free space on an empty page. */ Determine the guaranteed free space on an empty page. */
...@@ -1442,6 +1471,8 @@ page_zip_dir_decode( ...@@ -1442,6 +1471,8 @@ page_zip_dir_decode(
n_recs = page_get_n_recs(page); n_recs = page_get_n_recs(page);
if (UNIV_UNLIKELY(n_recs > n_dense)) { if (UNIV_UNLIKELY(n_recs > n_dense)) {
page_zip_fail(("page_zip_dir_decode 1: %lu > %lu\n",
(ulong) n_recs, (ulong) n_dense));
return(FALSE); return(FALSE);
} }
...@@ -1470,6 +1501,9 @@ page_zip_dir_decode( ...@@ -1470,6 +1501,9 @@ page_zip_dir_decode(
if (UNIV_UNLIKELY((offs & PAGE_ZIP_DIR_SLOT_MASK) if (UNIV_UNLIKELY((offs & PAGE_ZIP_DIR_SLOT_MASK)
< PAGE_ZIP_START + REC_N_NEW_EXTRA_BYTES)) { < PAGE_ZIP_START + REC_N_NEW_EXTRA_BYTES)) {
page_zip_fail(("page_zip_dir_decode 2: %u %u %lx\n",
(unsigned) i, (unsigned) n_recs,
(ulong) offs));
return(FALSE); return(FALSE);
} }
...@@ -1477,10 +1511,16 @@ page_zip_dir_decode( ...@@ -1477,10 +1511,16 @@ page_zip_dir_decode(
} }
mach_write_to_2(slot, PAGE_NEW_SUPREMUM); mach_write_to_2(slot, PAGE_NEW_SUPREMUM);
if (UNIV_UNLIKELY {
(slot != page_dir_get_nth_slot(page, const page_dir_slot_t* last_slot = page_dir_get_nth_slot(
page_dir_get_n_slots(page) - 1))) { page, page_dir_get_n_slots(page) - 1);
return(FALSE);
if (UNIV_UNLIKELY(slot != last_slot)) {
page_zip_fail(("page_zip_dir_decode 3: %p != %p\n",
(const void*) slot,
(const void*) last_slot));
return(FALSE);
}
} }
/* Copy the rest of the dense directory. */ /* Copy the rest of the dense directory. */
...@@ -1488,6 +1528,9 @@ page_zip_dir_decode( ...@@ -1488,6 +1528,9 @@ page_zip_dir_decode(
ulint offs = page_zip_dir_get(page_zip, i); ulint offs = page_zip_dir_get(page_zip, i);
if (UNIV_UNLIKELY(offs & ~PAGE_ZIP_DIR_SLOT_MASK)) { if (UNIV_UNLIKELY(offs & ~PAGE_ZIP_DIR_SLOT_MASK)) {
page_zip_fail(("page_zip_dir_decode 4: %u %u %lx\n",
(unsigned) i, (unsigned) n_dense,
(ulong) offs));
return(FALSE); return(FALSE);
} }
...@@ -1536,6 +1579,10 @@ page_zip_set_extra_bytes( ...@@ -1536,6 +1579,10 @@ page_zip_set_extra_bytes(
offs &= PAGE_ZIP_DIR_SLOT_MASK; offs &= PAGE_ZIP_DIR_SLOT_MASK;
if (UNIV_UNLIKELY(offs < PAGE_ZIP_START if (UNIV_UNLIKELY(offs < PAGE_ZIP_START
+ REC_N_NEW_EXTRA_BYTES)) { + REC_N_NEW_EXTRA_BYTES)) {
page_zip_fail(("page_zip_set_extra_bytes 1:"
" %u %u %lx\n",
(unsigned) i, (unsigned) n,
(ulong) offs));
return(FALSE); return(FALSE);
} }
...@@ -1555,8 +1602,13 @@ page_zip_set_extra_bytes( ...@@ -1555,8 +1602,13 @@ page_zip_set_extra_bytes(
n = page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW; n = page_dir_get_n_heap(page) - PAGE_HEAP_NO_USER_LOW;
if (i >= n) { if (i >= n) {
if (UNIV_LIKELY(i == n)) {
return(TRUE);
}
return(UNIV_LIKELY(i == n)); page_zip_fail(("page_zip_set_extra_bytes 2: %u != %u\n",
(unsigned) i, (unsigned) n));
return(FALSE);
} }
offs = page_zip_dir_get(page_zip, i); offs = page_zip_dir_get(page_zip, i);
...@@ -1565,6 +1617,9 @@ page_zip_set_extra_bytes( ...@@ -1565,6 +1617,9 @@ page_zip_set_extra_bytes(
for (;;) { for (;;) {
if (UNIV_UNLIKELY(!offs) if (UNIV_UNLIKELY(!offs)
|| UNIV_UNLIKELY(offs & ~PAGE_ZIP_DIR_SLOT_MASK)) { || UNIV_UNLIKELY(offs & ~PAGE_ZIP_DIR_SLOT_MASK)) {
page_zip_fail(("page_zip_set_extra_bytes 3: %lx\n",
(ulong) offs));
return(FALSE); return(FALSE);
} }
...@@ -2508,6 +2563,9 @@ page_zip_decompress( ...@@ -2508,6 +2563,9 @@ page_zip_decompress(
n_dense = page_dir_get_n_heap(page_zip->data) - PAGE_HEAP_NO_USER_LOW; n_dense = page_dir_get_n_heap(page_zip->data) - PAGE_HEAP_NO_USER_LOW;
if (UNIV_UNLIKELY(n_dense * PAGE_ZIP_DIR_SLOT_SIZE if (UNIV_UNLIKELY(n_dense * PAGE_ZIP_DIR_SLOT_SIZE
>= page_zip_get_size(page_zip))) { >= page_zip_get_size(page_zip))) {
page_zip_fail(("page_zip_decompress 1: %lu %lu\n",
(ulong) n_dense,
(ulong) page_zip_get_size(page_zip)));
return(FALSE); return(FALSE);
} }
...@@ -2672,7 +2730,7 @@ page_zip_validate( ...@@ -2672,7 +2730,7 @@ page_zip_validate(
|| memcmp(page_zip->data + FIL_PAGE_TYPE, page + FIL_PAGE_TYPE, 2) || memcmp(page_zip->data + FIL_PAGE_TYPE, page + FIL_PAGE_TYPE, 2)
|| memcmp(page_zip->data + FIL_PAGE_DATA, page + FIL_PAGE_DATA, || memcmp(page_zip->data + FIL_PAGE_DATA, page + FIL_PAGE_DATA,
PAGE_DATA - FIL_PAGE_DATA)) { PAGE_DATA - FIL_PAGE_DATA)) {
fputs("page_zip_validate(): page header mismatch\n", stderr); page_zip_fail(("page_zip_validate: page header\n"));
return(FALSE); return(FALSE);
} }
...@@ -2706,34 +2764,31 @@ page_zip_validate( ...@@ -2706,34 +2764,31 @@ page_zip_validate(
goto func_exit; goto func_exit;
} }
if (page_zip->n_blobs != temp_page_zip.n_blobs) { if (page_zip->n_blobs != temp_page_zip.n_blobs) {
fprintf(stderr, page_zip_fail(("page_zip_validate: n_blobs: %u!=%u\n",
"page_zip_validate(): n_blobs mismatch: %d!=%d\n", page_zip->n_blobs, temp_page_zip.n_blobs));
page_zip->n_blobs, temp_page_zip.n_blobs);
valid = FALSE; valid = FALSE;
} }
#ifdef UNIV_DEBUG #ifdef UNIV_DEBUG
if (page_zip->m_start != temp_page_zip.m_start) { if (page_zip->m_start != temp_page_zip.m_start) {
fprintf(stderr, page_zip_fail(("page_zip_validate: m_start: %u!=%u\n",
"page_zip_validate(): m_start mismatch: %d!=%d\n", page_zip->m_start, temp_page_zip.m_start));
page_zip->m_start, temp_page_zip.m_start);
valid = FALSE; valid = FALSE;
} }
#endif /* UNIV_DEBUG */ #endif /* UNIV_DEBUG */
if (page_zip->m_end != temp_page_zip.m_end) { if (page_zip->m_end != temp_page_zip.m_end) {
fprintf(stderr, page_zip_fail(("page_zip_validate: m_end: %u!=%u\n",
"page_zip_validate(): m_end mismatch: %d!=%d\n", page_zip->m_end, temp_page_zip.m_end));
page_zip->m_end, temp_page_zip.m_end);
valid = FALSE; valid = FALSE;
} }
if (page_zip->m_nonempty != temp_page_zip.m_nonempty) { if (page_zip->m_nonempty != temp_page_zip.m_nonempty) {
fprintf(stderr, page_zip_fail(("page_zip_validate(): m_nonempty: %u!=%u\n",
"page_zip_validate(): m_nonempty mismatch: %d!=%d\n", page_zip->m_nonempty,
page_zip->m_nonempty, temp_page_zip.m_nonempty); temp_page_zip.m_nonempty));
valid = FALSE; valid = FALSE;
} }
if (memcmp(page + PAGE_HEADER, temp_page + PAGE_HEADER, if (memcmp(page + PAGE_HEADER, temp_page + PAGE_HEADER,
UNIV_PAGE_SIZE - PAGE_HEADER - FIL_PAGE_DATA_END)) { UNIV_PAGE_SIZE - PAGE_HEADER - FIL_PAGE_DATA_END)) {
fputs("page_zip_validate(): content mismatch\n", stderr); page_zip_fail(("page_zip_validate: content\n"));
valid = FALSE; valid = FALSE;
} }
......
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