Commit e914e6c7 authored by unknown's avatar unknown

Merge mysql.com:/home/jonas/src/mysql-4.1

into mysql.com:/home/jonas/src/mysql-4.1-ndb

parents 9155e8de 89ba9400
......@@ -111,7 +111,7 @@ inline
void
TcKeyConf::setNoOfOperations(Uint32 & confInfo, Uint32 noOfOps){
ASSERT_MAX(noOfOps, 65535, "TcKeyConf::setNoOfOperations");
confInfo |= noOfOps;
confInfo = (confInfo & 0xFFFF0000) | noOfOps;
}
inline
......
......@@ -165,6 +165,7 @@ Parser<T>::Parser(const ParserRow<T> rows[], class InputStream & in,
template<class T>
inline
Parser<T>::~Parser(){
delete impl;
}
template<class T>
......
ndbtools_PROGRAMS = ndb_restore
ndb_restore_SOURCES = main.cpp Restore.cpp
ndb_restore_SOURCES = main.cpp consumer.cpp consumer_restore.cpp consumer_printer.cpp Restore.cpp
LDADD_LOC = $(top_builddir)/ndb/src/libndbclient.la
......
include .defs.mk
TYPE := *
BIN_TARGET := restore
BIN_TARGET_LIBS :=
BIN_TARGET_ARCHIVES := NDB_API
CCFLAGS_LOC = -I.. -I$(NDB_TOP)/src/ndbapi -I$(NDB_TOP)/include/ndbapi -I$(NDB_TOP)/include/util -I$(NDB_TOP)/include/portlib -I$(NDB_TOP)/include/kernel
#ifneq ($(MYSQLCLUSTER_TOP),)
#CCFLAGS_LOC +=-I$(MYSQLCLUSTER_TOP)/include -D USE_MYSQL
#LDFLAGS_LOC += -L$(MYSQLCLUSTER_TOP)/libmysql_r/ -lmysqlclient_r
#endif
SOURCES = main.cpp Restore.cpp
include $(NDB_TOP)/Epilogue.mk
......@@ -18,13 +18,15 @@
#define RESTORE_H
#include <ndb_global.h>
#include <NdbOut.hpp>
#include <BackupFormat.hpp>
#include <NdbApi.hpp>
#include "myVector.hpp"
#include <ndb_version.h>
#include <version.h>
static const char * delimiter = ";"; // Delimiter in file dump
const int FileNameLenC = 256;
const int TableNameLenC = 256;
const int AttrNameLenC = 256;
......@@ -89,19 +91,26 @@ class TupleS {
private:
friend class RestoreDataIterator;
const TableS * m_currentTable;
myVector<AttributeS*> allAttributes;
Uint32 * dataRecord;
const TableS *m_currentTable;
AttributeData *allAttrData;
bool prepareRecord(const TableS &);
public:
TupleS() {dataRecord = NULL;};
~TupleS() {if(dataRecord != NULL) delete [] dataRecord;};
int getNoOfAttributes() const { return allAttributes.size(); };
const TableS * getTable() const { return m_currentTable;};
const AttributeS * operator[](int i) const { return allAttributes[i];};
Uint32 * getDataRecord() { return dataRecord;};
void createDataRecord(Uint32 bytes) { dataRecord = new Uint32[bytes];};
TupleS() {
m_currentTable= 0;
allAttrData= 0;
};
~TupleS()
{
if (allAttrData)
delete [] allAttrData;
};
TupleS(const TupleS& tuple); // disable copy constructor
TupleS & operator=(const TupleS& tuple);
int getNoOfAttributes() const;
const TableS * getTable() const;
const AttributeDesc * getDesc(int i) const;
AttributeData * getData(int i) const;
}; // class TupleS
class TableS {
......@@ -112,27 +121,23 @@ class TableS {
Uint32 schemaVersion;
Uint32 backupVersion;
myVector<AttributeDesc *> allAttributesDesc;
myVector<AttributeDesc *> m_fixedKeys;
//myVector<AttributeDesc *> m_variableKey;
myVector<AttributeDesc *> m_fixedAttribs;
myVector<AttributeDesc *> m_variableAttribs;
Vector<AttributeDesc *> allAttributesDesc;
Vector<AttributeDesc *> m_fixedKeys;
//Vector<AttributeDesc *> m_variableKey;
Vector<AttributeDesc *> m_fixedAttribs;
Vector<AttributeDesc *> m_variableAttribs;
Uint32 m_noOfNullable;
Uint32 m_nullBitmaskSize;
int pos;
char create_string[2048];
/*
char mysqlTableName[1024];
char mysqlDatabaseName[1024];
*/
void createAttr(NdbDictionary::Column *column);
public:
class NdbDictionary::Table* m_dictTable;
TableS (class NdbTableImpl* dictTable);
~TableS();
Uint32 getTableId() const {
return m_dictTable->getTableId();
......@@ -185,18 +190,26 @@ protected:
BackupFormat::FileHeader m_expectedFileHeader;
Uint32 m_nodeId;
Uint32 * m_buffer;
Uint32 m_bufferSize;
Uint32 * createBuffer(Uint32 bytes);
void * m_buffer;
void * m_buffer_ptr;
Uint32 m_buffer_sz;
Uint32 m_buffer_data_left;
void (* free_data_callback)();
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);
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);
BackupFile();
BackupFile(void (* free_data_callback)() = 0);
~BackupFile();
public:
bool readHeader();
......@@ -206,12 +219,12 @@ public:
const char * getFilename() const { return m_fileName;}
Uint32 getNodeId() const { return m_nodeId;}
const BackupFormat::FileHeader & getFileHeader() const { return m_fileHeader;}
bool Twiddle(AttributeS * attr, Uint32 arraySize = 0);
bool Twiddle(const AttributeDesc * attr_desc, AttributeData * attr_data, Uint32 arraySize = 0);
};
class RestoreMetaData : public BackupFile {
myVector<TableS *> allTables;
Vector<TableS *> allTables;
bool readMetaFileHeader();
bool readMetaTableDesc();
......@@ -224,14 +237,11 @@ class RestoreMetaData : public BackupFile {
bool parseTableDescriptor(const Uint32 * data, Uint32 len);
public:
RestoreMetaData(const char * path, Uint32 nodeId, Uint32 bNo);
~RestoreMetaData();
virtual ~RestoreMetaData();
int loadContent();
Uint32 getNoOfTables() const { return allTables.size();}
const TableS * operator[](int i) const { return allTables[i];}
......@@ -243,20 +253,20 @@ public:
class RestoreDataIterator : public BackupFile {
const RestoreMetaData & m_metaData;
Uint32 m_count;
TupleS m_tuple;
const TableS* m_currentTable;
TupleS m_tuple;
public:
// Constructor
RestoreDataIterator(const RestoreMetaData &);
~RestoreDataIterator();
RestoreDataIterator(const RestoreMetaData &, void (* free_data_callback)());
~RestoreDataIterator() {};
// Read data file fragment header
bool readFragmentHeader(int & res);
bool validateFragmentFooter();
const TupleS *getNextTuple(int & res);
};
......@@ -269,9 +279,35 @@ public:
};
EntryType m_type;
const TableS * m_table;
myVector<AttributeS*> m_values;
Vector<AttributeS*> m_values;
Vector<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.erase(m_values_e.size()-1);
}
else
{
attr = new AttributeS;
}
m_values.push_back(attr);
return attr;
}
void clear() {
for(Uint32 i= 0; i < m_values.size(); i++)
m_values_e.push_back(m_values[i]);
m_values.clear();
}
~LogEntry()
{
for(Uint32 i= 0; i< m_values.size(); i++)
delete m_values[i];
for(Uint32 i= 0; i< m_values_e.size(); i++)
delete m_values_e[i];
}
Uint32 size() const { return m_values.size(); }
const AttributeS * operator[](int i) const { return m_values[i];}
};
class RestoreLogIterator : public BackupFile {
......@@ -282,10 +318,16 @@ private:
LogEntry m_logEntry;
public:
RestoreLogIterator(const RestoreMetaData &);
virtual ~RestoreLogIterator() {};
const LogEntry * getNextLogEntry(int & res);
};
NdbOut& operator<<(NdbOut& ndbout, const TableS&);
NdbOut& operator<<(NdbOut& ndbout, const TupleS&);
NdbOut& operator<<(NdbOut& ndbout, const LogEntry&);
NdbOut& operator<<(NdbOut& ndbout, const RestoreMetaData&);
#endif
/* 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 */
#include "consumer.hpp"
#ifdef USE_MYSQL
int
BackupConsumer::create_table_string(const TableS & table,
char * tableName,
char *buf){
int pos = 0;
int pos2 = 0;
char buf2[2048];
pos += sprintf(buf+pos, "%s%s", "CREATE TABLE ", tableName);
pos += sprintf(buf+pos, "%s", "(");
pos2 += sprintf(buf2+pos2, "%s", " primary key(");
for (int j = 0; j < table.getNoOfAttributes(); j++)
{
const AttributeDesc * desc = table[j];
// ndbout << desc->name << ": ";
pos += sprintf(buf+pos, "%s%s", desc->m_column->getName()," ");
switch(desc->m_column->getType()){
case NdbDictionary::Column::Int:
pos += sprintf(buf+pos, "%s", "int");
break;
case NdbDictionary::Column::Unsigned:
pos += sprintf(buf+pos, "%s", "int unsigned");
break;
case NdbDictionary::Column::Float:
pos += sprintf(buf+pos, "%s", "float");
break;
case NdbDictionary::Column::Decimal:
pos += sprintf(buf+pos, "%s", "decimal");
break;
case NdbDictionary::Column::Char:
pos += sprintf(buf+pos, "%s", "char");
break;
case NdbDictionary::Column::Varchar:
pos += sprintf(buf+pos, "%s", "varchar");
break;
case NdbDictionary::Column::Binary:
pos += sprintf(buf+pos, "%s", "binary");
break;
case NdbDictionary::Column::Varbinary:
pos += sprintf(buf+pos, "%s", "varchar binary");
break;
case NdbDictionary::Column::Bigint:
pos += sprintf(buf+pos, "%s", "bigint");
break;
case NdbDictionary::Column::Bigunsigned:
pos += sprintf(buf+pos, "%s", "bigint unsigned");
break;
case NdbDictionary::Column::Double:
pos += sprintf(buf+pos, "%s", "double");
break;
case NdbDictionary::Column::Datetime:
pos += sprintf(buf+pos, "%s", "datetime");
break;
case NdbDictionary::Column::Timespec:
pos += sprintf(buf+pos, "%s", "time");
break;
case NdbDictionary::Column::Undefined:
// pos += sprintf(buf+pos, "%s", "varchar binary");
return -1;
break;
default:
//pos += sprintf(buf+pos, "%s", "varchar binary");
return -1;
}
if (desc->arraySize > 1) {
int attrSize = desc->arraySize;
pos += sprintf(buf+pos, "%s%u%s",
"(",
attrSize,
")");
}
if (desc->m_column->getPrimaryKey()) {
pos += sprintf(buf+pos, "%s", " not null");
pos2 += sprintf(buf2+pos2, "%s%s", desc->m_column->getName(), ",");
}
pos += sprintf(buf+pos, "%s", ",");
} // for
pos2--; // remove trailing comma
pos2 += sprintf(buf2+pos2, "%s", ")");
// pos--; // remove trailing comma
pos += sprintf(buf+pos, "%s", buf2);
pos += sprintf(buf+pos, "%s", ") type=ndbcluster");
return 0;
}
#endif // USE_MYSQL
/* 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 CONSUMER_HPP
#define CONSUMER_HPP
#include "Restore.hpp"
class BackupConsumer {
public:
virtual ~BackupConsumer() { }
virtual bool init() { return true;}
virtual bool table(const TableS &){return true;}
virtual void tuple(const TupleS &){}
virtual void tuple_free(){}
virtual void endOfTuples(){}
virtual void logEntry(const LogEntry &){}
virtual void endOfLogEntrys(){}
};
#endif
/* 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 */
#include "consumer_printer.hpp"
bool
BackupPrinter::table(const TableS & tab)
{
if (m_print || m_print_meta)
{
m_ndbout << tab;
ndbout_c("Successfully printed table: %s", tab.m_dictTable->getName());
}
return true;
}
void
BackupPrinter::tuple(const TupleS & tup)
{
m_dataCount++;
if (m_print || m_print_data)
m_ndbout << tup << endl;
}
void
BackupPrinter::logEntry(const LogEntry & logE)
{
if (m_print || m_print_log)
m_ndbout << logE << endl;
m_logCount++;
}
void
BackupPrinter::endOfLogEntrys()
{
if (m_print || m_print_log)
{
ndbout << "Printed " << m_dataCount << " tuples and "
<< m_logCount << " log entries"
<< " to stdout." << endl;
}
}
/* 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 CONSUMER_PRINTER_HPP
#define CONSUMER_PRINTER_HPP
#include "consumer.hpp"
class BackupPrinter : public BackupConsumer
{
NdbOut & m_ndbout;
public:
BackupPrinter(NdbOut & out = ndbout) : m_ndbout(out)
{
m_print = false;
m_print_log = false;
m_print_data = false;
m_print_meta = false;
}
virtual bool table(const TableS &);
#ifdef USE_MYSQL
virtual bool table(const TableS &, MYSQL* mysqlp);
#endif
virtual void tuple(const TupleS &);
virtual void logEntry(const LogEntry &);
virtual void endOfTuples() {};
virtual void endOfLogEntrys();
bool m_print;
bool m_print_log;
bool m_print_data;
bool m_print_meta;
Uint32 m_logCount;
Uint32 m_dataCount;
};
#endif
This diff is collapsed.
/* 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 CONSUMER_RESTORE_HPP
#define CONSUMER_RESTORE_HPP
#include "consumer.hpp"
struct restore_callback_t {
class BackupRestore *restore;
class TupleS *tup;
class NdbConnection *connection;
int retries;
restore_callback_t *next;
};
class BackupRestore : public BackupConsumer
{
public:
BackupRestore(Uint32 parallelism=1)
{
m_ndb = 0;
m_logCount = m_dataCount = 0;
m_restore = false;
m_restore_meta = false;
m_parallelism = parallelism;
m_callback = 0;
m_tuples = 0;
m_free_callback = 0;
m_transactions = 0;
}
virtual ~BackupRestore();
virtual bool init();
virtual void release();
virtual bool table(const TableS &);
virtual void tuple(const TupleS &);
virtual void tuple_free();
virtual void tuple_a(restore_callback_t *cb);
virtual void cback(int result, restore_callback_t *cb);
virtual bool errorHandler(restore_callback_t *cb);
virtual void exitHandler();
virtual void endOfTuples();
virtual void logEntry(const LogEntry &);
virtual void endOfLogEntrys();
void connectToMysql();
Ndb * m_ndb;
bool m_restore;
bool m_restore_meta;
Uint32 m_logCount;
Uint32 m_dataCount;
Uint32 m_parallelism;
Uint32 m_transactions;
TupleS *m_tuples;
restore_callback_t *m_callback;
restore_callback_t *m_free_callback;
};
#endif
This diff is collapsed.
/* 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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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 MY_VECTOR_HPP
#define MY_VECTOR_HPP
// Template class for std::vector-like class (hopefully works in OSE)
template <class T>
class myVector
{
// Note that last element in array is used for end() and is always empty
int sizeIncrement;
int thisSize;
int used;
T *storage;
public:
// Assignment of whole vector
myVector<T> & operator=(myVector<T> & org) {
// Don't copy if they point to the same address
if (!(this == &org)) {
// Check memory space
if (thisSize < org.thisSize) {
// We have to increase memory for destination
T* tmpStorage = new T[org.thisSize];
delete[] storage;
storage = tmpStorage;
} // if
thisSize = org.thisSize;
sizeIncrement = org.sizeIncrement;
used = org.used;
for (int i = 0; i < thisSize; i++) {
storage[i] = org.storage[i];
} // for
} // if
return *this;
} // operator=
// Construct with size s+1
myVector(int s = 1) : sizeIncrement(5), // sizeIncrement(s),
thisSize(s + 1),
used(0),
storage(new T[s + 1]) { }
~myVector() { delete[] storage; } // Destructor: deallocate memory
T& operator[](int i) { // Return by index
if ((i < 0) || (i >= used)) {
// Index error
ndbout << "vector index out of range" << endl;
abort();
return storage[used - 1];
} // if
else {
return storage[i];
} // else
} // operator[]
const T& operator[](int i) const { // Return by index
if ((i < 0) || (i >= used)) {
// Index error
ndbout << "vector index out of range" << endl;
abort();
return storage[used - 1];
} // if
else {
return storage[i];
} // else
} // operator[]
int getSize() const { return used; }
void push_back (T& item) {
if (used >= thisSize - 1) {
// We have to allocate new storage
int newSize = thisSize + sizeIncrement;
T* tmpStorage = new T[newSize];
if (tmpStorage == NULL) {
// Memory allocation error! break
ndbout << "PANIC: Memory allocation error in vector" << endl;
return;
} // if
thisSize = newSize;
for (int i = 0; i < used; i++) {
tmpStorage[i] = storage[i];
} // for
delete[] storage;
storage = tmpStorage;
} // if
// Now push
storage[used] = item;
used++;
}; // myVector<> push_back()
// Remove item at back
void pop_back() {
if (used > 0) {
used--;
} // if
} // pop_back()
int size() const { return used; };
bool empty() const { return(used == 0); }
void clear() {
used = 0;
}
};
#endif
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