⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbutil.cpp

📁 mysql-5.0.22.tar.gz源码包
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	len = attrDesc.AttributeArraySize;	break;      case DictTabInfo::a64Bit:	len = attrDesc.AttributeArraySize * 2;      break;      case DictTabInfo::a128Bit:	len = attrDesc.AttributeArraySize * 4;	break;      }      attrLength += len;      if (attrDesc.AttributeKeyFlag)	pkAttrLength += len;      if (operationType == UtilPrepareReq::Read) {	AttributeHeader::init(rsInfoIt.data, 			      attrDesc.AttributeId,    // 1. Store AttrId			      len);	prepOpPtr.p->rsInfo.next(rsInfoIt, 1);      }    }#if 0    ndbout << ": AttributeSize: " << attrDesc.AttributeSize << endl;    ndbout << ": AttributeArraySize: " << attrDesc.AttributeArraySize << endl;    ndbout << "AFTER: attrLength: " << attrLength << endl;#endif        //attrMappingIt.print(stdout);    //prepPtr.p->prepOpPtr.p->attrMapping.print(stdout);    prepPtr.p->prepOpPtr.p->attrMapping.next(attrMappingIt, 1);  }     /***************************   * Error: Not all PKs found    ***************************/  if (noOfPKAttribsStored != tableDesc.NoOfKeyAttr) {    jam();     releaseSections(signal);    sendUtilPrepareRef(signal, 		       UtilPrepareRef::DICT_TAB_INFO_ERROR,		       prepPtr.p->clientRef, prepPtr.p->clientData);    infoEvent("UTIL: Not all primary key attributes requested for table: %s",	      tableName);    releasePreparedOperation(prepOpPtr);    releasePrepare(prepPtr);    return;  }#if 0  AttrMappingBuffer::ConstDataBufferIterator tmpIt;  for (prepPtr.p->prepOpPtr.p->attrMapping.first(tmpIt); tmpIt.curr.i != RNIL;       prepPtr.p->prepOpPtr.p->attrMapping.next(tmpIt)) {    AttributeHeader* ah = (AttributeHeader *) tmpIt.data;    ah->print(stdout);  }#endif    /**********************************************   * Preparing of PreparedOperation signal train    **********************************************/  Uint32 static_len = TcKeyReq::StaticLength;  prepOpPtr.p->tckey.tableId = tableDesc.TableId;  prepOpPtr.p->tckey.tableSchemaVersion = tableDesc.TableVersion;  prepOpPtr.p->noOfKeyAttr = tableDesc.NoOfKeyAttr;  prepOpPtr.p->keyLen = tableDesc.KeyLength; // Total no of words in PK  if (prepOpPtr.p->keyLen > TcKeyReq::MaxKeyInfo) {    jam();    prepOpPtr.p->tckeyLenInBytes = (static_len + TcKeyReq::MaxKeyInfo) * 4;  } else {    jam();    prepOpPtr.p->tckeyLenInBytes = (static_len + prepOpPtr.p->keyLen) * 4;  }  prepOpPtr.p->keyDataPos = static_len;  // Start of keyInfo[] in tckeyreq    Uint32 requestInfo = 0;  TcKeyReq::setAbortOption(requestInfo, TcKeyReq::AbortOnError);  TcKeyReq::setKeyLength(requestInfo, tableDesc.KeyLength);    switch(operationType) {  case(UtilPrepareReq::Read):    prepOpPtr.p->rsLen =      attrLength +       tableDesc.NoOfKeyAttr +      noOfNonPKAttribsStored;          // Read needs a resultset    prepOpPtr.p->noOfAttr = tableDesc.NoOfKeyAttr + noOfNonPKAttribsStored;    prepOpPtr.p->tckey.attrLen = prepOpPtr.p->noOfAttr;    TcKeyReq::setOperationType(requestInfo, ZREAD);    break;  case(UtilPrepareReq::Update):    prepOpPtr.p->rsLen = 0;     prepOpPtr.p->noOfAttr = tableDesc.NoOfKeyAttr + noOfNonPKAttribsStored;    prepOpPtr.p->tckey.attrLen = attrLength + prepOpPtr.p->noOfAttr;    TcKeyReq::setOperationType(requestInfo, ZUPDATE);    break;  case(UtilPrepareReq::Insert):    prepOpPtr.p->rsLen = 0;     prepOpPtr.p->noOfAttr = tableDesc.NoOfKeyAttr + noOfNonPKAttribsStored;    prepOpPtr.p->tckey.attrLen = attrLength + prepOpPtr.p->noOfAttr;    TcKeyReq::setOperationType(requestInfo, ZINSERT);    break;  case(UtilPrepareReq::Delete):    // The number of attributes should equal the size of the primary key    ndbrequire(tableDesc.KeyLength == attrLength);    prepOpPtr.p->rsLen = 0;     prepOpPtr.p->noOfAttr = tableDesc.NoOfKeyAttr;    prepOpPtr.p->tckey.attrLen = 0;    TcKeyReq::setOperationType(requestInfo, ZDELETE);    break;  case(UtilPrepareReq::Write):    prepOpPtr.p->rsLen = 0;     prepOpPtr.p->noOfAttr = tableDesc.NoOfKeyAttr + noOfNonPKAttribsStored;    prepOpPtr.p->tckey.attrLen = attrLength + prepOpPtr.p->noOfAttr;    TcKeyReq::setOperationType(requestInfo, ZWRITE);    break;  }  TcKeyReq::setAIInTcKeyReq(requestInfo, 0);  // Attrinfo sent separately  prepOpPtr.p->tckey.requestInfo = requestInfo;  /****************************   * Confirm completed prepare   ****************************/  UtilPrepareConf * conf = (UtilPrepareConf *)signal->getDataPtr();  conf->senderData = prepPtr.p->clientData;  conf->prepareId = prepPtr.p->prepOpPtr.i;  releaseSections(signal);  sendSignal(prepPtr.p->clientRef, GSN_UTIL_PREPARE_CONF, signal, 	     UtilPrepareConf::SignalLength, JBB);#if 0  prepPtr.p->prepOpPtr.p->print();#endif  releasePrepare(prepPtr);}void DbUtil::execUTIL_RELEASE_REQ(Signal* signal){  jamEntry();      UtilReleaseReq * req = (UtilReleaseReq *)signal->getDataPtr();  const Uint32 clientRef      = signal->senderBlockRef();  const Uint32 prepareId      = req->prepareId;  const Uint32 senderData     = req->senderData;#if 0  /**   * This only works in when ARRAY_GUARD is defined (debug-mode)   */  if (!c_preparedOperationPool.isSeized(prepareId)) {    UtilReleaseRef * ref = (UtilReleaseRef *)signal->getDataPtr();    ref->prepareId = prepareId;    ref->errorCode = UtilReleaseRef::NO_SUCH_PREPARE_SEIZED;    sendSignal(clientRef, GSN_UTIL_RELEASE_REF, signal, 	       UtilReleaseRef::SignalLength, JBB);  }#endif  PreparedOperationPtr prepOpPtr;  c_preparedOperationPool.getPtr(prepOpPtr, prepareId);    releasePreparedOperation(prepOpPtr);    UtilReleaseConf * const conf = (UtilReleaseConf*)signal->getDataPtrSend();  conf->senderData = senderData;  sendSignal(clientRef, GSN_UTIL_RELEASE_CONF, signal, 	     UtilReleaseConf::SignalLength, JBB);}/************************************************************************** * ------------------------------------------------------------------------ *  MODULE:       Sequence Service * ------------------------------------------------------------------------ * *  A service with a stored incrementable number **************************************************************************/voidDbUtil::hardcodedPrepare() {  /**   * Prepare SequenceCurrVal (READ)   */  {    PreparedOperationPtr ptr;    ndbrequire(c_preparedOperationPool.seizeId(ptr, 0));    ptr.p->keyLen = 1;    ptr.p->tckey.attrLen = 1;    ptr.p->rsLen = 3;    ptr.p->tckeyLenInBytes = (TcKeyReq::StaticLength +                              ptr.p->keyLen + ptr.p->tckey.attrLen) * 4;    ptr.p->keyDataPos = TcKeyReq::StaticLength;     ptr.p->tckey.tableId = 0;    Uint32 requestInfo = 0;    TcKeyReq::setAbortOption(requestInfo, TcKeyReq::CommitIfFailFree);    TcKeyReq::setOperationType(requestInfo, ZREAD);    TcKeyReq::setKeyLength(requestInfo, 1);    TcKeyReq::setAIInTcKeyReq(requestInfo, 1);    ptr.p->tckey.requestInfo = requestInfo;    ptr.p->tckey.tableSchemaVersion = 1;    // This is actually attr data    AttributeHeader::init(&ptr.p->tckey.distrGroupHashValue, 1, 0);         ndbrequire(ptr.p->rsInfo.seize(1));    ResultSetInfoBuffer::DataBufferIterator it;     ptr.p->rsInfo.first(it);    AttributeHeader::init(it.data, 1, 2); // Attribute 1 - 2 data words  }  /**   * Prepare SequenceNextVal (UPDATE)   */  {    PreparedOperationPtr ptr;    ndbrequire(c_preparedOperationPool.seizeId(ptr, 1));    ptr.p->keyLen = 1;    ptr.p->rsLen = 3;    ptr.p->tckeyLenInBytes = (TcKeyReq::StaticLength + ptr.p->keyLen + 5) * 4;    ptr.p->keyDataPos = TcKeyReq::StaticLength;     ptr.p->tckey.attrLen = 11;    ptr.p->tckey.tableId = 0;    Uint32 requestInfo = 0;    TcKeyReq::setAbortOption(requestInfo, TcKeyReq::CommitIfFailFree);    TcKeyReq::setOperationType(requestInfo, ZUPDATE);    TcKeyReq::setKeyLength(requestInfo, 1);    TcKeyReq::setAIInTcKeyReq(requestInfo, 5);    TcKeyReq::setInterpretedFlag(requestInfo, 1);    ptr.p->tckey.requestInfo = requestInfo;    ptr.p->tckey.tableSchemaVersion = 1;        // Signal is packed, which is why attrInfo is at distrGroupHashValue     // position     Uint32 * attrInfo = &ptr.p->tckey.distrGroupHashValue;    attrInfo[0] = 0; // IntialReadSize    attrInfo[1] = 5; // InterpretedSize    attrInfo[2] = 0; // FinalUpdateSize    attrInfo[3] = 1; // FinalReadSize    attrInfo[4] = 0; // SubroutineSize        { // AttrInfo      ndbrequire(ptr.p->attrInfo.seize(6));      AttrInfoBuffer::DataBufferIterator it;      ptr.p->attrInfo.first(it);      * it.data = Interpreter::Read(1, 6);      ndbrequire(ptr.p->attrInfo.next(it));      * it.data = Interpreter::LoadConst16(7, 1);      ndbrequire(ptr.p->attrInfo.next(it));      * it.data = Interpreter::Add(7, 6, 7);      ndbrequire(ptr.p->attrInfo.next(it));      * it.data = Interpreter::Write(1, 7);      ndbrequire(ptr.p->attrInfo.next(it));      * it.data = Interpreter::ExitOK();            ndbrequire(ptr.p->attrInfo.next(it));      AttributeHeader::init(it.data, 1, 0);    }        { // ResultSet      ndbrequire(ptr.p->rsInfo.seize(1));      ResultSetInfoBuffer::DataBufferIterator it;       ptr.p->rsInfo.first(it);      AttributeHeader::init(it.data, 1, 2); // Attribute 1 - 2 data words    }  }  /**   * Prepare CreateSequence (INSERT)   */  {    PreparedOperationPtr ptr;    ndbrequire(c_preparedOperationPool.seizeId(ptr, 2));    ptr.p->keyLen = 1;    ptr.p->tckey.attrLen = 5;    ptr.p->rsLen = 0;    ptr.p->tckeyLenInBytes = (TcKeyReq::StaticLength +                              ptr.p->keyLen + ptr.p->tckey.attrLen) * 4;    ptr.p->keyDataPos = TcKeyReq::StaticLength;    ptr.p->tckey.tableId = 0;    Uint32 requestInfo = 0;    TcKeyReq::setAbortOption(requestInfo, TcKeyReq::CommitIfFailFree);    TcKeyReq::setOperationType(requestInfo, ZINSERT);    TcKeyReq::setKeyLength(requestInfo, 1);    TcKeyReq::setAIInTcKeyReq(requestInfo, 0);    ptr.p->tckey.requestInfo = requestInfo;    ptr.p->tckey.tableSchemaVersion = 1;  }}voidDbUtil::execUTIL_SEQUENCE_REQ(Signal* signal){  jamEntry();  UtilSequenceReq * req = (UtilSequenceReq*)signal->getDataPtr();    PreparedOperation * prepOp;    switch(req->requestType){  case UtilSequenceReq::CurrVal:    prepOp = c_preparedOperationPool.getPtr(0); //c_SequenceCurrVal    break;  case UtilSequenceReq::NextVal:    prepOp = c_preparedOperationPool.getPtr(1); //c_SequenceNextVal    break;  case UtilSequenceReq::Create:    prepOp = c_preparedOperationPool.getPtr(2); //c_CreateSequence    break;  default:    ndbrequire(false);    prepOp = 0; // remove warning  }    /**   * 1 Transaction with 1 operation   */  TransactionPtr transPtr;  ndbrequire(c_runningTransactions.seize(transPtr));    OperationPtr opPtr;  ndbrequire(transPtr.p->operations.seize(opPtr));    ndbrequire(opPtr.p->rs.seize(prepOp->rsLen));  ndbrequire(opPtr.p->keyInfo.seize(prepOp->keyLen));  transPtr.p->gsn = GSN_UTIL_SEQUENCE_REQ;  transPtr.p->clientRef = signal->senderBlockRef();  transPtr.p->clientData = req->senderData;  transPtr.p->sequence.sequenceId = req->sequenceId;  transPtr.p->sequence.requestType = req->requestType;    opPtr.p->prepOp   = prepOp;  opPtr.p->prepOp_i = RNIL;  KeyInfoBuffer::DataBufferIterator it;   opPtr.p->keyInfo.first(it);  it.data[0] = transPtr.p->sequence.sequenceId;  if(req->requestType == UtilSequenceReq::Create){    ndbrequire(opPtr.p->attrInfo.seize(5));    AttrInfoBuffer::DataBufferIterator it;       opPtr.p->attrInfo.first(it);    AttributeHeader::init(it.data, 0, 1);    ndbrequire(opPtr.p->attrInfo.next(it));    * it.data = transPtr.p->sequence.sequenceId;    ndbrequire(opPtr.p->attrInfo.next(it));    AttributeHeader::init(it.data, 1, 2);        ndbrequire(opPtr.p->attrInfo.next(it));    * it.data = 0;        ndbrequire(opPtr.p->attrInfo.next(it));    * it.data = 0;  }    runTransaction(signal, transPtr);}intDbUtil::getResultSet(Signal* signal, const Transaction * transP,		     struct LinearSectionPtr sectionsPtr[]) {  OperationPtr opPtr;  ndbrequire(transP->operations.first(opPtr));  ndbrequire(transP->operations.hasNext(opPtr) == false);  int noAttr = 0;  int dataSz = 0;  Uint32* tmpBuf = signal->theData + 25;  const Uint32* headerBuffer = tmpBuf;  const ResultSetBuffer & rs = opPtr.p->rs;  ResultSetInfoBuffer::ConstDataBufferIterator it;  // extract headers  for(rs.first(it); it.curr.i != RNIL; ) {    *tmpBuf++ = it.data[0];    rs.next(it, ((AttributeHeader*)&it.data[0])->getDataSize() + 1);    noAttr++;  }  if (noAttr == 0)    return 0;  const Uint32* dataBuffer = tmpBuf;  // extract data  for(rs.first(it); it.curr.i != RNIL; ) {    int sz = ((AttributeHeader*)&it.data[0])->getDataSize();    rs.next(it,1);    for (int i = 0; i < sz; i++) {      *tmpBuf++ = *it.data;      rs.next(it,1);      dataSz++;    }  }  sectionsPtr[UtilExecuteReq::HEADER_SECTION].p = (Uint32 *)headerBuffer;  sectionsPtr[UtilExecuteReq::HEADER_SECTION].sz = noAttr;  sectionsPtr[UtilExecuteReq::DATA_SECTION].p = (Uint32 *)dataBuffer;  sectionsPtr[UtilExecuteReq::DATA_SECTION].sz = dataSz;  return 1;}voidDbUtil::reportSequence(Signal* signal, const Transaction * transP){  OperationPtr opPtr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -