// Copyright (C) 2019-2020 Zilliz. All rights reserved. // // Licensed 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 "db/snapshot/Operations.h" #include "db/snapshot/ResourceHelper.h" #include "utils/Status.h" namespace milvus { namespace engine { namespace snapshot { class Event { public: virtual Status Process() = 0; }; template class ResourceGCEvent : public Event { public: using Ptr = std::shared_ptr; explicit ResourceGCEvent(class ResourceT::Ptr res) : res_(res) { } ~ResourceGCEvent() = default; Status Process() override { auto& store = Store::GetInstance(); /* mark resource as 'deleted' in meta */ auto sd_op = std::make_shared>(res_->GetID()); STATUS_CHECK((*sd_op)(store)); /* TODO: physically clean resource */ std::vector res_file_list; STATUS_CHECK(GetResFiles(res_file_list, res_)); for (auto& res_file : res_file_list) { if (!boost::filesystem::exists(res_file)) { continue; } if (boost::filesystem::is_directory(res_file)) { boost::filesystem::remove_all(res_file); } else { boost::filesystem::remove(res_file); } } /* remove resource from meta */ auto hd_op = std::make_shared>(res_->GetID()); STATUS_CHECK((*hd_op)(store)); return Status::OK(); } private: class ResourceT::Ptr res_; }; } // namespace snapshot } // namespace engine } // namespace milvus