diff options
Diffstat (limited to 'ndb/test/src')
-rw-r--r-- | ndb/test/src/Makefile.am | 3 | ||||
-rw-r--r-- | ndb/test/src/NDBT_ResultRow.cpp | 74 | ||||
-rw-r--r-- | ndb/test/src/NdbBackup.cpp | 12 | ||||
-rw-r--r-- | ndb/test/src/NdbSchemaCon.cpp | 169 | ||||
-rw-r--r-- | ndb/test/src/NdbSchemaOp.cpp | 220 |
5 files changed, 401 insertions, 77 deletions
diff --git a/ndb/test/src/Makefile.am b/ndb/test/src/Makefile.am index d062eeae76c..a513086dc33 100644 --- a/ndb/test/src/Makefile.am +++ b/ndb/test/src/Makefile.am @@ -8,7 +8,8 @@ libNDBT_a_SOURCES = \ HugoOperations.cpp HugoTransactions.cpp \ HugoAsynchTransactions.cpp UtilTransactions.cpp \ NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \ - NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp + NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp \ + NdbSchemaCon.cpp NdbSchemaOp.cpp INCLUDES_LOC = -I$(top_srcdir)/ndb/src/common/mgmcommon -I$(top_srcdir)/ndb/include/mgmcommon -I$(top_srcdir)/ndb/include/kernel -I$(top_srcdir)/ndb/src/mgmapi diff --git a/ndb/test/src/NDBT_ResultRow.cpp b/ndb/test/src/NDBT_ResultRow.cpp index 350a9719c2c..2539d6be0cc 100644 --- a/ndb/test/src/NDBT_ResultRow.cpp +++ b/ndb/test/src/NDBT_ResultRow.cpp @@ -118,78 +118,8 @@ BaseString NDBT_ResultRow::c_str() { NdbOut & operator << (NdbOut& ndbout, const NDBT_ResultRow & res) { - for(int i = 0; i<res.cols; i++){ - if(res.data[i]->isNULL()) - ndbout << "NULL"; - else{ - const int size = res.data[i]->attrSize(); - const int aSize = res.data[i]->arraySize(); - switch(convertColumnTypeToAttrType(res.data[i]->getType())){ - case UnSigned: - switch(size){ - case 8: - ndbout << res.data[i]->u_64_value(); - break; - case 4: - ndbout << res.data[i]->u_32_value(); - break; - case 2: - ndbout << res.data[i]->u_short_value(); - break; - case 1: - ndbout << (unsigned) res.data[i]->u_char_value(); - break; - default: - ndbout << "Unknown size"; - } - break; - - case Signed: - switch(size){ - case 8: - ndbout << res.data[i]->int64_value(); - break; - case 4: - ndbout << res.data[i]->int32_value(); - break; - case 2: - ndbout << res.data[i]->short_value(); - break; - case 1: - ndbout << (int) res.data[i]->char_value(); - break; - default: - ndbout << "Unknown size"; - } - break; - - case String: - { - char * buf = new char[aSize+1]; - memcpy(buf, res.data[i]->aRef(), aSize); - buf[aSize] = 0; - ndbout << buf; - delete [] buf; - // Null terminate string - //res.data[i][res.sizes[i]] = 0; - //ndbout << res.data[i]; - } - break; - - case Float: - ndbout_c("%f", res.data[i]->float_value()); - break; - - default: - ndbout << "Unknown(" << - convertColumnTypeToAttrType(res.data[i]->getType()) << ")"; - break; - } - } - if (i < res.cols-1) - ndbout << res.ad; - } - + for(int i = 0; i<res.cols; i++) + ndbout << res.data[i]; return ndbout; } diff --git a/ndb/test/src/NdbBackup.cpp b/ndb/test/src/NdbBackup.cpp index 13dc67748a5..169034e0c07 100644 --- a/ndb/test/src/NdbBackup.cpp +++ b/ndb/test/src/NdbBackup.cpp @@ -90,8 +90,9 @@ NdbBackup::getFileSystemPathForNode(int _node_id){ ndbout << "Invalid configuration fetched, DB missing" << endl; return NULL; } - unsigned int type; - if(!iter.get(CFG_TYPE_OF_SECTION, &type) || type != NODE_TYPE_DB){ + unsigned int type = 123456; + if(iter.get(CFG_TYPE_OF_SECTION, &type) || type != NODE_TYPE_DB){ + ndbout <<"type = " << type << endl; ndbout <<"Invalid configuration fetched, I'm wrong type of node" << endl; return NULL; } @@ -114,10 +115,13 @@ NdbBackup::execRestore(bool _restore_data, const int buf_len = 1000; char buf[buf_len]; + ndbout << "getFileSystemPathForNode "<< _node_id <<endl; + const char* path = getFileSystemPathForNode(_node_id); if (path == NULL) return -1; + ndbout << "getHostName "<< _node_id <<endl; const char *host; if (!getHostName(_node_id, &host)){ return -1; @@ -138,7 +142,7 @@ NdbBackup::execRestore(bool _restore_data, ndbout << "res: " << res << endl; #if 0 - snprintf(buf, 255, "restore -c \"nodeid=%d;host=%s\" -n %d -b %d %s %s %s/BACKUP/BACKUP-%d", + snprintf(buf, 255, "ndb_restore -c \"nodeid=%d;host=%s\" -n %d -b %d %s %s %s/BACKUP/BACKUP-%d", ownNodeId, addr, _node_id, @@ -150,7 +154,7 @@ NdbBackup::execRestore(bool _restore_data, #endif - snprintf(buf, 255, "restore -c \"nodeid=%d;host=%s\" -n %d -b %d %s %s .", + snprintf(buf, 255, "ndb_restore -c \"nodeid=%d;host=%s\" -n %d -b %d %s %s .", ownNodeId, addr, _node_id, diff --git a/ndb/test/src/NdbSchemaCon.cpp b/ndb/test/src/NdbSchemaCon.cpp new file mode 100644 index 00000000000..0de49ff983f --- /dev/null +++ b/ndb/test/src/NdbSchemaCon.cpp @@ -0,0 +1,169 @@ +/* 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 */ + + + +/********************************************************************* +Name: NdbSchemaCon.cpp +Include: +Link: +Author: UABMNST Mona Natterkvist UAB/B/SD + EMIKRON Mikael Ronstrom +Date: 020826 +Version: 3.0 +Description: Old Interface between application and NDB +Documentation: +Adjust: 980126 UABMNST First version. + 020826 EMIKRON New version adapted to new DICT version + 040524 Magnus Svensson - Adapted to not be included in public NdbApi + unless the user wants to use it. + + NOTE: This file is only used as a compatibility layer for old test programs, + New programs should use NdbDictionary.hpp +*********************************************************************/ + +#include <ndb_global.h> +#include <NdbApi.hpp> +#include <NdbSchemaCon.hpp> +#include <NdbSchemaOp.hpp> + + +/********************************************************************* +NdbSchemaCon(Ndb* aNdb); + +Parameters: aNdb: Pointers to the Ndb object +Remark: Creates a schemacon object. +************************************************************************************************/ +NdbSchemaCon::NdbSchemaCon( Ndb* aNdb ) : + theNdb(aNdb), + theFirstSchemaOpInList(NULL), + theMagicNumber(0x75318642) +{ + theError.code = 0; +}//NdbSchemaCon::NdbSchemaCon() + +/********************************************************************* +~NdbSchemaCon(); + +Remark: Deletes the connection object. +************************************************************************************************/ +NdbSchemaCon::~NdbSchemaCon() +{ +}//NdbSchemaCon::~NdbSchemaCon() + +/********************************************************************* +NdbSchemaOp* getNdbSchemaOp(); + +Return Value Return a pointer to a NdbSchemaOp object if getNdbSchemaOp was sussesful. + Return NULL: In all other case. +Parameters: tableId : Id of the database table beeing deleted. +************************************************************************************************/ +NdbSchemaOp* +NdbSchemaCon::getNdbSchemaOp() +{ + NdbSchemaOp* tSchemaOp; + if (theFirstSchemaOpInList != NULL) { + theError.code = 4401; // Only support one add table per transaction + return NULL; + }//if + tSchemaOp = new NdbSchemaOp(theNdb); + if ( tSchemaOp == NULL ) { + theError.code = 4000; // Could not allocate schema operation + return NULL; + }//if + theFirstSchemaOpInList = tSchemaOp; + int retValue = tSchemaOp->init(this); + if (retValue == -1) { + release(); + theError.code = 4000; // Could not allocate buffer in schema operation + return NULL; + }//if + return tSchemaOp; +}//NdbSchemaCon::getNdbSchemaOp() + +/********************************************************************* +int execute(); + +Return Value: Return 0 : execute was successful. + Return -1: In all other case. +Parameters : aTypeOfExec: Type of execute. +Remark: Initialise connection object for new transaction. +************************************************************************************************/ +int +NdbSchemaCon::execute() +{ + if(theError.code != 0) { + return -1; + }//if + + NdbSchemaOp* tSchemaOp; + + tSchemaOp = theFirstSchemaOpInList; + if (tSchemaOp == NULL) { + theError.code = 4402; + return -1; + }//if + + if ((tSchemaOp->sendRec() == -1) || (theError.code != 0)) { + // Error Code already set in other place + return -1; + }//if + + return 0; +}//NdbSchemaCon::execute() + +/********************************************************************* +void release(); + +Remark: Release all schemaop. +************************************************************************************************/ +void +NdbSchemaCon::release() +{ + NdbSchemaOp* tSchemaOp; + tSchemaOp = theFirstSchemaOpInList; + if (tSchemaOp != NULL) { + tSchemaOp->release(); + delete tSchemaOp; + }//if + theFirstSchemaOpInList = NULL; + return; +}//NdbSchemaCon::release() + +#include <NdbError.hpp> + +static void +update(const NdbError & _err){ + NdbError & error = (NdbError &) _err; + ndberror_struct ndberror = (ndberror_struct)error; + ndberror_update(&ndberror); + error = NdbError(ndberror); +} + +const +NdbError & +NdbSchemaCon::getNdbError() const { + update(theError); + return theError; +} + + + + + + + + diff --git a/ndb/test/src/NdbSchemaOp.cpp b/ndb/test/src/NdbSchemaOp.cpp new file mode 100644 index 00000000000..a296094ea9d --- /dev/null +++ b/ndb/test/src/NdbSchemaOp.cpp @@ -0,0 +1,220 @@ +/* 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 */ + + +/***************************************************************************** +Name: NdbSchemaOp.cpp +Include: +Link: +Author: UABMNST Mona Natterkvist UAB/B/SD + EMIKRON Mikael Ronstrom +Date: 040524 +Version: 3.0 +Description: Interface between application and NDB +Documentation: Handles createTable and createAttribute calls + +Adjust: 980125 UABMNST First version. + 020826 EMIKRON New version for new DICT + 040524 Magnus Svensson - Adapted to not be included in public NdbApi + unless the user wants to use it. + + NOTE: This file is only used as a compatibility layer for old test programs, + New programs should use NdbDictionary.hpp +*****************************************************************************/ + +#include <ndb_global.h> +#include <NdbApi.hpp> +#include <NdbSchemaOp.hpp> +#include <NdbSchemaCon.hpp> + + +/***************************************************************************** +NdbSchemaOp(Ndb* aNdb, Table* aTable); + +Return Value: None +Parameters: aNdb: Pointers to the Ndb object. + aTable: Pointers to the Table object +Remark: Creat an object of NdbSchemaOp. +*****************************************************************************/ +NdbSchemaOp::NdbSchemaOp(Ndb* aNdb) : + theNdb(aNdb), + theSchemaCon(NULL), + m_currentTable(NULL) +{ +}//NdbSchemaOp::NdbSchemaOp() + +/***************************************************************************** +~NdbSchemaOp(); + +Remark: Delete tables for connection pointers (id). +*****************************************************************************/ +NdbSchemaOp::~NdbSchemaOp( ) +{ +}//~NdbSchemaOp::NdbSchemaOp() + +/***************************************************************************** +int createTable( const char* tableName ) +*****************************************************************************/ +int +NdbSchemaOp::createTable(const char* aTableName, + Uint32 aTableSize, + KeyType aTupleKey, + int aNrOfPages, + FragmentType aFragmentType, + int aKValue, + int aMinLoadFactor, + int aMaxLoadFactor, + int aMemoryType, + bool aStoredTable) +{ + if(m_currentTable != 0){ + return -1; + } + + m_currentTable = new NdbDictionary::Table(aTableName); + m_currentTable->setKValue(aKValue); + m_currentTable->setMinLoadFactor(aMinLoadFactor); + m_currentTable->setMaxLoadFactor(aMaxLoadFactor); + m_currentTable->setLogging(aStoredTable); + m_currentTable->setFragmentType(NdbDictionary::Object::FragAllMedium); + return 0; +}//NdbSchemaOp::createTable() + +/****************************************************************************** +int createAttribute( const char* anAttrName, + KeyType aTupleyKey, + int anAttrSize, + int anArraySize, + AttrType anAttrType, + SafeType aSafeType, + StorageMode aStorageMode, + int aNullAttr, + int aStorageAttr ); + +******************************************************************************/ +int +NdbSchemaOp::createAttribute( const char* anAttrName, + KeyType aTupleKey, + int anAttrSize, + int anArraySize, + AttrType anAttrType, + StorageMode aStorageMode, + bool nullable, + StorageAttributeType aStorageAttr, + int aDistributionKeyFlag, + int aDistributionGroupFlag, + int aDistributionGroupNoOfBits, + bool aAutoIncrement, + const char* aDefaultValue) +{ + if (m_currentTable == 0){ + return -1; + }//if + + NdbDictionary::Column col(anAttrName); + switch(anAttrType){ + case Signed: + if(anAttrSize == 64) + col.setType(NdbDictionary::Column::Bigint); + else + col.setType(NdbDictionary::Column::Int); + break; + case UnSigned: + if(anAttrSize == 64) + col.setType(NdbDictionary::Column::Bigunsigned); + else + col.setType(NdbDictionary::Column::Unsigned); + break; + case Float: + if(anAttrSize == 64) + col.setType(NdbDictionary::Column::Double); + else + col.setType(NdbDictionary::Column::Float); + break; + case String: + col.setType(NdbDictionary::Column::Char); + break; + case NoAttrTypeDef: + abort(); + } + col.setLength(anArraySize); + col.setNullable(nullable); + if(aTupleKey != NoKey) + col.setPrimaryKey(true); + else + col.setPrimaryKey(false); + + col.setDistributionKey(aDistributionKeyFlag); + col.setDistributionGroup(aDistributionGroupFlag,aDistributionGroupNoOfBits); + col.setAutoIncrement(aAutoIncrement); + col.setDefaultValue(aDefaultValue != 0 ? aDefaultValue : ""); + + m_currentTable->addColumn(col); + return 0; +} + +/****************************************************************************** +void release(); + +Remark: Release all objects connected to the schemaop object. +******************************************************************************/ +void +NdbSchemaOp::release(){ +}//NdbSchemaOp::release() + +/****************************************************************************** +int sendRec() + +Return Value: Return 0 : send was succesful. + Return -1: In all other case. +Parameters: +Remark: Send and receive signals for schema transaction based on state +******************************************************************************/ +int +NdbSchemaOp::sendRec(){ + int retVal = 0; + if(m_currentTable == 0){ + retVal = -1; + } else { + retVal = theNdb->getDictionary()->createTable(* m_currentTable); + delete m_currentTable; + theSchemaCon->theError.code = theNdb->getDictionary()->getNdbError().code; + } + + return retVal; +}//NdbSchemaOp::sendRec() + +/****************************************************************************** +int init(); + +Return Value: Return 0 : init was successful. + Return -1: In all other case. +Remark: Initiates SchemaOp record after allocation. +******************************************************************************/ +int +NdbSchemaOp::init(NdbSchemaCon* aSchemaCon) +{ + theSchemaCon = aSchemaCon; + return 0; +}//NdbSchemaOp::init() + + +const NdbError & +NdbSchemaOp::getNdbError() const +{ + return theSchemaCon->getNdbError(); +} + |