Dbdict.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:368k
- *
- * NdbEventOperation, reading systable, creating event in suma
- *
- */
- void
- Dbdict::createEvent_RT_USER_GET(Signal* signal, OpCreateEventPtr evntRecPtr){
- jam();
- EVENT_TRACE;
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Coordinator) got GSN_CREATE_EVNT_REQ::RT_USER_GET evntRecPtr.i = (%d), ref = %u", evntRecPtr.i, evntRecPtr.p->m_request.getUserRef());
- #endif
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr, 0);
- SimplePropertiesSectionReader r0(ssPtr, getSectionSegmentPool());
- #ifdef EVENT_DEBUG
- r0.printAll(ndbout);
- #endif
- 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);
-
- releaseSections(signal);
-
- Callback c = { safe_cast(&Dbdict::createEventUTIL_PREPARE), 0 };
-
- prepareTransactionEventSysTable(&c, signal, evntRecPtr.i,
- UtilPrepareReq::Read);
- /*
- * Will read systable and fill an OpCreateEventPtr
- * and return below
- */
- }
- void
- Dbdict::createEventComplete_RT_USER_GET(Signal* signal,
- OpCreateEventPtr evntRecPtr){
- jam();
- // Send to oneself and the other DICT's
- CreateEvntReq * req = (CreateEvntReq *)signal->getDataPtrSend();
-
- *req = evntRecPtr.p->m_request;
- req->senderRef = reference();
- req->senderData = evntRecPtr.i;
-
- req->addRequestFlag(CreateEvntReq::RT_DICT_AFTER_GET);
-
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Coordinator) sending GSN_CREATE_EVNT_REQ::RT_DICT_AFTER_GET to DBDICT participants evntRecPtr.i = (%d)", evntRecPtr.i);
- #endif
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- RequestTracker & p = evntRecPtr.p->m_reqTracker;
- p.init<CreateEvntRef>(c_counterMgr, rg, GSN_CREATE_EVNT_REF, evntRecPtr.i);
- sendSignal(rg, GSN_CREATE_EVNT_REQ, signal, CreateEvntReq::SignalLength, JBB);
- }
- void
- Dbdict::createEvent_nodeFailCallback(Signal* signal, Uint32 eventRecPtrI,
- Uint32 returnCode){
- OpCreateEventPtr evntRecPtr;
- c_opCreateEvent.getPtr(evntRecPtr, eventRecPtrI);
- createEvent_sendReply(signal, evntRecPtr);
- }
- void Dbdict::execCREATE_EVNT_REF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- CreateEvntRef * const ref = (CreateEvntRef *)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = ref->getUserData();
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Coordinator) got GSN_CREATE_EVNT_REF evntRecPtr.i = (%d)", evntRecPtr.i);
- #endif
- if (ref->errorCode == CreateEvntRef::NF_FakeErrorREF){
- jam();
- evntRecPtr.p->m_reqTracker.ignoreRef(c_counterMgr, refToNode(ref->senderRef));
- } else {
- jam();
- evntRecPtr.p->m_reqTracker.reportRef(c_counterMgr, refToNode(ref->senderRef));
- }
- createEvent_sendReply(signal, evntRecPtr);
- return;
- }
- void Dbdict::execCREATE_EVNT_CONF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- CreateEvntConf * const conf = (CreateEvntConf *)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = conf->getUserData();
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Coordinator) got GSN_CREATE_EVNT_CONF evntRecPtr.i = (%d)", evntRecPtr.i);
- #endif
- evntRecPtr.p->m_reqTracker.reportConf(c_counterMgr, refToNode(conf->senderRef));
- // we will only have a valid tablename if it the master DICT sending this
- // but that's ok
- LinearSectionPtr ptr[1];
- ptr[0].p = (Uint32 *)evntRecPtr.p->m_eventRec.TABLE_NAME;
- ptr[0].sz =
- (strlen(evntRecPtr.p->m_eventRec.TABLE_NAME)+4)/4; // to make sure we have a null
- createEvent_sendReply(signal, evntRecPtr, ptr, 1);
-
- return;
- }
- /************************************************
- *
- * Participant stuff
- *
- */
- void
- Dbdict::createEvent_RT_DICT_AFTER_GET(Signal* signal, OpCreateEventPtr evntRecPtr){
- jam();
- evntRecPtr.p->m_request.setUserRef(signal->senderBlockRef());
-
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Participant) got CREATE_EVNT_REQ::RT_DICT_AFTER_GET evntRecPtr.i = (%d)", evntRecPtr.i);
- #endif
- // the signal comes from the DICT block that got the first user request!
- // This code runs on all DICT nodes, including oneself
- // Seize a Create Event record, the Coordinator will now have two seized
- // but that's ok, it's like a recursion
- SubCreateReq * sumaReq = (SubCreateReq *)signal->getDataPtrSend();
-
- sumaReq->subscriberRef = reference(); // reference to DICT
- sumaReq->subscriberData = evntRecPtr.i;
- sumaReq->subscriptionId = evntRecPtr.p->m_request.getEventId();
- sumaReq->subscriptionKey = evntRecPtr.p->m_request.getEventKey();
- sumaReq->subscriptionType = SubCreateReq::TableEvent;
- sumaReq->tableId = evntRecPtr.p->m_request.getTableId();
-
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("sending GSN_SUB_CREATE_REQ");
- #endif
- sendSignal(SUMA_REF, GSN_SUB_CREATE_REQ, signal,
- SubCreateReq::SignalLength+1 /*to get table Id*/, JBB);
- }
- void Dbdict::execSUB_CREATE_REF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- SubCreateRef * const ref = (SubCreateRef *)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = ref->subscriberData;
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Participant) got SUB_CREATE_REF evntRecPtr.i = (%d)", evntRecPtr.i);
- #endif
- if (ref->err == GrepError::SUBSCRIPTION_ID_NOT_UNIQUE) {
- jam();
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("SUBSCRIPTION_ID_NOT_UNIQUE");
- #endif
- createEvent_sendReply(signal, evntRecPtr);
- return;
- }
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("Other error");
- #endif
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
- createEvent_sendReply(signal, evntRecPtr);
- }
- void Dbdict::execSUB_CREATE_CONF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- SubCreateConf * const sumaConf = (SubCreateConf *)signal->getDataPtr();
- const Uint32 subscriptionId = sumaConf->subscriptionId;
- const Uint32 subscriptionKey = sumaConf->subscriptionKey;
- const Uint32 evntRecId = sumaConf->subscriberData;
- OpCreateEvent *evntRec;
- ndbrequire((evntRec = c_opCreateEvent.getPtr(evntRecId)) != NULL);
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT(Participant) got SUB_CREATE_CONF evntRecPtr.i = (%d)", evntRecId);
- #endif
- SubSyncReq *sumaSync = (SubSyncReq *)signal->getDataPtrSend();
- sumaSync->subscriptionId = subscriptionId;
- sumaSync->subscriptionKey = subscriptionKey;
- sumaSync->part = (Uint32) SubscriptionData::MetaData;
- sumaSync->subscriberData = evntRecId;
- sendSignal(SUMA_REF, GSN_SUB_SYNC_REQ, signal,
- SubSyncReq::SignalLength, JBB);
- }
- void Dbdict::execSUB_SYNC_REF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- SubSyncRef * const ref = (SubSyncRef *)signal->getDataPtr();
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = ref->subscriberData;
- 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::execSUB_SYNC_CONF(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- SubSyncConf * const sumaSyncConf = (SubSyncConf *)signal->getDataPtr();
- // Uint32 subscriptionId = sumaSyncConf->subscriptionId;
- // Uint32 subscriptionKey = sumaSyncConf->subscriptionKey;
- OpCreateEventPtr evntRecPtr;
- evntRecPtr.i = sumaSyncConf->subscriberData;
- ndbrequire((evntRecPtr.p = c_opCreateEvent.getPtr(evntRecPtr.i)) != NULL);
- ndbrequire(sumaSyncConf->part == (Uint32)SubscriptionData::MetaData);
- createEvent_sendReply(signal, evntRecPtr);
- }
- /****************************************************
- *
- * common create reply method
- *
- *******************************************************/
- void Dbdict::createEvent_sendReply(Signal* signal,
- OpCreateEventPtr evntRecPtr,
- LinearSectionPtr *ptr, int noLSP)
- {
- jam();
- EVENT_TRACE;
- // check if we're ready to sent reply
- // if we are the master dict we might be waiting for conf/ref
- if (!evntRecPtr.p->m_reqTracker.done()) {
- jam();
- return; // there's more to come
- }
- if (evntRecPtr.p->m_reqTracker.hasRef()) {
- ptr = NULL; // we don't want to return anything if there's an error
- if (!evntRecPtr.p->hasError()) {
- evntRecPtr.p->m_errorCode = CreateEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
- jam();
- } else
- jam();
- }
- // reference to API if master DICT
- // else reference to master DICT
- Uint32 senderRef = evntRecPtr.p->m_request.getUserRef();
- Uint32 signalLength;
- Uint32 gsn;
- if (evntRecPtr.p->hasError()) {
- jam();
- EVENT_TRACE;
- CreateEvntRef * ret = (CreateEvntRef *)signal->getDataPtrSend();
-
- ret->setEventId(evntRecPtr.p->m_request.getEventId());
- ret->setEventKey(evntRecPtr.p->m_request.getEventKey());
- ret->setUserData(evntRecPtr.p->m_request.getUserData());
- ret->senderRef = reference();
- ret->setTableId(evntRecPtr.p->m_request.getTableId());
- ret->setEventType(evntRecPtr.p->m_request.getEventType());
- ret->setRequestType(evntRecPtr.p->m_request.getRequestType());
- ret->setErrorCode(evntRecPtr.p->m_errorCode);
- ret->setErrorLine(evntRecPtr.p->m_errorLine);
- ret->setErrorNode(evntRecPtr.p->m_errorNode);
- signalLength = CreateEvntRef::SignalLength;
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT sending GSN_CREATE_EVNT_REF to evntRecPtr.i = (%d) node = %u ref = %u", evntRecPtr.i, refToNode(senderRef), senderRef);
- ndbout_c("errorCode = %u", evntRecPtr.p->m_errorCode);
- ndbout_c("errorLine = %u", evntRecPtr.p->m_errorLine);
- #endif
- gsn = GSN_CREATE_EVNT_REF;
- } else {
- jam();
- EVENT_TRACE;
- CreateEvntConf * evntConf = (CreateEvntConf *)signal->getDataPtrSend();
-
- evntConf->setEventId(evntRecPtr.p->m_request.getEventId());
- evntConf->setEventKey(evntRecPtr.p->m_request.getEventKey());
- evntConf->setUserData(evntRecPtr.p->m_request.getUserData());
- evntConf->senderRef = reference();
- evntConf->setTableId(evntRecPtr.p->m_request.getTableId());
- evntConf->setAttrListBitmask(evntRecPtr.p->m_request.getAttrListBitmask());
- evntConf->setEventType(evntRecPtr.p->m_request.getEventType());
- evntConf->setRequestType(evntRecPtr.p->m_request.getRequestType());
- signalLength = CreateEvntConf::SignalLength;
- #ifdef EVENT_PH2_DEBUG
- ndbout_c("DBDICT sending GSN_CREATE_EVNT_CONF to evntRecPtr.i = (%d) node = %u ref = %u", evntRecPtr.i, refToNode(senderRef), senderRef);
- #endif
- gsn = GSN_CREATE_EVNT_CONF;
- }
- if (ptr) {
- jam();
- sendSignal(senderRef, gsn, signal, signalLength, JBB, ptr, noLSP);
- } else {
- jam();
- sendSignal(senderRef, gsn, signal, signalLength, JBB);
- }
- c_opCreateEvent.release(evntRecPtr);
- }
- /*************************************************************/
- /********************************************************************
- *
- * Start event
- *
- *******************************************************************/
- void Dbdict::execSUB_START_REQ(Signal* signal)
- {
- jamEntry();
- Uint32 origSenderRef = signal->senderBlockRef();
- OpSubEventPtr subbPtr;
- if (!c_opSubEvent.seize(subbPtr)) {
- SubStartRef * ref = (SubStartRef *)signal->getDataPtrSend();
- { // fix
- Uint32 subcriberRef = ((SubStartReq*)signal->getDataPtr())->subscriberRef;
- ref->subscriberRef = subcriberRef;
- }
- jam();
- // ret->setErrorCode(SubStartRef::SeizeError);
- // ret->setErrorLine(__LINE__);
- // ret->setErrorNode(reference());
- ref->senderRef = reference();
- ref->setTemporary(SubStartRef::Busy);
- sendSignal(origSenderRef, GSN_SUB_START_REF, signal,
- SubStartRef::SignalLength2, JBB);
- return;
- }
- {
- const SubStartReq* req = (SubStartReq*) signal->getDataPtr();
- subbPtr.p->m_senderRef = req->senderRef;
- subbPtr.p->m_senderData = req->senderData;
- subbPtr.p->m_errorCode = 0;
- }
-
- if (refToBlock(origSenderRef) != DBDICT) {
- /*
- * Coordinator
- */
- jam();
-
- subbPtr.p->m_senderRef = origSenderRef; // not sure if API sets correctly
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- RequestTracker & p = subbPtr.p->m_reqTracker;
- p.init<SubStartRef>(c_counterMgr, rg, GSN_SUB_START_REF, subbPtr.i);
-
- SubStartReq* req = (SubStartReq*) signal->getDataPtrSend();
-
- req->senderRef = reference();
- req->senderData = subbPtr.i;
-
- #ifdef EVENT_PH3_DEBUG
- ndbout_c("DBDICT(Coordinator) sending GSN_SUB_START_REQ to DBDICT participants subbPtr.i = (%d)", subbPtr.i);
- #endif
- sendSignal(rg, GSN_SUB_START_REQ, signal, SubStartReq::SignalLength2, JBB);
- return;
- }
- /*
- * Participant
- */
- ndbrequire(refToBlock(origSenderRef) == DBDICT);
-
- {
- SubStartReq* req = (SubStartReq*) signal->getDataPtrSend();
-
- req->senderRef = reference();
- req->senderData = subbPtr.i;
-
- #ifdef EVENT_PH3_DEBUG
- ndbout_c("DBDICT(Participant) sending GSN_SUB_START_REQ to SUMA subbPtr.i = (%d)", subbPtr.i);
- #endif
- sendSignal(SUMA_REF, GSN_SUB_START_REQ, signal, SubStartReq::SignalLength2, JBB);
- }
- }
- void Dbdict::execSUB_START_REF(Signal* signal)
- {
- jamEntry();
- const SubStartRef* ref = (SubStartRef*) signal->getDataPtr();
- Uint32 senderRef = ref->senderRef;
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, ref->senderData);
- if (refToBlock(senderRef) == SUMA) {
- /*
- * Participant
- */
- jam();
- #ifdef EVENT_PH3_DEBUG
- ndbout_c("DBDICT(Participant) got GSN_SUB_START_REF = (%d)", subbPtr.i);
- #endif
- if (ref->isTemporary()){
- jam();
- SubStartReq* req = (SubStartReq*)signal->getDataPtrSend();
- { // fix
- Uint32 subscriberRef = ref->subscriberRef;
- req->subscriberRef = subscriberRef;
- }
- req->senderRef = reference();
- req->senderData = subbPtr.i;
- sendSignal(SUMA_REF, GSN_SUB_START_REQ,
- signal, SubStartReq::SignalLength2, JBB);
- } else {
- jam();
- SubStartRef* ref = (SubStartRef*) signal->getDataPtrSend();
- ref->senderRef = reference();
- ref->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_START_REF,
- signal, SubStartRef::SignalLength2, JBB);
- c_opSubEvent.release(subbPtr);
- }
- return;
- }
- /*
- * Coordinator
- */
- ndbrequire(refToBlock(senderRef) == DBDICT);
- #ifdef EVENT_PH3_DEBUG
- ndbout_c("DBDICT(Coordinator) got GSN_SUB_START_REF = (%d)", subbPtr.i);
- #endif
- if (ref->errorCode == SubStartRef::NF_FakeErrorREF){
- jam();
- subbPtr.p->m_reqTracker.ignoreRef(c_counterMgr, refToNode(senderRef));
- } else {
- jam();
- subbPtr.p->m_reqTracker.reportRef(c_counterMgr, refToNode(senderRef));
- }
- completeSubStartReq(signal,subbPtr.i,0);
- }
- void Dbdict::execSUB_START_CONF(Signal* signal)
- {
- jamEntry();
- const SubStartConf* conf = (SubStartConf*) signal->getDataPtr();
- Uint32 senderRef = conf->senderRef;
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, conf->senderData);
- if (refToBlock(senderRef) == SUMA) {
- /*
- * Participant
- */
- jam();
- SubStartConf* conf = (SubStartConf*) signal->getDataPtrSend();
- #ifdef EVENT_PH3_DEBUG
- ndbout_c("DBDICT(Participant) got GSN_SUB_START_CONF = (%d)", subbPtr.i);
- #endif
- conf->senderRef = reference();
- conf->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_START_CONF,
- signal, SubStartConf::SignalLength2, JBB);
- c_opSubEvent.release(subbPtr);
- return;
- }
- /*
- * Coordinator
- */
- ndbrequire(refToBlock(senderRef) == DBDICT);
- #ifdef EVENT_PH3_DEBUG
- ndbout_c("DBDICT(Coordinator) got GSN_SUB_START_CONF = (%d)", subbPtr.i);
- #endif
- subbPtr.p->m_reqTracker.reportConf(c_counterMgr, refToNode(senderRef));
- completeSubStartReq(signal,subbPtr.i,0);
- }
- /*
- * Coordinator
- */
- void Dbdict::completeSubStartReq(Signal* signal,
- Uint32 ptrI,
- Uint32 returnCode){
- jam();
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, ptrI);
- if (!subbPtr.p->m_reqTracker.done()){
- jam();
- return;
- }
- if (subbPtr.p->m_reqTracker.hasRef()) {
- jam();
- #ifdef EVENT_DEBUG
- ndbout_c("SUB_START_REF");
- #endif
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_START_REF,
- signal, SubStartRef::SignalLength, JBB);
- if (subbPtr.p->m_reqTracker.hasConf()) {
- // stopStartedNodes(signal);
- }
- c_opSubEvent.release(subbPtr);
- return;
- }
- #ifdef EVENT_DEBUG
- ndbout_c("SUB_START_CONF");
- #endif
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_START_CONF,
- signal, SubStartConf::SignalLength, JBB);
- c_opSubEvent.release(subbPtr);
- }
- /********************************************************************
- *
- * Stop event
- *
- *******************************************************************/
- void Dbdict::execSUB_STOP_REQ(Signal* signal)
- {
- jamEntry();
- Uint32 origSenderRef = signal->senderBlockRef();
- OpSubEventPtr subbPtr;
- if (!c_opSubEvent.seize(subbPtr)) {
- SubStopRef * ref = (SubStopRef *)signal->getDataPtrSend();
- jam();
- // ret->setErrorCode(SubStartRef::SeizeError);
- // ret->setErrorLine(__LINE__);
- // ret->setErrorNode(reference());
- ref->senderRef = reference();
- ref->setTemporary(SubStopRef::Busy);
- sendSignal(origSenderRef, GSN_SUB_STOP_REF, signal,
- SubStopRef::SignalLength, JBB);
- return;
- }
- {
- const SubStopReq* req = (SubStopReq*) signal->getDataPtr();
- subbPtr.p->m_senderRef = req->senderRef;
- subbPtr.p->m_senderData = req->senderData;
- subbPtr.p->m_errorCode = 0;
- }
-
- if (refToBlock(origSenderRef) != DBDICT) {
- /*
- * Coordinator
- */
- jam();
- #ifdef EVENT_DEBUG
- ndbout_c("SUB_STOP_REQ 1");
- #endif
- subbPtr.p->m_senderRef = origSenderRef; // not sure if API sets correctly
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- RequestTracker & p = subbPtr.p->m_reqTracker;
- p.init<SubStopRef>(c_counterMgr, rg, GSN_SUB_STOP_REF, subbPtr.i);
- SubStopReq* req = (SubStopReq*) signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = subbPtr.i;
-
- sendSignal(rg, GSN_SUB_STOP_REQ, signal, SubStopReq::SignalLength, JBB);
- return;
- }
- /*
- * Participant
- */
- #ifdef EVENT_DEBUG
- ndbout_c("SUB_STOP_REQ 2");
- #endif
- ndbrequire(refToBlock(origSenderRef) == DBDICT);
- {
- SubStopReq* req = (SubStopReq*) signal->getDataPtrSend();
-
- req->senderRef = reference();
- req->senderData = subbPtr.i;
-
- sendSignal(SUMA_REF, GSN_SUB_STOP_REQ, signal, SubStopReq::SignalLength, JBB);
- }
- }
- void Dbdict::execSUB_STOP_REF(Signal* signal)
- {
- jamEntry();
- const SubStopRef* ref = (SubStopRef*) signal->getDataPtr();
- Uint32 senderRef = ref->senderRef;
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, ref->senderData);
- if (refToBlock(senderRef) == SUMA) {
- /*
- * Participant
- */
- jam();
- if (ref->isTemporary()){
- jam();
- SubStopReq* req = (SubStopReq*)signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = subbPtr.i;
- sendSignal(SUMA_REF, GSN_SUB_STOP_REQ,
- signal, SubStopReq::SignalLength, JBB);
- } else {
- jam();
- SubStopRef* ref = (SubStopRef*) signal->getDataPtrSend();
- ref->senderRef = reference();
- ref->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_STOP_REF,
- signal, SubStopRef::SignalLength, JBB);
- c_opSubEvent.release(subbPtr);
- }
- return;
- }
- /*
- * Coordinator
- */
- ndbrequire(refToBlock(senderRef) == DBDICT);
- if (ref->errorCode == SubStopRef::NF_FakeErrorREF){
- jam();
- subbPtr.p->m_reqTracker.ignoreRef(c_counterMgr, refToNode(senderRef));
- } else {
- jam();
- subbPtr.p->m_reqTracker.reportRef(c_counterMgr, refToNode(senderRef));
- }
- completeSubStopReq(signal,subbPtr.i,0);
- }
- void Dbdict::execSUB_STOP_CONF(Signal* signal)
- {
- jamEntry();
- const SubStopConf* conf = (SubStopConf*) signal->getDataPtr();
- Uint32 senderRef = conf->senderRef;
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, conf->senderData);
- if (refToBlock(senderRef) == SUMA) {
- /*
- * Participant
- */
- jam();
- SubStopConf* conf = (SubStopConf*) signal->getDataPtrSend();
- conf->senderRef = reference();
- conf->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_STOP_CONF,
- signal, SubStopConf::SignalLength, JBB);
- c_opSubEvent.release(subbPtr);
- return;
- }
- /*
- * Coordinator
- */
- ndbrequire(refToBlock(senderRef) == DBDICT);
- subbPtr.p->m_reqTracker.reportConf(c_counterMgr, refToNode(senderRef));
- completeSubStopReq(signal,subbPtr.i,0);
- }
- /*
- * Coordinator
- */
- void Dbdict::completeSubStopReq(Signal* signal,
- Uint32 ptrI,
- Uint32 returnCode){
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, ptrI);
- if (!subbPtr.p->m_reqTracker.done()){
- jam();
- return;
- }
- if (subbPtr.p->m_reqTracker.hasRef()) {
- jam();
- #ifdef EVENT_DEBUG
- ndbout_c("SUB_STOP_REF");
- #endif
- SubStopRef* ref = (SubStopRef*)signal->getDataPtrSend();
- ref->senderRef = reference();
- ref->senderData = subbPtr.p->m_senderData;
- /*
- ref->subscriptionId = subbPtr.p->m_senderData;
- ref->subscriptionKey = subbPtr.p->m_senderData;
- ref->part = subbPtr.p->m_part; // SubscriptionData::Part
- ref->subscriberData = subbPtr.p->m_subscriberData;
- ref->subscriberRef = subbPtr.p->m_subscriberRef;
- */
- ref->errorCode = subbPtr.p->m_errorCode;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_STOP_REF,
- signal, SubStopRef::SignalLength, JBB);
- if (subbPtr.p->m_reqTracker.hasConf()) {
- // stopStartedNodes(signal);
- }
- c_opSubEvent.release(subbPtr);
- return;
- }
- #ifdef EVENT_DEBUG
- ndbout_c("SUB_STOP_CONF");
- #endif
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_STOP_CONF,
- signal, SubStopConf::SignalLength, JBB);
- c_opSubEvent.release(subbPtr);
- }
- /***************************************************************
- * MODULE: Drop event.
- *
- * Drop event.
- *
- * TODO
- */
- void
- Dbdict::execDROP_EVNT_REQ(Signal* signal)
- {
- jamEntry();
- EVENT_TRACE;
- DropEvntReq *req = (DropEvntReq*)signal->getDataPtr();
- const Uint32 senderRef = signal->senderBlockRef();
- OpDropEventPtr evntRecPtr;
- // Seize a Create Event record
- if (!c_opDropEvent.seize(evntRecPtr)) {
- // Failed to allocate event record
- jam();
- releaseSections(signal);
-
- DropEvntRef * ret = (DropEvntRef *)signal->getDataPtrSend();
- ret->setErrorCode(DropEvntRef::SeizeError);
- ret->setErrorLine(__LINE__);
- ret->setErrorNode(reference());
- sendSignal(senderRef, GSN_DROP_EVNT_REF, signal,
- DropEvntRef::SignalLength, JBB);
- return;
- }
- #ifdef EVENT_DEBUG
- ndbout_c("DBDICT::execDROP_EVNT_REQ evntRecId = (%d)", evntRecPtr.i);
- #endif
- OpDropEvent* evntRec = evntRecPtr.p;
- evntRec->init(req);
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr, 0);
- 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 = DropEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorNode = reference();
- dropEvent_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("DropEvntReq; 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
- }
-
- releaseSections(signal);
- Callback c = { safe_cast(&Dbdict::dropEventUTIL_PREPARE_READ), 0 };
- prepareTransactionEventSysTable(&c, signal, evntRecPtr.i,
- UtilPrepareReq::Read);
- }
- void
- Dbdict::dropEventUTIL_PREPARE_READ(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- if (returnCode != 0) {
- EVENT_TRACE;
- dropEventUtilPrepareRef(signal, callbackData, returnCode);
- return;
- }
- UtilPrepareConf* const req = (UtilPrepareConf*)signal->getDataPtr();
- OpDropEventPtr evntRecPtr;
- evntRecPtr.i = req->getSenderData();
- const Uint32 prepareId = req->getPrepareId();
- ndbrequire((evntRecPtr.p = c_opDropEvent.getPtr(evntRecPtr.i)) != NULL);
- Callback c = { safe_cast(&Dbdict::dropEventUTIL_EXECUTE_READ), 0 };
- executeTransEventSysTable(&c, signal,
- evntRecPtr.i, evntRecPtr.p->m_eventRec,
- prepareId, UtilPrepareReq::Read);
- }
- void
- Dbdict::dropEventUTIL_EXECUTE_READ(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- if (returnCode != 0) {
- EVENT_TRACE;
- dropEventUtilExecuteRef(signal, callbackData, returnCode);
- return;
- }
- OpDropEventPtr evntRecPtr;
- UtilExecuteConf * const ref = (UtilExecuteConf *)signal->getDataPtr();
- jam();
- evntRecPtr.i = ref->getSenderData();
- ndbrequire((evntRecPtr.p = c_opDropEvent.getPtr(evntRecPtr.i)) != NULL);
- parseReadEventSys(signal, evntRecPtr.p->m_eventRec);
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- RequestTracker & p = evntRecPtr.p->m_reqTracker;
- p.init<SubRemoveRef>(c_counterMgr, rg, GSN_SUB_REMOVE_REF,
- evntRecPtr.i);
- SubRemoveReq* req = (SubRemoveReq*) signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = evntRecPtr.i;
- req->subscriptionId = evntRecPtr.p->m_eventRec.SUBID;
- req->subscriptionKey = evntRecPtr.p->m_eventRec.SUBKEY;
- sendSignal(rg, GSN_SUB_REMOVE_REQ, signal, SubRemoveReq::SignalLength, JBB);
- }
- /*
- * Participant
- */
- void
- Dbdict::execSUB_REMOVE_REQ(Signal* signal)
- {
- jamEntry();
- Uint32 origSenderRef = signal->senderBlockRef();
- OpSubEventPtr subbPtr;
- if (!c_opSubEvent.seize(subbPtr)) {
- SubRemoveRef * ref = (SubRemoveRef *)signal->getDataPtrSend();
- jam();
- ref->senderRef = reference();
- ref->setTemporary(SubRemoveRef::Busy);
- sendSignal(origSenderRef, GSN_SUB_REMOVE_REF, signal,
- SubRemoveRef::SignalLength, JBB);
- return;
- }
- {
- const SubRemoveReq* req = (SubRemoveReq*) signal->getDataPtr();
- subbPtr.p->m_senderRef = req->senderRef;
- subbPtr.p->m_senderData = req->senderData;
- subbPtr.p->m_errorCode = 0;
- }
- SubRemoveReq* req = (SubRemoveReq*) signal->getDataPtrSend();
- req->senderRef = reference();
- req->senderData = subbPtr.i;
- sendSignal(SUMA_REF, GSN_SUB_REMOVE_REQ, signal, SubRemoveReq::SignalLength, JBB);
- }
- /*
- * Coordintor/Participant
- */
- void
- Dbdict::execSUB_REMOVE_REF(Signal* signal)
- {
- jamEntry();
- const SubRemoveRef* ref = (SubRemoveRef*) signal->getDataPtr();
- Uint32 senderRef = ref->senderRef;
- if (refToBlock(senderRef) == SUMA) {
- /*
- * Participant
- */
- jam();
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, ref->senderData);
- if (ref->errorCode == (Uint32) GrepError::SUBSCRIPTION_ID_NOT_FOUND) {
- // conf this since this may occur if a nodefailiure has occured
- // earlier so that the systable was not cleared
- SubRemoveConf* conf = (SubRemoveConf*) signal->getDataPtrSend();
- conf->senderRef = reference();
- conf->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_REMOVE_CONF,
- signal, SubRemoveConf::SignalLength, JBB);
- } else {
- SubRemoveRef* ref = (SubRemoveRef*) signal->getDataPtrSend();
- ref->senderRef = reference();
- ref->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_REMOVE_REF,
- signal, SubRemoveRef::SignalLength, JBB);
- }
- c_opSubEvent.release(subbPtr);
- return;
- }
- /*
- * Coordinator
- */
- ndbrequire(refToBlock(senderRef) == DBDICT);
- OpDropEventPtr eventRecPtr;
- c_opDropEvent.getPtr(eventRecPtr, ref->senderData);
- if (ref->errorCode == SubRemoveRef::NF_FakeErrorREF){
- jam();
- eventRecPtr.p->m_reqTracker.ignoreRef(c_counterMgr, refToNode(senderRef));
- } else {
- jam();
- eventRecPtr.p->m_reqTracker.reportRef(c_counterMgr, refToNode(senderRef));
- }
- completeSubRemoveReq(signal,eventRecPtr.i,0);
- }
- void
- Dbdict::execSUB_REMOVE_CONF(Signal* signal)
- {
- jamEntry();
- const SubRemoveConf* conf = (SubRemoveConf*) signal->getDataPtr();
- Uint32 senderRef = conf->senderRef;
- if (refToBlock(senderRef) == SUMA) {
- /*
- * Participant
- */
- jam();
- OpSubEventPtr subbPtr;
- c_opSubEvent.getPtr(subbPtr, conf->senderData);
- SubRemoveConf* conf = (SubRemoveConf*) signal->getDataPtrSend();
- conf->senderRef = reference();
- conf->senderData = subbPtr.p->m_senderData;
- sendSignal(subbPtr.p->m_senderRef, GSN_SUB_REMOVE_CONF,
- signal, SubRemoveConf::SignalLength, JBB);
- c_opSubEvent.release(subbPtr);
- return;
- }
- /*
- * Coordinator
- */
- ndbrequire(refToBlock(senderRef) == DBDICT);
- OpDropEventPtr eventRecPtr;
- c_opDropEvent.getPtr(eventRecPtr, conf->senderData);
- eventRecPtr.p->m_reqTracker.reportConf(c_counterMgr, refToNode(senderRef));
- completeSubRemoveReq(signal,eventRecPtr.i,0);
- }
- void
- Dbdict::completeSubRemoveReq(Signal* signal, Uint32 ptrI, Uint32 xxx)
- {
- OpDropEventPtr evntRecPtr;
- c_opDropEvent.getPtr(evntRecPtr, ptrI);
- if (!evntRecPtr.p->m_reqTracker.done()){
- jam();
- return;
- }
- if (evntRecPtr.p->m_reqTracker.hasRef()) {
- jam();
- evntRecPtr.p->m_errorNode = reference();
- evntRecPtr.p->m_errorLine = __LINE__;
- evntRecPtr.p->m_errorCode = DropEvntRef::Undefined;
- dropEvent_sendReply(signal, evntRecPtr);
- return;
- }
- Callback c = { safe_cast(&Dbdict::dropEventUTIL_PREPARE_DELETE), 0 };
- prepareTransactionEventSysTable(&c, signal, evntRecPtr.i,
- UtilPrepareReq::Delete);
- }
- void
- Dbdict::dropEventUTIL_PREPARE_DELETE(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- if (returnCode != 0) {
- EVENT_TRACE;
- dropEventUtilPrepareRef(signal, callbackData, returnCode);
- return;
- }
- UtilPrepareConf* const req = (UtilPrepareConf*)signal->getDataPtr();
- OpDropEventPtr evntRecPtr;
- jam();
- evntRecPtr.i = req->getSenderData();
- const Uint32 prepareId = req->getPrepareId();
-
- ndbrequire((evntRecPtr.p = c_opDropEvent.getPtr(evntRecPtr.i)) != NULL);
- #ifdef EVENT_DEBUG
- printf("DropEvntUTIL_PREPARE; evntRecPtr.i len %un",evntRecPtr.i);
- #endif
- Callback c = { safe_cast(&Dbdict::dropEventUTIL_EXECUTE_DELETE), 0 };
- executeTransEventSysTable(&c, signal,
- evntRecPtr.i, evntRecPtr.p->m_eventRec,
- prepareId, UtilPrepareReq::Delete);
- }
- void
- Dbdict::dropEventUTIL_EXECUTE_DELETE(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- if (returnCode != 0) {
- EVENT_TRACE;
- dropEventUtilExecuteRef(signal, callbackData, returnCode);
- return;
- }
- OpDropEventPtr evntRecPtr;
- UtilExecuteConf * const ref = (UtilExecuteConf *)signal->getDataPtr();
- jam();
- evntRecPtr.i = ref->getSenderData();
- ndbrequire((evntRecPtr.p = c_opDropEvent.getPtr(evntRecPtr.i)) != NULL);
- dropEvent_sendReply(signal, evntRecPtr);
- }
- void
- Dbdict::dropEventUtilPrepareRef(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- UtilPrepareRef * const ref = (UtilPrepareRef *)signal->getDataPtr();
- OpDropEventPtr evntRecPtr;
- evntRecPtr.i = ref->getSenderData();
- ndbrequire((evntRecPtr.p = c_opDropEvent.getPtr(evntRecPtr.i)) != NULL);
- bool temporary = false;
- interpretUtilPrepareErrorCode((UtilPrepareRef::ErrorCode)ref->getErrorCode(),
- temporary, evntRecPtr.p->m_errorLine);
- if (temporary) {
- evntRecPtr.p->m_errorCode = (DropEvntRef::ErrorCode)
- ((Uint32) DropEvntRef::Undefined | (Uint32) DropEvntRef::Temporary);
- }
- if (evntRecPtr.p->m_errorCode == 0) {
- evntRecPtr.p->m_errorCode = DropEvntRef::Undefined;
- evntRecPtr.p->m_errorLine = __LINE__;
- }
- evntRecPtr.p->m_errorNode = reference();
- dropEvent_sendReply(signal, evntRecPtr);
- }
- void
- Dbdict::dropEventUtilExecuteRef(Signal* signal,
- Uint32 callbackData,
- Uint32 returnCode)
- {
- jam();
- EVENT_TRACE;
- OpDropEventPtr evntRecPtr;
- UtilExecuteRef * const ref = (UtilExecuteRef *)signal->getDataPtr();
- jam();
- evntRecPtr.i = ref->getSenderData();
- ndbrequire((evntRecPtr.p = c_opDropEvent.getPtr(evntRecPtr.i)) != NULL);
-
- 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 = DropEvntRef::EventNotFound;
- break;
- default:
- jam();
- evntRecPtr.p->m_errorCode = DropEvntRef::UndefinedTCError;
- break;
- }
- break;
- default:
- jam();
- evntRecPtr.p->m_errorCode = DropEvntRef::Undefined;
- break;
- }
- dropEvent_sendReply(signal, evntRecPtr);
- }
- void Dbdict::dropEvent_sendReply(Signal* signal,
- OpDropEventPtr evntRecPtr)
- {
- jam();
- EVENT_TRACE;
- Uint32 senderRef = evntRecPtr.p->m_request.getUserRef();
- if (evntRecPtr.p->hasError()) {
- jam();
- DropEvntRef * ret = (DropEvntRef *)signal->getDataPtrSend();
-
- ret->setUserData(evntRecPtr.p->m_request.getUserData());
- ret->setUserRef(evntRecPtr.p->m_request.getUserRef());
- ret->setErrorCode(evntRecPtr.p->m_errorCode);
- ret->setErrorLine(evntRecPtr.p->m_errorLine);
- ret->setErrorNode(evntRecPtr.p->m_errorNode);
- sendSignal(senderRef, GSN_DROP_EVNT_REF, signal,
- DropEvntRef::SignalLength, JBB);
- } else {
- jam();
- DropEvntConf * evntConf = (DropEvntConf *)signal->getDataPtrSend();
-
- evntConf->setUserData(evntRecPtr.p->m_request.getUserData());
- evntConf->setUserRef(evntRecPtr.p->m_request.getUserRef());
- sendSignal(senderRef, GSN_DROP_EVNT_CONF, signal,
- DropEvntConf::SignalLength, JBB);
- }
- c_opDropEvent.release(evntRecPtr);
- }
- /**
- * MODULE: Alter index
- *
- * Alter index state. Alter online creates the index in each TC and
- * then invokes create trigger and alter trigger protocols to activate
- * the 3 triggers. Alter offline does the opposite.
- *
- * Request type received in REQ and returned in CONF/REF:
- *
- * RT_USER - from API to DICT master
- * RT_CREATE_INDEX - part of create index operation
- * RT_DROP_INDEX - part of drop index operation
- * RT_NODERESTART - node restart, activate locally only
- * RT_SYSTEMRESTART - system restart, activate and build if not logged
- * RT_DICT_PREPARE - prepare participants
- * RT_DICT_TC - to local TC via each participant
- * RT_DICT_COMMIT - commit in each participant
- */
- void
- Dbdict::execALTER_INDX_REQ(Signal* signal)
- {
- jamEntry();
- AlterIndxReq* const req = (AlterIndxReq*)signal->getDataPtrSend();
- OpAlterIndexPtr opPtr;
- const Uint32 senderRef = signal->senderBlockRef();
- const AlterIndxReq::RequestType requestType = req->getRequestType();
- if (requestType == AlterIndxReq::RT_USER ||
- requestType == AlterIndxReq::RT_CREATE_INDEX ||
- requestType == AlterIndxReq::RT_DROP_INDEX ||
- requestType == AlterIndxReq::RT_NODERESTART ||
- requestType == AlterIndxReq::RT_SYSTEMRESTART) {
- jam();
- const bool isLocal = req->getRequestFlag() & RequestFlag::RF_LOCAL;
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (isLocal) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- }
- if (signal->getLength() == AlterIndxReq::SignalLength) {
- jam();
- if (! isLocal && getOwnNodeId() != c_masterNodeId) {
- jam();
- releaseSections(signal);
- OpAlterIndex opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = AlterIndxRef::NotMaster;
- opPtr.p->m_errorLine = __LINE__;
- opPtr.p->m_errorNode = c_masterNodeId;
- alterIndex_sendReply(signal, opPtr, true);
- return;
- }
- // forward initial request plus operation key to all
- req->setOpKey(++c_opRecordSequence);
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_ALTER_INDX_REQ,
- signal, AlterIndxReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == AlterIndxReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpAlterIndex opBusy;
- if (! c_opAlterIndex.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 = AlterIndxReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = AlterIndxRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- alterIndex_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opAlterIndex.add(opPtr);
- // master expects to hear from all
- if (opPtr.p->m_isMaster)
- opPtr.p->m_signalCounter = receiverNodes;
- // check request in all participants
- alterIndex_slavePrepare(signal, opPtr);
- alterIndex_sendReply(signal, opPtr, false);
- return;
- }
- c_opAlterIndex.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == AlterIndxReq::RT_DICT_TC) {
- jam();
- if (opPtr.p->m_request.getOnline())
- alterIndex_toCreateTc(signal, opPtr);
- else
- alterIndex_toDropTc(signal, opPtr);
- return;
- }
- if (requestType == AlterIndxReq::RT_DICT_COMMIT ||
- requestType == AlterIndxReq::RT_DICT_ABORT) {
- jam();
- if (requestType == AlterIndxReq::RT_DICT_COMMIT)
- alterIndex_slaveCommit(signal, opPtr);
- else
- alterIndex_slaveAbort(signal, opPtr);
- alterIndex_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opAlterIndex.release(opPtr);
- return;
- }
- }
- jam();
- // return to sender
- OpAlterIndex opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = AlterIndxRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- alterIndex_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::execALTER_INDX_CONF(Signal* signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 0);
- AlterIndxConf* conf = (AlterIndxConf*)signal->getDataPtrSend();
- alterIndex_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execALTER_INDX_REF(Signal* signal)
- {
- jamEntry();
- AlterIndxRef* ref = (AlterIndxRef*)signal->getDataPtrSend();
- alterIndex_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::alterIndex_recvReply(Signal* signal, const AlterIndxConf* conf,
- const AlterIndxRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const AlterIndxReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == AlterIndxReq::RT_CREATE_INDEX) {
- jam();
- // part of create index operation
- OpCreateIndexPtr opPtr;
- c_opCreateIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- createIndex_fromAlterIndex(signal, opPtr);
- return;
- }
- if (requestType == AlterIndxReq::RT_DROP_INDEX) {
- jam();
- // part of drop index operation
- OpDropIndexPtr opPtr;
- c_opDropIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- dropIndex_fromAlterIndex(signal, opPtr);
- return;
- }
- if (requestType == AlterIndxReq::RT_TC ||
- requestType == AlterIndxReq::RT_TUX) {
- jam();
- // part of build index operation
- OpBuildIndexPtr opPtr;
- c_opBuildIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- buildIndex_fromOnline(signal, opPtr);
- return;
- }
- if (requestType == AlterIndxReq::RT_NODERESTART) {
- jam();
- if (ref == 0) {
- infoEvent("DICT: index %u activated", (unsigned)key);
- } else {
- warningEvent("DICT: index %u activation failed: code=%d line=%d",
- (unsigned)key,
- ref->getErrorCode(), ref->getErrorLine());
- }
- activateIndexes(signal, key + 1);
- return;
- }
- if (requestType == AlterIndxReq::RT_SYSTEMRESTART) {
- jam();
- if (ref == 0) {
- infoEvent("DICT: index %u activated done", (unsigned)key);
- } else {
- warningEvent("DICT: index %u activated failed: code=%d line=%d node=%d",
- (unsigned)key,
- ref->getErrorCode(), ref->getErrorLine(), ref->getErrorNode());
- }
- activateIndexes(signal, key + 1);
- return;
- }
- OpAlterIndexPtr opPtr;
- c_opAlterIndex.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 == AlterIndxReq::RT_DICT_COMMIT ||
- requestType == AlterIndxReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- alterIndex_sendReply(signal, opPtr, true);
- c_opAlterIndex.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_ABORT;
- alterIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- if (indexPtr.p->isHashIndex()) {
- if (requestType == AlterIndxReq::RT_DICT_PREPARE) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_TC;
- alterIndex_sendSlaveReq(signal, opPtr);
- } else {
- // start drop triggers
- alterIndex_toDropTrigger(signal, opPtr);
- }
- return;
- }
- if (requestType == AlterIndxReq::RT_DICT_TC) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- // start create triggers
- alterIndex_toCreateTrigger(signal, opPtr);
- } else {
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_COMMIT;
- alterIndex_sendSlaveReq(signal, opPtr);
- }
- return;
- }
- }
- if (indexPtr.p->isOrderedIndex()) {
- if (requestType == AlterIndxReq::RT_DICT_PREPARE) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- // start create triggers
- alterIndex_toCreateTrigger(signal, opPtr);
- } else {
- // start drop triggers
- alterIndex_toDropTrigger(signal, opPtr);
- }
- return;
- }
- }
- ndbrequire(false);
- }
- void
- Dbdict::alterIndex_slavePrepare(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- const AlterIndxReq* const req = &opPtr.p->m_request;
- if (! (req->getIndexId() < c_tableRecordPool.getSize())) {
- jam();
- opPtr.p->m_errorCode = AlterIndxRef::Inconsistency;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, req->getIndexId());
- if (indexPtr.p->tabState != TableRecord::DEFINED) {
- jam();
- opPtr.p->m_errorCode = AlterIndxRef::IndexNotFound;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (! indexPtr.p->isIndex()) {
- jam();
- opPtr.p->m_errorCode = AlterIndxRef::NotAnIndex;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (req->getOnline())
- indexPtr.p->indexState = TableRecord::IS_BUILDING;
- else
- indexPtr.p->indexState = TableRecord::IS_DROPPING;
- }
- void
- Dbdict::alterIndex_toCreateTc(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- // request to create index in local TC
- CreateIndxReq* const req = (CreateIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(CreateIndxReq::RT_TC);
- req->setIndexType(indexPtr.p->tableType);
- req->setTableId(indexPtr.p->primaryTableId);
- req->setIndexId(indexPtr.i);
- req->setOnline(true);
- getIndexAttrList(indexPtr, opPtr.p->m_attrList);
- // send
- LinearSectionPtr lsPtr[3];
- lsPtr[0].p = (Uint32*)&opPtr.p->m_attrList;
- lsPtr[0].sz = 1 + opPtr.p->m_attrList.sz;
- sendSignal(calcTcBlockRef(getOwnNodeId()), GSN_CREATE_INDX_REQ,
- signal, CreateIndxReq::SignalLength, JBB, lsPtr, 1);
- }
- void
- Dbdict::alterIndex_fromCreateTc(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- // mark created in local TC
- if (! opPtr.p->hasLastError()) {
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- indexPtr.p->indexLocal |= TableRecord::IL_CREATED_TC;
- }
- // forward CONF or REF to master
- ndbrequire(opPtr.p->m_requestType == AlterIndxReq::RT_DICT_TC);
- alterIndex_sendReply(signal, opPtr, false);
- }
- void
- Dbdict::alterIndex_toDropTc(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- // broken index allowed if force
- if (! (indexPtr.p->indexLocal & TableRecord::IL_CREATED_TC)) {
- jam();
- ndbrequire(opPtr.p->m_requestFlag & RequestFlag::RF_FORCE);
- alterIndex_sendReply(signal, opPtr, false);
- return;
- }
- // request to drop in local TC
- DropIndxReq* const req = (DropIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(DropIndxReq::RT_TC);
- req->setTableId(indexPtr.p->primaryTableId);
- req->setIndexId(indexPtr.i);
- req->setIndexVersion(indexPtr.p->tableVersion);
- // send
- sendSignal(calcTcBlockRef(getOwnNodeId()), GSN_DROP_INDX_REQ,
- signal, DropIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::alterIndex_fromDropTc(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- ndbrequire(opPtr.p->m_requestType == AlterIndxReq::RT_DICT_TC);
- // mark dropped locally
- if (! opPtr.p->hasLastError()) {
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- indexPtr.p->indexLocal &= ~TableRecord::IL_CREATED_TC;
- }
- // forward CONF or REF to master
- alterIndex_sendReply(signal, opPtr, false);
- }
- void
- Dbdict::alterIndex_toCreateTrigger(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- // start creation of index triggers
- CreateTrigReq* const req = (CreateTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(CreateTrigReq::RT_ALTER_INDEX);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setTableId(opPtr.p->m_request.getTableId());
- req->setIndexId(opPtr.p->m_request.getIndexId());
- req->setTriggerId(RNIL);
- req->setTriggerActionTime(TriggerActionTime::TA_AFTER);
- req->setMonitorAllAttributes(false);
- req->setOnline(true); // alter online after create
- req->setReceiverRef(0); // implicit for index triggers
- getIndexAttrMask(indexPtr, req->getAttributeMask());
- // name section
- char triggerName[MAX_TAB_NAME_SIZE];
- Uint32 buffer[2 + ((MAX_TAB_NAME_SIZE + 3) >> 2)]; // SP string
- LinearWriter w(buffer, sizeof(buffer) >> 2);
- LinearSectionPtr lsPtr[3];
- if (indexPtr.p->isHashIndex()) {
- req->setTriggerType(TriggerType::SECONDARY_INDEX);
- req->setMonitorReplicas(false);
- // insert
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL)
- req->setTriggerId(indexPtr.p->insertTriggerId);
- req->setTriggerEvent(TriggerEvent::TE_INSERT);
- sprintf(triggerName, "NDB$INDEX_%u_INSERT", opPtr.p->m_request.getIndexId());
- w.reset();
- w.add(CreateTrigReq::TriggerNameKey, triggerName);
- lsPtr[0].p = buffer;
- lsPtr[0].sz = w.getWordsUsed();
- sendSignal(reference(), GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB, lsPtr, 1);
- // update
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL)
- req->setTriggerId(indexPtr.p->updateTriggerId);
- req->setTriggerEvent(TriggerEvent::TE_UPDATE);
- sprintf(triggerName, "NDB$INDEX_%u_UPDATE", opPtr.p->m_request.getIndexId());
- w.reset();
- w.add(CreateTrigReq::TriggerNameKey, triggerName);
- lsPtr[0].p = buffer;
- lsPtr[0].sz = w.getWordsUsed();
- sendSignal(reference(), GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB, lsPtr, 1);
- // delete
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL)
- req->setTriggerId(indexPtr.p->deleteTriggerId);
- req->setTriggerEvent(TriggerEvent::TE_DELETE);
- sprintf(triggerName, "NDB$INDEX_%u_DELETE", opPtr.p->m_request.getIndexId());
- w.reset();
- w.add(CreateTrigReq::TriggerNameKey, triggerName);
- lsPtr[0].p = buffer;
- lsPtr[0].sz = w.getWordsUsed();
- sendSignal(reference(), GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB, lsPtr, 1);
- // triggers left to create
- opPtr.p->m_triggerCounter = 3;
- return;
- }
- if (indexPtr.p->isOrderedIndex()) {
- req->addRequestFlag(RequestFlag::RF_NOTCTRIGGER);
- req->setTriggerType(TriggerType::ORDERED_INDEX);
- req->setTriggerActionTime(TriggerActionTime::TA_CUSTOM);
- req->setMonitorReplicas(true);
- // one trigger for 5 events (insert, update, delete, commit, abort)
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL)
- req->setTriggerId(indexPtr.p->customTriggerId);
- req->setTriggerEvent(TriggerEvent::TE_CUSTOM);
- sprintf(triggerName, "NDB$INDEX_%u_CUSTOM", opPtr.p->m_request.getIndexId());
- w.reset();
- w.add(CreateTrigReq::TriggerNameKey, triggerName);
- lsPtr[0].p = buffer;
- lsPtr[0].sz = w.getWordsUsed();
- sendSignal(reference(), GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB, lsPtr, 1);
- // triggers left to create
- opPtr.p->m_triggerCounter = 1;
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::alterIndex_fromCreateTrigger(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- ndbrequire(opPtr.p->m_triggerCounter != 0);
- if (--opPtr.p->m_triggerCounter != 0) {
- jam();
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_ABORT;
- alterIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- if(opPtr.p->m_requestType != AlterIndxReq::RT_SYSTEMRESTART){
- // send build request
- alterIndex_toBuildIndex(signal, opPtr);
- return;
- }
-
- /**
- * During system restart,
- * leave index in activated but not build state.
- *
- * Build a bit later when REDO has been run
- */
- alterIndex_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::alterIndex_toDropTrigger(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- // start drop of index triggers
- DropTrigReq* const req = (DropTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(DropTrigReq::RT_ALTER_INDEX);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setTableId(opPtr.p->m_request.getTableId());
- req->setIndexId(opPtr.p->m_request.getIndexId());
- req->setTriggerInfo(0); // not used
- opPtr.p->m_triggerCounter = 0;
- if (indexPtr.p->isHashIndex()) {
- // insert
- req->setTriggerId(indexPtr.p->insertTriggerId);
- sendSignal(reference(), GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- opPtr.p->m_triggerCounter++;
- // update
- req->setTriggerId(indexPtr.p->updateTriggerId);
- sendSignal(reference(), GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- opPtr.p->m_triggerCounter++;
- // delete
- req->setTriggerId(indexPtr.p->deleteTriggerId);
- sendSignal(reference(), GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- opPtr.p->m_triggerCounter++;
- // build
- if (indexPtr.p->buildTriggerId != RNIL) {
- req->setTriggerId(indexPtr.p->buildTriggerId);
- sendSignal(reference(), GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- opPtr.p->m_triggerCounter++;
- }
- return;
- }
- if (indexPtr.p->isOrderedIndex()) {
- // custom
- req->addRequestFlag(RequestFlag::RF_NOTCTRIGGER);
- req->setTriggerId(indexPtr.p->customTriggerId);
- sendSignal(reference(), GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- opPtr.p->m_triggerCounter++;
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::alterIndex_fromDropTrigger(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- ndbrequire(opPtr.p->m_triggerCounter != 0);
- if (--opPtr.p->m_triggerCounter != 0) {
- jam();
- return;
- }
- // finally drop index in each TC
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- const bool isHashIndex = indexPtr.p->isHashIndex();
- const bool isOrderedIndex = indexPtr.p->isOrderedIndex();
- ndbrequire(isHashIndex != isOrderedIndex); // xor
- if (isHashIndex)
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_TC;
- if (isOrderedIndex)
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_COMMIT;
- alterIndex_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::alterIndex_toBuildIndex(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- // get index and table records
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, indexPtr.p->primaryTableId);
- // build request to self (short signal)
- BuildIndxReq* const req = (BuildIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(BuildIndxReq::RT_ALTER_INDEX);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setBuildId(0); // not used
- req->setBuildKey(0); // not used
- req->setIndexType(indexPtr.p->tableType);
- req->setIndexId(indexPtr.i);
- req->setTableId(indexPtr.p->primaryTableId);
- req->setParallelism(16);
- // send
- sendSignal(reference(), GSN_BUILDINDXREQ,
- signal, BuildIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::alterIndex_fromBuildIndex(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_ABORT;
- alterIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = AlterIndxReq::RT_DICT_COMMIT;
- alterIndex_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::alterIndex_slaveCommit(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- // get index record
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- indexPtr.p->indexState = TableRecord::IS_ONLINE;
- }
- void
- Dbdict::alterIndex_slaveAbort(Signal* signal, OpAlterIndexPtr opPtr)
- {
- jam();
- // find index record
- const Uint32 indexId = opPtr.p->m_request.getIndexId();
- if (indexId >= c_tableRecordPool.getSize())
- return;
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, indexId);
- if (! indexPtr.p->isIndex())
- return;
- // mark broken
- indexPtr.p->indexState = TableRecord::IS_BROKEN;
- }
- void
- Dbdict::alterIndex_sendSlaveReq(Signal* signal, OpAlterIndexPtr opPtr)
- {
- AlterIndxReq* const req = (AlterIndxReq*)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);
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- }
- opPtr.p->m_signalCounter = receiverNodes;
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_ALTER_INDX_REQ,
- signal, AlterIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::alterIndex_sendReply(Signal* signal, OpAlterIndexPtr opPtr,
- bool toUser)
- {
- AlterIndxRef* rep = (AlterIndxRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_ALTER_INDX_CONF;
- Uint32 length = AlterIndxConf::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 == AlterIndxReq::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 = AlterIndxConf::SignalLength;
- }
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setIndexId(opPtr.p->m_request.getIndexId());
- 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_ALTER_INDX_REF;
- length = AlterIndxRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /**
- * MODULE: Build index
- *
- * Build index or all indexes on a table. Request type:
- *
- * RT_USER - normal user request, not yet used
- * RT_ALTER_INDEX - from alter index
- * RT_SYSTEM_RESTART -
- * RT_DICT_PREPARE - prepare participants
- * RT_DICT_TRIX - to participant on way to local TRIX
- * RT_DICT_COMMIT - commit in each participant
- * RT_DICT_ABORT - abort
- * RT_TRIX - to local TRIX
- */
- void
- Dbdict::execBUILDINDXREQ(Signal* signal)
- {
- jamEntry();
- BuildIndxReq* const req = (BuildIndxReq*)signal->getDataPtrSend();
- OpBuildIndexPtr opPtr;
- const Uint32 senderRef = signal->senderBlockRef();
- const BuildIndxReq::RequestType requestType = req->getRequestType();
- if (requestType == BuildIndxReq::RT_USER ||
- requestType == BuildIndxReq::RT_ALTER_INDEX ||
- requestType == BuildIndxReq::RT_SYSTEMRESTART) {
- jam();
- const bool isLocal = req->getRequestFlag() & RequestFlag::RF_LOCAL;
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (isLocal) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- }
-
- if (signal->getLength() == BuildIndxReq::SignalLength) {
- jam();
-
- if (!isLocal && getOwnNodeId() != c_masterNodeId) {
- jam();
-
- releaseSections(signal);
- OpBuildIndex opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = BuildIndxRef::NotMaster;
- opPtr.p->m_errorLine = __LINE__;
- opPtr.p->m_errorNode = c_masterNodeId;
- buildIndex_sendReply(signal, opPtr, true);
- return;
- }
- // forward initial request plus operation key to all
- req->setOpKey(++c_opRecordSequence);
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_BUILDINDXREQ,
- signal, BuildIndxReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == BuildIndxReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpBuildIndex opBusy;
- if (! c_opBuildIndex.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 = BuildIndxReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = BuildIndxRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- buildIndex_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opBuildIndex.add(opPtr);
- // master expects to hear from all
- opPtr.p->m_signalCounter = receiverNodes;
- buildIndex_sendReply(signal, opPtr, false);
- return;
- }
- c_opBuildIndex.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == BuildIndxReq::RT_DICT_TRIX) {
- jam();
- buildIndex_buildTrix(signal, opPtr);
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_TC ||
- requestType == BuildIndxReq::RT_DICT_TUX) {
- jam();
- buildIndex_toOnline(signal, opPtr);
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_COMMIT ||
- requestType == BuildIndxReq::RT_DICT_ABORT) {
- jam();
- buildIndex_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opBuildIndex.release(opPtr);
- return;
- }
- }
- jam();
- // return to sender
- OpBuildIndex opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = BuildIndxRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- buildIndex_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::execBUILDINDXCONF(Signal* signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 0);
- BuildIndxConf* conf = (BuildIndxConf*)signal->getDataPtrSend();
- buildIndex_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execBUILDINDXREF(Signal* signal)
- {
- jamEntry();
- BuildIndxRef* ref = (BuildIndxRef*)signal->getDataPtrSend();
- buildIndex_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::buildIndex_recvReply(Signal* signal, const BuildIndxConf* conf,
- const BuildIndxRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const BuildIndxReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == BuildIndxReq::RT_ALTER_INDEX) {
- jam();
- // part of alter index operation
- OpAlterIndexPtr opPtr;
- c_opAlterIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterIndex_fromBuildIndex(signal, opPtr);
- return;
- }
- if (requestType == BuildIndxReq::RT_SYSTEMRESTART) {
- jam();
- if (ref == 0) {
- infoEvent("DICT: index %u rebuild done", (unsigned)key);
- } else {
- warningEvent("DICT: index %u rebuild failed: code=%d line=%d node=%d",
- (unsigned)key, ref->getErrorCode());
- }
- rebuildIndexes(signal, key + 1);
- return;
- }
- OpBuildIndexPtr opPtr;
- c_opBuildIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- if (requestType == BuildIndxReq::RT_TRIX) {
- jam();
- // forward to master
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TRIX;
- buildIndex_sendReply(signal, opPtr, false);
- return;
- }
- ndbrequire(opPtr.p->m_isMaster);
- ndbrequire(opPtr.p->m_requestType == requestType);
- opPtr.p->m_signalCounter.clearWaitingFor(refToNode(senderRef));
- if (! opPtr.p->m_signalCounter.done()) {
- jam();
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_COMMIT ||
- requestType == BuildIndxReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- buildIndex_sendReply(signal, opPtr, true);
- c_opBuildIndex.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_ABORT;
- buildIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- if (indexPtr.p->isHashIndex()) {
- if (requestType == BuildIndxReq::RT_DICT_PREPARE) {
- jam();
- if (! (opPtr.p->m_requestFlag & RequestFlag::RF_NOBUILD)) {
- buildIndex_toCreateConstr(signal, opPtr);
- } else {
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TC;
- buildIndex_sendSlaveReq(signal, opPtr);
- }
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_TRIX) {
- jam();
- ndbrequire(! (opPtr.p->m_requestFlag & RequestFlag::RF_NOBUILD));
- buildIndex_toDropConstr(signal, opPtr);
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_TC) {
- jam();
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_COMMIT;
- buildIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- }
- if (indexPtr.p->isOrderedIndex()) {
- if (requestType == BuildIndxReq::RT_DICT_PREPARE) {
- jam();
- if (! (opPtr.p->m_requestFlag & RequestFlag::RF_NOBUILD)) {
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TRIX;
- buildIndex_sendSlaveReq(signal, opPtr);
- } else {
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TUX;
- buildIndex_sendSlaveReq(signal, opPtr);
- }
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_TRIX) {
- jam();
- ndbrequire(! (opPtr.p->m_requestFlag & RequestFlag::RF_NOBUILD));
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TUX;
- buildIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == BuildIndxReq::RT_DICT_TUX) {
- jam();
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_COMMIT;
- buildIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- }
- ndbrequire(false);
- }
- void
- Dbdict::buildIndex_toCreateConstr(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- // request to create constraint trigger
- CreateTrigReq* req = (CreateTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(CreateTrigReq::RT_BUILD_INDEX);
- req->addRequestFlag(0); // none
- req->setTableId(indexPtr.i);
- req->setIndexId(RNIL);
- req->setTriggerId(RNIL);
- req->setTriggerType(TriggerType::READ_ONLY_CONSTRAINT);
- req->setTriggerActionTime(TriggerActionTime::TA_AFTER);
- req->setTriggerEvent(TriggerEvent::TE_UPDATE);
- req->setMonitorReplicas(false);
- req->setMonitorAllAttributes(false);
- req->setOnline(true); // alter online after create
- req->setReceiverRef(0); // no receiver, REF-ed by TUP
- req->getAttributeMask().clear();
- // NDB$PK is last attribute
- req->getAttributeMask().set(indexPtr.p->noOfAttributes - 1);
- // name section
- char triggerName[MAX_TAB_NAME_SIZE];
- Uint32 buffer[2 + ((MAX_TAB_NAME_SIZE + 3) >> 2)]; // SP string
- LinearWriter w(buffer, sizeof(buffer) >> 2);
- LinearSectionPtr lsPtr[3];
- sprintf(triggerName, "NDB$INDEX_%u_BUILD", indexPtr.i);
- w.reset();
- w.add(CreateTrigReq::TriggerNameKey, triggerName);
- lsPtr[0].p = buffer;
- lsPtr[0].sz = w.getWordsUsed();
- sendSignal(reference(), GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB, lsPtr, 1);
- }
- void
- Dbdict::buildIndex_fromCreateConstr(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_ABORT;
- buildIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TRIX;
- buildIndex_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::buildIndex_buildTrix(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, indexPtr.p->primaryTableId);
- // build request
- BuildIndxReq* const req = (BuildIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(BuildIndxReq::RT_TRIX);
- req->setBuildId(0); // not yet..
- req->setBuildKey(0); // ..in use
- req->setIndexType(indexPtr.p->tableType);
- req->setIndexId(indexPtr.i);
- req->setTableId(indexPtr.p->primaryTableId);
- req->setParallelism(16);
- if (indexPtr.p->isHashIndex()) {
- jam();
- getIndexAttrList(indexPtr, opPtr.p->m_attrList);
- getTableKeyList(tablePtr, opPtr.p->m_tableKeyList);
- // send
- LinearSectionPtr lsPtr[3];
- lsPtr[0].sz = opPtr.p->m_attrList.sz;
- lsPtr[0].p = opPtr.p->m_attrList.id;
- lsPtr[1].sz = opPtr.p->m_tableKeyList.sz;
- lsPtr[1].p = opPtr.p->m_tableKeyList.id;
- sendSignal(calcTrixBlockRef(getOwnNodeId()), GSN_BUILDINDXREQ,
- signal, BuildIndxReq::SignalLength, JBB, lsPtr, 2);
- return;
- }
- if (indexPtr.p->isOrderedIndex()) {
- jam();
- sendSignal(calcTupBlockRef(getOwnNodeId()), GSN_BUILDINDXREQ,
- signal, BuildIndxReq::SignalLength, JBB);
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::buildIndex_toDropConstr(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- // request to drop constraint trigger
- DropTrigReq* req = (DropTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(DropTrigReq::RT_BUILD_INDEX);
- req->addRequestFlag(0); // none
- req->setTableId(indexPtr.i);
- req->setIndexId(RNIL);
- req->setTriggerId(opPtr.p->m_constrTriggerId);
- req->setTriggerInfo(0); // not used
- sendSignal(reference(), GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::buildIndex_fromDropConstr(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_ABORT;
- buildIndex_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = BuildIndxReq::RT_DICT_TC;
- buildIndex_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::buildIndex_toOnline(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, opPtr.p->m_request.getIndexId());
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, indexPtr.p->primaryTableId);
- // request to set index online in TC or TUX
- AlterIndxReq* const req = (AlterIndxReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- if (opPtr.p->m_requestType == BuildIndxReq::RT_DICT_TC) {
- jam();
- req->setRequestType(AlterIndxReq::RT_TC);
- } else if (opPtr.p->m_requestType == BuildIndxReq::RT_DICT_TUX) {
- jam();
- req->setRequestType(AlterIndxReq::RT_TUX);
- } else {
- ndbrequire(false);
- }
- req->setTableId(tablePtr.i);
- req->setIndexId(indexPtr.i);
- req->setIndexVersion(indexPtr.p->tableVersion);
- req->setOnline(true);
- BlockReference blockRef = 0;
- if (opPtr.p->m_requestType == BuildIndxReq::RT_DICT_TC) {
- jam();
- blockRef = calcTcBlockRef(getOwnNodeId());
- } else if (opPtr.p->m_requestType == BuildIndxReq::RT_DICT_TUX) {
- jam();
- blockRef = calcTuxBlockRef(getOwnNodeId());
- } else {
- ndbrequire(false);
- }
- // send
- sendSignal(blockRef, GSN_ALTER_INDX_REQ,
- signal, BuildIndxReq::SignalLength, JBB);
- }
- void
- Dbdict::buildIndex_fromOnline(Signal* signal, OpBuildIndexPtr opPtr)
- {
- jam();
- // forward to master
- buildIndex_sendReply(signal, opPtr, false);
- }
- void
- Dbdict::buildIndex_sendSlaveReq(Signal* signal, OpBuildIndexPtr opPtr)
- {
- BuildIndxReq* const req = (BuildIndxReq*)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);
- if(opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL) {
- jam();
- opPtr.p->m_signalCounter.clearWaitingFor();
- opPtr.p->m_signalCounter.setWaitingFor(getOwnNodeId());
- sendSignal(reference(), GSN_BUILDINDXREQ,
- signal, BuildIndxReq::SignalLength, JBB);
- } else {
- jam();
- opPtr.p->m_signalCounter = c_aliveNodes;
- NodeReceiverGroup rg(DBDICT, c_aliveNodes);
- sendSignal(rg, GSN_BUILDINDXREQ,
- signal, BuildIndxReq::SignalLength, JBB);
- }
- }
- void
- Dbdict::buildIndex_sendReply(Signal* signal, OpBuildIndexPtr opPtr,
- bool toUser)
- {
- BuildIndxRef* rep = (BuildIndxRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_BUILDINDXCONF;
- Uint32 length = BuildIndxConf::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 == BuildIndxReq::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 = BuildIndxConf::SignalLength;
- }
- rep->setIndexType(opPtr.p->m_request.getIndexType());
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setIndexId(opPtr.p->m_request.getIndexId());
- if (sendRef) {
- rep->setErrorCode(opPtr.p->m_errorCode);
- rep->masterNodeId = opPtr.p->m_errorNode;
- gsn = GSN_BUILDINDXREF;
- length = BuildIndxRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /**
- * MODULE: Create trigger
- *
- * Create trigger in all DICT blocks. Optionally start alter trigger
- * operation to set the trigger online.
- *
- * Request type received in REQ and returned in CONF/REF:
- *
- * RT_USER - normal user e.g. BACKUP
- * RT_ALTER_INDEX - from alter index online
- * RT_DICT_PREPARE - seize operation in each DICT
- * RT_DICT_COMMIT - commit create in each DICT
- * RT_TC - sending to TC (operation alter trigger)
- * RT_LQH - sending to LQH (operation alter trigger)
- */
- void
- Dbdict::execCREATE_TRIG_REQ(Signal* signal)
- {
- jamEntry();
- CreateTrigReq* const req = (CreateTrigReq*)signal->getDataPtrSend();
- OpCreateTriggerPtr opPtr;
- const Uint32 senderRef = signal->senderBlockRef();
- const CreateTrigReq::RequestType requestType = req->getRequestType();
- if (requestType == CreateTrigReq::RT_USER ||
- requestType == CreateTrigReq::RT_ALTER_INDEX ||
- requestType == CreateTrigReq::RT_BUILD_INDEX) {
- jam();
- if (! assembleFragments(signal)) {
- jam();
- return;
- }
- const bool isLocal = req->getRequestFlag() & RequestFlag::RF_LOCAL;
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (isLocal) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- }
- if (signal->getLength() == CreateTrigReq::SignalLength) {
- jam();
- if (! isLocal && getOwnNodeId() != c_masterNodeId) {
- jam();
- releaseSections(signal);
- OpCreateTrigger opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = CreateTrigRef::NotMaster;
- opPtr.p->m_errorLine = __LINE__;
- opPtr.p->m_errorNode = c_masterNodeId;
- createTrigger_sendReply(signal, opPtr, true);
- return;
- }
- // forward initial request plus operation key to all
- req->setOpKey(++c_opRecordSequence);
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == CreateTrigReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpCreateTrigger opBusy;
- if (! c_opCreateTrigger.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 = CreateTrigReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- releaseSections(signal);
- createTrigger_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opCreateTrigger.add(opPtr);
- {
- // save name
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr, CreateTrigReq::TRIGGER_NAME_SECTION);
- SimplePropertiesSectionReader ssReader(ssPtr, getSectionSegmentPool());
- if (ssReader.getKey() != CreateTrigReq::TriggerNameKey ||
- ! ssReader.getString(opPtr.p->m_triggerName)) {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::InvalidName;
- opPtr.p->m_errorLine = __LINE__;
- releaseSections(signal);
- createTrigger_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- }
- releaseSections(signal);
- {
- // check that trigger name is unique
- TriggerRecordPtr triggerPtr;
- TriggerRecord keyRecord;
- strcpy(keyRecord.triggerName, opPtr.p->m_triggerName);
- c_triggerRecordHash.find(triggerPtr, keyRecord);
- if (triggerPtr.i != RNIL) {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::TriggerExists;
- opPtr.p->m_errorLine = __LINE__;
- createTrigger_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- }
- // master expects to hear from all
- if (opPtr.p->m_isMaster)
- opPtr.p->m_signalCounter = receiverNodes;
- // check request in all participants
- createTrigger_slavePrepare(signal, opPtr);
- createTrigger_sendReply(signal, opPtr, false);
- return;
- }
- c_opCreateTrigger.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == CreateTrigReq::RT_DICT_CREATE) {
- jam();
- // master has set trigger id
- opPtr.p->m_request.setTriggerId(req->getTriggerId());
- createTrigger_slaveCreate(signal, opPtr);
- createTrigger_sendReply(signal, opPtr, false);
- return;
- }
- if (requestType == CreateTrigReq::RT_DICT_COMMIT ||
- requestType == CreateTrigReq::RT_DICT_ABORT) {
- jam();
- if (requestType == CreateTrigReq::RT_DICT_COMMIT)
- createTrigger_slaveCommit(signal, opPtr);
- else
- createTrigger_slaveAbort(signal, opPtr);
- createTrigger_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opCreateTrigger.release(opPtr);
- return;
- }
- }
- jam();
- // return to sender
- releaseSections(signal);
- OpCreateTrigger opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = CreateTrigRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- createTrigger_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::execCREATE_TRIG_CONF(Signal* signal)
- {
- jamEntry();
- ndbrequire(signal->getNoOfSections() == 0);
- CreateTrigConf* conf = (CreateTrigConf*)signal->getDataPtrSend();
- createTrigger_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execCREATE_TRIG_REF(Signal* signal)
- {
- jamEntry();
- CreateTrigRef* ref = (CreateTrigRef*)signal->getDataPtrSend();
- createTrigger_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::createTrigger_recvReply(Signal* signal, const CreateTrigConf* conf,
- const CreateTrigRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const CreateTrigReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == CreateTrigReq::RT_ALTER_INDEX) {
- jam();
- // part of alter index operation
- OpAlterIndexPtr opPtr;
- c_opAlterIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterIndex_fromCreateTrigger(signal, opPtr);
- return;
- }
- if (requestType == CreateTrigReq::RT_BUILD_INDEX) {
- jam();
- // part of build index operation
- OpBuildIndexPtr opPtr;
- c_opBuildIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- // fill in trigger id
- opPtr.p->m_constrTriggerId = conf->getTriggerId();
- buildIndex_fromCreateConstr(signal, opPtr);
- return;
- }
- if (requestType == CreateTrigReq::RT_TC ||
- requestType == CreateTrigReq::RT_LQH) {
- jam();
- // part of alter trigger operation
- OpAlterTriggerPtr opPtr;
- c_opAlterTrigger.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterTrigger_fromCreateLocal(signal, opPtr);
- return;
- }
- OpCreateTriggerPtr opPtr;
- c_opCreateTrigger.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 == CreateTrigReq::RT_DICT_COMMIT ||
- requestType == CreateTrigReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- createTrigger_sendReply(signal, opPtr, true);
- c_opCreateTrigger.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateTrigReq::RT_DICT_ABORT;
- createTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == CreateTrigReq::RT_DICT_PREPARE) {
- jam();
- // seize trigger id in master
- createTrigger_masterSeize(signal, opPtr);
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateTrigReq::RT_DICT_ABORT;
- createTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = CreateTrigReq::RT_DICT_CREATE;
- createTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == CreateTrigReq::RT_DICT_CREATE) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- jam();
- // start alter online
- createTrigger_toAlterTrigger(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = CreateTrigReq::RT_DICT_COMMIT;
- createTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::createTrigger_slavePrepare(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- jam();
- const CreateTrigReq* const req = &opPtr.p->m_request;
- // check trigger type
- if (req->getRequestType() == CreateTrigReq::RT_USER &&
- req->getTriggerType() == TriggerType::SUBSCRIPTION ||
- req->getRequestType() == CreateTrigReq::RT_ALTER_INDEX &&
- req->getTriggerType() == TriggerType::SECONDARY_INDEX ||
- req->getRequestType() == CreateTrigReq::RT_ALTER_INDEX &&
- req->getTriggerType() == TriggerType::ORDERED_INDEX ||
- req->getRequestType() == CreateTrigReq::RT_BUILD_INDEX &&
- req->getTriggerType() == TriggerType::READ_ONLY_CONSTRAINT) {
- ;
- } else {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::UnsupportedTriggerType;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- // check the table
- const Uint32 tableId = req->getTableId();
- if (! (tableId < c_tableRecordPool.getSize())) {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::InvalidTable;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, tableId);
- if (tablePtr.p->tabState != TableRecord::DEFINED &&
- tablePtr.p->tabState != TableRecord::BACKUP_ONGOING) {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::InvalidTable;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- }
- void
- Dbdict::createTrigger_masterSeize(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- TriggerRecordPtr triggerPtr;
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL) {
- triggerPtr.i = opPtr.p->m_request.getTriggerId();
- } else {
- triggerPtr.i = getFreeTriggerRecord();
- if (triggerPtr.i == RNIL) {
- jam();
- opPtr.p->m_errorCode = CreateTrigRef::TooManyTriggers;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- }
- c_triggerRecordPool.getPtr(triggerPtr);
- initialiseTriggerRecord(triggerPtr);
- triggerPtr.p->triggerState = TriggerRecord::TS_DEFINING;
- opPtr.p->m_request.setTriggerId(triggerPtr.i);
- }
- void
- Dbdict::createTrigger_slaveCreate(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- jam();
- const CreateTrigReq* const req = &opPtr.p->m_request;
- // get the trigger record
- const Uint32 triggerId = req->getTriggerId();
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, triggerId);
- initialiseTriggerRecord(triggerPtr);
- // fill in trigger data
- strcpy(triggerPtr.p->triggerName, opPtr.p->m_triggerName);
- triggerPtr.p->triggerId = triggerId;
- triggerPtr.p->tableId = req->getTableId();
- triggerPtr.p->indexId = RNIL;
- triggerPtr.p->triggerType = req->getTriggerType();
- triggerPtr.p->triggerActionTime = req->getTriggerActionTime();
- triggerPtr.p->triggerEvent = req->getTriggerEvent();
- triggerPtr.p->monitorReplicas = req->getMonitorReplicas();
- triggerPtr.p->monitorAllAttributes = req->getMonitorAllAttributes();
- triggerPtr.p->attributeMask = req->getAttributeMask();
- triggerPtr.p->triggerState = TriggerRecord::TS_OFFLINE;
- // add to hash table
- // ndbout_c("++++++++++++ Adding trigger id %u, %s", triggerPtr.p->triggerId, triggerPtr.p->triggerName);
- c_triggerRecordHash.add(triggerPtr);
- if (triggerPtr.p->triggerType == TriggerType::SECONDARY_INDEX ||
- triggerPtr.p->triggerType == TriggerType::ORDERED_INDEX) {
- jam();
- // connect to index record XXX should be done in caller instead
- triggerPtr.p->indexId = req->getIndexId();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, triggerPtr.p->indexId);
- switch (triggerPtr.p->triggerEvent) {
- case TriggerEvent::TE_INSERT:
- indexPtr.p->insertTriggerId = triggerPtr.p->triggerId;
- break;
- case TriggerEvent::TE_UPDATE:
- indexPtr.p->updateTriggerId = triggerPtr.p->triggerId;
- break;
- case TriggerEvent::TE_DELETE:
- indexPtr.p->deleteTriggerId = triggerPtr.p->triggerId;
- break;
- case TriggerEvent::TE_CUSTOM:
- indexPtr.p->customTriggerId = triggerPtr.p->triggerId;
- break;
- default:
- ndbrequire(false);
- break;
- }
- }
- if (triggerPtr.p->triggerType == TriggerType::READ_ONLY_CONSTRAINT) {
- jam();
- // connect to index record XXX should be done in caller instead
- triggerPtr.p->indexId = req->getTableId();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, triggerPtr.p->indexId);
- indexPtr.p->buildTriggerId = triggerPtr.p->triggerId;
- }
- }
- void
- Dbdict::createTrigger_toAlterTrigger(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- jam();
- AlterTrigReq* req = (AlterTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(AlterTrigReq::RT_CREATE_TRIGGER);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setTableId(opPtr.p->m_request.getTableId());
- req->setTriggerId(opPtr.p->m_request.getTriggerId());
- req->setTriggerInfo(0); // not used
- req->setOnline(true);
- req->setReceiverRef(opPtr.p->m_request.getReceiverRef());
- sendSignal(reference(), GSN_ALTER_TRIG_REQ,
- signal, AlterTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::createTrigger_fromAlterTrigger(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- jam();
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = CreateTrigReq::RT_DICT_ABORT;
- createTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- opPtr.p->m_requestType = CreateTrigReq::RT_DICT_COMMIT;
- createTrigger_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::createTrigger_slaveCommit(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- jam();
- const CreateTrigReq* const req = &opPtr.p->m_request;
- // get the trigger record
- const Uint32 triggerId = req->getTriggerId();
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, triggerId);
- if (! req->getOnline()) {
- triggerPtr.p->triggerState = TriggerRecord::TS_OFFLINE;
- } else {
- ndbrequire(triggerPtr.p->triggerState == TriggerRecord::TS_ONLINE);
- }
- }
- void
- Dbdict::createTrigger_slaveAbort(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- jam();
- }
- void
- Dbdict::createTrigger_sendSlaveReq(Signal* signal, OpCreateTriggerPtr opPtr)
- {
- CreateTrigReq* const req = (CreateTrigReq*)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);
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- }
- opPtr.p->m_signalCounter = receiverNodes;
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::createTrigger_sendReply(Signal* signal, OpCreateTriggerPtr opPtr,
- bool toUser)
- {
- CreateTrigRef* rep = (CreateTrigRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_CREATE_TRIG_CONF;
- Uint32 length = CreateTrigConf::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 == CreateTrigReq::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 = CreateTrigConf::SignalLength;
- }
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setIndexId(opPtr.p->m_request.getIndexId());
- rep->setTriggerId(opPtr.p->m_request.getTriggerId());
- rep->setTriggerInfo(opPtr.p->m_request.getTriggerInfo());
- 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_TRIG_REF;
- length = CreateTrigRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /**
- * MODULE: Drop trigger.
- */
- void
- Dbdict::execDROP_TRIG_REQ(Signal* signal)
- {
- jamEntry();
- DropTrigReq* const req = (DropTrigReq*)signal->getDataPtrSend();
- OpDropTriggerPtr opPtr;
- const Uint32 senderRef = signal->senderBlockRef();
- const DropTrigReq::RequestType requestType = req->getRequestType();
- if (signal->getNoOfSections() > 0) {
- ndbrequire(signal->getNoOfSections() == 1);
- jam();
- TriggerRecord keyRecord;
- OpDropTrigger opTmp;
- opPtr.p=&opTmp;
- SegmentedSectionPtr ssPtr;
- signal->getSection(ssPtr, DropTrigReq::TRIGGER_NAME_SECTION);
- SimplePropertiesSectionReader ssReader(ssPtr, getSectionSegmentPool());
- if (ssReader.getKey() != DropTrigReq::TriggerNameKey ||
- ! ssReader.getString(keyRecord.triggerName)) {
- jam();
- opPtr.p->m_errorCode = DropTrigRef::InvalidName;
- opPtr.p->m_errorLine = __LINE__;
- releaseSections(signal);
- dropTrigger_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- releaseSections(signal);
- TriggerRecordPtr triggerPtr;
- // ndbout_c("++++++++++++++ Looking for trigger %s", keyRecord.triggerName);
- c_triggerRecordHash.find(triggerPtr, keyRecord);
- if (triggerPtr.i == RNIL) {
- jam();
- req->setTriggerId(RNIL);
- } else {
- jam();
- // ndbout_c("++++++++++ Found trigger %s", triggerPtr.p->triggerName);
- req->setTriggerId(triggerPtr.p->triggerId);
- req->setTableId(triggerPtr.p->tableId);
- }
- }
- if (requestType == DropTrigReq::RT_USER ||
- requestType == DropTrigReq::RT_ALTER_INDEX ||
- requestType == DropTrigReq::RT_BUILD_INDEX) {
- jam();
- if (signal->getLength() == DropTrigReq::SignalLength) {
- if (getOwnNodeId() != c_masterNodeId) {
- jam();
- // forward to DICT master
- sendSignal(calcDictBlockRef(c_masterNodeId), GSN_DROP_TRIG_REQ,
- signal, signal->getLength(), JBB);
- return;
- }
- if (!c_triggerRecordPool.findId(req->getTriggerId())) {
- jam();
- // return to sender
- OpDropTrigger opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- if (! (req->getRequestFlag() & RequestFlag::RF_FORCE)) {
- opPtr.p->m_errorCode = DropTrigRef::TriggerNotFound;
- opPtr.p->m_errorLine = __LINE__;
- }
- dropTrigger_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_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == DropTrigReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpDropTrigger opBusy;
- if (! c_opDropTrigger.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 = DropTrigReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = DropTrigRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- dropTrigger_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opDropTrigger.add(opPtr);
- // master expects to hear from all
- if (opPtr.p->m_isMaster)
- opPtr.p->m_signalCounter = c_aliveNodes;
- dropTrigger_slavePrepare(signal, opPtr);
- dropTrigger_sendReply(signal, opPtr, false);
- return;
- }
- c_opDropTrigger.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == DropTrigReq::RT_DICT_COMMIT ||
- requestType == DropTrigReq::RT_DICT_ABORT) {
- jam();
- if (requestType == DropTrigReq::RT_DICT_COMMIT)
- dropTrigger_slaveCommit(signal, opPtr);
- else
- dropTrigger_slaveAbort(signal, opPtr);
- dropTrigger_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opDropTrigger.release(opPtr);
- return;
- }
- }
- jam();
- // return to sender
- OpDropTrigger opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = DropTrigRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- dropTrigger_sendReply(signal, opPtr, true);
- }
- void
- Dbdict::execDROP_TRIG_CONF(Signal* signal)
- {
- jamEntry();
- DropTrigConf* conf = (DropTrigConf*)signal->getDataPtrSend();
- dropTrigger_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execDROP_TRIG_REF(Signal* signal)
- {
- jamEntry();
- DropTrigRef* ref = (DropTrigRef*)signal->getDataPtrSend();
- dropTrigger_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::dropTrigger_recvReply(Signal* signal, const DropTrigConf* conf,
- const DropTrigRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const DropTrigReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == DropTrigReq::RT_ALTER_INDEX) {
- jam();
- // part of alter index operation
- OpAlterIndexPtr opPtr;
- c_opAlterIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterIndex_fromDropTrigger(signal, opPtr);
- return;
- }
- if (requestType == DropTrigReq::RT_BUILD_INDEX) {
- jam();
- // part of build index operation
- OpBuildIndexPtr opPtr;
- c_opBuildIndex.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- buildIndex_fromDropConstr(signal, opPtr);
- return;
- }
- if (requestType == DropTrigReq::RT_TC ||
- requestType == DropTrigReq::RT_LQH) {
- jam();
- // part of alter trigger operation
- OpAlterTriggerPtr opPtr;
- c_opAlterTrigger.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- alterTrigger_fromDropLocal(signal, opPtr);
- return;
- }
- OpDropTriggerPtr opPtr;
- c_opDropTrigger.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 == DropTrigReq::RT_DICT_COMMIT ||
- requestType == DropTrigReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- dropTrigger_sendReply(signal, opPtr, true);
- c_opDropTrigger.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = DropTrigReq::RT_DICT_ABORT;
- dropTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == DropTrigReq::RT_DICT_PREPARE) {
- jam();
- // start alter offline
- dropTrigger_toAlterTrigger(signal, opPtr);
- return;
- }
- ndbrequire(false);
- }
- void
- Dbdict::dropTrigger_slavePrepare(Signal* signal, OpDropTriggerPtr opPtr)
- {
- jam();
- }
- void
- Dbdict::dropTrigger_toAlterTrigger(Signal* signal, OpDropTriggerPtr opPtr)
- {
- jam();
- AlterTrigReq* req = (AlterTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- req->setRequestType(AlterTrigReq::RT_DROP_TRIGGER);
- req->addRequestFlag(opPtr.p->m_requestFlag);
- req->setTableId(opPtr.p->m_request.getTableId());
- req->setTriggerId(opPtr.p->m_request.getTriggerId());
- req->setTriggerInfo(0); // not used
- req->setOnline(false);
- req->setReceiverRef(0);
- sendSignal(reference(), GSN_ALTER_TRIG_REQ,
- signal, AlterTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::dropTrigger_fromAlterTrigger(Signal* signal, OpDropTriggerPtr opPtr)
- {
- jam();
- // remove in all
- opPtr.p->m_requestType = DropTrigReq::RT_DICT_COMMIT;
- dropTrigger_sendSlaveReq(signal, opPtr);
- }
- void
- Dbdict::dropTrigger_sendSlaveReq(Signal* signal, OpDropTriggerPtr opPtr)
- {
- DropTrigReq* const req = (DropTrigReq*)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_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::dropTrigger_slaveCommit(Signal* signal, OpDropTriggerPtr opPtr)
- {
- jam();
- const DropTrigReq* const req = &opPtr.p->m_request;
- // get trigger record
- const Uint32 triggerId = req->getTriggerId();
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, triggerId);
- if (triggerPtr.p->triggerType == TriggerType::SECONDARY_INDEX ||
- triggerPtr.p->triggerType == TriggerType::ORDERED_INDEX) {
- jam();
- // disconnect from index if index trigger XXX move to drop index
- triggerPtr.p->indexId = req->getIndexId();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, triggerPtr.p->indexId);
- ndbrequire(! indexPtr.isNull());
- switch (triggerPtr.p->triggerEvent) {
- case TriggerEvent::TE_INSERT:
- indexPtr.p->insertTriggerId = RNIL;
- break;
- case TriggerEvent::TE_UPDATE:
- indexPtr.p->updateTriggerId = RNIL;
- break;
- case TriggerEvent::TE_DELETE:
- indexPtr.p->deleteTriggerId = RNIL;
- break;
- case TriggerEvent::TE_CUSTOM:
- indexPtr.p->customTriggerId = RNIL;
- break;
- default:
- ndbrequire(false);
- break;
- }
- }
- if (triggerPtr.p->triggerType == TriggerType::READ_ONLY_CONSTRAINT) {
- jam();
- // disconnect from index record XXX should be done in caller instead
- triggerPtr.p->indexId = req->getTableId();
- TableRecordPtr indexPtr;
- c_tableRecordPool.getPtr(indexPtr, triggerPtr.p->indexId);
- indexPtr.p->buildTriggerId = RNIL;
- }
- // remove trigger
- // ndbout_c("++++++++++++ Removing trigger id %u, %s", triggerPtr.p->triggerId, triggerPtr.p->triggerName);
- c_triggerRecordHash.remove(triggerPtr);
- triggerPtr.p->triggerState = TriggerRecord::TS_NOT_DEFINED;
- }
- void
- Dbdict::dropTrigger_slaveAbort(Signal* signal, OpDropTriggerPtr opPtr)
- {
- jam();
- }
- void
- Dbdict::dropTrigger_sendReply(Signal* signal, OpDropTriggerPtr opPtr,
- bool toUser)
- {
- DropTrigRef* rep = (DropTrigRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_DROP_TRIG_CONF;
- Uint32 length = DropTrigConf::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 == DropTrigReq::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 = DropTrigConf::SignalLength;
- }
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setIndexId(opPtr.p->m_request.getIndexId());
- rep->setTriggerId(opPtr.p->m_request.getTriggerId());
- 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_TRIG_REF;
- length = CreateTrigRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /**
- * MODULE: Alter trigger.
- *
- * Alter trigger state. Alter online creates the trigger first in all
- * TC (if index trigger) and then in all LQH-TUP.
- *
- * Request type received in REQ and returned in CONF/REF:
- *
- * RT_USER - normal user e.g. BACKUP
- * RT_CREATE_TRIGGER - from create trigger
- * RT_DROP_TRIGGER - from drop trigger
- * RT_DICT_PREPARE - seize operations and check request
- * RT_DICT_TC - master to each DICT on way to TC
- * RT_DICT_LQH - master to each DICT on way to LQH-TUP
- * RT_DICT_COMMIT - commit state change in each DICT (no reply)
- */
- void
- Dbdict::execALTER_TRIG_REQ(Signal* signal)
- {
- jamEntry();
- AlterTrigReq* const req = (AlterTrigReq*)signal->getDataPtrSend();
- OpAlterTriggerPtr opPtr;
- const Uint32 senderRef = signal->senderBlockRef();
- const AlterTrigReq::RequestType requestType = req->getRequestType();
- if (requestType == AlterTrigReq::RT_USER ||
- requestType == AlterTrigReq::RT_CREATE_TRIGGER ||
- requestType == AlterTrigReq::RT_DROP_TRIGGER) {
- jam();
- const bool isLocal = req->getRequestFlag() & RequestFlag::RF_LOCAL;
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (isLocal) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- }
- if (signal->getLength() == AlterTrigReq::SignalLength) {
- jam();
- if (! isLocal && getOwnNodeId() != c_masterNodeId) {
- jam();
- // forward to DICT master
- sendSignal(calcDictBlockRef(c_masterNodeId), GSN_ALTER_TRIG_REQ,
- signal, AlterTrigReq::SignalLength, JBB);
- return;
- }
- // forward initial request plus operation key to all
- req->setOpKey(++c_opRecordSequence);
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_ALTER_TRIG_REQ,
- signal, AlterTrigReq::SignalLength + 1, JBB);
- return;
- }
- // seize operation record
- ndbrequire(signal->getLength() == AlterTrigReq::SignalLength + 1);
- const Uint32 opKey = req->getOpKey();
- OpAlterTrigger opBusy;
- if (! c_opAlterTrigger.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 = AlterTrigReq::RT_DICT_PREPARE;
- if (opPtr.p == &opBusy) {
- jam();
- opPtr.p->m_errorCode = AlterTrigRef::Busy;
- opPtr.p->m_errorLine = __LINE__;
- alterTrigger_sendReply(signal, opPtr, opPtr.p->m_isMaster);
- return;
- }
- c_opAlterTrigger.add(opPtr);
- // master expects to hear from all
- if (opPtr.p->m_isMaster) {
- opPtr.p->m_nodes = receiverNodes;
- opPtr.p->m_signalCounter = receiverNodes;
- }
- alterTrigger_slavePrepare(signal, opPtr);
- alterTrigger_sendReply(signal, opPtr, false);
- return;
- }
- c_opAlterTrigger.find(opPtr, req->getConnectionPtr());
- if (! opPtr.isNull()) {
- opPtr.p->m_requestType = requestType;
- if (requestType == AlterTrigReq::RT_DICT_TC ||
- requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- if (req->getOnline())
- alterTrigger_toCreateLocal(signal, opPtr);
- else
- alterTrigger_toDropLocal(signal, opPtr);
- return;
- }
- if (requestType == AlterTrigReq::RT_DICT_COMMIT ||
- requestType == AlterTrigReq::RT_DICT_ABORT) {
- jam();
- if (requestType == AlterTrigReq::RT_DICT_COMMIT)
- alterTrigger_slaveCommit(signal, opPtr);
- else
- alterTrigger_slaveAbort(signal, opPtr);
- alterTrigger_sendReply(signal, opPtr, false);
- // done in slave
- if (! opPtr.p->m_isMaster)
- c_opAlterTrigger.release(opPtr);
- return;
- }
- }
- jam();
- // return to sender
- OpAlterTrigger opBad;
- opPtr.p = &opBad;
- opPtr.p->save(req);
- opPtr.p->m_errorCode = AlterTrigRef::BadRequestType;
- opPtr.p->m_errorLine = __LINE__;
- alterTrigger_sendReply(signal, opPtr, true);
- return;
- }
- void
- Dbdict::execALTER_TRIG_CONF(Signal* signal)
- {
- jamEntry();
- AlterTrigConf* conf = (AlterTrigConf*)signal->getDataPtrSend();
- alterTrigger_recvReply(signal, conf, 0);
- }
- void
- Dbdict::execALTER_TRIG_REF(Signal* signal)
- {
- jamEntry();
- AlterTrigRef* ref = (AlterTrigRef*)signal->getDataPtrSend();
- alterTrigger_recvReply(signal, ref->getConf(), ref);
- }
- void
- Dbdict::alterTrigger_recvReply(Signal* signal, const AlterTrigConf* conf,
- const AlterTrigRef* ref)
- {
- jam();
- const Uint32 senderRef = signal->senderBlockRef();
- const AlterTrigReq::RequestType requestType = conf->getRequestType();
- const Uint32 key = conf->getConnectionPtr();
- if (requestType == AlterTrigReq::RT_CREATE_TRIGGER) {
- jam();
- // part of create trigger operation
- OpCreateTriggerPtr opPtr;
- c_opCreateTrigger.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- createTrigger_fromAlterTrigger(signal, opPtr);
- return;
- }
- if (requestType == AlterTrigReq::RT_DROP_TRIGGER) {
- jam();
- // part of drop trigger operation
- OpDropTriggerPtr opPtr;
- c_opDropTrigger.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- opPtr.p->setError(ref);
- dropTrigger_fromAlterTrigger(signal, opPtr);
- return;
- }
- OpAlterTriggerPtr opPtr;
- c_opAlterTrigger.find(opPtr, key);
- ndbrequire(! opPtr.isNull());
- ndbrequire(opPtr.p->m_isMaster);
- ndbrequire(opPtr.p->m_requestType == requestType);
- /*
- * If refuse on drop trig, because of non-existent trigger,
- * comes from anyone but the master node - ignore it and
- * remove the node from forter ALTER_TRIG communication
- * This will happen if a new node has started since the
- * trigger whas created.
- */
- if (ref &&
- refToNode(senderRef) != refToNode(reference()) &&
- opPtr.p->m_request.getRequestType() == AlterTrigReq::RT_DROP_TRIGGER &&
- ref->getErrorCode() == AlterTrigRef::TriggerNotFound) {
- jam();
- ref = 0; // ignore this error
- opPtr.p->m_nodes.clear(refToNode(senderRef)); // remove this from group
- }
- opPtr.p->setError(ref);
- opPtr.p->m_signalCounter.clearWaitingFor(refToNode(senderRef));
- if (! opPtr.p->m_signalCounter.done()) {
- jam();
- return;
- }
- if (requestType == AlterTrigReq::RT_DICT_COMMIT ||
- requestType == AlterTrigReq::RT_DICT_ABORT) {
- jam();
- // send reply to user
- alterTrigger_sendReply(signal, opPtr, true);
- c_opAlterTrigger.release(opPtr);
- return;
- }
- if (opPtr.p->hasError()) {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_ABORT;
- alterTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (! (opPtr.p->m_request.getRequestFlag() & RequestFlag::RF_NOTCTRIGGER)) {
- if (requestType == AlterTrigReq::RT_DICT_PREPARE) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_TC;
- } else {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_LQH;
- }
- alterTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_LQH;
- } else {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_COMMIT;
- }
- alterTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- if (opPtr.p->m_request.getOnline()) {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_COMMIT;
- } else {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_TC;
- }
- alterTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- } else {
- if (requestType == AlterTrigReq::RT_DICT_PREPARE) {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_LQH;
- alterTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- if (requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- opPtr.p->m_requestType = AlterTrigReq::RT_DICT_COMMIT;
- alterTrigger_sendSlaveReq(signal, opPtr);
- return;
- }
- }
- ndbrequire(false);
- }
- void
- Dbdict::alterTrigger_slavePrepare(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- const AlterTrigReq* const req = &opPtr.p->m_request;
- const Uint32 triggerId = req->getTriggerId();
- TriggerRecordPtr triggerPtr;
- if (! (triggerId < c_triggerRecordPool.getSize())) {
- jam();
- opPtr.p->m_errorCode = AlterTrigRef::TriggerNotFound;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- c_triggerRecordPool.getPtr(triggerPtr, triggerId);
- if (triggerPtr.p->triggerState == TriggerRecord::TS_NOT_DEFINED) {
- jam();
- opPtr.p->m_errorCode = AlterTrigRef::TriggerNotFound;
- opPtr.p->m_errorLine = __LINE__;
- return;
- }
- if (triggerPtr.p->triggerType == TriggerType::SUBSCRIPTION)
- {
- opPtr.p->m_request.addRequestFlag(RequestFlag::RF_NOTCTRIGGER);
- }
- }
- void
- Dbdict::alterTrigger_toCreateLocal(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- // find trigger record
- const Uint32 triggerId = opPtr.p->m_request.getTriggerId();
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, triggerId);
- CreateTrigReq* const req = (CreateTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- req->setRequestType(CreateTrigReq::RT_TC);
- } else if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- req->setRequestType(CreateTrigReq::RT_LQH);
- } else {
- ndbassert(false);
- }
- req->setTableId(triggerPtr.p->tableId);
- req->setIndexId(triggerPtr.p->indexId);
- req->setTriggerId(triggerPtr.i);
- req->setTriggerType(triggerPtr.p->triggerType);
- req->setTriggerActionTime(triggerPtr.p->triggerActionTime);
- req->setTriggerEvent(triggerPtr.p->triggerEvent);
- req->setMonitorReplicas(triggerPtr.p->monitorReplicas);
- req->setMonitorAllAttributes(triggerPtr.p->monitorAllAttributes);
- req->setOnline(true);
- req->setReceiverRef(opPtr.p->m_request.getReceiverRef());
- BlockReference blockRef = 0;
- if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- blockRef = calcTcBlockRef(getOwnNodeId());
- } else if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- blockRef = calcLqhBlockRef(getOwnNodeId());
- } else {
- ndbassert(false);
- }
- req->setAttributeMask(triggerPtr.p->attributeMask);
- sendSignal(blockRef, GSN_CREATE_TRIG_REQ,
- signal, CreateTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::alterTrigger_fromCreateLocal(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- if (! opPtr.p->hasLastError()) {
- // mark created locally
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, opPtr.p->m_request.getTriggerId());
- if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- triggerPtr.p->triggerLocal |= TriggerRecord::TL_CREATED_TC;
- } else if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- triggerPtr.p->triggerLocal |= TriggerRecord::TL_CREATED_LQH;
- } else {
- ndbrequire(false);
- }
- }
- // forward CONF or REF to master
- alterTrigger_sendReply(signal, opPtr, false);
- }
- void
- Dbdict::alterTrigger_toDropLocal(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, opPtr.p->m_request.getTriggerId());
- DropTrigReq* const req = (DropTrigReq*)signal->getDataPtrSend();
- req->setUserRef(reference());
- req->setConnectionPtr(opPtr.p->key);
- if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- // broken trigger allowed if force
- if (! (triggerPtr.p->triggerLocal & TriggerRecord::TL_CREATED_TC)) {
- jam();
- ndbrequire(opPtr.p->m_requestFlag & RequestFlag::RF_FORCE);
- alterTrigger_sendReply(signal, opPtr, false);
- return;
- }
- req->setRequestType(DropTrigReq::RT_TC);
- } else if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- // broken trigger allowed if force
- if (! (triggerPtr.p->triggerLocal & TriggerRecord::TL_CREATED_LQH)) {
- jam();
- ndbrequire(opPtr.p->m_requestFlag & RequestFlag::RF_FORCE);
- alterTrigger_sendReply(signal, opPtr, false);
- return;
- }
- req->setRequestType(DropTrigReq::RT_LQH);
- } else {
- ndbassert(false);
- }
- req->setTableId(triggerPtr.p->tableId);
- req->setIndexId(triggerPtr.p->indexId);
- req->setTriggerId(triggerPtr.i);
- req->setTriggerType(triggerPtr.p->triggerType);
- req->setTriggerActionTime(triggerPtr.p->triggerActionTime);
- req->setTriggerEvent(triggerPtr.p->triggerEvent);
- req->setMonitorReplicas(triggerPtr.p->monitorReplicas);
- req->setMonitorAllAttributes(triggerPtr.p->monitorAllAttributes);
- BlockReference blockRef = 0;
- if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- blockRef = calcTcBlockRef(getOwnNodeId());
- } else if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- blockRef = calcLqhBlockRef(getOwnNodeId());
- } else {
- ndbassert(false);
- }
- sendSignal(blockRef, GSN_DROP_TRIG_REQ,
- signal, DropTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::alterTrigger_fromDropLocal(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- if (! opPtr.p->hasLastError()) {
- // mark dropped locally
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, opPtr.p->m_request.getTriggerId());
- if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_TC) {
- jam();
- triggerPtr.p->triggerLocal &= ~TriggerRecord::TL_CREATED_TC;
- } else if (opPtr.p->m_requestType == AlterTrigReq::RT_DICT_LQH) {
- jam();
- triggerPtr.p->triggerLocal &= ~TriggerRecord::TL_CREATED_LQH;
- } else {
- ndbrequire(false);
- }
- }
- // forward CONF or REF to master
- alterTrigger_sendReply(signal, opPtr, false);
- }
- void
- Dbdict::alterTrigger_slaveCommit(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- TriggerRecordPtr triggerPtr;
- c_triggerRecordPool.getPtr(triggerPtr, opPtr.p->m_request.getTriggerId());
- // set state
- triggerPtr.p->triggerState = TriggerRecord::TS_ONLINE;
- }
- void
- Dbdict::alterTrigger_slaveAbort(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- jam();
- }
- void
- Dbdict::alterTrigger_sendSlaveReq(Signal* signal, OpAlterTriggerPtr opPtr)
- {
- AlterTrigReq* const req = (AlterTrigReq*)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);
- NdbNodeBitmask receiverNodes = c_aliveNodes;
- if (opPtr.p->m_requestFlag & RequestFlag::RF_LOCAL) {
- receiverNodes.clear();
- receiverNodes.set(getOwnNodeId());
- } else {
- opPtr.p->m_nodes.bitAND(receiverNodes);
- receiverNodes = opPtr.p->m_nodes;
- }
- opPtr.p->m_signalCounter = receiverNodes;
- NodeReceiverGroup rg(DBDICT, receiverNodes);
- sendSignal(rg, GSN_ALTER_TRIG_REQ,
- signal, AlterTrigReq::SignalLength, JBB);
- }
- void
- Dbdict::alterTrigger_sendReply(Signal* signal, OpAlterTriggerPtr opPtr,
- bool toUser)
- {
- jam();
- AlterTrigRef* rep = (AlterTrigRef*)signal->getDataPtrSend();
- Uint32 gsn = GSN_ALTER_TRIG_CONF;
- Uint32 length = AlterTrigConf::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 == AlterTrigReq::RT_DICT_ABORT) {
- jam();
- sendRef = false;
- } else {
- jam();
- }
- } else {
- sendRef = opPtr.p->hasError();
- jam();
- rep->setUserRef(opPtr.p->m_request.getUserRef());
- rep->setConnectionPtr(opPtr.p->m_request.getConnectionPtr());
- rep->setRequestType(opPtr.p->m_request.getRequestType());
- length = AlterTrigConf::SignalLength;
- }
- rep->setTableId(opPtr.p->m_request.getTableId());
- rep->setTriggerId(opPtr.p->m_request.getTriggerId());
- if (sendRef) {
- if (opPtr.p->m_errorNode == 0) {
- jam();
- opPtr.p->m_errorNode = getOwnNodeId();
- } else {
- jam();
- }
- rep->setErrorCode(opPtr.p->m_errorCode);
- rep->setErrorLine(opPtr.p->m_errorLine);
- rep->setErrorNode(opPtr.p->m_errorNode);
- gsn = GSN_ALTER_TRIG_REF;
- length = AlterTrigRef::SignalLength;
- }
- sendSignal(rep->getUserRef(), gsn, signal, length, JBB);
- }
- /**
- * MODULE: Support routines for index and trigger.
- */
- void
- Dbdict::getTableKeyList(TableRecordPtr tablePtr, AttributeList& list)
- {
- jam();
- list.sz = 0;
- for (Uint32 tAttr = tablePtr.p->firstAttribute; tAttr != RNIL; ) {
- AttributeRecord* aRec = c_attributeRecordPool.getPtr(tAttr);
- if (aRec->tupleKey)
- list.id[list.sz++] = aRec->attributeId;
- tAttr = aRec->nextAttrInTable;
- }
- }
- // XXX should store the primary attribute id
- void
- Dbdict::getIndexAttr(TableRecordPtr indexPtr, Uint32 itAttr, Uint32* id)
- {
- jam();
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, indexPtr.p->primaryTableId);
- AttributeRecord* iaRec = c_attributeRecordPool.getPtr(itAttr);
- for (Uint32 tAttr = tablePtr.p->firstAttribute; tAttr != RNIL; ) {
- AttributeRecord* aRec = c_attributeRecordPool.getPtr(tAttr);
- if (iaRec->equal(*aRec)) {
- id[0] = aRec->attributeId;
- return;
- }
- tAttr = aRec->nextAttrInTable;
- }
- ndbrequire(false);
- }
- void
- Dbdict::getIndexAttrList(TableRecordPtr indexPtr, AttributeList& list)
- {
- jam();
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, indexPtr.p->primaryTableId);
- list.sz = 0;
- memset(list.id, 0, sizeof(list.id));
- ndbrequire(indexPtr.p->noOfAttributes >= 2);
- Uint32 itAttr = indexPtr.p->firstAttribute;
- for (Uint32 i = 0; i < (Uint32)indexPtr.p->noOfAttributes - 1; i++) {
- getIndexAttr(indexPtr, itAttr, &list.id[list.sz++]);
- AttributeRecord* iaRec = c_attributeRecordPool.getPtr(itAttr);
- itAttr = iaRec->nextAttrInTable;
- }
- }
- void
- Dbdict::getIndexAttrMask(TableRecordPtr indexPtr, AttributeMask& mask)
- {
- jam();
- TableRecordPtr tablePtr;
- c_tableRecordPool.getPtr(tablePtr, indexPtr.p->primaryTableId);
- mask.clear();
- ndbrequire(indexPtr.p->noOfAttributes >= 2);
- Uint32 itAttr = indexPtr.p->firstAttribute;
- for (Uint32 i = 0; i < (Uint32)indexPtr.p->noOfAttributes - 1; i++) {
- Uint32 id;
- getIndexAttr(indexPtr, itAttr, &id);
- mask.set(id);
- AttributeRecord* iaRec = c_attributeRecordPool.getPtr(itAttr);
- itAttr = iaRec->nextAttrInTable;
- }
- }
- /* **************************************************************** */
- /* ---------------------------------------------------------------- */
- /* MODULE: STORE/RESTORE SCHEMA FILE---------------------- */
- /* ---------------------------------------------------------------- */
- /* */
- /* General module used to store the schema file on disk and */
- /* similar function to restore it from disk. */
- /* ---------------------------------------------------------------- */
- /* **************************************************************** */
- void
- Dbdict::initSchemaFile(SchemaFile * sf, Uint32 fileSz){
- memcpy(sf->Magic, "NDBSCHMA", sizeof(sf->Magic));
- sf->ByteOrder = 0x12345678;
- sf->NdbVersion = NDB_VERSION;
- sf->FileSize = fileSz;
- sf->CheckSum = 0;
-
- Uint32 headSz = (sizeof(SchemaFile)-sizeof(SchemaFile::TableEntry));
- Uint32 noEntries = (fileSz - headSz) / sizeof(SchemaFile::TableEntry);
- Uint32 slack = (fileSz - headSz) - noEntries * sizeof(SchemaFile::TableEntry);
-
- ndbrequire(noEntries > MAX_TABLES);
- sf->NoOfTableEntries = noEntries;
- memset(sf->TableEntries, 0, noEntries*sizeof(SchemaFile::TableEntry));
- memset(&(sf->TableEntries[noEntries]), 0, slack);
- computeChecksum(sf);
- }
- void
- Dbdict::computeChecksum(SchemaFile * sf){
- sf->CheckSum = 0;
- sf->CheckSum = computeChecksum((const Uint32*)sf, sf->FileSize/4);
- }
- bool
- Dbdict::validateChecksum(const SchemaFile * sf){
-
- Uint32 c = computeChecksum((const Uint32*)sf, sf->FileSize/4);
- return c == 0;
- }
- Uint32
- Dbdict::computeChecksum(const Uint32 * src, Uint32 len){
- Uint32 ret = 0;
- for(Uint32 i = 0; i<len; i++)
- ret ^= src[i];
- return ret;
- }
- SchemaFile::TableEntry *
- Dbdict::getTableEntry(void * p, Uint32 tableId, bool allowTooBig){
- SchemaFile * sf = (SchemaFile*)p;
-
- ndbrequire(allowTooBig || tableId < sf->NoOfTableEntries);
- return &sf->TableEntries[tableId];
- }
- // global metadata support
- int
- Dbdict::getMetaTablePtr(TableRecordPtr& tablePtr, Uint32 tableId, Uint32 tableVersion)
- {
- if (tableId >= c_tableRecordPool.getSize()) {
- return MetaData::InvalidArgument;
- }
- c_tableRecordPool.getPtr(tablePtr, tableId);
- if (tablePtr.p->tabState == TableRecord::NOT_DEFINED) {
- return MetaData::TableNotFound;
- }
- if (tablePtr.p->tableVersion != tableVersion) {
- return MetaData::InvalidTableVersion;
- }
- // online flag is not maintained by DICT
- tablePtr.p->online =
- tablePtr.p->isTable() &&
- (tablePtr.p->tabState == TableRecord::DEFINED ||
- tablePtr.p->tabState == TableRecord::BACKUP_ONGOING) ||
- tablePtr.p->isIndex() && tablePtr.p->indexState == TableRecord::IS_ONLINE;
- return 0;
- }
- int
- Dbdict::getMetaTable(MetaData::Table& table, Uint32 tableId, Uint32 tableVersion)
- {
- int ret;
- TableRecordPtr tablePtr;
- if ((ret = getMetaTablePtr(tablePtr, tableId, tableVersion)) < 0) {
- return ret;
- }
- new (&table) MetaData::Table(*tablePtr.p);
- return 0;
- }
- int
- Dbdict::getMetaTable(MetaData::Table& table, const char* tableName)
- {
- int ret;
- TableRecordPtr tablePtr;
- if (strlen(tableName) + 1 > MAX_TAB_NAME_SIZE) {
- return MetaData::InvalidArgument;
- }
- TableRecord keyRecord;
- strcpy(keyRecord.tableName, tableName);
- c_tableRecordHash.find(tablePtr, keyRecord);
- if (tablePtr.i == RNIL) {
- return MetaData::TableNotFound;
- }
- if ((ret = getMetaTablePtr(tablePtr, tablePtr.i, tablePtr.p->tableVersion)) < 0) {
- return ret;
- }
- new (&table) MetaData::Table(*tablePtr.p);
- return 0;
- }
- int
- Dbdict::getMetaAttribute(MetaData::Attribute& attr, const MetaData::Table& table, Uint32 attributeId)
- {
- int ret;
- TableRecordPtr tablePtr;
- if ((ret = getMetaTablePtr(tablePtr, table.tableId, table.tableVersion)) < 0) {
- return ret;
- }
- AttributeRecordPtr attrPtr;
- attrPtr.i = tablePtr.p->firstAttribute;
- while (attrPtr.i != RNIL) {
- c_attributeRecordPool.getPtr(attrPtr);
- if (attrPtr.p->attributeId == attributeId)
- break;
- attrPtr.i = attrPtr.p->nextAttrInTable;
- }
- if (attrPtr.i == RNIL) {
- return MetaData::AttributeNotFound;
- }
- new (&attr) MetaData::Attribute(*attrPtr.p);
- return 0;
- }
- int
- Dbdict::getMetaAttribute(MetaData::Attribute& attr, const MetaData::Table& table, const char* attributeName)
- {
- int ret;
- TableRecordPtr tablePtr;
- if ((ret = getMetaTablePtr(tablePtr, table.tableId, table.tableVersion)) < 0) {
- return ret;
- }
- AttributeRecordPtr attrPtr;
- attrPtr.i = tablePtr.p->firstAttribute;
- while (attrPtr.i != RNIL) {
- c_attributeRecordPool.getPtr(attrPtr);
- if (strcmp(attrPtr.p->attributeName, attributeName) == 0)
- break;
- attrPtr.i = attrPtr.p->nextAttrInTable;
- }
- if (attrPtr.i == RNIL) {
- return MetaData::AttributeNotFound;
- }
- new (&attr) MetaData::Attribute(*attrPtr.p);
- return 0;
- }