diff options
author | monty@donna.mysql.com <> | 2000-10-23 15:35:42 +0300 |
---|---|---|
committer | monty@donna.mysql.com <> | 2000-10-23 15:35:42 +0300 |
commit | 8dabd3b053f11f5f03744019a888b860d725a565 (patch) | |
tree | 20b25b09438bf3aad77ad7810faab9651daf310f /sql | |
parent | e0b30726001e3fe43e6f34194eed1c8fc3979718 (diff) | |
download | mariadb-git-8dabd3b053f11f5f03744019a888b860d725a565.tar.gz |
Fix of automatic repair
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_myisam.cc | 55 | ||||
-rw-r--r-- | sql/handler.cc | 1 | ||||
-rw-r--r-- | sql/mysqlbinlog.cc | 4 | ||||
-rw-r--r-- | sql/sql_insert.cc | 6 | ||||
-rw-r--r-- | sql/sql_parse.cc | 1 | ||||
-rw-r--r-- | sql/sql_select.cc | 22 |
6 files changed, 53 insertions, 36 deletions
diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 639c2dc04a6..7b1d274922d 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -368,14 +368,14 @@ int ha_myisam::restore(THD* thd, HA_CHECK_OPT *check_opt) err: { - MI_CHECK param; - myisamchk_init(¶m); - param.thd = thd; - param.op_name = (char*)"restore"; - param.table_name = table->table_name; - param.testflag = 0; - mi_check_print_error(¶m,errmsg, errno ); - return error; + MI_CHECK param; + myisamchk_init(¶m); + param.thd = thd; + param.op_name = (char*)"restore"; + param.table_name = table->table_name; + param.testflag = 0; + mi_check_print_error(¶m,errmsg, errno ); + return error; } } @@ -409,10 +409,11 @@ int ha_myisam::backup(THD* thd, HA_CHECK_OPT *check_opt) int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) { int error; - if (!file) return HA_ADMIN_INTERNAL_ERROR; MI_CHECK param; ha_rows start_records; + if (!file) return HA_ADMIN_INTERNAL_ERROR; + myisamchk_init(¶m); param.thd = thd; param.op_name = (char*) "repair"; @@ -428,14 +429,15 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) if (param.retry_without_quick && param.opt_rep_quick) { param.opt_rep_quick=0; - sql_print_error("Warning: Retrying recover of: %s without quick", + sql_print_error("Warning: Retrying repair of: '%s' without quick", table->path); continue; } + param.opt_rep_quick=0; // Safety if ((param.testflag & T_REP_BY_SORT)) { param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP; - sql_print_error("Warning: Retrying recover of: %s with keycache", + sql_print_error("Warning: Retrying repair of: '%s' with keycache", table->path); continue; } @@ -444,7 +446,7 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) if (!error && start_records != file->state->records) { char llbuff[22],llbuff2[22]; - sql_print_error("Warning: Found %s of %s rows from %s", + sql_print_error("Warning: Found %s of %s rows when repairing '%s'", llstr(file->state->records, llbuff), llstr(start_records, llbuff2), table->path); @@ -472,6 +474,7 @@ int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt) int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) { int error=0; + uint extra_testflag=0; bool optimize_done= !optimize, statistics_done=0; char fixed_name[FN_REFLEN]; const char *old_proc_info=thd->proc_info; @@ -487,6 +490,12 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) VOID(fn_format(fixed_name,file->filename,"",MI_NAME_IEXT, 4+ (param.opt_follow_links ? 16 : 0))); + if (mi_lock_database(file,F_WRLCK)) + { + mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno); + DBUG_RETURN(HA_ADMIN_FAILED); + } + if (!optimize || ((file->state->del || share->state.split != file->state->records) && (!param.opt_rep_quick || @@ -496,10 +505,13 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) if (mi_test_if_sort_rep(file,file->state->records,0) && (param.testflag & T_REP_BY_SORT)) { + uint testflag=param.testflag; + extra_testflag= T_STATISTICS; param.testflag|= T_STATISTICS; // We get this for free thd->proc_info="Repair by sorting"; statistics_done=1; error = mi_repair_by_sort(¶m, file, fixed_name, param.opt_rep_quick); + param.testflag=testflag; } else { @@ -539,17 +551,19 @@ int ha_myisam::repair(THD *thd, MI_CHECK ¶m, bool optimize) update_auto_increment_key(¶m, file, 1); error = update_state_info(¶m, file, UPDATE_TIME | UPDATE_OPEN_COUNT | - (param.testflag & T_STATISTICS ? - UPDATE_STAT : 0)); + ((param.testflag | extra_testflag) & + T_STATISTICS ? UPDATE_STAT : 0)); info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | HA_STATUS_CONST); } - else if (!mi_is_crashed(file)) + else { - mi_mark_crashed(file); + mi_mark_crashed_on_repair(file); file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; + update_state_info(¶m, file, 0); } thd->proc_info=old_proc_info; + mi_lock_database(file,F_UNLCK); DBUG_RETURN(error ? HA_ADMIN_FAILED : !optimize_done ? HA_ADMIN_ALREADY_DONE : HA_ADMIN_OK); } @@ -593,6 +607,7 @@ bool ha_myisam::activate_all_index(THD *thd) bool ha_myisam::check_and_repair(THD *thd) { int error=0; + int marked_crashed; HA_CHECK_OPT check_opt; DBUG_ENTER("ha_myisam::auto_check_and_repair"); @@ -601,11 +616,11 @@ bool ha_myisam::check_and_repair(THD *thd) // Don't use quick if deleted rows if (!file->state->del && (myisam_recover_options & HA_RECOVER_QUICK)) check_opt.quick=1; - sql_print_error("Warning: Checking table: %s",table->path); - if (mi_is_crashed(file) || check(thd, &check_opt)) + sql_print_error("Warning: Checking table: '%s'",table->path); + if ((marked_crashed=mi_is_crashed(file)) || check(thd, &check_opt)) { - sql_print_error("Warning: Recovering table: %s",table->path); - check_opt.quick= !check_opt.retry_without_quick; + sql_print_error("Warning: Recovering table: '%s'",table->path); + check_opt.quick= !check_opt.retry_without_quick && !marked_crashed; check_opt.flags=(((myisam_recover_options & HA_RECOVER_BACKUP) ? T_BACKUP_DATA : 0) | (!(myisam_recover_options & HA_RECOVER_FORCE) ? diff --git a/sql/handler.cc b/sql/handler.cc index c7353a864ff..df44df4a8c1 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -542,6 +542,7 @@ void handler::print_error(int error, myf errflag) textno=ER_CHECKREAD; break; case HA_ERR_CRASHED: + case HA_ERR_CRASHED_ON_REPAIR: textno=ER_NOT_KEYFILE; break; case HA_ERR_OUT_OF_MEM: diff --git a/sql/mysqlbinlog.cc b/sql/mysqlbinlog.cc index 5c94d5d5a57..179bc717093 100644 --- a/sql/mysqlbinlog.cc +++ b/sql/mysqlbinlog.cc @@ -327,8 +327,8 @@ static void dump_local_log_entries(const char* logname) if(!position) { char magic[4]; - if(my_fread(file, (byte*) magic, sizeof(magic), MYF(MY_NABP|MY_WME))) - die("I/O error reading binlog magic number"); + if (my_fread(file, (byte*) magic, sizeof(magic), MYF(MY_NABP|MY_WME))) + die("I/O error reading binlog magic number"); if(memcmp(magic, BINLOG_MAGIC, 4)) die("Bad magic number"); } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index b32e5393404..9fc47cd4dfc 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -567,6 +567,9 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) pthread_mutex_unlock(&LOCK_delayed_create); DBUG_RETURN(0); } + pthread_mutex_lock(&LOCK_thread_count); + thread_count++; + pthread_mutex_unlock(&LOCK_thread_count); if (!(tmp->thd.db=my_strdup(table_list->db,MYF(MY_WME))) || !(tmp->thd.query=my_strdup(table_list->real_name,MYF(MY_FAE)))) { @@ -578,9 +581,6 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list) } tmp->table_list=table_list; // Needed to open table tmp->lock(); - pthread_mutex_lock(&LOCK_thread_count); - thread_count++; - pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_lock(&tmp->mutex); if ((error=pthread_create(&tmp->thd.real_id,&connection_attrib, handle_delayed_insert,(void*) tmp))) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 83355d08925..359ed495a83 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -817,6 +817,7 @@ bool do_command(THD *thd) mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); } } + thd->proc_info="cleaning up2"; VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list thd->proc_info=0; thd->command=COM_SLEEP; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 35949c41b3c..4cdfc992e19 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3721,6 +3721,7 @@ static bool create_myisam_tmp_table(TABLE *table,TMP_TABLE_PARAM *param, table->db_stat=0; goto err; } + statistic_increment(created_tmp_disk_tables, &LOCK_status); table->db_record_offset=1; DBUG_RETURN(0); err: @@ -3781,7 +3782,6 @@ bool create_myisam_from_heap(TABLE *table, TMP_TABLE_PARAM *param, int error, save_proc_info=thd->proc_info; thd->proc_info="converting HEAP to MyISAM"; - statistic_increment(created_tmp_disk_tables, &LOCK_status); if (create_myisam_tmp_table(&new_table,param, thd->lex.options | thd->options)) goto err2; @@ -4196,7 +4196,7 @@ join_read_const(JOIN_TAB *tab) if (error != HA_ERR_KEY_NOT_FOUND) { sql_print_error("read_const: Got error %d when reading table %s", - error, table->real_name); + error, table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4231,7 +4231,7 @@ join_read_key(JOIN_TAB *tab) if (error && error != HA_ERR_KEY_NOT_FOUND) { sql_print_error("read_key: Got error %d when reading table '%s'",error, - table->real_name); + table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4255,7 +4255,7 @@ join_read_always_key(JOIN_TAB *tab) if (error != HA_ERR_KEY_NOT_FOUND) { sql_print_error("read_const: Got error %d when reading table %s",error, - table->real_name); + table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4287,7 +4287,7 @@ join_read_next(READ_RECORD *info) if (error != HA_ERR_END_OF_FILE) { sql_print_error("read_next: Got error %d when reading table %s",error, - table->real_name); + table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4365,7 +4365,7 @@ join_init_read_next_with_key(READ_RECORD *info) if (error != HA_ERR_END_OF_FILE) { sql_print_error("read_next_with_key: Got error %d when reading table %s", - error, info->table->real_name); + error, info->table->path); info->file->print_error(error,MYF(0)); return 1; } @@ -4397,7 +4397,7 @@ join_init_read_last_with_key(JOIN_TAB *tab) if (error != HA_ERR_END_OF_FILE) { sql_print_error("read_first_with_key: Got error %d when reading table", - error, table->real_name); + error, table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4415,7 +4415,7 @@ join_init_read_prev_with_key(READ_RECORD *info) if (error != HA_ERR_END_OF_FILE) { sql_print_error("read_prev_with_key: Got error %d when reading table: %s", - error,info->table->real_name); + error,info->table->path); info->file->print_error(error,MYF(0)); return 1; } @@ -4441,7 +4441,7 @@ join_ft_read_first(JOIN_TAB *tab) if (error != HA_ERR_KEY_NOT_FOUND) { sql_print_error("ft_read_first/init: Got error %d when reading table %s",error, - table->real_name); + table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4454,7 +4454,7 @@ join_ft_read_first(JOIN_TAB *tab) if (error != HA_ERR_END_OF_FILE) { sql_print_error("ft_read_first/read: Got error %d when reading table %s", - error, table->real_name); + error, table->path); table->file->print_error(error,MYF(0)); return 1; } @@ -4472,7 +4472,7 @@ join_ft_read_next(READ_RECORD *info) if (error != HA_ERR_END_OF_FILE) { sql_print_error("ft_read_next: Got error %d when reading table %s", - error, info->table->real_name); + error, info->table->path); info->file->print_error(error,MYF(0)); return 1; } |