From 5ac15923176130dc8e7274efb80fe108cc4bed02 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Mon, 23 Aug 2021 17:41:21 +0200 Subject: [PATCH] Remote Exec should not survive to a host failure --- examples/cpp/exec-remote/s4u-exec-remote.cpp | 13 +++++++++++++ examples/cpp/exec-remote/s4u-exec-remote.tesh | 3 +++ src/s4u/s4u_Exec.cpp | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/examples/cpp/exec-remote/s4u-exec-remote.cpp b/examples/cpp/exec-remote/s4u-exec-remote.cpp index dc91d04720..aa6d80bd25 100644 --- a/examples/cpp/exec-remote/s4u-exec-remote.cpp +++ b/examples/cpp/exec-remote/s4u-exec-remote.cpp @@ -42,6 +42,19 @@ static void wizard() exec->wait(); XBT_INFO("Done!"); + + XBT_INFO("And now, even harder. Start a remote activity on Ginette and turn off the host after 0.5 sec"); + exec = simgrid::s4u::this_actor::exec_init(48.492e6)->set_host(ginette); + exec->start(); + + simgrid::s4u::this_actor::sleep_for(0.5); + ginette->turn_off(); + try { + exec->wait(); + } catch (const simgrid::HostFailureException& e) { + XBT_INFO("Execution failed on %s", ginette->get_cname()); + } + XBT_INFO("Done!"); } int main(int argc, char* argv[]) diff --git a/examples/cpp/exec-remote/s4u-exec-remote.tesh b/examples/cpp/exec-remote/s4u-exec-remote.tesh index 9b2c9933e0..3ccd924355 100644 --- a/examples/cpp/exec-remote/s4u-exec-remote.tesh +++ b/examples/cpp/exec-remote/s4u-exec-remote.tesh @@ -10,3 +10,6 @@ $ ${bindir:=.}/s4u-exec-remote ${platfdir}/small_platform.xml "--log=root.fmt:[% > [ 1.500000] (1:test@Fafard) Loads before the move: Boivin=0; Fafard=0; Ginette=48492000 > [ 1.600000] (1:test@Fafard) Loads after the move: Boivin=98095000; Fafard=0; Ginette=0 > [ 2.000000] (1:test@Fafard) Done! +> [ 2.000000] (1:test@Fafard) And now, even harder. Start a remote activity on Ginette and turn off the host after 0.5 sec +> [ 2.500000] (1:test@Fafard) Execution failed on Ginette +> [ 2.500000] (1:test@Fafard) Done! diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index febefcebc6..ab680d81ae 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -7,6 +7,7 @@ #include "simgrid/exec.h" #include "simgrid/s4u/Actor.hpp" #include "simgrid/s4u/Exec.hpp" +#include "simgrid/s4u/Host.hpp" #include "src/kernel/activity/ExecImpl.hpp" #include "src/kernel/actor/ActorImpl.hpp" #include "src/kernel/actor/SimcallObserver.hpp" @@ -33,6 +34,13 @@ void Exec::complete(Activity::State state) ExecPtr Exec::init() { auto pimpl = kernel::activity::ExecImplPtr(new kernel::activity::ExecImpl()); + Host::on_state_change.connect([pimpl](s4u::Host const& h) { + if (not h.is_on() && pimpl->state_ == kernel::activity::State::RUNNING && + std::find(pimpl->get_hosts().begin(), pimpl->get_hosts().end(), &h) != pimpl->get_hosts().end()) { + pimpl->state_ = kernel::activity::State::FAILED; + pimpl->post(); + } + }); return ExecPtr(pimpl->get_iface()); } -- 2.20.1