提交 8cfeb988 编写于 作者: W wxyu

MS-364 Modify tasktableitem in tasktable


Former-commit-id: 09f5f8f085cf93aaadd780c36a7bc8026fffe199
上级 e0f650cf
...@@ -19,6 +19,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -19,6 +19,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-357 - Add minimum schedule function - MS-357 - Add minimum schedule function
- MS-359 - Add cost test in new scheduler - MS-359 - Add cost test in new scheduler
- MS-361 - Add event in resource - MS-361 - Add event in resource
- MS-364 - Modify tasktableitem in tasktable
## New Feature ## New Feature
- MS-343 - Implement ResourceMgr - MS-343 - Implement ResourceMgr
......
...@@ -21,7 +21,7 @@ push_task(ResourcePtr &self, ResourcePtr &other) { ...@@ -21,7 +21,7 @@ push_task(ResourcePtr &self, ResourcePtr &other) {
auto indexes = PickToMove(self_task_table, cache, 1); auto indexes = PickToMove(self_task_table, cache, 1);
for (auto index : indexes) { for (auto index : indexes) {
if (self_task_table.Move(index)) { if (self_task_table.Move(index)) {
auto task = self_task_table.Get(index).task; auto task = self_task_table.Get(index)->task;
other_task_table.Put(task); other_task_table.Put(task);
// TODO: mark moved future // TODO: mark moved future
other->WakeupLoader(); other->WakeupLoader();
......
...@@ -27,7 +27,7 @@ TaskTable::Put(std::vector<TaskPtr> &tasks) { ...@@ -27,7 +27,7 @@ TaskTable::Put(std::vector<TaskPtr> &tasks) {
} }
TaskTableItem & TaskTableItemPtr
TaskTable::Get(uint64_t index) { TaskTable::Get(uint64_t index) {
return table_[index]; return table_[index];
} }
...@@ -46,9 +46,9 @@ bool ...@@ -46,9 +46,9 @@ bool
TaskTable::Move(uint64_t index) { TaskTable::Move(uint64_t index) {
auto &task = table_[index]; auto &task = table_[index];
std::lock_guard<std::mutex> lock(task.mutex); std::lock_guard<std::mutex> lock(task->mutex);
if (task.state == TaskTableItemState::START) { if (task->state == TaskTableItemState::START) {
task.state = TaskTableItemState::LOADING; task->state = TaskTableItemState::LOADING;
return true; return true;
} }
return false; return false;
......
...@@ -42,6 +42,8 @@ struct TaskTableItem { ...@@ -42,6 +42,8 @@ struct TaskTableItem {
uint8_t priority; // just a number, meaningless; uint8_t priority; // just a number, meaningless;
}; };
using TaskTableItemPtr = std::shared_ptr<TaskTableItem>;
class TaskTable { class TaskTable {
public: public:
TaskTable() = default; TaskTable() = default;
...@@ -65,7 +67,7 @@ public: ...@@ -65,7 +67,7 @@ public:
/* /*
* Return task table item reference; * Return task table item reference;
*/ */
TaskTableItem & TaskTableItemPtr
Get(uint64_t index); Get(uint64_t index);
/* /*
...@@ -154,7 +156,7 @@ public: ...@@ -154,7 +156,7 @@ public:
private: private:
// TODO: map better ? // TODO: map better ?
std::deque<TaskTableItem> table_; std::deque<TaskTableItemPtr> table_;
}; };
......
...@@ -46,7 +46,7 @@ TaskPtr Resource::pick_task_load() { ...@@ -46,7 +46,7 @@ TaskPtr Resource::pick_task_load() {
for (auto index : indexes) { for (auto index : indexes) {
// try to set one task loading, then return // try to set one task loading, then return
if (task_table_.Load(index)) if (task_table_.Load(index))
return task_table_.Get(index).task; return task_table_.Get(index)->task;
// else try next // else try next
} }
return nullptr; return nullptr;
...@@ -57,7 +57,7 @@ TaskPtr Resource::pick_task_execute() { ...@@ -57,7 +57,7 @@ TaskPtr Resource::pick_task_execute() {
for (auto index : indexes) { for (auto index : indexes) {
// try to set one task executing, then return // try to set one task executing, then return
if (task_table_.Execute(index)) if (task_table_.Execute(index))
return task_table_.Get(index).task; return task_table_.Get(index)->task;
// else try next // else try next
} }
return nullptr; return nullptr;
......
...@@ -13,14 +13,14 @@ protected: ...@@ -13,14 +13,14 @@ protected:
auto task = std::make_shared<XSearchTask>(); auto task = std::make_shared<XSearchTask>();
table_.Put(task); table_.Put(task);
} }
table_.Get(0).state = TaskTableItemState::INVALID; table_.Get(0)->state = TaskTableItemState::INVALID;
table_.Get(1).state = TaskTableItemState::START; table_.Get(1)->state = TaskTableItemState::START;
table_.Get(2).state = TaskTableItemState::LOADING; table_.Get(2)->state = TaskTableItemState::LOADING;
table_.Get(3).state = TaskTableItemState::LOADED; table_.Get(3)->state = TaskTableItemState::LOADED;
table_.Get(4).state = TaskTableItemState::EXECUTING; table_.Get(4)->state = TaskTableItemState::EXECUTING;
table_.Get(5).state = TaskTableItemState::EXECUTED; table_.Get(5)->state = TaskTableItemState::EXECUTED;
table_.Get(6).state = TaskTableItemState::MOVING; table_.Get(6)->state = TaskTableItemState::MOVING;
table_.Get(7).state = TaskTableItemState::MOVED; table_.Get(7)->state = TaskTableItemState::MOVED;
} }
......
...@@ -58,19 +58,19 @@ protected: ...@@ -58,19 +58,19 @@ protected:
TEST_F(TaskTableBaseTest, put_task) { TEST_F(TaskTableBaseTest, put_task) {
empty_table_.Put(task1_); empty_table_.Put(task1_);
ASSERT_EQ(empty_table_.Get(0).task, task1_); ASSERT_EQ(empty_table_.Get(0)->task, task1_);
} }
TEST_F(TaskTableBaseTest, put_invalid_test) { TEST_F(TaskTableBaseTest, put_invalid_test) {
empty_table_.Put(invalid_task_); empty_table_.Put(invalid_task_);
ASSERT_EQ(empty_table_.Get(0).task, invalid_task_); ASSERT_EQ(empty_table_.Get(0)->task, invalid_task_);
} }
TEST_F(TaskTableBaseTest, put_batch) { TEST_F(TaskTableBaseTest, put_batch) {
std::vector<TaskPtr> tasks{task1_, task2_}; std::vector<TaskPtr> tasks{task1_, task2_};
empty_table_.Put(tasks); empty_table_.Put(tasks);
ASSERT_EQ(empty_table_.Get(0).task, task1_); ASSERT_EQ(empty_table_.Get(0)->task, task1_);
ASSERT_EQ(empty_table_.Get(1).task, task2_); ASSERT_EQ(empty_table_.Get(1)->task, task2_);
} }
TEST_F(TaskTableBaseTest, put_empty_batch) { TEST_F(TaskTableBaseTest, put_empty_batch) {
...@@ -89,14 +89,14 @@ protected: ...@@ -89,14 +89,14 @@ protected:
table1_.Put(task); table1_.Put(task);
} }
table1_.Get(0).state = TaskTableItemState::INVALID; table1_.Get(0)->state = TaskTableItemState::INVALID;
table1_.Get(1).state = TaskTableItemState::START; table1_.Get(1)->state = TaskTableItemState::START;
table1_.Get(2).state = TaskTableItemState::LOADING; table1_.Get(2)->state = TaskTableItemState::LOADING;
table1_.Get(3).state = TaskTableItemState::LOADED; table1_.Get(3)->state = TaskTableItemState::LOADED;
table1_.Get(4).state = TaskTableItemState::EXECUTING; table1_.Get(4)->state = TaskTableItemState::EXECUTING;
table1_.Get(5).state = TaskTableItemState::EXECUTED; table1_.Get(5)->state = TaskTableItemState::EXECUTED;
table1_.Get(6).state = TaskTableItemState::MOVING; table1_.Get(6)->state = TaskTableItemState::MOVING;
table1_.Get(7).state = TaskTableItemState::MOVED; table1_.Get(7)->state = TaskTableItemState::MOVED;
} }
TaskTable table1_; TaskTable table1_;
...@@ -106,22 +106,22 @@ TEST_F(TaskTableAdvanceTest, load) { ...@@ -106,22 +106,22 @@ TEST_F(TaskTableAdvanceTest, load) {
table1_.Load(1); table1_.Load(1);
table1_.Loaded(2); table1_.Loaded(2);
ASSERT_EQ(table1_.Get(1).state, TaskTableItemState::LOADING); ASSERT_EQ(table1_.Get(1)->state, TaskTableItemState::LOADING);
ASSERT_EQ(table1_.Get(2).state, TaskTableItemState::LOADED); ASSERT_EQ(table1_.Get(2)->state, TaskTableItemState::LOADED);
} }
TEST_F(TaskTableAdvanceTest, execute) { TEST_F(TaskTableAdvanceTest, execute) {
table1_.Execute(3); table1_.Execute(3);
table1_.Executed(4); table1_.Executed(4);
ASSERT_EQ(table1_.Get(3).state, TaskTableItemState::EXECUTING); ASSERT_EQ(table1_.Get(3)->state, TaskTableItemState::EXECUTING);
ASSERT_EQ(table1_.Get(4).state, TaskTableItemState::EXECUTED); ASSERT_EQ(table1_.Get(4)->state, TaskTableItemState::EXECUTED);
} }
TEST_F(TaskTableAdvanceTest, move) { TEST_F(TaskTableAdvanceTest, move) {
table1_.Move(3); table1_.Move(3);
table1_.Moved(6); table1_.Moved(6);
ASSERT_EQ(table1_.Get(3).state, TaskTableItemState::MOVING); ASSERT_EQ(table1_.Get(3)->state, TaskTableItemState::MOVING);
ASSERT_EQ(table1_.Get(6).state, TaskTableItemState::MOVED); ASSERT_EQ(table1_.Get(6)->state, TaskTableItemState::MOVED);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册