diff options
-rw-r--r-- | dbug/dbug.c | 1 | ||||
-rw-r--r-- | include/my_dbug.h | 20 | ||||
-rw-r--r-- | storage/maria/ha_maria.cc | 40 | ||||
-rw-r--r-- | storage/maria/ha_maria.h | 4 | ||||
-rw-r--r-- | storage/maria/ma_check.c | 3 | ||||
-rw-r--r-- | storage/maria/ma_open.c | 14 | ||||
-rw-r--r-- | storage/maria/maria_def.h | 1 |
7 files changed, 67 insertions, 16 deletions
diff --git a/dbug/dbug.c b/dbug/dbug.c index 68e52388ae3..136f86e6c33 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -951,7 +951,6 @@ void _db_enter_(const char *_func_, const char *_file_, *_slevel_= 0; /* Set to avoid valgrind warnings if dbug is enabled later */ return; } - get_code_state_or_return; save_errno= errno; *_sfunc_= cs->func; diff --git a/include/my_dbug.h b/include/my_dbug.h index 5372a13f4af..a284e648f7f 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -82,20 +82,20 @@ extern void _db_force_flush(); #define DBUG_ASSERT(A) assert(A) #define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len)) #define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) -#define DEBUGGER_OFF _dbug_on_= 0 -#define DEBUGGER_ON _dbug_on_= 1 +#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) +#define DEBUGGER_ON do { _dbug_on_= 1; } while(0) #define IF_DBUG(A) A #else /* No debugger */ #define DBUG_ENTER(a1) #define DBUG_LEAVE -#define DBUG_RETURN(a1) do { return(a1); } while(0) -#define DBUG_VOID_RETURN do { return; } while(0) -#define DBUG_EXECUTE(keyword,a1) do { } while(0) -#define DBUG_EXECUTE_IF(keyword,a1) do { } while(0) +#define DBUG_RETURN(a1) do { return(a1); } while(0) +#define DBUG_VOID_RETURN do { return; } while(0) +#define DBUG_EXECUTE(keyword,a1) do { } while(0) +#define DBUG_EXECUTE_IF(keyword,a1) do { } while(0) #define DBUG_EVALUATE(keyword,a1,a2) (a2) #define DBUG_EVALUATE_IF(keyword,a1,a2) (a2) -#define DBUG_PRINT(keyword,arglist) do { } while(0) +#define DBUG_PRINT(keyword,arglist) do { } while(0) #define DBUG_PUSH(a1) #define DBUG_SET(a1) #define DBUG_SET_INITIAL(a1) @@ -105,14 +105,14 @@ extern void _db_force_flush(); #define DBUG_LONGJMP(a1) longjmp(a1) #define DBUG_DUMP(keyword,a1,a2) #define DBUG_END() -#define DBUG_ASSERT(A) do { } while(0) +#define DBUG_ASSERT(A) do { } while(0) #define DBUG_LOCK_FILE #define DBUG_FILE (stderr) -#define DEBUGGER_OFF -#define DEBUGGER_ON #define DBUG_UNLOCK_FILE #define DBUG_EXPLAIN(buf,len) #define DBUG_EXPLAIN_INITIAL(buf,len) +#define DEBUGGER_OFF do { } while(0) +#define DEBUGGER_ON do { } while(0) #define IF_DBUG(A) #endif #ifdef __cplusplus diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index d0870238244..4e7d2b04471 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -1181,6 +1181,24 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) return error; } +int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) +{ + int error; + HA_CHECK param; + + if (!file) + return HA_ADMIN_INTERNAL_ERROR; + + maria_chk_init(¶m); + param.thd= thd; + param.op_name= "zerofill"; + param.testflag= check_opt->flags | T_SILENT | T_ZEROFILL; + param.sort_buffer_length= check_opt->sort_buffer_size; + error=maria_zerofill(¶m, file, file->s->open_file_name); + + return error; +} + int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt) { int error; @@ -1736,7 +1754,7 @@ int ha_maria::end_bulk_insert() bool ha_maria::check_and_repair(THD *thd) { - int error= 0; + int error; int marked_crashed; char *old_query; uint old_query_length; @@ -1744,6 +1762,24 @@ bool ha_maria::check_and_repair(THD *thd) DBUG_ENTER("ha_maria::check_and_repair"); check_opt.init(); + + if (file->s->state.changed & STATE_MOVED) + { + sql_print_information("Zerofilling table: '%s'", table->s->path.str); + if (!(error= zerofill(thd, &check_opt))) + DBUG_RETURN(0); + } + else + error= 1; + + /* + if we got this far - the table is crashed. + but don't auto-repair if maria_recover_options is not set + */ + if (!maria_recover_options) + DBUG_RETURN(error); + + error= 0; check_opt.flags= T_MEDIUM | T_AUTO_REPAIR; // Don't use quick if deleted rows if (!file->state->del && (maria_recover_options & HA_RECOVER_QUICK)) @@ -1778,7 +1814,7 @@ bool ha_maria::check_and_repair(THD *thd) bool ha_maria::is_crashed() const { - return (file->s->state.changed & STATE_CRASHED || + return (file->s->state.changed & (STATE_CRASHED | STATE_MOVED) || (my_disable_locking && file->s->state.open_count)); } diff --git a/storage/maria/ha_maria.h b/storage/maria/ha_maria.h index cb4efffff5f..b4ba3b5ef31 100644 --- a/storage/maria/ha_maria.h +++ b/storage/maria/ha_maria.h @@ -41,6 +41,7 @@ class ha_maria :public handler enum data_file_type data_file_type; bool can_enable_indexes; int repair(THD * thd, HA_CHECK ¶m, bool optimize); + int zerofill(THD * thd, HA_CHECK_OPT *check_opt); public: ha_maria(handlerton *hton, TABLE_SHARE * table_arg); @@ -133,8 +134,7 @@ public: int repair(THD * thd, HA_CHECK_OPT * check_opt); bool check_and_repair(THD * thd); bool is_crashed() const; - bool auto_repair() const - { return maria_recover_options != 0; } + bool auto_repair() const { return 1; } int optimize(THD * thd, HA_CHECK_OPT * check_opt); int restore(THD * thd, HA_CHECK_OPT * check_opt); int backup(THD * thd, HA_CHECK_OPT * check_opt); diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index e7bee662c1d..da6b6d0aa57 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -3079,7 +3079,8 @@ int maria_zerofill(HA_CHECK *param, MARIA_HA *info, const char *name) Mark that table is movable and that we have done zerofill of data and index */ - info->s->state.changed&= ~(STATE_NOT_ZEROFILLED | STATE_NOT_MOVABLE); + info->s->state.changed&= ~(STATE_NOT_ZEROFILLED | STATE_NOT_MOVABLE | + STATE_MOVED); /* Ensure state are flushed to disk */ info->update= (HA_STATE_CHANGED | HA_STATE_ROW_CHANGED); DBUG_RETURN(0); diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 00aff46aafb..2acaa3db01d 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -396,6 +396,17 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) goto err; } + if (memcmp(share->base.uuid, maria_uuid, MY_UUID_SIZE)) + { + if (open_flags & HA_OPEN_FOR_REPAIR) + share->state.changed|= STATE_MOVED; + else + { + my_errno= HA_ERR_OLD_FILE; + goto err; + } + } + /* sanity check */ if (share->base.keystart > 65535 || share->base.rec_reflength > 8) { @@ -796,6 +807,7 @@ MARIA_HA *maria_open(const char *name, int mode, uint open_flags) if (!(m_info= maria_clone_internal(share, mode, data_file))) goto err; + pthread_mutex_unlock(&THR_LOCK_maria); DBUG_RETURN(m_info); @@ -805,6 +817,8 @@ err: (save_errno == HA_ERR_CRASHED_ON_USAGE) || (save_errno == HA_ERR_CRASHED_ON_REPAIR)) _ma_report_error(save_errno, name); + if (save_errno == HA_ERR_OLD_FILE) /* uuid is different ? */ + save_errno= HA_ERR_CRASHED_ON_USAGE; /* the code to trigger auto-repair */ switch (errpos) { case 5: if (data_file >= 0) diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index b26babd2f54..05a1dbe2d56 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -548,6 +548,7 @@ struct st_maria_handler #define STATE_NOT_OPTIMIZED_ROWS 64 #define STATE_NOT_ZEROFILLED 128 #define STATE_NOT_MOVABLE 256 +#define STATE_MOVED 512 /* set if base->uuid != maria_uuid */ /* options to maria_read_cache */ |