Commit 3d241eb9 authored by Monty's avatar Monty Committed by Sergei Petrunia

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.
parent 1de18a83
......@@ -3,7 +3,7 @@ call mtr.add_suppression("mysql.user");
flush tables;
flush privileges;
Warnings:
Error 145 Table './mysql/user' is marked as crashed and should be repaired
Error 145 Got error '145 "Table was marked as crashed and should be repaired"' for './mysql/user'
Warning 1034 12544 clients are using or haven't closed the table properly
Note 1034 Table is fixed
# switching back from mysql.user to mysql.global_priv
call mtr.add_suppression('Unknown key id 1. Can''t continue');
call mtr.add_suppression('Unknown key id 1');
call mtr.add_suppression('try to repair it');
call mtr.add_suppression('Index is corrupted');
set global aria_encrypt_tables= 1;
create table t1 (pk int primary key, a int, key(a)) engine=aria transactional=1;
alter table t1 disable keys;
insert into t1 values (1,1);
alter table t1 enable keys;
ERROR HY000: Unknown key id 1. Can't continue!
ERROR HY000: Unknown key id 1 for ./test/t1. Can't continue!
repair table t1 use_frm;
Table Op Msg_type Msg_text
test.t1 repair warning Number of rows changed from 0 to 1
test.t1 repair Error Unknown key id 1. Can't continue!
test.t1 repair Error Unknown key id 1. Can't continue!
test.t1 repair Error Unknown key id 1 for ./test/t1. Can't continue!
test.t1 repair Error Unknown key id 1 for ./test/t1. Can't continue!
test.t1 repair status OK
drop table t1;
set global aria_encrypt_tables= default;
#
# MDEV-18496 Crash when Aria encryption is enabled but plugin not available
#
call mtr.add_suppression('Unknown key id 1. Can''t continue');
call mtr.add_suppression('Unknown key id 1');
call mtr.add_suppression('try to repair it');
call mtr.add_suppression('Index is corrupted');
set global aria_encrypt_tables= 1;
create table t1 (pk int primary key, a int, key(a)) engine=aria transactional=1;
alter table t1 disable keys;
insert into t1 values (1,1);
error 192;
--replace_result \\ /
--error 192
alter table t1 enable keys;
--replace_result \\ /
repair table t1 use_frm;
drop table t1;
set global aria_encrypt_tables= default;
......@@ -26,9 +26,10 @@ a
ThursdayMorningsMarket
ThursdayMorningsMarketb
Warnings:
Error 145 t_corrupted2' is marked as crashed and should be repaired
Error 145 Got error '145 "Table was marked as crashed and should be repaired"' for './mysqltest/t_corrupted2'
Warning 1034 1 client is using or hasn't closed the table properly
Error 1034 Wrong base information on indexpage at page: 1
Error 176 Got error '176 "Read page with wrong checksum"' for './mysqltest/t_corrupted2.MAI'
Error 1034 Can't read indexpage from page: 1, error: 176
select * from t_corrupted2;
a
ThursdayMorningsMarket
......
......@@ -20,8 +20,8 @@ select count(*) from mysql.proc;
# account for Unix and Windows variation.
call mtr.add_suppression("Checking table: '\\..mysqltest.t_corrupted2'");
call mtr.add_suppression("Recovering table: '\\..mysqltest.t_corrupted2'");
call mtr.add_suppression("Table '\\..mysqltest.t_corrupted2' is marked as crashed and should be repaired");
call mtr.add_suppression("Table 't_corrupted2' is marked as crashed and should be repaired");
call mtr.add_suppression("Table was marked as crashed and should be repaired");
call mtr.add_suppression("Read page with wrong checksum");
let $def_checkinterval=`select @@global.aria_checkpoint_interval`;
......@@ -78,7 +78,7 @@ perl;
syswrite (FILE, $whatever) or die;
close FILE;
EOF
replace_regex /Table.*t_corrupted2/t_corrupted2/ ;
--replace_result \\ /
--enable_prepare_warnings
select * from t_corrupted2; # should show corruption and repair messages
--disable_prepare_warnings
......
call mtr.add_suppression("Table '.*' is marked as crashed and should be repaired");
call mtr.add_suppression("Table was marked as crashed");
call mtr.add_suppression("Checking table: .*");
create table t1 (a int primary key auto_increment, b int) engine=aria transactional= 1;
create table t2 (a int primary key auto_increment, b int) engine=aria transactional= 0;
......@@ -54,7 +54,7 @@ a b
10 11
11 12
Warnings:
Error 145 Table './test/t2' is marked as crashed and should be repaired
Error 145 Got error '145 "Table was marked as crashed and should be repaired"' for './test/t2'
Warning 1034 1 client is using or hasn't closed the table properly
Note 1034 Table is fixed
insert into t1 (b) values (100),(200);
......@@ -92,7 +92,7 @@ NEXT VALUE for s1 seq
11 3
12 4
Warnings:
Error 145 Table './test/s1' is marked as crashed and should be repaired
Error 145 Got error '145 "Table was marked as crashed and should be repaired"' for './test/s1'
Warning 1034 1 client is using or hasn't closed the table properly
Note 1034 Table is fixed
drop table t1,t2;
......@@ -100,7 +100,7 @@ drop sequence s1;
include/show_binlog_events.inc
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'Table \'.*\' is marked as crashed and should be repaired' COLLATE 'latin1_swedish_ci'))
master-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'Table was marked as crashed' COLLATE 'latin1_swedish_ci'))
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `mtr`; INSERT INTO test_suppressions (pattern) VALUES ( NAME_CONST('pattern',_latin1'Checking table: .*' COLLATE 'latin1_swedish_ci'))
......
......@@ -3,7 +3,7 @@
# no-protocol doesn't print warnings about repaired tables
--source include/no_protocol.inc
call mtr.add_suppression("Table '.*' is marked as crashed and should be repaired");
call mtr.add_suppression("Table was marked as crashed");
call mtr.add_suppression("Checking table: .*");
#
......
......@@ -179,6 +179,8 @@ handler::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
{
/* Can't scan one range => can't do MRR scan at all */
total_rows= HA_POS_ERROR;
if (thd->is_error())
DBUG_RETURN(HA_POS_ERROR);
break;
}
if (pages.first_page == UNUSED_PAGE_NO)
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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 @@ int _ma_read_block_record2(MARIA_HA *info, uchar *record,
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 @@ int _ma_scan_block_record(MARIA_HA *info, uchar *record,
(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 @@ int _ma_scan_block_record(MARIA_HA *info, uchar *record,
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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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 @@ int maria_delete(MARIA_HA *info,const uchar *record)
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;
......
......@@ -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 @@ int _ma_read_dynamic_record(MARIA_HA *info, uchar *buf,
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 @@ uint _ma_get_block_info(MARIA_HA *handler, MARIA_BLOCK_INFO *info, File file,
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;
}
......@@ -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);
}
......
......@@ -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);
}
......@@ -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;
......
......@@ -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 @@ uint _ma_apply_redo_index(MARIA_HA *info,
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);
}
......
......@@ -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);
}
/*
......
......@@ -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
......
......@@ -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 @@ static MARIA_HA *maria_clone_internal(MARIA_SHARE *share,
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 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags,
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
......
......@@ -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
......
......@@ -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))
......
......@@ -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;
......
......@@ -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);
}
}
......
......@@ -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?) */
}
......@@ -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 @@ int maria_update(register MARIA_HA *info, const uchar *oldrec,
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 @@ int maria_update(register MARIA_HA *info, const uchar *oldrec,
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 @@ int maria_update(register MARIA_HA *info, const uchar *oldrec,
} 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 @@ int maria_update(register MARIA_HA *info, const uchar *oldrec,
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 */
......@@ -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 @@ int maria_write(MARIA_HA *info, const uchar *record)
}
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);
......
......@@ -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,
......
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