summaryrefslogtreecommitdiff
path: root/sql/sql_handler.cc
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2010-03-13 13:58:27 +0300
committerKonstantin Osipov <kostja@sun.com>2010-03-13 13:58:27 +0300
commit9cb8a98216586cd7b5e2aa90d374e6d5ff757072 (patch)
tree6b9c6dacc901f2c4ee1b09bfa596846e1c345e4c /sql/sql_handler.cc
parent42b7812898540b06f2705ab6533289f5503e9687 (diff)
downloadmariadb-git-9cb8a98216586cd7b5e2aa90d374e6d5ff757072.tar.gz
A review comment for the fix for Bug#46672.
Remove unnecessary need_reopen loops.
Diffstat (limited to 'sql/sql_handler.cc')
-rw-r--r--sql/sql_handler.cc60
1 files changed, 57 insertions, 3 deletions
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 3afeb4164bd..f4db3f21db7 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -405,6 +405,56 @@ bool mysql_ha_close(THD *thd, TABLE_LIST *tables)
}
+/**
+ A helper class to process an error from mysql_lock_tables().
+ HANDLER READ statement's attempt to lock the subject table
+ may get aborted if there is a pending DDL. In that case
+ we close the table, reopen it, and try to read again.
+ This is implicit and obscure, since HANDLER position
+ is lost in the process, but it's the legacy server
+ behaviour we should preserve.
+*/
+
+class Sql_handler_lock_error_handler: public Internal_error_handler
+{
+public:
+ virtual
+ bool handle_condition(THD *thd,
+ uint sql_errno,
+ const char *sqlstate,
+ MYSQL_ERROR::enum_warning_level level,
+ const char* msg,
+ MYSQL_ERROR **cond_hdl);
+
+ bool need_reopen() const { return m_need_reopen; };
+ void init() { m_need_reopen= FALSE; };
+private:
+ bool m_need_reopen;
+};
+
+
+/**
+ Handle an error from mysql_lock_tables().
+ Ignore ER_LOCK_ABORTED errors.
+*/
+
+bool
+Sql_handler_lock_error_handler::
+handle_condition(THD *thd,
+ uint sql_errno,
+ const char *sqlstate,
+ MYSQL_ERROR::enum_warning_level level,
+ const char* msg,
+ MYSQL_ERROR **cond_hdl)
+{
+ *cond_hdl= NULL;
+ if (sql_errno == ER_LOCK_ABORTED)
+ m_need_reopen= TRUE;
+
+ return m_need_reopen;
+}
+
+
/*
Read from a HANDLER table.
@@ -442,7 +492,7 @@ bool mysql_ha_read(THD *thd, TABLE_LIST *tables,
uint num_rows;
uchar *UNINIT_VAR(key);
uint UNINIT_VAR(key_len);
- bool need_reopen;
+ Sql_handler_lock_error_handler sql_handler_lock_error;
DBUG_ENTER("mysql_ha_read");
DBUG_PRINT("enter",("'%s'.'%s' as '%s'",
tables->db, tables->table_name, tables->alias));
@@ -506,8 +556,12 @@ retry:
thd->open_tables= hash_tables->table;
- lock= mysql_lock_tables(thd, &thd->open_tables, 1, 0, &need_reopen);
+ sql_handler_lock_error.init();
+ thd->push_internal_handler(&sql_handler_lock_error);
+
+ lock= mysql_lock_tables(thd, &thd->open_tables, 1, 0);
+ thd->pop_internal_handler();
/*
In 5.1 and earlier, mysql_lock_tables() could replace the TABLE
object with another one (reopen it). This is no longer the case
@@ -517,7 +571,7 @@ retry:
/* Restore previous context. */
thd->open_tables= backup_open_tables;
- if (need_reopen)
+ if (sql_handler_lock_error.need_reopen())
{
mysql_ha_close_table(thd, hash_tables);
goto retry;