diff options
author | Michael Widenius <monty@askmonty.org> | 2012-03-28 13:22:21 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2012-03-28 13:22:21 +0300 |
commit | 74b064933267f58b9201c46eb67454237d7664d3 (patch) | |
tree | 0edbcdc70f9ca702a1e95782f8f20472ff6849a5 /storage | |
parent | d1f311799988266159310afce3cf19eaf58a1fa5 (diff) | |
download | mariadb-git-74b064933267f58b9201c46eb67454237d7664d3.tar.gz |
Fixed lp:944422 "mysql_upgrade destroys Maria tables?"
The issue was that check/optimize/anaylze did not zerofill the table before they started to work on it.
Added one more element to not often used function handler::auto_repair() to allow handler to decide when to auto repair.
mysql-test/suite/maria/r/maria-autozerofill.result:
Test case for lp:944422
mysql-test/suite/maria/t/maria-autozerofill.test:
Test case for lp:944422
sql/ha_partition.cc:
Added argument to auto_repair()
sql/ha_partition.h:
Added argument to auto_repair()
sql/handler.h:
Added argument to auto_repair()
sql/table.cc:
Let auto_repair() decide which errors to trigger auto-repair
storage/archive/ha_archive.h:
Added argument to auto_repair()
storage/csv/ha_tina.h:
Added argument to auto_repair()
storage/maria/ha_maria.cc:
Give better error & warning messages for auto-repaired tables.
storage/maria/ha_maria.h:
Added argument to auto_repair()
Always auto-repair in case of moved table.
storage/maria/ma_open.c:
Remove special handling of HA_ERR_OLD_FILE (this is now handled in auto_repair())
storage/myisam/ha_myisam.h:
Added argument to auto_repair()
Diffstat (limited to 'storage')
-rw-r--r-- | storage/archive/ha_archive.h | 4 | ||||
-rw-r--r-- | storage/csv/ha_tina.h | 2 | ||||
-rw-r--r-- | storage/maria/ha_maria.cc | 23 | ||||
-rw-r--r-- | storage/maria/ha_maria.h | 10 | ||||
-rw-r--r-- | storage/maria/ma_open.c | 2 | ||||
-rw-r--r-- | storage/myisam/ha_myisam.h | 6 |
6 files changed, 41 insertions, 6 deletions
diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h index 653a13b242d..6f0c0b529fb 100644 --- a/storage/archive/ha_archive.h +++ b/storage/archive/ha_archive.h @@ -125,7 +125,9 @@ public: int free_share(); int init_archive_writer(); int init_archive_reader(); - bool auto_repair() const { return 1; } // For the moment we just do this + // Always try auto_repair in case of HA_ERR_CRASHED_ON_USAGE + bool auto_repair(int error) const + { return error == HA_ERR_CRASHED_ON_USAGE; } int read_data_header(azio_stream *file_to_read); void position(const uchar *record); int info(uint); diff --git a/storage/csv/ha_tina.h b/storage/csv/ha_tina.h index 8572a53a94d..54860ecb3fb 100644 --- a/storage/csv/ha_tina.h +++ b/storage/csv/ha_tina.h @@ -151,6 +151,8 @@ public: int rnd_end(); int repair(THD* thd, HA_CHECK_OPT* check_opt); /* This is required for SQL layer to know that we support autorepair */ + bool auto_repair(int error) const + { return error == HA_ERR_CRASHED_ON_USAGE; } bool auto_repair() const { return 1; } void position(const uchar *record); int info(uint); diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index e02c8c5e2cd..6c0914ab751 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -52,6 +52,9 @@ C_MODE_END ulong pagecache_division_limit, pagecache_age_threshold; ulonglong pagecache_buffer_size; +const char *zerofill_error_msg= + "Table is from another system and must be zerofilled or repaired to be " + "usable on this system"; /** As the auto-repair is initiated when opened from the SQL layer @@ -972,7 +975,15 @@ int ha_maria::open(const char *name, int mode, uint test_if_locked) } if (!(file= maria_open(name, mode, test_if_locked | HA_OPEN_FROM_SQL_LAYER))) + { + if (my_errno == HA_ERR_OLD_FILE) + { + push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_CRASHED_ON_USAGE, + zerofill_error_msg); + } return (my_errno ? my_errno : -1); + } file->s->chst_invalidator= query_cache_invalidate_by_MyISAM_filename_ref; @@ -1074,6 +1085,13 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) return HA_ADMIN_ALREADY_DONE; maria_chk_init_for_check(¶m, file); + if ((file->s->state.changed & (STATE_CRASHED_FLAGS | STATE_MOVED)) == + STATE_MOVED) + { + _ma_check_print_error(¶m, zerofill_error_msg); + return HA_ADMIN_CORRUPT; + } + (void) maria_chk_status(¶m, file); // Not fatal error= maria_chk_size(¶m, file); if (!error) @@ -2024,6 +2042,11 @@ bool ha_maria::check_and_repair(THD *thd) if ((file->s->state.changed & (STATE_CRASHED_FLAGS | STATE_MOVED)) == STATE_MOVED) { + /* Remove error about crashed table */ + mysql_reset_errors(thd, true); + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_CRASHED_ON_USAGE, + "Zerofilling moved table %s", table->s->path.str); sql_print_information("Zerofilling moved table: '%s'", table->s->path.str); if (!(error= zerofill(thd, &check_opt))) diff --git a/storage/maria/ha_maria.h b/storage/maria/ha_maria.h index 47545b67ff3..343675e9452 100644 --- a/storage/maria/ha_maria.h +++ b/storage/maria/ha_maria.h @@ -142,8 +142,14 @@ public: bool check_and_repair(THD * thd); bool is_crashed() const; bool is_changed() const; - bool auto_repair() const - { return test(maria_recover_options & HA_RECOVER_ANY); } + bool auto_repair(int error) const + { + /* Always auto-repair moved tables (error == HA_ERR_OLD_FILE) */ + return ((test(maria_recover_options & HA_RECOVER_ANY) && + error == HA_ERR_CRASHED_ON_USAGE) || + error == HA_ERR_OLD_FILE); + + } 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_open.c b/storage/maria/ma_open.c index eb7ef510d88..cf2e2ceb704 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -968,8 +968,6 @@ err: tmp_name.length= strlen(name); _ma_report_error(save_errno, &tmp_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/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index ea9db8f0f2b..98a0d393bbb 100644 --- a/storage/myisam/ha_myisam.h +++ b/storage/myisam/ha_myisam.h @@ -128,7 +128,11 @@ class ha_myisam: public handler int repair(THD* thd, HA_CHECK_OPT* check_opt); bool check_and_repair(THD *thd); bool is_crashed() const; - bool auto_repair() const { return myisam_recover_options != 0; } + bool auto_repair(int error) const + { + return (myisam_recover_options != 0 && + error == HA_ERR_CRASHED_ON_USAGE); + } 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); |