MS-366 Implement TaskTable

Former-commit-id: e6d189c5c63b0477384353bf6f75482eeb196c7d
pull/191/head
wxyu 2019-08-16 16:09:02 +08:00
parent 404bc88b3f
commit 484f255f5e
3 changed files with 46 additions and 8 deletions

View File

@ -21,6 +21,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-361 - Add event in resource
- MS-364 - Modify tasktableitem in tasktable
- MS-365 - Use tasktableitemptr instead in event
- MS-366 - Implement TaskTable
## New Feature
- MS-343 - Implement ResourceMgr

View File

@ -12,18 +12,23 @@ namespace zilliz {
namespace milvus {
namespace engine {
TaskTable::TaskTable(std::vector<TaskPtr> &&tasks) {
}
void
TaskTable::Put(TaskPtr task) {
auto item = std::make_shared<TaskTableItem>();
item->task = std::move(task);
item->state = TaskTableItemState::LOADED;
table_.push_back(item);
}
void
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) {
bool
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;
}
bool
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;
}
bool
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;
}
bool
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;
}
bool
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;
}

View File

@ -48,9 +48,6 @@ class TaskTable {
public:
TaskTable() = default;
explicit
TaskTable(std::vector<TaskPtr> &&tasks);
/*
* Put one task;
*/