You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2018/01/11 00:18:29 UTC

[4/5] mesos git commit: Replaced `protobuf::read` with `state::read`.

Replaced `protobuf::read` with `state::read`.

The `state::checkpoint` utility was updated to checkpoint
the automatically downgraded resources. This was done to mitigate
the need to manually invoke `downgradeResources` prior to
checkpointing. `state::read` was introduced to provide a symmetric
functionality for `state::checkpoint`. Specifically, it will perform
upgrade resources upon reading the checkpointed resources state.

This patch updates the previous uses of `protobuf::read` accompanied
by calls to `convertResourceFormat`. Rather than reading the protobufs
then upgrading the resources, we know simply call `state::read` which
performs the reverse operation of `state::checkpoint`.

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


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

Branch: refs/heads/master
Commit: 80f66061e343fa26dd7e3b9613f0fa8e0b9b4a36
Parents: ef30390
Author: Michael Park <mp...@apache.org>
Authored: Fri Jan 5 18:03:42 2018 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Wed Jan 10 15:57:11 2018 -0800

----------------------------------------------------------------------
 src/resource_provider/storage/provider.cpp      | 19 +++-------------
 src/slave/containerizer/mesos/paths.cpp         | 23 ++++----------------
 .../provisioner/docker/metadata_manager.cpp     |  2 +-
 .../mesos/provisioner/provisioner.cpp           |  2 +-
 src/slave/state.cpp                             | 23 ++++----------------
 src/tests/slave_recovery_tests.cpp              | 12 +++-------
 6 files changed, 16 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/80f66061/src/resource_provider/storage/provider.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index c0bf3fa..9a32204 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -706,7 +706,7 @@ Future<Nothing> StorageLocalResourceProviderProcess::recoverServices()
 
       if (os::exists(configPath)) {
         Try<CSIPluginContainerInfo> config =
-          ::protobuf::read<CSIPluginContainerInfo>(configPath);
+          slave::state::read<CSIPluginContainerInfo>(configPath);
 
         if (config.isError()) {
           return Failure(
@@ -714,9 +714,6 @@ Future<Nothing> StorageLocalResourceProviderProcess::recoverServices()
               configPath + "': " + config.error());
         }
 
-        convertResourceFormat(
-            config->mutable_resources(), POST_RESERVATION_REFINEMENT);
-
         if (getCSIPluginContainerInfo(info, containerId) == config.get()) {
           continue;
         }
@@ -799,7 +796,7 @@ Future<Nothing> StorageLocalResourceProviderProcess::recoverVolumes()
     }
 
     Try<csi::state::VolumeState> volumeState =
-      ::protobuf::read<csi::state::VolumeState>(statePath);
+      slave::state::read<csi::state::VolumeState>(statePath);
 
     if (volumeState.isError()) {
       return Failure(
@@ -903,7 +900,7 @@ StorageLocalResourceProviderProcess::recoverResourceProviderState()
     }
 
     Try<ResourceProviderState> resourceProviderState =
-      ::protobuf::read<ResourceProviderState>(statePath);
+      slave::state::read<ResourceProviderState>(statePath);
 
     if (resourceProviderState.isError()) {
       return Failure(
@@ -911,16 +908,6 @@ StorageLocalResourceProviderProcess::recoverResourceProviderState()
           "': " + resourceProviderState.error());
     }
 
-    foreach (
-        Operation& operation,
-        *resourceProviderState->mutable_operations()) {
-      upgradeResources(operation.mutable_info());
-    }
-
-    convertResourceFormat(
-        resourceProviderState->mutable_resources(),
-        POST_RESERVATION_REFINEMENT);
-
     foreach (const Operation& operation,
              resourceProviderState->operations()) {
       Try<id::UUID> uuid = id::UUID::fromBytes(operation.uuid().value());

http://git-wip-us.apache.org/repos/asf/mesos/blob/80f66061/src/slave/containerizer/mesos/paths.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/paths.cpp b/src/slave/containerizer/mesos/paths.cpp
index 4cec2d2..4784d91 100644
--- a/src/slave/containerizer/mesos/paths.cpp
+++ b/src/slave/containerizer/mesos/paths.cpp
@@ -23,6 +23,7 @@
 #include "common/resources_utils.hpp"
 
 #include "slave/containerizer/mesos/paths.hpp"
+#include "slave/state.hpp"
 
 #ifndef __WINDOWS__
 namespace unix = process::network::unix;
@@ -277,16 +278,13 @@ Result<ContainerTermination> getContainerTermination(
   }
 
   Try<ContainerTermination> termination =
-    ::protobuf::read<ContainerTermination>(path);
+    state::read<ContainerTermination>(path);
 
   if (termination.isError()) {
     return Error("Failed to read termination state of container: " +
                  termination.error());
   }
 
-  convertResourceFormat(
-      termination->mutable_limited_resources(), POST_RESERVATION_REFINEMENT);
-
   return termination;
 }
 
@@ -327,25 +325,12 @@ Result<ContainerConfig> getContainerConfig(
     return None();
   }
 
-  Try<ContainerConfig> containerConfig =
-    ::protobuf::read<ContainerConfig>(path);
-
+  Try<ContainerConfig> containerConfig = state::read<ContainerConfig>(path);
   if (containerConfig.isError()) {
     return Error("Failed to read launch config of container: " +
                  containerConfig.error());
   }
 
-  convertResourceFormat(
-      containerConfig->mutable_executor_info()->mutable_resources(),
-      POST_RESERVATION_REFINEMENT);
-
-  convertResourceFormat(
-      containerConfig->mutable_task_info()->mutable_resources(),
-      POST_RESERVATION_REFINEMENT);
-
-  convertResourceFormat(
-      containerConfig->mutable_resources(), POST_RESERVATION_REFINEMENT);
-
   return containerConfig;
 }
 
@@ -436,7 +421,7 @@ Result<ContainerLaunchInfo> getContainerLaunchInfo(
   }
 
   Try<ContainerLaunchInfo> containerLaunchInfo =
-    ::protobuf::read<ContainerLaunchInfo>(path);
+    state::read<ContainerLaunchInfo>(path);
 
   if (containerLaunchInfo.isError()) {
     return Error(

http://git-wip-us.apache.org/repos/asf/mesos/blob/80f66061/src/slave/containerizer/mesos/provisioner/docker/metadata_manager.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/metadata_manager.cpp b/src/slave/containerizer/mesos/provisioner/docker/metadata_manager.cpp
index 548c524..168f786 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/metadata_manager.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/metadata_manager.cpp
@@ -256,7 +256,7 @@ Future<Nothing> MetadataManagerProcess::recover()
     return Nothing();
   }
 
-  Try<Images> images = ::protobuf::read<Images>(storedImagesPath);
+  Try<Images> images = state::read<Images>(storedImagesPath);
   if (images.isError()) {
     return Failure("Failed to read images from '" + storedImagesPath + "' " +
                    images.error());

http://git-wip-us.apache.org/repos/asf/mesos/blob/80f66061/src/slave/containerizer/mesos/provisioner/provisioner.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/provisioner.cpp b/src/slave/containerizer/mesos/provisioner/provisioner.cpp
index 57a437b..39eea34 100644
--- a/src/slave/containerizer/mesos/provisioner/provisioner.cpp
+++ b/src/slave/containerizer/mesos/provisioner/provisioner.cpp
@@ -429,7 +429,7 @@ Future<Nothing> ProvisionerProcess::recover(
       VLOG(1) << "Layers path '" << path << "' is missing for container' "
               << containerId << "'";
     } else {
-      Try<ContainerLayers> layers = ::protobuf::read<ContainerLayers>(path);
+      Try<ContainerLayers> layers = state::read<ContainerLayers>(path);
       if (layers.isError()) {
         return Failure(
             "Failed to recover layers for container '" +

http://git-wip-us.apache.org/repos/asf/mesos/blob/80f66061/src/slave/state.cpp
----------------------------------------------------------------------
diff --git a/src/slave/state.cpp b/src/slave/state.cpp
index 0bc0cca..63ae264 100644
--- a/src/slave/state.cpp
+++ b/src/slave/state.cpp
@@ -151,7 +151,7 @@ Try<SlaveState> SlaveState::recover(
     return state;
   }
 
-  Try<SlaveInfo> slaveInfo = ::protobuf::read<SlaveInfo>(path);
+  Try<SlaveInfo> slaveInfo = state::read<SlaveInfo>(path);
   if (slaveInfo.isError()) {
     const string& message = "Failed to read agent info from '" + path + "': " +
                             slaveInfo.error();
@@ -164,10 +164,6 @@ Try<SlaveState> SlaveState::recover(
     }
   }
 
-  convertResourceFormat(
-      slaveInfo.get().mutable_resources(),
-      POST_RESERVATION_REFINEMENT);
-
   state.info = slaveInfo.get();
 
   // Find the frameworks.
@@ -219,9 +215,7 @@ Try<FrameworkState> FrameworkState::recover(
     return state;
   }
 
-  const Try<FrameworkInfo> frameworkInfo =
-    ::protobuf::read<FrameworkInfo>(path);
-
+  const Try<FrameworkInfo> frameworkInfo = state::read<FrameworkInfo>(path);
   if (frameworkInfo.isError()) {
     message = "Failed to read framework info from '" + path + "': " +
               frameworkInfo.error();
@@ -379,7 +373,7 @@ Try<ExecutorState> ExecutorState::recover(
     return state;
   }
 
-  Try<ExecutorInfo> executorInfo = ::protobuf::read<ExecutorInfo>(path);
+  Try<ExecutorInfo> executorInfo = state::read<ExecutorInfo>(path);
   if (executorInfo.isError()) {
     message = "Failed to read executor info from '" + path + "': " +
               executorInfo.error();
@@ -393,10 +387,6 @@ Try<ExecutorState> ExecutorState::recover(
     }
   }
 
-  convertResourceFormat(
-      executorInfo.get().mutable_resources(),
-      POST_RESERVATION_REFINEMENT);
-
   state.info = executorInfo.get();
 
   return state;
@@ -572,8 +562,7 @@ Try<TaskState> TaskState::recover(
     return state;
   }
 
-  Try<Task> task = ::protobuf::read<Task>(path);
-
+  Try<Task> task = state::read<Task>(path);
   if (task.isError()) {
     message = "Failed to read task info from '" + path + "': " + task.error();
 
@@ -586,10 +575,6 @@ Try<TaskState> TaskState::recover(
     }
   }
 
-  convertResourceFormat(
-      task.get().mutable_resources(),
-      POST_RESERVATION_REFINEMENT);
-
   state.info = task.get();
 
   // Read the status updates.

http://git-wip-us.apache.org/repos/asf/mesos/blob/80f66061/src/tests/slave_recovery_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_recovery_tests.cpp b/src/tests/slave_recovery_tests.cpp
index fc26987..4d32a84 100644
--- a/src/tests/slave_recovery_tests.cpp
+++ b/src/tests/slave_recovery_tests.cpp
@@ -128,7 +128,7 @@ TEST_F(SlaveStateTest, CheckpointProtobufMessage)
   const string file = "slave.id";
   slave::state::checkpoint(file, expected);
 
-  const Try<SlaveID> actual = ::protobuf::read<SlaveID>(file);
+  const Try<SlaveID> actual = slave::state::read<SlaveID>(file);
   ASSERT_SOME(actual);
 
   EXPECT_SOME_EQ(expected, actual);
@@ -144,16 +144,10 @@ TEST_F(SlaveStateTest, CheckpointRepeatedProtobufMessages)
   const string file = "resources-file";
   slave::state::checkpoint(file, expected);
 
-  Try<RepeatedPtrField<Resource>> actual =
-    ::protobuf::read<RepeatedPtrField<Resource>>(file);
+  const Try<RepeatedPtrField<Resource>> actual =
+    slave::state::read<RepeatedPtrField<Resource>>(file);
 
   ASSERT_SOME(actual);
-
-  // We convert the `actual` back to "post-reservation-refinement"
-  // since `state::checkpoint` always downgrades whatever resources
-  // are downgradable.
-  convertResourceFormat(&actual.get(), POST_RESERVATION_REFINEMENT);
-
   EXPECT_SOME_EQ(expected, actual);
 }