Skip to content

Commit

Permalink
[fix](jni) avoid BE crash and NPE when close paimon reader (apache#27129
Browse files Browse the repository at this point in the history
)

1. Do not use FATAL log when jni encounter error, to avoid crash.
2. Fix NPE when closing PaimonReader, the reader may not be assigned if PaimonReader open failed.
  • Loading branch information
morningman authored and 胥剑旭 committed Dec 14, 2023
1 parent d25e47a commit 0a49d0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions be/src/vec/exec/jni_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Status JniConnector::open(RuntimeState* state, RuntimeProfile* profile) {
RETURN_IF_ERROR(_init_jni_scanner(env, batch_size));
// Call org.apache.doris.common.jni.JniScanner#open
env->CallVoidMethod(_jni_scanner_obj, _jni_scanner_open);
_scanner_opened = true;
RETURN_ERROR_IF_EXC(env);
return Status::OK();
}
Expand Down Expand Up @@ -167,7 +168,7 @@ Status JniConnector::close() {
if (!_closed) {
JNIEnv* env = nullptr;
RETURN_IF_ERROR(JniUtil::GetJNIEnv(&env));
if (_scanner_initialized) {
if (_scanner_opened) {
// update scanner metrics
for (const auto& metric : get_statistics(env)) {
std::vector<std::string> type_and_name = split(metric.first, ":");
Expand Down Expand Up @@ -204,8 +205,8 @@ Status JniConnector::close() {
_closed = true;
jthrowable exc = (env)->ExceptionOccurred();
if (exc != nullptr) {
LOG(FATAL) << "Failed to release jni resource: "
<< JniUtil::GetJniExceptionMsg(env).to_string();
LOG(WARNING) << "Failed to release jni resource: "
<< JniUtil::GetJniExceptionMsg(env).to_string();
}
}
return Status::OK();
Expand Down Expand Up @@ -241,7 +242,6 @@ Status JniConnector::_init_jni_scanner(JNIEnv* env, int batch_size) {
_jni_scanner_get_statistics =
env->GetMethodID(_jni_scanner_cls, "getStatistics", "()Ljava/util/Map;");
RETURN_IF_ERROR(JniUtil::LocalToGlobalRef(env, jni_scanner_obj, &_jni_scanner_obj));
_scanner_initialized = true;
env->DeleteLocalRef(jni_scanner_obj);
RETURN_ERROR_IF_EXC(env);
return Status::OK();
Expand Down
2 changes: 1 addition & 1 deletion be/src/vec/exec/jni_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class JniConnector {
size_t _has_read = 0;

bool _closed = false;
bool _scanner_initialized = false;
bool _scanner_opened = false;
jclass _jni_scanner_cls;
jobject _jni_scanner_obj;
jmethodID _jni_scanner_open;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ private void parseRequiredTypes() {

@Override
public void close() throws IOException {
reader.close();
if (reader != null) {
reader.close();
}
}

@Override
Expand Down

0 comments on commit 0a49d0f

Please sign in to comment.