提交 484f255f 编写于 作者: W wxyu

MS-366 Implement TaskTable


Former-commit-id: e6d189c5c63b0477384353bf6f75482eeb196c7d
上级 404bc88b
...@@ -21,6 +21,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -21,6 +21,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-361 - Add event in resource - MS-361 - Add event in resource
- MS-364 - Modify tasktableitem in tasktable - MS-364 - Modify tasktableitem in tasktable
- MS-365 - Use tasktableitemptr instead in event - MS-365 - Use tasktableitemptr instead in event
- MS-366 - Implement TaskTable
## New Feature ## New Feature
- MS-343 - Implement ResourceMgr - MS-343 - Implement ResourceMgr
......
...@@ -12,18 +12,23 @@ namespace zilliz { ...@@ -12,18 +12,23 @@ namespace zilliz {
namespace milvus { namespace milvus {
namespace engine { namespace engine {
TaskTable::TaskTable(std::vector<TaskPtr> &&tasks) {
}
void void
TaskTable::Put(TaskPtr task) { TaskTable::Put(TaskPtr task) {
auto item = std::make_shared<TaskTableItem>();
item->task = std::move(task);
item->state = TaskTableItemState::LOADED;
table_.push_back(item);
} }
void void
TaskTable::Put(std::vector<TaskPtr> &tasks) { TaskTable::Put(std::vector<TaskPtr> &tasks) {
for (auto &task : tasks) {
auto item = std::make_shared<TaskTableItem>();
item->task = std::move(task);
item->state = TaskTableItemState::LOADED;
table_.push_back(item);
}
} }
...@@ -56,26 +61,61 @@ TaskTable::Move(uint64_t index) { ...@@ -56,26 +61,61 @@ TaskTable::Move(uint64_t index) {
bool bool
TaskTable::Moved(uint64_t index) { TaskTable::Moved(uint64_t index) {
auto &task = table_[index];
std::lock_guard<std::mutex> lock(task->mutex);
if (task->state == TaskTableItemState::MOVING) {
task->state = TaskTableItemState::MOVED;
return true;
}
return false; return false;
} }
bool bool
TaskTable::Load(uint64_t index) { TaskTable::Load(uint64_t index) {
auto &task = table_[index];
std::lock_guard<std::mutex> lock(task->mutex);
if (task->state == TaskTableItemState::START) {
task->state = TaskTableItemState::LOADING;
return true;
}
return false; return false;
} }
bool bool
TaskTable::Loaded(uint64_t index) { TaskTable::Loaded(uint64_t index) {
auto &task = table_[index];
std::lock_guard<std::mutex> lock(task->mutex);
if (task->state == TaskTableItemState::LOADING) {
task->state = TaskTableItemState::LOADED;
return true;
}
return false; return false;
} }
bool bool
TaskTable::Execute(uint64_t index) { TaskTable::Execute(uint64_t index) {
auto &task = table_[index];
std::lock_guard<std::mutex> lock(task->mutex);
if (task->state == TaskTableItemState::LOADED) {
task->state = TaskTableItemState::EXECUTING;
return true;
}
return false; return false;
} }
bool bool
TaskTable::Executed(uint64_t index) { TaskTable::Executed(uint64_t index) {
auto &task = table_[index];
std::lock_guard<std::mutex> lock(task->mutex);
if (task->state == TaskTableItemState::EXECUTING) {
task->state = TaskTableItemState::EXECUTED;
return true;
}
return false; return false;
} }
......
...@@ -48,9 +48,6 @@ class TaskTable { ...@@ -48,9 +48,6 @@ class TaskTable {
public: public:
TaskTable() = default; TaskTable() = default;
explicit
TaskTable(std::vector<TaskPtr> &&tasks);
/* /*
* Put one task; * Put one task;
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册