Bug #33702 accessing a federated table with a non existing server returns random error code
Submitted: 5 Jan 2008 9:55 Modified: 18 Sep 2008 8:26
Reporter: Giuseppe Maxia
Status: Closed
Category:Server: Federated Severity:S3 (Non-critical)
Version:5.1.23 OS:Any (Linux and Mac OS X)
Assigned to: Ramil Kalimullin Target Version:
Tags: Contribution, error, server, federated
Triage: D4 (Minor)

[5 Jan 2008 9: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 14: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 12:01] Miguel Solorzano
Thank you for the bug report.
[29 Feb 2008 12: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 11: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 16: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 14: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 21: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 8: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.