Repository: trafodion Updated Branches: refs/heads/master 908ea7d5b -> fc939b990
[TRAFODION-3095] Trafodion SQL process should abort when it encounters OOM condition in java Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/81b2c6b4 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/81b2c6b4 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/81b2c6b4 Branch: refs/heads/master Commit: 81b2c6b4b98ddfe94ec79e0139c838e3b0581380 Parents: 8dbf5df Author: selvaganesang <[email protected]> Authored: Fri Jun 1 19:47:20 2018 +0000 Committer: selvaganesang <[email protected]> Committed: Fri Jun 1 19:47:20 2018 +0000 ---------------------------------------------------------------------- core/sql/executor/JavaObjectInterface.cpp | 32 ++++++++++++++++++++++---- core/sql/executor/JavaObjectInterface.h | 3 ++- 2 files changed, 29 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/81b2c6b4/core/sql/executor/JavaObjectInterface.cpp ---------------------------------------------------------------------- diff --git a/core/sql/executor/JavaObjectInterface.cpp b/core/sql/executor/JavaObjectInterface.cpp index 282e40b..7a29b24 100644 --- a/core/sql/executor/JavaObjectInterface.cpp +++ b/core/sql/executor/JavaObjectInterface.cpp @@ -49,6 +49,7 @@ __thread NAString *tsRecentJMFromJNI = NULL; __thread NAString *tsSqlJniErrorStr = NULL; jclass JavaObjectInterface::gThrowableClass = NULL; jclass JavaObjectInterface::gStackTraceClass = NULL; +jclass JavaObjectInterface::gOOMErrorClass = NULL; jmethodID JavaObjectInterface::gGetStackTraceMethodID = NULL; jmethodID JavaObjectInterface::gThrowableToStringMethodID = NULL; jmethodID JavaObjectInterface::gStackFrameToStringMethodID = NULL; @@ -442,6 +443,15 @@ JOI_RetCode JavaObjectInterface::initJVM(LmJavaOptions *options) "()Ljava/lang/String;"); } } + if (gOOMErrorClass == NULL) + { + lJavaClass = (jclass)jenv_->FindClass("java/lang/OutOfMemoryError"); + if (lJavaClass != NULL) + { + gOOMErrorClass = (jclass)jenv_->NewGlobalRef(lJavaClass); + jenv_->DeleteLocalRef(lJavaClass); + } + } return JOI_OK; } @@ -565,10 +575,11 @@ void JavaObjectInterface::logError(std::string &cat, const char* file, int line) QRLogger::log(cat, LL_ERROR, "Java exception in file %s, line %d.", file, line); } -NABoolean JavaObjectInterface::getExceptionDetails(const char *fileName, int lineNo, +NABoolean JavaObjectInterface::getExceptionDetails(const char *fileName, int lineNo, const char *methodName) { JNIEnv *jenv = jenv_; + NABoolean killProcess = FALSE; CliGlobals *cliGlobals = GetCliGlobals(); NAString error_msg; if (gThrowableClass == NULL) @@ -585,16 +596,25 @@ NABoolean JavaObjectInterface::getExceptionDetails(const char *fileName, int li setSqlJniErrorStr(error_msg); return FALSE; } - appendExceptionMessages(a_exception, error_msg); + if (appendExceptionMessages(a_exception, error_msg)) + killProcess = TRUE; setSqlJniErrorStr(error_msg); logError(CAT_SQL_EXE, fileName, lineNo); logError(CAT_SQL_EXE, methodName, error_msg); jenv->ExceptionClear(); + if (killProcess) { + // wait to get the hprof dump by JVM + sleep(30); + abort(); + } return TRUE; } -void JavaObjectInterface::appendExceptionMessages(jthrowable a_exception, NAString &error_msg) +NABoolean JavaObjectInterface::appendExceptionMessages(jthrowable a_exception, NAString &error_msg) { + NABoolean killProcess = FALSE; + if (jenv_->IsInstanceOf(a_exception, gOOMErrorClass) == JNI_TRUE) + killProcess = TRUE; jstring msg_obj = (jstring) jenv_->CallObjectMethod(a_exception, gThrowableToStringMethodID); @@ -616,7 +636,7 @@ void JavaObjectInterface::appendExceptionMessages(jthrowable a_exception, NAStri a_exception, gGetStackTraceMethodID); if (frames == NULL) - return; + return killProcess; jsize frames_length = jenv_->GetArrayLength(frames); jsize i = 0; @@ -638,9 +658,11 @@ void JavaObjectInterface::appendExceptionMessages(jthrowable a_exception, NAStri jthrowable j_cause = (jthrowable)jenv_->CallObjectMethod(a_exception, gGetCauseMethodID); if (j_cause != NULL) { error_msg += " Caused by \n"; - appendExceptionMessages(j_cause, error_msg); + if (appendExceptionMessages(j_cause, error_msg)) + killProcess = TRUE; } jenv_->DeleteLocalRef(a_exception); + return killProcess; } JOI_RetCode JavaObjectInterface::initJNIEnv() http://git-wip-us.apache.org/repos/asf/trafodion/blob/81b2c6b4/core/sql/executor/JavaObjectInterface.h ---------------------------------------------------------------------- diff --git a/core/sql/executor/JavaObjectInterface.h b/core/sql/executor/JavaObjectInterface.h index f6da8ec..78d1720 100644 --- a/core/sql/executor/JavaObjectInterface.h +++ b/core/sql/executor/JavaObjectInterface.h @@ -150,13 +150,14 @@ public: static NABoolean getExceptionDetails(const char *fileName, int lineNo, const char *methodName); - static void appendExceptionMessages(jthrowable a_exception, NAString &error_msg); + static NABoolean appendExceptionMessages(jthrowable a_exception, NAString &error_msg); NAHeap *getHeap() { return heap_; } protected: static JavaVM* jvm_; static jclass gThrowableClass; static jclass gStackTraceClass; + static jclass gOOMErrorClass; static jmethodID gGetStackTraceMethodID; static jmethodID gThrowableToStringMethodID; static jmethodID gStackFrameToStringMethodID;
