예제 #1
0
int64_t JNITopend::fragmentProgressUpdate(int32_t batchIndex,
                std::string planNodeName,
                std::string targetTableName,
                int64_t targetTableSize,
                int64_t tuplesProcessed,
                int64_t currMemoryInBytes,
                int64_t peakMemoryInBytes) {
        JNILocalFrameBarrier jni_frame = JNILocalFrameBarrier(m_jniEnv, 10);
        if (jni_frame.checkResult() < 0) {
                VOLT_ERROR("Unable to load dependency: jni frame error.");
                throw std::exception();
        }

        jstring jPlanNodeName = m_jniEnv->NewStringUTF(planNodeName.c_str());
        if (m_jniEnv->ExceptionCheck()) {
                m_jniEnv->ExceptionDescribe();
                throw std::exception();
        }
        jstring jTargetTableName = m_jniEnv->NewStringUTF(targetTableName.c_str());
        if (m_jniEnv->ExceptionCheck()) {
                m_jniEnv->ExceptionDescribe();
                throw std::exception();
        }

    jlong nextStep = m_jniEnv->CallLongMethod(m_javaExecutionEngine,m_fragmentProgressUpdateMID,
                batchIndex, jPlanNodeName, jTargetTableName, targetTableSize, tuplesProcessed,
                currMemoryInBytes, peakMemoryInBytes);
    return (int64_t)nextStep;
}
예제 #2
0
int JNITopend::loadNextDependency(int32_t dependencyId, voltdb::Pool *stringPool, Table* destination) {
    VOLT_DEBUG("iterating java dependency for id %d", dependencyId);

    JNILocalFrameBarrier jni_frame = JNILocalFrameBarrier(m_jniEnv, 10);
    if (jni_frame.checkResult() < 0) {
        VOLT_ERROR("Unable to load dependency: jni frame error.");
        throw std::exception();
    }

    jbyteArray jbuf = (jbyteArray)(m_jniEnv->CallObjectMethod(m_javaExecutionEngine,
                                                              m_nextDependencyMID,
                                                              dependencyId));

    if (!jbuf) {
        return 0;
    }

    jsize length = m_jniEnv->GetArrayLength(jbuf);
    if (length > 0) {
        jboolean is_copy;
        jbyte *bytes = m_jniEnv->GetByteArrayElements(jbuf, &is_copy);
        // Add the dependency buffer info to the stack object
        // so it'll get cleaned up if loadTuplesFrom throws
        jni_frame.addDependencyRef(is_copy, jbuf, bytes);
        ReferenceSerializeInputBE serialize_in(bytes, length);
        destination->loadTuplesFrom(serialize_in, stringPool);
        return 1;
    }
    else {
        return 0;
    }
}
예제 #3
0
std::string JNITopend::planForFragmentId(int64_t fragmentId) {
    VOLT_DEBUG("fetching plan for id %d", (int) fragmentId);

    JNILocalFrameBarrier jni_frame = JNILocalFrameBarrier(m_jniEnv, 10);
    if (jni_frame.checkResult() < 0) {
        VOLT_ERROR("Unable to load dependency: jni frame error.");
        throw std::exception();
    }

    jbyteArray jbuf = (jbyteArray)(m_jniEnv->CallObjectMethod(m_javaExecutionEngine,
                                                              m_planForFragmentIdMID,
                                                              fragmentId));
    // jbuf might be NULL or might have 0 length here.  In that case
    // we'll return a 0-length string to the caller, who will return
    // an appropriate error.
    return jbyteArrayToStdString(m_jniEnv, jni_frame, jbuf);
}
예제 #4
0
std::string JNITopend::decodeBase64AndDecompress(const std::string& base64Str) {
    JNILocalFrameBarrier jni_frame = JNILocalFrameBarrier(m_jniEnv, 2);
    if (jni_frame.checkResult() < 0) {
        VOLT_ERROR("Unable to load dependency: jni frame error.");
        throw std::exception();
    }

    jstring jBase64Str = m_jniEnv->NewStringUTF(base64Str.c_str());
    if (m_jniEnv->ExceptionCheck()) {
        m_jniEnv->ExceptionDescribe();
        throw std::exception();
    }

    jbyteArray jbuf = (jbyteArray)m_jniEnv->CallStaticObjectMethod(m_encoderClass,
                                                                   m_decodeBase64AndDecompressToBytesMID,
                                                                   jBase64Str);
    return jbyteArrayToStdString(m_jniEnv, jni_frame, jbuf);
}
예제 #5
0
void JNITopend::fallbackToEEAllocatedBuffer(char *buffer, size_t length) {
    JNILocalFrameBarrier jni_frame = JNILocalFrameBarrier(m_jniEnv, 1);
    if (jni_frame.checkResult() < 0) {
        VOLT_ERROR("Unable to load dependency: jni frame error.");
        throw std::exception();
    }

    jobject jbuffer = m_jniEnv->NewDirectByteBuffer(buffer, length);
    if (jbuffer == NULL) {
        m_jniEnv->ExceptionDescribe();
        throw std::exception();
    }

    m_jniEnv->CallVoidMethod(m_javaExecutionEngine, m_fallbackToEEAllocatedBufferMID, jbuffer);
    if (m_jniEnv->ExceptionCheck()) {
        m_jniEnv->ExceptionDescribe();
        throw std::exception();
    }
}
예제 #6
0
void JNITopend::crashVoltDB(FatalException e) {
    //Enough references for the reason string, traces array, and traces strings
    JNILocalFrameBarrier jni_frame =
            JNILocalFrameBarrier(
                    m_jniEnv,
                    static_cast<int32_t>(e.m_traces.size()) + 4);
    if (jni_frame.checkResult() < 0) {
        VOLT_ERROR("Unable to load dependency: jni frame error.");
        throw std::exception();
    }
    jstring jReason = m_jniEnv->NewStringUTF(e.m_reason.c_str());
    if (m_jniEnv->ExceptionCheck()) {
        m_jniEnv->ExceptionDescribe();
        throw std::exception();
    }
    jstring jFilename = m_jniEnv->NewStringUTF(e.m_filename);
    if (m_jniEnv->ExceptionCheck()) {
        m_jniEnv->ExceptionDescribe();
        throw std::exception();
    }
    jobjectArray jTracesArray =
            m_jniEnv->NewObjectArray(
                    static_cast<jsize>(e.m_traces.size()),
                    m_jniEnv->FindClass("java/lang/String"),
                    NULL);
    if (m_jniEnv->ExceptionCheck()) {
        m_jniEnv->ExceptionDescribe();
        throw std::exception();
    }
    for (int ii = 0; ii < e.m_traces.size(); ii++) {
        jstring traceString = m_jniEnv->NewStringUTF(e.m_traces[ii].c_str());
        m_jniEnv->SetObjectArrayElement( jTracesArray, ii, traceString);
    }
    m_jniEnv->CallStaticVoidMethod(
            m_jniEnv->GetObjectClass(m_javaExecutionEngine),
            m_crashVoltDBMID,
            jReason,
            jTracesArray,
            jFilename,
            static_cast<int32_t>(e.m_lineno));
    throw std::exception();
}
예제 #7
0
std::string JNITopend::planForFragmentId(int64_t fragmentId) {
    VOLT_DEBUG("fetching plan for id %d", (int) fragmentId);

    JNILocalFrameBarrier jni_frame = JNILocalFrameBarrier(m_jniEnv, 10);
    if (jni_frame.checkResult() < 0) {
        VOLT_ERROR("Unable to load dependency: jni frame error.");
        throw std::exception();
    }

    jbyteArray jbuf = (jbyteArray)(m_jniEnv->CallObjectMethod(m_javaExecutionEngine,
                                                              m_planForFragmentIdMID,
                                                              fragmentId));

    if (!jbuf) {
        // this will be trapped later ;-)
        return std::string("");
    }

    jsize length = m_jniEnv->GetArrayLength(jbuf);
    if (length > 0) {
        jboolean is_copy;
        jbyte *bytes = m_jniEnv->GetByteArrayElements(jbuf, &is_copy);
        // Add the plan buffer info to the stack object
        // so it'll get cleaned up if loadTuplesFrom throws
        jni_frame.addDependencyRef(is_copy, jbuf, bytes);

        // make a null terminated copy
        boost::scoped_array<char> strdata(new char[length + 1]);
        memcpy(strdata.get(), bytes, length);
        strdata.get()[length] = '\0';

        return std::string(strdata.get());
    }
    else {
        // this will be trapped later ;-)
        return std::string("");
    }
}