Search in sources :

Example 16 with ParameterSet

use of org.voltdb.ParameterSet in project voltdb by VoltDB.

the class AdHocPlannedStmtBatch method flattenPlanArrayToBuffer.

/**
     * For convenience, serialization is accomplished with this single method,
     * but deserialization is piecemeal via the static methods userParamsFromBuffer
     * and planArrayFromBuffer with no dummy "AdHocPlannedStmtBatch receiver" instance required.
     */
public ByteBuffer flattenPlanArrayToBuffer() throws IOException {
    // sizeof batch
    int size = 0;
    ParameterSet userParamCache = null;
    if (userParamSet == null) {
        userParamCache = ParameterSet.emptyParameterSet();
    } else {
        Object[] typedUserParams = new Object[userParamSet.length];
        int ii = 0;
        for (AdHocPlannedStatement cs : plannedStatements) {
            for (VoltType paramType : cs.core.parameterTypes) {
                if (ii >= typedUserParams.length) {
                    String errorMsg = "Too few actual arguments were passed for the parameters in the sql statement(s): (" + typedUserParams.length + " vs. " + ii + ")";
                    // Volt-TYPE-Exception is slightly cheating, here, should there be a more general VoltArgumentException?
                    throw new VoltTypeException(errorMsg);
                }
                typedUserParams[ii] = ParameterConverter.tryToMakeCompatible(paramType.classFromType(), userParamSet[ii]);
                // System.out.println("DEBUG typed parameter: " + work.userParamSet[ii] +
                //         "using type: " + paramType + "as: " + typedUserParams[ii]);
                ii++;
            }
        }
        // exactly once in userParams.
        if (ii < typedUserParams.length) {
            // Volt-TYPE-Exception is slightly cheating, here, should there be a more general VoltArgumentException?
            String errorMsg = "Too many actual arguments were passed for the parameters in the sql statement(s): (" + typedUserParams.length + " vs. " + ii + ")";
            throw new VoltTypeException(errorMsg);
        }
        userParamCache = ParameterSet.fromArrayNoCopy(typedUserParams);
    }
    size += userParamCache.getSerializedSize();
    // sizeof batch
    size += 2;
    for (AdHocPlannedStatement cs : plannedStatements) {
        size += cs.getSerializedSize();
    }
    ByteBuffer buf = ByteBuffer.allocate(size);
    userParamCache.flattenToBuffer(buf);
    buf.putShort((short) plannedStatements.size());
    for (AdHocPlannedStatement cs : plannedStatements) {
        cs.flattenToBuffer(buf);
    }
    return buf;
}
Also used : ParameterSet(org.voltdb.ParameterSet) VoltType(org.voltdb.VoltType) JSONObject(org.json_voltpatches.JSONObject) VoltTypeException(org.voltdb.VoltTypeException) ByteBuffer(java.nio.ByteBuffer)

Example 17 with ParameterSet

use of org.voltdb.ParameterSet 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 18 with ParameterSet

use of org.voltdb.ParameterSet in project voltdb by VoltDB.

the class AdHocBase method adHocSQLFromInvocationForDebug.

/**
     * Get a string containing the SQL statements and any parameters for a given
     * batch passed to an ad-hoc query. Used for debugging and logging.
     */
public static String adHocSQLFromInvocationForDebug(StoredProcedureInvocation invocation) {
    assert (invocation.getProcName().startsWith("@AdHoc"));
    ParameterSet params = invocation.getParams();
    assert (params.size() == 2 || params.size() == 3);
    // the final param is the byte array we need
    byte[] serializedBatchData = (byte[]) params.getParam(params.size() - 1);
    Pair<Object[], AdHocPlannedStatement[]> data = decodeSerializedBatchData(serializedBatchData);
    Object[] userparams = data.getFirst();
    AdHocPlannedStatement[] statements = data.getSecond();
    StringBuilder sb = new StringBuilder();
    if (statements.length == 0) {
        sb.append("ADHOC INVOCATION HAS NO SQL");
    } else if (statements.length == 1) {
        sb.append(adHocSQLStringFromPlannedStatement(statements[0], userparams));
    } else {
        // > 1
        sb.append("BEGIN ADHOC_SQL_BATCH {\n");
        for (AdHocPlannedStatement stmt : statements) {
            sb.append(adHocSQLStringFromPlannedStatement(stmt, userparams)).append("\n");
        }
        sb.append("} END ADHOC_SQL_BATCH");
    }
    return sb.toString();
}
Also used : ParameterSet(org.voltdb.ParameterSet) AdHocPlannedStatement(org.voltdb.compiler.AdHocPlannedStatement)

Example 19 with ParameterSet

use of org.voltdb.ParameterSet in project voltdb by VoltDB.

the class FragmentTaskMessage method getParameterSetForFragment.

public ParameterSet getParameterSetForFragment(int index) {
    ParameterSet params = null;
    final ByteBuffer paramData = m_items.get(index).m_parameterSet.asReadOnlyBuffer();
    if (paramData != null) {
        try {
            params = ParameterSet.fromByteBuffer(paramData);
        } catch (final IOException e) {
            hostLog.l7dlog(Level.FATAL, LogKeys.host_ExecutionSite_FailedDeserializingParamsForFragmentTask.name(), e);
            VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
        }
    } else {
        params = ParameterSet.emptyParameterSet();
    }
    return params;
}
Also used : ParameterSet(org.voltdb.ParameterSet) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 20 with ParameterSet

use of org.voltdb.ParameterSet in project voltdb by VoltDB.

the class ExecutionEngineJNI method hashinate.

@Override
public int hashinate(Object value, HashinatorConfig config) {
    ParameterSet parameterSet = ParameterSet.fromArrayNoCopy(value, config.type.typeId(), config.configBytes);
    // serialize the param set
    clearPsetAndEnsureCapacity(parameterSet.getSerializedSize());
    try {
        parameterSet.flattenToBuffer(m_psetBuffer);
    } catch (final IOException exception) {
        // can't happen
        throw new RuntimeException(exception);
    }
    return nativeHashinate(pointer, config.configPtr, config.numTokens);
}
Also used : ParameterSet(org.voltdb.ParameterSet) IOException(java.io.IOException)

Aggregations

ParameterSet (org.voltdb.ParameterSet)28 IOException (java.io.IOException)9 ByteBuffer (java.nio.ByteBuffer)9 EEException (org.voltdb.exceptions.EEException)5 PlanFragment (org.voltdb.catalog.PlanFragment)3 Statement (org.voltdb.catalog.Statement)3 SerializableException (org.voltdb.exceptions.SerializableException)3 FastDeserializer (org.voltdb.messaging.FastDeserializer)3 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)3 EOFException (java.io.EOFException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 DependencyPair (org.voltdb.DependencyPair)2 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)2 VoltTable (org.voltdb.VoltTable)2 SQLException (org.voltdb.exceptions.SQLException)2 FragmentResponseMessage (org.voltdb.messaging.FragmentResponseMessage)2 CorePlan (org.voltdb.planner.CorePlan)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1