From a004533a764097a75fadf33b2a883d3c8d9b3112 Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.homeip.net" <> Date: Thu, 17 Feb 2005 14:22:44 +0100 Subject: [PATCH 1/2] BUG#8547: Wrong errormessage when dropping table that does not exist in NDB - Added tescases - Added handling of HA_ERR_NO_SUCH_TABLE in mysql_rm_table_part2 so that error messages now are consistent --- mysql-test/r/ndb_autodiscover.result | 19 +++++++++++ mysql-test/t/ndb_autodiscover.test | 22 +++++++++++++ sql/ha_ndbcluster.cc | 48 +++++++++++++--------------- sql/sql_table.cc | 15 +++++++++ 4 files changed, 79 insertions(+), 25 deletions(-) diff --git a/mysql-test/r/ndb_autodiscover.result b/mysql-test/r/ndb_autodiscover.result index ba21483a9b0..afea2fa3e0a 100644 --- a/mysql-test/r/ndb_autodiscover.result +++ b/mysql-test/r/ndb_autodiscover.result @@ -167,6 +167,25 @@ show status like 'handler_discover%'; Variable_name Value Handler_discover 0 drop table t4; +ERROR 42S02: Unknown table 't4' +create table t4( +id int not null primary key, +name char(27) +) engine=ndb; +insert into t4 values (1, "Automatic"); +select * from t4; +id name +1 Automatic +select * from t4; +ERROR 42S02: Table 'test.t4' doesn't exist +drop table if exists t4; +Warnings: +Note 1051 Unknown table 't4' +drop table t5; +ERROR 42S02: Unknown table 't5' +drop table if exists t5; +Warnings: +Note 1051 Unknown table 't5' flush status; create table t4( id int not null primary key, diff --git a/mysql-test/t/ndb_autodiscover.test b/mysql-test/t/ndb_autodiscover.test index d305c1a9dd7..211d8344471 100644 --- a/mysql-test/t/ndb_autodiscover.test +++ b/mysql-test/t/ndb_autodiscover.test @@ -209,8 +209,30 @@ select * from t4; select * from t4; show status like 'handler_discover%'; +--error 1051 drop table t4; +create table t4( + id int not null primary key, + name char(27) +) engine=ndb; +insert into t4 values (1, "Automatic"); +select * from t4; + +# Remove the table from NDB +system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t4 >> $NDB_TOOLS_OUTPUT ; + +--error 1146 +select * from t4; + +drop table if exists t4; + +# Test that dropping a table that does not exists +# on disk or in NDB gives same result as above +--error 1051 +drop table t5; +drop table if exists t5; + ####################################################### # Test that a table that has been dropped from NDB diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 58f744438fc..1b0a717676e 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -157,7 +157,7 @@ static const err_code_mapping err_map[]= { 721, HA_ERR_TABLE_EXIST, 1 }, { 4244, HA_ERR_TABLE_EXIST, 1 }, - { 709, HA_ERR_NO_SUCH_TABLE, 1 }, + { 709, HA_ERR_NO_SUCH_TABLE, 0 }, { 284, HA_ERR_NO_SUCH_TABLE, 1 }, { 266, HA_ERR_LOCK_WAIT_TIMEOUT, 1 }, @@ -2361,14 +2361,13 @@ void ha_ndbcluster::print_results() char buf_type[MAX_FIELD_WIDTH], buf_val[MAX_FIELD_WIDTH]; String type(buf_type, sizeof(buf_type), &my_charset_bin); String val(buf_val, sizeof(buf_val), &my_charset_bin); - for (uint f=0; fs->fields;f++) + for (uint f= 0; f < table->s->fields; f++) { /* Use DBUG_PRINT since DBUG_FILE cannot be filtered out */ char buf[2000]; Field *field; void* ptr; NdbValue value; - NdbBlob *ndb_blob; buf[0]= 0; field= table->field[f]; @@ -2382,7 +2381,6 @@ void ha_ndbcluster::print_results() if (! (field->flags & BLOB_FLAG)) { - ndb_blob= NULL; if (value.rec->isNULL()) { my_snprintf(buf, sizeof(buf), "NULL"); @@ -2396,7 +2394,7 @@ void ha_ndbcluster::print_results() } else { - ndb_blob= value.blob; + NdbBlob *ndb_blob= value.blob; bool isNull= TRUE; ndb_blob->getNull(isNull); if (isNull) { @@ -3959,45 +3957,43 @@ int ha_ndbcluster::alter_table_name(const char *to) /* - Delete a table from NDB Cluster + Delete table from NDB Cluster + */ int ha_ndbcluster::delete_table(const char *name) { - DBUG_ENTER("delete_table"); + DBUG_ENTER("ha_ndbcluster::delete_table"); DBUG_PRINT("enter", ("name: %s", name)); set_dbname(name); set_tabname(name); - + if (check_ndb_connection()) DBUG_RETURN(HA_ERR_NO_CONNECTION); - // Remove .ndb file + + /* Call ancestor function to delete .ndb file */ handler::delete_table(name); + + /* Drop the table from NDB */ DBUG_RETURN(drop_table()); } /* - Drop a table in NDB Cluster + Drop table in NDB Cluster */ int ha_ndbcluster::drop_table() { Ndb *ndb= get_ndb(); NdbDictionary::Dictionary *dict= ndb->getDictionary(); - + DBUG_ENTER("drop_table"); DBUG_PRINT("enter", ("Deleting %s", m_tabname)); - - if (dict->dropTable(m_tabname)) - { - const NdbError err= dict->getNdbError(); - if (err.code == 709) - ; // 709: No such table existed - else - ERR_RETURN(dict->getNdbError()); - } + release_metadata(); + if (dict->dropTable(m_tabname)) + ERR_RETURN(dict->getNdbError()); DBUG_RETURN(0); } @@ -4474,18 +4470,20 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path, // Delete old files List_iterator_fast it3(delete_list); while ((file_name=it3++)) - { - DBUG_PRINT("info", ("Remove table %s/%s",db, file_name )); + { + DBUG_PRINT("info", ("Remove table %s/%s", db, file_name)); // Delete the table and all related files TABLE_LIST table_list; bzero((char*) &table_list,sizeof(table_list)); table_list.db= (char*) db; table_list.alias= table_list.table_name= (char*)file_name; - (void)mysql_rm_table_part2(thd, &table_list, - /* if_exists */ TRUE, - /* drop_temporary */ FALSE, + (void)mysql_rm_table_part2(thd, &table_list, + /* if_exists */ FALSE, + /* drop_temporary */ FALSE, /* drop_view */ FALSE, /* dont_log_query*/ TRUE); + /* Clear error message that is returned when table is deleted */ + thd->clear_error(); } } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index d7cefb3dceb..025d3c757a8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -249,6 +249,21 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, if (!(error=my_delete(path,MYF(MY_WME)))) some_tables_deleted=1; } + if (error == HA_ERR_NO_SUCH_TABLE) + { + /* The table did not exist in engine */ + if (if_exists) + { + push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), + table->table_name); + error= 0; + } + /* Delete the table definition file */ + strmov(end,reg_ext); + if (!(my_delete(path,MYF(MY_WME)))) + some_tables_deleted=1; + } } if (error) { From 4ebbb92054a9323dab342874f9f58b77ba3f69dd Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.(none)" <> Date: Fri, 18 Feb 2005 10:57:10 +0100 Subject: [PATCH 2/2] BUG#8583 ndb_...multi tests fail in 5.0.3 - the variable MASTER_MY_PORT1 was used from the script, but it was not set to the port where the second server was started --- mysql-test/mysql-test-run.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh index 36cf6d95ba5..8a71d8fc566 100644 --- a/mysql-test/mysql-test-run.sh +++ b/mysql-test/mysql-test-run.sh @@ -208,7 +208,6 @@ export UMASK UMASK_DIR MASTER_RUNNING=0 MASTER1_RUNNING=0 MASTER_MYPORT=9306 -MASTER_MYPORT1=9307 SLAVE_RUNNING=0 SLAVE_MYPORT=9308 # leave room for 2 masters for cluster tests MYSQL_MANAGER_PORT=9305 # needs to be out of the way of slaves @@ -495,7 +494,7 @@ SLAVE_MYERR="$MYSQL_TEST_DIR/var/log/slave.err" CURRENT_TEST="$MYSQL_TEST_DIR/var/log/current_test" SMALL_SERVER="--key_buffer_size=1M --sort_buffer=256K --max_heap_table_size=1M" -export MASTER_MYPORT MASTER_MYPORT1 SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1 +export MASTER_MYPORT SLAVE_MYPORT MYSQL_TCP_PORT MASTER_MYSOCK MASTER_MYSOCK1 NDBCLUSTER_BASE_PORT=`expr $NDBCLUSTER_PORT + 2` NDBCLUSTER_OPTS="--port=$NDBCLUSTER_PORT --port-base=$NDBCLUSTER_BASE_PORT --data-dir=$MYSQL_TEST_DIR/var --ndb_mgm-extra-opts=$NDB_MGM_EXTRA_OPTS --ndb_mgmd-extra-opts=$NDB_MGMD_EXTRA_OPTS --ndbd-extra-opts=$NDBD_EXTRA_OPTS" @@ -1145,6 +1144,8 @@ start_master() id=`$EXPR $1 + 101`; this_master_myport=`$EXPR $MASTER_MYPORT + $1` NOT_FIRST_MASTER_EXTRA_OPTS="--skip-innodb" + eval "MASTER_MYPORT$1=$this_master_myport" + export MASTER_MYPORT$1 else id=1; this_master_myport=$MASTER_MYPORT @@ -1763,7 +1764,7 @@ then $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 - $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT1 -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 + $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $MASTER_MYPORT+1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 $MYSQLADMIN --no-defaults --host=$hostname --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1 sleep_until_file_deleted 0 $MASTER_MYPID