Commit e938fb8f authored by tomas@mc05.(none)'s avatar tomas@mc05.(none)

removed version 2 backwards compatability from ndb restore

parent 443f1eb1
...@@ -101,42 +101,13 @@ RestoreMetaData::getStopGCP() const { ...@@ -101,42 +101,13 @@ RestoreMetaData::getStopGCP() const {
} }
int int
RestoreMetaData::loadContent(const char * catalog, RestoreMetaData::loadContent()
const char * schema)
{ {
#if NDB_VERSION_MAJOR >= VERSION_3X
if(getMajor(m_fileHeader.NdbVersion) < VERSION_3X) {
if(catalog == NULL)
return -1;
if(schema == NULL)
return -1;
}
/**
* if backup is of version 3 or higher, then
* return -2 to indicate for the user that he
* cannot restore tables to a certain catalog/schema
*/
if(getMajor(m_fileHeader.NdbVersion) >= VERSION_3X &&
(catalog != NULL ||
schema != NULL)) {
return -2;
}
#endif
#if NDB_VERSION_MAJOR < VERSION_3X
if(getMajor(m_fileHeader.NdbVersion) >= VERSION_3X)
{
return -2;
}
#endif
Uint32 noOfTables = readMetaTableList(); Uint32 noOfTables = readMetaTableList();
if(noOfTables == 0) if(noOfTables == 0)
return -3; return -3;
for(Uint32 i = 0; i<noOfTables; i++){ for(Uint32 i = 0; i<noOfTables; i++){
if(!readMetaTableDesc(catalog, schema)){ if(!readMetaTableDesc()){
return 0; return 0;
} }
} }
...@@ -170,8 +141,7 @@ RestoreMetaData::readMetaTableList() { ...@@ -170,8 +141,7 @@ RestoreMetaData::readMetaTableList() {
} }
bool bool
RestoreMetaData::readMetaTableDesc(const char * catalog, RestoreMetaData::readMetaTableDesc() {
const char * schema) {
Uint32 sectionInfo[2]; Uint32 sectionInfo[2];
...@@ -198,10 +168,7 @@ RestoreMetaData::readMetaTableDesc(const char * catalog, ...@@ -198,10 +168,7 @@ RestoreMetaData::readMetaTableDesc(const char * catalog,
return false; return false;
} // if } // if
return parseTableDescriptor(m_buffer, return parseTableDescriptor(m_buffer, len);
len,
catalog,
schema);
} }
bool bool
...@@ -287,72 +254,11 @@ static const Uint32 ...@@ -287,72 +254,11 @@ static const Uint32
AttrMapSize = sizeof(RestoreAttrMap) AttrMapSize = sizeof(RestoreAttrMap)
/ sizeof(SimpleProperties::SP2StructMapping); / sizeof(SimpleProperties::SP2StructMapping);
struct v2xKernel_to_v3xAPIMapping {
Int32 kernelConstant;
Int32 apiConstant;
};
enum v2xKernelTypes {
ExtUndefined=0,// Undefined
ExtInt, // 32 bit
ExtUnsigned, // 32 bit
ExtBigint, // 64 bit
ExtBigunsigned,// 64 Bit
ExtFloat, // 32-bit float
ExtDouble, // 64-bit float
ExtDecimal, // Precision, Scale
ExtChar, // Len
ExtVarchar, // Max len
ExtBinary, // Len
ExtVarbinary, // Max len
ExtDatetime, // Precision down to 1 sec (sizeof(Datetime) == 8 bytes )
ExtTimespec // Precision down to 1 nsec (sizeof(Datetime) == 12 bytes )
};
const
v2xKernel_to_v3xAPIMapping
columnTypeMapping[] = {
{ ExtInt, NdbDictionary::Column::Int },
{ ExtUnsigned, NdbDictionary::Column::Unsigned },
{ ExtBigint, NdbDictionary::Column::Bigint },
{ ExtBigunsigned, NdbDictionary::Column::Bigunsigned },
{ ExtFloat, NdbDictionary::Column::Float },
{ ExtDouble, NdbDictionary::Column::Double },
{ ExtDecimal, NdbDictionary::Column::Decimal },
{ ExtChar, NdbDictionary::Column::Char },
{ ExtVarchar, NdbDictionary::Column::Varchar },
{ ExtBinary, NdbDictionary::Column::Binary },
{ ExtVarbinary, NdbDictionary::Column::Varbinary },
{ ExtDatetime, NdbDictionary::Column::Datetime },
{ ExtTimespec, NdbDictionary::Column::Timespec },
{ -1, -1 }
};
static
NdbDictionary::Column::Type
convertToV3x(Int32 kernelConstant, const v2xKernel_to_v3xAPIMapping map[],
Int32 def)
{
int i = 0;
while(map[i].kernelConstant != kernelConstant){
if(map[i].kernelConstant == -1 &&
map[i].apiConstant == -1){
return (NdbDictionary::Column::Type)def;
}
i++;
}
return (NdbDictionary::Column::Type)map[i].apiConstant;
}
// Parse dictTabInfo buffer and pushback to to vector storage // Parse dictTabInfo buffer and pushback to to vector storage
// Using SimpleProperties (here we don't need ntohl, ref:ejonore) // Using SimpleProperties (here we don't need ntohl, ref:ejonore)
bool bool
RestoreMetaData::parseTableDescriptor(const Uint32 * data, RestoreMetaData::parseTableDescriptor(const Uint32 * data, Uint32 len)
Uint32 len, {
const char * catalog,
const char * schema) {
SimplePropertiesLinearReader it(data, len); SimplePropertiesLinearReader it(data, len);
SimpleProperties::UnpackStatus spStatus; SimpleProperties::UnpackStatus spStatus;
...@@ -362,49 +268,9 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data, ...@@ -362,49 +268,9 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data,
return false; return false;
} // if } // if
/**
* if backup was taken in v21x then there is no info about catalog,
* and schema. This infomration is concatenated to the tableName.
*
*/
char tableName[MAX_TAB_NAME_SIZE*2]; // * 2 for db and schema.-. char tableName[MAX_TAB_NAME_SIZE*2]; // * 2 for db and schema.-.
it.getString(tableName);
char tmpTableName[MAX_TAB_NAME_SIZE];
it.getString(tmpTableName);
#if NDB_VERSION_MAJOR >= VERSION_3X
/**
* only mess with name in version 3.
*/
/* switch(getMajor(m_fileHeader.NdbVersion)) {
*/
if(getMajor(m_fileHeader.NdbVersion) < VERSION_3X)
{
if(strcmp(tmpTableName, "SYSTAB_0") == 0 ||
strcmp(tmpTableName, "NDB$EVENTS_0") == 0)
{
sprintf(tableName,"sys/def/%s",tmpTableName);
}
else {
if(catalog == NULL && schema == NULL)
{
sprintf(tableName,"%s",tmpTableName);
}
else
{
sprintf(tableName,"%s/%s/%s",catalog,schema,tmpTableName);
}
}
}
else
sprintf(tableName,"%s",tmpTableName);
#elif NDB_VERSION_MAJOR < VERSION_3X
/**
* this is version two!
*/
sprintf(tableName,"%s",tmpTableName);
#endif
if (strlen(tableName) == 0) { if (strlen(tableName) == 0) {
err << "readMetaTableDesc getString table name error" << endl; err << "readMetaTableDesc getString table name error" << endl;
return false; return false;
...@@ -505,35 +371,9 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data, ...@@ -505,35 +371,9 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data,
debug << " with " << table->getNoOfAttributes() << " attributes" << endl; debug << " with " << table->getNoOfAttributes() << " attributes" << endl;
allTables.push_back(table); allTables.push_back(table);
#ifndef restore_old_types
NdbTableImpl* tableImpl = 0; NdbTableImpl* tableImpl = 0;
int ret = NdbDictInterface::parseTableInfo(&tableImpl, data, len); int ret = NdbDictInterface::parseTableInfo(&tableImpl, data, len, false);
#if NDB_VERSION_MAJOR >= VERSION_3X
NdbDictionary::Column::Type type;
if(getMajor(m_fileHeader.NdbVersion) < VERSION_3X) {
tableImpl->setName(tableName);
Uint32 noOfColumns = tableImpl->getNoOfColumns();
for(Uint32 i = 0 ; i < noOfColumns; i++) {
type = convertToV3x(tableImpl->getColumn(i)->m_extType,
columnTypeMapping,
-1);
if(type == -1)
{
ndbout_c("Restore: Was not able to map external type %d (in v2x) "
" to a proper type in v3x", tableImpl->getColumn(i)->m_extType);
return false;
}
else
{
tableImpl->getColumn(i)->m_type = type;
}
}
}
#endif
if (ret != 0) { if (ret != 0) {
err << "parseTableInfo " << tableName << " failed" << endl; err << "parseTableInfo " << tableName << " failed" << endl;
return false; return false;
...@@ -542,7 +382,7 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data, ...@@ -542,7 +382,7 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data,
return false; return false;
debug << "parseTableInfo " << tableName << " done" << endl; debug << "parseTableInfo " << tableName << " done" << endl;
table->m_dictTable = tableImpl; table->m_dictTable = tableImpl;
#endif
return true; return true;
} }
......
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include <ndb_version.h> #include <ndb_version.h>
#include <version.h> #include <version.h>
#define VERSION_3X 3
const int FileNameLenC = 256; const int FileNameLenC = 256;
const int TableNameLenC = 256; const int TableNameLenC = 256;
const int AttrNameLenC = 256; const int AttrNameLenC = 256;
...@@ -150,11 +147,8 @@ class TableS { ...@@ -150,11 +147,8 @@ class TableS {
const bool nullable, const bool nullable,
const KeyType key); const KeyType key);
#ifndef restore_old_types
public: public:
class NdbDictionary::Table* m_dictTable; class NdbDictionary::Table* m_dictTable;
#endif
public:
TableS (const char * name){ TableS (const char * name){
snprintf(tableName, sizeof(tableName), name); snprintf(tableName, sizeof(tableName), name);
m_noOfNullable = m_nullBitmaskSize = 0; m_noOfNullable = m_nullBitmaskSize = 0;
...@@ -244,8 +238,7 @@ class RestoreMetaData : public BackupFile { ...@@ -244,8 +238,7 @@ class RestoreMetaData : public BackupFile {
myVector<TableS *> allTables; myVector<TableS *> allTables;
bool readMetaFileHeader(); bool readMetaFileHeader();
bool readMetaTableDesc(const char * catalog, bool readMetaTableDesc();
const char * schema);
bool readGCPEntry(); bool readGCPEntry();
Uint32 readMetaTableList(); Uint32 readMetaTableList();
...@@ -253,17 +246,14 @@ class RestoreMetaData : public BackupFile { ...@@ -253,17 +246,14 @@ class RestoreMetaData : public BackupFile {
Uint32 m_startGCP; Uint32 m_startGCP;
Uint32 m_stopGCP; Uint32 m_stopGCP;
bool parseTableDescriptor(const Uint32 * data, Uint32 len, bool parseTableDescriptor(const Uint32 * data, Uint32 len);
const char * catalog,
const char * schema);
public: public:
RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo); RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo);
~RestoreMetaData(); ~RestoreMetaData();
int loadContent(const char * catalog, int loadContent();
const char * schema);
......
...@@ -69,10 +69,6 @@ typedef struct { ...@@ -69,10 +69,6 @@ typedef struct {
} restore_callback_t; } restore_callback_t;
static const char* ga_connect_NDB = NULL; static const char* ga_connect_NDB = NULL;
static const char* ga_schema = NULL;
static const char* ga_catalog = NULL;
/** /**
* print and restore flags * print and restore flags
...@@ -206,18 +202,6 @@ readArguments(const int argc, const char** argv) ...@@ -206,18 +202,6 @@ readArguments(const int argc, const char** argv)
"No of parallel transactions during restore of data." "No of parallel transactions during restore of data."
"(parallelism can be 1 to 1024)", "(parallelism can be 1 to 1024)",
"Parallelism"}, "Parallelism"},
#if NDB_VERSION_MAJOR >= VERSION_3X
{ "catalog", 'd', arg_string, &ga_catalog,
"Specifies the catalog/database where the data should be restored to. "
"Restores only to backups taken with v.2.x and restored on >v.3.x "
"systems. Note: system tables (if restored) defaults to sys/def/ ",
"catalog"},
{ "schema", 's', arg_string, &ga_schema,
"Specifies the schema where the data should be restored to."
"Restores only to backups taken with v.2.x and restored on >v.3.x "
"systems. Note: system tables (if restored) defaults to sys/def/ ",
"schema"},
#endif
#ifdef USE_MYSQL #ifdef USE_MYSQL
{ "use_mysql", '\0', arg_flag, &use_mysql, { "use_mysql", '\0', arg_flag, &use_mysql,
"Restore meta data via mysql. Systab will be ignored. Data is restored " "Restore meta data via mysql. Systab will be ignored. Data is restored "
...@@ -353,10 +337,6 @@ main(int argc, const char** argv) ...@@ -353,10 +337,6 @@ main(int argc, const char** argv)
{ {
return -1; return -1;
} }
// Turn off table name completion
#if NDB_VERSION_MAJOR >= VERSION_3X
Ndb::useFullyQualifiedNames(false);
#endif
/** /**
* we must always load meta data, even if we will only print it to stdout * we must always load meta data, even if we will only print it to stdout
...@@ -368,41 +348,19 @@ main(int argc, const char** argv) ...@@ -368,41 +348,19 @@ main(int argc, const char** argv)
return -1; return -1;
} }
/** /**
* check wheater we can restore the backup (right version, and if that * check wheater we can restore the backup (right version).
* version needs catalog and schema specified.
*/ */
int res = metaData.loadContent(ga_catalog, ga_schema); int res = metaData.loadContent();
if (res == 0) if (res == 0)
{ {
ndbout_c("Restore: Failed to load content"); ndbout_c("Restore: Failed to load content");
return -1; return -1;
} }
if (res == -1)
{
ndbout_c("Restore: The backup is from a NDB Cluster v.2.x version. "
"To restore this backup on a > 3.x version you must specify "
"catalog and schema.");
return -1;
}
if (res == -2)
{
#ifdef NDB_VERSION
ndbout_c("Restore: The backup is from a NDB Cluster v.3.x version "
"Catalog and schema are invalid parameters since they "
"already exist implicitly.");
#endif
#ifdef NDB_KERNEL_VERSION
ndbout_c("Restore: The backup is from a NDB Cluster v.3.x version "
"It is not possible to restore a 3.x backup on v.2.x. ");
#endif
return -1;
}
if (res == -3) if (res == -3)
{ {
ndbout_c("Restore: The backup contains no tables " ndbout_c("Restore: The backup contains no tables ");
"Catalog and schema are invalid parameters. ");
return -1; return -1;
} }
...@@ -879,10 +837,14 @@ BackupRestore::init() ...@@ -879,10 +837,14 @@ BackupRestore::init()
Ndb::setConnectString(ga_connect_NDB); Ndb::setConnectString(ga_connect_NDB);
} }
m_ndb = new Ndb("TEST_DB"); m_ndb = new Ndb();
if (m_ndb == NULL) if (m_ndb == NULL)
return false; return false;
// Turn off table name completion
m_ndb->useFullyQualifiedNames(false);
m_ndb->init(1024); m_ndb->init(1024);
if (m_ndb->waitUntilReady(30) != 0) if (m_ndb->waitUntilReady(30) != 0)
{ {
...@@ -1106,7 +1068,6 @@ BackupRestore::table(const TableS & table){ ...@@ -1106,7 +1068,6 @@ BackupRestore::table(const TableS & table){
{ {
return true; return true;
} }
#ifndef restore_old_types
NdbDictionary::Dictionary* dict = m_ndb->getDictionary(); NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
if (dict->createTable(*table.m_dictTable) == -1) if (dict->createTable(*table.m_dictTable) == -1)
{ {
...@@ -1116,81 +1077,6 @@ BackupRestore::table(const TableS & table){ ...@@ -1116,81 +1077,6 @@ BackupRestore::table(const TableS & table){
} }
info << "Successfully restored table " << table.getTableName()<< endl ; info << "Successfully restored table " << table.getTableName()<< endl ;
return true; return true;
#else
NdbSchemaCon * tableTransaction = 0;
NdbSchemaOp * tableOp = 0;
tableTransaction = m_ndb->startSchemaTransaction();
if (tableTransaction == NULL)
{
err << table.getTableName()
<< " - BackupRestore::table cannot startSchemaTransaction: "
<< tableTransaction->getNdbError() << endl;
return false;
} // if
tableOp = tableTransaction->getNdbSchemaOp();
if (tableOp == NULL)
{
err << table.getTableName()
<< " - BackupRestore::table cannot getNdbSchemaOp: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
// TODO: check for errors in table attributes. set aTupleKey
int check = 0;
check = tableOp->createTable(table.getTableName());
// aTableSize = 8, Not used?
// aTupleKey = TupleKey, go through attributes and check if there is a PK
// and so on....
if (check == -1)
{
err << table.getTableName()
<< " - BackupRestore::table cannot createTable: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
// Create attributes from meta data
for (int i = 0; i < table.getNoOfAttributes(); i++)
{
const AttributeDesc* desc = table[i];
check = tableOp->createAttribute(desc->name, // Attr name
desc->key, // Key type
desc->size, // bits
desc->arraySize,
desc->type,
MMBased, // only supported
desc->nullable
// Rest is don't care for the moment
);
if (check == -1)
{
err << table.getTableName()
<< " - RestoreDataIterator::createTable cannot createAttribute: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
} // for
if (tableTransaction->execute() == -1)
{
err << table.getTableName()
<< " - RestoreDataIterator::createTable cannot execute transaction: "
<< tableTransaction->getNdbError() << endl;
m_ndb->closeSchemaTransaction(tableTransaction);
return false;
} // if
m_ndb->closeSchemaTransaction(tableTransaction);
info << "Successfully created table " << table.getTableName() << endl;
return true ;
#endif
} }
...@@ -1314,26 +1200,6 @@ void BackupRestore::tupleAsynch(const TupleS & tup, restore_callback_t * cbData) ...@@ -1314,26 +1200,6 @@ void BackupRestore::tupleAsynch(const TupleS & tup, restore_callback_t * cbData)
Uint32 length = (size * arraySize) / 8; Uint32 length = (size * arraySize) / 8;
if (key == TupleKey) if (key == TupleKey)
{ {
#if NDB_VERSION_MAJOR >= VERSION3X
/**
* Convert VARCHAR from v.2x to v3x representation
*/
if (getMajor(tup.getTable()->getBackupVersion()) < VERSION_3X &&
((tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varbinary ) ||
(tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varchar)) && !attr->Data.null)
{
char * src = dataPtr;
char var_len[2];
var_len[0]= *(dataPtr+length - 2);
var_len[1]= *(dataPtr+length - 1);
memmove((char*)dataPtr+2, dataPtr, length);
src[0] = var_len[0];
src[1] = var_len[1];
dataPtr = src;
}
#endif
ret = op->equal(i, dataPtr, length); ret = op->equal(i, dataPtr, length);
if (ret<0) if (ret<0)
{ {
...@@ -1358,48 +1224,21 @@ void BackupRestore::tupleAsynch(const TupleS & tup, restore_callback_t * cbData) ...@@ -1358,48 +1224,21 @@ void BackupRestore::tupleAsynch(const TupleS & tup, restore_callback_t * cbData)
KeyType key = attr->Desc->key; KeyType key = attr->Desc->key;
char * dataPtr = attr->Data.string_value; char * dataPtr = attr->Data.string_value;
Uint32 length = (size * arraySize) / 8; Uint32 length = (size * arraySize) / 8;
#if NDB_VERSION_MAJOR >= VERSION3X
/**
* Convert VARCHAR from v.2x to v3x representation
*/
if (getMajor(tup.getTable()->getBackupVersion()) < VERSION_3X &&
((tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varbinary ) ||
(tup.getTable()->m_dictTable->getColumn(i)->getType() ==
NdbDictionary::Column::Varchar)) && !attr->Data.null)
{
char * src = dataPtr;
char var_len[2];
var_len[0]= *(dataPtr+length - 2);//length is last 2 bytes
var_len[1]= *(dataPtr+length - 1);
memmove((char*)dataPtr+2, dataPtr, length);
src[0] = var_len[0];
src[1] = var_len[1];
dataPtr = src;
}
#endif
if (key == NoKey && !attr->Data.null) if (key == NoKey && !attr->Data.null)
{
ret = op->setValue(i, dataPtr, length); ret = op->setValue(i, dataPtr, length);
}
else if (key == NoKey && attr->Data.null) else if (key == NoKey && attr->Data.null)
{
ret = op->setValue(i, NULL, 0); ret = op->setValue(i, NULL, 0);
}
if (ret<0) if (ret<0)
{ {
ndbout_c("Column: %d type %d",i, ndbout_c("Column: %d type %d",i,
tup.getTable()->m_dictTable->getColumn(i)->getType()); tup.getTable()->m_dictTable->getColumn(i)->getType());
if (asynchErrorHandler(asynchTrans[nPreparedTransactions], m_ndb)) if (asynchErrorHandler(asynchTrans[nPreparedTransactions], m_ndb))
{ {
retries++; retries++;
continue; continue;
} }
asynchExitHandler(); asynchExitHandler();
} }
} }
......
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