📄 ndb.cpp
字号:
{ theFirstTupleId[aTableId] = val - 1; DBUG_RETURN(true); } // else continue; } DBUG_RETURN((opTupleIdOnNdb(aTableId, val, 2) == val)); } else DBUG_RETURN((opTupleIdOnNdb(aTableId, val, 1) == val));}Uint64Ndb::opTupleIdOnNdb(Uint32 aTableId, Uint64 opValue, Uint32 op){ DBUG_ENTER("Ndb::opTupleIdOnNdb"); DBUG_PRINT("enter", ("table=%u value=%llu op=%u", aTableId, opValue, op)); NdbTransaction* tConnection; NdbOperation* tOperation= 0; // Compiler warning if not initialized Uint64 tValue; NdbRecAttr* tRecAttrResult; int result; Uint64 ret; CHECK_STATUS_MACRO_ZERO; BaseString currentDb(getDatabaseName()); BaseString currentSchema(getDatabaseSchemaName()); setDatabaseName("sys"); setDatabaseSchemaName("def"); tConnection = this->startTransaction(); if (tConnection == NULL) goto error_return; if (usingFullyQualifiedNames()) tOperation = tConnection->getNdbOperation("SYSTAB_0"); else tOperation = tConnection->getNdbOperation("sys/def/SYSTAB_0"); if (tOperation == NULL) goto error_handler; switch (op) { case 0: tOperation->interpretedUpdateTuple(); tOperation->equal("SYSKEY_0", aTableId ); tOperation->incValue("NEXTID", opValue); tRecAttrResult = tOperation->getValue("NEXTID"); if (tConnection->execute( Commit ) == -1 ) goto error_handler; tValue = tRecAttrResult->u_64_value(); theFirstTupleId[aTableId] = tValue - opValue; theLastTupleId[aTableId] = tValue - 1; ret = theFirstTupleId[aTableId]; break; case 1: tOperation->updateTuple(); tOperation->equal("SYSKEY_0", aTableId ); tOperation->setValue("NEXTID", opValue); if (tConnection->execute( Commit ) == -1 ) goto error_handler; theFirstTupleId[aTableId] = ~(Uint64)0; theLastTupleId[aTableId] = ~(Uint64)0; ret = opValue; break; case 2: tOperation->interpretedUpdateTuple(); tOperation->equal("SYSKEY_0", aTableId ); tOperation->load_const_u64(1, opValue); tOperation->read_attr("NEXTID", 2); tOperation->branch_le(2, 1, 0); tOperation->write_attr("NEXTID", 1); tOperation->interpret_exit_ok(); tOperation->def_label(0); tOperation->interpret_exit_nok(9999); if ( (result = tConnection->execute( Commit )) == -1 ) goto error_handler; if (result == 9999) ret = ~(Uint64)0; else { theFirstTupleId[aTableId] = theLastTupleId[aTableId] = opValue - 1; ret = opValue; } break; case 3: tOperation->readTuple(); tOperation->equal("SYSKEY_0", aTableId ); tRecAttrResult = tOperation->getValue("NEXTID"); if (tConnection->execute( Commit ) == -1 ) goto error_handler; ret = tRecAttrResult->u_64_value(); break; default: goto error_handler; } this->closeTransaction(tConnection); // Restore current name space setDatabaseName(currentDb.c_str()); setDatabaseSchemaName(currentSchema.c_str()); DBUG_RETURN(ret); error_handler: theError.code = tConnection->theError.code; this->closeTransaction(tConnection); error_return: // Restore current name space setDatabaseName(currentDb.c_str()); setDatabaseSchemaName(currentSchema.c_str()); DBUG_PRINT("error", ("ndb=%d con=%d op=%d", theError.code, tConnection ? tConnection->theError.code : -1, tOperation ? tOperation->theError.code : -1)); DBUG_RETURN(~(Uint64)0);}Uint32convertEndian(Uint32 Data){#ifdef WORDS_BIGENDIAN Uint32 t1, t2, t3, t4; t4 = (Data >> 24) & 255; t3 = (Data >> 16) & 255; t4 = t4 + (t3 << 8); t2 = (Data >> 8) & 255; t4 = t4 + (t2 << 16); t1 = Data & 255; t4 = t4 + (t1 << 24); return t4;#else return Data;#endif}const char * Ndb::getCatalogName() const{ return theImpl->m_dbname.c_str();}void Ndb::setCatalogName(const char * a_catalog_name){ if (a_catalog_name) { theImpl->m_dbname.assign(a_catalog_name); theImpl->update_prefix(); }}const char * Ndb::getSchemaName() const{ return theImpl->m_schemaname.c_str();}void Ndb::setSchemaName(const char * a_schema_name){ if (a_schema_name) { theImpl->m_schemaname.assign(a_schema_name); theImpl->update_prefix(); }} /*Deprecated functions*/const char * Ndb::getDatabaseName() const{ return getCatalogName();} void Ndb::setDatabaseName(const char * a_catalog_name){ setCatalogName(a_catalog_name);} const char * Ndb::getDatabaseSchemaName() const{ return getSchemaName();} void Ndb::setDatabaseSchemaName(const char * a_schema_name){ setSchemaName(a_schema_name);} bool Ndb::usingFullyQualifiedNames(){ return fullyQualifiedNames;} const char *Ndb::externalizeTableName(const char * internalTableName, bool fullyQualifiedNames){ if (fullyQualifiedNames) { register const char *ptr = internalTableName; // Skip database name while (*ptr && *ptr++ != table_name_separator); // Skip schema name while (*ptr && *ptr++ != table_name_separator); return ptr; } else return internalTableName;}const char *Ndb::externalizeTableName(const char * internalTableName){ return externalizeTableName(internalTableName, usingFullyQualifiedNames());}const char *Ndb::externalizeIndexName(const char * internalIndexName, bool fullyQualifiedNames){ if (fullyQualifiedNames) { register const char *ptr = internalIndexName; // Scan name from the end while (*ptr++); ptr--; // strend while (ptr >= internalIndexName && *ptr != table_name_separator) ptr--; return ptr + 1; } else return internalIndexName;}const char *Ndb::externalizeIndexName(const char * internalIndexName){ return externalizeIndexName(internalIndexName, usingFullyQualifiedNames());}const BaseStringNdb::internalize_table_name(const char *external_name) const{ BaseString ret; DBUG_ENTER("internalize_table_name"); DBUG_PRINT("enter", ("external_name: %s", external_name)); if (fullyQualifiedNames) { /* Internal table name format <db>/<schema>/<table> <db>/<schema> is already available in m_prefix so just concat the two strings */ ret.assfmt("%s%s", theImpl->m_prefix.c_str(), external_name); } else ret.assign(external_name); DBUG_PRINT("exit", ("internal_name: %s", ret.c_str())); DBUG_RETURN(ret);}const BaseStringNdb::internalize_index_name(const NdbTableImpl * table, const char * external_name) const{ BaseString ret; DBUG_ENTER("internalize_index_name"); DBUG_PRINT("enter", ("external_name: %s, table_id: %d", external_name, table ? table->m_tableId : ~0)); if (!table) { DBUG_PRINT("error", ("!table")); return ret; } if (fullyQualifiedNames) { /* Internal index name format <db>/<schema>/<tabid>/<table> */ ret.assfmt("%s%d%c%s", theImpl->m_prefix.c_str(), table->m_tableId, table_name_separator, external_name); } else ret.assign(external_name); DBUG_PRINT("exit", ("internal_name: %s", ret.c_str())); DBUG_RETURN(ret);}const BaseStringNdb::getDatabaseFromInternalName(const char * internalName){ char * databaseName = new char[strlen(internalName) + 1]; strcpy(databaseName, internalName); register char *ptr = databaseName; /* Scan name for the first table_name_separator */ while (*ptr && *ptr != table_name_separator) ptr++; *ptr = '\0'; BaseString ret = BaseString(databaseName); delete [] databaseName; return ret;} const BaseStringNdb::getSchemaFromInternalName(const char * internalName){ char * schemaName = new char[strlen(internalName)]; register const char *ptr1 = internalName; /* Scan name for the second table_name_separator */ while (*ptr1 && *ptr1 != table_name_separator) ptr1++; strcpy(schemaName, ptr1 + 1); register char *ptr = schemaName; while (*ptr && *ptr != table_name_separator) ptr++; *ptr = '\0'; BaseString ret = BaseString(schemaName); delete [] schemaName; return ret;}NdbEventOperation* Ndb::createEventOperation(const char* eventName, const int bufferLength){ NdbEventOperation* tOp; tOp = new NdbEventOperation(this, eventName, bufferLength); if (tOp == 0) { theError.code= 4000; return NULL; } if (tOp->getState() != NdbEventOperation::EO_CREATED) { theError.code= tOp->getNdbError().code; delete tOp; tOp = NULL; } //now we have to look up this event in dict return tOp;}int Ndb::dropEventOperation(NdbEventOperation* op) { delete op; return 0;}NdbGlobalEventBufferHandle* Ndb::getGlobalEventBufferHandle(){ return theGlobalEventBufferHandle;}//void Ndb::monitorEvent(NdbEventOperation *op, NdbEventCallback cb, void* rs)//{//}intNdb::pollEvents(int aMillisecondNumber){ return NdbEventOperation::wait(theGlobalEventBufferHandle, aMillisecondNumber);}#ifdef VM_TRACE#include <NdbMutex.h>extern NdbMutex *ndb_print_state_mutex;static boolcheckdups(NdbTransaction** list, unsigned no){ for (unsigned i = 0; i < no; i++) for (unsigned j = i + 1; j < no; j++) if (list[i] == list[j]) return true; return false;}voidNdb::printState(const char* fmt, ...){ char buf[200]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); NdbMutex_Lock(ndb_print_state_mutex); bool dups = false; unsigned i; ndbout << buf << " ndb=" << hex << this << dec;#ifndef NDB_WIN32 ndbout << " thread=" << (int)pthread_self();#endif ndbout << endl; for (unsigned n = 0; n < MAX_NDB_NODES; n++) { NdbTransaction* con = theConnectionArray[n]; if (con != 0) { ndbout << "conn " << n << ":" << endl; while (con != 0) { con->printState(); con = con->theNext; } } } ndbout << "prepared: " << theNoOfPreparedTransactions<< endl; if (checkdups(thePreparedTransactionsArray, theNoOfPreparedTransactions)) { ndbout << "!! DUPS !!" << endl; dups = true; } for (i = 0; i < theNoOfPreparedTransactions; i++) thePreparedTransactionsArray[i]->printState(); ndbout << "sent: " << theNoOfSentTransactions<< endl; if (checkdups(theSentTransactionsArray, theNoOfSentTransactions)) { ndbout << "!! DUPS !!" << endl; dups = true; } for (i = 0; i < theNoOfSentTransactions; i++) theSentTransactionsArray[i]->printState(); ndbout << "completed: " << theNoOfCompletedTransactions<< endl; if (checkdups(theCompletedTransactionsArray, theNoOfCompletedTransactions)) { ndbout << "!! DUPS !!" << endl; dups = true; } for (i = 0; i < theNoOfCompletedTransactions; i++) theCompletedTransactionsArray[i]->printState(); NdbMutex_Unlock(ndb_print_state_mutex);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -