25 #include <ndb_global.h>
28 #include <md5_hash.hpp>
31 #include <ndb_limits.h>
33 #include <BaseString.hpp>
34 #include <NdbSqlUtil.hpp>
47 DBUG_ENTER(
"Ndb::doConnect");
50 TretCode = NDB_connect(tConNode, instance);
51 if ((TretCode == 1) || (TretCode == 2)) {
55 DBUG_RETURN(getConnectedNdbTransaction(tConNode, instance));
56 }
else if (TretCode < 0) {
58 }
else if (TretCode != 0) {
66 Uint32 anyInstance = 0;
67 if (theImpl->m_optimized_node_selection)
71 theImpl->m_ndb_cluster_connection.init_get_next_node(node_iter);
72 while ((tNode= theImpl->m_ndb_cluster_connection.get_next_node(node_iter)))
74 TretCode= NDB_connect(tNode, anyInstance);
75 if ((TretCode == 1) ||
81 DBUG_RETURN(getConnectedNdbTransaction(tNode, anyInstance));
82 }
else if (TretCode < 0) {
84 }
else if (TretCode != 0) {
87 DBUG_PRINT(
"info",(
"tried node %d, TretCode %d, error code %d, %s",
94 Uint32 tNoOfDbNodes= theImpl->theNoOfDBnodes;
95 Uint32 &theCurrentConnectIndex= theImpl->theCurrentConnectIndex;
98 theCurrentConnectIndex++;
99 if (theCurrentConnectIndex >= tNoOfDbNodes)
100 theCurrentConnectIndex = 0;
103 tNode= theImpl->theDBnodes[theCurrentConnectIndex];
104 TretCode= NDB_connect(tNode, anyInstance);
105 if ((TretCode == 1) ||
111 DBUG_RETURN(getConnectedNdbTransaction(tNode, anyInstance));
112 }
else if (TretCode < 0) {
114 }
else if (TretCode != 0) {
117 DBUG_PRINT(
"info",(
"tried node %d TretCode %d", tNode, TretCode));
118 }
while (Tcount < tNoOfDbNodes);
124 if (tAnyAlive == 1) {
126 ndbout <<
"TretCode = " << TretCode << endl;
128 theError.
code = 4006;
130 theError.
code = 4009;
136 Ndb::NDB_connect(Uint32 tNode, Uint32 instance)
144 DBUG_ENTER(
"Ndb::NDB_connect");
147 if (theImpl->get_node_stopping(tNode))
154 if (instance != 0 && tConArray != 0)
160 if (refToInstance(curr->m_tcRef) == instance)
164 prev->theNext = curr->theNext;
165 curr->theNext = tConArray;
166 theConnectionArray[tNode] = curr;
170 assert(curr == tConArray);
175 curr = curr->theNext;
178 else if (tConArray != NULL)
184 if (tNdbCon == NULL) {
188 if (tSignal == NULL) {
189 releaseNdbCon(tNdbCon);
192 if (tSignal->setSignal(GSN_TCSEIZEREQ, DBTC) == -1) {
193 releaseNdbCon(tNdbCon);
194 releaseSignal(tSignal);
197 tSignal->setData(tNdbCon->ptr2int(), 1);
201 tSignal->setData(theMyRef, 2);
202 tSignal->setData(instance, 3);
203 tNdbCon->Status(NdbTransaction::Connecting);
204 tNdbCon->theDBnode = tNode;
206 tReturnCode= sendRecSignal(tNode, WAIT_TC_SEIZE, tSignal,
208 releaseSignal(tSignal);
209 if ((tReturnCode == 0) && (tNdbCon->Status() == NdbTransaction::Connected)) {
214 tNdbCon->setConnectedNodeId(tNode, nodeSequence);
216 tNdbCon->setMyBlockReference(theMyRef);
217 theConnectionArray[tNode] = tNdbCon;
218 tNdbCon->theNext = tPrevFirst;
225 (
"unsuccessful connect tReturnCode %d, tNdbCon->Status() %d",
226 tReturnCode, tNdbCon->Status()));
227 releaseNdbCon(tNdbCon);
228 if (theError.
code == 299 ||
229 theError.
code == 281 )
251 Ndb::getConnectedNdbTransaction(Uint32 nodeId, Uint32 instance){
258 if (refToInstance(next->m_tcRef) == instance)
263 prev->theNext = next->theNext;
268 assert(next == theConnectionArray[nodeId]);
273 next = next->theNext;
279 theConnectionArray[nodeId] = next->theNext;
281 next->theNext = NULL;
294 DBUG_ENTER(
"Ndb::doDisconnect");
296 CHECK_STATUS_MACRO_VOID;
298 Uint32 tNoOfDbNodes = theImpl->theNoOfDBnodes;
299 Uint8 *theDBnodes= theImpl->theDBnodes;
300 DBUG_PRINT(
"info", (
"theNoOfDBnodes=%d", tNoOfDbNodes));
302 for (i = 0; i < tNoOfDbNodes; i++) {
303 Uint32 tNode = theDBnodes[
i];
304 tNdbCon = theConnectionArray[tNode];
305 while (tNdbCon != NULL) {
307 tNdbCon = tNdbCon->theNext;
308 releaseConnectToNdb(tmpNdbCon);
311 tNdbCon = theTransactionList;
312 while (tNdbCon != NULL) {
314 tNdbCon = tNdbCon->theNext;
315 releaseConnectToNdb(tmpNdbCon);
330 DBUG_ENTER(
"Ndb::waitUntilReady");
331 int secondsCounter = 0;
332 int milliCounter = 0;
334 if (theInitState != Initialised) {
336 theError.
code = 4256;
340 while (theNode == 0) {
341 if (secondsCounter >= timeout)
343 theError.
code = 4269;
346 NdbSleep_MilliSleep(100);
348 if (milliCounter >= 1000) {
355 (timeout-secondsCounter,30) < 0)
357 theError.
code = 4009;
376 void*
buf, Uint32 bufLen)
380 const NdbTableImpl* impl = &NdbTableImpl::getImpl(*table);
381 const NdbColumnImpl*
const * cols = impl->m_columns.getBase();
385 Uint32 colcnt = impl->m_columns.size();
386 Uint32 parts = impl->m_noOfDistributionKeys;
388 if (unlikely(impl->m_fragmentType == NdbDictionary::Object::UserDefined))
401 for (Uint32 i = 0; i<parts; i++)
403 if (unlikely(keyData[i].ptr == 0))
407 if (unlikely(keyData[parts].ptr != 0))
408 goto emissingnullptr;
410 const NdbColumnImpl* partcols[NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY];
411 for (Uint32 i = 0; i<colcnt && j < parts; i++)
413 if (cols[i]->m_distributionKey)
417 partcols[j++] = cols[
i];
420 DBUG_ASSERT(j == parts);
422 for (Uint32 i = 0; i<parts; i++)
431 if (unlikely(keyData[i].len < (lb + len)))
434 Uint32 maxlen = (partcols[
i]->m_attrSize * partcols[
i]->m_arraySize);
436 if (unlikely(lb == 0 && keyData[i].len != maxlen))
439 if (partcols[i]->m_cs)
441 Uint32 xmul = partcols[
i]->m_cs->strxfrm_multiply;
442 xmul = xmul ? xmul : 1;
443 len = xmul * (maxlen - lb);
446 len = (lb + len + 3) & ~(Uint32)3;
455 UintPtr org = UintPtr(buf);
456 UintPtr use = (org + 7) & ~(UintPtr)7;
459 bufLen -= Uint32(use - org);
461 if (unlikely(sumlen > bufLen))
466 buf = malloc(sumlen);
467 if (unlikely(buf == 0))
470 assert((UintPtr(buf) & 7) == 0);
474 for (Uint32 i = 0; i<parts; i++)
478 keyData[i].ptr, keyData[i].len, lb, len);
480 if ((cs = partcols[i]->m_cs))
482 Uint32 xmul = cs->strxfrm_multiply;
489 Uint32 maxlen = (partcols[
i]->m_attrSize * partcols[
i]->m_arraySize);
490 Uint32 dstLen = xmul * (maxlen - lb);
494 ((
unsigned char*)keyData[i].ptr)+lb,
497 if (unlikely(n == -1))
498 goto emalformedstring;
509 memcpy(pos, keyData[i].ptr, len);
517 len = Uint32(UintPtr(pos) - UintPtr(buf));
518 assert((len & 3) == 0);
521 md5_hash(values, (
const Uint64*)buf, len >> 2);
525 * retval = values[1];
565 void*
buf, Uint32 bufLen)
570 Uint32 parts = keyRec->distkey_index_length;
572 if (unlikely(keyRec->flags & NdbRecord::RecHasUserDefinedPartitioning))
584 UintPtr org = UintPtr(buf);
585 UintPtr use = (org + 7) & ~(UintPtr)7;
588 bufLen -= Uint32(use - org);
596 buf= malloc(keyRec->m_keyLenInWords << 2);
597 if (unlikely(buf == 0))
600 assert((UintPtr(buf) & 7) == 0);
605 for (Uint32 i = 0; i < parts; i++)
608 keyRec->columns[keyRec->distkey_indexes[
i]];
611 Uint32 maxlen = keyAttr.maxSize;
612 unsigned char *src= (
unsigned char*)keyData + keyAttr.offset;
614 if (keyAttr.flags & NdbRecord::IsVar1ByteLen)
616 if (keyAttr.flags & NdbRecord::IsMysqldShrinkVarchar)
618 len = uint2korr(src);
628 else if (keyAttr.flags & NdbRecord::IsVar2ByteLen)
630 len = uint2korr(src);
642 Uint32 xmul = cs->strxfrm_multiply;
649 Uint32 dstLen = xmul * maxlen;
654 if (unlikely(n == -1))
655 goto emalformedstring;
660 if (keyAttr.flags & NdbRecord::IsVar1ByteLen)
662 *pos= (
unsigned char)len;
663 memcpy(pos+1, src, len);
666 else if (keyAttr.flags & NdbRecord::IsVar2ByteLen)
669 memcpy(pos, src-2, len);
672 memcpy(pos, src, len);
680 len = Uint32(UintPtr(pos) - UintPtr(buf));
681 assert((len & 3) == 0);
684 md5_hash(values, (
const Uint64*)buf, len >> 2);
688 * retval = values[1];
711 void* xfrmbuf, Uint32 xfrmbuflen)
715 if ((ret =
computeHash(&hash, keyRec, keyData, xfrmbuf, xfrmbuflen)) == 0)
726 void* buf, Uint32 bufLen)
730 if ((ret =
computeHash(&hash, table, keyData, buf, bufLen)) == 0)
742 DBUG_ENTER(
"Ndb::startTransaction");
744 (
"table: %s partitionId: %u", table->
getName(), partitionId));
745 if (theInitState == Initialised)
752 Uint32 cnt = NdbTableImpl::getImpl(* table).
get_nodes(partitionId,
759 theImpl->incClientStat(TransStartCount, 1);
762 DBUG_PRINT(
"exit",(
"start trans: 0x%lx transid: 0x%lx",
764 (
long) (trans ? trans->getTransactionId() : 0)));
772 const char * keyData, Uint32 keyLen)
774 DBUG_ENTER(
"Ndb::startTransaction");
776 if (theInitState == Initialised) {
789 if(unlikely(table != 0 && keyData != 0))
795 const Uint32 MaxKeySizeInLongWords= (NDB_MAX_KEY_SIZE + 7) / 8;
796 Uint64 tmp[ MaxKeySizeInLongWords ];
798 if (keyLen >=
sizeof(tmp))
800 theError.
code = 4207;
803 if((UintPtr(keyData) & 7) == 0 && (keyLen & 3) == 0)
805 md5_hash(buf, (
const Uint64*)keyData, keyLen >> 2);
810 memcpy(tmp, keyData, keyLen);
811 md5_hash(buf, tmp, (keyLen+3) >> 2);
827 theImpl->incClientStat( TransStartCount, 1 );
831 DBUG_PRINT(
"exit",(
"start trans: 0x%lx transid: 0x%lx",
833 (
long) (trans ? trans->getTransactionId() : 0)));
852 DBUG_ENTER(
"Ndb::hupp");
854 DBUG_PRINT(
"enter", (
"trans: 0x%lx", (
long) pBuddyTrans));
856 Uint32 aPriority = 0;
857 if (pBuddyTrans == NULL){
861 if (theInitState == Initialised) {
867 startTransactionLocal(aPriority, nodeId,
868 refToInstance(pBuddyTrans->m_tcRef));
876 theImpl->decClientStat( TransStartCount, 1 );
877 theError.
code = 4006;
881 pCon->setBuddyConPtr((Uint32)pBuddyTrans->getTC_ConnectPtr());
882 DBUG_PRINT(
"exit", (
"hupp trans: 0x%lx transid: 0x%lx",
884 (
long) (pCon ? pCon->getTransactionId() : 0)));
892 Ndb::startTransactionLocal(Uint32 aPriority, Uint32 nodeId, Uint32 instance)
896 const char* val = NdbEnv_GetEnv(
"NDB_TRANSACTION_NODE_ID", buf, 255);
902 DBUG_ENTER(
"Ndb::startTransactionLocal");
903 DBUG_PRINT(
"enter", (
"nodeid: %d", nodeId));
905 if(unlikely(theRemainingStartTransactions == 0))
907 theError.
code = 4006;
912 Uint64 tFirstTransId = theFirstTransId;
913 tConnection = doConnect(nodeId, instance);
914 if (tConnection == NULL) {
918 theRemainingStartTransactions--;
920 if (tConnection->init())
922 theError.
code = tConnection->theError.
code;
925 theTransactionList = tConnection;
926 tConnection->next(tConNext);
927 tConnection->setTransactionId(tFirstTransId);
928 tConnection->thePriority = aPriority;
929 if ((tFirstTransId & 0xFFFFFFFF) == 0xFFFFFFFF) {
934 theFirstTransId = ((tFirstTransId >> 32) << 32);
936 theFirstTransId = tFirstTransId + 1;
939 if (tConnection->theListState != NdbTransaction::NotInList) {
940 printState(
"startTransactionLocal %lx", (
long)tConnection);
944 DBUG_RETURN(tConnection);
956 DBUG_ENTER(
"Ndb::closeTransaction");
960 if (aConnection == NULL) {
966 printf(
"NULL into closeTransaction\n");
970 CHECK_STATUS_MACRO_VOID;
972 tCon = theTransactionList;
973 theRemainingStartTransactions++;
975 DBUG_PRINT(
"info",(
"close trans: 0x%lx transid: 0x%lx",
978 DBUG_PRINT(
"info",(
"magic number: 0x%x TCConPtr: 0x%x theMyRef: 0x%x 0x%x",
979 aConnection->theMagicNumber, aConnection->theTCConPtr,
980 aConnection->theMyRef, getReference()));
982 if (aConnection == tCon) {
983 theTransactionList = tCon->next();
985 while (aConnection != tCon) {
991 if(aConnection->theError.code == 4008){
998 printf(
"Scan timeout:ed NdbTransaction-> "
999 "not returning it-> memory leak\n");
1005 printf(
"Non-existing transaction into closeTransaction\n");
1010 tPreviousCon = tCon;
1011 tCon = tCon->next();
1013 tPreviousCon->next(tCon->next());
1016 aConnection->release();
1018 theImpl->incClientStat(TransCloseCount, 1);
1020 if(aConnection->theError.code == 4008){
1027 printf(
"Con timeout:ed NdbTransaction-> not returning it-> memory leak\n");
1035 Uint32 nodeId = aConnection->getConnectedNodeId();
1036 Uint32 seq = theImpl->getNodeSequence(nodeId);
1037 if (aConnection->theNodeSequence != seq)
1039 aConnection->theReleaseOnClose =
true;
1042 if (aConnection->theReleaseOnClose ==
false)
1047 aConnection->theNext = theConnectionArray[nodeId];
1048 theConnectionArray[nodeId] = aConnection;
1051 aConnection->theReleaseOnClose =
false;
1052 releaseNdbCon(aConnection);
1063 Ndb::getBlockNumber()
1065 return theNdbBlockNumber;
1070 return theDictionary;
1104 Ndb::getAutoIncrementValue(
const char* aTableName,
1105 Uint64 & autoValue, Uint32 cacheSize,
1106 Uint64 step, Uint64 start)
1108 DBUG_ENTER(
"Ndb::getAutoIncrementValue");
1110 BaseString internal_tabname(internalize_table_name(aTableName));
1113 theDictionary->get_local_table_info(internal_tabname);
1119 TupleIdRange & range = info->m_tuple_id_range;
1120 if (getTupleIdFromNdb(table, range, autoValue, cacheSize, step, start) == -1)
1122 DBUG_PRINT(
"info", (
"value %lu", (ulong) autoValue));
1128 Uint64 & autoValue, Uint32 cacheSize,
1129 Uint64 step, Uint64 start)
1131 DBUG_ENTER(
"Ndb::getAutoIncrementValue");
1133 assert(aTable != 0);
1134 const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
1135 const BaseString& internal_tabname = table->m_internalName;
1138 theDictionary->get_local_table_info(internal_tabname);
1143 TupleIdRange & range = info->m_tuple_id_range;
1144 if (getTupleIdFromNdb(table, range, autoValue, cacheSize, step, start) == -1)
1146 DBUG_PRINT(
"info", (
"value %lu", (ulong)autoValue));
1152 TupleIdRange & range, Uint64 & autoValue,
1153 Uint32 cacheSize, Uint64 step, Uint64 start)
1155 DBUG_ENTER(
"Ndb::getAutoIncrementValue");
1156 assert(aTable != 0);
1157 const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
1159 if (getTupleIdFromNdb(table, range, autoValue, cacheSize, step, start) == -1)
1161 DBUG_PRINT(
"info", (
"value %lu", (ulong)autoValue));
1167 TupleIdRange & range, Uint64 & tupleId,
1168 Uint32 cacheSize, Uint64 step, Uint64 start)
1179 DBUG_ENTER(
"Ndb::getTupleIdFromNdb");
1184 if (range.m_first_tuple_id != range.m_last_tuple_id &&
1185 range.m_first_tuple_id + step <= range.m_last_tuple_id)
1187 assert(range.m_first_tuple_id < range.m_last_tuple_id);
1188 range.m_first_tuple_id += step;
1189 tupleId = range.m_first_tuple_id;
1190 DBUG_PRINT(
"info", (
"Next cached value %lu", (ulong) tupleId));
1197 Uint64
offset = (start > step) ? 1 : start;
1205 DBUG_PRINT(
"info", (
"reading %u values from database", (uint)cacheSize));
1211 Uint64 opValue = cacheSize * step;
1213 if (opTupleIdOnNdb(table, range, opValue, 0) == -1)
1215 DBUG_PRINT(
"info", (
"Next value fetched from database %lu", (ulong) opValue));
1216 DBUG_PRINT(
"info", (
"Increasing %lu by offset %lu, increment is %lu", (ulong) (ulong) opValue, (ulong) offset, (ulong) step));
1217 Uint64 current, next;
1218 Uint64 div = ((Uint64) (opValue + step - offset)) / step;
1219 next = div * step +
offset;
1220 current = (next < step) ? next : next - step;
1221 tupleId = (opValue <= current) ? current : next;
1222 DBUG_PRINT(
"info", (
"Returning %lu", (ulong) tupleId));
1223 range.m_first_tuple_id = tupleId;
1238 Ndb::readAutoIncrementValue(
const char* aTableName,
1241 DBUG_ENTER(
"Ndb::readAutoIncrementValue");
1243 BaseString internal_tabname(internalize_table_name(aTableName));
1246 theDictionary->get_local_table_info(internal_tabname);
1252 TupleIdRange & range = info->m_tuple_id_range;
1253 if (readTupleIdFromNdb(table, range, autoValue) == -1)
1255 DBUG_PRINT(
"info", (
"value %lu", (ulong)autoValue));
1263 DBUG_ENTER(
"Ndb::readAutoIncrementValue");
1265 assert(aTable != 0);
1266 const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
1267 const BaseString& internal_tabname = table->m_internalName;
1270 theDictionary->get_local_table_info(internal_tabname);
1275 TupleIdRange & range = info->m_tuple_id_range;
1276 if (readTupleIdFromNdb(table, range, autoValue) == -1)
1278 DBUG_PRINT(
"info", (
"value %lu", (ulong)autoValue));
1284 TupleIdRange & range, Uint64 & autoValue)
1286 DBUG_ENTER(
"Ndb::readAutoIncrementValue");
1287 assert(aTable != 0);
1288 const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
1290 if (readTupleIdFromNdb(table, range, autoValue) == -1)
1292 DBUG_PRINT(
"info", (
"value %lu", (ulong)autoValue));
1298 TupleIdRange & range, Uint64 & tupleId)
1300 DBUG_ENTER(
"Ndb::readTupleIdFromNdb");
1301 if (range.m_first_tuple_id != range.m_last_tuple_id)
1303 assert(range.m_first_tuple_id < range.m_last_tuple_id);
1304 tupleId = range.m_first_tuple_id + 1;
1313 if (opTupleIdOnNdb(table, range, opValue, 3) == -1)
1332 Ndb::setAutoIncrementValue(
const char* aTableName,
1333 Uint64 autoValue,
bool modify)
1335 DBUG_ENTER(
"Ndb::setAutoIncrementValue");
1337 BaseString internal_tabname(internalize_table_name(aTableName));
1340 theDictionary->get_local_table_info(internal_tabname);
1346 TupleIdRange & range = info->m_tuple_id_range;
1347 if (setTupleIdInNdb(table, range, autoValue, modify) == -1)
1354 Uint64 autoValue,
bool modify)
1356 DBUG_ENTER(
"Ndb::setAutoIncrementValue");
1358 assert(aTable != 0);
1359 const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
1360 const BaseString& internal_tabname = table->m_internalName;
1363 theDictionary->get_local_table_info(internal_tabname);
1368 TupleIdRange & range = info->m_tuple_id_range;
1369 if (setTupleIdInNdb(table, range, autoValue, modify) == -1)
1376 TupleIdRange & range, Uint64 autoValue,
1379 DBUG_ENTER(
"Ndb::setAutoIncrementValue");
1380 assert(aTable != 0);
1381 const NdbTableImpl* table = & NdbTableImpl::getImpl(*aTable);
1383 if (setTupleIdInNdb(table, range, autoValue, modify) == -1)
1390 TupleIdRange & range, Uint64 tupleId,
bool modify)
1392 DBUG_ENTER(
"Ndb::setTupleIdInNdb");
1395 if (checkTupleIdInNdb(range, tupleId))
1397 if (range.m_first_tuple_id != range.m_last_tuple_id)
1399 assert(range.m_first_tuple_id < range.m_last_tuple_id);
1400 if (tupleId <= range.m_first_tuple_id + 1)
1402 if (tupleId <= range.m_last_tuple_id)
1404 range.m_first_tuple_id = tupleId - 1;
1406 (
"Setting next auto increment cached value to %lu",
1415 if (opTupleIdOnNdb(table, range, tupleId, 2) == -1)
1424 if (opTupleIdOnNdb(table, range, tupleId, 1) == -1)
1430 int Ndb::initAutoIncrement()
1441 m_sys_tab_0 = theDictionary->getTableGlobal(
"SYSTAB_0");
1447 if (m_sys_tab_0 == NULL) {
1448 assert(theDictionary->m_error.
code != 0);
1449 theError.
code = theDictionary->m_error.
code;
1457 Ndb::checkUpdateAutoIncrementValue(TupleIdRange & range, Uint64 autoValue)
1459 return(checkTupleIdInNdb(range, autoValue) != 0);
1463 Ndb::checkTupleIdInNdb(TupleIdRange & range, Uint64 tupleId)
1465 DBUG_ENTER(
"Ndb::checkTupleIdIndNdb");
1466 if ((range.m_first_tuple_id != ~(Uint64)0) &&
1467 (range.m_first_tuple_id > tupleId))
1476 if (range.m_highest_seen > tupleId)
1491 TupleIdRange & range, Uint64 & opValue, Uint32 op)
1493 DBUG_ENTER(
"Ndb::opTupleIdOnNdb");
1494 Uint32 aTableId = table->m_id;
1495 DBUG_PRINT(
"enter", (
"table: %u value: %lu op: %u",
1496 aTableId, (ulong) opValue, op));
1505 if (initAutoIncrement() == -1)
1510 (
const char *) &aTableId,
1513 if (tConnection == NULL)
1517 if (tOperation == NULL)
1524 tOperation->
equal(
"SYSKEY_0", aTableId);
1525 tOperation->
incValue(
"NEXTID", opValue);
1526 tRecAttrResult = tOperation->
getValue(
"NEXTID");
1533 range.m_first_tuple_id = tValue - opValue;
1534 range.m_last_tuple_id = tValue - 1;
1535 opValue = range.m_first_tuple_id;
1540 tOperation->
equal(
"SYSKEY_0", aTableId );
1541 tOperation->
setValue(
"NEXTID", opValue);
1550 tOperation->
equal(
"SYSKEY_0", aTableId );
1551 tOperation->load_const_u64(1, opValue);
1554 tOperation->branch_le(2, 1, 0);
1559 tRecAttrResult = tOperation->
getValue(
"NEXTID");
1566 range.m_highest_seen = tRecAttrResult->
u_64_value();
1568 (
"Setting next auto increment value (db) to %lu",
1570 range.m_first_tuple_id = range.m_last_tuple_id = opValue - 1;
1575 tOperation->
equal(
"SYSKEY_0", aTableId );
1576 tRecAttrResult = tOperation->
getValue(
"NEXTID");
1579 range.m_highest_seen = opValue = tRecAttrResult->
u_64_value();
1590 DBUG_PRINT(
"error", (
"ndb=%d con=%d op=%d",
1592 tConnection != NULL ? tConnection->theError.
code : -1,
1593 tOperation != NULL ? tOperation->theError.
code : -1));
1595 if (theError.
code == 0 && tConnection != NULL)
1596 theError.
code = tConnection->theError.
code;
1597 if (theError.
code == 0 && tOperation != NULL)
1598 theError.
code = tOperation->theError.
code;
1599 DBUG_ASSERT(theError.
code != 0);
1602 savedError = theError;
1604 if (tConnection != NULL)
1607 theError = savedError;
1613 convertEndian(Uint32
Data)
1615 #ifdef WORDS_BIGENDIAN
1616 Uint32 t1, t2, t3, t4;
1617 t4 = (Data >> 24) & 255;
1618 t3 = (Data >> 16) & 255;
1619 t4 = t4 + (t3 << 8);
1620 t2 = (Data >> 8) & 255;
1621 t4 = t4 + (t2 << 16);
1623 t4 = t4 + (t1 << 24);
1634 return theImpl->m_ndb_cluster_connection;
1639 return theImpl->m_dbname.
c_str();
1645 if (a_catalog_name && ! strchr(a_catalog_name, table_name_separator)) {
1646 if (!theImpl->m_dbname.
assign(a_catalog_name) ||
1647 theImpl->update_prefix())
1649 theError.
code = 4000;
1658 return theImpl->m_schemaname.
c_str();
1664 if (a_schema_name && ! strchr(a_schema_name, table_name_separator)) {
1665 if (!theImpl->m_schemaname.
assign(a_schema_name) ||
1666 theImpl->update_prefix())
1668 theError.
code = 4000;
1698 const char* s0 = t->m_impl.m_internalName.
c_str();
1699 const char* s1 = strchr(s0, table_name_separator);
1700 if (s1 && s1 != s0) {
1701 const char* s2 = strchr(s1 + 1, table_name_separator);
1702 if (s2 && s2 != s1 + 1) {
1703 char buf[NAME_LEN + 1];
1704 if (s1 - s0 <= NAME_LEN && s2 - (s1 + 1) <= NAME_LEN) {
1705 sprintf(buf,
"%.*s", (
int) (s1 - s0), s0);
1707 sprintf(buf,
"%.*s", (
int) (s2 - (s1 + 1)), s1 + 1);
1711 const char* s0 = theImpl->m_prefix.
c_str();
1712 const char* s1 = s0 ? strchr(s0, table_name_separator) : 0;
1713 const char* s2 = s1 ? strchr(s1 + 1, table_name_separator) : 0;
1714 if (!(s1 && s1 != s0 && s2 && s2 != s1 + 1 && *(s2 + 1) == 0))
1716 ndbout_c(
"t->m_impl.m_internalName.c_str(): %s", t->m_impl.m_internalName.
c_str());
1717 ndbout_c(
"s0: %s", s0);
1718 ndbout_c(
"s1: %s", s1);
1719 ndbout_c(
"s2: %s", s2);
1720 assert(s1 && s1 != s0 && s2 && s2 != s1 + 1 && *(s2 + 1) == 0);
1730 bool Ndb::usingFullyQualifiedNames()
1732 return fullyQualifiedNames;
1736 Ndb::externalizeTableName(
const char * internalTableName,
bool fullyQualifiedNames)
1738 if (fullyQualifiedNames) {
1739 register const char *ptr = internalTableName;
1742 while (*ptr && *ptr++ != table_name_separator);
1744 while (*ptr && *ptr++ != table_name_separator);
1748 return internalTableName;
1752 Ndb::externalizeTableName(
const char * internalTableName)
1754 return externalizeTableName(internalTableName, usingFullyQualifiedNames());
1758 Ndb::externalizeIndexName(
const char * internalIndexName,
bool fullyQualifiedNames)
1760 if (fullyQualifiedNames) {
1761 register const char *ptr = internalIndexName;
1764 while (*ptr++); ptr--;
1765 while (ptr >= internalIndexName && *ptr != table_name_separator)
1771 return internalIndexName;
1775 Ndb::externalizeIndexName(
const char * internalIndexName)
1777 return externalizeIndexName(internalIndexName, usingFullyQualifiedNames());
1782 Ndb::internalize_table_name(
const char *external_name)
const
1785 DBUG_ENTER(
"internalize_table_name");
1786 DBUG_PRINT(
"enter", (
"external_name: %s", external_name));
1788 if (fullyQualifiedNames)
1796 const char* s0 = theImpl->m_prefix.
c_str();
1797 const char* s1 = s0 ? strchr(s0, table_name_separator) : 0;
1798 const char* s2 = s1 ? strchr(s1 + 1, table_name_separator) : 0;
1799 if (!(s1 && s1 != s0 && s2 && s2 != s1 + 1 && *(s2 + 1) == 0))
1801 ndbout_c(
"s0: %s", s0);
1802 ndbout_c(
"s1: %s", s1);
1803 ndbout_c(
"s2: %s", s2);
1804 assert(s1 && s1 != s0 && s2 && s2 != s1 + 1 && *(s2 + 1) == 0);
1808 theImpl->m_prefix.
c_str(),
1812 ret.
assign(external_name);
1814 DBUG_PRINT(
"exit", (
"internal_name: %s", ret.
c_str()));
1819 Ndb::old_internalize_index_name(
const NdbTableImpl * table,
1820 const char * external_name)
const
1823 DBUG_ENTER(
"old_internalize_index_name");
1824 DBUG_PRINT(
"enter", (
"external_name: %s, table_id: %d",
1825 external_name, table ? table->m_id : ~0));
1828 DBUG_PRINT(
"error", (
"!table"));
1832 if (fullyQualifiedNames)
1836 theImpl->m_prefix.
c_str(),
1838 table_name_separator,
1842 ret.
assign(external_name);
1844 DBUG_PRINT(
"exit", (
"internal_name: %s", ret.
c_str()));
1849 Ndb::internalize_index_name(
const NdbTableImpl * table,
1850 const char * external_name)
const
1853 DBUG_ENTER(
"internalize_index_name");
1854 DBUG_PRINT(
"enter", (
"external_name: %s, table_id: %d",
1855 external_name, table ? table->m_id : ~0));
1858 DBUG_PRINT(
"error", (
"!table"));
1862 if (fullyQualifiedNames)
1866 theImpl->m_systemPrefix.
c_str(),
1868 table_name_separator,
1872 ret.
assign(external_name);
1874 DBUG_PRINT(
"exit", (
"internal_name: %s", ret.
c_str()));
1880 Ndb::getDatabaseFromInternalName(
const char * internalName)
1882 char * databaseName =
new char[strlen(internalName) + 1];
1883 if (databaseName == NULL)
1888 strcpy(databaseName, internalName);
1889 register char *ptr = databaseName;
1892 while (*ptr && *ptr != table_name_separator)
1896 delete [] databaseName;
1901 Ndb::getSchemaFromInternalName(
const char * internalName)
1903 char * schemaName =
new char[strlen(internalName)];
1904 if (schemaName == NULL)
1909 register const char *ptr1 = internalName;
1912 while (*ptr1 && *ptr1 != table_name_separator)
1914 strcpy(schemaName, ptr1 + 1);
1915 register char *ptr = schemaName;
1916 while (*ptr && *ptr != table_name_separator)
1920 delete [] schemaName;
1927 DBUG_ENTER(
"Ndb::createEventOperation");
1934 NdbEventBuffer::getEventOperationImpl(tOp);
1935 op->m_next= theImpl->m_ev_op;
1937 theImpl->m_ev_op= op;
1939 op->m_next->m_prev= op;
1947 DBUG_ENTER(
"Ndb::dropEventOperation");
1948 DBUG_PRINT(
"info", (
"name: %s", tOp->getEvent()->
getTable()->
getName()));
1959 op= NdbEventBuffer::getEventOperationImpl(tOp)->m_next;
1961 op= theImpl->m_ev_op;
1963 return op->m_facade;
1970 return theEventBuffer->pollEvents(aMillisecondNumber, latestGCI);
1974 Ndb::flushIncompleteEvents(Uint64 gci)
1976 theEventBuffer->lock();
1978 theEventBuffer->unlock();
1984 return theEventBuffer->nextEvent();
1990 return theEventBuffer->isConsistent(gci);
1996 return theEventBuffer->isConsistentGCI(gci);
2003 theEventBuffer->getGCIEventOperations(iter, event_types);
2005 return op->m_facade;
2009 Uint64 Ndb::getLatestGCI()
2011 return theEventBuffer->getLatestGCI();
2014 void Ndb::setReportThreshEventGCISlip(
unsigned thresh)
2016 if (theEventBuffer->m_gci_slip_thresh != thresh)
2018 theEventBuffer->m_gci_slip_thresh= thresh;
2022 void Ndb::setReportThreshEventFreeMem(
unsigned thresh)
2024 if (theEventBuffer->m_free_thresh != thresh)
2026 theEventBuffer->m_free_thresh= thresh;
2027 theEventBuffer->m_min_free_thresh= thresh;
2028 theEventBuffer->m_max_free_thresh= 100;
2032 Uint64 Ndb::allocate_transaction_id()
2034 Uint64 ret= theFirstTransId;
2036 if ((theFirstTransId & 0xFFFFFFFF) == 0xFFFFFFFF) {
2037 theFirstTransId = (theFirstTransId >> 32) << 32;
2046 #include <NdbMutex.h>
2047 extern NdbMutex *ndb_print_state_mutex;
2052 for (
unsigned i = 0; i < no; i++)
2053 for (
unsigned j = i + 1; j < no; j++)
2054 if (list[i] == list[j])
2059 Ndb::printState(
const char*
fmt, ...)
2064 vsprintf(buf, fmt, ap);
2066 NdbMutex_Lock(ndb_print_state_mutex);
2069 ndbout << buf <<
" ndb=" << hex << (
void*)
this << endl;
2070 for (
unsigned n = 0; n < MAX_NDB_NODES; n++) {
2073 ndbout <<
"conn " << n <<
":" << endl;
2080 ndbout <<
"prepared: " << theNoOfPreparedTransactions<< endl;
2081 if (checkdups(thePreparedTransactionsArray, theNoOfPreparedTransactions)) {
2082 ndbout <<
"!! DUPS !!" << endl;
2085 for (i = 0; i < theNoOfPreparedTransactions; i++)
2086 thePreparedTransactionsArray[i]->printState();
2087 ndbout <<
"sent: " << theNoOfSentTransactions<< endl;
2088 if (checkdups(theSentTransactionsArray, theNoOfSentTransactions)) {
2089 ndbout <<
"!! DUPS !!" << endl;
2092 for (i = 0; i < theNoOfSentTransactions; i++)
2093 theSentTransactionsArray[i]->printState();
2094 ndbout <<
"completed: " << theNoOfCompletedTransactions<< endl;
2095 if (checkdups(theCompletedTransactionsArray, theNoOfCompletedTransactions)) {
2096 ndbout <<
"!! DUPS !!" << endl;
2099 for (i = 0; i < theNoOfCompletedTransactions; i++)
2100 theCompletedTransactionsArray[i]->printState();
2101 NdbMutex_Unlock(ndb_print_state_mutex);
2109 DBUG_ENTER(
"Ndb::getNdbErrorDetail");
2118 DBUG_PRINT(
"info", (
"err.code is %u", err.
code));
2127 UintPtr uip = (UintPtr) err.
details;
2128 Uint32 indexObjectId = (Uint32) (uip - (UintPtr(0)));
2129 Uint32 primTableObjectId = ~ (Uint32) 0;
2131 char splitChars[2] = {table_name_separator, 0};
2135 DBUG_PRINT(
"info", (
"Index object id is %u", indexObjectId));
2137 int rc = theDictionary->listObjects(allIndices,
2142 DBUG_PRINT(
"info", (
"listObjects call 1 failed with rc %u", rc));
2146 DBUG_PRINT(
"info", (
"Retrieved details for %u indices", allIndices.
count));
2148 for (
unsigned i = 0; i < allIndices.
count; i++)
2150 if (allIndices.
elements[i].
id == indexObjectId)
2159 Uint32 components = idxName.
split(idxNameComponents,
2162 assert(components == 4);
2164 primTableObjectId = atoi(idxNameComponents[2].c_str());
2165 indexName = idxNameComponents[3];
2167 DBUG_PRINT(
"info", (
"Found index name : %s, primary table id : %u",
2168 indexName.
c_str(), primTableObjectId));
2175 if (primTableObjectId != (~(Uint32) 0))
2178 int rc = theDictionary->listObjects(allTables,
2184 DBUG_PRINT(
"info", (
"listObjects call 2 failed with rc %u", rc));
2188 DBUG_PRINT(
"info", (
"Retrieved details for %u tables", allTables.
count));
2190 for (Uint32 t = 0; t < allTables.
count; t++)
2193 if (allTables.
elements[t].
id == primTableObjectId)
2201 Uint32 components = tabName.
split(tabNameComponents,
2203 assert (components == 3);
2210 result.
assfmt(
"%s/%s/%s/%s",
2211 tabNameComponents[0].c_str(),
2212 tabNameComponents[1].c_str(),
2213 tabNameComponents[2].c_str(),
2216 DBUG_PRINT(
"info", (
"Found full index details : %s",
2219 memcpy(buff, result.
c_str(),
2231 DBUG_PRINT(
"info", (
"Table id %u not found", primTableObjectId));
2239 DBUG_PRINT(
"info", (
"Index id %u not found", indexObjectId));
2250 DBUG_PRINT(
"info", (
"No details string for this error"));
2255 Ndb::setCustomData(
void* _customDataPtr)
2257 theImpl->customDataPtr = _customDataPtr;
2261 Ndb::getCustomData()
const
2263 return theImpl->customDataPtr;
2267 Ndb::getMinDbNodeVersion()
const
2269 return theCachedMinDbNodeVersion;
2272 const char* ClientStatNames [] =
2273 {
"WaitExecCompleteCount",
2274 "WaitScanResultCount",
2275 "WaitMetaRequestCount",
2290 "TransLocalReadRowCount",
2291 "DataEventsRecvdCount",
2292 "NonDataEventsRecvdCount",
2293 "EventBytesRecvdCount"
2297 Ndb::getClientStat(Uint32
id)
const
2299 if (likely(
id < NumClientStatistics))
2300 return theImpl->clientStats[
id];
2306 Ndb::getClientStatName(Uint32
id)
const
2308 if (likely(
id < NumClientStatistics))
2309 return ClientStatNames[
id];