gavinchou commented on code in PR #42629:
URL: https://github.com/apache/doris/pull/42629#discussion_r1822710982


##########
be/src/io/hdfs_util.cpp:
##########
@@ -41,6 +43,21 @@ Status create_hdfs_fs(const THdfsParams& hdfs_params, const 
std::string& fs_name
     return Status::OK();
 }
 
+// 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.
+Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& 
fs_name, hdfsFS* fs) {
+    if (bthread_self() != 0) { // running in 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);
+}

Review Comment:
   ```suggestion
   // 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.
   Status create_hdfs_fs(const THdfsParams& hdfs_params, const std::string& 
fs_name, hdfsFS* fs) {
       if (bthread_self() != 0) { // running in bthread
           Status st;
           auto btx = butex_create();
           std::atomic_bool done = false;
           std::thread t([&] {
               st = _create_hdfs_fs(hdfs_params, fs_name, fs);
               done = true;
               butex_wake(btx);
           });
           if (!done) butex_wait(btx);
           butex_destroy(btx);
           if (t.joinable()) {
               t.join();
           }
           return st;
       }
       return _create_hdfs_fs(hdfs_params, fs_name, fs);
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to