summaryrefslogtreecommitdiff
path: root/ndb/src/ndbapi/Ndb.cpp
diff options
context:
space:
mode:
authorunknown <monty@mishka.local>2004-12-22 13:54:39 +0200
committerunknown <monty@mishka.local>2004-12-22 13:54:39 +0200
commitbb2d3eaa30a3881927142c985fb637aca06d9823 (patch)
tree8e5f08b17957f896c2d4e931e60b57d99c260ed6 /ndb/src/ndbapi/Ndb.cpp
parent52d080f09979deb2063a8010feee3b925a3d7938 (diff)
parent5c79810a6d3ca19254c310f1519664729367b647 (diff)
downloadmariadb-git-bb2d3eaa30a3881927142c985fb637aca06d9823.tar.gz
Merge with 4.1
BitKeeper/etc/ignore: auto-union BitKeeper/etc/logging_ok: auto-union Build-tools/Do-compile: Auto merged VC++Files/sql/mysqld.dsp: Auto merged client/Makefile.am: Auto merged client/mysql.cc: Auto merged BitKeeper/deleted/.del-acinclude.m4~f4ab416bac5003: Auto merged client/mysqltest.c: Auto merged include/my_base.h: Auto merged innobase/dict/dict0dict.c: Auto merged innobase/dict/dict0load.c: Auto merged innobase/include/dict0dict.h: Auto merged innobase/include/row0mysql.h: Auto merged innobase/os/os0file.c: Auto merged innobase/srv/srv0srv.c: Auto merged libmysql/libmysql.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_rnext_same.c: Auto merged myisam/mi_write.c: Auto merged myisam/sort.c: Auto merged mysql-test/mysql-test-run.sh: Auto merged mysql-test/r/ctype_ucs.result: Auto merged mysql-test/r/ctype_ujis.result: Auto merged mysql-test/r/gis-rtree.result: Auto merged mysql-test/r/group_by.result: Auto merged mysql-test/r/merge.result: Auto merged mysql-test/r/metadata.result: Auto merged mysql-test/r/ndb_alter_table.result: Auto merged mysql-test/r/ps_1general.result: Auto merged mysql-test/r/insert_update.result: Auto merged mysql-test/r/timezone2.result: Auto merged mysql-test/r/type_enum.result: Auto merged mysql-test/r/variables.result: Auto merged mysql-test/t/ctype_ucs.test: Auto merged mysql-test/t/merge.test: Auto merged mysql-test/t/ps_1general.test: Auto merged mysql-test/t/subselect.test: Auto merged mysql-test/t/system_mysql_db_fix.test: Auto merged mysql-test/t/variables.test: Auto merged ndb/include/ndbapi/NdbConnection.hpp: Auto merged ndb/include/ndbapi/NdbDictionary.hpp: Auto merged ndb/src/common/util/version.c: Auto merged ndb/src/kernel/blocks/dbacc/DbaccInit.cpp: Auto merged ndb/src/kernel/blocks/dbacc/Makefile.am: Auto merged ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Auto merged ndb/src/kernel/blocks/dbdih/DbdihMain.cpp: Auto merged ndb/src/kernel/blocks/dblqh/DblqhInit.cpp: Auto merged ndb/src/kernel/blocks/dbtc/DbtcMain.cpp: Auto merged ndb/src/kernel/blocks/dbtux/Dbtux.hpp: Auto merged ndb/src/ndbapi/NdbBlob.cpp: Auto merged ndb/src/ndbapi/NdbConnection.cpp: Auto merged ndb/src/ndbapi/NdbDictionary.cpp: Auto merged ndb/src/ndbapi/NdbDictionaryImpl.cpp: Auto merged ndb/src/ndbapi/NdbDictionaryImpl.hpp: Auto merged ndb/src/ndbapi/NdbOperationExec.cpp: Auto merged ndb/src/ndbapi/NdbScanOperation.cpp: Auto merged ndb/test/ndbapi/Makefile.am: Auto merged scripts/make_win_src_distribution.sh: Auto merged scripts/mysql_install_db.sh: Auto merged sql/field.cc: Auto merged sql/ha_innodb.cc: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/ha_ndbcluster.h: Auto merged sql/handler.cc: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_create.h: Auto merged sql/item_func.cc: Auto merged sql/item_geofunc.cc: Auto merged sql/item_row.cc: Auto merged sql/item_strfunc.cc: Auto merged sql/item_strfunc.h: Auto merged sql/item_sum.cc: Auto merged sql/item_sum.h: Auto merged sql/log.cc: Auto merged sql/log_event.cc: Auto merged sql/mysqld.cc: Auto merged sql/net_serv.cc: Auto merged sql/password.c: Auto merged sql/protocol.cc: Auto merged sql/repl_failsafe.cc: Auto merged sql/set_var.cc: Auto merged sql/slave.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_cache.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_derived.cc: Auto merged sql/sql_do.cc: Auto merged sql/sql_handler.cc: Auto merged sql/sql_help.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_repl.cc: Auto merged sql/sql_show.cc: Auto merged sql/sql_union.cc: Auto merged sql/examples/ha_archive.cc: Auto merged sql/strfunc.cc: Auto merged sql/table.cc: Auto merged sql/table.h: Auto merged sql/tztime.h: Auto merged sql/udf_example.cc: Auto merged sql/unireg.cc: Auto merged Makefile.am: Simple merge client/mysqldump.c: Simple merge configure.in: Simple merge libmysqld/lib_sql.cc: Automatic merge mysql-test/r/func_str.result: Automatic merge mysql-test/r/grant.result: simple merge mysql-test/r/multi_update.result: automatc merge mysql-test/r/ps.result: automatic merge mysql-test/r/ps_2myisam.result: Automatic merge mysql-test/r/ps_3innodb.result: Automatic merge mysql-test/r/ps_4heap.result: Automatic merge mysql-test/r/ps_5merge.result: Automatic merge mysql-test/r/ps_6bdb.result: Automatic merge mysql-test/r/ps_7ndb.result: Automatic merge mysql-test/r/show_check.result: Automatic merge mysql-test/r/subselect.result: Automatic merge mysql-test/t/grant.test: Automatic merge mysql-test/t/multi_update.test: Automatic merge mysql-test/t/ps.test: Automatic merge mysql-test/t/show_check.test: Automatic merge ndb/docs/wl2077.txt: merge ndb/src/mgmsrv/main.cpp: merge scripts/mysql_fix_privilege_tables.sh: merge sql/item.cc: Merge (difficult) sql/item.h: simple merge sql/item_cmpfunc.h: Automatic merge sql/item_subselect.cc: Simple merge sql/item_subselect.h: Automatic merge sql/mysql_priv.h: Simple merge sql/slave.h: Automatic merge sql/sql_base.cc: Removed code that was backported to 4.1 sql/sql_class.h: Merge (some code moved to sql_insert.cc) sql/sql_db.cc: simple merge sql/sql_insert.cc: Merge (difficult as logic had changed both in 4.1 and 5.0) Some coded moved here from sql_class.h sql/sql_parse.cc: Merge (difficult) sql/sql_prepare.cc: Simple merge sql/sql_select.cc: Automatic merge sql/sql_table.cc: Simple merge sql/sql_update.cc: Difficult merge because of different logic for multi-updates sql/sql_yacc.yy: Simple merge tests/client_test.c: Simple merge
Diffstat (limited to 'ndb/src/ndbapi/Ndb.cpp')
-rw-r--r--ndb/src/ndbapi/Ndb.cpp283
1 files changed, 62 insertions, 221 deletions
diff --git a/ndb/src/ndbapi/Ndb.cpp b/ndb/src/ndbapi/Ndb.cpp
index 75ae539fc8b..e9a125922c6 100644
--- a/ndb/src/ndbapi/Ndb.cpp
+++ b/ndb/src/ndbapi/Ndb.cpp
@@ -22,7 +22,7 @@ Name: Ndb.cpp
******************************************************************************/
#include <ndb_global.h>
-#include <pthread.h>
+
#include "NdbApiSignal.hpp"
#include "NdbImpl.hpp"
@@ -46,7 +46,6 @@ Connect to any node which has no connection at the moment.
NdbConnection* Ndb::doConnect(Uint32 tConNode)
{
Uint32 tNode;
- Uint32 i = 0;;
Uint32 tAnyAlive = 0;
int TretCode;
@@ -65,38 +64,51 @@ NdbConnection* Ndb::doConnect(Uint32 tConNode)
// We will connect to any node. Make sure that we have connections to all
// nodes.
//****************************************************************************
- Uint32 tNoOfDbNodes = theNoOfDBnodes;
- i = theCurrentConnectIndex;
- UintR Tcount = 0;
- do {
- if (i >= tNoOfDbNodes) {
- i = 0;
- }//if
- Tcount++;
- tNode = theDBnodes[i];
- TretCode = NDB_connect(tNode);
- if ((TretCode == 1) || (TretCode == 2)) {
+ if (theImpl->m_optimized_node_selection)
+ {
+ Ndb_cluster_connection_node_iter &node_iter=
+ theImpl->m_node_iter;
+ theImpl->m_ndb_cluster_connection.init_get_next_node(node_iter);
+ while ((tNode= theImpl->m_ndb_cluster_connection.get_next_node(node_iter)))
+ {
+ TretCode= NDB_connect(tNode);
+ if ((TretCode == 1) ||
+ (TretCode == 2))
+ {
//****************************************************************************
// We have connections now to the desired node. Return
//****************************************************************************
- if (theCurrentConnectIndex == i) {
- theCurrentConnectCounter++;
- if (theCurrentConnectCounter == 8) {
- theCurrentConnectCounter = 1;
- theCurrentConnectIndex++;
- }//if
- } else {
- // Set to 2 because we have already connected to a node
- // when we get here.
- theCurrentConnectCounter = 2;
- theCurrentConnectIndex = i;
+ return getConnectedNdbConnection(tNode);
+ } else if (TretCode != 0) {
+ tAnyAlive= 1;
}//if
- return getConnectedNdbConnection(tNode);
- } else if (TretCode != 0) {
- tAnyAlive = 1;
- }//if
- i++;
- } while (Tcount < tNoOfDbNodes);
+ }
+ }
+ else // just do a regular round robin
+ {
+ Uint32 tNoOfDbNodes= theImpl->theNoOfDBnodes;
+ Uint32 &theCurrentConnectIndex= theImpl->theCurrentConnectIndex;
+ UintR Tcount = 0;
+ do {
+ theCurrentConnectIndex++;
+ if (theCurrentConnectIndex >= tNoOfDbNodes)
+ theCurrentConnectIndex = 0;
+
+ Tcount++;
+ tNode= theImpl->theDBnodes[theCurrentConnectIndex];
+ TretCode= NDB_connect(tNode);
+ if ((TretCode == 1) ||
+ (TretCode == 2))
+ {
+//****************************************************************************
+// We have connections now to the desired node. Return
+//****************************************************************************
+ return getConnectedNdbConnection(tNode);
+ } else if (TretCode != 0) {
+ tAnyAlive= 1;
+ }//if
+ } while (Tcount < tNoOfDbNodes);
+ }
//****************************************************************************
// We were unable to find a free connection. If no node alive we will report
// error code for cluster failure otherwise connection failure.
@@ -161,8 +173,8 @@ Ndb::NDB_connect(Uint32 tNode)
tReturnCode = tp->sendSignal(tSignal, tNode);
releaseSignal(tSignal);
if (tReturnCode != -1) {
- theWaiter.m_node = tNode;
- theWaiter.m_state = WAIT_TC_SEIZE;
+ theImpl->theWaiter.m_node = tNode;
+ theImpl->theWaiter.m_state = WAIT_TC_SEIZE;
tReturnCode = receiveResponse();
}//if
} else {
@@ -211,8 +223,9 @@ Ndb::doDisconnect()
NdbConnection* tNdbCon;
CHECK_STATUS_MACRO_VOID;
- DBUG_PRINT("info", ("theNoOfDBnodes=%d", theNoOfDBnodes));
- Uint32 tNoOfDbNodes = theNoOfDBnodes;
+ Uint32 tNoOfDbNodes = theImpl->theNoOfDBnodes;
+ Uint8 *theDBnodes= theImpl->theDBnodes;
+ DBUG_PRINT("info", ("theNoOfDBnodes=%d", tNoOfDbNodes));
UintR i;
for (i = 0; i < tNoOfDbNodes; i++) {
Uint32 tNode = theDBnodes[i];
@@ -254,50 +267,28 @@ Ndb::waitUntilReady(int timeout)
DBUG_RETURN(-1);
}
- do {
- if ((id = theNode) != 0) {
- unsigned int foundAliveNode = 0;
- TransporterFacade *tp = TransporterFacade::instance();
- tp->lock_mutex();
- for (unsigned int i = 0; i < theNoOfDBnodes; i++) {
- const NodeId nodeId = theDBnodes[i];
- //************************************************
- // If any node is answering, ndb is answering
- //************************************************
- if (tp->get_node_alive(nodeId) != 0) {
- foundAliveNode++;
- }//if
- }//for
-
- tp->unlock_mutex();
- if (foundAliveNode == theNoOfDBnodes) {
- DBUG_RETURN(0);
- }//if
- if (foundAliveNode > 0) {
- noChecksSinceFirstAliveFound++;
- }//if
- if (noChecksSinceFirstAliveFound > 30) {
- DBUG_RETURN(0);
- }//if
- }//if theNode != 0
+ while (theNode == 0) {
if (secondsCounter >= timeout)
- break;
+ {
+ theError.code = 4269;
+ DBUG_RETURN(-1);
+ }
NdbSleep_MilliSleep(100);
milliCounter += 100;
if (milliCounter >= 1000) {
secondsCounter++;
milliCounter = 0;
}//if
- } while (1);
- if (id == 0) {
- theError.code = 4269;
+ }
+
+ if (theImpl->m_ndb_cluster_connection.wait_until_ready
+ (timeout-secondsCounter,30))
+ {
+ theError.code = 4009;
DBUG_RETURN(-1);
}
- if (noChecksSinceFirstAliveFound > 0) {
- DBUG_RETURN(0);
- }//if
- theError.code = 4009;
- DBUG_RETURN(-1);
+
+ DBUG_RETURN(0);
}
/*****************************************************************************
@@ -322,8 +313,8 @@ Ndb::startTransaction(Uint32 aPriority, const char * keyData, Uint32 keyLen)
*/
Uint32 nodeId;
if(keyData != 0) {
- Uint32 fragmentId = computeFragmentId(keyData, keyLen);
- nodeId = guessPrimaryNode(fragmentId);
+ nodeId = 0; // guess not supported
+ // nodeId = m_ndb_cluster_connection->guess_primary_node(keyData, keyLen);
} else {
nodeId = 0;
}//if
@@ -384,44 +375,6 @@ Ndb::hupp(NdbConnection* pBuddyTrans)
}//if
}//Ndb::hupp()
-NdbConnection*
-Ndb::startTransactionDGroup(Uint32 aPriority, const char * keyData, int type)
-{
-
- char DGroup[4];
- if ((keyData == NULL) ||
- (type > 1)) {
- theError.code = 4118;
- return NULL;
- }//if
- if (theInitState == Initialised) {
- theError.code = 0;
- checkFailedNode();
- /**
- * If the user supplied key data
- * We will make a qualified quess to which node is the primary for the
- * the fragment and contact that node
- */
- Uint32 fragmentId;
- if (type == 0) {
- DGroup[0] = keyData[0];
- DGroup[1] = keyData[1];
- DGroup[2] = 0x30;
- DGroup[3] = 0x30;
- fragmentId = computeFragmentId(&DGroup[0], 4);
- } else {
- Uint32 hashValue = ((keyData[0] - 0x30) * 10) + (keyData[1] - 0x30);
- fragmentId = getFragmentId(hashValue);
- }//if
- Uint32 nodeId = guessPrimaryNode(fragmentId);
- NdbConnection* trans= startTransactionLocal(aPriority, nodeId);
- DBUG_PRINT("exit", ("start DGroup trans: 0x%x transid: 0x%llx",
- trans, trans ? trans->getTransactionId() : 0));
- return trans;
- } else {
- return NULL;
- }//if
-}//Ndb::startTransaction()
NdbConnection*
Ndb::startTransactionLocal(Uint32 aPriority, Uint32 nodeId)
@@ -1021,118 +974,6 @@ Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op)
return ~0;
}
-static const Uint32 MAX_KEY_LEN_64_WORDS = 4;
-static const Uint32 MAX_KEY_LEN_32_WORDS = 8;
-static const Uint32 MAX_KEY_LEN_BYTES = 32;
-
-Uint32
-Ndb::computeFragmentId(const char * keyData, Uint32 keyLen)
-{
- Uint64 tempData[MAX_KEY_LEN_64_WORDS];
-
- const Uint32 usedKeyLen = (keyLen + 3) >> 2; // In words
- const char * usedKeyData = 0;
-
- /**
- * If key data buffer is not aligned (on 64 bit boundary)
- * or key len is not a multiple of 4
- * Use temp data
- */
- if(((((UintPtr)keyData) & 7) == 0) && ((keyLen & 3) == 0)) {
- usedKeyData = keyData;
- } else {
- memcpy(&tempData[0], keyData, keyLen);
- const int slack = keyLen & 3;
- if(slack > 0) {
- memset(&((char *)&tempData[0])[keyLen], 0, (4 - slack));
- }//if
- usedKeyData = (char *)&tempData[0];
- }//if
-
- Uint32 hashValue = md5_hash((Uint64 *)usedKeyData, usedKeyLen);
-
- hashValue >>= startTransactionNodeSelectionData.kValue;
- return getFragmentId(hashValue);
-}//Ndb::computeFragmentId()
-
-Uint32
-Ndb::getFragmentId(Uint32 hashValue)
-{
- Uint32 fragmentId = hashValue &
- startTransactionNodeSelectionData.hashValueMask;
- if(fragmentId < startTransactionNodeSelectionData.hashpointerValue) {
- fragmentId = hashValue &
- ((startTransactionNodeSelectionData.hashValueMask << 1) + 1);
- }//if
- return fragmentId;
-}
-
-Uint32
-Ndb::guessPrimaryNode(Uint32 fragmentId){
- //ASSERT(((fragmentId > 0) && fragmentId <
- // startTransactionNodeSelectionData.noOfFragments), "Invalid fragementId");
-
- return startTransactionNodeSelectionData.fragment2PrimaryNodeMap[fragmentId];
-}
-
-void
-Ndb::StartTransactionNodeSelectionData::init(Uint32 noOfNodes,
- Uint32 nodeIds[]) {
- kValue = 6;
- noOfFragments = 2 * noOfNodes;
-
- /**
- * Compute hashValueMask and hashpointerValue
- */
- {
- Uint32 topBit = (1 << 31);
- for(int i = 31; i>=0; i--){
- if((noOfFragments & topBit) != 0)
- break;
- topBit >>= 1;
- }
- hashValueMask = topBit - 1;
- hashpointerValue = noOfFragments - (hashValueMask + 1);
- }
-
- /**
- * This initialization depends on
- * the fact that:
- * primary node for fragment i = i % noOfNodes
- *
- * This algorithm should be implemented in Dbdih
- */
- {
- if (fragment2PrimaryNodeMap != 0)
- abort();
-
- fragment2PrimaryNodeMap = new Uint32[noOfFragments];
- Uint32 i;
- for(i = 0; i<noOfNodes; i++){
- fragment2PrimaryNodeMap[i] = nodeIds[i];
- }
-
- // Sort them (bubble sort)
- for(i = 0; i<noOfNodes-1; i++)
- for(Uint32 j = i+1; j<noOfNodes; j++)
- if(fragment2PrimaryNodeMap[i] > fragment2PrimaryNodeMap[j]){
- Uint32 tmp = fragment2PrimaryNodeMap[i];
- fragment2PrimaryNodeMap[i] = fragment2PrimaryNodeMap[j];
- fragment2PrimaryNodeMap[j] = tmp;
- }
-
- for(i = 0; i<noOfNodes; i++){
- fragment2PrimaryNodeMap[i+noOfNodes] = fragment2PrimaryNodeMap[i];
- }
- }
-}
-
-void
-Ndb::StartTransactionNodeSelectionData::release(){
- delete [] fragment2PrimaryNodeMap;
- fragment2PrimaryNodeMap = 0;
-}
-
Uint32
convertEndian(Uint32 Data)
{