Bug #27758 Restoring NDB backups makes table usable in SQL nodes

- parse indexname using "split" instead of sscanf, as not to break at space
- test case with space in key
- enclose names in printout
parent b86f256d
This diff is collapsed.
This diff is collapsed.
...@@ -205,7 +205,7 @@ BackupRestore::table(const TableS & table){ ...@@ -205,7 +205,7 @@ BackupRestore::table(const TableS & table){
BaseString tmp(name); BaseString tmp(name);
Vector<BaseString> split; Vector<BaseString> split;
if(tmp.split(split, "/") != 3){ if(tmp.split(split, "/") != 3){
err << "Invalid table name format " << name << endl; err << "Invalid table name format `" << name << "`" << endl;
return false; return false;
} }
...@@ -230,16 +230,17 @@ BackupRestore::table(const TableS & table){ ...@@ -230,16 +230,17 @@ BackupRestore::table(const TableS & table){
if (dict->createTable(copy) == -1) if (dict->createTable(copy) == -1)
{ {
err << "Create table " << table.getTableName() << " failed: " err << "Create table `" << table.getTableName() << "` failed: "
<< dict->getNdbError() << endl; << dict->getNdbError() << endl;
return false; return false;
} }
info << "Successfully restored table " << table.getTableName()<< endl ; info << "Successfully restored table `"
<< table.getTableName() << "`" << endl;
} }
const NdbDictionary::Table* tab = dict->getTable(split[2].c_str()); const NdbDictionary::Table* tab = dict->getTable(split[2].c_str());
if(tab == 0){ if(tab == 0){
err << "Unable to find table: " << split[2].c_str() << endl; err << "Unable to find table: `" << split[2].c_str() << "`" << endl;
return false; return false;
} }
const NdbDictionary::Table* null = 0; const NdbDictionary::Table* null = 0;
...@@ -257,52 +258,57 @@ BackupRestore::endOfTables(){ ...@@ -257,52 +258,57 @@ BackupRestore::endOfTables(){
for(size_t i = 0; i<m_indexes.size(); i++){ for(size_t i = 0; i<m_indexes.size(); i++){
NdbTableImpl & indtab = NdbTableImpl::getImpl(* m_indexes[i]); NdbTableImpl & indtab = NdbTableImpl::getImpl(* m_indexes[i]);
BaseString tmp(indtab.m_primaryTable.c_str());
Vector<BaseString> split; Vector<BaseString> split;
if(tmp.split(split, "/") != 3){ {
err << "Invalid table name format " << indtab.m_primaryTable.c_str() BaseString tmp(indtab.m_primaryTable.c_str());
<< endl; if (tmp.split(split, "/") != 3)
{
err << "Invalid table name format `" << indtab.m_primaryTable.c_str()
<< "`" << endl;
return false; return false;
} }
}
m_ndb->setDatabaseName(split[0].c_str()); m_ndb->setDatabaseName(split[0].c_str());
m_ndb->setSchemaName(split[1].c_str()); m_ndb->setSchemaName(split[1].c_str());
const NdbDictionary::Table * prim = dict->getTable(split[2].c_str()); const NdbDictionary::Table * prim = dict->getTable(split[2].c_str());
if(prim == 0){ if(prim == 0){
err << "Unable to find base table \"" << split[2].c_str() err << "Unable to find base table `" << split[2].c_str()
<< "\" for index " << "` for index `"
<< indtab.getName() << endl; << indtab.getName() << "`" << endl;
return false; return false;
} }
NdbTableImpl& base = NdbTableImpl::getImpl(*prim); NdbTableImpl& base = NdbTableImpl::getImpl(*prim);
NdbIndexImpl* idx; NdbIndexImpl* idx;
int id; Vector<BaseString> split_idx;
char idxName[255], buf[255]; {
if(sscanf(indtab.getName(), "%[^/]/%[^/]/%d/%s", BaseString tmp(indtab.getName());
buf, buf, &id, idxName) != 4){ if (tmp.split(split_idx, "/") != 4)
err << "Invalid index name format " << indtab.getName() << endl; {
err << "Invalid index name format `" << indtab.getName() << "`" << endl;
return false; return false;
} }
}
if(NdbDictInterface::create_index_obj_from_table(&idx, &indtab, &base)) if(NdbDictInterface::create_index_obj_from_table(&idx, &indtab, &base))
{ {
err << "Failed to create index " << idxName err << "Failed to create index `" << split_idx[3]
<< " on " << split[2].c_str() << endl; << "` on " << split[2].c_str() << endl;
return false; return false;
} }
idx->setName(idxName); idx->setName(split_idx[3].c_str());
if(dict->createIndex(* idx) != 0) if(dict->createIndex(* idx) != 0)
{ {
delete idx; delete idx;
err << "Failed to create index " << idxName err << "Failed to create index `" << split_idx[3].c_str()
<< " on " << split[2].c_str() << endl << "` on `" << split[2].c_str() << "`" << endl
<< dict->getNdbError() << endl; << dict->getNdbError() << endl;
return false; return false;
} }
delete idx; delete idx;
info << "Successfully created index " << idxName info << "Successfully created index `" << split_idx[3].c_str()
<< " on " << split[2].c_str() << endl; << "` on `" << split[2].c_str() << "`" << endl;
} }
return true; return true;
} }
......
...@@ -559,8 +559,8 @@ main(int argc, char** argv) ...@@ -559,8 +559,8 @@ main(int argc, char** argv)
for(Uint32 j= 0; j < g_consumers.size(); j++) for(Uint32 j= 0; j < g_consumers.size(); j++)
if (!g_consumers[j]->table(* table)) if (!g_consumers[j]->table(* table))
{ {
err << "Restore: Failed to restore table: "; err << "Restore: Failed to restore table: `";
err << table->getTableName() << " ... Exiting " << endl; err << table->getTableName() << "` ... Exiting " << endl;
exitHandler(NDBT_FAILED); exitHandler(NDBT_FAILED);
} }
} }
......
...@@ -1148,14 +1148,16 @@ int ha_ndbcluster::build_index_list(Ndb *ndb, TABLE *tab, enum ILBP phase) ...@@ -1148,14 +1148,16 @@ int ha_ndbcluster::build_index_list(Ndb *ndb, TABLE *tab, enum ILBP phase)
{ {
DBUG_PRINT("info", ("Get handle to index %s", index_name)); DBUG_PRINT("info", ("Get handle to index %s", index_name));
const NDBINDEX *index= dict->getIndex(index_name, m_tabname); const NDBINDEX *index= dict->getIndex(index_name, m_tabname);
if (!index) DBUG_RETURN(1); if (!index)
ERR_RETURN(dict->getNdbError());
m_index[i].index= (void *) index; m_index[i].index= (void *) index;
} }
if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX) if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX)
{ {
DBUG_PRINT("info", ("Get handle to unique_index %s", unique_index_name)); DBUG_PRINT("info", ("Get handle to unique_index %s", unique_index_name));
const NDBINDEX *index= dict->getIndex(unique_index_name, m_tabname); const NDBINDEX *index= dict->getIndex(unique_index_name, m_tabname);
if (!index) DBUG_RETURN(1); if (!index)
ERR_RETURN(dict->getNdbError());
m_index[i].unique_index= (void *) index; m_index[i].unique_index= (void *) index;
error= fix_unique_index_attr_order(m_index[i], index, key_info); error= fix_unique_index_attr_order(m_index[i], index, key_info);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment