From 042a0d85ad4f96229ab440cadb4ad3842c928c47 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 9 May 2024 10:28:55 +1000 Subject: [PATCH] MDEV-27186 spider/partition: Report error on info() failure Like MDEV-28105, spider may attempt to connect to remote server in info(), and it may emit an error upon failure to connect. In this case, the downstream caller ha_partition::open() should return the error to avoid inconsistency. This fixes MDEV-27186, MDEV-27237, MDEV-27334, MDEV-28241, MDEV-34101. --- sql/ha_partition.cc | 3 +- .../spider/bugfix/r/mdev_27186.result | 36 ++++++++++++++++++ .../mysql-test/spider/bugfix/t/mdev_27186.opt | 1 + .../spider/bugfix/t/mdev_27186.test | 37 +++++++++++++++++++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 735d5c4442d..0d2abc7d860 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3854,7 +3854,8 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) m_part_info->part_expr->get_monotonicity_info(); else if (m_part_info->list_of_part_fields) m_part_func_monotonicity_info= MONOTONIC_STRICT_INCREASING; - info(HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_OPEN); + if ((error= info(HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_OPEN))) + goto err_handler; DBUG_RETURN(0); err_handler: diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result new file mode 100644 index 00000000000..2b88b5da34c --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_27186.result @@ -0,0 +1,36 @@ +INSTALL SONAME 'ha_spider'; +Warnings: +Warning 1105 Cannot enable tc-log at run-time. XA features of SPIDER are disabled +CREATE TABLE t (s INT) ENGINE=SPIDER PARTITION BY HASH (s); +LOAD INDEX INTO CACHE t PARTITION (p,p1); +Table Op Msg_type Msg_text +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys Error Unable to connect to foreign data source: localhost +test.t preload_keys error Corrupt +DROP TABLE t; +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY KEY() PARTITIONS 2; +HANDLER t OPEN AS h; +ERROR HY000: Unable to connect to foreign data source: localhost +DROP TABLE t; +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY HASH (c) PARTITIONS 2; +CREATE TRIGGER t AFTER INSERT ON t FOR EACH ROW INSERT INTO t VALUES(0); +ERROR HY000: Unable to connect to foreign data source: localhost +DROP TABLE t; +CREATE TABLE t (b INT) ENGINE=InnoDB; +PREPARE s FROM 'SELECT * FROM t LIMIT 2'; +DROP TABLE t; +CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3)); +EXECUTE s; +ERROR HY000: Unable to connect to foreign data source: localhost +DROP TABLE t; +CREATE TABLE t (c INT) ENGINE=InnoDB; +LOCK TABLES t WRITE; +CREATE OR REPLACE TABLE t (d INT) ENGINE=Spider PARTITION BY LIST COLUMNS (d) (PARTITION p VALUES IN (0)); +ERROR HY000: Unable to connect to foreign data source: localhost +drop table t; +Warnings: +Warning 1620 Plugin is busy and will be uninstalled on shutdown diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt new file mode 100644 index 00000000000..789275fa25e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.opt @@ -0,0 +1 @@ +--skip-log-bin diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test new file mode 100644 index 00000000000..67c038009ba --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_27186.test @@ -0,0 +1,37 @@ +INSTALL SONAME 'ha_spider'; + +# MDEV-27186 +CREATE TABLE t (s INT) ENGINE=SPIDER PARTITION BY HASH (s); +LOAD INDEX INTO CACHE t PARTITION (p,p1); +DROP TABLE t; + +# MDEV-27237 +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY KEY() PARTITIONS 2; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +HANDLER t OPEN AS h; +DROP TABLE t; + +# MDEV-27334 +CREATE TABLE t (c INT PRIMARY KEY) ENGINE=SPIDER PARTITION BY HASH (c) PARTITIONS 2; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +CREATE TRIGGER t AFTER INSERT ON t FOR EACH ROW INSERT INTO t VALUES(0); +DROP TABLE t; + +# MDEV-28241 +CREATE TABLE t (b INT) ENGINE=InnoDB; +PREPARE s FROM 'SELECT * FROM t LIMIT 2'; +DROP TABLE t; +CREATE TABLE t (a INT) ENGINE=Spider PARTITION BY LIST (a) PARTITIONS 2 (PARTITION p1 VALUES IN (0,1),PARTITION p2 VALUES IN (2,3)); +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +EXECUTE s; +DROP TABLE t; + +# MDEV-34101 +CREATE TABLE t (c INT) ENGINE=InnoDB; +LOCK TABLES t WRITE; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +CREATE OR REPLACE TABLE t (d INT) ENGINE=Spider PARTITION BY LIST COLUMNS (d) (PARTITION p VALUES IN (0)); +drop table t; + +--disable_query_log +--source ../../include/clean_up_spider.inc