List:Commits« Previous MessageNext Message »
From:jstephens Date:July 28 2006 10:56am
Subject:svn commit - mysqldoc@docsrva: r2861 - trunk/ndbapi
View as plain text  
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 &lt;mysql.h&gt;
 #include &lt;NdbApi.hpp&gt;
-
 // Used for cout
 #include &lt;stdio.h&gt;
 #include &lt;iostream&gt;

@@ -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 &lt;&lt; "Cluster management server was not ready within 30 seconds.\n";
+      std::cout &lt;&lt; "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) &lt; 0)
     {
       std::cout &lt;&lt; "Cluster was not ready within 30 secs.\n";
       exit(-1);
     }
 
-    // Connect to the MySQL server.
+    // connect to mysql server
     MYSQL mysql;
     if ( !mysql_init(&amp;mysql) ) {
       std::cout &lt;&lt; "mysql_init failed\n";
       exit(-1);
     }
     if ( !mysql_real_connect(&amp;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 &lt;&lt; "\nTo drop created table use:\n"
-      &lt;&lt; "echo \"drop table MYTABLENAME\" | mysql TEST_DB_1 -u root\n";
+            &lt;&lt; "echo \"drop table MYTABLENAME\" | mysql TEST_DB_1 -u root\n";
 
   return 0;
 }

@@ -148,24 +141,24 @@
 static void do_read(Ndb &amp;);
 
 static void run_application(MYSQL &amp;mysql,
-          Ndb_cluster_connection &amp;cluster_connection)
+                            Ndb_cluster_connection &amp;cluster_connection)
 {
   /********************************************
-   * Connect to database via MySQL C API.     *
+   * Connect to database via mysql-c          *
    ********************************************/
   mysql_query(&amp;mysql, "CREATE DATABASE TEST_DB_1");
   if (mysql_query(&amp;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( &amp;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 &amp;mysql)
 {
-  if (mysql_query(&amp;mysql, 
-      "CREATE TABLE"
-      "  MYTABLENAME"
-      "    (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,"
-      "     ATTR2 INT UNSIGNED NOT NULL)"
-      "  ENGINE=NDB"))
+  if (mysql_query(&amp;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 &amp;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 &amp;myNdb)
 {
   const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();

@@ -248,17 +238,16 @@
     myOperation-&gt;equal( "ATTR1", i );
     myOperation-&gt;setValue( "ATTR2", i+10);
     
-    if( myTransaction-&gt;execute( NdbTransaction::Commit ) == -1 ) 
+    if( myTransaction-&gt;execute( NdbTransaction::Commit ) == -1 )
       APIERROR(myTransaction-&gt;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 &amp;myNdb)
 {
   const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();

@@ -276,15 +265,15 @@
   myOperation-&gt;deleteTuple();
   myOperation-&gt;equal( "ATTR1", 3 );
   
-  if (myTransaction-&gt;execute(NdbTransaction::Commit) == -1) 
+  if (myTransaction-&gt;execute(NdbTransaction::Commit) == -1)
     APIERROR(myTransaction-&gt;getNdbError());
   
   myNdb.closeTransaction(myTransaction);
 }
 
-/******************************
- * Read and print all tuples. *
- ******************************/
+/*****************************
+ * Read and print all tuples *
+ *****************************/
 static void do_read(Ndb &amp;myNdb)
 {
   const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();

@@ -310,9 +299,9 @@
     
     if(myTransaction-&gt;execute( NdbTransaction::Commit ) == -1)
       if (i == 3) {
-  std::cout &lt;&lt; "Detected that deleted tuple doesn't exist!" &lt;&lt; std::endl;
+        std::cout &lt;&lt; "Detected that deleted tuple doesn't exist!" &lt;&lt; std::endl;
       } else {
-  APIERROR(myTransaction-&gt;getNdbError());
+        APIERROR(myTransaction-&gt;getNdbError());
       }
     
     if (i != 3) {

@@ -398,20 +387,18 @@
 /* 
  *  ndbapi_retries.cpp: Error handling and retrying transactions
  */
-
 #include &lt;NdbApi.hpp&gt;
 
-// Used for cout.
-#include &lt;iostream&gt;  
+// Used for cout
+#include &lt;iostream&gt;
 
-// Used for sleep (use your own version of sleep).
+// Used for sleep (use your own version of sleep)
 #include &lt;unistd.h&gt;
 #define TIME_TO_SLEEP_BETWEEN_TRANSACTION_RETRIES 1
 
 //
-//  APIERROR prints an NdbError object.
+//  APIERROR prints an NdbError object
 //
-
 #define APIERROR(error) \
   { std::cout &lt;&lt; "API ERROR: " &lt;&lt; error.code &lt;&lt; " " &lt;&lt; error.message \
               &lt;&lt; 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-&gt;getNdbError(); \
     std::cout &lt;&lt; "TRANS ERROR: " &lt;&lt; error.code &lt;&lt; " " &lt;&lt; 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-&gt;getNextCompletedOperation(ndbOp)) != NULL) {
     NdbError error = ndbOp-&gt;getNdbError();
-    std::cout &lt;&lt; "           OPERATION " &lt;&lt; i+1 &lt;&lt; ": " 
-        &lt;&lt; error.code &lt;&lt; " " &lt;&lt; error.message &lt;&lt; std::endl
-        &lt;&lt; "           Status: " &lt;&lt; error.status 
-        &lt;&lt; ", Classification: " &lt;&lt; error.classification &lt;&lt; std::endl;
+    std::cout &lt;&lt; "           OPERATION " &lt;&lt; i+1 &lt;&lt; ": "
+              &lt;&lt; error.code &lt;&lt; " " &lt;&lt; error.message &lt;&lt; std::endl
+              &lt;&lt; "           Status: " &lt;&lt; error.status
+              &lt;&lt; ", Classification: " &lt;&lt; error.classification &lt;&lt; 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-&gt;getNdbOperation(myTable);
   if (myOperation == NULL) return -1;
   
-  if (myOperation-&gt;insertTuple() ||  
+  if (myOperation-&gt;insertTuple() ||
       myOperation-&gt;equal("ATTR1", transactionId) ||
       myOperation-&gt;setValue("ATTR2", transactionId)) {
     APIERROR(myOperation-&gt;getNdbError());

@@ -479,31 +467,32 @@
   return myTransaction-&gt;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 &gt; 0 &amp;&amp; !result) {
     
-    /*************************************
-     * Start and execute the transaction.*
-     *************************************/
+    /*********************************
+     * Start and execute transaction *
+     *********************************/
     myTransaction = myNdb-&gt;startTransaction();
     if (myTransaction == NULL) {
       APIERROR(myNdb-&gt;getNdbError());
       ndberror = myNdb-&gt;getNdbError();
       result = -1;  // Failure
     } else if (insert(transactionId, myTransaction, myTable) || 
-         insert(10000+transactionId, myTransaction, myTable) ||
-         myTransaction-&gt;execute(NdbTransaction::Commit)) {
+               insert(10000+transactionId, myTransaction, myTable) ||
+               myTransaction-&gt;execute(NdbTransaction::Commit)) {
       TRANSERROR(myTransaction);
       ndberror = myTransaction-&gt;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 &lt;&lt; "Retrying transaction..." &lt;&lt; std::endl;
-  sleep(TIME_TO_SLEEP_BETWEEN_TRANSACTION_RETRIES);
-  --noOfRetriesLeft;
-  result = 0;   // No completed transaction yet
-  break;
-  
+        std::cout &lt;&lt; "Retrying transaction..." &lt;&lt; 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 &lt;&lt; "No retry of transaction..." &lt;&lt; std::endl;
-  result = -1;  // Permanent failure
-  break;
+        std::cout &lt;&lt; "No retry of transaction..." &lt;&lt; std::endl;
+        result = -1;  // Permanent failure
+        break;
       }
     }
 
-    /**************************
-     * Close the transaction. *
-     **************************/
+    /*********************
+     * Close transaction *
+     *********************/
     if (myTransaction != NULL) {
       myNdb-&gt;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-&gt;connect(
-                      5 /* retries               */,
-                      3 /* delay between retries */,
-                      1 /* verbose               */);
+  int r= cluster_connection-&gt;connect(5 /* retries               */,
+                                     3 /* delay between retries */,
+                                     1 /* verbose               */);
   if (r &gt; 0)
   {
     std::cout
-      &lt;&lt; "Cluster connection failed, possibly resolved with more retries.\n";
+      &lt;&lt; "Cluster connect failed, possibly resolved with more retries.\n";
     exit(-1);
   }
   else if (r &lt; 0)
   {
     std::cout
-      &lt;&lt; "Cluster connection failed.\n";
+      &lt;&lt; "Cluster connect failed.\n";
     exit(-1);
   }
-             
+                                           
   if (cluster_connection-&gt;wait_until_ready(30,30))
   {
-    std::cout &lt;&lt; "Cluster was not ready within 30 seconds." &lt;&lt; std::endl;
+    std::cout &lt;&lt; "Cluster was not ready within 30 secs." &lt;&lt; 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-&gt;init() == -1) {
     APIERROR(myNdb-&gt;getNdbError());

@@ -591,9 +579,9 @@
     APIERROR(myDict-&gt;getNdbError());
     return -1;
   }
-  /*************************************
-   * Execute some insert transactions. *
-   *************************************/
+  /************************************
+   * Execute some insert transactions *
+   ************************************/
   for (int i = 10000; i &lt; 20000; i++) {
     executeInsertTransaction(i, myNdb, myTable);
   }

@@ -892,7 +880,6 @@
  * ndbapi_scan.cpp: Use of the NDB scanning API
  */
 
-
 #include &lt;mysql.h&gt;
 #include &lt;mysqld_error.h&gt;
 #include &lt;NdbApi.hpp&gt;

@@ -900,6 +887,9 @@
 #include &lt;iostream&gt;
 #include &lt;stdio.h&gt;
 
+/**
+ * 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 &lt;&lt; "Error in " &lt;&lt; __FILE__ &lt;&lt; ", line: " &lt;&lt; __LINE__ \
             &lt;&lt; ", code: " &lt;&lt; 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 &amp;mysql) 
+/**
+ * Function to create table
+ */
+int create_table(MYSQL &amp;mysql)
 {
-  while (mysql_query(&amp;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(&amp;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(&amp;mysql) != ER_TABLE_EXISTS_ERROR)
       MYSQLERROR(mysql);
-    std::cout &lt;&lt; "MySQL Cluster already has the example table GARAGE. "
-        &lt;&lt; "Now dropping it..." &lt;&lt; std::endl; 
-    /***************
-     * Drop table. *
-     ***************/
+    std::cout &lt;&lt; "MySQL Cluster already has example table: GARAGE. "
+              &lt;&lt; "Dropping it..." &lt;&lt; std::endl;
+    /**************
+     * Drop table *
+     **************/
     if (mysql_query(&amp;mysql, "DROP TABLE GARAGE"))
       MYSQLERROR(mysql);
   }

@@ -965,6 +965,9 @@
   if (myTable == NULL) 
     APIERROR(myDict-&gt;getNdbError());
 
+  /**
+   * Five blue mercedes
+   */
   for (i = 0; i &lt; 5; i++)
   {
     cars[i].reg_no = i;

@@ -972,6 +975,9 @@
     sprintf(cars[i].color, "Blue");
   }
 
+  /**
+   * Five black bmw
+   */
   for (i = 5; i &lt; 10; i++)
   {
     cars[i].reg_no = i;

@@ -979,6 +985,9 @@
     sprintf(cars[i].color, "Black");
   }
 
+  /**
+   * Five pink toyotas
+   */
   for (i = 10; i &lt; 15; i++)
   {
     cars[i].reg_no = i;

@@ -990,7 +999,7 @@
   if (myTrans == NULL)
     APIERROR(myNdb-&gt;getNdbError());
 
-  for (i = 0; i &lt; 15; i++) 
+  for (i = 0; i &lt; 15; i++)
   {
     NdbOperation* myNdbOperation = myTrans-&gt;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-&gt;getDictionary();
   const NdbDictionary::Table *myTable= myDict-&gt;getTable("GARAGE");

@@ -1030,11 +1039,21 @@
   if (myTable == NULL) 
     APIERROR(myDict-&gt;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 &gt;= retryMax)
     {
-      std::cout &lt;&lt; "ERROR: has retried this operation " &lt;&lt; retryAttempt  &lt;&lt; " times, failing!" &lt;&lt; std::endl;
+      std::cout &lt;&lt; "ERROR: has retried this operation " &lt;&lt; retryAttempt
+                &lt;&lt; " times, failing!" &lt;&lt; std::endl;
       return -1;
     }
 

@@ -1045,15 +1064,18 @@
 
       if (err.status == NdbError::TemporaryError)
       {
-  milliSleep(50);
-  retryAttempt++;
-  continue;
+        milliSleep(50);
+        retryAttempt++;
+        continue;
       }
       std::cout &lt;&lt;  err.message &lt;&lt; std::endl;
       return -1;
     }
 
-    myScanOp = myTrans-&gt;getNdbScanOperation(myTable); 
+   /**
+    * Get a scan operation.
+    */
+    myScanOp = myTrans-&gt;getNdbScanOperation(myTable);
     if (myScanOp == NULL) 
     {
       std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;

@@ -1061,6 +1083,9 @@
       return -1;
     }
 
+    /**
+     * Define a result set for the scan.
+     */ 
     if(myScanOp-&gt;readTuples(NdbOperation::LM_Exclusive) != 0)
     {
       std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;

@@ -1068,8 +1093,11 @@
       return -1;
     } 
     
+    /**
+     * Use NdbScanFilter to define a search critera
+     */ 
     NdbScanFilter filter(myScanOp) ;   
-    if(filter.begin(NdbScanFilter::AND) &lt; 0  || 
+    if(filter.begin(NdbScanFilter::AND) &lt; 0  ||
        filter.cmp(NdbScanFilter::COND_EQ, column, color) &lt; 0 ||
        filter.end() &lt; 0)
     {

@@ -1078,13 +1106,16 @@
       return -1;
     }    
     
-    if(myTrans-&gt;execute(NdbTransaction::NoCommit) != 0){      
-      err = myTrans-&gt;getNdbError();    
+    /**
+     * Start scan    (NoCommit since we are only reading at this stage);
+     */     
+    if(myTrans-&gt;execute(NdbTransaction::NoCommit) != 0){
+      err = myTrans-&gt;getNdbError();
       if(err.status == NdbError::TemporaryError){
-  std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-  myNdb-&gt;closeTransaction(myTrans);
-  milliSleep(50);
-  continue;
+        std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+        myNdb-&gt;closeTransaction(myTrans);
+        milliSleep(50);
+        continue;
       }
       std::cout &lt;&lt; err.code &lt;&lt; std::endl;
       std::cout &lt;&lt; myTrans-&gt;getNdbError().code &lt;&lt; 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-&gt;nextResult(true)) == 0){
       do 
       {
-  if (myScanOp-&gt;deleteCurrentTuple() != 0)
-  {
-    std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-    myNdb-&gt;closeTransaction(myTrans);
-    return -1;
-  }
-  deletedRows++;
-  
+        if (myScanOp-&gt;deleteCurrentTuple() != 0)
+        {
+          std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+          myNdb-&gt;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-&gt;nextResult(false)) == 0);
       
+      /**
+       * Commit when all cached tuple have been marked for deletion
+       */    
       if(check != -1)
       {
-  check = myTrans-&gt;execute(NdbTransaction::Commit);   
+        check = myTrans-&gt;execute(NdbTransaction::Commit);
       }
 
       if(check == -1)
       {
-  check = myTrans-&gt;restart();
+        /**
+         * Create a new transaction, while keeping scan open
+         */
+        check = myTrans-&gt;restart();
       }
 
-      err = myTrans-&gt;getNdbError();    
+      /**
+       * Check for errors
+       */
+      err = myTrans-&gt;getNdbError();
       if(check == -1)
       {
-  if(err.status == NdbError::TemporaryError)
-  {
-    std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-    myNdb-&gt;closeTransaction(myTrans);
-    milliSleep(50);
-    continue;
-  } 
+        if(err.status == NdbError::TemporaryError)
+        {
+          std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+          myNdb-&gt;closeTransaction(myTrans);
+          milliSleep(50);
+          continue;
+        }
       }
+      /**
+       * End of loop 
+       */
     }
     std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
     myNdb-&gt;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-&gt;getDictionary();
   const NdbDictionary::Table *myTable= myDict-&gt;getTable("GARAGE");

@@ -1165,13 +1217,22 @@
   if (myTable == NULL) 
     APIERROR(myDict-&gt;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 &gt;= retryMax)
     {
-      std::cout &lt;&lt; "ERROR: has retried this operation " &lt;&lt; retryAttempt 
-    &lt;&lt; " times, failing!" &lt;&lt; std::endl;
+      std::cout &lt;&lt; "ERROR: has retried this operation " &lt;&lt; retryAttempt
+                &lt;&lt; " times, failing!" &lt;&lt; std::endl;
       return -1;
     }
 

@@ -1182,15 +1243,18 @@
 
       if (err.status == NdbError::TemporaryError)
       {
-  milliSleep(50);
-  retryAttempt++;
-  continue;
+        milliSleep(50);
+        retryAttempt++;
+        continue;
       }
       std::cout &lt;&lt;  err.message &lt;&lt; std::endl;
       return -1;
     }
 
-    myScanOp = myTrans-&gt;getNdbScanOperation(myTable); 
+   /**
+    * Get a scan operation.
+    */
+    myScanOp = myTrans-&gt;getNdbScanOperation(myTable);
     if (myScanOp == NULL) 
     {
       std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;

@@ -1198,15 +1262,21 @@
       return -1;
     }
 
-    if( myScanOp-&gt;readTuples(NdbOperation::LM_Exclusive) ) 
+    /**
+     * Define a result set for the scan.
+     */ 
+    if( myScanOp-&gt;readTuples(NdbOperation::LM_Exclusive) )
     {
       std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
       myNdb-&gt;closeTransaction(myTrans);
       return -1;
     } 
 
+    /**
+     * Use NdbScanFilter to define a search critera
+     */ 
     NdbScanFilter filter(myScanOp) ;   
-    if(filter.begin(NdbScanFilter::AND) &lt; 0  || 
+    if(filter.begin(NdbScanFilter::AND) &lt; 0  ||
        filter.cmp(NdbScanFilter::COND_EQ, update_column, before_color) &lt;0||
        filter.end() &lt;0)
     {

@@ -1215,60 +1285,89 @@
       return -1;
     }    
     
+    /**
+     * Start scan    (NoCommit since we are only reading at this stage);
+     */     
     if(myTrans-&gt;execute(NdbTransaction::NoCommit) != 0)
     {      
-      err = myTrans-&gt;getNdbError();    
+      err = myTrans-&gt;getNdbError();
       if(err.status == NdbError::TemporaryError){
-  std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-  myNdb-&gt;closeTransaction(myTrans);
-  milliSleep(50);
-  continue;
+        std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+        myNdb-&gt;closeTransaction(myTrans);
+        milliSleep(50);
+        continue;
       }
       std::cout &lt;&lt; myTrans-&gt;getNdbError().code &lt;&lt; std::endl;
       myNdb-&gt;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-&gt;nextResult(true)) == 0){
       do {
-  NdbOperation * myUpdateOp = myScanOp-&gt;updateCurrentTuple();
-  if (myUpdateOp == 0)
-  {
-    std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-    myNdb-&gt;closeTransaction(myTrans);
-    return -1;
-  }
-  updatedRows++;
+        /**
+         * Get update operation
+         */
+        NdbOperation * myUpdateOp = myScanOp-&gt;updateCurrentTuple();
+        if (myUpdateOp == 0)
+        {
+          std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+          myNdb-&gt;closeTransaction(myTrans);
+          return -1;
+        }
+        updatedRows++;
 
-  myUpdateOp-&gt;setValue(update_column, after_color);
-  
+        /**
+         * do the update
+         */
+        myUpdateOp-&gt;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-&gt;nextResult(false)) == 0);
       
+      /**
+       * NoCommit when all cached tuple have been updated
+       */    
       if(check != -1)
       {
-  check = myTrans-&gt;execute(NdbTransaction::NoCommit);   
+        check = myTrans-&gt;execute(NdbTransaction::NoCommit);
       }
 
-      err = myTrans-&gt;getNdbError();    
+      /**
+       * Check for errors
+       */
+      err = myTrans-&gt;getNdbError();
       if(check == -1)
       {
-  if(err.status == NdbError::TemporaryError){
-    std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-    myNdb-&gt;closeTransaction(myTrans);
-    milliSleep(50);
-    continue;
-  } 
+        if(err.status == NdbError::TemporaryError){
+          std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+          myNdb-&gt;closeTransaction(myTrans);
+          milliSleep(50);
+          continue;
+        }
       }
+      /**
+       * End of loop 
+       */
     }
 
+    /**
+     * Commit all prepared operations
+     */
     if(myTrans-&gt;execute(NdbTransaction::Commit) == -1)
     {
       if(err.status == NdbError::TemporaryError){
-  std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-  myNdb-&gt;closeTransaction(myTrans);
-  milliSleep(50);
-  continue;
-      } 
+        std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+        myNdb-&gt;closeTransaction(myTrans);
+        milliSleep(50);
+        continue;
+      }        
     }
 
     std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; 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-&gt;getDictionary();
   const NdbDictionary::Table *myTable= myDict-&gt;getTable("GARAGE");

@@ -1311,13 +1408,22 @@
   if (myTable == NULL) 
     APIERROR(myDict-&gt;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 &gt;= retryMax)
     {
-      std::cout &lt;&lt; "ERROR: has retried this operation " &lt;&lt; retryAttempt 
-    &lt;&lt; " times, failing!" &lt;&lt; std::endl;
+      std::cout &lt;&lt; "ERROR: has retried this operation " &lt;&lt; retryAttempt
+                &lt;&lt; " times, failing!" &lt;&lt; std::endl;
       return -1;
     }
 

@@ -1328,18 +1434,18 @@
 
       if (err.status == NdbError::TemporaryError)
       {
-  milliSleep(50);
-  retryAttempt++;
-  continue;
+        milliSleep(50);
+        retryAttempt++;
+        continue;
       }
      std::cout &lt;&lt; err.message &lt;&lt; std::endl;
       return -1;
     }
     /*
      * Define a scan operation. 
-     * (NDBAPI.)
+     * NDBAPI.
      */
-    myScanOp = myTrans-&gt;getNdbScanOperation(myTable); 
+    myScanOp = myTrans-&gt;getNdbScanOperation(myTable);
     if (myScanOp == NULL) 
     {
       std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;

@@ -1347,6 +1453,9 @@
       return -1;
     }
 
+    /**
+     * Read without locks, without being placed in lock queue
+     */
     if( myScanOp-&gt;readTuples(NdbOperation::LM_CommittedRead) == -1)
     {
       std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;

@@ -1354,23 +1463,31 @@
       return -1;
     } 
 
+    /**
+     * Define storage for fetched attributes.
+     * E.g., the resulting attributes of executing
+     * myOp-&gt;getValue("REG_NO") is placed in myRecAttr[0].
+     * No data exists in myRecAttr until transaction has commited!
+     */
     myRecAttr[0] = myScanOp-&gt;getValue("REG_NO");
     myRecAttr[1] = myScanOp-&gt;getValue("BRAND");
     myRecAttr[2] = myScanOp-&gt;getValue("COLOR");
     if(myRecAttr[0] ==NULL || myRecAttr[1] == NULL || myRecAttr[2]==NULL) 
     {
-  std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-  myNdb-&gt;closeTransaction(myTrans);
-  return -1;
+        std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+        myNdb-&gt;closeTransaction(myTrans);
+        return -1;
     }
-    
-    if(myTrans-&gt;execute(NdbTransaction::NoCommit) != 0){      
-      err = myTrans-&gt;getNdbError();    
+    /**
+     * Start scan   (NoCommit since we are only reading at this stage);
+     */     
+    if(myTrans-&gt;execute(NdbTransaction::NoCommit) != 0){
+      err = myTrans-&gt;getNdbError();
       if(err.status == NdbError::TemporaryError){
-  std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
-  myNdb-&gt;closeTransaction(myTrans);
-  milliSleep(50);
-  continue;
+        std::cout &lt;&lt; myTrans-&gt;getNdbError().message &lt;&lt; std::endl;
+        myNdb-&gt;closeTransaction(myTrans);
+        milliSleep(50);
+        continue;
       }
       std::cout &lt;&lt; err.code &lt;&lt; std::endl;
       std::cout &lt;&lt; myTrans-&gt;getNdbError().code &lt;&lt; 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-&gt;nextResult(true)) == 0){
       do {
-  
-  fetchedRows++;
-  std::cout &lt;&lt; myRecAttr[0]-&gt;u_32_value() &lt;&lt; "\t";
+        
+        fetchedRows++;
+        /**
+         * print  REG_NO unsigned int
+         */
+        std::cout &lt;&lt; myRecAttr[0]-&gt;u_32_value() &lt;&lt; "\t";
 
-  std::cout &lt;&lt; myRecAttr[1]-&gt;aRef() &lt;&lt; "\t";
+        /**
+         * print  BRAND character string
+         */
+        std::cout &lt;&lt; myRecAttr[1]-&gt;aRef() &lt;&lt; "\t";
 
-  std::cout &lt;&lt; myRecAttr[2]-&gt;aRef() &lt;&lt; std::endl;
+        /**
+         * print  COLOR character string
+         */
+        std::cout &lt;&lt; myRecAttr[2]-&gt;aRef() &lt;&lt; std::endl;
 
+        /**
+         * nextResult(false) means that the records
+         * cached in the NDBAPI are modified before
+         * fetching more rows from NDB.
+         */
       } while((check = myScanOp-&gt;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(&amp;mysql) ) {

@@ -1413,7 +1548,7 @@
       exit(-1);
     }
     if ( !mysql_real_connect(&amp;mysql, "localhost", "root", "", "",
-           3306, "/tmp/mysql.sock", 0) )
+                             3306, "/tmp/mysql.sock", 0) )
       MYSQLERROR(mysql);
 
     mysql_query(&amp;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 &lt;&lt; "Unable to connect to cluster within 30 secs." &lt;&lt; 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) &lt; 0)
   {
     std::cout &lt;&lt; "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-&gt;getColumn("COLOR")-&gt;getLength() != sizeof(car.color) ||
-  t-&gt;getColumn("BRAND")-&gt;getLength() != sizeof(car.brand))
+        t-&gt;getColumn("BRAND")-&gt;getLength() != sizeof(car.brand))
     {
       std::cout &lt;&lt; "Wrong table definition" &lt;&lt; std::endl;
       exit(-1);

@@ -1472,6 +1607,9 @@
   std::cout &lt;&lt; "Going to delete all pink cars!" &lt;&lt; std::endl;
   
   {
+    /**
+     * Note! color needs to be of exact the same size as column defined
+     */
     Car tmp;
     sprintf(tmp.color, "Pink");
     if(scan_delete(&amp;myNdb, column_color, tmp.color) &gt; 0)

@@ -1482,12 +1620,15 @@
     std::cout &lt;&lt; "scan_print: Success!" &lt;&lt; std::endl  &lt;&lt; std::endl;
   
   {
+    /**
+     * Note! color1 &amp; 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 &lt;&lt; "Going to update all " &lt;&lt; tmp1.color 
-        &lt;&lt; " cars to " &lt;&lt; tmp2.color &lt;&lt; " cars!" &lt;&lt; std::endl;
-    if(scan_update(&amp;myNdb, column_color, tmp1.color, tmp2.color) &gt; 0) 
+    std::cout &lt;&lt; "Going to update all " &lt;&lt; tmp1.color
+              &lt;&lt; " cars to " &lt;&lt; tmp2.color &lt;&lt; " cars!" &lt;&lt; std::endl;
+    if(scan_update(&amp;myNdb, column_color, tmp1.color, tmp2.color) &gt; 0)
       std::cout &lt;&lt; "scan_update: Success!" &lt;&lt; std::endl  &lt;&lt; std::endl;
   }
   if(scan_print(&amp;myNdb) &gt; 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(&amp;mysql) ) {

@@ -1580,25 +1722,25 @@
       exit(-1);
     }
     if ( !mysql_real_connect(&amp;mysql, "localhost", "root", "", "",
-           3306, "/tmp/mysql.sock", 0) )
+                             3306, "/tmp/mysql.sock", 0) )
       MYSQLERROR(mysql);
 
     mysql_query(&amp;mysql, "CREATE DATABASE TEST_DB_1");
     if (mysql_query(&amp;mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
 
-    if (mysql_query(&amp;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(&amp;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-&gt;wait_until_ready(30,30))
   {
-    std::cout &lt;&lt; "Cluster was not ready within 30 seconds.\n";
+    std::cout &lt;&lt; "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-&gt;init() == -1) { 
+                        "TEST_DB_1" );  // Object representing the database
+  if (myNdb-&gt;init() == -1) {
     APIERROR(myNdb-&gt;getNdbError());
     exit(-1);
   }

@@ -1631,11 +1773,9 @@
   if (myIndex == NULL)
     APIERROR(myDict-&gt;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 &lt; 5; i++) {
     NdbTransaction *myTransaction= myNdb-&gt;startTransaction();
     if (myTransaction == NULL) APIERROR(myNdb-&gt;getNdbError());

@@ -1647,7 +1787,7 @@
     myOperation-&gt;equal("ATTR1", i);
     myOperation-&gt;setValue("ATTR2", i);
 
-    myOperation = myTransaction-&gt;getNdbOperation(myTable);  
+    myOperation = myTransaction-&gt;getNdbOperation(myTable);
     if (myOperation == NULL) APIERROR(myTransaction-&gt;getNdbError());
 
     myOperation-&gt;insertTuple();

@@ -1660,9 +1800,9 @@
     myNdb-&gt;closeTransaction(myTransaction);
   }
   
-  /**********************************************
-   * Read and print all tuples using the index. *
-   **********************************************/
+  /*****************************************
+   * Read and print all tuples using index *
+   *****************************************/
   std::cout &lt;&lt; "ATTR1 ATTR2" &lt;&lt; std::endl;
   
   for (int i = 0; i &lt; 10; i++) {

@@ -1685,10 +1825,9 @@
     myNdb-&gt;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 &lt; 10; i+=2) {
     NdbTransaction *myTransaction= myNdb-&gt;startTransaction();
     if (myTransaction == NULL) APIERROR(myNdb-&gt;getNdbError());

@@ -1701,16 +1840,15 @@
     myIndexOperation-&gt;equal( "ATTR2", i );
     myIndexOperation-&gt;setValue( "ATTR2", i+10);
     
-    if( myTransaction-&gt;execute( NdbTransaction::Commit ) == -1 ) 
+    if( myTransaction-&gt;execute( NdbTransaction::Commit ) == -1 )
       APIERROR(myTransaction-&gt;getNdbError());
     
     myNdb-&gt;closeTransaction(myTransaction);
   }
-    
-/**********************************************************
- * Delete one tuple (the one whose primary key equals 3). *
- **********************************************************/
- 
+  
+  /*************************************************
+   * Delete one tuple (the one with primary key 3) *
+   *************************************************/
   {
     NdbTransaction *myTransaction= myNdb-&gt;startTransaction();
     if (myTransaction == NULL) APIERROR(myNdb-&gt;getNdbError());

@@ -1722,15 +1860,15 @@
     myIndexOperation-&gt;deleteTuple();
     myIndexOperation-&gt;equal( "ATTR2", 3 );
   
-    if (myTransaction-&gt;execute(NdbTransaction::Commit) == -1) 
+    if (myTransaction-&gt;execute(NdbTransaction::Commit) == -1)
       APIERROR(myTransaction-&gt;getNdbError());
   
     myNdb-&gt;closeTransaction(myTransaction);
   }
 
-  /**********************************
-   * Read and print out all tuples. *
-   **********************************/
+  /*****************************
+   * Read and print all tuples *
+   *****************************/
   {
     std::cout &lt;&lt; "ATTR1 ATTR2" &lt;&lt; std::endl;
   

@@ -1748,23 +1886,22 @@
       if (myRecAttr == NULL) APIERROR(myTransaction-&gt;getNdbError());
     
       if(myTransaction-&gt;execute( NdbTransaction::Commit ) == -1)
-  if (i == 3) {
-    std::cout &lt;&lt; "Detected that deleted tuple doesn't exist!\n";
-  } else {
-    APIERROR(myTransaction-&gt;getNdbError());
-  }
+        if (i == 3) {
+          std::cout &lt;&lt; "Detected that deleted tuple doesn't exist!\n";
+        } else {
+          APIERROR(myTransaction-&gt;getNdbError());
+        }
     
       if (i != 3) {
-  printf(" %2d    %2d\n", i, myRecAttr-&gt;u_32_value());
+        printf(" %2d    %2d\n", i, myRecAttr-&gt;u_32_value());
       }
       myNdb-&gt;closeTransaction(myTransaction);
     }
   }
 
-  /*******************
-   * Drop the table. *
-   *******************/
-   
+  /**************
+   * Drop table *
+   **************/
   if (mysql_query(&amp;mysql, "DROP TABLE MYTABLENAME"))
     MYSQLERROR(mysql);
 

@@ -1808,7 +1945,7 @@
  */
 #include &lt;NdbApi.hpp&gt;
 
-// Used for cout.
+// Used for cout
 #include &lt;stdio.h&gt;
 #include &lt;iostream&gt;
 #include &lt;unistd.h&gt;

@@ -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&gt; mysql -u root
+ * mysql&gt; create database TEST_DB;
+ * mysql&gt; use TEST_DB;
+ * mysql&gt; 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 &lt;&lt; "Error in " &lt;&lt; __FILE__ &lt;&lt; ", line:" &lt;&lt; __LINE__ &lt;&lt; ", code:" \
               &lt;&lt; error.code &lt;&lt; ", msg: " &lt;&lt; error.message &lt;&lt; "." &lt;&lt; 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-&gt;connect(
-             5 /* retries               */,
-             3 /* delay between retries */,
-             1 /* verbose               */);
+  int r= cluster_connection-&gt;connect(5 /* retries               */,
+                                     3 /* delay between retries */,
+                                     1 /* verbose               */);
   if (r &gt; 0)
   {
     std::cout

@@ -1861,15 +2038,15 @@
       &lt;&lt; "Cluster connect failed.\n";
     exit(-1);
   }
-             
+        
   if (cluster_connection-&gt;wait_until_ready(30,30))
   {
-    std::cout &lt;&lt; "Cluster was not ready within 30 seconds." &lt;&lt; std::endl;
+    std::cout &lt;&lt; "Cluster was not ready within 30 secs." &lt;&lt; std::endl;
     exit(-1);
   }
 
   Ndb* myNdb= new Ndb(cluster_connection,
-          "TEST_DB");  // Object representing the database.
+                      "TEST_DB");  // Object representing the database
 
   if (myNdb-&gt;init() == -1) APIERROR(myNdb-&gt;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 &lt; 99) {
 
-    // Start "transaction" for handling events.
+    // Start "transaction" for handling events
     NdbEventOperation* op;
-    printf("Create EventOperation...\n");
+    printf("create EventOperation\n");
     if ((op = myNdb-&gt;createEventOperation(eventName)) == NULL)
       APIERROR(myNdb-&gt;getNdbError());
     op-&gt;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 &lt; noEventColumnName; i++) {
       if (i &lt; 4) {
         recAttr[i].ra    = op-&gt;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-&gt;execute())
       APIERROR(op-&gt;getNdbError());
 

@@ -1930,35 +2107,34 @@
 
     i= 0;
     while (i &lt; 40) {
-      // printf("Now waiting for event...\n");
-      int r = myNdb-&gt;pollEvents(1000);  //  Wait for the event (maximum 
-                                        //  1000 ms).
+      // printf("now waiting for event...\n");
+      int r = myNdb-&gt;pollEvents(1000); // wait for event or 1000 ms
       if (r &gt; 0) {
-  // printf("Got data! %d\n", r);
-  while ((op= myNdb-&gt;nextEvent())) {
+        // printf("got data! %d\n", r);
+        while ((op= myNdb-&gt;nextEvent())) {
           assert(the_op == op);
-    i++;
-    switch (op-&gt;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-&gt;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-&gt;getGCI());
           for (k = 0; k &lt;= 1; k++) {
             printf(k == 0 ? "post: " : "pre : ");
             for (l = 0; l &lt; noEventColumnName; l++) {
               if (l &lt; 4) {
                 NdbRecAttr* ra = k == 0 ? recAttr[l].ra : recAttrPre[l].ra;
-                if (ra-&gt;isNULL() &gt;= 0) { // We have a value.
-                  if (ra-&gt;isNULL() == 0) { // We have a non-null value.
+                if (ra-&gt;isNULL() &gt;= 0) { // we have a value
+                  if (ra-&gt;isNULL() == 0) { // we have a non-null value
                     if (l &lt; 2)
                       printf("%-5u", ra-&gt;u_32_value());
                     else

@@ -1971,15 +2147,15 @@
                 int isNull;
                 NdbBlob* bh = k == 0 ? recAttr[l].bh : recAttrPre[l].bh;
                 bh-&gt;getDefined(isNull);
-                if (isNull &gt;= 0) { // We have a value.
-                  if (! isNull) { // We have a non-null value.
+                if (isNull &gt;= 0) { // we have a value
+                  if (! isNull) { // we have a non-null value
                     Uint64 length = 0;
                     bh-&gt;getLength(length);
-                    // Read into buffer.
+                    // read into buffer
                     unsigned char* buf = new unsigned char [length];
                     memset(buf, 'X', length);
                     Uint32 n = length;
-                    bh-&gt;readData(buf, n); // n is in/out.
+                    bh-&gt;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-&gt;dropEventOperation(the_op)) APIERROR(myNdb-&gt;getNdbError());
     the_op = 0;
 

@@ -2018,7 +2194,7 @@
   {
     NdbDictionary::Dictionary *myDict = myNdb-&gt;getDictionary();
     if (!myDict) APIERROR(myNdb-&gt;getNdbError());
-    // Remove the event from the database.
+    // remove event from database
     if (myDict-&gt;dropEvent(eventName)) APIERROR(myDict-&gt;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-&gt;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-&gt;createEvent(myEvent) == 0)
     myEvent.print();
   else if (myDict-&gt;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-&gt;dropEvent(eventName)) APIERROR(myDict-&gt;getNdbError());
-    // Try again...
-    // Add the event to the database.
+    // try again
+    // Add event to database
     if ( myDict-&gt;createEvent(myEvent)) APIERROR(myDict-&gt;getNdbError());
   } else
     APIERROR(myDict-&gt;getNdbError());


Thread
svn commit - mysqldoc@docsrva: r2861 - trunk/ndbapijstephens28 Jul