diff --git a/core/src/db/snapshot/InActiveResourcesGCEvent.h b/core/src/db/snapshot/InActiveResourcesGCEvent.h index ecfcbc48d9c24821b56df61eab18b0c366f3af15..ced10c3d954b4696f0482a0203492b97c17c905d 100644 --- a/core/src/db/snapshot/InActiveResourcesGCEvent.h +++ b/core/src/db/snapshot/InActiveResourcesGCEvent.h @@ -26,7 +26,7 @@ namespace milvus { namespace engine { namespace snapshot { -class InActiveResourcesGCEvent : public MetaEvent, public Operations { +class InActiveResourcesGCEvent : public GCEvent, public Operations { public: using Ptr = std::shared_ptr; @@ -77,6 +77,7 @@ class InActiveResourcesGCEvent : public MetaEvent, public Operations { auto ok = boost::filesystem::remove(res_path); /* std::cout << "[GC] Remove file " << res_->ToString() << " " << res_path << " " << ok << std::endl; */ } else { + RemoveWithSuffix(res, res_path, store->GetSuffixSet()); std::cout << "[GC] Remove stale " << res_path << " for " << res->ToString() << std::endl; } diff --git a/core/src/db/snapshot/MetaEvent.h b/core/src/db/snapshot/MetaEvent.h index e5af67263c53652df5abc8baa7c4608b5d70fd95..b5880c2a64d5dc5eaecf15dc62966d5d6d2fc86e 100644 --- a/core/src/db/snapshot/MetaEvent.h +++ b/core/src/db/snapshot/MetaEvent.h @@ -11,6 +11,11 @@ #pragma once +#include +#include + +#include + #include "db/snapshot/Store.h" #include "utils/Status.h" @@ -23,6 +28,26 @@ class MetaEvent { virtual Status Process(StorePtr) = 0; }; +class GCEvent : virtual public MetaEvent { + protected: + template + void + RemoveWithSuffix(typename ResourceT::Ptr res, const std::string& path, const std::set& suffix_set) { + for (auto& suffix : suffix_set) { + if (suffix.empty()) { + continue; + } + auto adjusted = path + suffix; + if (boost::filesystem::is_regular_file(adjusted)) { + auto ok = boost::filesystem::remove(adjusted); + std::cout << "[GC] Remove FILE " << res->ToString() << " " << adjusted << " " << ok << std::endl; + return; + } + } + std::cout << "[GC] Remove STALE OBJECT " << path << " for " << res->ToString() << std::endl; + } +}; + } // namespace snapshot } // namespace engine } // namespace milvus diff --git a/core/src/db/snapshot/ResourceGCEvent.h b/core/src/db/snapshot/ResourceGCEvent.h index 41d0fba01111210f2bbea3dbfe9e807520dc6789..bde764808d9801d088d686da9408b9184d3e693b 100644 --- a/core/src/db/snapshot/ResourceGCEvent.h +++ b/core/src/db/snapshot/ResourceGCEvent.h @@ -25,7 +25,7 @@ namespace milvus::engine::snapshot { template -class ResourceGCEvent : public MetaEvent { +class ResourceGCEvent : public GCEvent { public: using Ptr = std::shared_ptr; @@ -52,7 +52,7 @@ class ResourceGCEvent : public MetaEvent { auto ok = boost::filesystem::remove(res_path); std::cout << "[GC] Remove FILE " << res_->ToString() << " " << res_path << " " << ok << std::endl; } else { - RemoveWithSuffix(res_path, store->GetSuffixSet()); + RemoveWithSuffix(res_, res_path, store->GetSuffixSet()); } /* remove resource from meta */ @@ -63,23 +63,7 @@ class ResourceGCEvent : public MetaEvent { } private: - void - RemoveWithSuffix(const std::string& path, const std::set& suffix_set) { - for (auto& suffix : suffix_set) { - if (suffix.empty()) { - continue; - } - auto adjusted = path + suffix; - if (boost::filesystem::is_regular_file(adjusted)) { - auto ok = boost::filesystem::remove(adjusted); - std::cout << "[GC] Remove FILE " << res_->ToString() << " " << adjusted << " " << ok << std::endl; - return; - } - } - std::cout << "[GC] Remove STALE OBJECT " << path << " for " << res_->ToString() << std::endl; - } - - class ResourceT::Ptr res_; + typename ResourceT::Ptr res_; }; } // namespace milvus::engine::snapshot