DbUtil.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:79k
- /* 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 <ndb_global.h>
- #include "DbUtil.hpp"
- #include <ndb_version.h>
- #include <signaldata/WaitGCP.hpp>
- #include <signaldata/KeyInfo.hpp>
- #include <signaldata/AttrInfo.hpp>
- #include <signaldata/TcKeyConf.hpp>
- #include <signaldata/TcKeyFailConf.hpp>
- #include <signaldata/GetTabInfo.hpp>
- #include <signaldata/DictTabInfo.hpp>
- #include <signaldata/UtilSequence.hpp>
- #include <signaldata/UtilPrepare.hpp>
- #include <signaldata/UtilRelease.hpp>
- #include <signaldata/UtilExecute.hpp>
- #include <signaldata/UtilLock.hpp>
- #include <SectionReader.hpp>
- #include <Interpreter.hpp>
- #include <AttributeHeader.hpp>
- #include <NdbTick.h>
- /**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: Startup
- * ------------------------------------------------------------------------
- *
- * Constructors, startup, initializations
- **************************************************************************/
- DbUtil::DbUtil(const Configuration & conf) :
- SimulatedBlock(DBUTIL, conf),
- c_runningPrepares(c_preparePool),
- c_runningPreparedOperations(c_preparedOperationPool),
- c_seizingTransactions(c_transactionPool),
- c_runningTransactions(c_transactionPool),
- c_lockQueues(c_lockQueuePool)
- {
- BLOCK_CONSTRUCTOR(DbUtil);
-
- // Add received signals
- addRecSignal(GSN_STTOR, &DbUtil::execSTTOR);
- addRecSignal(GSN_NDB_STTOR, &DbUtil::execNDB_STTOR);
- addRecSignal(GSN_DUMP_STATE_ORD, &DbUtil::execDUMP_STATE_ORD);
- addRecSignal(GSN_CONTINUEB, &DbUtil::execCONTINUEB);
-
- //addRecSignal(GSN_TCSEIZEREF, &DbUtil::execTCSEIZEREF);
- addRecSignal(GSN_TCSEIZECONF, &DbUtil::execTCSEIZECONF);
- addRecSignal(GSN_TCKEYCONF, &DbUtil::execTCKEYCONF);
- addRecSignal(GSN_TCKEYREF, &DbUtil::execTCKEYREF);
- addRecSignal(GSN_TCROLLBACKREP, &DbUtil::execTCROLLBACKREP);
- //addRecSignal(GSN_TCKEY_FAILCONF, &DbUtil::execTCKEY_FAILCONF);
- //addRecSignal(GSN_TCKEY_FAILREF, &DbUtil::execTCKEY_FAILREF);
- addRecSignal(GSN_TRANSID_AI, &DbUtil::execTRANSID_AI);
- /**
- * Sequence Service
- */
- addRecSignal(GSN_UTIL_SEQUENCE_REQ, &DbUtil::execUTIL_SEQUENCE_REQ);
- // Debug
- addRecSignal(GSN_UTIL_SEQUENCE_REF, &DbUtil::execUTIL_SEQUENCE_REF);
- addRecSignal(GSN_UTIL_SEQUENCE_CONF, &DbUtil::execUTIL_SEQUENCE_CONF);
- /**
- * Locking
- */
- addRecSignal(GSN_UTIL_CREATE_LOCK_REQ, &DbUtil::execUTIL_CREATE_LOCK_REQ);
- addRecSignal(GSN_UTIL_DESTROY_LOCK_REQ, &DbUtil::execUTIL_DESTORY_LOCK_REQ);
- addRecSignal(GSN_UTIL_LOCK_REQ, &DbUtil::execUTIL_LOCK_REQ);
- addRecSignal(GSN_UTIL_UNLOCK_REQ, &DbUtil::execUTIL_UNLOCK_REQ);
- /**
- * Backend towards Dict
- */
- addRecSignal(GSN_GET_TABINFOREF, &DbUtil::execGET_TABINFOREF);
- addRecSignal(GSN_GET_TABINFO_CONF, &DbUtil::execGET_TABINFO_CONF);
- /**
- * Prepare / Execute / Release Services
- */
- addRecSignal(GSN_UTIL_PREPARE_REQ, &DbUtil::execUTIL_PREPARE_REQ);
- addRecSignal(GSN_UTIL_PREPARE_CONF, &DbUtil::execUTIL_PREPARE_CONF);
- addRecSignal(GSN_UTIL_PREPARE_REF, &DbUtil::execUTIL_PREPARE_REF);
- addRecSignal(GSN_UTIL_EXECUTE_REQ, &DbUtil::execUTIL_EXECUTE_REQ);
- addRecSignal(GSN_UTIL_EXECUTE_CONF, &DbUtil::execUTIL_EXECUTE_CONF);
- addRecSignal(GSN_UTIL_EXECUTE_REF, &DbUtil::execUTIL_EXECUTE_REF);
- addRecSignal(GSN_UTIL_RELEASE_REQ, &DbUtil::execUTIL_RELEASE_REQ);
- addRecSignal(GSN_UTIL_RELEASE_CONF, &DbUtil::execUTIL_RELEASE_CONF);
- addRecSignal(GSN_UTIL_RELEASE_REF, &DbUtil::execUTIL_RELEASE_REF);
- c_pagePool.setSize(10);
- c_preparePool.setSize(1); // one parallel prepare at a time
- c_preparedOperationPool.setSize(5); // three hardcoded, two for test
- c_operationPool.setSize(64); // 64 parallel operations
- c_transactionPool.setSize(32); // 16 parallel transactions
- c_attrMappingPool.setSize(100);
- c_dataBufPool.setSize(6000); // 6000*11*4 = 264K > 8k+8k*16 = 256k
- {
- SLList<Prepare> tmp(c_preparePool);
- PreparePtr ptr;
- while(tmp.seize(ptr))
- new (ptr.p) Prepare(c_pagePool);
- tmp.release();
- }
- {
- SLList<Operation> tmp(c_operationPool);
- OperationPtr ptr;
- while(tmp.seize(ptr))
- new (ptr.p) Operation(c_dataBufPool, c_dataBufPool, c_dataBufPool);
- tmp.release();
- }
- {
- SLList<PreparedOperation> tmp(c_preparedOperationPool);
- PreparedOperationPtr ptr;
- while(tmp.seize(ptr))
- new (ptr.p) PreparedOperation(c_attrMappingPool,
- c_dataBufPool, c_dataBufPool);
- tmp.release();
- }
- {
- SLList<Transaction> tmp(c_transactionPool);
- TransactionPtr ptr;
- while(tmp.seize(ptr))
- new (ptr.p) Transaction(c_pagePool, c_operationPool);
- tmp.release();
- }
- c_lockQueuePool.setSize(5);
- c_lockElementPool.setSize(5);
- c_lockQueues.setSize(8);
- }
- DbUtil::~DbUtil()
- {
- }
- BLOCK_FUNCTIONS(DbUtil)
- void
- DbUtil::releasePrepare(PreparePtr prepPtr) {
- prepPtr.p->preparePages.release();
- c_runningPrepares.release(prepPtr); // Automatic release in pool
- }
- void
- DbUtil::releasePreparedOperation(PreparedOperationPtr prepOpPtr) {
- prepOpPtr.p->attrMapping.release();
- prepOpPtr.p->attrInfo.release();
- prepOpPtr.p->rsInfo.release();
- prepOpPtr.p->pkBitmask.clear();
- c_preparedOperationPool.release(prepOpPtr); // No list holding these structs
- }
- void
- DbUtil::releaseTransaction(TransactionPtr transPtr){
- transPtr.p->executePages.release();
- OperationPtr opPtr;
- for(transPtr.p->operations.first(opPtr); opPtr.i != RNIL;
- transPtr.p->operations.next(opPtr)){
- opPtr.p->attrInfo.release();
- opPtr.p->keyInfo.release();
- opPtr.p->rs.release();
- if (opPtr.p->prepOp != 0 && opPtr.p->prepOp_i != RNIL) {
- if (opPtr.p->prepOp->releaseFlag) {
- PreparedOperationPtr prepOpPtr;
- prepOpPtr.i = opPtr.p->prepOp_i;
- prepOpPtr.p = opPtr.p->prepOp;
- releasePreparedOperation(prepOpPtr);
- }
- }
- }
- transPtr.p->operations.release();
- c_runningTransactions.release(transPtr);
- }
- void
- DbUtil::execSTTOR(Signal* signal)
- {
- jamEntry();
- const Uint32 startphase = signal->theData[1];
-
- if(startphase == 1){
- c_transId[0] = (number() << 20) + (getOwnNodeId() << 8);
- c_transId[1] = 0;
- }
-
- if(startphase == 6){
- hardcodedPrepare();
- connectTc(signal);
- }
-
- signal->theData[0] = 0;
- signal->theData[3] = 1;
- signal->theData[4] = 6;
- signal->theData[5] = 255;
- sendSignal(NDBCNTR_REF, GSN_STTORRY, signal, 6, JBB);
- return;
- }
- void
- DbUtil::execNDB_STTOR(Signal* signal)
- {
- (void)signal; // Don't want compiler warning
- jamEntry();
- }
- /***************************
- * Seize a number of TC records
- * to use for Util transactions
- */
- void
- DbUtil::connectTc(Signal* signal){
-
- TransactionPtr ptr;
- while(c_seizingTransactions.seize(ptr)){
- signal->theData[0] = ptr.i << 1; // See TcCommitConf
- signal->theData[1] = reference();
- sendSignal(DBTC_REF, GSN_TCSEIZEREQ, signal, 2, JBB);
- }
- }
- void
- DbUtil::execTCSEIZECONF(Signal* signal){
- jamEntry();
-
- TransactionPtr ptr;
- ptr.i = signal->theData[0] >> 1;
- c_seizingTransactions.getPtr(ptr, signal->theData[0] >> 1);
- ptr.p->connectPtr = signal->theData[1];
-
- c_seizingTransactions.release(ptr);
- }
- /**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: Misc
- * ------------------------------------------------------------------------
- *
- * ContinueB, Dump
- **************************************************************************/
- void
- DbUtil::execCONTINUEB(Signal* signal){
- jamEntry();
- const Uint32 Tdata0 = signal->theData[0];
-
- switch(Tdata0){
- default:
- ndbrequire(0);
- }
- }
- void
- DbUtil::execDUMP_STATE_ORD(Signal* signal){
- jamEntry();
- /****************************************************************************
- * SEQUENCE SERVICE
- *
- * 200 : Simple test of Public Sequence Interface
- * ----------------------------------------------
- * - Sends a SEQUENCE_REQ signal to Util (itself)
- */
- const Uint32 tCase = signal->theData[0];
- if(tCase == 200){
- jam()
- ndbout << "--------------------------------------------------" << endl;
- UtilSequenceReq * req = (UtilSequenceReq*)signal->getDataPtrSend();
- Uint32 seqId = 1;
- Uint32 reqTy = UtilSequenceReq::CurrVal;
- if(signal->length() > 1) seqId = signal->theData[1];
- if(signal->length() > 2) reqTy = signal->theData[2];
-
- req->senderData = 12;
- req->sequenceId = seqId;
- req->requestType = reqTy;
- sendSignal(DBUTIL_REF, GSN_UTIL_SEQUENCE_REQ,
- signal, UtilSequenceReq::SignalLength, JBB);
- }
- /****************************************************************************/
- /* // Obsolete tests, should be rewritten for long signals!!
- if(tCase == 210){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0], 128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Delete);
- w.add(UtilPrepareReq::TableName, "sys/def/SYSTAB_0");
- w.add(UtilPrepareReq::AttributeName, "SYSKEY_0"); // AttrNo = 0
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 211){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Insert);
- w.add(UtilPrepareReq::TableName, "sys/def/SYSTAB_0");
- w.add(UtilPrepareReq::AttributeName, "SYSKEY_0"); // AttrNo = 0
- w.add(UtilPrepareReq::AttributeName, "NEXTID"); // AttrNo = 1
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 212){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Update);
- w.add(UtilPrepareReq::TableName, "sys/def/SYSTAB_0");
- w.add(UtilPrepareReq::AttributeName, "SYSKEY_0"); // AttrNo = 0
- w.add(UtilPrepareReq::AttributeName, "NEXTID"); // AttrNo = 1
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 213){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Read);
- w.add(UtilPrepareReq::TableName, "sys/def/SYSTAB_0");
- w.add(UtilPrepareReq::AttributeName, "SYSKEY_0"); // AttrNo = 0
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 214){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0], 128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Delete);
- w.add(UtilPrepareReq::TableId, (unsigned int)0); // SYSTAB_0
- w.add(UtilPrepareReq::AttributeId, (unsigned int)0);// SYSKEY_0
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 215){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Insert);
- w.add(UtilPrepareReq::TableId, (unsigned int)0); // SYSTAB_0
- w.add(UtilPrepareReq::AttributeId, (unsigned int)0); // SYSKEY_0
- w.add(UtilPrepareReq::AttributeId, 1); // NEXTID
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 216){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Update);
- w.add(UtilPrepareReq::TableId, (unsigned int)0); // SYSTAB_0
- w.add(UtilPrepareReq::AttributeId, (unsigned int)0);// SYSKEY_0
- w.add(UtilPrepareReq::AttributeId, 1); // NEXTID
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- if(tCase == 217){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, UtilPrepareReq::Read);
- w.add(UtilPrepareReq::TableId, (unsigned int)0); // SYSTAB_0
- w.add(UtilPrepareReq::AttributeId, (unsigned int)0);// SYSKEY_0
- Uint32 length = w.getWordsUsed();
- ndbassert(length <= pageSizeInWords);
- sendUtilPrepareReqSignals(signal, propPage, length);
- }
- */
- /****************************************************************************/
- /* // Obsolete tests, should be rewritten for long signals!!
- if(tCase == 220){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- Uint32 prepI = signal->theData[1];
- Uint32 length = signal->theData[2];
- Uint32 attributeValue0 = signal->theData[3];
- Uint32 attributeValue1a = signal->theData[4];
- Uint32 attributeValue1b = signal->theData[5];
- ndbrequire(prepI != 0);
- UtilExecuteReq * req = (UtilExecuteReq *)signal->getDataPtrSend();
- req->senderData = 221;
- req->prepareId = prepI;
- req->totalDataLen = length; // Including headers
- req->offset = 0;
- AttributeHeader::init(&req->attrData[0], 0, 1); // AttrNo 0, DataSize
- req->attrData[1] = attributeValue0; // AttrValue
- AttributeHeader::init(&req->attrData[2], 1, 2); // AttrNo 1, DataSize
- req->attrData[3] = attributeValue1a; // AttrValue
- req->attrData[4] = attributeValue1b; // AttrValue
- printUTIL_EXECUTE_REQ(stdout, signal->getDataPtrSend(), 3 + 5,0);
- sendSignal(DBUTIL_REF, GSN_UTIL_EXECUTE_REQ, signal, 3 + 5, JBB);
- }
- */
- /****************************************************************************
- * 230 : PRINT STATE
- */
- #ifdef ARRAY_GUARD
- if(tCase == 230){
- jam();
- ndbout << "--------------------------------------------------" << endl;
- if (signal->length() <= 1) {
- ndbout << "Usage: DUMP 230 <recordType> <recordNo>" << endl
- << "[1] Print Prepare (running) records" << endl
- << "[2] Print PreparedOperation records" << endl
- << "[3] Print Transaction records" << endl
- << "[4] Print Operation records" << endl
- << "Ex. "dump 230 1 2" prints Prepare record no 2." << endl
- << endl
- << "210 : PREPARE_REQ DELETE SYSTAB_0 SYSKEY_0" << endl
- << "211 : PREPARE_REQ INSERT SYSTAB_0 SYSKEY_0 NEXTID" << endl
- << "212 : PREPARE_REQ UPDATE SYSTAB_0 SYSKEY_0 NEXTID" << endl
- << "213 : PREPARE_REQ READ SYSTAB_0 SYSKEY_0" << endl
- << "214 : PREPARE_REQ DELETE SYSTAB_0 SYSKEY_0 using id" << endl
- << "215 : PREPARE_REQ INSERT SYSTAB_0 SYSKEY_0 NEXTID using id" << endl
- << "216 : PREPARE_REQ UPDATE SYSTAB_0 SYSKEY_0 NEXTID using id" << endl
- << "217 : PREPARE_REQ READ SYSTAB_0 SYSKEY_0 using id" << endl
- << "220 : EXECUTE_REQ <PrepId> <Len> <Val1> <Val2a> <Val2b>" <<endl
- << "299 : Crash system (using ndbrequire(0))"
- << endl
- << "Ex. "dump 220 3 5 1 0 17 " prints Prepare record no 2."
- << endl;
- return;
- }
- switch (signal->theData[1]) {
- case 1:
- // ** Print a specific record **
- if (signal->length() >= 3) {
- PreparePtr prepPtr;
- if (!c_preparePool.isSeized(signal->theData[2])) {
- ndbout << "Prepare Id: " << signal->theData[2]
- << " (Not seized!)" << endl;
- } else {
- c_preparePool.getPtr(prepPtr, signal->theData[2]);
- prepPtr.p->print();
- }
- return;
- }
- // ** Print all records **
- PreparePtr prepPtr;
- if (!c_runningPrepares.first(prepPtr)) {
- ndbout << "No Prepare records exist" << endl;
- return;
- }
-
- while (!prepPtr.isNull()) {
- prepPtr.p->print();
- c_runningPrepares.next(prepPtr);
- }
- return;
- case 2:
- // ** Print a specific record **
- if (signal->length() >= 3) {
- if (!c_preparedOperationPool.isSeized(signal->theData[2])) {
- ndbout << "PreparedOperation Id: " << signal->theData[2]
- << " (Not seized!)" << endl;
- return;
- }
- ndbout << "PreparedOperation Id: " << signal->theData[2] << endl;
- PreparedOperationPtr prepOpPtr;
- c_runningPreparedOperations.getPtr(prepOpPtr, signal->theData[2]);
- prepOpPtr.p->print();
- return;
- }
- // ** Print all records **
- PreparedOperationPtr prepOpPtr;
- if (!c_runningPreparedOperations.first(prepOpPtr)) {
- ndbout << "No PreparedOperations exist" << endl;
- return;
- }
- while (!prepOpPtr.isNull()) {
- ndbout << "[-PreparedOperation no " << prepOpPtr.i << ":";
- prepOpPtr.p->print();
- ndbout << "]";
- c_runningPreparedOperations.next(prepOpPtr);
- }
- return;
- case 3:
- // ** Print a specific record **
- if (signal->length() >= 3) {
- ndbout << "Print specific record not implemented." << endl;
- return;
- }
- // ** Print all records **
- ndbout << "Print all records not implemented, specify an Id." << endl;
- return;
- case 4:
- ndbout << "Not implemented" << endl;
- return;
- default:
- ndbout << "Unknown input (try without any data)" << endl;
- return;
- }
- }
- #endif
- if(tCase == 240 && signal->getLength() == 2){
- MutexManager::ActiveMutexPtr ptr;
- ndbrequire(c_mutexMgr.seize(ptr));
- ptr.p->m_mutexId = signal->theData[1];
- Callback c = { safe_cast(&DbUtil::mutex_created), ptr.i };
- ptr.p->m_callback = c;
- c_mutexMgr.create(signal, ptr);
- ndbout_c("c_mutexMgr.create ptrI=%d mutexId=%d", ptr.i, ptr.p->m_mutexId);
- }
- if(tCase == 241 && signal->getLength() == 2){
- MutexManager::ActiveMutexPtr ptr;
- ndbrequire(c_mutexMgr.seize(ptr));
- ptr.p->m_mutexId = signal->theData[1];
- Callback c = { safe_cast(&DbUtil::mutex_locked), ptr.i };
- ptr.p->m_callback = c;
- c_mutexMgr.lock(signal, ptr);
- ndbout_c("c_mutexMgr.lock ptrI=%d mutexId=%d", ptr.i, ptr.p->m_mutexId);
- }
- if(tCase == 242 && signal->getLength() == 2){
- MutexManager::ActiveMutexPtr ptr;
- ptr.i = signal->theData[1];
- c_mutexMgr.getPtr(ptr);
- Callback c = { safe_cast(&DbUtil::mutex_unlocked), ptr.i };
- ptr.p->m_callback = c;
- c_mutexMgr.unlock(signal, ptr);
- ndbout_c("c_mutexMgr.unlock ptrI=%d mutexId=%d", ptr.i, ptr.p->m_mutexId);
- }
-
- if(tCase == 243 && signal->getLength() == 3){
- MutexManager::ActiveMutexPtr ptr;
- ndbrequire(c_mutexMgr.seize(ptr));
- ptr.p->m_mutexId = signal->theData[1];
- ptr.p->m_mutexKey = signal->theData[2];
- Callback c = { safe_cast(&DbUtil::mutex_destroyed), ptr.i };
- ptr.p->m_callback = c;
- c_mutexMgr.destroy(signal, ptr);
- ndbout_c("c_mutexMgr.destroy ptrI=%d mutexId=%d key=%d",
- ptr.i, ptr.p->m_mutexId, ptr.p->m_mutexKey);
- }
- }
- void
- DbUtil::mutex_created(Signal* signal, Uint32 ptrI, Uint32 retVal){
- MutexManager::ActiveMutexPtr ptr; ptr.i = ptrI;
- c_mutexMgr.getPtr(ptr);
- ndbout_c("mutex_created - mutexId=%d, retVal=%d",
- ptr.p->m_mutexId, retVal);
- c_mutexMgr.release(ptrI);
- }
- void
- DbUtil::mutex_destroyed(Signal* signal, Uint32 ptrI, Uint32 retVal){
- MutexManager::ActiveMutexPtr ptr; ptr.i = ptrI;
- c_mutexMgr.getPtr(ptr);
- ndbout_c("mutex_destroyed - mutexId=%d, retVal=%d",
- ptr.p->m_mutexId, retVal);
- c_mutexMgr.release(ptrI);
- }
- void
- DbUtil::mutex_locked(Signal* signal, Uint32 ptrI, Uint32 retVal){
- MutexManager::ActiveMutexPtr ptr; ptr.i = ptrI;
- c_mutexMgr.getPtr(ptr);
- ndbout_c("mutex_locked - mutexId=%d, retVal=%d key=%d ptrI=%d",
- ptr.p->m_mutexId, retVal, ptr.p->m_mutexKey, ptrI);
- if(retVal)
- c_mutexMgr.release(ptrI);
- }
- void
- DbUtil::mutex_unlocked(Signal* signal, Uint32 ptrI, Uint32 retVal){
- MutexManager::ActiveMutexPtr ptr; ptr.i = ptrI;
- c_mutexMgr.getPtr(ptr);
- ndbout_c("mutex_unlocked - mutexId=%d, retVal=%d",
- ptr.p->m_mutexId, retVal);
- if(!retVal)
- c_mutexMgr.release(ptrI);
- }
-
- void
- DbUtil::execUTIL_SEQUENCE_REF(Signal* signal){
- jamEntry();
- ndbout << "UTIL_SEQUENCE_REF" << endl;
- printUTIL_SEQUENCE_REF(stdout, signal->getDataPtrSend(), signal->length(), 0);
- }
- void
- DbUtil::execUTIL_SEQUENCE_CONF(Signal* signal){
- jamEntry();
- ndbout << "UTIL_SEQUENCE_CONF" << endl;
- printUTIL_SEQUENCE_CONF(stdout, signal->getDataPtrSend(), signal->length(),0);
- }
- void
- DbUtil::execUTIL_PREPARE_CONF(Signal* signal){
- jamEntry();
- ndbout << "UTIL_PREPARE_CONF" << endl;
- printUTIL_PREPARE_CONF(stdout, signal->getDataPtrSend(), signal->length(), 0);
- }
- void
- DbUtil::execUTIL_PREPARE_REF(Signal* signal){
- jamEntry();
- ndbout << "UTIL_PREPARE_REF" << endl;
- printUTIL_PREPARE_REF(stdout, signal->getDataPtrSend(), signal->length(), 0);
- }
- void
- DbUtil::execUTIL_EXECUTE_CONF(Signal* signal) {
- jamEntry();
- ndbout << "UTIL_EXECUTE_CONF" << endl;
- printUTIL_EXECUTE_CONF(stdout, signal->getDataPtrSend(), signal->length(), 0);
- }
- void
- DbUtil::execUTIL_EXECUTE_REF(Signal* signal) {
- jamEntry();
- ndbout << "UTIL_EXECUTE_REF" << endl;
- printUTIL_EXECUTE_REF(stdout, signal->getDataPtrSend(), signal->length(), 0);
- }
- void
- DbUtil::execUTIL_RELEASE_CONF(Signal* signal) {
- jamEntry();
- ndbout << "UTIL_RELEASE_CONF" << endl;
- }
- void
- DbUtil::execUTIL_RELEASE_REF(Signal* signal) {
- jamEntry();
- ndbout << "UTIL_RELEASE_REF" << endl;
- }
- void
- DbUtil::sendUtilPrepareRef(Signal* signal, UtilPrepareRef::ErrorCode error,
- Uint32 recipient, Uint32 senderData){
- UtilPrepareRef * ref = (UtilPrepareRef *)signal->getDataPtrSend();
- ref->errorCode = error;
- ref->senderData = senderData;
- sendSignal(recipient, GSN_UTIL_PREPARE_REF, signal,
- UtilPrepareRef::SignalLength, JBB);
- }
- void
- DbUtil::sendUtilExecuteRef(Signal* signal, UtilExecuteRef::ErrorCode error,
- Uint32 TCerror, Uint32 recipient, Uint32 senderData){
-
- UtilExecuteRef * ref = (UtilExecuteRef *)signal->getDataPtrSend();
- ref->senderData = senderData;
- ref->errorCode = error;
- ref->TCErrorCode = TCerror;
- sendSignal(recipient, GSN_UTIL_EXECUTE_REF, signal,
- UtilPrepareRef::SignalLength, JBB);
- }
- /**************************************************************************
- * ------------------------------------------------------------------------
- * MODULE: Prepare service
- * ------------------------------------------------------------------------
- *
- * Prepares a transaction by storing info in some structs
- **************************************************************************/
- void
- DbUtil::execUTIL_PREPARE_REQ(Signal* signal)
- {
- jamEntry();
-
- /****************
- * Decode Signal
- ****************/
- UtilPrepareReq * req = (UtilPrepareReq *)signal->getDataPtr();
- const Uint32 senderRef = req->senderRef;
- const Uint32 senderData = req->senderData;
- if(signal->getNoOfSections() == 0) {
- // Missing prepare data
- jam();
- releaseSections(signal);
- sendUtilPrepareRef(signal, UtilPrepareRef::MISSING_PROPERTIES_SECTION,
- senderRef, senderData);
- return;
- }
- PreparePtr prepPtr;
- SegmentedSectionPtr ptr;
-
- jam();
- if(!c_runningPrepares.seize(prepPtr)) {
- jam();
- releaseSections(signal);
- sendUtilPrepareRef(signal, UtilPrepareRef::PREPARE_SEIZE_ERROR,
- senderRef, senderData);
- return;
- };
- signal->getSection(ptr, UtilPrepareReq::PROPERTIES_SECTION);
- const Uint32 noPages = (ptr.sz + sizeof(Page32)) / sizeof(Page32);
- ndbassert(noPages > 0);
- if (!prepPtr.p->preparePages.seize(noPages)) {
- jam();
- releaseSections(signal);
- sendUtilPrepareRef(signal, UtilPrepareRef::PREPARE_PAGES_SEIZE_ERROR,
- senderRef, senderData);
- c_preparePool.release(prepPtr);
- return;
- }
- // Save SimpleProperties
- Uint32* target = &prepPtr.p->preparePages.getPtr(0)->data[0];
- copy(target, ptr);
- prepPtr.p->prepDataLen = ptr.sz;
- // Release long signal sections
- releaseSections(signal);
- // Check table properties with DICT
- SimplePropertiesSectionReader reader(ptr, getSectionSegmentPool());
- prepPtr.p->clientRef = senderRef;
- prepPtr.p->clientData = senderData;
- // Release long signal sections
- releaseSections(signal);
- readPrepareProps(signal, &reader, prepPtr.i);
- }
- void DbUtil::readPrepareProps(Signal* signal,
- SimpleProperties::Reader* reader,
- Uint32 senderData)
- {
- jam();
- #if 0
- printf("DbUtil::readPrepareProps: Received SimpleProperties:n");
- reader->printAll(ndbout);
- #endif
- ndbrequire(reader->first());
- ndbrequire(reader->getKey() == UtilPrepareReq::NoOfOperations);
- ndbrequire(reader->getUint32() == 1); // Only one op/trans implemented
-
- ndbrequire(reader->next());
- ndbrequire(reader->getKey() == UtilPrepareReq::OperationType);
-
- ndbrequire(reader->next());
- UtilPrepareReq::KeyValue tableKey =
- (UtilPrepareReq::KeyValue) reader->getKey();
- ndbrequire((tableKey == UtilPrepareReq::TableName) ||
- (tableKey == UtilPrepareReq::TableId));
- /************************
- * Ask Dict for metadata
- ************************/
- {
- GetTabInfoReq * req = (GetTabInfoReq *)signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = senderData;
- if (tableKey == UtilPrepareReq::TableName) {
- jam();
- char tableName[MAX_TAB_NAME_SIZE];
- req->requestType = GetTabInfoReq::RequestByName |
- GetTabInfoReq::LongSignalConf;
- req->tableNameLen = reader->getValueLen(); // Including trailing