List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:May 2 2007 2:59am
Subject:Rev 92: Removed -O2 from compilation. Screws things up for Java. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptions
View as plain text  
------------------------------------------------------------
revno: 92
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: exceptions
timestamp: Tue 2007-05-01 19:56:57 -0700
message:
  Removed -O2 from compilation. Screws things up for Java. 
  Further work on exceptions. It seems that throwing and catching a custom
    exception from JNI means that sometimes the exception doesn't get caught. But
    if I throw a custom exception and just catch "Exception" it works fine. Nice.
  Also fixed a bug in ndbapi_simple_index where it wasn't using BATCH_SIZE to 
    generate and index number for the lookup. Really need to backport the python
    version of that program to C++ again. 
modified:
  configure.in                   configure.in-20070228020914-u2pk759xg7thauwf-13
  java/Makefile.am               makefile.am-20070415032352-9dpe6aurqcnuwcrd-1
  java/ndbapi.i                  ndbapi.i-20070130002924-gcvhapmvh0lu1pkd-3
  java/test.java                 test.java-20070130002924-gcvhapmvh0lu1pkd-4
  java/testasync.java            test2.java-20070305174931-p3qddjy9i6h6y1f3-4
  python/Makefile.in             makefile.in-20070228070804-4lbbg6f7u1jytlqv-1
  python/test.py                
svn-v2:1@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-python%2ftest.py
  swig/Ndb.i                     ndb.i-20070228021421-qkr4cbpxymyqdrf3-1
  swig/NdbClusterConnection.i    ndb_cluster_connecti-20070228021421-qkr4cbpxymyqdrf3-6
  swig/NdbFactory.i              ndbfactory.i-20070427052328-bwn5ewzrbigsg9v5-1
  swig/NdbTransaction.i          ndbtransaction.i-20070227184716-ecjyhh3jgvmye4de-7
  swig/globals.i                 globals.i-20070228021421-qkr4cbpxymyqdrf3-7
  testndbapi/Makefile           
svn-v2:1@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-testndbapi%2fMakefile
  testndbapi/ndbapi_simple_index.cpp
svn-v2:1@5fca6d9a-db22-0410-b55c-899b0a28da89-trunk-testndbapi%2fndbapi_simple_index.cpp
=== modified file 'configure.in'
--- a/configure.in	2007-04-27 05:51:26 +0000
+++ b/configure.in	2007-05-02 02:56:57 +0000
@@ -1,6 +1,14 @@
 AC_INIT(ndb, 0.3.1)
 AM_INIT_AUTOMAKE(ndb, 0.3.1)
 
+# -02 causes problems per SWIG... although I think we should get that fixed
+if test -z $CXXFLAGS ; then 
+  CXXFLAGS="-O0 -g -Wall"
+fi 
+if test -z $CFLAGS ; then 
+  CFLAGS="-O0 -g -Wall"
+fi 
+
 #AC_CHECK_PROGS(SWIG,swig)
 AC_PROG_SWIG(1.3.31)
 SWIG_ENABLE_CXX
@@ -46,9 +54,8 @@
 
 SWIG_DIR="\${top_srcdir}/swig"
 
-SWIG="$SWIG \${DEFS} "
+SWIG="$SWIG \${DEFS} -DDOXYGEN_SHOULD_SKIP_INTERNAL=1 "
 
-AC_DEFINE(DOXYGEN_SHOULD_SKIP_INTERNAL,1)
 
 AC_SUBST(MYSQL_INCLUDES)
 AC_SUBST(SWIG_SOURCES)

=== modified file 'java/Makefile.am'
--- a/java/Makefile.am	2007-05-01 22:50:04 +0000
+++ b/java/Makefile.am	2007-05-02 02:56:57 +0000
@@ -8,11 +8,11 @@
 SUBDIRS = . com
 
 lib_LTLIBRARIES = libndbj.la libmgmj.la
-libndbj_la_SOURCES = $(NDBAPT_BUILT_SRC)
+libndbj_la_SOURCES = ndbapi_wrap.cxx
 libndbj_la_LIBADD = -lstdc++
 libndbj_la_LDFLAGS = -fpic
 libndbj_la_CPPFLAGS = $(JNI_INCLUDES) $(PTHREAD_CFLAGS)
-libmgmj_la_SOURCES = $(MGMAPI_BUILT_SRC)
+libmgmj_la_SOURCES = mgmapi_wrap.cxx
 libmgmj_la_CPPFLAGS = $(JNI_INCLUDES) $(PTHREAD_CFLAGS)
 
 %_wrap.cxx: %.i

=== modified file 'java/ndbapi.i'
--- a/java/ndbapi.i	2007-05-01 22:50:04 +0000
+++ b/java/ndbapi.i	2007-05-02 02:56:57 +0000
@@ -55,7 +55,7 @@
 
 }
 
-#define NDB_exception(excp, msg) { ndb_throw_exception(jenv, #excp,msg); } 
+#define NDB_exception(excp, msg) { ndb_throw_exception(jenv, #excp,msg);  } 
 
 void ndb_throw_exception(JNIEnv *jenv, const char * excp, const char *msg) { 
   const char * prefix = "com/mysql/cluster/ndbapi/";
@@ -99,7 +99,8 @@
 */
 %include "NdbFactory.i"
 
-%javaexception("com.mysql.cluster.ndbapi.NdbApiException")
Ndb_cluster_connection::connect;
+//%javaexception("com.mysql.cluster.ndbapi.NdbApiException")
Ndb_cluster_connection::connect;
+//%javaexception("com.mysql.cluster.ndbapi.NdbApiException")
Ndb_cluster_connection::wait_until_ready;
 
 %include "NdbClusterConnection.i"
 %include "Ndb.i"

=== modified file 'java/test.java'
--- a/java/test.java	2007-05-01 22:50:04 +0000
+++ b/java/test.java	2007-05-02 02:56:57 +0000
@@ -80,20 +80,24 @@
     NdbClusterConnection connection = NdbFactory.createNdbClusterConnection();
 
     try {
-    if (connection.connect(1,1,1)==-1) { 
-      System.out.println("Connect to cluster management server failed.");
-      System.exit(-1);
-    }
-    } catch (NdbApiException e) { 
+      connection.connect(1,1,1);
+      /*if (connection.connect(1,1,1)==-1) { 
+        throw new NdbApiException("Couldn't connect");
+      }*/
+    } catch (Exception e) { 
+      System.out.println("caught exception");
       System.out.println(e.getMessage());
       System.exit(-1);
     }
       
 
     
-    if (connection.wait_until_ready(30,30)==-1) {
-        System.out.println("Cluster was not ready within 30 secs.");
-    	System.exit(-1);
+    try { 
+      connection.wait_until_ready(30,30);
+    } catch (Exception e) {
+      System.out.println(e.getMessage());
+      System.out.println("Cluster was not ready within 30 secs.");
+      System.exit(-1);
     }
 
     Ndb myNdb = new Ndb(connection,"test" ) ;
@@ -114,8 +118,13 @@
 
     for(int t=0;t<Math.ceil(INSERT_NUM/BATCH_SIZE);t++) { 
 
-      NdbTransaction myTransaction = myNdb.startTransaction();
-
+      NdbTransaction myTransaction = null; 
+      try { 
+         myTransaction = myNdb.startTransaction();
+      } catch (Exception e) { 
+        System.out.println(e.getMessage());
+        System.exit(-1);
+      } 
       int val = ((t+1)*BATCH_SIZE)-INSERT_NUM;
       int offset = 0;
       if ( val > 0 ) {

=== modified file 'java/testasync.java'
--- a/java/testasync.java	2007-05-01 22:50:04 +0000
+++ b/java/testasync.java	2007-05-02 02:56:57 +0000
@@ -83,14 +83,16 @@
       System.out.println("Connect to cluster management server failed.");
       System.exit(-1);
     }
-    } catch (NdbApiException e) { 
+    } catch (Exception e) { 
       System.out.println(e.getMessage());
       System.exit(-1);
     }
       
 
     
-    if (connection.wait_until_ready(30,30)==-1) {
+    try { 
+       connection.wait_until_ready(30,30); 
+    } catch (Exception e) { 
         System.out.println("Cluster was not ready within 30 secs.");
     	System.exit(-1);
     }

=== modified file 'python/Makefile.in'
--- a/python/Makefile.in	2007-03-26 15:17:17 +0000
+++ b/python/Makefile.in	2007-05-02 02:56:57 +0000
@@ -15,7 +15,7 @@
 
 clean: 
 	${PYTHON} setup.py clean
-	rm -rf ndb_wrap.cpp ndbapi_wrap.cpp ndb.py _ndb.so ndbapi.py mysql/cluster/ndbapi.py
mysql/cluster/_ndbapi.so build *pyc
+	rm -rf ndbapi_wrap.cpp mgmapi_wrap.cpp mysql/cluster/ndbapi.py mysql/cluster/mgmapi.py
mysql/cluster/*.so build *pyc
 		
 distclean: clean
 	rm -rf Makefile setup.cfg python_ndbapi.egg-info

=== modified file 'python/test.py'
--- a/python/test.py	2007-05-01 22:50:04 +0000
+++ b/python/test.py	2007-05-02 02:56:57 +0000
@@ -45,7 +45,7 @@
 
   connection.connect(1,1,1)
 except mysql.cluster.ndbapi.NdbApiException,e:
-  print "Couldn't connect to cluster"
+  print e
   sys.exit(-1)
 
 if (connection.wait_until_ready(30,30)):

=== modified file 'swig/Ndb.i'
--- a/swig/Ndb.i	2007-05-01 22:50:04 +0000
+++ b/swig/Ndb.i	2007-05-02 02:56:57 +0000
@@ -18,8 +18,6 @@
 */
 
 
-%newobject Ndb::startTransaction; 
-
 class Ndb { 
 
 public:

=== modified file 'swig/NdbClusterConnection.i'
--- a/swig/NdbClusterConnection.i	2007-05-01 22:50:04 +0000
+++ b/swig/NdbClusterConnection.i	2007-05-02 02:56:57 +0000
@@ -21,30 +21,53 @@
 
 class Ndb_cluster_connection {
 
-public:
-
+  // NdbFactory.getNdbClusterConnection should be used instead
   Ndb_cluster_connection(const char * connectstring = 0);
   ~Ndb_cluster_connection();
 
-  %exception connect { 
+public:
+
+  void set_name(const char* name); 
+
+  %exception { 
     $action
       if (result) { 
 	const char * msg = "Connect to management server failed"; 
 	NDB_exception(NdbApiException,msg);
+        return -1;
       }
   }
-  %exception wait_until_ready { 
+  %typemap(check) int no_retries {
+    if ($1 < 0) { 
+      NDB_exception(NdbClusterConnectionPermanentException,"Retries must be greater than
or equal to zero.");
+      return -1;
+    }
+  }
+  %typemap(check) int retry_delay_in_seconds {
+    if ($1 < 0) { 
+      NDB_exception(NdbClusterConnectionPermanentException,"Delay must be greater than or
equal to zero.");
+      return -1;
+    }
+  }
+  %typemap(check) int verbose {
+    if ($1 < 0 || $1 > 1) { 
+      NDB_exception(NdbClusterConnectionPermanentException,"Verbose must be either zero
or one.");
+      return -1;
+    }
+  }
+  int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
+
+  %exception { 
     $action
       if (result) { 
         const char * msg = "Cluster was not ready";
 	NDB_exception(NdbApiException,msg);
       }
   }
-
-  int connect(int no_retries=0, int retry_delay_in_seconds=1, int verbose=0);
   int wait_until_ready(int timeout_for_first_alive,
 		       int timeout_after_first_alive);
-  void set_name(const char* name); 
+
+ 
 };
 
 %extend Ndb_cluster_connection {

=== modified file 'swig/NdbFactory.i'
--- a/swig/NdbFactory.i	2007-04-27 22:54:17 +0000
+++ b/swig/NdbFactory.i	2007-05-02 02:56:57 +0000
@@ -17,6 +17,7 @@
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
+%newobject NdbFactory::createNdbClusterConnection();
 
 %{
 
@@ -25,11 +26,17 @@
 public:
 static Ndb_cluster_connection * createNdbClusterConnection()
 {
-  return new Ndb_cluster_connection();
+  if (theConnection == NULL) { 
+    theConnection =  new Ndb_cluster_connection();
+  } 
+  return theConnection; 
 }
 static Ndb_cluster_connection * createNdbClusterConnection(const char * connectString)
 {
-  return new Ndb_cluster_connection(connectString);
+  if (theConnection == NULL) { 
+    theConnection =  new Ndb_cluster_connection(connectString);
+  }
+  return theConnection; 
 }
 
 };
@@ -38,9 +45,15 @@
 
 class NdbFactory
 {
-  // We list these here as private so that SWIG doesn't generate them
+  // We list these here as private so that SWIG doesnt generate them
   NdbFactory();
   ~NdbFactory();
 public:
+  %exception {
+    $action
+      if (result==NULL) {
+        NDB_exception(NdbApiException,"Couldn't allocate NdbClusterConnection");
+      }
+  }
   static Ndb_cluster_connection * createNdbClusterConnection(const char * connectString =
0);
 };

=== modified file 'swig/NdbTransaction.i'
--- a/swig/NdbTransaction.i	2007-05-01 22:50:04 +0000
+++ b/swig/NdbTransaction.i	2007-05-02 02:56:57 +0000
@@ -18,6 +18,7 @@
 */
 
 %delobject NdbTransaction::close;
+%newobject NdbTransaction::getNdbOperation;
 
 class NdbTransaction {
   ~NdbTransaction();

=== modified file 'swig/globals.i'
--- a/swig/globals.i	2007-05-01 22:50:04 +0000
+++ b/swig/globals.i	2007-05-02 02:56:57 +0000
@@ -21,6 +21,8 @@
     NoSuchTableException,
 };
 
+Ndb_cluster_connection * theConnection = NULL;
+
 %}
 
 %include "ndb_constants.h"

=== modified file 'testndbapi/Makefile'
--- a/testndbapi/Makefile	2007-04-24 23:41:52 +0000
+++ b/testndbapi/Makefile	2007-05-02 02:56:57 +0000
@@ -1,4 +1,4 @@
-TARGET = ndbapi_bug
+TARGET = ndbapi_simple_index
 SRCS = $(TARGET).cpp
 OBJS = $(TARGET).o
 CXX = g++

=== modified file 'testndbapi/ndbapi_simple_index.cpp'
--- a/testndbapi/ndbapi_simple_index.cpp	2007-01-30 21:02:20 +0000
+++ b/testndbapi/ndbapi_simple_index.cpp	2007-05-02 02:56:57 +0000
@@ -52,7 +52,7 @@
 
 int random_id = 0;
 
-#define NUM_ITER 100000
+#define NUM_ITER 1000
 #define INSERT_NUM 1000
 
 int main()
@@ -81,7 +81,7 @@
     if (mysql_query(&mysql, 
 		    "CREATE TABLE if not exists"
 		    "  MYTABLENAME"
-		    "    (ATTR1 INT UNSIGNED,"
+		    "    (ATTR1 INT UNSIGNED auto_increment,"
 		    "     ATTR2 INT UNSIGNED NOT NULL,"
 		    "     PRIMARY KEY USING HASH (ATTR1),"
 		    "     UNIQUE MYINDEXNAME USING HASH (ATTR2))"
@@ -217,7 +217,7 @@
     for(int i=0;i<NUM_ITER;i++){
       
       char buffer[50]; 
-      int id_num = ids[rand()%1000];
+      int id_num = ids[rand()%INSERT_NUM];
       sprintf(buffer,"select ATTR2 from MYTABLENAME where ATTR1=%d",
 	      id_num);
 

Thread
Rev 92: Removed -O2 from compilation. Screws things up for Java. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/exceptionsMonty Taylor2 May