Commit 14346aa9 authored by petr@mysql.com's avatar petr@mysql.com

Merge pchardin@bk-internal.mysql.com:/home/bk/mysql-5.1-new

into  mysql.com:/home/cps/mysql/devel/5.1-repair-csv
parents 3d13f61e 39a251f3
...@@ -4993,6 +4993,99 @@ val ...@@ -4993,6 +4993,99 @@ val
2 2
UNLOCK TABLES; UNLOCK TABLES;
DROP TABLE test_concurrent_insert; 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 test_repair_table4 (
num int not null,
magic_no int(4) unsigned zerofill DEFAULT '0000' NOT NULL,
company_name char(30) DEFAULT '' NOT NULL,
founded char(4) DEFAULT '' NOT NULL
) ENGINE = CSV;
SELECT * FROM test_repair_table4;
num magic_no company_name founded
Warnings:
Error 1194 Table 'test_repair_table4' is marked as crashed and should be repaired
SELECT * FROM test_repair_table4;
num magic_no company_name founded
CHECK TABLE test_repair_table4;
Table Op Msg_type Msg_text
test.test_repair_table4 check status OK
INSERT INTO test_repair_table4 VALUES (2,101,'SAP','1972');
INSERT INTO test_repair_table4 VALUES (1,101,'Microsoft','1978');
INSERT INTO test_repair_table4 VALUES (2,101,'MySQL','1995');
SELECT * FROM test_repair_table4;
num magic_no company_name founded
2 0101 SAP 1972
1 0101 Microsoft 1978
2 0101 MySQL 1995
CHECK TABLE test_repair_table4;
Table Op Msg_type Msg_text
test.test_repair_table4 check status OK
REPAIR TABLE test_repair_table4;
Table Op Msg_type Msg_text
test.test_repair_table4 repair status OK
SELECT * FROM test_repair_table4;
num magic_no company_name founded
2 0101 SAP 1972
1 0101 Microsoft 1978
2 0101 MySQL 1995
CHECK TABLE test_repair_table4;
Table Op Msg_type Msg_text
test.test_repair_table4 check status OK
REPAIR TABLE test_repair_table4;
Table Op Msg_type Msg_text
test.test_repair_table4 repair status OK
SELECT * FROM test_repair_table4;
num magic_no company_name founded
2 0101 SAP 1972
1 0101 Microsoft 1978
2 0101 MySQL 1995
DROP TABLE test_repair_table4;
CREATE TABLE test_repair_table5 (
num int not null,
magic_no int(4) unsigned zerofill DEFAULT '0000' NOT NULL,
company_name char(30) DEFAULT '' NOT NULL,
founded char(4) DEFAULT '' NOT NULL
) ENGINE = CSV;
CHECK TABLE test_repair_table5;
Table Op Msg_type Msg_text
test.test_repair_table5 check error Corrupt
REPAIR TABLE test_repair_table5;
Table Op Msg_type Msg_text
test.test_repair_table5 repair status OK
SELECT * FROM test_repair_table5;
num magic_no company_name founded
DROP TABLE test_repair_table5;
create table t1 (a int) engine=csv; create table t1 (a int) engine=csv;
insert t1 values (1); insert t1 values (1);
delete from t1; delete from t1;
......
...@@ -1387,6 +1387,92 @@ UNLOCK TABLES; ...@@ -1387,6 +1387,92 @@ UNLOCK TABLES;
# cleanup # cleanup
DROP TABLE test_concurrent_insert; 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;
# Test with more sophisticated table
CREATE TABLE test_repair_table4 (
num int not null,
magic_no int(4) unsigned zerofill DEFAULT '0000' NOT NULL,
company_name char(30) DEFAULT '' NOT NULL,
founded char(4) DEFAULT '' NOT NULL
) ENGINE = CSV;
--exec rm $MYSQLTEST_VARDIR/master-data/test/test_repair_table4.CSM
SELECT * FROM test_repair_table4;
SELECT * FROM test_repair_table4;
CHECK TABLE test_repair_table4;
INSERT INTO test_repair_table4 VALUES (2,101,'SAP','1972');
INSERT INTO test_repair_table4 VALUES (1,101,'Microsoft','1978');
INSERT INTO test_repair_table4 VALUES (2,101,'MySQL','1995');
# list table content
SELECT * FROM test_repair_table4;
CHECK TABLE test_repair_table4;
REPAIR TABLE test_repair_table4;
# check that nothing changed
SELECT * FROM test_repair_table4;
# verify that check/repair did non corrupt the table itself
CHECK TABLE test_repair_table4;
REPAIR TABLE test_repair_table4;
SELECT * FROM test_repair_table4;
DROP TABLE test_repair_table4;
# Run CHECK/REPAIR on the CSV file with a single row, which misses a column.
CREATE TABLE test_repair_table5 (
num int not null,
magic_no int(4) unsigned zerofill DEFAULT '0000' NOT NULL,
company_name char(30) DEFAULT '' NOT NULL,
founded char(4) DEFAULT '' NOT NULL
) ENGINE = CSV;
# Corrupt a table -- put a file with wrong # of columns
--exec echo -n -e \"1\",\"101\",\"IBM\"\\n > $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
CHECK TABLE test_repair_table5;
REPAIR TABLE test_repair_table5;
SELECT * FROM test_repair_table5;
DROP TABLE test_repair_table5;
# #
# BUG#13406 - incorrect amount of "records deleted" # BUG#13406 - incorrect amount of "records deleted"
# #
......
This diff is collapsed.
...@@ -19,9 +19,16 @@ ...@@ -19,9 +19,16 @@
#include <my_dir.h> #include <my_dir.h>
#define DEFAULT_CHAIN_LENGTH 512 #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 { typedef struct st_tina_share {
char *table_name; char *table_name;
char data_file_name[FN_REFLEN];
byte *mapped_file; /* mapped region of file */ byte *mapped_file; /* mapped region of file */
uint table_name_length, use_count; uint table_name_length, use_count;
/* /*
...@@ -39,6 +46,9 @@ typedef struct st_tina_share { ...@@ -39,6 +46,9 @@ typedef struct st_tina_share {
off_t saved_data_file_length; off_t saved_data_file_length;
pthread_mutex_t mutex; pthread_mutex_t mutex;
THR_LOCK lock; 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; } TINA_SHARE;
typedef struct tina_set { typedef struct tina_set {
...@@ -108,7 +118,7 @@ public: ...@@ -108,7 +118,7 @@ public:
ulong type, TABLE *table, ulong type, TABLE *table,
uint count, uint count,
bool called_by_logger_thread); 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 close(void);
int write_row(byte * buf); int write_row(byte * buf);
int update_row(const byte * old_data, byte * new_data); int update_row(const byte * old_data, byte * new_data);
...@@ -116,7 +126,13 @@ public: ...@@ -116,7 +126,13 @@ public:
int rnd_init(bool scan=1); int rnd_init(bool scan=1);
int rnd_next(byte *buf); int rnd_next(byte *buf);
int rnd_pos(byte * buf, byte *pos); 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 rnd_end(); 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 position(const byte *record);
void info(uint); void info(uint);
int extra(enum ha_extra_function operation); 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