Search in sources :

Example 1 with InitiateResponseMessage

use of org.voltdb.messaging.InitiateResponseMessage in project voltdb by VoltDB.

the class MpProcedureTask method run.

/** Run is invoked by a run-loop to execute this transaction. */
@Override
public void run(SiteProcedureConnection siteConnection) {
    // Thread name has to be materialized here
    final String threadName = Thread.currentThread().getName();
    final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.MPSITE);
    if (traceLog != null) {
        traceLog.add(() -> VoltTrace.meta("thread_name", "name", threadName)).add(() -> VoltTrace.meta("thread_sort_index", "sort_index", Integer.toString(1000))).add(() -> VoltTrace.beginDuration("mpinittask", "txnId", TxnEgo.txnIdToString(getTxnId())));
    }
    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();
    // restarted, the run() method is not rerun. Let the elastic join coordinator reissue it.
    if (m_isRestart && spName.startsWith("@") && !spName.startsWith("@AdHoc") && !spName.startsWith("@LoadMultipartitionTable") && !spName.equals("@UpdateCore") && !spName.equals("@ApplyBinaryLogMP")) {
        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(true);
        completeInitiateTask(siteConnection);
        errorResp.m_sourceHSId = m_initiator.getHSId();
        m_initiator.deliver(errorResp);
        hostLog.debug("SYSPROCFAIL: " + this);
        return;
    }
    // at the masters we're going to try to use this time around.
    if (m_isRestart) {
        CompleteTransactionMessage restart = new CompleteTransactionMessage(// who is the "initiator" now??
        m_initiator.getHSId(), m_initiator.getHSId(), m_txnState.txnId, m_txnState.isReadOnly(), 0, true, // really don't want to have ack the ack.
        false, !m_txnState.isReadOnly(), m_msg.isForReplay());
        restart.setTruncationHandle(m_msg.getTruncationHandle());
        m_initiator.send(com.google_voltpatches.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(true);
        }
        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);
    }
    if (traceLog != null) {
        traceLog.add(VoltTrace::endDuration);
    }
}
Also used : VoltTrace(org.voltdb.utils.VoltTrace) CompleteTransactionMessage(org.voltdb.messaging.CompleteTransactionMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 2 with InitiateResponseMessage

use of org.voltdb.messaging.InitiateResponseMessage in project voltdb by VoltDB.

the class SpProcedureTask method run.

/** Run is invoked by a run-loop to execute this transaction. */
@Override
public void run(SiteProcedureConnection siteConnection) {
    LatencyWatchdog.pet();
    waitOnDurabilityBackpressureFuture();
    if (HOST_DEBUG_ENABLED) {
        hostLog.debug("STARTING: " + this);
    }
    final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.SPI);
    if (traceLog != null) {
        traceLog.add(() -> VoltTrace.beginDuration("runsptask", "txnId", TxnEgo.txnIdToString(getTxnId()), "partition", Integer.toString(siteConnection.getCorrespondingPartitionId())));
    }
    if (!m_txnState.isReadOnly()) {
        m_txnState.setBeginUndoToken(siteConnection.getLatestUndoToken());
    }
    // cast up here .. ugly.
    SpTransactionState txnState = (SpTransactionState) m_txnState;
    InitiateResponseMessage response;
    int originalTimeout = siteConnection.getBatchTimeout();
    int individualTimeout = m_txnState.getInvocation().getBatchTimeout();
    try {
        // run the procedure with a specific individual timeout
        if (BatchTimeoutOverrideType.isUserSetTimeout(individualTimeout)) {
            siteConnection.setBatchTimeout(individualTimeout);
        }
        response = processInitiateTask(txnState.m_initiationMsg, siteConnection);
    } finally {
        // reset the deployment timeout value back to its original value
        if (BatchTimeoutOverrideType.isUserSetTimeout(individualTimeout)) {
            siteConnection.setBatchTimeout(originalTimeout);
        }
    }
    if (!response.shouldCommit()) {
        m_txnState.setNeedsRollback(true);
    }
    completeInitiateTask(siteConnection);
    response.m_sourceHSId = m_initiator.getHSId();
    m_initiator.deliver(response);
    if (EXEC_TRACE_ENABLED) {
        execLog.l7dlog(Level.TRACE, LogKeys.org_voltdb_ExecutionSite_SendingCompletedWUToDtxn.name(), null);
    }
    if (HOST_DEBUG_ENABLED) {
        hostLog.debug("COMPLETE: " + this);
    }
    if (traceLog != null) {
        traceLog.add(VoltTrace::endDuration);
    }
    logToDR(siteConnection.getDRGateway(), txnState, response);
}
Also used : VoltTrace(org.voltdb.utils.VoltTrace) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage)

Example 3 with InitiateResponseMessage

use of org.voltdb.messaging.InitiateResponseMessage in project voltdb by VoltDB.

the class TestSpSchedulerDedupe method testReplicaInitiateTaskResponseShortCircuitRead.

@Test
public void testReplicaInitiateTaskResponseShortCircuitRead() throws Exception {
    // replica does not receive reads on SAFE mode, except for FAST mode
    m_readLevel = Consistency.ReadLevel.FAST;
    long txnid = TxnEgo.makeZero(0).getTxnId();
    createObjs();
    Iv2InitiateTaskMessage sptask = createMsg(txnid, true, true, dut_hsid);
    sptask.setSpHandle(txnid);
    dut.deliver(sptask);
    // verify no response sent yet
    verify(mbox, times(0)).send(anyLong(), (VoltMessage) anyObject());
    verify(mbox, times(0)).send(new long[] { anyLong() }, (VoltMessage) anyObject());
    InitiateResponseMessage resp = new InitiateResponseMessage(sptask);
    dut.deliver(resp);
    verify(mbox, times(1)).send(eq(dut_hsid), eq(resp));
    m_readLevel = Consistency.ReadLevel.SAFE;
}
Also used : Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) Test(org.junit.Test)

Example 4 with InitiateResponseMessage

use of org.voltdb.messaging.InitiateResponseMessage in project voltdb by VoltDB.

the class ProcedureRunnerNT method call.

/**
     * Synchronous call to NT procedure run(..) method.
     *
     * Wraps coreCall with statistics.
     *
     * @return True if done and null if there is an
     * async task still running.
     */
protected boolean call(Object... paramListIn) {
    m_perCallStats = m_statsCollector.beginProcedure();
    // if we're keeping track, calculate parameter size
    if (m_perCallStats.samplingProcedure()) {
        ParameterSet params = ParameterSet.fromArrayNoCopy(paramListIn);
        m_perCallStats.setParameterSize(params.getSerializedSize());
    }
    ClientResponseImpl response = coreCall(paramListIn);
    // null response means this procedure isn't over and has some async component
    if (response == null) {
        return false;
    }
    // if we're keeping track, calculate result size
    if (m_perCallStats.samplingProcedure()) {
        m_perCallStats.setResultSize(response.getResults());
    }
    m_statsCollector.endProcedure(response.getStatus() == ClientResponse.USER_ABORT, (response.getStatus() != ClientResponse.USER_ABORT) && (response.getStatus() != ClientResponse.SUCCESS), m_perCallStats);
    // send the response to caller
    // must be done as IRM to CI mailbox for backpressure accounting
    response.setClientHandle(m_clientHandle);
    InitiateResponseMessage irm = InitiateResponseMessage.messageForNTProcResponse(m_ciHandle, m_ccxn.connectionId(), response);
    m_mailbox.deliver(irm);
    // remove record of this procedure in NTPS
    // only done if procedure is really done
    m_ntProcService.handleNTProcEnd(this);
    return true;
}
Also used : InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage)

Example 5 with InitiateResponseMessage

use of org.voltdb.messaging.InitiateResponseMessage in project voltdb by VoltDB.

the class ProcedureRunnerNT method completeCall.

/**
     * Send a response back to the proc caller. Refactored out of coreCall for both
     * regular and exceptional paths.
     */
private void completeCall(ClientResponseImpl response) {
    // if we're keeping track, calculate result size
    if (m_perCallStats.samplingProcedure()) {
        m_perCallStats.setResultSize(response.getResults());
    }
    m_statsCollector.endProcedure(response.getStatus() == ClientResponse.USER_ABORT, (response.getStatus() != ClientResponse.USER_ABORT) && (response.getStatus() != ClientResponse.SUCCESS), m_perCallStats);
    // send the response to the caller
    // must be done as IRM to CI mailbox for backpressure accounting
    response.setClientHandle(m_clientHandle);
    InitiateResponseMessage irm = InitiateResponseMessage.messageForNTProcResponse(m_ciHandle, m_ccxn.connectionId(), response);
    m_mailbox.deliver(irm);
    m_ntProcService.handleNTProcEnd(ProcedureRunnerNT.this);
}
Also used : InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage)

Aggregations

InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)17 ClientResponseImpl (org.voltdb.ClientResponseImpl)7 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)7 VoltTable (org.voltdb.VoltTable)5 Test (org.junit.Test)4 Matchers.anyLong (org.mockito.Matchers.anyLong)3 VoltMessage (org.voltcore.messaging.VoltMessage)3 VoltTrace (org.voltdb.utils.VoltTrace)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 TransactionInfoBaseMessage (org.voltcore.messaging.TransactionInfoBaseMessage)1 DeferredSerialization (org.voltcore.utils.DeferredSerialization)1 ExpectedProcedureException (org.voltdb.ExpectedProcedureException)1 ProcedureRunner (org.voltdb.ProcedureRunner)1 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)1 CompleteTransactionMessage (org.voltdb.messaging.CompleteTransactionMessage)1