📄 dbutil.cpp
字号:
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 \0 /******************************************** * Code signal data and send signals to DICT ********************************************/ ndbrequire(req->tableNameLen < MAX_TAB_NAME_SIZE); reader->getString((char*)tableName); LinearSectionPtr ptr[1]; ptr[0].p = (Uint32*)tableName; ptr[0].sz = req->tableNameLen; sendSignal(DBDICT_REF, GSN_GET_TABINFOREQ, signal, GetTabInfoReq::SignalLength, JBB, ptr,1); } else { // (tableKey == UtilPrepareReq::TableId) jam(); req->requestType = GetTabInfoReq::RequestById | GetTabInfoReq::LongSignalConf; req->tableId = reader->getUint32(); sendSignal(DBDICT_REF, GSN_GET_TABINFOREQ, signal, GetTabInfoReq::SignalLength, JBB); } }}/** * @note We assume that this signal comes due to a request related * to a Prepare struct. DictTabInfo:s 'senderData' denotes * the Prepare struct related to the request. */voidDbUtil::execGET_TABINFO_CONF(Signal* signal){ jamEntry(); if(!assembleFragments(signal)){ jam(); return; } /**************** * Decode signal ****************/ GetTabInfoConf * const conf = (GetTabInfoConf*)signal->getDataPtr(); const Uint32 prepI = conf->senderData; const Uint32 totalLen = conf->totalLen; SegmentedSectionPtr dictTabInfoPtr; signal->getSection(dictTabInfoPtr, GetTabInfoConf::DICT_TAB_INFO); ndbrequire(dictTabInfoPtr.sz == totalLen); PreparePtr prepPtr; c_runningPrepares.getPtr(prepPtr, prepI); prepareOperation(signal, prepPtr);}voidDbUtil::execGET_TABINFOREF(Signal* signal){ jamEntry(); GetTabInfoRef * ref = (GetTabInfoRef *)signal->getDataPtr(); Uint32 prepI = ref->senderData;#define EVENT_DEBUG#if 0 //def EVENT_DEBUG ndbout << "Signal GET_TABINFOREF received." << endl; ndbout << "Error Code: " << ref->errorCode << endl; switch (ref->errorCode) { case GetTabInfoRef::InvalidTableId: ndbout << " Msg: Invalid table id" << endl; break; case GetTabInfoRef::TableNotDefined: ndbout << " Msg: Table not defined" << endl; break; case GetTabInfoRef::TableNameToLong: ndbout << " Msg: Table node too long" << endl; break; default: ndbout << " Msg: Unknown error returned from Dict" << endl; break; } #endif PreparePtr prepPtr; c_runningPrepares.getPtr(prepPtr, prepI); sendUtilPrepareRef(signal, UtilPrepareRef::DICT_TAB_INFO_ERROR, prepPtr.p->clientRef, prepPtr.p->clientData); releasePrepare(prepPtr);}/****************************************************************************** * Prepare Operation * * Using a prepare record, prepare an operation (i.e. create PreparedOperation). * Info from both Pepare request (PreparePages) and DictTabInfo is used. * * Algorithm: * -# Seize AttrbuteMapping * - Lookup in preparePages how many attributes should be prepared * - Seize AttributeMapping * -# For each attributes in preparePages * - Lookup id and isPK in dictInfoPages * - Store "no -> (AttributeId, Position)" in AttributeMapping * -# For each map in AttributeMapping * - if (isPK) then assign offset ******************************************************************************/voidDbUtil::prepareOperation(Signal* signal, PreparePtr prepPtr) { jam(); /******************************************* * Seize and store PreparedOperation struct *******************************************/ PreparedOperationPtr prepOpPtr; if(!c_runningPreparedOperations.seize(prepOpPtr)) { jam(); releaseSections(signal); sendUtilPrepareRef(signal, UtilPrepareRef::PREPARED_OPERATION_SEIZE_ERROR, prepPtr.p->clientRef, prepPtr.p->clientData); releasePrepare(prepPtr); return; } prepPtr.p->prepOpPtr = prepOpPtr; /******************** * Read request info ********************/ SimplePropertiesLinearReader prepPagesReader(&prepPtr.p->preparePages.getPtr(0)->data[0], prepPtr.p->prepDataLen); ndbrequire(prepPagesReader.first()); ndbrequire(prepPagesReader.getKey() == UtilPrepareReq::NoOfOperations); const Uint32 noOfOperations = prepPagesReader.getUint32(); ndbrequire(noOfOperations == 1); ndbrequire(prepPagesReader.next()); ndbrequire(prepPagesReader.getKey() == UtilPrepareReq::OperationType); const Uint32 operationType = prepPagesReader.getUint32(); ndbrequire(prepPagesReader.next()); char tableName[MAX_TAB_NAME_SIZE]; Uint32 tableId; UtilPrepareReq::KeyValue tableKey = (UtilPrepareReq::KeyValue) prepPagesReader.getKey(); if (tableKey == UtilPrepareReq::TableId) { jam(); tableId = prepPagesReader.getUint32(); } else { jam(); ndbrequire(prepPagesReader.getKey() == UtilPrepareReq::TableName); ndbrequire(prepPagesReader.getValueLen() <= MAX_TAB_NAME_SIZE); prepPagesReader.getString(tableName); } /****************************************************************** * Seize AttributeMapping (by counting no of attribs in prepPages) ******************************************************************/ Uint32 noOfAttributes = 0; // No of attributes in PreparePages (used later) while(prepPagesReader.next()) { if (tableKey == UtilPrepareReq::TableName) { jam(); ndbrequire(prepPagesReader.getKey() == UtilPrepareReq::AttributeName); } else { jam(); ndbrequire(prepPagesReader.getKey() == UtilPrepareReq::AttributeId); } noOfAttributes++; } ndbrequire(prepPtr.p->prepOpPtr.p->attrMapping.seize(noOfAttributes)); if (operationType == UtilPrepareReq::Read) { ndbrequire(prepPtr.p->prepOpPtr.p->rsInfo.seize(noOfAttributes)); } /*************************************** * For each attribute name, lookup info ***************************************/ // Goto start of attribute names ndbrequire(prepPagesReader.first() && prepPagesReader.next() && prepPagesReader.next()); DictTabInfo::Table tableDesc; tableDesc.init(); AttrMappingBuffer::DataBufferIterator attrMappingIt; ndbrequire(prepPtr.p->prepOpPtr.p->attrMapping.first(attrMappingIt)); ResultSetBuffer::DataBufferIterator rsInfoIt; if (operationType == UtilPrepareReq::Read) { ndbrequire(prepPtr.p->prepOpPtr.p->rsInfo.first(rsInfoIt)); } Uint32 noOfPKAttribsStored = 0; Uint32 noOfNonPKAttribsStored = 0; Uint32 attrLength = 0; Uint32 pkAttrLength = 0; char attrNameRequested[MAX_ATTR_NAME_SIZE]; Uint32 attrIdRequested; while(prepPagesReader.next()) { UtilPrepareReq::KeyValue attributeKey = (UtilPrepareReq::KeyValue) prepPagesReader.getKey(); ndbrequire((attributeKey == UtilPrepareReq::AttributeName) || (attributeKey == UtilPrepareReq::AttributeId)); if (attributeKey == UtilPrepareReq::AttributeName) { jam(); ndbrequire(prepPagesReader.getValueLen() <= MAX_ATTR_NAME_SIZE); prepPagesReader.getString(attrNameRequested); attrIdRequested= ~0u; } else { jam(); attrIdRequested = prepPagesReader.getUint32(); } /***************************************** * Copy DictTabInfo into tableDesc struct *****************************************/ SegmentedSectionPtr ptr; signal->getSection(ptr, GetTabInfoConf::DICT_TAB_INFO); SimplePropertiesSectionReader dictInfoReader(ptr, getSectionSegmentPool()); SimpleProperties::UnpackStatus unpackStatus; unpackStatus = SimpleProperties::unpack(dictInfoReader, &tableDesc, DictTabInfo::TableMapping, DictTabInfo::TableMappingSize, true, true); ndbrequire(unpackStatus == SimpleProperties::Break); /************************ * Lookup in DictTabInfo ************************/ DictTabInfo::Attribute attrDesc; attrDesc.init(); char attrName[MAX_ATTR_NAME_SIZE]; Uint32 attrId= ~(Uint32)0; bool attributeFound = false; Uint32 noOfKeysFound = 0; // # PK attrs found before attr in DICTdata Uint32 noOfNonKeysFound = 0; // # nonPK attrs found before attr in DICTdata for (Uint32 i=0; i<tableDesc.NoOfAttributes; i++) { if (tableKey == UtilPrepareReq::TableName) { jam(); ndbrequire(dictInfoReader.getKey() == DictTabInfo::AttributeName); ndbrequire(dictInfoReader.getValueLen() <= MAX_ATTR_NAME_SIZE); dictInfoReader.getString(attrName); attrId= ~(Uint32)0; // attrId not used } else { // (tableKey == UtilPrepareReq::TableId) jam(); dictInfoReader.next(); // Skip name ndbrequire(dictInfoReader.getKey() == DictTabInfo::AttributeId); attrId = dictInfoReader.getUint32(); attrName[0]= '\0'; // attrName not used } unpackStatus = SimpleProperties::unpack(dictInfoReader, &attrDesc, DictTabInfo::AttributeMapping, DictTabInfo::AttributeMappingSize, true, true); ndbrequire(unpackStatus == SimpleProperties::Break); //attrDesc.print(stdout); if (attrDesc.AttributeKeyFlag) { jam(); noOfKeysFound++; } else { jam(); noOfNonKeysFound++; } if (attributeKey == UtilPrepareReq::AttributeName) { if (strcmp(attrName, attrNameRequested) == 0) { attributeFound = true; break; } } else // (attributeKey == UtilPrepareReq::AttributeId) if (attrId == attrIdRequested) { attributeFound = true; break; } // Move to next attribute ndbassert(dictInfoReader.getKey() == DictTabInfo::AttributeEnd); dictInfoReader.next(); } /********************** * Attribute not found **********************/ if (!attributeFound) { jam(); releaseSections(signal); sendUtilPrepareRef(signal, UtilPrepareRef::DICT_TAB_INFO_ERROR, prepPtr.p->clientRef, prepPtr.p->clientData); infoEvent("UTIL: Unknown attribute requested: %s in table: %s", attrNameRequested, tableName); releasePreparedOperation(prepOpPtr); releasePrepare(prepPtr); return; } /************************************************************** * Attribute found - store in mapping (AttributeId, Position) **************************************************************/ AttributeHeader & attrMap = AttributeHeader::init(attrMappingIt.data, attrDesc.AttributeId, // 1. Store AttrId 0); if (attrDesc.AttributeKeyFlag) { // ** Attribute belongs to PK ** prepOpPtr.p->pkBitmask.set(attrDesc.AttributeId); attrMap.setDataSize(noOfKeysFound - 1); // 2. Store Position noOfPKAttribsStored++; } else { attrMap.setDataSize(0x3fff); // 2. Store Position (fake) noOfNonPKAttribsStored++; /*********************************************************** * Error: Read nonPK Attr before all PK attr have been read ***********************************************************/ if (noOfPKAttribsStored != tableDesc.NoOfKeyAttr) { jam(); releaseSections(signal); sendUtilPrepareRef(signal, UtilPrepareRef::DICT_TAB_INFO_ERROR, prepPtr.p->clientRef, prepPtr.p->clientData); infoEvent("UTIL: Non-PK attr not allowed before " "all PK attrs have been defined, table: %s", tableName); releasePreparedOperation(prepOpPtr); releasePrepare(prepPtr); return; } }#if 0 ndbout << "BEFORE: attrLength: " << attrLength << endl;#endif { int len = 0; switch (attrDesc.AttributeSize) { case DictTabInfo::an8Bit: len = (attrDesc.AttributeArraySize + 3)/ 4; break; case DictTabInfo::a16Bit: len = (attrDesc.AttributeArraySize + 1) / 2; break; case DictTabInfo::a32Bit:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -