From 1938d6b769df40f9467381a125544315ab55a951 Mon Sep 17 00:00:00 2001 From: Wang Xiangyu Date: Thu, 20 Aug 2020 17:40:46 +0800 Subject: [PATCH] #3265 clear finished task to release some resource (#3360) Signed-off-by: Wang Xiangyu --- core/src/scheduler/TaskTable.cpp | 8 ++++++ core/src/scheduler/TaskTable.h | 4 +++ core/src/scheduler/task/FinishedTask.cpp | 34 +++++++++++++++++++++++ core/src/scheduler/task/FinishedTask.h | 35 ++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 core/src/scheduler/task/FinishedTask.cpp create mode 100644 core/src/scheduler/task/FinishedTask.h diff --git a/core/src/scheduler/TaskTable.cpp b/core/src/scheduler/TaskTable.cpp index 90996dc5..7b0bc27e 100644 --- a/core/src/scheduler/TaskTable.cpp +++ b/core/src/scheduler/TaskTable.cpp @@ -13,6 +13,7 @@ #include "Utils.h" #include "event/TaskTableUpdatedEvent.h" #include "scheduler/SchedInst.h" +#include "scheduler/task/FinishedTask.h" #include "utils/Log.h" #include "utils/TimeRecorder.h" @@ -146,6 +147,11 @@ TaskTableItem::Dump() const { return ret; } +void +TaskTableItem::SetFinished(const TaskPtr& t) { + task = t; +} + std::vector TaskTable::PickToLoad(uint64_t limit) { #if 1 @@ -162,6 +168,7 @@ TaskTable::PickToLoad(uint64_t limit) { break; if (not cross && table_[index]->IsFinish()) { table_.set_front(index); + table_[index]->SetFinished(FinishedTask::Create()); } else if (table_[index]->state == TaskTableItemState::LOADED) { cross = true; ++loaded_count; @@ -248,6 +255,7 @@ TaskTable::PickToExecute(uint64_t limit) { if (not cross && table_[index]->IsFinish()) { table_.set_front(index); + table_[index]->SetFinished(FinishedTask::Create()); } else if (table_[index]->state == TaskTableItemState::LOADED) { cross = true; indexes.push_back(index); diff --git a/core/src/scheduler/TaskTable.h b/core/src/scheduler/TaskTable.h index e4466b4e..066c33b4 100644 --- a/core/src/scheduler/TaskTable.h +++ b/core/src/scheduler/TaskTable.h @@ -94,6 +94,10 @@ struct TaskTableItem : public interface::dumpable { json Dump() const override; + + public: + void + SetFinished(const TaskPtr& t); }; class TaskTable : public interface::dumpable { diff --git a/core/src/scheduler/task/FinishedTask.cpp b/core/src/scheduler/task/FinishedTask.cpp new file mode 100644 index 00000000..46a42053 --- /dev/null +++ b/core/src/scheduler/task/FinishedTask.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#include "scheduler/task/FinishedTask.h" + +namespace milvus::scheduler { + +std::shared_ptr +FinishedTask::Create() { + return std::make_shared(); +} + +FinishedTask::FinishedTask() : Task(TaskType::SearchTask, nullptr) { +} + +Status +FinishedTask::OnLoad(LoadType type, uint8_t device_id) { + return Status::OK(); +} + +Status +FinishedTask::OnExecute() { + return Status::OK(); +} + +} // namespace milvus::scheduler diff --git a/core/src/scheduler/task/FinishedTask.h b/core/src/scheduler/task/FinishedTask.h new file mode 100644 index 00000000..0fa36c2e --- /dev/null +++ b/core/src/scheduler/task/FinishedTask.h @@ -0,0 +1,35 @@ +// Copyright (C) 2019-2020 Zilliz. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software distributed under the License +// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions and limitations under the License. + +#pragma once + +#include "scheduler/task/Task.h" + +#include + +namespace milvus::scheduler { + +class FinishedTask : public Task { + public: + static std::shared_ptr + Create(); + + public: + FinishedTask(); + + Status + OnLoad(LoadType type, uint8_t device_id) override; + + Status + OnExecute() override; +}; + +} // namespace milvus::scheduler -- GitLab