diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 63f6999353..5bb6053d49 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -22,6 +22,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-364 - Modify tasktableitem in tasktable - MS-365 - Use tasktableitemptr instead in event - MS-366 - Implement TaskTable +- MS-368 - Implement cost.cpp ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/Cost.cpp b/cpp/src/scheduler/Cost.cpp index 14b56d98a5..724a717d2f 100644 --- a/cpp/src/scheduler/Cost.cpp +++ b/cpp/src/scheduler/Cost.cpp @@ -12,22 +12,40 @@ namespace milvus { namespace engine { std::vector -PickToMove(const TaskTable &task_table, const CacheMgr &cache_mgr, uint64_t limit) { +PickToMove(TaskTable &task_table, const CacheMgr &cache_mgr, uint64_t limit) { std::vector indexes; + for (uint64_t i = 0, count = 0; i < task_table.Size() && count < limit; ++i) { + if (task_table[i]->state == TaskTableItemState::LOADED) { + indexes.push_back(i); + ++count; + } + } return indexes; } std::vector -PickToLoad(const TaskTable &task_table, uint64_t limit) { +PickToLoad(TaskTable &task_table, uint64_t limit) { std::vector indexes; + for (uint64_t i = 0, count = 0; i < task_table.Size() && count < limit; ++i) { + if (task_table[i]->state == TaskTableItemState::START) { + indexes.push_back(i); + ++count; + } + } return indexes; } std::vector -PickToExecute(const TaskTable &task_table, uint64_t limit) { +PickToExecute(TaskTable &task_table, uint64_t limit) { std::vector indexes; + for (uint64_t i = 0, count = 0; i < task_table.Size() && count < limit; ++i) { + if (task_table[i]->state == TaskTableItemState::LOADED) { + indexes.push_back(i); + ++count; + } + } return indexes; } diff --git a/cpp/src/scheduler/Cost.h b/cpp/src/scheduler/Cost.h index 85414337bc..76f16d4d1d 100644 --- a/cpp/src/scheduler/Cost.h +++ b/cpp/src/scheduler/Cost.h @@ -23,7 +23,7 @@ namespace engine { * call from scheduler; */ std::vector -PickToMove(const TaskTable &task_table, const CacheMgr &cache_mgr, uint64_t limit); +PickToMove(TaskTable &task_table, const CacheMgr &cache_mgr, uint64_t limit); /* @@ -32,7 +32,7 @@ PickToMove(const TaskTable &task_table, const CacheMgr &cache_mgr, uint64_t limi * I DONT SURE NEED THIS; */ std::vector -PickToLoad(const TaskTable &task_table, uint64_t limit); +PickToLoad(TaskTable &task_table, uint64_t limit); /* * select task to execute; @@ -40,7 +40,7 @@ PickToLoad(const TaskTable &task_table, uint64_t limit); * I DONT SURE NEED THIS; */ std::vector -PickToExecute(const TaskTable &task_table, uint64_t limit); +PickToExecute(TaskTable &task_table, uint64_t limit); } diff --git a/cpp/src/scheduler/TaskTable.h b/cpp/src/scheduler/TaskTable.h index 21c376a627..528c2f3d5c 100644 --- a/cpp/src/scheduler/TaskTable.h +++ b/cpp/src/scheduler/TaskTable.h @@ -90,6 +90,14 @@ public: Size() { return table_.size(); } +public: + TaskTableItemPtr & + operator[](uint64_t index) { + return table_[index]; + } + + std::deque::iterator begin() { return table_.begin(); } + std::deque::iterator end() { return table_.end(); } public: