#At file:///Users/mz/mysql/ndb-7.1-opt64/ based on revid:martin.zaun@stripped
3862 Martin Zaun 2010-10-07
crund - added c++/ndbapi TWS benchmark.
added:
storage/ndb/test/crund/tws/
storage/ndb/test/crund/tws/run.properties.sample
storage/ndb/test/crund/tws/tws_cpp/
storage/ndb/test/crund/tws/tws_cpp/README.txt
storage/ndb/test/crund/tws/tws_cpp/TwsDriver.cpp
modified:
.bzrignore
storage/ndb/test/crund/Makefile.defaults
storage/ndb/test/crund/martins_little_helpers/src/utils/Properties.hpp
storage/ndb/test/crund/src/com/mysql/cluster/crund/CrundDriver.java
storage/ndb/test/crund/src/com/mysql/cluster/crund/NdbBase.java
storage/ndb/test/crund/src/crundndb/CrundDriver.cpp
storage/ndb/test/crund/src/crundndb/CrundNdbApiOperations.cpp
storage/ndb/test/crund/src/crundndb/Driver.cpp
storage/ndb/test/crund/src/crundndb/Driver.hpp
storage/ndb/test/crund/src/crundndb/NdbApiDriver.cpp
storage/ndb/test/crund/tws_benchmark/schema.sql
storage/ndb/test/crund/tws_benchmark/src/Main.java
=== modified file '.bzrignore'
--- a/.bzrignore 2010-10-05 08:48:30 +0000
+++ b/.bzrignore 2010-10-08 04:22:28 +0000
@@ -3138,6 +3138,8 @@ storage/ndb/test/crund/tws_benchmark/bui
storage/ndb/test/crund/tws_benchmark/nbproject/configs/
storage/ndb/test/crund/tws_benchmark/nbproject/private/
storage/ndb/test/crund/tws_benchmark/run.properties
+storage/ndb/test/crund/tws/*.properties
+storage/ndb/test/crund/tws/tws_cpp/TwsDriver
libmysqld/examples/mysqltest.cc
libmysqld/debug_sync.cc
=== modified file 'storage/ndb/test/crund/Makefile.defaults'
--- a/storage/ndb/test/crund/Makefile.defaults 2010-09-29 10:02:15 +0000
+++ b/storage/ndb/test/crund/Makefile.defaults 2010-10-08 04:22:28 +0000
@@ -146,6 +146,8 @@
.PHONY: dep depend dbg opt prf clean mostlyclean distclean check
+help:
+
dep depend:
@set -e; \
rm -f .depend .depend$$$$ ; touch _dummy.c _dummy.cc _dummy.cpp; \
=== modified file 'storage/ndb/test/crund/martins_little_helpers/src/utils/Properties.hpp'
--- a/storage/ndb/test/crund/martins_little_helpers/src/utils/Properties.hpp 2010-10-06 06:15:04 +0000
+++ b/storage/ndb/test/crund/martins_little_helpers/src/utils/Properties.hpp 2010-10-08 04:22:28 +0000
@@ -23,8 +23,11 @@ using std::map;
using std::wstring;
using std::ios_base;
using std::istream;
+//using std::wistream;
using std::ostream;
+//using std::wostream;
using std::streambuf;
+//using std::wstreambuf;
/**
* The Properties class is a specialized map container that stores
@@ -66,22 +69,22 @@ class Properties : public map<wstring, w
{
public:
/**
- * Reads properties from the file and adds them to this
+ * Reads properties from the character file and adds them to this
* property table.
*/
void load(const char* filename)
throw (ios_base::failure);
/**
- * Reads properties from the input stream and adds them to this
- * property table.
+ * Reads properties from the character input stream and adds them
+ * to this property table.
*/
void load(istream& is)
throw (ios_base::failure);
/**
- * Reads properties from the input byte buffer and adds them to this
- * property table.
+ * Reads properties from the character buffer and adds them
+ * to this property table.
*
* The line-oriented format is the same as used by Java Properties.
* The byte stream is read under the ISO 8859-1 character encoding,
@@ -92,19 +95,39 @@ public:
throw (ios_base::failure);
/**
- * Writes this property table to the file.
+ * Reads properties from the wide character input stream and adds them
+ * to this property table.
+ */
+ // not implemented yet
+ //void load(wistream& is)
+ // throw (ios_base::failure);
+
+ /**
+ * Reads properties from the wide character buffer and adds them
+ * to this property table.
+ *
+ * The byte stream is read under the UTF-32/UCS-4 character encoding,
+ * and characters of the key and value strings are not parsed as an
+ * escape sequence.
+ */
+ // not implemented yet
+ //void load(wstreambuf& ib)
+ // throw (ios_base::failure);
+
+ /**
+ * Writes this property table to the character file.
*/
void store(const char* filename, const wstring* header = NULL) const
throw (ios_base::failure);
/**
- * Writes this property table to the output stream.
+ * Writes this property table to the character output stream.
*/
void store(ostream& os, const wstring* header = NULL) const
throw (ios_base::failure);
/**
- * Writes this property table to the output byte buffer.
+ * Writes this property table to the character buffer.
*
* The format is suitable for reading the properties using the load
* function. The stream is written using the ISO 8859-1 character
@@ -118,6 +141,29 @@ public:
void store(streambuf& ob, const wstring* header = NULL) const
throw (ios_base::failure);
+ /**
+ * Writes this property table to the wide character output stream.
+ */
+ // not implemented yet
+ //void store(wostream& os, const wstring* header = NULL) const
+ // throw (ios_base::failure);
+
+ /**
+ * Writes this property table to the wide character buffer.
+ *
+ * The format is suitable for reading the properties using the load
+ * function. The stream is written using the UTF-32/UCS-4 character
+ * encoding, and characters of the key and value strings are not
+ * rendered as an escape sequence.
+ *
+ * If the header argument is not null, then an ASCII # character, the
+ * header string, and a line separator are first written to the output
+ * stream. Thus, the header can serve as an identifying comment.
+ */
+ // not implemented yet
+ //void store(wstreambuf& ob, const wstring* header = NULL) const
+ // throw (ios_base::failure);
+
protected:
static bool isWS(int c);
static bool isNL(int c);
@@ -146,6 +192,16 @@ operator>>(istream& s, Properties& p)
return s;
}
+/*
+// not implemented yet
+inline wistream&
+operator>>(wistream& s, Properties& p)
+{
+ p.load(s);
+ return s;
+}
+*/
+
inline ostream&
operator<<(ostream& s, const Properties& p)
{
@@ -153,6 +209,17 @@ operator<<(ostream& s, const Properties&
return s;
}
+/*
+// not implemented yet
+inline wostream&
+operator<<(wostream& s, const Properties& p)
+{
+ p.store(s);
+ return s;
+}
+*/
+
+
// ---------------------------------------------------------------------------
// Properties Implementation
// ---------------------------------------------------------------------------
=== modified file 'storage/ndb/test/crund/src/com/mysql/cluster/crund/CrundDriver.java'
--- a/storage/ndb/test/crund/src/com/mysql/cluster/crund/CrundDriver.java 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/com/mysql/cluster/crund/CrundDriver.java 2010-10-08 04:22:28 +0000
@@ -275,10 +275,6 @@ abstract public class CrundDriver extend
}
runOp(op, countA, countB);
}
- if (logHeader) {
- if (logSumOfOps)
- header.append("\ttotal");
- }
if (logSumOfOps) {
out.println();
@@ -295,7 +291,12 @@ abstract public class CrundDriver extend
}
// log buffers
- logHeader = false;
+ if (logHeader) {
+ if (logSumOfOps) {
+ header.append("\ttotal");
+ }
+ logHeader = false;
+ }
if (logRealTime) {
rtimes.append(endl);
if (logSumOfOps) {
=== modified file 'storage/ndb/test/crund/src/com/mysql/cluster/crund/NdbBase.java'
--- a/storage/ndb/test/crund/src/com/mysql/cluster/crund/NdbBase.java 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/com/mysql/cluster/crund/NdbBase.java 2010-10-08 04:22:28 +0000
@@ -47,11 +47,11 @@ abstract public class NdbBase extends Cr
assert mgmdConnect != null;
// the database
- catalog = props.getProperty("ndb.catalog", "");
+ catalog = props.getProperty("ndb.catalog", "crunddb");
assert catalog != null;
// the schema
- schema = props.getProperty("ndb.schema", "");
+ schema = props.getProperty("ndb.schema", "def");
assert schema != null;
if (msg.length() == 0) {
=== modified file 'storage/ndb/test/crund/src/crundndb/CrundDriver.cpp'
--- a/storage/ndb/test/crund/src/crundndb/CrundDriver.cpp 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/crundndb/CrundDriver.cpp 2010-10-08 04:22:28 +0000
@@ -245,10 +245,6 @@ CrundDriver::runOperations(int countA, i
//}
runOp(**i, countA, countB);
}
- if (logHeader) {
- if (logSumOfOps)
- header << "\ttotal";
- }
if (logSumOfOps) {
cout << endl
@@ -264,7 +260,12 @@ CrundDriver::runOperations(int countA, i
}
// log buffers
- logHeader = false;
+ if (logHeader) {
+ if (logSumOfOps) {
+ header << "\ttotal";
+ }
+ logHeader = false;
+ }
if (logRealTime) {
if (logSumOfOps) {
rtimes << "\t" << rta;
=== modified file 'storage/ndb/test/crund/src/crundndb/CrundNdbApiOperations.cpp'
--- a/storage/ndb/test/crund/src/crundndb/CrundNdbApiOperations.cpp 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/crundndb/CrundNdbApiOperations.cpp 2010-10-08 04:22:28 +0000
@@ -257,6 +257,8 @@ CrundNdbApiOperations::closeConnection()
void
CrundNdbApiOperations::beginTransaction()
{
+ assert(tx == NULL);
+
// start a transaction
// must be closed with Ndb::closeTransaction or NdbTransaction::close
if ((tx = ndb->startTransaction()) == NULL)
@@ -266,6 +268,8 @@ CrundNdbApiOperations::beginTransaction(
void
CrundNdbApiOperations::executeOperations()
{
+ assert(tx != NULL);
+
// execute but don't commit the current transaction
if (tx->execute(NdbTransaction::NoCommit) != 0
|| tx->getNdbError().status != NdbError::Success)
@@ -275,6 +279,8 @@ CrundNdbApiOperations::executeOperations
void
CrundNdbApiOperations::commitTransaction()
{
+ assert(tx != NULL);
+
// commit the current transaction
if (tx->execute(NdbTransaction::Commit) != 0
|| tx->getNdbError().status != NdbError::Success)
@@ -284,6 +290,8 @@ CrundNdbApiOperations::commitTransaction
void
CrundNdbApiOperations::rollbackTransaction()
{
+ assert(tx != NULL);
+
// abort the current transaction
if (tx->execute(NdbTransaction::Rollback) != 0
|| tx->getNdbError().status != NdbError::Success)
@@ -293,6 +301,8 @@ CrundNdbApiOperations::rollbackTransacti
void
CrundNdbApiOperations::closeTransaction()
{
+ assert(tx != NULL);
+
// close the current transaction
// to be called irrespectively of success or failure
ndb->closeTransaction(tx);
@@ -501,7 +511,7 @@ CrundNdbApiOperations::setByPK(const Ndb
{
beginTransaction();
for (int i = from; i <= to; i++) {
- // get an insert operation for the table
+ // get an update operation for the table
NdbOperation* op = tx->getNdbOperation(table);
if (op == NULL)
ABORT_NDB_ERROR(tx->getNdbError());
@@ -722,7 +732,7 @@ CrundNdbApiOperations::setVar(const NdbD
beginTransaction();
for (int i = from; i <= to; i++) {
- // get an insert operation for the table
+ // get an update operation for the table
NdbOperation* op = tx->getNdbOperation(table);
if (op == NULL)
ABORT_NDB_ERROR(tx->getNdbError());
=== modified file 'storage/ndb/test/crund/src/crundndb/Driver.cpp'
--- a/storage/ndb/test/crund/src/crundndb/Driver.cpp 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/crundndb/Driver.cpp 2010-10-08 04:22:28 +0000
@@ -105,8 +105,8 @@ Driver::parseArguments(int argc, const c
logFileName += dest;
logFileName += ".txt";
- //cout << "logFileName='" << logFileName << "'" << endl;
}
+ //cout << "logFileName='" << logFileName << "'" << endl;
}
// ----------------------------------------------------------------------
@@ -182,7 +182,6 @@ Driver::loadProperties() {
i != propFileNames.end(); ++i) {
cout << "reading properties file: " << *i << endl;
props.load(i->c_str());
- props.load(i->c_str());
//wcout << props << endl;
}
}
=== modified file 'storage/ndb/test/crund/src/crundndb/Driver.hpp'
--- a/storage/ndb/test/crund/src/crundndb/Driver.hpp 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/crundndb/Driver.hpp 2010-10-08 04:22:28 +0000
@@ -51,6 +51,11 @@ public:
Driver() {}
/**
+ * Deletes an instance.
+ */
+ virtual ~Driver() {}
+
+ /**
* Runs the benchmark.
*/
void run();
=== modified file 'storage/ndb/test/crund/src/crundndb/NdbApiDriver.cpp'
--- a/storage/ndb/test/crund/src/crundndb/NdbApiDriver.cpp 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/src/crundndb/NdbApiDriver.cpp 2010-10-08 04:22:28 +0000
@@ -104,9 +104,20 @@ NdbApiDriver::initProperties() {
ostringstream msg;
mgmdConnect = toString(props[L"ndb.mgmdConnect"]);
+ if (mgmdConnect.empty()) {
+ mgmdConnect = string("localhost");
+ }
+
catalog = toString(props[L"ndb.catalog"]);
- schema = toString(props[L"ndb.schema"]);
+ if (catalog.empty()) {
+ catalog = string("crunddb");
+ }
+ schema = toString(props[L"ndb.schema"]);
+ if (schema.empty()) {
+ schema = string("def");
+ }
+
if (msg.tellp() == 0) {
cout << " [ok]" << endl;
} else {
@@ -133,15 +144,7 @@ NdbApiDriver::printProperties() {
cout.flags(f);
}
-void
-NdbApiDriver::initConnection() {
- ops->initConnection(catalog.c_str(), schema.c_str());
-}
-
-void
-NdbApiDriver::closeConnection() {
- ops->closeConnection();
-}
+//---------------------------------------------------------------------------
void
NdbApiDriver::initOperations() {
@@ -377,6 +380,18 @@ NdbApiDriver::closeOperations() {
cout << " [ok]" << endl;
}
+//---------------------------------------------------------------------------
+
+void
+NdbApiDriver::initConnection() {
+ ops->initConnection(catalog.c_str(), schema.c_str());
+}
+
+void
+NdbApiDriver::closeConnection() {
+ ops->closeConnection();
+}
+
void
NdbApiDriver::clearPersistenceContext() {
// XXX not implemented yet
=== added directory 'storage/ndb/test/crund/tws'
=== added file 'storage/ndb/test/crund/tws/run.properties.sample'
--- a/storage/ndb/test/crund/tws/run.properties.sample 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/test/crund/tws/run.properties.sample 2010-10-08 04:22:28 +0000
@@ -0,0 +1,76 @@
+# benchmark settings
+doJdbc=true
+doClusterj=true
+doNdbjtie=true
+doInsert=true
+doLookup=true
+doUpdate=true
+doDelete=true
+doSingle=true
+doBulk=true
+doBatch=true
+
+# lock mode for lookup and read scans
+lockMode=READ_COMMITTED
+#lockMode=SHARED
+#lockMode=EXCLUSIVE,
+
+# nRows >= 40000
+# jdbc bulk: 1217 'Out of operation records in local data manager
+# (increase MaxNoOfLocalOperations)' from NDBCLUSTER
+#
+# nRows >= 500
+# "Job buffer congestion" crashes with node failure with unique indexes
+# http://bugs.mysql.com/bug.php?id=56552
+# ndbjtie batch: ndb-7.1.8 revno 3782 crashes with node failure during
+# clusterj single/bulk: ndb-7.1.8 revno 3782 crashes with node failure during
+#nRows=16000
+#nRows=4000
+nRows=1000
+#nRows=500
+#nRows=250
+#nRows=10
+
+#warmupRuns=1000
+#warmupRuns=100
+#warmupRuns=10
+#warmupRuns=1
+warmupRuns=0
+
+#hotRuns=10000
+#hotRuns=1000
+#hotRuns=100
+#hotRuns=10
+hotRuns=1
+
+# NDBAPI connection settings
+ndb.mgmdConnect=localhost
+ndb.catalog=testdb
+ndb.schema=def
+
+# JDBC - MySQL settings
+jdbc.url=jdbc:mysql://localhost/testdb
+jdbc.driver=com.mysql.jdbc.Driver
+jdbc.user=root
+jdbc.password=
+
+# ClusterJ settings
+com.mysql.clusterj.connectstring=localhost:1186
+com.mysql.clusterj.database=testdb
+com.mysql.clusterj.connect.retries=4
+com.mysql.clusterj.connect.delay=5
+com.mysql.clusterj.connect.verbose=1
+com.mysql.clusterj.connect.timeout.before=30
+com.mysql.clusterj.connect.timeout.after=20
+com.mysql.clusterj.max.transactions=1024
+
+com.mysql.clusterj.bindings.level=INFO
+com.mysql.clusterj.core.level=INFO
+com.mysql.clusterj.core.metadata.level=INFO
+com.mysql.clusterj.core.query.level=INFO
+com.mysql.clusterj.core.util.level=INFO
+com.mysql.clusterj.tie.level=INFO
+#handlers=java.util.logging.FileHandler
+#java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
+#java.util.logging.FileHandler.level=FINEST
+#java.util.logging.FileHandler.pattern=./target/log%u
\ No newline at end of file
=== added directory 'storage/ndb/test/crund/tws/tws_cpp'
=== added file 'storage/ndb/test/crund/tws/tws_cpp/README.txt'
--- a/storage/ndb/test/crund/tws/tws_cpp/README.txt 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/test/crund/tws/tws_cpp/README.txt 2010-10-08 04:22:28 +0000
@@ -0,0 +1,52 @@
+
+How to Build and Run the NDB API TWS Benchmark
+----------------------------------------------
+
+This benchmark is built with
+-> Gnu 'make' (using generic, hand-coded Makefiles)
+-> Gnu g++ (or Solaris Studio CC as compilers)
+
+0) Configure external dependencies
+
+ Edit the file
+ ../../env.properties
+
+ and configure these five properties (shared with CRUND):
+
+ MYSQL_HOME=${HOME}/mysql/bin-7.1-opt32
+ TARGET_ARCH=-m32
+
+ NDB_INCLUDEOPT0=-I${MYSQL_HOME}/include/mysql/storage/ndb
+ NDB_INCLUDEOPT1=-I${MYSQL_HOME}/include/mysql/storage/ndb/ndbapi
+ NDB_LIBDIR=${MYSQL_HOME}/lib/mysql
+
+ Important: TARGET_ARCH must match the MYSQL_HOME binaries.
+
+1) Build the binary
+
+ Run once to build the include dependencies:
+ $ make dep
+
+ Build either a Release or Debug binary:
+ $ make opt
+ $ make dbg
+
+ For a list of available targets:
+ $ make help
+
+2) Run the benchmark
+
+ Edit the benchmark's settings (copy from ../run.properties.sample)
+ ../run.properties
+
+ Have a running NDB Cluster with loaded schema file: ../schema.sql.
+
+ Run the benchmark:
+ $ make run.driver
+ or
+ $ ./TwsDriver -p ../run.properties
+
+ The benchmark's result data is written to a generated log_XXX file.
+
+Comments or questions appreciated.
+martin.zaun@stripped
=== added file 'storage/ndb/test/crund/tws/tws_cpp/TwsDriver.cpp'
--- a/storage/ndb/test/crund/tws/tws_cpp/TwsDriver.cpp 1970-01-01 00:00:00 +0000
+++ b/storage/ndb/test/crund/tws/tws_cpp/TwsDriver.cpp 2010-10-08 04:22:28 +0000
@@ -0,0 +1,1611 @@
+/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=4:tabstop=4:smarttab:
+ *
+ * Copyright (C) 2010 MySQL
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <cstdlib>
+#include <iostream>
+#include <sstream>
+#include <fstream>
+#include <string>
+#include <vector>
+#include <cassert>
+#include <algorithm>
+#include <cctype>
+
+#include <sys/time.h>
+
+#include <NdbApi.hpp>
+#include <NdbError.hpp>
+
+#include "helpers.hpp"
+#include "string_helpers.hpp"
+#include "Properties.hpp"
+
+using std::cout;
+using std::flush;
+using std::endl;
+using std::ios_base;
+using std::string;
+using std::wstring;
+using std::vector;
+using std::ofstream;
+using std::ostringstream;
+
+using utils::Properties;
+using utils::toBool;
+using utils::toInt;
+using utils::toString;
+
+// ---------------------------------------------------------------------------
+
+class Driver {
+public:
+
+ /**
+ * Parses the benchmark's command-line arguments.
+ */
+ static void parseArguments(int argc, const char* argv[]);
+
+ /**
+ * Creates an instance.
+ */
+ Driver() {}
+
+ /**
+ * Deletes an instance.
+ */
+ virtual ~Driver() {}
+
+ /**
+ * Runs the benchmark.
+ */
+ void run();
+
+protected:
+
+ // command-line arguments
+ static vector< string > propFileNames;
+ static string logFileName;
+
+ static void exitUsage();
+
+ // driver settings
+ Properties props;
+ bool renewConnection;
+ int warmupRuns;
+ int hotRuns;
+
+ // driver resources
+ ofstream log;
+ string descr;
+ bool logHeader;
+ ostringstream header;
+ ostringstream rtimes;
+ struct timeval t0, t1;
+ long rta;
+
+ // driver intializers/finalizers
+ virtual void init();
+ virtual void close();
+ virtual void loadProperties();
+ virtual void initProperties();
+ virtual void printProperties();
+ virtual void openLogFile();
+ virtual void closeLogFile();
+
+ // benchmark operations
+ virtual void runTests() = 0;
+ virtual void begin(const string& name);
+ virtual void commit(const string& name);
+
+ // datastore operations
+ virtual void initConnection() = 0;
+ virtual void closeConnection() = 0;
+ //virtual void clearPersistenceContext() = 0; // not used
+ //virtual void clearData() = 0; // not used
+};
+
+// ---------------------------------------------------------------------------
+
+class TwsDriver : public Driver {
+protected:
+
+ // benchmark settings
+ enum LockMode { READ_COMMITTED, SHARED, EXCLUSIVE };
+ static const char* toStr(LockMode mode);
+ enum XMode { SINGLE, BULK, BATCH };
+ static const char* toStr(XMode mode);
+ bool doInsert;
+ bool doLookup;
+ bool doUpdate;
+ bool doDelete;
+ bool doSingle;
+ bool doBulk;
+ bool doBatch;
+ bool doVerify;
+ LockMode lockMode;
+ int nRows;
+
+ // benchmark intializers/finalizers
+ virtual void initProperties();
+ virtual void printProperties();
+
+ // benchmark operations
+ virtual void runTests();
+ virtual void runLoads();
+ virtual void runOperations() = 0;
+ void verify(Int32 exp, Int32 act);
+ void verify(const char* exp, const char* act);
+};
+
+// ---------------------------------------------------------------------------
+
+struct NdbApiTwsModel {
+ const NdbDictionary::Table* table_t0;
+ const NdbDictionary::Column* column_c0;
+ const NdbDictionary::Column* column_c1;
+ const NdbDictionary::Column* column_c2;
+ const NdbDictionary::Column* column_c3;
+ const NdbDictionary::Column* column_c4;
+ const NdbDictionary::Column* column_c5;
+ const NdbDictionary::Column* column_c6;
+ const NdbDictionary::Column* column_c7;
+ const NdbDictionary::Column* column_c8;
+ const NdbDictionary::Column* column_c9;
+ const NdbDictionary::Column* column_c10;
+ const NdbDictionary::Column* column_c11;
+ const NdbDictionary::Column* column_c12;
+ const NdbDictionary::Column* column_c13;
+ const NdbDictionary::Column* column_c14;
+
+ int attr_c0;
+ int attr_c1;
+ int attr_c2;
+ int attr_c3;
+ int attr_c4;
+ int attr_c5;
+ int attr_c6;
+ int attr_c7;
+ int attr_c8;
+ int attr_c9;
+ int attr_c10;
+ int attr_c11;
+ int attr_c12;
+ int attr_c13;
+ int attr_c14;
+
+ int width_c0;
+ int width_c1;
+ int width_c2;
+ int width_c3;
+ int width_c4;
+ int width_c5;
+ int width_c6;
+ int width_c7;
+ int width_c8;
+ int width_c9;
+ int width_c10;
+ int width_c11;
+ int width_c12;
+ int width_c13;
+ int width_c14;
+ int width_row; // sum of {width_c0 .. width_c14}
+ static const int nCols = 15;
+
+ NdbApiTwsModel(Ndb* ndb);
+
+ ~NdbApiTwsModel() {}
+
+ static int columnWidth(const NdbDictionary::Column* c) {
+ int s = c->getSize(); // size of type or of base type
+ int al = c->getLength(); // length or max length, 1 for scalars
+ int at = c->getArrayType(); // size of length prefix, practically
+ return (s * al) + at;
+ }
+
+private:
+
+ NdbApiTwsModel(const NdbApiTwsModel&);
+ NdbApiTwsModel& operator=(const NdbApiTwsModel&);
+};
+
+class NdbApiTwsDriver : public TwsDriver {
+public:
+
+ NdbApiTwsDriver()
+ : mgmd(NULL), ndb(NULL), tx(NULL), model(NULL), bb(NULL), ra(NULL) {
+ }
+
+ ~NdbApiTwsDriver() {
+ assert(mgmd == NULL); assert(ndb == NULL); assert(tx == NULL);
+ assert(model == NULL); assert(bb == NULL); assert(ra == NULL);
+ }
+
+private:
+
+ NdbApiTwsDriver(const NdbApiTwsDriver&);
+ NdbApiTwsDriver& operator=(const NdbApiTwsDriver&);
+
+protected:
+
+ // NDB API settings
+ string mgmdConnect;
+ string catalog;
+ string schema;
+
+ // NDB API resources
+ Ndb_cluster_connection* mgmd;
+ Ndb* ndb;
+ NdbTransaction* tx;
+ NdbOperation::LockMode ndbOpLockMode;
+
+ // NDB Api metadata resources
+ NdbApiTwsModel* model;
+
+ // NDB Api data resources
+ char* bb;
+ char* bb_pos;
+ NdbRecAttr** ra;
+ NdbRecAttr** ra_pos;
+
+ // NDB API intializers/finalizers
+ virtual void initProperties();
+ virtual void printProperties();
+ virtual void init();
+ virtual void close();
+ void initNdbapiBuffers();
+ void closeNdbapiBuffers();
+
+ // NDB API operations
+ virtual void runOperations();
+ void runNdbapiInsert(XMode mode);
+ void ndbapiInsert(int c0);
+ void runNdbapiLookup(XMode mode);
+ void ndbapiLookup(int c0);
+ void ndbapiRead(int c0);
+ void runNdbapiUpdate(XMode mode);
+ void ndbapiUpdate(int c0);
+ void runNdbapiDelete(XMode mode);
+ void ndbapiDelete(int c0);
+ void ndbapiBeginTransaction();
+ void ndbapiExecuteTransaction();
+ void ndbapiCommitTransaction();
+ void ndbapiRollbackTransaction();
+ void ndbapiCloseTransaction();
+ static void ndbapiToBuffer1blp(void* to, const char* from, size_t width);
+ static void ndbapiToString1blp(char* to, const void* from, size_t width);
+
+ // NDB API datastore operations
+ virtual void initConnection();
+ virtual void closeConnection();
+ //virtual void clearPersistenceContext(); // not used
+ //virtual void clearData(); // not used
+};
+
+// ---------------------------------------------------------------------------
+// Helper Macros & Functions
+// ---------------------------------------------------------------------------
+
+// This benchmark's error handling of NDBAPI calls is rigorous but crude:
+// - all calls' return value is checked for errors
+// - all errors are reported and then followed by a process exit
+#define ABORT_NDB_ERROR(error) \
+ do { cout << "!!! error in " << __FILE__ << ", line: " << __LINE__ \
+ << ", code: " << (int)(error).code \
+ << ", msg: " << (error).message << "." << endl; \
+ exit(-1); \
+ } while (0)
+
+#define ABORT_GETTIMEOFDAY_ERROR() \
+ do { cout << "!!! error in " << __FILE__ << ", line: " << __LINE__ \
+ << ", gettimeofday() returned an error code." << endl; \
+ exit(-1); \
+ } while (0)
+
+#define ABORT_VERIFICATION_ERROR() \
+ do { cout << "!!! error in " << __FILE__ << ", line: " << __LINE__ \
+ << ", failed data verification." << endl; \
+ exit(-1); \
+ } while (0)
+
+// ---------------------------------------------------------------------------
+// Driver Implementation
+// ---------------------------------------------------------------------------
+
+vector< string > Driver::propFileNames;
+string Driver::logFileName;
+
+void
+Driver::exitUsage()
+{
+ cout << "usage: [options]" << endl
+ << " [-p <file name>]... properties file name" << endl
+ << " [-l <file name>] log file name for data output" << endl
+ << " [-h|--help] print usage message and exit" << endl
+ << endl;
+ exit(1); // return an error code
+}
+
+void
+Driver::parseArguments(int argc, const char* argv[])
+{
+ for (int i = 1; i < argc; i++) {
+ const string arg = argv[i];
+ if (arg.compare("-p") == 0) {
+ if (i >= argc) {
+ exitUsage();
+ }
+ propFileNames.push_back(argv[++i]);
+ } else if (arg.compare("-l") == 0) {
+ if (i >= argc) {
+ exitUsage();
+ }
+ logFileName = argv[++i];
+ } else if (arg.compare("-h") == 0 || arg.compare("--help") == 0) {
+ exitUsage();
+ } else {
+ cout << "unknown option: " << arg << endl;
+ exitUsage();
+ }
+ }
+
+ if (propFileNames.size() == 0) {
+ propFileNames.push_back("run.properties");
+ }
+
+ if (logFileName.empty()) {
+ logFileName = "log_";
+
+ // format, destination strings (static size)
+ const char format[] = "%Y%m%d_%H%M%S";
+ const int size = sizeof("yyyymmdd_HHMMSS");
+ char dest[size];
+
+ // get time, convert to timeinfo (statically allocated) then to string
+ const time_t now = time(0);
+ const int nchars = strftime(dest, size, format, localtime(&now));
+ assert(nchars == size-1);
+ (void)nchars;
+
+ logFileName += dest;
+ logFileName += ".txt";
+ }
+ //cout << "logFileName='" << logFileName << "'" << endl;
+}
+
+// ----------------------------------------------------------------------
+
+void
+Driver::run() {
+ init();
+
+ if (warmupRuns > 0) {
+ cout << endl
+ << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl
+ << "warmup runs ..." << endl
+ << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
+
+ for (int i = 0; i < warmupRuns; i++) {
+ runTests();
+ }
+
+ // truncate log file, reset log buffers
+ closeLogFile();
+ openLogFile();
+ header.rdbuf()->str("");
+ rtimes.rdbuf()->str("");
+ }
+
+ if (hotRuns > 0) {
+ cout << endl
+ << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl
+ << "hot runs ..." << endl
+ << "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
+
+ for (int i = 0; i < hotRuns; i++) {
+ runTests();
+ }
+
+ // write log buffers
+ log << descr << ", rtime[ms]"
+ << header.rdbuf()->str() << endl
+ << rtimes.rdbuf()->str() << endl << endl << endl;
+ }
+
+ close();
+}
+
+void
+Driver::init() {
+ loadProperties();
+ initProperties();
+ printProperties();
+ openLogFile();
+
+ // clear log buffers
+ logHeader = true;
+ header.rdbuf()->str("");
+ rtimes.rdbuf()->str("");
+}
+
+void
+Driver::close() {
+ // clear log buffers
+ header.rdbuf()->str("");
+ rtimes.rdbuf()->str("");
+
+ closeLogFile();
+}
+
+void
+Driver::loadProperties() {
+ cout << endl;
+ for (vector<string>::const_iterator i = propFileNames.begin();
+ i != propFileNames.end(); ++i) {
+ cout << "reading properties file: " << *i << endl;
+ props.load(i->c_str());
+ //cout << "props = {" << endl << props << "}" << endl;
+ }
+}
+
+void
+Driver::initProperties() {
+ cout << "setting driver properties ..." << flush;
+
+ ostringstream msg;
+
+ renewConnection = toBool(props[L"renewConnection"], false);
+
+ warmupRuns = toInt(props[L"warmupRuns"], 0, -1);
+ if (warmupRuns < 0) {
+ msg << "[ignored] warmupRuns: '"
+ << toString(props[L"warmupRuns"]) << "'" << endl;
+ warmupRuns = 0;
+ }
+
+ hotRuns = toInt(props[L"hotRuns"], 1, -1);
+ if (hotRuns < 0) {
+ msg << "[ignored] hotRuns: '"
+ << toString(props[L"hotRuns"]) << "'" << endl;
+ hotRuns = 1;
+ }
+
+ //if (msg.tellp() == 0) // netbeans reports amibuities
+ if (msg.str().empty()) {
+ cout << " [ok]" << endl;
+ } else {
+ cout << endl << msg.str() << endl;
+ }
+}
+
+void
+Driver::printProperties() {
+ const ios_base::fmtflags f = cout.flags();
+ // no effect calling manipulator function, not sure why
+ //cout << ios_base::boolalpha;
+ cout.flags(ios_base::boolalpha);
+
+ cout << endl << "driver settings ..." << endl;
+ cout << "renewConnection: " << renewConnection << endl;
+ cout << "warmupRuns: " << warmupRuns << endl;
+ cout << "hotRuns: " << hotRuns << endl;
+
+ cout.flags(f);
+}
+
+void
+Driver::openLogFile() {
+ cout << endl
+ << "opening results file:" << flush;
+ log.open(logFileName.c_str(), ios_base::out | ios_base::trunc);
+ assert(log.good());
+ cout << " [ok: " << logFileName << "]" << endl;
+}
+
+void
+Driver::closeLogFile() {
+ cout << endl
+ << "closing results file:" << flush;
+ log.close();
+ cout << " [ok: " << logFileName << "]" << endl;
+}
+
+// ---------------------------------------------------------------------------
+
+void
+Driver::begin(const string& name) {
+ cout << endl;
+ cout << name << endl;
+
+ if (gettimeofday(&t0, NULL) != 0)
+ ABORT_GETTIMEOFDAY_ERROR();
+}
+
+void
+Driver::commit(const string& name) {
+ if (gettimeofday(&t1, NULL) != 0)
+ ABORT_GETTIMEOFDAY_ERROR();
+
+ const long r_usec = (((t1.tv_sec - t0.tv_sec) * 1000000)
+ + (t1.tv_usec - t0.tv_usec));
+ const long r_msec = r_usec / 1000;
+
+ cout << "tx real time: " << r_msec
+ << "\tms" << endl;
+ rtimes << "\t" << r_msec;
+ rta += r_msec;
+
+ if (logHeader)
+ header << "\t" << name;
+}
+
+// ---------------------------------------------------------------------------
+// TwsDriver Implementation
+// ---------------------------------------------------------------------------
+
+void
+TwsDriver::initProperties() {
+ Driver::initProperties();
+
+ cout << "setting tws properties ..." << flush;
+
+ ostringstream msg;
+
+ doInsert = toBool(props[L"doInsert"], true);
+ doLookup = toBool(props[L"doLookup"], true);
+ doUpdate = toBool(props[L"doUpdate"], true);
+ doDelete = toBool(props[L"doDelete"], true);
+ doSingle = toBool(props[L"doSingle"], true);
+ doBulk = toBool(props[L"doBulk"], true);
+ doBatch = toBool(props[L"doBatch"], true);
+ doVerify = toBool(props[L"doVerify"], true);
+
+ string lm = toString(props[L"lockMode"]);
+ if (lm.empty()) {
+ lockMode = READ_COMMITTED;
+ } else if (lm.compare("READ_COMMITTED") == 0) {
+ lockMode = READ_COMMITTED;
+ } else if (lm.compare("SHARED") == 0) {
+ lockMode = SHARED;
+ } else if (lm.compare("EXCLUSIVE") == 0) {
+ lockMode = EXCLUSIVE;
+ } else {
+ msg << "[ignored] lockMode: '" << lm << "'" << endl;
+ lockMode = READ_COMMITTED;
+ }
+
+ nRows = toInt(props[L"nRows"], 256, 0);
+ if (nRows < 1) {
+ msg << "[ignored] nRows: '"
+ << toString(props[L"nRows"]) << "'" << endl;
+ nRows = 256;
+ }
+
+ //if (msg.tellp() == 0) // netbeans reports amibuities
+ if (msg.str().empty()) {
+ cout << " [ok]" << endl;
+ } else {
+ cout << endl << msg.str() << endl;
+ }
+}
+
+void
+TwsDriver::printProperties() {
+ Driver::printProperties();
+
+ const ios_base::fmtflags f = cout.flags();
+ // no effect calling manipulator function, not sure why
+ //cout << ios_base::boolalpha;
+ cout.flags(ios_base::boolalpha);
+
+ cout << endl << "tws settings..." << endl;
+ cout << "doInsert: " << doInsert << endl;
+ cout << "doLookup: " << doLookup << endl;
+ cout << "doUpdate: " << doUpdate << endl;
+ cout << "doDelete: " << doDelete << endl;
+ cout << "doSingle: " << doSingle << endl;
+ cout << "doBulk: " << doBulk << endl;
+ cout << "doBatch: " << doBatch << endl;
+ cout << "doVerify: " << doVerify << endl;
+ cout << "lockMode: " << toStr(lockMode) << endl;
+ cout << "nRows: " << nRows << endl;
+
+ cout.flags(f);
+}
+
+// ----------------------------------------------------------------------
+
+void
+TwsDriver::runTests() {
+ //initConnection();
+
+ //assert(rStart <= rEnd && rScale > 1);
+ //for (int i = rStart; i <= rEnd; i *= rScale)
+ runLoads();
+
+ //closeConnection();
+}
+
+void
+TwsDriver::runLoads() {
+ // log buffers
+ rtimes << "nRows=" << nRows;
+ rta = 0L;
+
+ // pre-run cleanup
+ if (renewConnection) {
+ closeConnection();
+ initConnection();
+ }
+ //clearData(); // not used
+
+ runOperations();
+
+ cout << endl
+ << "total" << endl;
+ cout << "tx real time " << rta
+ << "\tms" << endl;
+
+ // log buffers
+ if (logHeader) {
+ header << "\ttotal";
+ logHeader = false;
+ }
+ rtimes << "\t" << rta << endl;
+
+ cout << endl
+ << "------------------------------------------------------------" << endl;
+}
+
+void
+TwsDriver::verify(Int32 exp, Int32 act) {
+ if (doVerify) {
+ //cout << "XXX exp=" << exp << ", act=" << act << endl;
+ if (exp != act) {
+ ABORT_VERIFICATION_ERROR();
+ }
+ }
+}
+
+void
+TwsDriver::verify(const char* exp, const char* act) {
+ if (doVerify) {
+ //cout << "XXX exp='" << exp << "', act='" << act << "'" << endl;
+ if (strcmp(exp, act) != 0) {
+ ABORT_VERIFICATION_ERROR();
+ }
+ }
+}
+
+const char*
+TwsDriver::toStr(XMode mode) {
+ switch (mode) {
+ case SINGLE:
+ return "single";
+ case BULK:
+ return "bulk";
+ case BATCH:
+ return "batch";
+ default:
+ assert(false);
+ return NULL;
+ };
+}
+
+const char*
+TwsDriver::toStr(LockMode mode) {
+ switch (mode) {
+ case SINGLE:
+ return "READ_COMMITTED";
+ case BULK:
+ return "bulk";
+ case BATCH:
+ return "batch";
+ default:
+ assert(false);
+ return NULL;
+ };
+}
+
+// ---------------------------------------------------------------------------
+// NDB API Model Implementation
+// ---------------------------------------------------------------------------
+
+NdbApiTwsModel::NdbApiTwsModel(Ndb* ndb) {
+ const NdbDictionary::Dictionary* dict = ndb->getDictionary();
+
+ // get table T0
+ if ((table_t0 = dict->getTable("mytable")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+
+ // get columns of table T0
+ if ((column_c0 = table_t0->getColumn("c0")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c1 = table_t0->getColumn("c1")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c2 = table_t0->getColumn("c2")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c3 = table_t0->getColumn("c3")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c4 = table_t0->getColumn("c4")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c5 = table_t0->getColumn("c5")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c6 = table_t0->getColumn("c6")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c7 = table_t0->getColumn("c7")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c8 = table_t0->getColumn("c8")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c9 = table_t0->getColumn("c9")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c10 = table_t0->getColumn("c10")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c11 = table_t0->getColumn("c11")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c12 = table_t0->getColumn("c12")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c13 = table_t0->getColumn("c13")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+ if ((column_c14 = table_t0->getColumn("c14")) == NULL)
+ ABORT_NDB_ERROR(dict->getNdbError());
+
+ // get attribute ids for columns of table T0
+ attr_c0 = column_c0->getAttrId();
+ attr_c1 = column_c1->getAttrId();
+ attr_c2 = column_c2->getAttrId();
+ attr_c3 = column_c3->getAttrId();
+ attr_c4 = column_c4->getAttrId();
+ attr_c5 = column_c5->getAttrId();
+ attr_c6 = column_c6->getAttrId();
+ attr_c7 = column_c7->getAttrId();
+ attr_c8 = column_c8->getAttrId();
+ attr_c9 = column_c9->getAttrId();
+ attr_c10 = column_c10->getAttrId();
+ attr_c11 = column_c11->getAttrId();
+ attr_c12 = column_c12->getAttrId();
+ attr_c13 = column_c13->getAttrId();
+ attr_c14 = column_c14->getAttrId();
+
+ width_c0 = columnWidth(column_c0);
+ width_c1 = columnWidth(column_c1);
+ width_c2 = columnWidth(column_c2);
+ width_c3 = columnWidth(column_c3);
+ width_c4 = columnWidth(column_c4);
+ width_c5 = columnWidth(column_c5);
+ width_c6 = columnWidth(column_c6);
+ width_c7 = columnWidth(column_c7);
+ width_c8 = columnWidth(column_c8);
+ width_c9 = columnWidth(column_c9);
+ width_c10 = columnWidth(column_c10);
+ width_c11 = columnWidth(column_c11);
+ width_c12 = columnWidth(column_c12);
+ width_c13 = columnWidth(column_c13);
+ width_c14 = columnWidth(column_c14);
+
+ width_row = (
+ + width_c0
+ + width_c1
+ + width_c2
+ + width_c3
+ + width_c4
+ + width_c5
+ + width_c6
+ + width_c7
+ + width_c8
+ + width_c9
+ + width_c10
+ + width_c11
+ + width_c12
+ + width_c13
+ + width_c14);
+}
+
+// ---------------------------------------------------------------------------
+// NdbApiTwsDriver Implementation
+// ---------------------------------------------------------------------------
+
+void
+NdbApiTwsDriver::init() {
+ TwsDriver::init();
+
+ // ndb_init must be called first
+ cout << endl
+ << "initializing NDBAPI ..." << flush;
+ int stat = ndb_init();
+ if (stat != 0)
+ ABORT_ERROR("ndb_init() returned: " << stat);
+ cout << " [ok]" << endl;
+
+ initConnection();
+}
+
+void
+NdbApiTwsDriver::close() {
+ closeConnection();
+
+ // ndb_close must be called last
+ cout << "closing NDBAPI ... " << flush;
+ ndb_end(0);
+ cout << " [ok]" << endl;
+
+ TwsDriver::close();
+}
+
+void
+NdbApiTwsDriver::initProperties() {
+ TwsDriver::initProperties();
+
+ cout << "setting ndb properties ..." << flush;
+
+ ostringstream msg;
+
+ mgmdConnect = toString(props[L"ndb.mgmdConnect"]);
+ if (mgmdConnect.empty()) {
+ mgmdConnect = string("localhost");
+ }
+
+ catalog = toString(props[L"ndb.catalog"]);
+ if (catalog.empty()) {
+ catalog = string("testdb");
+ }
+
+ schema = toString(props[L"ndb.schema"]);
+ if (schema.empty()) {
+ schema = string("def");
+ }
+
+ //if (msg.tellp() == 0) {
+ if (msg.str().empty()) {
+ cout << " [ok]" << endl;
+ } else {
+ cout << endl << msg.str() << endl;
+ }
+
+ descr = "ndbapi(" + mgmdConnect + ")";
+}
+
+void
+NdbApiTwsDriver::printProperties() {
+ TwsDriver::printProperties();
+
+ const ios_base::fmtflags f = cout.flags();
+ // no effect calling manipulator function, not sure why
+ //cout << ios_base::boolalpha;
+ cout.flags(ios_base::boolalpha);
+
+ cout << endl << "ndb settings ..." << endl;
+ cout << "ndb.mgmdConnect: \"" << mgmdConnect << "\"" << endl;
+ cout << "ndb.catalog: \"" << catalog << "\"" << endl;
+ cout << "ndb.schema: \"" << schema << "\"" << endl;
+
+ cout.flags(f);
+}
+
+void
+NdbApiTwsDriver::initNdbapiBuffers() {
+ assert(model->column_c0 != NULL);
+ assert(bb == NULL);
+ assert(ra == NULL);
+
+ cout << "allocating ndbapi buffers ..." << flush;
+ bb = new char[model->width_row * nRows];
+ ra = new NdbRecAttr*[model->nCols * nRows];
+ cout << " [ok]" << endl;
+}
+
+void
+NdbApiTwsDriver::closeNdbapiBuffers() {
+ assert(bb != NULL);
+ assert(ra != NULL);
+
+ cout << "releasing ndbapi buffers ..." << flush;
+ delete[] ra;
+ ra = NULL;
+ delete[] bb;
+ bb = NULL;
+ cout << " [ok]" << endl;
+}
+
+// ---------------------------------------------------------------------------
+
+void
+NdbApiTwsDriver::runOperations() {
+ cout << endl
+ << "running NDB API operations ..." << " [nRows=" << nRows << "]"
+ << endl;
+
+ if (doSingle) {
+ if (doInsert) runNdbapiInsert(SINGLE);
+ if (doLookup) runNdbapiLookup(SINGLE);
+ if (doUpdate) runNdbapiUpdate(SINGLE);
+ if (doDelete) runNdbapiDelete(SINGLE);
+ }
+ if (doBulk) {
+ if (doInsert) runNdbapiInsert(BULK);
+ if (doLookup) runNdbapiLookup(BULK);
+ if (doUpdate) runNdbapiUpdate(BULK);
+ if (doDelete) runNdbapiDelete(BULK);
+ }
+ if (doBatch) {
+ if (doInsert) runNdbapiInsert(BATCH);
+ if (doLookup) runNdbapiLookup(BATCH);
+ if (doUpdate) runNdbapiUpdate(BATCH);
+ if (doDelete) runNdbapiDelete(BATCH);
+ }
+}
+
+// Alternative Implementation:
+// The recurring pattern of runNdbapiXXX(XMode mode) can be parametrized
+// over the operation, for instance, by a member function template:
+//
+// template< XMode M, void (NdbApiTwsDriver::*OP)(int) >
+// void runOp(string name);
+//
+// which tests the template parameter XMode and calls the operation
+// ...
+// if (M == SINGLE) {
+// ... (this->*OP)(i); ...
+// }
+// ...
+// while the caller selects the mode and function to be invoked
+// ...
+// switch (mode) {
+// case SINGLE:
+// runOp< SINGLE, &NdbApiTwsDriver::ndbapiInsert >(name);
+// }...
+// Alas, it turns out not worth it in terms of readability and lines of code.
+
+void
+NdbApiTwsDriver::runNdbapiInsert(XMode mode) {
+ const string name = string("insert_") + toStr(mode);
+ begin(name);
+
+ if (mode == SINGLE) {
+ for(int i = 0; i < nRows; i++) {
+ ndbapiBeginTransaction();
+ ndbapiInsert(i);
+ ndbapiCommitTransaction();
+ ndbapiCloseTransaction();
+ }
+ } else {
+ ndbapiBeginTransaction();
+ for(int i = 0; i < nRows; i++) {
+ ndbapiInsert(i);
+ if (mode == BULK)
+ ndbapiExecuteTransaction();
+ }
+ ndbapiCommitTransaction();
+ ndbapiCloseTransaction();
+ }
+
+ commit(name);
+}
+
+void
+NdbApiTwsDriver::ndbapiInsert(int c0) {
+ // get an insert operation for the table
+ NdbOperation* op = tx->getNdbOperation(model->table_t0);
+ if (op == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ if (op->insertTuple() != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+
+ // values
+ Uint32 i = c0;
+ const int maxlen = 256;
+ char str[maxlen];
+ snprintf(str, maxlen, "%d", i);
+
+ // set values; key attribute needs to be set first
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c0);
+ if (op->equal(model->attr_c0, bb_pos) != 0) // key
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c0;
+
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c1);
+ if (op->setValue(model->attr_c1, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c1;
+
+ if (op->setValue(model->attr_c2, i) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c2;
+
+ if (op->setValue(model->attr_c3, i) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c3;
+
+ if (op->setValue(model->attr_c4, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c4;
+
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c5);
+ if (op->setValue(model->attr_c5, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c5;
+
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c6);
+ if (op->setValue(model->attr_c6, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c6;
+
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c7);
+ if (op->setValue(model->attr_c7, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c7;
+
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c8);
+ if (op->setValue(model->attr_c8, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c8;
+
+ if (op->setValue(model->attr_c9, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c9;
+
+ if (op->setValue(model->attr_c10, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c10;
+
+ if (op->setValue(model->attr_c11, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c11;
+
+ if (op->setValue(model->attr_c12, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c12;
+
+ if (op->setValue(model->attr_c13, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c13;
+
+ if (op->setValue(model->attr_c14, (char*)NULL) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c14;
+}
+
+void
+NdbApiTwsDriver::runNdbapiLookup(XMode mode) {
+ const string name = string("lookup_") + toStr(mode);
+ begin(name);
+
+ if (mode == SINGLE) {
+ for(int i = 0; i < nRows; i++) {
+ ndbapiBeginTransaction();
+ ndbapiLookup(i);
+ ndbapiCommitTransaction();
+ ndbapiRead(i);
+ ndbapiCloseTransaction();
+ }
+ } else {
+ ndbapiBeginTransaction();
+ for(int i = 0; i < nRows; i++) {
+ ndbapiLookup(i);
+
+ if (mode == BULK)
+ ndbapiExecuteTransaction();
+ }
+ ndbapiCommitTransaction();
+ for(int i = 0; i < nRows; i++) {
+ ndbapiRead(i);
+ }
+ ndbapiCloseTransaction();
+ }
+
+ commit(name);
+}
+
+void
+NdbApiTwsDriver::ndbapiLookup(int c0) {
+ // get a lookup operation for the table
+ NdbOperation* op = tx->getNdbOperation(model->table_t0);
+ if (op == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ if (op->readTuple(ndbOpLockMode) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+
+ // values
+ Uint32 i = c0;
+ const int maxlen = 256;
+ char str[maxlen];
+ snprintf(str, maxlen, "%d", i);
+
+ // set values; key attribute needs to be set first
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c0);
+ if (op->equal(model->attr_c0, bb_pos) != 0) // key
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c0;
+
+ // get attributes (not readable until after commit)
+ if ((*ra_pos = op->getValue(model->attr_c1, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c1;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c2, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c2;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c3, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c3;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c4, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c4;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c5, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c5;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c6, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c6;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c7, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c7;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c8, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c8;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c9, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c9;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c10, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c10;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c11, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c11;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c12, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c12;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c13, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c13;
+ ra_pos++;
+
+ if ((*ra_pos = op->getValue(model->attr_c14, bb_pos)) == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c14;
+ ra_pos++;
+}
+
+void
+NdbApiTwsDriver::ndbapiRead(int c0) {
+ // values
+ const int maxlen = 256;
+ char str0[maxlen];
+ snprintf(str0, maxlen, "%d", c0);
+ Int32 i1;
+ char str1[maxlen];
+
+ // no need to read key column
+ bb_pos += model->width_c0;
+
+ ndbapiToString1blp(str1, bb_pos, model->width_c1);
+ verify(str0, str1);
+ bb_pos += model->width_c1;
+ ra_pos++;
+
+ memcpy(&i1, bb_pos, model->width_c2);
+ verify(c0, i1);
+ bb_pos += model->width_c2;
+ ra_pos++;
+
+ memcpy(&i1, bb_pos, model->width_c3);
+ verify(c0, i1);
+ bb_pos += model->width_c3;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c4;
+ ra_pos++;
+
+ ndbapiToString1blp(str1, bb_pos, model->width_c5);
+ verify(str0, str1);
+ bb_pos += model->width_c5;
+ ra_pos++;
+
+ ndbapiToString1blp(str1, bb_pos, model->width_c6);
+ verify(str0, str1);
+ bb_pos += model->width_c6;
+ ra_pos++;
+
+ ndbapiToString1blp(str1, bb_pos, model->width_c7);
+ verify(str0, str1);
+ bb_pos += model->width_c7;
+ ra_pos++;
+
+ ndbapiToString1blp(str1, bb_pos, model->width_c8);
+ verify(str0, str1);
+ bb_pos += model->width_c8;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c9;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c10;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c11;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c12;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c13;
+ ra_pos++;
+
+ // null expected
+ verify(1, (*ra_pos)->isNULL());
+ bb_pos += model->width_c14;
+ ra_pos++;
+}
+
+void
+NdbApiTwsDriver::runNdbapiUpdate(XMode mode) {
+ const string name = string("update_") + toStr(mode);
+ begin(name);
+
+ if (mode == SINGLE) {
+ for(int i = 0; i < nRows; i++) {
+ ndbapiBeginTransaction();
+ ndbapiUpdate(i);
+ ndbapiCommitTransaction();
+ ndbapiCloseTransaction();
+ }
+ } else {
+ ndbapiBeginTransaction();
+ for(int i = 0; i < nRows; i++) {
+ ndbapiUpdate(i);
+ if (mode == BULK)
+ ndbapiExecuteTransaction();
+ }
+ ndbapiCommitTransaction();
+ ndbapiCloseTransaction();
+ }
+
+ commit(name);
+}
+
+void
+NdbApiTwsDriver::ndbapiUpdate(int c0) {
+ // get an update operation for the table
+ NdbOperation* op = tx->getNdbOperation(model->table_t0);
+ if (op == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ if (op->updateTuple() != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+
+ // values
+ const int maxlen = 256;
+ char str0[maxlen];
+ snprintf(str0, maxlen, "%d", c0);
+ int i = -c0;
+ char str1[maxlen];
+ snprintf(str1, maxlen, "%d", i);
+
+ // set values; key attribute needs to be set first
+ ndbapiToBuffer1blp(bb_pos, str0, model->width_c0);
+ if (op->equal(model->attr_c0, bb_pos) != 0) // key
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c0;
+
+ ndbapiToBuffer1blp(bb_pos, str1, model->width_c1);
+ if (op->setValue(model->attr_c1, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c1;
+
+ if (op->setValue(model->attr_c2, i) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c2;
+
+ if (op->setValue(model->attr_c3, i) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c3;
+
+ ndbapiToBuffer1blp(bb_pos, str1, model->width_c5);
+ if (op->setValue(model->attr_c5, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c5;
+
+ ndbapiToBuffer1blp(bb_pos, str1, model->width_c6);
+ if (op->setValue(model->attr_c6, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c6;
+
+ ndbapiToBuffer1blp(bb_pos, str1, model->width_c7);
+ if (op->setValue(model->attr_c7, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c7;
+
+ ndbapiToBuffer1blp(bb_pos, str1, model->width_c8);
+ if (op->setValue(model->attr_c8, bb_pos) != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c8;
+}
+
+void
+NdbApiTwsDriver::runNdbapiDelete(XMode mode) {
+ const string name = string("delete_") + toStr(mode);
+ begin(name);
+
+ if (mode == SINGLE) {
+ for(int i = 0; i < nRows; i++) {
+ ndbapiBeginTransaction();
+ ndbapiDelete(i);
+ ndbapiCommitTransaction();
+ ndbapiCloseTransaction();
+ }
+ } else {
+ ndbapiBeginTransaction();
+ for(int i = 0; i < nRows; i++) {
+ ndbapiDelete(i);
+ if (mode == BULK)
+ ndbapiExecuteTransaction();
+ }
+ ndbapiCommitTransaction();
+ ndbapiCloseTransaction();
+ }
+
+ commit(name);
+}
+
+void
+NdbApiTwsDriver::ndbapiDelete(int c0) {
+ // get a delete operation for the table
+ NdbOperation* op = tx->getNdbOperation(model->table_t0);
+ if (op == NULL)
+ ABORT_NDB_ERROR(tx->getNdbError());
+ if (op->deleteTuple() != 0)
+ ABORT_NDB_ERROR(tx->getNdbError());
+
+ // values
+ Uint32 i = c0;
+ const int maxlen = 256;
+ char str[maxlen];
+ snprintf(str, maxlen, "%d", i);
+
+ // set values; key attribute needs to be set first
+ ndbapiToBuffer1blp(bb_pos, str, model->width_c0);
+ if (op->equal(model->attr_c0, bb_pos) != 0) // key
+ ABORT_NDB_ERROR(tx->getNdbError());
+ bb_pos += model->width_c0;
+}
+
+// ----------------------------------------------------------------------
+
+void
+NdbApiTwsDriver::ndbapiBeginTransaction() {
+ assert(tx == NULL);
+
+ // prepare buffer for writing
+ bb_pos = bb; // clear
+ ra_pos = ra;
+
+ // start a transaction
+ // must be closed with Ndb::closeTransaction or NdbTransaction::close
+ if ((tx = ndb->startTransaction()) == NULL)
+ ABORT_NDB_ERROR(ndb->getNdbError());
+}
+
+void
+NdbApiTwsDriver::ndbapiExecuteTransaction() {
+ assert(tx != NULL);
+
+ // execute but don't commit the current transaction
+ if (tx->execute(NdbTransaction::NoCommit) != 0
+ || tx->getNdbError().status != NdbError::Success)
+ ABORT_NDB_ERROR(tx->getNdbError());
+}
+
+void
+NdbApiTwsDriver::ndbapiCommitTransaction() {
+ assert(tx != NULL);
+
+ // commit the current transaction
+ if (tx->execute(NdbTransaction::Commit) != 0
+ || tx->getNdbError().status != NdbError::Success)
+ ABORT_NDB_ERROR(tx->getNdbError());
+
+ // prepare buffer for reading
+ bb_pos = bb; // rewind
+ ra_pos = ra;
+}
+
+void
+NdbApiTwsDriver::ndbapiCloseTransaction() {
+ assert(tx != NULL);
+
+ // close the current transaction
+ // to be called irrespectively of success or failure
+ ndb->closeTransaction(tx);
+ tx = NULL;
+}
+
+// ---------------------------------------------------------------------------
+
+void
+NdbApiTwsDriver::initConnection() {
+ assert(mgmd == NULL);
+ assert(ndb == NULL);
+ assert(tx == NULL);
+ assert(model == NULL);
+
+ cout << endl;
+
+ // instantiate NDB cluster singleton
+ cout << "creating cluster conn ..." << flush;
+ assert(!mgmdConnect.empty());
+ mgmd = new Ndb_cluster_connection(mgmdConnect.c_str());
+ cout << " [ok]" << endl; // no useful mgmd->string conversion
+
+ // connect to cluster management node (ndb_mgmd)
+ cout << "connecting to mgmd ..." << flush;
+ const int retries = 0; // number of retries (< 0 = indefinitely)
+ const int delay = 0; // seconds to wait after retry
+ const int verbose = 1; // print report of progess
+ // returns: 0 = success, 1 = recoverable error, -1 = non-recoverable error
+ if (mgmd->connect(retries, delay, verbose) != 0)
+ ABORT_ERROR("mgmd@" << mgmdConnect << " was not ready within "
+ << (retries * delay) << "s.");
+ cout << " [ok: " << mgmdConnect << "]" << endl;
+
+ // optionally, connect and wait for reaching the data nodes (ndbds)
+ cout << "waiting for data nodes..." << flush;
+ const int initial_wait = 10; // seconds to wait until first node detected
+ const int final_wait = 0; // seconds to wait after first node detected
+ // returns: 0 all nodes live, > 0 at least one node live, < 0 error
+ if (mgmd->wait_until_ready(initial_wait, final_wait) < 0)
+ ABORT_ERROR("data nodes were not ready within "
+ << (initial_wait + final_wait) << "s.");
+ cout << " [ok]" << endl;
+
+ // connect to database
+ cout << "connecting to database..." << flush;
+ ndb = new Ndb(mgmd, catalog.c_str(), schema.c_str());
+ const int max_no_tx = 10; // maximum number of parallel tx (<=1024)
+ // note each scan or index scan operation uses one extra transaction
+ //if (ndb->init() != 0)
+ if (ndb->init(max_no_tx) != 0)
+ ABORT_NDB_ERROR(ndb->getNdbError());
+ cout << " [ok: " + catalog + "." + schema + "]" << endl;
+
+ cout << "caching metadata ..." << flush;
+ model = new NdbApiTwsModel(ndb);
+ cout << " [ok]" << endl;
+
+ initNdbapiBuffers();
+
+ cout << "using lock mode for reads ..." << flush;
+ string lm;
+ switch (lockMode) {
+ case READ_COMMITTED:
+ ndbOpLockMode = NdbOperation::LM_CommittedRead;
+ lm = "LM_CommittedRead";
+ break;
+ case SHARED:
+ ndbOpLockMode = NdbOperation::LM_Read;
+ lm = "LM_Read";
+ break;
+ case EXCLUSIVE:
+ ndbOpLockMode = NdbOperation::LM_Exclusive;
+ lm = "LM_Exclusive";
+ break;
+ default:
+ ndbOpLockMode = NdbOperation::LM_CommittedRead;
+ lm = "LM_CommittedRead";
+ assert(false);
+ }
+ cout << " [ok: " + lm + "]" << endl;
+}
+
+void
+NdbApiTwsDriver::closeConnection() {
+ assert(mgmd != NULL);
+ assert(ndb != NULL);
+ assert(tx == NULL);
+ assert(model != NULL);
+
+ cout << endl;
+
+ closeNdbapiBuffers();
+
+ cout << "clearing metadata cache ..." << flush;
+ delete model;
+ model = NULL;
+ cout << " [ok]" << endl;
+
+ cout << "closing database connection ..." << flush;
+ // no ndb->close();
+ delete ndb;
+ ndb = NULL;
+ cout << " [ok]" << endl;
+
+ cout << "closing cluster connection ..." << flush;
+ delete mgmd;
+ mgmd = NULL;
+ cout << " [ok]" << endl;
+}
+
+//---------------------------------------------------------------------------
+
+void
+NdbApiTwsDriver::ndbapiToBuffer1blp(void* to, const char* from, size_t width) {
+ char* t = (char*)to;
+ size_t n = strlen(from);
+ assert(0 <= n && n < width && width < 256); // width <= 256 ?
+
+ memcpy(t + 1, from, n);
+ *t = n;
+}
+
+void
+NdbApiTwsDriver::ndbapiToString1blp(char* to, const void* from, size_t width) {
+ const char* s = (const char*)from;
+ size_t n = *s;
+ assert(0 <= n && n < width && width < 256); // width <= 256 ?
+
+ memcpy(to, s + 1, n);
+ to[n] = '\0';
+}
+
+// ---------------------------------------------------------------------------
+
+int
+main(int argc, const char* argv[])
+{
+ NdbApiTwsDriver::parseArguments(argc, argv);
+ NdbApiTwsDriver d;
+ d.run();
+
+ return 0;
+}
+
+//---------------------------------------------------------------------------
=== modified file 'storage/ndb/test/crund/tws_benchmark/schema.sql'
--- a/storage/ndb/test/crund/tws_benchmark/schema.sql 2010-09-27 05:58:05 +0000
+++ b/storage/ndb/test/crund/tws_benchmark/schema.sql 2010-10-08 04:22:28 +0000
@@ -23,9 +23,11 @@ CREATE TABLE IF NOT EXISTS testdb.mytab
c13 CHAR NULL,
c14 VARCHAR(34) NULL,
PRIMARY KEY (c0),
- UNIQUE INDEX c0_UNIQUE USING BTREE (c0 ASC),
- UNIQUE INDEX c1_UNIQUE USING BTREE (c1 ASC),
- UNIQUE INDEX c2_UNIQUE (c2 ASC),
- UNIQUE INDEX c7_UNIQUE (c7 ASC),
- UNIQUE INDEX c8_UNIQUE (c8 ASC)
+ UNIQUE INDEX c0_UNIQUE USING BTREE (c0 ASC)
+-- "Job buffer congestion" crashes with node failure with unique indexes
+-- http://bugs.mysql.com/bug.php?id=56552
+-- UNIQUE INDEX c1_UNIQUE USING BTREE (c1 ASC),
+-- UNIQUE INDEX c2_UNIQUE (c2 ASC),
+-- UNIQUE INDEX c7_UNIQUE (c7 ASC),
+-- UNIQUE INDEX c8_UNIQUE (c8 ASC)
);
=== modified file 'storage/ndb/test/crund/tws_benchmark/src/Main.java'
--- a/storage/ndb/test/crund/tws_benchmark/src/Main.java 2010-10-05 08:48:30 +0000
+++ b/storage/ndb/test/crund/tws_benchmark/src/Main.java 2010-10-08 04:22:28 +0000
@@ -65,6 +65,8 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
public class Main
{
@@ -73,7 +75,7 @@ public class Main
static protected final PrintWriter err = new PrintWriter(System.err, true);
// command-line arguments
- static protected String propsFileName;
+ static private final List<String> propFileNames = new ArrayList<String>();
static protected String logFileName;
// benchmark settings
@@ -156,9 +158,10 @@ public class Main
protected int width_c12;
protected int width_c13;
protected int width_c14;
+ protected int width_row; // sum of {width_c0 .. width_c14}
// NDB JTie data resources
- protected ByteBuffer bb_r;
+ protected ByteBuffer bb;
// NDB JTie static resources
static protected final ByteOrder bo = ByteOrder.nativeOrder();
@@ -227,6 +230,8 @@ public class Main
protected void init() throws IOException, SQLException {
loadProperties();
+ initProperties();
+ printProperties();
// XXX openLogFile();
// XXX init log buffers
@@ -261,17 +266,27 @@ public class Main
// ----------------------------------------------------------------------
- protected void loadProperties() throws IOException {
- out.println("reading properties file: " + propsFileName);
- InputStream is = null;
- try {
- is = new FileInputStream(propsFileName);
- props.load(is);
- } finally {
- if (is != null)
- is.close();
+ // loads the benchmark's properties from properties files
+ private void loadProperties() throws IOException {
+ out.println();
+ for (String fn : propFileNames) {
+ out.println("reading properties file: " + fn);
+ InputStream is = null;
+ try {
+ is = new FileInputStream(fn);
+ props.load(is);
+ } finally {
+ if (is != null)
+ is.close();
+ }
}
+ }
+
+ // initializes the benchmark properties
+ protected void initProperties() {
//props.list(out);
+ out.print("setting driver properties ...");
+ out.flush();
out.print("initializing properties ...");
final StringBuilder msg = new StringBuilder();
@@ -287,9 +302,29 @@ public class Main
doSingle = parseBoolean("doSingle", false);
doBulk = parseBoolean("doBulk", false);
doBatch = parseBoolean("doBatch", false);
- lockMode = parseLockMode("lockMode", LockMode.READ_COMMITTED);
- nRows = parseInt("nRows", 50000);
- nRuns = parseInt("nRuns", 5);
+
+ final String lm = props.getProperty("lockMode");
+ try {
+ lockMode = (lm == null
+ ? LockMode.READ_COMMITTED : LockMode.valueOf(lm));
+ } catch (IllegalArgumentException e) {
+ msg.append("[ignored] lockMode: " + lm + eol);
+ lockMode = LockMode.READ_COMMITTED;
+ }
+
+ nRows = parseInt("nRows", 256);
+ if (nRows < 1) {
+ msg.append("[ignored] nRows: '"
+ + props.getProperty("nRows") + "'" + eol);
+ nRows = 256;
+ }
+
+ nRuns = parseInt("nRuns", 1);
+ if (nRuns < 1) {
+ msg.append("[ignored] nRuns: '"
+ + props.getProperty("nRuns") + "'" + eol);
+ nRuns = 1;
+ }
if (msg.length() == 0) {
out.println(" [ok]");
@@ -297,9 +332,12 @@ public class Main
out.println();
out.print(msg.toString());
}
-
+ }
+
+ // prints the benchmark's properties
+ protected void printProperties() {
out.println();
- out.println("main settings ...");
+ out.println("driver settings ...");
out.println("doJdbc: " + doJdbc);
out.println("doClusterj: " + doClusterj);
out.println("doNdbjtie: " + doNdbjtie);
@@ -333,19 +371,6 @@ public class Main
}
}
- protected LockMode parseLockMode(String k, LockMode vdefault) {
- final String v = props.getProperty(k);
- try {
- return (v == null ? vdefault : LockMode.valueOf(v));
- } catch (IllegalArgumentException e) {
- final IllegalArgumentException iae = new IllegalArgumentException(
- "invalid value of benchmark property ('" + k + "', '"
- + v + "').");
- iae.initCause(e);
- throw iae;
- }
- }
-
// ----------------------------------------------------------------------
protected void initJdbcConnection() throws SQLException {
@@ -438,7 +463,7 @@ public class Main
assert (del0 == null);
out.print("using lock mode for reads ...");
- out.flush;
+ out.flush();
final String lm;
switch (lockMode) {
case READ_COMMITTED:
@@ -607,12 +632,12 @@ public class Main
}
out.println(" [ok: " + catalog + "." + schema + "]");
- initNdbjtieMeta();
+ initNdbjtieModel();
initNdbjtieBuffers();
out.print("using lock mode for reads ...");
- out.flush;
+ out.flush();
final String lm;
switch (lockMode) {
case READ_COMMITTED:
@@ -644,7 +669,7 @@ public class Main
closeNdbjtieBuffers();
- closeNdbjtieMeta();
+ closeNdbjtieModel();
out.print("closing database connection ...");
out.flush();
@@ -654,13 +679,12 @@ public class Main
out.print("closing cluster connection ...");
out.flush();
- if (mgmd != null)
- Ndb_cluster_connection.delete(mgmd);
+ Ndb_cluster_connection.delete(mgmd);
mgmd = null;
out.println(" [ok]");
}
- protected void initNdbjtieMeta() {
+ protected void initNdbjtieModel() {
assert (ndb != null);
assert (table_t0 == null);
assert (column_c0 == null);
@@ -736,10 +760,27 @@ public class Main
width_c13 = ndbjtieColumnWidth(column_c13);
width_c14 = ndbjtieColumnWidth(column_c14);
+ width_row = (
+ + width_c0
+ + width_c1
+ + width_c2
+ + width_c3
+ + width_c4
+ + width_c5
+ + width_c6
+ + width_c7
+ + width_c8
+ + width_c9
+ + width_c10
+ + width_c11
+ + width_c12
+ + width_c13
+ + width_c14);
+
out.println(" [ok]");
}
- protected void closeNdbjtieMeta() {
+ protected void closeNdbjtieModel() {
assert (ndb != null);
assert (table_t0 != null);
assert (column_c0 != null);
@@ -747,22 +788,6 @@ public class Main
out.print("clearing metadata cache...");
out.flush();
- width_c14 = 0;
- width_c13 = 0;
- width_c12 = 0;
- width_c11 = 0;
- width_c10 = 0;
- width_c9 = 0;
- width_c8 = 0;
- width_c7 = 0;
- width_c6 = 0;
- width_c5 = 0;
- width_c4 = 0;
- width_c3 = 0;
- width_c2 = 0;
- width_c1 = 0;
- width_c0 = 0;
-
column_c14 = null;
column_c13 = null;
column_c12 = null;
@@ -786,45 +811,27 @@ public class Main
protected void initNdbjtieBuffers() {
assert (column_c0 != null);
- assert (bb_r == null);
+ assert (bb == null);
out.print("allocating buffers...");
out.flush();
- final int width_row = (
- + width_c0
- + width_c1
- + width_c2
- + width_c3
- + width_c4
- + width_c5
- + width_c6
- + width_c7
- + width_c8
- + width_c9
- + width_c10
- + width_c11
- + width_c12
- + width_c13
- + width_c14);
-
- //bb_r = ByteBuffer.allocateDirect(width_row);
- bb_r = ByteBuffer.allocateDirect(width_row * nRows);
+ bb = ByteBuffer.allocateDirect(width_row * nRows);
// initial order of a byte buffer is always BIG_ENDIAN
- bb_r.order(bo);
+ bb.order(bo);
out.println(" [ok]");
}
protected void closeNdbjtieBuffers() {
assert (column_c0 != null);
- assert (bb_r != null);
+ assert (bb != null);
out.print("releasing buffers...");
out.flush();
- bb_r = null;
+ bb = null;
out.println(" [ok]");
}
@@ -857,9 +864,9 @@ public class Main
}
static protected int ndbjtieColumnWidth(ColumnConst c) {
- final int s = c.getSize(); // size of type or of base type
- final int al = c.getLength(); // length or max length, 1 for scalars
- final int at = c.getArrayType(); // size of length prefix, practically
+ int s = c.getSize(); // size of type or of base type
+ int al = c.getLength(); // length or max length, 1 for scalars
+ int at = c.getArrayType(); // size of length prefix, practically
return (s * al) + at;
}
@@ -1088,16 +1095,16 @@ public class Main
try {
// set values; key attribute needs to be set first
//str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.equal(attr_c0, bb_r) != 0) // key
+ ndbjtieTranscode(bb, str);
+ if (op.equal(attr_c0, bb) != 0) // key
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c0);
+ bb.position(bb.position() + width_c0);
str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.setValue(attr_c1, bb_r) != 0)
+ ndbjtieTranscode(bb, str);
+ if (op.setValue(attr_c1, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c1);
+ bb.position(bb.position() + width_c1);
if (op.setValue(attr_c2, i) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
@@ -1105,29 +1112,52 @@ public class Main
if (op.setValue(attr_c3, i) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
+ // XXX
+ if (op.setValue(attr_c4, null) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+
str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.setValue(attr_c5, bb_r) != 0)
+ ndbjtieTranscode(bb, str);
+ if (op.setValue(attr_c5, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c5);
+ bb.position(bb.position() + width_c5);
str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.setValue(attr_c6, bb_r) != 0)
+ ndbjtieTranscode(bb, str);
+ if (op.setValue(attr_c6, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c6);
+ bb.position(bb.position() + width_c6);
str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.setValue(attr_c7, bb_r) != 0)
+ ndbjtieTranscode(bb, str);
+ if (op.setValue(attr_c7, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c7);
+ bb.position(bb.position() + width_c7);
str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.setValue(attr_c8, bb_r) != 0)
+ ndbjtieTranscode(bb, str);
+ if (op.setValue(attr_c8, bb) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+ bb.position(bb.position() + width_c8);
+
+ // XXX
+ if (op.setValue(attr_c9, null) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+
+ if (op.setValue(attr_c10, null) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+
+ if (op.setValue(attr_c11, null) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+
+ if (op.setValue(attr_c12, null) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+
+ if (op.setValue(attr_c13, null) != 0)
+ throw new RuntimeException(toStr(tx.getNdbError()));
+
+ if (op.setValue(attr_c14, null) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c8);
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
@@ -1183,8 +1213,8 @@ public class Main
ndbjtieBeginTransaction();
ndbjtieLookup(i);
ndbjtieCommitTransaction();
- ndbjtieCloseTransaction();
ndbjtieRead(i);
+ ndbjtieCloseTransaction();
}
} else {
ndbjtieBeginTransaction();
@@ -1195,10 +1225,10 @@ public class Main
ndbjtieExecuteTransaction();
}
ndbjtieCommitTransaction();
- ndbjtieCloseTransaction();
for(int i = 0; i < nRows; i++) {
ndbjtieRead(i);
}
+ ndbjtieCloseTransaction();
}
time += System.currentTimeMillis();
@@ -1268,109 +1298,111 @@ public class Main
if (op.readTuple(ndbOpLockMode) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- int p = bb_r.position();
+ int p = bb.position();
// include exception handling as part of transcoding pattern
final CharBuffer str = CharBuffer.wrap(Integer.toString(c0));
try {
// set values; key attribute needs to be set first
//str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.equal(attr_c0, bb_r) != 0) // key
+ ndbjtieTranscode(bb, str);
+ if (op.equal(attr_c0, bb) != 0) // key
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c0);
+ bb.position(p += width_c0);
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
// get attributes (not readable until after commit)
- if (op.getValue(attr_c1, bb_r) == null)
+ if (op.getValue(attr_c1, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c1);
- if (op.getValue(attr_c2, bb_r) == null)
+ bb.position(p += width_c1);
+ if (op.getValue(attr_c2, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c2);
- if (op.getValue(attr_c3, bb_r) == null)
+ bb.position(p += width_c2);
+ if (op.getValue(attr_c3, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c3);
- if (op.getValue(attr_c4, bb_r) == null)
+ bb.position(p += width_c3);
+ if (op.getValue(attr_c4, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c4);
- if (op.getValue(attr_c5, bb_r) == null)
+ bb.position(p += width_c4);
+ if (op.getValue(attr_c5, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c5);
- if (op.getValue(attr_c6, bb_r) == null)
+ bb.position(p += width_c5);
+ if (op.getValue(attr_c6, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c6);
- if (op.getValue(attr_c7, bb_r) == null)
+ bb.position(p += width_c6);
+ if (op.getValue(attr_c7, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c7);
- if (op.getValue(attr_c8, bb_r) == null)
+ bb.position(p += width_c7);
+ if (op.getValue(attr_c8, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c8);
- if (op.getValue(attr_c9, bb_r) == null)
+ bb.position(p += width_c8);
+ if (op.getValue(attr_c9, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c9);
- if (op.getValue(attr_c10, bb_r) == null)
+ bb.position(p += width_c9);
+ if (op.getValue(attr_c10, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c10);
- if (op.getValue(attr_c11, bb_r) == null)
+ bb.position(p += width_c10);
+ if (op.getValue(attr_c11, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c11);
- if (op.getValue(attr_c12, bb_r) == null)
+ bb.position(p += width_c11);
+ if (op.getValue(attr_c12, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c12);
- if (op.getValue(attr_c13, bb_r) == null)
+ bb.position(p += width_c12);
+ if (op.getValue(attr_c13, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c13);
- if (op.getValue(attr_c14, bb_r) == null)
+ bb.position(p += width_c13);
+ if (op.getValue(attr_c14, bb) == null)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c14);
+ bb.position(p += width_c14);
}
protected void ndbjtieRead(int c0) {
// include exception handling as part of transcoding pattern
- final int i = c0;
- final CharBuffer str = CharBuffer.wrap(Integer.toString(i));
- assert (str.position() == 0);
+ //final int i = c0;
+ //final CharBuffer str = CharBuffer.wrap(Integer.toString(i));
+ //assert (str.position() == 0);
try {
- int p = bb_r.position();
- bb_r.position(p += width_c0);
+ int p = bb.position();
+ bb.position(p += width_c0);
// not verifying at this time
// (str.equals(ndbjtieTranscode(bb_c1)));
// (i == bb_c2.asIntBuffer().get());
- CharBuffer y = ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c1);
+ //CharBuffer y = ndbjtieTranscode(bb);
- bb_r.asIntBuffer().get();
- bb_r.position(p += width_c2);
- bb_r.asIntBuffer().get();
- bb_r.position(p += width_c3);
- bb_r.asIntBuffer().get();
- bb_r.position(p += width_c4);
-
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c5);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c6);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c7);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c8);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c9);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c10);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c11);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c12);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c13);
- ndbjtieTranscode(bb_r);
- bb_r.position(p += width_c14);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c1);
+
+ bb.asIntBuffer().get();
+ bb.position(p += width_c2);
+ bb.asIntBuffer().get();
+ bb.position(p += width_c3);
+ bb.asIntBuffer().get();
+ bb.position(p += width_c4);
+
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c5);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c6);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c7);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c8);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c9);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c10);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c11);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c12);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c13);
+ ndbjtieTranscode(bb);
+ bb.position(p += width_c14);
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
@@ -1510,16 +1542,16 @@ public class Main
try {
// set values; key attribute needs to be set first
//str0.rewind();
- ndbjtieTranscode(bb_r, str0);
- if (op.equal(attr_c0, bb_r) != 0) // key
+ ndbjtieTranscode(bb, str0);
+ if (op.equal(attr_c0, bb) != 0) // key
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c0);
+ bb.position(bb.position() + width_c0);
//str1.rewind();
- ndbjtieTranscode(bb_r, str1);
- if (op.setValue(attr_c1, bb_r) != 0)
+ ndbjtieTranscode(bb, str1);
+ if (op.setValue(attr_c1, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c1);
+ bb.position(bb.position() + width_c1);
if (op.setValue(attr_c2, r) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
@@ -1528,28 +1560,28 @@ public class Main
throw new RuntimeException(toStr(tx.getNdbError()));
str1.rewind();
- ndbjtieTranscode(bb_r, str1);
- if (op.setValue(attr_c5, bb_r) != 0)
+ ndbjtieTranscode(bb, str1);
+ if (op.setValue(attr_c5, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c5);
+ bb.position(bb.position() + width_c5);
str1.rewind();
- ndbjtieTranscode(bb_r, str1);
- if (op.setValue(attr_c6, bb_r) != 0)
+ ndbjtieTranscode(bb, str1);
+ if (op.setValue(attr_c6, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c6);
+ bb.position(bb.position() + width_c6);
str1.rewind();
- ndbjtieTranscode(bb_r, str1);
- if (op.setValue(attr_c7, bb_r) != 0)
+ ndbjtieTranscode(bb, str1);
+ if (op.setValue(attr_c7, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c7);
+ bb.position(bb.position() + width_c7);
str1.rewind();
- ndbjtieTranscode(bb_r, str1);
- if (op.setValue(attr_c8, bb_r) != 0)
+ ndbjtieTranscode(bb, str1);
+ if (op.setValue(attr_c8, bb) != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(bb_r.position() + width_c8);
+ bb.position(bb.position() + width_c8);
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
@@ -1645,14 +1677,14 @@ public class Main
}
protected void ndbjtieDelete(int c0) {
- // get an delete operation for the table
+ // get a delete operation for the table
NdbOperation op = tx.getNdbOperation(table_t0);
if (op == null)
throw new RuntimeException(toStr(tx.getNdbError()));
if (op.deleteTuple() != 0)
throw new RuntimeException(toStr(tx.getNdbError()));
- int p = bb_r.position();
+ int p = bb.position();
// include exception handling as part of transcoding pattern
final int i = c0;
@@ -1660,10 +1692,10 @@ public class Main
try {
// set values; key attribute needs to be set first
//str.rewind();
- ndbjtieTranscode(bb_r, str);
- if (op.equal(attr_c0, bb_r) != 0) // key
+ ndbjtieTranscode(bb, str);
+ if (op.equal(attr_c0, bb) != 0) // key
throw new RuntimeException(toStr(tx.getNdbError()));
- bb_r.position(p += width_c0);
+ bb.position(p += width_c0);
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
@@ -1675,7 +1707,7 @@ public class Main
assert (tx == null);
// prepare buffer for writing
- bb_r.clear();
+ bb.clear();
// start a transaction
// must be closed with NdbTransaction.close
@@ -1708,18 +1740,9 @@ public class Main
if (tx.execute(execType, abortOption, force) != 0
|| tx.getNdbError().status() != NdbError.Status.Success)
throw new RuntimeException(toStr(tx.getNdbError()));
- }
-
- protected void ndbjtieRollbackTransaction() {
- assert (tx != null);
- // abort the current transaction
- final int execType = NdbTransaction.ExecType.Rollback;
- final int abortOption = NdbOperation.AbortOption.DefaultAbortOption;
- final int force = 0;
- if (tx.execute(execType, abortOption, force) != 0
- || tx.getNdbError().status() != NdbError.Status.Success)
- throw new RuntimeException(toStr(tx.getNdbError()));
+ // prepare buffer for reading
+ bb.rewind();
}
protected void ndbjtieCloseTransaction() {
@@ -1728,9 +1751,6 @@ public class Main
// close the current transaction (required after commit, rollback)
ndb.closeTransaction(tx);
tx = null;
-
- // prepare buffer for reading
- bb_r.rewind();
}
// ----------------------------------------------------------------------
Attachment: [text/bzr-bundle] bzr/martin.zaun@oracle.com-20101008042228-kinzemaqdpo39zph.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.1 branch (martin.zaun:3862) | Martin Zaun | 8 Oct |