[enhancement](exception safe) make function state exception safe (#16771)

This commit is contained in:
yiguolei
2023-02-20 23:01:45 +08:00
committed by GitHub
parent a46941c684
commit e04c13b7a6
19 changed files with 83 additions and 167 deletions

View File

@ -64,7 +64,8 @@ Status JavaFunctionCall::prepare(FunctionContext* context,
executor_close_id_ = env->GetMethodID(executor_cl_, "close", EXECUTOR_CLOSE_SIGNATURE);
RETURN_ERROR_IF_EXC(env);
JniContext* jni_ctx = new JniContext(_argument_types.size(), this);
std::shared_ptr<JniContext> jni_ctx =
std::make_shared<JniContext>(_argument_types.size(), this);
context->set_function_state(FunctionContext::THREAD_LOCAL, jni_ctx);
// Add a scoped cleanup jni reference object. This cleans up local refs made below.
@ -308,10 +309,9 @@ Status JavaFunctionCall::close(FunctionContext* context,
FunctionContext::FunctionStateScope scope) {
JniContext* jni_ctx = reinterpret_cast<JniContext*>(
context->get_function_state(FunctionContext::THREAD_LOCAL));
if (jni_ctx != nullptr) {
delete jni_ctx;
context->set_function_state(FunctionContext::THREAD_LOCAL, nullptr);
}
// JNIContext own some resource and its release method depend on JavaFunctionCall
// has to release the resource before JavaFunctionCall is deconstructed.
jni_ctx->close();
return Status::OK();
}
} // namespace doris::vectorized