/******************************************************************************* * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved * Unauthorized copying of this file, via any medium is strictly prohibited. * Proprietary and confidential. ******************************************************************************/ #pragma once #include #include #include #include #include #include #include "resource/Resource.h" #include "utils/Log.h" namespace zilliz { namespace milvus { namespace engine { class ResourceMgr { public: ResourceMgr(); /******** Management Interface ********/ inline void RegisterSubscriber(std::function subscriber) { subscriber_ = std::move(subscriber); } std::vector & GetDiskResources() { return disk_resources_; } /* * Return account of resource which enable executor; */ uint64_t GetNumOfComputeResource(); /* * Add resource into Resource Management; * Generate functions on events; * Functions only modify bool variable, like event trigger; */ ResourceWPtr Add(ResourcePtr &&resource); /* * Create connection between A and B; */ void Connect(ResourceWPtr &res1, ResourceWPtr &res2, Connection &connection); /* * Synchronous start all resource; * Last, start event process thread; */ void Start(); void Stop(); void PostEvent(const EventPtr &event); // TODO: add stats interface(low) public: /******** Utlitity Functions ********/ std::string Dump(); std::string DumpTaskTables(); private: void event_process(); private: std::queue queue_; std::function subscriber_ = nullptr; bool running_; std::vector disk_resources_; std::vector resources_; mutable std::mutex resources_mutex_; std::thread worker_thread_; std::mutex event_mutex_; std::condition_variable event_cv_; }; using ResourceMgrPtr = std::shared_ptr; using ResourceMgrWPtr = std::weak_ptr; } } }