1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
#include <ndb_global.h>
21
#include "../src/kernel/blocks/backup/BackupFormat.hpp"
22
#include "../src/ndbapi/NdbDictionaryImpl.hpp"
25
#include <ndb_version.h>
28
const int FileNameLenC = 256;
29
const int TableNameLenC = 256;
30
const int AttrNameLenC = 256;
31
const Uint32 timeToWaitForNdbC = 10000;
32
const Uint32 opsDefaultC = 1000;
34
// Forward declarations
35
//class AttributeDesc;
40
struct AttributeData {
48
Uint16 * u_int16_value;
51
Uint32 * u_int32_value;
54
Uint64 * u_int64_value;
62
struct AttributeDesc {
66
friend class RestoreDataIterator;
67
friend class RestoreMetaData;
68
friend struct AttributeS;
72
NdbDictionary::Column *m_column;
74
Uint32 m_nullBitIndex;
77
AttributeDesc(NdbDictionary::Column *column);
80
Uint32 getSizeInWords() const { return (size * arraySize + 31)/ 32;}
84
const AttributeDesc * Desc;
90
friend class RestoreDataIterator;
92
class TableS *m_currentTable;
93
AttributeData *allAttrData;
94
bool prepareRecord(TableS &);
104
delete [] allAttrData;
106
TupleS(const TupleS& tuple); // disable copy constructor
107
TupleS & operator=(const TupleS& tuple);
108
int getNoOfAttributes() const;
109
TableS * getTable() const;
110
const AttributeDesc * getDesc(int i) const;
111
AttributeData * getData(int i) const;
125
friend class RestoreMetaData;
126
friend class RestoreDataIterator;
128
Uint32 schemaVersion;
129
Uint32 backupVersion;
130
Vector<AttributeDesc *> allAttributesDesc;
131
Vector<AttributeDesc *> m_fixedKeys;
132
//Vector<AttributeDesc *> m_variableKey;
133
Vector<AttributeDesc *> m_fixedAttribs;
134
Vector<AttributeDesc *> m_variableAttribs;
136
Uint32 m_noOfNullable;
137
Uint32 m_nullBitmaskSize;
139
Uint32 m_auto_val_id;
140
Uint64 m_max_auto_val;
143
TableS *m_main_table;
146
Uint64 m_noOfRecords;
147
Vector<FragmentInfo *> m_fragmentInfo;
149
void createAttr(NdbDictionary::Column *column);
152
class NdbDictionary::Table* m_dictTable;
153
TableS (Uint32 version, class NdbTableImpl* dictTable);
156
Uint32 getTableId() const {
157
return m_dictTable->getTableId();
159
Uint32 getLocalId() const {
162
Uint32 getNoOfRecords() const {
163
return m_noOfRecords;
166
void setMysqlTableName(char * tableName) {
167
strpcpy(mysqlTableName, tableName);
171
void setMysqlDatabaseName(char * databaseName) {
172
strpcpy(mysqlDatabaseName, databaseName);
175
table.setMysqlDatabaseName(database);
177
void setBackupVersion(Uint32 version) {
178
backupVersion = version;
181
Uint32 getBackupVersion() const {
182
return backupVersion;
185
const char * getTableName() const {
186
return m_dictTable->getName();
189
int getNoOfAttributes() const {
190
return allAttributesDesc.size();
193
bool have_auto_inc() const {
194
return m_auto_val_id != ~(Uint32)0;
197
bool have_auto_inc(Uint32 id) const {
198
return m_auto_val_id == id;
201
Uint64 get_max_auto_val() const {
202
return m_max_auto_val;
205
void update_max_auto_val(const char *data, int size) {
217
memcpy(&val.u32,data,4);
221
v= uint3korr((unsigned char*)data);
224
memcpy(&val.u16,data,2);
228
memcpy(&val.u8,data,1);
234
if(v > m_max_auto_val)
238
* Get attribute descriptor
240
const AttributeDesc * operator[](int attributeId) const {
241
return allAttributesDesc[attributeId];
244
bool getSysTable() const {
248
const TableS *getMainTable() const {
252
TableS& operator=(TableS& org) ;
255
class RestoreLogIterator;
260
char m_path[PATH_MAX];
261
char m_fileName[PATH_MAX];
262
bool m_hostByteOrder;
263
BackupFormat::FileHeader m_fileHeader;
264
BackupFormat::FileHeader m_expectedFileHeader;
271
Uint32 m_buffer_data_left;
272
void (* free_data_callback)();
275
void setCtlFile(Uint32 nodeId, Uint32 backupId, const char * path);
276
void setDataFile(const BackupFile & bf, Uint32 no);
277
void setLogFile(const BackupFile & bf, Uint32 no);
279
Uint32 buffer_get_ptr(void **p_buf_ptr, Uint32 size, Uint32 nmemb);
280
Uint32 buffer_read(void *ptr, Uint32 size, Uint32 nmemb);
281
Uint32 buffer_get_ptr_ahead(void **p_buf_ptr, Uint32 size, Uint32 nmemb);
282
Uint32 buffer_read_ahead(void *ptr, Uint32 size, Uint32 nmemb);
284
void setName(const char * path, const char * name);
286
BackupFile(void (* free_data_callback)() = 0);
290
bool validateFooter();
292
const char * getPath() const { return m_path;}
293
const char * getFilename() const { return m_fileName;}
294
Uint32 getNodeId() const { return m_nodeId;}
295
const BackupFormat::FileHeader & getFileHeader() const { return m_fileHeader;}
296
bool Twiddle(const AttributeDesc * attr_desc, AttributeData * attr_data, Uint32 arraySize = 0);
304
class RestoreMetaData : public BackupFile {
306
Vector<TableS *> allTables;
307
bool readMetaFileHeader();
308
bool readMetaTableDesc();
309
bool markSysTables();
312
bool readFragmentInfo();
313
Uint32 readMetaTableList();
318
bool parseTableDescriptor(const Uint32 * data, Uint32 len);
320
Vector<DictObject> m_objects;
323
RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo);
324
virtual ~RestoreMetaData();
328
Uint32 getNoOfTables() const { return allTables.size();}
330
const TableS * operator[](int i) const { return allTables[i];}
331
TableS * getTable(Uint32 tableId) const;
333
Uint32 getNoOfObjects() const { return m_objects.size();}
334
Uint32 getObjType(Uint32 i) const { return m_objects[i].m_objType; }
335
void* getObjPtr(Uint32 i) const { return m_objects[i].m_objPtr; }
337
Uint32 getStopGCP() const;
338
}; // RestoreMetaData
341
class RestoreDataIterator : public BackupFile {
342
const RestoreMetaData & m_metaData;
344
TableS* m_currentTable;
350
RestoreDataIterator(const RestoreMetaData &, void (* free_data_callback)());
351
~RestoreDataIterator() {};
353
// Read data file fragment header
354
bool readFragmentHeader(int & res, Uint32 *fragmentId);
355
bool validateFragmentFooter();
357
const TupleS *getNextTuple(int & res);
361
int readTupleData(Uint32 *buf_ptr, Uint32 *ptr, Uint32 dataLength);
374
Vector<AttributeS*> m_values;
375
Vector<AttributeS*> m_values_e;
376
AttributeS *add_attr() {
378
if (m_values_e.size() > 0) {
379
attr = m_values_e[m_values_e.size()-1];
380
m_values_e.erase(m_values_e.size()-1);
384
attr = new AttributeS;
386
m_values.push_back(attr);
390
for(Uint32 i= 0; i < m_values.size(); i++)
391
m_values_e.push_back(m_values[i]);
398
for(i= 0; i< m_values.size(); i++)
400
for(i= 0; i< m_values_e.size(); i++)
401
delete m_values_e[i];
403
Uint32 size() const { return m_values.size(); }
404
const AttributeS * operator[](int i) const { return m_values[i];}
407
class RestoreLogIterator : public BackupFile {
409
const RestoreMetaData & m_metaData;
415
RestoreLogIterator(const RestoreMetaData &);
416
virtual ~RestoreLogIterator() {};
418
const LogEntry * getNextLogEntry(int & res);
421
NdbOut& operator<<(NdbOut& ndbout, const TableS&);
422
NdbOut& operator<<(NdbOut& ndbout, const TupleS&);
423
NdbOut& operator<<(NdbOut& ndbout, const LogEntry&);
424
NdbOut& operator<<(NdbOut& ndbout, const RestoreMetaData&);