Author: jstephens
Date: 2006-07-28 12:56:28 +0200 (Fri, 28 Jul 2006)
New Revision: 2861
Log:
Fixed formatting/indentation in examples (Thanks, Hartmut!)
Modified:
trunk/ndbapi/examples.xml
Modified: trunk/ndbapi/examples.xml
===================================================================
--- trunk/ndbapi/examples.xml 2006-07-28 04:57:36 UTC (rev 2860)
+++ trunk/ndbapi/examples.xml 2006-07-28 10:56:28 UTC (rev 2861)
Changed blocks: 74, Lines Added: 531, Lines Deleted: 355; 55833 bytes
@@ -67,13 +67,8 @@
</programlisting>
<programlisting>
-/*
- * ndbapi_simple.cpp: Using synchronous transactions in the NDB API.
- */
-
#include <mysql.h>
#include <NdbApi.hpp>
-
// Used for cout
#include <stdio.h>
#include <iostream>
@@ -93,50 +88,48 @@
int main()
{
- // ndb_init must be called first.
+ // ndb_init must be called first
ndb_init();
- // Connect to the MySQL server and the cluster,
- // and run the application.
+ // connect to mysql server and cluster and run application
{
- // Object representing the cluster.
+ // Object representing the cluster
Ndb_cluster_connection cluster_connection;
- // Connect to the cluster management server (ndb_mgmd)
- if (cluster_connection.connect(
- 4 /* retries */,
- 5 /* delay between retries */,
- 1 /* verbose */))
+ // Connect to cluster management server (ndb_mgmd)
+ if (cluster_connection.connect(4 /* retries */,
+ 5 /* delay between retries */,
+ 1 /* verbose */))
{
- std::cout << "Cluster management server was not ready within 30 seconds.\n";
+ std::cout << "Cluster management server was not ready within 30 secs.\n";
exit(-1);
}
- // Connect and wait for the storage nodes (ndbd processes)
+ // Optionally connect and wait for the storage nodes (ndbd's)
if (cluster_connection.wait_until_ready(30,0) < 0)
{
std::cout << "Cluster was not ready within 30 secs.\n";
exit(-1);
}
- // Connect to the MySQL server.
+ // connect to mysql server
MYSQL mysql;
if ( !mysql_init(&mysql) ) {
std::cout << "mysql_init failed\n";
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
- 3306, "/tmp/mysql.sock", 0) )
+ 3306, "/tmp/mysql.sock", 0) )
MYSQLERROR(mysql);
- // Run the application code.
+ // run the application code
run_application(mysql, cluster_connection);
}
ndb_end(0);
std::cout << "\nTo drop created table use:\n"
- << "echo \"drop table MYTABLENAME\" | mysql TEST_DB_1 -u root\n";
+ << "echo \"drop table MYTABLENAME\" | mysql TEST_DB_1 -u root\n";
return 0;
}
@@ -148,24 +141,24 @@
static void do_read(Ndb &);
static void run_application(MYSQL &mysql,
- Ndb_cluster_connection &cluster_connection)
+ Ndb_cluster_connection &cluster_connection)
{
/********************************************
- * Connect to database via MySQL C API. *
+ * Connect to database via mysql-c *
********************************************/
mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
create_table(mysql);
/********************************************
- * Connect to database via NDB API *
+ * Connect to database via NdbApi *
********************************************/
- // Object representing the database.
+ // Object representing the database
Ndb myNdb( &cluster_connection, "TEST_DB_1" );
if (myNdb.init()) APIERROR(myNdb.getNdbError());
/*
- * Perform various operations on the database.
+ * Do different operations on database
*/
do_insert(myNdb);
do_update(myNdb);
@@ -174,24 +167,22 @@
}
/*********************************************************
- * Create a table named MYTABLENAME if it does not exist.*
+ * Create a table named MYTABLENAME if it does not exist *
*********************************************************/
static void create_table(MYSQL &mysql)
{
- if (mysql_query(&mysql,
- "CREATE TABLE"
- " MYTABLENAME"
- " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,"
- " ATTR2 INT UNSIGNED NOT NULL)"
- " ENGINE=NDB"))
+ if (mysql_query(&mysql,
+ "CREATE TABLE"
+ " MYTABLENAME"
+ " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,"
+ " ATTR2 INT UNSIGNED NOT NULL)"
+ " ENGINE=NDB"))
MYSQLERROR(mysql);
}
-/***********************************************
- * Using 5 transactions, insert 10 tuples into *
- * the table: (0,0),(1,1),...,(9,9) *
- ***********************************************/
-
+/**************************************************************************
+ * Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
+ **************************************************************************/
static void do_insert(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
@@ -226,9 +217,8 @@
}
/*****************************************************************
- * Update the second attribute in half of the tuples (adding 10).*
+ * Update the second attribute in half of the tuples (adding 10) *
*****************************************************************/
-
static void do_update(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
@@ -248,17 +238,16 @@
myOperation->equal( "ATTR1", i );
myOperation->setValue( "ATTR2", i+10);
- if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
+ if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
-/**********************************************************
- * Delete one tuple (the one whose primary key equals 3). *
- **********************************************************/
-
+/*************************************************
+ * Delete one tuple (the one with primary key 3) *
+ *************************************************/
static void do_delete(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
@@ -276,15 +265,15 @@
myOperation->deleteTuple();
myOperation->equal( "ATTR1", 3 );
- if (myTransaction->execute(NdbTransaction::Commit) == -1)
+ if (myTransaction->execute(NdbTransaction::Commit) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
-/******************************
- * Read and print all tuples. *
- ******************************/
+/*****************************
+ * Read and print all tuples *
+ *****************************/
static void do_read(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
@@ -310,9 +299,9 @@
if(myTransaction->execute( NdbTransaction::Commit ) == -1)
if (i == 3) {
- std::cout << "Detected that deleted tuple doesn't exist!" << std::endl;
+ std::cout << "Detected that deleted tuple doesn't exist!" << std::endl;
} else {
- APIERROR(myTransaction->getNdbError());
+ APIERROR(myTransaction->getNdbError());
}
if (i != 3) {
@@ -398,20 +387,18 @@
/*
* ndbapi_retries.cpp: Error handling and retrying transactions
*/
-
#include <NdbApi.hpp>
-// Used for cout.
-#include <iostream>
+// Used for cout
+#include <iostream>
-// Used for sleep (use your own version of sleep).
+// Used for sleep (use your own version of sleep)
#include <unistd.h>
#define TIME_TO_SLEEP_BETWEEN_TRANSACTION_RETRIES 1
//
-// APIERROR prints an NdbError object.
+// APIERROR prints an NdbError object
//
-
#define APIERROR(error) \
{ std::cout << "API ERROR: " << error.code << " " << error.message \
<< std::endl \
@@ -423,9 +410,8 @@
}
//
-// TRANSERROR prints all error info regarding an NdbTransaction.
+// TRANSERROR prints all error info regarding an NdbTransaction
//
-
#define TRANSERROR(ndbTransaction) \
{ NdbError error = ndbTransaction->getNdbError(); \
std::cout << "TRANS ERROR: " << error.code << " " << error.message \
@@ -443,33 +429,35 @@
int i=0;
/****************************************************************
- * Print NdbError object for each operation in the transaction. *
+ * Print NdbError object of every operations in the transaction *
****************************************************************/
while ((ndbOp = ndbTransaction->getNextCompletedOperation(ndbOp)) != NULL) {
NdbError error = ndbOp->getNdbError();
- std::cout << " OPERATION " << i+1 << ": "
- << error.code << " " << error.message << std::endl
- << " Status: " << error.status
- << ", Classification: " << error.classification << std::endl;
+ std::cout << " OPERATION " << i+1 << ": "
+ << error.code << " " << error.message << std::endl
+ << " Status: " << error.status
+ << ", Classification: " << error.classification << std::endl;
i++;
}
}
-// Example insert:
+
+//
+// Example insert
// @param myNdb Ndb object representing NDB Cluster
// @param myTransaction NdbTransaction used for transaction
// @param myTable Table to insert into
// @param error NdbError object returned in case of errors
-// @return -1 on failure, otherwise 0.
+// @return -1 in case of failures, 0 otherwise
//
int insert(int transactionId, NdbTransaction* myTransaction,
- const NdbDictionary::Table *myTable) {
- NdbOperation *myOperation; // For other operations.
+ const NdbDictionary::Table *myTable) {
+ NdbOperation *myOperation; // For other operations
myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) return -1;
- if (myOperation->insertTuple() ||
+ if (myOperation->insertTuple() ||
myOperation->equal("ATTR1", transactionId) ||
myOperation->setValue("ATTR2", transactionId)) {
APIERROR(myOperation->getNdbError());
@@ -479,31 +467,32 @@
return myTransaction->execute(NdbTransaction::NoCommit);
}
-// Execute function which re-executes the transaction (tries 10 times)
-// if there are temporary errors (for example, if the NDB Cluster is
-// overloaded).
-// @return -1 on failure, 1 on success
+
//
+// Execute function which re-executes (tries 10 times) the transaction
+// if there are temporary errors (e.g. the NDB Cluster is overloaded).
+// @return -1 failure, 1 success
+//
int executeInsertTransaction(int transactionId, Ndb* myNdb,
- const NdbDictionary::Table *myTable) {
- int result = 0; // No result yet.
+ const NdbDictionary::Table *myTable) {
+ int result = 0; // No result yet
int noOfRetriesLeft = 10;
- NdbTransaction *myTransaction; // For other transactions.
+ NdbTransaction *myTransaction; // For other transactions
NdbError ndberror;
while (noOfRetriesLeft > 0 && !result) {
- /*************************************
- * Start and execute the transaction.*
- *************************************/
+ /*********************************
+ * Start and execute transaction *
+ *********************************/
myTransaction = myNdb->startTransaction();
if (myTransaction == NULL) {
APIERROR(myNdb->getNdbError());
ndberror = myNdb->getNdbError();
result = -1; // Failure
} else if (insert(transactionId, myTransaction, myTable) ||
- insert(10000+transactionId, myTransaction, myTable) ||
- myTransaction->execute(NdbTransaction::Commit)) {
+ insert(10000+transactionId, myTransaction, myTable) ||
+ myTransaction->execute(NdbTransaction::Commit)) {
TRANSERROR(myTransaction);
ndberror = myTransaction->getNdbError();
result = -1; // Failure
@@ -512,30 +501,30 @@
}
/**********************************
- * On failure: analyse the error. *
+ * If failure, then analyze error *
**********************************/
if (result == -1) {
switch (ndberror.status) {
case NdbError::Success:
- break;
+ break;
case NdbError::TemporaryError:
- std::cout << "Retrying transaction..." << std::endl;
- sleep(TIME_TO_SLEEP_BETWEEN_TRANSACTION_RETRIES);
- --noOfRetriesLeft;
- result = 0; // No completed transaction yet
- break;
-
+ std::cout << "Retrying transaction..." << std::endl;
+ sleep(TIME_TO_SLEEP_BETWEEN_TRANSACTION_RETRIES);
+ --noOfRetriesLeft;
+ result = 0; // No completed transaction yet
+ break;
+
case NdbError::UnknownResult:
case NdbError::PermanentError:
- std::cout << "No retry of transaction..." << std::endl;
- result = -1; // Permanent failure
- break;
+ std::cout << "No retry of transaction..." << std::endl;
+ result = -1; // Permanent failure
+ break;
}
}
- /**************************
- * Close the transaction. *
- **************************/
+ /*********************
+ * Close transaction *
+ *********************/
if (myTransaction != NULL) {
myNdb->closeTransaction(myTransaction);
}
@@ -551,33 +540,32 @@
ndb_init();
Ndb_cluster_connection *cluster_connection=
- new Ndb_cluster_connection(); // Object representing the cluster.
+ new Ndb_cluster_connection(); // Object representing the cluster
- int r= cluster_connection->connect(
- 5 /* retries */,
- 3 /* delay between retries */,
- 1 /* verbose */);
+ int r= cluster_connection->connect(5 /* retries */,
+ 3 /* delay between retries */,
+ 1 /* verbose */);
if (r > 0)
{
std::cout
- << "Cluster connection failed, possibly resolved with more retries.\n";
+ << "Cluster connect failed, possibly resolved with more retries.\n";
exit(-1);
}
else if (r < 0)
{
std::cout
- << "Cluster connection failed.\n";
+ << "Cluster connect failed.\n";
exit(-1);
}
-
+
if (cluster_connection->wait_until_ready(30,30))
{
- std::cout << "Cluster was not ready within 30 seconds." << std::endl;
+ std::cout << "Cluster was not ready within 30 secs." << std::endl;
exit(-1);
}
Ndb* myNdb= new Ndb( cluster_connection,
- "TEST_DB_1" ); // Object representing the database.
+ "TEST_DB_1" ); // Object representing the database
if (myNdb->init() == -1) {
APIERROR(myNdb->getNdbError());
@@ -591,9 +579,9 @@
APIERROR(myDict->getNdbError());
return -1;
}
- /*************************************
- * Execute some insert transactions. *
- *************************************/
+ /************************************
+ * Execute some insert transactions *
+ ************************************/
for (int i = 10000; i < 20000; i++) {
executeInsertTransaction(i, myNdb, myTable);
}
@@ -892,7 +880,6 @@
* ndbapi_scan.cpp: Use of the NDB scanning API
*/
-
#include <mysql.h>
#include <mysqld_error.h>
#include <NdbApi.hpp>
@@ -900,6 +887,9 @@
#include <iostream>
#include <stdio.h>
+/**
+ * Helper sleep function
+ */
static void
milliSleep(int milliseconds){
struct timeval sleeptime;
@@ -909,6 +899,9 @@
}
+/**
+ * Helper sleep function
+ */
#define PRINT_ERROR(code,msg) \
std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \
<< ", code: " << code \
@@ -922,6 +915,10 @@
struct Car
{
+ /**
+ * Note memset, so that entire char-fields are cleared
+ * as all 20 bytes are significant (as type is char)
+ */
Car() { memset(this, 0, sizeof(* this)); }
unsigned int reg_no;
@@ -929,24 +926,27 @@
char color[20];
};
-int create_table(MYSQL &mysql)
+/**
+ * Function to create table
+ */
+int create_table(MYSQL &mysql)
{
- while (mysql_query(&mysql,
- "CREATE TABLE"
- " GARAGE"
- " (REG_NO INT UNSIGNED NOT NULL,"
- " BRAND CHAR(20) NOT NULL,"
- " COLOR CHAR(20) NOT NULL,"
- " PRIMARY KEY USING HASH (REG_NO))"
- " ENGINE=NDB"))
+ while (mysql_query(&mysql,
+ "CREATE TABLE"
+ " GARAGE"
+ " (REG_NO INT UNSIGNED NOT NULL,"
+ " BRAND CHAR(20) NOT NULL,"
+ " COLOR CHAR(20) NOT NULL,"
+ " PRIMARY KEY USING HASH (REG_NO))"
+ " ENGINE=NDB"))
{
if (mysql_errno(&mysql) != ER_TABLE_EXISTS_ERROR)
MYSQLERROR(mysql);
- std::cout << "MySQL Cluster already has the example table GARAGE. "
- << "Now dropping it..." << std::endl;
- /***************
- * Drop table. *
- ***************/
+ std::cout << "MySQL Cluster already has example table: GARAGE. "
+ << "Dropping it..." << std::endl;
+ /**************
+ * Drop table *
+ **************/
if (mysql_query(&mysql, "DROP TABLE GARAGE"))
MYSQLERROR(mysql);
}
@@ -965,6 +965,9 @@
if (myTable == NULL)
APIERROR(myDict->getNdbError());
+ /**
+ * Five blue mercedes
+ */
for (i = 0; i < 5; i++)
{
cars[i].reg_no = i;
@@ -972,6 +975,9 @@
sprintf(cars[i].color, "Blue");
}
+ /**
+ * Five black bmw
+ */
for (i = 5; i < 10; i++)
{
cars[i].reg_no = i;
@@ -979,6 +985,9 @@
sprintf(cars[i].color, "Black");
}
+ /**
+ * Five pink toyotas
+ */
for (i = 10; i < 15; i++)
{
cars[i].reg_no = i;
@@ -990,7 +999,7 @@
if (myTrans == NULL)
APIERROR(myNdb->getNdbError());
- for (i = 0; i < 15; i++)
+ for (i = 0; i < 15; i++)
{
NdbOperation* myNdbOperation = myTrans->getNdbOperation(myTable);
if (myNdbOperation == NULL)
@@ -1009,20 +1018,20 @@
}
int scan_delete(Ndb* myNdb,
- int column,
- const char * color)
+ int column,
+ const char * color)
{
- // Perform an exclusive scan on all records,
- // then delete them one by one.
+ // Scan all records exclusive and delete
+ // them one by one
int retryAttempt = 0;
const int retryMax = 10;
int deletedRows = 0;
int check;
NdbError err;
- NdbTransaction *myTrans;
- NdbScanOperation *myScanOp;
+ NdbTransaction *myTrans;
+ NdbScanOperation *myScanOp;
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
@@ -1030,11 +1039,21 @@
if (myTable == NULL)
APIERROR(myDict->getNdbError());
+ /**
+ * Loop as long as :
+ * retryMax not reached
+ * failed operations due to TEMPORARY erros
+ *
+ * Exit loop;
+ * retyrMax reached
+ * Permanent error (return -1)
+ */
while (true)
{
if (retryAttempt >= retryMax)
{
- std::cout << "ERROR: has retried this operation " << retryAttempt << " times, failing!" << std::endl;
+ std::cout << "ERROR: has retried this operation " << retryAttempt
+ << " times, failing!" << std::endl;
return -1;
}
@@ -1045,15 +1064,18 @@
if (err.status == NdbError::TemporaryError)
{
- milliSleep(50);
- retryAttempt++;
- continue;
+ milliSleep(50);
+ retryAttempt++;
+ continue;
}
std::cout << err.message << std::endl;
return -1;
}
- myScanOp = myTrans->getNdbScanOperation(myTable);
+ /**
+ * Get a scan operation.
+ */
+ myScanOp = myTrans->getNdbScanOperation(myTable);
if (myScanOp == NULL)
{
std::cout << myTrans->getNdbError().message << std::endl;
@@ -1061,6 +1083,9 @@
return -1;
}
+ /**
+ * Define a result set for the scan.
+ */
if(myScanOp->readTuples(NdbOperation::LM_Exclusive) != 0)
{
std::cout << myTrans->getNdbError().message << std::endl;
@@ -1068,8 +1093,11 @@
return -1;
}
+ /**
+ * Use NdbScanFilter to define a search critera
+ */
NdbScanFilter filter(myScanOp) ;
- if(filter.begin(NdbScanFilter::AND) < 0 ||
+ if(filter.begin(NdbScanFilter::AND) < 0 ||
filter.cmp(NdbScanFilter::COND_EQ, column, color) < 0 ||
filter.end() < 0)
{
@@ -1078,13 +1106,16 @@
return -1;
}
- if(myTrans->execute(NdbTransaction::NoCommit) != 0){
- err = myTrans->getNdbError();
+ /**
+ * Start scan (NoCommit since we are only reading at this stage);
+ */
+ if(myTrans->execute(NdbTransaction::NoCommit) != 0){
+ err = myTrans->getNdbError();
if(err.status == NdbError::TemporaryError){
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- milliSleep(50);
- continue;
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ milliSleep(50);
+ continue;
}
std::cout << err.code << std::endl;
std::cout << myTrans->getNdbError().code << std::endl;
@@ -1093,40 +1124,61 @@
}
+ /**
+ * start of loop: nextResult(true) means that "parallelism" number of
+ * rows are fetched from NDB and cached in NDBAPI
+ */
while((check = myScanOp->nextResult(true)) == 0){
do
{
- if (myScanOp->deleteCurrentTuple() != 0)
- {
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- return -1;
- }
- deletedRows++;
-
+ if (myScanOp->deleteCurrentTuple() != 0)
+ {
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ return -1;
+ }
+ deletedRows++;
+
+ /**
+ * nextResult(false) means that the records
+ * cached in the NDBAPI are modified before
+ * fetching more rows from NDB.
+ */
} while((check = myScanOp->nextResult(false)) == 0);
+ /**
+ * Commit when all cached tuple have been marked for deletion
+ */
if(check != -1)
{
- check = myTrans->execute(NdbTransaction::Commit);
+ check = myTrans->execute(NdbTransaction::Commit);
}
if(check == -1)
{
- check = myTrans->restart();
+ /**
+ * Create a new transaction, while keeping scan open
+ */
+ check = myTrans->restart();
}
- err = myTrans->getNdbError();
+ /**
+ * Check for errors
+ */
+ err = myTrans->getNdbError();
if(check == -1)
{
- if(err.status == NdbError::TemporaryError)
- {
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- milliSleep(50);
- continue;
- }
+ if(err.status == NdbError::TemporaryError)
+ {
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ milliSleep(50);
+ continue;
+ }
}
+ /**
+ * End of loop
+ */
}
std::cout << myTrans->getNdbError().message << std::endl;
myNdb->closeTransaction(myTrans);
@@ -1143,21 +1195,21 @@
int scan_update(Ndb* myNdb,
- int update_column,
- const char * before_color,
- const char * after_color)
-
+ int update_column,
+ const char * before_color,
+ const char * after_color)
+
{
- // Perform an exclusive scan on all records,
- // then update them one by one.
+ // Scan all records exclusive and update
+ // them one by one
int retryAttempt = 0;
const int retryMax = 10;
int updatedRows = 0;
int check;
NdbError err;
- NdbTransaction *myTrans;
- NdbScanOperation *myScanOp;
+ NdbTransaction *myTrans;
+ NdbScanOperation *myScanOp;
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
@@ -1165,13 +1217,22 @@
if (myTable == NULL)
APIERROR(myDict->getNdbError());
+ /**
+ * Loop as long as :
+ * retryMax not reached
+ * failed operations due to TEMPORARY erros
+ *
+ * Exit loop;
+ * retyrMax reached
+ * Permanent error (return -1)
+ */
while (true)
{
if (retryAttempt >= retryMax)
{
- std::cout << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << std::endl;
+ std::cout << "ERROR: has retried this operation " << retryAttempt
+ << " times, failing!" << std::endl;
return -1;
}
@@ -1182,15 +1243,18 @@
if (err.status == NdbError::TemporaryError)
{
- milliSleep(50);
- retryAttempt++;
- continue;
+ milliSleep(50);
+ retryAttempt++;
+ continue;
}
std::cout << err.message << std::endl;
return -1;
}
- myScanOp = myTrans->getNdbScanOperation(myTable);
+ /**
+ * Get a scan operation.
+ */
+ myScanOp = myTrans->getNdbScanOperation(myTable);
if (myScanOp == NULL)
{
std::cout << myTrans->getNdbError().message << std::endl;
@@ -1198,15 +1262,21 @@
return -1;
}
- if( myScanOp->readTuples(NdbOperation::LM_Exclusive) )
+ /**
+ * Define a result set for the scan.
+ */
+ if( myScanOp->readTuples(NdbOperation::LM_Exclusive) )
{
std::cout << myTrans->getNdbError().message << std::endl;
myNdb->closeTransaction(myTrans);
return -1;
}
+ /**
+ * Use NdbScanFilter to define a search critera
+ */
NdbScanFilter filter(myScanOp) ;
- if(filter.begin(NdbScanFilter::AND) < 0 ||
+ if(filter.begin(NdbScanFilter::AND) < 0 ||
filter.cmp(NdbScanFilter::COND_EQ, update_column, before_color) <0||
filter.end() <0)
{
@@ -1215,60 +1285,89 @@
return -1;
}
+ /**
+ * Start scan (NoCommit since we are only reading at this stage);
+ */
if(myTrans->execute(NdbTransaction::NoCommit) != 0)
{
- err = myTrans->getNdbError();
+ err = myTrans->getNdbError();
if(err.status == NdbError::TemporaryError){
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- milliSleep(50);
- continue;
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ milliSleep(50);
+ continue;
}
std::cout << myTrans->getNdbError().code << std::endl;
myNdb->closeTransaction(myTrans);
return -1;
}
+ /**
+ * start of loop: nextResult(true) means that "parallelism" number of
+ * rows are fetched from NDB and cached in NDBAPI
+ */
while((check = myScanOp->nextResult(true)) == 0){
do {
- NdbOperation * myUpdateOp = myScanOp->updateCurrentTuple();
- if (myUpdateOp == 0)
- {
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- return -1;
- }
- updatedRows++;
+ /**
+ * Get update operation
+ */
+ NdbOperation * myUpdateOp = myScanOp->updateCurrentTuple();
+ if (myUpdateOp == 0)
+ {
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ return -1;
+ }
+ updatedRows++;
- myUpdateOp->setValue(update_column, after_color);
-
+ /**
+ * do the update
+ */
+ myUpdateOp->setValue(update_column, after_color);
+ /**
+ * nextResult(false) means that the records
+ * cached in the NDBAPI are modified before
+ * fetching more rows from NDB.
+ */
} while((check = myScanOp->nextResult(false)) == 0);
+ /**
+ * NoCommit when all cached tuple have been updated
+ */
if(check != -1)
{
- check = myTrans->execute(NdbTransaction::NoCommit);
+ check = myTrans->execute(NdbTransaction::NoCommit);
}
- err = myTrans->getNdbError();
+ /**
+ * Check for errors
+ */
+ err = myTrans->getNdbError();
if(check == -1)
{
- if(err.status == NdbError::TemporaryError){
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- milliSleep(50);
- continue;
- }
+ if(err.status == NdbError::TemporaryError){
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ milliSleep(50);
+ continue;
+ }
}
+ /**
+ * End of loop
+ */
}
+ /**
+ * Commit all prepared operations
+ */
if(myTrans->execute(NdbTransaction::Commit) == -1)
{
if(err.status == NdbError::TemporaryError){
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- milliSleep(50);
- continue;
- }
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ milliSleep(50);
+ continue;
+ }
}
std::cout << myTrans->getNdbError().message << std::endl;
@@ -1289,21 +1388,19 @@
int scan_print(Ndb * myNdb)
{
- // Perform an exclusive scan on all records,
- // then update them one by one.
+// Scan all records exclusive and update
+ // them one by one
int retryAttempt = 0;
const int retryMax = 10;
int fetchedRows = 0;
int check;
NdbError err;
- NdbTransaction *myTrans;
- NdbScanOperation *myScanOp;
- /* The result from reading the attribute value
- is made up of three columns:
-
- REG_NO, BRAND, and COLOR.
+ NdbTransaction *myTrans;
+ NdbScanOperation *myScanOp;
+ /* Result of reading attribute value, three columns:
+ REG_NO, BRAND, and COLOR
*/
- NdbRecAttr * myRecAttr[3];
+ NdbRecAttr * myRecAttr[3];
const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("GARAGE");
@@ -1311,13 +1408,22 @@
if (myTable == NULL)
APIERROR(myDict->getNdbError());
+ /**
+ * Loop as long as :
+ * retryMax not reached
+ * failed operations due to TEMPORARY erros
+ *
+ * Exit loop;
+ * retyrMax reached
+ * Permanent error (return -1)
+ */
while (true)
{
if (retryAttempt >= retryMax)
{
- std::cout << "ERROR: has retried this operation " << retryAttempt
- << " times, failing!" << std::endl;
+ std::cout << "ERROR: has retried this operation " << retryAttempt
+ << " times, failing!" << std::endl;
return -1;
}
@@ -1328,18 +1434,18 @@
if (err.status == NdbError::TemporaryError)
{
- milliSleep(50);
- retryAttempt++;
- continue;
+ milliSleep(50);
+ retryAttempt++;
+ continue;
}
std::cout << err.message << std::endl;
return -1;
}
/*
* Define a scan operation.
- * (NDBAPI.)
+ * NDBAPI.
*/
- myScanOp = myTrans->getNdbScanOperation(myTable);
+ myScanOp = myTrans->getNdbScanOperation(myTable);
if (myScanOp == NULL)
{
std::cout << myTrans->getNdbError().message << std::endl;
@@ -1347,6 +1453,9 @@
return -1;
}
+ /**
+ * Read without locks, without being placed in lock queue
+ */
if( myScanOp->readTuples(NdbOperation::LM_CommittedRead) == -1)
{
std::cout << myTrans->getNdbError().message << std::endl;
@@ -1354,23 +1463,31 @@
return -1;
}
+ /**
+ * Define storage for fetched attributes.
+ * E.g., the resulting attributes of executing
+ * myOp->getValue("REG_NO") is placed in myRecAttr[0].
+ * No data exists in myRecAttr until transaction has commited!
+ */
myRecAttr[0] = myScanOp->getValue("REG_NO");
myRecAttr[1] = myScanOp->getValue("BRAND");
myRecAttr[2] = myScanOp->getValue("COLOR");
if(myRecAttr[0] ==NULL || myRecAttr[1] == NULL || myRecAttr[2]==NULL)
{
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- return -1;
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ return -1;
}
-
- if(myTrans->execute(NdbTransaction::NoCommit) != 0){
- err = myTrans->getNdbError();
+ /**
+ * Start scan (NoCommit since we are only reading at this stage);
+ */
+ if(myTrans->execute(NdbTransaction::NoCommit) != 0){
+ err = myTrans->getNdbError();
if(err.status == NdbError::TemporaryError){
- std::cout << myTrans->getNdbError().message << std::endl;
- myNdb->closeTransaction(myTrans);
- milliSleep(50);
- continue;
+ std::cout << myTrans->getNdbError().message << std::endl;
+ myNdb->closeTransaction(myTrans);
+ milliSleep(50);
+ continue;
}
std::cout << err.code << std::endl;
std::cout << myTrans->getNdbError().code << std::endl;
@@ -1378,16 +1495,34 @@
return -1;
}
+ /**
+ * start of loop: nextResult(true) means that "parallelism" number of
+ * rows are fetched from NDB and cached in NDBAPI
+ */
while((check = myScanOp->nextResult(true)) == 0){
do {
-
- fetchedRows++;
- std::cout << myRecAttr[0]->u_32_value() << "\t";
+
+ fetchedRows++;
+ /**
+ * print REG_NO unsigned int
+ */
+ std::cout << myRecAttr[0]->u_32_value() << "\t";
- std::cout << myRecAttr[1]->aRef() << "\t";
+ /**
+ * print BRAND character string
+ */
+ std::cout << myRecAttr[1]->aRef() << "\t";
- std::cout << myRecAttr[2]->aRef() << std::endl;
+ /**
+ * print COLOR character string
+ */
+ std::cout << myRecAttr[2]->aRef() << std::endl;
+ /**
+ * nextResult(false) means that the records
+ * cached in the NDBAPI are modified before
+ * fetching more rows from NDB.
+ */
} while((check = myScanOp->nextResult(false)) == 0);
}
@@ -1405,7 +1540,7 @@
MYSQL mysql;
/**************************************************************
- * Connect to the MySQL server, and create the table. *
+ * Connect to mysql server and create table *
**************************************************************/
{
if ( !mysql_init(&mysql) ) {
@@ -1413,7 +1548,7 @@
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
- 3306, "/tmp/mysql.sock", 0) )
+ 3306, "/tmp/mysql.sock", 0) )
MYSQLERROR(mysql);
mysql_query(&mysql, "CREATE DATABASE TEST_DB");
@@ -1423,7 +1558,7 @@
}
/**************************************************************
- * Connect to NDB Cluster. *
+ * Connect to ndb cluster *
**************************************************************/
Ndb_cluster_connection cluster_connection;
@@ -1432,7 +1567,7 @@
std::cout << "Unable to connect to cluster within 30 secs." << std::endl;
exit(-1);
}
- // Connect and wait for the storage nodes (ndbd processes).
+ // Optionally connect and wait for the storage nodes (ndbd's)
if (cluster_connection.wait_until_ready(30,0) < 0)
{
std::cout << "Cluster was not ready within 30 secs.\n";
@@ -1446,7 +1581,7 @@
}
/*******************************************
- * Check table definition. *
+ * Check table definition *
*******************************************/
int column_color;
{
@@ -1455,7 +1590,7 @@
Car car;
if (t->getColumn("COLOR")->getLength() != sizeof(car.color) ||
- t->getColumn("BRAND")->getLength() != sizeof(car.brand))
+ t->getColumn("BRAND")->getLength() != sizeof(car.brand))
{
std::cout << "Wrong table definition" << std::endl;
exit(-1);
@@ -1472,6 +1607,9 @@
std::cout << "Going to delete all pink cars!" << std::endl;
{
+ /**
+ * Note! color needs to be of exact the same size as column defined
+ */
Car tmp;
sprintf(tmp.color, "Pink");
if(scan_delete(&myNdb, column_color, tmp.color) > 0)
@@ -1482,12 +1620,15 @@
std::cout << "scan_print: Success!" << std::endl << std::endl;
{
+ /**
+ * Note! color1 & 2 need to be of exact the same size as column defined
+ */
Car tmp1, tmp2;
sprintf(tmp1.color, "Blue");
sprintf(tmp2.color, "Black");
- std::cout << "Going to update all " << tmp1.color
- << " cars to " << tmp2.color << " cars!" << std::endl;
- if(scan_update(&myNdb, column_color, tmp1.color, tmp2.color) > 0)
+ std::cout << "Going to update all " << tmp1.color
+ << " cars to " << tmp2.color << " cars!" << std::endl;
+ if(scan_update(&myNdb, column_color, tmp1.color, tmp2.color) > 0)
std::cout << "scan_update: Success!" << std::endl << std::endl;
}
if(scan_print(&myNdb) > 0)
@@ -1495,6 +1636,7 @@
return 0;
}
+
</programlisting>
</section>
@@ -1572,7 +1714,7 @@
MYSQL mysql;
/**************************************************************
- * Connect to the MySQL server and create the table *
+ * Connect to mysql server and create table *
**************************************************************/
{
if ( !mysql_init(&mysql) ) {
@@ -1580,25 +1722,25 @@
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
- 3306, "/tmp/mysql.sock", 0) )
+ 3306, "/tmp/mysql.sock", 0) )
MYSQLERROR(mysql);
mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
- if (mysql_query(&mysql,
- "CREATE TABLE"
- " MYTABLENAME"
- " (ATTR1 INT UNSIGNED,"
- " ATTR2 INT UNSIGNED NOT NULL,"
- " PRIMARY KEY USING HASH (ATTR1),"
- " UNIQUE MYINDEXNAME USING HASH (ATTR2))"
- " ENGINE=NDB"))
+ if (mysql_query(&mysql,
+ "CREATE TABLE"
+ " MYTABLENAME"
+ " (ATTR1 INT UNSIGNED,"
+ " ATTR2 INT UNSIGNED NOT NULL,"
+ " PRIMARY KEY USING HASH (ATTR1),"
+ " UNIQUE MYINDEXNAME USING HASH (ATTR2))"
+ " ENGINE=NDB"))
MYSQLERROR(mysql);
}
/**************************************************************
- * Connect to the NDB cluster. *
+ * Connect to ndb cluster *
**************************************************************/
Ndb_cluster_connection *cluster_connection=
@@ -1612,13 +1754,13 @@
if (cluster_connection->wait_until_ready(30,30))
{
- std::cout << "Cluster was not ready within 30 seconds.\n";
+ std::cout << "Cluster was not ready within 30 secs.\n";
exit(-1);
}
Ndb* myNdb = new Ndb( cluster_connection,
- "TEST_DB_1" ); // Object representing the database.
- if (myNdb->init() == -1) {
+ "TEST_DB_1" ); // Object representing the database
+ if (myNdb->init() == -1) {
APIERROR(myNdb->getNdbError());
exit(-1);
}
@@ -1631,11 +1773,9 @@
if (myIndex == NULL)
APIERROR(myDict->getNdbError());
-/***********************************************
- * Using 5 transactions, insert 10 tuples into *
- * the table: (0,0),(1,1),...,(9,9) *
- ***********************************************/
-
+ /**************************************************************************
+ * Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) *
+ **************************************************************************/
for (int i = 0; i < 5; i++) {
NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
@@ -1647,7 +1787,7 @@
myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i);
- myOperation = myTransaction->getNdbOperation(myTable);
+ myOperation = myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
@@ -1660,9 +1800,9 @@
myNdb->closeTransaction(myTransaction);
}
- /**********************************************
- * Read and print all tuples using the index. *
- **********************************************/
+ /*****************************************
+ * Read and print all tuples using index *
+ *****************************************/
std::cout << "ATTR1 ATTR2" << std::endl;
for (int i = 0; i < 10; i++) {
@@ -1685,10 +1825,9 @@
myNdb->closeTransaction(myTransaction);
}
- /******************************************************************
- * Update the second attribute in half of the tuples (adding 10). *
- ******************************************************************/
-
+ /*****************************************************************
+ * Update the second attribute in half of the tuples (adding 10) *
+ *****************************************************************/
for (int i = 0; i < 10; i+=2) {
NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
@@ -1701,16 +1840,15 @@
myIndexOperation->equal( "ATTR2", i );
myIndexOperation->setValue( "ATTR2", i+10);
- if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
+ if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
APIERROR(myTransaction->getNdbError());
myNdb->closeTransaction(myTransaction);
}
-
-/**********************************************************
- * Delete one tuple (the one whose primary key equals 3). *
- **********************************************************/
-
+
+ /*************************************************
+ * Delete one tuple (the one with primary key 3) *
+ *************************************************/
{
NdbTransaction *myTransaction= myNdb->startTransaction();
if (myTransaction == NULL) APIERROR(myNdb->getNdbError());
@@ -1722,15 +1860,15 @@
myIndexOperation->deleteTuple();
myIndexOperation->equal( "ATTR2", 3 );
- if (myTransaction->execute(NdbTransaction::Commit) == -1)
+ if (myTransaction->execute(NdbTransaction::Commit) == -1)
APIERROR(myTransaction->getNdbError());
myNdb->closeTransaction(myTransaction);
}
- /**********************************
- * Read and print out all tuples. *
- **********************************/
+ /*****************************
+ * Read and print all tuples *
+ *****************************/
{
std::cout << "ATTR1 ATTR2" << std::endl;
@@ -1748,23 +1886,22 @@
if (myRecAttr == NULL) APIERROR(myTransaction->getNdbError());
if(myTransaction->execute( NdbTransaction::Commit ) == -1)
- if (i == 3) {
- std::cout << "Detected that deleted tuple doesn't exist!\n";
- } else {
- APIERROR(myTransaction->getNdbError());
- }
+ if (i == 3) {
+ std::cout << "Detected that deleted tuple doesn't exist!\n";
+ } else {
+ APIERROR(myTransaction->getNdbError());
+ }
if (i != 3) {
- printf(" %2d %2d\n", i, myRecAttr->u_32_value());
+ printf(" %2d %2d\n", i, myRecAttr->u_32_value());
}
myNdb->closeTransaction(myTransaction);
}
}
- /*******************
- * Drop the table. *
- *******************/
-
+ /**************
+ * Drop table *
+ **************/
if (mysql_query(&mysql, "DROP TABLE MYTABLENAME"))
MYSQLERROR(mysql);
@@ -1808,7 +1945,7 @@
*/
#include <NdbApi.hpp>
-// Used for cout.
+// Used for cout
#include <stdio.h>
#include <iostream>
#include <unistd.h>
@@ -1820,16 +1957,57 @@
#endif
+/**
+ * Assume that there is a table which is being updated by
+ * another process (e.g. flexBench -l 0 -stdtables).
+ * We want to monitor what happens with column values.
+ *
+ * Or using the mysql client:
+ *
+ * shell> mysql -u root
+ * mysql> create database TEST_DB;
+ * mysql> use TEST_DB;
+ * mysql> create table t0
+ * (c0 int, c1 int, c2 char(4), c3 char(4), c4 text,
+ * primary key(c0, c2)) engine ndb charset latin1;
+ *
+ * In another window start ndbapi_event, wait until properly started
+
+ insert into t0 values (1, 2, 'a', 'b', null);
+ insert into t0 values (3, 4, 'c', 'd', null);
+ update t0 set c3 = 'e' where c0 = 1 and c2 = 'a'; -- use pk
+ update t0 set c3 = 'f'; -- use scan
+ update t0 set c3 = 'F'; -- use scan update to 'same'
+ update t0 set c2 = 'g' where c0 = 1; -- update pk part
+ update t0 set c2 = 'G' where c0 = 1; -- update pk part to 'same'
+ update t0 set c0 = 5, c2 = 'H' where c0 = 3; -- update full PK
+ delete from t0;
+
+ insert ...; update ...; -- see events w/ same pk merged (if -m option)
+ delete ...; insert ...; -- there are 5 combinations ID IU DI UD UU
+ update ...; update ...;
+
+ -- text requires -m flag
+ set @a = repeat('a',256); -- inline size
+ set @b = repeat('b',2000); -- part size
+ set @c = repeat('c',2000*30); -- 30 parts
+
+ -- update the text field using combinations of @a, @b, @c ...
+
+ * you should see the data popping up in the example window
+ *
+ */
+
#define APIERROR(error) \
{ std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \
<< error.code << ", msg: " << error.message << "." << std::endl; \
exit(-1); }
int myCreateEvent(Ndb* myNdb,
- const char *eventName,
- const char *eventTableName,
- const char **eventColumnName,
- const int noEventColumnName,
+ const char *eventName,
+ const char *eventTableName,
+ const char **eventColumnName,
+ const int noEventColumnName,
bool merge_events);
int main(int argc, char** argv)
@@ -1843,12 +2021,11 @@
#endif
Ndb_cluster_connection *cluster_connection=
- new Ndb_cluster_connection(); // Object representing the cluster.
+ new Ndb_cluster_connection(); // Object representing the cluster
- int r= cluster_connection->connect(
- 5 /* retries */,
- 3 /* delay between retries */,
- 1 /* verbose */);
+ int r= cluster_connection->connect(5 /* retries */,
+ 3 /* delay between retries */,
+ 1 /* verbose */);
if (r > 0)
{
std::cout
@@ -1861,15 +2038,15 @@
<< "Cluster connect failed.\n";
exit(-1);
}
-
+
if (cluster_connection->wait_until_ready(30,30))
{
- std::cout << "Cluster was not ready within 30 seconds." << std::endl;
+ std::cout << "Cluster was not ready within 30 secs." << std::endl;
exit(-1);
}
Ndb* myNdb= new Ndb(cluster_connection,
- "TEST_DB"); // Object representing the database.
+ "TEST_DB"); // Object representing the database
if (myNdb->init() == -1) APIERROR(myNdb->getNdbError());
@@ -1884,12 +2061,12 @@
"c4"
};
- // Create events.
+ // Create events
myCreateEvent(myNdb,
- eventName,
- eventTableName,
- eventColumnName,
- noEventColumnName,
+ eventName,
+ eventTableName,
+ eventColumnName,
+ noEventColumnName,
merge_events);
// Normal values and blobs are unfortunately handled differently..
@@ -1899,17 +2076,17 @@
j = 0;
while (j < 99) {
- // Start "transaction" for handling events.
+ // Start "transaction" for handling events
NdbEventOperation* op;
- printf("Create EventOperation...\n");
+ printf("create EventOperation\n");
if ((op = myNdb->createEventOperation(eventName)) == NULL)
APIERROR(myNdb->getNdbError());
op->mergeEvents(merge_events);
- printf("Get values...\n");
+ printf("get values\n");
RA_BH recAttr[noEventColumnName];
RA_BH recAttrPre[noEventColumnName];
- // Primary keys should always be a part of the result.
+ // primary keys should always be a part of the result
for (i = 0; i < noEventColumnName; i++) {
if (i < 4) {
recAttr[i].ra = op->getValue(eventColumnName[i]);
@@ -1920,9 +2097,9 @@
}
}
- // Set up the callbacks.
- printf("Execute...\n");
- // This causes the changes to start "flowing".
+ // set up the callbacks
+ printf("execute\n");
+ // This starts changes to "start flowing"
if (op->execute())
APIERROR(op->getNdbError());
@@ -1930,35 +2107,34 @@
i= 0;
while (i < 40) {
- // printf("Now waiting for event...\n");
- int r = myNdb->pollEvents(1000); // Wait for the event (maximum
- // 1000 ms).
+ // printf("now waiting for event...\n");
+ int r = myNdb->pollEvents(1000); // wait for event or 1000 ms
if (r > 0) {
- // printf("Got data! %d\n", r);
- while ((op= myNdb->nextEvent())) {
+ // printf("got data! %d\n", r);
+ while ((op= myNdb->nextEvent())) {
assert(the_op == op);
- i++;
- switch (op->getEventType()) {
- case NdbDictionary::Event::TE_INSERT:
- printf("%u INSERT", i);
- break;
- case NdbDictionary::Event::TE_DELETE:
- printf("%u DELETE", i);
- break;
- case NdbDictionary::Event::TE_UPDATE:
- printf("%u UPDATE", i);
- break;
- default:
- abort(); // This should not happen.
- }
+ i++;
+ switch (op->getEventType()) {
+ case NdbDictionary::Event::TE_INSERT:
+ printf("%u INSERT", i);
+ break;
+ case NdbDictionary::Event::TE_DELETE:
+ printf("%u DELETE", i);
+ break;
+ case NdbDictionary::Event::TE_UPDATE:
+ printf("%u UPDATE", i);
+ break;
+ default:
+ abort(); // should not happen
+ }
printf(" gci=%d\n", (int)op->getGCI());
for (k = 0; k <= 1; k++) {
printf(k == 0 ? "post: " : "pre : ");
for (l = 0; l < noEventColumnName; l++) {
if (l < 4) {
NdbRecAttr* ra = k == 0 ? recAttr[l].ra : recAttrPre[l].ra;
- if (ra->isNULL() >= 0) { // We have a value.
- if (ra->isNULL() == 0) { // We have a non-null value.
+ if (ra->isNULL() >= 0) { // we have a value
+ if (ra->isNULL() == 0) { // we have a non-null value
if (l < 2)
printf("%-5u", ra->u_32_value());
else
@@ -1971,15 +2147,15 @@
int isNull;
NdbBlob* bh = k == 0 ? recAttr[l].bh : recAttrPre[l].bh;
bh->getDefined(isNull);
- if (isNull >= 0) { // We have a value.
- if (! isNull) { // We have a non-null value.
+ if (isNull >= 0) { // we have a value
+ if (! isNull) { // we have a non-null value
Uint64 length = 0;
bh->getLength(length);
- // Read into buffer.
+ // read into buffer
unsigned char* buf = new unsigned char [length];
memset(buf, 'X', length);
Uint32 n = length;
- bh->readData(buf, n); // n is in/out.
+ bh->readData(buf, n); // n is in/out
assert(n == length);
// pretty-print
bool first = true;
@@ -1999,16 +2175,16 @@
} else
printf("%-5s", "NULL");
} else
- printf("%-5s", "-"); // No value.
+ printf("%-5s", "-"); // no value
}
}
printf("\n");
}
- }
+ }
} else
- ; // printf("Timed out.\n");
+ ;//printf("timed out\n");
}
- // We don't want to listen to events anymore...
+ // don't want to listen to events anymore
if (myNdb->dropEventOperation(the_op)) APIERROR(myNdb->getNdbError());
the_op = 0;
@@ -2018,7 +2194,7 @@
{
NdbDictionary::Dictionary *myDict = myNdb->getDictionary();
if (!myDict) APIERROR(myNdb->getNdbError());
- // Remove the event from the database.
+ // remove event from database
if (myDict->dropEvent(eventName)) APIERROR(myDict->getNdbError());
}
@@ -2029,10 +2205,10 @@
}
int myCreateEvent(Ndb* myNdb,
- const char *eventName,
- const char *eventTableName,
- const char **eventColumnNames,
- const int noEventColumnNames,
+ const char *eventName,
+ const char *eventTableName,
+ const char **eventColumnNames,
+ const int noEventColumnNames,
bool merge_events)
{
NdbDictionary::Dictionary *myDict= myNdb->getDictionary();
@@ -2050,16 +2226,16 @@
myEvent.addEventColumns(noEventColumnNames, eventColumnNames);
myEvent.mergeEvents(merge_events);
- // Add an event to the database.
+ // Add event to database
if (myDict->createEvent(myEvent) == 0)
myEvent.print();
else if (myDict->getNdbError().classification ==
- NdbError::SchemaObjectExists) {
- printf("Event creation failed; event already exists.\n");
- printf("Dropping event...\n");
+ NdbError::SchemaObjectExists) {
+ printf("Event creation failed, event exists\n");
+ printf("dropping Event...\n");
if (myDict->dropEvent(eventName)) APIERROR(myDict->getNdbError());
- // Try again...
- // Add the event to the database.
+ // try again
+ // Add event to database
if ( myDict->createEvent(myEvent)) APIERROR(myDict->getNdbError());
} else
APIERROR(myDict->getNdbError());
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r2861 - trunk/ndbapi | jstephens | 28 Jul |