Skip to content

Commit 78e8a6e

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 3303c04 commit 78e8a6e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

be/src/io/hdfs_util.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
#include "io/hdfs_util.h"
1919

20+
#include <bthread/bthread.h>
2021
#include <bvar/latency_recorder.h>
2122
#include <gen_cpp/cloud.pb.h>
2223

2324
#include <ostream>
25+
#include <thread>
2426

2527
#include "common/logging.h"
2628
#include "io/fs/err_utils.h"
@@ -30,7 +32,7 @@
3032
namespace doris::io {
3133
namespace {
3234

33-
Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) {
35+
Status _create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name, hdfsFS* fs) {
3436
HDFSCommonBuilder builder;
3537
RETURN_IF_ERROR(create_hdfs_builder(hdfs_params, fs_name, &builder));
3638
hdfsFS hdfs_fs = hdfsBuilderConnect(builder.get());
@@ -41,6 +43,22 @@ Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& fs_name
4143
return Status::OK();
4244
}
4345

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

0 commit comments

Comments
 (0)