diff options
Diffstat (limited to 'ndb/test')
37 files changed, 879 insertions, 2487 deletions
diff --git a/ndb/test/include/CpcClient.hpp b/ndb/test/include/CpcClient.hpp new file mode 100644 index 00000000000..1655bc57b56 --- /dev/null +++ b/ndb/test/include/CpcClient.hpp @@ -0,0 +1,104 @@ +/* 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 __CPCCLIENT_HPP_INCLUDED__ +#define __CPCCLIENT_HPP_INCLUDED__ + +#include <Parser.hpp> +#include <SocketServer.hpp> +#include <util/InputStream.hpp> +#include <util/OutputStream.hpp> + +/** + * Simple CPC client class. The whole management client should be replaced + * something smarter and more worked through. + */ +class SimpleCpcClient { +public: + SimpleCpcClient(const char *host, int port); + ~SimpleCpcClient(); + + static void run(SimpleCpcClient &); + + int getPort() const { return port;} + const char * getHost() const { return host;} + + struct Process { + int m_id; + BaseString m_name; + + BaseString m_owner; + BaseString m_group; + BaseString m_runas; + + BaseString m_cwd; + BaseString m_env; + BaseString m_path; + BaseString m_args; + + BaseString m_type; + BaseString m_status; + + BaseString m_stdin; + BaseString m_stdout; + BaseString m_stderr; + BaseString m_ulimit; + }; + +private: + class ParserDummy : SocketServer::Session { + public: + ParserDummy(NDB_SOCKET_TYPE sock); + }; + + typedef Parser<ParserDummy> Parser_t; + typedef ParserRow<ParserDummy> ParserRow_t; + + char *host; + int port; + NDB_SOCKET_TYPE cpc_sock; + InputStream *cpc_in; + OutputStream *cpc_out; + +public: + int connect(); + + void cmd_list(char *arg); + void cmd_start(char *arg); + void cmd_stop(char *arg); + void cmd_help(char *arg); + + int list_processes(Vector<Process>&, Properties &reply); + int start_process(Uint32 id, Properties& reply); + int stop_process(Uint32 id, Properties& reply); + int undefine_process(Uint32 id, Properties& reply); + int define_process(Process & p, Properties& reply); + +private: + int cpc_send(const char *cmd, + const Properties &args); + + + Parser_t::ParserStatus cpc_recv(const ParserRow_t *syntax, + const Properties **reply, + void **user_data = NULL); + + const Properties *cpc_call(const char *cmd, + const Properties &args, + const ParserRow_t *reply_syntax); +}; + +#endif /* !__CPCCLIENT_HPP_INCLUDED__ */ diff --git a/ndb/test/include/NDBT_Test.hpp b/ndb/test/include/NDBT_Test.hpp index b0b5fe15960..8b69faebde8 100644 --- a/ndb/test/include/NDBT_Test.hpp +++ b/ndb/test/include/NDBT_Test.hpp @@ -392,10 +392,10 @@ C##suitname():NDBT_TestSuite(#suitname){ \ // Add a number of equal steps to the testcase #define STEPS(stepfunc, num) \ - for (int i = 0; i < num; i++){ \ + { int i; for (i = 0; i < num; i++){ \ pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \ pt->addStep(pts);\ - } + } } #define VERIFIER(stepfunc) \ ptv = new NDBT_Verifier(pt, #stepfunc, stepfunc); \ diff --git a/ndb/test/ndbapi/Makefile_old b/ndb/test/ndbapi/Makefile_old deleted file mode 100644 index c3198096ec0..00000000000 --- a/ndb/test/ndbapi/Makefile_old +++ /dev/null @@ -1,49 +0,0 @@ -include .defs.mk - - -ifeq ($(NDB_OS), OSE) -DIRS = basic flexBench flexAsynch -else -DIRS = lmc-bench ronja -BIN_DIRS = \ - flexAsynch \ - flexBench \ - flexHammer \ - flexTT \ - create_tab \ - create_all_tabs \ - drop_all_tabs \ - bulk_copy \ - restarter2 restarter \ - restarts testScan testNdbApi \ - testScanInterpreter testIndex \ - testInterpreter \ - testOIBasic \ - testBackup \ - testBasic \ - basicAsynch \ - testNodeRestart \ - testOperations testTransactions \ - testSystemRestart \ - testTimeout \ - testMgm \ - testRestartGci \ - testDataBuffers \ - testDict \ - acid \ - telco \ - indexTest \ - test_event \ - indexTest2 \ - testGrep \ - testBlobs - -ifeq ($(NDB_OS), SOLARIS) -ifeq ($(NDB_COMPILER), FORTE6) - DIRS += flexTimedAsynch -endif -endif -endif - -include ${NDB_TOP}/Epilogue.mk - diff --git a/ndb/test/ndbapi/ScanFunctions.hpp b/ndb/test/ndbapi/ScanFunctions.hpp index 2ff4b751c33..6964f8c73a8 100644 --- a/ndb/test/ndbapi/ScanFunctions.hpp +++ b/ndb/test/ndbapi/ScanFunctions.hpp @@ -286,36 +286,36 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attr = new Attrib; attr->numAttribs = 0; attriblist.push_back(attr); - - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + int i; + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = i; for(int a = 0; a<i; a++) attr->attribs[a] = a; attriblist.push_back(attr); } - for(int i = pTab->getNoOfColumns()-1; i > 0; i--){ + for(i = pTab->getNoOfColumns()-1; i > 0; i--){ attr = new Attrib; attr->numAttribs = i; for(int a = 0; a<i; a++) attr->attribs[a] = a; attriblist.push_back(attr); } - for(int i = pTab->getNoOfColumns(); i > 0; i--){ + for(i = pTab->getNoOfColumns(); i > 0; i--){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; a<pTab->getNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; a<pTab->getNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = 2; for(int a = 0; a<2; a++){ @@ -345,11 +345,11 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attriblist.push_back(attr); #if 1 - for(size_t i = 0; i < attriblist.size(); i++){ + for(size_t j = 0; j < attriblist.size(); j++){ - g_info << attriblist[i]->numAttribs << ": " ; - for(int a = 0; a < attriblist[i]->numAttribs; a++) - g_info << attriblist[i]->attribs[a] << ", "; + g_info << attriblist[j]->numAttribs << ": " ; + for(int a = 0; a < attriblist[j]->numAttribs; a++) + g_info << attriblist[j]->attribs[a] << ", "; g_info << endl; } #endif diff --git a/ndb/test/ndbapi/bank/Makefile_old b/ndb/test/ndbapi/bank/Makefile_old deleted file mode 100644 index f710f9e6612..00000000000 --- a/ndb/test/ndbapi/bank/Makefile_old +++ /dev/null @@ -1,12 +0,0 @@ -include .defs.mk - -DIRS = src bankCreator \ - bankSumAccounts \ - bankTransactionMaker \ - bankValidateAllGLs \ - bankMakeGL \ - bankTimer \ - testBank - - -include $(NDB_TOP)/Epilogue.mk diff --git a/ndb/test/ndbapi/old_dirs/flexBench/Makefile_old b/ndb/test/ndbapi/old_dirs/flexBench/Makefile_old deleted file mode 100644 index bfff5cd161a..00000000000 --- a/ndb/test/ndbapi/old_dirs/flexBench/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := ndbapitest - -BIN_TARGET := flexBench - -# Source files of non-templated classes (.C files) -SOURCES = flexBench.cpp - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/test/ndbapi/testBlobs.cpp b/ndb/test/ndbapi/testBlobs.cpp index 08bf8a2fd4b..efa0811aa39 100644 --- a/ndb/test/ndbapi/testBlobs.cpp +++ b/ndb/test/ndbapi/testBlobs.cpp @@ -42,6 +42,7 @@ struct Opt { bool m_core; bool m_dbg; bool m_dbgall; + const char* m_dbug; bool m_full; unsigned m_loop; unsigned m_parts; @@ -66,6 +67,7 @@ struct Opt { m_core(false), m_dbg(false), m_dbgall(false), + m_dbug(0), m_full(false), m_loop(1), m_parts(10), @@ -100,6 +102,7 @@ printusage() << " -core dump core on error" << endl << " -dbg print debug" << endl << " -dbgall print also NDB API debug (if compiled in)" << endl + << " -dbug opt dbug options" << endl << " -full read/write only full blob values" << endl << " -loop N loop N times 0=forever [" << d.m_loop << "]" << endl << " -parts N max parts in blob value [" << d.m_parts << "]" << endl @@ -1046,8 +1049,12 @@ writeIdx(int style) if (style == 0) { CHK(setBlobValue(tup) == 0); } else if (style == 1) { + // non-nullable must be set + CHK(g_bh1->setValue("", 0) == 0); CHK(setBlobWriteHook(tup) == 0); } else { + // non-nullable must be set + CHK(g_bh1->setValue("", 0) == 0); CHK(g_con->execute(NoCommit) == 0); CHK(writeBlobData(tup) == 0); } @@ -1463,6 +1470,12 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535) putenv(strdup("NDB_BLOB_DEBUG=1")); continue; } + if (strcmp(arg, "-dbug") == 0) { + if (++argv, --argc > 0) { + g_opt.m_dbug = strdup(argv[0]); + continue; + } + } if (strcmp(arg, "-full") == 0) { g_opt.m_full = true; continue; @@ -1533,6 +1546,9 @@ NDB_COMMAND(testOdbcDriver, "testBlobs", "testBlobs", "testBlobs", 65535) printusage(); return NDBT_ProgramExit(NDBT_WRONGARGS); } + if (g_opt.m_dbug != 0) { + DBUG_PUSH(g_opt.m_dbug); + } if (g_opt.m_pk2len == 0) { char b[100]; b[0] = 0; diff --git a/ndb/test/ndbapi/testDataBuffers.cpp b/ndb/test/ndbapi/testDataBuffers.cpp index 04602f51d5f..03d52252334 100644 --- a/ndb/test/ndbapi/testDataBuffers.cpp +++ b/ndb/test/ndbapi/testDataBuffers.cpp @@ -123,15 +123,15 @@ chkerror(char const* fmt, ...) // alignment of addresses and data sizes -static bool isAligned(unsigned x) +static bool isAligned(UintPtr x) { return ((x & 3) == 0); } static bool isAligned(char* p) { - return isAligned(unsigned(p)); + return isAligned(UintPtr(p)); } -static unsigned toAligned(unsigned x) +static unsigned toAligned(UintPtr x) { while (! isAligned(x)) x++; @@ -223,10 +223,10 @@ testcase(int flag) noRandom = ! (flag & 8); ndbout << (noRandom ? "simple sizes" : "randomize sizes") << endl; - int smax = 0, stot = 0; + int smax = 0, stot = 0, i; if (xverbose) ndbout << "- define table " << tab << endl; - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; memset(&c, 0, sizeof(c)); sprintf(c.aAttrName, "C%d", i); @@ -266,7 +266,7 @@ testcase(int flag) return ndberror("getNdbSchemaOp"); if (top->createTable(tab) < 0) return ndberror("createTable"); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (top->createAttribute( c.aAttrName, @@ -299,7 +299,7 @@ testcase(int flag) return ndberror("getNdbOperation key=%d", key); if (op->deleteTuple() < 0) return ndberror("deleteTuple key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) @@ -329,7 +329,7 @@ testcase(int flag) return ndberror("getNdbOperation key=%d", key); if (op->insertTuple() < 0) return ndberror("insertTuple key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) @@ -362,7 +362,7 @@ testcase(int flag) return ndberror("getNdbOperation key=%d", key); if (op->readTuple() < 0) return ndberror("readTuple key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->equal(c.aAttrName, (char*)&key, sizeof(key)) < 0) @@ -371,7 +371,7 @@ testcase(int flag) if (xverbose) { char tmp[20]; if (useBuf) - sprintf(tmp, "0x%x", int(c.buf + off)); + sprintf(tmp, "0x%p", c.buf + off); else strcpy(tmp, "ndbapi"); ndbout << "--- column " << i << " addr=" << tmp << endl; @@ -388,23 +388,24 @@ testcase(int flag) } if (con->execute(Commit) != 0) return ndberror("execute key=%d", key); - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { } else if (useBuf) { - for (int j = 0; j < off; j++) { + int j; + for (j = 0; j < off; j++) { if (c.buf[j] != 'B') { return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'B', c.buf[j]); } } - for (int j = 0; j < c.aArraySize; j++) { + for (j = 0; j < c.aArraySize; j++) { if (c.buf[j + off] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), c.buf[j]); } } - for (int j = c.aArraySize + off; j < c.bufsiz; j++) { + for (j = c.aArraySize + off; j < c.bufsiz; j++) { if (c.buf[j] != 'B') { return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'B', c.buf[j]); @@ -431,7 +432,8 @@ testcase(int flag) if (xverbose) ndbout << "- scan" << endl; char found[MaxOper]; - for (int k = 0; k < opercnt; k++) + int k; + for (k = 0; k < opercnt; k++) found[k] = 0; for (key = 0; key < opercnt; key++) { int off = makeOff(key); @@ -459,7 +461,7 @@ testcase(int flag) if (op->interpret_exit_ok() < 0) return ndberror("interpret_exit_ok"); } - for (int i = 0; i < attrcnt; i++) { + for (i = 0; i < attrcnt; i++) { col& c = ccol[i]; if (i == 0) { if (op->getValue(c.aAttrName, (char*)&newkey) < 0) @@ -468,7 +470,7 @@ testcase(int flag) if (xverbose) { char tmp[20]; if (useBuf) - sprintf(tmp, "0x%x", int(c.buf + off)); + sprintf(tmp, "0x%p", c.buf + off); else strcpy(tmp, "ndbapi"); ndbout << "--- column " << i << " addr=" << tmp << endl; @@ -489,22 +491,23 @@ testcase(int flag) while ((ret = rs->nextResult()) == 0) { if (key != newkey) return ndberror("unexpected key=%d newkey=%d", key, newkey); - for (int i = 1; i < attrcnt; i++) { + for (i = 1; i < attrcnt; i++) { col& c = ccol[i]; if (useBuf) { - for (int j = 0; j < off; j++) { + int j; + for (j = 0; j < off; j++) { if (c.buf[j] != 'C') { return chkerror("mismatch before key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'C', c.buf[j]); } } - for (int j = 0; j < c.aArraySize; j++) { + for (j = 0; j < c.aArraySize; j++) { if (c.buf[j + off] != byteVal(key, i, j)) { return chkerror("mismatch key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, byteVal(key, i, j), c.buf[j]); } } - for (int j = c.aArraySize + off; j < c.bufsiz; j++) { + for (j = c.aArraySize + off; j < c.bufsiz; j++) { if (c.buf[j] != 'C') { return chkerror("mismatch after key=%d col=%d pos=%d ok=%02x bad=%02x", key, i, j, 'C', c.buf[j]); @@ -533,7 +536,7 @@ testcase(int flag) } con = 0; op = 0; - for (int k = 0; k < opercnt; k++) + for (k = 0; k < opercnt; k++) if (! found[k]) return ndberror("key %d not found", k); ndbout << "scanned " << key << endl; @@ -545,6 +548,7 @@ testcase(int flag) NDB_COMMAND(testDataBuffers, "testDataBuffers", "testDataBuffers", "testDataBuffers", 65535) { + int i; ndb_init(); while (++argv, --argc > 0) { char const* p = argv[0]; @@ -602,7 +606,7 @@ NDB_COMMAND(testDataBuffers, "testDataBuffers", "testDataBuffers", "testDataBuff } } unsigned ok = true; - for (int i = 1; 0 == loopcnt || i <= loopcnt; i++) { + for (i = 1; 0 == loopcnt || i <= loopcnt; i++) { ndbout << "=== loop " << i << " ===" << endl; for (int flag = 0; flag < (1<<testbits); flag++) { if (testcase(flag) < 0) { diff --git a/ndb/test/ndbapi/testDeadlock.cpp b/ndb/test/ndbapi/testDeadlock.cpp index 66fa48173cc..eb985e815ac 100644 --- a/ndb/test/ndbapi/testDeadlock.cpp +++ b/ndb/test/ndbapi/testDeadlock.cpp @@ -459,7 +459,8 @@ wl1822_main(char scantx) static const unsigned thrcount = 2; // create threads for tx1 and tx2 Thr* thrlist[2]; - for (int n = 0; n < thrcount; n++) { + int n; + for (n = 0; n < thrcount; n++) { Thr& thr = *(thrlist[n] = new Thr(1 + n)); CHK(thr.m_ret == 0); } @@ -472,7 +473,7 @@ wl1822_main(char scantx) if (runstep != 0) thr.start(runstep); } - for (int n = 0; n < thrcount; n++) { + for (n = 0; n < thrcount; n++) { Thr& thr = *thrlist[n]; Runstep runstep = wl1822_step[i][n]; if (runstep != 0) @@ -480,7 +481,7 @@ wl1822_main(char scantx) } } // delete threads - for (int n = 0; n < thrcount; n++) { + for (n = 0; n < thrcount; n++) { Thr& thr = *thrlist[n]; thr.exit(); thr.join(); diff --git a/ndb/test/ndbapi/testDict.cpp b/ndb/test/ndbapi/testDict.cpp index 89232de2535..712ab2e4d25 100644 --- a/ndb/test/ndbapi/testDict.cpp +++ b/ndb/test/ndbapi/testDict.cpp @@ -1431,11 +1431,12 @@ int runTestDictionaryPerf(NDBT_Context* ctx, NDBT_Step* step){ Vector<char*> cols; Vector<const NdbDictionary::Table*> tabs; + int i; Ndb* pNdb = GETNDB(step); const Uint32 count = NDBT_Tables::getNumTables(); - for (int i=0; i < count; i++){ + for (i=0; i < count; i++){ const NdbDictionary::Table * tab = NDBT_Tables::getTable(i); pNdb->getDictionary()->createTable(* tab); @@ -1458,7 +1459,7 @@ runTestDictionaryPerf(NDBT_Context* ctx, NDBT_Step* step){ Uint32 size = cols.size() / 2; char ** columns = &cols[0]; Uint64 start = NdbTick_CurrentMillisecond(); - for(int i = 0; i<times; i++){ + for(i = 0; i<times; i++){ int j = 2 * (rand() % size); const NdbDictionary::Table* tab = (const NdbDictionary::Table*)tcols[j]; const char * col = tcols[j+1]; @@ -1478,6 +1479,69 @@ runTestDictionaryPerf(NDBT_Context* ctx, NDBT_Step* step){ return NDBT_OK; } +int runFailAddFragment(NDBT_Context* ctx, NDBT_Step* step){ + static int tuplst[] = { 4007, 4008, 4009, 4010, 4011, 4012 }; + static int tuxlst[] = { 12001, 12002, 12003, 12004, 12005, 12006 }; + static unsigned tupcnt = sizeof(tuplst)/sizeof(tuplst[0]); + static unsigned tuxcnt = sizeof(tuxlst)/sizeof(tuxlst[0]); + + NdbRestarter restarter; + int nodeId = restarter.getMasterNodeId(); + Ndb* pNdb = GETNDB(step); + NdbDictionary::Dictionary* pDic = pNdb->getDictionary(); + NdbDictionary::Table tab(*ctx->getTab()); + tab.setFragmentType(NdbDictionary::Object::FragAllLarge); + + // ordered index on first few columns + NdbDictionary::Index idx("X"); + idx.setTable(tab.getName()); + idx.setType(NdbDictionary::Index::OrderedIndex); + idx.setLogging(false); + for (int i_hate_broken_compilers = 0; + i_hate_broken_compilers < 3 && + i_hate_broken_compilers < tab.getNoOfColumns(); + i_hate_broken_compilers++) { + idx.addColumn(*tab.getColumn(i_hate_broken_compilers)); + } + + const int loops = ctx->getNumLoops(); + int result = NDBT_OK; + (void)pDic->dropTable(tab.getName()); + + for (int l = 0; l < loops; l++) { + for (unsigned i1 = 0; i1 < tupcnt; i1++) { + unsigned j = (l == 0 ? i1 : myRandom48(tupcnt)); + int errval = tuplst[j]; + g_info << "insert error node=" << nodeId << " value=" << errval << endl; + CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0, + "failed to set error insert"); + CHECK2(pDic->createTable(tab) != 0, + "failed to fail after error insert " << errval); + CHECK2(pDic->createTable(tab) == 0, + pDic->getNdbError()); + CHECK2(pDic->dropTable(tab.getName()) == 0, + pDic->getNdbError()); + } + for (unsigned i2 = 0; i2 < tuxcnt; i2++) { + unsigned j = (l == 0 ? i2 : myRandom48(tuxcnt)); + int errval = tuxlst[j]; + g_info << "insert error node=" << nodeId << " value=" << errval << endl; + CHECK2(restarter.insertErrorInNode(nodeId, errval) == 0, + "failed to set error insert"); + CHECK2(pDic->createTable(tab) == 0, + pDic->getNdbError()); + CHECK2(pDic->createIndex(idx) != 0, + "failed to fail after error insert " << errval); + CHECK2(pDic->createIndex(idx) == 0, + pDic->getNdbError()); + CHECK2(pDic->dropTable(tab.getName()) == 0, + pDic->getNdbError()); + } + } +end: + return result; +} + NDBT_TESTSUITE(testDict); TESTCASE("CreateAndDrop", "Try to create and drop the table loop number of times\n"){ @@ -1573,6 +1637,10 @@ TESTCASE("DictionaryPerf", ""){ INITIALIZER(runTestDictionaryPerf); } +TESTCASE("FailAddFragment", + "Fail add fragment or attribute in TUP or TUX\n"){ + INITIALIZER(runFailAddFragment); +} NDBT_TESTSUITE_END(testDict); int main(int argc, const char** argv){ diff --git a/ndb/test/ndbapi/testIndex.cpp b/ndb/test/ndbapi/testIndex.cpp index ed9e114fd92..6623ad35a7f 100644 --- a/ndb/test/ndbapi/testIndex.cpp +++ b/ndb/test/ndbapi/testIndex.cpp @@ -58,7 +58,9 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ // Build attrib definitions that describes which attributes to build index // Try to build strange combinations, not just "all" or all PK's - for(int i = 1; i <= pTab->getNoOfColumns(); i++){ + int i; + + for(i = 1; i <= pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = i; for(int a = 0; a<i; a++) @@ -66,7 +68,7 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attriblist.push_back(attr); } int b = 0; - for(int i = pTab->getNoOfColumns()-1; i > 0; i--){ + for(i = pTab->getNoOfColumns()-1; i > 0; i--){ attr = new Attrib; attr->numAttribs = i; b++; @@ -74,21 +76,21 @@ void AttribList::buildAttribList(const NdbDictionary::Table* pTab){ attr->attribs[a] = a+b; attriblist.push_back(attr); } - for(int i = pTab->getNoOfColumns(); i > 0; i--){ + for(i = pTab->getNoOfColumns(); i > 0; i--){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; a<pTab->getNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = pTab->getNoOfColumns() - i; for(int a = 0; a<pTab->getNoOfColumns() - i; a++) attr->attribs[a] = pTab->getNoOfColumns()-a-1; attriblist.push_back(attr); } - for(int i = 1; i < pTab->getNoOfColumns(); i++){ + for(i = 1; i < pTab->getNoOfColumns(); i++){ attr = new Attrib; attr->numAttribs = 2; for(int a = 0; a<2; a++){ @@ -226,8 +228,8 @@ int runCreateIndexes(NDBT_Context* ctx, NDBT_Step* step){ while (l < loops && result == NDBT_OK){ - - for (unsigned int i = 0; i < attrList.attriblist.size(); i++){ + unsigned int i; + for (i = 0; i < attrList.attriblist.size(); i++){ // Try to create index if (create_index(ctx, i, pTab, pNdb, attrList.attriblist[i], logged) == NDBT_FAILED) @@ -235,7 +237,7 @@ int runCreateIndexes(NDBT_Context* ctx, NDBT_Step* step){ } // Now drop all indexes that where created - for (unsigned int i = 0; i < attrList.attriblist.size(); i++){ + for (i = 0; i < attrList.attriblist.size(); i++){ // Try to drop index if (drop_index(i, pNdb, pTab, attrList.attriblist[i]) != NDBT_OK) @@ -1083,8 +1085,8 @@ runUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){ else pIdx.setType(NdbDictionary::Index::UniqueHashIndex); pIdx.setStoredIndex(logged); - - for (int c = 0; c< pTab->getNoOfColumns(); c++){ + int c; + for (c = 0; c< pTab->getNoOfColumns(); c++){ const NdbDictionary::Column * col = pTab->getColumn(c); if(col->getPrimaryKey()){ pIdx.addIndexColumn(col->getName()); @@ -1093,7 +1095,7 @@ runUniqueNullTransactions(NDBT_Context* ctx, NDBT_Step* step){ } int colId = -1; - for (int c = 0; c< pTab->getNoOfColumns(); c++){ + for (c = 0; c< pTab->getNoOfColumns(); c++){ const NdbDictionary::Column * col = pTab->getColumn(c); if(col->getNullable()){ pIdx.addIndexColumn(col->getName()); diff --git a/ndb/test/ndbapi/testLcp.cpp b/ndb/test/ndbapi/testLcp.cpp index c92be091a97..d11692db761 100644 --- a/ndb/test/ndbapi/testLcp.cpp +++ b/ndb/test/ndbapi/testLcp.cpp @@ -85,7 +85,8 @@ main(int argc, char ** argv){ g_info << " where ZLCP_OP_WRITE_RT_BREAK is finished before SAVE_PAGES" << endl; require(!pause_lcp()); - for(size_t j = 0; j<g_rows; j++){ + size_t j; + for(j = 0; j<g_rows; j++){ require(!do_op(j)); } require(!continue_lcp(5900)); @@ -98,7 +99,7 @@ main(int argc, char ** argv){ << endl; require(!load_table()); require(!pause_lcp()); - for(size_t j = 0; j<g_rows; j++){ + for(j = 0; j<g_rows; j++){ require(!do_op(j)); } require(!continue_lcp(5901)); @@ -109,7 +110,7 @@ main(int argc, char ** argv){ g_info << "Testing pre LCP operations, undo-ed at commit" << endl; require(!load_table()); require(!pause_lcp()); - for(size_t j = 0; j<g_rows; j++){ + for(j = 0; j<g_rows; j++){ require(!do_op(j)); } require(!continue_lcp(5902)); diff --git a/ndb/test/ndbapi/testNdbApi.cpp b/ndb/test/ndbapi/testNdbApi.cpp index 74cb1f8bcd0..a1ebac609b6 100644 --- a/ndb/test/ndbapi/testNdbApi.cpp +++ b/ndb/test/ndbapi/testNdbApi.cpp @@ -88,10 +88,10 @@ int runTestMaxNdb(NDBT_Context* ctx, NDBT_Step* step){ oldi = i; - for(size_t i = 0; i < ndbVector.size(); i++){ - delete ndbVector[i]; - if(((i+1) % 250) == 0){ - ndbout << "Deleted " << (Uint64) i << " ndb objects " << endl; + for(size_t j = 0; j < ndbVector.size(); j++){ + delete ndbVector[j]; + if(((j+1) % 250) == 0){ + ndbout << "Deleted " << (Uint64) j << " ndb objects " << endl; } } ndbVector.clear(); @@ -178,8 +178,8 @@ int runTestMaxTransaction(NDBT_Context* ctx, NDBT_Step* step){ oldi = i; - for(size_t i = 0; i < conVector.size(); i++){ - pNdb->closeTransaction(conVector[i]); + for(size_t j = 0; j < conVector.size(); j++){ + pNdb->closeTransaction(conVector[j]); } conVector.clear(); l++; @@ -537,8 +537,8 @@ int runTestDeleteNdb(NDBT_Context* ctx, NDBT_Step* step){ } // Delete the ndb objects - for(size_t i = 0; i < ndbVector.size(); i++) - delete ndbVector[i]; + for(size_t j = 0; j < ndbVector.size(); j++) + delete ndbVector[j]; ndbVector.clear(); l++; } diff --git a/ndb/test/ndbapi/testOIBasic.cpp b/ndb/test/ndbapi/testOIBasic.cpp index 21862e02328..41f0686e63b 100644 --- a/ndb/test/ndbapi/testOIBasic.cpp +++ b/ndb/test/ndbapi/testOIBasic.cpp @@ -407,10 +407,11 @@ Col::verify(const void* addr) const const unsigned char* p = (const unsigned char*)addr; unsigned n = (p[0] << 8) | p[1]; assert(n <= m_length); - for (unsigned i = 0; i < n; i++) { + unsigned i; + for (i = 0; i < n; i++) { assert(p[2 + i] != 0); } - for (unsigned i = n; i < m_length; i++) { + for (i = n; i < m_length; i++) { assert(p[2 + i] == 0); } } @@ -3021,7 +3022,8 @@ runstep(Par par, const char* fname, TFunc func, unsigned mode) { LL2(fname); const int threads = (mode & ST ? 1 : par.m_threads); - for (int n = 0; n < threads; n++) { + int n; + for (n = 0; n < threads; n++) { LL4("start " << n); Thr& thr = *g_thrlist[n]; thr.m_par.m_tab = par.m_tab; @@ -3033,7 +3035,7 @@ runstep(Par par, const char* fname, TFunc func, unsigned mode) thr.start(); } unsigned errs = 0; - for (int n = threads - 1; n >= 0; n--) { + for (n = threads - 1; n >= 0; n--) { LL4("stop " << n); Thr& thr = *g_thrlist[n]; thr.stopped(); @@ -3301,10 +3303,11 @@ runtest(Par par) CHK(con.connect() == 0); par.m_con = &con; g_thrlist = new Thr* [par.m_threads]; - for (unsigned n = 0; n < par.m_threads; n++) { + unsigned n; + for (n = 0; n < par.m_threads; n++) { g_thrlist[n] = 0; } - for (unsigned n = 0; n < par.m_threads; n++) { + for (n = 0; n < par.m_threads; n++) { g_thrlist[n] = new Thr(par, n); Thr& thr = *g_thrlist[n]; assert(thr.m_thread != 0); @@ -3330,11 +3333,11 @@ runtest(Par par) } } } - for (unsigned n = 0; n < par.m_threads; n++) { + for (n = 0; n < par.m_threads; n++) { Thr& thr = *g_thrlist[n]; thr.exit(); } - for (unsigned n = 0; n < par.m_threads; n++) { + for (n = 0; n < par.m_threads; n++) { Thr& thr = *g_thrlist[n]; thr.join(); delete &thr; diff --git a/ndb/test/ndbapi/testReadPerf.cpp b/ndb/test/ndbapi/testReadPerf.cpp index f8ecc6192dc..3adcb5a2d9b 100644 --- a/ndb/test/ndbapi/testReadPerf.cpp +++ b/ndb/test/ndbapi/testReadPerf.cpp @@ -99,7 +99,8 @@ main(int argc, const char** argv){ { "verbose", 'v', arg_flag, &verbose, "Print verbose status", "verbose" } }; const int num_args = 1 + P_MAX; - for(int i = 0; i<P_MAX; i++){ + int i; + for(i = 0; i<P_MAX; i++){ args[i+1].long_name = g_paramters[i].name; args[i+1].short_name = * g_paramters[i].name; args[i+1].type = arg_integer; @@ -127,7 +128,7 @@ main(int argc, const char** argv){ g_err << "Wait until ready failed" << endl; goto error; } - for(int i = optind; i<argc; i++){ + for(i = optind; i<argc; i++){ const char * T = argv[i]; g_info << "Testing " << T << endl; BaseString::snprintf(g_table, sizeof(g_table), T); diff --git a/ndb/test/ndbapi/testRestartGci.cpp b/ndb/test/ndbapi/testRestartGci.cpp index e817245af55..4e541d1f38f 100644 --- a/ndb/test/ndbapi/testRestartGci.cpp +++ b/ndb/test/ndbapi/testRestartGci.cpp @@ -132,7 +132,8 @@ int runVerifyInserts(NDBT_Context* ctx, NDBT_Step* step){ // RULE1: The vector with saved records should have exactly as many // records with lower or same gci as there are in DB int recordsWithLowerOrSameGci = 0; - for (unsigned i = 0; i < savedRecords.size(); i++){ + unsigned i; + for (i = 0; i < savedRecords.size(); i++){ if (savedRecords[i].m_gci <= restartGCI) recordsWithLowerOrSameGci++; } @@ -144,7 +145,7 @@ int runVerifyInserts(NDBT_Context* ctx, NDBT_Step* step){ // RULE2: The records found in db should have same or lower // gci as in the vector - for (unsigned i = 0; i < savedRecords.size(); i++){ + for (i = 0; i < savedRecords.size(); i++){ CHECK(hugoOps.startTransaction(pNdb) == 0); CHECK(hugoOps.pkReadRecord(pNdb, i) == 0); if (hugoOps.execute_Commit(pNdb) != 0){ diff --git a/ndb/test/ndbapi/testScanPerf.cpp b/ndb/test/ndbapi/testScanPerf.cpp index fca67c6abcb..ee2a92e88a9 100644 --- a/ndb/test/ndbapi/testScanPerf.cpp +++ b/ndb/test/ndbapi/testScanPerf.cpp @@ -82,7 +82,8 @@ main(int argc, const char** argv){ { "verbose", 'v', arg_flag, &verbose, "Print verbose status", "verbose" } }; const int num_args = 1 + P_MAX; - for(int i = 0; i<P_MAX; i++){ + int i; + for(i = 0; i<P_MAX; i++){ args[i+1].long_name = g_paramters[i].name; args[i+1].short_name = * g_paramters[i].name; args[i+1].type = arg_integer; @@ -109,7 +110,7 @@ main(int argc, const char** argv){ g_err << "Wait until ready failed" << endl; goto error; } - for(int i = optind; i<argc; i++){ + for(i = optind; i<argc; i++){ const char * T = argv[i]; g_info << "Testing " << T << endl; BaseString::snprintf(g_tablename, sizeof(g_tablename), T); diff --git a/ndb/test/ndbapi/testSystemRestart.cpp b/ndb/test/ndbapi/testSystemRestart.cpp index f8f2b84acc4..35016896495 100644 --- a/ndb/test/ndbapi/testSystemRestart.cpp +++ b/ndb/test/ndbapi/testSystemRestart.cpp @@ -452,7 +452,7 @@ int runSystemRestart3(NDBT_Context* ctx, NDBT_Step* step){ } Vector<int> nodeIds; - for(Uint32 i = 0; i<nodeCount; i++) + for(i = 0; i<nodeCount; i++) nodeIds.push_back(restarter.getDbNodeId(i)); Uint32 currentRestartNodeIndex = 0; @@ -561,7 +561,7 @@ int runSystemRestart4(NDBT_Context* ctx, NDBT_Step* step){ } Vector<int> nodeIds; - for(Uint32 i = 0; i<nodeCount; i++) + for(i = 0; i<nodeCount; i++) nodeIds.push_back(restarter.getDbNodeId(i)); Uint32 currentRestartNodeIndex = 0; @@ -691,7 +691,7 @@ int runSystemRestart5(NDBT_Context* ctx, NDBT_Step* step){ } Vector<int> nodeIds; - for(Uint32 i = 0; i<nodeCount; i++) + for(i = 0; i<nodeCount; i++) nodeIds.push_back(restarter.getDbNodeId(i)); Uint32 currentRestartNodeIndex = 0; @@ -821,7 +821,7 @@ int runSystemRestart6(NDBT_Context* ctx, NDBT_Step* step){ } Vector<int> nodeIds; - for(Uint32 i = 0; i<nodeCount; i++) + for(i = 0; i<nodeCount; i++) nodeIds.push_back(restarter.getDbNodeId(i)); Uint32 currentRestartNodeIndex = 0; @@ -877,7 +877,7 @@ int runSystemRestart7(NDBT_Context* ctx, NDBT_Step* step){ } Vector<int> nodeIds; - for(Uint32 i = 0; i<nodeCount; i++) + for(i = 0; i<nodeCount; i++) nodeIds.push_back(restarter.getDbNodeId(i)); int a_nodeIds[64]; @@ -952,7 +952,7 @@ int runSystemRestart8(NDBT_Context* ctx, NDBT_Step* step){ } Vector<int> nodeIds; - for(Uint32 i = 0; i<nodeCount; i++) + for(i = 0; i<nodeCount; i++) nodeIds.push_back(restarter.getDbNodeId(i)); int a_nodeIds[64]; diff --git a/ndb/test/odbc/tpcb/Makefile b/ndb/test/odbc/tpcb/Makefile deleted file mode 100644 index 8ab429c8ea1..00000000000 --- a/ndb/test/odbc/tpcb/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -include .defs.mk - -TYPE = * - -BIN_TARGET = tpcb - -SOURCES = ttTime.c tpcb.cpp - -CCFLAGS_LOC += \ - -I$(NDB_TOP)/include \ - -I$(NDB_TOP)/include/ndbapi \ - -I$(NDB_TOP)/include/portlib \ - -I$(NDB_TOP)/include/util \ - -I$(NDB_TOP)/test/include \ - -I/usr/local/include - -CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare -Wformat - -CCFLAGS_TOP += -DndbODBC - -BIN_TARGET_LIBS = NDB_API_pic NDB_ODBC_pic NDBT - -ifeq ($(NDB_OS),SOLARIS) -BIN_TARGET_LIBS += dmallocthcxx -CCFLAGS_TOP += -DDMALLOC -endif - -include $(NDB_TOP)/Epilogue.mk - -$(BIN_DIR)$(BIN_TARGET): Makefile diff --git a/ndb/test/odbc/tpcb/Makefile_mysql b/ndb/test/odbc/tpcb/Makefile_mysql deleted file mode 100644 index 4e1b9a25fe2..00000000000 --- a/ndb/test/odbc/tpcb/Makefile_mysql +++ /dev/null @@ -1,33 +0,0 @@ -include $(NDB_TOP)/Defs.mk - -TYPE = odbcclient - -BIN_TARGET = tpcb - -SOURCES = ttTime.c tpcb.cpp - -CCFLAGS_LOC += -I/usr/local/include \ - -I$(NDB_TOP)/test/include \ - -I$(NDB_TOP)/include \ - -I$(NDB_TOP)/include/util \ - -I$(NDB_TOP)/src/client/odbc/common - - - - -#CCFLAGS_WARNINGS += -Wno-unused - -LIBS_LOC += -L/usr/local/lib -BIN_TARGET_LIBS_DIRS += /usr/local/lib -BIN_TARGET_LIBS += odbc odbcinst - -#LIBS_SPEC += -pg -# -lNDBT \ -# -lodbc \ -# -lodbcinst \ -# -lportlib - - - -include $(NDB_TOP)/Epilogue.mk - diff --git a/ndb/test/odbc/tpcb/Makefile_ndb b/ndb/test/odbc/tpcb/Makefile_ndb deleted file mode 100644 index 85960413ef0..00000000000 --- a/ndb/test/odbc/tpcb/Makefile_ndb +++ /dev/null @@ -1,30 +0,0 @@ -include $(NDB_TOP)/Defs.mk - -TYPE = * - -BIN_TARGET = tpcb - -SOURCES = ttTime.c tpcb.cpp - -CCFLAGS_LOC += \ - -I$(NDB_TOP)/include \ - -I$(NDB_TOP)/include/ndbapi \ - -I$(NDB_TOP)/include/portlib \ - -I$(NDB_TOP)/include/util \ - -I$(NDB_TOP)/test/include \ - -I/usr/local/include - -CCFLAGS_WARNINGS += -Wno-unused -Wno-sign-compare -Wformat - -CCFLAGS_TOP += -DndbODBC - -BIN_TARGET_LIBS = NDB_API_pic NDB_ODBC_pic NDBT - -ifeq ($(NDB_OS),SOLARIS) -BIN_TARGET_LIBS += dmallocthcxx -CCFLAGS_TOP += -DDMALLOC -endif - -include $(NDB_TOP)/Epilogue.mk - -$(BIN_DIR)$(BIN_TARGET): Makefile diff --git a/ndb/test/odbc/tpcb/readme.txt b/ndb/test/odbc/tpcb/readme.txt deleted file mode 100644 index 008cafb9d2f..00000000000 --- a/ndb/test/odbc/tpcb/readme.txt +++ /dev/null @@ -1,15 +0,0 @@ -'tpcb' requires an .odbc.ini file in -/etc/ -or in -/home/user/ - -The .odbc.ini file must contain a DSN entry called ndb: - -#--------- .odbc.ini example -------------------- - -[ndb] -Driver = /path_to_installation/lib/libNDB_ODBC.so - -#--------- End of example ----------------------- - - diff --git a/ndb/test/odbc/tpcb/timesten.h b/ndb/test/odbc/tpcb/timesten.h deleted file mode 100644 index 45579f9d277..00000000000 --- a/ndb/test/odbc/tpcb/timesten.h +++ /dev/null @@ -1,188 +0,0 @@ -/* 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 */ - -/* - * $Revision: 1.1 $ - * (c) Copyright 1997-2003, TimesTen, Inc. - * All rights reserved. - */ - -#ifndef TIMESTEN_H_INCLUDED -#define TIMESTEN_H_INCLUDED - -#ifdef _WIN32 -#include <windows.h> -#endif - -#include <sql.h> -#include <sqltypes.h> -#include <sqlext.h> -/* - * TimesTen extension to application data types; only usable - * when application directly linked to the TimesTen driver. - */ -#define SQL_C_ADDR 100 - -#ifndef SQL_C_SBIGINT -#if (ODBCVER < 0x0300) -#define SQL_C_SBIGINT (SQL_BIGINT+SQL_SIGNED_OFFSET) -#define SQL_C_UBIGINT (SQL_BIGINT+SQL_UNSIGNED_OFFSET) -#endif -#endif - -#define SQL_C_BIGINT SQL_C_SBIGINT - -#if (ODBCVER < 0x0300) -#ifdef _WIN32 -typedef __int64 SQLBIGINT; -/* On Unix platforms SQLBIGINT is defined in odbcinclude directory*/ -#endif -#endif - -#define BIGINT SQLBIGINT - -#ifdef _WIN32 -#define UBIGINT unsigned __int64 -#else -#define UBIGINT unsigned long long -#endif - - -#define SQL_WCHAR (-8) -#define SQL_WVARCHAR (-9) -#define SQL_WLONGVARCHAR (-10) -#define SQL_C_WCHAR SQL_WCHAR - -/* SQLGetInfo() InfoTypes */ -#define SQL_CONVERT_WCHAR 122 -#define SQL_CONVERT_WLONGVARCHAR 125 -#define SQL_CONVERT_WVARCHAR 126 - -/* TimesTen specific SQLGetInfo types */ -#define TT_REPLICATION_INVALID (SQL_INFO_DRIVER_START + 2000) - -/* SQLGetInfo() return value bitmasks */ -#ifndef SQL_CVT_WCHAR -/* -** These definitions differ from Microsoft in that they are not -** specified as long (e.g. 0x00200000L), hence they are protected -** by the ifndef above. -*/ -#define SQL_CVT_WCHAR 0x00200000 -#define SQL_CVT_WLONGVARCHAR 0x00400000 -#define SQL_CVT_WVARCHAR 0x00800000 -#endif - -/* -** The Microsoft Driver Manager SQLBindParameter() will not pass SQL_WCHAR -** through. Use this hack to get around it. -*/ -#define SQL_WCHAR_DM_SQLBINDPARAMETER_BYPASS -888 - -/* This is an extension to ODBC's isolation levels. It reflects an - * earlier implementation of read-committed that released locks on - * next fetch, rather than releasing locks before returning value to - * application. */ -#define SQL_TXN_CURSOR_STABILITY 0x00001000 -#define SQL_TXN_NOBLOCK_DELETE 0x00002000 - -/* TimesTen-specific connection option */ -#define TT_PREFETCH_CLOSE 10001 -#define TT_PREFETCH_CLOSE_OFF 0 -#define TT_PREFETCH_CLOSE_ON 1 - -/* Adding a new sql connection option */ -#define TT_PREFETCH_COUNT 10003 -#define TT_PREFETCH_COUNT_MAX 128 - -/* - * Platform specific data types for integers that scale - * with pointer size - */ - -#ifdef _IA64_ -typedef signed __int64 tt_ptrint; -typedef unsigned __int64 tt_uptrint; -#else -#ifdef _WIN32 -typedef signed long tt_ptrint; -typedef unsigned long tt_uptrint; -#else -typedef signed long tt_ptrint; -typedef unsigned long tt_uptrint; -#endif -#endif - -#ifdef _WIN32 -typedef signed __int64 tt_int8; -typedef unsigned __int64 tt_uint8; -#else -typedef signed long long tt_int8; -typedef unsigned long long tt_uint8; -#endif - -/* printf formats for pointer-sized integers */ -#ifdef _IA64_ /* 64-bit NT */ -#define PTRINT_FMT "I64d" -#define UPTRINT_FMT "I64u" -#define xPTRINT_FMT "I64x" -#define XPTRINT_FMT "I64X" -#else -#ifdef _WIN32 /* 32-bit NT */ -#define PTRINT_FMT "ld" -#define UPTRINT_FMT "lu" -#define xPTRINT_FMT "lx" -#define XPTRINT_FMT "lX" -#else /* 32 and 64-bit UNIX */ -#define PTRINT_FMT "ld" -#define UPTRINT_FMT "lu" -#define xPTRINT_FMT "lx" -#define XPTRINT_FMT "lX" -#endif -#endif - -/* printf formats for 8-byte integers */ -#ifndef INT8_FMT_DEFINED -#ifdef _WIN32 /* 32 and 64-bit NT */ -#define INT8_FMT "I64d" -#define UINT8_FMT "I64u" -#define xINT8_FMT "I64x" -#define XINT8_FMT "I64X" -#else /* 32 and 64-bit UNIX */ -#define INT8_FMT "lld" -#define UINT8_FMT "llu" -#define xINT8_FMT "llx" -#define XINT8_FMT "llX" -#endif -#define INT8_FMT_DEFINED 1 -#endif - -/* The following types are defined in the newer odbc include files - from Microsoft -*/ -#if defined (_WIN32) && !defined (_IA64_) -#ifndef SQLROWSETSIZE -#define SQLROWSETSIZE SQLUINTEGER -#define SQLLEN SQLINTEGER -#define SQLROWOFFSET SQLINTEGER -#define SQLROWCOUNT SQLUINTEGER -#define SQLULEN SQLUINTEGER -#define SQLSETPOSIROW SQLUSMALLINT -#endif -#endif - - -#endif diff --git a/ndb/test/odbc/tpcb/tpcb.cpp b/ndb/test/odbc/tpcb/tpcb.cpp deleted file mode 100644 index 60d746e7844..00000000000 --- a/ndb/test/odbc/tpcb/tpcb.cpp +++ /dev/null @@ -1,1415 +0,0 @@ -/* 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 */ - -static const volatile char cvsid[] = "$Id: tpcb.cpp,v 1.4 2003/09/26 09:04:34 johan Exp $"; -/* - * $Revision: 1.4 $ - * (c) Copyright 1996-2003, TimesTen, Inc. - * All rights reserved. - */ - -/* This source is best displayed with a tabstop of 4 */ - -#define NDB - -//#define MYSQL - -#ifdef WIN32 -#include <windows.h> -#include "ttRand.h" -#else -#if !defined NDB && !defined MYSQL -#include <sqlunix.h> -#endif -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#ifdef SB_P_OS_CHORUS -#include "ttRand.h" -#endif -#endif - -#include <math.h> -#include <time.h> -#include <sql.h> -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> - -#if !defined NDB && !defined MYSQL -#include "ttTime.h" -#include "utils.h" -#include "tt_version.h" -#include "timesten.h" -#endif - -#if defined NDB || defined MYSQL -#include <NdbOut.hpp> -#include <string.h> - -#include <sqlext.h> -#include <sql.h> -extern "C" { -#include "ttTime.h" -#include "timesten.h" - void ttGetWallClockTime(ttWallClockTime* timeP); - void ttCalcElapsedWallClockTime(ttWallClockTime* beforeP, - ttWallClockTime* afterP, - double* nmillisecondsP); - void ttGetThreadTimes(ttThreadTimes * endRes); - void ttCalcElapsedThreadTimes(ttThreadTimes* startRes, - ttThreadTimes * endRes, - double * kernel, - double * user); -} - -#define app_exit exit -#define status_msg0 ndbout_c -#define status_msg1 ndbout_c -#define status_msg2 ndbout_c -#define err_msg0 ndbout_c -#define err_msg1 ndbout_c -#define err_msg3 ndbout_c -#define out_msg0 ndbout_c -#define out_msg1 ndbout_c -#define out_msg3 ndbout_c -#define CONN_STR_LEN 255 -#define DBMS_TIMESTEN 1 -#define DBMS_MSSQL 2 -#define DBMS_UNKNOWN 3 -#define ABORT_DISCONNECT_EXIT 1 -#define NO_EXIT 0 -#define ERROR_EXIT 1 -#define DISCONNECT_EXIT 2 -#endif - -#define VERBOSE_NOMSGS 0 -/* this value is used for results (and err msgs) only */ -#define VERBOSE_RESULTS 1 -/* this value is the default for the cmdline demo */ -#define VERBOSE_DFLT 2 -#define VERBOSE_ALL 3 - -#ifdef MYSQL -#define DSNNAME "DSN=myodbc3" -#elif defined NDB -#define DSNNAME "DSN=ndb" -#else -#define DSNNAME "DSN=" -#endif - -/* number of branches, tellers, and accounts */ - -#define NumBranches 1 -#define TellersPerBranch 10 -#define AccountsPerBranch 10000 - -/* number of transactions to execute */ - -#define NumXacts 25000 - -/* starting seed value for the random number generator */ - -#define SeedVal 84773 - -/* for MS SQL, the drop, create and use database statements */ - -#define DatabaseDropStmt "drop database tpcbDB;" -#ifdef MYSQL -#define DatabaseCreateStmt "create database tpcbDB;" -#else -#define DatabaseCreateStmt "create database tpcbDB ON DEFAULT = %d;" -#endif -#define DatabaseUseStmt "use tpcbDB;" - -/* - * Specifications of table columns. - * Fillers of 80, 80, 84, and 24 bytes, respectively, are used - * to ensure that rows are the width required by the benchmark. - * - * Note: The TimesTen and MS SQL CREATE TABLE statements for the - * accounts, tellers and branches tables are different. - * - */ - -#define TuplesPerPage 256 - - -#ifdef MYSQL - -#define AccountCrTblStmt "create table accounts \ -(number integer not null primary key, \ -branchnum integer not null, \ -balance float not null, \ -filler char(80));" - -#define TellerCrTblStmt "create table tellers \ -(number integer not null primary key, \ -branchnum integer not null, \ -balance float not null, \ -filler char(80));" - -#define BranchCrTblStmt "create table branches \ -(number integer not null primary key, \ -balance float not null, \ -filler char(84));" - -#endif - - -#ifdef NDB -#define AccountCrTblStmt "create table accounts \ -(number integer not null primary key, \ -branchnum integer not null, \ -balance float not null, \ -filler char(80)) nologging" - -#define TellerCrTblStmt "create table tellers \ -(number integer not null primary key, \ -branchnum integer not null, \ -balance float not null, \ -filler char(80)) nologging" - -#define BranchCrTblStmt "create table branches \ -(number integer not null primary key, \ -balance float not null, \ -filler char(84)) nologging" -#endif - -#ifdef NDB - -#define HistoryCrTblStmt "create table History \ -(tellernum integer not null, \ -branchnum integer not null, \ -accountnum integer not null, \ -delta float not null, \ -createtime integer not null, \ -filler char(24), \ -primary key (tellernum, branchnum, accountnum, delta, createtime)) nologging" - -#else - -#ifdef MYSQL - -#define HistoryCrTblStmt "create table History \ -(tellernum integer not null, \ -branchnum integer not null, \ -accountnum integer not null, \ -delta float(53) not null, \ -createtime integer not null, \ -filler char(24))" -#endif - -#define HistoryCrTblStmt "create table History \ -(tellernum integer not null, \ -branchnum integer not null, \ -accountnum integer not null, \ -delta float(53) not null, \ -createtime integer not null, \ -filler char(24));" -#endif - -#define TTAccountCrTblStmt "create table accounts \ -(number integer not null primary key, \ -branchnum integer not null, \ -balance float(53) not null, \ -filler char(80)) unique hash on (number) pages = %" PTRINT_FMT ";" - -#define TTTellerCrTblStmt "create table tellers \ -(number integer not null primary key, \ -branchnum integer not null, \ -balance float(53) not null, \ -filler char(80)) unique hash on (number) pages = %" PTRINT_FMT ";" - -#define TTBranchCrTblStmt "create table branches \ -(number integer not null primary key, \ -balance float(53) not null, \ -filler char(84)) unique hash on (number) pages = %" PTRINT_FMT ";" - - -/* Insertion statements used to populate the tables */ - -#define NumInsStmts 3 -char* insStmt[NumInsStmts] = { - "insert into branches values (?, 0.0, NULL)", - "insert into tellers values (?, ?, 0.0, NULL)", - "insert into accounts values (?, ?, 0.0, NULL)" -}; - -/* Transaction statements used to update the tables */ - -#define NumXactStmts 5 - -#ifdef NDB -char* tpcbXactStmt[NumXactStmts] = { - "update accounts \ -set balance = balance + ? \ -where number = ?", - - "select balance \ -from accounts \ -where number = ?", - - "update tellers \ -set balance = balance + ? \ -where number = ?", - - "update branches \ -set balance = balance + ? \ -where number = ?", - - "insert into History(tellernum, branchnum, \ -accountnum, delta, createtime, filler) \ -values (?, ?, ?, ?, ?, NULL)" -}; - -#else -char* tpcbXactStmt[NumXactStmts] = { - "update accounts \ -set balance = balance + ? \ -where number = ?;", - - "select balance \ -from accounts \ -where number = ?;", - - "update tellers \ -set balance = balance + ? \ -where number = ?;", - - "update branches \ -set balance = balance + ? \ -where number = ?;", - - "insert into History \ -values (?, ?, ?, ?, ?, NULL);" -}; - - -#endif - -/* Global parameters and flags (typically set by parse_args()) */ - -int tabFlag = 0; /* Default is NOT tab output mode */ -char szConnStrIn[CONN_STR_LEN]; /* ODBC Connection String */ -int printXactTimes = 0; /* Transaction statistics - * gathering flag */ -char statFile[FILENAME_MAX]; /* Transaction statistics filename */ -int scaleFactor = 2; /* Default TPS scale factor */ -int numBranchTups; /* Number of branches */ -int numTellerTups; /* Number of tellers */ -int numAccountTups; /* Number of accounts */ -int numNonLocalAccountTups; /* Number of local accounts */ -int numXacts = NumXacts; /* Default number of transactions */ -int verbose = VERBOSE_DFLT; /* Verbose level */ -FILE *statusfp; /* File for status messages */ - - - -int DBMSType; /* DBMS type (DBMS_TIMESTEN, DBMS_MSSQL...) */ - - -SQLHENV henv; /* Environment handle */ - - - - - - - -void handle_errors( SQLHDBC hdbc, SQLHSTMT hstmt, int errcode, int action, char * msg, - char * file, int line) { - - if (errcode == SQL_SUCCESS) - return; - - if(errcode == SQL_ERROR) { - int ret; - long diagCount=0; - short length=0; - SQLCHAR state[10] = ""; - SQLCHAR message[200] = ""; - long native = 0; - if(hstmt != 0) { - ret = SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, SQL_DIAG_NUMBER, &diagCount, SQL_IS_INTEGER, 0); - - for(long i = 0; i < diagCount; i++) { - ret = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, (SQLCHAR*)state, &native, (SQLCHAR*)message, 200, &length); - ndbout_c("GetDiagRec: Message : %s ", message); - } - } - } - - if(errcode != SQL_SUCCESS) { - ndbout_c("Message: %s", msg); - switch(errcode) { - case SQL_SUCCESS_WITH_INFO: - ndbout_c("SQL_SUCCESS_WITH_INFO"); - break; - case SQL_STILL_EXECUTING: - ndbout_c("SQL_STILL_EXECUTING"); - break; - case SQL_ERROR: - ndbout_c("SQL_ERROR"); - break; - case SQL_INVALID_HANDLE: - ndbout_c("SQL_INVALID_HANDLE"); - break; - default: - ndbout_c("Some other error"); - } - exit(1); - } - - -} - - - - - -/********************************************************************* - * FUNCTION: usage - * - * DESCRIPTION: This function prints a usage message describing - * the command line options of the program. - * - * PARAMETERS: char* prog full program path name - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -static void usage(char *prog) -{ - char *progname; - - /* Get the name of the program (sans path). */ - -#ifdef WIN32 - progname = strrchr(prog, '\\'); -#else - progname = strrchr(prog, '/'); -#endif - if (progname == 0) - progname = prog; - else - ++progname; - - /* Print the usage message */ - - fprintf(stderr, - "Usage:\t%s [-h] [-help] [-V] [-connStr <string>] [-v <level>]\n" - "\t\t[-xact <xacts>] [-scale <scale>] [-tabs] [-s <statfile>]\n\n" - " -h Prints this message and exits.\n" - " -help Same as -h.\n" - " -V Prints version number and exits.\n" - " -connStr <string> Specifies an ODBC connection string to replace the\n" - " default DSN for the program. The default is\n" - " \"DSN=TpcbData<version>;OverWrite=1\".\n" - " -v <level> Verbose level\n" - " 0 = errors only\n" - " 1 = results only\n" - " 2 = results and some status messages (default)\n" - " 3 = all messages\n" - " -xact <xacts> Specifies the number of transactions to be run\n" - " The default is 25000 transactions.\n" - " -scale <scale> Specifies a scale factor which determines the\n" - " number of branches (scale), tellers (scale x 10),\n" - " accounts (scale x 10000) and non-local accounts\n" - " ((scale-1) x 10000. The default scale factor is 2.\n" - " -tabs Specifies that the output be a tab-separated\n" - " format suitable for import into a spreadsheet.\n" - " Results only go to stdout; status and other\n" - " messages go to stderr.\n" - " -s <statfile> Prints individual transaction times to <statfile>.\n", - progname); -} - -/********************************************************************* - * - * FUNCTION: parse_args - * - * DESCRIPTION: This function parses the command line arguments - * passed to main(), setting the appropriate global - * variables and issuing a usage message for - * invalid arguments. - * - * PARAMETERS: int argc # of arguments from main() - * char *argv[] arguments from main() - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -parse_args(int argc, char *argv[]) -{ - int i = 1; - - *szConnStrIn = 0; - - while (i < argc) { - - if ( !strcmp(argv[i], "-h") || !strcmp(argv[i], "-help") ) { - usage(argv[0]); - app_exit(0); - } - /* - if (!strcmp(argv[i], "-V")) { - printf("%s\n", TTVERSION_STRING); - app_exit(0); - } - */ - if (strcmp(argv[i], "-s") == 0) { - if (argc < i+2 ) { - usage(argv[0]); - app_exit(1); - } - if (sscanf(argv[i+1], "%s", statFile) == 0) { - usage(argv[0]); - app_exit(1); - } - printXactTimes = 1; - i += 2; - } - else if (!strcmp(argv[i], "-connStr")) { - if (argc < i+2 ) { - usage(argv[0]); - app_exit(1); - } - strcpy(szConnStrIn, argv[i+1]); - i += 2; - continue; - } - else if (strcmp("-v", argv[i]) == 0) { - if (argc < i+2 ) { - usage(argv[0]); - app_exit(1); - } - if (sscanf(argv[i+1], "%d", &verbose) == -1 || - verbose < 0 || verbose > 3) { - fprintf(stderr, "-v flag requires an integer parameter (0-3)\n"); - usage(argv[0]); - app_exit(1); - } - i += 2; - } - else if (strcmp("-xact",argv[i]) == 0) { - if (argc < i+2 ) { - usage(argv[0]); - app_exit(1); - } - - if (sscanf(argv[i+1], "%" PTRINT_FMT, &numXacts) == -1 || numXacts < 0) { - fprintf(stderr, "-xact flag requires a non-negative integer argument\n"); - usage(argv[0]); - app_exit(1); - } - - i += 2; - } - else if (strcmp("-scale",argv[i]) == 0) { - if (argc < i+2 ) { - usage(argv[0]); - app_exit(1); - } - if (sscanf(argv[i+1], "%d", &scaleFactor) == -1 || scaleFactor < 1) { - fprintf(stderr, "-scale flag requires an integer argument >= 1\n"); - usage(argv[0]); - app_exit(1); - } - /* Calculate tuple sizes */ - numBranchTups = NumBranches * scaleFactor; - numTellerTups = TellersPerBranch * scaleFactor; - numAccountTups = AccountsPerBranch * scaleFactor; - numNonLocalAccountTups = AccountsPerBranch * (scaleFactor-1); - i += 2; - } - else if (strcmp("-tabs",argv[i]) == 0) { - tabFlag = 1; - statusfp = stderr; - i += 1; - } - else { - usage(argv[0]); - app_exit(1); - } - } -} - -/********************************************************************* - * - * FUNCTION: doImmed - * - * DESCRIPTION: This function executes and frees the specified - * statement. It is used as a direct means to - * create the tables used by this benchmark, - * - * PARAMETERS: SQLHDBC hdbc SQL Connection handle - * SQLHSTMT hs SQL Statement handle - * char* cmd SQL Statement text - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -doImmed(SQLHDBC hdbc, SQLHSTMT hs, char* cmd) -{ - SQLRETURN rc; - - /* Execute the command */ - - rc = SQLExecDirect(hs, (SQLCHAR *) cmd, SQL_NTS); - handle_errors(hdbc, hs, rc, ABORT_DISCONNECT_EXIT, - "Error executing statement", __FILE__, __LINE__); - - /* Close associated cursor and drop pending results */ - - rc = SQLFreeStmt(hs, SQL_CLOSE); - handle_errors(hdbc, hs, rc, ABORT_DISCONNECT_EXIT, - "closing statement handle", - __FILE__, __LINE__); - -} - - -/********************************************************************* - * - * FUNCTION: main - * - * DESCRIPTION: This is the main function of the tpcb benchmark. - * It connects to an ODBC data source, creates and - * populates tables, updates the tables in a user- - * specified number of transactions and reports on - * on the transaction times. - * - * PARAMETERS: int argc # of command line arguments - * char *argv[] command line arguments - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -int -main(int argc, char *argv[]) -{ - - /* variables used for setting up the tables */ - - char cmdStr[1024]; - char errstr[4096]; - - /* variables used during transactions */ - - int accountNum; - int tellerNum; - int branchNum; - int timeStamp; - double delta; - unsigned int lrand; - unsigned short *srands, localLimit; - int lp64; - - /* variables used for timing and statistics */ - - int warmup; - double kernel, user, real; - ttThreadTimes startRes, endRes; - ttWallClockTime startT, endT; - ttWallClockTime** rtStart; - ttWallClockTime** rtEnd; - double** resTime; - double maxTime, totTime; - int i; - int j; - int numLocalXacts=0, numRemoteXacts=0; - - /* variables for ODBC */ - - SQLHDBC hdbc; - SQLHSTMT hstmt; - SQLHSTMT txstmt[NumXactStmts]; - SQLRETURN rc; - char DBMSName[32]; - char DBMSVersion[32]; - int databaseSize; - - int fThreadTime = 1; - -#ifdef WIN32 - OSVERSIONINFO sysInfo; - - sysInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx (&sysInfo); - - /* GetThreadTimes is not supported on 95/98. Hence, - we do not support Resource/User/System times */ - if (sysInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) - fThreadTime = 0; -#endif -#if defined(TTCLIENTSERVER) && defined(__hpux) && !defined(__LP64__) - /* HP requires this for C main programs that call aC++ shared libs */ - _main(); -#endif /* hpux32 */ - - /* Set up default signal handlers */ - -#ifndef NDB - /* StopRequestClear(); - if (HandleSignals() != 0) { - err_msg0("Unable to set signal handlers\n"); - return 1; - } - */ -#endif - /* set IO mode for demo */ - /* set_io_mode(); */ - - /* initialize the file for status messages */ - statusfp = stdout; - - /* set variable for 8-byte longs */ - lp64 = (sizeof(lrand) == 8); - - /* set the default tuple sizes */ - - numBranchTups = NumBranches * scaleFactor; - numTellerTups = TellersPerBranch * scaleFactor; - numAccountTups = AccountsPerBranch * scaleFactor; - numNonLocalAccountTups = AccountsPerBranch * (scaleFactor-1); - - /* parse the command arguments */ - parse_args(argc, argv); - - /* allocate the transaction-based variables */ - - rtStart = (ttWallClockTime**) malloc(numXacts * sizeof(ttWallClockTime*)); - if (!rtStart) { - err_msg0("Cannot allocate the transaction timing structures"); - app_exit(1); - } - for (i = 0; i < numXacts; i++) { - rtStart[i] = (ttWallClockTime*) malloc(sizeof(ttWallClockTime)); - if (!rtStart[i]) { - err_msg0("Cannot allocate the transaction timing structures"); - app_exit(1); - } - } - - rtEnd = (ttWallClockTime**) malloc(numXacts * sizeof(ttWallClockTime*)); - if (!rtEnd) { - err_msg0("Cannot allocate the transaction timing structures"); - app_exit(1); - } - for (i = 0; i < numXacts; i++) { - rtEnd[i] = (ttWallClockTime*) malloc(sizeof(ttWallClockTime)); - if (!rtEnd[i]) { - err_msg0("Cannot allocate the transaction timing structures"); - app_exit(1); - } - } - - resTime = (double**) malloc(numXacts * sizeof(double*)); - if (!resTime) { - err_msg0("Cannot allocate the transaction timing structures"); - app_exit(1); - } - for (i = 0; i < numXacts; i++) { - resTime[i] = (double*) malloc(sizeof(double)); - if (!resTime[i]) { - err_msg0("Cannot allocate the transaction timing structures"); - app_exit(1); - } - } - - /* ODBC initialization */ - - rc = SQLAllocEnv(&henv); - if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { - /* error occurred -- don't bother calling handle_errors, since handle - * is not valid so SQLError won't work */ - err_msg3("ERROR in %s, line %d: %s\n", - __FILE__, __LINE__, "allocating an environment handle"); - app_exit(1); - } - SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER); - - /* call this in case of warning */ - handle_errors(NULL, NULL, rc, NO_EXIT, - "allocating execution environment", - __FILE__, __LINE__); - - rc = SQLAllocConnect(henv, &hdbc); - handle_errors(NULL, NULL, rc, ERROR_EXIT, - "allocating connection handle", - __FILE__, __LINE__); - - /* Connect to data store */ - - status_msg0("Connecting to the data source...\n"); - - /* Set up the connection options if not specified on the command line - * (default to TimesTen settings). - */ - - if ( !*szConnStrIn ) { - /* Running the benchmark with a scale factor creates (scale) branches, - * (scale x 10) tellers, (scale x 10000) accounts and ((scale-1) x 10000) - * non-local accounts. The size of the table rows are branches (141) - * tellers (141) and accounts (141). Therefore the data size requirements - * of this benchmark is: - * size ~= 141 * ((scale * 20011) - 10000) (bytes) - * - * Multiply data size by 20% to account for additional DB overhead (e.g. - * indexes), and round up the nearest 10Mb for safety. - */ - - int est_size = (int) (3.6 * scaleFactor + 10.0); - est_size = est_size - (est_size % 10); - - sprintf(szConnStrIn,"OverWrite=1;PermSize=%d;%s", - est_size, DSNNAME); - status_msg0("Connecting to the data source... %s \n", szConnStrIn); - } - - rc = SQLDriverConnect(hdbc, NULL, (SQLCHAR *) szConnStrIn, SQL_NTS, - NULL, 0, NULL, - SQL_DRIVER_NOPROMPT); - - status_msg0("Connected to the data source...\n"); - sprintf(errstr, "connecting to driver (connect string %s)\n", - szConnStrIn); - handle_errors(hdbc, NULL, rc, ERROR_EXIT, - errstr, __FILE__, __LINE__); - - /* Turn auto-commit off */ - - rc = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); - handle_errors(hdbc, NULL, rc, DISCONNECT_EXIT, - "switching off the AUTO_COMMIT option", - __FILE__, __LINE__); - - /* Allocate a statement handle */ - - rc = SQLAllocStmt(hdbc, &hstmt); - handle_errors(hdbc, NULL, rc, DISCONNECT_EXIT, - "allocating a statement handle", - __FILE__, __LINE__); - - /* (Implicit) Transaction begin */ - - /* Determine the DBMS Type*/ - - DBMSName[0] = '\0'; - rc = SQLGetInfo(hdbc, SQL_DBMS_NAME, (PTR) &DBMSName, - sizeof(DBMSName), NULL); - rc = SQLGetInfo(hdbc, SQL_DRIVER_VER, (PTR) &DBMSVersion, - sizeof(DBMSVersion), NULL); - - if (strcmp(DBMSName, "TimesTen") == 0) - DBMSType = DBMS_TIMESTEN; - else if (strcmp(DBMSName, "Microsoft SQL Server") == 0) - DBMSType = DBMS_MSSQL; - else DBMSType = DBMS_UNKNOWN; - - /* if not TimesTen: delete (if it exists), create & use the new database */ - - if (DBMSType != DBMS_TIMESTEN) { - status_msg0("Deleting the database...\n"); - rc = SQLExecDirect(hstmt, (SQLCHAR *) DatabaseDropStmt, SQL_NTS); - - /* estimate database size, size = data space + log space - * data space = (#tuples)/(tuples per page) * 2K bytes/page - * tuples per page = useable page size / row size (no index) = 2016/(96+2) - * log space = #transactions * average log size for the program transaction mix - * database size is in MB - */ - - databaseSize = (int) ceil((((numBranchTups + numTellerTups + numAccountTups)/ - (2016/98)) * 2048 + (numXacts * 600)) / 1000000.0); - - status_msg1("Creating the database (%dMB)...\n", databaseSize); -#ifndef NDB - sprintf(cmdStr, DatabaseCreateStmt, databaseSize); - doImmed(hdbc, hstmt, cmdStr); - strcpy(cmdStr, DatabaseUseStmt); - doImmed(hdbc, hstmt, cmdStr); -#endif - } - - status_msg2("Connected to '%s' version '%s'...\n", DBMSName, DBMSVersion); - - /* create branches table */ - status_msg0("Creating tasddbles...\n"); -#ifndef NDB - if (DBMSType == DBMS_TIMESTEN) - sprintf(cmdStr, TTBranchCrTblStmt, numBranchTups/TuplesPerPage + 1); - else -#endif - sprintf(cmdStr, BranchCrTblStmt); - doImmed(hdbc, hstmt, cmdStr); - - /* create tellers table */ -#ifndef NDB - if (DBMSType == DBMS_TIMESTEN) - sprintf(cmdStr, TTTellerCrTblStmt, numTellerTups/TuplesPerPage + 1); - - else -#endif - sprintf(cmdStr, TellerCrTblStmt); - doImmed(hdbc, hstmt, cmdStr); - - /* create accounts table */ -#ifndef NDB - if (DBMSType == DBMS_TIMESTEN) - sprintf(cmdStr, TTAccountCrTblStmt, numAccountTups/TuplesPerPage + 1); - else -#endif - sprintf(cmdStr, AccountCrTblStmt); - doImmed(hdbc, hstmt, cmdStr); - - /* create History table */ - - doImmed(hdbc, hstmt, HistoryCrTblStmt); - - /* lock the database during population */ -#ifndef NDB - if ( DBMSType == DBMS_TIMESTEN ) { - rc = SQLExecDirect(hstmt, (SQLCHAR *)"call ttlocklevel('DS')", SQL_NTS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "specifying dbs lock usage", - __FILE__, __LINE__); - /* make sure dbs lock take effect in next transaction */ - rc = SQLTransact(henv,hdbc,SQL_COMMIT); - if ( rc != SQL_SUCCESS) { - handle_errors(hdbc, SQL_NULL_HSTMT, rc, ERROR_EXIT, - "committing transaction", - __FILE__, __LINE__); - } - } -#endif - /* populate branches table */ - - - rc = SQLPrepare(hstmt, (SQLCHAR *) insStmt[0], SQL_NTS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "preparing statement", - __FILE__, __LINE__); - - rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 10, 0, &branchNum, sizeof branchNum, NULL); - - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - - status_msg1("Populating branches table (%" PTRINT_FMT " rows)...\n", - numBranchTups); - - - for (i=0; i<numBranchTups; i++) { - branchNum = i; - rc = SQLExecute(hstmt); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "Error executing statement", - __FILE__, __LINE__); - } - - /* Reset all bind-parameters for the statement handle. */ - rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "resetting parms on statement handle", - __FILE__, __LINE__); - - /* populate tellers table */ - - status_msg1("Populating tellers table (%" PTRINT_FMT " rows)...\n", - numTellerTups); - - - rc = SQLPrepare(hstmt, (SQLCHAR *) insStmt[1], SQL_NTS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "preparing statement", - __FILE__, __LINE__); - - rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, - 10, 0, &tellerNum, sizeof tellerNum, NULL); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, - 10, 0, &branchNum, sizeof branchNum, NULL); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - for (i=0; i<numTellerTups; i++) { - tellerNum = i; - branchNum = i/TellersPerBranch; - rc = SQLExecute(hstmt); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "Error executing statement", - __FILE__, __LINE__); - } - - /* Reset all bind-parameters for the statement handle. */ - - rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "resetting parms on statement handle", - __FILE__, __LINE__); - - /* populate accounts table */ - - status_msg1("Populating accounts table (%" PTRINT_FMT " rows)...\n", - numAccountTups); - - rc = SQLPrepare(hstmt, (SQLCHAR *) insStmt[2], SQL_NTS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "preparing statement", - __FILE__, __LINE__); - - rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, - 10, 0, &accountNum, sizeof accountNum, NULL); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, - 10, 0, &branchNum, sizeof branchNum, NULL); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - for (i=0; i<numAccountTups; i++) { - accountNum = i; - branchNum = i/AccountsPerBranch; - rc = SQLExecute(hstmt); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "Error executing statement", - __FILE__, __LINE__); - } - status_msg0("Commit...\n"); - rc = SQLTransact(henv, hdbc, SQL_COMMIT); - status_msg0("Commit done...\n"); - handle_errors(hdbc, NULL, rc, ERROR_EXIT, - "committing transaction", - __FILE__, __LINE__); - - /* compile SQL statements of transaction */ - - status_msg0("Compiling statements of transaction...\n"); - for (i=0; i<NumXactStmts; i++) { -#ifndef NDB - rc = SQLAllocStmt(hdbc, &txstmt[i]); - handle_errors(hdbc, NULL, rc, ABORT_DISCONNECT_EXIT, - "allocating a statement handle", - __FILE__, __LINE__); -#else - rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &txstmt[i]); - handle_errors(hdbc, NULL, rc, ABORT_DISCONNECT_EXIT, - "allocating a statement handle", - __FILE__, __LINE__); - -#endif - - rc = SQLPrepare(txstmt[i], (SQLCHAR *) tpcbXactStmt[i], SQL_NTS); - handle_errors(hdbc, txstmt[i], rc, ABORT_DISCONNECT_EXIT, - "preparing statement", - __FILE__, __LINE__); - } - - /* unuse dbs lock */ -#ifndef NDB - if ( DBMSType == DBMS_TIMESTEN ) { - rc = SQLExecDirect(hstmt, (SQLCHAR *)"call ttlocklevel('Row')", SQL_NTS); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "specifying row lock usage", - __FILE__, __LINE__); - } -#endif - - /* commit transaction */ - - rc = SQLTransact(henv, hdbc, SQL_COMMIT); - handle_errors(hdbc, NULL, rc, ERROR_EXIT, - "committing transaction", - __FILE__, __LINE__); - - - /* Initialize random seed and timers */ - - srand48(SeedVal); - localLimit = (unsigned short)((1<<16) * 0.85); - - /* Initialize parameter lists for each of the transactions */ - - rc = SQLBindParameter(txstmt[0], 1, SQL_PARAM_INPUT, SQL_C_DOUBLE, - SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL); - handle_errors(hdbc, txstmt[0], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[0], 2, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &accountNum, sizeof accountNum, - NULL); - handle_errors(hdbc, txstmt[0], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[1], 1, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &accountNum, sizeof accountNum, - NULL); - handle_errors(hdbc, txstmt[1], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[2], 1, SQL_PARAM_INPUT, SQL_C_DOUBLE, - SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL); - handle_errors(hdbc, txstmt[2], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[2], 2, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &tellerNum, sizeof tellerNum, - NULL); - handle_errors(hdbc, txstmt[2], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[3], 1, SQL_PARAM_INPUT, SQL_C_DOUBLE, - SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL); - handle_errors(hdbc, txstmt[3], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[3], 2, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &branchNum, sizeof branchNum, - NULL); - handle_errors(hdbc, txstmt[3], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[4], 1, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &tellerNum, sizeof tellerNum, - NULL); - handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[4], 2, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &branchNum, sizeof branchNum, - NULL); - handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[4], 3, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &accountNum, sizeof accountNum, - NULL); - handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[4], 4, SQL_PARAM_INPUT, SQL_C_DOUBLE, - SQL_DOUBLE, 15, 0, &delta, sizeof delta, NULL); - handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - rc = SQLBindParameter(txstmt[4], 5, SQL_PARAM_INPUT, SQL_C_SLONG, - SQL_INTEGER, 10, 0, &timeStamp, sizeof timeStamp, - NULL); - handle_errors(hdbc, txstmt[4], rc, ABORT_DISCONNECT_EXIT, - "binding parameter", - __FILE__, __LINE__); - - /* Execute transaction loop. - * Do it twice, once briefly as a warm-up. */ - - - - for (warmup = 1; warmup >= 0; warmup--) { - - int max_i = (warmup ? numXacts/10 : numXacts); - - /* Execute tpcb transaction max_i times.*/ - - if (warmup) { - status_msg1("\nWarming up with %d tpcb transactions...\n", max_i); - } - else { - status_msg1("Executing and timing %d tpcb transactions...\n", max_i); - } - - ttGetWallClockTime(&startT); - ttGetThreadTimes(&startRes); - - for (i = 0; i < max_i; i++) { - - lrand = lrand48(); - srands = (unsigned short *)(&lrand); - if (lp64) srands += 2; /* skip high half -- all zero */ - - /* randomly choose a teller */ - - tellerNum = srands[0] % numTellerTups; - - /* compute branch */ - - branchNum = (tellerNum / TellersPerBranch); - - /* randomly choose an account */ - - if (srands[1] < localLimit || numBranchTups == 1) { - - /* choose account local to selected branch */ - - accountNum = branchNum * AccountsPerBranch + - (lrand48() % AccountsPerBranch); - - ++numLocalXacts; - - } - else { - /* choose account not local to selected branch */ - - /* first select account in range [0,numNonLocalAccountTups) */ - - accountNum = lrand48() % numNonLocalAccountTups; - - /* if branch number of selected account is at least as big - * as local branch number, then increment account number - * by AccountsPerBranch to skip over local accounts - */ - - if ((accountNum/AccountsPerBranch) >= branchNum) - accountNum += AccountsPerBranch; - - ++numRemoteXacts; - } - - /* select delta amount, -999,999 to +999,999 */ - - delta = ((lrand48() % 1999999) - 999999); - - - /* begin timing the "residence time" */ - - ttGetWallClockTime(rtStart[i]); - - for ( j = 0; j < NumXactStmts - 2; j++) { - rc = SQLExecute(txstmt[j]); - handle_errors(hdbc, txstmt[j], rc, ABORT_DISCONNECT_EXIT, - "Error executing statement1", - __FILE__, __LINE__); - - /* Close the handle after the SELECT statement - * (txstmt[1]) for non TimesTen DBMS' */ - - if ((DBMSType != DBMS_TIMESTEN) && (j == 1)) { - SQLFreeStmt(txstmt[1], SQL_CLOSE); - } - - - } - - /* note that time must be taken within the */ - timeStamp = time(NULL); - - rc = SQLExecute(txstmt[NumXactStmts - 1]); - handle_errors(hdbc, txstmt[NumXactStmts - 1], rc, - ABORT_DISCONNECT_EXIT, "Error executing statement2", - __FILE__, __LINE__); - - rc = SQLTransact(henv, hdbc, SQL_COMMIT); - handle_errors(hdbc, NULL, rc, ERROR_EXIT, - "Error committing transaction", - __FILE__, __LINE__); - - ttGetWallClockTime(rtEnd[i]); - - } /* end fortransaction loop */ - - - - - ttGetThreadTimes(&endRes); - ttGetWallClockTime(&endT); - ttCalcElapsedThreadTimes(&startRes, &endRes, &kernel, &user); - ttCalcElapsedWallClockTime(&startT, &endT, &real); - - if (warmup) { - if (!tabFlag) { - if (verbose) { - if (fThreadTime) { - out_msg0(" time user system\n"); - - out_msg3("Warmup time (sec): %12.3f %12.3f %12.3f\n\n", - real/1000.0, user, kernel); - } else { - out_msg1("Warmup time (sec): %12.3f\n\n", real/1000.0); - } - } - } else { - if (verbose) { - if (fThreadTime) { - out_msg0("\ttime\tuser\tsystem\n"); - - out_msg3("Warmup time (sec):\t%12.3f\t%12.3f\t%12.3f\n", - real/1000.0, user, kernel); - } else { - out_msg1("Warmup time (sec):\t%12.3f\n", real/1000.0); - } - } - } - } - } - - status_msg0("\nExecution completed...\n"); - - /* Compute and report timing statistics */ - - maxTime = 0.0; - totTime = 0.0; - - for (i = 0; i < numXacts; i++) { - ttCalcElapsedWallClockTime(rtStart[i], rtEnd[i], resTime[i]); - totTime += *(resTime[i]); - - if (*(resTime[i]) > maxTime) maxTime = *(resTime[i]); - } - - if (!tabFlag) { - if (verbose) { - if (fThreadTime) { - out_msg0(" time user system\n"); - out_msg3("Total time (sec): %12.3f %12.3f %12.3f\n", - real/1000.0, user, kernel); - } else { - out_msg1("Total time (sec): %12.3f\n", real/1000.0); - } - } - - if (verbose) - out_msg1("\nAverage transaction time (msec):%12.3f\n", - totTime/numXacts); - if (verbose) - out_msg1("Maximum transaction time (msec):%12.3f\n", maxTime); - if (verbose) - out_msg1("\nLocal transactions: %7" PTRINT_FMT "\n", numLocalXacts); - if (verbose) - out_msg1("Remote transactions: %7" PTRINT_FMT "\n", numRemoteXacts); - - } else { - if (verbose) { - if (fThreadTime) { - out_msg0("\ttime\tuser\tsystem\n"); - out_msg3("Total time (sec):\t%12.3f\t%12.3f\t%12.3f\n", - real/1000.0, user, kernel); - } else { - out_msg1("Total time (sec):\t%12.3f\n", real/1000.0); - } - } - - if (verbose) - out_msg1("\nAverage transaction time (msec):\t%12.3f\n", - totTime/numXacts); - if (verbose) - out_msg1("Maximum transaction time (msec):\t%12.3f\n", maxTime); - if (verbose) - out_msg1("Local transactions:\t%7" PTRINT_FMT "\n", numLocalXacts); - - if (verbose) - out_msg1("Remote transactions:\t%7" PTRINT_FMT "\n", numRemoteXacts); - - - - } - - /* If the statfile option is selected, print each transaction's time */ - - if (printXactTimes) { - FILE * fp; - if ( (fp = fopen (statFile, "w")) == NULL ) { - err_msg1("Unable to open stat file %s for writing\n\n", statFile); - } else { - for (int i = 0; i < numXacts; i++) - fprintf(fp,"%6d: %12.3f\n", i, *(resTime[i])); - fclose(fp); - } - } - - /* Disconnect and return */ - - rc = SQLFreeStmt(hstmt, SQL_DROP); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "dropping the statement handle", - __FILE__, __LINE__); - - for (int i=0; i<NumXactStmts; i++) { - rc = SQLFreeStmt(txstmt[i], SQL_DROP); - handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT, - "dropping the statement handle", - __FILE__, __LINE__); - } - - if (verbose >= VERBOSE_DFLT) - status_msg0("Disconnecting from the data source...\n"); - - rc = SQLDisconnect(hdbc); - handle_errors(hdbc, NULL, rc, ERROR_EXIT, - "disconnecting", - __FILE__, __LINE__); - - rc = SQLFreeConnect(hdbc); - handle_errors(hdbc, NULL, rc, ERROR_EXIT, - "freeing connection handle", - __FILE__, __LINE__); - - rc = SQLFreeEnv(henv); - handle_errors(NULL, NULL, rc, ERROR_EXIT, - "freeing environment handle", - __FILE__, __LINE__); - - app_exit(0); - return 0; -} - - - - - -/* Emacs variable settings */ -/* Local Variables: */ -/* tab-width:8 */ -/* indent-tabs-mode:nil */ -/* c-basic-offset:2 */ -/* End: */ - - - diff --git a/ndb/test/odbc/tpcb/ttTime.c b/ndb/test/odbc/tpcb/ttTime.c deleted file mode 100644 index 8f10b0c6b91..00000000000 --- a/ndb/test/odbc/tpcb/ttTime.c +++ /dev/null @@ -1,366 +0,0 @@ -/* 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 */ - -static const volatile char cvsid[] = "$Id: ttTime.c,v 1.1 2003/09/23 12:43:46 johan Exp $"; -/* - * $Revision: 1.1 $ - * (c) Copyright 1996-2003, TimesTen, Inc. - * All rights reserved. - * - */ - - -/* Contains functions for performing elapsed-time calculations - in a portable manner */ - -#include "ttTime.h" - -#ifdef WIN32 - -#include <stdio.h> -#include <mapiutil.h> - -/*------------*/ -/* NT VERSION */ -/*------------*/ - -/********************************************************************* - * - * FUNCTION: ttGetThreadTimes - * - * DESCRIPTION: This function sets the supplied parameter's - * user and kernel time for the current thread. - * - * PARAMETERS: ttThreadTimes* timesP thread time structure - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -ttGetThreadTimes(ttThreadTimes* timesP) -{ - BOOL rc; - HANDLE curThread; - FILETIME creationTime; - FILETIME exitTime; - FILETIME kTime; - FILETIME uTime; - - memset (&kTime, 0, sizeof (FILETIME)); - memset (&uTime, 0, sizeof (FILETIME)); - - curThread = GetCurrentThread(); - rc = GetThreadTimes(curThread, - &creationTime, - &exitTime, - &kTime, - &uTime); - - timesP->kernelTime = kTime; - timesP->userTime = uTime; - -} - -/********************************************************************* - * - * FUNCTION: ttCalcElapsedThreadTimes - * - * DESCRIPTION: This function calculates the user and kernel - * time deltas. - * - * PARAMETERS: ttThreadTimes* beforeP beginning timestamp (IN) - * ttThreadTimes* afterP ending timestamp (IN) - * double* kernelDeltaP kernel time delta (OUT) - * double* userDeltaP user time delta (OUT) - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -ttCalcElapsedThreadTimes(ttThreadTimes* beforeP, - ttThreadTimes* afterP, - double* kernelDeltaP, - double* userDeltaP) -{ - static const double secPerHi = (double) 4.294967296; /* 2**32 * 10**-9 */ - FILETIME *before, *after; - - before = &beforeP->kernelTime; - after = &afterP->kernelTime; - *kernelDeltaP = (double) ((after->dwHighDateTime - before->dwHighDateTime) * secPerHi - + (after->dwLowDateTime - before->dwLowDateTime) * 100e-9); - before = &beforeP->userTime; - after = &afterP->userTime; - *userDeltaP = (double) ((after->dwHighDateTime - before->dwHighDateTime) * secPerHi - + (after->dwLowDateTime - before->dwLowDateTime) * 100e-9); -} - -/********************************************************************* - * - * FUNCTION: ttGetWallClockTime - * - * DESCRIPTION: This function gets the current wall-clock time. - * - * PARAMETERS: ttWallClockTime* timeP tms time structure (OUT) - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -ttGetWallClockTime(ttWallClockTime* timeP) -{ - LARGE_INTEGER frequency; - if ( QueryPerformanceFrequency(&frequency) ) { - QueryPerformanceCounter(&(timeP->time64)); - } - else { - _ftime(&(timeP->notSoLargeTime)); - } -} - -/********************************************************************* - * - * FUNCTION: ttCalcElapsedWallClockTime - * - * DESCRIPTION: This function calculates the elapsed wall-clock - * time in msec. - * - * PARAMETERS: ttWallClockTime* beforeP starting timestamp - * ttWallClockTime* afterP ending timestamp - * double* nmillisecondsP elapsed time (OUT) - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -ttCalcElapsedWallClockTime(ttWallClockTime* beforeP, - ttWallClockTime* afterP, - double* nmillisecondsP) -{ - LARGE_INTEGER frequency; - - if ( QueryPerformanceFrequency(&frequency) ) { - *nmillisecondsP = 1000 * ((double) (afterP->time64.QuadPart - - beforeP->time64.QuadPart)) - / frequency.QuadPart; - - } - else { - double start; - double end; - - start = (double) beforeP->notSoLargeTime.time * 1000. + - (double) beforeP->notSoLargeTime.millitm; - end = (double) afterP->notSoLargeTime.time * 1000. + - (double) afterP->notSoLargeTime.millitm; - - *nmillisecondsP = (double) (end - start); - } -} - -#elif defined (RTSYS_VXWORKS) - -/*-----------------*/ -/* VxWorks VERSION */ -/*-----------------*/ - -/* - * The TimeBase registers have a period of 60ns, i.e. - * 0.00000006 or (6e-8) seconds. - */ -#define TIMER_MSEC_PER_CYC (6e-5) - -void -ttGetWallClockTime(ttWallClockTime* timeP) -{ - vxTimeBaseGet(&timeP->sep.upper32, &timeP->sep.lower32); -} - - -void -ttCalcElapsedWallClockTime(ttWallClockTime* beforeP, - ttWallClockTime* afterP, - double* nmillisecondsP) -{ - *nmillisecondsP = (double)(afterP->val - beforeP->val) * TIMER_MSEC_PER_CYC; -} - - -#else - -/*--------------*/ -/* UNIX VERSION */ -/*--------------*/ - -#include <unistd.h> - -/********************************************************************* - * - * FUNCTION: ttGetThreadTimes - * - * DESCRIPTION: This function sets the supplied parameter's - * tms structure. - * - * PARAMETERS: ttThreadTimes* timesP tms time structure - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -#ifdef SB_P_OS_CHORUS -void ttGetThreadTimes(ttThreadTimes* timesP) -{ - KnCap actorCap; - - if (acap (agetId(), &actorCap) == -1) { - timesP->ins.tmSec = 0; - timesP->ins.tmNSec = 0; - timesP->ext.tmSec = 0; - timesP->ext.tmNSec = 0; - } - else { - (void) threadTimes (&actorCap, K_ALLACTORTHREADS, - ×P->ins, ×P->ext); - } -} -#else -void ttGetThreadTimes(ttThreadTimes* timesP) -{ - (void) times(timesP); -} -#endif - -/********************************************************************* - * - * FUNCTION: ttCalcElapsedThreadTimes - * - * DESCRIPTION: This function calculates the user and kernel - * time deltas. - * - * PARAMETERS: ttThreadTimes* beforeP beginning timestamp (IN) - * ttThreadTimes* afterP ending timestamp (IN) - * double* kernelDeltaP kernel time delta (OUT) - * double* userDeltaP user time delta (OUT) - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -#ifdef SB_P_OS_CHORUS -void -ttCalcElapsedThreadTimes(ttThreadTimes* beforeP, - ttThreadTimes* afterP, - double* kernelDeltaP, - double* userDeltaP) -{ - double kernelBefore; - double kernelAfter; - double userBefore; - double userAfter; - - kernelBefore = (beforeP->ext.tmSec) + (beforeP->ext.tmNSec / 1e9); - kernelAfter = (afterP->ext.tmSec) + (afterP->ext.tmNSec / 1e9); - *kernelDeltaP = kernelAfter - kernelBefore; - - userBefore = (beforeP->ins.tmSec) + (beforeP->ins.tmNSec / 1e9); - userAfter = (afterP->ins.tmSec) + (afterP->ins.tmNSec / 1e9); - *userDeltaP = userAfter - userBefore; - -} -#else -void -ttCalcElapsedThreadTimes(ttThreadTimes* beforeP, - ttThreadTimes* afterP, - double* kernelDeltaP, - double* userDeltaP) -{ - double ticks = (double)sysconf(_SC_CLK_TCK); - - *kernelDeltaP = (afterP->tms_stime - beforeP->tms_stime) / ticks; - *userDeltaP = (afterP->tms_utime - beforeP->tms_utime) / ticks; -} -#endif - -/********************************************************************* - * - * FUNCTION: ttGetWallClockTime - * - * DESCRIPTION: This function gets the current wall-clock time. - * - * PARAMETERS: ttWallClockTime* timeP tms time structure (OUT) - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -ttGetWallClockTime(ttWallClockTime* timeP) -{ - gettimeofday(timeP, NULL); -} - -/********************************************************************* - * - * FUNCTION: ttCalcElapsedWallClockTime - * - * DESCRIPTION: This function calculates the elapsed wall-clock - * time is msec. - * - * PARAMETERS: ttWallClockTime* beforeP starting timestamp - * ttWallClockTime* afterP ending timestamp - * double* nmillisecondsP elapsed time (OUT) - * - * RETURNS: void - * - * NOTES: NONE - * - *********************************************************************/ - -void -ttCalcElapsedWallClockTime(ttWallClockTime* beforeP, - ttWallClockTime* afterP, - double* nmillisP) -{ - *nmillisP = (afterP->tv_sec - beforeP->tv_sec)*1000.0 + - (afterP->tv_usec - beforeP->tv_usec)/1000.0; -} - -#endif - -/* Emacs variable settings */ -/* Local Variables: */ -/* tab-width:8 */ -/* indent-tabs-mode:nil */ -/* c-basic-offset:2 */ -/* End: */ diff --git a/ndb/test/odbc/tpcb/ttTime.h b/ndb/test/odbc/tpcb/ttTime.h deleted file mode 100644 index f78b71667fe..00000000000 --- a/ndb/test/odbc/tpcb/ttTime.h +++ /dev/null @@ -1,125 +0,0 @@ -/* 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 */ - -/* - * $Revision: 1.1 $ - * (c) Copyright 1996-2003, TimesTen, Inc. - * All rights reserved. - * - */ - -#ifndef __TT_TIME -#define __TT_TIME - - -#ifdef WIN32 - -#include <windows.h> -#include <sys/types.h> -#include <sys/timeb.h> - -typedef struct { - FILETIME kernelTime; - FILETIME userTime; -} ttThreadTimes; - - -typedef union { - LARGE_INTEGER time64; - struct _timeb notSoLargeTime; -} ttWallClockTime; - -#elif defined(RTSYS_VXWORKS) - -#define srand48(x) sb_srand48((x)) -#define drand48() sb_drand48() - -#ifdef SB_P_OS_VXPPC -/* For little-endian switch the lower, upper fields */ -typedef union { - struct { - unsigned int upper32; - unsigned int lower32; - } sep; - long long val; -} ttWallClockTime; - -/* - * This is a VxWorks private function to read the PPC's 64 bit Time Base - * Register. This is the assembler dump of this function. - 001126e4 7cad42e6 mftb r5, TBU - 001126e8 7ccc42e6 mftb r6, TBL - 001126ec 7ced42e6 mftb r7, TBU - 001126f0 7c053800 cmp crf0, 0, r5, r7 - 001126f4 4082fff0 bc 0x4, 0x2, vxTimeBaseGet - 001126f8 90a30000 stw r5, 0x0(r3) - 001126fc 90c40000 stw r6, 0x0(r4) - 00112700 4e800020 blr - * This is a fine grained timer with a period of 60ns. - */ -void vxTimeBaseGet(unsigned int* pUpper32, unsigned int* pLower32); -#endif /* SB_P_OS_VXPPC */ - -#elif defined(SB_P_OS_CHORUS) -#include <sys/types.h> -#include <sys/times.h> -#include <sys/time.h> - -#include <vtimer/chVtimer.h> - -struct chrTimes { - KnTimeVal ins; - KnTimeVal ext; -}; -typedef struct chrTimes ttThreadTimes; - -typedef struct timeval ttWallClockTime; - -#else -/* UNIX version */ - -#include <sys/times.h> -#include <sys/time.h> - -typedef struct tms ttThreadTimes; - -typedef struct timeval ttWallClockTime; - -#endif /* NT, VxWorks, Chorus, Unix */ - - -#ifndef RTSYS_VXWORKS -void ttGetThreadTimes(ttThreadTimes* timesP); -void ttCalcElapsedThreadTimes(ttThreadTimes* beforeP, ttThreadTimes* afterP, - double* kernelDeltaP, double* userDeltaP); -#endif /* ! VXWORKS */ -void ttGetWallClockTime(ttWallClockTime* timeP); -void ttCalcElapsedWallClockTime(ttWallClockTime* beforeP, - ttWallClockTime* afterP, - double* nmillisecondsP); - - - - - -#endif /* __TT_TIME */ - -/* Emacs variable settings */ -/* Local Variables: */ -/* tab-width:8 */ -/* indent-tabs-mode:nil */ -/* c-basic-offset:2 */ -/* End: */ diff --git a/ndb/test/run-test/Makefile.am b/ndb/test/run-test/Makefile.am index 1eac96e7ac7..c890536dcc6 100644 --- a/ndb/test/run-test/Makefile.am +++ b/ndb/test/run-test/Makefile.am @@ -11,9 +11,8 @@ test_SCRIPTS=atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \ atrt-clear-result.sh make-config.sh make-index.sh make-html-reports.sh atrt_SOURCES = main.cpp -INCLUDES_LOC = -I$(top_srcdir)/ndb/test/include -I$(top_srcdir)/ndb/src/mgmclient -LDADD_LOC = $(top_builddir)/ndb/src/mgmclient/CpcClient.o \ - $(top_builddir)/ndb/test/src/libNDBT.a \ +INCLUDES_LOC = -I$(top_srcdir)/ndb/test/include +LDADD_LOC = $(top_builddir)/ndb/test/src/libNDBT.a \ $(top_builddir)/ndb/src/libndbclient.la \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/mysys/libmysys.a \ diff --git a/ndb/test/run-test/Makefile_old b/ndb/test/run-test/Makefile_old deleted file mode 100644 index 6b4689b2dbb..00000000000 --- a/ndb/test/run-test/Makefile_old +++ /dev/null @@ -1,22 +0,0 @@ -include .defs.mk - -TYPE := util - -BIN_TARGET := atrt -BIN_TARGET_LIBS := mgmapi - -SOURCES = main.cpp -SCRIPTS = atrt-analyze-result.sh atrt-gather-result.sh atrt-setup.sh \ - atrt-clear-result.sh make-config.sh - -OBJECTS_LOC = $(call fixpath,$(NDB_TOP)/src/mgmclient/CpcClient.o) - -CFLAGS_main.cpp := -I$(call fixpath,$(NDB_TOP)/src/mgmclient) -CCFLAGS_LOC += -I$(call fixpath,$(NDB_TOP)/include/mgmapi) - -include $(NDB_TOP)/Epilogue.mk - -_bins:: - -rm -f $(SCRIPTS:%=$(NDB_TOP)/bin/%) - cp $(SCRIPTS) $(NDB_TOP)/bin - diff --git a/ndb/test/run-test/main.cpp b/ndb/test/run-test/main.cpp index 22799a9a1b2..ac7710d9546 100644 --- a/ndb/test/run-test/main.cpp +++ b/ndb/test/run-test/main.cpp @@ -459,7 +459,7 @@ setup_config(atrt_config& config){ proc.m_type = atrt_process::NDB_MGM; proc.m_proc.m_name.assfmt("%d-%s", index, "ndb_mgmd"); proc.m_proc.m_path.assign(dir).append("/libexec/ndb_mgmd"); - proc.m_proc.m_args = "--nodaemon -c initconfig.txt"; + proc.m_proc.m_args = "--nodaemon -f config.ini"; proc.m_proc.m_cwd.appfmt("%d.ndb_mgmd", index); connect_string.appfmt("host=%s:%d;", proc.m_hostname.c_str(), proc.m_ndb_mgm_port); @@ -538,15 +538,19 @@ connect_ndb_mgm(atrt_process & proc){ } BaseString tmp = proc.m_hostname; tmp.appfmt(":%d", proc.m_ndb_mgm_port); - time_t start = time(0); - const time_t max_connect_time = 30; - do { - if(ndb_mgm_connect(handle, tmp.c_str()) != -1){ - proc.m_ndb_mgm_handle = handle; - return true; - } - sleep(1); - } while(time(0) < (start + max_connect_time)); + + if (ndb_mgm_set_connectstring(handle,tmp.c_str())) + { + g_logger.critical("Unable to create parse connectstring"); + return false; + } + + if(ndb_mgm_connect(handle, 30, 1, 0) != -1) + { + proc.m_ndb_mgm_handle = handle; + return true; + } + g_logger.critical("Unable to connect to ndb mgm %s", tmp.c_str()); return false; } diff --git a/ndb/test/src/CpcClient.cpp b/ndb/test/src/CpcClient.cpp new file mode 100644 index 00000000000..d407ba65312 --- /dev/null +++ b/ndb/test/src/CpcClient.cpp @@ -0,0 +1,562 @@ +/* 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 <ndb_global.h> +#include <editline/editline.h> + +#include <netdb.h> + +#include <NdbOut.hpp> +#include <NdbTCP.h> +#include "CpcClient.hpp" + +#define CPC_CMD(name, value, desc) \ + { (name), \ + 0, \ + ParserRow_t::Cmd, \ + ParserRow_t::String, \ + ParserRow_t::Optional, \ + ParserRow_t::IgnoreMinMax, \ + 0, 0, \ + 0, \ + (desc), \ + (void *)(value) } + +#define CPC_ARG(name, type, opt, desc) \ + { (name), \ + 0, \ + ParserRow_t::Arg, \ + ParserRow_t::type, \ + ParserRow_t::opt, \ + ParserRow_t::IgnoreMinMax, \ + 0, 0, \ + 0, \ + (desc), 0 } + +#define CPC_END() \ + { 0, \ + 0, \ + ParserRow_t::Arg, \ + ParserRow_t::Int, \ + ParserRow_t::Optional, \ + ParserRow_t::IgnoreMinMax, \ + 0, 0, \ + 0, \ + 0, 0 } + +#ifdef DEBUG_PRINT_PROPERTIES +static void printprop(const Properties &p) { + Properties::Iterator iter(&p); + const char *name; + while((name = iter.next()) != NULL) { + PropertiesType t; + Uint32 val_i; + BaseString val_s; + + p.getTypeOf(name, &t); + switch(t) { + case PropertiesType_Uint32: + p.get(name, &val_i); + ndbout << name << " (Uint32): " << val_i << endl; + break; + case PropertiesType_char: + p.get(name, val_s); + ndbout << name << " (string): " << val_s << endl; + break; + default: + ndbout << "Unknown type " << t << endl; + break; + } + } +} +#endif + +void +SimpleCpcClient::cmd_stop(char *arg) { + Properties p; + Vector<Process> proc_list; + + list_processes(proc_list, p); + bool stopped = false; + + for(size_t i = 0; i < proc_list.size(); i++) { + if(strcmp(proc_list[i].m_name.c_str(), arg) == 0) { + stopped = true; + Properties reply; + stop_process(proc_list[i].m_id, reply); + + Uint32 status; + reply.get("status", &status); + if(status != 0) { + BaseString msg; + reply.get("errormessage", msg); + ndbout << "Stop failed: " << msg << endl; + } + } + } + + if(!stopped) + ndbout << "No such process" << endl; +} + +int +SimpleCpcClient::stop_process(Uint32 id, Properties& reply){ + const ParserRow_t stop_reply[] = { + CPC_CMD("stop process", NULL, ""), + CPC_ARG("status", Int, Mandatory, ""), + CPC_ARG("id", Int, Optional, ""), + CPC_ARG("errormessage", String, Optional, ""), + + CPC_END() + }; + + Properties args; + args.put("id", id); + + const Properties* ret = cpc_call("stop process", args, stop_reply); + if(ret == 0){ + reply.put("status", (Uint32)0); + reply.put("errormessage", "unknown error"); + return -1; + } + + Uint32 status = 0; + ret->get("status", &status); + reply.put("status", status); + if(status != 0) { + BaseString msg; + ret->get("errormessage", msg); + reply.put("errormessage", msg.c_str()); + } + + return status; +} + +void +SimpleCpcClient::cmd_start(char *arg) { + Properties p; + Vector<Process> proc_list; + list_processes(proc_list, p); + bool startped = false; + + for(size_t i = 0; i < proc_list.size(); i++) { + if(strcmp(proc_list[i].m_name.c_str(), arg) == 0) { + startped = true; + + Properties reply; + start_process(proc_list[i].m_id, reply); + + Uint32 status; + reply.get("status", &status); + if(status != 0) { + BaseString msg; + reply.get("errormessage", msg); + ndbout << "Start failed: " << msg << endl; + } + } + } + + if(!startped) + ndbout << "No such process" << endl; +} + +int +SimpleCpcClient::start_process(Uint32 id, Properties& reply){ + const ParserRow_t start_reply[] = { + CPC_CMD("start process", NULL, ""), + CPC_ARG("status", Int, Mandatory, ""), + CPC_ARG("id", Int, Optional, ""), + CPC_ARG("errormessage", String, Optional, ""), + + CPC_END() + }; + + Properties args; + args.put("id", id); + + const Properties* ret = cpc_call("start process", args, start_reply); + if(ret == 0){ + reply.put("status", (Uint32)0); + reply.put("errormessage", "unknown error"); + return -1; + } + + Uint32 status = 0; + ret->get("status", &status); + reply.put("status", status); + if(status != 0) { + BaseString msg; + ret->get("errormessage", msg); + reply.put("errormessage", msg.c_str()); + } + + return status; +} + +int +SimpleCpcClient::undefine_process(Uint32 id, Properties& reply){ + const ParserRow_t stop_reply[] = { + CPC_CMD("undefine process", NULL, ""), + CPC_ARG("status", Int, Mandatory, ""), + CPC_ARG("id", Int, Optional, ""), + CPC_ARG("errormessage", String, Optional, ""), + + CPC_END() + }; + + Properties args; + args.put("id", id); + + const Properties* ret = cpc_call("undefine process", args, stop_reply); + if(ret == 0){ + reply.put("status", (Uint32)0); + reply.put("errormessage", "unknown error"); + return -1; + } + + Uint32 status = 0; + ret->get("status", &status); + reply.put("status", status); + if(status != 0) { + BaseString msg; + ret->get("errormessage", msg); + reply.put("errormessage", msg.c_str()); + } + + return status; +} + +static void +printproc(SimpleCpcClient::Process & p) { + ndbout.println("Name: %s", p.m_name.c_str()); + ndbout.println("Id: %d", p.m_id); + ndbout.println("Type: %s", p.m_type.c_str()); + ndbout.println("Group: %s", p.m_group.c_str()); + ndbout.println("Program path: %s", p.m_path.c_str()); + ndbout.println("Arguments: %s", p.m_args.c_str()); + ndbout.println("Environment: %s", p.m_env.c_str()); + ndbout.println("Working directory: %s", p.m_cwd.c_str()); + ndbout.println("Owner: %s", p.m_owner.c_str()); + ndbout.println("Runas: %s", p.m_runas.c_str()); + ndbout.println("Ulimit: %s", p.m_ulimit.c_str()); + ndbout.println(""); +} + +void +SimpleCpcClient::cmd_list(char *arg) { + Properties p; + Vector<Process> proc_list; + list_processes(proc_list, p); + + for(size_t i = 0; i < proc_list.size(); i++) { + printproc(proc_list[i]); + } +} + +static int +convert(const Properties & src, SimpleCpcClient::Process & dst){ + bool b = true; + b &= src.get("id", (Uint32*)&dst.m_id); + b &= src.get("name", dst.m_name); + b &= src.get("type", dst.m_type); + b &= src.get("status", dst.m_status); + b &= src.get("owner", dst.m_owner); + b &= src.get("group", dst.m_group); + b &= src.get("path", dst.m_path); + b &= src.get("args", dst.m_args); + b &= src.get("env", dst.m_env); + b &= src.get("cwd", dst.m_cwd); + b &= src.get("runas", dst.m_runas); + + b &= src.get("stdin", dst.m_stdin); + b &= src.get("stdout", dst.m_stdout); + b &= src.get("stderr", dst.m_stderr); + b &= src.get("ulimit", dst.m_ulimit); + + return b; +} + +static int +convert(const SimpleCpcClient::Process & src, Properties & dst ){ + bool b = true; + //b &= dst.put("id", (Uint32)src.m_id); + b &= dst.put("name", src.m_name.c_str()); + b &= dst.put("type", src.m_type.c_str()); + //b &= dst.put("status", src.m_status.c_str()); + b &= dst.put("owner", src.m_owner.c_str()); + b &= dst.put("group", src.m_group.c_str()); + b &= dst.put("path", src.m_path.c_str()); + b &= dst.put("args", src.m_args.c_str()); + b &= dst.put("env", src.m_env.c_str()); + b &= dst.put("cwd", src.m_cwd.c_str()); + b &= dst.put("runas", src.m_runas.c_str()); + + b &= dst.put("stdin", src.m_stdin.c_str()); + b &= dst.put("stdout", src.m_stdout.c_str()); + b &= dst.put("stderr", src.m_stderr.c_str()); + b &= dst.put("ulimit", src.m_ulimit.c_str()); + + return b; +} + +int +SimpleCpcClient::define_process(Process & p, Properties& reply){ + const ParserRow_t define_reply[] = { + CPC_CMD("define process", NULL, ""), + CPC_ARG("status", Int, Mandatory, ""), + CPC_ARG("id", Int, Optional, ""), + CPC_ARG("errormessage", String, Optional, ""), + + CPC_END() + }; + + Properties args; + convert(p, args); + + const Properties* ret = cpc_call("define process", args, define_reply); + if(ret == 0){ + reply.put("status", (Uint32)0); + reply.put("errormessage", "unknown error"); + return -1; + } + + Uint32 status = 0; + ret->get("status", &status); + reply.put("status", status); + if(status != 0) { + BaseString msg; + ret->get("errormessage", msg); + reply.put("errormessage", msg.c_str()); + } + + Uint32 id; + if(!ret->get("id", &id)){ + return -1; + } + + p.m_id = id; + + return status; +} + +int +SimpleCpcClient::list_processes(Vector<Process> &procs, Properties& reply) { + enum Proclist { + Proclist_Start, + Proclist_End, + Proclist_Entry + }; + const ParserRow_t list_reply[] = { + CPC_CMD("start processes", Proclist_Start, ""), + + CPC_CMD("end processes", Proclist_End, ""), + + CPC_CMD("process", Proclist_Entry, ""), + CPC_ARG("id", Int, Mandatory, "Id of process."), + CPC_ARG("name", String, Mandatory, "Name of process"), + CPC_ARG("group", String, Mandatory, "Group of process"), + CPC_ARG("env", String, Mandatory, "Environment variables for process"), + CPC_ARG("path", String, Mandatory, "Path to binary"), + CPC_ARG("args", String, Mandatory, "Arguments to process"), + CPC_ARG("type", String, Mandatory, "Type of process"), + CPC_ARG("cwd", String, Mandatory, "Working directory of process"), + CPC_ARG("owner", String, Mandatory, "Owner of process"), + CPC_ARG("status",String, Mandatory, "Status of process"), + CPC_ARG("runas", String, Mandatory, "Run as user"), + CPC_ARG("stdin", String, Mandatory, "Redirect stdin"), + CPC_ARG("stdout",String, Mandatory, "Redirect stdout"), + CPC_ARG("stderr",String, Mandatory, "Redirect stderr"), + CPC_ARG("ulimit",String, Mandatory, "ulimit"), + + CPC_END() + }; + + reply.clear(); + + const Properties args; + + cpc_send("list processes", args); + + bool done = false; + while(!done) { + const Properties *proc; + enum Proclist p; + cpc_recv(list_reply, &proc, (void **)&p); + + switch(p) { + case Proclist_Start: + /* do nothing */ + break; + case Proclist_End: + done = true; + break; + case Proclist_Entry: + if(proc != NULL){ + Process p; + convert(* proc, p); + procs.push_back(p); + } + break; + default: + /* ignore */ + break; + } + } + return 0; +} + +void +SimpleCpcClient::cmd_help(char *arg) { + ndbout + << "HELP Print help text" << endl + << "LIST List processes" << endl + << "START Start process" << endl + << "STOP Stop process" << endl; +} + +SimpleCpcClient::SimpleCpcClient(const char *_host, int _port) { + host = strdup(_host); + port = _port; + cpc_sock = -1; + cpc_in = NULL; + cpc_out = NULL; +} + +SimpleCpcClient::~SimpleCpcClient() { + if(host != NULL) { + free(host); + host = NULL; + } + + port = 0; + + if(cpc_sock == -1) { + close(cpc_sock); + cpc_sock = -1; + } + + if(cpc_in != NULL) + delete cpc_in; + + if(cpc_out != NULL) + delete cpc_out; +} + +int +SimpleCpcClient::connect() { + struct sockaddr_in sa; + struct hostent *hp; + + /* Create socket */ + cpc_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if(cpc_sock < 0) + return -1; + + /* Connect socket */ + sa.sin_family = AF_INET; + hp = gethostbyname(host); + if(hp == NULL) { + errno = ENOENT; + return -1; + } + + memcpy(&sa.sin_addr, hp->h_addr, hp->h_length); + sa.sin_port = htons(port); + if (::connect(cpc_sock, (struct sockaddr*) &sa, sizeof(sa)) < 0) + return -1; + + cpc_in = new SocketInputStream(cpc_sock, 60000); + cpc_out = new SocketOutputStream(cpc_sock); + + return 0; +} + +int +SimpleCpcClient::cpc_send(const char *cmd, + const Properties &args) { + + cpc_out->println(cmd); + + Properties::Iterator iter(&args); + const char *name; + while((name = iter.next()) != NULL) { + PropertiesType t; + Uint32 val_i; + BaseString val_s; + + args.getTypeOf(name, &t); + switch(t) { + case PropertiesType_Uint32: + args.get(name, &val_i); + cpc_out->println("%s: %d", name, val_i); + break; + case PropertiesType_char: + args.get(name, val_s); + cpc_out->println("%s: %s", name, val_s.c_str()); + break; + default: + /* Silently ignore */ + break; + } + } + cpc_out->println(""); + + return 0; +} + +/** + * Receive a response from the CPCD. The argument reply will point + * to a Properties object describing the reply. Note that the caller + * is responsible for deleting the Properties object returned. + */ +SimpleCpcClient::Parser_t::ParserStatus +SimpleCpcClient::cpc_recv(const ParserRow_t *syntax, + const Properties **reply, + void **user_value) { + Parser_t::Context ctx; + ParserDummy session(cpc_sock); + Parser_t parser(syntax, *cpc_in, true, true, true); + *reply = parser.parse(ctx, session); + if(user_value != NULL) + *user_value = ctx.m_currentCmd->user_value; + return ctx.m_status; +} + +const Properties * +SimpleCpcClient::cpc_call(const char *cmd, + const Properties &args, + const ParserRow_t *reply_syntax) { + cpc_send(cmd, args); + +#if 0 + Parser_t::Context ctx; + ParserDummy session(cpc_sock); + Parser_t parser(reply_syntax, *cpc_in, true, true, true); + const Properties *ret = parser.parse(ctx, session); + return ret; +#endif + const Properties *ret; + cpc_recv(reply_syntax, &ret); + return ret; +} + + +SimpleCpcClient::ParserDummy::ParserDummy(NDB_SOCKET_TYPE sock) + : SocketServer::Session(sock) { +} + +template class Vector<SimpleCpcClient::Process>; +template class Vector<ParserRow<SimpleCpcClient::ParserDummy> const*>; diff --git a/ndb/test/src/Makefile.am b/ndb/test/src/Makefile.am index a8f34a0ea22..56f3d6a1ec6 100644 --- a/ndb/test/src/Makefile.am +++ b/ndb/test/src/Makefile.am @@ -9,7 +9,8 @@ libNDBT_a_SOURCES = \ HugoAsynchTransactions.cpp UtilTransactions.cpp \ NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \ NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp \ - NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c + NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c \ + CpcClient.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/Makefile_old b/ndb/test/src/Makefile_old deleted file mode 100644 index 2738ce1aba2..00000000000 --- a/ndb/test/src/Makefile_old +++ /dev/null @@ -1,33 +0,0 @@ -include .defs.mk - -TYPE := ndbapitest - -ARCHIVE_TARGET := NDBT - -SOURCES = NDBT_ReturnCodes.cpp \ - NDBT_Error.cpp NDBT_Tables.cpp NDBT_ResultRow.cpp \ - NDBT_Test.cpp HugoCalculator.cpp \ - HugoOperations.cpp HugoTransactions.cpp \ - HugoAsynchTransactions.cpp UtilTransactions.cpp \ - NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp \ - NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp - -SOURCES.c = - -CFLAGS_NdbRestarter.cpp := -I$(call fixpath,$(NDB_TOP)/src/common/mgmcommon) -CFLAGS_NdbConfig.cpp := -I$(call fixpath,$(NDB_TOP)/include/mgmcommon) \ - -I$(call fixpath,$(NDB_TOP)/src/mgmapi) -CFLAGS_NdbRestarts.cpp := -I$(call fixpath,$(NDB_TOP)/include/kernel) -CFLAGS_NdbBackup.cpp := -I$(call fixpath,$(NDB_TOP)/include/mgmcommon) \ - -I$(call fixpath,$(NDB_TOP)/src/mgmapi) \ - -I$(call fixpath,$(NDB_TOP)/include/kernel) -CFLAGS_NdbGrep.cpp += -I$(call fixpath,$(NDB_TOP)/include/kernel) -I$(call fixpath,$(NDB_TOP)/include/mgmcommon) - -include $(NDB_TOP)/Epilogue.mk - - - - - - - diff --git a/ndb/test/src/NdbBackup.cpp b/ndb/test/src/NdbBackup.cpp index 1ce48d495a5..398a7c32fc4 100644 --- a/ndb/test/src/NdbBackup.cpp +++ b/ndb/test/src/NdbBackup.cpp @@ -69,16 +69,14 @@ NdbBackup::getBackupDataDirForNode(int _node_id){ /** * Fetch configuration from management server */ - LocalConfig lc; - if (!lc.init(0,0)) { - abort(); - } - ConfigRetriever cr(lc, 0, NODE_TYPE_API); + ConfigRetriever cr(0, 0, NODE_TYPE_API); ndb_mgm_configuration * p = 0; BaseString tmp; tmp.assfmt("%s:%d", host.c_str(), port); NdbMgmHandle handle = ndb_mgm_create_handle(); - if(handle == 0 || ndb_mgm_connect(handle, tmp.c_str()) != 0 || + if(handle == 0 || + ndb_mgm_set_connectstring(handle,tmp.c_str()) != 0 || + ndb_mgm_connect(handle,0,0,0) != 0 || (p = ndb_mgm_get_configuration(handle, 0)) == 0){ const char * s = 0; diff --git a/ndb/test/src/NdbRestarter.cpp b/ndb/test/src/NdbRestarter.cpp index 4d6d3ddc001..e1802f36e82 100644 --- a/ndb/test/src/NdbRestarter.cpp +++ b/ndb/test/src/NdbRestarter.cpp @@ -18,7 +18,6 @@ #include <NdbOut.hpp> #include <NdbSleep.h> #include <NdbTick.h> -#include <LocalConfig.hpp> #include <mgmapi_debug.h> #include <NDBT_Output.hpp> #include <random.h> @@ -38,37 +37,7 @@ NdbRestarter::NdbRestarter(const char* _addr): m_config(0) { if (_addr == NULL){ - LocalConfig lcfg; - if(!lcfg.init()){ - lcfg.printError(); - lcfg.printUsage(); - g_err << "NdbRestarter - Error parsing local config file" << endl; - return; - } - - if (lcfg.ids.size() == 0){ - g_err << "NdbRestarter - No management servers configured in local config file" << endl; - return; - } - - for (int i = 0; i<lcfg.ids.size(); i++){ - MgmtSrvrId * m = &lcfg.ids[i]; - - switch(m->type){ - case MgmId_TCP: - char buf[255]; - snprintf(buf, 255, "%s:%d", m->name.c_str(), m->port); - addr.assign(buf); - host.assign(m->name.c_str()); - port = m->port; - return; - break; - case MgmId_File: - break; - default: - break; - } - } + addr.assign(""); } else { addr.assign(_addr); } @@ -397,7 +366,15 @@ NdbRestarter::connect(){ return -1; } g_info << "Connecting to mgmsrv at " << addr.c_str() << endl; - if (ndb_mgm_connect(handle, addr.c_str()) == -1) { + if (ndb_mgm_set_connectstring(handle,addr.c_str())) + { + MGMERR(handle); + g_err << "Connection to " << addr.c_str() << " failed" << endl; + return -1; + } + + if (ndb_mgm_connect(handle, 0, 0, 0) == -1) + { MGMERR(handle); g_err << "Connection to " << addr.c_str() << " failed" << endl; return -1; diff --git a/ndb/test/tools/Makefile.am b/ndb/test/tools/Makefile.am index 8d94c21b721..3255267b636 100644 --- a/ndb/test/tools/Makefile.am +++ b/ndb/test/tools/Makefile.am @@ -20,12 +20,10 @@ copy_tab_SOURCES = copy_tab.cpp create_index_SOURCES = create_index.cpp ndb_cpcc_SOURCES = cpcc.cpp -INCLUDES_LOC = -I$(top_srcdir)/ndb/src/mgmclient - include $(top_srcdir)/ndb/config/common.mk.am include $(top_srcdir)/ndb/config/type_ndbapitest.mk.am -ndb_cpcc_LDADD = $(LDADD) $(top_builddir)/ndb/src/mgmclient/CpcClient.o +ndb_cpcc_LDADD = $(LDADD) # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/ndb/test/tools/Makefile_old b/ndb/test/tools/Makefile_old deleted file mode 100644 index b8e90ae207f..00000000000 --- a/ndb/test/tools/Makefile_old +++ /dev/null @@ -1,9 +0,0 @@ -include .defs.mk - -DIRS := hugoCalculator hugoFill hugoLoad hugoLockRecords \ - hugoPkDelete hugoPkRead hugoPkReadRecord hugoPkUpdate \ - hugoScanRead hugoScanUpdate restart waiter - -include $(NDB_TOP)/Epilogue.mk - -_bins_ndbapi : _libs_src diff --git a/ndb/test/tools/old_dirs/waiter/Makefile_old b/ndb/test/tools/old_dirs/waiter/Makefile_old deleted file mode 100644 index da2c9daff00..00000000000 --- a/ndb/test/tools/old_dirs/waiter/Makefile_old +++ /dev/null @@ -1,11 +0,0 @@ -include .defs.mk - -TYPE := ndbapitest - -BIN_TARGET := waiter - -# Source files of non-templated classes (.C files) -SOURCES = waiter.cpp - -include $(NDB_TOP)/Epilogue.mk - |