You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2016/09/26 01:55:03 UTC

mesos git commit: Fixed driver based schedulers to ACK updates from HTTP executors.

Repository: mesos
Updated Branches:
  refs/heads/master f8c684019 -> ec4c81a12


Fixed driver based schedulers to ACK updates from HTTP executors.

Previously, driver based schedulers were not able to acknowledge
status updates from HTTP based executors if they had explicit
acknowledgements enabled. This was due to the fact that we
were not populating `TaskStatus.slave_id` correctly if not
set. It would also be great to validate `TaskStatus.slave_id`
set by the executor and let them know if the value is incorrect.

Review: https://reviews.apache.org/r/52231/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ec4c81a1
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ec4c81a1
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ec4c81a1

Branch: refs/heads/master
Commit: ec4c81a12559030791334359e7e1e2b6565cce01
Parents: f8c6840
Author: Anand Mazumdar <an...@apache.org>
Authored: Sun Sep 25 18:54:21 2016 -0700
Committer: Anand Mazumdar <an...@apache.org>
Committed: Sun Sep 25 18:54:21 2016 -0700

----------------------------------------------------------------------
 src/common/protobuf_utils.cpp        | 10 +++-
 src/slave/slave.cpp                  | 16 +++++++
 src/tests/command_executor_tests.cpp | 78 ++++++++++++++++++++++++++++++-
 3 files changed, 101 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ec4c81a1/src/common/protobuf_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp
index 5db4be4..3ff37f4 100644
--- a/src/common/protobuf_utils.cpp
+++ b/src/common/protobuf_utils.cpp
@@ -172,11 +172,17 @@ StatusUpdate createStatusUpdate(
     update.mutable_executor_id()->MergeFrom(status.executor_id());
   }
 
+  update.mutable_status()->MergeFrom(status);
+
   if (slaveId.isSome()) {
     update.mutable_slave_id()->MergeFrom(slaveId.get());
-  }
 
-  update.mutable_status()->MergeFrom(status);
+    // We also populate `TaskStatus.slave_id` if the executor
+    // did not set it.
+    if (!status.has_slave_id()) {
+      update.mutable_status()->mutable_slave_id()->MergeFrom(slaveId.get());
+    }
+  }
 
   if (!status.has_timestamp()) {
     update.set_timestamp(process::Clock::now().secs());

http://git-wip-us.apache.org/repos/asf/mesos/blob/ec4c81a1/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 11e9c8a..fdcc6d9 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -3616,6 +3616,22 @@ void Slave::statusUpdate(StatusUpdate update, const Option<UPID>& pid)
     return;
   }
 
+  if (update.slave_id() != info.id()) {
+    LOG(WARNING) << "Ignoring status update " << update << " due to "
+                 << "Slave ID mismatch; expected '" << info.id()
+                 << "', received '" << update.slave_id() << "'";
+    metrics.invalid_status_updates++;
+    return;
+  }
+
+  if (update.status().slave_id() != info.id()) {
+    LOG(WARNING) << "Ignoring status update " << update << " due to "
+                 << "Slave ID mismatch; expected '" << info.id()
+                 << "', received '" << update.status().slave_id() << "'";
+    metrics.invalid_status_updates++;
+    return;
+  }
+
   // TODO(bmahler): With the HTTP API, we must validate the UUID
   // inside the TaskStatus. For now, we ensure that the uuid of task
   // status matches the update's uuid, in case the executor is using

http://git-wip-us.apache.org/repos/asf/mesos/blob/ec4c81a1/src/tests/command_executor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/command_executor_tests.cpp b/src/tests/command_executor_tests.cpp
index beb3cbc..6e47243 100644
--- a/src/tests/command_executor_tests.cpp
+++ b/src/tests/command_executor_tests.cpp
@@ -185,7 +185,7 @@ TEST_P(CommandExecutorTest, TaskKillingCapability)
   TaskInfo task = createTask(
       offers->front().slave_id(),
       offers->front().resources(),
-      "sleep 1000");
+       "sleep 1000");
 
   Future<TaskStatus> statusRunning;
   EXPECT_CALL(sched, statusUpdate(_, _))
@@ -296,6 +296,82 @@ TEST_F(HTTPCommandExecutorTest, TerminateWithACK)
   wait(slave);
 }
 
+
+// This test ensures that driver based schedulers using explicit
+// acknowledgements can acknowledge status updates sent from
+// HTTP based executors.
+TEST_F(HTTPCommandExecutorTest, ExplicitAcknowledgements)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+
+  slave::Flags flags = CreateSlaveFlags();
+  flags.http_command_executor = true;
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags);
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched,
+      DEFAULT_FRAMEWORK_INFO,
+      master.get()->pid,
+      false,
+      DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(sched, registered(&driver, _, _));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(offers);
+  EXPECT_EQ(1u, offers->size());
+
+  // Launch a task with the command executor.
+  TaskInfo task = createTask(
+      offers->front().slave_id(),
+      offers->front().resources(),
+      "sleep 1000");
+
+  Future<TaskStatus> statusRunning;
+  EXPECT_CALL(sched, statusUpdate(_, _))
+    .WillOnce(FutureArg<1>(&statusRunning));
+
+  // Ensure no status update acknowledgements are sent from the driver
+  // to the master until the explicit acknowledgement is sent.
+  EXPECT_NO_FUTURE_CALLS(
+      mesos::scheduler::Call(),
+      mesos::scheduler::Call::ACKNOWLEDGE,
+      _ ,
+      master.get()->pid);
+
+  driver.launchTasks(offers->front().id(), {task});
+
+  AWAIT_READY(statusRunning);
+  EXPECT_TRUE(statusRunning->has_slave_id());
+  EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+  // Now send the acknowledgement.
+  Future<mesos::scheduler::Call> acknowledgement = FUTURE_CALL(
+      mesos::scheduler::Call(),
+      mesos::scheduler::Call::ACKNOWLEDGE,
+      _,
+      master.get()->pid);
+
+  driver.acknowledgeStatusUpdate(statusRunning.get());
+
+  AWAIT_READY(acknowledgement);
+
+  driver.stop();
+  driver.join();
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {