Search in sources :

Example 6 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 7 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)

Example 8 with EEException

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

the class ExecutionEngineJNI method loadTable.

@Override
public byte[] loadTable(final int tableId, final VoltTable table, final long txnId, final long spHandle, final long lastCommittedSpHandle, final long uniqueId, boolean returnUniqueViolations, boolean shouldDRStream, long undoToken) throws EEException {
    if (HOST_TRACE_ENABLED) {
        LOG.trace("loading table id=" + tableId + "...");
    }
    byte[] serialized_table = PrivateVoltTableFactory.getTableDataReference(table).array();
    if (HOST_TRACE_ENABLED) {
        LOG.trace("passing " + serialized_table.length + " bytes to EE...");
    }
    //Clear is destructive, do it before the native call
    m_nextDeserializer.clear();
    final int errorCode = nativeLoadTable(pointer, tableId, serialized_table, txnId, spHandle, lastCommittedSpHandle, uniqueId, returnUniqueViolations, shouldDRStream, undoToken);
    checkErrorCode(errorCode);
    try {
        int length = m_nextDeserializer.readInt();
        if (length == 0)
            return null;
        if (length < 0)
            VoltDB.crashLocalVoltDB("Length shouldn't be < 0", true, null);
        byte[] uniqueViolations = new byte[length];
        m_nextDeserializer.readFully(uniqueViolations);
        return uniqueViolations;
    } catch (final IOException ex) {
        LOG.error("Failed to retrieve unique violations: " + tableId, ex);
        throw new EEException(ERRORCODE_WRONG_SERIALIZED_BYTES);
    }
}
Also used : IOException(java.io.IOException) EEException(org.voltdb.exceptions.EEException)

Example 9 with EEException

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

the class ExecutionEngineIPC method coreExecutePlanFragments.

@Override
protected FastDeserializer coreExecutePlanFragments(final int bufferHint, 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, final long uniqueId, final long undoToken, boolean traceOn) throws EEException {
    sendPlanFragmentsInvocation(Commands.QueryPlanFragments, numFragmentIds, planFragmentIds, inputDepIds, parameterSets, determinismHash, isWriteFrags, sqlCRCs, txnId, spHandle, lastCommittedSpHandle, uniqueId, undoToken);
    int result = ExecutionEngine.ERRORCODE_ERROR;
    if (m_perFragmentTimingEnabled) {
        m_executionTimes = new long[numFragmentIds];
    }
    while (true) {
        try {
            result = m_connection.readStatusByte();
            ByteBuffer resultTables = null;
            if (result == ExecutionEngine.ERRORCODE_NEED_PLAN) {
                long fragmentId = m_connection.readLong();
                byte[] plan = planForFragmentId(fragmentId);
                m_data.clear();
                m_data.put(plan);
                m_data.flip();
                m_connection.write();
            } else if (result == ExecutionEngine.ERRORCODE_SUCCESS) {
                try {
                    resultTables = m_connection.readResultsBuffer();
                } catch (final IOException e) {
                    throw new EEException(ExecutionEngine.ERRORCODE_WRONG_SERIALIZED_BYTES);
                }
                return new FastDeserializer(resultTables);
            } else {
                // failure
                return null;
            }
        } catch (final IOException e) {
            m_history.append("GOT IOException: " + e.toString());
            System.out.println("Exception: " + e.getMessage());
            throw new RuntimeException(e);
        } catch (final Throwable thrown) {
            thrown.printStackTrace();
            m_history.append("GOT Throwable: " + thrown.toString());
            throw thrown;
        }
    }
}
Also used : FastDeserializer(org.voltdb.messaging.FastDeserializer) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) EEException(org.voltdb.exceptions.EEException)

Example 10 with EEException

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

the class ExecutionEngineIPC method applyBinaryLog.

@Override
public long applyBinaryLog(ByteBuffer log, long txnId, long spHandle, long lastCommittedSpHandle, long uniqueId, int remoteClusterId, long undoToken) throws EEException {
    m_data.clear();
    m_data.putInt(Commands.applyBinaryLog.m_id);
    m_data.putLong(txnId);
    m_data.putLong(spHandle);
    m_data.putLong(lastCommittedSpHandle);
    m_data.putLong(uniqueId);
    m_data.putInt(remoteClusterId);
    m_data.putLong(undoToken);
    m_data.put(log.array());
    try {
        m_data.flip();
        m_connection.write();
        ByteBuffer rowCount = ByteBuffer.allocate(8);
        while (rowCount.hasRemaining()) {
            int read = m_connection.m_socketChannel.read(rowCount);
            if (read <= 0) {
                throw new EOFException();
            }
        }
        rowCount.flip();
        return rowCount.getLong();
    } catch (final Exception e) {
        System.out.println("Exception: " + e.getMessage());
        throw new RuntimeException(e);
    }
}
Also used : EOFException(java.io.EOFException) ByteBuffer(java.nio.ByteBuffer) SerializableException(org.voltdb.exceptions.SerializableException) IOException(java.io.IOException) EOFException(java.io.EOFException) EEException(org.voltdb.exceptions.EEException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

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