Commit ecba6dc6 authored by unknown's avatar unknown

WL#3154 "Enable REPAIR for CSV tables".

This is the first commit. Cleanups are
likely to follow after the merge.


mysql-test/r/csv.result:
  update result
mysql-test/t/csv.test:
  add tests for CSV REPAIR/RESTORE.
storage/csv/ha_tina.cc:
  add repair/check and a meta-file processing for it
storage/csv/ha_tina.h:
  add new functions required for tina repair/check
parent 7e2a9aa4
......@@ -4993,6 +4993,38 @@ val
2
UNLOCK TABLES;
DROP TABLE test_concurrent_insert;
CREATE TABLE test_repair_table ( val integer ) ENGINE = CSV;
CHECK TABLE test_repair_table;
Table Op Msg_type Msg_text
test.test_repair_table check status OK
REPAIR TABLE test_repair_table;
Table Op Msg_type Msg_text
test.test_repair_table repair status OK
DROP TABLE test_repair_table;
CREATE TABLE test_repair_table2 ( val integer ) ENGINE = CSV;
SELECT * from test_repair_table2;
val
Warnings:
Error 1194 Table 'test_repair_table2' is marked as crashed and should be repaired
SELECT * from test_repair_table2;
val
test_repair_table2.CSM
CHECK TABLE test_repair_table2;
Table Op Msg_type Msg_text
test.test_repair_table2 check status OK
DROP TABLE test_repair_table2;
CREATE TABLE test_repair_table3 ( val integer ) ENGINE = CSV;
CHECK TABLE test_repair_table3;
Table Op Msg_type Msg_text
test.test_repair_table3 check error Corrupt
REPAIR TABLE test_repair_table3;
Table Op Msg_type Msg_text
test.test_repair_table3 repair status OK
SELECT * FROM test_repair_table3;
val
1
4
DROP TABLE test_repair_table3;
create table t1 (a int) engine=csv;
insert t1 values (1);
delete from t1;
......
......@@ -1387,6 +1387,45 @@ UNLOCK TABLES;
# cleanup
DROP TABLE test_concurrent_insert;
#
# Test REPAIR/CHECK TABLE (5.1)
#
# Check that repair on the newly created table works fine
CREATE TABLE test_repair_table ( val integer ) ENGINE = CSV;
CHECK TABLE test_repair_table;
REPAIR TABLE test_repair_table;
DROP TABLE test_repair_table;
#
# Check autorepair. Here we also check that we can work w/o metafile
# restore the meta-file
#
CREATE TABLE test_repair_table2 ( val integer ) ENGINE = CSV;
--exec rm $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM
# should give a warning and perform autorepair
SELECT * from test_repair_table2;
# this should work ok, as the table is already repaired
SELECT * from test_repair_table2;
# check that the metafile appeared again. chop the path to it
--exec ls $MYSQLTEST_VARDIR/master-data/test/test_repair_table2.CSM | perl -pi -e "s/.*\///"
CHECK TABLE test_repair_table2;
DROP TABLE test_repair_table2;
# Corrupt csv file and see if we can repair it
CREATE TABLE test_repair_table3 ( val integer ) ENGINE = CSV;
--exec echo -n -e \"1\"\\n\"4\"\\n\"3 > $MYSQLTEST_VARDIR/master-data/test/test_repair_table3.CSV
CHECK TABLE test_repair_table3;
REPAIR TABLE test_repair_table3;
SELECT * FROM test_repair_table3;
DROP TABLE test_repair_table3;
#
# BUG#13406 - incorrect amount of "records deleted"
#
......
This diff is collapsed.
......@@ -19,9 +19,16 @@
#include <my_dir.h>
#define DEFAULT_CHAIN_LENGTH 512
/*
Version for file format.
1 - Initial Version. That is, the version when the metafile was introduced.
*/
#define TINA_VERSION 1
typedef struct st_tina_share {
char *table_name;
char data_file_name[FN_REFLEN];
byte *mapped_file; /* mapped region of file */
uint table_name_length, use_count;
/*
......@@ -39,6 +46,9 @@ typedef struct st_tina_share {
off_t saved_data_file_length;
pthread_mutex_t mutex;
THR_LOCK lock;
File meta_file; /* Meta file we use */
bool crashed; /* Meta file is crashed */
ha_rows rows_recorded; /* Number of rows in tables */
} TINA_SHARE;
typedef struct tina_set {
......@@ -108,7 +118,7 @@ public:
ulong type, TABLE *table,
uint count,
bool called_by_logger_thread);
int open(const char *name, int mode, uint test_if_locked);
int open(const char *name, int mode, uint open_options);
int close(void);
int write_row(byte * buf);
int update_row(const byte * old_data, byte * new_data);
......@@ -116,7 +126,17 @@ public:
int rnd_init(bool scan=1);
int rnd_next(byte *buf);
int rnd_pos(byte * buf, byte *pos);
bool check_and_repair(THD *thd);
int check(THD* thd, HA_CHECK_OPT* check_opt);
bool is_crashed() const;
int read_meta_file(File meta_file, ha_rows *rows);
int write_meta_file(File meta_file, ha_rows rows, bool dirty);
TINA_SHARE *get_share(const char *table_name, TABLE *table, int *rc);
int free_share(TINA_SHARE *share);
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() const { return 1; }
void position(const byte *record);
void info(uint);
int extra(enum ha_extra_function operation);
......
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