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){
BaseString tmp(name);
Vector<BaseString> split;
if(tmp.split(split, "/") != 3){
err << "Invalid table name format " << name << endl;
err << "Invalid table name format `" << name << "`" << endl;
return false;
}
......@@ -230,16 +230,17 @@ BackupRestore::table(const TableS & table){
if (dict->createTable(copy) == -1)
{
err << "Create table " << table.getTableName() << " failed: "
err << "Create table `" << table.getTableName() << "` failed: "
<< dict->getNdbError() << endl;
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());
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;
}
const NdbDictionary::Table* null = 0;
......@@ -257,52 +258,57 @@ BackupRestore::endOfTables(){
for(size_t i = 0; i<m_indexes.size(); i++){
NdbTableImpl & indtab = NdbTableImpl::getImpl(* m_indexes[i]);
BaseString tmp(indtab.m_primaryTable.c_str());
Vector<BaseString> split;
if(tmp.split(split, "/") != 3){
err << "Invalid table name format " << indtab.m_primaryTable.c_str()
<< endl;
{
BaseString tmp(indtab.m_primaryTable.c_str());
if (tmp.split(split, "/") != 3)
{
err << "Invalid table name format `" << indtab.m_primaryTable.c_str()
<< "`" << endl;
return false;
}
}
m_ndb->setDatabaseName(split[0].c_str());
m_ndb->setSchemaName(split[1].c_str());
const NdbDictionary::Table * prim = dict->getTable(split[2].c_str());
if(prim == 0){
err << "Unable to find base table \"" << split[2].c_str()
<< "\" for index "
<< indtab.getName() << endl;
err << "Unable to find base table `" << split[2].c_str()
<< "` for index `"
<< indtab.getName() << "`" << endl;
return false;
}
NdbTableImpl& base = NdbTableImpl::getImpl(*prim);
NdbIndexImpl* idx;
int id;
char idxName[255], buf[255];
if(sscanf(indtab.getName(), "%[^/]/%[^/]/%d/%s",
buf, buf, &id, idxName) != 4){
err << "Invalid index name format " << indtab.getName() << endl;
Vector<BaseString> split_idx;
{
BaseString tmp(indtab.getName());
if (tmp.split(split_idx, "/") != 4)
{
err << "Invalid index name format `" << indtab.getName() << "`" << endl;
return false;
}
}
if(NdbDictInterface::create_index_obj_from_table(&idx, &indtab, &base))
{
err << "Failed to create index " << idxName
<< " on " << split[2].c_str() << endl;
err << "Failed to create index `" << split_idx[3]
<< "` on " << split[2].c_str() << endl;
return false;
}
idx->setName(idxName);
idx->setName(split_idx[3].c_str());
if(dict->createIndex(* idx) != 0)
{
delete idx;
err << "Failed to create index " << idxName
<< " on " << split[2].c_str() << endl
err << "Failed to create index `" << split_idx[3].c_str()
<< "` on `" << split[2].c_str() << "`" << endl
<< dict->getNdbError() << endl;
return false;
}
delete idx;
info << "Successfully created index " << idxName
<< " on " << split[2].c_str() << endl;
info << "Successfully created index `" << split_idx[3].c_str()
<< "` on `" << split[2].c_str() << "`" << endl;
}
return true;
}
......
......@@ -559,8 +559,8 @@ main(int argc, char** argv)
for(Uint32 j= 0; j < g_consumers.size(); j++)
if (!g_consumers[j]->table(* table))
{
err << "Restore: Failed to restore table: ";
err << table->getTableName() << " ... Exiting " << endl;
err << "Restore: Failed to restore table: `";
err << table->getTableName() << "` ... Exiting " << endl;
exitHandler(NDBT_FAILED);
}
}
......
......@@ -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));
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;
}
if (idx_type == UNIQUE_ORDERED_INDEX || idx_type == UNIQUE_INDEX)
{
DBUG_PRINT("info", ("Get handle to unique_index %s", unique_index_name));
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;
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