diff options
author | unknown <msvensson@neptunus.(none)> | 2005-06-08 13:31:59 +0200 |
---|---|---|
committer | unknown <msvensson@neptunus.(none)> | 2005-06-08 13:31:59 +0200 |
commit | 205ac33cf39a72e834992ead58de54efc0a98d21 (patch) | |
tree | b82e8da8fb00ab3aeb74266b31c0094ac048b5a8 /sql/handler.cc | |
parent | 4b5728d2194258e5f0753d9c591fbc259ec887fd (diff) | |
download | mariadb-git-205ac33cf39a72e834992ead58de54efc0a98d21.tar.gz |
BUG#10365 Cluster handler uses non-standard error codes
- Added better error messages when trying to open a table that can't be discovered or unpacked. The most likely cause of this is that it does not have any frm data, probably since it has been created from NdbApi or is a NDB system table.
- Separated functionality that was in ha_create_table_from_engine into two functions. One that checks if the table exists and another one that tries to create the table from the engine.
mysql-test/r/ndb_autodiscover.result:
Add tests for reading from a table that can't be discovered(SYSTAB_0)
Discovery is not performed during create table anymore.
mysql-test/t/ndb_autodiscover.test:
Add tests for reading from a table that can't be discovered(SYSTAB_0)
Discovery is not performed during create table anymore.
ndb/test/ndbapi/create_tab.cpp:
Set connectstring before creating Ndb object.
sql/ha_ndbcluster.cc:
Rename and use the function ndbcluster_table_exists_in_engine.
Correct return valu from ndbcluster_discover
Remove old code "ndb_discover_tables"
sql/ha_ndbcluster.h:
Rename function ndbcluster_table_exists to ndb ndbcluster_table_exists_in_engine
sql/handler.cc:
Update comment of ha_create_table_from_engine
Remove parameter create_if_found from ha_create_table_from_engine, the function ha_table_exists_in_engine is now used toi check if table is found in engine.
Cleanup return codes from ha_create_table_from_engine.
Change name of ha_table_exists to ha_table_exists_in_engine, update comment and returne codes.
sql/handler.h:
Remove paramter create_if_cound from ha_create_table_from_engine
Rename ha_table_exists to ha_table_exists_in_engine
sql/sql_base.cc:
Use the function ha_table_exists_in_engine to detect if table exists in enegine.
If it exists, call function ha_create_table_from_engine to try and create it.
If create of table fails, set correct error message.
sql/sql_table.cc:
Add comments, remove parameter create_if_found to ha_create_table_from_engine.
When dropping a table, try to discover it from engine. If discover fails, use same error message as if the table didn't exists.
Maybe another message should be displayed here, ex: "Table could not be dropped, unpack failed"
When creating a new table, use ha_table_exists_in_engine to check if a table with the given name already exists.
Diffstat (limited to 'sql/handler.cc')
-rw-r--r-- | sql/handler.cc | 91 |
1 files changed, 43 insertions, 48 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index f14564b6629..ad5cd28d932 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1336,21 +1336,18 @@ int ha_create_table(const char *name, HA_CREATE_INFO *create_info, } /* - Try to discover table from engine and + Try to discover table from engine and if found, write the frm file to disk. - + RETURN VALUES: - 0 : Table existed in engine and created - on disk if so requested - 1 : Table does not exist - >1 : error + 0 : Table created ok + 1 : Table could not be created */ -int ha_create_table_from_engine(THD* thd, - const char *db, - const char *name, - bool create_if_found) +int ha_create_table_from_engine(THD* thd, + const char *db, + const char *name) { int error; const void *frmblob; @@ -1359,45 +1356,47 @@ int ha_create_table_from_engine(THD* thd, HA_CREATE_INFO create_info; TABLE table; DBUG_ENTER("ha_create_table_from_engine"); - DBUG_PRINT("enter", ("name '%s'.'%s' create_if_found: %d", - db, name, create_if_found)); + DBUG_PRINT("enter", ("name '%s'.'%s'", + db, name)); bzero((char*) &create_info,sizeof(create_info)); - if ((error= ha_discover(thd, db, name, &frmblob, &frmlen))) - DBUG_RETURN(error); + if(ha_discover(thd, db, name, &frmblob, &frmlen)) + { + // Table could not be discovered and thus not created + DBUG_RETURN(1); + } + /* - Table exists in handler - frmblob and frmlen are set + Table exists in handler and could be discovered + frmblob and frmlen are set, write the frm to disk */ - if (create_if_found) + (void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS); + // Save the frm file + if (writefrm(path, frmblob, frmlen)) { - (void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS); - // Save the frm file - if ((error = writefrm(path, frmblob, frmlen))) - goto err_end; + my_free((char*) frmblob, MYF(MY_ALLOW_ZERO_PTR)); + DBUG_RETURN(1); + } - if (openfrm(path,"",0,(uint) READ_ALL, 0, &table)) - DBUG_RETURN(1); + if (openfrm(path,"",0,(uint) READ_ALL, 0, &table)) + DBUG_RETURN(1); - update_create_info_from_table(&create_info, &table); - create_info.table_options|= HA_CREATE_FROM_ENGINE; + update_create_info_from_table(&create_info, &table); + create_info.table_options|= HA_CREATE_FROM_ENGINE; - if (lower_case_table_names == 2 && - !(table.file->table_flags() & HA_FILE_BASED)) - { - /* Ensure that handler gets name in lower case */ - my_casedn_str(files_charset_info, path); - } - - error=table.file->create(path,&table,&create_info); - VOID(closefrm(&table)); + if (lower_case_table_names == 2 && + !(table.file->table_flags() & HA_FILE_BASED)) + { + /* Ensure that handler gets name in lower case */ + my_casedn_str(files_charset_info, path); } - -err_end: + error=table.file->create(path,&table,&create_info); + VOID(closefrm(&table)); my_free((char*) frmblob, MYF(MY_ALLOW_ZERO_PTR)); - DBUG_RETURN(error); + + DBUG_RETURN(error != 0); } static int NEAR_F delete_file(const char *name,const char *ext,int extflag) @@ -1507,8 +1506,8 @@ int ha_change_key_cache(KEY_CACHE *old_key_cache, Try to discover one table from handler(s) RETURN - 0 ok. In this case *frmblob and *frmlen are set - 1 error. frmblob and frmlen may not be set + 0 ok. In this case *frmblob and *frmlen are set + >=1 error. frmblob and frmlen may not be set */ int ha_discover(THD *thd, const char *db, const char *name, @@ -1546,11 +1545,8 @@ ha_find_files(THD *thd,const char *db,const char *path, error= ndbcluster_find_files(thd, db, path, wild, dir, files); #endif DBUG_RETURN(error); - - } -#ifdef NOT_YET_USED /* Ask handler if the table exists in engine @@ -1561,20 +1557,19 @@ ha_find_files(THD *thd,const char *db,const char *path, # Error code */ -int ha_table_exists(THD* thd, const char* db, const char* name) +int ha_table_exists_in_engine(THD* thd, const char* db, const char* name) { - int error= 2; - DBUG_ENTER("ha_table_exists"); + int error= 0; + DBUG_ENTER("ha_table_exists_in_engine"); DBUG_PRINT("enter", ("db: %s, name: %s", db, name)); #ifdef HAVE_NDBCLUSTER_DB if (have_ndbcluster == SHOW_OPTION_YES) - error= ndbcluster_table_exists(thd, db, name); + error= ndbcluster_table_exists_in_engine(thd, db, name); #endif + DBUG_PRINT("exit", ("error: %d", error)); DBUG_RETURN(error); } -#endif - /* Read first row between two ranges. |