Skip to content

Commit 4a80011

Browse files
[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.
1 parent 1d1c425 commit 4a80011

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

be/src/io/hdfs_util.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
#include <bvar/latency_recorder.h>
2121
#include <gen_cpp/cloud.pb.h>
2222

23+
#include <future>
2324
#include <ostream>
25+
#include <thread>
26+
#include <utility>
2427

2528
#include "common/logging.h"
2629
#include "io/fs/err_utils.h"
@@ -30,7 +33,7 @@
3033
namespace doris::io {
3134
namespace {
3235

33-
Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) {
36+
Status _create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) {
3437
HDFSCommonBuilder builder;
3538
RETURN_IF_ERROR(create_hdfs_builder(hdfs_params, fs_name, &builder));
3639
hdfsFS hdfs_fs = hdfsBuilderConnect(builder.get());
@@ -41,6 +44,22 @@ Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name
4144
return Status::OK();
4245
}
4346

47+
inline bool is_bthread() {
48+
return (bthread_self() != 0);
49+
}
50+
51+
Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) {
52+
if (is_bthread()) {
53+
Status st;
54+
std::thread t([&] { st = _create_hdfs_fs(hdfs_params, fs_name, fs); });
55+
if (t.joinable()) {
56+
t.join();
57+
}
58+
return st;
59+
}
60+
return _create_hdfs_fs(hdfs_params, fs_name, fs);
61+
}
62+
4463
uint64_t hdfs_hash_code(const THdfsParams& hdfs_params, const std::string& fs_name) {
4564
uint64_t hash_code = 0;
4665
// The specified fsname is used first.

0 commit comments

Comments
 (0)