Commit e199c7cd authored by Christopher Powers's avatar Christopher Powers

Bug#35333, "If Federated table can't connect to remote host, can't retrieve metadata"

Improved error handling such that queries against Information_Schema.Tables won't
fail if a Federated table is unable to connect to remote host.



sql/sql_show.cc:
  If Handler::Info() fails, save error text in TABLE COMMENTS column, clear error.
parent e9cb1469
#
# Bug 35333 "If a Federated table can't connect to the remote hose, can't retrieve metadata"
#
# Queries such as SHOW TABLE STATUS and SELECT * FROM INFORMATION_SCHEMA.TABLES fail
# when encountering a federated table that cannot connect to its remote table.
#
# The fix is to store the error text in the TABLE COMMENTS column of I_S.TABLES, clear
# the remote connection error and push a warning instead. This allows the SELECT operation
# to complete while still indicating a problem. This fix applies to any non-fatal system
# error that occurs during a query against I_S.TABLES.de
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
stop slave;
DROP DATABASE IF EXISTS federated;
CREATE DATABASE federated;
DROP DATABASE IF EXISTS federated;
CREATE DATABASE federated;
CREATE DATABASE IF NOT EXISTS realdb;
DROP TABLE IF EXISTS realdb.t0;
DROP TABLE IF EXISTS federated.t0;
#
# Create the base table to be referenced
#
CREATE TABLE realdb.t0 (a text, b text) ENGINE=MYISAM;
#
# Create a federated table with a bogus port number
#
CREATE TABLE federated.t0 (a text, b text) ENGINE=FEDERATED
CONNECTION='mysql://root@127.0.0.1:63333/realdb/t0';
#
# Trigger a federated system error during a INFORMATION_SCHEMA.TABLES query
#
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'realdb' or TABLE_SCHEMA = 'federated';
TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE ROW_FORMAT TABLE_ROWS DATA_LENGTH TABLE_COMMENT
federated t0 NULL NULL NULL NULL Unable to connect to foreign data source: Can't connect to MySQL server on '127.
realdb t0 BASE TABLE MyISAM Dynamic 0 0
Warnings:
Warning 1429 Unable to connect to foreign data source: Can't connect to MySQL server on '127.0.0.1' (socket errno)
SHOW WARNINGS;
Level Code Message
Warning 1429 Unable to connect to foreign data source: Can't connect to MySQL server on '127.0.0.1' (socket errno)
#
# Create a MyISAM table then corrupt the file
#
USE realdb;
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
#
# Corrupt the MyISAM table by deleting the base file
#
#
# Trigger a MyISAM system error during an INFORMATION_SCHEMA.TABLES query
#
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
TABLE_SCHEMA TABLE_NAME TABLE_TYPE ENGINE ROW_FORMAT TABLE_ROWS DATA_LENGTH TABLE_COMMENT
realdb t1 BASE TABLE NULL NULL NULL NULL Can't find file: 't1' (errno: 2)
Warnings:
Warning 1017 Can't find file: 't1' (errno: 2)
SHOW WARNINGS;
Level Code Message
Warning 1017 Can't find file: 't1' (errno: 2)
#
# Cleanup
#
DROP TABLE IF EXISTS realdb.t0;
DROP TABLE IF EXISTS federated.t0;
DROP DATABASE realdb;
DROP TABLE IF EXISTS federated.t1;
DROP DATABASE IF EXISTS federated;
DROP TABLE IF EXISTS federated.t1;
DROP DATABASE IF EXISTS federated;
......@@ -1053,6 +1053,8 @@ select table_type from information_schema.tables
where table_name="v1";
table_type
VIEW
Warnings:
Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop view v1;
create temporary table t1(f1 int, index(f1));
show columns from t1;
......
......@@ -65,10 +65,14 @@ select table_name, table_type, table_comment from information_schema.tables
where table_schema='inf%' and func2();
table_name table_type table_comment
v1 VIEW View 'inf%.v1' references invalid table(s) or column(s) or function(s) or define
Warnings:
Warning 1356 View 'inf%.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
select table_name, table_type, table_comment from information_schema.tables
where table_schema='inf%' and func2();
table_name table_type table_comment
v1 VIEW View 'inf%.v1' references invalid table(s) or column(s) or function(s) or define
Warnings:
Warning 1356 View 'inf%.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop view v1;
drop function func1;
drop function func2;
......
......@@ -622,6 +622,8 @@ flush tables;
SHOW TABLE STATUS like 't1';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 NULL NULL NULL NULL # # # # NULL NULL NULL NULL NULL NULL NULL NULL Incorrect information in file: './test/t1.frm'
Warnings:
Warning 1033 Incorrect information in file: './test/t1.frm'
show create table t1;
ERROR HY000: Incorrect information in file: './test/t1.frm'
drop table t1;
......
......@@ -840,6 +840,8 @@ show table status;
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 MyISAM 10 Fixed 0 0 0 # 1024 0 NULL # # NULL latin1_swedish_ci NULL
v1 NULL NULL NULL NULL NULL NULL # NULL NULL NULL # # NULL NULL NULL NULL View 'test.v1' references invalid table(s) or column(s) or function(s) or define
Warnings:
Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
drop view v1;
drop table t1;
create view v1 as select 99999999999999999999999999999999999999999999999999999 as col1;
......
--echo #
--echo # Bug 35333 "If a Federated table can't connect to the remote hose, can't retrieve metadata"
--echo #
--echo # Queries such as SHOW TABLE STATUS and SELECT * FROM INFORMATION_SCHEMA.TABLES fail
--echo # when encountering a federated table that cannot connect to its remote table.
--echo #
--echo # The fix is to store the error text in the TABLE COMMENTS column of I_S.TABLES, clear
--echo # the remote connection error and push a warning instead. This allows the SELECT operation
--echo # to complete while still indicating a problem. This fix applies to any non-fatal system
--echo # error that occurs during a query against I_S.TABLES.de
--source include/federated.inc
--disable_warnings
CREATE DATABASE IF NOT EXISTS realdb;
# Federated database exists
DROP TABLE IF EXISTS realdb.t0;
DROP TABLE IF EXISTS federated.t0;
--enable_warnings
--echo #
--echo # Create the base table to be referenced
--echo #
CREATE TABLE realdb.t0 (a text, b text) ENGINE=MYISAM;
--echo #
--echo # Create a federated table with a bogus port number
--echo #
CREATE TABLE federated.t0 (a text, b text) ENGINE=FEDERATED
CONNECTION='mysql://root@127.0.0.1:63333/realdb/t0';
#--warning ER_CONNECT_TO_FOREIGN_DATA_SOURCE
--echo #
--echo # Trigger a federated system error during a INFORMATION_SCHEMA.TABLES query
--echo #
# Remove O/S-specific socket error
--replace_regex /\(.*\)/(socket errno)/
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'realdb' or TABLE_SCHEMA = 'federated';
# Remove O/S-specific socket error
--replace_regex /\(.*\)/(socket errno)/
SHOW WARNINGS;
--echo #
--echo # Create a MyISAM table then corrupt the file
--echo #
USE realdb;
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
--echo #
--echo # Corrupt the MyISAM table by deleting the base file
--echo #
let $MYSQLD_DATADIR= `SELECT @@datadir`;
--remove_file $MYSQLD_DATADIR/realdb/t1.MYD
--remove_file $MYSQLD_DATADIR/realdb/t1.MYI
--echo #
--echo # Trigger a MyISAM system error during an INFORMATION_SCHEMA.TABLES query
--echo #
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ENGINE, ROW_FORMAT, TABLE_ROWS, DATA_LENGTH, TABLE_COMMENT
FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1';
SHOW WARNINGS;
--echo #
--echo # Cleanup
--echo #
--disable_warnings
DROP TABLE IF EXISTS realdb.t0;
DROP TABLE IF EXISTS federated.t0;
DROP DATABASE realdb;
--enable_warnings
--source include/federated_cleanup.inc
......@@ -2486,28 +2486,28 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
{
const char *tmp_buff;
MYSQL_TIME time;
int info_error= 0;
CHARSET_INFO *cs= system_charset_info;
DBUG_ENTER("get_schema_tables_record");
restore_record(table, s->default_values);
table->field[1]->store(base_name, (uint) strlen(base_name), cs);
table->field[2]->store(file_name, (uint) strlen(file_name), cs);
if (res)
{
/*
there was errors during opening tables
*/
const char *error= thd->net.last_error;
/* There was a table open error, so set the table type and return */
if (tables->view)
table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
else if (tables->schema_table)
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
else
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
table->field[20]->store(error, (uint) strlen(error), cs);
thd->clear_error();
goto err;
}
else if (tables->view)
if (tables->view)
{
table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
table->field[20]->store(STRING_WITH_LEN("VIEW"), cs);
......@@ -2518,8 +2518,15 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
TABLE_SHARE *share= show_table->s;
handler *file= show_table->file;
file->info(HA_STATUS_VARIABLE | HA_STATUS_TIME | HA_STATUS_AUTO |
HA_STATUS_NO_LOCK);
if (!file)
goto err;
if ((info_error= file->info(HA_STATUS_VARIABLE |
HA_STATUS_TIME |
HA_STATUS_AUTO |
HA_STATUS_NO_LOCK)) != 0)
goto err;
if (share->tmp_table == SYSTEM_TMP_TABLE)
table->field[3]->store(STRING_WITH_LEN("SYSTEM VIEW"), cs);
else if (share->tmp_table)
......@@ -2665,6 +2672,25 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
}
}
}
err:
if (res || info_error)
{
/*
If an error was encountered, push a warning, set the TABLE COMMENT
column with the error text, and clear the error so that the operation
can continue.
*/
const char *error= thd->net.last_error;
if (error)
{
table->field[20]->store(error, strlen(error), cs);
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
thd->net.last_errno, thd->net.last_error);
thd->clear_error();
}
}
DBUG_RETURN(schema_table_store_record(thd, table));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment