From e03d0b7d216f02e489236978a9641c43b9d6d00c Mon Sep 17 00:00:00 2001 From: Ke Jia Date: Mon, 22 Sep 2025 17:13:11 +0800 Subject: [PATCH 1/2] Call HdfsFileSystem#close() method to close the hdfs connection prior to the jvm termination --- cpp/velox/compute/VeloxBackend.cc | 24 ++++++++++++++++++++++++ cpp/velox/compute/VeloxBackend.h | 20 +------------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/cpp/velox/compute/VeloxBackend.cc b/cpp/velox/compute/VeloxBackend.cc index 04faab8f3ac..b20be533381 100644 --- a/cpp/velox/compute/VeloxBackend.cc +++ b/cpp/velox/compute/VeloxBackend.cc @@ -331,4 +331,28 @@ VeloxBackend* VeloxBackend::get() { } return instance_.get(); } + +void VeloxBackend::tearDown() { + for (const auto& [_, filesystem] : facebook::velox::filesystems::registeredFilesystems) { + filesystem->close(); + } + // Destruct IOThreadPoolExecutor will join all threads. + // On threads exit, thread local variables can be constructed with referencing global variables. + // So, we need to destruct IOThreadPoolExecutor and stop the threads before global variables get destructed. + ioExecutor_.reset(); + globalMemoryManager_.reset(); + + // dump cache stats on exit if enabled + if (dynamic_cast(asyncDataCache_.get())) { + LOG(INFO) << asyncDataCache_->toString(); + for (const auto& entry : std::filesystem::directory_iterator(cachePathPrefix_)) { + if (entry.path().filename().string().find(cacheFilePrefix_) != std::string::npos) { + LOG(INFO) << "Removing cache file " << entry.path().filename().string(); + std::filesystem::remove(cachePathPrefix_ + "/" + entry.path().filename().string()); + } + } + asyncDataCache_->shutdown(); + } +} + } // namespace gluten diff --git a/cpp/velox/compute/VeloxBackend.h b/cpp/velox/compute/VeloxBackend.h index be923c22d16..94e7ec93fba 100644 --- a/cpp/velox/compute/VeloxBackend.h +++ b/cpp/velox/compute/VeloxBackend.h @@ -56,25 +56,7 @@ class VeloxBackend { return globalMemoryManager_.get(); } - void tearDown() { - // Destruct IOThreadPoolExecutor will join all threads. - // On threads exit, thread local variables can be constructed with referencing global variables. - // So, we need to destruct IOThreadPoolExecutor and stop the threads before global variables get destructed. - ioExecutor_.reset(); - globalMemoryManager_.reset(); - - // dump cache stats on exit if enabled - if (dynamic_cast(asyncDataCache_.get())) { - LOG(INFO) << asyncDataCache_->toString(); - for (const auto& entry : std::filesystem::directory_iterator(cachePathPrefix_)) { - if (entry.path().filename().string().find(cacheFilePrefix_) != std::string::npos) { - LOG(INFO) << "Removing cache file " << entry.path().filename().string(); - std::filesystem::remove(cachePathPrefix_ + "/" + entry.path().filename().string()); - } - } - asyncDataCache_->shutdown(); - } - } + void tearDown(); private: explicit VeloxBackend( From 907fdd5bfd417c1a93e069d1e7ba3eab66c5e70b Mon Sep 17 00:00:00 2001 From: Ke Jia Date: Mon, 22 Sep 2025 19:37:17 +0800 Subject: [PATCH 2/2] Fix the compile issue --- cpp/velox/compute/VeloxBackend.cc | 4 ++++ cpp/velox/operators/writer/VeloxParquetDataSource.h | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cpp/velox/compute/VeloxBackend.cc b/cpp/velox/compute/VeloxBackend.cc index b20be533381..e26cd852b61 100644 --- a/cpp/velox/compute/VeloxBackend.cc +++ b/cpp/velox/compute/VeloxBackend.cc @@ -44,6 +44,7 @@ #include "velox/connectors/hive/HiveDataSource.h" #include "velox/connectors/hive/storage_adapters/abfs/RegisterAbfsFileSystem.h" // @manual #include "velox/connectors/hive/storage_adapters/gcs/RegisterGcsFileSystem.h" // @manual +#include "velox/connectors/hive/storage_adapters/hdfs/HdfsFileSystem.h" #include "velox/connectors/hive/storage_adapters/hdfs/RegisterHdfsFileSystem.h" // @manual #include "velox/connectors/hive/storage_adapters/s3fs/RegisterS3FileSystem.h" // @manual #include "velox/dwio/orc/reader/OrcReader.h" @@ -333,9 +334,12 @@ VeloxBackend* VeloxBackend::get() { } void VeloxBackend::tearDown() { +#ifdef ENABLE_HDFS for (const auto& [_, filesystem] : facebook::velox::filesystems::registeredFilesystems) { filesystem->close(); } +#endif + // Destruct IOThreadPoolExecutor will join all threads. // On threads exit, thread local variables can be constructed with referencing global variables. // So, we need to destruct IOThreadPoolExecutor and stop the threads before global variables get destructed. diff --git a/cpp/velox/operators/writer/VeloxParquetDataSource.h b/cpp/velox/operators/writer/VeloxParquetDataSource.h index 8bbbd5ef061..4dde5c69aa8 100644 --- a/cpp/velox/operators/writer/VeloxParquetDataSource.h +++ b/cpp/velox/operators/writer/VeloxParquetDataSource.h @@ -39,7 +39,6 @@ #include "velox/connectors/hive/storage_adapters/gcs/GcsFileSystem.h" #endif #ifdef ENABLE_HDFS -#include "velox/connectors/hive/storage_adapters/hdfs/HdfsFileSystem.h" #include "velox/connectors/hive/storage_adapters/hdfs/HdfsUtil.h" #endif #ifdef ENABLE_ABFS