Commit e82eabcb authored by unknown's avatar unknown

more ndb restore cleanup

parent d294a753
...@@ -122,7 +122,8 @@ RestoreMetaData::readMetaTableList() { ...@@ -122,7 +122,8 @@ RestoreMetaData::readMetaTableList() {
Uint32 sectionInfo[2]; Uint32 sectionInfo[2];
if (fread(&sectionInfo, sizeof(sectionInfo), 1, m_file) != 1){ if (buffer_read(&sectionInfo, sizeof(sectionInfo), 1) != 1){
err << "readMetaTableList read header error" << endl;
return 0; return 0;
} }
sectionInfo[0] = ntohl(sectionInfo[0]); sectionInfo[0] = ntohl(sectionInfo[0]);
...@@ -130,11 +131,9 @@ RestoreMetaData::readMetaTableList() { ...@@ -130,11 +131,9 @@ RestoreMetaData::readMetaTableList() {
const Uint32 tabCount = sectionInfo[1] - 2; const Uint32 tabCount = sectionInfo[1] - 2;
const Uint32 len = 4 * tabCount; void *tmp;
if(createBuffer(len) == 0) if (buffer_get_ptr(&tmp, 4, tabCount) != tabCount){
abort(); err << "readMetaTableList read tabCount error" << endl;
if (fread(m_buffer, 1, len, m_file) != len){
return 0; return 0;
} }
...@@ -147,7 +146,7 @@ RestoreMetaData::readMetaTableDesc() { ...@@ -147,7 +146,7 @@ RestoreMetaData::readMetaTableDesc() {
Uint32 sectionInfo[2]; Uint32 sectionInfo[2];
// Read section header // Read section header
if (fread(&sectionInfo, sizeof(sectionInfo), 1, m_file) != 1){ if (buffer_read(&sectionInfo, sizeof(sectionInfo), 1) != 1){
err << "readMetaTableDesc read header error" << endl; err << "readMetaTableDesc read header error" << endl;
return false; return false;
} // if } // if
...@@ -156,20 +155,15 @@ RestoreMetaData::readMetaTableDesc() { ...@@ -156,20 +155,15 @@ RestoreMetaData::readMetaTableDesc() {
assert(sectionInfo[0] == BackupFormat::TABLE_DESCRIPTION); assert(sectionInfo[0] == BackupFormat::TABLE_DESCRIPTION);
// Allocate temporary storage for dictTabInfo buffer
const Uint32 len = (sectionInfo[1] - 2);
if (createBuffer(4 * (len+1)) == NULL) {
err << "readMetaTableDesc allocation error" << endl;
return false;
} // if
// Read dictTabInfo buffer // Read dictTabInfo buffer
if (fread(m_buffer, 4, len, m_file) != len){ const Uint32 len = (sectionInfo[1] - 2);
void *ptr;
if (buffer_get_ptr(&ptr, 4, len) != len){
err << "readMetaTableDesc read error" << endl; err << "readMetaTableDesc read error" << endl;
return false; return false;
} // if } // if
return parseTableDescriptor(m_buffer, len); return parseTableDescriptor((Uint32*)ptr, len);
} }
bool bool
...@@ -177,11 +171,10 @@ RestoreMetaData::readGCPEntry() { ...@@ -177,11 +171,10 @@ RestoreMetaData::readGCPEntry() {
Uint32 data[4]; Uint32 data[4];
BackupFormat::CtlFile::GCPEntry * dst = BackupFormat::CtlFile::GCPEntry * dst =
(BackupFormat::CtlFile::GCPEntry *)&data[0]; (BackupFormat::CtlFile::GCPEntry *)&data[0];
if(fread(dst, 4, 4, m_file) != 4){ if(buffer_read(dst, 4, 4) != 4){
err << "readGCPEntry read error" << endl; err << "readGCPEntry read error" << endl;
return false; return false;
} }
...@@ -212,6 +205,12 @@ TableS::TableS(NdbTableImpl* tableImpl) ...@@ -212,6 +205,12 @@ TableS::TableS(NdbTableImpl* tableImpl)
createAttr(tableImpl->getColumn(i)); createAttr(tableImpl->getColumn(i));
} }
TableS::~TableS()
{
for (int i = 0; i < allAttributesDesc.size(); i++)
delete allAttributesDesc[i];
}
// Parse dictTabInfo buffer and pushback to to vector storage // Parse dictTabInfo buffer and pushback to to vector storage
bool bool
RestoreMetaData::parseTableDescriptor(const Uint32 * data, Uint32 len) RestoreMetaData::parseTableDescriptor(const Uint32 * data, Uint32 len)
...@@ -247,31 +246,18 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data, Uint32 len) ...@@ -247,31 +246,18 @@ RestoreMetaData::parseTableDescriptor(const Uint32 * data, Uint32 len)
// Constructor // Constructor
RestoreDataIterator::RestoreDataIterator(const RestoreMetaData & md, void (* _free_data_callback)()) RestoreDataIterator::RestoreDataIterator(const RestoreMetaData & md, void (* _free_data_callback)())
: m_metaData(md), free_data_callback(_free_data_callback) : BackupFile(_free_data_callback), m_metaData(md)
{ {
debug << "RestoreDataIterator constructor" << endl; debug << "RestoreDataIterator constructor" << endl;
setDataFile(md, 0); setDataFile(md, 0);
m_buffer_sz = 64*1024;
m_buffer = malloc(m_buffer_sz);
m_buffer_ptr = m_buffer;
m_buffer_data_left = 0;
}
RestoreDataIterator::~RestoreDataIterator()
{
if (m_buffer)
free(m_buffer);
} }
TupleS & TupleS::operator=(const TupleS& tuple) TupleS & TupleS::operator=(const TupleS& tuple)
{ {
prepareRecord(*tuple.m_currentTable); prepareRecord(*tuple.m_currentTable);
if (allAttrData) { if (allAttrData)
allAttrData= new AttributeData[getNoOfAttributes()];
memcpy(allAttrData, tuple.allAttrData, getNoOfAttributes()*sizeof(AttributeData)); memcpy(allAttrData, tuple.allAttrData, getNoOfAttributes()*sizeof(AttributeData));
}
return *this; return *this;
}; };
...@@ -296,12 +282,16 @@ AttributeData * TupleS::getData(int i) const{ ...@@ -296,12 +282,16 @@ AttributeData * TupleS::getData(int i) const{
bool bool
TupleS::prepareRecord(const TableS & tab){ TupleS::prepareRecord(const TableS & tab){
if (allAttrData) { if (allAttrData) {
if (getNoOfAttributes() == tab.getNoOfAttributes())
{
m_currentTable = &tab;
return true;
}
delete [] allAttrData; delete [] allAttrData;
m_currentTable= 0; m_currentTable= 0;
} }
allAttrData = new AttributeData[tab.getNoOfAttributes()]; allAttrData = new AttributeData[tab.getNoOfAttributes()];
if (allAttrData == 0) if (allAttrData == 0)
return false; return false;
...@@ -310,47 +300,12 @@ TupleS::prepareRecord(const TableS & tab){ ...@@ -310,47 +300,12 @@ TupleS::prepareRecord(const TableS & tab){
return true; return true;
} }
Uint32 RestoreDataIterator::get_buffer_ptr(void **p_buf_ptr, Uint32 size, Uint32 nmemb, FILE *stream)
{
Uint32 sz = size*nmemb;
if (sz > m_buffer_data_left) {
if (free_data_callback)
(*free_data_callback)();
memcpy(m_buffer, m_buffer_ptr, m_buffer_data_left);
size_t r = fread(((char *)m_buffer) + m_buffer_data_left, 1, m_buffer_sz - m_buffer_data_left, stream);
m_buffer_data_left += r;
m_buffer_ptr = m_buffer;
if (sz > m_buffer_data_left)
sz = size * (m_buffer_data_left / size);
}
*p_buf_ptr = m_buffer_ptr;
m_buffer_ptr = ((char*)m_buffer_ptr)+sz;
m_buffer_data_left -= sz;
return sz/size;
}
Uint32 RestoreDataIterator::fread_buffer(void *ptr, Uint32 size, Uint32 nmemb, FILE *stream)
{
void *buf_ptr;
Uint32 r = get_buffer_ptr(&buf_ptr, size, nmemb, stream);
memcpy(ptr, buf_ptr, r*size);
return r;
}
const TupleS * const TupleS *
RestoreDataIterator::getNextTuple(int & res) RestoreDataIterator::getNextTuple(int & res)
{ {
Uint32 dataLength = 0; Uint32 dataLength = 0;
// Read record length // Read record length
if (fread_buffer(&dataLength, sizeof(dataLength), 1, m_file) != 1){ if (buffer_read(&dataLength, sizeof(dataLength), 1) != 1){
err << "getNextTuple:Error reading length of data part" << endl; err << "getNextTuple:Error reading length of data part" << endl;
res = -1; res = -1;
return NULL; return NULL;
...@@ -370,7 +325,7 @@ RestoreDataIterator::getNextTuple(int & res) ...@@ -370,7 +325,7 @@ RestoreDataIterator::getNextTuple(int & res)
// Read tuple data // Read tuple data
void *_buf_ptr; void *_buf_ptr;
if (get_buffer_ptr(&_buf_ptr, 1, dataLenBytes, m_file) != dataLenBytes) { if (buffer_get_ptr(&_buf_ptr, 1, dataLenBytes) != dataLenBytes) {
err << "getNextTuple:Read error: " << endl; err << "getNextTuple:Read error: " << endl;
res = -1; res = -1;
return NULL; return NULL;
...@@ -468,12 +423,17 @@ RestoreDataIterator::getNextTuple(int & res) ...@@ -468,12 +423,17 @@ RestoreDataIterator::getNextTuple(int & res)
return &m_tuple; return &m_tuple;
} // RestoreDataIterator::getNextTuple } // RestoreDataIterator::getNextTuple
BackupFile::BackupFile(){ BackupFile::BackupFile(void (* _free_data_callback)())
: free_data_callback(_free_data_callback)
{
m_file = 0; m_file = 0;
m_path[0] = 0; m_path[0] = 0;
m_fileName[0] = 0; m_fileName[0] = 0;
m_buffer = 0;
m_bufferSize = 0; m_buffer_sz = 64*1024;
m_buffer = malloc(m_buffer_sz);
m_buffer_ptr = m_buffer;
m_buffer_data_left = 0;
} }
BackupFile::~BackupFile(){ BackupFile::~BackupFile(){
...@@ -494,15 +454,54 @@ BackupFile::openFile(){ ...@@ -494,15 +454,54 @@ BackupFile::openFile(){
return m_file != 0; return m_file != 0;
} }
Uint32 * Uint32 BackupFile::buffer_get_ptr_ahead(void **p_buf_ptr, Uint32 size, Uint32 nmemb)
BackupFile::createBuffer(Uint32 bytes){ {
if(bytes > m_bufferSize){ Uint32 sz = size*nmemb;
if(m_buffer != 0) if (sz > m_buffer_data_left) {
free(m_buffer);
m_bufferSize = m_bufferSize + 2 * bytes; if (free_data_callback)
m_buffer = (Uint32*)malloc(m_bufferSize); (*free_data_callback)();
memcpy(m_buffer, m_buffer_ptr, m_buffer_data_left);
size_t r = fread(((char *)m_buffer) + m_buffer_data_left, 1, m_buffer_sz - m_buffer_data_left, m_file);
m_buffer_data_left += r;
m_buffer_ptr = m_buffer;
if (sz > m_buffer_data_left)
sz = size * (m_buffer_data_left / size);
} }
return m_buffer;
*p_buf_ptr = m_buffer_ptr;
return sz/size;
}
Uint32 BackupFile::buffer_get_ptr(void **p_buf_ptr, Uint32 size, Uint32 nmemb)
{
Uint32 r = buffer_get_ptr_ahead(p_buf_ptr, size, nmemb);
m_buffer_ptr = ((char*)m_buffer_ptr)+(r*size);
m_buffer_data_left -= (r*size);
return r;
}
Uint32 BackupFile::buffer_read_ahead(void *ptr, Uint32 size, Uint32 nmemb)
{
void *buf_ptr;
Uint32 r = buffer_get_ptr_ahead(&buf_ptr, size, nmemb);
memcpy(ptr, buf_ptr, r*size);
return r;
}
Uint32 BackupFile::buffer_read(void *ptr, Uint32 size, Uint32 nmemb)
{
void *buf_ptr;
Uint32 r = buffer_get_ptr(&buf_ptr, size, nmemb);
memcpy(ptr, buf_ptr, r*size);
return r;
} }
void void
...@@ -563,7 +562,7 @@ BackupFile::readHeader(){ ...@@ -563,7 +562,7 @@ BackupFile::readHeader(){
return false; return false;
} }
if(fread(&m_fileHeader, sizeof(m_fileHeader), 1, m_file) != 1){ if(buffer_read(&m_fileHeader, sizeof(m_fileHeader), 1) != 1){
err << "readDataFileHeader: Error reading header" << endl; err << "readDataFileHeader: Error reading header" << endl;
return false; return false;
} }
...@@ -611,14 +610,13 @@ BackupFile::validateFooter(){ ...@@ -611,14 +610,13 @@ BackupFile::validateFooter(){
return true; return true;
} }
bool bool RestoreDataIterator::readFragmentHeader(int & ret)
RestoreDataIterator::readFragmentHeader(int & ret)
{ {
BackupFormat::DataFile::FragmentHeader Header; BackupFormat::DataFile::FragmentHeader Header;
debug << "RestoreDataIterator::getNextFragment" << endl; debug << "RestoreDataIterator::getNextFragment" << endl;
if (fread_buffer(&Header, sizeof(Header), 1, m_file) != 1){ if (buffer_read(&Header, sizeof(Header), 1) != 1){
ret = 0; ret = 0;
return false; return false;
} // if } // if
...@@ -663,7 +661,7 @@ bool ...@@ -663,7 +661,7 @@ bool
RestoreDataIterator::validateFragmentFooter() { RestoreDataIterator::validateFragmentFooter() {
BackupFormat::DataFile::FragmentFooter footer; BackupFormat::DataFile::FragmentFooter footer;
if (fread_buffer(&footer, sizeof(footer), 1, m_file) != 1){ if (buffer_read(&footer, sizeof(footer), 1) != 1){
err << "getFragmentFooter:Error reading fragment footer" << endl; err << "getFragmentFooter:Error reading fragment footer" << endl;
return false; return false;
} }
...@@ -771,45 +769,32 @@ RestoreLogIterator::getNextLogEntry(int & res) { ...@@ -771,45 +769,32 @@ RestoreLogIterator::getNextLogEntry(int & res) {
// Read record length // Read record length
typedef BackupFormat::LogFile::LogEntry LogE; typedef BackupFormat::LogFile::LogEntry LogE;
Uint32 gcp = 0; Uint32 gcp= 0;
LogE * logE = 0; LogE * logE= 0;
Uint32 len = ~0; Uint32 len= ~0;
const Uint32 stopGCP = m_metaData.getStopGCP(); const Uint32 stopGCP = m_metaData.getStopGCP();
do { do {
if (buffer_read_ahead(&len, sizeof(Uint32), 1) != 1){
if(createBuffer(4) == 0) { res= -1;
res = -1; return 0;
return NULL;
} }
len= ntohl(len);
Uint32 data_len = sizeof(Uint32) + len*4;
if (fread(m_buffer, sizeof(Uint32), 1, m_file) != 1){ if (buffer_get_ptr((void **)(&logE), 1, data_len) != data_len) {
res = -1; res= -2;
return NULL; return 0;
} }
m_buffer[0] = ntohl(m_buffer[0]);
len = m_buffer[0];
if(len == 0){ if(len == 0){
res = 0; res= 0;
return 0; return 0;
} }
if(createBuffer(4 * (len + 1)) == 0){ logE->TableId= ntohl(logE->TableId);
res = -1; logE->TriggerEvent= ntohl(logE->TriggerEvent);
return NULL;
}
if (fread(&m_buffer[1], 4, len, m_file) != len) { const bool hasGcp= (logE->TriggerEvent & 0x10000) != 0;
res = -1;
return NULL;
}
logE = (LogE *)&m_buffer[0];
logE->TableId = ntohl(logE->TableId);
logE->TriggerEvent = ntohl(logE->TriggerEvent);
const bool hasGcp = (logE->TriggerEvent & 0x10000) != 0;
logE->TriggerEvent &= 0xFFFF; logE->TriggerEvent &= 0xFFFF;
if(hasGcp){ if(hasGcp){
...@@ -818,9 +803,6 @@ RestoreLogIterator::getNextLogEntry(int & res) { ...@@ -818,9 +803,6 @@ RestoreLogIterator::getNextLogEntry(int & res) {
} }
} while(gcp > stopGCP + 1); } while(gcp > stopGCP + 1);
for(int i=0; i<m_logEntry.m_values.size();i++)
delete m_logEntry.m_values[i];
m_logEntry.m_values.clear();
m_logEntry.m_table = m_metaData.getTable(logE->TableId); m_logEntry.m_table = m_metaData.getTable(logE->TableId);
switch(logE->TriggerEvent){ switch(logE->TriggerEvent){
case TriggerEvent::TE_INSERT: case TriggerEvent::TE_INSERT:
...@@ -838,31 +820,32 @@ RestoreLogIterator::getNextLogEntry(int & res) { ...@@ -838,31 +820,32 @@ RestoreLogIterator::getNextLogEntry(int & res) {
} }
const TableS * tab = m_logEntry.m_table; const TableS * tab = m_logEntry.m_table;
m_logEntry.clear();
AttributeHeader * ah = (AttributeHeader *)&logE->Data[0]; AttributeHeader * ah = (AttributeHeader *)&logE->Data[0];
AttributeHeader *end = (AttributeHeader *)&logE->Data[len - 2]; AttributeHeader *end = (AttributeHeader *)&logE->Data[len - 2];
AttributeS * attr; AttributeS * attr;
while(ah < end){ while(ah < end){
attr = new AttributeS; attr= m_logEntry.add_attr();
if(attr == NULL) { if(attr == NULL) {
ndbout_c("Restore: Failed to allocate memory"); ndbout_c("Restore: Failed to allocate memory");
res = -1; res = -1;
return NULL; return 0;
} }
attr->Desc = (* tab)[ah->getAttributeId()]; attr->Desc = (* tab)[ah->getAttributeId()];
assert(attr->Desc != 0); assert(attr->Desc != 0);
const Uint32 sz = ah->getDataSize(); const Uint32 sz = ah->getDataSize();
if(sz == 0){ if(sz == 0){
attr->Data->null = true; attr->Data.null = true;
attr->Data->void_value = NULL; attr->Data.void_value = NULL;
} else { } else {
attr->Data->null = false; attr->Data.null = false;
attr->Data->void_value = ah->getDataPtr(); attr->Data.void_value = ah->getDataPtr();
} }
Twiddle(attr->Desc, attr->Data); Twiddle(attr->Desc, &(attr->Data));
m_logEntry.m_values.push_back(attr);
ah = ah->getNext(); ah = ah->getNext();
} }
...@@ -874,7 +857,7 @@ RestoreLogIterator::getNextLogEntry(int & res) { ...@@ -874,7 +857,7 @@ RestoreLogIterator::getNextLogEntry(int & res) {
NdbOut & NdbOut &
operator<<(NdbOut& ndbout, const AttributeS& attr){ operator<<(NdbOut& ndbout, const AttributeS& attr){
const AttributeData & data = *(attr.Data); const AttributeData & data = attr.Data;
const AttributeDesc & desc = *(attr.Desc); const AttributeDesc & desc = *(attr.Desc);
if (data.null) if (data.null)
...@@ -899,7 +882,7 @@ operator<<(NdbOut& ndbout, const TupleS& tuple) ...@@ -899,7 +882,7 @@ operator<<(NdbOut& ndbout, const TupleS& tuple)
{ {
AttributeData * attr_data = tuple.getData(i); AttributeData * attr_data = tuple.getData(i);
const AttributeDesc * attr_desc = tuple.getDesc(i); const AttributeDesc * attr_desc = tuple.getDesc(i);
const AttributeS attr = {attr_desc, attr_data}; const AttributeS attr = {attr_desc, *attr_data};
debug << i << " " << attr_desc->m_column->getName(); debug << i << " " << attr_desc->m_column->getName();
ndbout << attr; ndbout << attr;
...@@ -928,12 +911,12 @@ operator<<(NdbOut& ndbout, const LogEntry& logE) ...@@ -928,12 +911,12 @@ operator<<(NdbOut& ndbout, const LogEntry& logE)
ndbout << "Unknown log entry type (not insert, delete or update)" ; ndbout << "Unknown log entry type (not insert, delete or update)" ;
} }
for (int i = 0; i < logE.m_values.size();i++) for (int i = 0; i < logE.size();i++)
{ {
const AttributeS * attr = logE.m_values[i]; const AttributeS * attr = logE[i];
ndbout << attr->Desc->m_column->getName() << "="; ndbout << attr->Desc->m_column->getName() << "=";
ndbout << (* attr); ndbout << (* attr);
if (i < (logE.m_values.size() - 1)) if (i < (logE.size() - 1))
ndbout << ", "; ndbout << ", ";
} }
return ndbout; return ndbout;
......
...@@ -85,7 +85,7 @@ public: ...@@ -85,7 +85,7 @@ public:
struct AttributeS { struct AttributeS {
const AttributeDesc * Desc; const AttributeDesc * Desc;
AttributeData * Data; AttributeData Data;
}; };
class TupleS { class TupleS {
...@@ -97,7 +97,10 @@ private: ...@@ -97,7 +97,10 @@ private:
bool prepareRecord(const TableS &); bool prepareRecord(const TableS &);
public: public:
TupleS() {}; TupleS() {
m_currentTable= 0;
allAttrData= 0;
};
~TupleS() ~TupleS()
{ {
if (allAttrData) if (allAttrData)
...@@ -129,17 +132,13 @@ class TableS { ...@@ -129,17 +132,13 @@ class TableS {
Uint32 m_nullBitmaskSize; Uint32 m_nullBitmaskSize;
int pos; int pos;
char create_string[2048];
/*
char mysqlTableName[1024];
char mysqlDatabaseName[1024];
*/
void createAttr(NdbDictionary::Column *column); void createAttr(NdbDictionary::Column *column);
public: public:
class NdbDictionary::Table* m_dictTable; class NdbDictionary::Table* m_dictTable;
TableS (class NdbTableImpl* dictTable); TableS (class NdbTableImpl* dictTable);
~TableS();
Uint32 getTableId() const { Uint32 getTableId() const {
return m_dictTable->getTableId(); return m_dictTable->getTableId();
...@@ -192,18 +191,26 @@ protected: ...@@ -192,18 +191,26 @@ protected:
BackupFormat::FileHeader m_expectedFileHeader; BackupFormat::FileHeader m_expectedFileHeader;
Uint32 m_nodeId; Uint32 m_nodeId;
Uint32 * m_buffer;
Uint32 m_bufferSize; void * m_buffer;
Uint32 * createBuffer(Uint32 bytes); void * m_buffer_ptr;
Uint32 m_buffer_sz;
Uint32 m_buffer_data_left;
void (* free_data_callback)();
bool openFile(); bool openFile();
void setCtlFile(Uint32 nodeId, Uint32 backupId, const char * path); void setCtlFile(Uint32 nodeId, Uint32 backupId, const char * path);
void setDataFile(const BackupFile & bf, Uint32 no); void setDataFile(const BackupFile & bf, Uint32 no);
void setLogFile(const BackupFile & bf, Uint32 no); void setLogFile(const BackupFile & bf, Uint32 no);
Uint32 buffer_get_ptr(void **p_buf_ptr, Uint32 size, Uint32 nmemb);
Uint32 buffer_read(void *ptr, Uint32 size, Uint32 nmemb);
Uint32 buffer_get_ptr_ahead(void **p_buf_ptr, Uint32 size, Uint32 nmemb);
Uint32 buffer_read_ahead(void *ptr, Uint32 size, Uint32 nmemb);
void setName(const char * path, const char * name); void setName(const char * path, const char * name);
BackupFile(); BackupFile(void (* free_data_callback)() = 0);
~BackupFile(); ~BackupFile();
public: public:
bool readHeader(); bool readHeader();
...@@ -231,14 +238,11 @@ class RestoreMetaData : public BackupFile { ...@@ -231,14 +238,11 @@ class RestoreMetaData : public BackupFile {
bool parseTableDescriptor(const Uint32 * data, Uint32 len); bool parseTableDescriptor(const Uint32 * data, Uint32 len);
public: public:
RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo); RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo);
~RestoreMetaData(); virtual ~RestoreMetaData();
int loadContent(); int loadContent();
Uint32 getNoOfTables() const { return allTables.size();} Uint32 getNoOfTables() const { return allTables.size();}
const TableS * operator[](int i) const { return allTables[i];} const TableS * operator[](int i) const { return allTables[i];}
...@@ -254,24 +258,16 @@ class RestoreDataIterator : public BackupFile { ...@@ -254,24 +258,16 @@ class RestoreDataIterator : public BackupFile {
const TableS* m_currentTable; const TableS* m_currentTable;
TupleS m_tuple; TupleS m_tuple;
void * m_buffer;
void * m_buffer_ptr;
Uint32 m_buffer_sz;
Uint32 m_buffer_data_left;
void (* free_data_callback)();
public: public:
// Constructor // Constructor
RestoreDataIterator(const RestoreMetaData &, void (* free_data_callback)()); RestoreDataIterator(const RestoreMetaData &, void (* free_data_callback)());
~RestoreDataIterator(); ~RestoreDataIterator() {};
// Read data file fragment header // Read data file fragment header
bool readFragmentHeader(int & res); bool readFragmentHeader(int & res);
bool validateFragmentFooter(); bool validateFragmentFooter();
Uint32 get_buffer_ptr(void **p_buf_ptr, Uint32 size, Uint32 nmemb, FILE *stream);
Uint32 fread_buffer(void *ptr, Uint32 size, Uint32 nmemb, FILE *stream);
const TupleS *getNextTuple(int & res); const TupleS *getNextTuple(int & res);
}; };
...@@ -285,8 +281,34 @@ public: ...@@ -285,8 +281,34 @@ public:
EntryType m_type; EntryType m_type;
const TableS * m_table; const TableS * m_table;
myVector<AttributeS*> m_values; myVector<AttributeS*> m_values;
myVector<AttributeS*> m_values_e;
AttributeS *add_attr() {
AttributeS * attr;
if (m_values_e.size() > 0) {
attr = m_values_e[m_values_e.size()-1];
m_values_e.pop_back();
}
else
{
attr = new AttributeS;
}
m_values.push_back(attr);
return attr;
}
void clear() {
for(int i= 0; i < m_values.size(); i++)
m_values_e.push_back(m_values[i]);
m_values.clear();
}
~LogEntry()
{
for(int i= 0; i< m_values.size(); i++)
delete m_values[i];
for(int i= 0; i< m_values_e.size(); i++)
delete m_values_e[i];
}
int size() const { return m_values.size(); }
const AttributeS * operator[](int i) const { return m_values[i];}
}; };
class RestoreLogIterator : public BackupFile { class RestoreLogIterator : public BackupFile {
...@@ -297,6 +319,7 @@ private: ...@@ -297,6 +319,7 @@ private:
LogEntry m_logEntry; LogEntry m_logEntry;
public: public:
RestoreLogIterator(const RestoreMetaData &); RestoreLogIterator(const RestoreMetaData &);
virtual ~RestoreLogIterator() {};
const LogEntry * getNextLogEntry(int & res); const LogEntry * getNextLogEntry(int & res);
}; };
......
...@@ -21,20 +21,14 @@ ...@@ -21,20 +21,14 @@
class BackupConsumer { class BackupConsumer {
public: public:
virtual ~BackupConsumer() { }
virtual bool init() { return true;} virtual bool init() { return true;}
virtual bool table(const TableS &){return true;} virtual bool table(const TableS &){return true;}
#ifdef USE_MYSQL
virtual bool table(const TableS &, MYSQL* mysqlp) {return true;};
#endif
virtual void tuple(const TupleS &){} virtual void tuple(const TupleS &){}
virtual void tuple_free(){} virtual void tuple_free(){}
virtual void endOfTuples(){} virtual void endOfTuples(){}
virtual void logEntry(const LogEntry &){} virtual void logEntry(const LogEntry &){}
virtual void endOfLogEntrys(){} virtual void endOfLogEntrys(){}
protected:
#ifdef USE_MYSQL
int create_table_string(const TableS & table, char * ,char *);
#endif
}; };
#endif #endif
...@@ -27,47 +27,6 @@ BackupPrinter::table(const TableS & tab) ...@@ -27,47 +27,6 @@ BackupPrinter::table(const TableS & tab)
return true; return true;
} }
#ifdef USE_MYSQL
bool
BackupPrinter::table(const TableS & tab, MYSQL * mysql)
{
if (m_print || m_print_meta)
{
char tmpTabName[MAX_TAB_NAME_SIZE*2];
sprintf(tmpTabName, "%s", tab.getTableName());
char * database = strtok(tmpTabName, "/");
char * schema = strtok( NULL , "/");
char * tableName = strtok( NULL , "/");
/**
* this means that the user did not specify schema
* and it is a v2x backup
*/
if(database == NULL)
return false;
if(schema == NULL)
return false;
if(tableName==NULL)
tableName = schema;
char stmtCreateDB[255];
sprintf(stmtCreateDB,"CREATE DATABASE %s", database);
ndbout_c("%s", stmtCreateDB);
char buf [2048];
create_table_string(tab, tableName, buf);
ndbout_c("%s", buf);
ndbout_c("Successfully printed table: %s", tab.m_dictTable->getName());
}
return true;
}
#endif
void void
BackupPrinter::tuple(const TupleS & tup) BackupPrinter::tuple(const TupleS & tup)
{ {
......
...@@ -105,9 +105,8 @@ BackupRestore::~BackupRestore() ...@@ -105,9 +105,8 @@ BackupRestore::~BackupRestore()
bool bool
BackupRestore::table(const TableS & table){ BackupRestore::table(const TableS & table){
if (!m_restore_meta) if (!m_restore_meta)
{
return true; return true;
}
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)
{ {
...@@ -320,13 +319,14 @@ BackupRestore::tuple_free() ...@@ -320,13 +319,14 @@ BackupRestore::tuple_free()
if (!m_restore) if (!m_restore)
return; return;
if (m_transactions > 0) {
// Send all transactions to NDB // Send all transactions to NDB
if (m_transactions > 0)
m_ndb->sendPreparedTransactions(0); m_ndb->sendPreparedTransactions(0);
// Poll all transactions // Poll all transactions
while (m_transactions > 0) while (m_transactions > 0)
m_ndb->pollNdb(3000, m_transactions); m_ndb->pollNdb(3000, m_transactions);
}
} }
void void
...@@ -375,12 +375,12 @@ BackupRestore::logEntry(const LogEntry & tup) ...@@ -375,12 +375,12 @@ BackupRestore::logEntry(const LogEntry & tup)
exit(-1); exit(-1);
} }
for (int i = 0; i < tup.m_values.size(); i++) for (int i = 0; i < tup.size(); i++)
{ {
const AttributeS * attr = tup.m_values[i]; const AttributeS * attr = tup[i];
int size = attr->Desc->size; int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize; int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data->string_value; const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size / 8) * arraySize; const Uint32 length = (size / 8) * arraySize;
if (attr->Desc->m_column->getPrimaryKey()) if (attr->Desc->m_column->getPrimaryKey())
...@@ -389,19 +389,27 @@ BackupRestore::logEntry(const LogEntry & tup) ...@@ -389,19 +389,27 @@ BackupRestore::logEntry(const LogEntry & tup)
op->setValue(attr->Desc->attrId, dataPtr, length); op->setValue(attr->Desc->attrId, dataPtr, length);
} }
#if 1
trans->execute(Commit);
#else
const int ret = trans->execute(Commit); const int ret = trans->execute(Commit);
if (ret != 0)
{
// Both insert update and delete can fail during log running // Both insert update and delete can fail during log running
// and it's ok // and it's ok
// TODO: check that the error is either tuple exists or tuple does not exist?
if (ret != 0) switch(tup.m_type)
{
case LogEntry::LE_INSERT:
break;
case LogEntry::LE_UPDATE:
break;
case LogEntry::LE_DELETE:
break;
}
if (false)
{ {
err << "execute failed: " << trans->getNdbError() << endl; err << "execute failed: " << trans->getNdbError() << endl;
exit(-1); exit(-1);
} }
#endif }
m_ndb->closeTransaction(trans); m_ndb->closeTransaction(trans);
m_logCount++; m_logCount++;
...@@ -410,11 +418,11 @@ BackupRestore::logEntry(const LogEntry & tup) ...@@ -410,11 +418,11 @@ BackupRestore::logEntry(const LogEntry & tup)
void void
BackupRestore::endOfLogEntrys() BackupRestore::endOfLogEntrys()
{ {
if (m_restore) if (!m_restore)
{ return;
info << "Restored " << m_dataCount << " tuples and " info << "Restored " << m_dataCount << " tuples and "
<< m_logCount << " log entries" << endl; << m_logCount << " log entries" << endl;
}
} }
/* /*
...@@ -471,7 +479,7 @@ BackupRestore::tuple(const TupleS & tup) ...@@ -471,7 +479,7 @@ BackupRestore::tuple(const TupleS & tup)
const AttributeS * attr = tup[i]; const AttributeS * attr = tup[i];
int size = attr->Desc->size; int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize; int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data->string_value; const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size * arraySize) / 8; const Uint32 length = (size * arraySize) / 8;
if (attr->Desc->m_column->getPrimaryKey()) if (attr->Desc->m_column->getPrimaryKey())
...@@ -483,11 +491,11 @@ BackupRestore::tuple(const TupleS & tup) ...@@ -483,11 +491,11 @@ BackupRestore::tuple(const TupleS & tup)
const AttributeS * attr = tup[i]; const AttributeS * attr = tup[i];
int size = attr->Desc->size; int size = attr->Desc->size;
int arraySize = attr->Desc->arraySize; int arraySize = attr->Desc->arraySize;
const char * dataPtr = attr->Data->string_value; const char * dataPtr = attr->Data.string_value;
const Uint32 length = (size * arraySize) / 8; const Uint32 length = (size * arraySize) / 8;
if (!attr->Desc->m_column->getPrimaryKey()) if (!attr->Desc->m_column->getPrimaryKey())
if (attr->Data->null) if (attr->Data.null)
op->setValue(i, NULL, 0); op->setValue(i, NULL, 0);
else else
op->setValue(i, dataPtr, length); op->setValue(i, dataPtr, length);
......
...@@ -45,13 +45,9 @@ public: ...@@ -45,13 +45,9 @@ public:
} }
virtual ~BackupRestore(); virtual ~BackupRestore();
virtual bool init(); virtual bool init();
virtual void release(); virtual void release();
virtual bool table(const TableS &); virtual bool table(const TableS &);
#ifdef USE_MYSQL
virtual bool table(const TableS &, MYSQL* mysqlp);
#endif
virtual void tuple(const TupleS &); virtual void tuple(const TupleS &);
virtual void tuple_free(); virtual void tuple_free();
virtual void tuple_a(restore_callback_t *cb); virtual void tuple_a(restore_callback_t *cb);
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
#include <Vector.hpp> #include <Vector.hpp>
#include <ndb_limits.h> #include <ndb_limits.h>
#include <NdbTCP.h> #include <NdbTCP.h>
#ifdef USE_MYSQL
#include <mysql.h>
#endif
#include <NdbOut.hpp> #include <NdbOut.hpp>
#include "consumer_restore.hpp" #include "consumer_restore.hpp"
...@@ -37,26 +33,7 @@ static int ga_backupId = 0; ...@@ -37,26 +33,7 @@ static int ga_backupId = 0;
static bool ga_dont_ignore_systab_0 = false; static bool ga_dont_ignore_systab_0 = false;
static myVector<class BackupConsumer *> g_consumers; static myVector<class BackupConsumer *> g_consumers;
#ifdef USE_MYSQL
/**
* mysql specific stuff:
*/
static const char* ga_user = "root";
static const char* ga_host = "localhost";
static const char* ga_socket = "/tmp/mysql.sock";
static const char* ga_password = "";
static const char* ga_database = "";
static int ga_port = 3306;
static bool use_mysql = false;
static MYSQL mysql;
#endif
#ifdef NDB_WIN32
static const char* ga_backupPath = "." DIR_SEPARATOR; static const char* ga_backupPath = "." DIR_SEPARATOR;
#else
static const char* ga_backupPath = "." DIR_SEPARATOR;
#endif
static const char* ga_connect_NDB = NULL; static const char* ga_connect_NDB = NULL;
...@@ -130,7 +107,6 @@ readArguments(const int argc, const char** argv) ...@@ -130,7 +107,6 @@ readArguments(const int argc, const char** argv)
ga_nParallelism < 1 || ga_nParallelism < 1 ||
ga_nParallelism >1024) ga_nParallelism >1024)
{ {
arg_printusage(args, num_args, argv[0], "<path to backup files>\n"); arg_printusage(args, num_args, argv[0], "<path to backup files>\n");
return false; return false;
} }
...@@ -197,20 +173,6 @@ readArguments(const int argc, const char** argv) ...@@ -197,20 +173,6 @@ readArguments(const int argc, const char** argv)
{ {
ga_backupPath = argv[optind]; ga_backupPath = argv[optind];
} }
#ifdef USE_MYSQL
if(use_mysql) {
ga_dont_ignore_systab_0 = false;
ga_database = ""; //not used yet. pethaps later if we want to
// restore meta data in an existing mysql database,
// and not just restore it to the same database
// as when the backup was taken.
// If implementing this, then the
// tupleAsynch must also be changed so that the
// table data is restored to the correct table.
// also, mysql_select_db must be set properly (ie.,
// ignored in codw below)
}
#endif
return true; return true;
} }
...@@ -234,7 +196,6 @@ checkSysTable(const char *tableName) ...@@ -234,7 +196,6 @@ checkSysTable(const char *tableName)
strcmp(tableName, "sys/def/NDB$EVENTS_0") != 0); strcmp(tableName, "sys/def/NDB$EVENTS_0") != 0);
} }
static void static void
free_data_callback() free_data_callback()
{ {
...@@ -305,17 +266,6 @@ main(int argc, const char** argv) ...@@ -305,17 +266,6 @@ main(int argc, const char** argv)
if (checkSysTable(metaData[i]->getTableName())) if (checkSysTable(metaData[i]->getTableName()))
{ {
for(int j = 0; j<g_consumers.size(); j++) for(int j = 0; j<g_consumers.size(); j++)
#ifdef USE_MYSQL
if(use_mysql) {
if (!g_consumers[j]->table(* metaData[i], &mysql))
{
ndbout_c("Restore: Failed to restore table: %s. "
"Exiting...",
metaData[i]->getTableName());
return -11;
}
} else
#endif
if (!g_consumers[j]->table(* metaData[i])) if (!g_consumers[j]->table(* metaData[i]))
{ {
ndbout_c("Restore: Failed to restore table: %s. " ndbout_c("Restore: Failed to restore table: %s. "
...@@ -323,7 +273,6 @@ main(int argc, const char** argv) ...@@ -323,7 +273,6 @@ main(int argc, const char** argv)
metaData[i]->getTableName()); metaData[i]->getTableName());
return -11; return -11;
} }
} }
} }
...@@ -341,10 +290,10 @@ main(int argc, const char** argv) ...@@ -341,10 +290,10 @@ main(int argc, const char** argv)
} }
while (dataIter.readFragmentHeader(res)) while (dataIter.readFragmentHeader(res= 0))
{ {
const TupleS* tuple; const TupleS* tuple;
while ((tuple = dataIter.getNextTuple(res)) != NULL) while ((tuple = dataIter.getNextTuple(res= 1)) != 0)
{ {
if (checkSysTable(tuple->getTable()->getTableName())) if (checkSysTable(tuple->getTable()->getTableName()))
for(int i = 0; i < g_consumers.size(); i++) for(int i = 0; i < g_consumers.size(); i++)
...@@ -366,40 +315,33 @@ main(int argc, const char** argv) ...@@ -366,40 +315,33 @@ main(int argc, const char** argv)
if (res < 0) if (res < 0)
{ {
ndbout_c("Restore: An error occured while restoring data. " err << "Restore: An error occured while restoring data. Exiting... res=" << res << endl;
"Exiting...");
return -1; return -1;
} }
dataIter.validateFooter(); //not implemented dataIter.validateFooter(); //not implemented
for (int i = 0; i<g_consumers.size(); i++) for (int i = 0; i<g_consumers.size(); i++)
g_consumers[i]->endOfTuples(); g_consumers[i]->endOfTuples();
RestoreLogIterator logIter(metaData); RestoreLogIterator logIter(metaData);
if (!logIter.readHeader()) if (!logIter.readHeader())
{ {
ndbout << "Failed to read header of data file. Exiting..."; err << "Failed to read header of data file. Exiting..." << endl;
return -1; return -1;
} }
/**
* I have not touched the part below : -johan 040218
* except fixing return values.
*/
const LogEntry * logEntry = 0; const LogEntry * logEntry = 0;
while ((logEntry = logIter.getNextLogEntry(res))) while ((logEntry = logIter.getNextLogEntry(res= 0)) != 0)
{ {
if (checkSysTable(logEntry->m_table->getTableName())) if (checkSysTable(logEntry->m_table->getTableName()))
{
for(int i = 0; i<g_consumers.size(); i++) for(int i = 0; i<g_consumers.size(); i++)
g_consumers[i]->logEntry(* logEntry); g_consumers[i]->logEntry(* logEntry);
} }
}
if (res < 0) if (res < 0)
{ {
ndbout_c("Restore: An restoring the data log" err << "Restore: An restoring the data log. Exiting... res=" << res << endl;
"Exiting...");
return -1; return -1;
} }
logIter.validateFooter(); //not implemented logIter.validateFooter(); //not implemented
......
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