diff options
author | unknown <mskold/marty@linux.site> | 2006-09-01 15:26:03 +0200 |
---|---|---|
committer | unknown <mskold/marty@linux.site> | 2006-09-01 15:26:03 +0200 |
commit | d225ffd750928471cd8101669778ebb3e2662da3 (patch) | |
tree | f38a702387b93f32f4ee18de42b1a50e717b9123 /storage | |
parent | 72df0b3e303c457ce02ec1d6c839786c4cd53f22 (diff) | |
parent | 6138410cf08728e607e7bc80d8744953eeeef79a (diff) | |
download | mariadb-git-d225ffd750928471cd8101669778ebb3e2662da3.tar.gz |
Merge mysql.com:/windows/Linux_space/MySQL/mysql-5.1
into mysql.com:/windows/Linux_space/MySQL/mysql-5.1-new-ndb
sql/ha_ndbcluster.cc:
Auto merged
sql/ha_ndbcluster_binlog.cc:
Auto merged
storage/ndb/include/ndbapi/NdbTransaction.hpp:
Auto merged
storage/ndb/src/mgmapi/mgmapi.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp:
Auto merged
storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp:
Auto merged
storage/ndb/src/ndbapi/ndb_cluster_connection.cpp:
Auto merged
mysql-test/mysql-test-run.pl:
Merge
storage/ndb/include/ndbapi/ndb_cluster_connection.hpp:
Merge
Diffstat (limited to 'storage')
36 files changed, 1053 insertions, 185 deletions
diff --git a/storage/ndb/include/ndbapi/Ndb.hpp b/storage/ndb/include/ndbapi/Ndb.hpp index 07f11f6e78a..5c6ad76c063 100644 --- a/storage/ndb/include/ndbapi/Ndb.hpp +++ b/storage/ndb/include/ndbapi/Ndb.hpp @@ -1095,6 +1095,15 @@ public: #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** + * The current ndb_cluster_connection get_ndb_cluster_connection. + * + * @return the current connection + */ + Ndb_cluster_connection& get_ndb_cluster_connection(); +#endif + +#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL + /** * The current catalog name can be fetched by getCatalogName. * * @return the current catalog name diff --git a/storage/ndb/include/ndbapi/NdbTransaction.hpp b/storage/ndb/include/ndbapi/NdbTransaction.hpp index 3edb8c60c13..b3fb07d2905 100644 --- a/storage/ndb/include/ndbapi/NdbTransaction.hpp +++ b/storage/ndb/include/ndbapi/NdbTransaction.hpp @@ -735,6 +735,7 @@ private: Uint32 theTCConPtr; // Transaction Co-ordinator connection pointer. Uint64 theTransactionId; // theTransactionId of the transaction Uint32 theGlobalCheckpointId; // The gloabl checkpoint identity of the transaction + Uint64 *p_latest_trans_gci; // Reference to latest gci for connection ConStatusType theStatus; // The status of the connection enum CompletionStatus { NotCompleted, @@ -753,7 +754,7 @@ private: bool theTransactionIsStarted; bool theInUseState; bool theSimpleState; - Uint8 m_abortOption; // Type of commit + Uint8 m_abortOption; // Type of commi enum ListState { NotInList, diff --git a/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp b/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp index 8c8155d80ab..bc8993c4000 100644 --- a/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp +++ b/storage/ndb/include/ndbapi/ndb_cluster_connection.hpp @@ -115,6 +115,8 @@ public: void init_get_next_node(Ndb_cluster_connection_node_iter &iter); unsigned int get_next_node(Ndb_cluster_connection_node_iter &iter); unsigned get_active_ndb_objects() const; + + Uint64 *get_latest_trans_gci(); #endif private: diff --git a/storage/ndb/include/transporter/TransporterRegistry.hpp b/storage/ndb/include/transporter/TransporterRegistry.hpp index 0bb9733e8c4..89ae3a19e87 100644 --- a/storage/ndb/include/transporter/TransporterRegistry.hpp +++ b/storage/ndb/include/transporter/TransporterRegistry.hpp @@ -361,6 +361,7 @@ private: Uint32 poll_SHM(Uint32 timeOutMillis); int m_shm_own_pid; + int m_transp_count; }; #endif // Define of TransporterRegistry_H diff --git a/storage/ndb/ndbapi-examples/Makefile b/storage/ndb/ndbapi-examples/Makefile index 8e60857dc81..2a77cb20afe 100644 --- a/storage/ndb/ndbapi-examples/Makefile +++ b/storage/ndb/ndbapi-examples/Makefile @@ -5,7 +5,9 @@ BIN_DIRS := ndbapi_simple \ ndbapi_simple_index \ ndbapi_event \ ndbapi_scan \ - mgmapi_logevent + mgmapi_logevent \ + ndbapi_simple_dual \ + mgmapi_logevent_dual bins: $(patsubst %, _bins_%, $(BIN_DIRS)) diff --git a/storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile b/storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile index f96989c885c..c9b4507c4a7 100644 --- a/storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile +++ b/storage/ndb/ndbapi-examples/mgmapi_logevent/Makefile @@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../.. INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = diff --git a/storage/ndb/ndbapi-examples/mgmapi_logevent/mgmapi_logevent.cpp b/storage/ndb/ndbapi-examples/mgmapi_logevent/mgmapi_logevent.cpp index 5ec1fba6314..34db5e2ff8c 100644 --- a/storage/ndb/ndbapi-examples/mgmapi_logevent/mgmapi_logevent.cpp +++ b/storage/ndb/ndbapi-examples/mgmapi_logevent/mgmapi_logevent.cpp @@ -39,7 +39,7 @@ exit(-1); \ } -int main() +int main(int argc, char** argv) { NdbMgmHandle h; NdbLogEventHandle le; @@ -51,22 +51,36 @@ int main() 0 }; struct ndb_logevent event; + if (argc < 2) + { + printf("Arguments are <connect_string cluster> [<iterations>].\n"); + exit(-1); + } + const char *connectstring = argv[1]; + int iterations = -1; + if (argc > 2) + iterations = atoi(argv[2]); ndb_init(); - + h= ndb_mgm_create_handle(); if ( h == 0) { printf("Unable to create handle\n"); exit(-1); } + if (ndb_mgm_set_connectstring(h, connectstring) == -1) + { + printf("Unable to set connectstring\n"); + exit(-1); + } if (ndb_mgm_connect(h,0,0,0)) MGMERROR(h); le= ndb_mgm_create_logevent_handle(h, filter); if ( le == 0 ) MGMERROR(h); - while (1) + while (iterations-- != 0) { - int timeout= 5000; + int timeout= 1000; int r= ndb_logevent_get_next(le,&event,timeout); if (r == 0) printf("No event within %d milliseconds\n", timeout); diff --git a/storage/ndb/ndbapi-examples/mgmapi_logevent_dual/Makefile b/storage/ndb/ndbapi-examples/mgmapi_logevent_dual/Makefile new file mode 100644 index 00000000000..4a80a9fe087 --- /dev/null +++ b/storage/ndb/ndbapi-examples/mgmapi_logevent_dual/Makefile @@ -0,0 +1,24 @@ +TARGET = mgmapi_logevent_dual +SRCS = $(TARGET).cpp +OBJS = $(TARGET).o +CXX = g++ +CFLAGS = -c -Wall -fno-rtti -fno-exceptions +CXXFLAGS = +DEBUG = +LFLAGS = -Wall +TOP_SRCDIR = ../../../.. +INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include +LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ + -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ + -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings +SYS_LIB = + +$(TARGET): $(OBJS) + $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lmystrings -lz $(SYS_LIB) -o $(TARGET) + +$(TARGET).o: $(SRCS) + $(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/mgmapi -I$(INCLUDE_DIR)/ndbapi $(SRCS) + +clean: + rm -f *.o $(TARGET) diff --git a/storage/ndb/ndbapi-examples/mgmapi_logevent_dual/mgmapi_logevent_dual.cpp b/storage/ndb/ndbapi-examples/mgmapi_logevent_dual/mgmapi_logevent_dual.cpp new file mode 100644 index 00000000000..2073ec540d7 --- /dev/null +++ b/storage/ndb/ndbapi-examples/mgmapi_logevent_dual/mgmapi_logevent_dual.cpp @@ -0,0 +1,225 @@ +/* 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 */ + +#include <mysql.h> +#include <ndbapi/NdbApi.hpp> +#include <mgmapi.h> +#include <stdio.h> + +/* + * export LD_LIBRARY_PATH=../../../libmysql_r/.libs:../../../ndb/src/.libs + */ + +#define MGMERROR(h) \ +{ \ + fprintf(stderr, "code: %d msg: %s\n", \ + ndb_mgm_get_latest_error(h), \ + ndb_mgm_get_latest_error_msg(h)); \ + exit(-1); \ +} + +#define LOGEVENTERROR(h) \ +{ \ + fprintf(stderr, "code: %d msg: %s\n", \ + ndb_logevent_get_latest_error(h), \ + ndb_logevent_get_latest_error_msg(h)); \ + exit(-1); \ +} + +int main(int argc, char** argv) +{ + NdbMgmHandle h1,h2; + NdbLogEventHandle le1,le2; + int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, + 15, NDB_MGM_EVENT_CATEGORY_CONNECTION, + 15, NDB_MGM_EVENT_CATEGORY_NODE_RESTART, + 15, NDB_MGM_EVENT_CATEGORY_STARTUP, + 15, NDB_MGM_EVENT_CATEGORY_ERROR, + 0 }; + struct ndb_logevent event1, event2; + + if (argc < 3) + { + printf("Arguments are <connect_string cluster 1> <connect_string cluster 2> [<iterations>].\n"); + exit(-1); + } + const char *connectstring1 = argv[1]; + const char *connectstring2 = argv[2]; + int iterations = -1; + if (argc > 3) + iterations = atoi(argv[3]); + ndb_init(); + + h1= ndb_mgm_create_handle(); + h2= ndb_mgm_create_handle(); + if ( h1 == 0 || h2 == 0 ) + { + printf("Unable to create handle\n"); + exit(-1); + } + if (ndb_mgm_set_connectstring(h1, connectstring1) == -1 || + ndb_mgm_set_connectstring(h2, connectstring1)) + { + printf("Unable to set connectstring\n"); + exit(-1); + } + if (ndb_mgm_connect(h1,0,0,0)) MGMERROR(h1); + if (ndb_mgm_connect(h2,0,0,0)) MGMERROR(h2); + + if ((le1= ndb_mgm_create_logevent_handle(h1, filter)) == 0) MGMERROR(h1); + if ((le2= ndb_mgm_create_logevent_handle(h1, filter)) == 0) MGMERROR(h2); + + while (iterations-- != 0) + { + int timeout= 1000; + int r1= ndb_logevent_get_next(le1,&event1,timeout); + if (r1 == 0) + printf("No event within %d milliseconds\n", timeout); + else if (r1 < 0) + LOGEVENTERROR(le1) + else + { + switch (event1.type) { + case NDB_LE_BackupStarted: + printf("Node %d: BackupStarted\n", event1.source_nodeid); + printf(" Starting node ID: %d\n", event1.BackupStarted.starting_node); + printf(" Backup ID: %d\n", event1.BackupStarted.backup_id); + break; + case NDB_LE_BackupCompleted: + printf("Node %d: BackupCompleted\n", event1.source_nodeid); + printf(" Backup ID: %d\n", event1.BackupStarted.backup_id); + break; + case NDB_LE_BackupAborted: + printf("Node %d: BackupAborted\n", event1.source_nodeid); + break; + case NDB_LE_BackupFailedToStart: + printf("Node %d: BackupFailedToStart\n", event1.source_nodeid); + break; + + case NDB_LE_NodeFailCompleted: + printf("Node %d: NodeFailCompleted\n", event1.source_nodeid); + break; + case NDB_LE_ArbitResult: + printf("Node %d: ArbitResult\n", event1.source_nodeid); + printf(" code %d, arbit_node %d\n", + event1.ArbitResult.code & 0xffff, + event1.ArbitResult.arbit_node); + break; + case NDB_LE_DeadDueToHeartbeat: + printf("Node %d: DeadDueToHeartbeat\n", event1.source_nodeid); + printf(" node %d\n", event1.DeadDueToHeartbeat.node); + break; + + case NDB_LE_Connected: + printf("Node %d: Connected\n", event1.source_nodeid); + printf(" node %d\n", event1.Connected.node); + break; + case NDB_LE_Disconnected: + printf("Node %d: Disconnected\n", event1.source_nodeid); + printf(" node %d\n", event1.Disconnected.node); + break; + case NDB_LE_NDBStartCompleted: + printf("Node %d: StartCompleted\n", event1.source_nodeid); + printf(" version %d.%d.%d\n", + event1.NDBStartCompleted.version >> 16 & 0xff, + event1.NDBStartCompleted.version >> 8 & 0xff, + event1.NDBStartCompleted.version >> 0 & 0xff); + break; + case NDB_LE_ArbitState: + printf("Node %d: ArbitState\n", event1.source_nodeid); + printf(" code %d, arbit_node %d\n", + event1.ArbitState.code & 0xffff, + event1.ArbitResult.arbit_node); + break; + + default: + break; + } + } + + int r2= ndb_logevent_get_next(le1,&event2,timeout); + if (r2 == 0) + printf("No event within %d milliseconds\n", timeout); + else if (r2 < 0) + LOGEVENTERROR(le2) + else + { + switch (event2.type) { + case NDB_LE_BackupStarted: + printf("Node %d: BackupStarted\n", event2.source_nodeid); + printf(" Starting node ID: %d\n", event2.BackupStarted.starting_node); + printf(" Backup ID: %d\n", event2.BackupStarted.backup_id); + break; + case NDB_LE_BackupCompleted: + printf("Node %d: BackupCompleted\n", event2.source_nodeid); + printf(" Backup ID: %d\n", event2.BackupStarted.backup_id); + break; + case NDB_LE_BackupAborted: + printf("Node %d: BackupAborted\n", event2.source_nodeid); + break; + case NDB_LE_BackupFailedToStart: + printf("Node %d: BackupFailedToStart\n", event2.source_nodeid); + break; + + case NDB_LE_NodeFailCompleted: + printf("Node %d: NodeFailCompleted\n", event2.source_nodeid); + break; + case NDB_LE_ArbitResult: + printf("Node %d: ArbitResult\n", event2.source_nodeid); + printf(" code %d, arbit_node %d\n", + event2.ArbitResult.code & 0xffff, + event2.ArbitResult.arbit_node); + break; + case NDB_LE_DeadDueToHeartbeat: + printf("Node %d: DeadDueToHeartbeat\n", event2.source_nodeid); + printf(" node %d\n", event2.DeadDueToHeartbeat.node); + break; + + case NDB_LE_Connected: + printf("Node %d: Connected\n", event2.source_nodeid); + printf(" node %d\n", event2.Connected.node); + break; + case NDB_LE_Disconnected: + printf("Node %d: Disconnected\n", event2.source_nodeid); + printf(" node %d\n", event2.Disconnected.node); + break; + case NDB_LE_NDBStartCompleted: + printf("Node %d: StartCompleted\n", event2.source_nodeid); + printf(" version %d.%d.%d\n", + event2.NDBStartCompleted.version >> 16 & 0xff, + event2.NDBStartCompleted.version >> 8 & 0xff, + event2.NDBStartCompleted.version >> 0 & 0xff); + break; + case NDB_LE_ArbitState: + printf("Node %d: ArbitState\n", event2.source_nodeid); + printf(" code %d, arbit_node %d\n", + event2.ArbitState.code & 0xffff, + event2.ArbitResult.arbit_node); + break; + + default: + break; + } + } + } + + ndb_mgm_destroy_logevent_handle(&le1); + ndb_mgm_destroy_logevent_handle(&le2); + ndb_mgm_destroy_handle(&h1); + ndb_mgm_destroy_handle(&h2); + ndb_end(0); + return 0; +} diff --git a/storage/ndb/ndbapi-examples/ndbapi_async/Makefile b/storage/ndb/ndbapi-examples/ndbapi_async/Makefile index c5de3b06fc7..c18e9676b58 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_async/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_async/Makefile @@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = diff --git a/storage/ndb/ndbapi-examples/ndbapi_async/ndbapi_async.cpp b/storage/ndb/ndbapi-examples/ndbapi_async/ndbapi_async.cpp index aa745f4d28d..d0306b0c51d 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_async/ndbapi_async.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_async/ndbapi_async.cpp @@ -136,7 +136,12 @@ void closeTransaction(Ndb * ndb , async_callback_t * cb); /** * Function to create table */ -int create_table(Ndb * myNdb); +void create_table(MYSQL &mysql); + +/** + * Function to drop table + */ +void drop_table(MYSQL &mysql); /** * stat. variables @@ -193,7 +198,7 @@ callback(int result, NdbTransaction* trans, void* aObject) /** * Create table "GARAGE" */ -int create_table(MYSQL &mysql) +void create_table(MYSQL &mysql) { while (mysql_query(&mysql, "CREATE TABLE" @@ -208,15 +213,21 @@ int create_table(MYSQL &mysql) MYSQLERROR(mysql); std::cout << "MySQL Cluster already has example table: GARAGE. " << "Dropping it..." << std::endl; - /************** - * Drop table * - **************/ - if (mysql_query(&mysql, "DROP TABLE GARAGE")) - MYSQLERROR(mysql); + drop_table(mysql); + create_table(mysql); } - return 1; } +/** + * Drop table GARAGE + */ +void drop_table(MYSQL &mysql) +{ + if (mysql_query(&mysql, "DROP TABLE GARAGE")) + MYSQLERROR(mysql); +} + + void asynchExitHandler(Ndb * m_ndb) { if (m_ndb != NULL) @@ -339,16 +350,12 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) { transaction[current].conn = myNdb->startTransaction(); if (transaction[current].conn == NULL) { - if (asynchErrorHandler(transaction[current].conn, myNdb)) - { - /** - * no transaction to close since conn == null - */ - milliSleep(10); - retries++; - continue; - } - asynchExitHandler(myNdb); + /** + * no transaction to close since conn == null + */ + milliSleep(10); + retries++; + continue; } myNdbOperation = transaction[current].conn->getNdbOperation(myTable); if (myNdbOperation == NULL) @@ -406,8 +413,15 @@ int populate(Ndb * myNdb, int data, async_callback_t * cbData) return -1; } -int main() +int main(int argc, char** argv) { + if (argc != 3) + { + std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; + exit(-1); + } + char * mysqld_sock = argv[1]; + const char *connectstring = argv[2]; ndb_init(); MYSQL mysql; @@ -420,7 +434,7 @@ int main() exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", - 3306, "/tmp/mysql.sock", 0) ) + 0, mysqld_sock, 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE TEST_DB"); @@ -432,7 +446,7 @@ int main() /************************************************************** * Connect to ndb cluster * **************************************************************/ - Ndb_cluster_connection cluster_connection; + Ndb_cluster_connection cluster_connection(connectstring); if (cluster_connection.connect(4, 5, 1)) { std::cout << "Unable to connect to cluster within 30 secs." << std::endl; @@ -447,14 +461,14 @@ int main() Ndb* myNdb = new Ndb( &cluster_connection, "TEST_DB" ); // Object representing the database - if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions + if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb->getNdbError()); } /** * Initialise transaction array */ - for(int i = 0 ; i < 1024 ; i++) + for(int i = 0 ; i < 10 ; i++) { transaction[i].used = 0; transaction[i].conn = 0; @@ -462,9 +476,9 @@ int main() } int i=0; /** - * Do 20000 insert transactions. + * Do 10 insert transactions. */ - while(i < 20000) + while(i < 10) { while(populate(myNdb,i,0)<0) // <0, no space on free list. Sleep and try again. milliSleep(10); @@ -473,4 +487,6 @@ int main() } std::cout << "Number of temporary errors: " << tempErrors << std::endl; delete myNdb; + + drop_table(mysql); } diff --git a/storage/ndb/ndbapi-examples/ndbapi_async1/Makefile b/storage/ndb/ndbapi-examples/ndbapi_async1/Makefile index cc6bcebb71b..c88086157e7 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_async1/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_async1/Makefile @@ -6,9 +6,10 @@ CFLAGS = -c -Wall -fno-rtti -fno-exceptions DEBUG = LFLAGS = -Wall TOP_SRCDIR = ../../../.. -INCLUDE_DIR = $(TOP_SRCDIR) +INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = @@ -16,7 +17,7 @@ $(TARGET): $(OBJS) $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lmystrings -lz $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) - $(CXX) $(CFLAGS) -I$(INCLUDE_DIR)/storage/ndb/include -I$(INCLUDE_DIR)/storage/ndb/include/ndbapi $(SRCS) + $(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) clean: rm -f *.o $(TARGET) diff --git a/storage/ndb/ndbapi-examples/ndbapi_async1/ndbapi_async1.cpp b/storage/ndb/ndbapi-examples/ndbapi_async1/ndbapi_async1.cpp index e8bc19e267b..beb38ce771d 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_async1/ndbapi_async1.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_async1/ndbapi_async1.cpp @@ -17,38 +17,48 @@ // // ndbapi_async1.cpp: Using asynchronous transactions in NDB API // -// Execute ndbapi_example1 to create the table "MYTABLENAME" -// before executing this program. // // Correct output from this program is: // // Successful insert. // Successful insert. +#include <mysql.h> #include <NdbApi.hpp> // Used for cout #include <iostream> + +#define PRINT_ERROR(code,msg) \ + std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \ + << ", code: " << code \ + << ", msg: " << msg << "." << std::endl +#define MYSQLERROR(mysql) { \ + PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \ + exit(-1); } #define APIERROR(error) \ { std::cout << "Error in " << __FILE__ << ", line:" << __LINE__ << ", code:" \ << error.code << ", msg: " << error.message << "." << std::endl; \ exit(-1); } +static void create_table(MYSQL &); +static void drop_table(MYSQL &); static void callback(int result, NdbTransaction* NdbObject, void* aObject); -int main() +int main(int argc, char** argv) { - ndb_init(); - - Ndb_cluster_connection *cluster_connection= - new Ndb_cluster_connection(); // Object representing the cluster - - if (cluster_connection->wait_until_ready(30,30)) + if (argc != 3) { - std::cout << "Cluster was not ready within 30 secs." << std::endl; + std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; exit(-1); } + char * mysqld_sock = argv[1]; + const char *connectstring = argv[2]; + ndb_init(); + + Ndb_cluster_connection *cluster_connection= + new Ndb_cluster_connection(connectstring); // Object representing the cluster int r= cluster_connection->connect(5 /* retries */, 3 /* delay between retries */, @@ -65,15 +75,32 @@ int main() << "Cluster connect failed.\n"; exit(-1); } - - if (cluster_connection->wait_until_ready(30,30)) + + if (cluster_connection->wait_until_ready(30,0)) { std::cout << "Cluster was not ready within 30 secs." << std::endl; exit(-1); } + + // 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", "", "", + 0, mysqld_sock, 0) ) + MYSQLERROR(mysql); + + /******************************************** + * 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); Ndb* myNdb = new Ndb( cluster_connection, - "TEST_DB_2" ); // Object representing the database + "TEST_DB_1" ); // Object representing the database NdbTransaction* myNdbTransaction[2]; // For transactions NdbOperation* myNdbOperation; // For operations @@ -119,10 +146,38 @@ int main() delete myNdb; delete cluster_connection; + drop_table(mysql); + ndb_end(0); return 0; } +/********************************************************* + * 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); +} + +/*********************************** + * Drop a table named MYTABLENAME + ***********************************/ +static void drop_table(MYSQL &mysql) +{ + if (mysql_query(&mysql, + "DROP TABLE" + " MYTABLENAME")) + MYSQLERROR(mysql); +} + + /* * callback : This is called when the transaction is polled * diff --git a/storage/ndb/ndbapi-examples/ndbapi_event/Makefile b/storage/ndb/ndbapi-examples/ndbapi_event/Makefile index a3ca6fd61e3..c0430011ab6 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_event/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_event/Makefile @@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../.. INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = diff --git a/storage/ndb/ndbapi-examples/ndbapi_event/ndbapi_event.cpp b/storage/ndb/ndbapi-examples/ndbapi_event/ndbapi_event.cpp index 328d43caf28..ce568af3e1f 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_event/ndbapi_event.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_event/ndbapi_event.cpp @@ -117,16 +117,23 @@ int myCreateEvent(Ndb* myNdb, int main(int argc, char** argv) { + if (argc < 3) + { + std::cout << "Arguments are <connect_string cluster> <timeout> [m(merge events)|d(debug)].\n"; + exit(-1); + } + const char *connectstring = argv[1]; + int timeout = atoi(argv[2]); ndb_init(); - bool merge_events = argc > 1 && strchr(argv[1], 'm') != 0; + bool merge_events = argc > 3 && strchr(argv[3], 'm') != 0; #ifdef VM_TRACE - bool dbug = argc > 1 && strchr(argv[1], 'd') != 0; + bool dbug = argc > 3 && strchr(argv[3], 'd') != 0; if (dbug) DBUG_PUSH("d:t:"); if (dbug) putenv("API_SIGNAL_LOG=-"); #endif Ndb_cluster_connection *cluster_connection= - new Ndb_cluster_connection(); // Object representing the cluster + new Ndb_cluster_connection(connectstring); // Object representing the cluster int r= cluster_connection->connect(5 /* retries */, 3 /* delay between retries */, @@ -179,7 +186,7 @@ int main(int argc, char** argv) int i, j, k, l; j = 0; - while (j < 99) { + while (j < timeout) { // Start "transaction" for handling events NdbEventOperation* op; @@ -211,7 +218,7 @@ int main(int argc, char** argv) NdbEventOperation* the_op = op; i= 0; - while (i < 40) { + while (i < timeout) { // printf("now waiting for event...\n"); int r = myNdb->pollEvents(1000); // wait for event or 1000 ms if (r > 0) { @@ -287,7 +294,7 @@ int main(int argc, char** argv) } } } else - ;//printf("timed out\n"); + printf("timed out (%i)\n", timeout); } // don't want to listen to events anymore if (myNdb->dropEventOperation(the_op)) APIERROR(myNdb->getNdbError()); diff --git a/storage/ndb/ndbapi-examples/ndbapi_retries/Makefile b/storage/ndb/ndbapi-examples/ndbapi_retries/Makefile index 3dee4f77e35..1b4a316f406 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_retries/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_retries/Makefile @@ -6,9 +6,10 @@ CFLAGS = -c -Wall -fno-rtti -fno-exceptions DEBUG = LFLAGS = -Wall TOP_SRCDIR = ../../../.. -INCLUDE_DIR = ../../include +INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = @@ -16,7 +17,7 @@ $(TARGET): $(OBJS) $(CXX) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lmystrings -lz $(SYS_LIB) -o $(TARGET) $(TARGET).o: $(SRCS) - $(CXX) $(CFLAGS) -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) + $(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) clean: rm -f *.o $(TARGET) diff --git a/storage/ndb/ndbapi-examples/ndbapi_retries/ndbapi_retries.cpp b/storage/ndb/ndbapi-examples/ndbapi_retries/ndbapi_retries.cpp index 8c29fe31446..940a62c7080 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_retries/ndbapi_retries.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_retries/ndbapi_retries.cpp @@ -17,9 +17,6 @@ // // ndbapi_retries.cpp: Error handling and transaction retries // -// Execute ndbapi_simple to create the table "MYTABLENAME" -// before executing this program. -// // There are many ways to program using the NDB API. In this example // we execute two inserts in the same transaction using // NdbConnection::execute(NoCommit). @@ -29,6 +26,7 @@ // Application errors (i.e. errors at points marked with APIERROR) // should be handled by the application programmer. +#include <mysql.h> #include <NdbApi.hpp> // Used for cout @@ -38,6 +36,14 @@ #include <unistd.h> #define TIME_TO_SLEEP_BETWEEN_TRANSACTION_RETRIES 1 +#define PRINT_ERROR(code,msg) \ + std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \ + << ", code: " << code \ + << ", msg: " << msg << "." << std::endl +#define MYSQLERROR(mysql) { \ + PRINT_ERROR(mysql_errno(&mysql),mysql_error(&mysql)); \ + exit(-1); } + // // APIERROR prints an NdbError object // @@ -176,13 +182,44 @@ int executeInsertTransaction(int transactionId, Ndb* myNdb, return result; } +/********************************************************* + * 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); +} + +/*********************************** + * Drop a table named MYTABLENAME + ***********************************/ +static void drop_table(MYSQL &mysql) +{ + if (mysql_query(&mysql, + "DROP TABLE" + " MYTABLENAME")) + MYSQLERROR(mysql); +} -int main() +int main(int argc, char** argv) { + if (argc != 3) + { + std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; + exit(-1); + } + char * mysqld_sock = argv[1]; + const char *connectstring = argv[2]; ndb_init(); Ndb_cluster_connection *cluster_connection= - new Ndb_cluster_connection(); // Object representing the cluster + new Ndb_cluster_connection(connectstring); // Object representing the cluster int r= cluster_connection->connect(5 /* retries */, 3 /* delay between retries */, @@ -205,6 +242,22 @@ int main() std::cout << "Cluster was not ready within 30 secs." << std::endl; exit(-1); } + // 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", "", "", + 0, mysqld_sock, 0) ) + MYSQLERROR(mysql); + + /******************************************** + * 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); Ndb* myNdb= new Ndb( cluster_connection, "TEST_DB_1" ); // Object representing the database @@ -230,7 +283,9 @@ int main() delete myNdb; delete cluster_connection; - + + drop_table(mysql); + ndb_end(0); return 0; } diff --git a/storage/ndb/ndbapi-examples/ndbapi_scan/Makefile b/storage/ndb/ndbapi-examples/ndbapi_scan/Makefile index e3a7d9c97b0..30742509f75 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_scan/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_scan/Makefile @@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = diff --git a/storage/ndb/ndbapi-examples/ndbapi_scan/ndbapi_scan.cpp b/storage/ndb/ndbapi-examples/ndbapi_scan/ndbapi_scan.cpp index 69ffd99b8ca..8f1057f2531 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_scan/ndbapi_scan.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_scan/ndbapi_scan.cpp @@ -114,9 +114,19 @@ struct Car }; /** + * Function to drop table + */ +void drop_table(MYSQL &mysql) +{ + if (mysql_query(&mysql, "DROP TABLE GARAGE")) + MYSQLERROR(mysql); +} + + +/** * Function to create table */ -int create_table(MYSQL &mysql) +void create_table(MYSQL &mysql) { while (mysql_query(&mysql, "CREATE TABLE" @@ -131,16 +141,14 @@ int create_table(MYSQL &mysql) MYSQLERROR(mysql); std::cout << "MySQL Cluster already has example table: GARAGE. " << "Dropping it..." << std::endl; - /************** - * Drop table * - **************/ - if (mysql_query(&mysql, "DROP TABLE GARAGE")) - MYSQLERROR(mysql); + /****************** + * Recreate table * + ******************/ + drop_table(mysql); + create_table(mysql); } - return 1; } - int populate(Ndb * myNdb) { int i; @@ -721,8 +729,15 @@ int scan_print(Ndb * myNdb) } -int main() +int main(int argc, char** argv) { + if (argc != 3) + { + std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; + exit(-1); + } + char * mysqld_sock = argv[1]; + const char *connectstring = argv[2]; ndb_init(); MYSQL mysql; @@ -735,7 +750,7 @@ int main() exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", - 3306, "/tmp/mysql.sock", 0) ) + 0, mysqld_sock, 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE TEST_DB"); @@ -748,7 +763,7 @@ int main() * Connect to ndb cluster * **************************************************************/ - Ndb_cluster_connection cluster_connection; + Ndb_cluster_connection cluster_connection(connectstring); if (cluster_connection.connect(4, 5, 1)) { std::cout << "Unable to connect to cluster within 30 secs." << std::endl; @@ -821,5 +836,10 @@ int main() if(scan_print(&myNdb) > 0) std::cout << "scan_print: Success!" << std::endl << std::endl; + /** + * Drop table + */ + drop_table(mysql); + return 0; } diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple/Makefile b/storage/ndb/ndbapi-examples/ndbapi_simple/Makefile index b792c4c4a47..fa407fb7d63 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_simple/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_simple/Makefile @@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../.. INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp b/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp index 152d4fa44af..08e681755c6 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_simple/ndbapi_simple.cpp @@ -52,15 +52,22 @@ static void run_application(MYSQL &, Ndb_cluster_connection &); PRINT_ERROR(error.code,error.message); \ exit(-1); } -int main() +int main(int argc, char** argv) { + if (argc != 3) + { + std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; + exit(-1); + } // ndb_init must be called first ndb_init(); // connect to mysql server and cluster and run application { + char * mysqld_sock = argv[1]; + const char *connectstring = argv[2]; // Object representing the cluster - Ndb_cluster_connection cluster_connection; + Ndb_cluster_connection cluster_connection(connectstring); // Connect to cluster management server (ndb_mgmd) if (cluster_connection.connect(4 /* retries */, @@ -85,7 +92,7 @@ int main() exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", - 3306, "/tmp/mysql.sock", 0) ) + 0, mysqld_sock, 0) ) MYSQLERROR(mysql); // run the application code @@ -94,13 +101,11 @@ int main() ndb_end(0); - std::cout << "\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 drop_table(MYSQL &); static void do_insert(Ndb &); static void do_update(Ndb &); static void do_delete(Ndb &); @@ -130,6 +135,8 @@ static void run_application(MYSQL &mysql, do_update(myNdb); do_delete(myNdb); do_read(myNdb); + drop_table(mysql); + mysql_query(&mysql, "DROP DATABASE TEST_DB_1"); } /********************************************************* @@ -146,6 +153,17 @@ static void create_table(MYSQL &mysql) MYSQLERROR(mysql); } +/*********************************** + * Drop a table named MYTABLENAME + ***********************************/ +static void drop_table(MYSQL &mysql) +{ + if (mysql_query(&mysql, + "DROP TABLE" + " MYTABLENAME")) + MYSQLERROR(mysql); +} + /************************************************************************** * Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) * **************************************************************************/ diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple_dual/Makefile b/storage/ndb/ndbapi-examples/ndbapi_simple_dual/Makefile new file mode 100644 index 00000000000..7f0ca52fcc3 --- /dev/null +++ b/storage/ndb/ndbapi-examples/ndbapi_simple_dual/Makefile @@ -0,0 +1,24 @@ +TARGET = ndbapi_simple_dual +SRCS = $(TARGET).cpp +OBJS = $(TARGET).o +CXX = g++ +CFLAGS = -c -Wall -fno-rtti -fno-exceptions +CXXFLAGS = +DEBUG = +LFLAGS = -Wall +TOP_SRCDIR = ../../../.. +INCLUDE_DIR = $(TOP_SRCDIR)/storage/ndb/include +LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ + -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ + -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings +SYS_LIB = + +$(TARGET): $(OBJS) + $(CXX) $(CXXFLAGS) $(LFLAGS) $(LIB_DIR) $(OBJS) -lndbclient -lmysqlclient_r -lmysys -lmystrings -lz $(SYS_LIB) -o $(TARGET) + +$(TARGET).o: $(SRCS) + $(CXX) $(CFLAGS) -I$(TOP_SRCDIR)/include -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/ndbapi $(SRCS) + +clean: + rm -f *.o $(TARGET) diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple_dual/ndbapi_simple_dual.cpp b/storage/ndb/ndbapi-examples/ndbapi_simple_dual/ndbapi_simple_dual.cpp new file mode 100644 index 00000000000..838884f8090 --- /dev/null +++ b/storage/ndb/ndbapi-examples/ndbapi_simple_dual/ndbapi_simple_dual.cpp @@ -0,0 +1,348 @@ +/* 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_dual.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 + * 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 <iostream> + +static void run_application(MYSQL &, Ndb_cluster_connection &, const char* table, const char* db); + +#define PRINT_ERROR(code,msg) \ + std::cout << "Error in " << __FILE__ << ", line: " << __LINE__ \ + << ", code: " << code \ + << ", msg: " << msg << "." << std::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(int argc, char** argv) +{ + if (argc != 5) + { + std::cout << "Arguments are <socket mysqld1> <connect_string cluster 1> <socket mysqld2> <connect_string cluster 2>.\n"; + exit(-1); + } + // ndb_init must be called first + ndb_init(); + { + char * mysqld1_sock = argv[1]; + const char *connectstring1 = argv[2]; + char * mysqld2_sock = argv[3]; + const char *connectstring2 = argv[4]; + + // Object representing the cluster 1 + Ndb_cluster_connection cluster1_connection(connectstring1); + MYSQL mysql1; + // Object representing the cluster 2 + Ndb_cluster_connection cluster2_connection(connectstring2); + MYSQL mysql2; + + // connect to mysql server and cluster 1 and run application + // Connect to cluster 1 management server (ndb_mgmd) + if (cluster1_connection.connect(4 /* retries */, + 5 /* delay between retries */, + 1 /* verbose */)) + { + std::cout << "Cluster 1 management server was not ready within 30 secs.\n"; + exit(-1); + } + // Optionally connect and wait for the storage nodes (ndbd's) + if (cluster1_connection.wait_until_ready(30,0) < 0) + { + std::cout << "Cluster 1 was not ready within 30 secs.\n"; + exit(-1); + } + // connect to mysql server in cluster 1 + if ( !mysql_init(&mysql1) ) { + std::cout << "mysql_init failed\n"; + exit(-1); + } + if ( !mysql_real_connect(&mysql1, "localhost", "root", "", "", + 0, mysqld1_sock, 0) ) + MYSQLERROR(mysql1); + + + // connect to mysql server and cluster 2 and run application + + // Connect to cluster management server (ndb_mgmd) + if (cluster2_connection.connect(4 /* retries */, + 5 /* delay between retries */, + 1 /* verbose */)) + { + std::cout << "Cluster 2 management server was not ready within 30 secs.\n"; + exit(-1); + } + // Optionally connect and wait for the storage nodes (ndbd's) + if (cluster2_connection.wait_until_ready(30,0) < 0) + { + std::cout << "Cluster 2 was not ready within 30 secs.\n"; + exit(-1); + } + // connect to mysql server in cluster 2 + if ( !mysql_init(&mysql2) ) { + std::cout << "mysql_init failed\n"; + exit(-1); + } + if ( !mysql_real_connect(&mysql2, "localhost", "root", "", "", + 0, mysqld2_sock, 0) ) + MYSQLERROR(mysql2); + + // run the application code + run_application(mysql1, cluster1_connection, "MYTABLENAME1", "TEST_DB_1"); + run_application(mysql2, cluster2_connection, "MYTABLENAME2", "TEST_DB_2"); + } + // Note: all connections must have been destroyed before calling ndb_end() + ndb_end(0); + + return 0; +} + +static void create_table(MYSQL &, const char* table); +static void drop_table(MYSQL &, const char* table); +static void do_insert(Ndb &, const char* table); +static void do_update(Ndb &, const char* table); +static void do_delete(Ndb &, const char* table); +static void do_read(Ndb &, const char* table); + +static void run_application(MYSQL &mysql, + Ndb_cluster_connection &cluster_connection, + const char* table, + const char* db) +{ + /******************************************** + * Connect to database via mysql-c * + ********************************************/ + char db_stmt[256]; + sprintf(db_stmt, "CREATE DATABASE %s\n", db); + mysql_query(&mysql, db_stmt); + sprintf(db_stmt, "USE %s", db); + if (mysql_query(&mysql, db_stmt) != 0) MYSQLERROR(mysql); + create_table(mysql, table); + + /******************************************** + * Connect to database via NdbApi * + ********************************************/ + // Object representing the database + Ndb myNdb( &cluster_connection, db ); + if (myNdb.init()) APIERROR(myNdb.getNdbError()); + + /* + * Do different operations on database + */ + do_insert(myNdb, table); + do_update(myNdb, table); + do_delete(myNdb, table); + do_read(myNdb, table); + /* + * Drop the table + */ + drop_table(mysql, table); + sprintf(db_stmt, "DROP DATABASE %s\n", db); + mysql_query(&mysql, db_stmt); +} + +/********************************************************* + * Create a table named by table if it does not exist * + *********************************************************/ +static void create_table(MYSQL &mysql, const char* table) +{ + char create_stmt[256]; + + sprintf(create_stmt, "CREATE TABLE %s \ + (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY,\ + ATTR2 INT UNSIGNED NOT NULL)\ + ENGINE=NDB", table); + if (mysql_query(&mysql, create_stmt)) + MYSQLERROR(mysql); +} + +/******************************* + * Drop a table named by table + *******************************/ +static void drop_table(MYSQL &mysql, const char* table) +{ + char drop_stmt[256]; + + sprintf(drop_stmt, "DROP TABLE IF EXISTS %s", table); + if (mysql_query(&mysql, drop_stmt)) + MYSQLERROR(mysql); +} + +/************************************************************************** + * Using 5 transactions, insert 10 tuples in table: (0,0),(1,1),...,(9,9) * + **************************************************************************/ +static void do_insert(Ndb &myNdb, const char* table) +{ + const NdbDictionary::Dictionary* myDict= myNdb.getDictionary(); + const NdbDictionary::Table *myTable= myDict->getTable(table); + + 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 ) == -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 char* table) +{ + const NdbDictionary::Dictionary* myDict= myNdb.getDictionary(); + const NdbDictionary::Table *myTable= myDict->getTable(table); + + 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 char* table) +{ + const NdbDictionary::Dictionary* myDict= myNdb.getDictionary(); + const NdbDictionary::Table *myTable= myDict->getTable(table); + + 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 char* table) +{ + const NdbDictionary::Dictionary* myDict= myNdb.getDictionary(); + const NdbDictionary::Table *myTable= myDict->getTable(table); + + if (myTable == NULL) + APIERROR(myDict->getNdbError()); + + std::cout << "ATTR1 ATTR2" << std::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) { + std::cout << "Detected that deleted tuple doesn't exist!" << std::endl; + } else { + APIERROR(myTransaction->getNdbError()); + } + + if (i != 3) { + printf(" %2d %2d\n", i, myRecAttr->u_32_value()); + } + myNdb.closeTransaction(myTransaction); + } +} diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple_index/Makefile b/storage/ndb/ndbapi-examples/ndbapi_simple_index/Makefile index 3b3ac7f484a..c38975381f5 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_simple_index/Makefile +++ b/storage/ndb/ndbapi-examples/ndbapi_simple_index/Makefile @@ -10,6 +10,7 @@ TOP_SRCDIR = ../../../.. INCLUDE_DIR = $(TOP_SRCDIR) LIB_DIR = -L$(TOP_SRCDIR)/storage/ndb/src/.libs \ -L$(TOP_SRCDIR)/libmysql_r/.libs \ + -L$(TOP_SRCDIR)/zlib/.libs \ -L$(TOP_SRCDIR)/mysys -L$(TOP_SRCDIR)/strings SYS_LIB = diff --git a/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp b/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp index 5afaf6078d1..c1cc20f2ea1 100644 --- a/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp +++ b/storage/ndb/ndbapi-examples/ndbapi_simple_index/ndbapi_simple_index.cpp @@ -49,8 +49,15 @@ PRINT_ERROR(error.code,error.message); \ exit(-1); } -int main() +int main(int argc, char** argv) { + if (argc != 3) + { + std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; + exit(-1); + } + char * mysqld_sock = argv[1]; + const char *connectstring = argv[2]; ndb_init(); MYSQL mysql; @@ -63,7 +70,7 @@ int main() exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", - 3306, "/tmp/mysql.sock", 0) ) + 0, mysqld_sock, 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE TEST_DB_1"); @@ -85,7 +92,7 @@ int main() **************************************************************/ Ndb_cluster_connection *cluster_connection= - new Ndb_cluster_connection(); // Object representing the cluster + new Ndb_cluster_connection(connectstring); // Object representing the cluster if (cluster_connection->connect(5,3,1)) { @@ -110,7 +117,7 @@ int main() const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME"); if (myTable == NULL) APIERROR(myDict->getNdbError()); - const NdbDictionary::Index *myIndex= myDict->getIndex("MYINDEXNAME","MYTABLENAME"); + const NdbDictionary::Index *myIndex= myDict->getIndex("MYINDEXNAME$unique","MYTABLENAME"); if (myIndex == NULL) APIERROR(myDict->getNdbError()); diff --git a/storage/ndb/src/common/transporter/Packer.cpp b/storage/ndb/src/common/transporter/Packer.cpp index bcfac8417bb..e9da641de75 100644 --- a/storage/ndb/src/common/transporter/Packer.cpp +++ b/storage/ndb/src/common/transporter/Packer.cpp @@ -213,8 +213,8 @@ TransporterRegistry::unpack(Uint32 * readPtr, Uint32 * eodPtr, NodeId remoteNodeId, IOState state) { - static SignalHeader signalHeader; - static LinearSectionPtr ptr[3]; + SignalHeader signalHeader; + LinearSectionPtr ptr[3]; Uint32 loop_count = 0; if(state == NoHalt || state == HaltOutput){ while ((readPtr < eodPtr) && (loop_count < MAX_RECEIVED_SIGNALS)) { diff --git a/storage/ndb/src/common/transporter/TransporterRegistry.cpp b/storage/ndb/src/common/transporter/TransporterRegistry.cpp index 458f7c4f47e..4a0be702a86 100644 --- a/storage/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/storage/ndb/src/common/transporter/TransporterRegistry.cpp @@ -80,14 +80,15 @@ SocketServer::Session * TransporterService::newSession(NDB_SOCKET_TYPE sockfd) TransporterRegistry::TransporterRegistry(void * callback, unsigned _maxTransporters, - unsigned sizeOfLongSignalMemory) + unsigned sizeOfLongSignalMemory) : + m_mgm_handle(0), + m_transp_count(0) { DBUG_ENTER("TransporterRegistry::TransporterRegistry"); nodeIdSpecified = false; maxTransporters = _maxTransporters; sendCounter = 1; - m_mgm_handle= 0; callbackObj=callback; @@ -1002,7 +1003,6 @@ TransporterRegistry::performReceive() #endif } -static int x = 0; void TransporterRegistry::performSend() { @@ -1070,7 +1070,7 @@ TransporterRegistry::performSend() } #endif #ifdef NDB_TCP_TRANSPORTER - for (i = x; i < nTCPTransporters; i++) + for (i = m_transp_count; i < nTCPTransporters; i++) { TCP_Transporter *t = theTCPTransporters[i]; if (t && t->hasDataToSend() && t->isConnected() && @@ -1079,7 +1079,7 @@ TransporterRegistry::performSend() t->doSend(); } } - for (i = 0; i < x && i < nTCPTransporters; i++) + for (i = 0; i < m_transp_count && i < nTCPTransporters; i++) { TCP_Transporter *t = theTCPTransporters[i]; if (t && t->hasDataToSend() && t->isConnected() && @@ -1088,8 +1088,8 @@ TransporterRegistry::performSend() t->doSend(); } } - x++; - if (x == nTCPTransporters) x = 0; + m_transp_count++; + if (m_transp_count == nTCPTransporters) m_transp_count = 0; #endif #endif #ifdef NDB_SCI_TRANSPORTER diff --git a/storage/ndb/src/common/util/ndb_init.c b/storage/ndb/src/common/util/ndb_init.c index f3aa734d7f9..0c71a74371a 100644 --- a/storage/ndb/src/common/util/ndb_init.c +++ b/storage/ndb/src/common/util/ndb_init.c @@ -16,6 +16,16 @@ #include <ndb_global.h> #include <my_sys.h> +#include <NdbMutex.h> + +NdbMutex *g_ndb_connection_mutex = NULL; + +void +ndb_init_internal() +{ + if (!g_ndb_connection_mutex) + g_ndb_connection_mutex = NdbMutex_Create(); +} int ndb_init() @@ -25,11 +35,20 @@ ndb_init() write(2, err, strlen(err)); exit(1); } + ndb_init_internal(); return 0; } void +ndb_end_internal() +{ + if (g_ndb_connection_mutex) + NdbMutex_Destroy(g_ndb_connection_mutex); +} + +void ndb_end(int flags) { my_end(flags); + ndb_end_internal(); } diff --git a/storage/ndb/src/mgmapi/mgmapi.cpp b/storage/ndb/src/mgmapi/mgmapi.cpp index ed655ab1b7b..11d81fa0fdd 100644 --- a/storage/ndb/src/mgmapi/mgmapi.cpp +++ b/storage/ndb/src/mgmapi/mgmapi.cpp @@ -1194,7 +1194,7 @@ const unsigned int * ndb_mgm_get_clusterlog_severity_filter(NdbMgmHandle handle) { SET_ERROR(handle, NDB_MGM_NO_ERROR, "Executing: ndb_mgm_get_clusterlog_severity_filter"); - static unsigned int enabled[(int)NDB_MGM_EVENT_SEVERITY_ALL]= + unsigned int enabled[(int)NDB_MGM_EVENT_SEVERITY_ALL]= {0,0,0,0,0,0,0}; const ParserRow<ParserDummy> getinfo_reply[] = { MGM_CMD("clusterlog", NULL, ""), diff --git a/storage/ndb/src/ndbapi/Ndb.cpp b/storage/ndb/src/ndbapi/Ndb.cpp index 5eddbc35665..973b400f5a2 100644 --- a/storage/ndb/src/ndbapi/Ndb.cpp +++ b/storage/ndb/src/ndbapi/Ndb.cpp @@ -1172,6 +1172,12 @@ convertEndian(Uint32 Data) } // <internal> +Ndb_cluster_connection & +Ndb::get_ndb_cluster_connection() +{ + return theImpl->m_ndb_cluster_connection; +} + const char * Ndb::getCatalogName() const { return theImpl->m_dbname.c_str(); diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp index 9c2284e147c..6c8a447f627 100644 --- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -1303,8 +1303,6 @@ NdbDictionaryImpl::NdbDictionaryImpl(Ndb &ndb, m_local_table_data_size= 0; } -static int f_dictionary_count = 0; - NdbDictionaryImpl::~NdbDictionaryImpl() { NdbElement_t<Ndb_local_table_info> * curr = m_localHash.m_tableHash.getNext(0); @@ -1317,33 +1315,6 @@ NdbDictionaryImpl::~NdbDictionaryImpl() curr = m_localHash.m_tableHash.getNext(curr); } - - m_globalHash->lock(); - if(--f_dictionary_count == 0){ - delete NdbDictionary::Column::FRAGMENT; - delete NdbDictionary::Column::FRAGMENT_FIXED_MEMORY; - delete NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY; - delete NdbDictionary::Column::ROW_COUNT; - delete NdbDictionary::Column::COMMIT_COUNT; - delete NdbDictionary::Column::ROW_SIZE; - delete NdbDictionary::Column::RANGE_NO; - delete NdbDictionary::Column::DISK_REF; - delete NdbDictionary::Column::RECORDS_IN_RANGE; - delete NdbDictionary::Column::ROWID; - delete NdbDictionary::Column::ROW_GCI; - NdbDictionary::Column::FRAGMENT= 0; - NdbDictionary::Column::FRAGMENT_FIXED_MEMORY= 0; - NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY= 0; - NdbDictionary::Column::ROW_COUNT= 0; - NdbDictionary::Column::COMMIT_COUNT= 0; - NdbDictionary::Column::ROW_SIZE= 0; - NdbDictionary::Column::RANGE_NO= 0; - NdbDictionary::Column::DISK_REF= 0; - NdbDictionary::Column::RECORDS_IN_RANGE= 0; - NdbDictionary::Column::ROWID= 0; - NdbDictionary::Column::ROW_GCI= 0; - } - m_globalHash->unlock(); } else { assert(curr == 0); } @@ -1486,32 +1457,6 @@ NdbDictionaryImpl::setTransporter(class Ndb* ndb, { m_globalHash = &tf->m_globalDictCache; if(m_receiver.setTransporter(ndb, tf)){ - m_globalHash->lock(); - if(f_dictionary_count++ == 0){ - NdbDictionary::Column::FRAGMENT= - NdbColumnImpl::create_pseudo("NDB$FRAGMENT"); - NdbDictionary::Column::FRAGMENT_FIXED_MEMORY= - NdbColumnImpl::create_pseudo("NDB$FRAGMENT_FIXED_MEMORY"); - NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY= - NdbColumnImpl::create_pseudo("NDB$FRAGMENT_VARSIZED_MEMORY"); - NdbDictionary::Column::ROW_COUNT= - NdbColumnImpl::create_pseudo("NDB$ROW_COUNT"); - NdbDictionary::Column::COMMIT_COUNT= - NdbColumnImpl::create_pseudo("NDB$COMMIT_COUNT"); - NdbDictionary::Column::ROW_SIZE= - NdbColumnImpl::create_pseudo("NDB$ROW_SIZE"); - NdbDictionary::Column::RANGE_NO= - NdbColumnImpl::create_pseudo("NDB$RANGE_NO"); - NdbDictionary::Column::DISK_REF= - NdbColumnImpl::create_pseudo("NDB$DISK_REF"); - NdbDictionary::Column::RECORDS_IN_RANGE= - NdbColumnImpl::create_pseudo("NDB$RECORDS_IN_RANGE"); - NdbDictionary::Column::ROWID= - NdbColumnImpl::create_pseudo("NDB$ROWID"); - NdbDictionary::Column::ROW_GCI= - NdbColumnImpl::create_pseudo("NDB$ROW_GCI"); - } - m_globalHash->unlock(); return true; } return false; diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp index 31a9ab1f7bd..9f2a5844476 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp @@ -927,8 +927,6 @@ NdbEventOperationImpl::printAll() * Each Ndb object has a Object. */ -// ToDo ref count this so it get's destroyed -NdbMutex *NdbEventBuffer::p_add_drop_mutex= 0; NdbEventBuffer::NdbEventBuffer(Ndb *ndb) : m_system_nodes(ndb->theImpl->theNoOfDBnodes), @@ -940,7 +938,8 @@ NdbEventBuffer::NdbEventBuffer(Ndb *ndb) : m_max_free_thresh(100), m_gci_slip_thresh(3), m_dropped_ev_op(0), - m_active_op_count(0) + m_active_op_count(0), + m_add_drop_mutex(0) { #ifdef VM_TRACE m_latest_command= "NdbEventBuffer::NdbEventBuffer"; @@ -952,16 +951,6 @@ NdbEventBuffer::NdbEventBuffer(Ndb *ndb) : exit(-1); } m_mutex= ndb->theImpl->theWaiter.m_mutex; - lock(); - if (p_add_drop_mutex == 0) - { - if ((p_add_drop_mutex = NdbMutex_Create()) == NULL) { - ndbout_c("NdbEventBuffer: NdbMutex_Create() failed"); - exit(-1); - } - } - unlock(); - // ToDo set event buffer size // pre allocate event data array m_sz= 0; @@ -971,6 +960,10 @@ NdbEventBuffer::NdbEventBuffer(Ndb *ndb) : m_free_data= 0; m_free_data_sz= 0; + // get reference to mutex managed by current connection + m_add_drop_mutex= + m_ndb->theImpl->m_ndb_cluster_connection.m_event_add_drop_mutex; + // initialize lists bzero(&g_empty_gci_container, sizeof(Gci_container)); init_gci_containers(); @@ -1008,14 +1001,6 @@ NdbEventBuffer::~NdbEventBuffer() } NdbCondition_Destroy(p_cond); - - lock(); - if (p_add_drop_mutex) - { - NdbMutex_Destroy(p_add_drop_mutex); - p_add_drop_mutex = 0; - } - unlock(); } void diff --git a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp index b245c676199..0d6618a7365 100644 --- a/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp +++ b/storage/ndb/src/ndbapi/NdbEventOperationImpl.hpp @@ -407,8 +407,8 @@ public: void dropEventOperation(NdbEventOperation *); static NdbEventOperationImpl* getEventOperationImpl(NdbEventOperation* tOp); - void add_drop_lock() { NdbMutex_Lock(p_add_drop_mutex); } - void add_drop_unlock() { NdbMutex_Unlock(p_add_drop_mutex); } + void add_drop_lock() { NdbMutex_Lock(m_add_drop_mutex); } + void add_drop_unlock() { NdbMutex_Unlock(m_add_drop_mutex); } void lock() { NdbMutex_Lock(m_mutex); } void unlock() { NdbMutex_Unlock(m_mutex); } @@ -510,6 +510,7 @@ private: NdbEventOperationImpl *m_dropped_ev_op; Uint32 m_active_op_count; + NdbMutex *m_add_drop_mutex; }; inline diff --git a/storage/ndb/src/ndbapi/NdbTransaction.cpp b/storage/ndb/src/ndbapi/NdbTransaction.cpp index 916135b12d5..9788b9bdce6 100644 --- a/storage/ndb/src/ndbapi/NdbTransaction.cpp +++ b/storage/ndb/src/ndbapi/NdbTransaction.cpp @@ -32,8 +32,6 @@ #include <signaldata/TcKeyFailConf.hpp> #include <signaldata/TcHbRep.hpp> -Uint64 g_latest_trans_gci = 0; - /***************************************************************************** NdbTransaction( Ndb* aNdb ); @@ -64,6 +62,7 @@ NdbTransaction::NdbTransaction( Ndb* aNdb ) : theTCConPtr(0), theTransactionId(0), theGlobalCheckpointId(0), + p_latest_trans_gci(0), theStatus(NotConnected), theCompletionStatus(NotCompleted), theCommitStatus(NotStarted), @@ -129,6 +128,8 @@ NdbTransaction::init() theCompletedLastOp = NULL; theGlobalCheckpointId = 0; + p_latest_trans_gci = + theNdb->theImpl->m_ndb_cluster_connection.get_latest_trans_gci(); theCommitStatus = Started; theCompletionStatus = NotCompleted; m_abortOption = AbortOnError; @@ -1572,7 +1573,7 @@ NdbTransaction::receiveTC_COMMITCONF(const TcCommitConf * commitConf) theGlobalCheckpointId = commitConf->gci; // theGlobalCheckpointId == 0 if NoOp transaction if (theGlobalCheckpointId) - g_latest_trans_gci = theGlobalCheckpointId; + *p_latest_trans_gci = theGlobalCheckpointId; return 0; } else { #ifdef NDB_NO_DROPPED_SIGNAL @@ -1752,7 +1753,7 @@ from other transactions. theCommitStatus = Committed; theGlobalCheckpointId = tGCI; assert(tGCI); - g_latest_trans_gci = tGCI; + *p_latest_trans_gci = tGCI; } else if ((tNoComp >= tNoSent) && (theLastExecOpInList->theCommitIndicator == 1)){ @@ -1930,7 +1931,7 @@ NdbTransaction::receiveTCINDXCONF(const TcIndxConf * indxConf, theCommitStatus = Committed; theGlobalCheckpointId = tGCI; assert(tGCI); - g_latest_trans_gci = tGCI; + *p_latest_trans_gci = tGCI; } else if ((tNoComp >= tNoSent) && (theLastExecOpInList->theCommitIndicator == 1)){ /**********************************************************************/ diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp index 97af326d95c..b7c43bf81c9 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection.cpp @@ -35,8 +35,6 @@ #include <EventLogger.hpp> EventLogger g_eventLogger; -static int g_run_connect_thread= 0; - #include <NdbMutex.h> #ifdef VM_TRACE NdbMutex *ndb_print_state_mutex= NULL; @@ -87,8 +85,9 @@ const char *Ndb_cluster_connection::get_connectstring(char *buf, pthread_handler_t run_ndb_cluster_connection_connect_thread(void *me) { - g_run_connect_thread= 1; - ((Ndb_cluster_connection_impl*) me)->connect_thread(); + Ndb_cluster_connection_impl* connection= (Ndb_cluster_connection_impl*) me; + connection->m_run_connect_thread= 1; + connection->connect_thread(); return me; } @@ -258,9 +257,6 @@ unsigned Ndb_cluster_connection::get_connect_count() const return m_impl.get_connect_count(); } - - - /* * Ndb_cluster_connection_impl */ @@ -269,11 +265,17 @@ Ndb_cluster_connection_impl::Ndb_cluster_connection_impl(const char * connect_string) : Ndb_cluster_connection(*this), m_optimized_node_selection(1), - m_name(0) + m_name(0), + m_run_connect_thread(0), + m_event_add_drop_mutex(0), + m_latest_trans_gci(0) { DBUG_ENTER("Ndb_cluster_connection"); DBUG_PRINT("enter",("Ndb_cluster_connection this=0x%x", this)); + if (!m_event_add_drop_mutex) + m_event_add_drop_mutex= NdbMutex_Create(); + g_eventLogger.createConsoleHandler(); g_eventLogger.setCategory("NdbApi"); g_eventLogger.enable(Logger::LL_ON, Logger::LL_ERROR); @@ -301,6 +303,33 @@ Ndb_cluster_connection_impl::Ndb_cluster_connection_impl(const char * } m_transporter_facade= new TransporterFacade(); + NdbMutex_Lock(g_ndb_connection_mutex); + if(g_ndb_connection_count++ == 0){ + NdbDictionary::Column::FRAGMENT= + NdbColumnImpl::create_pseudo("NDB$FRAGMENT"); + NdbDictionary::Column::FRAGMENT_FIXED_MEMORY= + NdbColumnImpl::create_pseudo("NDB$FRAGMENT_FIXED_MEMORY"); + NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY= + NdbColumnImpl::create_pseudo("NDB$FRAGMENT_VARSIZED_MEMORY"); + NdbDictionary::Column::ROW_COUNT= + NdbColumnImpl::create_pseudo("NDB$ROW_COUNT"); + NdbDictionary::Column::COMMIT_COUNT= + NdbColumnImpl::create_pseudo("NDB$COMMIT_COUNT"); + NdbDictionary::Column::ROW_SIZE= + NdbColumnImpl::create_pseudo("NDB$ROW_SIZE"); + NdbDictionary::Column::RANGE_NO= + NdbColumnImpl::create_pseudo("NDB$RANGE_NO"); + NdbDictionary::Column::DISK_REF= + NdbColumnImpl::create_pseudo("NDB$DISK_REF"); + NdbDictionary::Column::RECORDS_IN_RANGE= + NdbColumnImpl::create_pseudo("NDB$RECORDS_IN_RANGE"); + NdbDictionary::Column::ROWID= + NdbColumnImpl::create_pseudo("NDB$ROWID"); + NdbDictionary::Column::ROW_GCI= + NdbColumnImpl::create_pseudo("NDB$ROW_GCI"); + } + NdbMutex_Unlock(g_ndb_connection_mutex); + DBUG_VOID_RETURN; } @@ -314,7 +343,7 @@ Ndb_cluster_connection_impl::~Ndb_cluster_connection_impl() if (m_connect_thread) { void *status; - g_run_connect_thread= 0; + m_run_connect_thread= 0; NdbThread_WaitFor(m_connect_thread, &status); NdbThread_Destroy(&m_connect_thread); m_connect_thread= 0; @@ -339,6 +368,36 @@ Ndb_cluster_connection_impl::~Ndb_cluster_connection_impl() if (m_name) free(m_name); + NdbMutex_Lock(g_ndb_connection_mutex); + if(--g_ndb_connection_count == 0){ + delete NdbDictionary::Column::FRAGMENT; + delete NdbDictionary::Column::FRAGMENT_FIXED_MEMORY; + delete NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY; + delete NdbDictionary::Column::ROW_COUNT; + delete NdbDictionary::Column::COMMIT_COUNT; + delete NdbDictionary::Column::ROW_SIZE; + delete NdbDictionary::Column::RANGE_NO; + delete NdbDictionary::Column::DISK_REF; + delete NdbDictionary::Column::RECORDS_IN_RANGE; + delete NdbDictionary::Column::ROWID; + delete NdbDictionary::Column::ROW_GCI; + NdbDictionary::Column::FRAGMENT= 0; + NdbDictionary::Column::FRAGMENT_FIXED_MEMORY= 0; + NdbDictionary::Column::FRAGMENT_VARSIZED_MEMORY= 0; + NdbDictionary::Column::ROW_COUNT= 0; + NdbDictionary::Column::COMMIT_COUNT= 0; + NdbDictionary::Column::ROW_SIZE= 0; + NdbDictionary::Column::RANGE_NO= 0; + NdbDictionary::Column::DISK_REF= 0; + NdbDictionary::Column::RECORDS_IN_RANGE= 0; + NdbDictionary::Column::ROWID= 0; + NdbDictionary::Column::ROW_GCI= 0; + } + NdbMutex_Unlock(g_ndb_connection_mutex); + + if (m_event_add_drop_mutex) + NdbMutex_Destroy(m_event_add_drop_mutex); + DBUG_VOID_RETURN; } @@ -576,17 +635,23 @@ void Ndb_cluster_connection_impl::connect_thread() if (r == -1) { printf("Ndb_cluster_connection::connect_thread error\n"); DBUG_ASSERT(false); - g_run_connect_thread= 0; + m_run_connect_thread= 0; } else { // Wait before making a new connect attempt NdbSleep_SecSleep(1); } - } while (g_run_connect_thread); + } while (m_run_connect_thread); if (m_connect_callback) (*m_connect_callback)(); DBUG_VOID_RETURN; } +Uint64 * +Ndb_cluster_connection::get_latest_trans_gci() +{ + m_impl.get_latest_trans_gci(); +} + void Ndb_cluster_connection::init_get_next_node(Ndb_cluster_connection_node_iter &iter) { diff --git a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp index 6f0df0403d9..5b350dca7ba 100644 --- a/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp +++ b/storage/ndb/src/ndbapi/ndb_cluster_connection_impl.hpp @@ -20,6 +20,10 @@ #include <ndb_cluster_connection.hpp> #include <Vector.hpp> +#include <NdbMutex.h> + +extern NdbMutex *g_ndb_connection_mutex; +static int g_ndb_connection_count = 0; class TransporterFacade; class ConfigRetriever; @@ -41,6 +45,9 @@ class Ndb_cluster_connection_impl : public Ndb_cluster_connection Uint32 get_next_node(Ndb_cluster_connection_node_iter &iter); inline unsigned get_connect_count() const; +public: + inline Uint64 *get_latest_trans_gci() { return &m_latest_trans_gci; } + private: friend class Ndb; friend class NdbImpl; @@ -72,6 +79,9 @@ private: int m_optimized_node_selection; char *m_name; + int m_run_connect_thread; + NdbMutex *m_event_add_drop_mutex; + Uint64 m_latest_trans_gci; }; #endif |