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 2016/08/16 00:38:52 UTC

[3/6] mesos git commit: Updated hash and equality functions for ContainerID.

Updated hash and equality functions for ContainerID.

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


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

Branch: refs/heads/master
Commit: 27a21b1007b3837df876cf7f62088244d9bf6915
Parents: 40115df
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Aug 15 12:33:14 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Aug 15 17:38:44 2016 -0700

----------------------------------------------------------------------
 include/mesos/type_utils.hpp                    | 16 +++++++-----
 src/common/type_utils.cpp                       |  8 ++++++
 .../containerizer/mesos_containerizer_tests.cpp | 27 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/27a21b10/include/mesos/type_utils.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp
index d0d2356..5826eff 100644
--- a/include/mesos/type_utils.hpp
+++ b/include/mesos/type_utils.hpp
@@ -47,6 +47,7 @@ namespace mesos {
 
 bool operator==(const CommandInfo& left, const CommandInfo& right);
 bool operator==(const CommandInfo::URI& left, const CommandInfo::URI& right);
+bool operator==(const ContainerID& left, const ContainerID& right);
 bool operator==(const Credential& left, const Credential& right);
 bool operator==(const DiscoveryInfo& left, const DiscoveryInfo& right);
 bool operator==(const Environment& left, const Environment& right);
@@ -69,12 +70,6 @@ bool operator!=(const Labels& left, const Labels& right);
 bool operator!=(const TaskStatus& left, const TaskStatus& right);
 
 
-inline bool operator==(const ContainerID& left, const ContainerID& right)
-{
-  return left.value() == right.value();
-}
-
-
 inline bool operator==(const ExecutorID& left, const ExecutorID& right)
 {
   return left.value() == right.value();
@@ -176,7 +171,7 @@ inline bool operator==(const MachineID& left, const MachineID& right)
 
 inline bool operator!=(const ContainerID& left, const ContainerID& right)
 {
-  return left.value() != right.value();
+  return !(left == right);
 }
 
 
@@ -364,6 +359,13 @@ struct hash<mesos::ContainerID>
   {
     size_t seed = 0;
     boost::hash_combine(seed, containerId.value());
+
+    if (containerId.has_parent()) {
+      boost::hash_combine(
+          seed,
+          std::hash<mesos::ContainerID>()(containerId.parent()));
+    }
+
     return seed;
   }
 };

http://git-wip-us.apache.org/repos/asf/mesos/blob/27a21b10/src/common/type_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp
index 7110d87..a8a9d90 100644
--- a/src/common/type_utils.cpp
+++ b/src/common/type_utils.cpp
@@ -82,6 +82,14 @@ bool operator==(const CommandInfo::URI& left, const CommandInfo::URI& right)
 }
 
 
+bool operator==(const ContainerID& left, const ContainerID& right)
+{
+  return left.value() == right.value() &&
+    left.has_parent() == right.has_parent() &&
+    (!left.has_parent() || left.parent() == right.parent());
+}
+
+
 bool operator==(const Credential& left, const Credential& right)
 {
   return left.principal() == right.principal() &&

http://git-wip-us.apache.org/repos/asf/mesos/blob/27a21b10/src/tests/containerizer/mesos_containerizer_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/mesos_containerizer_tests.cpp b/src/tests/containerizer/mesos_containerizer_tests.cpp
index b47e569..4a49247 100644
--- a/src/tests/containerizer/mesos_containerizer_tests.cpp
+++ b/src/tests/containerizer/mesos_containerizer_tests.cpp
@@ -89,6 +89,33 @@ namespace mesos {
 namespace internal {
 namespace tests {
 
+TEST(MesosContainerizerTest, NestedContainerID)
+{
+  ContainerID id1;
+  id1.set_value(UUID::random().toString());
+
+  ContainerID id2;
+  id2.set_value(UUID::random().toString());
+
+  EXPECT_EQ(id1, id1);
+  EXPECT_NE(id1, id2);
+
+  ContainerID id3 = id1;
+  id3.mutable_parent()->CopyFrom(id2);
+
+  EXPECT_EQ(id3, id3);
+  EXPECT_NE(id3, id1);
+
+  hashset<ContainerID> ids;
+  ids.insert(id2);
+  ids.insert(id3);
+
+  EXPECT_TRUE(ids.contains(id2));
+  EXPECT_TRUE(ids.contains(id3));
+  EXPECT_FALSE(ids.contains(id1));
+}
+
+
 class MesosContainerizerIsolatorPreparationTest :
   public TemporaryDirectoryTest
 {