Search in sources :

Example 1 with EEException

use of org.voltdb.exceptions.EEException in project voltdb by VoltDB.

the class FragmentTask method processFragmentTask.

// Cut and pasted from ExecutionSite processFragmentTask(), then
// modifed to work in the new world
public FragmentResponseMessage processFragmentTask(SiteProcedureConnection siteConnection) {
    // Ensure default procs loaded here
    // Also used for LoadMultipartitionTable
    String procNameToLoad = m_fragmentMsg.getProcNameToLoad();
    if (procNameToLoad != null) {
        // this will ensure proc is loaded
        ProcedureRunner runner = siteConnection.getProcedureRunner(procNameToLoad);
        assert (runner != null);
    }
    // IZZY: actually need the "executor" HSId these days?
    final FragmentResponseMessage currentFragResponse = new FragmentResponseMessage(m_fragmentMsg, m_initiator.getHSId());
    currentFragResponse.setStatus(FragmentResponseMessage.SUCCESS, null);
    if (m_inputDeps != null) {
        siteConnection.stashWorkUnitDependencies(m_inputDeps);
    }
    if (m_fragmentMsg.isEmptyForRestart()) {
        int outputDepId = m_fragmentMsg.getOutputDepId(0);
        currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId, m_rawDummyResponse, 0, m_rawDummyResponse.length));
        return currentFragResponse;
    }
    ProcedureRunner currRunner = siteConnection.getProcedureRunner(m_fragmentMsg.getProcedureName());
    long[] executionTimes = null;
    int succeededFragmentsCount = 0;
    if (currRunner != null) {
        currRunner.getExecutionEngine().setPerFragmentTimingEnabled(m_fragmentMsg.isPerFragmentStatsRecording());
        if (m_fragmentMsg.isPerFragmentStatsRecording()) {
            // At this point, we will execute the fragments one by one.
            executionTimes = new long[1];
        }
    }
    for (int frag = 0; frag < m_fragmentMsg.getFragmentCount(); frag++) {
        byte[] planHash = m_fragmentMsg.getPlanHash(frag);
        final int outputDepId = m_fragmentMsg.getOutputDepId(frag);
        ParameterSet params = m_fragmentMsg.getParameterSetForFragment(frag);
        final int inputDepId = m_fragmentMsg.getOnlyInputDepId(frag);
        long fragmentId = 0;
        byte[] fragmentPlan = null;
        /*
             * Currently the error path when executing plan fragments
             * does not adequately distinguish between fatal errors and
             * abort type errors that should result in a roll back.
             * Assume that it is ninja: succeeds or doesn't return.
             * No roll back support.
             *
             * AW in 2012, the preceding comment might be wrong,
             * I am pretty sure what we don't support is partial rollback.
             * The entire procedure will roll back successfully on failure
             */
        VoltTable dependency = null;
        try {
            FastDeserializer fragResult;
            fragmentPlan = m_fragmentMsg.getFragmentPlan(frag);
            String stmtText = null;
            // if custom fragment, load the plan and get local fragment id
            if (fragmentPlan != null) {
                // statement text for unplanned fragments are pulled from the message,
                // to ensure that we get the correct constants from the most recent
                // invocation.
                stmtText = m_fragmentMsg.getStmtText(frag);
                fragmentId = ActivePlanRepository.loadOrAddRefPlanFragment(planHash, fragmentPlan, null);
            } else // otherwise ask the plan source for a local fragment id
            {
                fragmentId = ActivePlanRepository.getFragmentIdForPlanHash(planHash);
                stmtText = ActivePlanRepository.getStmtTextForPlanHash(planHash);
            }
            // set up the batch context for the fragment set
            siteConnection.setBatch(m_fragmentMsg.getCurrentBatchIndex());
            fragResult = siteConnection.executePlanFragments(1, new long[] { fragmentId }, new long[] { inputDepId }, new ParameterSet[] { params }, null, // for long-running queries
            stmtText == null ? null : new String[] { stmtText }, // FragmentTasks don't generate statement hashes,
            new boolean[] { false }, null, m_txnState.txnId, m_txnState.m_spHandle, m_txnState.uniqueId, m_txnState.isReadOnly(), VoltTrace.log(VoltTrace.Category.EE) != null);
            // get a copy of the result buffers from the cache buffer so we can post the
            // fragment response to the network
            final int tableSize;
            final byte[] fullBacking;
            try {
                // read the complete size of the buffer used
                fragResult.readInt();
                // read number of dependencies (1)
                fragResult.readInt();
                // read the dependencyId() -1;
                fragResult.readInt();
                tableSize = fragResult.readInt();
                fullBacking = new byte[tableSize];
                // get a copy of the buffer
                fragResult.readFully(fullBacking);
            } catch (final IOException ex) {
                LOG.error("Failed to deserialze result table" + ex);
                throw new EEException(ExecutionEngine.ERRORCODE_WRONG_SERIALIZED_BYTES);
            }
            if (hostLog.isTraceEnabled()) {
                hostLog.l7dlog(Level.TRACE, LogKeys.org_voltdb_ExecutionSite_SendingDependency.name(), new Object[] { outputDepId }, null);
            }
            currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId, fullBacking, 0, tableSize));
        } catch (final EEException e) {
            hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(planHash) }, e);
            currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId, m_rawDummyResult, 0, m_rawDummyResult.length));
            }
            break;
        } catch (final SQLException e) {
            hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(planHash) }, e);
            currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId, m_rawDummyResult, 0, m_rawDummyResult.length));
            }
            break;
        } catch (final InterruptException e) {
            hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(planHash) }, e);
            currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId, m_rawDummyResult, 0, m_rawDummyResult.length));
            }
            break;
        } finally {
            // ensure adhoc plans are unloaded
            if (fragmentPlan != null) {
                ActivePlanRepository.decrefPlanFragmentById(fragmentId);
            }
            // The single-partition stored procedure handler is in the ProcedureRunner.
            if (currRunner != null) {
                succeededFragmentsCount = currRunner.getExecutionEngine().extractPerFragmentStats(1, executionTimes);
                long stmtDuration = 0;
                int stmtResultSize = 0;
                int stmtParameterSetSize = 0;
                if (m_fragmentMsg.isPerFragmentStatsRecording()) {
                    stmtDuration = executionTimes == null ? 0 : executionTimes[0];
                    stmtResultSize = dependency == null ? 0 : dependency.getSerializedSize();
                    stmtParameterSetSize = params == null ? 0 : params.getSerializedSize();
                }
                currRunner.getStatsCollector().endFragment(m_fragmentMsg.getStmtName(frag), m_fragmentMsg.isCoordinatorTask(), succeededFragmentsCount == 0, m_fragmentMsg.isPerFragmentStatsRecording(), stmtDuration, stmtResultSize, stmtParameterSetSize);
            }
        }
    }
    return currentFragResponse;
}
Also used : ParameterSet(org.voltdb.ParameterSet) FastDeserializer(org.voltdb.messaging.FastDeserializer) SQLException(org.voltdb.exceptions.SQLException) InterruptException(org.voltdb.exceptions.InterruptException) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) ProcedureRunner(org.voltdb.ProcedureRunner) FragmentResponseMessage(org.voltdb.messaging.FragmentResponseMessage) EEException(org.voltdb.exceptions.EEException) DependencyPair(org.voltdb.DependencyPair)

Example 2 with EEException

use of org.voltdb.exceptions.EEException in project voltdb by VoltDB.

the class SysprocFragmentTask method processFragmentTask.

// Extracted the sysproc portion of ExecutionSite processFragmentTask(), then
// modified to work in the new world
public FragmentResponseMessage processFragmentTask(SiteProcedureConnection siteConnection) {
    final FragmentResponseMessage currentFragResponse = new FragmentResponseMessage(m_fragmentMsg, m_initiator.getHSId());
    currentFragResponse.setStatus(FragmentResponseMessage.SUCCESS, null);
    for (int frag = 0; frag < m_fragmentMsg.getFragmentCount(); frag++) {
        final long fragmentId = VoltSystemProcedure.hashToFragId(m_fragmentMsg.getPlanHash(frag));
        // equivalent to dep.depId:
        // final int outputDepId = m_fragmentMsg.getOutputDepId(frag);
        final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.SPSITE);
        if (traceLog != null) {
            traceLog.add(() -> VoltTrace.beginDuration("runfragmenttask", "txnId", TxnEgo.txnIdToString(getTxnId()), "partition", Integer.toString(siteConnection.getCorrespondingPartitionId()), "fragmentId", String.valueOf(fragmentId)));
        }
        ParameterSet params = m_fragmentMsg.getParameterSetForFragment(frag);
        try {
            // run the overloaded sysproc planfragment. pass an empty dependency
            // set since remote (non-aggregator) fragments don't receive dependencies.
            final DependencyPair dep = siteConnection.executeSysProcPlanFragment(m_txnState, m_inputDeps, fragmentId, params);
            // @Shutdown returns null, handle it here
            if (dep != null) {
                currentFragResponse.addDependency(dep);
            }
        } catch (final EEException e) {
            hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(m_fragmentMsg.getFragmentPlan(frag)) }, e);
            currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
            }
            break;
        } catch (final SQLException e) {
            hostLog.l7dlog(Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(m_fragmentMsg.getFragmentPlan(frag)) }, e);
            currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
            }
            break;
        } catch (final SpecifiedException e) {
            // Note that with SpecifiedException, the error code here might get changed before
            // the client/user sees it. It really just needs to indicate failure.
            //
            // Key point here vs the next catch block for VAE is to not wrap the subclass of
            // SerializableException here to preserve it during the serialization.
            //
            currentFragResponse.setStatus(FragmentResponseMessage.USER_ERROR, e);
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
            }
        } catch (final VoltAbortException e) {
            currentFragResponse.setStatus(FragmentResponseMessage.USER_ERROR, new SerializableException(CoreUtils.throwableToString(e)));
            if (currentFragResponse.getTableCount() == 0) {
                // Make sure the response has at least 1 result with a valid DependencyId
                currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(m_fragmentMsg.getOutputDepId(0), m_rawDummyResult, 0, m_rawDummyResult.length));
            }
            break;
        }
        if (traceLog != null) {
            traceLog.add(VoltTrace::endDuration);
        }
    }
    return currentFragResponse;
}
Also used : ParameterSet(org.voltdb.ParameterSet) VoltTrace(org.voltdb.utils.VoltTrace) SQLException(org.voltdb.exceptions.SQLException) SpecifiedException(org.voltdb.exceptions.SpecifiedException) SerializableException(org.voltdb.exceptions.SerializableException) FragmentResponseMessage(org.voltdb.messaging.FragmentResponseMessage) EEException(org.voltdb.exceptions.EEException) DependencyPair(org.voltdb.DependencyPair) VoltAbortException(org.voltdb.VoltProcedure.VoltAbortException)

Example 3 with EEException

use of org.voltdb.exceptions.EEException in project voltdb by VoltDB.

the class ExecutionEngineJNI method tableStreamSerializeMore.

@Override
public Pair<Long, int[]> tableStreamSerializeMore(int tableId, TableStreamType streamType, List<BBContainer> outputBuffers) {
    //Clear is destructive, do it before the native call
    m_nextDeserializer.clear();
    byte[] bytes = outputBuffers != null ? SnapshotUtil.OutputBuffersToBytes(outputBuffers) : null;
    long remaining = nativeTableStreamSerializeMore(pointer, tableId, streamType.ordinal(), bytes);
    int[] positions = null;
    assert (m_nextDeserializer != null);
    int count;
    try {
        count = m_nextDeserializer.readInt();
        if (count > 0) {
            positions = new int[count];
            for (int i = 0; i < count; i++) {
                positions[i] = m_nextDeserializer.readInt();
            }
            return Pair.of(remaining, positions);
        }
    } catch (final IOException ex) {
        LOG.error("Failed to deserialize position array" + ex);
        throw new EEException(ERRORCODE_WRONG_SERIALIZED_BYTES);
    }
    return Pair.of(remaining, new int[] { 0 });
}
Also used : IOException(java.io.IOException) EEException(org.voltdb.exceptions.EEException)

Example 4 with EEException

use of org.voltdb.exceptions.EEException in project voltdb by VoltDB.

the class ExecutionEngineJNI method getStats.

/**
     * Retrieve a set of statistics using the specified selector from the StatisticsSelector enum.
     * @param selector Selector from StatisticsSelector specifying what statistics to retrieve
     * @param locators CatalogIds specifying what set of items the stats should come from.
     * @param interval Return counters since the beginning or since this method was last invoked
     * @param now Timestamp to return with each row
     * @return Array of results tables. An array of length 0 indicates there are no results. On error, an EEException will be thrown.
     */
@Override
public VoltTable[] getStats(final StatsSelector selector, final int[] locators, final boolean interval, final Long now) {
    //Clear is destructive, do it before the native call
    m_nextDeserializer.clear();
    final int numResults = nativeGetStats(pointer, selector.ordinal(), locators, interval, now);
    if (numResults == -1) {
        throwExceptionForError(ERRORCODE_ERROR);
    }
    try {
        //Ignore the length of the result tables
        m_nextDeserializer.readInt();
        final VoltTable[] results = new VoltTable[numResults];
        for (int ii = 0; ii < numResults; ii++) {
            int len = m_nextDeserializer.readInt();
            byte[] bufCopy = new byte[len];
            m_nextDeserializer.readFully(bufCopy, 0, len);
            results[ii] = PrivateVoltTableFactory.createVoltTableFromBuffer(ByteBuffer.wrap(bufCopy), true);
        }
        return results;
    } catch (final IOException ex) {
        LOG.error("Failed to deserialze result table for getStats" + ex);
        throw new EEException(ERRORCODE_WRONG_SERIALIZED_BYTES);
    }
}
Also used : IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) EEException(org.voltdb.exceptions.EEException)

Example 5 with EEException

use of org.voltdb.exceptions.EEException in project voltdb by VoltDB.

the class ExecutionEngineJNI method coreExecutePlanFragments.

/**
     * @param undoToken Token identifying undo quantum for generated undo info
     * @param traceOn
     */
@Override
protected FastDeserializer coreExecutePlanFragments(final int batchIndex, final int numFragmentIds, final long[] planFragmentIds, final long[] inputDepIds, final Object[] parameterSets, DeterminismHash determinismHash, boolean[] isWriteFrags, int[] sqlCRCs, final long txnId, final long spHandle, final long lastCommittedSpHandle, long uniqueId, final long undoToken, final boolean traceOn) throws EEException {
    // plan frag zero is invalid
    assert ((numFragmentIds == 0) || (planFragmentIds[0] != 0));
    if (numFragmentIds == 0)
        return m_emptyDeserializer;
    final int batchSize = numFragmentIds;
    if (HOST_TRACE_ENABLED) {
        for (int i = 0; i < batchSize; ++i) {
            LOG.trace("Batch Executing planfragment:" + planFragmentIds[i] + ", params=" + parameterSets[i].toString());
        }
    }
    // serialize the param sets
    int allPsetSize = 0;
    for (int i = 0; i < batchSize; ++i) {
        if (parameterSets[i] instanceof ByteBuffer) {
            allPsetSize += ((ByteBuffer) parameterSets[i]).limit();
        } else {
            allPsetSize += ((ParameterSet) parameterSets[i]).getSerializedSize();
        }
    }
    clearPsetAndEnsureCapacity(allPsetSize);
    for (int i = 0; i < batchSize; ++i) {
        int paramStart = m_psetBuffer.position();
        Object param = parameterSets[i];
        if (param instanceof ByteBuffer) {
            ByteBuffer buf = (ByteBuffer) param;
            m_psetBuffer.put(buf);
        } else {
            ParameterSet pset = (ParameterSet) param;
            try {
                pset.flattenToBuffer(m_psetBuffer);
            } catch (final IOException exception) {
                throw new RuntimeException("Error serializing parameters for SQL batch element: " + i + " with plan fragment ID: " + planFragmentIds[i] + " and with params: " + pset.toJSONString(), exception);
            }
        }
        // determinismHash can be null in FragmentTask.processFragmentTask() and many tests
        if (determinismHash != null && isWriteFrags[i]) {
            determinismHash.offerStatement(sqlCRCs[i], paramStart, m_psetBuffer);
        }
    }
    // checkMaxFsSize();
    clearPerFragmentStatsAndEnsureCapacity(batchSize);
    // Execute the plan, passing a raw pointer to the byte buffers for input and output
    //Clear is destructive, do it before the native call
    FastDeserializer targetDeserializer = (batchIndex == 0) ? m_firstDeserializer : m_nextDeserializer;
    targetDeserializer.clear();
    final int errorCode = nativeExecutePlanFragments(pointer, batchIndex, numFragmentIds, planFragmentIds, inputDepIds, txnId, spHandle, lastCommittedSpHandle, uniqueId, undoToken, traceOn);
    try {
        checkErrorCode(errorCode);
        m_usingFallbackBuffer = m_fallbackBuffer != null;
        FastDeserializer fds = m_usingFallbackBuffer ? new FastDeserializer(m_fallbackBuffer) : targetDeserializer;
        assert (fds != null);
        try {
            // check if anything was changed
            m_dirty |= fds.readBoolean();
        } catch (final IOException ex) {
            LOG.error("Failed to deserialize result table" + ex);
            throw new EEException(ERRORCODE_WRONG_SERIALIZED_BYTES);
        }
        return fds;
    } finally {
        m_fallbackBuffer = null;
    }
}
Also used : ParameterSet(org.voltdb.ParameterSet) FastDeserializer(org.voltdb.messaging.FastDeserializer) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) EEException(org.voltdb.exceptions.EEException)

Aggregations

EEException (org.voltdb.exceptions.EEException)14 IOException (java.io.IOException)9 ByteBuffer (java.nio.ByteBuffer)5 FragmentResponseMessage (org.voltdb.messaging.FragmentResponseMessage)5 DependencyPair (org.voltdb.DependencyPair)4 VoltTable (org.voltdb.VoltTable)4 FastDeserializer (org.voltdb.messaging.FastDeserializer)4 ParameterSet (org.voltdb.ParameterSet)3 SerializableException (org.voltdb.exceptions.SerializableException)3 EOFException (java.io.EOFException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Test (org.junit.Test)2 Mailbox (org.voltcore.messaging.Mailbox)2 SiteProcedureConnection (org.voltdb.SiteProcedureConnection)2 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)2 SQLException (org.voltdb.exceptions.SQLException)2 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)2 ArrayList (java.util.ArrayList)1 ProcedureRunner (org.voltdb.ProcedureRunner)1 VoltAbortException (org.voltdb.VoltProcedure.VoltAbortException)1