diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 63f69993533ebc65ee02582ff28e5391a19f5f4e..5bb6053d49fcc837894354831fa66628152db1f8 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 14b56d98a5b469223c2e7d25bbfa0bbdbd7d7b10..724a717d2f32f0475f8d119cbf4fb3ffb8d79092 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 85414337bc6c61b99abb881c9df37da34b14eb4f..76f16d4d1dcbe1b8f4f89ba80a66f34bb9115d64 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 21c376a627b253fc25a0d211da00a69f4e174e17..528c2f3d5cf7577ea8682897aa6de057d1315338 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: