Пример #1
0
  @Override
  void completeInitiateTask(SiteProcedureConnection siteConnection) {
    CompleteTransactionMessage complete =
        new CompleteTransactionMessage(
            m_initiator.getHSId(), // who is the "initiator" now??
            m_initiator.getHSId(),
            m_txnState.txnId,
            m_txnState.isReadOnly(),
            m_txnState.getHash(),
            m_txnState.needsRollback(),
            false, // really don't want to have ack the ack.
            false,
            m_msg.isForReplay());

    complete.setTruncationHandle(m_msg.getTruncationHandle());
    complete.setOriginalTxnId(m_msg.getOriginalTxnId());
    m_initiator.send(com.google.common.primitives.Longs.toArray(m_initiatorHSIds), complete);
    m_txnState.setDone();
    m_queue.flush();
  }
Пример #2
0
  /** Run is invoked by a run-loop to execute this transaction. */
  @Override
  public void run(SiteProcedureConnection siteConnection) {
    hostLog.debug("STARTING: " + this);
    // Cast up. Could avoid ugliness with Iv2TransactionClass baseclass
    MpTransactionState txn = (MpTransactionState) m_txnState;
    // Check for restarting sysprocs
    String spName = txn.m_initiationMsg.getStoredProcedureName();

    // certain system procs can and can't be restarted
    // Right now this is adhoc and catalog update. Since these are treated specially
    // in a few places (here, recovery, dr), maybe we should add another metadata
    // property the sysproc registry about whether a proc can be restarted/recovered/dr-ed
    if (m_isRestart
        && spName.startsWith("@")
        && !spName.startsWith("@AdHoc")
        && !spName.equals("@UpdateApplicationCatalog")) {
      InitiateResponseMessage errorResp = new InitiateResponseMessage(txn.m_initiationMsg);
      errorResp.setResults(
          new ClientResponseImpl(
              ClientResponse.UNEXPECTED_FAILURE,
              new VoltTable[] {},
              "Failure while running system procedure "
                  + txn.m_initiationMsg.getStoredProcedureName()
                  + ", and system procedures can not be restarted."));
      txn.setNeedsRollback();
      completeInitiateTask(siteConnection);
      errorResp.m_sourceHSId = m_initiator.getHSId();
      m_initiator.deliver(errorResp);
      hostLog.debug("SYSPROCFAIL: " + this);
      return;
    }

    // Let's ensure that we flush any previous attempts of this transaction
    // at the masters we're going to try to use this time around.
    if (m_isRestart) {
      CompleteTransactionMessage restart =
          new CompleteTransactionMessage(
              m_initiator.getHSId(), // who is the "initiator" now??
              m_initiator.getHSId(),
              m_txnState.txnId,
              m_txnState.isReadOnly(),
              0,
              true,
              false, // really don't want to have ack the ack.
              !m_txnState.isReadOnly(),
              m_msg.isForReplay());

      restart.setTruncationHandle(m_msg.getTruncationHandle());
      restart.setOriginalTxnId(m_msg.getOriginalTxnId());
      m_initiator.send(com.google.common.primitives.Longs.toArray(m_initiatorHSIds), restart);
    }
    final InitiateResponseMessage response =
        processInitiateTask(txn.m_initiationMsg, siteConnection);
    // We currently don't want to restart read-only MP transactions because:
    // 1) We're not writing the Iv2InitiateTaskMessage to the first
    // FragmentTaskMessage in read-only case in the name of some unmeasured
    // performance impact,
    // 2) We don't want to perturb command logging and/or DR this close to the 3.0 release
    // 3) We don't guarantee the restarted results returned to the client
    // anyway, so not restarting the read is currently harmless.
    // We could actually restart this here, since we have the invocation, but let's be consistent?
    int status = response.getClientResponseData().getStatus();
    if (status != ClientResponse.TXN_RESTART
        || (status == ClientResponse.TXN_RESTART && m_msg.isReadOnly())) {
      if (!response.shouldCommit()) {
        txn.setNeedsRollback();
      }
      completeInitiateTask(siteConnection);
      // Set the source HSId (ugh) to ourselves so we track the message path correctly
      response.m_sourceHSId = m_initiator.getHSId();
      m_initiator.deliver(response);
      execLog.l7dlog(
          Level.TRACE, LogKeys.org_voltdb_ExecutionSite_SendingCompletedWUToDtxn.name(), null);
      hostLog.debug("COMPLETE: " + this);
    } else {
      restartTransaction();
      hostLog.debug("RESTART: " + this);
    }
  }