Commit 3c44bca6 authored by unknown's avatar unknown

auto-zerofill when a table is moved from another server

parent cab8a363
......@@ -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(&param);
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(&param, file, file->s->open_file_name);
return error;
}
int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt)
{
int error;
......@@ -1740,7 +1758,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;
......@@ -1748,6 +1766,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))
......@@ -1782,7 +1818,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));
}
......
......@@ -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 &param, 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);
......
......@@ -3061,7 +3061,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);
......
......@@ -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)
......
......@@ -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 */
......
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