Dbdict.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:368k
- void
- Dbdict::createTab_prepare(Signal* signal, CreateTabReq * req){
- const Uint32 gci = req->gci;
- const Uint32 tableId = req->tableId;
- const Uint32 tableVersion = req->tableVersion;
- SegmentedSectionPtr tabInfoPtr;
- signal->getSection(tabInfoPtr, CreateTabReq::DICT_TAB_INFO);
-
- CreateTableRecordPtr createTabPtr;
- if(req->senderRef == reference()){
- jam();
- ndbrequire(c_opCreateTable.find(createTabPtr, req->senderData));
- } else {
- jam();
- c_opCreateTable.seize(createTabPtr);
-
- ndbrequire(!createTabPtr.isNull());
-
- createTabPtr.p->key = req->senderData;
- c_opCreateTable.add(createTabPtr);
- createTabPtr.p->m_errorCode = 0;
- createTabPtr.p->m_tablePtrI = tableId;
- createTabPtr.p->m_coordinatorRef = req->senderRef;
- createTabPtr.p->m_senderRef = req->clientRef;
- createTabPtr.p->m_senderData = req->clientData;
- createTabPtr.p->m_dihAddFragPtr = RNIL;
-
- /**
- * Put data into table record
- */
- ParseDictTabInfoRecord parseRecord;
- parseRecord.requestType = DictTabInfo::AddTableFromDict;
- parseRecord.errorCode = 0;
-
- SimplePropertiesSectionReader r(tabInfoPtr, getSectionSegmentPool());
-
- handleTabInfoInit(r, &parseRecord);
- ndbrequire(parseRecord.errorCode == 0);
- }
-
- ndbrequire(!createTabPtr.isNull());
- SegmentedSectionPtr fragPtr;
- signal->getSection(fragPtr, CreateTabReq::FRAGMENTATION);
- createTabPtr.p->m_tabInfoPtrI = tabInfoPtr.i;
- createTabPtr.p->m_fragmentsPtrI = fragPtr.i;
-
- signal->header.m_noOfSections = 0;
-
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, tableId);
- tabPtr.p->packedSize = tabInfoPtr.sz;
- tabPtr.p->tableVersion = tableVersion;
- tabPtr.p->gciTableCreated = gci;
- SchemaFile::TableEntry tabEntry;
- tabEntry.m_tableVersion = tableVersion;
- tabEntry.m_tableType = tabPtr.p->tableType;
- tabEntry.m_tableState = SchemaFile::ADD_STARTED;
- tabEntry.m_gcp = gci;
- tabEntry.m_noOfPages =
- DIV(tabInfoPtr.sz + ZPAGE_HEADER_SIZE, ZSIZE_OF_PAGES_IN_WORDS);
-
- Callback callback;
- callback.m_callbackData = createTabPtr.p->key;
- callback.m_callbackFunction =
- safe_cast(&Dbdict::createTab_writeSchemaConf1);
-
- updateSchemaState(signal, tableId, &tabEntry, &callback);
- }
- void getSection(SegmentedSectionPtr & ptr, Uint32 i);
- void
- Dbdict::createTab_writeSchemaConf1(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode){
- jam();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, callbackData));
- Callback callback;
- callback.m_callbackData = createTabPtr.p->key;
- callback.m_callbackFunction =
- safe_cast(&Dbdict::createTab_writeTableConf);
-
- SegmentedSectionPtr tabInfoPtr;
- getSection(tabInfoPtr, createTabPtr.p->m_tabInfoPtrI);
- writeTableFile(signal, createTabPtr.p->m_tablePtrI, tabInfoPtr, &callback);
- createTabPtr.p->m_tabInfoPtrI = RNIL;
- signal->setSection(tabInfoPtr, 0);
- releaseSections(signal);
- }
- void
- Dbdict::createTab_writeTableConf(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode){
- jam();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, callbackData));
- SegmentedSectionPtr fragDataPtr;
- getSection(fragDataPtr, createTabPtr.p->m_fragmentsPtrI);
-
- Callback callback;
- callback.m_callbackData = callbackData;
- callback.m_callbackFunction =
- safe_cast(&Dbdict::createTab_dihComplete);
-
- createTab_dih(signal, createTabPtr, fragDataPtr, &callback);
- }
- void
- Dbdict::createTab_dih(Signal* signal,
- CreateTableRecordPtr createTabPtr,
- SegmentedSectionPtr fragDataPtr,
- Callback * c){
- jam();
-
- createTabPtr.p->m_callback = * c;
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
-
- DiAddTabReq * req = (DiAddTabReq*)signal->getDataPtrSend();
- req->connectPtr = createTabPtr.p->key;
- req->tableId = tabPtr.i;
- req->fragType = tabPtr.p->fragmentType;
- req->kValue = tabPtr.p->kValue;
- req->noOfReplicas = 0;
- req->storedTable = tabPtr.p->storedTable;
- req->tableType = tabPtr.p->tableType;
- req->schemaVersion = tabPtr.p->tableVersion;
- req->primaryTableId = tabPtr.p->primaryTableId;
- if(!fragDataPtr.isNull()){
- signal->setSection(fragDataPtr, DiAddTabReq::FRAGMENTATION);
- }
- sendSignal(DBDIH_REF, GSN_DIADDTABREQ, signal,
- DiAddTabReq::SignalLength, JBB);
- }
- static
- void
- calcLHbits(Uint32 * lhPageBits, Uint32 * lhDistrBits,
- Uint32 fid, Uint32 totalFragments)
- {
- Uint32 distrBits = 0;
- Uint32 pageBits = 0;
-
- Uint32 tmp = 1;
- while (tmp < totalFragments) {
- jam();
- tmp <<= 1;
- distrBits++;
- }//while
- #ifdef ndb_classical_lhdistrbits
- if (tmp != totalFragments) {
- tmp >>= 1;
- if ((fid >= (totalFragments - tmp)) && (fid < (tmp - 1))) {
- distrBits--;
- }//if
- }//if
- #endif
- * lhPageBits = pageBits;
- * lhDistrBits = distrBits;
- }//calcLHbits()
- void
- Dbdict::execADD_FRAGREQ(Signal* signal) {
- jamEntry();
- AddFragReq * const req = (AddFragReq*)signal->getDataPtr();
-
- Uint32 dihPtr = req->dihPtr;
- Uint32 senderData = req->senderData;
- Uint32 tableId = req->tableId;
- Uint32 fragId = req->fragmentId;
- Uint32 node = req->nodeId;
- Uint32 lcpNo = req->nextLCP;
- Uint32 fragCount = req->totalFragments;
- Uint32 requestInfo = req->requestInfo;
- Uint32 startGci = req->startGci;
- ndbrequire(node == getOwnNodeId());
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, senderData));
-
- createTabPtr.p->m_dihAddFragPtr = dihPtr;
-
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, tableId);
- #if 0
- tabPtr.p->gciTableCreated = (startGci > tabPtr.p->gciTableCreated ? startGci:
- startGci > tabPtr.p->gciTableCreated);
- #endif
-
- /**
- * Calc lh3PageBits
- */
- Uint32 lhDistrBits = 0;
- Uint32 lhPageBits = 0;
- ::calcLHbits(&lhPageBits, &lhDistrBits, fragId, fragCount);
- {
- LqhFragReq* req = (LqhFragReq*)signal->getDataPtrSend();
- req->senderData = senderData;
- req->senderRef = reference();
- req->fragmentId = fragId;
- req->requestInfo = requestInfo;
- req->tableId = tableId;
- req->localKeyLength = tabPtr.p->localKeyLen;
- req->maxLoadFactor = tabPtr.p->maxLoadFactor;
- req->minLoadFactor = tabPtr.p->minLoadFactor;
- req->kValue = tabPtr.p->kValue;
- req->lh3DistrBits = lhDistrBits;
- req->lh3PageBits = lhPageBits;
- req->noOfAttributes = tabPtr.p->noOfAttributes;
- req->noOfNullAttributes = tabPtr.p->noOfNullAttr;
- req->noOfPagesToPreAllocate = 0;
- req->schemaVersion = tabPtr.p->tableVersion;
- Uint32 keyLen = tabPtr.p->tupKeyLength;
- req->keyLength = keyLen > 8 ? 0 : keyLen; // Put this into ACC instead
- req->nextLCP = lcpNo;
- req->noOfKeyAttr = tabPtr.p->noOfPrimkey;
- req->noOfNewAttr = 0;
- // noOfCharsets passed to TUP in upper half
- req->noOfNewAttr |= (tabPtr.p->noOfCharsets << 16);
- req->checksumIndicator = 1;
- req->noOfAttributeGroups = 1;
- req->GCPIndicator = 0;
- req->startGci = startGci;
- req->tableType = tabPtr.p->tableType;
- req->primaryTableId = tabPtr.p->primaryTableId;
- sendSignal(DBLQH_REF, GSN_LQHFRAGREQ, signal,
- LqhFragReq::SignalLength, JBB);
- }
- }
- void
- Dbdict::execLQHFRAGREF(Signal * signal){
- jamEntry();
- LqhFragRef * const ref = (LqhFragRef*)signal->getDataPtr();
-
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, ref->senderData));
-
- createTabPtr.p->setErrorCode(ref->errorCode);
-
- {
- AddFragRef * const ref = (AddFragRef*)signal->getDataPtr();
- ref->dihPtr = createTabPtr.p->m_dihAddFragPtr;
- sendSignal(DBDIH_REF, GSN_ADD_FRAGREF, signal,
- AddFragRef::SignalLength, JBB);
- }
- }
- void
- Dbdict::execLQHFRAGCONF(Signal * signal){
- jamEntry();
- LqhFragConf * const conf = (LqhFragConf*)signal->getDataPtr();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, conf->senderData));
-
- createTabPtr.p->m_lqhFragPtr = conf->lqhFragPtr;
-
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
- sendLQHADDATTRREQ(signal, createTabPtr, tabPtr.p->firstAttribute);
- }
- void
- Dbdict::sendLQHADDATTRREQ(Signal* signal,
- CreateTableRecordPtr createTabPtr,
- Uint32 attributePtrI){
- jam();
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
- LqhAddAttrReq * const req = (LqhAddAttrReq*)signal->getDataPtrSend();
- Uint32 i = 0;
- for(i = 0; i<LqhAddAttrReq::MAX_ATTRIBUTES && attributePtrI != RNIL; i++){
- jam();
- AttributeRecordPtr attrPtr;
- c_attributeRecordPool.getPtr(attrPtr, attributePtrI);
- LqhAddAttrReq::Entry& entry = req->attributes[i];
- entry.attrId = attrPtr.p->attributeId;
- entry.attrDescriptor = attrPtr.p->attributeDescriptor;
- entry.extTypeInfo = attrPtr.p->extType;
- // charset number passed to TUP, TUX in upper half
- entry.extTypeInfo |= (attrPtr.p->extPrecision & ~0xFFFF);
- if (tabPtr.p->isIndex()) {
- Uint32 primaryAttrId;
- if (attrPtr.p->nextAttrInTable != RNIL) {
- getIndexAttr(tabPtr, attributePtrI, &primaryAttrId);
- } else {
- primaryAttrId = ZNIL;
- if (tabPtr.p->isOrderedIndex())
- entry.attrId = 0; // attribute goes to TUP
- }
- entry.attrId |= (primaryAttrId << 16);
- }
- attributePtrI = attrPtr.p->nextAttrInTable;
- }
- req->lqhFragPtr = createTabPtr.p->m_lqhFragPtr;
- req->senderData = createTabPtr.p->key;
- req->senderAttrPtr = attributePtrI;
- req->noOfAttributes = i;
-
- sendSignal(DBLQH_REF, GSN_LQHADDATTREQ, signal,
- LqhAddAttrReq::HeaderLength + LqhAddAttrReq::EntryLength * i, JBB);
- }
- void
- Dbdict::execLQHADDATTREF(Signal * signal){
- jamEntry();
- LqhAddAttrRef * const ref = (LqhAddAttrRef*)signal->getDataPtr();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, ref->senderData));
-
- createTabPtr.p->setErrorCode(ref->errorCode);
-
- {
- AddFragRef * const ref = (AddFragRef*)signal->getDataPtr();
- ref->dihPtr = createTabPtr.p->m_dihAddFragPtr;
- sendSignal(DBDIH_REF, GSN_ADD_FRAGREF, signal,
- AddFragRef::SignalLength, JBB);
- }
-
- }
- void
- Dbdict::execLQHADDATTCONF(Signal * signal){
- jamEntry();
- LqhAddAttrConf * const conf = (LqhAddAttrConf*)signal->getDataPtr();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, conf->senderData));
-
- const Uint32 fragId = conf->fragId;
- const Uint32 nextAttrPtr = conf->senderAttrPtr;
- if(nextAttrPtr != RNIL){
- jam();
- sendLQHADDATTRREQ(signal, createTabPtr, nextAttrPtr);
- return;
- }
- {
- AddFragConf * const conf = (AddFragConf*)signal->getDataPtr();
- conf->dihPtr = createTabPtr.p->m_dihAddFragPtr;
- conf->fragId = fragId;
- sendSignal(DBDIH_REF, GSN_ADD_FRAGCONF, signal,
- AddFragConf::SignalLength, JBB);
- }
- }
- void
- Dbdict::execDIADDTABREF(Signal* signal){
- jam();
-
- DiAddTabRef * const ref = (DiAddTabRef*)signal->getDataPtr();
-
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, ref->senderData));
-
- createTabPtr.p->setErrorCode(ref->errorCode);
- execute(signal, createTabPtr.p->m_callback, 0);
- }
- void
- Dbdict::execDIADDTABCONF(Signal* signal){
- jam();
-
- DiAddTabConf * const conf = (DiAddTabConf*)signal->getDataPtr();
-
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, conf->senderData));
- signal->theData[0] = createTabPtr.p->key;
- signal->theData[1] = reference();
- signal->theData[2] = createTabPtr.p->m_tablePtrI;
- if(createTabPtr.p->m_dihAddFragPtr != RNIL){
- jam();
- /**
- * We did perform at least one LQHFRAGREQ
- */
- sendSignal(DBLQH_REF, GSN_TAB_COMMITREQ, signal, 3, JBB);
- return;
- } else {
- /**
- * No local fragment (i.e. no LQHFRAGREQ)
- */
- execute(signal, createTabPtr.p->m_callback, 0);
- return;
- //sendSignal(DBDIH_REF, GSN_TAB_COMMITREQ, signal, 3, JBB);
- }
- }
- void
- Dbdict::execTAB_COMMITREF(Signal* signal) {
- jamEntry();
- ndbrequire(false);
- }//execTAB_COMMITREF()
- void
- Dbdict::execTAB_COMMITCONF(Signal* signal){
- jamEntry();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, signal->theData[0]));
-
- if(refToBlock(signal->getSendersBlockRef()) == DBLQH){
- execute(signal, createTabPtr.p->m_callback, 0);
- return;
- }
- if(refToBlock(signal->getSendersBlockRef()) == DBDIH){
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
-
- signal->theData[0] = tabPtr.i;
- signal->theData[1] = tabPtr.p->tableVersion;
- signal->theData[2] = (Uint32)tabPtr.p->storedTable;
- signal->theData[3] = reference();
- signal->theData[4] = (Uint32)tabPtr.p->tableType;
- signal->theData[5] = createTabPtr.p->key;
- sendSignal(DBTC_REF, GSN_TC_SCHVERREQ, signal, 6, JBB);
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::createTab_dihComplete(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode){
- jam();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, callbackData));
- //@todo check for master failed
-
- if(createTabPtr.p->m_errorCode == 0){
- jam();
- CreateTabConf * const conf = (CreateTabConf*)signal->getDataPtr();
- conf->senderRef = reference();
- conf->senderData = createTabPtr.p->key;
- sendSignal(createTabPtr.p->m_coordinatorRef, GSN_CREATE_TAB_CONF,
- signal, CreateTabConf::SignalLength, JBB);
- return;
- }
- CreateTabRef * const ref = (CreateTabRef*)signal->getDataPtr();
- ref->senderRef = reference();
- ref->senderData = createTabPtr.p->key;
- ref->errorCode = createTabPtr.p->m_errorCode;
- ref->errorLine = 0;
- ref->errorKey = 0;
- ref->errorStatus = 0;
- sendSignal(createTabPtr.p->m_coordinatorRef, GSN_CREATE_TAB_REF,
- signal, CreateTabRef::SignalLength, JBB);
- }
- void
- Dbdict::createTab_commit(Signal * signal, CreateTabReq * req){
- jam();
-
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, req->senderData));
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
-
- SchemaFile::TableEntry tabEntry;
- tabEntry.m_tableVersion = tabPtr.p->tableVersion;
- tabEntry.m_tableType = tabPtr.p->tableType;
- tabEntry.m_tableState = SchemaFile::TABLE_ADD_COMMITTED;
- tabEntry.m_gcp = tabPtr.p->gciTableCreated;
- tabEntry.m_noOfPages =
- DIV(tabPtr.p->packedSize + ZPAGE_HEADER_SIZE, ZSIZE_OF_PAGES_IN_WORDS);
-
- Callback callback;
- callback.m_callbackData = createTabPtr.p->key;
- callback.m_callbackFunction =
- safe_cast(&Dbdict::createTab_writeSchemaConf2);
-
- updateSchemaState(signal, tabPtr.i, &tabEntry, &callback);
- }
- void
- Dbdict::createTab_writeSchemaConf2(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode){
- jam();
-
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, callbackData));
-
- Callback c;
- c.m_callbackData = callbackData;
- c.m_callbackFunction = safe_cast(&Dbdict::createTab_alterComplete);
- alterTab_activate(signal, createTabPtr, &c);
- }
- void
- Dbdict::createTab_alterComplete(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode){
- jam();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, callbackData));
-
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
- tabPtr.p->tabState = TableRecord::DEFINED;
-
- //@todo check error
- //@todo check master failed
-
- CreateTabConf * const conf = (CreateTabConf*)signal->getDataPtr();
- conf->senderRef = reference();
- conf->senderData = createTabPtr.p->key;
- sendSignal(createTabPtr.p->m_coordinatorRef, GSN_CREATE_TAB_CONF,
- signal, CreateTabConf::SignalLength, JBB);
- if(createTabPtr.p->m_coordinatorRef != reference()){
- jam();
- c_opCreateTable.release(createTabPtr);
- }
- }
- void
- Dbdict::createTab_drop(Signal* signal, CreateTabReq * req){
- jam();
- const Uint32 key = req->senderData;
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, key));
-
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
- tabPtr.p->tabState = TableRecord::DROPPING;
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.seize(dropTabPtr));
-
- dropTabPtr.p->key = key;
- c_opDropTable.add(dropTabPtr);
-
- dropTabPtr.p->m_errorCode = 0;
- dropTabPtr.p->m_request.tableId = createTabPtr.p->m_tablePtrI;
- dropTabPtr.p->m_requestType = DropTabReq::CreateTabDrop;
- dropTabPtr.p->m_coordinatorRef = createTabPtr.p->m_coordinatorRef;
- dropTabPtr.p->m_participantData.m_gsn = GSN_DROP_TAB_REQ;
-
- dropTabPtr.p->m_participantData.m_block = 0;
- dropTabPtr.p->m_participantData.m_callback.m_callbackData = req->senderData;
- dropTabPtr.p->m_participantData.m_callback.m_callbackFunction =
- safe_cast(&Dbdict::createTab_dropComplete);
- dropTab_nextStep(signal, dropTabPtr);
- }
- void
- Dbdict::createTab_dropComplete(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode){
- jam();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, callbackData));
-
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, callbackData));
- TableRecordPtr tabPtr;
- c_tableRecordPool.getPtr(tabPtr, createTabPtr.p->m_tablePtrI);
-
- releaseTableObject(tabPtr.i);
- PageRecordPtr pagePtr;
- c_pageRecordArray.getPtr(pagePtr, c_schemaRecord.schemaPage);
- SchemaFile::TableEntry * tableEntry = getTableEntry(pagePtr.p, tabPtr.i);
- tableEntry->m_tableState = SchemaFile::DROP_TABLE_COMMITTED;
-
- //@todo check error
- //@todo check master failed
-
- CreateTabConf * const conf = (CreateTabConf*)signal->getDataPtr();
- conf->senderRef = reference();
- conf->senderData = createTabPtr.p->key;
- sendSignal(createTabPtr.p->m_coordinatorRef, GSN_CREATE_TAB_CONF,
- signal, CreateTabConf::SignalLength, JBB);
- if(createTabPtr.p->m_coordinatorRef != reference()){
- jam();
- c_opCreateTable.release(createTabPtr);
- }
- c_opDropTable.release(dropTabPtr);
- }
- void
- Dbdict::alterTab_activate(Signal* signal, CreateTableRecordPtr createTabPtr,
- Callback * c){
- createTabPtr.p->m_callback = * c;
-
- signal->theData[0] = createTabPtr.p->key;
- signal->theData[1] = reference();
- signal->theData[2] = createTabPtr.p->m_tablePtrI;
- sendSignal(DBDIH_REF, GSN_TAB_COMMITREQ, signal, 3, JBB);
- }
- void
- Dbdict::execTC_SCHVERCONF(Signal* signal){
- jamEntry();
- CreateTableRecordPtr createTabPtr;
- ndbrequire(c_opCreateTable.find(createTabPtr, signal->theData[1]));
- execute(signal, createTabPtr.p->m_callback, 0);
- }
- #define tabRequire(cond, error)
- if (!(cond)) {
- jam();
- parseP->errorCode = error; parseP->errorLine = __LINE__;
- parseP->errorKey = it.getKey();
- return;
- }//if
- // handleAddTableFailure(signal, __LINE__, allocatedTable);
- void Dbdict::handleTabInfoInit(SimpleProperties::Reader & it,
- ParseDictTabInfoRecord * parseP,
- bool checkExist)
- {
- /* ---------------------------------------------------------------- */
- // We always start by handling table name since this must be the first
- // item in the list. Through the table name we can derive if it is a
- // correct name, a new name or an already existing table.
- /* ---------------------------------------------------------------- */
- it.first();
- SimpleProperties::UnpackStatus status;
- DictTabInfo::Table tableDesc; tableDesc.init();
- status = SimpleProperties::unpack(it, &tableDesc,
- DictTabInfo::TableMapping,
- DictTabInfo::TableMappingSize,
- true, true);
-
- if(status != SimpleProperties::Break){
- parseP->errorCode = CreateTableRef::InvalidFormat;
- parseP->status = status;
- parseP->errorKey = it.getKey();
- parseP->errorLine = __LINE__;
- return;
- }
- if(parseP->requestType == DictTabInfo::AlterTableFromAPI)
- {
- ndbrequire(!checkExist);
- }
- if(!checkExist)
- {
- ndbrequire(parseP->requestType == DictTabInfo::AlterTableFromAPI);
- }
-
- /* ---------------------------------------------------------------- */
- // Verify that table name is an allowed table name.
- // TODO
- /* ---------------------------------------------------------------- */
- const Uint32 tableNameLength = strlen(tableDesc.TableName) + 1;
- TableRecord keyRecord;
- tabRequire(tableNameLength <= sizeof(keyRecord.tableName),
- CreateTableRef::TableNameTooLong);
- strcpy(keyRecord.tableName, tableDesc.TableName);
-
- TableRecordPtr tablePtr;
- c_tableRecordHash.find(tablePtr, keyRecord);
-
- if (checkExist){
- jam();
- /* ---------------------------------------------------------------- */
- // Check if table already existed.
- /* ---------------------------------------------------------------- */
- tabRequire(tablePtr.i == RNIL, CreateTableRef::TableAlreadyExist);
- }
- switch (parseP->requestType) {
- case DictTabInfo::CreateTableFromAPI: {
- jam();
- }
- case DictTabInfo::AlterTableFromAPI:{
- jam();
- tablePtr.i = getFreeTableRecord(tableDesc.PrimaryTableId);
- /* ---------------------------------------------------------------- */
- // Check if no free tables existed.
- /* ---------------------------------------------------------------- */
- tabRequire(tablePtr.i != RNIL, CreateTableRef::NoMoreTableRecords);
-
- c_tableRecordPool.getPtr(tablePtr);
- break;
- }
- case DictTabInfo::AddTableFromDict:
- case DictTabInfo::ReadTableFromDiskSR:
- case DictTabInfo::GetTabInfoConf:
- {
- /* ---------------------------------------------------------------- */
- // Get table id and check that table doesn't already exist
- /* ---------------------------------------------------------------- */
- tablePtr.i = tableDesc.TableId;
-
- if (parseP->requestType == DictTabInfo::ReadTableFromDiskSR) {
- ndbrequire(tablePtr.i == c_restartRecord.activeTable);
- }//if
- if (parseP->requestType == DictTabInfo::GetTabInfoConf) {
- ndbrequire(tablePtr.i == c_restartRecord.activeTable);
- }//if
-
- c_tableRecordPool.getPtr(tablePtr);
- ndbrequire(tablePtr.p->tabState == TableRecord::NOT_DEFINED);
-
- //Uint32 oldTableVersion = tablePtr.p->tableVersion;
- initialiseTableRecord(tablePtr);
- if (parseP->requestType == DictTabInfo::AddTableFromDict) {
- jam();
- tablePtr.p->tabState = TableRecord::DEFINING;
- }//if
- #ifdef HAVE_TABLE_REORG
- /* ---------------------------------------------------------------- */
- // Get id of second table id and check that table doesn't already exist
- // and set up links between first and second table.
- /* ---------------------------------------------------------------- */
- TableRecordPtr secondTablePtr;
- secondTablePtr.i = tableDesc.SecondTableId;
- c_tableRecordPool.getPtr(secondTablePtr);
- ndbrequire(secondTablePtr.p->tabState == TableRecord::NOT_DEFINED);
-
- initialiseTableRecord(secondTablePtr);
- secondTablePtr.p->tabState = TableRecord::REORG_TABLE_PREPARED;
- secondTablePtr.p->secondTable = tablePtr.i;
- tablePtr.p->secondTable = secondTablePtr.i;
- #endif
- /* ---------------------------------------------------------------- */
- // Set table version
- /* ---------------------------------------------------------------- */
- Uint32 tableVersion = tableDesc.TableVersion;
- tablePtr.p->tableVersion = tableVersion;
-
- break;
- }
- default:
- ndbrequire(false);
- break;
- }//switch
- parseP->tablePtr = tablePtr;
-
- strcpy(tablePtr.p->tableName, keyRecord.tableName);
- if (parseP->requestType != DictTabInfo::AlterTableFromAPI) {
- jam();
- #ifdef VM_TRACE
- ndbout_c("Dbdict: name=%s,id=%u", tablePtr.p->tableName, tablePtr.i);
- TableRecordPtr tmp;
- ndbrequire(!c_tableRecordHash.find(tmp, * tablePtr.p));
- #endif
- c_tableRecordHash.add(tablePtr);
- }
-
- //tablePtr.p->noOfPrimkey = tableDesc.NoOfKeyAttr;
- //tablePtr.p->noOfNullAttr = tableDesc.NoOfNullable;
- //tablePtr.p->tupKeyLength = tableDesc.KeyLength;
- tablePtr.p->noOfAttributes = tableDesc.NoOfAttributes;
- tablePtr.p->storedTable = tableDesc.TableLoggedFlag;
- tablePtr.p->minLoadFactor = tableDesc.MinLoadFactor;
- tablePtr.p->maxLoadFactor = tableDesc.MaxLoadFactor;
- tablePtr.p->fragmentType = (DictTabInfo::FragmentType)tableDesc.FragmentType;
- tablePtr.p->fragmentKeyType = (DictTabInfo::FragmentKeyType)tableDesc.FragmentKeyType;
- tablePtr.p->tableType = (DictTabInfo::TableType)tableDesc.TableType;
- tablePtr.p->kValue = tableDesc.TableKValue;
- tablePtr.p->fragmentCount = tableDesc.FragmentCount;
- tablePtr.p->frmLen = tableDesc.FrmLen;
- memcpy(tablePtr.p->frmData, tableDesc.FrmData, tableDesc.FrmLen);
- if(tableDesc.PrimaryTableId != RNIL) {
-
- tablePtr.p->primaryTableId = tableDesc.PrimaryTableId;
- tablePtr.p->indexState = (TableRecord::IndexState)tableDesc.IndexState;
- tablePtr.p->insertTriggerId = tableDesc.InsertTriggerId;
- tablePtr.p->updateTriggerId = tableDesc.UpdateTriggerId;
- tablePtr.p->deleteTriggerId = tableDesc.DeleteTriggerId;
- tablePtr.p->customTriggerId = tableDesc.CustomTriggerId;
- } else {
- tablePtr.p->primaryTableId = RNIL;
- tablePtr.p->indexState = TableRecord::IS_UNDEFINED;
- tablePtr.p->insertTriggerId = RNIL;
- tablePtr.p->updateTriggerId = RNIL;
- tablePtr.p->deleteTriggerId = RNIL;
- tablePtr.p->customTriggerId = RNIL;
- }
- tablePtr.p->buildTriggerId = RNIL;
- tablePtr.p->indexLocal = 0;
-
- handleTabInfo(it, parseP);
- if(parseP->errorCode != 0)
- {
- /**
- * Release table
- */
- releaseTableObject(tablePtr.i, checkExist);
- }
- }//handleTabInfoInit()
- void Dbdict::handleTabInfo(SimpleProperties::Reader & it,
- ParseDictTabInfoRecord * parseP)
- {
- TableRecordPtr tablePtr = parseP->tablePtr;
-
- SimpleProperties::UnpackStatus status;
-
- Uint32 keyCount = 0;
- Uint32 keyLength = 0;
- Uint32 attrCount = tablePtr.p->noOfAttributes;
- Uint32 nullCount = 0;
- Uint32 noOfCharsets = 0;
- Uint16 charsets[128];
- Uint32 recordLength = 0;
- AttributeRecordPtr attrPtr;
- c_attributeRecordHash.removeAll();
-
- for(Uint32 i = 0; i<attrCount; i++){
- /**
- * Attribute Name
- */
- DictTabInfo::Attribute attrDesc; attrDesc.init();
- status = SimpleProperties::unpack(it, &attrDesc,
- DictTabInfo::AttributeMapping,
- DictTabInfo::AttributeMappingSize,
- true, true);
- if(status != SimpleProperties::Break){
- parseP->errorCode = CreateTableRef::InvalidFormat;
- parseP->status = status;
- parseP->errorKey = it.getKey();
- parseP->errorLine = __LINE__;
- return;
- }
- /**
- * Check that attribute is not defined twice
- */
- AttributeRecord tmpAttr;
- {
- strcpy(tmpAttr.attributeName, attrDesc.AttributeName);
-
- AttributeRecordPtr attrPtr;
- c_attributeRecordHash.find(attrPtr, tmpAttr);
-
- if(attrPtr.i != RNIL){
- parseP->errorCode = CreateTableRef::AttributeNameTwice;
- return;
- }
- }
-
- if(!getNewAttributeRecord(tablePtr, attrPtr)){
- jam();
- parseP->errorCode = CreateTableRef::NoMoreAttributeRecords;
- return;
- }
-
- /**
- * TmpAttrib to Attribute mapping
- */
- strcpy(attrPtr.p->attributeName, attrDesc.AttributeName);
- attrPtr.p->attributeId = attrDesc.AttributeId;
- attrPtr.p->tupleKey = (keyCount + 1) * attrDesc.AttributeKeyFlag;
- attrPtr.p->extType = attrDesc.AttributeExtType;
- attrPtr.p->extPrecision = attrDesc.AttributeExtPrecision;
- attrPtr.p->extScale = attrDesc.AttributeExtScale;
- attrPtr.p->extLength = attrDesc.AttributeExtLength;
- // charset in upper half of precision
- unsigned csNumber = (attrPtr.p->extPrecision >> 16);
- if (csNumber != 0) {
- CHARSET_INFO* cs = get_charset(csNumber, MYF(0));
- if (cs == NULL) {
- parseP->errorCode = CreateTableRef::InvalidCharset;
- parseP->errorLine = __LINE__;
- return;
- }
- unsigned i = 0;
- while (i < noOfCharsets) {
- if (charsets[i] == csNumber)
- break;
- i++;
- }
- if (i == noOfCharsets) {
- noOfCharsets++;
- if (noOfCharsets > sizeof(charsets)/sizeof(charsets[0])) {
- parseP->errorCode = CreateTableRef::InvalidFormat;
- parseP->errorLine = __LINE__;
- return;
- }
- charsets[i] = csNumber;
- }
- }
- /**
- * Ignore incoming old-style type and recompute it.
- */
- bool translateOk = attrDesc.translateExtType();
- tabRequire(translateOk, CreateTableRef::Inconsistency);
- if(attrDesc.AttributeArraySize > 65535){
- parseP->errorCode = CreateTableRef::ArraySizeTooBig;
- parseP->status = status;
- parseP->errorKey = it.getKey();
- parseP->errorLine = __LINE__;
- return;
- }
-
- Uint32 desc = 0;
- AttributeDescriptor::setType(desc, attrDesc.AttributeType);
- AttributeDescriptor::setSize(desc, attrDesc.AttributeSize);
- AttributeDescriptor::setArray(desc, attrDesc.AttributeArraySize);
- AttributeDescriptor::setNullable(desc, attrDesc.AttributeNullableFlag);
- AttributeDescriptor::setDGroup(desc, attrDesc.AttributeDGroup);
- AttributeDescriptor::setDKey(desc, attrDesc.AttributeDKey);
- AttributeDescriptor::setPrimaryKey(desc, attrDesc.AttributeKeyFlag);
- AttributeDescriptor::setStoredInTup(desc, attrDesc.AttributeStoredInd);
- attrPtr.p->attributeDescriptor = desc;
- attrPtr.p->autoIncrement = attrDesc.AttributeAutoIncrement;
- strcpy(attrPtr.p->defaultValue, attrDesc.AttributeDefaultValue);
-
- tabRequire(attrDesc.AttributeId == i, CreateTableRef::InvalidFormat);
-
- attrCount ++;
- keyCount += attrDesc.AttributeKeyFlag;
- nullCount += attrDesc.AttributeNullableFlag;
-
- const Uint32 aSz = (1 << attrDesc.AttributeSize);
- const Uint32 sz = ((aSz * attrDesc.AttributeArraySize) + 31) >> 5;
-
- recordLength += sz;
- if(attrDesc.AttributeKeyFlag){
- keyLength += sz;
- if(attrDesc.AttributeNullableFlag){
- parseP->errorCode = CreateTableRef::NullablePrimaryKey;
- parseP->status = status;
- parseP->errorKey = it.getKey();
- parseP->errorLine = __LINE__;
- return;
- }
- }
-
- if (parseP->requestType != DictTabInfo::AlterTableFromAPI)
- c_attributeRecordHash.add(attrPtr);
-
- if(!it.next())
- break;
-
- if(it.getKey() != DictTabInfo::AttributeName)
- break;
- }//while
-
- tablePtr.p->noOfPrimkey = keyCount;
- tablePtr.p->noOfNullAttr = nullCount;
- tablePtr.p->noOfCharsets = noOfCharsets;
- tablePtr.p->tupKeyLength = keyLength;
- tabRequire(recordLength<= MAX_TUPLE_SIZE_IN_WORDS,
- CreateTableRef::RecordTooBig);
- tabRequire(keyLength <= MAX_KEY_SIZE_IN_WORDS,
- CreateTableRef::InvalidPrimaryKeySize);
- tabRequire(keyLength > 0,
- CreateTableRef::InvalidPrimaryKeySize);
-
- }//handleTabInfo()
- /* ---------------------------------------------------------------- */
- // DICTTABCONF is sent when participants have received all DICTTABINFO
- // and successfully handled it.
- // Also sent to self (DICT master) when index table creation ready.
- /* ---------------------------------------------------------------- */
- void Dbdict::execCREATE_TABLE_CONF(Signal* signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 0);
- CreateTableConf * const conf = (CreateTableConf *)signal->getDataPtr();
- // assume part of create index operation
- OpCreateIndexPtr opPtr;
- c_opCreateIndex.find(opPtr, conf->senderData);
- ndbrequire(! opPtr.isNull());
- opPtr.p->m_request.setIndexId(conf->tableId);
- opPtr.p->m_request.setIndexVersion(conf->tableVersion);
- createIndex_fromCreateTable(signal, opPtr);
- }//execCREATE_TABLE_CONF()
- void Dbdict::execCREATE_TABLE_REF(Signal* signal)
- {
- jamEntry();
- CreateTableRef * const ref = (CreateTableRef *)signal->getDataPtr();
- // assume part of create index operation
- OpCreateIndexPtr opPtr;
- c_opCreateIndex.find(opPtr, ref->senderData);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- createIndex_fromCreateTable(signal, opPtr);
- }//execCREATE_TABLE_REF()
- /* ---------------------------------------------------------------- */
- // New global checkpoint created.
- /* ---------------------------------------------------------------- */
- void Dbdict::execWAIT_GCP_CONF(Signal* signal)
- {
- #if 0
- TableRecordPtr tablePtr;
- jamEntry();
- WaitGCPConf* const conf = (WaitGCPConf*)&signal->theData[0];
- c_tableRecordPool.getPtr(tablePtr, c_connRecord.connTableId);
- tablePtr.p->gciTableCreated = conf->gcp;
- sendUpdateSchemaState(signal,
- tablePtr.i,
- SchemaFile::TABLE_ADD_COMMITTED,
- c_connRecord.noOfPagesForTable,
- conf->gcp);
- #endif
- }//execWAIT_GCP_CONF()
- /* ---------------------------------------------------------------- */
- // Refused new global checkpoint.
- /* ---------------------------------------------------------------- */
- void Dbdict::execWAIT_GCP_REF(Signal* signal)
- {
- jamEntry();
- WaitGCPRef* const ref = (WaitGCPRef*)&signal->theData[0];
- /* ---------------------------------------------------------------- */
- // Error Handling code needed
- /* ---------------------------------------------------------------- */
- progError(ref->errorCode, 0);
- }//execWAIT_GCP_REF()
- /* **************************************************************** */
- /* ---------------------------------------------------------------- */
- /* MODULE: DROP TABLE -------------------- */
- /* ---------------------------------------------------------------- */
- /* */
- /* This module contains the code used to drop a table. */
- /* ---------------------------------------------------------------- */
- /* **************************************************************** */
- void
- Dbdict::execDROP_TABLE_REQ(Signal* signal){
- jamEntry();
- DropTableReq* req = (DropTableReq*)signal->getDataPtr();
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, req->tableId, false);
- if(tablePtr.isNull()){
- jam();
- dropTableRef(signal, req, DropTableRef::NoSuchTable);
- return;
- }
- if(getOwnNodeId() != c_masterNodeId){
- jam();
- dropTableRef(signal, req, DropTableRef::NotMaster);
- return;
- }
- if(c_blockState != BS_IDLE){
- jam();
- dropTableRef(signal, req, DropTableRef::Busy);
- return;
- }
-
- const TableRecord::TabState tabState = tablePtr.p->tabState;
- bool ok = false;
- switch(tabState){
- case TableRecord::NOT_DEFINED:
- case TableRecord::REORG_TABLE_PREPARED:
- case TableRecord::DEFINING:
- case TableRecord::CHECKED:
- jam();
- dropTableRef(signal, req, DropTableRef::NoSuchTable);
- return;
- case TableRecord::DEFINED:
- ok = true;
- jam();
- break;
- case TableRecord::PREPARE_DROPPING:
- case TableRecord::DROPPING:
- jam();
- dropTableRef(signal, req, DropTableRef::DropInProgress);
- return;
- case TableRecord::BACKUP_ONGOING:
- jam();
- dropTableRef(signal, req, DropTableRef::BackupInProgress);
- return;
- }
- ndbrequire(ok);
- if(tablePtr.p->tableVersion != req->tableVersion){
- jam();
- dropTableRef(signal, req, DropTableRef::InvalidTableVersion);
- return;
- }
- /**
- * Seems ok
- */
- DropTableRecordPtr dropTabPtr;
- c_opDropTable.seize(dropTabPtr);
-
- if(dropTabPtr.isNull()){
- jam();
- dropTableRef(signal, req, DropTableRef::NoDropTableRecordAvailable);
- return;
- }
- c_blockState = BS_BUSY;
-
- dropTabPtr.p->key = ++c_opRecordSequence;
- c_opDropTable.add(dropTabPtr);
- dropTabPtr.p->m_request = * req;
- dropTabPtr.p->m_errorCode = 0;
- dropTabPtr.p->m_requestType = DropTabReq::OnlineDropTab;
- dropTabPtr.p->m_coordinatorRef = reference();
- dropTabPtr.p->m_coordinatorData.m_gsn = GSN_PREP_DROP_TAB_REQ;
- dropTabPtr.p->m_coordinatorData.m_block = 0;
-
- Mutex mutex(signal, c_mutexMgr, dropTabPtr.p->m_define_backup_mutex);
- Callback c = { safe_cast(&Dbdict::dropTable_backup_mutex_locked),
- dropTabPtr.p->key};
-
- ndbrequire(mutex.lock(c));
- }
- void
- Dbdict::dropTable_backup_mutex_locked(Signal* signal,
- Uint32 callbackData,
- Uint32 retValue){
- jamEntry();
-
- ndbrequire(retValue == 0);
-
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, callbackData));
-
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, dropTabPtr.p->m_request.tableId, true);
-
- Mutex mutex(signal, c_mutexMgr, dropTabPtr.p->m_define_backup_mutex);
- mutex.unlock(); // ignore response
-
- if(tablePtr.p->tabState == TableRecord::BACKUP_ONGOING)
- {
- jam();
- dropTableRef(signal, &dropTabPtr.p->m_request,
- DropTableRef::BackupInProgress);
-
- c_blockState = BS_IDLE;
- c_opDropTable.release(dropTabPtr);
- }
- else
- {
- jam();
- tablePtr.p->tabState = TableRecord::PREPARE_DROPPING;
- prepDropTab_nextStep(signal, dropTabPtr);
- }
- }
- void
- Dbdict::dropTableRef(Signal * signal,
- DropTableReq * req, DropTableRef::ErrorCode errCode){
- Uint32 tableId = req->tableId;
- Uint32 tabVersion = req->tableVersion;
- Uint32 senderData = req->senderData;
- Uint32 senderRef = req->senderRef;
-
- DropTableRef * ref = (DropTableRef*)signal->getDataPtrSend();
- ref->tableId = tableId;
- ref->tableVersion = tabVersion;
- ref->senderData = senderData;
- ref->senderRef = reference();
- ref->errorCode = errCode;
- ref->masterNodeId = c_masterNodeId;
- sendSignal(senderRef, GSN_DROP_TABLE_REF, signal,
- DropTableRef::SignalLength, JBB);
- }
- void
- Dbdict::prepDropTab_nextStep(Signal* signal, DropTableRecordPtr dropTabPtr){
-
- /**
- * No errors currently allowed
- */
- ndbrequire(dropTabPtr.p->m_errorCode == 0);
- Uint32 block = 0;
- switch(dropTabPtr.p->m_coordinatorData.m_block){
- case 0:
- jam();
- block = dropTabPtr.p->m_coordinatorData.m_block = DBDICT;
- break;
- case DBDICT:
- jam();
- block = dropTabPtr.p->m_coordinatorData.m_block = DBLQH;
- break;
- case DBLQH:
- jam();
- block = dropTabPtr.p->m_coordinatorData.m_block = DBTC;
- break;
- case DBTC:
- jam();
- block = dropTabPtr.p->m_coordinatorData.m_block = DBDIH;
- break;
- case DBDIH:
- jam();
- prepDropTab_complete(signal, dropTabPtr);
- return;
- default:
- ndbrequire(false);
- }
- PrepDropTabReq * prep = (PrepDropTabReq*)signal->getDataPtrSend();
- prep->senderRef = reference();
- prep->senderData = dropTabPtr.p->key;
- prep->tableId = dropTabPtr.p->m_request.tableId;
- prep->requestType = dropTabPtr.p->m_requestType;
-
- dropTabPtr.p->m_coordinatorData.m_signalCounter = c_aliveNodes;
- NodeReceiverGroup rg(block, c_aliveNodes);
- sendSignal(rg, GSN_PREP_DROP_TAB_REQ, signal,
- PrepDropTabReq::SignalLength, JBB);
-
- #if 0
- for (Uint32 i = 1; i < MAX_NDB_NODES; i++){
- if(c_aliveNodes.get(i)){
- jam();
- BlockReference ref = numberToRef(block, i);
-
- dropTabPtr.p->m_coordinatorData.m_signalCounter.setWaitingFor(i);
- }
- }
- #endif
- }
- void
- Dbdict::execPREP_DROP_TAB_CONF(Signal * signal){
- jamEntry();
- PrepDropTabConf * prep = (PrepDropTabConf*)signal->getDataPtr();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, prep->senderData));
-
- ndbrequire(dropTabPtr.p->m_coordinatorRef == reference());
- ndbrequire(dropTabPtr.p->m_request.tableId == prep->tableId);
- ndbrequire(dropTabPtr.p->m_coordinatorData.m_gsn == GSN_PREP_DROP_TAB_REQ);
-
- Uint32 nodeId = refToNode(prep->senderRef);
- dropTabPtr.p->m_coordinatorData.m_signalCounter.clearWaitingFor(nodeId);
-
- if(!dropTabPtr.p->m_coordinatorData.m_signalCounter.done()){
- jam();
- return;
- }
- prepDropTab_nextStep(signal, dropTabPtr);
- }
- void
- Dbdict::execPREP_DROP_TAB_REF(Signal* signal){
- jamEntry();
- PrepDropTabRef * prep = (PrepDropTabRef*)signal->getDataPtr();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, prep->senderData));
-
- ndbrequire(dropTabPtr.p->m_coordinatorRef == reference());
- ndbrequire(dropTabPtr.p->m_request.tableId == prep->tableId);
- ndbrequire(dropTabPtr.p->m_coordinatorData.m_gsn == GSN_PREP_DROP_TAB_REQ);
-
- Uint32 nodeId = refToNode(prep->senderRef);
- dropTabPtr.p->m_coordinatorData.m_signalCounter.clearWaitingFor(nodeId);
-
- Uint32 block = refToBlock(prep->senderRef);
- if((prep->errorCode == PrepDropTabRef::NoSuchTable && block == DBLQH) ||
- (prep->errorCode == PrepDropTabRef::NF_FakeErrorREF)){
- jam();
- /**
- * Ignore errors:
- * 1) no such table and LQH, it might not exists in different LQH's
- * 2) node failure...
- */
- } else {
- dropTabPtr.p->setErrorCode((Uint32)prep->errorCode);
- }
-
- if(!dropTabPtr.p->m_coordinatorData.m_signalCounter.done()){
- jam();
- return;
- }
- prepDropTab_nextStep(signal, dropTabPtr);
- }
- void
- Dbdict::prepDropTab_complete(Signal* signal, DropTableRecordPtr dropTabPtr){
- jam();
- dropTabPtr.p->m_coordinatorData.m_gsn = GSN_DROP_TAB_REQ;
- dropTabPtr.p->m_coordinatorData.m_block = DBDICT;
-
- DropTabReq * req = (DropTabReq*)signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = dropTabPtr.p->key;
- req->tableId = dropTabPtr.p->m_request.tableId;
- req->requestType = dropTabPtr.p->m_requestType;
- dropTabPtr.p->m_coordinatorData.m_signalCounter = c_aliveNodes;
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- sendSignal(rg, GSN_DROP_TAB_REQ, signal,
- DropTabReq::SignalLength, JBB);
- }
- void
- Dbdict::execDROP_TAB_REF(Signal* signal){
- jamEntry();
- DropTabRef * const req = (DropTabRef*)signal->getDataPtr();
- Uint32 block = refToBlock(req->senderRef);
- ndbrequire(req->errorCode == DropTabRef::NF_FakeErrorREF ||
- (req->errorCode == DropTabRef::NoSuchTable &&
- (block == DBTUP || block == DBACC || block == DBLQH)));
-
- if(block != DBDICT){
- jam();
- ndbrequire(refToNode(req->senderRef) == getOwnNodeId());
- dropTab_localDROP_TAB_CONF(signal);
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::execDROP_TAB_CONF(Signal* signal){
- jamEntry();
- DropTabConf * const req = (DropTabConf*)signal->getDataPtr();
- if(refToBlock(req->senderRef) != DBDICT){
- jam();
- ndbrequire(refToNode(req->senderRef) == getOwnNodeId());
- dropTab_localDROP_TAB_CONF(signal);
- return;
- }
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, req->senderData));
-
- ndbrequire(dropTabPtr.p->m_coordinatorRef == reference());
- ndbrequire(dropTabPtr.p->m_request.tableId == req->tableId);
- ndbrequire(dropTabPtr.p->m_coordinatorData.m_gsn == GSN_DROP_TAB_REQ);
- Uint32 nodeId = refToNode(req->senderRef);
- dropTabPtr.p->m_coordinatorData.m_signalCounter.clearWaitingFor(nodeId);
-
- if(!dropTabPtr.p->m_coordinatorData.m_signalCounter.done()){
- jam();
- return;
- }
-
- DropTableConf* conf = (DropTableConf*)signal->getDataPtrSend();
- conf->senderRef = reference();
- conf->senderData = dropTabPtr.p->m_request.senderData;
- conf->tableId = dropTabPtr.p->m_request.tableId;
- conf->tableVersion = dropTabPtr.p->m_request.tableVersion;
-
- Uint32 ref = dropTabPtr.p->m_request.senderRef;
- sendSignal(ref, GSN_DROP_TABLE_CONF, signal,
- DropTableConf::SignalLength, JBB);
- c_opDropTable.release(dropTabPtr);
- c_blockState = BS_IDLE;
- }
- /**
- * DROP TABLE PARTICIPANT CODE
- */
- void
- Dbdict::execPREP_DROP_TAB_REQ(Signal* signal){
- jamEntry();
- PrepDropTabReq * prep = (PrepDropTabReq*)signal->getDataPtrSend();
- DropTableRecordPtr dropTabPtr;
- if(prep->senderRef == reference()){
- jam();
- ndbrequire(c_opDropTable.find(dropTabPtr, prep->senderData));
- ndbrequire(dropTabPtr.p->m_requestType == prep->requestType);
- } else {
- jam();
- c_opDropTable.seize(dropTabPtr);
- if(!dropTabPtr.isNull()){
- dropTabPtr.p->key = prep->senderData;
- c_opDropTable.add(dropTabPtr);
- }
- }
-
- ndbrequire(!dropTabPtr.isNull());
- dropTabPtr.p->m_errorCode = 0;
- dropTabPtr.p->m_request.tableId = prep->tableId;
- dropTabPtr.p->m_requestType = prep->requestType;
- dropTabPtr.p->m_coordinatorRef = prep->senderRef;
- dropTabPtr.p->m_participantData.m_gsn = GSN_PREP_DROP_TAB_REQ;
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, prep->tableId);
- tablePtr.p->tabState = TableRecord::PREPARE_DROPPING;
-
- /**
- * Modify schema
- */
- PageRecordPtr pagePtr;
- c_pageRecordArray.getPtr(pagePtr, c_schemaRecord.schemaPage);
-
- SchemaFile::TableEntry * tableEntry = getTableEntry(pagePtr.p, tablePtr.i);
- SchemaFile::TableState tabState =
- (SchemaFile::TableState)tableEntry->m_tableState;
- ndbrequire(tabState == SchemaFile::TABLE_ADD_COMMITTED ||
- tabState == SchemaFile::ALTER_TABLE_COMMITTED);
- tableEntry->m_tableState = SchemaFile::DROP_TABLE_STARTED;
- computeChecksum((SchemaFile*)pagePtr.p);
-
- ndbrequire(c_writeSchemaRecord.inUse == false);
- c_writeSchemaRecord.inUse = true;
-
- c_writeSchemaRecord.pageId = c_schemaRecord.schemaPage;
- c_writeSchemaRecord.m_callback.m_callbackData = dropTabPtr.p->key;
- c_writeSchemaRecord.m_callback.m_callbackFunction =
- safe_cast(&Dbdict::prepDropTab_writeSchemaConf);
- startWriteSchemaFile(signal);
- }
- void
- Dbdict::prepDropTab_writeSchemaConf(Signal* signal,
- Uint32 dropTabPtrI,
- Uint32 returnCode){
- jam();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, dropTabPtrI));
- ndbrequire(dropTabPtr.p->m_participantData.m_gsn == GSN_PREP_DROP_TAB_REQ);
-
- /**
- * There probably should be node fail handlign here
- *
- * To check that coordinator hasn't died
- */
-
- PrepDropTabConf * prep = (PrepDropTabConf*)signal->getDataPtr();
- prep->senderRef = reference();
- prep->senderData = dropTabPtrI;
- prep->tableId = dropTabPtr.p->m_request.tableId;
-
- dropTabPtr.p->m_participantData.m_gsn = GSN_PREP_DROP_TAB_CONF;
- sendSignal(dropTabPtr.p->m_coordinatorRef, GSN_PREP_DROP_TAB_CONF, signal,
- PrepDropTabConf::SignalLength, JBB);
- }
- void
- Dbdict::execDROP_TAB_REQ(Signal* signal){
- jamEntry();
- DropTabReq * req = (DropTabReq*)signal->getDataPtrSend();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, req->senderData));
- ndbrequire(dropTabPtr.p->m_participantData.m_gsn == GSN_PREP_DROP_TAB_CONF);
- dropTabPtr.p->m_participantData.m_gsn = GSN_DROP_TAB_REQ;
- ndbrequire(dropTabPtr.p->m_requestType == req->requestType);
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, dropTabPtr.p->m_request.tableId);
- tablePtr.p->tabState = TableRecord::DROPPING;
- dropTabPtr.p->m_participantData.m_block = 0;
- dropTabPtr.p->m_participantData.m_callback.m_callbackData = dropTabPtr.p->key;
- dropTabPtr.p->m_participantData.m_callback.m_callbackFunction =
- safe_cast(&Dbdict::dropTab_complete);
- dropTab_nextStep(signal, dropTabPtr);
- }
- #include <DebuggerNames.hpp>
- void
- Dbdict::dropTab_nextStep(Signal* signal, DropTableRecordPtr dropTabPtr){
- /**
- * No errors currently allowed
- */
- ndbrequire(dropTabPtr.p->m_errorCode == 0);
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, dropTabPtr.p->m_request.tableId);
- Uint32 block = 0;
- switch(dropTabPtr.p->m_participantData.m_block){
- case 0:
- jam();
- block = DBTC;
- break;
- case DBTC:
- jam();
- if (tablePtr.p->isTable() || tablePtr.p->isHashIndex())
- block = DBACC;
- if (tablePtr.p->isOrderedIndex())
- block = DBTUP;
- break;
- case DBACC:
- jam();
- block = DBTUP;
- break;
- case DBTUP:
- jam();
- if (tablePtr.p->isTable() || tablePtr.p->isHashIndex())
- block = DBLQH;
- if (tablePtr.p->isOrderedIndex())
- block = DBTUX;
- break;
- case DBTUX:
- jam();
- block = DBLQH;
- break;
- case DBLQH:
- jam();
- block = DBDIH;
- break;
- case DBDIH:
- jam();
- execute(signal, dropTabPtr.p->m_participantData.m_callback, 0);
- return;
- }
- ndbrequire(block != 0);
- dropTabPtr.p->m_participantData.m_block = block;
- DropTabReq * req = (DropTabReq*)signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = dropTabPtr.p->key;
- req->tableId = dropTabPtr.p->m_request.tableId;
- req->requestType = dropTabPtr.p->m_requestType;
-
- const Uint32 nodeId = getOwnNodeId();
- dropTabPtr.p->m_participantData.m_signalCounter.clearWaitingFor();
- dropTabPtr.p->m_participantData.m_signalCounter.setWaitingFor(nodeId);
- BlockReference ref = numberToRef(block, 0);
- sendSignal(ref, GSN_DROP_TAB_REQ, signal, DropTabReq::SignalLength, JBB);
- }
- void
- Dbdict::dropTab_localDROP_TAB_CONF(Signal* signal){
- jamEntry();
-
- DropTabConf * conf = (DropTabConf*)signal->getDataPtr();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, conf->senderData));
-
- ndbrequire(dropTabPtr.p->m_request.tableId == conf->tableId);
- ndbrequire(dropTabPtr.p->m_participantData.m_gsn == GSN_DROP_TAB_REQ);
-
- Uint32 nodeId = refToNode(conf->senderRef);
- dropTabPtr.p->m_participantData.m_signalCounter.clearWaitingFor(nodeId);
-
- if(!dropTabPtr.p->m_participantData.m_signalCounter.done()){
- jam();
- ndbrequire(false);
- return;
- }
- dropTab_nextStep(signal, dropTabPtr);
- }
- void
- Dbdict::dropTab_complete(Signal* signal,
- Uint32 dropTabPtrI,
- Uint32 returnCode){
- jam();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, dropTabPtrI));
-
- Uint32 tableId = dropTabPtr.p->m_request.tableId;
-
- /**
- * Write to schema file
- */
- PageRecordPtr pagePtr;
- c_pageRecordArray.getPtr(pagePtr, c_schemaRecord.schemaPage);
-
- SchemaFile::TableEntry * tableEntry = getTableEntry(pagePtr.p, tableId);
- SchemaFile::TableState tabState =
- (SchemaFile::TableState)tableEntry->m_tableState;
- ndbrequire(tabState == SchemaFile::DROP_TABLE_STARTED);
- tableEntry->m_tableState = SchemaFile::DROP_TABLE_COMMITTED;
- computeChecksum((SchemaFile*)pagePtr.p);
-
- ndbrequire(c_writeSchemaRecord.inUse == false);
- c_writeSchemaRecord.inUse = true;
- c_writeSchemaRecord.pageId = c_schemaRecord.schemaPage;
- c_writeSchemaRecord.m_callback.m_callbackData = dropTabPtr.p->key;
- c_writeSchemaRecord.m_callback.m_callbackFunction =
- safe_cast(&Dbdict::dropTab_writeSchemaConf);
- startWriteSchemaFile(signal);
- }
- void
- Dbdict::dropTab_writeSchemaConf(Signal* signal,
- Uint32 dropTabPtrI,
- Uint32 returnCode){
- jam();
- DropTableRecordPtr dropTabPtr;
- ndbrequire(c_opDropTable.find(dropTabPtr, dropTabPtrI));
- ndbrequire(dropTabPtr.p->m_participantData.m_gsn == GSN_DROP_TAB_REQ);
- dropTabPtr.p->m_participantData.m_gsn = GSN_DROP_TAB_CONF;
- releaseTableObject(dropTabPtr.p->m_request.tableId);
- DropTabConf * conf = (DropTabConf*)signal->getDataPtr();
- conf->senderRef = reference();
- conf->senderData = dropTabPtrI;
- conf->tableId = dropTabPtr.p->m_request.tableId;
-
- dropTabPtr.p->m_participantData.m_gsn = GSN_DROP_TAB_CONF;
- sendSignal(dropTabPtr.p->m_coordinatorRef, GSN_DROP_TAB_CONF, signal,
- DropTabConf::SignalLength, JBB);
-
- if(dropTabPtr.p->m_coordinatorRef != reference()){
- c_opDropTable.release(dropTabPtr);
- }
- }
- void Dbdict::releaseTableObject(Uint32 tableId, bool removeFromHash)
- {
- TableRecordPtr tablePtr;
- AttributeRecordPtr attrPtr;
- c_tableRecordPool.getPtr(tablePtr, tableId);
- if (removeFromHash)
- {
- #ifdef VM_TRACE
- TableRecordPtr tmp;
- ndbrequire(c_tableRecordHash.find(tmp, * tablePtr.p));
- #endif
- c_tableRecordHash.remove(tablePtr);
- }
- tablePtr.p->tabState = TableRecord::NOT_DEFINED;
- Uint32 nextAttrRecord = tablePtr.p->firstAttribute;
- while (nextAttrRecord != RNIL) {
- jam();
- /* ---------------------------------------------------------------- */
- // Release all attribute records
- /* ---------------------------------------------------------------- */
- c_attributeRecordPool.getPtr(attrPtr, nextAttrRecord);
- nextAttrRecord = attrPtr.p->nextAttrInTable;
- c_attributeRecordPool.release(attrPtr);
- }//if
- #ifdef HAVE_TABLE_REORG
- Uint32 secondTableId = tablePtr.p->secondTable;
- initialiseTableRecord(tablePtr);
- c_tableRecordPool.getPtr(tablePtr, secondTableId);
- initialiseTableRecord(tablePtr);
- #endif
- return;
- }//releaseTableObject()
- /**
- * DICT receives these on index create and drop.
- */
- void Dbdict::execDROP_TABLE_CONF(Signal* signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 0);
- DropTableConf * const conf = (DropTableConf *)signal->getDataPtr();
- // assume part of drop index operation
- OpDropIndexPtr opPtr;
- c_opDropIndex.find(opPtr, conf->senderData);
- ndbrequire(! opPtr.isNull());
- ndbrequire(opPtr.p->m_request.getIndexId() == conf->tableId);
- ndbrequire(opPtr.p->m_request.getIndexVersion() == conf->tableVersion);
- dropIndex_fromDropTable(signal, opPtr);
- }
- void Dbdict::execDROP_TABLE_REF(Signal* signal)
- {
- jamEntry();
- DropTableRef * const ref = (DropTableRef *)signal->getDataPtr();
- // assume part of drop index operation
- OpDropIndexPtr opPtr;
- c_opDropIndex.find(opPtr, ref->senderData);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- opPtr.p->m_errorLine = __LINE__;
- dropIndex_fromDropTable(signal, opPtr);
- }
- /* **************************************************************** */
- /* ---------------------------------------------------------------- */
- /* MODULE: EXTERNAL INTERFACE TO DATA -------------------- */
- /* ---------------------------------------------------------------- */
- /* */
- /* This module contains the code that is used by other modules to. */
- /* access the data within DBDICT. */
- /* ---------------------------------------------------------------- */
- /* **************************************************************** */
- void Dbdict::execGET_TABLEDID_REQ(Signal * signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 1);
- GetTableIdReq const * req = (GetTableIdReq *)signal->getDataPtr();
- Uint32 senderData = req->senderData;
- Uint32 senderRef = req->senderRef;
- Uint32 len = req->len;
- if(len>MAX_TAB_NAME_SIZE)
- {
- jam();
- sendGET_TABLEID_REF((Signal*)signal,
- (GetTableIdReq *)req,
- GetTableIdRef::TableNameTooLong);
- return;
- }
- char tableName[MAX_TAB_NAME_SIZE];
- TableRecord keyRecord;
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr,GetTableIdReq::TABLE_NAME);
- copy((Uint32*)tableName, ssPtr);
- strcpy(keyRecord.tableName, tableName);
- releaseSections(signal);
- if(len > sizeof(keyRecord.tableName)){
- jam();
- sendGET_TABLEID_REF((Signal*)signal,
- (GetTableIdReq *)req,
- GetTableIdRef::TableNameTooLong);
- return;
- }
-
- TableRecordPtr tablePtr;
- if(!c_tableRecordHash.find(tablePtr, keyRecord)) {
- jam();
- sendGET_TABLEID_REF((Signal*)signal,
- (GetTableIdReq *)req,
- GetTableIdRef::TableNotDefined);
- return;
- }
- GetTableIdConf * conf = (GetTableIdConf *)req;
- conf->tableId = tablePtr.p->tableId;
- conf->schemaVersion = tablePtr.p->tableVersion;
- conf->senderData = senderData;
- sendSignal(senderRef, GSN_GET_TABLEID_CONF, signal,
- GetTableIdConf::SignalLength, JBB);
-
- }
- void Dbdict::sendGET_TABLEID_REF(Signal* signal,
- GetTableIdReq * req,
- GetTableIdRef::ErrorCode errorCode)
- {
- GetTableIdRef * const ref = (GetTableIdRef *)req;
- /**
- * The format of GetTabInfo Req/Ref is the same
- */
- BlockReference retRef = req->senderRef;
- ref->err = errorCode;
- sendSignal(retRef, GSN_GET_TABLEID_REF, signal,
- GetTableIdRef::SignalLength, JBB);
- }//sendGET_TABINFOREF()
- /* ---------------------------------------------------------------- */
- // Get a full table description.
- /* ---------------------------------------------------------------- */
- void Dbdict::execGET_TABINFOREQ(Signal* signal)
- {
- jamEntry();
- if(!assembleFragments(signal)) { return; }
- GetTabInfoReq * const req = (GetTabInfoReq *)&signal->theData[0];
- /**
- * If I get a GET_TABINFO_REQ from myself
- * it's is a one from the time queue
- */
- bool fromTimeQueue = (signal->senderBlockRef() == reference());
-
- if (c_retrieveRecord.busyState && fromTimeQueue == true) {
- jam();
-
- sendSignalWithDelay(reference(), GSN_GET_TABINFOREQ, signal, 30,
- signal->length());
- return;
- }//if
- const Uint32 MAX_WAITERS = 5;
-
- if(c_retrieveRecord.busyState && fromTimeQueue == false){
- jam();
- if(c_retrieveRecord.noOfWaiters < MAX_WAITERS){
- jam();
- c_retrieveRecord.noOfWaiters++;
-
- sendSignalWithDelay(reference(), GSN_GET_TABINFOREQ, signal, 30,
- signal->length());
- return;
- }
-
- sendGET_TABINFOREF(signal, req, GetTabInfoRef::Busy);
- return;
- }
-
- if(fromTimeQueue){
- jam();
- c_retrieveRecord.noOfWaiters--;
- }
- const bool useLongSig = (req->requestType & GetTabInfoReq::LongSignalConf);
- const Uint32 reqType = req->requestType & (~GetTabInfoReq::LongSignalConf);
-
- TableRecordPtr tablePtr;
- if(reqType == GetTabInfoReq::RequestByName){
- jam();
- ndbrequire(signal->getNoOfSections() == 1);
- const Uint32 len = req->tableNameLen;
-
- TableRecord keyRecord;
- if(len > sizeof(keyRecord.tableName)){
- jam();
- releaseSections(signal);
- sendGET_TABINFOREF(signal, req, GetTabInfoRef::TableNameTooLong);
- return;
- }
- char tableName[MAX_TAB_NAME_SIZE];
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr,GetTabInfoReq::TABLE_NAME);
- SimplePropertiesSectionReader r0(ssPtr, getSectionSegmentPool());
- r0.reset(); // undo implicit first()
- if(r0.getWords((Uint32*)tableName, ((len + 3)/4)))
- memcpy(keyRecord.tableName, tableName, len);
- else {
- jam();
- releaseSections(signal);
- sendGET_TABINFOREF(signal, req, GetTabInfoRef::TableNotDefined);
- return;
- }
- releaseSections(signal);
- // memcpy(keyRecord.tableName, req->tableName, len);
- //ntohS(&keyRecord.tableName[0], len);
-
- c_tableRecordHash.find(tablePtr, keyRecord);
- } else {
- jam();
- c_tableRecordPool.getPtr(tablePtr, req->tableId, false);
- }
-
- // The table seached for was not found
- if(tablePtr.i == RNIL){
- jam();
- sendGET_TABINFOREF(signal, req, GetTabInfoRef::InvalidTableId);
- return;
- }//if
-
- if (! (tablePtr.p->tabState == TableRecord::DEFINED ||
- tablePtr.p->tabState == TableRecord::BACKUP_ONGOING)) {
- jam();
- sendGET_TABINFOREF(signal, req, GetTabInfoRef::TableNotDefined);
- return;
- }//if
-
- c_retrieveRecord.busyState = true;
- c_retrieveRecord.blockRef = req->senderRef;
- c_retrieveRecord.m_senderData = req->senderData;
- c_retrieveRecord.tableId = tablePtr.i;
- c_retrieveRecord.currentSent = 0;
- c_retrieveRecord.m_useLongSig = useLongSig;
-
- c_packTable.m_state = PackTable::PTS_GET_TAB;
-
- signal->theData[0] = ZPACK_TABLE_INTO_PAGES;
- signal->theData[1] = tablePtr.i;
- signal->theData[2] = c_retrieveRecord.retrievePage;
- sendSignal(reference(), GSN_CONTINUEB, signal, 3, JBB);
- }//execGET_TABINFOREQ()
- void Dbdict::sendGetTabResponse(Signal* signal)
- {
- PageRecordPtr pagePtr;
- DictTabInfo * const conf = (DictTabInfo *)&signal->theData[0];
- conf->senderRef = reference();
- conf->senderData = c_retrieveRecord.m_senderData;
- conf->requestType = DictTabInfo::GetTabInfoConf;
- conf->totalLen = c_retrieveRecord.retrievedNoOfWords;
- c_pageRecordArray.getPtr(pagePtr, c_retrieveRecord.retrievePage);
- Uint32* pagePointer = (Uint32*)&pagePtr.p->word[0] + ZPAGE_HEADER_SIZE;
-
- if(c_retrieveRecord.m_useLongSig){
- jam();
- GetTabInfoConf* conf = (GetTabInfoConf*)signal->getDataPtr();
- conf->gci = 0;
- conf->tableId = c_retrieveRecord.tableId;
- conf->senderData = c_retrieveRecord.m_senderData;
- conf->totalLen = c_retrieveRecord.retrievedNoOfWords;
-
- Callback c = { safe_cast(&Dbdict::initRetrieveRecord), 0 };
- LinearSectionPtr ptr[3];
- ptr[0].p = pagePointer;
- ptr[0].sz = c_retrieveRecord.retrievedNoOfWords;
- sendFragmentedSignal(c_retrieveRecord.blockRef,
- GSN_GET_TABINFO_CONF,
- signal,
- GetTabInfoConf::SignalLength,
- JBB,
- ptr,
- 1,
- c);
- return;
- }
- ndbrequire(false);
- }//sendGetTabResponse()
- void Dbdict::sendGET_TABINFOREF(Signal* signal,
- GetTabInfoReq * req,
- GetTabInfoRef::ErrorCode errorCode)
- {
- jamEntry();
- GetTabInfoRef * const ref = (GetTabInfoRef *)&signal->theData[0];
- /**
- * The format of GetTabInfo Req/Ref is the same
- */
- BlockReference retRef = req->senderRef;
- ref->errorCode = errorCode;
-
- sendSignal(retRef, GSN_GET_TABINFOREF, signal, signal->length(), JBB);
- }//sendGET_TABINFOREF()
- Uint32 convertEndian(Uint32 in) {
- #ifdef WORDS_BIGENDIAN
- Uint32 ut = 0;
- ut += ((in >> 24) & 255);
- ut += (((in >> 16) & 255) << 8);
- ut += (((in >> 8) & 255) << 16);
- ut += ((in & 255) << 24);
- return ut;
- #else
- return in;
- #endif
- }
- void
- Dbdict::execLIST_TABLES_REQ(Signal* signal)
- {
- jamEntry();
- Uint32 i;
- ListTablesReq * req = (ListTablesReq*)signal->getDataPtr();
- Uint32 senderRef = req->senderRef;
- Uint32 senderData = req->senderData;
- // save req flags
- const Uint32 reqTableId = req->getTableId();
- const Uint32 reqTableType = req->getTableType();
- const bool reqListNames = req->getListNames();
- const bool reqListIndexes = req->getListIndexes();
- // init the confs
- ListTablesConf * conf = (ListTablesConf *)signal->getDataPtrSend();
- conf->senderData = senderData;
- conf->counter = 0;
- Uint32 pos = 0;
- for (i = 0; i < c_tableRecordPool.getSize(); i++) {
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, i);
- // filter
- if (tablePtr.p->tabState == TableRecord::NOT_DEFINED ||
- tablePtr.p->tabState == TableRecord::REORG_TABLE_PREPARED)
- continue;
- if ((reqTableType != (Uint32)0) && (reqTableType != (unsigned)tablePtr.p->tableType))
- continue;
- if (reqListIndexes && reqTableId != tablePtr.p->primaryTableId)
- continue;
- conf->tableData[pos] = 0;
- // id
- conf->setTableId(pos, tablePtr.i);
- // type
- conf->setTableType(pos, tablePtr.p->tableType);
- // state
- if (tablePtr.p->isTable()) {
- switch (tablePtr.p->tabState) {
- case TableRecord::DEFINING:
- case TableRecord::CHECKED:
- conf->setTableState(pos, DictTabInfo::StateBuilding);
- break;
- case TableRecord::PREPARE_DROPPING:
- case TableRecord::DROPPING:
- conf->setTableState(pos, DictTabInfo::StateDropping);
- break;
- case TableRecord::DEFINED:
- conf->setTableState(pos, DictTabInfo::StateOnline);
- break;
- case TableRecord::BACKUP_ONGOING:
- conf->setTableState(pos, DictTabInfo::StateBackup);
- break;
- default:
- conf->setTableState(pos, DictTabInfo::StateBroken);
- break;
- }
- }
- if (tablePtr.p->isIndex()) {
- switch (tablePtr.p->indexState) {
- case TableRecord::IS_OFFLINE:
- conf->setTableState(pos, DictTabInfo::StateOffline);
- break;
- case TableRecord::IS_BUILDING:
- conf->setTableState(pos, DictTabInfo::StateBuilding);
- break;
- case TableRecord::IS_DROPPING:
- conf->setTableState(pos, DictTabInfo::StateDropping);
- break;
- case TableRecord::IS_ONLINE:
- conf->setTableState(pos, DictTabInfo::StateOnline);
- break;
- default:
- conf->setTableState(pos, DictTabInfo::StateBroken);
- break;
- }
- }
- // store
- if (! tablePtr.p->storedTable) {
- conf->setTableStore(pos, DictTabInfo::StoreTemporary);
- } else {
- conf->setTableStore(pos, DictTabInfo::StorePermanent);
- }
- pos++;
- if (pos >= ListTablesConf::DataLength) {
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::SignalLength, JBB);
- conf->counter++;
- pos = 0;
- }
- if (! reqListNames)
- continue;
- const Uint32 size = strlen(tablePtr.p->tableName) + 1;
- conf->tableData[pos] = size;
- pos++;
- if (pos >= ListTablesConf::DataLength) {
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::SignalLength, JBB);
- conf->counter++;
- pos = 0;
- }
- Uint32 k = 0;
- while (k < size) {
- char* p = (char*)&conf->tableData[pos];
- for (Uint32 j = 0; j < 4; j++) {
- if (k < size)
- *p++ = tablePtr.p->tableName[k++];
- else
- *p++ = 0;
- }
- pos++;
- if (pos >= ListTablesConf::DataLength) {
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::SignalLength, JBB);
- conf->counter++;
- pos = 0;
- }
- }
- }
- // XXX merge with above somehow
- for (i = 0; i < c_triggerRecordPool.getSize(); i++) {
- if (reqListIndexes)
- break;
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, i);
- if (triggerPtr.p->triggerState == TriggerRecord::TS_NOT_DEFINED)
- continue;
- // constant 10 hardcoded
- Uint32 type = 10 + triggerPtr.p->triggerType;
- if (reqTableType != 0 && reqTableType != type)
- continue;
- conf->tableData[pos] = 0;
- conf->setTableId(pos, triggerPtr.i);
- conf->setTableType(pos, type);
- switch (triggerPtr.p->triggerState) {
- case TriggerRecord::TS_OFFLINE:
- conf->setTableState(pos, DictTabInfo::StateOffline);
- break;
- case TriggerRecord::TS_ONLINE:
- conf->setTableState(pos, DictTabInfo::StateOnline);
- break;
- default:
- conf->setTableState(pos, DictTabInfo::StateBroken);
- break;
- }
- conf->setTableStore(pos, DictTabInfo::StoreTemporary);
- pos++;
- if (pos >= ListTablesConf::DataLength) {
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::SignalLength, JBB);
- conf->counter++;
- pos = 0;
- }
- if (! reqListNames)
- continue;
- const Uint32 size = strlen(triggerPtr.p->triggerName) + 1;
- conf->tableData[pos] = size;
- pos++;
- if (pos >= ListTablesConf::DataLength) {
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::SignalLength, JBB);
- conf->counter++;
- pos = 0;
- }
- Uint32 k = 0;
- while (k < size) {
- char* p = (char*)&conf->tableData[pos];
- for (Uint32 j = 0; j < 4; j++) {
- if (k < size)
- *p++ = triggerPtr.p->triggerName[k++];
- else
- *p++ = 0;
- }
- pos++;
- if (pos >= ListTablesConf::DataLength) {
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::SignalLength, JBB);
- conf->counter++;
- pos = 0;
- }
- }
- }
- // last signal must have less than max length
- sendSignal(senderRef, GSN_LIST_TABLES_CONF, signal,
- ListTablesConf::HeaderLength + pos, JBB);
- }
- /**
- * MODULE: Create index
- *
- * Create index in DICT via create table operation. Then invoke alter
- * index opearation to online the index.
- *
- * Request type in CREATE_INDX signals:
- *
- * RT_USER - from API to DICT master
- * RT_DICT_PREPARE - prepare participants
- * RT_DICT_COMMIT - commit participants
- * RT_TC - create index in TC (part of alter index operation)
- */
- void
- Dbdict::execCREATE_INDX_REQ(Signal* signal)
- {
- jamEntry();
- CreateIndxReq* const req = (CreateIndxReq*)signal->getDataPtrSend();
- OpCreateIndexPtr opPtr;
- const Uint32 senderRef = signal->senderBlockRef();
- const CreateIndxReq::RequestType requestType = req->getRequestType();
- if (requestType == CreateIndxReq::RT_USER) {
- jam();
- if (! assembleFragments(signal)) {
- jam();
- return;
- }
- if (signal->getLength() == CreateIndxReq::SignalLength) {
- jam();
- if (getOwnNodeId() != c_masterNodeId) {
- jam();
-
- releaseSections(signal);
- OpCreateIndex opBusy;
- opPtr.p = &opBusy;
- opPtr.p->save(req);
- opPtr.p->m_isMaster = (senderRef == reference());
- opPtr.p->key = 0;
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_PREPARE;
- opPtr.p->m_errorCode = CreateIndxRef::NotMaster;
- opPtr.p->m_errorLine = __LINE__;
- opPtr.p->m_errorNode = c_masterNodeId;
- createIndex_sendReply(signal, opPtr, true);
- return;
- }
-
- // forward initial request plus operation key to all
- req->setOpKey(++c_opRecordSequence);
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- sendSignal(rg, GSN_CREATE_INDX_REQ,
- signal, CreateIndxReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == CreateIndxReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpCreateIndex opBusy;
- if (! c_opCreateIndex.seize(opPtr))
- opPtr.p = &opBusy;
- opPtr.p->save(req);
- opPtr.p->m_coordinatorRef = senderRef;
- opPtr.p->m_isMaster = (senderRef == reference());
- opPtr.p->key = opKey;
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- releaseSections(signal);
- createIndex_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opCreateIndex.add(opPtr);
- // save attribute list
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr, CreateIndxReq::ATTRIBUTE_LIST_SECTION);
- SimplePropertiesSectionReader r0(ssPtr, getSectionSegmentPool());
- r0.reset(); // undo implicit first()
- if (! r0.getWord(&opPtr.p->m_attrList.sz) ||
- ! r0.getWords(opPtr.p->m_attrList.id, opPtr.p->m_attrList.sz)) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidName;
- opPtr.p->m_errorLine = __LINE__;
- releaseSections(signal);
- createIndex_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- // save name and index table properties
- signal->getSection(ssPtr, CreateIndxReq::INDEX_NAME_SECTION);
- SimplePropertiesSectionReader r1(ssPtr, getSectionSegmentPool());
- DictTabInfo::Table tableDesc;
- tableDesc.init();
- SimpleProperties::UnpackStatus status = SimpleProperties::unpack(
- r1, &tableDesc,
- DictTabInfo::TableMapping, DictTabInfo::TableMappingSize,
- true, true);
- if (status != SimpleProperties::Eof) {
- opPtr.p->m_errorCode = CreateIndxRef::InvalidName;
- opPtr.p->m_errorLine = __LINE__;
- releaseSections(signal);
- createIndex_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- memcpy(opPtr.p->m_indexName, tableDesc.TableName, MAX_TAB_NAME_SIZE);
- opPtr.p->m_storedIndex = tableDesc.TableLoggedFlag;
- releaseSections(signal);
- // master expects to hear from all
- if (opPtr.p->m_isMaster)
- opPtr.p->m_signalCounter = c_aliveNodes;
- createIndex_slavePrepare(signal, opPtr);
- createIndex_sendReply(signal, opPtr, false);
- return;
- }
- c_opCreateIndex.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == CreateIndxReq::RT_DICT_COMMIT ||
- requestType == CreateIndxReq::RT_DICT_ABORT) {
- jam();
- if (requestType == CreateIndxReq::RT_DICT_COMMIT) {
- opPtr.p->m_request.setIndexId(req->getIndexId());
- opPtr.p->m_request.setIndexVersion(req->getIndexVersion());
- createIndex_slaveCommit(signal, opPtr);
- } else {
- createIndex_slaveAbort(signal, opPtr);
- }
- createIndex_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opCreateIndex.release(opPtr);
- return;
- }
- }
- jam();
- // return to sender
- releaseSections(signal);
- OpCreateIndex opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = CreateIndxRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- createIndex_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::execCREATE_INDX_CONF(Signal* signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 0);
- CreateIndxConf* conf = (CreateIndxConf*)signal->getDataPtrSend();
- createIndex_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execCREATE_INDX_REF(Signal* signal)
- {
- jamEntry();
- CreateIndxRef* ref = (CreateIndxRef*)signal->getDataPtrSend();
- createIndex_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::createIndex_recvReply(Signal* signal, const CreateIndxConf* conf,
- const CreateIndxRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const CreateIndxReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == CreateIndxReq::RT_TC) {
- jam();
- // part of alter index operation
- OpAlterIndexPtr opPtr;
- c_opAlterIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterIndex_fromCreateTc(signal, opPtr);
- return;
- }
- OpCreateIndexPtr opPtr;
- c_opCreateIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- ndbrequire(opPtr.p->m_isMaster);
- ndbrequire(opPtr.p->m_requestType == requestType);
- opPtr.p->setError(ref);
- opPtr.p->m_signalCounter.clearWaitingFor(refToNode(senderRef));
- if (! opPtr.p->m_signalCounter.done()) {
- jam();
- return;
- }
- if (requestType == CreateIndxReq::RT_DICT_COMMIT ||
- requestType == CreateIndxReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- createIndex_sendReply(signal, opPtr, true);
- c_opCreateIndex.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_ABORT;
- createIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == CreateIndxReq::RT_DICT_PREPARE) {
- jam();
- // start index table create
- createIndex_toCreateTable(signal, opPtr);
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_ABORT;
- createIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::createIndex_slavePrepare(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- }
- void
- Dbdict::createIndex_toCreateTable(Signal* signal, OpCreateIndexPtr opPtr)
- {
- Uint32 k;
- jam();
- const CreateIndxReq* const req = &opPtr.p->m_request;
- // signal data writer
- Uint32* wbuffer = &c_indexPage.word[0];
- LinearWriter w(wbuffer, sizeof(c_indexPage) >> 2);
- w.first();
- // get table being indexed
- if (! (req->getTableId() < c_tableRecordPool.getSize())) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidPrimaryTable;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, req->getTableId());
- if (tablePtr.p->tabState != TableRecord::DEFINED &&
- tablePtr.p->tabState != TableRecord::BACKUP_ONGOING) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidPrimaryTable;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (! tablePtr.p->isTable()) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidPrimaryTable;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- // compute index table record
- TableRecord indexRec;
- TableRecordPtr indexPtr;
- indexPtr.i = RNIL; // invalid
- indexPtr.p = &indexRec;
- initialiseTableRecord(indexPtr);
- if (req->getIndexType() == DictTabInfo::UniqueHashIndex) {
- indexPtr.p->storedTable = opPtr.p->m_storedIndex;
- indexPtr.p->fragmentType = tablePtr.p->fragmentType;
- } else if (req->getIndexType() == DictTabInfo::OrderedIndex) {
- // first version will not supported logging
- if (opPtr.p->m_storedIndex) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidIndexType;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- indexPtr.p->storedTable = false;
- // follows table fragmentation
- indexPtr.p->fragmentType = tablePtr.p->fragmentType;
- } else {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidIndexType;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- indexPtr.p->tableType = (DictTabInfo::TableType)req->getIndexType();
- indexPtr.p->primaryTableId = req->getTableId();
- indexPtr.p->noOfAttributes = opPtr.p->m_attrList.sz;
- indexPtr.p->tupKeyLength = 0;
- if (indexPtr.p->noOfAttributes == 0) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidIndexType;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (indexPtr.p->isOrderedIndex()) {
- // tree node size in words (make configurable later)
- indexPtr.p->tupKeyLength = MAX_TTREE_NODE_SIZE;
- }
- // hash index attributes must currently be in table order
- Uint32 prevAttrId = RNIL;
- for (k = 0; k < opPtr.p->m_attrList.sz; k++) {
- jam();
- bool found = false;
- for (Uint32 tAttr = tablePtr.p->firstAttribute; tAttr != RNIL; ) {
- AttributeRecord* aRec = c_attributeRecordPool.getPtr(tAttr);
- tAttr = aRec->nextAttrInTable;
- if (aRec->attributeId != opPtr.p->m_attrList.id[k])
- continue;
- jam();
- found = true;
- const Uint32 a = aRec->attributeDescriptor;
- if (indexPtr.p->isHashIndex()) {
- const Uint32 s1 = AttributeDescriptor::getSize(a);
- const Uint32 s2 = AttributeDescriptor::getArraySize(a);
- indexPtr.p->tupKeyLength += ((1 << s1) * s2 + 31) >> 5;
- }
- }
- if (! found) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (indexPtr.p->isHashIndex() &&
- k > 0 && prevAttrId >= opPtr.p->m_attrList.id[k]) {
- jam();
- opPtr.p->m_errorCode = CreateIndxRef::InvalidAttributeOrder;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- prevAttrId = opPtr.p->m_attrList.id[k];
- }
- indexPtr.p->noOfPrimkey = indexPtr.p->noOfAttributes;
- // plus concatenated primary table key attribute
- indexPtr.p->noOfAttributes += 1;
- indexPtr.p->noOfNullAttr = 0;
- // write index table
- w.add(DictTabInfo::TableName, opPtr.p->m_indexName);
- w.add(DictTabInfo::TableLoggedFlag, indexPtr.p->storedTable);
- w.add(DictTabInfo::FragmentTypeVal, indexPtr.p->fragmentType);
- w.add(DictTabInfo::TableTypeVal, indexPtr.p->tableType);
- w.add(DictTabInfo::PrimaryTable, tablePtr.p->tableName);
- w.add(DictTabInfo::PrimaryTableId, tablePtr.i);
- w.add(DictTabInfo::NoOfAttributes, indexPtr.p->noOfAttributes);
- w.add(DictTabInfo::NoOfKeyAttr, indexPtr.p->noOfPrimkey);
- w.add(DictTabInfo::NoOfNullable, indexPtr.p->noOfNullAttr);
- w.add(DictTabInfo::KeyLength, indexPtr.p->tupKeyLength);
- // write index key attributes
- AttributeRecordPtr aRecPtr;
- c_attributeRecordPool.getPtr(aRecPtr, tablePtr.p->firstAttribute);
- for (k = 0; k < opPtr.p->m_attrList.sz; k++) {
- jam();
- for (Uint32 tAttr = tablePtr.p->firstAttribute; tAttr != RNIL; ) {
- AttributeRecord* aRec = c_attributeRecordPool.getPtr(tAttr);
- tAttr = aRec->nextAttrInTable;
- if (aRec->attributeId != opPtr.p->m_attrList.id[k])
- continue;
- jam();
- const Uint32 a = aRec->attributeDescriptor;
- bool isNullable = AttributeDescriptor::getNullable(a);
- w.add(DictTabInfo::AttributeName, aRec->attributeName);
- w.add(DictTabInfo::AttributeId, k);
- if (indexPtr.p->isHashIndex()) {
- w.add(DictTabInfo::AttributeKeyFlag, (Uint32)true);
- w.add(DictTabInfo::AttributeNullableFlag, (Uint32)false);
- }
- if (indexPtr.p->isOrderedIndex()) {
- w.add(DictTabInfo::AttributeKeyFlag, (Uint32)false);
- w.add(DictTabInfo::AttributeNullableFlag, (Uint32)isNullable);
- }
- w.add(DictTabInfo::AttributeStoredInd, (Uint32)DictTabInfo::Stored);
- // ext type overrides
- w.add(DictTabInfo::AttributeExtType, aRec->extType);
- w.add(DictTabInfo::AttributeExtPrecision, aRec->extPrecision);
- w.add(DictTabInfo::AttributeExtScale, aRec->extScale);
- w.add(DictTabInfo::AttributeExtLength, aRec->extLength);
- w.add(DictTabInfo::AttributeEnd, (Uint32)true);
- }
- }
- if (indexPtr.p->isHashIndex()) {
- jam();
- // write concatenated primary table key attribute
- w.add(DictTabInfo::AttributeName, "NDB$PK");
- w.add(DictTabInfo::AttributeId, opPtr.p->m_attrList.sz);
- w.add(DictTabInfo::AttributeKeyFlag, (Uint32)false);
- w.add(DictTabInfo::AttributeStoredInd, (Uint32)DictTabInfo::Stored);
- w.add(DictTabInfo::AttributeNullableFlag, (Uint32)false);
- // ext type overrides
- w.add(DictTabInfo::AttributeExtType, (Uint32)DictTabInfo::ExtUnsigned);
- w.add(DictTabInfo::AttributeExtLength, tablePtr.p->tupKeyLength);
- w.add(DictTabInfo::AttributeEnd, (Uint32)true);
- }
- if (indexPtr.p->isOrderedIndex()) {
- jam();
- // write index tree node as Uint32 array attribute
- w.add(DictTabInfo::AttributeName, "NDB$TNODE");
- w.add(DictTabInfo::AttributeId, opPtr.p->m_attrList.sz);
- w.add(DictTabInfo::AttributeKeyFlag, (Uint32)true);
- w.add(DictTabInfo::AttributeStoredInd, (Uint32)DictTabInfo::Stored);
- w.add(DictTabInfo::AttributeNullableFlag, (Uint32)false);
- // ext type overrides
- w.add(DictTabInfo::AttributeExtType, (Uint32)DictTabInfo::ExtUnsigned);
- w.add(DictTabInfo::AttributeExtLength, indexPtr.p->tupKeyLength);
- w.add(DictTabInfo::AttributeEnd, (Uint32)true);
- }
- // finish
- w.add(DictTabInfo::TableEnd, (Uint32)true);
- // remember to...
- releaseSections(signal);
- // send create index table request
- CreateTableReq * const cre = (CreateTableReq*)signal->getDataPtrSend();
- cre->senderRef = reference();
- cre->senderData = opPtr.p->key;
- LinearSectionPtr lsPtr[3];
- lsPtr[0].p = wbuffer;
- lsPtr[0].sz = w.getWordsUsed();
- sendSignal(DBDICT_REF, GSN_CREATE_TABLE_REQ,
- signal, CreateTableReq::SignalLength, JBB, lsPtr, 1);
- }
- void
- Dbdict::createIndex_fromCreateTable(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_ABORT;
- createIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- if (! opPtr.p->m_request.getOnline()) {
- jam();
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_COMMIT;
- createIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- createIndex_toAlterIndex(signal, opPtr);
- }
- void
- Dbdict::createIndex_toAlterIndex(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- AlterIndxReq* const req = (AlterIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(AlterIndxReq::RT_CREATE_INDEX);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setTableId(opPtr.p->m_request.getTableId());
- req->setIndexId(opPtr.p->m_request.getIndexId());
- req->setIndexVersion(opPtr.p->m_request.getIndexVersion());
- req->setOnline(true);
- sendSignal(reference(), GSN_ALTER_INDX_REQ,
- signal, AlterIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::createIndex_fromAlterIndex(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_ABORT;
- createIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = CreateIndxReq::RT_DICT_COMMIT;
- createIndex_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::createIndex_slaveCommit(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- const Uint32 indexId = opPtr.p->m_request.getIndexId();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, indexId);
- if (! opPtr.p->m_request.getOnline()) {
- ndbrequire(indexPtr.p->indexState == TableRecord::IS_UNDEFINED);
- indexPtr.p->indexState = TableRecord::IS_OFFLINE;
- } else {
- ndbrequire(indexPtr.p->indexState == TableRecord::IS_ONLINE);
- }
- }
- void
- Dbdict::createIndex_slaveAbort(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- CreateIndxReq* const req = &opPtr.p->m_request;
- const Uint32 indexId = req->getIndexId();
- if (indexId >= c_tableRecordPool.getSize()) {
- jam();
- return;
- }
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, indexId);
- if (! indexPtr.p->isIndex()) {
- jam();
- return;
- }
- indexPtr.p->indexState = TableRecord::IS_BROKEN;
- }
- void
- Dbdict::createIndex_sendSlaveReq(Signal* signal, OpCreateIndexPtr opPtr)
- {
- jam();
- CreateIndxReq* const req = (CreateIndxReq*)signal->getDataPtrSend();
- *req = opPtr.p->m_request;
- req->setUserRef(opPtr.p->m_coordinatorRef);
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(opPtr.p->m_requestType);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- opPtr.p->m_signalCounter = c_aliveNodes;
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- sendSignal(rg, GSN_CREATE_INDX_REQ,
- signal, CreateIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::createIndex_sendReply(Signal* signal, OpCreateIndexPtr opPtr,
- bool toUser)
- {
- CreateIndxRef* rep = (CreateIndxRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_CREATE_INDX_CONF;
- Uint32 length = CreateIndxConf::InternalLength;
- bool sendRef;
- if (! toUser) {
- sendRef = opPtr.p->hasLastError();
- rep->setUserRef(opPtr.p->m_coordinatorRef);
- rep->setConnectionPtr(opPtr.p->key);
- rep->setRequestType(opPtr.p->m_requestType);
- if (opPtr.p->m_requestType == CreateIndxReq::RT_DICT_ABORT)
- sendRef = false;
- } else {
- sendRef = opPtr.p->hasError();
- rep->setUserRef(opPtr.p->m_request.getUserRef());
- rep->setConnectionPtr(opPtr.p->m_request.getConnectionPtr());
- rep->setRequestType(opPtr.p->m_request.getRequestType());
- length = CreateIndxConf::SignalLength;
- }
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setIndexId(opPtr.p->m_request.getIndexId());
- rep->setIndexVersion(opPtr.p->m_request.getIndexVersion());
- if (sendRef) {
- if (opPtr.p->m_errorNode == 0)
- opPtr.p->m_errorNode = getOwnNodeId();
- rep->setErrorCode(opPtr.p->m_errorCode);
- rep->setErrorLine(opPtr.p->m_errorLine);
- rep->setErrorNode(opPtr.p->m_errorNode);
- gsn = GSN_CREATE_INDX_REF;
- length = CreateIndxRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /**
- * MODULE: Drop index.
- *
- * Drop index. First alters the index offline (i.e. drops metadata in
- * other blocks) and then drops the index table.
- */
- void
- Dbdict::execDROP_INDX_REQ(Signal* signal)
- {
- jamEntry();
- DropIndxReq* const req = (DropIndxReq*)signal->getDataPtrSend();
- OpDropIndexPtr opPtr;
- int err = DropIndxRef::BadRequestType;
- const Uint32 senderRef = signal->senderBlockRef();
- const DropIndxReq::RequestType requestType = req->getRequestType();
- if (requestType == DropIndxReq::RT_USER) {
- jam();
- if (signal->getLength() == DropIndxReq::SignalLength) {
- jam();
- if (getOwnNodeId() != c_masterNodeId) {
- jam();
- err = DropIndxRef::NotMaster;
- goto error;
- }
- // forward initial request plus operation key to all
- Uint32 indexId= req->getIndexId();
- Uint32 indexVersion= req->getIndexVersion();
- TableRecordPtr tmp;
- int res = getMetaTablePtr(tmp, indexId, indexVersion);
- switch(res){
- case MetaData::InvalidArgument:
- err = DropIndxRef::IndexNotFound;
- goto error;
- case MetaData::TableNotFound:
- case MetaData::InvalidTableVersion:
- err = DropIndxRef::InvalidIndexVersion;
- goto error;
- }
- if (! tmp.p->isIndex()) {
- jam();
- err = DropIndxRef::NotAnIndex;
- goto error;
- }
- if (tmp.p->indexState != TableRecord::IS_ONLINE)
- req->addRequestFlag(RequestFlag::RF_FORCE);
- tmp.p->indexState = TableRecord::IS_DROPPING;
- req->setOpKey(++c_opRecordSequence);
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- sendSignal(rg, GSN_DROP_INDX_REQ,
- signal, DropIndxReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == DropIndxReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpDropIndex opBusy;
- if (! c_opDropIndex.seize(opPtr))
- opPtr.p = &opBusy;
- opPtr.p->save(req);
- opPtr.p->m_coordinatorRef = senderRef;
- opPtr.p->m_isMaster = (senderRef == reference());
- opPtr.p->key = opKey;
- opPtr.p->m_requestType = DropIndxReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = DropIndxRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- dropIndex_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opDropIndex.add(opPtr);
- // master expects to hear from all
- if (opPtr.p->m_isMaster)
- opPtr.p->m_signalCounter = c_aliveNodes;
- dropIndex_slavePrepare(signal, opPtr);
- dropIndex_sendReply(signal, opPtr, false);
- return;
- }
- c_opDropIndex.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == DropIndxReq::RT_DICT_COMMIT ||
- requestType == DropIndxReq::RT_DICT_ABORT) {
- jam();
- if (requestType == DropIndxReq::RT_DICT_COMMIT)
- dropIndex_slaveCommit(signal, opPtr);
- else
- dropIndex_slaveAbort(signal, opPtr);
- dropIndex_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opDropIndex.release(opPtr);
- return;
- }
- }
- error:
- jam();
- // return to sender
- OpDropIndex opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = (DropIndxRef::ErrorCode)err;
- opPtr.p->m_errorLine = __LINE__;
- opPtr.p->m_errorNode = c_masterNodeId;
- dropIndex_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::execDROP_INDX_CONF(Signal* signal)
- {
- jamEntry();
- DropIndxConf* conf = (DropIndxConf*)signal->getDataPtrSend();
- dropIndex_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execDROP_INDX_REF(Signal* signal)
- {
- jamEntry();
- DropIndxRef* ref = (DropIndxRef*)signal->getDataPtrSend();
- dropIndex_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::dropIndex_recvReply(Signal* signal, const DropIndxConf* conf,
- const DropIndxRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const DropIndxReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == DropIndxReq::RT_TC) {
- jam();
- // part of alter index operation
- OpAlterIndexPtr opPtr;
- c_opAlterIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterIndex_fromDropTc(signal, opPtr);
- return;
- }
- OpDropIndexPtr opPtr;
- c_opDropIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- ndbrequire(opPtr.p->m_isMaster);
- ndbrequire(opPtr.p->m_requestType == requestType);
- opPtr.p->setError(ref);
- opPtr.p->m_signalCounter.clearWaitingFor(refToNode(senderRef));
- if (! opPtr.p->m_signalCounter.done()) {
- jam();
- return;
- }
- if (requestType == DropIndxReq::RT_DICT_COMMIT ||
- requestType == DropIndxReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- dropIndex_sendReply(signal, opPtr, true);
- c_opDropIndex.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = DropIndxReq::RT_DICT_ABORT;
- dropIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == DropIndxReq::RT_DICT_PREPARE) {
- jam();
- // start alter offline
- dropIndex_toAlterIndex(signal, opPtr);
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::dropIndex_slavePrepare(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- DropIndxReq* const req = &opPtr.p->m_request;
- // check index exists
- TableRecordPtr indexPtr;
- if (! (req->getIndexId() < c_tableRecordPool.getSize())) {
- jam();
- opPtr.p->m_errorCode = DropIndxRef::IndexNotFound;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- c_tableRecordPool.getPtr(indexPtr, req->getIndexId());
- if (indexPtr.p->tabState != TableRecord::DEFINED) {
- jam();
- opPtr.p->m_errorCode = DropIndxRef::IndexNotFound;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (! indexPtr.p->isIndex()) {
- jam();
- opPtr.p->m_errorCode = DropIndxRef::NotAnIndex;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- // ignore incoming primary table id
- req->setTableId(indexPtr.p->primaryTableId);
- }
- void
- Dbdict::dropIndex_toAlterIndex(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- AlterIndxReq* const req = (AlterIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(AlterIndxReq::RT_DROP_INDEX);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setTableId(opPtr.p->m_request.getTableId());
- req->setIndexId(opPtr.p->m_request.getIndexId());
- req->setIndexVersion(opPtr.p->m_request.getIndexVersion());
- req->setOnline(false);
- sendSignal(reference(), GSN_ALTER_INDX_REQ,
- signal, AlterIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::dropIndex_fromAlterIndex(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = DropIndxReq::RT_DICT_ABORT;
- dropIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- dropIndex_toDropTable(signal, opPtr);
- }
- void
- Dbdict::dropIndex_toDropTable(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- DropTableReq* const req = (DropTableReq*)signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = opPtr.p->key;
- req->tableId = opPtr.p->m_request.getIndexId();
- req->tableVersion = opPtr.p->m_request.getIndexVersion();
- sendSignal(reference(), GSN_DROP_TABLE_REQ,
- signal,DropTableReq::SignalLength, JBB);
- }
- void
- Dbdict::dropIndex_fromDropTable(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = DropIndxReq::RT_DICT_ABORT;
- dropIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = DropIndxReq::RT_DICT_COMMIT;
- dropIndex_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::dropIndex_slaveCommit(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- }
- void
- Dbdict::dropIndex_slaveAbort(Signal* signal, OpDropIndexPtr opPtr)
- {
- jam();
- DropIndxReq* const req = &opPtr.p->m_request;
- const Uint32 indexId = req->getIndexId();
- if (indexId >= c_tableRecordPool.getSize()) {
- jam();
- return;
- }
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, indexId);
- indexPtr.p->indexState = TableRecord::IS_BROKEN;
- }
- void
- Dbdict::dropIndex_sendSlaveReq(Signal* signal, OpDropIndexPtr opPtr)
- {
- DropIndxReq* const req = (DropIndxReq*)signal->getDataPtrSend();
- *req = opPtr.p->m_request;
- req->setUserRef(opPtr.p->m_coordinatorRef);
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(opPtr.p->m_requestType);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- opPtr.p->m_signalCounter = c_aliveNodes;
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- sendSignal(rg, GSN_DROP_INDX_REQ,
- signal, DropIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::dropIndex_sendReply(Signal* signal, OpDropIndexPtr opPtr,
- bool toUser)
- {
- DropIndxRef* rep = (DropIndxRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_DROP_INDX_CONF;
- Uint32 length = DropIndxConf::InternalLength;
- bool sendRef;
- if (! toUser) {
- sendRef = opPtr.p->hasLastError();
- rep->setUserRef(opPtr.p->m_coordinatorRef);
- rep->setConnectionPtr(opPtr.p->key);
- rep->setRequestType(opPtr.p->m_requestType);
- if (opPtr.p->m_requestType == DropIndxReq::RT_DICT_ABORT)
- sendRef = false;
- } else {
- sendRef = opPtr.p->hasError();
- rep->setUserRef(opPtr.p->m_request.getUserRef());
- rep->setConnectionPtr(opPtr.p->m_request.getConnectionPtr());
- rep->setRequestType(opPtr.p->m_request.getRequestType());
- length = DropIndxConf::SignalLength;
- }
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setIndexId(opPtr.p->m_request.getIndexId());
- rep->setIndexVersion(opPtr.p->m_request.getIndexVersion());
- if (sendRef) {
- if (opPtr.p->m_errorNode == 0)
- opPtr.p->m_errorNode = getOwnNodeId();
- rep->setErrorCode(opPtr.p->m_errorCode);
- rep->setErrorLine(opPtr.p->m_errorLine);
- rep->setErrorNode(opPtr.p->m_errorNode);
- gsn = GSN_DROP_INDX_REF;
- length = DropIndxRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /*****************************************************
- *
- * Util signalling
- *
- *****************************************************/
- int
- Dbdict::sendSignalUtilReq(Callback *pcallback,
- BlockReference ref,
- GlobalSignalNumber gsn,
- Signal* signal,
- Uint32 length,
- JobBufferLevel jbuf,
- LinearSectionPtr ptr[3],
- Uint32 noOfSections)
- {
- jam();
- EVENT_TRACE;
- OpSignalUtilPtr utilRecPtr;
- // Seize a Util Send record
- if (!c_opSignalUtil.seize(utilRecPtr)) {
- // Failed to allocate util record
- return -1;
- }
- utilRecPtr.p->m_callback = *pcallback;
- // should work for all util signal classes
- UtilPrepareReq *req = (UtilPrepareReq*)signal->getDataPtrSend();
- utilRecPtr.p->m_userData = req->getSenderData();
- req->setSenderData(utilRecPtr.i);
- if (ptr) {
- jam();
- sendSignal(ref, gsn, signal, length, jbuf, ptr, noOfSections);
- } else {
- jam();
- sendSignal(ref, gsn, signal, length, jbuf);
- }
- return 0;
- }
- int
- Dbdict::recvSignalUtilReq(Signal* signal, Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- UtilPrepareConf * const req = (UtilPrepareConf*)signal->getDataPtr();
- OpSignalUtilPtr utilRecPtr;
- utilRecPtr.i = req->getSenderData();
- if ((utilRecPtr.p = c_opSignalUtil.getPtr(utilRecPtr.i)) == NULL) {
- jam();
- return -1;
- }
- req->setSenderData(utilRecPtr.p->m_userData);
- Callback c = utilRecPtr.p->m_callback;
- c_opSignalUtil.release(utilRecPtr);
- execute(signal, c, returnCode);
- return 0;
- }
- void Dbdict::execUTIL_PREPARE_CONF(Signal *signal)
- {
- jamEntry();
- EVENT_TRACE;
- ndbrequire(recvSignalUtilReq(signal, 0) == 0);
- }
- void
- Dbdict::execUTIL_PREPARE_REF(Signal *signal)
- {
- jamEntry();
- EVENT_TRACE;
- ndbrequire(recvSignalUtilReq(signal, 1) == 0);
- }
- void Dbdict::execUTIL_EXECUTE_CONF(Signal *signal)
- {
- jamEntry();
- EVENT_TRACE;
- ndbrequire(recvSignalUtilReq(signal, 0) == 0);
- }
- void Dbdict::execUTIL_EXECUTE_REF(Signal *signal)
- {
- jamEntry();
- EVENT_TRACE;
- #ifdef EVENT_DEBUG
- UtilExecuteRef * ref = (UtilExecuteRef *)signal->getDataPtrSend();
- ndbout_c("execUTIL_EXECUTE_REF");
- ndbout_c("senderData %u",ref->getSenderData());
- ndbout_c("errorCode %u",ref->getErrorCode());
- ndbout_c("TCErrorCode %u",ref->getTCErrorCode());
- #endif
-
- ndbrequire(recvSignalUtilReq(signal, 1) == 0);
- }
- void Dbdict::execUTIL_RELEASE_CONF(Signal *signal)
- {
- jamEntry();
- EVENT_TRACE;
- ndbrequire(false);
- ndbrequire(recvSignalUtilReq(signal, 0) == 0);
- }
- void Dbdict::execUTIL_RELEASE_REF(Signal *signal)
- {
- jamEntry();
- EVENT_TRACE;
- ndbrequire(false);
- ndbrequire(recvSignalUtilReq(signal, 1) == 0);
- }
- /**
- * MODULE: Create event
- *
- * Create event in DICT.
- *
- *
- * Request type in CREATE_EVNT signals:
- *
- * Signalflow see Dbdict.txt
- *
- */
- /*****************************************************************
- *
- * Systable stuff
- *
- */
- const Uint32 Dbdict::sysTab_NDBEVENTS_0_szs[EVENT_SYSTEM_TABLE_LENGTH] = {
- sizeof(((sysTab_NDBEVENTS_0*)0)->NAME),
- sizeof(((sysTab_NDBEVENTS_0*)0)->EVENT_TYPE),
- sizeof(((sysTab_NDBEVENTS_0*)0)->TABLE_NAME),
- sizeof(((sysTab_NDBEVENTS_0*)0)->ATTRIBUTE_MASK),
- sizeof(((sysTab_NDBEVENTS_0*)0)->SUBID),
- sizeof(((sysTab_NDBEVENTS_0*)0)->SUBKEY)
- };
- void
- Dbdict::prepareTransactionEventSysTable (Callback *pcallback,
- Signal* signal,
- Uint32 senderData,
- UtilPrepareReq::OperationTypeValue prepReq)
- {
- // find table id for event system table
- TableRecord keyRecord;
- strcpy(keyRecord.tableName, EVENT_SYSTEM_TABLE_NAME);
- TableRecordPtr tablePtr;
- c_tableRecordHash.find(tablePtr, keyRecord);
-
- ndbrequire(tablePtr.i != RNIL); // system table must exist
- Uint32 tableId = tablePtr.p->tableId; /* System table */
- Uint32 noAttr = tablePtr.p->noOfAttributes;
- ndbrequire(noAttr == EVENT_SYSTEM_TABLE_LENGTH);
- switch (prepReq) {
- case UtilPrepareReq::Update:
- case UtilPrepareReq::Insert:
- case UtilPrepareReq::Write:
- case UtilPrepareReq::Read:
- jam();
- break;
- case UtilPrepareReq::Delete:
- jam();
- noAttr = 1; // only involves Primary key which should be the first
- break;
- }
- prepareUtilTransaction(pcallback, signal, senderData, tableId, NULL,
- prepReq, noAttr, NULL, NULL);
- }
- void
- Dbdict::prepareUtilTransaction(Callback *pcallback,
- Signal* signal,
- Uint32 senderData,
- Uint32 tableId,
- const char* tableName,
- UtilPrepareReq::OperationTypeValue prepReq,
- Uint32 noAttr,
- Uint32 attrIds[],
- const char *attrNames[])
- {
- jam();
- EVENT_TRACE;
- UtilPrepareReq * utilPrepareReq =
- (UtilPrepareReq *)signal->getDataPtrSend();
-
- utilPrepareReq->setSenderRef(reference());
- utilPrepareReq->setSenderData(senderData);
- const Uint32 pageSizeInWords = 128;
- Uint32 propPage[pageSizeInWords];
- LinearWriter w(&propPage[0],128);
- w.first();
- w.add(UtilPrepareReq::NoOfOperations, 1);
- w.add(UtilPrepareReq::OperationType, prepReq);
- if (tableName) {
- jam();
- w.add(UtilPrepareReq::TableName, tableName);
- } else {
- jam();
- w.add(UtilPrepareReq::TableId, tableId);
- }
- for(Uint32 i = 0; i < noAttr; i++)
- if (tableName) {
- jam();
- w.add(UtilPrepareReq::AttributeName, attrNames[i]);
- } else {
- if (attrIds) {
- jam();
- w.add(UtilPrepareReq::AttributeId, attrIds[i]);
- } else {
- jam();
- w.add(UtilPrepareReq::AttributeId, i);
- }
- }
- #ifdef EVENT_DEBUG
- // Debugging
- SimplePropertiesLinearReader reader(propPage, w.getWordsUsed());
- printf("Dict::prepareInsertTransactions: Sent SimpleProperties:n");
- reader.printAll(ndbout);
- #endif
- struct LinearSectionPtr sectionsPtr[UtilPrepareReq::NoOfSections];
- sectionsPtr[UtilPrepareReq::PROPERTIES_SECTION].p = propPage;
- sectionsPtr[UtilPrepareReq::PROPERTIES_SECTION].sz = w.getWordsUsed();
- sendSignalUtilReq(pcallback, DBUTIL_REF, GSN_UTIL_PREPARE_REQ, signal,
- UtilPrepareReq::SignalLength, JBB,
- sectionsPtr, UtilPrepareReq::NoOfSections);
- }
- /*****************************************************************
- *
- * CREATE_EVNT_REQ has three types RT_CREATE, RT_GET (from user)
- * and RT_DICT_AFTER_GET send from master DICT to slaves
- *
- * This function just dscpaches these to
- *
- * createEvent_RT_USER_CREATE
- * createEvent_RT_USER_GET
- * createEvent_RT_DICT_AFTER_GET
- *
- * repectively
- *
- */
- void
- Dbdict::execCREATE_EVNT_REQ(Signal* signal)
- {
- jamEntry();
- #if 0
- {
- SafeCounterHandle handle;
- {
- SafeCounter tmp(c_counterMgr, handle);
- tmp.init<CreateEvntRef>(CMVMI, GSN_DUMP_STATE_ORD, /* senderData */ 13);
- tmp.clearWaitingFor();
- tmp.setWaitingFor(3);
- ndbrequire(!tmp.done());
- ndbout_c("Allocted");
- }
- ndbrequire(!handle.done());
- {
- SafeCounter tmp(c_counterMgr, handle);
- tmp.clearWaitingFor(3);
- ndbrequire(tmp.done());
- ndbout_c("Deallocted");
- }
- ndbrequire(handle.done());
- }
- {
- NodeBitmask nodes;
- nodes.clear();
- nodes.set(2);
- nodes.set(3);
- nodes.set(4);
- nodes.set(5);
- {
- Uint32 i = 0;
- while((i = nodes.find(i)) != NodeBitmask::NotFound){
- ndbout_c("1 Node id = %u", i);
- i++;
- }
- }
- NodeReceiverGroup rg(DBDICT, nodes);
- RequestTracker rt2;
- ndbrequire(rt2.done());
- ndbrequire(!rt2.hasRef());
- ndbrequire(!rt2.hasConf());
- rt2.init<CreateEvntRef>(c_counterMgr, rg, GSN_CREATE_EVNT_REF, 13);
- RequestTracker rt3;
- rt3.init<CreateEvntRef>(c_counterMgr, rg, GSN_CREATE_EVNT_REF, 13);
- ndbrequire(!rt2.done());
- ndbrequire(!rt3.done());
- rt2.reportRef(c_counterMgr, 2);
- rt3.reportConf(c_counterMgr, 2);
- ndbrequire(!rt2.done());
- ndbrequire(!rt3.done());
- rt2.reportConf(c_counterMgr, 3);
- rt3.reportConf(c_counterMgr, 3);
- ndbrequire(!rt2.done());
- ndbrequire(!rt3.done());
- rt2.reportConf(c_counterMgr, 4);
- rt3.reportConf(c_counterMgr, 4);
- ndbrequire(!rt2.done());
- ndbrequire(!rt3.done());
- rt2.reportConf(c_counterMgr, 5);
- rt3.reportConf(c_counterMgr, 5);
- ndbrequire(rt2.done());
- ndbrequire(rt3.done());
- }
- #endif
- if (! assembleFragments(signal)) {
- jam();
- return;
- }
- CreateEvntReq *req = (CreateEvntReq*)signal->getDataPtr();
- const CreateEvntReq::RequestType requestType = req->getRequestType();
- const Uint32 requestFlag = req->getRequestFlag();
- OpCreateEventPtr evntRecPtr;
- // Seize a Create Event record
- if (!c_opCreateEvent.seize(evntRecPtr)) {
- // Failed to allocate event record
- jam();
- releaseSections(signal);
- CreateEvntRef * ret = (CreateEvntRef *)signal->getDataPtrSend();
- ret->senderRef = reference();
- ret->setErrorCode(CreateEvntRef::SeizeError);
- ret->setErrorLine(__LINE__);
- ret->setErrorNode(reference());
- sendSignal(signal->senderBlockRef(), GSN_CREATE_EVNT_REF, signal,
- CreateEvntRef::SignalLength, JBB);
- return;
- }
- #ifdef EVENT_DEBUG
- ndbout_c("DBDICT::execCREATE_EVNT_REQ from %u evntRecId = (%d)", refToNode(signal->getSendersBlockRef()), evntRecPtr.i);
- #endif
-
- ndbrequire(req->getUserRef() == signal->getSendersBlockRef());
- evntRecPtr.p->init(req,this);
- if (requestFlag & (Uint32)CreateEvntReq::RT_DICT_AFTER_GET) {
- jam();
- EVENT_TRACE;
- createEvent_RT_DICT_AFTER_GET(signal, evntRecPtr);
- return;
- }
- if (requestType == CreateEvntReq::RT_USER_GET) {
- jam();
- EVENT_TRACE;
- createEvent_RT_USER_GET(signal, evntRecPtr);
- return;
- }
- if (requestType == CreateEvntReq::RT_USER_CREATE) {
- jam();
- EVENT_TRACE;
- createEvent_RT_USER_CREATE(signal, evntRecPtr);
- return;
- }
- #ifdef EVENT_DEBUG
- ndbout << "Dbdict.cpp: Dbdict::execCREATE_EVNT_REQ other" << endl;
- #endif
- jam();
- releaseSections(signal);
-
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
-
- createEvent_sendReply(signal, evntRecPtr);
- }
- /********************************************************************
- *
- * Event creation
- *
- *****************************************************************/
- void
- Dbdict::createEvent_RT_USER_CREATE(Signal* signal, OpCreateEventPtr evntRecPtr){
- jam();
- evntRecPtr.p->m_request.setUserRef(signal->senderBlockRef());
- #ifdef EVENT_DEBUG
- ndbout << "Dbdict.cpp: Dbdict::execCREATE_EVNT_REQ RT_USER" << endl;
- char buf[128] = {0};
- AttributeMask mask = evntRecPtr.p->m_request.getAttrListBitmask();
- mask.getText(buf);
- ndbout_c("mask = %s", buf);
- #endif
- // Interpret the long signal
- SegmentedSectionPtr ssPtr;
- // save name and event properties
- signal->getSection(ssPtr, CreateEvntReq::EVENT_NAME_SECTION);
- SimplePropertiesSectionReader r0(ssPtr, getSectionSegmentPool());
- #ifdef EVENT_DEBUG
- r0.printAll(ndbout);
- #endif
- // event name
- if ((!r0.first()) ||
- (r0.getValueType() != SimpleProperties::StringValue) ||
- (r0.getValueLen() <= 0)) {
- jam();
- releaseSections(signal);
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
- createEvent_sendReply(signal, evntRecPtr);
- return;
- }
- r0.getString(evntRecPtr.p->m_eventRec.NAME);
- {
- int len = strlen(evntRecPtr.p->m_eventRec.NAME);
- memset(evntRecPtr.p->m_eventRec.NAME+len, 0, MAX_TAB_NAME_SIZE-len);
- #ifdef EVENT_DEBUG
- printf("CreateEvntReq::RT_USER_CREATE; EventName %s, len %un",
- evntRecPtr.p->m_eventRec.NAME, len);
- for(int i = 0; i < MAX_TAB_NAME_SIZE/4; i++)
- printf("H'%.8x ", ((Uint32*)evntRecPtr.p->m_eventRec.NAME)[i]);
- printf("n");
- #endif
- }
- // table name
- if ((!r0.next()) ||
- (r0.getValueType() != SimpleProperties::StringValue) ||
- (r0.getValueLen() <= 0)) {
- jam();
- releaseSections(signal);
-
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
-
- createEvent_sendReply(signal, evntRecPtr);
- return;
- }
- r0.getString(evntRecPtr.p->m_eventRec.TABLE_NAME);
- {
- int len = strlen(evntRecPtr.p->m_eventRec.TABLE_NAME);
- memset(evntRecPtr.p->m_eventRec.TABLE_NAME+len, 0, MAX_TAB_NAME_SIZE-len);
- }
-
- #ifdef EVENT_DEBUG
- ndbout_c("event name: %s",evntRecPtr.p->m_eventRec.NAME);
- ndbout_c("table name: %s",evntRecPtr.p->m_eventRec.TABLE_NAME);
- #endif
-
- releaseSections(signal);
-
- // Send request to SUMA
- CreateSubscriptionIdReq * sumaIdReq =
- (CreateSubscriptionIdReq *)signal->getDataPtrSend();
-
- // make sure we save the original sender for later
- sumaIdReq->senderData = evntRecPtr.i;
- #ifdef EVENT_DEBUG
- ndbout << "sumaIdReq->senderData = " << sumaIdReq->senderData << endl;
- #endif
- sendSignal(SUMA_REF, GSN_CREATE_SUBID_REQ, signal,
- CreateSubscriptionIdReq::SignalLength, JBB);
- // we should now return in either execCREATE_SUBID_CONF
- // or execCREATE_SUBID_REF
- }
- void Dbdict::execCREATE_SUBID_REF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- CreateSubscriptionIdRef * const ref =
- (CreateSubscriptionIdRef *)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = ref->senderData;
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
- createEvent_sendReply(signal, evntRecPtr);
- }
- void Dbdict::execCREATE_SUBID_CONF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- CreateSubscriptionIdConf const * sumaIdConf =
- (CreateSubscriptionIdConf *)signal->getDataPtr();
- Uint32 evntRecId = sumaIdConf->senderData;
- OpCreateEvent *evntRec;
- ndbrequire((evntRec = c_opCreateEvent.getPtr(evntRecId)) != NULL);
- evntRec->m_request.setEventId(sumaIdConf->subscriptionId);
- evntRec->m_request.setEventKey(sumaIdConf->subscriptionKey);
- releaseSections(signal);
- Callback c = { safe_cast(&Dbdict::createEventUTIL_PREPARE), 0 };
- prepareTransactionEventSysTable(&c, signal, evntRecId,
- UtilPrepareReq::Insert);
- }
- void
- Dbdict::createEventComplete_RT_USER_CREATE(Signal* signal,
- OpCreateEventPtr evntRecPtr){
- jam();
- createEvent_sendReply(signal, evntRecPtr);
- }
- /*********************************************************************
- *
- * UTIL_PREPARE, UTIL_EXECUTE
- *
- * insert or read systable NDB$EVENTS_0
- */
- void interpretUtilPrepareErrorCode(UtilPrepareRef::ErrorCode errorCode,
- bool& temporary, Uint32& line)
- {
- switch (errorCode) {
- case UtilPrepareRef::NO_ERROR:
- jam();
- line = __LINE__;
- EVENT_TRACE;
- break;
- case UtilPrepareRef::PREPARE_SEIZE_ERROR:
- jam();
- temporary = true;
- line = __LINE__;
- EVENT_TRACE;
- break;
- case UtilPrepareRef::PREPARE_PAGES_SEIZE_ERROR:
- jam();
- line = __LINE__;
- EVENT_TRACE;
- break;
- case UtilPrepareRef::PREPARED_OPERATION_SEIZE_ERROR:
- jam();
- line = __LINE__;
- EVENT_TRACE;
- break;
- case UtilPrepareRef::DICT_TAB_INFO_ERROR:
- jam();
- line = __LINE__;
- EVENT_TRACE;
- break;
- case UtilPrepareRef::MISSING_PROPERTIES_SECTION:
- jam();
- line = __LINE__;
- EVENT_TRACE;
- break;
- default:
- jam();
- line = __LINE__;
- EVENT_TRACE;
- break;
- }
- }
- void
- Dbdict::createEventUTIL_PREPARE(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- if (returnCode == 0) {
- UtilPrepareConf* const req = (UtilPrepareConf*)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- jam();
- evntRecPtr.i = req->getSenderData();
- const Uint32 prepareId = req->getPrepareId();
-
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
-
- Callback c = { safe_cast(&Dbdict::createEventUTIL_EXECUTE), 0 };
- switch (evntRecPtr.p->m_requestType) {
- case CreateEvntReq::RT_USER_GET:
- #ifdef EVENT_DEBUG
- printf("get type = %dn", CreateEvntReq::RT_USER_GET);
- #endif
- jam();
- executeTransEventSysTable(&c, signal,
- evntRecPtr.i, evntRecPtr.p->m_eventRec,
- prepareId, UtilPrepareReq::Read);
- break;
- case CreateEvntReq::RT_USER_CREATE:
- #ifdef EVENT_DEBUG
- printf("create type = %dn", CreateEvntReq::RT_USER_CREATE);
- #endif
- {
- evntRecPtr.p->m_eventRec.EVENT_TYPE = evntRecPtr.p->m_request.getEventType();
- AttributeMask m = evntRecPtr.p->m_request.getAttrListBitmask();
- memcpy(evntRecPtr.p->m_eventRec.ATTRIBUTE_MASK, &m,
- sizeof(evntRecPtr.p->m_eventRec.ATTRIBUTE_MASK));
- evntRecPtr.p->m_eventRec.SUBID = evntRecPtr.p->m_request.getEventId();
- evntRecPtr.p->m_eventRec.SUBKEY = evntRecPtr.p->m_request.getEventKey();
- }
- jam();
- executeTransEventSysTable(&c, signal,
- evntRecPtr.i, evntRecPtr.p->m_eventRec,
- prepareId, UtilPrepareReq::Insert);
- break;
- default:
- #ifdef EVENT_DEBUG
- printf("type = %dn", evntRecPtr.p->m_requestType);
- printf("bet type = %dn", CreateEvntReq::RT_USER_GET);
- printf("create type = %dn", CreateEvntReq::RT_USER_CREATE);
- #endif
- ndbrequire(false);
- }
- } else { // returnCode != 0
- UtilPrepareRef* const ref = (UtilPrepareRef*)signal->getDataPtr();
- const UtilPrepareRef::ErrorCode errorCode =
- (UtilPrepareRef::ErrorCode)ref->getErrorCode();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = ref->getSenderData();
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- bool temporary = false;
- interpretUtilPrepareErrorCode(errorCode,
- temporary, evntRecPtr.p->m_errorLine);
- if (temporary) {
- evntRecPtr.p->m_errorCode =
- CreateEvntRef::makeTemporary(CreateEvntRef::Undefined);
- }
- if (evntRecPtr.p->m_errorCode == 0) {
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- }
- evntRecPtr.p->m_errorNode = reference();
- createEvent_sendReply(signal, evntRecPtr);
- }
- }
- void Dbdict::executeTransEventSysTable(Callback *pcallback, Signal *signal,
- const Uint32 ptrI,
- sysTab_NDBEVENTS_0& m_eventRec,
- const Uint32 prepareId,
- UtilPrepareReq::OperationTypeValue prepReq)
- {
- jam();
- const Uint32 noAttr = EVENT_SYSTEM_TABLE_LENGTH;
- Uint32 total_len = 0;
- Uint32* attrHdr = signal->theData + 25;
- Uint32* attrPtr = attrHdr;
- Uint32 id=0;
- // attribute 0 event name: Primary Key
- {
- AttributeHeader::init(attrPtr, id, sysTab_NDBEVENTS_0_szs[id]/4);
- total_len += sysTab_NDBEVENTS_0_szs[id];
- attrPtr++; id++;
- }
- switch (prepReq) {
- case UtilPrepareReq::Read:
- jam();
- EVENT_TRACE;
- // no more
- while ( id < noAttr )
- AttributeHeader::init(attrPtr++, id++, 0);
- ndbrequire(id == (Uint32) noAttr);
- break;
- case UtilPrepareReq::Insert:
- jam();
- EVENT_TRACE;
- while ( id < noAttr ) {
- AttributeHeader::init(attrPtr, id, sysTab_NDBEVENTS_0_szs[id]/4);
- total_len += sysTab_NDBEVENTS_0_szs[id];
- attrPtr++; id++;
- }
- ndbrequire(id == (Uint32) noAttr);
- break;
- case UtilPrepareReq::Delete:
- ndbrequire(id == 1);
- break;
- default:
- ndbrequire(false);
- }
-
- LinearSectionPtr headerPtr;
- LinearSectionPtr dataPtr;
-
- headerPtr.p = attrHdr;
- headerPtr.sz = noAttr;
-
- dataPtr.p = (Uint32*)&m_eventRec;
- dataPtr.sz = total_len/4;
- ndbrequire((total_len == sysTab_NDBEVENTS_0_szs[0]) ||
- (total_len == sizeof(sysTab_NDBEVENTS_0)));
- #if 0
- printf("Header size %un", headerPtr.sz);
- for(int i = 0; i < (int)headerPtr.sz; i++)
- printf("H'%.8x ", attrHdr[i]);
- printf("n");
-
- printf("Data size %un", dataPtr.sz);
- for(int i = 0; i < (int)dataPtr.sz; i++)
- printf("H'%.8x ", dataPage[i]);
- printf("n");
- #endif
- executeTransaction(pcallback, signal,
- ptrI,
- prepareId,
- id,
- headerPtr,
- dataPtr);
- }
- void Dbdict::executeTransaction(Callback *pcallback,
- Signal* signal,
- Uint32 senderData,
- Uint32 prepareId,
- Uint32 noAttr,
- LinearSectionPtr headerPtr,
- LinearSectionPtr dataPtr)
- {
- jam();
- EVENT_TRACE;
- UtilExecuteReq * utilExecuteReq =
- (UtilExecuteReq *)signal->getDataPtrSend();
- utilExecuteReq->setSenderRef(reference());
- utilExecuteReq->setSenderData(senderData);
- utilExecuteReq->setPrepareId(prepareId);
- utilExecuteReq->setReleaseFlag(); // must be done after setting prepareId
- #if 0
- printf("Header size %un", headerPtr.sz);
- for(int i = 0; i < (int)headerPtr.sz; i++)
- printf("H'%.8x ", headerBuffer[i]);
- printf("n");
-
- printf("Data size %un", dataPtr.sz);
- for(int i = 0; i < (int)dataPtr.sz; i++)
- printf("H'%.8x ", dataBuffer[i]);
- printf("n");
- #endif
- struct LinearSectionPtr sectionsPtr[UtilExecuteReq::NoOfSections];
- sectionsPtr[UtilExecuteReq::HEADER_SECTION].p = headerPtr.p;
- sectionsPtr[UtilExecuteReq::HEADER_SECTION].sz = noAttr;
- sectionsPtr[UtilExecuteReq::DATA_SECTION].p = dataPtr.p;
- sectionsPtr[UtilExecuteReq::DATA_SECTION].sz = dataPtr.sz;
- sendSignalUtilReq(pcallback, DBUTIL_REF, GSN_UTIL_EXECUTE_REQ, signal,
- UtilExecuteReq::SignalLength, JBB,
- sectionsPtr, UtilExecuteReq::NoOfSections);
- }
- void Dbdict::parseReadEventSys(Signal* signal, sysTab_NDBEVENTS_0& m_eventRec)
- {
- SegmentedSectionPtr headerPtr, dataPtr;
- jam();
- signal->getSection(headerPtr, UtilExecuteReq::HEADER_SECTION);
- SectionReader headerReader(headerPtr, getSectionSegmentPool());
-
- signal->getSection(dataPtr, UtilExecuteReq::DATA_SECTION);
- SectionReader dataReader(dataPtr, getSectionSegmentPool());
-
- AttributeHeader header;
- Uint32 *dst = (Uint32*)&m_eventRec;
- for (int i = 0; i < EVENT_SYSTEM_TABLE_LENGTH; i++) {
- headerReader.getWord((Uint32 *)&header);
- int sz = header.getDataSize();
- for (int i=0; i < sz; i++)
- dataReader.getWord(dst++);
- }
- ndbrequire( ((char*)dst-(char*)&m_eventRec) == sizeof(m_eventRec) );
- releaseSections(signal);
- }
-
- void Dbdict::createEventUTIL_EXECUTE(Signal *signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- if (returnCode == 0) {
- // Entry into system table all set
- UtilExecuteConf* const conf = (UtilExecuteConf*)signal->getDataPtr();
- jam();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = conf->getSenderData();
-
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- OpCreateEvent *evntRec = evntRecPtr.p;
-
- switch (evntRec->m_requestType) {
- case CreateEvntReq::RT_USER_GET: {
- #ifdef EVENT_DEBUG
- printf("get type = %dn", CreateEvntReq::RT_USER_GET);
- #endif
- parseReadEventSys(signal, evntRecPtr.p->m_eventRec);
- evntRec->m_request.setEventType(evntRecPtr.p->m_eventRec.EVENT_TYPE);
- evntRec->m_request.setAttrListBitmask(*(AttributeMask*)evntRecPtr.p->m_eventRec.ATTRIBUTE_MASK);
- evntRec->m_request.setEventId(evntRecPtr.p->m_eventRec.SUBID);
- evntRec->m_request.setEventKey(evntRecPtr.p->m_eventRec.SUBKEY);
- #ifdef EVENT_DEBUG
- printf("EventName: %sn", evntRec->m_eventRec.NAME);
- printf("TableName: %sn", evntRec->m_eventRec.TABLE_NAME);
- #endif
-
- // find table id for event table
- TableRecord keyRecord;
- strcpy(keyRecord.tableName, evntRecPtr.p->m_eventRec.TABLE_NAME);
-
- TableRecordPtr tablePtr;
- c_tableRecordHash.find(tablePtr, keyRecord);
-
- if (tablePtr.i == RNIL) {
- jam();
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
-
- createEvent_sendReply(signal, evntRecPtr);
- return;
- }
-
- evntRec->m_request.setTableId(tablePtr.p->tableId);
-
- createEventComplete_RT_USER_GET(signal, evntRecPtr);
- return;
- }
- case CreateEvntReq::RT_USER_CREATE: {
- #ifdef EVENT_DEBUG
- printf("create type = %dn", CreateEvntReq::RT_USER_CREATE);
- #endif
- jam();
- createEventComplete_RT_USER_CREATE(signal, evntRecPtr);
- return;
- }
- break;
- default:
- ndbrequire(false);
- }
- } else { // returnCode != 0
- UtilExecuteRef * const ref = (UtilExecuteRef *)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = ref->getSenderData();
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- jam();
- evntRecPtr.p->m_errorNode = reference();
- evntRecPtr.p->m_errorLine = __LINE__;
- switch (ref->getErrorCode()) {
- case UtilExecuteRef::TCError:
- switch (ref->getTCErrorCode()) {
- case ZNOT_FOUND:
- jam();
- evntRecPtr.p->m_errorCode = CreateEvntRef::EventNotFound;
- break;
- case ZALREADYEXIST:
- jam();
- evntRecPtr.p->m_errorCode = CreateEvntRef::EventExists;
- break;
- default:
- jam();
- evntRecPtr.p->m_errorCode = CreateEvntRef::UndefinedTCError;
- break;
- }
- break;
- default:
- jam();
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- break;
- }
-
- createEvent_sendReply(signal, evntRecPtr);
- }
- }
- /***********************************************************************