You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2020/01/24 11:17:54 UTC
[mesos] 02/03: Sync'd whether an executor was generated to and from
disk.
This is an automated email from the ASF dual-hosted git repository.
bbannier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit e8ef153ef6702ba5d1e43bf1f3a736ca01d82454
Author: Benjamin Bannier <bb...@apache.org>
AuthorDate: Thu Jan 23 14:19:51 2020 +0100
Sync'd whether an executor was generated to and from disk.
This patch introduces an `ExecutorState` variable signifying whether an
executor was generated by the agent (and is thus unknown to the master).
Currently we still detect agent-generated executors with a heuristic,
but will adapt that heuristic in a follow-up path making us of the
additional state we now persist.
Review: https://reviews.apache.org/r/72034/
---
src/slave/paths.cpp | 15 +++++++++++++++
src/slave/paths.hpp | 7 +++++++
src/slave/slave.cpp | 10 ++++++++++
src/slave/state.cpp | 39 +++++++++++++++++++++++++++++++++++++++
src/slave/state.hpp | 1 +
5 files changed, 72 insertions(+)
diff --git a/src/slave/paths.cpp b/src/slave/paths.cpp
index af2679f..3e44b63 100644
--- a/src/slave/paths.cpp
+++ b/src/slave/paths.cpp
@@ -301,6 +301,21 @@ string getExecutorRunPath(
}
+string getExecutorGeneratedForCommandTaskPath(
+ const string& rootDir,
+ const SlaveID& slaveId,
+ const FrameworkID& frameworkId,
+ const ExecutorID& executorId)
+{
+ constexpr char EXECUTOR_GENERATED_FOR_COMMAND_TASK_PATH[] =
+ "executor_generated_for_command_task";
+
+ return path::join(
+ getExecutorPath(rootDir, slaveId, frameworkId, executorId),
+ EXECUTOR_GENERATED_FOR_COMMAND_TASK_PATH);
+}
+
+
string getExecutorHttpMarkerPath(
const string& rootDir,
const SlaveID& slaveId,
diff --git a/src/slave/paths.hpp b/src/slave/paths.hpp
index d7fcb13..7d43e9c 100644
--- a/src/slave/paths.hpp
+++ b/src/slave/paths.hpp
@@ -239,6 +239,13 @@ std::string getExecutorRunPath(
const ContainerID& containerId);
+std::string getExecutorGeneratedForCommandTaskPath(
+ const std::string& rootDir,
+ const SlaveID& slaveId,
+ const FrameworkID& frameworkId,
+ const ExecutorID& executorId);
+
+
std::string getExecutorHttpMarkerPath(
const std::string& rootDir,
const SlaveID& slaveId,
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 12008b7..4b02978 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -10628,6 +10628,7 @@ Executor::Executor(
// hacky. We rely on the fact that docker executor launch command is
// set in the docker containerizer so that this check is still valid
// in the slave.
+ // TODO(bbannier): Initialize this field with a value passed to constructor.
isGeneratedForCommandTask_ =
strings::endsWith(info.command().value(), MESOS_EXECUTOR) &&
strings::startsWith(info.name(), "Command Executor");
@@ -10778,6 +10779,15 @@ void Executor::checkpointExecutor()
CHECK_SOME(state::checkpoint(path, info));
+ // Sync state of sentinel indicating whether the executor was
+ // generated by the agent.
+ CHECK_SOME(state::checkpoint(
+ paths::getExecutorGeneratedForCommandTaskPath(
+ slave->metaDir, slave->info.id(), frameworkId, id),
+ stringify(static_cast<int>(isGeneratedForCommandTask_)),
+ true));
+
+
// Create the meta executor directory.
// NOTE: This creates the 'latest' symlink in the meta directory.
Try<string> mkdir = paths::createExecutorDirectory(
diff --git a/src/slave/state.cpp b/src/slave/state.cpp
index 821132b..96f22b3 100644
--- a/src/slave/state.cpp
+++ b/src/slave/state.cpp
@@ -48,6 +48,7 @@
#include "messages/messages.hpp"
+#include "slave/constants.hpp"
#include "slave/paths.hpp"
#include "slave/state.hpp"
#include "slave/state.pb.h"
@@ -497,6 +498,44 @@ Try<ExecutorState> ExecutorState::recover(
state.info = executorInfo.get();
+ const string executorGeneratedForCommandTaskPath =
+ paths::getExecutorGeneratedForCommandTaskPath(
+ rootDir, slaveId, frameworkId, executorId);
+
+ if (os::exists(executorGeneratedForCommandTaskPath)) {
+ Try<string> read = os::read(executorGeneratedForCommandTaskPath);
+
+ if (read.isError()) {
+ return Error(
+ "Could not read '" + executorGeneratedForCommandTaskPath + "': " +
+ read.error());
+ }
+
+ Try<int> generatedForCommandTask = numify<int>(*read);
+
+ if (generatedForCommandTask.isError()) {
+ return Error(
+ "Could not parse '" + executorGeneratedForCommandTaskPath + "': " +
+ generatedForCommandTask.error());
+ }
+
+ state.generatedForCommandTask = *generatedForCommandTask;
+ } else {
+ // If we did not find persisted information on whether this executor was
+ // generated by the agent, use a heuristic.
+ //
+ // TODO(bbannier): Remove this code once we do not need to support
+ // versions anymore which do not persist this information.
+ // TODO(jieyu): The way we determine if an executor is generated for
+ // a command task (either command or docker executor) is really
+ // hacky. We rely on the fact that docker executor launch command is
+ // set in the docker containerizer so that this check is still valid
+ // in the slave.
+ state.generatedForCommandTask =
+ strings::endsWith(executorInfo->command().value(), MESOS_EXECUTOR) &&
+ strings::startsWith(executorInfo->name(), "Command Executor");
+ }
+
return state;
}
diff --git a/src/slave/state.hpp b/src/slave/state.hpp
index 6d6ae01..e80aac5 100644
--- a/src/slave/state.hpp
+++ b/src/slave/state.hpp
@@ -333,6 +333,7 @@ struct ExecutorState
Option<ContainerID> latest;
hashmap<ContainerID, RunState> runs;
unsigned int errors;
+ bool generatedForCommandTask = false;
};