Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](jni) avoid BE crash and NPE when close paimon reader #27129

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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