Skip to content

Commit 10f08af

Browse files
committed
Added support for CHECK TABLE for S3 tables
Other things: - Don't allocate an IO_CACHE for scanning tables of type BLOCK (It was never used in this case) - Fixed bug in page cache that cased a hang when trying to read a not existing S3 block.
1 parent 49ae199 commit 10f08af

File tree

7 files changed

+54
-30
lines changed

7 files changed

+54
-30
lines changed

mysql-test/suite/s3/basic.result

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ drop table if exists t1;
22
#
33
# Test simple create of s3 table
44
#
5-
create or replace table t1 (a int, b int, key (a)) engine=aria;
6-
insert into t1 select seq,seq+10 from seq_1_to_10000;
5+
create or replace table t1 (a int, b int, c varchar(1000), key (a), key(c)) engine=aria;
6+
insert into t1 select seq, seq+10, repeat(char(65+ mod(seq, 20)),mod(seq,1000)) from seq_1_to_10000;
77
alter table t1 engine=s3;
88
show create table t1;
99
Table Create Table
1010
t1 CREATE TABLE `t1` (
1111
`a` int(11) DEFAULT NULL,
1212
`b` int(11) DEFAULT NULL,
13-
KEY `a` (`a`)
13+
`c` varchar(1000) DEFAULT NULL,
14+
KEY `a` (`a`),
15+
KEY `c` (`c`)
1416
) ENGINE=S3 DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
1517
select * from information_schema.tables where table_schema="database" and table_name="t1";;
1618
TABLE_CATALOG TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE VERSION ROW_FORMAT TABLE_ROWS AVG_ROW_LENGTH DATA_LENGTH MAX_DATA_LENGTH INDEX_LENGTH DATA_FREE AUTO_INCREMENT CREATE_TIME UPDATE_TIME CHECK_TIME TABLE_COLLATION CHECKSUM CREATE_OPTIONS TABLE_COMMENT MAX_INDEX_LENGTH TEMPORARY
17-
def # t1 BASE TABLE S3 10 Page 10000 33 335872 # 122880 0 NULL # # # latin1_swedish_ci NULL page_checksum=1 9007199254732800 #
19+
def # t1 BASE TABLE S3 10 Page 10000 567 5677056 # 761856 0 NULL # # # latin1_swedish_ci NULL page_checksum=1 2305843009213685760 #
1820
show table status like "t1";
1921
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 Max_index_length Temporary
20-
t1 S3 10 Page 10000 33 335872 # 122880 0 NULL # # # latin1_swedish_ci NULL page_checksum=1 # N
21-
select * from t1 limit 10;
22+
t1 S3 10 Page 10000 567 5677056 # 761856 0 NULL # # # latin1_swedish_ci NULL page_checksum=1 # N
23+
select a,b from t1 limit 10;
2224
a b
2325
1 11
2426
2 12
@@ -33,7 +35,7 @@ a b
3335
select count(*) from t1;
3436
count(*)
3537
10000
36-
select * from t1 where a between 10 and 20;
38+
select a,b from t1 where a between 10 and 20;
3739
a b
3840
10 20
3941
11 21
@@ -60,9 +62,15 @@ ERROR HY000: Table 't1' is read only
6062
#
6163
set @@use_stat_tables='never';
6264
truncate mysql.table_stats;
63-
check table t1;
65+
check table t1 fast;
6466
Table Op Msg_type Msg_text
65-
database.t1 check status Table 'database.t1' is read only
67+
database.t1 check status Table is already up to date
68+
check table t1 quick;
69+
Table Op Msg_type Msg_text
70+
database.t1 check status OK
71+
check table t1 extended;
72+
Table Op Msg_type Msg_text
73+
database.t1 check status OK
6674
analyze table t1;
6775
Table Op Msg_type Msg_text
6876
database.t1 analyze status Table 'database.t1' is read only
@@ -91,9 +99,11 @@ Table Create Table
9199
t1 CREATE TABLE `t1` (
92100
`a` int(11) DEFAULT NULL,
93101
`b` int(11) DEFAULT NULL,
94-
KEY `a` (`a`)
102+
`c` varchar(1000) DEFAULT NULL,
103+
KEY `a` (`a`),
104+
KEY `c` (`c`)
95105
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
96-
select * from t1 limit 10;
106+
select a,b from t1 limit 10;
97107
a b
98108
1 11
99109
2 12

mysql-test/suite/s3/basic.test

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ drop table if exists t1;
1313
--echo # Test simple create of s3 table
1414
--echo #
1515

16-
create or replace table t1 (a int, b int, key (a)) engine=aria;
17-
insert into t1 select seq,seq+10 from seq_1_to_10000;
16+
create or replace table t1 (a int, b int, c varchar(1000), key (a), key(c)) engine=aria;
17+
insert into t1 select seq, seq+10, repeat(char(65+ mod(seq, 20)),mod(seq,1000)) from seq_1_to_10000;
1818
alter table t1 engine=s3;
1919
show create table t1;
2020

@@ -23,9 +23,9 @@ show create table t1;
2323
--eval select * from information_schema.tables where table_schema="$database" and table_name="t1";
2424
--replace_column 8 # 12 # 13 # 14 # 19 #
2525
show table status like "t1";
26-
select * from t1 limit 10;
26+
select a,b from t1 limit 10;
2727
select count(*) from t1;
28-
select * from t1 where a between 10 and 20;
28+
select a,b from t1 where a between 10 and 20;
2929
--replace_column 9 #
3030
explain select * from t1 where a between 10 and 20;
3131
--error ER_OPEN_AS_READONLY
@@ -43,7 +43,11 @@ delete from t1 where a>10;
4343
set @@use_stat_tables='never';
4444
truncate mysql.table_stats;
4545
--replace_result $database database
46-
check table t1;
46+
check table t1 fast;
47+
--replace_result $database database
48+
check table t1 quick;
49+
--replace_result $database database
50+
check table t1 extended;
4751
--replace_result $database database
4852
analyze table t1;
4953
--replace_result $database database
@@ -61,7 +65,7 @@ select * from mysql.table_stats;
6165

6266
alter table t1 engine=aria;
6367
show create table t1;
64-
select * from t1 limit 10;
68+
select a,b from t1 limit 10;
6569
select count(*) from t1;
6670
delete from t1 where a=1;
6771
drop table t1;

mysql-test/suite/s3/partition.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ count(*)
6464
6
6565
ALTER TABLE t2 CHECK PARTITION p3;
6666
Table Op Msg_type Msg_text
67-
s3.t2 check status Table 's3.t2' is read only
67+
s3.t2 check status OK
6868
SELECT count(*) FROM t2;
6969
count(*)
7070
6

storage/maria/ha_maria.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
12701270
if (!file || !param) return HA_ADMIN_INTERNAL_ERROR;
12711271

12721272
unmap_file(file);
1273+
register_handler(file);
12731274
maria_chk_init(param);
12741275
param->thd= thd;
12751276
param->op_name= "check";
@@ -1325,14 +1326,18 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
13251326
{
13261327
ulonglong old_testflag= param->testflag;
13271328
param->testflag |= T_MEDIUM;
1328-
if (!(error= init_io_cache(&param->read_cache, file->dfile.file,
1329-
my_default_record_cache_size, READ_CACHE,
1330-
share->pack.header_length, 1, MYF(MY_WME))))
1331-
{
1329+
1330+
/* BLOCK_RECORD does not need a cache as it is using the page cache */
1331+
if (file->s->data_file_type != BLOCK_RECORD)
1332+
error= init_io_cache(&param->read_cache, file->dfile.file,
1333+
my_default_record_cache_size, READ_CACHE,
1334+
share->pack.header_length, 1, MYF(MY_WME));
1335+
if (!error)
13321336
error= maria_chk_data_link(param, file,
13331337
MY_TEST(param->testflag & T_EXTEND));
1338+
1339+
if (file->s->data_file_type != BLOCK_RECORD)
13341340
end_io_cache(&param->read_cache);
1335-
}
13361341
param->testflag= old_testflag;
13371342
}
13381343
}

storage/maria/ha_s3.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ class ha_s3 final :public ha_maria
4444
DBUG_ENTER("delete_row");
4545
DBUG_RETURN(HA_ERR_TABLE_READONLY);
4646
}
47-
int check(THD *, HA_CHECK_OPT *) override
48-
{
49-
DBUG_ENTER("check");
50-
DBUG_RETURN(HA_ERR_TABLE_READONLY);
51-
}
5247
int analyze(THD *, HA_CHECK_OPT *) override
5348
{
5449
DBUG_ENTER("analyze");

storage/maria/ma_check.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ int maria_chk_size(HA_CHECK *param, register MARIA_HA *info)
413413
char buff[22],buff2[22];
414414
DBUG_ENTER("maria_chk_size");
415415

416+
if (info->s3)
417+
{
418+
/* We cannot check file sizes for S3 */
419+
DBUG_RETURN(0);
420+
}
421+
416422
if (!(param->testflag & T_SILENT))
417423
puts("- check file-size");
418424

storage/maria/ma_pagecache.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,7 +2772,7 @@ static my_bool make_lock_and_pin(PAGECACHE *pagecache,
27722772

27732773
#ifdef WITH_S3_STORAGE_ENGINE
27742774
static void read_big_block(PAGECACHE *pagecache,
2775-
PAGECACHE_BLOCK_LINK *block)
2775+
PAGECACHE_BLOCK_LINK *block)
27762776
{
27772777
int page_st;
27782778
size_t big_block_size_in_pages;
@@ -2810,6 +2810,11 @@ static void read_big_block(PAGECACHE *pagecache,
28102810
if (block_to_read->status & PCBLOCK_ERROR)
28112811
{
28122812
/* We get first block with an error so all operation failed */
2813+
DBUG_PRINT("error", ("Got error when reading first page"));
2814+
block->status|= PCBLOCK_ERROR;
2815+
block->error= block_to_read->error;
2816+
remove_reader(block_to_read);
2817+
unreg_request(pagecache, block_to_read, 1);
28132818
DBUG_VOID_RETURN;
28142819
}
28152820
if (block_to_read->status & PCBLOCK_BIG_READ)
@@ -3952,7 +3957,6 @@ void pagecache_set_write_on_delete_by_link(PAGECACHE_BLOCK_LINK *block)
39523957
39533958
@retval 0 deleted or was not present at all
39543959
@retval 1 error
3955-
39563960
*/
39573961

39583962
static my_bool pagecache_delete_internal(PAGECACHE *pagecache,

0 commit comments

Comments
 (0)