/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include "velox/common/caching/AsyncDataCache.h" #include "velox/common/memory/MemoryPool.h" #include "velox/common/memory/MmapAllocator.h" #include "velox/core/Config.h" namespace gluten { /// As a static instance in per executor, initialized at executor startup. /// Should not put heavily work here. class VeloxBackend { public: ~VeloxBackend() { 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(); } } static void create(const std::unordered_map& conf); static VeloxBackend* get(); facebook::velox::cache::AsyncDataCache* getAsyncDataCache() const; private: explicit VeloxBackend(const std::unordered_map& conf) { init(conf); } void init(const std::unordered_map& conf); void initCache(const std::shared_ptr& conf); void initConnector(const std::shared_ptr& conf); void initUdf(const std::shared_ptr& conf); void initJolFilesystem(const std::shared_ptr& conf); std::string getCacheFilePrefix() { return "cache." + boost::lexical_cast(boost::uuids::random_generator()()) + "."; } static std::unique_ptr instance_; // Instance of AsyncDataCache used for all large allocations. std::shared_ptr asyncDataCache_; std::unique_ptr ssdCacheExecutor_; std::unique_ptr ioExecutor_; std::shared_ptr cacheAllocator_; std::string cachePathPrefix_; std::string cacheFilePrefix_; }; } // namespace gluten