From fd76746234b480ce386e335533eefdab92795022 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 7 May 2024 13:49:17 +1000 Subject: [PATCH] MDEV-28105 Return error in ha_spider::write_row() if info(HA_STATUS_AUTO) fails Spider calls info with HA_STATUS_AUTO to update auto increment info, which may attempt to connect the data node. If the connection fails, it may emit an error and return the same error. This error should not be of lower priority than any possible error from the later call to handler::update_auto_increment(). Without this change, certain errors from update_auto_increment() such as HA_ERR_AUTOINC_ERANGE may get ignored, causing my_insert() to call my_ok(), which fails the assertion because the error was emitted in the info() call (Diagnostics_area::is_set() returns true). --- storage/spider/ha_spider.cc | 19 ++++++------------- .../spider/bugfix/r/mdev_28105.result | 10 ++++++++++ .../mysql-test/spider/bugfix/t/mdev_28105.opt | 1 + .../spider/bugfix/t/mdev_28105.test | 8 ++++++++ 4 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 storage/spider/mysql-test/spider/bugfix/r/mdev_28105.result create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28105.opt create mode 100644 storage/spider/mysql-test/spider/bugfix/t/mdev_28105.test diff --git a/storage/spider/ha_spider.cc b/storage/spider/ha_spider.cc index 997f57ab6c8..31498328535 100644 --- a/storage/spider/ha_spider.cc +++ b/storage/spider/ha_spider.cc @@ -9396,18 +9396,6 @@ int ha_spider::update_auto_increment() DBUG_ENTER("ha_spider::update_auto_increment"); DBUG_PRINT("info",("spider this=%p", this)); force_auto_increment = TRUE; -/* - if ( - next_insert_id >= auto_inc_interval_for_cur_row.maximum() && - wide_handler->trx->thd->auto_inc_intervals_forced.get_current() - ) { - force_auto_increment = TRUE; - DBUG_PRINT("info",("spider force_auto_increment=TRUE")); - } else { - force_auto_increment = FALSE; - DBUG_PRINT("info",("spider force_auto_increment=FALSE")); - } -*/ DBUG_PRINT("info",("spider auto_increment_mode=%d", auto_increment_mode)); DBUG_PRINT("info",("spider next_number_field=%lld", @@ -9662,7 +9650,12 @@ int ha_spider::write_row( pthread_mutex_lock(&share->lgtm_tblhnd_share->auto_increment_mutex); if (!share->lgtm_tblhnd_share->auto_increment_init) { - info(HA_STATUS_AUTO); + if ((error_num= info(HA_STATUS_AUTO))) + { + pthread_mutex_unlock( + &share->lgtm_tblhnd_share->auto_increment_mutex); + DBUG_RETURN(error_num); + } share->lgtm_tblhnd_share->auto_increment_lclval = stats.auto_increment_value; share->lgtm_tblhnd_share->auto_increment_init = TRUE; diff --git a/storage/spider/mysql-test/spider/bugfix/r/mdev_28105.result b/storage/spider/mysql-test/spider/bugfix/r/mdev_28105.result new file mode 100644 index 00000000000..1932f6b2624 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/mdev_28105.result @@ -0,0 +1,10 @@ +install soname 'ha_spider'; +Warnings: +Warning 1105 Cannot enable tc-log at run-time. XA features of SPIDER are disabled +SET @@insert_id=128; +CREATE TABLE t(c TINYINT AUTO_INCREMENT KEY) ENGINE=Spider; +INSERT IGNORE INTO t VALUES(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_28105.opt b/storage/spider/mysql-test/spider/bugfix/t/mdev_28105.opt new file mode 100644 index 00000000000..789275fa25e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28105.opt @@ -0,0 +1 @@ +--skip-log-bin diff --git a/storage/spider/mysql-test/spider/bugfix/t/mdev_28105.test b/storage/spider/mysql-test/spider/bugfix/t/mdev_28105.test new file mode 100644 index 00000000000..219835075ba --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/mdev_28105.test @@ -0,0 +1,8 @@ +install soname 'ha_spider'; +SET @@insert_id=128; # 127 does not crash +CREATE TABLE t(c TINYINT AUTO_INCREMENT KEY) ENGINE=Spider; +--error ER_CONNECT_TO_FOREIGN_DATA_SOURCE +INSERT IGNORE INTO t VALUES(0); +drop table t; +--disable_query_log +--source ../../include/clean_up_spider.inc