mirror of
https://github.com/MariaDB/server.git
synced 2026-05-15 11:27:39 +02:00
Bug#8283 - OPTIMIZE TABLE causes data loss
OPTIMIZE TABLE with myisam_repair_threads > 1 performs a non-quick parallel repair. This means that it does not only rebuild all indexes, but also the data file. Non-quick parallel repair works so that there is one thread per index. The first of the threads rebuilds also the new data file. The problem was that all threads shared the read io cache on the old data file. If there were holes (deleted records) in the table, the first thread skipped them, writing only contiguous, non-deleted records to the new data file. Then it built the new index so that its entries pointed to the correct record positions. But the other threads didn't know the new record positions, but put the positions from the old data file into the index. The new design is so that there is a shared io cache which is filled by the first thread (the data file writer) with the new contiguous records and read by the other threads. Now they know the new record positions. Another problem was that for the parallel repair of compressed tables a common bit_buff and rec_buff was used. I changed it so that thread specific buffers are used for parallel repair. A similar problem existed for checksum calculation. I made this multi-thread safe too. include/my_sys.h: Bug#8283 - OPTIMIZE TABLE causes data loss Redesign of io_cache_share. include/myisam.h: Bug#8283 - OPTIMIZE TABLE causes data loss Redesign of checksum calculation in mi_check.c. 'calc_checksum' is now in myisamdef.h:st_mi_sort_param. myisam/mi_check.c: Bug#8283 - OPTIMIZE TABLE causes data loss Implemented a new parallel repair design. Using a synchronized shared read/write cache. Allowed for thread specific bit_buff, rec_buff, and calc_checksum. myisam/mi_open.c: Bug#8283 - OPTIMIZE TABLE causes data loss Added DBUG output. myisam/mi_packrec.c: Bug#8283 - OPTIMIZE TABLE causes data loss Allowed for thread specific bit_buff and rec_buff. myisam/myisamdef.h: Bug#8283 - OPTIMIZE TABLE causes data loss Commented on checksum calculation variables. Allowed for thread specific bit_buff. Added DBUG output for better table crash detection. myisam/sort.c: Bug#8283 - OPTIMIZE TABLE causes data loss Added implications of the new parallel repair design. Renamed 'info' -> 'sort_param'. Added DBUG output. mysql-test/r/myisam.result: Bug#8283 - OPTIMIZE TABLE causes data loss Added test results. mysql-test/t/myisam.test: Bug#8283 - OPTIMIZE TABLE causes data loss Added test cases. mysys/mf_iocache.c: Bug#8283 - OPTIMIZE TABLE causes data loss Redesign of io_cache_share. We do now allow a writer to synchronize himself with the readers of a shared cache. When all threads join in the lock, the writer copies the data from his write buffer to the shared read buffer.
This commit is contained in:
parent
868fee4dde
commit
3109da7719
10 changed files with 1134 additions and 234 deletions
|
|
@ -756,3 +756,129 @@ a b
|
|||
xxxxxxxxx bbbbbb
|
||||
xxxxxxxxx bbbbbb
|
||||
DROP TABLE t1;
|
||||
SET @@myisam_repair_threads=2;
|
||||
SHOW VARIABLES LIKE 'myisam_repair%';
|
||||
Variable_name Value
|
||||
myisam_repair_threads 2
|
||||
CREATE TABLE t1 (
|
||||
`_id` int(11) NOT NULL default '0',
|
||||
`url` text,
|
||||
`email` text,
|
||||
`description` text,
|
||||
`loverlap` int(11) default NULL,
|
||||
`roverlap` int(11) default NULL,
|
||||
`lneighbor_id` int(11) default NULL,
|
||||
`rneighbor_id` int(11) default NULL,
|
||||
`length_` int(11) default NULL,
|
||||
`sequence` mediumtext,
|
||||
`name` text,
|
||||
`_obj_class` text NOT NULL,
|
||||
PRIMARY KEY (`_id`),
|
||||
UNIQUE KEY `sequence_name_index` (`name`(50)),
|
||||
KEY (`length_`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
INSERT INTO t1 VALUES
|
||||
(1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
|
||||
(2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
|
||||
(3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
|
||||
(4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
|
||||
(5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
|
||||
(6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
|
||||
(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
|
||||
(8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
|
||||
(9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
|
||||
SELECT _id FROM t1;
|
||||
_id
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
DELETE FROM t1 WHERE _id < 8;
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
|
||||
t1 MyISAM 9 Dynamic 2 # # # # 140 # # # # # #
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
OPTIMIZE TABLE t1;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 optimize status OK
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
|
||||
t1 MyISAM 9 Dynamic 2 # # # # 0 # # # # # #
|
||||
SELECT _id FROM t1;
|
||||
_id
|
||||
8
|
||||
9
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (
|
||||
`_id` int(11) NOT NULL default '0',
|
||||
`url` text,
|
||||
`email` text,
|
||||
`description` text,
|
||||
`loverlap` int(11) default NULL,
|
||||
`roverlap` int(11) default NULL,
|
||||
`lneighbor_id` int(11) default NULL,
|
||||
`rneighbor_id` int(11) default NULL,
|
||||
`length_` int(11) default NULL,
|
||||
`sequence` mediumtext,
|
||||
`name` text,
|
||||
`_obj_class` text NOT NULL,
|
||||
PRIMARY KEY (`_id`),
|
||||
UNIQUE KEY `sequence_name_index` (`name`(50)),
|
||||
KEY (`length_`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
INSERT INTO t1 VALUES
|
||||
(1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
|
||||
(2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
|
||||
(3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
|
||||
(4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
|
||||
(5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
|
||||
(6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
|
||||
(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
|
||||
(8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
|
||||
(9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
|
||||
SELECT _id FROM t1;
|
||||
_id
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
DELETE FROM t1 WHERE _id < 8;
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
|
||||
t1 MyISAM 9 Dynamic 2 # # # # 140 # # # # # #
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
REPAIR TABLE t1 QUICK;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 repair status OK
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
Table Op Msg_type Msg_text
|
||||
test.t1 check status OK
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
|
||||
t1 MyISAM 9 Dynamic 2 # # # # 140 # # # # # #
|
||||
SELECT _id FROM t1;
|
||||
_id
|
||||
8
|
||||
9
|
||||
DROP TABLE t1;
|
||||
SET @@myisam_repair_threads=1;
|
||||
SHOW VARIABLES LIKE 'myisam_repair%';
|
||||
Variable_name Value
|
||||
myisam_repair_threads 1
|
||||
|
|
|
|||
|
|
@ -714,4 +714,97 @@ UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb';
|
|||
SELECT * FROM t1;
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Bug#8283 - OPTIMIZE TABLE causes data loss
|
||||
#
|
||||
SET @@myisam_repair_threads=2;
|
||||
SHOW VARIABLES LIKE 'myisam_repair%';
|
||||
#
|
||||
# Test OPTIMIZE. This creates a new data file.
|
||||
CREATE TABLE t1 (
|
||||
`_id` int(11) NOT NULL default '0',
|
||||
`url` text,
|
||||
`email` text,
|
||||
`description` text,
|
||||
`loverlap` int(11) default NULL,
|
||||
`roverlap` int(11) default NULL,
|
||||
`lneighbor_id` int(11) default NULL,
|
||||
`rneighbor_id` int(11) default NULL,
|
||||
`length_` int(11) default NULL,
|
||||
`sequence` mediumtext,
|
||||
`name` text,
|
||||
`_obj_class` text NOT NULL,
|
||||
PRIMARY KEY (`_id`),
|
||||
UNIQUE KEY `sequence_name_index` (`name`(50)),
|
||||
KEY (`length_`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
#
|
||||
INSERT INTO t1 VALUES
|
||||
(1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
|
||||
(2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
|
||||
(3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
|
||||
(4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
|
||||
(5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
|
||||
(6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
|
||||
(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
|
||||
(8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
|
||||
(9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
|
||||
#
|
||||
SELECT _id FROM t1;
|
||||
DELETE FROM t1 WHERE _id < 8;
|
||||
--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
OPTIMIZE TABLE t1;
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
SELECT _id FROM t1;
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Test REPAIR QUICK. This retains the old data file.
|
||||
CREATE TABLE t1 (
|
||||
`_id` int(11) NOT NULL default '0',
|
||||
`url` text,
|
||||
`email` text,
|
||||
`description` text,
|
||||
`loverlap` int(11) default NULL,
|
||||
`roverlap` int(11) default NULL,
|
||||
`lneighbor_id` int(11) default NULL,
|
||||
`rneighbor_id` int(11) default NULL,
|
||||
`length_` int(11) default NULL,
|
||||
`sequence` mediumtext,
|
||||
`name` text,
|
||||
`_obj_class` text NOT NULL,
|
||||
PRIMARY KEY (`_id`),
|
||||
UNIQUE KEY `sequence_name_index` (`name`(50)),
|
||||
KEY (`length_`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
|
||||
#
|
||||
INSERT INTO t1 VALUES
|
||||
(1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample1',''),
|
||||
(2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample2',''),
|
||||
(3,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample3',''),
|
||||
(4,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample4',''),
|
||||
(5,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample5',''),
|
||||
(6,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample6',''),
|
||||
(7,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample7',''),
|
||||
(8,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample8',''),
|
||||
(9,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'sample9','');
|
||||
#
|
||||
SELECT _id FROM t1;
|
||||
DELETE FROM t1 WHERE _id < 8;
|
||||
--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
REPAIR TABLE t1 QUICK;
|
||||
CHECK TABLE t1 EXTENDED;
|
||||
--replace_column 6 # 7 # 8 # 9 # 11 # 12 # 13 # 14 # 15 # 16 #
|
||||
SHOW TABLE STATUS LIKE 't1';
|
||||
SELECT _id FROM t1;
|
||||
DROP TABLE t1;
|
||||
#
|
||||
SET @@myisam_repair_threads=1;
|
||||
SHOW VARIABLES LIKE 'myisam_repair%';
|
||||
|
||||
# End of 4.1 tests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue