From: Date: April 22 2005 3:28pm Subject: bk commit into 4.1 tree (mskold:1.2201) BUG#9318 List-Archive: http://lists.mysql.com/internals/24229 X-Bug: 9318 Message-Id: <200504221328.j3MDSTjF017170@localhost.localdomain> Below is the list of changes that have just been committed into a local 4.1 repository of marty. When marty does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2201 05/04/22 15:28:23 mskold@stripped +4 -0 Fix for Bug #9318 drop database does not drop ndb tables mysql-test/r/ndb_database.result 1.1 05/04/22 15:27:54 mskold@stripped +27 -0 mysql-test/r/ndb_database.result 1.0 05/04/22 15:27:54 mskold@stripped +0 -0 BitKeeper file /usr/local/home/marty/MySQL/mysql-4.1/mysql-test/r/ndb_database.result mysql-test/t/ndb_database.test 1.1 05/04/22 15:27:52 mskold@stripped +50 -0 mysql-test/t/ndb_database.test 1.0 05/04/22 15:27:52 mskold@stripped +0 -0 BitKeeper file /usr/local/home/marty/MySQL/mysql-4.1/mysql-test/t/ndb_database.test sql/ha_ndbcluster.h 1.51 05/04/22 15:27:08 mskold@stripped +4 -2 Fix for Bug #9318 drop database does not drop ndb tables sql/ha_ndbcluster.cc 1.144 05/04/22 15:27:08 mskold@stripped +73 -50 Fix for Bug #9318 drop database does not drop ndb tables # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: mskold # Host: blowfish.ndb.mysql.com # Root: /usr/local/home/marty/MySQL/mysql-4.1 --- 1.143/sql/ha_ndbcluster.cc Thu Apr 21 13:08:58 2005 +++ 1.144/sql/ha_ndbcluster.cc Fri Apr 22 15:27:08 2005 @@ -3965,18 +3965,6 @@ } -/* - Drop a database in NDB Cluster - */ - -int ndbcluster_drop_database(const char *path) -{ - DBUG_ENTER("ndbcluster_drop_database"); - // TODO drop all tables for this database - DBUG_RETURN(1); -} - - longlong ha_ndbcluster::get_auto_increment() { DBUG_ENTER("get_auto_increment"); @@ -4325,6 +4313,53 @@ } +/* + Drop a database in NDB Cluster + */ + +int ndbcluster_drop_database(const char *path) +{ + DBUG_ENTER("ndbcluster_drop_database"); + THD *thd= current_thd; + char dbname[FN_HEADLEN]; + Ndb* ndb; + NdbDictionary::Dictionary::List list; + uint i; + char *tabname; + List drop_list; + ha_ndbcluster::set_dbname(path, (char *)&dbname); + DBUG_PRINT("enter", ("db: %s", dbname)); + + if (!(ndb= check_ndb_in_thd(thd))) + DBUG_RETURN(HA_ERR_NO_CONNECTION); + + // List tables in NDB + NDBDICT *dict= ndb->getDictionary(); + if (dict->listObjects(list, + NdbDictionary::Object::UserTable) != 0) + ERR_RETURN(dict->getNdbError()); + for (i= 0 ; i < list.count ; i++) + { + NdbDictionary::Dictionary::List::Element& t= list.elements[i]; + DBUG_PRINT("info", ("Found %s/%s in NDB", t.database, t.name)); + + // Add only tables that belongs to db + if (my_strcasecmp(system_charset_info, t.database, dbname)) + continue; + DBUG_PRINT("info", ("%s must be dropped", t.name)); + drop_list.push_back(thd->strdup(t.name)); + } + // Drop any tables belonging to database + ndb->setDatabaseName(dbname); + List_iterator_fast it(drop_list); + while ((tabname=it++)) + if (dict->dropTable(tabname)) + ERR_RETURN(dict->getNdbError()); + + DBUG_RETURN(0); +} + + int ndbcluster_find_files(THD *thd,const char *db,const char *path, const char *wild, bool dir, List *files) { @@ -4595,26 +4630,31 @@ DBUG_VOID_RETURN; } -/* - Set m_tabname from full pathname to table file +/** + * Set a given location from full pathname to database name + * */ - -void ha_ndbcluster::set_tabname(const char *path_name) +void ha_ndbcluster::set_dbname(const char *path_name, char *dbname) { char *end, *ptr; /* Scan name from the end */ - end= strend(path_name)-1; - ptr= end; + ptr= strend(path_name)-1; + while (ptr >= path_name && *ptr != '\\' && *ptr != '/') { + ptr--; + } + ptr--; + end= ptr; while (ptr >= path_name && *ptr != '\\' && *ptr != '/') { ptr--; } uint name_len= end - ptr; - memcpy(m_tabname, ptr + 1, end - ptr); - m_tabname[name_len]= '\0'; + memcpy(dbname, ptr + 1, name_len); + dbname[name_len]= '\0'; #ifdef __WIN__ /* Put to lower case */ - ptr= m_tabname; + + ptr= dbname; while (*ptr != '\0') { *ptr= tolower(*ptr); @@ -4623,6 +4663,15 @@ #endif } +/* + Set m_dbname from full pathname to table file + */ + +void ha_ndbcluster::set_dbname(const char *path_name) +{ + set_dbname(path_name, m_dbname); +} + /** * Set a given location from full pathname to table file * @@ -4652,39 +4701,13 @@ #endif } - /* - Set m_dbname from full pathname to table file - + Set m_tabname from full pathname to table file */ -void ha_ndbcluster::set_dbname(const char *path_name) +void ha_ndbcluster::set_tabname(const char *path_name) { - char *end, *ptr; - - /* Scan name from the end */ - ptr= strend(path_name)-1; - while (ptr >= path_name && *ptr != '\\' && *ptr != '/') { - ptr--; - } - ptr--; - end= ptr; - while (ptr >= path_name && *ptr != '\\' && *ptr != '/') { - ptr--; - } - uint name_len= end - ptr; - memcpy(m_dbname, ptr + 1, name_len); - m_dbname[name_len]= '\0'; -#ifdef __WIN__ - /* Put to lower case */ - - ptr= m_dbname; - - while (*ptr != '\0') { - *ptr= tolower(*ptr); - ptr++; - } -#endif + set_tabname(path_name, m_tabname); } --- 1.50/sql/ha_ndbcluster.h Tue Mar 22 17:41:44 2005 +++ 1.51/sql/ha_ndbcluster.h Fri Apr 22 15:27:08 2005 @@ -147,7 +147,10 @@ static Thd_ndb* seize_thd_ndb(); static void release_thd_ndb(Thd_ndb* thd_ndb); uint8 table_cache_type(); - + + static void set_dbname(const char *pathname, char *dbname); + static void set_tabname(const char *pathname, char *tabname); + private: int alter_table_name(const char *to); int drop_table(); @@ -183,7 +186,6 @@ void set_dbname(const char *pathname); void set_tabname(const char *pathname); - void set_tabname(const char *pathname, char *tabname); bool set_hidden_key(NdbOperation*, uint fieldnr, const byte* field_ptr); --- New file --- +++ mysql-test/r/ndb_database.result 05/04/22 15:27:54 drop table if exists t1; drop database if exists mysqltest; drop table if exists t1; drop database if exists mysqltest; create database mysqltest; create database mysqltest; create table mysqltest.t1 (a int primary key, b int) engine=ndb; use mysqltest; show tables; Tables_in_mysqltest t1 drop database mysqltest; use mysqltest; show tables; Tables_in_mysqltest create database mysqltest; create table mysqltest.t1 (c int, d int primary key) engine=ndb; use mysqltest; show tables; Tables_in_mysqltest t1 drop database mysqltest; use mysqltest; show tables; Tables_in_mysqltest drop table if exists t1; drop database if exists mysqltest; --- New file --- +++ mysql-test/t/ndb_database.test 05/04/22 15:27:52 -- source include/have_ndb.inc -- source include/have_multi_ndb.inc -- source include/not_embedded.inc --disable_warnings connection server1; drop table if exists t1; drop database if exists mysqltest; connection server2; drop table if exists t1; drop database if exists mysqltest; --enable_warnings # # Check that all tables in a database are dropped when database is dropped # connection server1; create database mysqltest; connection server2; create database mysqltest; create table mysqltest.t1 (a int primary key, b int) engine=ndb; use mysqltest; show tables; connection server1; drop database mysqltest; connection server2; use mysqltest; show tables; connection server1; create database mysqltest; create table mysqltest.t1 (c int, d int primary key) engine=ndb; use mysqltest; show tables; connection server2; drop database mysqltest; connection server1; use mysqltest; show tables; --disable_warnings drop table if exists t1; drop database if exists mysqltest; --enable_warnings