You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/12/18 23:40:22 UTC

[8/9] mesos git commit: Saved all docker image information on disk instead of rootfs only.

Saved all docker image information on disk instead of rootfs only.

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


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

Branch: refs/heads/master
Commit: 43cc4c9a6e467b71fe8d098fd2fe02d5c9570f35
Parents: a2004e4
Author: Gilbert Song <so...@gmail.com>
Authored: Fri Dec 18 14:13:23 2015 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Dec 18 14:29:59 2015 -0800

----------------------------------------------------------------------
 .../mesos/provisioner/docker/puller.cpp          |  8 ++++----
 .../mesos/provisioner/docker/store.cpp           | 19 +++++++++++++++----
 .../containerizer/provisioner_docker_tests.cpp   |  2 +-
 3 files changed, 20 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/43cc4c9a/src/slave/containerizer/mesos/provisioner/docker/puller.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/puller.cpp b/src/slave/containerizer/mesos/provisioner/docker/puller.cpp
index 7e830bc..dd17acf 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/puller.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/puller.cpp
@@ -163,16 +163,16 @@ Future<pair<string, string>> untarLayer(
   // The tar file will be removed when the staging directory is removed.
   return untar(file, localRootfsPath)
     .then([directory, layerId]() -> Future<pair<string, string>> {
-      const string rootfsPath =
-        paths::getImageArchiveLayerRootfsPath(directory, layerId);
+      const string layerPath =
+        paths::getImageArchiveLayerPath(directory, layerId);
 
-      if (!os::exists(rootfsPath)) {
+      if (!os::exists(layerPath)) {
         return Failure(
             "Failed to find the rootfs path after extracting layer"
             " '" + layerId + "'");
       }
 
-      return pair<string, string>(layerId, rootfsPath);
+      return pair<string, string>(layerId, layerPath);
     });
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/43cc4c9a/src/slave/containerizer/mesos/provisioner/docker/store.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/provisioner/docker/store.cpp b/src/slave/containerizer/mesos/provisioner/docker/store.cpp
index 53800c2..e951c96 100644
--- a/src/slave/containerizer/mesos/provisioner/docker/store.cpp
+++ b/src/slave/containerizer/mesos/provisioner/docker/store.cpp
@@ -80,7 +80,8 @@ private:
       const Image::Name& name,
       const std::vector<std::string>& layerIds);
 
-  Future<Nothing> moveLayer(const pair<string, string>& layerPath);
+  Future<Nothing> moveLayer(
+      const pair<string, string>& layerPath);
 
   const Flags flags;
   Owned<MetadataManager> metadataManager;
@@ -268,7 +269,8 @@ Future<Image> StoreProcess::storeImage(
 }
 
 
-Future<Nothing> StoreProcess::moveLayer(const pair<string, string>& layerPath)
+Future<Nothing> StoreProcess::moveLayer(
+    const pair<string, string>& layerPath)
 {
   if (!os::exists(layerPath.second)) {
     return Failure("Unable to find layer '" + layerPath.first + "' in '" +
@@ -278,6 +280,16 @@ Future<Nothing> StoreProcess::moveLayer(const pair<string, string>& layerPath)
   const string imageLayerPath =
     paths::getImageLayerPath(flags.docker_store_dir, layerPath.first);
 
+  // If image layer path exists, we should remove it and make an empty
+  // directory, because os::rename can only have empty or non-existed
+  // directory as destination.
+  if (os::exists(imageLayerPath)) {
+    Try<Nothing> rmdir = os::rmdir(imageLayerPath);
+    if (rmdir.isError()) {
+      return Failure("Failed to remove existing layer: " + rmdir.error());
+    }
+  }
+
   Try<Nothing> mkdir = os::mkdir(imageLayerPath);
   if (mkdir.isError()) {
     return Failure("Failed to create layer path in store for id '" +
@@ -286,8 +298,7 @@ Future<Nothing> StoreProcess::moveLayer(const pair<string, string>& layerPath)
 
   Try<Nothing> status = os::rename(
       layerPath.second,
-      paths::getImageLayerRootfsPath(
-          flags.docker_store_dir, layerPath.first));
+      imageLayerPath);
 
   if (status.isError()) {
     return Failure("Failed to move layer '" + layerPath.first +

http://git-wip-us.apache.org/repos/asf/mesos/blob/43cc4c9a/src/tests/containerizer/provisioner_docker_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/provisioner_docker_tests.cpp b/src/tests/containerizer/provisioner_docker_tests.cpp
index 635c9da..836898d 100644
--- a/src/tests/containerizer/provisioner_docker_tests.cpp
+++ b/src/tests/containerizer/provisioner_docker_tests.cpp
@@ -1228,7 +1228,7 @@ TEST_F(RegistryClientTest, SimpleRegistryPuller)
             "1ce2e90b0bc7224de3db1f0d646fe8e2c4dd37f1793928287f6074bc451a57ea");
 
   Try<string> blob = os::read(
-      path::join(layers.front().second, blobFile));
+      path::join(layers.front().second, "rootfs", blobFile));
   ASSERT_SOME(blob);
   ASSERT_EQ(blob.get(), blobResponse);
 }