From 4a800115f95512e67074b723432888f35becd1df Mon Sep 17 00:00:00 2001 From: Lei Zhang <27994433+SWJTU-ZhangLei@users.noreply.github.com> Date: Mon, 28 Oct 2024 15:08:11 +0800 Subject: [PATCH] [fix](be) Fix creating hdfs connection coredump within bthread * https://brpc.apache.org/docs/server/basics/ * According to the brpc doc, `JNI code checks stack layout and cannot be run in bthreads` so create a pthread for creating hdfs connection if necessary. --- be/src/io/hdfs_util.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/be/src/io/hdfs_util.cpp b/be/src/io/hdfs_util.cpp index 6c1bbf80a1526f1..f78c292169e7cbd 100644 --- a/be/src/io/hdfs_util.cpp +++ b/be/src/io/hdfs_util.cpp @@ -20,7 +20,10 @@ #include #include +#include #include +#include +#include #include "common/logging.h" #include "io/fs/err_utils.h" @@ -30,7 +33,7 @@ namespace doris::io { namespace { -Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) { +Status _create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) { HDFSCommonBuilder builder; RETURN_IF_ERROR(create_hdfs_builder(hdfs_params, fs_name, &builder)); hdfsFS hdfs_fs = hdfsBuilderConnect(builder.get()); @@ -41,6 +44,22 @@ Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name return Status::OK(); } +inline bool is_bthread() { + return (bthread_self() != 0); +} + +Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) { + if (is_bthread()) { + Status st; + std::thread t([&] { st = _create_hdfs_fs(hdfs_params, fs_name, fs); }); + if (t.joinable()) { + t.join(); + } + return st; + } + return _create_hdfs_fs(hdfs_params, fs_name, fs); +} + uint64_t hdfs_hash_code(const THdfsParams& hdfs_params, const std::string& fs_name) { uint64_t hash_code = 0; // The specified fsname is used first.