2004-04-14 10:53:21 +02:00
|
|
|
/* Copyright (C) 2003 MySQL AB
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#ifndef RESTORE_H
|
|
|
|
#define RESTORE_H
|
|
|
|
|
2004-05-07 15:34:12 +02:00
|
|
|
#include <ndb_global.h>
|
2004-06-09 21:24:36 +02:00
|
|
|
#include <NdbOut.hpp>
|
2004-11-14 12:02:06 +01:00
|
|
|
#include "../src/kernel/blocks/backup/BackupFormat.hpp"
|
|
|
|
#include "../src/ndbapi/NdbDictionaryImpl.hpp"
|
2004-04-14 10:53:21 +02:00
|
|
|
#include <NdbApi.hpp>
|
|
|
|
|
|
|
|
#include <ndb_version.h>
|
|
|
|
#include <version.h>
|
|
|
|
|
|
|
|
const int FileNameLenC = 256;
|
|
|
|
const int TableNameLenC = 256;
|
|
|
|
const int AttrNameLenC = 256;
|
|
|
|
const Uint32 timeToWaitForNdbC = 10000;
|
|
|
|
const Uint32 opsDefaultC = 1000;
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
//class AttributeDesc;
|
|
|
|
struct AttributeDesc;
|
|
|
|
struct AttributeData;
|
|
|
|
struct AttributeS;
|
|
|
|
|
|
|
|
struct AttributeData {
|
|
|
|
bool null;
|
|
|
|
Uint32 size;
|
|
|
|
union {
|
|
|
|
Int8 * int8_value;
|
|
|
|
Uint8 * u_int8_value;
|
|
|
|
|
|
|
|
Int16 * int16_value;
|
|
|
|
Uint16 * u_int16_value;
|
|
|
|
|
|
|
|
Int32 * int32_value;
|
|
|
|
Uint32 * u_int32_value;
|
|
|
|
|
|
|
|
Int64 * int64_value;
|
|
|
|
Uint64 * u_int64_value;
|
|
|
|
|
|
|
|
char * string_value;
|
|
|
|
|
|
|
|
void* void_value;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AttributeDesc {
|
|
|
|
//private:
|
|
|
|
friend class TupleS;
|
|
|
|
friend class TableS;
|
|
|
|
friend class RestoreDataIterator;
|
|
|
|
friend class RestoreMetaData;
|
|
|
|
friend struct AttributeS;
|
|
|
|
Uint32 size; // bits
|
|
|
|
Uint32 arraySize;
|
2004-06-07 19:31:32 +02:00
|
|
|
Uint32 attrId;
|
|
|
|
NdbDictionary::Column *m_column;
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
Uint32 m_nullBitIndex;
|
|
|
|
public:
|
|
|
|
|
2004-06-07 19:31:32 +02:00
|
|
|
AttributeDesc(NdbDictionary::Column *column);
|
|
|
|
AttributeDesc();
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
Uint32 getSizeInWords() const { return (size * arraySize + 31)/ 32;}
|
|
|
|
}; // AttributeDesc
|
|
|
|
|
|
|
|
struct AttributeS {
|
|
|
|
const AttributeDesc * Desc;
|
2004-06-10 03:38:38 +02:00
|
|
|
AttributeData Data;
|
2004-04-14 10:53:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class TupleS {
|
|
|
|
private:
|
|
|
|
friend class RestoreDataIterator;
|
|
|
|
|
2004-10-22 17:13:06 +02:00
|
|
|
class TableS *m_currentTable;
|
2004-06-09 21:24:36 +02:00
|
|
|
AttributeData *allAttrData;
|
2004-10-01 04:38:03 +02:00
|
|
|
bool prepareRecord(TableS &);
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
public:
|
2004-06-10 03:38:38 +02:00
|
|
|
TupleS() {
|
|
|
|
m_currentTable= 0;
|
|
|
|
allAttrData= 0;
|
|
|
|
};
|
2004-06-09 21:24:36 +02:00
|
|
|
~TupleS()
|
|
|
|
{
|
|
|
|
if (allAttrData)
|
|
|
|
delete [] allAttrData;
|
|
|
|
};
|
|
|
|
TupleS(const TupleS& tuple); // disable copy constructor
|
|
|
|
TupleS & operator=(const TupleS& tuple);
|
|
|
|
int getNoOfAttributes() const;
|
2004-10-01 04:38:03 +02:00
|
|
|
TableS * getTable() const;
|
2004-06-09 21:24:36 +02:00
|
|
|
const AttributeDesc * getDesc(int i) const;
|
|
|
|
AttributeData * getData(int i) const;
|
2004-04-14 10:53:21 +02:00
|
|
|
}; // class TupleS
|
|
|
|
|
2006-06-27 10:02:58 +02:00
|
|
|
struct FragmentInfo
|
|
|
|
{
|
|
|
|
Uint32 fragmentNo;
|
|
|
|
Uint64 noOfRecords;
|
|
|
|
Uint32 filePosLow;
|
|
|
|
Uint32 filePosHigh;
|
|
|
|
};
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
class TableS {
|
|
|
|
|
|
|
|
friend class TupleS;
|
|
|
|
friend class RestoreMetaData;
|
|
|
|
friend class RestoreDataIterator;
|
|
|
|
|
|
|
|
Uint32 schemaVersion;
|
|
|
|
Uint32 backupVersion;
|
2004-06-10 14:01:47 +02:00
|
|
|
Vector<AttributeDesc *> allAttributesDesc;
|
2004-12-09 13:36:23 +01:00
|
|
|
Vector<AttributeDesc *> m_fixedKeys;
|
|
|
|
//Vector<AttributeDesc *> m_variableKey;
|
2004-06-10 14:01:47 +02:00
|
|
|
Vector<AttributeDesc *> m_fixedAttribs;
|
|
|
|
Vector<AttributeDesc *> m_variableAttribs;
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
Uint32 m_noOfNullable;
|
|
|
|
Uint32 m_nullBitmaskSize;
|
|
|
|
|
2004-10-01 04:38:03 +02:00
|
|
|
Uint32 m_auto_val_id;
|
|
|
|
Uint64 m_max_auto_val;
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
int pos;
|
|
|
|
|
2007-03-07 07:18:08 +01:00
|
|
|
bool isSysTable;
|
|
|
|
TableS *m_main_table;
|
|
|
|
Uint32 m_local_id;
|
|
|
|
|
2006-06-27 10:02:58 +02:00
|
|
|
Uint64 m_noOfRecords;
|
|
|
|
Vector<FragmentInfo *> m_fragmentInfo;
|
|
|
|
|
2004-06-07 19:31:32 +02:00
|
|
|
void createAttr(NdbDictionary::Column *column);
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
class NdbDictionary::Table* m_dictTable;
|
2004-12-09 13:36:23 +01:00
|
|
|
TableS (Uint32 version, class NdbTableImpl* dictTable);
|
2004-06-10 03:38:38 +02:00
|
|
|
~TableS();
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
Uint32 getTableId() const {
|
2004-06-07 19:31:32 +02:00
|
|
|
return m_dictTable->getTableId();
|
2004-04-14 10:53:21 +02:00
|
|
|
}
|
2007-03-07 07:18:08 +01:00
|
|
|
Uint32 getLocalId() const {
|
|
|
|
return m_local_id;
|
|
|
|
}
|
2006-06-27 10:02:58 +02:00
|
|
|
Uint32 getNoOfRecords() const {
|
|
|
|
return m_noOfRecords;
|
|
|
|
}
|
2004-04-14 10:53:21 +02:00
|
|
|
/*
|
|
|
|
void setMysqlTableName(char * tableName) {
|
|
|
|
strpcpy(mysqlTableName, tableName);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
void setMysqlDatabaseName(char * databaseName) {
|
|
|
|
strpcpy(mysqlDatabaseName, databaseName);
|
|
|
|
}
|
|
|
|
|
|
|
|
table.setMysqlDatabaseName(database);
|
|
|
|
*/
|
|
|
|
void setBackupVersion(Uint32 version) {
|
|
|
|
backupVersion = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
Uint32 getBackupVersion() const {
|
|
|
|
return backupVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * getTableName() const {
|
|
|
|
return m_dictTable->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
int getNoOfAttributes() const {
|
|
|
|
return allAttributesDesc.size();
|
|
|
|
};
|
|
|
|
|
2004-10-01 04:38:03 +02:00
|
|
|
bool have_auto_inc() const {
|
|
|
|
return m_auto_val_id != ~(Uint32)0;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool have_auto_inc(Uint32 id) const {
|
|
|
|
return m_auto_val_id == id;
|
|
|
|
};
|
|
|
|
|
|
|
|
Uint64 get_max_auto_val() const {
|
|
|
|
return m_max_auto_val;
|
|
|
|
};
|
|
|
|
|
|
|
|
void update_max_auto_val(const char *data, int size) {
|
2005-01-17 12:29:43 +01:00
|
|
|
union {
|
|
|
|
Uint8 u8;
|
|
|
|
Uint16 u16;
|
|
|
|
Uint32 u32;
|
|
|
|
} val;
|
|
|
|
Uint64 v;
|
2004-10-01 04:38:03 +02:00
|
|
|
switch(size){
|
2005-01-17 12:29:43 +01:00
|
|
|
case 64:
|
|
|
|
memcpy(&v,data,8);
|
2004-10-01 04:38:03 +02:00
|
|
|
break;
|
|
|
|
case 32:
|
2005-01-17 12:29:43 +01:00
|
|
|
memcpy(&val.u32,data,4);
|
|
|
|
v= val.u32;
|
2004-10-01 04:38:03 +02:00
|
|
|
break;
|
2005-01-17 12:29:43 +01:00
|
|
|
case 16:
|
|
|
|
memcpy(&val.u16,data,2);
|
|
|
|
v= val.u16;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
memcpy(&val.u8,data,1);
|
|
|
|
v= val.u8;
|
2004-10-01 04:38:03 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
};
|
2005-01-17 12:29:43 +01:00
|
|
|
if(v > m_max_auto_val)
|
|
|
|
m_max_auto_val= v;
|
2004-10-01 04:38:03 +02:00
|
|
|
};
|
2004-04-14 10:53:21 +02:00
|
|
|
/**
|
|
|
|
* Get attribute descriptor
|
|
|
|
*/
|
|
|
|
const AttributeDesc * operator[](int attributeId) const {
|
|
|
|
return allAttributesDesc[attributeId];
|
|
|
|
}
|
|
|
|
|
2007-03-07 07:18:08 +01:00
|
|
|
bool getSysTable() const {
|
|
|
|
return isSysTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TableS *getMainTable() const {
|
|
|
|
return m_main_table;
|
|
|
|
}
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
TableS& operator=(TableS& org) ;
|
|
|
|
}; // TableS;
|
|
|
|
|
|
|
|
class BackupFile {
|
|
|
|
protected:
|
|
|
|
FILE * m_file;
|
|
|
|
char m_path[PATH_MAX];
|
|
|
|
char m_fileName[PATH_MAX];
|
|
|
|
bool m_hostByteOrder;
|
|
|
|
BackupFormat::FileHeader m_fileHeader;
|
|
|
|
BackupFormat::FileHeader m_expectedFileHeader;
|
|
|
|
|
|
|
|
Uint32 m_nodeId;
|
|
|
|
|
2004-06-10 03:38:38 +02:00
|
|
|
void * m_buffer;
|
|
|
|
void * m_buffer_ptr;
|
|
|
|
Uint32 m_buffer_sz;
|
|
|
|
Uint32 m_buffer_data_left;
|
|
|
|
void (* free_data_callback)();
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
bool openFile();
|
|
|
|
void setCtlFile(Uint32 nodeId, Uint32 backupId, const char * path);
|
|
|
|
void setDataFile(const BackupFile & bf, Uint32 no);
|
|
|
|
void setLogFile(const BackupFile & bf, Uint32 no);
|
|
|
|
|
2004-06-10 03:38:38 +02:00
|
|
|
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);
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
void setName(const char * path, const char * name);
|
|
|
|
|
2004-06-10 03:38:38 +02:00
|
|
|
BackupFile(void (* free_data_callback)() = 0);
|
2004-04-14 10:53:21 +02:00
|
|
|
~BackupFile();
|
|
|
|
public:
|
|
|
|
bool readHeader();
|
|
|
|
bool validateFooter();
|
|
|
|
|
|
|
|
const char * getPath() const { return m_path;}
|
|
|
|
const char * getFilename() const { return m_fileName;}
|
|
|
|
Uint32 getNodeId() const { return m_nodeId;}
|
|
|
|
const BackupFormat::FileHeader & getFileHeader() const { return m_fileHeader;}
|
2004-06-09 21:24:36 +02:00
|
|
|
bool Twiddle(const AttributeDesc * attr_desc, AttributeData * attr_data, Uint32 arraySize = 0);
|
2004-04-14 10:53:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class RestoreMetaData : public BackupFile {
|
|
|
|
|
2004-06-10 14:01:47 +02:00
|
|
|
Vector<TableS *> allTables;
|
2004-04-14 10:53:21 +02:00
|
|
|
bool readMetaFileHeader();
|
2004-05-27 09:45:42 +02:00
|
|
|
bool readMetaTableDesc();
|
2007-03-07 07:18:08 +01:00
|
|
|
bool markSysTables();
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
bool readGCPEntry();
|
2006-06-27 10:02:58 +02:00
|
|
|
bool readFragmentInfo();
|
2004-04-14 10:53:21 +02:00
|
|
|
Uint32 readMetaTableList();
|
|
|
|
|
|
|
|
Uint32 m_startGCP;
|
|
|
|
Uint32 m_stopGCP;
|
|
|
|
|
2004-05-27 09:45:42 +02:00
|
|
|
bool parseTableDescriptor(const Uint32 * data, Uint32 len);
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo);
|
2004-06-10 03:38:38 +02:00
|
|
|
virtual ~RestoreMetaData();
|
2004-04-14 10:53:21 +02:00
|
|
|
|
2004-05-27 09:45:42 +02:00
|
|
|
int loadContent();
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
Uint32 getNoOfTables() const { return allTables.size();}
|
|
|
|
|
|
|
|
const TableS * operator[](int i) const { return allTables[i];}
|
2004-10-01 04:38:03 +02:00
|
|
|
TableS * getTable(Uint32 tableId) const;
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
Uint32 getStopGCP() const;
|
|
|
|
}; // RestoreMetaData
|
|
|
|
|
|
|
|
|
|
|
|
class RestoreDataIterator : public BackupFile {
|
|
|
|
const RestoreMetaData & m_metaData;
|
|
|
|
Uint32 m_count;
|
2004-10-01 04:38:03 +02:00
|
|
|
TableS* m_currentTable;
|
2004-06-09 21:24:36 +02:00
|
|
|
TupleS m_tuple;
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
2004-06-09 21:24:36 +02:00
|
|
|
RestoreDataIterator(const RestoreMetaData &, void (* free_data_callback)());
|
2004-06-10 03:38:38 +02:00
|
|
|
~RestoreDataIterator() {};
|
2004-04-14 10:53:21 +02:00
|
|
|
|
|
|
|
// Read data file fragment header
|
|
|
|
bool readFragmentHeader(int & res);
|
|
|
|
bool validateFragmentFooter();
|
2004-06-09 21:24:36 +02:00
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
const TupleS *getNextTuple(int & res);
|
|
|
|
};
|
|
|
|
|
|
|
|
class LogEntry {
|
|
|
|
public:
|
|
|
|
enum EntryType {
|
|
|
|
LE_INSERT,
|
|
|
|
LE_DELETE,
|
|
|
|
LE_UPDATE
|
|
|
|
};
|
|
|
|
EntryType m_type;
|
2004-10-01 04:38:03 +02:00
|
|
|
TableS * m_table;
|
2004-06-10 14:01:47 +02:00
|
|
|
Vector<AttributeS*> m_values;
|
|
|
|
Vector<AttributeS*> m_values_e;
|
2004-06-10 03:38:38 +02:00
|
|
|
AttributeS *add_attr() {
|
|
|
|
AttributeS * attr;
|
|
|
|
if (m_values_e.size() > 0) {
|
|
|
|
attr = m_values_e[m_values_e.size()-1];
|
2004-06-10 14:01:47 +02:00
|
|
|
m_values_e.erase(m_values_e.size()-1);
|
2004-06-10 03:38:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attr = new AttributeS;
|
|
|
|
}
|
|
|
|
m_values.push_back(attr);
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
void clear() {
|
2004-06-10 14:01:47 +02:00
|
|
|
for(Uint32 i= 0; i < m_values.size(); i++)
|
2004-06-10 03:38:38 +02:00
|
|
|
m_values_e.push_back(m_values[i]);
|
|
|
|
m_values.clear();
|
|
|
|
}
|
2006-12-14 23:51:37 +01:00
|
|
|
LogEntry() {}
|
2004-06-10 03:38:38 +02:00
|
|
|
~LogEntry()
|
|
|
|
{
|
2004-07-09 12:48:32 +02:00
|
|
|
Uint32 i;
|
|
|
|
for(i= 0; i< m_values.size(); i++)
|
2004-06-10 03:38:38 +02:00
|
|
|
delete m_values[i];
|
2004-07-09 12:48:32 +02:00
|
|
|
for(i= 0; i< m_values_e.size(); i++)
|
2004-06-10 03:38:38 +02:00
|
|
|
delete m_values_e[i];
|
|
|
|
}
|
2004-06-10 14:01:47 +02:00
|
|
|
Uint32 size() const { return m_values.size(); }
|
2004-06-10 03:38:38 +02:00
|
|
|
const AttributeS * operator[](int i) const { return m_values[i];}
|
2004-04-14 10:53:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class RestoreLogIterator : public BackupFile {
|
|
|
|
private:
|
|
|
|
const RestoreMetaData & m_metaData;
|
|
|
|
|
|
|
|
Uint32 m_count;
|
2005-06-08 16:48:57 +02:00
|
|
|
Uint32 m_last_gci;
|
2004-04-14 10:53:21 +02:00
|
|
|
LogEntry m_logEntry;
|
|
|
|
public:
|
|
|
|
RestoreLogIterator(const RestoreMetaData &);
|
2004-06-10 03:38:38 +02:00
|
|
|
virtual ~RestoreLogIterator() {};
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
const LogEntry * getNextLogEntry(int & res);
|
|
|
|
};
|
|
|
|
|
2004-06-09 21:24:36 +02:00
|
|
|
NdbOut& operator<<(NdbOut& ndbout, const TableS&);
|
|
|
|
NdbOut& operator<<(NdbOut& ndbout, const TupleS&);
|
|
|
|
NdbOut& operator<<(NdbOut& ndbout, const LogEntry&);
|
|
|
|
NdbOut& operator<<(NdbOut& ndbout, const RestoreMetaData&);
|
|
|
|
|
2004-04-14 10:53:21 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|