Below is the list of changes that have just been committed into a local
5.1 repository of jonas. When jonas does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-06-12 14:22:44+02:00, jonas@stripped +3 -0
ndb -
add NDBAPI_50_COMPAT define that currently
1) defines AbortOption in NdbTransaction
2) tries to mimic 50-execute behaviour
storage/ndb/include/ndbapi/NdbTransaction.hpp@stripped, 2007-06-12 14:22:42+02:00, jonas@stripped +32 -0
add NDBAPI_50_COMPAT define
that currently
1) defines AbortOption in NdbTransaction
2) tries to mimic 50-execute behaviour
storage/ndb/test/ndbapi/Makefile.am@stripped, 2007-06-12 14:22:42+02:00, jonas@stripped +6 -1
add "old" testprg for testing of compat layer
storage/ndb/test/ndbapi/ndbapi_50compat0.cpp@stripped, 2007-06-12 14:22:42+02:00, jonas@stripped +278 -0
New BitKeeper file ``storage/ndb/test/ndbapi/ndbapi_50compat0.cpp''
storage/ndb/test/ndbapi/ndbapi_50compat0.cpp@stripped, 2007-06-12 14:22:42+02:00, jonas@stripped +0 -0
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: jonas
# Host: perch.ndb.mysql.com
# Root: /home/jonas/src/51-telco
--- New file ---
+++ storage/ndb/test/ndbapi/ndbapi_50compat0.cpp 07/06/12 14:22:42
/* Copyright (C) 2003 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
* ndbapi_simple.cpp: Using synchronous transactions in NDB API
*
* Correct output from this program is:
*
* ATTR1 ATTR2
* 0 10
* 1 1
* 2 12
* Detected that deleted tuple doesn't exist!
* 4 14
* 5 5
* 6 16
* 7 7
* 8 18
* 9 9
*
*/
#include <mysql.h>
#include <NdbApi.hpp>
// Used for cout
#include <stdio.h>
#include <NdbOut.hpp>
static void run_application(MYSQL &, Ndb_cluster_connection &);
#define PRINT_ERROR(code,msg) \
ndbout << "Error in " << __FILE__ << ", line: " << __LINE__ \
<< ", code: " << code \
<< ", msg: " << msg << "." << endl
#define MYSQLERROR(mysql) { \
PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \
exit(-1); }
#define APIERROR(error) { \
PRINT_ERROR(error.code,error.message); \
exit(-1); }
int main()
{
// ndb_init must be called first
ndb_init();
// connect to mysql server and cluster and run application
{
// Object representing the cluster
Ndb_cluster_connection cluster_connection;
// Connect to cluster management server (ndb_mgmd)
if (cluster_connection.connect(4 /* retries */,
5 /* delay between retries */,
1 /* verbose */))
{
ndbout << "Cluster management server was not ready within 30 secs.\n";
exit(-1);
}
// Optionally connect and wait for the storage nodes (ndbd's)
if (cluster_connection.wait_until_ready(30,0) < 0)
{
ndbout << "Cluster was not ready within 30 secs.\n";
exit(-1);
}
// connect to mysql server
MYSQL mysql;
if ( !mysql_init(&mysql) ) {
ndbout << "mysql_init failed\n";
exit(-1);
}
if ( !mysql_real_connect(&mysql, "localhost", "root", "", "",
3306, "/tmp/mysql.sock", 0) )
MYSQLERROR(mysql);
// run the application code
run_application(mysql, cluster_connection);
}
ndb_end(0);
ndbout << "\nTo drop created table use:\n"
<< "echo \"drop table MYTABLENAME\" | mysql TEST_DB_1 -u root\n";
return 0;
}
static void create_table(MYSQL &);
static void do_insert(Ndb &);
static void do_update(Ndb &);
static void do_delete(Ndb &);
static void do_read(Ndb &);
static void run_application(MYSQL &mysql,
Ndb_cluster_connection &cluster_connection)
{
/********************************************
* 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 NdbApi *
********************************************/
// Object representing the database
Ndb myNdb( &cluster_connection, "TEST_DB_1" );
if (myNdb.init()) APIERROR(myNdb.getNdbError());
/*
* Do different operations on database
*/
do_insert(myNdb);
do_update(myNdb);
do_delete(myNdb);
do_read(myNdb);
}
/*********************************************************
* 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"))
MYSQLERROR(mysql);
}
/**************************************************************************
* 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();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 5; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i);
myOperation->setValue("ATTR2", i);
myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->insertTuple();
myOperation->equal("ATTR1", i+5);
myOperation->setValue("ATTR2", i+5);
if (myTransaction->execute( NdbTransaction::Commit, NdbTransaction::AbortOnError, 1) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
/*****************************************************************
* Update the second attribute in half of the tuples (adding 10) *
*****************************************************************/
static void do_update(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
for (int i = 0; i < 10; i+=2) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->updateTuple();
myOperation->equal( "ATTR1", i );
myOperation->setValue( "ATTR2", i+10);
if( myTransaction->execute( NdbTransaction::Commit ) == -1 )
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
}
/*************************************************
* Delete one tuple (the one with primary key 3) *
*************************************************/
static void do_delete(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->deleteTuple();
myOperation->equal( "ATTR1", 3 );
if (myTransaction->execute(NdbTransaction::Commit) == -1)
APIERROR(myTransaction->getNdbError());
myNdb.closeTransaction(myTransaction);
}
/*****************************
* Read and print all tuples *
*****************************/
static void do_read(Ndb &myNdb)
{
const NdbDictionary::Dictionary* myDict= myNdb.getDictionary();
const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME");
if (myTable == NULL)
APIERROR(myDict->getNdbError());
ndbout << "ATTR1 ATTR2" << endl;
for (int i = 0; i < 10; i++) {
NdbTransaction *myTransaction= myNdb.startTransaction();
if (myTransaction == NULL) APIERROR(myNdb.getNdbError());
NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
if (myOperation == NULL) APIERROR(myTransaction->getNdbError());
myOperation->readTuple(NdbOperation::LM_Read);
myOperation->equal("ATTR1", i);
NdbRecAttr *myRecAttr= myOperation->getValue("ATTR2", NULL);
if (myRecAttr == NULL) APIERROR(myTransaction->getNdbError());
if(myTransaction->execute( NdbTransaction::Commit ) == -1)
if (i == 3) {
ndbout << "Detected that deleted tuple doesn't exist!" << endl;
} else {
APIERROR(myTransaction->getNdbError());
}
if (i != 3) {
printf(" %2d %2d\n", i, myRecAttr->u_32_value());
}
myNdb.closeTransaction(myTransaction);
}
}
--- 1.67/storage/ndb/include/ndbapi/NdbTransaction.hpp 2007-06-12 14:22:50 +02:00
+++ 1.68/storage/ndb/include/ndbapi/NdbTransaction.hpp 2007-06-12 14:22:50 +02:00
@@ -148,6 +148,17 @@
#endif
public:
+#ifdef NDBAPI_50_COMPAT
+ enum AbortOption {
+ DefaultAbortOption = NdbOperation::DefaultAbortOption,
+ CommitIfFailFree = NdbOperation::AbortOnError,
+ TryCommit = NdbOperation::AbortOnError,
+ AbortOnError= NdbOperation::AbortOnError,
+ CommitAsMuchAsPossible = NdbOperation::AO_IgnoreError,
+ AO_IgnoreError= NdbOperation::AO_IgnoreError
+ };
+#endif
+
/**
* Execution type of transaction
@@ -307,6 +318,7 @@
* the send.
* @return 0 if successful otherwise -1.
*/
+#ifndef NDBAPI_50_COMPAT
int execute(ExecType execType,
NdbOperation::AbortOption = NdbOperation::DefaultAbortOption,
int force = 0 );
@@ -317,6 +329,26 @@
return execute ((ExecType)execType,
(NdbOperation::AbortOption)abortOption,
force); }
+#endif
+#else
+ /**
+ * 50 compability layer
+ * Check 50-docs for sematics
+ */
+
+ int execute(ExecType execType, NdbOperation::AbortOption, int force);
+
+ int execute(NdbTransaction::ExecType execType,
+ NdbTransaction::AbortOption abortOption = AbortOnError,
+ int force = 0)
+ {
+ int ret = execute ((ExecType)execType,
+ (NdbOperation::AbortOption)abortOption,
+ force);
+ if (ret || (abortOption != AO_IgnoreError && theError.code))
+ return -1;
+ return 0;
+ }
#endif
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
--- 1.35/storage/ndb/test/ndbapi/Makefile.am 2007-06-12 14:22:50 +02:00
+++ 1.36/storage/ndb/test/ndbapi/Makefile.am 2007-06-12 14:22:50 +02:00
@@ -52,7 +52,8 @@
DbCreate DbAsyncGenerator \
testSRBank \
test_event_merge \
-testIndexStat
+testIndexStat \
+ndbapi_50compat0
EXTRA_PROGRAMS = \
test_event \
@@ -105,6 +106,10 @@
test_event_merge_SOURCES = test_event_merge.cpp
test_event_multi_table_SOURCES = test_event_multi_table.cpp
testIndexStat_SOURCES = testIndexStat.cpp
+
+ndbapi_50compat0_CPPFLAGS = -DNDBAPI_50_COMPAT
+ndbapi_50compat0_SOURCES = ndbapi_50compat0.cpp
+ndbapi_50compat0_LDADD = $(LDADD) $(top_srcdir)/libmysql/libmysqlclient.la
INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/include/kernel
| Thread |
|---|
| • bk commit into 5.1 tree (jonas:1.2533) | jonas | 12 Jun |