void NdbImpl::trp_deliver_signal()

in storage/ndb/src/ndbapi/Ndbif.cpp [398:1230]


void NdbImpl::trp_deliver_signal(const NdbApiSignal *aSignal,
                                 const LinearSectionPtr ptr[3]) {
  Ndb *myNdb = &m_ndb;
  int tReturnCode = -1;
  const Uint32 *tDataPtr = aSignal->getDataPtr();
  const Uint32 tSignalNumber = aSignal->readSignalNumber();
  Ndb::InitType tInitState = myNdb->theInitState;
  const Uint32 tFirstData = *tDataPtr;
  const Uint32 tLen = aSignal->getLength();
  Uint32 secs = aSignal->m_noOfSections;
  Uint32 bytesReceived =
      ((aSignal->getLength() << 2) + ((secs > 2) ? ptr[2].sz << 2 : 0) +
       ((secs > 1) ? ptr[1].sz << 2 : 0) + ((secs > 0) ? ptr[0].sz << 2 : 0));

  NdbOperation *tOp;
  NdbIndexOperation *tIndexOp;
  NdbTransaction *tCon;

  /* Check that Ndb object is properly setup to handle the signal */
  if (tInitState != Ndb::Initialised) return;

  void *tFirstDataPtr = int2void(tFirstData);
  const Uint32 tWaitState = theWaiter.get_state();
  Uint32 tNewState = tWaitState;

  /* Update cached Min Db node version */
  myNdb->theCachedMinDbNodeVersion =
      m_transporter_facade->getMinDbNodeVersion();

  if (likely(recordGSN(tSignalNumber))) {
    incClientStat(Ndb::BytesRecvdCount, bytesReceived);
  }

  /*
    In order to support 64 bit processes in the application we need to use
    id's rather than a direct pointer to the object used. It is also a good
    idea that one cannot corrupt the application code by sending a corrupt
    memory pointer.

    All traffic signals received by the API requires the first data word to be
    such an id to the receiving object.
  */

  switch (tSignalNumber) {
    case GSN_TCKEYCONF:
    case GSN_TCINDXCONF: {
      const auto *const keyConf = (const TcKeyConf *)tDataPtr;
      if (tFirstData != RNIL) {
        tCon = void2con(tFirstDataPtr);
      } else {
        tCon = lookupTransactionFromOperation(keyConf);
      }
      if (likely(tCon != nullptr)) {
        const Uint32 magicNumber = tCon->getMagicNumberFromObject();
        NdbTransaction::SendStatusType tSendStatus = tCon->theSendStatus;
        const BlockReference aTCRef = aSignal->theSendersBlockRef;
        const bool marker = TcKeyConf::getMarkerFlag(keyConf->confInfo);

        if (likely((magicNumber == tCon->getMagicNumber()) &&
                   (tSendStatus == NdbTransaction::sendTC_OP))) {
          tReturnCode = tCon->receiveTCKEYCONF(keyConf, tLen);
          /**
           * BUG#19643174
           * ------------
           * Ensure that we always send TC_COMMIT_ACK before we report
           * transaction as completed, this avoids races where the API
           * user starts another activity before we've completed the
           * sending of TC_COMMIT_ACK. This is mostly a problem for
           * test applications that e.g. want to check for memory
           * leaks after a transaction has completed. We only do this
           * action if requested by the API user (should only be
           * requested by test application).
           */
          if (unlikely(marker && send_TC_COMMIT_ACK_immediate_flag)) {
            NdbTransaction::sendTC_COMMIT_ACK(
                this, myNdb->theCommitAckSignal, keyConf->transId1,
                keyConf->transId2, aTCRef, send_TC_COMMIT_ACK_immediate_flag);
            if (tReturnCode != -1) {
              myNdb->completedTransaction(tCon);
            }
            return;
          }
          if (tReturnCode != -1) {
            myNdb->completedTransaction(tCon);
          }
          if (marker) {
            NdbTransaction::sendTC_COMMIT_ACK(this, myNdb->theCommitAckSignal,
                                              keyConf->transId1,
                                              keyConf->transId2, aTCRef, false);
          }
          return;
        }
      }
      const bool marker = TcKeyConf::getMarkerFlag(keyConf->confInfo);
      const BlockReference aTCRef = aSignal->theSendersBlockRef;
      if (marker) {
        /**
         * We must send the TC_COMMIT_ACK even if we "reject" signal!
         */
        NdbTransaction::sendTC_COMMIT_ACK(
            this, myNdb->theCommitAckSignal, keyConf->transId1,
            keyConf->transId2, aTCRef, send_TC_COMMIT_ACK_immediate_flag);
      }
      goto InvalidSignal;
      return;
    }
    case GSN_TRANSID_AI: {
      if (likely(tFirstDataPtr != nullptr)) {
        NdbReceiver *const tRec = void2rec(tFirstDataPtr);
        Uint32 magicNumber = tRec->getMagicNumberFromObject();
        Uint32 num_sections = aSignal->m_noOfSections;
        NdbReceiver::ReceiverType type = tRec->getType();

        if (unlikely(magicNumber != tRec->getMagicNumber())) {
#ifdef NDB_NO_DROPPED_SIGNAL
          abort();
#endif
          return;
        }
        tCon = tRec->getTransaction(type);
        if (likely(((tCon != nullptr) &&
                    tCon->checkState_TransId(
                        ((const TransIdAI *)tDataPtr)->transId)))) {
          void *owner = (void *)tRec->getOwner();
          Uint32 com;
          if (num_sections > 0) {
            if (type == NdbReceiver::NDB_QUERY_OPERATION) {
              auto *impl_owner = (NdbQueryOperationImpl *)owner;
              com = impl_owner->execTRANSID_AI(ptr[0].p, ptr[0].sz);
            } else {
              com = tRec->execTRANSID_AI(ptr[0].p, ptr[0].sz);
            }
          } else {
            DBUG_EXECUTE_IF("ndb_delay_transid_ai", {
              fprintf(stderr,
                      "NdbImpl::trp_deliver_signal() (%p)"
                      " taking a break before TRANSID_AI\n",
                      this);
              NdbSleep_MilliSleep(1000);
              fprintf(stderr, "NdbImpl::trp_deliver_signal() resuming\n");
            });

            /**
             * Note that prior to V7.6.2 we assumed that all 'QUERY'
             * results were returned as 'long' signals. The version
             * check ndbd_spj_api_support_short_TRANSID_AI() function
             * has been added to allow the sender to check if the
             * QUERY-receiver support short (and 'packed') TRANSID_AI.
             */
            if (type == NdbReceiver::NDB_QUERY_OPERATION) {
              auto *impl_owner = (NdbQueryOperationImpl *)owner;
              com =
                  impl_owner->execTRANSID_AI(tDataPtr + TransIdAI::HeaderLength,
                                             tLen - TransIdAI::HeaderLength);
            } else {
              com = tRec->execTRANSID_AI(tDataPtr + TransIdAI::HeaderLength,
                                         tLen - TransIdAI::HeaderLength);
            }
          }
          {
            BlockReference ref = aSignal->theSendersBlockRef;
            NodeId dbNode = tCon->theDBnode;
            NodeId senderNode = refToNode(ref);
            incClientStat(Ndb::ReadRowCount, 1);
            if (senderNode == dbNode) {
              incClientStat(Ndb::TransLocalReadRowCount, 1);
            }
          }
          if (com == 0) {
            return;
          }
          switch (type) {
            case NdbReceiver::NDB_OPERATION:
            case NdbReceiver::NDB_INDEX_OPERATION: {
              if (tCon->OpCompleteSuccess() !=
                  -1) {  // More completions pending?
                myNdb->completedTransaction(tCon);
              }
              return;
            }
            case NdbReceiver::NDB_SCANRECEIVER: {
              tCon->theScanningOp->receiver_delivered(tRec);
              tNewState =
                  (((WaitSignalType)tWaitState) == WAIT_SCAN ? (Uint32)NO_WAIT
                                                             : tWaitState);
              break;
            }
            case NdbReceiver::NDB_QUERY_OPERATION: {
              // Handled differently whether it is a scan or lookup
              auto *impl_owner = (NdbQueryOperationImpl *)owner;
              if (impl_owner->getQueryDef().isScanQuery()) {
                tNewState =
                    (((WaitSignalType)tWaitState) == WAIT_SCAN ? (Uint32)NO_WAIT
                                                               : tWaitState);
                break;
              }
              if (tCon->OpCompleteSuccess() !=
                  -1) {  // More completions pending?
                myNdb->completedTransaction(tCon);
              }
              return;
            }
            default: {
              goto InvalidSignal;
            }
          }
          break;
        }
        /**
         * This is ok as transaction can have been aborted before TRANSID_AI
         * arrives (if TUP on  other node than TC)
         */
        return;
      }
      return;
    }
    case GSN_SCAN_TABCONF: {
      tCon = void2con(tFirstDataPtr);
      if (unlikely(tFirstDataPtr == nullptr)) {
        goto InvalidSignal;
      }
      Uint32 magicNumber = tCon->getMagicNumberFromObject();
      Uint32 num_sections = aSignal->m_noOfSections;
      Uint32 sz;
      const Uint32 *sig_ptr;

      if (unlikely(magicNumber != tCon->getMagicNumber())) {
        goto InvalidSignal;
      }
      if (num_sections > 0) {
        sig_ptr = ptr[0].p;
        sz = ptr[0].sz;
      } else {
        sig_ptr = tDataPtr + ScanTabConf::SignalLength,
        sz = tLen - ScanTabConf::SignalLength;
      }
      tReturnCode = tCon->receiveSCAN_TABCONF(aSignal, sig_ptr, sz);
      if (tReturnCode != -1 && tWaitState == WAIT_SCAN) {
        tNewState = NO_WAIT;
      }
      break;
    }
    case GSN_TC_COMMITCONF: {
      const auto *const commitConf = (const TcCommitConf *)tDataPtr;
      const BlockReference aTCRef = aSignal->theSendersBlockRef;

      if (tFirstDataPtr == nullptr) {
        goto invalid0;
      }
      tCon = void2con(tFirstDataPtr);
      if ((tCon->checkMagicNumber() == 0) &&
          (tCon->theSendStatus == NdbTransaction::sendTC_COMMIT)) {
        tReturnCode = tCon->receiveTC_COMMITCONF(commitConf, tLen);
        if (unlikely((tFirstData & 1) && send_TC_COMMIT_ACK_immediate_flag)) {
          NdbTransaction::sendTC_COMMIT_ACK(this, myNdb->theCommitAckSignal,
                                            commitConf->transId1,
                                            commitConf->transId2, aTCRef, true);
          if (tReturnCode != -1) {
            myNdb->completedTransaction(tCon);
          }
          return;
        }
        if (tReturnCode != -1) {
          myNdb->completedTransaction(tCon);
        }
        if (tFirstData & 1) {
          NdbTransaction::sendTC_COMMIT_ACK(
              this, myNdb->theCommitAckSignal, commitConf->transId1,
              commitConf->transId2, aTCRef, false);
        }
        return;
      }
    invalid0:
      if (tFirstData & 1) {
        /**
         * We must send TC_COMMIT_ACK regardless if we "reject" signal!
         */
        NdbTransaction::sendTC_COMMIT_ACK(
            this, myNdb->theCommitAckSignal, commitConf->transId1,
            commitConf->transId2, aTCRef, send_TC_COMMIT_ACK_immediate_flag);
      }
      goto InvalidSignal;
      return;
    }
    case GSN_TCROLLBACKCONF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if ((tCon->checkMagicNumber() == 0) &&
          (tCon->theSendStatus == NdbTransaction::sendTC_ROLLBACK)) {
        tReturnCode = tCon->receiveTCROLLBACKCONF(aSignal);
        if (tReturnCode != -1) {
          myNdb->completedTransaction(tCon);
        }
      }
      return;
    }
    case GSN_KEYINFO20: {
      NdbReceiver *tRec;
      if (tFirstDataPtr && (tRec = void2rec(tFirstDataPtr)) &&
          tRec->checkMagicNumber() &&
          (tCon = tRec->getTransaction(tRec->getType())) &&
          tCon->checkState_TransId(&((const KeyInfo20 *)tDataPtr)->transId1)) {
        Uint32 len = ((const KeyInfo20 *)tDataPtr)->keyLen;
        Uint32 info = ((const KeyInfo20 *)tDataPtr)->scanInfo_Node;
        int com = -1;
        if (aSignal->m_noOfSections > 0 && len == ptr[0].sz) {
          com = tRec->execKEYINFO20(info, ptr[0].p, len);
        } else if (len == tLen - KeyInfo20::HeaderLength) {
          com = tRec->execKEYINFO20(info, tDataPtr + KeyInfo20::HeaderLength,
                                    len);
        }

        switch (com) {
          case 1:
            tCon->theScanningOp->receiver_delivered(tRec);
            tNewState =
                (((WaitSignalType)tWaitState) == WAIT_SCAN ? (Uint32)NO_WAIT
                                                           : tWaitState);
            break;
          case 0:
            break;
          case -1:
            goto InvalidSignal;
        }
        break;
      }
      /**
       * This is ok as transaction can have been aborted before KEYINFO20
       * arrives (if TUP on  other node than TC)
       */
      return;
    }
    case GSN_TCKEYREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      const NdbReceiver *const receiver = void2rec(tFirstDataPtr);
      if (!receiver->checkMagicNumber()) {
        goto InvalidSignal;
      }
      tCon = receiver->getTransaction(receiver->getType());
      if (tCon != nullptr) {
        if (tCon->theSendStatus == NdbTransaction::sendTC_OP) {
          if (receiver->getType() == NdbReceiver::NDB_QUERY_OPERATION) {
            auto *tmp = (NdbQueryOperationImpl *)(receiver->m_owner);
            if (tmp->execTCKEYREF(aSignal) && tCon->OpCompleteFailure() != -1) {
              myNdb->completedTransaction(tCon);
              return;
            }
          } else {
            tOp = (NdbOperation *)(receiver->getOwner());
            /* NB! NdbOperation::checkMagicNumber() returns 0 if it *is*
             * an NdbOperation.*/
            if (tOp->checkMagicNumber() != 0) goto InvalidSignal;
            tReturnCode = tOp->receiveTCKEYREF(aSignal);
            if (tReturnCode != -1) {
              myNdb->completedTransaction(tCon);
              return;
            }  // if
          }    // if
          break;
        }
      }
      goto InvalidSignal;
      return;
    }
    case GSN_TCINDXREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      const NdbReceiver *const receiver = void2rec(tFirstDataPtr);
      if (!receiver->checkMagicNumber()) {
        goto InvalidSignal;
      }
      tIndexOp = (NdbIndexOperation *)(receiver->getOwner());
      if (tIndexOp->checkMagicNumber() == 0) {
        tCon = tIndexOp->theNdbCon;
        if (tCon != nullptr) {
          if (tCon->theSendStatus == NdbTransaction::sendTC_OP) {
            tReturnCode = tIndexOp->receiveTCINDXREF(aSignal);
            if (tReturnCode != -1) {
              myNdb->completedTransaction(tCon);
            }
            return;
          }
        }
      }
      goto InvalidSignal;
      return;
    }
    case GSN_TC_COMMITREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if ((tCon->checkMagicNumber() == 0) &&
          (tCon->theSendStatus == NdbTransaction::sendTC_COMMIT)) {
        tReturnCode = tCon->receiveTC_COMMITREF(aSignal);
        if (tReturnCode != -1) {
          myNdb->completedTransaction(tCon);
        }
      }
      return;
    }
    case GSN_TCROLLBACKREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if ((tCon->checkMagicNumber() == 0) &&
          (tCon->theSendStatus == NdbTransaction::sendTC_ROLLBACK)) {
        tReturnCode = tCon->receiveTCROLLBACKREF(aSignal);
        if (tReturnCode != -1) {
          myNdb->completedTransaction(tCon);
        }
      }
      return;
    }
    case GSN_TCROLLBACKREP: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if (tCon->checkMagicNumber() == 0) {
        tReturnCode = tCon->receiveTCROLLBACKREP(aSignal);
        if (tReturnCode != -1) {
          myNdb->completedTransaction(tCon);
        }
      }
      return;
    }
    case GSN_SCAN_TABREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if (tCon->checkMagicNumber() == 0) {
        tReturnCode = tCon->receiveSCAN_TABREF(aSignal);
        if (tReturnCode != -1 && tWaitState == WAIT_SCAN) {
          tNewState = NO_WAIT;
        }
        break;
      }
      goto InvalidSignal;
    }
    case GSN_TCSEIZECONF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      if (tWaitState != WAIT_TC_SEIZE) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if (tCon->checkMagicNumber() != 0) {
        goto InvalidSignal;
      }
      tReturnCode = tCon->receiveTCSEIZECONF(aSignal);
      if (tReturnCode != -1) {
        tNewState = NO_WAIT;
      } else {
        goto InvalidSignal;
      }
      break;
    }
    case GSN_TCSEIZEREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      if (tWaitState != WAIT_TC_SEIZE) {
        return;
      }
      tCon = void2con(tFirstDataPtr);
      if (tCon->checkMagicNumber() != 0) {
        return;
      }
      tReturnCode = tCon->receiveTCSEIZEREF(aSignal);
      if (tReturnCode != -1) {
        tNewState = NO_WAIT;
      } else {
        return;
      }
      break;
    }
    case GSN_TCRELEASECONF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      if (tWaitState != WAIT_TC_RELEASE) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if (tCon->checkMagicNumber() != 0) {
        goto InvalidSignal;
      }
      tReturnCode = tCon->receiveTCRELEASECONF(aSignal);
      if (tReturnCode != -1) {
        tNewState = NO_WAIT;
      }
      break;
    }
    case GSN_TCRELEASEREF: {
      if (tFirstDataPtr == nullptr) {
        goto InvalidSignal;
      }
      if (tWaitState != WAIT_TC_RELEASE) {
        goto InvalidSignal;
      }
      tCon = void2con(tFirstDataPtr);
      if (tCon->checkMagicNumber() != 0) {
        goto InvalidSignal;
      }
      tReturnCode = tCon->receiveTCRELEASEREF(aSignal);
      if (tReturnCode != -1) {
        tNewState = NO_WAIT;
      }
      break;
    }
    case GSN_TCKEY_FAILCONF: {
      const auto *failConf = (const TcKeyFailConf *)tDataPtr;
      const BlockReference aTCRef = aSignal->theSendersBlockRef;
      if (tFirstDataPtr != nullptr) {
        const NdbReceiver *const receiver = void2rec(tFirstDataPtr);
        if (!receiver->checkMagicNumber()) {
          goto InvalidSignal;
        }
        tOp = (NdbOperation *)(receiver->getOwner());
        if (tOp->checkMagicNumber(false) == 0) {
          tCon = tOp->theNdbCon;
          if (tCon != nullptr) {
            if ((tCon->theSendStatus == NdbTransaction::sendTC_OP) ||
                (tCon->theSendStatus == NdbTransaction::sendTC_COMMIT)) {
              tReturnCode = tCon->receiveTCKEY_FAILCONF(failConf);
              if (tFirstData & 1) {
                NdbTransaction::sendTC_COMMIT_ACK(
                    this, myNdb->theCommitAckSignal, failConf->transId1,
                    failConf->transId2, aTCRef,
                    send_TC_COMMIT_ACK_immediate_flag);
              }
              if (tReturnCode != -1) {
                myNdb->completedTransaction(tCon);
              }
              return;
            }
          }
        }
      } else {
#ifdef VM_TRACE
        g_eventLogger->info("Received TCKEY_FAILCONF wo/ operation");
#endif
      }
      if (tFirstData & 1) {
        NdbTransaction::sendTC_COMMIT_ACK(
            this, myNdb->theCommitAckSignal, failConf->transId1,
            failConf->transId2, aTCRef, send_TC_COMMIT_ACK_immediate_flag);
      }
      return;
    }
    case GSN_TCKEY_FAILREF: {
      if (tFirstDataPtr != nullptr) {
        const NdbReceiver *const receiver = void2rec(tFirstDataPtr);
        if (!receiver->checkMagicNumber()) {
          goto InvalidSignal;
        }
        tOp = (NdbOperation *)(receiver->getOwner());
        if (tOp->checkMagicNumber(false) == 0) {
          tCon = tOp->theNdbCon;
          if (tCon != nullptr) {
            if ((tCon->theSendStatus == NdbTransaction::sendTC_OP) ||
                (tCon->theSendStatus == NdbTransaction::sendTC_ROLLBACK)) {
              tReturnCode = tCon->receiveTCKEY_FAILREF(aSignal);
              if (tReturnCode != -1) {
                myNdb->completedTransaction(tCon);
                return;
              }
            }
          }
        }
      }
#ifdef VM_TRACE
      g_eventLogger->info("Received TCKEY_FAILREF wo/ operation");
#endif
      return;
    }
    case GSN_CLOSE_COMREQ: {
      m_transporter_facade->perform_close_clnt(this);
      break;
    }
    case GSN_GET_TABINFOREF:
    case GSN_GET_TABINFO_CONF:
    case GSN_CREATE_TABLE_REF:
    case GSN_CREATE_TABLE_CONF:
    case GSN_DROP_TABLE_CONF:
    case GSN_DROP_TABLE_REF:
    case GSN_ALTER_TABLE_CONF:
    case GSN_ALTER_TABLE_REF:
    case GSN_CREATE_INDX_CONF:
    case GSN_CREATE_INDX_REF:
    case GSN_DROP_INDX_CONF:
    case GSN_DROP_INDX_REF:
    case GSN_INDEX_STAT_CONF:
    case GSN_INDEX_STAT_REF:
    case GSN_CREATE_EVNT_CONF:
    case GSN_CREATE_EVNT_REF:
    case GSN_DROP_EVNT_CONF:
    case GSN_DROP_EVNT_REF:
    case GSN_LIST_TABLES_CONF:
    case GSN_CREATE_FILE_REF:
    case GSN_CREATE_FILE_CONF:
    case GSN_CREATE_FILEGROUP_REF:
    case GSN_CREATE_FILEGROUP_CONF:
    case GSN_DROP_FILE_REF:
    case GSN_DROP_FILE_CONF:
    case GSN_DROP_FILEGROUP_REF:
    case GSN_DROP_FILEGROUP_CONF:
    case GSN_SCHEMA_TRANS_BEGIN_CONF:
    case GSN_SCHEMA_TRANS_BEGIN_REF:
    case GSN_SCHEMA_TRANS_END_CONF:
    case GSN_SCHEMA_TRANS_END_REF:
    case GSN_SCHEMA_TRANS_END_REP:
    case GSN_WAIT_GCP_CONF:
    case GSN_WAIT_GCP_REF:
    case GSN_CREATE_HASH_MAP_REF:
    case GSN_CREATE_HASH_MAP_CONF:
    case GSN_CREATE_FK_REF:
    case GSN_CREATE_FK_CONF:
    case GSN_DROP_FK_REF:
    case GSN_DROP_FK_CONF: {
      NdbDictInterface::execSignal(&myNdb->theDictionary->m_receiver, aSignal,
                                   ptr);
      return;
    }
    case GSN_SUB_REMOVE_CONF:
    case GSN_SUB_REMOVE_REF: {
      return;  // ignore these signals
    }
    case GSN_SUB_START_CONF:
    case GSN_SUB_START_REF:
    case GSN_SUB_STOP_CONF:
    case GSN_SUB_STOP_REF: {
      const Uint64 latestGCI = myNdb->getLatestGCI();
      NdbDictInterface::execSignal(&myNdb->theDictionary->m_receiver, aSignal,
                                   ptr);
      if (tWaitState == WAIT_EVENT && myNdb->getLatestGCI() != latestGCI) {
        tNewState = NO_WAIT;
        break;
      }
      return;
    }
    case GSN_SUB_GCP_COMPLETE_REP: {
      /* SUB_GCP_COMPLETE_REP signal will not be fragmented but must check if
       * there is some fragmented data event ongoing to guarantee correct signal
       * order from Suma.
       */
      const Uint32 sender_node = aSignal->get_sender_node();
      if (unlikely(m_suma_fragmented_signals[sender_node].is_in_progress())) {
        drop_batched_fragments(&m_suma_fragmented_signals[sender_node]);
      }

      const Uint64 latestGCI = myNdb->getLatestGCI();
      const auto *const rep =
          CAST_CONSTPTR(SubGcpCompleteRep, aSignal->getDataPtr());
      myNdb->theEventBuffer->execSUB_GCP_COMPLETE_REP(rep, tLen);
      if (tWaitState == WAIT_EVENT && myNdb->getLatestGCI() != latestGCI) {
        tNewState = NO_WAIT;
        break;
      }
      return;
    }
    case GSN_SUB_TABLE_DATA: {
      NdbApiSignal copy_signal(BlockReference(0));
      LinearSectionPtr copy_ptr[3];

      for (int i = 0; i < aSignal->m_noOfSections; i++) {
        copy_ptr[i] = ptr[i];
      }
      for (int i = aSignal->m_noOfSections; i < 3; i++) {
        copy_ptr[i].p = nullptr;
        copy_ptr[i].sz = 0;
      }

      const auto *sdata = CAST_CONSTPTR(SubTableData, aSignal->getDataPtr());

      const Uint32 oid = sdata->senderData;
      auto *op = (NdbEventOperationImpl *)int2void(oid);
      if (unlikely(op == nullptr ||
                   op->m_magic_number != NDB_EVENT_OP_MAGIC_NUMBER)) {
        g_eventLogger->error(
            "Dropped GSN_SUB_TABLE_DATA due to wrong magic "
            "number");
        DBUG_EXECUTE_IF("ndb_crash_on_drop_SUB_TABLE_DATA", DBUG_SUICIDE(););
        return;
      }

      const Uint32 event = SubTableData::getOperation(sdata->requestInfo);
      const bool is_data_event =
          event < NdbDictionary::Event::_TE_FIRST_NON_DATA_EVENT;
      bool do_cleanup = false;

      const Uint32 sender_node = aSignal->get_sender_node();

      if (unlikely(!is_data_event)) {
        if (m_suma_fragmented_signals[sender_node].is_in_progress()) {
          drop_batched_fragments(&m_suma_fragmented_signals[sender_node]);
        }

        const bool is_alter_event = event == NdbDictionary::Event::_TE_ALTER;
        if (is_alter_event) {
          if (!op->execSUB_TABLE_DATA(aSignal, copy_ptr)) {
            return;
          }
        }
      } else {
        copy_signal = *aSignal;
        Int32 num_secs = assemble_data_event_signal(
            &m_suma_fragmented_signals[sender_node], &copy_signal, copy_ptr);
        if (num_secs < 0) {
          // Need more fragments.
          return;
        }

        /* num_secs == 0 is in the case the signal was not fragmented which we
         * take as the fast path.  Note that in this case the number of sections
         * for is unchanged by assemble and is still likely more than 0.
         */
        if (unlikely(num_secs > 0)) {
          aSignal = &copy_signal;
          for (int i = num_secs; i < 3; i++) {
            copy_ptr[i].p = nullptr;
            copy_ptr[i].sz = 0;
          }
          do_cleanup = true;
        }
        sdata = CAST_CONSTPTR(SubTableData, aSignal->getDataPtr());
        require(oid == sdata->senderData);
      }

      DBUG_PRINT(
          "info",
          ("oid=senderData: %d, gci{hi/lo}: %d/%d, operation: %d, "
           "tableId: %d",
           sdata->senderData, sdata->gci_hi, sdata->gci_lo,
           SubTableData::getOperation(sdata->requestInfo), sdata->tableId));

      myNdb->theEventBuffer->insertDataL(op, sdata, tLen, copy_ptr);
      if (do_cleanup) {
        m_suma_fragmented_signals[sender_node].cleanup();
      }
      return;
    }
    case GSN_API_REGCONF:
    case GSN_CONNECT_REP: {
      return;  // Ignore
    }
    case GSN_NODE_FAILREP: {
      const auto *rep = CAST_CONSTPTR(NodeFailRep, aSignal->getDataPtr());
      Uint32 len = NodeFailRep::getNodeMaskLength(aSignal->getLength());
      const Uint32 *nbm;
      if (aSignal->m_noOfSections >= 1) {
        assert(len == 0);
        nbm = ptr[0].p;
        len = ptr[0].sz;
      } else {
        assert(len == NodeBitmask::Size);  // only full length in ndbapi
        nbm = rep->theAllNodes;
      }
      for (Uint32 i = BitmaskImpl::find_first(len, nbm);
           i != BitmaskImpl::NotFound;
           i = BitmaskImpl::find_next(len, nbm, i + 1)) {
        if (i <= MAX_DATA_NODE_ID) {
          // Ndbif only cares about data-nodes (so far??)
          myNdb->report_node_failure(i);
        }
      }

      NdbDictInterface::execSignal(&myNdb->theDictionary->m_receiver, aSignal,
                                   ptr);
      break;
    }
    case GSN_NF_COMPLETEREP: {
      const auto *rep = CAST_CONSTPTR(NFCompleteRep, aSignal->getDataPtr());
      myNdb->report_node_failure_completed(rep->failedNodeId);
      break;
    }
    case GSN_TAKE_OVERTCCONF: {
      myNdb->abortTransactionsAfterNodeFailure(tFirstData);  // theData[0]
      break;
    }
    case GSN_ALLOC_NODEID_CONF: {
      const auto *rep = CAST_CONSTPTR(AllocNodeIdConf, aSignal->getDataPtr());
      Uint32 nodeId = rep->nodeId;
      myNdb->connected(numberToRef(myNdb->theNdbBlockNumber, nodeId));
      break;
    }
    default: {
      tFirstDataPtr = nullptr;
      goto InvalidSignal;
    }
  }  // switch

  if (tNewState != tWaitState) {
    /*
      If our waiter object is the owner of the "poll rights", then we
      can simply return, we will return from this routine to the
      place where external_poll was called. From there it will move
      the "poll ownership" to a new thread if available.

      If our waiter object doesn't own the "poll rights", then we must
      signal the thread from where this waiter object called
      its conditional wait. This will wake up this thread so that it
      can continue its work.
    */
    theWaiter.signal(tNewState);
  }
  return;

InvalidSignal:
#ifdef VM_TRACE
  g_eventLogger->warning(
      "Ndbif: Error Invalid Signal received NdbImpl::trp_deliver_signal "
      "(tFirstDataPtr=%p, GSN=%d, theWaiter.m_state=%d)"
      " sender = (Block: %d Node: %d)",
      tFirstDataPtr, tSignalNumber, tWaitState,
      refToBlock(aSignal->theSendersBlockRef),
      refToNode(aSignal->theSendersBlockRef));
#endif
#ifdef NDB_NO_DROPPED_SIGNAL
  abort();
#endif

  return;
}