From 63b43a2aa411ff9e381b228c28985ead546af0d3 Mon Sep 17 00:00:00 2001 From: wxyu Date: Mon, 26 Aug 2019 15:36:19 +0800 Subject: [PATCH] MS-421 Add TaskLabel in scheduler Former-commit-id: 5a96ba4e51f67d13e2440af594034dacd6b6097b --- cpp/CHANGELOG.md | 1 + cpp/src/scheduler/Scheduler.cpp | 2 - cpp/src/scheduler/resource/Resource.h | 1 + cpp/src/scheduler/task/Task.h | 25 ++++++++--- cpp/src/scheduler/task/TaskConvert.cpp | 4 ++ cpp/src/scheduler/tasklabel/BroadcastLabel.h | 27 +++++++++++ cpp/src/scheduler/tasklabel/DefaultLabel.h | 28 ++++++++++++ cpp/src/scheduler/tasklabel/SpecResLabel.h | 47 ++++++++++++++++++++ cpp/src/scheduler/tasklabel/TaskLabel.h | 39 ++++++++++++++++ 9 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 cpp/src/scheduler/tasklabel/BroadcastLabel.h create mode 100644 cpp/src/scheduler/tasklabel/DefaultLabel.h create mode 100644 cpp/src/scheduler/tasklabel/SpecResLabel.h create mode 100644 cpp/src/scheduler/tasklabel/TaskLabel.h diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 268940e8..76dd3a8f 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -57,6 +57,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-415 - Add command tasktable to dump all tasktables - MS-418 - Update server_config.template file, set CPU compute only default - MS-419 - Move index_file_size from IndexParam to TableSchema +- MS-421 - Add TaskLabel in scheduler ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/Scheduler.cpp b/cpp/src/scheduler/Scheduler.cpp index 85fa9058..164ea430 100644 --- a/cpp/src/scheduler/Scheduler.cpp +++ b/cpp/src/scheduler/Scheduler.cpp @@ -104,8 +104,6 @@ Scheduler::OnStartUp(const EventPtr &event) { void Scheduler::OnFinishTask(const EventPtr &event) { - if (auto resource = event->resource_.lock()) { - } } void diff --git a/cpp/src/scheduler/resource/Resource.h b/cpp/src/scheduler/resource/Resource.h index 5a6ae28c..e55f84de 100644 --- a/cpp/src/scheduler/resource/Resource.h +++ b/cpp/src/scheduler/resource/Resource.h @@ -29,6 +29,7 @@ namespace zilliz { namespace milvus { namespace engine { +// TODO(wxyu): Storage, Route, Executor enum class ResourceType { DISK = 0, CPU = 1, diff --git a/cpp/src/scheduler/task/Task.h b/cpp/src/scheduler/task/Task.h index bc2dae46..31a1a884 100644 --- a/cpp/src/scheduler/task/Task.h +++ b/cpp/src/scheduler/task/Task.h @@ -5,10 +5,12 @@ ******************************************************************************/ #pragma once +#include "db/scheduler/context/SearchContext.h" +#include "db/scheduler/task/IScheduleTask.h" +#include "scheduler/tasklabel/TaskLabel.h" + #include #include -#include -#include "src/db/scheduler/task/IScheduleTask.h" namespace zilliz { @@ -36,6 +38,21 @@ public: explicit Task(TaskType type) : type_(type) {} + /* + * Just Getter; + */ + inline TaskType + Type() const { return type_; } + + /* + * Getter and Setter; + */ + inline TaskLabelPtr & + label() { + return label_; + } + +public: virtual void Load(LoadType type, uint8_t device_id) = 0; @@ -46,13 +63,11 @@ public: virtual TaskPtr Clone() = 0; - inline TaskType - Type() const { return type_; } - public: std::vector search_contexts_; ScheduleTaskPtr task_; TaskType type_; + TaskLabelPtr label_ = nullptr; }; diff --git a/cpp/src/scheduler/task/TaskConvert.cpp b/cpp/src/scheduler/task/TaskConvert.cpp index 43f70903..30a3a38b 100644 --- a/cpp/src/scheduler/task/TaskConvert.cpp +++ b/cpp/src/scheduler/task/TaskConvert.cpp @@ -5,6 +5,8 @@ ******************************************************************************/ #include "TaskConvert.h" +#include "scheduler/tasklabel/DefaultLabel.h" +#include "scheduler/tasklabel/BroadcastLabel.h" namespace zilliz { @@ -17,6 +19,7 @@ TaskConvert(const ScheduleTaskPtr &schedule_task) { case ScheduleTaskType::kIndexLoad: { auto load_task = std::static_pointer_cast(schedule_task); auto task = std::make_shared(load_task->file_); + task->label() = std::make_shared(); task->search_contexts_ = load_task->search_contexts_; task->task_ = schedule_task; return task; @@ -24,6 +27,7 @@ TaskConvert(const ScheduleTaskPtr &schedule_task) { case ScheduleTaskType::kDelete: { auto delete_task = std::static_pointer_cast(schedule_task); auto task = std::make_shared(delete_task->context_); + task->label() = std::make_shared(); return task; } default: { diff --git a/cpp/src/scheduler/tasklabel/BroadcastLabel.h b/cpp/src/scheduler/tasklabel/BroadcastLabel.h new file mode 100644 index 00000000..406add51 --- /dev/null +++ b/cpp/src/scheduler/tasklabel/BroadcastLabel.h @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include "TaskLabel.h" + +#include + + +namespace zilliz { +namespace milvus { +namespace engine { + + +class BroadcastLabel : public TaskLabel { +public: + BroadcastLabel() : TaskLabel(TaskLabelType::BROADCAST) {} +}; + +using BroadcastLabelPtr = std::shared_ptr; + +} +} +} diff --git a/cpp/src/scheduler/tasklabel/DefaultLabel.h b/cpp/src/scheduler/tasklabel/DefaultLabel.h new file mode 100644 index 00000000..ada34cd6 --- /dev/null +++ b/cpp/src/scheduler/tasklabel/DefaultLabel.h @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include "TaskLabel.h" + +#include + + +namespace zilliz { +namespace milvus { +namespace engine { + +class DefaultLabel : public TaskLabel { +public: + DefaultLabel() : TaskLabel(TaskLabelType::DEFAULT) {} +}; + +using DefaultLabelPtr = std::shared_ptr; + +} +} +} + + diff --git a/cpp/src/scheduler/tasklabel/SpecResLabel.h b/cpp/src/scheduler/tasklabel/SpecResLabel.h new file mode 100644 index 00000000..9f69f575 --- /dev/null +++ b/cpp/src/scheduler/tasklabel/SpecResLabel.h @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include "TaskLabel.h" + +#include +#include + + +class Resource; + +using ResourceWPtr = std::weak_ptr; + +namespace zilliz { +namespace milvus { +namespace engine { + +class SpecResLabel : public TaskLabel { +public: + SpecResLabel(const ResourceWPtr &resource) + : TaskLabel(TaskLabelType::SPECIAL_RESOURCE), resource_(resource) {} + + inline ResourceWPtr & + resource() const { + return resource_; + } + + inline std::string & + resource_name() const { + return resource_name_; + } + +private: + ResourceWPtr resource_; + std::string resource_name_; +} + +using SpecResLabelPtr = std::make_shared; + +} +} +} + diff --git a/cpp/src/scheduler/tasklabel/TaskLabel.h b/cpp/src/scheduler/tasklabel/TaskLabel.h new file mode 100644 index 00000000..3f39b8ec --- /dev/null +++ b/cpp/src/scheduler/tasklabel/TaskLabel.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include + +namespace zilliz { +namespace milvus { +namespace engine { + +enum class TaskLabelType { + DEFAULT, // means can be executed in any resource + SPECIAL_RESOURCE, // means must executing in special resource + BROADCAST, // means all enable-executor resource must execute task +}; + +class TaskLabel { +public: + inline TaskLabelType + Type() const { + return type_; + } + +protected: + TaskLabel(TaskLabelType type) : type_(type) {} + +private: + TaskLabelType type_; +}; + +using TaskLabelPtr = std::shared_ptr; + +} +} +} + -- GitLab