Skip to content

Commit 698dae5

Browse files
MDEV-31475 Spider: only reset wide_handler when owning it
A wide_handler is shared among ha_spider of partitions of the same spider table, where the last partition is designated the owner of the wide_handler, and is responsible for its deallocation. Therefore in case of failure, we only reset wide_handler in error handling if the current ha_spider is the owner of the wide_handler, otherwise it will result in segv in the destructor of ha_spider, or during ha_spider::close().
1 parent 86adee3 commit 698dae5

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

storage/spider/ha_spider.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ int ha_spider::open(
614614
owner->wide_handler = NULL;
615615
owner->wide_handler_owner = FALSE;
616616
}
617-
wide_handler = NULL;
617+
if (!wide_handler_owner)
618+
wide_handler = NULL;
618619
error_wide_handler_alloc:
619620
DBUG_RETURN(error_num);
620621
}

storage/spider/ha_spider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class ha_spider final : public handler
9494
#ifdef WITH_PARTITION_STORAGE_ENGINE
9595
SPIDER_PARTITION_HANDLER *partition_handler;
9696
#endif
97+
/* Whether this ha_spider is the owner of its wide_handler. */
9798
bool wide_handler_owner = FALSE;
9899
SPIDER_WIDE_HANDLER *wide_handler = NULL;
99100

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
for master_1
2+
for child2
3+
for child3
4+
CREATE TABLE t3 (c1 MEDIUMINT NULL, c2 CHAR(5)) ENGINE=Spider PARTITION BY KEY(c1) PARTITIONS 2;
5+
ALTER TABLE t3 DROP PRIMARY KEY;
6+
ERROR 42000: Can't DROP INDEX `PRIMARY`; check that it exists
7+
SELECT * FROM t3 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2;
8+
ERROR HY000: Unable to connect to foreign data source: localhost
9+
CREATE TABLE t1 (a INT UNSIGNED NOT NULL PRIMARY KEY, b INT UNSIGNED NOT NULL, c INT UNSIGNED, UNIQUE (b, c) USING HASH) ENGINE=Spider;
10+
SELECT t1.c1 FROM t3 RIGHT JOIN t1 ON t1.c1=current_date() UNION SELECT t1.c2 FROM t1 LEFT OUTER JOIN t3 ON t1.c2;
11+
ERROR HY000: Unable to connect to foreign data source: localhost
12+
drop table t1, t3;
13+
set spider_same_server_link= 1;
14+
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
15+
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
16+
CREATE TABLE t1 (a INT, b VARCHAR(255), PRIMARY KEY(a)) ENGINE=Spider PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN (3), PARTITION p2 VALUES LESS THAN MAXVALUE COMMENT='srv "srv"');
17+
DROP SERVER srv;
18+
SELECT * FROM t1;
19+
ERROR HY000: The foreign server name you are trying to reference does not exist. Data source error: srv
20+
drop table t1;
21+
for master_1
22+
for child2
23+
for child3
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--disable_query_log
2+
--disable_result_log
3+
--source ../../t/test_init.inc
4+
--enable_result_log
5+
--enable_query_log
6+
7+
# test 1
8+
CREATE TABLE t3 (c1 MEDIUMINT NULL, c2 CHAR(5)) ENGINE=Spider PARTITION BY KEY(c1) PARTITIONS 2;
9+
--error ER_CANT_DROP_FIELD_OR_KEY
10+
ALTER TABLE t3 DROP PRIMARY KEY;
11+
--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
12+
SELECT * FROM t3 WHERE c1 <=> '1000-00-01 00:00:00' ORDER BY c1,c2 LIMIT 2;
13+
CREATE TABLE t1 (a INT UNSIGNED NOT NULL PRIMARY KEY, b INT UNSIGNED NOT NULL, c INT UNSIGNED, UNIQUE (b, c) USING HASH) ENGINE=Spider;
14+
--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE
15+
SELECT t1.c1 FROM t3 RIGHT JOIN t1 ON t1.c1=current_date() UNION SELECT t1.c2 FROM t1 LEFT OUTER JOIN t3 ON t1.c2;
16+
drop table t1, t3;
17+
18+
# test 2
19+
set spider_same_server_link= 1;
20+
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
21+
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
22+
CREATE TABLE t1 (a INT, b VARCHAR(255), PRIMARY KEY(a)) ENGINE=Spider PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN (3), PARTITION p2 VALUES LESS THAN MAXVALUE COMMENT='srv "srv"');
23+
DROP SERVER srv;
24+
--error 1477
25+
SELECT * FROM t1;
26+
drop table t1;
27+
28+
--disable_query_log
29+
--disable_result_log
30+
--source ../../t/test_deinit.inc
31+
--enable_result_log
32+
--enable_query_log

storage/spider/spd_include.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,10 @@ enum spider_hnd_stage {
879879
SPD_HND_STAGE_CLEAR_TOP_TABLE_FIELDS
880880
};
881881

882+
/*
883+
A wide handler is shared among ha_spider of partitions of the same
884+
table. It is owned by the last partition.
885+
*/
882886
typedef struct st_spider_wide_handler
883887
{
884888
spider_hnd_stage stage;

0 commit comments

Comments
 (0)