diff options
Diffstat (limited to 'storage/maria/ha_maria.cc')
-rw-r--r-- | storage/maria/ha_maria.cc | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index b9c8410895d..8eed173e475 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1563,6 +1563,7 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) MARIA_SHARE *share= file->s; ha_rows rows= file->state->records; TRN *old_trn= file->trn; + my_bool locking= 0; DBUG_ENTER("ha_maria::repair"); /* @@ -1599,12 +1600,18 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) share->state.dupp_key= MI_MAX_KEY; strmov(fixed_name, share->open_file_name.str); - // Don't lock tables if we have used LOCK TABLE - if (!thd->locked_tables_mode && - maria_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) + /* + Don't lock tables if we have used LOCK TABLE or if we come from + enable_index() + */ + if (!thd->locked_tables_mode && ! (param->testflag & T_NO_LOCKS)) { - _ma_check_print_error(param, ER(ER_CANT_LOCK), my_errno); - DBUG_RETURN(HA_ADMIN_FAILED); + locking= 1; + if (maria_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) + { + _ma_check_print_error(param, ER(ER_CANT_LOCK), my_errno); + DBUG_RETURN(HA_ADMIN_FAILED); + } } if (!do_optimize || @@ -1740,7 +1747,7 @@ int ha_maria::repair(THD *thd, HA_CHECK *param, bool do_optimize) mysql_mutex_unlock(&share->intern_lock); thd_proc_info(thd, old_proc_info); thd_progress_end(thd); // Mark done - if (!thd->locked_tables_mode) + if (locking) maria_lock_database(file, F_UNLCK); /* Reset trn, that may have been set by repair */ @@ -1974,8 +1981,16 @@ int ha_maria::enable_indexes(uint mode) param.op_name= "recreating_index"; param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | T_CREATE_MISSING_KEYS | T_SAFE_REPAIR); + /* + Don't lock and unlock table if it's locked. + Normally table should be locked. This test is mostly for safety. + */ + if (likely(file->lock_type != F_UNLCK)) + param.testflag|= T_NO_LOCKS; + if (file->create_unique_index_by_sort) param.testflag|= T_CREATE_UNIQUE_BY_SORT; + if (bulk_insert_single_undo == BULK_INSERT_SINGLE_UNDO_AND_NO_REPAIR) { bulk_insert_single_undo= BULK_INSERT_SINGLE_UNDO_AND_REPAIR; @@ -2219,7 +2234,7 @@ bool ha_maria::check_and_repair(THD *thd) { /* Remove error about crashed table */ thd->get_stmt_da()->clear_warning_info(thd->query_id); - push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_NOTE, + push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_CRASHED_ON_USAGE, "Zerofilling moved table %s", table->s->path.str); sql_print_information("Zerofilling moved table: '%s'", |