Commit 6df2c722 authored by Stanislav Bohm's avatar Stanislav Bohm

RF: WStatus

parent 67bb8cc2
......@@ -18,7 +18,7 @@ public:
New,
Connecting,
Open,
Closing,
Closing,
Closed,
};
......
......@@ -43,16 +43,16 @@ void ComputationState::set_running_task(const PlanNode &node, WorkerConnection *
assert(it != pending_tasks.end());
pending_tasks.erase(it);
assert(state.get_worker_status(wc) == TaskState::S_NONE);
state.set_worker_status(wc, TaskState::S_RUNNING);
assert(state.get_worker_status(wc) == WStatus::NONE);
state.set_worker_status(wc, WStatus::RUNNING);
workers[wc].free_cpus -= node.get_n_cpus();
}
void ComputationState::set_task_finished(const PlanNode&node, size_t size, size_t length, WorkerConnection *wc)
{
TaskState &state = get_state(node.get_id());
assert(state.get_worker_status(wc) == TaskState::S_RUNNING);
state.set_worker_status(wc, TaskState::S_OWNER);
assert(state.get_worker_status(wc) == WStatus::RUNNING);
state.set_worker_status(wc, WStatus::OWNER);
state.set_size(size);
state.set_length(length);
workers[wc].free_cpus += node.get_n_cpus();
......@@ -293,7 +293,7 @@ void ComputationState::collect_requirements_for_node(WorkerConnection *wc,
{
for (loom::base::Id id : node.get_inputs()) {
TaskState &state = get_state(id);
if (state.get_worker_status(wc) == TaskState::S_OWNER) {
if (state.get_worker_status(wc) == WStatus::OWNER) {
// nothing
} else {
nonlocals.insert(id);
......
......@@ -162,7 +162,7 @@ Scheduler::Scheduler(ComputationState &cstate)
const TaskState &state = cstate.get_state(pair.first);
DataObj obj;
obj.size = state.get_size();
state.foreach_source([&obj, &worker_map](WorkerConnection *wc) {
state.foreach_planned_owner([&obj, &worker_map](WorkerConnection *wc) {
obj.owners.push_back(worker_map[wc]);
});
data[pair.second] = std::move(obj);
......
......@@ -50,12 +50,12 @@ void TaskManager::start_task(WorkerConnection *wc, Id task_id)
const PlanNode &node = cstate.get_node(task_id);
for (loom::base::Id id : node.get_inputs()) {
TaskState &state = cstate.get_state(id);
TaskState::WStatus st = state.get_worker_status(wc);
if (st == TaskState::S_NONE) {
WStatus st = state.get_worker_status(wc);
if (st == WStatus::NONE) {
WorkerConnection *owner = state.get_first_owner();
assert(owner);
owner->send_data(id, wc->get_address());
state.set_worker_status(wc, TaskState::S_OWNER);
state.set_worker_status(wc, WStatus::OWNER);
}
}
......
......@@ -18,7 +18,7 @@ std::string TaskState::get_info() const
s << "[TS id=" << id << " size=" << size;
for (auto &pair : workers) {
s << " " << pair.first->get_address() << ":";
s << pair.second;
s << static_cast<int>(pair.second);
}
s << "]";
return s.str();
......
......@@ -10,16 +10,24 @@ template<typename T> using WorkerMap = std::unordered_map<WorkerConnection*, T>;
class ComputationState;
class PlanNode;
enum class WStatus {
NONE,
READY,
RUNNING,
TRANSFER,
OWNER,
};
inline bool is_planned_owner(WStatus status) {
return status == WStatus::OWNER || \
status == WStatus::RUNNING || \
status == WStatus::TRANSFER;
}
class TaskState {
public:
enum WStatus {
S_NONE,
S_READY,
S_RUNNING,
S_OWNER,
};
TaskState(const PlanNode &node);
loom::base::Id get_id() const {
......@@ -61,14 +69,14 @@ public:
WStatus get_worker_status(WorkerConnection *wc) {
auto i = workers.find(wc);
if (i == workers.end()) {
return S_NONE;
return WStatus::NONE;
}
return i->second;
}
WorkerConnection *get_first_owner() {
for (auto &p : workers) {
if (p.second == S_OWNER) {
if (p.second == WStatus::OWNER) {
return p.first;
}
}
......@@ -81,17 +89,16 @@ public:
bool is_running() const {
for(auto &pair : workers) {
if (pair.second == S_RUNNING) {
if (pair.second == WStatus::RUNNING) {
return true;
}
}
return false;
}
template<typename F> void foreach_source(F f) const {
template<typename F> void foreach_planned_owner(F f) const {
for(auto &pair : workers) {
if (pair.second == S_OWNER || pair.second == S_RUNNING) {
if (is_planned_owner(pair.second)) {
f(pair.first);
}
}
......@@ -99,7 +106,7 @@ public:
template<typename F> void foreach_owner(F f) const {
for(auto &pair : workers) {
if (pair.second == S_OWNER) {
if (pair.second == WStatus::OWNER) {
f(pair.first);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment