From cd4b667b30f14b922c3ebdb446d458cdbf9490ca Mon Sep 17 00:00:00 2001 From: BossZou <40255591+BossZou@users.noreply.github.com> Date: Tue, 28 Jul 2020 19:33:33 +0800 Subject: [PATCH] Update InactiveResourceGCEvent (#3051) Signed-off-by: yhz <413554850@qq.com> --- .../db/snapshot/InActiveResourcesGCEvent.h | 3 ++- core/src/db/snapshot/MetaEvent.h | 25 +++++++++++++++++++ core/src/db/snapshot/ResourceGCEvent.h | 22 +++------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/core/src/db/snapshot/InActiveResourcesGCEvent.h b/core/src/db/snapshot/InActiveResourcesGCEvent.h index ecfcbc48..ced10c3d 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 e5af6726..b5880c2a 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 41d0fba0..bde76480 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 -- GitLab