From 44271d49a0cb213ea854db41ea017126803e65f1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Apr 2007 15:15:47 +0800 Subject: [PATCH] BUG#18676 In order to coincide with 5.0 mysqld error code after bug#18676, Map the 4009 ndb error code to 157 mysql error code mysql-test/r/ndb_autodiscover.result: changes ndbd error code 4009 to mysqld error code 157 when no cluster connection sql/ha_ndbcluster.cc: define return codes to ndbcluster_table_exists_in_engine to something useful sql/handler.cc: define return codes to ha_table_exists_in_engine to something useful sql/sql_plugin.cc: Add a comment sql/sql_table.cc: clearly define what happens on create table if exists/not exists/not connected to engine storage/ndb/src/ndbapi/ndberror.c: map 4009 ndb error code to 157 mysqld error code --- mysql-test/r/ndb_autodiscover.result | 2 +- sql/ha_ndbcluster.cc | 6 +++--- sql/handler.cc | 31 ++++++++++++++++------------ sql/sql_plugin.cc | 1 + sql/sql_table.cc | 24 ++++++++++++++------- storage/ndb/src/ndbapi/ndberror.c | 2 +- 6 files changed, 41 insertions(+), 25 deletions(-) diff --git a/mysql-test/r/ndb_autodiscover.result b/mysql-test/r/ndb_autodiscover.result index cb85c4ac873..487f52f6427 100644 --- a/mysql-test/r/ndb_autodiscover.result +++ b/mysql-test/r/ndb_autodiscover.result @@ -382,7 +382,7 @@ create table t1 (a int primary key) engine=ndb; select * from t1; a select * from t1; -ERROR HY000: Can't lock file (errno: 4009) +ERROR HY000: Can't lock file (errno: 157) use test; drop database test_only_ndb_tables; CREATE TABLE t9 ( diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 4db35cd7377..af12ad7554a 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -6244,9 +6244,9 @@ int ndbcluster_table_exists_in_engine(handlerton *hton, THD* thd, if (my_strcasecmp(system_charset_info, elmt.name, name)) continue; DBUG_PRINT("info", ("Found table")); - DBUG_RETURN(1); + DBUG_RETURN(HA_ERR_TABLE_EXIST); } - DBUG_RETURN(0); + DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); } @@ -6608,7 +6608,7 @@ int ndbcluster_find_files(handlerton *hton, THD *thd, DBUG_PRINT("info", ("%s existed on disk", name)); // The .ndb file exists on disk, but it's not in list of tables in ndb // Verify that handler agrees table is gone. - if (ndbcluster_table_exists_in_engine(hton, thd, db, file_name) == 0) + if (ndbcluster_table_exists_in_engine(hton, thd, db, file_name) == HA_ERR_NO_SUCH_TABLE) { DBUG_PRINT("info", ("NDB says %s does not exists", file_name)); it.remove(); diff --git a/sql/handler.cc b/sql/handler.cc index 23c3103493e..e129c677251 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2860,20 +2860,21 @@ ha_find_files(THD *thd,const char *db,const char *path, DBUG_RETURN(error); } - -/** @brief +/* Ask handler if the table exists in engine RETURN - 0 Table does not exist - 1 Table exists - # Error code + HA_ERR_NO_SUCH_TABLE Table does not exist + HA_ERR_TABLE_EXIST Table exists + # Error code + + */ -*/ struct st_table_exists_in_engine_args { const char *db; const char *name; + int err; }; static my_bool table_exists_in_engine_handlerton(THD *thd, st_plugin_int *plugin, @@ -2882,23 +2883,27 @@ static my_bool table_exists_in_engine_handlerton(THD *thd, st_plugin_int *plugin st_table_exists_in_engine_args *vargs= (st_table_exists_in_engine_args *)arg; handlerton *hton= (handlerton *)plugin->data; + int err= HA_ERR_NO_SUCH_TABLE; + if (hton->state == SHOW_OPTION_YES && hton->table_exists_in_engine) - if ((hton->table_exists_in_engine(hton, thd, vargs->db, vargs->name)) == 1) - return TRUE; + err = hton->table_exists_in_engine(hton, thd, vargs->db, vargs->name); + + vargs->err = err; + if (vargs->err == HA_ERR_TABLE_EXIST) + return TRUE; return FALSE; } int ha_table_exists_in_engine(THD* thd, const char* db, const char* name) { - int error= 0; DBUG_ENTER("ha_table_exists_in_engine"); DBUG_PRINT("enter", ("db: %s, name: %s", db, name)); - st_table_exists_in_engine_args args= {db, name}; - error= plugin_foreach(thd, table_exists_in_engine_handlerton, + st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE}; + plugin_foreach(thd, table_exists_in_engine_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, &args); - DBUG_PRINT("exit", ("error: %d", error)); - DBUG_RETURN(error); + DBUG_PRINT("exit", ("error: %d", args.err)); + DBUG_RETURN(args.err); } #ifdef HAVE_NDB_BINLOG diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index e3e24c1f375..32f89f155bb 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1009,6 +1009,7 @@ my_bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func, rw_unlock(&THR_LOCK_plugin); } plugin= plugins[idx]; + /* It will stop iterating on first engine error when "func" returns TRUE */ if (plugin && func(thd, plugin, arg)) goto err; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index fc401e93d9c..2e2269b8829 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3481,15 +3481,25 @@ bool mysql_create_table_internal(THD *thd, { bool create_if_not_exists = create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS; - - if (ha_table_exists_in_engine(thd, db, table_name)) + int retcode = ha_table_exists_in_engine(thd, db, table_name); + DBUG_PRINT("info", ("exists_in_engine: %u",retcode)); + switch (retcode) { - DBUG_PRINT("info", ("Table with same name already existed in handler")); + case HA_ERR_NO_SUCH_TABLE: + /* Normal case, no table exists. we can go and create it */ + break; + case HA_ERR_TABLE_EXIST: + DBUG_PRINT("info", ("Table existed in handler")); - if (create_if_not_exists) - goto warn; - my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); - goto unlock_and_end; + if (create_if_not_exists) + goto warn; + my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); + goto unlock_and_end; + break; + default: + DBUG_PRINT("info", ("error: %u from storage engine", retcode)); + my_error(retcode, MYF(0),table_name); + goto unlock_and_end; } } diff --git a/storage/ndb/src/ndbapi/ndberror.c b/storage/ndb/src/ndbapi/ndberror.c index b21b64156c8..8b14234c4be 100644 --- a/storage/ndb/src/ndbapi/ndberror.c +++ b/storage/ndb/src/ndbapi/ndberror.c @@ -151,7 +151,7 @@ ErrorBundle ErrorCodes[] = { */ { 4007, DMEC, UR, "Send to ndbd node failed" }, { 4008, DMEC, UR, "Receive from NDB failed" }, - { 4009, DMEC, UR, "Cluster Failure" }, + { 4009, HA_ERR_NO_CONNECTION, UR, "Cluster Failure" }, { 4012, DMEC, UR, "Request ndbd time-out, maybe due to high load or communication problems"}, { 4013, DMEC, UR, "Request timed out in waiting for node failure"},