Skip to content

Commit 0be6930

Browse files
committed
MDEV-39196: SELECT from information schema fails when FederatedX loses underlying table
When a remote table is unavailable, FederatedX was passing a hard error back to the SQL layer, causing INFORMATION_SCHEMA queries to abort entirely. This patch intercepts the remote error in ha_federatedx::info, downgrades it to a warning using push_warning_printf, and includes the local table name in the warning message so the user knows which table is inaccessible. Signed-off-by: Anway Durge <124391429+itzanway@users.noreply.github.com>
1 parent b4bc43e commit 0be6930

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# MDEV-39196: INFORMATION_SCHEMA query must succeed with a
3+
# warning when a FederatedX remote table is unreachable.
4+
#
5+
# Verify the federated table works before dropping remote table.
6+
SELECT * FROM federated.t1;
7+
id name
8+
1 foo
9+
# Drop the remote table to simulate unreachable/missing table.
10+
# INFORMATION_SCHEMA query must succeed and issue a warning.
11+
SELECT TABLE_NAME, TABLE_ROWS
12+
FROM information_schema.TABLES
13+
WHERE TABLE_SCHEMA = 'federated'
14+
AND TABLE_NAME = 't1';
15+
TABLE_NAME TABLE_ROWS
16+
t1 NULL
17+
# Warning must be present.
18+
SHOW WARNINGS;
19+
Level Code Message
20+
Warning 1296 FederatedX: Table 't1' is inaccessible: 1146 : Table 'federated.t1' doesn't exist
21+
# Cleanup.
22+
DROP TABLE IF EXISTS federated.t1;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# MDEV-39196: SELECT from information_schema fails when FederatedX
2+
# loses underlying table.
3+
--source include/not_embedded.inc
4+
--source include/federated.inc
5+
6+
--echo #
7+
--echo # MDEV-39196: INFORMATION_SCHEMA query must succeed with a
8+
--echo # warning when a FederatedX remote table is unreachable.
9+
--echo #
10+
11+
--connection slave
12+
CREATE TABLE federated.t1 (
13+
id INT NOT NULL,
14+
name VARCHAR(64)
15+
) ENGINE=MyISAM;
16+
INSERT INTO federated.t1 VALUES (1, 'foo');
17+
18+
--connection master
19+
--replace_result $SLAVE_MYPORT SLAVE_PORT
20+
eval CREATE TABLE federated.t1 (
21+
id INT NOT NULL,
22+
name VARCHAR(64)
23+
) ENGINE=FEDERATED
24+
CONNECTION='mysql://root@127.0.0.1:$SLAVE_MYPORT/federated/t1';
25+
26+
--echo # Verify the federated table works before dropping remote table.
27+
SELECT * FROM federated.t1;
28+
29+
--echo # Drop the remote table to simulate unreachable/missing table.
30+
--connection slave
31+
DROP TABLE federated.t1;
32+
33+
--connection master
34+
--echo # INFORMATION_SCHEMA query must succeed and issue a warning.
35+
SELECT TABLE_NAME, TABLE_ROWS
36+
FROM information_schema.TABLES
37+
WHERE TABLE_SCHEMA = 'federated'
38+
AND TABLE_NAME = 't1';
39+
40+
--echo # Warning must be present.
41+
SHOW WARNINGS;
42+
43+
--echo # Cleanup.
44+
DROP TABLE IF EXISTS federated.t1;
45+
46+
--source include/federated_cleanup.inc

storage/federatedx/ha_federatedx.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3130,8 +3130,34 @@ int ha_federatedx::info(uint flag)
31303130
error:
31313131
if (iop && *iop)
31323132
{
3133-
my_printf_error((*iop)->error_code(), "Received error: %d : %s", MYF(0),
3134-
(*iop)->error_code(), (*iop)->error_str());
3133+
uint remote_err= (uint)(*iop)->error_code();
3134+
/*
3135+
Only downgrade to a warning for errors that mean the remote server
3136+
or table is temporarily unreachable (connection failure, table
3137+
dropped on remote side). All other errors including access-denied
3138+
must remain hard errors so callers receive the correct errno.
3139+
*/
3140+
switch (remote_err)
3141+
{
3142+
case 2002: /* CR_CONNECTION_ERROR - can't connect via socket */
3143+
case 2003: /* CR_CONN_HOST_ERROR - can't connect to host */
3144+
case 2005: /* CR_UNKNOWN_HOST - unknown host */
3145+
case 2006: /* CR_SERVER_GONE_ERROR - server has gone away */
3146+
case 2013: /* CR_SERVER_LOST - lost connection during query */
3147+
case 1146: /* ER_NO_SUCH_TABLE - remote table dropped */
3148+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
3149+
ER_QUERY_ON_FOREIGN_DATA_SOURCE,
3150+
"FederatedX: Table '%s' is inaccessible: "
3151+
"%d : %s",
3152+
share->table_name,
3153+
(*iop)->error_code(),
3154+
(*iop)->error_str());
3155+
error_code= 0;
3156+
break;
3157+
default:
3158+
error_code= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
3159+
break;
3160+
}
31353161
}
31363162
else if (remote_error_number != -1 /* error already reported */)
31373163
{

0 commit comments

Comments
 (0)