diff options
author | Monty <monty@mariadb.org> | 2022-06-06 15:22:24 +0300 |
---|---|---|
committer | Sergei Petrunia <sergey@mariadb.com> | 2022-06-07 20:43:11 +0300 |
commit | 3d241eb948855dbe0688a04c8111cc78deac3c1c (patch) | |
tree | fb4419ec163dffd9780afef2c5083a988d94b91f /storage | |
parent | 1de18a836f1abbe76632337f9296f402bbdf4cfc (diff) | |
download | mariadb-git-3d241eb948855dbe0688a04c8111cc78deac3c1c.tar.gz |
Improve error reporting in Aria
This patch fixes the following issues in Aria error reporting in case
of read errors & crashed tables:
- Added the table name to the most error messages, including in case of
read errors or when encrypting/decrypting a table. The format for
error messages was changed sligtly to accomodate logging of errors
from lower level routines.
- If we got an read error from storage (hard disk, ssd, S3 etc) we only
reported 'table is crashed'. Now the error number from the storage
is reported.
- Added checking of read failure from records_in_range()
- Calls to ma_set_fatal_error() did not inform the SQL level of
errors (to not spam the user with multiple error messages).
Now the first error message and any fatal error messages are reported
to the user.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/maria/ha_maria.cc | 1 | ||||
-rw-r--r-- | storage/maria/ma_bitmap.c | 5 | ||||
-rw-r--r-- | storage/maria/ma_blockrec.c | 45 | ||||
-rw-r--r-- | storage/maria/ma_cache.c | 2 | ||||
-rw-r--r-- | storage/maria/ma_crypt.c | 5 | ||||
-rw-r--r-- | storage/maria/ma_delete.c | 12 | ||||
-rw-r--r-- | storage/maria/ma_dynrec.c | 20 | ||||
-rw-r--r-- | storage/maria/ma_extra.c | 7 | ||||
-rw-r--r-- | storage/maria/ma_info.c | 83 | ||||
-rw-r--r-- | storage/maria/ma_key.c | 4 | ||||
-rw-r--r-- | storage/maria/ma_key_recover.c | 15 | ||||
-rw-r--r-- | storage/maria/ma_keycache.c | 2 | ||||
-rw-r--r-- | storage/maria/ma_locking.c | 27 | ||||
-rw-r--r-- | storage/maria/ma_open.c | 15 | ||||
-rw-r--r-- | storage/maria/ma_packrec.c | 12 | ||||
-rw-r--r-- | storage/maria/ma_page.c | 9 | ||||
-rw-r--r-- | storage/maria/ma_rkey.c | 2 | ||||
-rw-r--r-- | storage/maria/ma_search.c | 28 | ||||
-rw-r--r-- | storage/maria/ma_statrec.c | 2 | ||||
-rw-r--r-- | storage/maria/ma_update.c | 10 | ||||
-rw-r--r-- | storage/maria/ma_write.c | 15 | ||||
-rw-r--r-- | storage/maria/maria_def.h | 22 |
22 files changed, 209 insertions, 134 deletions
diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index c180365f9e4..1e6680d30de 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1477,6 +1477,7 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) maria_chk_init(param); param->thd= thd; param->op_name= "repair"; + file->error_count=0; /* The following can only be true if the table was marked as STATE_MOVED diff --git a/storage/maria/ma_bitmap.c b/storage/maria/ma_bitmap.c index 49604fa43f6..23135ff00a9 100644 --- a/storage/maria/ma_bitmap.c +++ b/storage/maria/ma_bitmap.c @@ -1082,6 +1082,10 @@ static my_bool _ma_read_bitmap_page(MARIA_HA *info, bitmap->used_size= (uint) ((data + 1) - end); DBUG_ASSERT(bitmap->used_size <= bitmap->total_size); } + else + { + _ma_set_fatal_error(info, my_errno); + } /* We can't check maria_bitmap_marker here as if the bitmap page previously had a true checksum and the user switched mode to not checksum @@ -3204,6 +3208,7 @@ _ma_bitmap_create_missing_into_pagecache(MARIA_SHARE *share, */ return FALSE; err: + _ma_set_fatal_error_with_share(share, my_errno); return TRUE; } diff --git a/storage/maria/ma_blockrec.c b/storage/maria/ma_blockrec.c index 05040d962eb..baa777edcf0 100644 --- a/storage/maria/ma_blockrec.c +++ b/storage/maria/ma_blockrec.c @@ -921,7 +921,7 @@ static my_bool extend_area_on_page(MARIA_HA *info, DBUG_PRINT("error", ("Not enough space: " "length: %u request_length: %u", length, request_length)); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(1); /* Error in block */ } *empty_space= length; /* All space is here */ @@ -1788,7 +1788,10 @@ static my_bool get_head_or_tail_page(MARIA_HA *info, page_link.changed= res->buff != 0; push_dynamic(&info->pinned_pages, (void*) &page_link); if (!page_link.changed) - goto crashed; + { + _ma_set_fatal_error(info, my_errno); + DBUG_RETURN(1); + } DBUG_ASSERT((uint) (res->buff[PAGE_TYPE_OFFSET] & PAGE_TYPE_MASK) == page_type); @@ -1826,7 +1829,7 @@ static my_bool get_head_or_tail_page(MARIA_HA *info, crashed: DBUG_ASSERT(!maria_assert_if_crashed_table); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); /* File crashed */ + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); /* File crashed */ DBUG_RETURN(1); } @@ -1884,7 +1887,10 @@ static my_bool get_rowpos_in_head_or_tail_page(MARIA_HA *info, page_link.changed= buff != 0; push_dynamic(&info->pinned_pages, (void*) &page_link); if (!page_link.changed) /* Read error */ - goto err; + { + _ma_set_fatal_error(info, my_errno); + DBUG_RETURN(1); + } DBUG_ASSERT((buff[PAGE_TYPE_OFFSET] & PAGE_TYPE_MASK) == (uchar) page_type); if ((buff[PAGE_TYPE_OFFSET] & PAGE_TYPE_MASK) != (uchar) page_type) @@ -1921,7 +1927,7 @@ static my_bool get_rowpos_in_head_or_tail_page(MARIA_HA *info, err: DBUG_ASSERT(!maria_assert_if_crashed_table); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); /* File crashed */ + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); /* File crashed */ DBUG_RETURN(1); } @@ -2146,7 +2152,7 @@ static my_bool write_full_pages(MARIA_HA *info, { if (!--sub_blocks) { - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(1); } @@ -3475,7 +3481,7 @@ static my_bool write_block_record(MARIA_HA *info, crashed: DBUG_ASSERT(!maria_assert_if_crashed_table); /* Something was wrong with data on page */ - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); disk_err: /** @@ -3759,7 +3765,10 @@ static my_bool _ma_update_block_record2(MARIA_HA *info, page_link.changed= buff != 0; push_dynamic(&info->pinned_pages, (void*) &page_link); if (!buff) + { + _ma_set_fatal_error(info, my_errno); goto err; + } org_empty_size= uint2korr(buff + EMPTY_SPACE_OFFSET); rownr= ma_recordpos_to_dir_entry(record_pos); @@ -3947,7 +3956,10 @@ static my_bool _ma_update_at_original_place(MARIA_HA *info, page_link.changed= buff != 0; push_dynamic(&info->pinned_pages, (void*) &page_link); if (!buff) + { + _ma_set_fatal_error(info, my_errno); goto err; + } org_empty_size= uint2korr(buff + EMPTY_SPACE_OFFSET); dir= dir_entry_pos(buff, block_size, rownr); @@ -3958,7 +3970,7 @@ static my_bool _ma_update_at_original_place(MARIA_HA *info, ("org_empty_size: %u head_length: %u length_on_page: %u", org_empty_size, (uint) cur_row->head_length, length_on_head_page)); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } @@ -4200,7 +4212,10 @@ static my_bool delete_head_or_tail(MARIA_HA *info, page_link.changed= buff != 0; push_dynamic(&info->pinned_pages, (void*) &page_link); if (!buff) + { + _ma_set_fatal_error(info, my_errno); DBUG_RETURN(1); + } DBUG_ASSERT((buff[PAGE_TYPE_OFFSET] & PAGE_TYPE_MASK) == (head ? HEAD_PAGE : TAIL_PAGE)); @@ -4608,7 +4623,7 @@ static uchar *read_next_extent(MARIA_HA *info, MARIA_EXTENT_CURSOR *extent, crashed: DBUG_ASSERT(!maria_assert_if_crashed_table); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_PRINT("error", ("wrong extent information")); DBUG_RETURN(0); } @@ -4754,7 +4769,7 @@ int _ma_read_block_record2(MARIA_HA *info, uchar *record, { /* File crashed */ DBUG_ASSERT(!maria_assert_if_crashed_table); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(HA_ERR_WRONG_IN_RECORD); } if (!trnman_can_read_from(info->trn, cur_row->trid)) @@ -5042,7 +5057,7 @@ err: DBUG_ASSERT(!maria_assert_if_crashed_table); /* Something was wrong with data on record */ DBUG_PRINT("error", ("Found record with wrong data")); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(HA_ERR_WRONG_IN_RECORD); } @@ -5554,7 +5569,7 @@ restart_bitmap_scan: (uint) (uchar) info->scan.page_buff[DIR_COUNT_OFFSET]) == 0) { DBUG_PRINT("error", ("Wrong page header")); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(HA_ERR_WRONG_IN_RECORD); } DBUG_PRINT("info", ("Page %lu has %u rows", @@ -5601,7 +5616,7 @@ restart_bitmap_scan: err: DBUG_ASSERT(!maria_assert_if_crashed_table); DBUG_PRINT("error", ("Wrong data on page")); - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(HA_ERR_WRONG_IN_RECORD); } @@ -6523,7 +6538,7 @@ uint _ma_apply_redo_insert_row_head_or_tail(MARIA_HA *info, LSN lsn, DBUG_RETURN(result); crashed_file: - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); err: error= my_errno; if (lock_method == PAGECACHE_LOCK_LEFT_WRITELOCKED) @@ -6611,7 +6626,7 @@ uint _ma_apply_redo_purge_row_head_or_tail(MARIA_HA *info, LSN lsn, if (delete_dir_entry(share, buff, rownr, &empty_space) < 0) { - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } diff --git a/storage/maria/ma_cache.c b/storage/maria/ma_cache.c index 6684a1df20b..59cc0ad6ba9 100644 --- a/storage/maria/ma_cache.c +++ b/storage/maria/ma_cache.c @@ -107,7 +107,7 @@ my_bool _ma_read_cache(MARIA_HA *handler, IO_CACHE *info, uchar *buff, if (!my_errno || my_errno == HA_ERR_FILE_TOO_SHORT) { if (!handler->in_check_table) - _ma_set_fatal_error(handler->s, HA_ERR_FILE_TOO_SHORT); + _ma_set_fatal_error(handler, HA_ERR_FILE_TOO_SHORT); if (!my_errno) my_errno= HA_ERR_WRONG_IN_RECORD; } diff --git a/storage/maria/ma_crypt.c b/storage/maria/ma_crypt.c index 9282405bae9..a69ebf3928f 100644 --- a/storage/maria/ma_crypt.c +++ b/storage/maria/ma_crypt.c @@ -470,9 +470,10 @@ static int ma_encrypt(MARIA_SHARE *share, MARIA_CRYPT_DATA *crypt_data, */ my_errno= HA_ERR_DECRYPTION_FAILED; my_printf_error(HA_ERR_DECRYPTION_FAILED, - "Unknown key id %u. Can't continue!", + "Unknown key id %u for %s. Can't continue!", MYF(ME_FATAL|ME_ERROR_LOG), - crypt_data->scheme.key_id); + crypt_data->scheme.key_id, + share->open_file_name.str); return 1; } diff --git a/storage/maria/ma_delete.c b/storage/maria/ma_delete.c index cbba9d975dc..b24cfcc6842 100644 --- a/storage/maria/ma_delete.c +++ b/storage/maria/ma_delete.c @@ -45,10 +45,10 @@ int maria_delete(MARIA_HA *info,const uchar *record) /* Test if record is in datafile */ DBUG_EXECUTE_IF("maria_pretend_crashed_table_on_usage", - maria_print_error(share, HA_ERR_CRASHED); + _ma_print_error(info, HA_ERR_CRASHED, 0); DBUG_RETURN(my_errno= HA_ERR_CRASHED);); DBUG_EXECUTE_IF("my_error_test_undefined_error", - maria_print_error(share, INT_MAX); + _ma_print_error(info, INT_MAX, 0); DBUG_RETURN(my_errno= INT_MAX);); if (!(info->update & HA_STATE_AKTIV)) { @@ -139,7 +139,7 @@ err: info->update|=HA_STATE_WRITTEN; /* Buffer changed */ if (save_errno != HA_ERR_RECORD_CHANGED) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); save_errno= HA_ERR_CRASHED; } DBUG_RETURN(my_errno= save_errno); @@ -215,7 +215,7 @@ my_bool _ma_ck_real_delete(register MARIA_HA *info, MARIA_KEY *key, if ((old_root=*root) == HA_OFFSET_ERROR) { - _ma_set_fatal_error(info->s, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(1); } @@ -354,7 +354,7 @@ static int d_search(MARIA_HA *info, MARIA_KEY *key, uint32 comp_flag, if (!(tmp_key_length=(*keyinfo->get_key)(&tmp_key, page_flag, nod_flag, &kpos))) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); goto err; } root= _ma_row_pos_from_key(&tmp_key); @@ -415,7 +415,7 @@ static int d_search(MARIA_HA *info, MARIA_KEY *key, uint32 comp_flag, { /* This should newer happend */ DBUG_PRINT("error",("Didn't find key")); - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); goto err; } save_flag=0; diff --git a/storage/maria/ma_dynrec.c b/storage/maria/ma_dynrec.c index 7bd85ae5fd1..33f238d9754 100644 --- a/storage/maria/ma_dynrec.c +++ b/storage/maria/ma_dynrec.c @@ -415,7 +415,7 @@ static int _ma_find_writepos(MARIA_HA *info, BLOCK_DELETED)) { DBUG_PRINT("error",("Delete link crashed")); - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error_with_share(info->s, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(-1); } info->s->state.dellink=block_info.next_filepos; @@ -544,7 +544,7 @@ static my_bool update_backward_delete_link(MARIA_HA *info, } else { - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(1); /* Wrong delete link */ } } @@ -577,7 +577,7 @@ static my_bool delete_dynamic_record(MARIA_HA *info, MARIA_RECORD_POS filepos, (length=(uint) (block_info.filepos-filepos) +block_info.block_len) < MARIA_MIN_BLOCK_LENGTH) { - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(1); } /* Check if next block is a delete block */ @@ -863,7 +863,7 @@ static my_bool update_dynamic_record(MARIA_HA *info, MARIA_RECORD_POS filepos, { DBUG_PRINT("error",("Got wrong block info")); if (!(error & BLOCK_FATAL_ERROR)) - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } length=(ulong) (block_info.filepos-filepos) + block_info.block_len; @@ -1381,7 +1381,7 @@ size_t _ma_rec_unpack(register MARIA_HA *info, register uchar *to, uchar *from, DBUG_RETURN(found_length); err: - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_PRINT("error",("to_end: %p -> %p from_end: %p -> %p", to, to_end, from, from_end)); DBUG_DUMP("from", info->rec_buff, info->s->base.min_pack_length); @@ -1580,7 +1580,7 @@ err: DBUG_RETURN(my_errno); panic: - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } @@ -1686,7 +1686,7 @@ my_bool _ma_cmp_dynamic_record(register MARIA_HA *info, } } else if (reclength < block_info.data_len) { - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } reclength-= block_info.data_len; @@ -1925,7 +1925,7 @@ int _ma_read_rnd_dynamic_record(MARIA_HA *info, if (my_errno == HA_ERR_FILE_TOO_SHORT) { /* Unexpected end of file */ - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); } goto err; } @@ -1954,7 +1954,7 @@ int _ma_read_rnd_dynamic_record(MARIA_HA *info, panic: /* Something is fatal wrong */ - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); err: fast_ma_writeinfo(info); DBUG_RETURN(my_errno); @@ -2103,7 +2103,7 @@ err: if (!handler->in_check_table) { /* We may be scanning the table for new rows; Don't give an error */ - _ma_set_fatal_error(handler->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(handler, HA_ERR_WRONG_IN_RECORD); } return BLOCK_ERROR; } diff --git a/storage/maria/ma_extra.c b/storage/maria/ma_extra.c index 94e5e448b09..425cb421e22 100644 --- a/storage/maria/ma_extra.c +++ b/storage/maria/ma_extra.c @@ -174,7 +174,7 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function, if ((error= flush_io_cache(&info->rec_cache))) { /* Fatal error found */ - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); } } break; @@ -441,7 +441,7 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function, { /* Fatal error found */ share->changed= 1; - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); } } mysql_mutex_unlock(&share->intern_lock); @@ -584,6 +584,7 @@ int maria_reset(MARIA_HA *info) info->page_changed= 1; info->update= ((info->update & HA_STATE_CHANGED) | HA_STATE_NEXT_FOUND | HA_STATE_PREV_FOUND); + info->error_count= 0; DBUG_RETURN(error); } @@ -665,7 +666,7 @@ int _ma_flush_table_files(MARIA_HA *info, uint flush_data_or_index, if (!error) DBUG_RETURN(0); - _ma_set_fatal_error(info->s, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(1); } diff --git a/storage/maria/ma_info.c b/storage/maria/ma_info.c index f31113d8384..ddf92654be0 100644 --- a/storage/maria/ma_info.c +++ b/storage/maria/ma_info.c @@ -111,12 +111,13 @@ int maria_status(MARIA_HA *info, register MARIA_INFO *x, uint flag) /* - Write a message to the error log. + Write a message to the user or the error log. SYNOPSIS _ma_report_error() file_name Name of table file (e.g. index_file_name). errcode Error number. + flags Flags to my_error DESCRIPTION This function supplies my_error() with a table name. Most error @@ -129,12 +130,12 @@ int maria_status(MARIA_HA *info, register MARIA_INFO *x, uint flag) void */ -void _ma_report_error(int errcode, const LEX_STRING *name) +void _ma_report_error(int errcode, const LEX_STRING *name, myf flags) { size_t length; const char *file_name= name->str; DBUG_ENTER("_ma_report_error"); - DBUG_PRINT("enter",("errcode %d, table '%s'", errcode, file_name)); + DBUG_PRINT("enter",("error: %d table: '%s'", errcode, file_name)); if ((length= name->length) > 64) { @@ -147,7 +148,81 @@ void _ma_report_error(int errcode, const LEX_STRING *name) file_name+= length - 64; } } + my_printf_error(errcode, "Got error '%M' for '%s'", + flags, (int) errcode, file_name); + DBUG_VOID_RETURN; +} + + +/** + If standalone report all errors to the user + If run trough the Aria handler, only report first error to the user + to not spam him - my_error(errcode, MYF(ME_ERROR_LOG), file_name); + @param info Aria Handler + @param error Error code + @apram write_to_log If set to 1, print the error to the log. This is only set + when a table was found to be crashed the first time +*/ + +void _ma_print_error(MARIA_HA *info, int error, my_bool write_to_log) +{ + DBUG_ENTER("_ma_print_error"); + DBUG_PRINT("error", ("error: %d log: %d", error, write_to_log)); + if (!info->error_count++ || !maria_in_ha_maria || write_to_log) + { + MARIA_SHARE *share= info->s; + _ma_report_error(error, + (share->index_file_name.length ? + &share->index_file_name : + &share->unique_file_name), + MYF(write_to_log ? ME_ERROR_LOG : 0)); + } DBUG_VOID_RETURN; } + + +/* + Handle a fatal error + + - Mark the table as crashed + - Print an error message, if we had not issued an error message before + that the table had been crashed. + - set my_errno to error + - If 'maria_assert_if_crashed_table is set, then assert. +*/ + +void _ma_set_fatal_error(MARIA_HA *info, int error) +{ + MARIA_SHARE *share= info->s; + _ma_print_error(info, error, + (share->state.changed & STATE_CRASHED_PRINTED) == 0); + maria_mark_crashed_share(share); + share->state.changed|= STATE_CRASHED_PRINTED; + my_errno= error; + DBUG_ASSERT(!maria_assert_if_crashed_table); +} + + +/* + Similar to the above, but only used from maria_open() where we don't have + an active handler object. Here we don't set a fatal error as we may + still want to do an automatic repair on the table +*/ + +void _ma_set_fatal_error_with_share(MARIA_SHARE *share, int error) +{ + DBUG_PRINT("error", ("error: %d", error)); + + if (!(share->state.changed & STATE_CRASHED_PRINTED)) + { + _ma_report_error(error, + (share->index_file_name.length ? + &share->index_file_name : + &share->unique_file_name), + MYF(ME_WARNING | ME_ERROR_LOG)); + } + maria_mark_crashed_share(share); + share->state.changed|= STATE_CRASHED_PRINTED; + DBUG_ASSERT(!maria_assert_if_crashed_table); +} diff --git a/storage/maria/ma_key.c b/storage/maria/ma_key.c index 51a042b381e..d47e8cf715a 100644 --- a/storage/maria/ma_key.c +++ b/storage/maria/ma_key.c @@ -644,7 +644,7 @@ int _ma_read_key_record(MARIA_HA *info, uchar *buf, MARIA_RECORD_POS filepos) { /* Read only key */ if (_ma_put_key_in_record(info, (uint)info->lastinx, TRUE, buf)) { - _ma_set_fatal_error(info->s, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); return -1; } info->update|= HA_STATE_AKTIV; /* We should find a record */ @@ -687,7 +687,7 @@ check_result_t ma_check_index_cond(register MARIA_HA *info, uint keynr, if (_ma_put_key_in_record(info, keynr, FALSE, record)) { /* Impossible case; Can only happen if bug in code */ - maria_print_error(info->s, HA_ERR_CRASHED); + _ma_print_error(info, HA_ERR_CRASHED, 0); info->cur_row.lastpos= HA_OFFSET_ERROR; /* No active record */ my_errno= HA_ERR_CRASHED; res= CHECK_ERROR; diff --git a/storage/maria/ma_key_recover.c b/storage/maria/ma_key_recover.c index 2f28ec8d175..acec592b922 100644 --- a/storage/maria/ma_key_recover.c +++ b/storage/maria/ma_key_recover.c @@ -771,6 +771,7 @@ uint _ma_apply_redo_index_new_page(MARIA_HA *info, LSN lsn, my_errno != HA_ERR_DECRYPTION_FAILED) { result= 1; + _ma_set_fatal_error(info, my_errno); goto err; } buff= pagecache_block_link_to_buffer(page_link.link); @@ -861,6 +862,7 @@ uint _ma_apply_redo_index_free_page(MARIA_HA *info, &page_link.link))) { result= (uint) my_errno; + _ma_set_fatal_error(info, my_errno); goto err; } if (lsn_korr(buff) >= lsn) @@ -949,7 +951,7 @@ uint _ma_apply_redo_index(MARIA_HA *info, #ifdef DBUG_ASSERT_EXISTS uint new_page_length= 0; #endif - int result; + int result, mark_crashed; MARIA_PAGE page; DBUG_ENTER("_ma_apply_redo_index"); DBUG_PRINT("enter", ("page: %lu", (ulong) page_pos)); @@ -962,14 +964,15 @@ uint _ma_apply_redo_index(MARIA_HA *info, PAGECACHE_PLAIN_PAGE, PAGECACHE_LOCK_WRITE, &page_link.link))) { - result= 1; + result= 1; mark_crashed= 0; + _ma_set_fatal_error(info, my_errno); goto err; } if (lsn_korr(buff) >= lsn) { /* Already applied */ check_skipped_lsn(info, lsn_korr(buff), 0, page_pos); - result= 0; + result= mark_crashed= 0; goto err; } @@ -1165,7 +1168,7 @@ uint _ma_apply_redo_index(MARIA_HA *info, header+= TRANSID_SIZE; if (_ma_compact_keypage(&page, transid)) { - result= 1; + result= mark_crashed= 1; goto err; } page_length= page.size; @@ -1174,7 +1177,7 @@ uint _ma_apply_redo_index(MARIA_HA *info, case KEY_OP_NONE: default: DBUG_ASSERT(0); - result= 1; + result= mark_crashed= 1; goto err; } } while (header < header_end); @@ -1203,7 +1206,7 @@ err: PAGECACHE_LOCK_WRITE_UNLOCK, PAGECACHE_UNPIN, LSN_IMPOSSIBLE, LSN_IMPOSSIBLE, 0, FALSE); - if (result) + if (mark_crashed) _ma_mark_file_crashed(share); DBUG_RETURN(result); } diff --git a/storage/maria/ma_keycache.c b/storage/maria/ma_keycache.c index ba6da707240..2ff8d019d1c 100644 --- a/storage/maria/ma_keycache.c +++ b/storage/maria/ma_keycache.c @@ -80,7 +80,7 @@ int maria_assign_to_pagecache(MARIA_HA *info, { error= my_errno; /* Mark that table must be checked */ - _ma_set_fatal_error(share, error); + _ma_set_fatal_error(info, error); } /* diff --git a/storage/maria/ma_locking.c b/storage/maria/ma_locking.c index e53c3759f13..b14a8ddfdcd 100644 --- a/storage/maria/ma_locking.c +++ b/storage/maria/ma_locking.c @@ -82,7 +82,7 @@ int maria_lock_database(MARIA_HA *info, int lock_type) if (end_io_cache(&info->rec_cache)) { error= my_errno; - _ma_set_fatal_error(share, error); + _ma_set_fatal_error(info, error); } } if (!count) @@ -129,7 +129,7 @@ int maria_lock_database(MARIA_HA *info, int lock_type) else share->not_flushed=1; if (error) - _ma_set_fatal_error(share, error); + _ma_set_fatal_error(info, error); } } info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED); @@ -572,29 +572,6 @@ void _ma_mark_file_crashed(MARIA_SHARE *share) DBUG_VOID_RETURN; } -/* - Handle a fatal error - - - Mark the table as crashed - - Print an error message, if we had not issued an error message before - that the table had been crashed. - - set my_errno to error - - If 'maria_assert_if_crashed_table is set, then assert. -*/ - -void _ma_set_fatal_error(MARIA_SHARE *share, int error) -{ - DBUG_PRINT("error", ("error: %d", error)); - maria_mark_crashed_share(share); - if (!(share->state.changed & STATE_CRASHED_PRINTED)) - { - share->state.changed|= STATE_CRASHED_PRINTED; - maria_print_error(share, error); - } - my_errno= error; - DBUG_ASSERT(!maria_assert_if_crashed_table); -} - /** @brief Set uuid of for a Maria file diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 09f156722cf..d642f1a7194 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -44,7 +44,7 @@ static uchar *_ma_state_info_read(uchar *, MARIA_STATE_INFO *, myf); #define disk_pos_assert(share, pos, end_pos) \ if (pos > end_pos) \ { \ - _ma_set_fatal_error(share, HA_ERR_CRASHED); \ + _ma_set_fatal_error_with_share(share, HA_ERR_CRASHED); \ goto err; \ } @@ -232,7 +232,8 @@ err: if ((save_errno == HA_ERR_CRASHED) || (save_errno == HA_ERR_CRASHED_ON_USAGE) || (save_errno == HA_ERR_CRASHED_ON_REPAIR)) - _ma_report_error(save_errno, &share->open_file_name); + _ma_report_error(save_errno, &share->open_file_name, + MYF(ME_ERROR_LOG)); switch (errpos) { case 6: (*share->end)(&info); @@ -475,7 +476,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags, { if (mysql_file_pread(kfile, disk_cache, info_length, 0L, MYF(MY_NABP))) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(share, HA_ERR_CRASHED); goto err; } } @@ -583,7 +584,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags, /* sanity check */ if (share->base.keystart > 65535 || share->base.rec_reflength > 8) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(share, HA_ERR_CRASHED); goto err; } @@ -784,7 +785,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags, pos[0].language= pos[-1].language; if (!(pos[0].charset= pos[-1].charset)) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(share, HA_ERR_CRASHED); goto err; } pos++; @@ -1192,7 +1193,7 @@ err: LEX_STRING tmp_name; tmp_name.str= (char*) name; tmp_name.length= strlen(name); - _ma_report_error(save_errno, &tmp_name); + _ma_report_error(save_errno, &tmp_name, MYF(ME_ERROR_LOG)); } switch (errpos) { case 7: @@ -2126,7 +2127,7 @@ int maria_enable_indexes(MARIA_HA *info) DBUG_PRINT("error", ("data_file_length: %lu key_file_length: %lu", (ulong) share->state.state.data_file_length, (ulong) share->state.state.key_file_length)); - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); error= HA_ERR_CRASHED; } else diff --git a/storage/maria/ma_packrec.c b/storage/maria/ma_packrec.c index d7f86a9a7ae..19783423ab5 100644 --- a/storage/maria/ma_packrec.c +++ b/storage/maria/ma_packrec.c @@ -194,7 +194,7 @@ static my_bool _ma_read_pack_info(MARIA_SHARE *share, File file, /* Only the first three bytes of magic number are independent of version. */ if (memcmp(header, maria_pack_file_magic, 3)) { - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error_with_share(share, HA_ERR_WRONG_IN_RECORD); goto err0; } share->pack.version= header[3]; /* fourth uchar of magic number */ @@ -331,7 +331,7 @@ static my_bool _ma_read_pack_info(MARIA_SHARE *share, File file, DBUG_RETURN(0); err3: - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error_with_share(share, HA_ERR_WRONG_IN_RECORD); err2: my_free(share->decode_tables); err1: @@ -762,7 +762,7 @@ int _ma_read_pack_record(MARIA_HA *info, uchar *buf, MARIA_RECORD_POS filepos) DBUG_RETURN(_ma_pack_rec_unpack(info,&info->bit_buff, buf, info->rec_buff, block_info.rec_len)); panic: - _ma_set_fatal_error(info->s, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); err: DBUG_RETURN(my_errno); } @@ -797,7 +797,7 @@ int _ma_pack_rec_unpack(register MARIA_HA *info, MARIA_BIT_BUFF *bit_buff, bit_buff->pos - bit_buff->bits / 8 == bit_buff->end) DBUG_RETURN(0); info->update&= ~HA_STATE_AKTIV; - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(HA_ERR_WRONG_IN_RECORD); } /* _ma_pack_rec_unpack */ @@ -1375,7 +1375,7 @@ int _ma_read_rnd_pack_record(MARIA_HA *info, #ifndef DBUG_OFF if (block_info.rec_len > share->max_pack_length) { - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } #endif @@ -1655,7 +1655,7 @@ static int _ma_read_rnd_mempack_record(MARIA_HA *info, #ifndef DBUG_OFF if (block_info.rec_len > info->s->max_pack_length) { - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); goto err; } #endif diff --git a/storage/maria/ma_page.c b/storage/maria/ma_page.c index 13f5b7d698b..25db0e8acec 100644 --- a/storage/maria/ma_page.c +++ b/storage/maria/ma_page.c @@ -128,7 +128,7 @@ my_bool _ma_fetch_keypage(MARIA_PAGE *page, MARIA_HA *info, { DBUG_PRINT("error",("Got errno: %d from pagecache_read",my_errno)); info->last_keypage=HA_OFFSET_ERROR; - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, my_errno); DBUG_RETURN(1); } info->last_keypage= pos; @@ -160,7 +160,7 @@ my_bool _ma_fetch_keypage(MARIA_PAGE *page, MARIA_HA *info, _ma_get_keynr(share, tmp))); DBUG_DUMP("page", tmp, page_size); info->last_keypage = HA_OFFSET_ERROR; - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(1); } } @@ -433,7 +433,10 @@ my_off_t _ma_new(register MARIA_HA *info, int level, (pgcache_page_no_t) (pos / block_size), level, 0, share->page_type, PAGECACHE_LOCK_WRITE, &(*page_link)->link))) + { pos= HA_OFFSET_ERROR; + _ma_set_fatal_error(info, my_errno); + } else { /* @@ -566,7 +569,7 @@ my_bool _ma_compact_keypage(MARIA_PAGE *ma_page, TrID min_read_from) { DBUG_PRINT("error",("Couldn't find last key: page_pos: %p", page)); - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(1); } if (key_has_transid(page-1)) diff --git a/storage/maria/ma_rkey.c b/storage/maria/ma_rkey.c index b48b0fc0c6b..8cd82e1c6fc 100644 --- a/storage/maria/ma_rkey.c +++ b/storage/maria/ma_rkey.c @@ -94,7 +94,7 @@ int maria_rkey(MARIA_HA *info, uchar *buf, int inx, const uchar *key_data, case HA_KEY_ALG_RTREE: if (maria_rtree_find_first(info, &key, nextflag) < 0) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); info->cur_row.lastpos= HA_OFFSET_ERROR; } break; diff --git a/storage/maria/ma_search.c b/storage/maria/ma_search.c index a57db7d2a2d..63c11632969 100644 --- a/storage/maria/ma_search.c +++ b/storage/maria/ma_search.c @@ -50,6 +50,12 @@ int _ma_check_index(MARIA_HA *info, int inx) my_errno= HA_ERR_INTERNAL_ERROR; /* Impossible */ return(-1); } + if (unlikely(maria_is_crashed(info))) + { + my_errno= HA_ERR_CRASHED; + return(-1); + } + return(inx); } /* _ma_check_index */ @@ -155,7 +161,7 @@ static int _ma_search_no_save(register MARIA_HA *info, MARIA_KEY *key, &last_key_not_used); if (flag == MARIA_FOUND_WRONG_KEY) { - maria_print_error(info->s, HA_ERR_CRASHED); + _ma_print_error(info, HA_ERR_CRASHED, 0); my_errno= HA_ERR_CRASHED; goto err; } @@ -389,7 +395,7 @@ int _ma_seq_search(const MARIA_KEY *key, const MARIA_PAGE *ma_page, length=(*keyinfo->get_key)(&tmp_key, page_flag, nod_flag, &page); if (length == 0 || page > end) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(share, HA_ERR_CRASHED); DBUG_PRINT("error", ("Found wrong key: length: %u page: %p end: %p", length, page, end)); @@ -564,7 +570,7 @@ int _ma_prefix_search(const MARIA_KEY *key, const MARIA_PAGE *ma_page, if (page > end) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(share, HA_ERR_CRASHED); DBUG_PRINT("error", ("Found wrong key: length: %u page: %p end: %p", length, page, end)); @@ -1046,7 +1052,7 @@ uint _ma_get_pack_key(MARIA_KEY *int_key, uint page_flag, { if (length > (uint) keyseg->length) { - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); return 0; /* Error */ } if (length == 0) /* Same key */ @@ -1061,7 +1067,7 @@ uint _ma_get_pack_key(MARIA_KEY *int_key, uint page_flag, ("Found too long null packed key: %u of %u at %p", length, keyseg->length, *page_pos)); DBUG_DUMP("key", *page_pos, 16); - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); return 0; } continue; @@ -1118,7 +1124,7 @@ uint _ma_get_pack_key(MARIA_KEY *int_key, uint page_flag, DBUG_PRINT("error",("Found too long packed key: %u of %u at %p", length, keyseg->length, *page_pos)); DBUG_DUMP("key", *page_pos, 16); - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); return 0; /* Error */ } store_key_length_inc(key,length); @@ -1277,7 +1283,7 @@ uint _ma_get_binary_pack_key(MARIA_KEY *int_key, uint page_flag, uint nod_flag, ("Found too long binary packed key: %u of %u at %p", length, keyinfo->maxlength, *page_pos)); DBUG_DUMP("key", *page_pos, 16); - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); DBUG_RETURN(0); /* Wrong key */ } /* Key is packed against prev key, take prefix from prev key. */ @@ -1368,7 +1374,7 @@ uint _ma_get_binary_pack_key(MARIA_KEY *int_key, uint page_flag, uint nod_flag, if (from_end != page_end) { DBUG_PRINT("error",("Error when unpacking key")); - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); DBUG_RETURN(0); /* Error */ } } @@ -1458,7 +1464,7 @@ uchar *_ma_get_key(MARIA_KEY *key, MARIA_PAGE *ma_page, uchar *keypos) { if (!(*keyinfo->get_key)(key, page_flag, nod_flag, &page)) { - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); DBUG_RETURN(0); } } @@ -1508,7 +1514,7 @@ static my_bool _ma_get_prev_key(MARIA_KEY *key, MARIA_PAGE *ma_page, { if (! (*keyinfo->get_key)(key, page_flag, nod_flag, &page)) { - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); DBUG_RETURN(1); } } @@ -1561,7 +1567,7 @@ uchar *_ma_get_last_key(MARIA_KEY *key, MARIA_PAGE *ma_page, uchar *endpos) { DBUG_PRINT("error",("Couldn't find last key: page: %p", page)); - _ma_set_fatal_error(keyinfo->share, HA_ERR_CRASHED); + _ma_set_fatal_error_with_share(keyinfo->share, HA_ERR_CRASHED); DBUG_RETURN(0); } } diff --git a/storage/maria/ma_statrec.c b/storage/maria/ma_statrec.c index 98fa235a2cc..d8a8b0a05d7 100644 --- a/storage/maria/ma_statrec.c +++ b/storage/maria/ma_statrec.c @@ -294,6 +294,6 @@ int _ma_read_rnd_static_record(MARIA_HA *info, uchar *buf, } /* my_errno should be set if rec_cache.error == -1 */ if (info->rec_cache.error != -1 || my_errno == 0) - _ma_set_fatal_error(share, HA_ERR_WRONG_IN_RECORD); + _ma_set_fatal_error(info, HA_ERR_WRONG_IN_RECORD); DBUG_RETURN(my_errno); /* Something wrong (EOF?) */ } diff --git a/storage/maria/ma_update.c b/storage/maria/ma_update.c index cb1a1e48ad2..60ab4452384 100644 --- a/storage/maria/ma_update.c +++ b/storage/maria/ma_update.c @@ -35,7 +35,7 @@ int maria_update(register MARIA_HA *info, const uchar *oldrec, DBUG_ENTER("maria_update"); DBUG_EXECUTE_IF("maria_pretend_crashed_table_on_usage", - maria_print_error(info->s, HA_ERR_CRASHED); + _ma_print_error(info, HA_ERR_CRASHED, 0); DBUG_RETURN(my_errno= HA_ERR_CRASHED);); if (!(info->update & HA_STATE_AKTIV)) { @@ -217,7 +217,7 @@ err: if ((flag++ && _ma_ft_del(info,i,new_key_buff,newrec,pos)) || _ma_ft_add(info,i,old_key_buff,oldrec,pos)) { - _ma_set_fatal_error(share, my_errno); + _ma_set_fatal_error(info, my_errno); break; } } @@ -232,7 +232,7 @@ err: if ((flag++ && _ma_ck_delete(info, &new_key)) || _ma_ck_write(info, &old_key)) { - _ma_set_fatal_error(share, my_errno); + _ma_set_fatal_error(info, my_errno); break; } } @@ -240,7 +240,7 @@ err: } while (i-- != 0); } else - _ma_set_fatal_error(share, save_errno); + _ma_set_fatal_error(info, save_errno); info->update= (HA_STATE_CHANGED | HA_STATE_AKTIV | HA_STATE_ROW_CHANGED | key_changed); @@ -248,6 +248,6 @@ err: err_end: _ma_writeinfo(info, WRITEINFO_UPDATE_KEYFILE); if (save_errno == HA_ERR_KEY_NOT_FOUND) - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(my_errno=save_errno); } /* maria_update */ diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c index 392f0bf6d0e..1dbee5d744a 100644 --- a/storage/maria/ma_write.c +++ b/storage/maria/ma_write.c @@ -98,7 +98,7 @@ int maria_write(MARIA_HA *info, const uchar *record) share->kfile.file, info->dfile.file)); DBUG_EXECUTE_IF("maria_pretend_crashed_table_on_usage", - maria_print_error(info->s, HA_ERR_CRASHED); + _ma_print_error(info, HA_ERR_CRASHED, 0); DBUG_RETURN(my_errno= HA_ERR_CRASHED);); if (share->options & HA_OPTION_READ_ONLY_DATA) { @@ -403,10 +403,7 @@ err: } if (fatal_error) - { - maria_print_error(info->s, HA_ERR_CRASHED); - maria_mark_crashed(info); - } + _ma_set_fatal_error(info, HA_ERR_CRASHED); info->update= (HA_STATE_CHANGED | HA_STATE_WRITTEN | HA_STATE_ROW_CHANGED); my_errno=save_errno; @@ -835,7 +832,7 @@ int _ma_insert(register MARIA_HA *info, MARIA_KEY *key, { if (t_length >= keyinfo->maxlength*2+MARIA_INDEX_OVERHEAD_SIZE) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(-1); } bmove_upp(endpos+t_length, endpos, (uint) (endpos-key_pos)); @@ -844,7 +841,7 @@ int _ma_insert(register MARIA_HA *info, MARIA_KEY *key, { if (-t_length >= keyinfo->maxlength*2+MARIA_INDEX_OVERHEAD_SIZE) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(-1); } bmove(key_pos,key_pos-t_length,(uint) (endpos-key_pos)+t_length); @@ -1206,7 +1203,7 @@ static uchar *_ma_find_last_pos(MARIA_KEY *int_key, MARIA_PAGE *ma_page, if (!(length=(*keyinfo->get_key)(&tmp_key, page_flag, 0, &page))) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(0); } @@ -1219,7 +1216,7 @@ static uchar *_ma_find_last_pos(MARIA_KEY *int_key, MARIA_PAGE *ma_page, memcpy(int_key->data, key_buff, length); /* previous key */ if (!(length=(*keyinfo->get_key)(&tmp_key, page_flag, 0, &page))) { - _ma_set_fatal_error(share, HA_ERR_CRASHED); + _ma_set_fatal_error(info, HA_ERR_CRASHED); DBUG_RETURN(0); } } while (page < end); diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index 722ab150160..c7aef97072b 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -976,6 +976,7 @@ struct st_maria_handler uint opt_flag; /* Optim. for space/speed */ uint open_flags; /* Flags used in open() */ uint update; /* If file changed since open */ + uint error_count; /* Incremented for each error given */ int lastinx; /* Last used index */ uint last_rkey_length; /* Last length in maria_rkey() */ uint *last_rtree_keypos; /* Last key positions for rtrees */ @@ -1141,20 +1142,6 @@ struct ha_table_option_struct #define maria_is_crashed_on_repair(x) ((x)->s->state.changed & STATE_CRASHED_ON_REPAIR) #define maria_in_repair(x) ((x)->s->state.changed & STATE_IN_REPAIR) -#ifdef EXTRA_DEBUG -/** - Brings additional information in certain debug builds and in standalone - (non-ha_maria) programs. To help debugging. Not in ha_maria, to not spam the - user (some messages can be produced many times per statement, or even - wrongly during some repair operations). -*/ -#define maria_print_error(SHARE, ERRNO) \ - do{ if (!maria_in_ha_maria) \ - _ma_report_error((ERRNO), &(SHARE)->index_file_name); } \ - while(0) -#else -#define maria_print_error(SHARE, ERRNO) while (0) -#endif #define DBUG_DUMP_KEY(name, key) DBUG_DUMP(name, (key)->data, (key)->data_length + (key)->ref_length) /* Functions to store length of space packed keys, VARCHAR or BLOB keys */ @@ -1413,7 +1400,8 @@ extern int _ma_test_if_changed(MARIA_HA *info); extern int _ma_mark_file_changed(MARIA_SHARE *info); extern int _ma_mark_file_changed_now(MARIA_SHARE *info); extern void _ma_mark_file_crashed(MARIA_SHARE *share); -void _ma_set_fatal_error(MARIA_SHARE *share, int error); +extern void _ma_set_fatal_error(MARIA_HA *share, int error); +extern void _ma_set_fatal_error_with_share(MARIA_SHARE *share, int error); extern my_bool _ma_set_uuid(MARIA_SHARE *info, my_bool reset_uuid); extern my_bool _ma_check_if_zero(uchar *pos, size_t size); extern int _ma_decrement_open_count(MARIA_HA *info, my_bool lock_table); @@ -1600,7 +1588,9 @@ extern uint _ma_pack_get_block_info(MARIA_HA *maria, MARIA_BIT_BUFF *bit_buff, size_t *rec_buff_size, File file, my_off_t filepos); extern void _ma_store_blob_length(uchar *pos, uint pack_length, uint length); -extern void _ma_report_error(int errcode, const LEX_STRING *file_name); +extern void _ma_report_error(int errcode, const LEX_STRING *file_name, + myf flags); +extern void _ma_print_error(MARIA_HA *info, int error, my_bool write_to_log); extern my_bool _ma_memmap_file(MARIA_HA *info); extern void _ma_unmap_file(MARIA_HA *info); extern uint _ma_save_pack_length(uint version, uchar * block_buff, |