Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cpp/velox/compute/VeloxBackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -331,4 +332,31 @@ VeloxBackend* VeloxBackend::get() {
}
return instance_.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.
ioExecutor_.reset();
globalMemoryManager_.reset();

// dump cache stats on exit if enabled
if (dynamic_cast<facebook::velox::cache::AsyncDataCache*>(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
20 changes: 1 addition & 19 deletions cpp/velox/compute/VeloxBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<facebook::velox::cache::AsyncDataCache*>(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(
Expand Down
1 change: 0 additions & 1 deletion cpp/velox/operators/writer/VeloxParquetDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down