From ac230a7ec3bf2be6ae343d8da2879f13d3aad357 Mon Sep 17 00:00:00 2001 From: wxyu Date: Sun, 18 Aug 2019 19:59:15 +0800 Subject: [PATCH] MS-374 Add action definition Former-commit-id: d3ed4be48d8c27f380b9d20d7eb1bff6abe7cee0 --- cpp/CHANGELOG.md | 1 + cpp/src/scheduler/action/Action.h | 34 +++++++++++++ .../action/PullTaskFromNeighbour.cpp | 24 +++++++++ .../scheduler/action/PushTaskToNeighbour.cpp | 49 +++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 cpp/src/scheduler/action/Action.h create mode 100644 cpp/src/scheduler/action/PullTaskFromNeighbour.cpp create mode 100644 cpp/src/scheduler/action/PushTaskToNeighbour.cpp diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index bc75974f..07f8ba34 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -25,6 +25,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-368 - Implement cost.cpp - MS-371 - Add TaskTableUpdatedEvent - MS-373 - Add resource test +- MS-374 - Add action definition ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/action/Action.h b/cpp/src/scheduler/action/Action.h new file mode 100644 index 00000000..d72bbefc --- /dev/null +++ b/cpp/src/scheduler/action/Action.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * copyright 上海赜睿信息科技有限公司(zilliz) - all rights reserved + * unauthorized copying of this file, via any medium is strictly prohibited. + * proprietary and confidential. + ******************************************************************************/ +#pragma once + +#include "../resource/Resource.h" + + +namespace zilliz { +namespace milvus { +namespace engine { + +class Action { +public: + /* + * Push task to neighbour; + */ + static void + PushTaskToNeighbour(const ResourceWPtr &self); + + + /* + * Pull task From neighbour; + */ + static void + PullTaskFromNeighbour(const ResourceWPtr &self); +}; + + +} +} +} diff --git a/cpp/src/scheduler/action/PullTaskFromNeighbour.cpp b/cpp/src/scheduler/action/PullTaskFromNeighbour.cpp new file mode 100644 index 00000000..b1ac97b6 --- /dev/null +++ b/cpp/src/scheduler/action/PullTaskFromNeighbour.cpp @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ + +#include "Action.h" + + +namespace zilliz { +namespace milvus { +namespace engine { + +void +Action::PullTaskFromNeighbour(const ResourceWPtr &self) { + // TODO: implement +} + + +} +} +} + + diff --git a/cpp/src/scheduler/action/PushTaskToNeighbour.cpp b/cpp/src/scheduler/action/PushTaskToNeighbour.cpp new file mode 100644 index 00000000..4347ee84 --- /dev/null +++ b/cpp/src/scheduler/action/PushTaskToNeighbour.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved + * Unauthorized copying of this file, via any medium is strictly prohibited. + * Proprietary and confidential. + ******************************************************************************/ + +#include "Action.h" + + +namespace zilliz { +namespace milvus { +namespace engine { + +void +push_task(ResourcePtr &self, ResourcePtr &other) { + auto self_task_table = self->task_table(); + auto other_task_table = other->task_table(); + if (!other_task_table.Empty()) { + CacheMgr cache; + auto indexes = PickToMove(self_task_table, cache, 1); + for (auto index : indexes) { + if (self_task_table.Move(index)) { + auto task = self_task_table.Get(index)->task; + other_task_table.Put(task); + // TODO: mark moved future + other->WakeupLoader(); + other->WakeupExecutor(); + } + } + } +} + +void +Action::PushTaskToNeighbour(const ResourceWPtr &res) { + if (auto self = res.lock()) { + for (auto &neighbour : self->GetNeighbours()) { + if (auto n = neighbour.neighbour_node.lock()) { + auto neighbour = std::static_pointer_cast(n); + push_task(self, neighbour); + } + } + } +} + + +} +} +} + -- GitLab