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 2ea8b26a84b..05bd356bdf3 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -6354,9 +6354,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); } @@ -6718,7 +6718,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 617bf9ee378..12dfe37ec71 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2858,20 +2858,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, @@ -2880,23 +2881,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 70bc9ef23d5..bd5472133e2 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1008,6 +1008,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 feaefa160b8..9531e667e7a 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3488,15 +3488,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"},