From 0bf9e496ad19629adada747087a130014cb0ec16 Mon Sep 17 00:00:00 2001 From: "Mingyu Chen (Rayner)" Date: Wed, 26 Feb 2025 10:12:54 +0800 Subject: [PATCH] [fix](jvm) the jvm opt should only be set once (#48335) ### What problem does this PR solve? Introduced from #47299 the `SetEnvIfNecessary` may be called multiple times, and in #47299, we changed `setenv("LIBHDFS_OPTS", libhdfs_opts.c_str(), 0);` to `setenv("LIBHDFS_OPTS", libhdfs_opts.c_str(), 1);` so it will add `krb5 path` at the end of `LIBHDFS_OPTS` and set it every time, so `LIBHDFS_OPTS` becomes longer and longer. This PR fix this issue by calling `SetEnvIfNecessary` only once --- be/src/util/jni-util.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/be/src/util/jni-util.cpp b/be/src/util/jni-util.cpp index 6ad0790ef0859e..eb71bb449b492b 100644 --- a/be/src/util/jni-util.cpp +++ b/be/src/util/jni-util.cpp @@ -46,6 +46,7 @@ namespace doris { namespace { JavaVM* g_vm; [[maybe_unused]] std::once_flag g_vm_once; +[[maybe_unused]] std::once_flag g_jvm_conf_once; const std::string GetDorisJNIDefaultClasspath() { const auto* doris_home = getenv("DORIS_HOME"); @@ -271,7 +272,7 @@ Status JniUtil::GetJNIEnvSlowPath(JNIEnv** env) { } #else // the hadoop libhdfs will do all the stuff - SetEnvIfNecessary(); + std::call_once(g_jvm_conf_once, SetEnvIfNecessary); tls_env_ = getJNIEnv(); #endif *env = tls_env_;