Commit 8701728f authored by unknown's avatar unknown
Browse files

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
parent 0122ca60
Loading
Loading
Loading
Loading
+1218 −0

File changed.

Preview size limit exceeded, changes collapsed.

+5 −1
Original line number Diff line number Diff line
@@ -1339,6 +1339,10 @@ SELECT * FROM t2;
TRUNCATE TABLE t2;
SELECT * FROM t2;

# Adding support for CHECK table
CHECK TABLE t2;
SELECT * FROM t2;


# Just test syntax, we will never know if the output is right or wrong
# Must be the last test
+77 −0
Original line number Diff line number Diff line
@@ -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 */
+3 −0
Original line number Diff line number Diff line
@@ -103,6 +103,9 @@ class ha_archive: public handler
  }
  THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
                             enum thr_lock_type lock_type);
  bool is_crashed() const;
  int check(THD* thd, HA_CHECK_OPT* check_opt);
  bool check_and_repair(THD *thd);
};

bool archive_db_init(void);