Bug #33702 accessing a federated table with a non existing server returns random error code
Submitted: 5 Jan 2008 8:55 Modified: 18 Sep 2008 6:26
Reporter: Giuseppe Maxia Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Federated storage engine Severity:S3 (Non-critical)
Version:5.1.23 OS:Any (Linux and Mac OS X)
Assigned to: Ramil Kalimullin CPU Architecture:Any
Tags: Contribution, error, federated, server

[5 Jan 2008 8:55] Giuseppe Maxia
Description:
When accessing a federated table through a non existing server, you get what looks like a random error code.
For example:

drop table if exists t1;

create table t1 (id int);

create server s1 foreign data wrapper mysql options (
database 'test', host '127.0.0.1', user 'root', password '', port 3306);

create table t1f (id int) engine=federated connection='s1/t1';

insert into t1f values (1);

select * from t1f;
+------+
| id   |
+------+
|    1 | 
+------+
1 row in set (0.00 sec)

drop server s1;
Query OK, 1 row affected (0.00 sec)

select * from t1f;
ERROR 1 (HY000): Can't create/write to file 'server name: 's1' doesn't exist!' (Errcode: 875770417)

create table t1f1 (id int) engine=federated connection='s1/t1';
ERROR 1 (HY000): Can't create/write to file 'server name: 's1' doesn't exist!' (Errcode: 1043963)

This bug affects all federated testing, because it prevents a sane test case with appropriate error checking.

How to repeat:
drop table if exists t1,t1f,t1f1;
create table t1 (id int);
create server s1 foreign data wrapper mysql options (
database 'test', host '127.0.0.1', user 'root', password '', port 3306);
create table t1f (id int) engine=federated connection='s1/t1';
insert into t1f values (1);
select * from t1f;
drop server s1;
select * from t1f;
create table t1f1 (id int) engine=federated connection='s1/t1';

Suggested fix:
No workaround.
Fix the error codes.
[5 Jan 2008 13:28] Giuseppe Maxia
This simple change to storage/federated/ha_federated.cc should solve the problem.

577c577
<     error_num=1;
---
>     error_num=ER_FOREIGN_SERVER_DOESNT_EXIST;
[7 Jan 2008 11:01] MySQL Verification Team
Thank you for the bug report.
[29 Feb 2008 11:53] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43215

ChangeSet@1.2530, 2008-02-29 15:48:48+04:00, ramil@mysql.com +3 -0
  Fix for bug #33702: accessing a federated table with a non existing server 
  returns random error code
  
  Problem: accessing a federated table through a non existing server leads to
  wrong error number returned.
  
  Fix: return a proper error.
[5 Mar 2008 10:59] Sergey Vojtovich
The patch is ok to push. But I still believe that get_connection() shouldn't report an error. Instead error code should be passed to parse_url_error() function.

That is "error" label should be removed, error code should be returned immediately after get_server_by_name().
[7 Mar 2008 15:42] Ingo Strüwing
I agree with Sergey. Your patch is correct and solves the problem. But the current approach of reporting an error in get_connection() could lead to a buffer overrun. Reporting the error through parse_url_error() would fix it. Also the error message would not repeat "does not exist" in English language. OTOH this is unreleated to the reported problem. Sergey usually opposes against fixing unrelated issues.

For the records: I did not find any use of ER_FOREIGN_SERVER_DOESNT_EXIST in the test suite. parse_url_error() is probably untested. And hence parse_url() is poorly tested.
[15 Aug 2008 12:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/51726

2768 Ramil Kalimullin	2008-08-15
        Fix for bug #33702: accessing a federated table with a non existing server 
        returns random error code
        
        Problem: accessing a federated table through a non existing server leads to
        wrong error number returned.
        
        Fix: return a proper error.
[13 Sep 2008 19:46] Bugs System
Pushed into 6.0.6-alpha  (revid:ramil@mysql.com-20080815122632-udl05gwcqjrgh47e) (version source revid:sergefp@mysql.com-20080611231653-nmuqmw6dedjra79i) (pib:3)
[18 Sep 2008 6:26] Paul DuBois
Noted in 6.0.6 changelog.

Attempts to access a FEDERATED table using a non-existent server did
not reliably return a proper error.
[29 Jan 2010 22:08] MySQL Verification Team
for the record, this bug still affects 5.1.42 and 5.5.99-m3:

Server version: 5.5.99-m3-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create table `t1_fed`(`a` int not null) engine=federated;
ERROR 1 (HY000): Can't create/write to file 'server name: '' doesn't exist!' (Errcode: 82505120)
mysql>
[10 Jul 2012 20:15] Elena Stepanova
.. and in 5.6, too:

Version: '5.6.6-m9-debug-log'

Warnings from just before the error:
Error 1 server name: 'connect_string' doesn't exist! 
Error 1 Can't create/write to file 'connect_string' (Errcode: 58905942 - }O)
[10 Jul 2012 20:15] Elena Stepanova
.. and in 5.6, too:

Version: '5.6.6-m9-debug-log'

Warnings from just before the error:
Error 1 server name: 'connect_string' doesn't exist! 
Error 1 Can't create/write to file 'connect_string' (Errcode: 58905942 - }O)
[10 Jul 2012 20:19] Elena Stepanova
Sorry for the duplicate, blame the new captcha system which is barely passable for a living being (and is apparently glitchy, too)