diff options
author | unknown <brian@zim.(none)> | 2005-10-18 14:52:38 -0700 |
---|---|---|
committer | unknown <brian@zim.(none)> | 2005-10-18 14:52:38 -0700 |
commit | 8701728f17d1e435cb8c9dbb997728b002e6d9b4 (patch) | |
tree | d35c29b82f6f0ce13afca8385af66fc079dc7813 /sql/ha_archive.cc | |
parent | 0122ca60b8c07b9493fa453eb5e12a52234dd579 (diff) | |
download | mariadb-git-8701728f17d1e435cb8c9dbb997728b002e6d9b4.tar.gz |
Per a user request there is now support for "CHECK TABLE" where the table is an archive file.
mysql-test/r/archive.result:
Result file for adding check table support
mysql-test/t/archive.test:
Simple test for check table. The additional select is added just to make sure the file is not destroyed.
sql/ha_archive.cc:
Updates for adding CHECK table support. is_crashed() now returns the state of the file.
sql/ha_archive.h:
Updates for adding CHECK table support
Diffstat (limited to 'sql/ha_archive.cc')
-rw-r--r-- | sql/ha_archive.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/sql/ha_archive.cc b/sql/ha_archive.cc index 59c56e80cc3..b4bcf162ff0 100644 --- a/sql/ha_archive.cc +++ b/sql/ha_archive.cc @@ -1053,4 +1053,81 @@ int ha_archive::delete_all_rows() DBUG_ENTER("ha_archive::delete_all_rows"); DBUG_RETURN(0); } + +/* + We just return state if asked. +*/ +bool ha_archive::is_crashed() const +{ + return share->crashed; +} + +/* + Simple scan of the tables to make sure everything is ok. +*/ + +int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt) +{ + int rc= 0; + byte *buf; + const char *old_proc_info=thd->proc_info; + ha_rows count= share->rows_recorded; + DBUG_ENTER("ha_archive::check"); + + thd->proc_info= "Checking table"; + /* Flush any waiting data */ + gzflush(share->archive_write, Z_SYNC_FLUSH); + + /* + First we create a buffer that we can use for reading rows, and can pass + to get_row(). + */ + if (!(buf= (byte*) my_malloc(table->s->reclength, MYF(MY_WME)))) + rc= HA_ERR_OUT_OF_MEM; + + /* + Now we will rewind the archive file so that we are positioned at the + start of the file. + */ + if (!rc) + read_data_header(archive); + + if (!rc) + while (!(rc= get_row(archive, buf))) + count--; + + my_free((char*)buf, MYF(0)); + + thd->proc_info= old_proc_info; + + if ((rc && rc != HA_ERR_END_OF_FILE) || count) + { + share->crashed= FALSE; + DBUG_RETURN(HA_ADMIN_CORRUPT); + } + else + { + DBUG_RETURN(HA_ADMIN_OK); + } +} + +/* + Check and repair the table if needed. +*/ +bool ha_archive::check_and_repair(THD *thd) +{ + HA_CHECK_OPT check_opt; + DBUG_ENTER("ha_archive::check_and_repair"); + + check_opt.init(); + + if (check(thd, &check_opt) == HA_ADMIN_CORRUPT) + { + DBUG_RETURN(repair(thd, &check_opt)); + } + else + { + DBUG_RETURN(HA_ADMIN_OK); + } +} #endif /* HAVE_ARCHIVE_DB */ |