milvus/cpp/src/scheduler/ResourceMgr.h
wxyu 4f5466dbe8 MS-400 Add timestamp record in task state change function
Former-commit-id: 062045c8e5cbd0b0c71a05e0f5650ea943e4b3fa
2019-08-22 11:56:45 +08:00

103 lines
2.1 KiB
C++

/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#pragma once
#include <string>
#include <vector>
#include <memory>
#include <mutex>
#include <queue>
#include <condition_variable>
#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<void(EventPtr)> subscriber) {
subscriber_ = std::move(subscriber);
}
std::vector<ResourceWPtr> &
GetDiskResources() {
return disk_resources_;
}
/*
* 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<EventPtr> queue_;
std::function<void(EventPtr)> subscriber_ = nullptr;
bool running_;
std::vector<ResourceWPtr> disk_resources_;
std::vector<ResourcePtr> resources_;
mutable std::mutex resources_mutex_;
std::thread worker_thread_;
std::mutex event_mutex_;
std::condition_variable event_cv_;
};
using ResourceMgrPtr = std::shared_ptr<ResourceMgr>;
using ResourceMgrWPtr = std::weak_ptr<ResourceMgr>;
}
}
}