Ejemplo n.º 1
0
/**
 * Executes a plan fragment with the given parameter set.
 * @param engine_ptr the VoltDBEngine pointer
 * @param plan_fragment_id ID of the plan fragment to be executed.
 * @return error code
*/
SHAREDLIB_JNIEXPORT jint JNICALL Java_org_voltdb_jni_ExecutionEngine_nativeExecutePlanFragment (
        JNIEnv *env,
        jobject obj,
        jlong engine_ptr,
        jlong plan_fragment_id,
        jint outputDependencyId,
        jint inputDependencyId,
        jlong txnId,
        jlong lastCommittedTxnId,
        jlong undoToken) {
    VOLT_DEBUG("nativeExecutePlanFragment() start");
    VoltDBEngine *engine = castToEngine(engine_ptr);
    Topend *topend = static_cast<JNITopend*>(engine->getTopend())->updateJNIEnv(env);
    assert(engine);
    try {
        updateJNILogProxy(engine); //JNIEnv pointer can change between calls, must be updated
        engine->setUndoToken(undoToken);
        engine->resetReusedResultOutputBuffer();
        NValueArray &params = engine->getParameterContainer();
        Pool *stringPool = engine->getStringPool();
        const int paramcnt = deserializeParameterSet(engine->getParameterBuffer(), engine->getParameterBufferCapacity(), params, engine->getStringPool());
        engine->setUsedParamcnt(paramcnt);
        const int retval = engine->executeQuery(plan_fragment_id, outputDependencyId, inputDependencyId, params, txnId, lastCommittedTxnId, true, true);
        stringPool->purge();
        return retval;
    } catch (FatalException e) {
        topend->crashVoltDB(e);
    }
    return org_voltdb_jni_ExecutionEngine_ERRORCODE_ERROR;
}
Ejemplo n.º 2
0
/**
 * Executes multiple plan fragments with the given parameter sets and gets the results.
 * @param pointer the VoltDBEngine pointer
 * @param plan_fragment_ids ID of the plan fragment to be executed.
 * @param outputBuffer buffer to be filled with the tables.
 * @param outputCapacity maximum number of bytes to write to buffer.
 * @return error code
*/
SHAREDLIB_JNIEXPORT jint JNICALL Java_org_voltdb_jni_ExecutionEngine_nativeExecutePlanFragments
(JNIEnv *env,
        jobject obj,
        jlong engine_ptr,
        jint num_fragments,
        jlongArray plan_fragment_ids,
        jlongArray input_dep_ids,
        jlong spHandle,
        jlong lastCommittedSpHandle,
        jlong uniqueId,
        jlong undoToken) {
    //VOLT_DEBUG("nativeExecutePlanFragments() start");

    // setup
    VoltDBEngine *engine = castToEngine(engine_ptr);
    assert(engine);
    Topend *topend = static_cast<JNITopend*>(engine->getTopend())->updateJNIEnv(env);
    try {
        updateJNILogProxy(engine); //JNIEnv pointer can change between calls, must be updated
        engine->resetReusedResultOutputBuffer();
        engine->setUndoToken(undoToken);
        static_cast<JNITopend*>(engine->getTopend())->updateJNIEnv(env);
        Pool *stringPool = engine->getStringPool();

        // fragment info
        int batch_size = num_fragments;
        assert (batch_size <= MAX_BATCH_COUNT);
        jlong* fragment_ids_buffer = engine->getBatchFragmentIdsContainer();
        env->GetLongArrayRegion(plan_fragment_ids, 0, batch_size, fragment_ids_buffer);

        // all fragments' parameters are in this buffer
        ReferenceSerializeInput serialize_in(engine->getParameterBuffer(), engine->getParameterBufferCapacity());
        NValueArray &params = engine->getParameterContainer();

        // count failures
        int failures = 0;

        for (int i = 0; i < batch_size; ++i) {
            int cnt = serialize_in.readShort();
            if (cnt < 0) {
                throwFatalException("parameter count is negative: %d", cnt);
            }
            assert (cnt < MAX_PARAM_COUNT);
            deserializeParameterSetCommon(cnt, serialize_in, params, stringPool);

            engine->setUsedParamcnt(cnt);

            int64_t input_dep_id = -1;
            if (input_dep_ids) {
                env->GetLongArrayRegion(input_dep_ids, i, 1, (jlong*) &input_dep_id);
            }

            // success is 0 and error is 1.
            if (engine->executeQuery(fragment_ids_buffer[i], 1, static_cast<int32_t>(input_dep_id),
                                     params, spHandle, lastCommittedSpHandle, uniqueId, i == 0,
                                     i == (batch_size - 1)))
            {
                ++failures;
            }
        }

        // cleanup
        stringPool->purge();
        engine->resizePlanCache();

        if (failures > 0)
            return org_voltdb_jni_ExecutionEngine_ERRORCODE_ERROR;
        else
            return org_voltdb_jni_ExecutionEngine_ERRORCODE_SUCCESS;
    } catch (FatalException e) {
        topend->crashVoltDB(e);
    }
    return org_voltdb_jni_ExecutionEngine_ERRORCODE_ERROR;
}