You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/12/02 17:56:55 UTC

[01/14] git commit: Made Promise::associate 'discard' in both directions.

Updated Branches:
  refs/heads/master 3b9d480b4 -> e427fae0c


Made Promise::associate 'discard' in both directions.

Say you have a process defined as follows:

class FooProcess : public Process<FooProcess>
{
public:
  Future<bool> func() { return future; }
private:
  Future<bool> future;
};

Then you call dispatch that returns a future:

Future<bool> f = dispatch(process, &FooProcess::func);

If the user discards the future 'f', we expect the 'future' field in
FooProcess also being discarded. However, this is not the case
currently.

This patch fixed this issue.

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15319


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

Branch: refs/heads/master
Commit: 6b13a6e7450ea9e060777c429059b13192e095e1
Parents: 3b9d480
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:46:54 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:46:54 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/future.hpp  | 8 ++++++++
 3rdparty/libprocess/src/tests/process_tests.cpp | 8 ++++++++
 2 files changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6b13a6e7/3rdparty/libprocess/include/process/future.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/future.hpp b/3rdparty/libprocess/include/process/future.hpp
index 1625d1d..6d70d7d 100644
--- a/3rdparty/libprocess/include/process/future.hpp
+++ b/3rdparty/libprocess/include/process/future.hpp
@@ -318,6 +318,14 @@ bool Promise<T>::set(const Future<T>& future)
 template <typename T>
 bool Promise<T>::associate(const Future<T>& future)
 {
+  // TODO(jieyu): Make 'f' a true alias of 'future'. Currently, only
+  // 'discard' is associated in both directions. In other words, if a
+  // future gets discarded, the other future will also get discarded.
+  // For 'set' and 'fail', they are associated only in one direction.
+  // In other words, calling 'set' or 'fail' on this promise will not
+  // affect the result of the future that we associated.
+  f.onDiscarded(std::tr1::bind(&Future<T>::discard, future));
+
   if (!f.isPending()) {
     return false;
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/6b13a6e7/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index 7848599..68300f3 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -85,6 +85,14 @@ TEST(Process, associate)
   promise4.fail("associate");
   ASSERT_TRUE(promise3.future().isFailed());
   EXPECT_EQ("associate", promise3.future().failure());
+
+  // Test that 'discard' is associated in both directions.
+  Promise<bool> promise5;
+  Future<bool> future3;
+  promise5.associate(future3);
+  EXPECT_FALSE(future3.isDiscarded());
+  promise5.future().discard();
+  EXPECT_TRUE(future3.isDiscarded());
 }
 
 


[09/14] git commit: Added stout 'Set' tests to libprocess/3rdparty Makefile.

Posted by be...@apache.org.
Added stout 'Set' tests to libprocess/3rdparty Makefile.

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


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

Branch: refs/heads/master
Commit: 009a26d4bd3460125dafb04701907429a0637a28
Parents: f6c4a02
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Nov 26 20:00:13 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:12:15 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/Makefile.am | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/009a26d4/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index 86bee73..0b630f8 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -135,6 +135,7 @@ stout_tests_SOURCES =				\
   $(STOUT)/tests/protobuf_tests.proto		\
   $(STOUT)/tests/os/sendfile_tests.cpp		\
   $(STOUT)/tests/os/signals_tests.cpp		\
+  $(STOUT)/tests/set_tests.cpp			\
   $(STOUT)/tests/strings_tests.cpp		\
   $(STOUT)/tests/thread_tests.cpp		\
   $(STOUT)/tests/uuid_tests.cpp


[10/14] git commit: Added 'Some'.

Posted by be...@apache.org.
Added 'Some'.

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


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

Branch: refs/heads/master
Commit: 3a51ff2efc5a5333dd019f53fdfceec6783ea9d1
Parents: 009a26d
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Nov 26 22:43:25 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:16:43 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/Makefile.am  |  2 +
 .../3rdparty/stout/include/stout/check.hpp      |  5 +-
 .../3rdparty/stout/include/stout/flags.hpp      | 10 +--
 .../stout/include/stout/flags/flags.hpp         | 11 ++-
 .../stout/include/stout/flags/loader.hpp        |  5 +-
 .../3rdparty/stout/include/stout/os.hpp         |  2 +-
 .../3rdparty/stout/include/stout/some.hpp       | 73 ++++++++++++++++++++
 .../3rdparty/stout/tests/flags_tests.cpp        | 19 ++---
 .../3rdparty/stout/tests/some_tests.cpp         | 67 ++++++++++++++++++
 9 files changed, 168 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index cc9a120..e46e763 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -53,6 +53,7 @@ EXTRA_DIST =					\
   include/stout/protobuf.hpp			\
   include/stout/result.hpp			\
   include/stout/set.hpp				\
+  include/stout/some.hpp			\
   include/stout/stopwatch.hpp			\
   include/stout/stringify.hpp			\
   include/stout/strings.hpp			\
@@ -81,6 +82,7 @@ EXTRA_DIST =					\
   tests/protobuf_tests.pb.h			\
   tests/protobuf_tests.proto			\
   tests/set_tests.cpp				\
+  tests/some_tests.cpp				\
   tests/strings_tests.cpp			\
   tests/thread_tests.cpp			\
   tests/uuid_tests.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
index 0165d42..eb31841 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/check.hpp
@@ -10,6 +10,7 @@
 #include <stout/none.hpp>
 #include <stout/option.hpp>
 #include <stout/result.hpp>
+#include <stout/some.hpp>
 #include <stout/try.hpp>
 
 // Provides a CHECK_SOME macro, akin to CHECK.
@@ -26,7 +27,7 @@ template <typename T>
 Option<std::string> _check(const Option<T>& o)
 {
   if (o.isNone()) {
-    return Option<std::string>::some("is NONE");
+    return Some("is NONE");
   }
   return None();
 }
@@ -48,7 +49,7 @@ Option<std::string> _check(const Result<T>& r)
   if (r.isError()) {
     return r.error();
   } else if (r.isNone()) {
-    return Option<std::string>::some("is NONE");
+    return Some("is NONE");
   }
   return None();
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/include/stout/flags.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags.hpp
index 0efd079..a70db19 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags.hpp
@@ -28,11 +28,11 @@
 // ...
 //
 // map<string, Option<string> > values;
-// values["no-debug"] = None();                       // --no-debug
-// values["debug"] = None();                          // --debug
-// values["debug"] = Option<string>::some("true");    // --debug=true
-// values["debug"] = Option<string>::some("false");   // --debug=false
-// values["name"] = Option<string>::some("frank");    // --name=frank
+// values["no-debug"] = None();            // --no-debug
+// values["debug"] = None();               // --debug
+// values["debug"] = Some("true");         // --debug=true
+// values["debug"] = Some("false");        // --debug=false
+// values["name"] = Some("frank");         // --name=frank
 //
 // MyFlags flags;
 // flags.load(values);

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
index fcaa4e4..cfe996e 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
@@ -16,6 +16,7 @@
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
 #include <stout/os.hpp>
+#include <stout/some.hpp>
 #include <stout/stringify.hpp>
 #include <stout/strings.hpp>
 #include <stout/try.hpp>
@@ -289,7 +290,7 @@ inline std::map<std::string, Option<std::string> > FlagsBase::extract(
       if (flags.count(name) > 0 ||
           (name.find("no-") == 0 && flags.count(name.substr(3)) > 0)) {
         std::string value = variable.substr(eq + 1);
-        values[name] = Option<std::string>::some(value);
+        values[name] = Some(value);
       }
     }
   }
@@ -361,11 +362,7 @@ inline Try<Nothing> FlagsBase::load(
     bool unknowns,
     bool duplicates)
 {
-  return load(Option<std::string>::some(prefix),
-              argc,
-              argv,
-              unknowns,
-              duplicates);
+  return load(Some(prefix), argc, argv, unknowns, duplicates);
 }
 
 
@@ -436,7 +433,7 @@ inline Try<Nothing> FlagsBase::load(
   for (iterator = _values.begin(); iterator != _values.end(); ++iterator) {
     const std::string& name = iterator->first;
     const std::string& value = iterator->second;
-    values[name] = Option<std::string>::some(value);
+    values[name] = Some(value);
   }
   return load(values, unknowns);
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/include/stout/flags/loader.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/loader.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/loader.hpp
index e5eaf24..a6e0f58 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/loader.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/loader.hpp
@@ -8,6 +8,7 @@
 #include <stout/error.hpp>
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
+#include <stout/some.hpp>
 #include <stout/try.hpp>
 
 #include <stout/flags/parse.hpp>
@@ -48,7 +49,7 @@ struct OptionLoader
   {
     Try<T> t = parse(value);
     if (t.isSome()) {
-      *flag = Option<T>::some(t.get());
+      *flag = Some(t.get());
     } else {
       return Error("Failed to load value '" + value + "': " + t.error());
     }
@@ -95,7 +96,7 @@ struct OptionMemberLoader
     if (f != NULL) {
       Try<T> t = parse(value);
       if (t.isSome()) {
-        f->*flag = Option<T>::some(t.get());
+        f->*flag = Some(t.get());
       } else {
         return Error("Failed to load value '" + value + "': " + t.error());
       }

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index f6bbf5e..544cf8c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -704,7 +704,7 @@ inline Try<std::string> hostname()
 
   std::string hostname = hep->h_name;
   delete[] temp;
-  return Try<std::string>::some(hostname);
+  return hostname;
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/include/stout/some.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/some.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/some.hpp
new file mode 100644
index 0000000..e2f56cc
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/some.hpp
@@ -0,0 +1,73 @@
+#ifndef __STOUT_SOME_HPP__
+#define __STOUT_SOME_HPP__
+
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+
+// A "some" type that is implicitely convertable to an Option<T> and
+// Result<T> for any T (effectively "syntactic sugar" to make code
+// more readable). The implementation uses cast operators to perform
+// the conversions instead of adding constructors to Option/Result
+// directly. The extra copies involved here can be elided with C++11
+// rvalue references. Furthermore, since in most circumstances a Some
+// will not be needed (an Option<T> or Result<T> can be constructed
+// directly from the value) we don't worry about performance.
+
+template <typename T>
+struct _Some
+{
+  _Some(T _t) : t(_t) {}
+
+  template <typename U>
+  operator Option<U> () const
+  {
+    return Option<U>::some(t);
+  }
+
+  // Give the compiler some help for nested Option<U>.
+  template <template <typename> class S, typename U>
+  operator S<Option<U> > () const
+  {
+    return S<Option<U> >(Option<U>::some(t));
+  }
+
+  template <typename U>
+  operator Result<U> () const
+  {
+    return Result<U>::some(t);
+  }
+
+  // Give the compiler some help for nested Result<U>.
+  template <template <typename> class S, typename U>
+  operator S<Result<U> > () const
+  {
+    return S<Result<U> >(Result<U>::some(t));
+  }
+
+  // Give the compiler some more help to disambiguate the above cast
+  // operators from Option<Result<U>>.
+  template <typename U>
+  operator Option<Result<U> > () const
+  {
+    return Option<Result<U> >::some(t);
+  }
+
+  // Give the compiler some more help to disambiguate the above cast
+  // operators from Result<Option<U>>.
+  template <typename U>
+  operator Result<Option<U> > () const
+  {
+    return Result<Option<U> >::some(t);
+  }
+
+  const T t;
+};
+
+
+template <typename T>
+_Some<T> Some(T t)
+{
+  return _Some<T>(t);
+}
+
+#endif // __STOUT_SOME_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
index 2780cc5..9af2da1 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/flags_tests.cpp
@@ -10,6 +10,7 @@
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
 #include <stout/os.hpp>
+#include <stout/some.hpp>
 
 
 using namespace flags;
@@ -57,9 +58,9 @@ TEST(FlagsTest, Load)
 
   std::map<std::string, Option<std::string> > values;
 
-  values["name1"] = Option<std::string>::some("billy joel");
-  values["name2"] = Option<std::string>::some("43");
-  values["name3"] = Option<std::string>::some("false");
+  values["name1"] = Some("billy joel");
+  values["name2"] = Some("43");
+  values["name3"] = Some("false");
   values["no-name4"] = None();
   values["name5"] = None();
 
@@ -100,7 +101,7 @@ TEST(FlagsTest, Add)
 
   std::map<std::string, Option<std::string> > values;
 
-  values["name6"] = Option<std::string>::some("ben folds");
+  values["name6"] = Some("ben folds");
   values["no-name7"] = None();
 
   flags.load(values);
@@ -120,9 +121,9 @@ TEST(FlagsTest, Flags)
 
   std::map<std::string, Option<std::string> > values;
 
-  values["name1"] = Option<std::string>::some("billy joel");
-  values["name2"] = Option<std::string>::some("43");
-  values["name3"] = Option<std::string>::some("false");
+  values["name1"] = Some("billy joel");
+  values["name2"] = Some("43");
+  values["name3"] = Some("false");
   values["no-name4"] = None();
   values["name5"] = None();
 
@@ -369,8 +370,8 @@ TEST(FlagsTest, Duration)
 
   std::map<std::string, Option<std::string> > values;
 
-  values["name6"] = Option<std::string>::some("2mins");
-  values["name7"] = Option<std::string>::some("3hrs");
+  values["name6"] = Some("2mins");
+  values["name7"] = Some("3hrs");
 
   flags.load(values);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/3a51ff2e/3rdparty/libprocess/3rdparty/stout/tests/some_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/some_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/some_tests.cpp
new file mode 100644
index 0000000..4041dc4
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/some_tests.cpp
@@ -0,0 +1,67 @@
+#include <gtest/gtest.h>
+
+#include <map>
+#include <string>
+
+#include <stout/gtest.hpp>
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+#include <stout/some.hpp>
+#include <stout/try.hpp>
+
+TEST(Stout, Some)
+{
+  Option<int> o1 = Some(42);
+  EXPECT_SOME(o1);
+  EXPECT_EQ(42, o1.get());
+
+  Result<int> r1 = Some(42);
+  EXPECT_SOME(r1);
+  EXPECT_EQ(42, r1.get());
+
+  Try<Option<int> > t1 = Some(42);
+  ASSERT_SOME(t1);
+  EXPECT_SOME(t1.get());
+  EXPECT_EQ(42, t1.get().get());
+
+  Try<Result<int> > t2 = Some(42);
+  ASSERT_SOME(t2);
+  EXPECT_SOME(t2.get());
+  EXPECT_EQ(42, t2.get().get());
+
+  Option<Result<int> > o2 = Some(42);
+  ASSERT_SOME(o2);
+  EXPECT_SOME(o2.get());
+  EXPECT_EQ(42, o2.get().get());
+
+  Option<Result<int> > o3 = Some(Some(42));
+  ASSERT_SOME(o3);
+  EXPECT_SOME(o3.get());
+  EXPECT_EQ(42, o3.get().get());
+
+  Result<Option<int> > r2 = Some(42);
+  ASSERT_SOME(r2);
+  EXPECT_SOME(r2.get());
+  EXPECT_EQ(42, r2.get().get());
+
+  Result<Option<int> > r3 = Some(Some(42));
+  ASSERT_SOME(r3);
+  EXPECT_SOME(r3.get());
+  EXPECT_EQ(42, r3.get().get());
+
+  Option<std::string> o4 = Some("hello");
+  EXPECT_SOME(o4);
+  EXPECT_EQ("hello", o4.get());
+
+  Result<std::string> r4 = Some("world");
+  EXPECT_SOME(r4);
+  EXPECT_EQ("world", r4.get());
+
+  std::map<std::string, Option<std::string> > values;
+  values["no-debug"] = None();
+  values["debug"] = None();
+  values["debug"] = Some("true");
+  values["debug"] = Some("false");
+  values["name"] = Some("frank");
+}


[13/14] git commit: Added 'Failure' as a helper for a failed Future.

Posted by be...@apache.org.
Added 'Failure' as a helper for a failed Future.

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


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

Branch: refs/heads/master
Commit: 43e90f53eba58716b1f255bdf8eb25ca797d9ab0
Parents: 51f81e2
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Nov 26 22:50:02 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:17:16 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/future.hpp  | 28 ++++++++++++++++++++
 3rdparty/libprocess/include/process/shared.hpp  |  2 +-
 3rdparty/libprocess/src/process.cpp             | 17 +++++-------
 3rdparty/libprocess/src/tests/process_tests.cpp |  2 +-
 4 files changed, 36 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/43e90f53/3rdparty/libprocess/include/process/future.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/future.hpp b/3rdparty/libprocess/include/process/future.hpp
index 6d70d7d..e473b3d 100644
--- a/3rdparty/libprocess/include/process/future.hpp
+++ b/3rdparty/libprocess/include/process/future.hpp
@@ -18,6 +18,7 @@
 #include <process/pid.hpp>
 
 #include <stout/duration.hpp>
+#include <stout/error.hpp>
 #include <stout/option.hpp>
 #include <stout/preprocessor.hpp>
 
@@ -254,6 +255,33 @@ private:
 };
 
 
+// Helper for creating failed futures.
+struct _Failure
+{
+  _Failure(const std::string& _message) : message(_message) {}
+
+  template <typename T>
+  operator Future<T> () const
+  {
+    return Future<T>::failed(message);
+  }
+
+  const std::string message;
+};
+
+
+inline _Failure Failure(const std::string& message)
+{
+  return _Failure(message);
+}
+
+
+inline _Failure Failure(const Error& error)
+{
+  return _Failure(error.message);
+}
+
+
 // TODO(benh): Make Promise a subclass of Future?
 template <typename T>
 class Promise

http://git-wip-us.apache.org/repos/asf/mesos/blob/43e90f53/3rdparty/libprocess/include/process/shared.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/shared.hpp b/3rdparty/libprocess/include/process/shared.hpp
index b1b6234..8f5b59b 100644
--- a/3rdparty/libprocess/include/process/shared.hpp
+++ b/3rdparty/libprocess/include/process/shared.hpp
@@ -154,7 +154,7 @@ Future<Owned<T> > Shared<T>::own()
   }
 
   if (!__sync_bool_compare_and_swap(&data->owned, false, true)) {
-    return Future<Owned<T> >::failed("Ownership has already been transferred");
+    return Failure("Ownership has already been transferred");
   }
 
   Future<Owned<T> > future = data->promise.future();

http://git-wip-us.apache.org/repos/asf/mesos/blob/43e90f53/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 0c816cc..2d193b1 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -3603,8 +3603,7 @@ Future<Response> decode(const string& buffer)
     for (size_t i = 0; i < responses.size(); ++i) {
       delete responses[i];
     }
-    return Future<Response>::failed(
-        "Failed to decode HTTP response:\n" + buffer + "\n");
+    return Failure("Failed to decode HTTP response:\n" + buffer + "\n");
   } else if (responses.size() > 1) {
     PLOG(ERROR) << "Received more than 1 HTTP Response";
   }
@@ -3625,13 +3624,12 @@ Future<Response> get(const UPID& upid, const string& path, const string& query)
   int s = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
 
   if (s < 0) {
-    return Future<Response>::failed(
-        string("Failed to create socket: ") + strerror(errno));
+    return Failure(string("Failed to create socket: ") + strerror(errno));
   }
 
   Try<Nothing> cloexec = os::cloexec(s);
   if (!cloexec.isSome()) {
-    return Future<Response>::failed("Failed to cloexec: " + cloexec.error());
+    return Failure("Failed to cloexec: " + cloexec.error());
   }
 
   sockaddr_in addr;
@@ -3642,8 +3640,7 @@ Future<Response> get(const UPID& upid, const string& path, const string& query)
 
   if (connect(s, (sockaddr*) &addr, sizeof(addr)) < 0) {
     os::close(s);
-    return Future<Response>::failed(
-        string("Failed to connect: ") + strerror(errno));
+    return Failure(string("Failed to connect: ") + strerror(errno));
   }
 
   std::ostringstream out;
@@ -3674,8 +3671,7 @@ Future<Response> get(const UPID& upid, const string& path, const string& query)
         continue;
       }
       os::close(s);
-      return Future<Response>::failed(
-          string("Failed to write: ") + strerror(errno));
+      return Failure(string("Failed to write: ") + strerror(errno));
     }
 
     remaining -= n;
@@ -3684,8 +3680,7 @@ Future<Response> get(const UPID& upid, const string& path, const string& query)
   Try<Nothing> nonblock = os::nonblock(s);
   if (!nonblock.isSome()) {
     os::close(s);
-    return Future<Response>::failed(
-        "Failed to set nonblock: " + nonblock.error());
+    return Failure("Failed to set nonblock: " + nonblock.error());
   }
 
   // Decode once the async read completes.

http://git-wip-us.apache.org/repos/asf/mesos/blob/43e90f53/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index 68300f3..b0fb5c2 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -158,7 +158,7 @@ Future<bool> readyFuture()
 
 Future<bool> failedFuture()
 {
-  return Future<bool>::failed("The value is not positive (or zero)");
+  return Failure("The value is not positive (or zero)");
 }
 
 


[06/14] git commit: Updated references in Mesos to use the new Owned.

Posted by be...@apache.org.
Updated references in Mesos to use the new Owned.

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15839


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

Branch: refs/heads/master
Commit: 92bbaf8af27e640f7f9b2c50c0d6e681e6cab5dc
Parents: d1194f6
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:58:39 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:58:58 2013 -0800

----------------------------------------------------------------------
 src/master/contender.hpp                      |  4 ++--
 src/master/detector.hpp                       |  4 ++--
 src/master/master.cpp                         |  5 ++---
 src/master/master.hpp                         |  2 +-
 src/sched/sched.cpp                           |  2 +-
 src/slave/gc.hpp                              |  6 +++---
 src/slave/http.cpp                            |  2 ++
 src/slave/monitor.cpp                         |  2 +-
 src/slave/reaper.hpp                          |  5 +++--
 src/slave/slave.hpp                           |  2 +-
 src/tests/authentication_tests.cpp            | 13 +++++++------
 src/tests/cluster.hpp                         | 22 ++++++++++++----------
 src/tests/fault_tolerance_tests.cpp           | 17 ++++++++++-------
 src/tests/master_contender_detector_tests.cpp |  4 +++-
 src/tests/master_tests.cpp                    |  5 ++++-
 src/tests/mesos.hpp                           |  7 ++++---
 src/tests/slave_recovery_tests.cpp            |  5 +++--
 src/tests/zookeeper_tests.cpp                 | 17 +++++++++++------
 18 files changed, 72 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/master/contender.hpp
----------------------------------------------------------------------
diff --git a/src/master/contender.hpp b/src/master/contender.hpp
index 50fd4f3..7764edd 100644
--- a/src/master/contender.hpp
+++ b/src/master/contender.hpp
@@ -21,11 +21,11 @@
 
 #include <process/defer.hpp>
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 
 #include <stout/lambda.hpp>
 #include <stout/nothing.hpp>
-#include <stout/owned.hpp>
 
 #include "zookeeper/contender.hpp"
 #include "zookeeper/group.hpp"
@@ -109,7 +109,7 @@ public:
   // Creates a contender that uses ZooKeeper to determine (i.e.,
   // elect) a leading master.
   ZooKeeperMasterContender(const zookeeper::URL& url);
-  ZooKeeperMasterContender(Owned<zookeeper::Group> group);
+  ZooKeeperMasterContender(process::Owned<zookeeper::Group> group);
 
   virtual ~ZooKeeperMasterContender();
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/master/detector.hpp
----------------------------------------------------------------------
diff --git a/src/master/detector.hpp b/src/master/detector.hpp
index ceb3a3f..6e7a4c4 100644
--- a/src/master/detector.hpp
+++ b/src/master/detector.hpp
@@ -20,9 +20,9 @@
 #define __MASTER_DETECTOR_HPP__
 
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 
-#include <stout/owned.hpp>
 #include <stout/result.hpp>
 #include <stout/try.hpp>
 
@@ -112,7 +112,7 @@ public:
   // elect) a leading master.
   ZooKeeperMasterDetector(const zookeeper::URL& url);
   // A constructor overload for testing purposes.
-  ZooKeeperMasterDetector(Owned<zookeeper::Group> group);
+  ZooKeeperMasterDetector(process::Owned<zookeeper::Group> group);
   virtual ~ZooKeeperMasterDetector();
 
   // MasterDetector implementation.

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index f13d2a0..23c2a5f 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -31,7 +31,6 @@
 #include <stout/multihashmap.hpp>
 #include <stout/nothing.hpp>
 #include <stout/os.hpp>
-#include <stout/owned.hpp>
 #include <stout/path.hpp>
 #include <stout/utils.hpp>
 #include <stout/uuid.hpp>
@@ -1841,10 +1840,10 @@ void Master::authenticate(const UPID& from, const UPID& pid)
 
   // Create a promise to capture the entire "authenticating"
   // procedure. We'll set this _after_ we finish _authenticate.
-  Owned<Promise<Nothing> > promise = new Promise<Nothing>();
+  Owned<Promise<Nothing> > promise(new Promise<Nothing>());
 
   // Create the authenticator.
-  Owned<sasl::Authenticator> authenticator = new sasl::Authenticator(from);
+  Owned<sasl::Authenticator> authenticator(new sasl::Authenticator(from));
 
   // Start authentication.
   const Future<bool>& future = authenticator->authenticate()

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 2d5dfaf..a7bf963 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -30,6 +30,7 @@
 #include <mesos/resources.hpp>
 
 #include <process/http.hpp>
+#include <process/owned.hpp>
 #include <process/process.hpp>
 #include <process/protobuf.hpp>
 
@@ -38,7 +39,6 @@
 #include <stout/hashset.hpp>
 #include <stout/multihashmap.hpp>
 #include <stout/option.hpp>
-#include <stout/owned.hpp>
 
 #include "common/type_utils.hpp"
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/sched/sched.cpp
----------------------------------------------------------------------
diff --git a/src/sched/sched.cpp b/src/sched/sched.cpp
index af57f28..b958435 100644
--- a/src/sched/sched.cpp
+++ b/src/sched/sched.cpp
@@ -38,6 +38,7 @@
 #include <process/id.hpp>
 #include <process/dispatch.hpp>
 #include <process/id.hpp>
+#include <process/owned.hpp>
 #include <process/process.hpp>
 #include <process/protobuf.hpp>
 
@@ -48,7 +49,6 @@
 #include <stout/hashmap.hpp>
 #include <stout/lambda.hpp>
 #include <stout/option.hpp>
-#include <stout/owned.hpp>
 #include <stout/os.hpp>
 #include <stout/stopwatch.hpp>
 #include <stout/uuid.hpp>

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/slave/gc.hpp
----------------------------------------------------------------------
diff --git a/src/slave/gc.hpp b/src/slave/gc.hpp
index 083aa79..328aa31 100644
--- a/src/slave/gc.hpp
+++ b/src/slave/gc.hpp
@@ -23,6 +23,7 @@
 #include <vector>
 
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/process.hpp>
 #include <process/timeout.hpp>
 #include <process/timer.hpp>
@@ -31,7 +32,6 @@
 #include <stout/hashmap.hpp>
 #include <stout/multimap.hpp>
 #include <stout/nothing.hpp>
-#include <stout/owned.hpp>
 #include <stout/try.hpp>
 
 namespace mesos {
@@ -101,7 +101,7 @@ private:
   struct PathInfo
   {
     PathInfo(const std::string& _path,
-             Owned<process::Promise<Nothing> > _promise)
+             process::Owned<process::Promise<Nothing> > _promise)
       : path(_path), promise(_promise) {}
 
     bool operator == (const PathInfo& that) const
@@ -110,7 +110,7 @@ private:
     }
 
     const std::string path;
-    const Owned<process::Promise<Nothing> > promise;
+    const process::Owned<process::Promise<Nothing> > promise;
   };
 
   // Store all the timeouts and corresponding paths to delete.

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/slave/http.cpp
----------------------------------------------------------------------
diff --git a/src/slave/http.cpp b/src/slave/http.cpp
index fbc917b..55a5e7d 100644
--- a/src/slave/http.cpp
+++ b/src/slave/http.cpp
@@ -25,6 +25,7 @@
 #include <mesos/resources.hpp>
 
 #include <process/help.hpp>
+#include <process/owned.hpp>
 
 #include <stout/foreach.hpp>
 #include <stout/json.hpp>
@@ -45,6 +46,7 @@ namespace slave {
 
 using process::Future;
 using process::HELP;
+using process::Owned;
 using process::TLDR;
 using process::USAGE;
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/slave/monitor.cpp
----------------------------------------------------------------------
diff --git a/src/slave/monitor.cpp b/src/slave/monitor.cpp
index dd25855..7201ad7 100644
--- a/src/slave/monitor.cpp
+++ b/src/slave/monitor.cpp
@@ -108,7 +108,7 @@ Future<Nothing> ResourceMonitorProcess::watch(
   ::statistics->meter(
       "monitor",
       prefix + CPUS_TIME_SECS,
-      new meters::TimeRate(prefix + CPU_USAGE));
+      Owned<meters::Meter>(new meters::TimeRate(prefix + CPU_USAGE)));
 
   // Schedule the resource collection.
   delay(interval, self(), &Self::collect, frameworkId, executorId, interval);

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/slave/reaper.hpp
----------------------------------------------------------------------
diff --git a/src/slave/reaper.hpp b/src/slave/reaper.hpp
index 4498139..9a31c75 100644
--- a/src/slave/reaper.hpp
+++ b/src/slave/reaper.hpp
@@ -23,11 +23,11 @@
 #include <set>
 
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/process.hpp>
 
 #include <stout/multihashmap.hpp>
 #include <stout/nothing.hpp>
-#include <stout/owned.hpp>
 #include <stout/try.hpp>
 
 namespace mesos {
@@ -80,7 +80,8 @@ protected:
 private:
   // Mapping from the monitored pid to all promises the pid exit
   // status should be sent to.
-  multihashmap<pid_t, Owned<process::Promise<Option<int> > > > promises;
+  multihashmap<
+    pid_t, process::Owned<process::Promise<Option<int> > > > promises;
 };
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 6d7c3e8..2d093a3 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -31,6 +31,7 @@
 
 #include <process/http.hpp>
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/process.hpp>
 #include <process/protobuf.hpp>
 
@@ -41,7 +42,6 @@
 #include <stout/multihashmap.hpp>
 #include <stout/option.hpp>
 #include <stout/os.hpp>
-#include <stout/owned.hpp>
 #include <stout/path.hpp>
 #include <stout/uuid.hpp>
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/authentication_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/authentication_tests.cpp b/src/tests/authentication_tests.cpp
index cc8b7a9..127c5e6 100644
--- a/src/tests/authentication_tests.cpp
+++ b/src/tests/authentication_tests.cpp
@@ -24,6 +24,7 @@
 
 #include <process/dispatch.hpp>
 #include <process/gmock.hpp>
+#include <process/owned.hpp>
 
 #include <stout/nothing.hpp>
 
@@ -277,8 +278,8 @@ TEST_F(AuthenticationTest, MasterFailover)
   ASSERT_SOME(master);
 
   MockScheduler sched;
-  Owned<StandaloneMasterDetector> detector =
-    new StandaloneMasterDetector(master.get());
+  Owned<StandaloneMasterDetector> detector(
+      new StandaloneMasterDetector(master.get()));
   TestingMesosSchedulerDriver driver(&sched, detector.get());
 
   // Drop the authenticate message from the scheduler.
@@ -321,8 +322,8 @@ TEST_F(AuthenticationTest, LeaderElection)
   ASSERT_SOME(master);
 
   MockScheduler sched;
-  Owned<StandaloneMasterDetector> detector =
-    new StandaloneMasterDetector(master.get());
+  Owned<StandaloneMasterDetector> detector(
+      new StandaloneMasterDetector(master.get()));
   TestingMesosSchedulerDriver driver(&sched, detector.get());
 
   // Drop the AuthenticationStepMessage from authenticator.
@@ -361,8 +362,8 @@ TEST_F(AuthenticationTest, SchedulerFailover)
 
   // Launch the first (i.e., failing) scheduler.
   MockScheduler sched1;
-  Owned<StandaloneMasterDetector> detector =
-    new StandaloneMasterDetector(master.get());
+  Owned<StandaloneMasterDetector> detector(
+      new StandaloneMasterDetector(master.get()));
   TestingMesosSchedulerDriver driver1(&sched1, detector.get());
 
   Future<FrameworkID> frameworkId;

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/cluster.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.hpp b/src/tests/cluster.hpp
index fa64ed1..065976c 100644
--- a/src/tests/cluster.hpp
+++ b/src/tests/cluster.hpp
@@ -21,6 +21,7 @@
 
 #include <map>
 
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 #include <process/process.hpp>
 
@@ -29,7 +30,6 @@
 #include <stout/none.hpp>
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
-#include <stout/owned.hpp>
 #include <stout/path.hpp>
 #include <stout/try.hpp>
 
@@ -90,7 +90,7 @@ public:
     Try<Nothing> stop(const process::PID<master::Master>& pid);
 
     // Returns a new master detector for this instance of masters.
-    Owned<MasterDetector> detector();
+    process::Owned<MasterDetector> detector();
 
   private:
     // Not copyable, not assignable.
@@ -149,12 +149,12 @@ public:
     // Detector. The detector is expected to outlive the launched
     // slave (i.e., until it is stopped via Slaves::stop).
     Try<process::PID<slave::Slave> > start(
-        Owned<MasterDetector> detector,
+        process::Owned<MasterDetector> detector,
         const slave::Flags& flags = slave::Flags());
 
     Try<process::PID<slave::Slave> > start(
         slave::Isolator* isolator,
-        Owned<MasterDetector> detector,
+        process::Owned<MasterDetector> detector,
         const slave::Flags& flags = slave::Flags());
 
     // Stops and cleans up a slave at the specified PID. If 'shutdown'
@@ -184,7 +184,7 @@ public:
       // Cluster.
       slave::Isolator* isolator;
       slave::Slave* slave;
-      Owned<MasterDetector> detector;
+      process::Owned<MasterDetector> detector;
     };
 
     std::map<process::PID<slave::Slave>, Slave> slaves;
@@ -382,15 +382,17 @@ inline Try<Nothing> Cluster::Masters::stop(
 }
 
 
-inline Owned<MasterDetector> Cluster::Masters::detector()
+inline process::Owned<MasterDetector> Cluster::Masters::detector()
 {
   if (url.isSome()) {
-    return new ZooKeeperMasterDetector(url.get());
+    return process::Owned<MasterDetector>(
+        new ZooKeeperMasterDetector(url.get()));
   }
 
   CHECK(masters.size() == 1);
 
-  return new StandaloneMasterDetector(masters.begin()->first);
+  return process::Owned<MasterDetector>(
+      new StandaloneMasterDetector(masters.begin()->first));
 }
 
 
@@ -448,7 +450,7 @@ inline Try<process::PID<slave::Slave> > Cluster::Slaves::start(
 
 
 inline Try<process::PID<slave::Slave> > Cluster::Slaves::start(
-    Owned<MasterDetector> detector,
+    process::Owned<MasterDetector> detector,
     const slave::Flags& flags)
 {
   return start(new slave::ProcessIsolator(), detector, flags);
@@ -457,7 +459,7 @@ inline Try<process::PID<slave::Slave> > Cluster::Slaves::start(
 
 inline Try<process::PID<slave::Slave> > Cluster::Slaves::start(
     slave::Isolator* isolator,
-    Owned<MasterDetector> detector,
+    process::Owned<MasterDetector> detector,
     const slave::Flags& flags)
 {
   // TODO(benh): Create a work directory if using the default.

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/fault_tolerance_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fault_tolerance_tests.cpp b/src/tests/fault_tolerance_tests.cpp
index f376b88..66ada33 100644
--- a/src/tests/fault_tolerance_tests.cpp
+++ b/src/tests/fault_tolerance_tests.cpp
@@ -30,6 +30,7 @@
 
 #include <process/future.hpp>
 #include <process/gmock.hpp>
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 #include <process/process.hpp>
 #include <process/protobuf.hpp>
@@ -60,6 +61,7 @@ using mesos::internal::slave::STATUS_UPDATE_RETRY_INTERVAL_MIN;
 using process::Clock;
 using process::Future;
 using process::Message;
+using process::Owned;
 using process::PID;
 using process::UPID;
 
@@ -864,8 +866,8 @@ TEST_F(FaultToleranceTest, FrameworkReregister)
   Try<PID<Master> > master = StartMaster();
   ASSERT_SOME(master);
 
-  Owned<MasterDetector> slaveDetector =
-    new StandaloneMasterDetector(master.get());
+  Owned<MasterDetector> slaveDetector(
+      new StandaloneMasterDetector(master.get()));
   Try<PID<Slave> > slave = StartSlave(slaveDetector);
   ASSERT_SOME(slave);
 
@@ -873,8 +875,8 @@ TEST_F(FaultToleranceTest, FrameworkReregister)
   // Create a detector for the scheduler driver because we want the
   // spurious leading master change to be known by the scheduler
   // driver only.
-  Owned<MasterDetector> schedDetector =
-    new StandaloneMasterDetector(master.get());
+  Owned<MasterDetector> schedDetector(
+      new StandaloneMasterDetector(master.get()));
   MockScheduler sched;
   TestingMesosSchedulerDriver driver(&sched, schedDetector.get());
 
@@ -1105,13 +1107,14 @@ TEST_F(FaultToleranceTest, ReregisterFrameworkExitedExecutor)
 
   MockExecutor exec(DEFAULT_EXECUTOR_ID);
   TestingIsolator isolator(&exec);
-  Owned<MasterDetector> slaveDetector = new StandaloneMasterDetector(master.get());
+  Owned<MasterDetector> slaveDetector(
+      new StandaloneMasterDetector(master.get()));
   Try<PID<Slave> > slave = StartSlave(&isolator, slaveDetector);
   ASSERT_SOME(slave);
 
   MockScheduler sched;
-  Owned<StandaloneMasterDetector> schedDetector =
-    new StandaloneMasterDetector(master.get());
+  Owned<StandaloneMasterDetector> schedDetector(
+      new StandaloneMasterDetector(master.get()));
   TestingMesosSchedulerDriver driver(&sched, schedDetector.get());
 
   Future<process::Message> frameworkRegisteredMessage =

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/master_contender_detector_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_contender_detector_tests.cpp b/src/tests/master_contender_detector_tests.cpp
index 6f268ba..76464ea 100644
--- a/src/tests/master_contender_detector_tests.cpp
+++ b/src/tests/master_contender_detector_tests.cpp
@@ -30,6 +30,7 @@
 
 #include <process/clock.hpp>
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 #include <process/protobuf.hpp>
 
@@ -66,6 +67,7 @@ using mesos::internal::slave::Slave;
 
 using process::Clock;
 using process::Future;
+using process::Owned;
 using process::PID;
 using process::UPID;
 
@@ -99,7 +101,7 @@ TEST_F(MasterContenderDetectorTest, File)
 
   ASSERT_SOME(detector);
 
-  StartSlave(detector.get(), flags);
+  StartSlave(Owned<MasterDetector>(detector.get()), flags);
 
   MockScheduler sched;
   MesosSchedulerDriver driver(

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/master_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_tests.cpp b/src/tests/master_tests.cpp
index 37ee7a0..d34450b 100644
--- a/src/tests/master_tests.cpp
+++ b/src/tests/master_tests.cpp
@@ -30,6 +30,7 @@
 #include <process/clock.hpp>
 #include <process/future.hpp>
 #include <process/gmock.hpp>
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 
 #include <stout/option.hpp>
@@ -61,6 +62,7 @@ using mesos::internal::slave::Slave;
 
 using process::Clock;
 using process::Future;
+using process::Owned;
 using process::PID;
 
 using std::map;
@@ -983,7 +985,8 @@ TEST_F(MasterTest, MasterLost)
   Try<PID<Master> > master = StartMaster();
   ASSERT_SOME(master);
 
-  Owned<StandaloneMasterDetector> detector = new StandaloneMasterDetector();
+  Owned<StandaloneMasterDetector> detector(
+      new StandaloneMasterDetector());
   detector->appoint(master.get());
 
   Try<PID<Slave> > slave = StartSlave();

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 3d510b2..b1239a6 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -29,6 +29,7 @@
 #include <process/future.hpp>
 #include <process/gmock.hpp>
 #include <process/gtest.hpp>
+#include <process/owned.hpp>
 #include <process/pid.hpp>
 #include <process/process.hpp>
 
@@ -103,19 +104,19 @@ protected:
   // Starts a slave with the specified isolator, detector and flags.
   virtual Try<process::PID<slave::Slave> > StartSlave(
       slave::Isolator* isolator,
-      Owned<MasterDetector> detector,
+      process::Owned<MasterDetector> detector,
       const Option<slave::Flags>& flags = None());
 
   // Starts a slave with the specified MasterDetector and flags.
   virtual Try<process::PID<slave::Slave> > StartSlave(
-      Owned<MasterDetector> detector,
+      process::Owned<MasterDetector> detector,
       const Option<slave::Flags>& flags = None());
 
   // Starts a slave with the specified mock executor, MasterDetector
   // and flags.
   virtual Try<process::PID<slave::Slave> > StartSlave(
       MockExecutor* executor,
-      Owned<MasterDetector> detector,
+      process::Owned<MasterDetector> detector,
       const Option<slave::Flags>& flags = None());
 
   // Stop the specified master.

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/slave_recovery_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_recovery_tests.cpp b/src/tests/slave_recovery_tests.cpp
index 3c677e6..250083d 100644
--- a/src/tests/slave_recovery_tests.cpp
+++ b/src/tests/slave_recovery_tests.cpp
@@ -28,6 +28,7 @@
 
 #include <process/dispatch.hpp>
 #include <process/gmock.hpp>
+#include <process/owned.hpp>
 
 #include <stout/none.hpp>
 #include <stout/numify.hpp>
@@ -2322,8 +2323,8 @@ TYPED_TEST(SlaveRecoveryTest, MasterFailover)
   frameworkInfo.CopyFrom(DEFAULT_FRAMEWORK_INFO);
   frameworkInfo.set_checkpoint(true);
 
-  Owned<StandaloneMasterDetector> detector =
-    new StandaloneMasterDetector(master.get());
+  Owned<StandaloneMasterDetector> detector(
+      new StandaloneMasterDetector(master.get()));
   TestingMesosSchedulerDriver driver(
       &sched, frameworkInfo, DEFAULT_CREDENTIAL, detector.get());
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/92bbaf8a/src/tests/zookeeper_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/zookeeper_tests.cpp b/src/tests/zookeeper_tests.cpp
index 0059438..a5fe9e1 100644
--- a/src/tests/zookeeper_tests.cpp
+++ b/src/tests/zookeeper_tests.cpp
@@ -23,9 +23,9 @@
 #include <string>
 
 #include <process/gtest.hpp>
+#include <process/owned.hpp>
 
 #include <stout/gtest.hpp>
-#include <stout/owned.hpp>
 #include <stout/strings.hpp>
 
 #include "zookeeper/authentication.hpp"
@@ -238,7 +238,8 @@ TEST_F(ZooKeeperTest, LeaderContender)
   Seconds timeout(10);
   Group group(server->connectString(), timeout, "/test/");
 
-  Owned<LeaderContender> contender = new LeaderContender(&group, "candidate 1");
+  Owned<LeaderContender> contender(
+      new LeaderContender(&group, "candidate 1"));
   contender->contend();
 
   // Immediately withdrawing after contending leads to delayed
@@ -248,7 +249,8 @@ TEST_F(ZooKeeperTest, LeaderContender)
   EXPECT_TRUE(withdrawn.get());
 
   // Normal workflow.
-  contender = new LeaderContender(&group, "candidate 1");
+  contender = Owned<LeaderContender>(
+      new LeaderContender(&group, "candidate 1"));
 
   Future<Future<Nothing> > candidated = contender->contend();
   AWAIT_READY(candidated);
@@ -271,7 +273,8 @@ TEST_F(ZooKeeperTest, LeaderContender)
   EXPECT_FALSE(withdrawn.get());
 
   // Contend again.
-  contender = new LeaderContender(&group, "candidate 1");
+  contender = Owned<LeaderContender>(
+      new LeaderContender(&group, "candidate 1"));
   candidated = contender->contend();
 
   session = group.session();
@@ -293,7 +296,8 @@ TEST_F(ZooKeeperTest, LeaderContender)
   AWAIT_READY(withdrawn);
 
   // Contend (3) and shutdown the network this time.
-  contender = new LeaderContender(&group, "candidate 1");
+  contender = Owned<LeaderContender>(
+      new LeaderContender(&group, "candidate 1"));
   candidated = contender->contend();
   AWAIT_READY(candidated);
   lostCandidacy = candidated.get();
@@ -317,7 +321,8 @@ TEST_F(ZooKeeperTest, LeaderContender)
   server->startNetwork();
 
   // Contend again (4).
-  contender = new LeaderContender(&group, "candidate 1");
+  contender = Owned<LeaderContender>(
+      new LeaderContender(&group, "candidate 1"));
   candidated = contender->contend();
   AWAIT_READY(candidated);
 }


[12/14] git commit: Replaced 'Option::some(...)' with 'Some(...)'.

Posted by be...@apache.org.
Replaced 'Option<T>::some(...)' with 'Some(...)'.

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


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

Branch: refs/heads/master
Commit: 51f81e2faedf858916e977e6aebb0333d7af21fe
Parents: 2906911
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Nov 26 22:47:04 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:17:09 2013 -0800

----------------------------------------------------------------------
 src/master/master.cpp   | 6 +++---
 src/state/leveldb.cpp   | 5 +++--
 src/state/protobuf.hpp  | 3 ++-
 src/state/state.hpp     | 3 ++-
 src/state/zookeeper.cpp | 3 ++-
 src/tests/gc_tests.cpp  | 2 +-
 src/zookeeper/group.cpp | 3 ++-
 7 files changed, 15 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 23c2a5f..4f4db93 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -96,14 +96,14 @@ protected:
       } else if (read.get().empty()) {
         LOG(WARNING) << "Empty whitelist file " << path << ". "
                      << "No offers will be made!";
-        whitelist = Option<hashset<string> >::some(hashset<string>());
+        whitelist = hashset<string>();
       } else {
         hashset<string> hostnames;
         vector<string> lines = strings::tokenize(read.get(), "\n");
         foreach (const string& hostname, lines) {
           hostnames.insert(hostname);
         }
-        whitelist = Option<hashset<string> >::some(hostnames);
+        whitelist = hostnames;
       }
     }
 
@@ -2229,7 +2229,7 @@ Resources Master::launchTask(const TaskInfo& task,
       resources += task.executor().resources();
     }
 
-    executorId = Option<ExecutorID>::some(task.executor().executor_id());
+    executorId = task.executor().executor_id();
   }
 
   // Add the task to the framework and slave.

http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/state/leveldb.cpp
----------------------------------------------------------------------
diff --git a/src/state/leveldb.cpp b/src/state/leveldb.cpp
index 49872b8..a099db9 100644
--- a/src/state/leveldb.cpp
+++ b/src/state/leveldb.cpp
@@ -14,6 +14,7 @@
 #include <stout/error.hpp>
 #include <stout/none.hpp>
 #include <stout/option.hpp>
+#include <stout/some.hpp>
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
@@ -52,7 +53,7 @@ void LevelDBStorageProcess::initialize()
 
   if (!status.ok()) {
     // TODO(benh): Consider trying to repair the DB.
-    error = Option<string>::some(status.ToString());
+    error = status.ToString();
   } else {
     // TODO(benh): Conditionally compact to avoid long recovery times?
     db->CompactRange(NULL, NULL);
@@ -199,7 +200,7 @@ Try<Option<Entry> > LevelDBStorageProcess::read(const string& name)
     return Error("Failed to deserialize Entry");
   }
 
-  return Option<Entry>::some(entry);
+  return Some(entry);
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/state/protobuf.hpp
----------------------------------------------------------------------
diff --git a/src/state/protobuf.hpp b/src/state/protobuf.hpp
index 75e082b..5ee2880 100644
--- a/src/state/protobuf.hpp
+++ b/src/state/protobuf.hpp
@@ -25,6 +25,7 @@
 
 #include <stout/lambda.hpp>
 #include <stout/option.hpp>
+#include <stout/some.hpp>
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
@@ -145,7 +146,7 @@ process::Future<Option<Variable<T> > > State::_store(
     const Option<state::Variable>& variable)
 {
   if (variable.isSome()) {
-    return Option<Variable<T> >::some(Variable<T>(variable.get(), t));
+    return Some(Variable<T>(variable.get(), t));
   }
 
   return None();

http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/state/state.hpp
----------------------------------------------------------------------
diff --git a/src/state/state.hpp b/src/state/state.hpp
index b3abf89..02620b3 100644
--- a/src/state/state.hpp
+++ b/src/state/state.hpp
@@ -27,6 +27,7 @@
 #include <stout/lambda.hpp>
 #include <stout/none.hpp>
 #include <stout/option.hpp>
+#include <stout/some.hpp>
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
@@ -174,7 +175,7 @@ inline process::Future<Option<Variable > > State::_store(
     const bool& b) // TODO(benh): Remove 'const &' after fixing libprocess.
 {
   if (b) {
-    return Option<Variable>::some(Variable(entry));
+    return Some(Variable(entry));
   }
 
   return None();

http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/state/zookeeper.cpp
----------------------------------------------------------------------
diff --git a/src/state/zookeeper.cpp b/src/state/zookeeper.cpp
index 1801fce..6e6a01a 100644
--- a/src/state/zookeeper.cpp
+++ b/src/state/zookeeper.cpp
@@ -15,6 +15,7 @@
 #include <stout/none.hpp>
 #include <stout/option.hpp>
 #include <stout/result.hpp>
+#include <stout/some.hpp>
 #include <stout/strings.hpp>
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
@@ -339,7 +340,7 @@ Result<Option<Entry> > ZooKeeperStorageProcess::doGet(const string& name)
     return Error("Failed to deserialize Entry");
   }
 
-  return Option<Entry>::some(entry);
+  return Some(entry);
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/tests/gc_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/gc_tests.cpp b/src/tests/gc_tests.cpp
index 538976a..6638a4a 100644
--- a/src/tests/gc_tests.cpp
+++ b/src/tests/gc_tests.cpp
@@ -655,7 +655,7 @@ TEST_F(GarbageCollectorIntegrationTest, DiskUsage)
   process::dispatch(
       slave.get(),
       &Slave::_checkDiskUsage,
-      Try<double>::some(1.0 - slave::GC_DISK_HEADROOM));
+      Try<double>(1.0 - slave::GC_DISK_HEADROOM));
 
   AWAIT_READY(_checkDiskUsage);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/51f81e2f/src/zookeeper/group.cpp
----------------------------------------------------------------------
diff --git a/src/zookeeper/group.cpp b/src/zookeeper/group.cpp
index 12c781b..db55151 100644
--- a/src/zookeeper/group.cpp
+++ b/src/zookeeper/group.cpp
@@ -14,6 +14,7 @@
 #include <stout/numify.hpp>
 #include <stout/os.hpp>
 #include <stout/result.hpp>
+#include <stout/some.hpp>
 #include <stout/strings.hpp>
 #include <stout/utils.hpp>
 
@@ -270,7 +271,7 @@ Future<Option<int64_t> > GroupProcess::session()
     return None();
   }
 
-  return Option<int64_t>::some(zk->getSessionId());
+  return Some(zk->getSessionId());
 }
 
 


[11/14] git commit: Added stout 'Some' tests to libprocess/3rdparty Makefile.

Posted by be...@apache.org.
Added stout 'Some' tests to libprocess/3rdparty Makefile.

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


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

Branch: refs/heads/master
Commit: 2906911f0bef6b4b2bd92d5aa23929cfae7a6261
Parents: 3a51ff2
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Nov 26 22:44:16 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:16:45 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/Makefile.am | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2906911f/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index 0b630f8..f9d1aed 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -136,6 +136,7 @@ stout_tests_SOURCES =				\
   $(STOUT)/tests/os/sendfile_tests.cpp		\
   $(STOUT)/tests/os/signals_tests.cpp		\
   $(STOUT)/tests/set_tests.cpp			\
+  $(STOUT)/tests/some_tests.cpp			\
   $(STOUT)/tests/strings_tests.cpp		\
   $(STOUT)/tests/thread_tests.cpp		\
   $(STOUT)/tests/uuid_tests.cpp


[14/14] git commit: Used 'Failure' instead of Future::failed.

Posted by be...@apache.org.
Used 'Failure' instead of Future<T>::failed.

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


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

Branch: refs/heads/master
Commit: e427fae0c7e9bed5424f33a6cfe4ca5c9d99b0dc
Parents: 43e90f5
Author: Benjamin Hindman <be...@gmail.com>
Authored: Wed Nov 27 11:15:28 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:17:46 2013 -0800

----------------------------------------------------------------------
 src/files/files.cpp                 |  6 +--
 src/linux/cgroups.cpp               | 86 ++++++++++++++++----------------
 src/master/registrar.cpp            |  7 +--
 src/slave/cgroups_isolator.cpp      | 17 +++----
 src/slave/monitor.cpp               |  4 +-
 src/slave/process_isolator.cpp      |  6 +--
 src/slave/reaper.cpp                |  2 +-
 src/slave/slave.cpp                 |  2 +-
 src/slave/status_update_manager.cpp | 20 ++++----
 src/state/leveldb.cpp               | 18 +++----
 src/state/protobuf.hpp              |  4 +-
 src/state/zookeeper.cpp             | 16 +++---
 src/zookeeper/group.cpp             | 14 +++---
 13 files changed, 99 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/files/files.cpp
----------------------------------------------------------------------
diff --git a/src/files/files.cpp b/src/files/files.cpp
index 6b85842..45ef95c 100644
--- a/src/files/files.cpp
+++ b/src/files/files.cpp
@@ -116,7 +116,7 @@ Future<Nothing> FilesProcess::attach(const string& path, const string& name)
   Result<string> result = os::realpath(path);
 
   if (!result.isSome()) {
-    return Future<Nothing>::failed(
+    return Failure(
         "Failed to get realpath of '" + path + "': " +
         (result.isError()
          ? result.error()
@@ -127,8 +127,8 @@ Future<Nothing> FilesProcess::attach(const string& path, const string& name)
   Try<bool> access = os::access(result.get(), R_OK);
 
   if (access.isError() || !access.get()) {
-    return Future<Nothing>::failed("Failed to access '" + path + "': " +
-        (access.isError() ? access.error() : "Access denied"));
+    return Failure("Failed to access '" + path + "': " +
+                   (access.isError() ? access.error() : "Access denied"));
   }
 
   // To simplify the read/browse logic, strip any trailing / from the name.

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/linux/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp
index 8379aa3..5a95e75 100644
--- a/src/linux/cgroups.cpp
+++ b/src/linux/cgroups.cpp
@@ -407,32 +407,30 @@ static Try<Nothing> write(
 
 // Returns some error string if either (a) hierarchy is not mounted,
 // (b) cgroup does not exist, or (c) control file does not exist.
-static Option<string> verify(
+static Option<Error> verify(
     const string& hierarchy,
     const string& cgroup = "",
     const string& control = "")
 {
   Try<bool> mounted = cgroups::mounted(hierarchy);
   if (mounted.isError()) {
-    return Option<string>::some(
+    return Error(
         "Failed to determine if the hierarchy at '" + hierarchy +
         "' is mounted: " + mounted.error());
   } else if (!mounted.get()) {
-    return Option<string>::some(
-        "'" + hierarchy + "' is not a valid hierarchy");
+    return Error("'" + hierarchy + "' is not a valid hierarchy");
   }
 
   if (cgroup != "") {
     if (!os::exists(path::join(hierarchy, cgroup))) {
-      return Option<string>::some(
-          "'" + cgroup + "' is not a valid cgroup");
+      return Error("'" + cgroup + "' is not a valid cgroup");
     }
   }
 
   if (control != "") {
     CHECK(cgroup != "");
     if (!os::exists(path::join(hierarchy, cgroup, control))) {
-      return Option<string>::some(
+      return Error(
           "'" + control + "' is not a valid control (is subsystem attached?)");
     }
   }
@@ -655,9 +653,9 @@ Try<Nothing> mount(const string& hierarchy, const string& subsystems, int retry)
 
 Try<Nothing> unmount(const string& hierarchy)
 {
-  Option<string> error = verify(hierarchy);
+  Option<Error> error = verify(hierarchy);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   Try<Nothing> unmount = internal::unmount(hierarchy);
@@ -721,9 +719,9 @@ Try<bool> mounted(const string& hierarchy, const string& subsystems)
 
 Try<Nothing> create(const string& hierarchy, const string& cgroup)
 {
-  Option<string> error = verify(hierarchy);
+  Option<Error> error = verify(hierarchy);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   return internal::create(hierarchy, cgroup);
@@ -732,9 +730,9 @@ Try<Nothing> create(const string& hierarchy, const string& cgroup)
 
 Try<Nothing> remove(const string& hierarchy, const string& cgroup)
 {
-  Option<string> error = verify(hierarchy, cgroup);
+  Option<Error> error = verify(hierarchy, cgroup);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   Try<vector<string> > cgroups = cgroups::get(hierarchy, cgroup);
@@ -752,9 +750,9 @@ Try<Nothing> remove(const string& hierarchy, const string& cgroup)
 
 Try<bool> exists(const string& hierarchy, const string& cgroup)
 {
-  Option<string> error = verify(hierarchy);
+  Option<Error> error = verify(hierarchy);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   return os::exists(path::join(hierarchy, cgroup));
@@ -763,9 +761,9 @@ Try<bool> exists(const string& hierarchy, const string& cgroup)
 
 Try<vector<string> > get(const string& hierarchy, const string& cgroup)
 {
-  Option<string> error = verify(hierarchy, cgroup);
+  Option<Error> error = verify(hierarchy, cgroup);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   Result<string> hierarchyAbsPath = os::realpath(hierarchy);
@@ -826,9 +824,9 @@ Try<Nothing> kill(
     const string& cgroup,
     int signal)
 {
-  Option<string> error = verify(hierarchy, cgroup);
+  Option<Error> error = verify(hierarchy, cgroup);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   Try<set<pid_t> > pids = tasks(hierarchy, cgroup);
@@ -858,9 +856,9 @@ Try<string> read(
     const string& cgroup,
     const string& control)
 {
-  Option<string> error = verify(hierarchy, cgroup, control);
+  Option<Error> error = verify(hierarchy, cgroup, control);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   return internal::read(hierarchy, cgroup, control);
@@ -873,9 +871,9 @@ Try<Nothing> write(
     const string& control,
     const string& value)
 {
-  Option<string> error = verify(hierarchy, cgroup, control);
+  Option<Error> error = verify(hierarchy, cgroup, control);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   return internal::write(hierarchy, cgroup, control, value);
@@ -887,9 +885,9 @@ Try<bool> exists(
     const string& cgroup,
     const string& control)
 {
-  Option<string> error = verify(hierarchy, cgroup);
+  Option<Error> error = verify(hierarchy, cgroup);
   if (error.isSome()) {
-    return Error(error.get());
+    return error.get();
   }
 
   return os::exists(path::join(hierarchy, cgroup, control));
@@ -1146,9 +1144,9 @@ Future<uint64_t> listen(
     const string& control,
     const Option<string>& args)
 {
-  Option<string> error = verify(hierarchy, cgroup, control);
+  Option<Error> error = verify(hierarchy, cgroup, control);
   if (error.isSome()) {
-    return Future<uint64_t>::failed(error.get());
+    return Failure(error.get());
   }
 
   internal::EventListener* listener =
@@ -1357,19 +1355,19 @@ Future<bool> freeze(
     const Duration& interval,
     unsigned int retries)
 {
-  Option<string> error = verify(hierarchy, cgroup, "freezer.state");
+  Option<Error> error = verify(hierarchy, cgroup, "freezer.state");
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   }
 
   if (interval < Seconds(0)) {
-    return Future<bool>::failed("Interval should be non-negative");
+    return Failure("Interval should be non-negative");
   }
 
   // Check the current freezer state.
   Try<string> state = internal::read(hierarchy, cgroup, "freezer.state");
   if (state.isError()) {
-    return Future<bool>::failed(
+    return Failure(
         "Failed to read control 'freezer.state': " + state.error());
   } else if (strings::trim(state.get()) == "FROZEN") {
     // Immediately return success.
@@ -1389,19 +1387,19 @@ Future<bool> thaw(
     const string& cgroup,
     const Duration& interval)
 {
-  Option<string> error = verify(hierarchy, cgroup, "freezer.state");
+  Option<Error> error = verify(hierarchy, cgroup, "freezer.state");
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   }
 
   if (interval < Seconds(0)) {
-    return Future<bool>::failed("Interval should be non-negative");
+    return Failure("Interval should be non-negative");
   }
 
   // Check the current freezer state.
   Try<string> state = internal::read(hierarchy, cgroup, "freezer.state");
   if (state.isError()) {
-    return Future<bool>::failed(
+    return Failure(
         "Failed to read control 'freezer.state': " + state.error());
   } else if (strings::trim(state.get()) == "THAWED") {
     // Immediately return success.
@@ -1551,7 +1549,7 @@ private:
   {
     Try<Nothing> kill = cgroups::kill(hierarchy, cgroup, signal);
     if (kill.isError()) {
-      return Future<Nothing>::failed(kill.error());
+      return Failure(kill.error());
     }
     return Nothing();
   }
@@ -1685,13 +1683,13 @@ Future<bool> destroy(
     const Duration& interval)
 {
   if (interval < Seconds(0)) {
-    return Future<bool>::failed("Interval should be non-negative");
+    return Failure("Interval should be non-negative");
   }
 
   // Construct the vector of cgroups to destroy.
   Try<vector<string> > cgroups = cgroups::get(hierarchy, cgroup);
   if (cgroups.isError()) {
-    return Future<bool>::failed(
+    return Failure(
         "Failed to get nested cgroups: " + cgroups.error());
   }
 
@@ -1705,7 +1703,7 @@ Future<bool> destroy(
   }
 
   // If the freezer subsystem is available, destroy the cgroups.
-  Option<string> error = verify(hierarchy, cgroup, "freezer.state");
+  Option<Error> error = verify(hierarchy, cgroup, "freezer.state");
   if (error.isNone()) {
     internal::Destroyer* destroyer =
       new internal::Destroyer(hierarchy, candidates, interval);
@@ -1717,7 +1715,7 @@ Future<bool> destroy(
     foreach (const std::string& cgroup, candidates) {
       Try<Nothing> remove = cgroups::remove(hierarchy, cgroup);
       if (remove.isError()) {
-        return Future<bool>::failed(remove.error());
+        return Failure(remove.error());
       }
     }
   }
@@ -1734,7 +1732,7 @@ Future<bool> cleanup(const string& hierarchy)
 {
   Try<bool> mounted = cgroups::mounted(hierarchy);
   if (mounted.isError()) {
-    return Future<bool>::failed(mounted.error());
+    return Failure(mounted.error());
   }
 
   if (mounted.get()) {
@@ -1746,7 +1744,7 @@ Future<bool> cleanup(const string& hierarchy)
     if (os::exists(hierarchy)) {
       Try<Nothing> rmdir = os::rmdir(hierarchy);
       if (rmdir.isError()) {
-        return Future<bool>::failed(rmdir.error());
+        return Failure(rmdir.error());
       }
     }
   }
@@ -1760,14 +1758,14 @@ Future<bool> _cleanup(const string& hierarchy)
   // Remove the hierarchy.
   Try<Nothing> unmount = cgroups::unmount(hierarchy);
   if (unmount.isError()) {
-    return Future<bool>::failed(unmount.error());
+    return Failure(unmount.error());
   }
 
   // Remove the directory if it still exists.
   if (os::exists(hierarchy)) {
     Try<Nothing> rmdir = os::rmdir(hierarchy);
     if (rmdir.isError()) {
-      return Future<bool>::failed(rmdir.error());
+      return Failure(rmdir.error());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/master/registrar.cpp
----------------------------------------------------------------------
diff --git a/src/master/registrar.cpp b/src/master/registrar.cpp
index 42fe30e..61fdea3 100644
--- a/src/master/registrar.cpp
+++ b/src/master/registrar.cpp
@@ -40,6 +40,7 @@ using mesos::internal::state::protobuf::State;
 using mesos::internal::state::protobuf::Variable;
 
 using process::dispatch;
+using process::Failure;
 using process::Future;
 using process::Process;
 using process::Promise;
@@ -259,7 +260,7 @@ Future<bool> RegistrarProcess::_readmit(
   CHECK_SOME(slaves.variable);
 
   if (!info.has_id()) {
-    return Future<bool>::failed("Expecting SlaveInfo to have a SlaveID");
+    return Failure("Expecting SlaveInfo to have a SlaveID");
   }
 
   Mutation<registry::Slaves>* mutation = new Readmit(info);
@@ -285,7 +286,7 @@ Future<bool> RegistrarProcess::_remove(
   CHECK_SOME(slaves.variable);
 
   if (!info.has_id()) {
-    return Future<bool>::failed("Expecting SlaveInfo to have a SlaveID");
+    return Failure("Expecting SlaveInfo to have a SlaveID");
   }
 
   Mutation<registry::Slaves>* mutation = new Remove(info);
@@ -355,7 +356,7 @@ Future<bool> RegistrarProcess::_update(
 
   if (variable.isNone()) {
     LOG(WARNING) << "Failed to update 'slaves': version mismatch";
-    return Future<bool>::failed("Failed to update 'slaves': version mismatch");
+    return Failure("Failed to update 'slaves': version mismatch");
   }
 
   LOG(INFO) << "Successfully updated 'slaves'";

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/slave/cgroups_isolator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/cgroups_isolator.cpp b/src/slave/cgroups_isolator.cpp
index e91d22e..80155a3 100644
--- a/src/slave/cgroups_isolator.cpp
+++ b/src/slave/cgroups_isolator.cpp
@@ -59,6 +59,7 @@
 #include "slave/state.hpp"
 
 using process::defer;
+using process::Failure;
 using process::Future;
 
 using std::list;
@@ -728,7 +729,7 @@ Future<ResourceStatistics> CgroupsIsolator::usage(
   if (!infos.contains(frameworkId) ||
       !infos[frameworkId].contains(executorId) ||
       infos[frameworkId][executorId]->killed) {
-    return Future<ResourceStatistics>::failed("Unknown or killed executor");
+    return Failure("Unknown or killed executor");
   }
 
   // Get the number of clock ticks, used for cpu accounting.
@@ -757,8 +758,7 @@ Future<ResourceStatistics> CgroupsIsolator::usage(
     cgroups::stat(hierarchy, info->name(), "cpuacct.stat");
 
   if (stat.isError()) {
-    return Future<ResourceStatistics>::failed(
-        "Failed to read cpuacct.stat: " + stat.error());
+    return Failure("Failed to read cpuacct.stat: " + stat.error());
   }
 
   // TODO(bmahler): Add namespacing to cgroups to enforce the expected
@@ -775,8 +775,7 @@ Future<ResourceStatistics> CgroupsIsolator::usage(
   //   2. It does not include any file backed pages.
   Try<Bytes> usage = cgroups::memory::usage_in_bytes(hierarchy, info->name());
   if (usage.isError()) {
-    return Future<ResourceStatistics>::failed(
-        "Failed to parse memory.usage_in_bytes: " + usage.error());
+    return Failure("Failed to parse memory.usage_in_bytes: " + usage.error());
   }
 
   // TODO(bmahler): Add namespacing to cgroups to enforce the expected
@@ -785,8 +784,7 @@ Future<ResourceStatistics> CgroupsIsolator::usage(
 
   stat = cgroups::stat(hierarchy, info->name(), "memory.stat");
   if (stat.isError()) {
-    return Future<ResourceStatistics>::failed(
-        "Failed to read memory.stat: " + stat.error());
+    return Failure("Failed to read memory.stat: " + stat.error());
   }
 
   if (stat.get().contains("total_cache")) {
@@ -805,8 +803,7 @@ Future<ResourceStatistics> CgroupsIsolator::usage(
   stat = cgroups::stat(hierarchy, info->name(), "cpu.stat");
 
   if (stat.isError()) {
-    return Future<ResourceStatistics>::failed(
-        "Failed to read cpu.stat: " + stat.error());
+    return Failure("Failed to read cpu.stat: " + stat.error());
   }
 
   if (stat.get().contains("nr_periods")) {
@@ -921,7 +918,7 @@ Future<Nothing> CgroupsIsolator::recover(
   // should be safe because we've been able to acquire the file lock).
   Try<vector<string> > orphans = cgroups::get(hierarchy, flags.cgroups_root);
   if (orphans.isError()) {
-    return Future<Nothing>::failed(orphans.error());
+    return Failure(orphans.error());
   }
 
   foreach (const string& orphan, orphans.get()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/slave/monitor.cpp
----------------------------------------------------------------------
diff --git a/src/slave/monitor.cpp b/src/slave/monitor.cpp
index 7201ad7..a931c4f 100644
--- a/src/slave/monitor.cpp
+++ b/src/slave/monitor.cpp
@@ -96,7 +96,7 @@ Future<Nothing> ResourceMonitorProcess::watch(
 {
   if (watches.contains(frameworkId) &&
       watches[frameworkId].contains(executorId)) {
-    return Future<Nothing>::failed("Already watched");
+    return Failure("Already watched");
   }
 
   watches[frameworkId][executorId] = executorInfo;
@@ -142,7 +142,7 @@ Future<Nothing> ResourceMonitorProcess::unwatch(
 
   if (!watches.contains(frameworkId) ||
       !watches[frameworkId].contains(executorId)) {
-    return Future<Nothing>::failed("Not watched");
+    return Failure("Not watched");
   }
 
   watches[frameworkId].erase(executorId);

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/slave/process_isolator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/process_isolator.cpp b/src/slave/process_isolator.cpp
index a6e9ed6..0bc698f 100644
--- a/src/slave/process_isolator.cpp
+++ b/src/slave/process_isolator.cpp
@@ -378,7 +378,7 @@ Future<ResourceStatistics> ProcessIsolator::usage(
   if (!infos.contains(frameworkId) ||
       !infos[frameworkId].contains(executorId) ||
       infos[frameworkId][executorId]->killed) {
-    return Future<ResourceStatistics>::failed("Unknown/killed executor");
+    return Failure("Unknown/killed executor");
   }
 
   ProcessInfo* info = infos[frameworkId][executorId];
@@ -404,7 +404,7 @@ Future<ResourceStatistics> ProcessIsolator::usage(
   Result<os::Process> process = os::process(info->pid.get());
 
   if (!process.isSome()) {
-    return Future<ResourceStatistics>::failed(
+    return Failure(
         process.isError() ? process.error() : "Process does not exist");
   }
 
@@ -425,7 +425,7 @@ Future<ResourceStatistics> ProcessIsolator::usage(
   const Try<set<pid_t> >& children = os::children(info->pid.get(), true);
 
   if (children.isError()) {
-    return Future<ResourceStatistics>::failed(
+    return Failure(
         "Failed to get children of " + stringify(info->pid.get()) + ": " +
         children.error());
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/slave/reaper.cpp
----------------------------------------------------------------------
diff --git a/src/slave/reaper.cpp b/src/slave/reaper.cpp
index 4ce9413..5eabbc3 100644
--- a/src/slave/reaper.cpp
+++ b/src/slave/reaper.cpp
@@ -60,7 +60,7 @@ Future<Option<int> > ReaperProcess::monitor(pid_t pid)
                  << " because it doesn't exist";
     return None();
   } else {
-    return Future<Option<int> >::failed(
+    return Failure(
         "Failed to monitor process " + stringify(pid) + ": " + process.error());
   }
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 6fc18c5..91afe03 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -2842,7 +2842,7 @@ Future<Nothing> Slave::garbageCollect(const string& path)
   if (mtime.isError()) {
     LOG(ERROR) << "Failed to find the mtime of '" << path
                << "': " << mtime.error();
-    return Future<Nothing>::failed(mtime.error());
+    return Failure(mtime.error());
   }
 
   // GC based on the modification time.

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/slave/status_update_manager.cpp
----------------------------------------------------------------------
diff --git a/src/slave/status_update_manager.cpp b/src/slave/status_update_manager.cpp
index b79f9de..f7a0c40 100644
--- a/src/slave/status_update_manager.cpp
+++ b/src/slave/status_update_manager.cpp
@@ -241,7 +241,7 @@ Future<Nothing> StatusUpdateManagerProcess::recover(
         // Replay the stream.
         Try<Nothing> replay = stream->replay(task.updates, task.acks);
         if (replay.isError()) {
-          return Future<Nothing>::failed(
+          return Failure(
               "Failed to replay status updates for task " + stringify(task.id) +
               " of framework " + stringify(framework.id) +
               ": " + replay.error());
@@ -322,7 +322,7 @@ Future<Nothing> StatusUpdateManagerProcess::_update(
   // Verify that we didn't get a non-checkpointable update for a
   // stream that is checkpointable, and vice-versa.
   if (stream->checkpoint != checkpoint) {
-    return Future<Nothing>::failed(
+    return Failure(
         "Mismatched checkpoint value for status update " + stringify(update) +
         " (expected checkpoint=" + stringify(stream->checkpoint) +
         " actual checkpoint=" + stringify(checkpoint) + ")");
@@ -331,7 +331,7 @@ Future<Nothing> StatusUpdateManagerProcess::_update(
   // Handle the status update.
   Try<bool> result = stream->update(update);
   if (result.isError()) {
-    return Future<Nothing>::failed(result.error());
+    return Failure(result.error());
   }
 
   // We don't return a failed future here so that the slave can re-ack
@@ -346,7 +346,7 @@ Future<Nothing> StatusUpdateManagerProcess::_update(
     CHECK(stream->timeout.isNone());
     const Result<StatusUpdate>& next = stream->next();
     if (next.isError()) {
-      return Future<Nothing>::failed(next.error());
+      return Failure(next.error());
     }
 
     CHECK_SOME(next);
@@ -396,7 +396,7 @@ Future<bool> StatusUpdateManagerProcess::acknowledgement(
   // This might happen if we haven't completed recovery yet or if the
   // acknowledgement is for a stream that has been cleaned up.
   if (stream == NULL) {
-    return Future<bool>::failed(
+    return Failure(
         "Cannot find the status update stream for task " + stringify(taskId) +
         " of framework " + stringify(frameworkId));
   }
@@ -404,13 +404,13 @@ Future<bool> StatusUpdateManagerProcess::acknowledgement(
   // Get the corresponding update for this ACK.
   const Result<StatusUpdate>& update = stream->next();
   if (update.isError()) {
-    return Future<bool>::failed(update.error());
+    return Failure(update.error());
   }
 
   // This might happen if we retried a status update and got back
   // acknowledgments for both the original and the retried update.
   if (update.isNone()) {
-    return Future<bool>::failed(
+    return Failure(
         "Unexpected status update acknowledgment (UUID: " + uuid.toString() +
         ") for task " + stringify(taskId) +
         " of framework " + stringify(frameworkId));
@@ -421,11 +421,11 @@ Future<bool> StatusUpdateManagerProcess::acknowledgement(
     stream->acknowledgement(taskId, frameworkId, uuid, update.get());
 
   if (result.isError()) {
-    return Future<bool>::failed(result.error());
+    return Failure(result.error());
   }
 
   if (!result.get()) {
-    return Future<bool>::failed("Duplicate acknowledgement");
+    return Failure("Duplicate acknowledgement");
   }
 
   // Reset the timeout.
@@ -434,7 +434,7 @@ Future<bool> StatusUpdateManagerProcess::acknowledgement(
   // Get the next update in the queue.
   const Result<StatusUpdate>& next = stream->next();
   if (next.isError()) {
-    return Future<bool>::failed(next.error());
+    return Failure(next.error());
   }
 
   bool terminated = stream->terminated;

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/state/leveldb.cpp
----------------------------------------------------------------------
diff --git a/src/state/leveldb.cpp b/src/state/leveldb.cpp
index a099db9..be0df0c 100644
--- a/src/state/leveldb.cpp
+++ b/src/state/leveldb.cpp
@@ -64,7 +64,7 @@ void LevelDBStorageProcess::initialize()
 Future<vector<string> > LevelDBStorageProcess::names()
 {
   if (error.isSome()) {
-    return Future<vector<string> >::failed(error.get());
+    return Failure(error.get());
   }
 
   vector<string> results;
@@ -87,13 +87,13 @@ Future<vector<string> > LevelDBStorageProcess::names()
 Future<Option<Entry> > LevelDBStorageProcess::get(const string& name)
 {
   if (error.isSome()) {
-    return Future<Option<Entry> >::failed(error.get());
+    return Failure(error.get());
   }
 
   Try<Option<Entry> > option = read(name);
 
   if (option.isError()) {
-    return Future<Option<Entry> >::failed(option.error());
+    return Failure(option.error());
   }
 
   return option.get();
@@ -103,7 +103,7 @@ Future<Option<Entry> > LevelDBStorageProcess::get(const string& name)
 Future<bool> LevelDBStorageProcess::set(const Entry& entry, const UUID& uuid)
 {
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   }
 
   // We do a read first to make sure the version has not changed. This
@@ -112,7 +112,7 @@ Future<bool> LevelDBStorageProcess::set(const Entry& entry, const UUID& uuid)
   Try<Option<Entry> > option = read(entry.name());
 
   if (option.isError()) {
-    return Future<bool>::failed(option.error());
+    return Failure(option.error());
   }
 
   if (option.get().isSome()) {
@@ -128,7 +128,7 @@ Future<bool> LevelDBStorageProcess::set(const Entry& entry, const UUID& uuid)
   Try<bool> result = write(entry);
 
   if (result.isError()) {
-    return Future<bool>::failed(result.error());
+    return Failure(result.error());
   }
 
   return result.get();
@@ -138,7 +138,7 @@ Future<bool> LevelDBStorageProcess::set(const Entry& entry, const UUID& uuid)
 Future<bool> LevelDBStorageProcess::expunge(const Entry& entry)
 {
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   }
 
   // We do a read first to make sure the version has not changed. This
@@ -147,7 +147,7 @@ Future<bool> LevelDBStorageProcess::expunge(const Entry& entry)
   Try<Option<Entry> > option = read(entry.name());
 
   if (option.isError()) {
-    return Future<bool>::failed(option.error());
+    return Failure(option.error());
   }
 
   if (option.get().isNone()) {
@@ -169,7 +169,7 @@ Future<bool> LevelDBStorageProcess::expunge(const Entry& entry)
   leveldb::Status status = db->Delete(options, entry.name());
 
   if (!status.ok()) {
-    return Future<bool>::failed(status.ToString());
+    return Failure(status.ToString());
   }
 
   return true;

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/state/protobuf.hpp
----------------------------------------------------------------------
diff --git a/src/state/protobuf.hpp b/src/state/protobuf.hpp
index 5ee2880..d1c21c6 100644
--- a/src/state/protobuf.hpp
+++ b/src/state/protobuf.hpp
@@ -118,7 +118,7 @@ process::Future<Variable<T> > State::_fetch(
 {
   Try<T> t = messages::deserialize<T>(variable.value());
   if (t.isError()) {
-    return process::Future<Variable<T> >::failed(t.error());
+    return process::Failure(t.error());
   }
 
   return Variable<T>(variable, t.get());
@@ -132,7 +132,7 @@ process::Future<Option<Variable<T> > > State::store(
   Try<std::string> value = messages::serialize(variable.t);
 
   if (value.isError()) {
-    return process::Future<Option<Variable<T> > >::failed(value.error());
+    return process::Failure(value.error());
   }
 
   return state::State::store(variable.variable.mutate(value.get()))

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/state/zookeeper.cpp
----------------------------------------------------------------------
diff --git a/src/state/zookeeper.cpp b/src/state/zookeeper.cpp
index 6e6a01a..09b63d4 100644
--- a/src/state/zookeeper.cpp
+++ b/src/state/zookeeper.cpp
@@ -97,7 +97,7 @@ void ZooKeeperStorageProcess::initialize()
 Future<vector<string> > ZooKeeperStorageProcess::names()
 {
   if (error.isSome()) {
-    return Future<vector<string> >::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Names* names = new Names();
     pending.names.push(names);
@@ -111,7 +111,7 @@ Future<vector<string> > ZooKeeperStorageProcess::names()
     pending.names.push(names);
     return names->promise.future();
   } else if (result.isError()) {
-    return Future<vector<string> >::failed(result.error());
+    return Failure(result.error());
   }
 
   return result.get();
@@ -121,7 +121,7 @@ Future<vector<string> > ZooKeeperStorageProcess::names()
 Future<Option<Entry> > ZooKeeperStorageProcess::get(const string& name)
 {
   if (error.isSome()) {
-    return Future<Option<Entry> >::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Get* get = new Get(name);
     pending.gets.push(get);
@@ -135,7 +135,7 @@ Future<Option<Entry> > ZooKeeperStorageProcess::get(const string& name)
     pending.gets.push(get);
     return get->promise.future();
   } else if (result.isError()) {
-    return Future<Option<Entry> >::failed(result.error());
+    return Failure(result.error());
   }
 
   return result.get();
@@ -145,7 +145,7 @@ Future<Option<Entry> > ZooKeeperStorageProcess::get(const string& name)
 Future<bool> ZooKeeperStorageProcess::set(const Entry& entry, const UUID& uuid)
 {
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Set* set = new Set(entry, uuid);
     pending.sets.push(set);
@@ -159,7 +159,7 @@ Future<bool> ZooKeeperStorageProcess::set(const Entry& entry, const UUID& uuid)
     pending.sets.push(set);
     return set->promise.future();
   } else if (result.isError()) {
-    return Future<bool>::failed(result.error());
+    return Failure(result.error());
   }
 
   return result.get();
@@ -169,7 +169,7 @@ Future<bool> ZooKeeperStorageProcess::set(const Entry& entry, const UUID& uuid)
 Future<bool> ZooKeeperStorageProcess::expunge(const Entry& entry)
 {
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Expunge* expunge = new Expunge(entry);
     pending.expunges.push(expunge);
@@ -183,7 +183,7 @@ Future<bool> ZooKeeperStorageProcess::expunge(const Entry& entry)
     pending.expunges.push(expunge);
     return expunge->promise.future();
   } else if (result.isError()) {
-    return Future<bool>::failed(result.error());
+    return Failure(result.error());
   }
 
   return result.get();

http://git-wip-us.apache.org/repos/asf/mesos/blob/e427fae0/src/zookeeper/group.cpp
----------------------------------------------------------------------
diff --git a/src/zookeeper/group.cpp b/src/zookeeper/group.cpp
index db55151..5218286 100644
--- a/src/zookeeper/group.cpp
+++ b/src/zookeeper/group.cpp
@@ -117,7 +117,7 @@ void GroupProcess::initialize()
 Future<Group::Membership> GroupProcess::join(const string& data)
 {
   if (error.isSome()) {
-    return Future<Group::Membership>::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Join* join = new Join(data);
     pending.joins.push(join);
@@ -143,7 +143,7 @@ Future<Group::Membership> GroupProcess::join(const string& data)
     pending.joins.push(join);
     return join->promise.future();
   } else if (membership.isError()) {
-    return Future<Group::Membership>::failed(membership.error());
+    return Failure(membership.error());
   }
 
   return membership.get();
@@ -153,7 +153,7 @@ Future<Group::Membership> GroupProcess::join(const string& data)
 Future<bool> GroupProcess::cancel(const Group::Membership& membership)
 {
   if (error.isSome()) {
-    return Future<bool>::failed(error.get());
+    return Failure(error.get());
   } else if (owned.count(membership.id()) == 0) {
     // TODO(benh): Should this be an error? Right now a user can't
     // differentiate when 'false' means they can't cancel because it's
@@ -184,7 +184,7 @@ Future<bool> GroupProcess::cancel(const Group::Membership& membership)
     pending.cancels.push(cancel);
     return cancel->promise.future();
   } else if (cancellation.isError()) {
-    return Future<bool>::failed(cancellation.error());
+    return Failure(cancellation.error());
   }
 
   return cancellation.get();
@@ -194,7 +194,7 @@ Future<bool> GroupProcess::cancel(const Group::Membership& membership)
 Future<string> GroupProcess::data(const Group::Membership& membership)
 {
   if (error.isSome()) {
-    return Future<string>::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Data* data = new Data(membership);
     pending.datas.push(data);
@@ -212,7 +212,7 @@ Future<string> GroupProcess::data(const Group::Membership& membership)
     pending.datas.push(data);
     return data->promise.future();
   } else if (result.isError()) {
-    return Future<string>::failed(result.error());
+    return Failure(result.error());
   }
 
   return result.get();
@@ -223,7 +223,7 @@ Future<set<Group::Membership> > GroupProcess::watch(
     const set<Group::Membership>& expected)
 {
   if (error.isSome()) {
-    return Future<set<Group::Membership> >::failed(error.get());
+    return Failure(error.get());
   } else if (state != CONNECTED) {
     Watch* watch = new Watch(expected);
     pending.watches.push(watch);


[02/14] git commit: Refactored Owned and added a function Owned::share().

Posted by be...@apache.org.
Refactored Owned and added a function Owned::share().

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15731


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

Branch: refs/heads/master
Commit: 845ff1be9d0f6a67726659c143a2457799bbb3de
Parents: 6b13a6e
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:48:48 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:48:48 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/Makefile.am               |   2 +
 3rdparty/libprocess/include/process/owned.hpp | 166 +++++++++++++++++++++
 3rdparty/libprocess/src/tests/owned_tests.cpp |  80 ++++++++++
 3 files changed, 248 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/845ff1be/3rdparty/libprocess/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/Makefile.am b/3rdparty/libprocess/Makefile.am
index d348780..47e6d02 100644
--- a/3rdparty/libprocess/Makefile.am
+++ b/3rdparty/libprocess/Makefile.am
@@ -82,6 +82,7 @@ libprocess_la_SOURCES +=					\
   $(top_srcdir)/include/process/message.hpp			\
   $(top_srcdir)/include/process/mime.hpp			\
   $(top_srcdir)/include/process/once.hpp			\
+  $(top_srcdir)/include/process/owned.hpp			\
   $(top_srcdir)/include/process/pid.hpp				\
   $(top_srcdir)/include/process/process.hpp			\
   $(top_srcdir)/include/process/profiler.hpp			\
@@ -103,6 +104,7 @@ tests_SOURCES =							\
   src/tests/http_tests.cpp					\
   src/tests/io_tests.cpp					\
   src/tests/main.cpp						\
+  src/tests/owned_tests.cpp					\
   src/tests/process_tests.cpp					\
   src/tests/shared_tests.cpp					\
   src/tests/statistics_tests.cpp				\

http://git-wip-us.apache.org/repos/asf/mesos/blob/845ff1be/3rdparty/libprocess/include/process/owned.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/owned.hpp b/3rdparty/libprocess/include/process/owned.hpp
new file mode 100644
index 0000000..4a03ea4
--- /dev/null
+++ b/3rdparty/libprocess/include/process/owned.hpp
@@ -0,0 +1,166 @@
+#ifndef __PROCESS_OWNED_HPP__
+#define __PROCESS_OWNED_HPP__
+
+#include <glog/logging.h>
+
+#include <boost/shared_ptr.hpp>
+
+namespace process {
+
+// Forward declaration.
+template <typename T>
+class Shared;
+
+
+// Represents a uniquely owned pointer.
+//
+// TODO(bmahler): For now, Owned only provides shared_ptr semantics.
+// When we make the switch to C++11, we will change to provide
+// unique_ptr semantics. Consequently, each usage of Owned that
+// invoked a copy will have to be adjusted to use move semantics.
+template <typename T>
+class Owned
+{
+public:
+  Owned();
+  explicit Owned(T* t);
+
+  bool operator == (const Owned<T>& that) const;
+  bool operator < (const Owned<T>& that) const;
+
+  T& operator * () const;
+  T* operator -> () const;
+  T* get() const;
+
+  void reset();
+  void reset(T* t);
+  void swap(Owned<T>& that);
+
+  // Converts from an owned pointer to a shared pointer. This owned
+  // pointer will be reset after this function is invoked.
+  Shared<T> share();
+
+private:
+  struct Data
+  {
+    Data(T* t);
+    ~Data();
+
+    T* volatile t; // The pointer 't' is volatile.
+  };
+
+  boost::shared_ptr<Data> data;
+};
+
+
+template <typename T>
+Owned<T>::Owned() {}
+
+
+template <typename T>
+Owned<T>::Owned(T* t)
+{
+  if (t != NULL) {
+    data.reset(new Data(t));
+  }
+}
+
+
+template <typename T>
+bool Owned<T>::operator == (const Owned<T>& that) const
+{
+  return data == that.data;
+}
+
+
+template <typename T>
+bool Owned<T>::operator < (const Owned<T>& that) const
+{
+  return data < that.data;
+}
+
+
+template <typename T>
+T& Owned<T>::operator * () const
+{
+  return *CHECK_NOTNULL(get());
+}
+
+
+template <typename T>
+T* Owned<T>::operator -> () const
+{
+  return CHECK_NOTNULL(get());
+}
+
+
+template <typename T>
+T* Owned<T>::get() const
+{
+  if (data.get() == NULL) {
+    return NULL;
+  } else {
+    CHECK(data->t != NULL) << "This owned pointer has already been shared";
+
+    return data->t;
+  }
+}
+
+
+template <typename T>
+void Owned<T>::reset()
+{
+  data.reset();
+}
+
+
+template <typename T>
+void Owned<T>::reset(T* t)
+{
+  if (t == NULL) {
+    data.reset();
+  } else {
+    data.reset(new Data(t));
+  }
+}
+
+
+template <typename T>
+void Owned<T>::swap(Owned<T>& that)
+{
+  data.swap(that.data);
+}
+
+
+template <typename T>
+Shared<T> Owned<T>::share()
+{
+  if (data.get() == NULL) {
+    return Shared<T>(NULL);
+  }
+
+  // Atomically set the pointer 'data->t' to NULL.
+  T* t = __sync_fetch_and_and(&data->t, NULL);
+  CHECK(t != NULL) << "The ownership of this pointer has already been shared";
+
+  data.reset();
+  return Shared<T>(t);
+}
+
+
+template <typename T>
+Owned<T>::Data::Data(T* _t)
+  : t(CHECK_NOTNULL(_t)) {}
+
+
+template <typename T>
+Owned<T>::Data::~Data()
+{
+  if (t != NULL) {
+    delete t;
+  }
+}
+
+} // namespace process {
+
+#endif // __PROCESS_OWNED_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/845ff1be/3rdparty/libprocess/src/tests/owned_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/owned_tests.cpp b/3rdparty/libprocess/src/tests/owned_tests.cpp
new file mode 100644
index 0000000..234469b
--- /dev/null
+++ b/3rdparty/libprocess/src/tests/owned_tests.cpp
@@ -0,0 +1,80 @@
+#include <gmock/gmock.h>
+
+#include <process/gtest.hpp>
+#include <process/owned.hpp>
+#include <process/shared.hpp>
+
+using namespace process;
+
+class Foo
+{
+public:
+  int get() const { return value; }
+  void set(int _value) { value = _value; }
+
+private:
+  int value;
+};
+
+
+TEST(Owned, Access)
+{
+  Foo* foo = new Foo();
+  foo->set(42);
+
+  Owned<Foo> owned(foo);
+
+  EXPECT_EQ(42, owned->get());
+  EXPECT_EQ(42, (*owned).get());
+  EXPECT_EQ(42, owned.get()->get());
+
+  owned->set(10);
+
+  EXPECT_EQ(10, owned->get());
+  EXPECT_EQ(10, (*owned).get());
+  EXPECT_EQ(10, owned.get()->get());
+}
+
+
+TEST(Owned, Null)
+{
+  Owned<Foo> owned;
+  Owned<Foo> owned2(NULL);
+
+  EXPECT_TRUE(owned.get() == NULL);
+  EXPECT_TRUE(owned2.get() == NULL);
+}
+
+
+TEST(Owned, Share)
+{
+  Foo* foo = new Foo();
+  foo->set(42);
+
+  Owned<Foo> owned(foo);
+
+  EXPECT_EQ(42, owned->get());
+  EXPECT_EQ(42, (*owned).get());
+  EXPECT_EQ(42, owned.get()->get());
+
+  Shared<Foo> shared = owned.share();
+
+  EXPECT_TRUE(owned.get() == NULL);
+  EXPECT_TRUE(shared.unique());
+
+  EXPECT_EQ(42, shared->get());
+  EXPECT_EQ(42, (*shared).get());
+  EXPECT_EQ(42, shared.get()->get());
+
+  {
+    Shared<Foo> shared2(shared);
+
+    EXPECT_EQ(42, shared2->get());
+    EXPECT_EQ(42, (*shared2).get());
+    EXPECT_EQ(42, shared2.get()->get());
+    EXPECT_FALSE(shared.unique());
+    EXPECT_FALSE(shared2.unique());
+  }
+
+  EXPECT_TRUE(shared.unique());
+}


[08/14] git commit: Added 'Set' wrapper in addition to union and intersect operators.

Posted by be...@apache.org.
Added 'Set' wrapper in addition to union and intersect operators.

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


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

Branch: refs/heads/master
Commit: f6c4a02e9a744d93623a036ac183c77f6771ad07
Parents: e94ec75
Author: Benjamin Hindman <be...@gmail.com>
Authored: Tue Nov 26 19:59:40 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 23:12:15 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/Makefile.am  |  2 +
 .../3rdparty/stout/include/stout/hashset.hpp    | 12 ++--
 .../3rdparty/stout/include/stout/set.hpp        | 69 ++++++++++++++++++++
 .../3rdparty/stout/tests/set_tests.cpp          | 28 ++++++++
 4 files changed, 104 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f6c4a02e/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index 451e614..cc9a120 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -52,6 +52,7 @@ EXTRA_DIST =					\
   include/stout/proc.hpp			\
   include/stout/protobuf.hpp			\
   include/stout/result.hpp			\
+  include/stout/set.hpp				\
   include/stout/stopwatch.hpp			\
   include/stout/stringify.hpp			\
   include/stout/strings.hpp			\
@@ -79,6 +80,7 @@ EXTRA_DIST =					\
   tests/protobuf_tests.pb.cc			\
   tests/protobuf_tests.pb.h			\
   tests/protobuf_tests.proto			\
+  tests/set_tests.cpp				\
   tests/strings_tests.cpp			\
   tests/thread_tests.cpp			\
   tests/uuid_tests.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/f6c4a02e/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
index 78bed73..f1f2099 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/hashset.hpp
@@ -57,14 +57,12 @@ public:
 
 // Union operator.
 template <typename Elem>
-hashset<Elem> operator | (const hashset<Elem>& set1, const hashset<Elem>& set2)
+hashset<Elem> operator | (const hashset<Elem>& left, const hashset<Elem>& right)
 {
-  hashset<Elem> result = set1;
-
-  foreach (const Elem& elem, set2) {
-    result.insert(elem);
-  }
-
+  // Note, we're not using 'set_union' since it affords us no benefit
+  // in efficiency and is more complicated to use given we have sets.
+  hashset<Elem> result = left;
+  result.insert(right.begin(), right.end());
   return result;
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/f6c4a02e/3rdparty/libprocess/3rdparty/stout/include/stout/set.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/set.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/set.hpp
new file mode 100644
index 0000000..789eeb6
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/set.hpp
@@ -0,0 +1,69 @@
+#include <set>
+#include <vector>
+
+template <typename T>
+class Set : public std::set<T>
+{
+public:
+  Set() {}
+
+  Set(const T& t1)
+  {
+    insert(t1);
+  }
+
+  Set(const T& t1, const T& t2)
+  {
+    insert(t1);
+    insert(t2);
+  }
+
+  Set(const T& t1, const T& t2, const T& t3)
+  {
+    insert(t1);
+    insert(t2);
+    insert(t3);
+  }
+
+  Set(const T& t1, const T& t2, const T& t3, const T& t4)
+  {
+    insert(t1);
+    insert(t2);
+    insert(t3);
+    insert(t4);
+  }
+};
+
+
+template <typename T>
+std::set<T> operator | (const std::set<T>& left, const std::set<T>& right)
+{
+  // Note, we're not using 'set_union' since it affords us no benefit
+  // in efficiency and is more complicated to use given we have sets.
+  std::set<T> result = left;
+  result.insert(right.begin(), right.end());
+  return result;
+}
+
+
+template <typename T>
+std::set<T> operator + (const std::set<T>& left, const T& t)
+{
+  std::set<T> result = left;
+  result.insert(t);
+  return result;
+}
+
+
+template <typename T>
+std::set<T> operator & (const std::set<T>& left, const std::set<T>& right)
+{
+  std::set<T> result;
+  std::set_intersection(
+      left.begin(),
+      left.end(),
+      right.begin(),
+      right.end(),
+      std::inserter(result, result.begin()));
+  return result;
+}

http://git-wip-us.apache.org/repos/asf/mesos/blob/f6c4a02e/3rdparty/libprocess/3rdparty/stout/tests/set_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/set_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/set_tests.cpp
new file mode 100644
index 0000000..cdedacd
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/set_tests.cpp
@@ -0,0 +1,28 @@
+#include <gtest/gtest.h>
+
+#include <stout/set.hpp>
+
+TEST(Stout, Set)
+{
+  EXPECT_EQ(Set<int>(1, 2), Set<int>(1) | Set<int>(2));
+  EXPECT_EQ(Set<int>(1, 2), Set<int>(1, 2) | Set<int>(1));
+  EXPECT_EQ(Set<int>(1, 2), Set<int>(1) + 2);
+  EXPECT_EQ(Set<int>(1, 2), Set<int>(1, 2) + 2);
+  EXPECT_EQ(Set<int>(1, 2), Set<int>(1, 2, 3) & Set<int>(1, 2));
+  EXPECT_EQ(Set<int>(1, 2), Set<int>(1, 2) & Set<int>(1, 2));
+
+  Set<int> left;
+  left.insert(2);
+  left.insert(4);
+
+  Set<int> right;
+  right.insert(1);
+  right.insert(3);
+
+  EXPECT_EQ(Set<int>(1, 2, 3, 4), left | right);
+  EXPECT_EQ(Set<int>(), left & right);
+
+  std::set<int> s = left;
+
+  EXPECT_EQ(Set<int>(2, 4, 6), s + 6);
+}


[05/14] git commit: Updated references in libprocess to use the new Owned.

Posted by be...@apache.org.
Updated references in libprocess to use the new Owned.

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15838


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

Branch: refs/heads/master
Commit: d1194f69872766f683d23ea5658ccc0a976f0fae
Parents: 1e842bc
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:54:09 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:54:10 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/shared.hpp     |  7 +++++--
 3rdparty/libprocess/include/process/statistics.hpp |  2 +-
 3rdparty/libprocess/src/tests/shared_tests.cpp     |  1 +
 3rdparty/libprocess/src/tests/statistics_tests.cpp | 10 ++++++++--
 4 files changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d1194f69/3rdparty/libprocess/include/process/shared.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/shared.hpp b/3rdparty/libprocess/include/process/shared.hpp
index 475a18c..b1b6234 100644
--- a/3rdparty/libprocess/include/process/shared.hpp
+++ b/3rdparty/libprocess/include/process/shared.hpp
@@ -5,12 +5,15 @@
 
 #include <boost/shared_ptr.hpp>
 
-#include <stout/owned.hpp>
-
 #include <process/future.hpp>
 
 namespace process {
 
+// Forward declaration.
+template <typename T>
+class Owned;
+
+
 // Represents a shared pointer and therefore enforces 'const' access.
 template <typename T>
 class Shared

http://git-wip-us.apache.org/repos/asf/mesos/blob/d1194f69/3rdparty/libprocess/include/process/statistics.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/statistics.hpp b/3rdparty/libprocess/include/process/statistics.hpp
index fbae641..ce122a5 100644
--- a/3rdparty/libprocess/include/process/statistics.hpp
+++ b/3rdparty/libprocess/include/process/statistics.hpp
@@ -3,13 +3,13 @@
 
 #include <process/clock.hpp>
 #include <process/future.hpp>
+#include <process/owned.hpp>
 #include <process/time.hpp>
 
 #include <stout/duration.hpp>
 #include <stout/none.hpp>
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
-#include <stout/owned.hpp>
 
 namespace process {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/d1194f69/3rdparty/libprocess/src/tests/shared_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/shared_tests.cpp b/3rdparty/libprocess/src/tests/shared_tests.cpp
index d4fc031..1df67b4 100644
--- a/3rdparty/libprocess/src/tests/shared_tests.cpp
+++ b/3rdparty/libprocess/src/tests/shared_tests.cpp
@@ -1,6 +1,7 @@
 #include <gmock/gmock.h>
 
 #include <process/gtest.hpp>
+#include <process/owned.hpp>
 #include <process/shared.hpp>
 
 using namespace process;

http://git-wip-us.apache.org/repos/asf/mesos/blob/d1194f69/3rdparty/libprocess/src/tests/statistics_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/statistics_tests.cpp b/3rdparty/libprocess/src/tests/statistics_tests.cpp
index 8695f45..e6c9a1b 100644
--- a/3rdparty/libprocess/src/tests/statistics_tests.cpp
+++ b/3rdparty/libprocess/src/tests/statistics_tests.cpp
@@ -80,7 +80,10 @@ TEST(Statistics, meter) {
 
   // Set up a meter, and ensure it captures the expected time rate.
   Future<Try<Nothing> > meter =
-    statistics.meter("test", "statistic", new meters::TimeRate("metered"));
+    statistics.meter(
+        "test",
+        "statistic",
+        Owned<meters::Meter>(new meters::TimeRate("metered")));
 
   AWAIT_ASSERT_READY(meter);
 
@@ -130,7 +133,10 @@ TEST(Statistics, archive)
   // Create a meter and a statistic for archival.
   // Set up a meter, and ensure it captures the expected time rate.
   Future<Try<Nothing> > meter =
-    statistics.meter("test", "statistic", new meters::TimeRate("metered"));
+    statistics.meter(
+        "test",
+        "statistic",
+        Owned<meters::Meter>(new meters::TimeRate("metered")));
 
   AWAIT_ASSERT_READY(meter);
 


[03/14] git commit: Renamed Shared::upgrade() to Shared::own().

Posted by be...@apache.org.
Renamed Shared::upgrade() to Shared::own().

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15739


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

Branch: refs/heads/master
Commit: 6e251cc7a6f32aab464ec725f56fbf201451460e
Parents: 845ff1b
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:50:26 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:50:26 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/shared.hpp | 24 ++++++++++-----------
 3rdparty/libprocess/src/tests/shared_tests.cpp | 12 +++++------
 2 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6e251cc7/3rdparty/libprocess/include/process/shared.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/shared.hpp b/3rdparty/libprocess/include/process/shared.hpp
index e0c7991..475a18c 100644
--- a/3rdparty/libprocess/include/process/shared.hpp
+++ b/3rdparty/libprocess/include/process/shared.hpp
@@ -33,12 +33,12 @@ public:
   void reset(T* t);
   void swap(Shared<T>& that);
 
-  // Upgrading from a shared pointer to an owned pointer. This shared
-  // pointer will be reset after this function is invoked. If two
-  // shared pointers pointing to the same object both want to be
-  // upgraded, only one of them may succeed and the other one will get
-  // a failed future.
-  Future<Owned<T> > upgrade();
+  // Transfers ownership of the pointer by waiting for exclusive
+  // access (i.e., no other Shared instances). This shared pointer
+  // will be reset after this function is invoked. If multiple shared
+  // pointers pointing to the same object all want to be upgraded,
+  // only one of them may succeed and the rest will get failures.
+  Future<Owned<T> > own();
 
 private:
   struct Data
@@ -47,7 +47,7 @@ private:
     ~Data();
 
     T* t;
-    volatile bool upgraded;
+    volatile bool owned;
     Promise<Owned<T> > promise;
   };
 
@@ -140,7 +140,7 @@ void Shared<T>::swap(Shared<T>& that)
 
 
 template <typename T>
-Future<Owned<T> > Shared<T>::upgrade()
+Future<Owned<T> > Shared<T>::own()
 {
   // If two threads simultaneously access this object and at least one
   // of them is a write, the behavior is undefined. This is similar to
@@ -150,8 +150,8 @@ Future<Owned<T> > Shared<T>::upgrade()
     return Owned<T>(NULL);
   }
 
-  if (!__sync_bool_compare_and_swap(&data->upgraded, false, true)) {
-    return Future<Owned<T> >::failed("An upgrade is already being performed");
+  if (!__sync_bool_compare_and_swap(&data->owned, false, true)) {
+    return Future<Owned<T> >::failed("Ownership has already been transferred");
   }
 
   Future<Owned<T> > future = data->promise.future();
@@ -162,13 +162,13 @@ Future<Owned<T> > Shared<T>::upgrade()
 
 template <typename T>
 Shared<T>::Data::Data(T* _t)
-  : t(CHECK_NOTNULL(_t)), upgraded(false) {}
+  : t(CHECK_NOTNULL(_t)), owned(false) {}
 
 
 template <typename T>
 Shared<T>::Data::~Data()
 {
-  if (upgraded) {
+  if (owned) {
     promise.set(Owned<T>(t));
   } else {
     delete t;

http://git-wip-us.apache.org/repos/asf/mesos/blob/6e251cc7/3rdparty/libprocess/src/tests/shared_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/shared_tests.cpp b/3rdparty/libprocess/src/tests/shared_tests.cpp
index 860a9aa..d4fc031 100644
--- a/3rdparty/libprocess/src/tests/shared_tests.cpp
+++ b/3rdparty/libprocess/src/tests/shared_tests.cpp
@@ -63,7 +63,7 @@ TEST(Shared, Reset)
 }
 
 
-TEST(Shared, Upgrade)
+TEST(Shared, Own)
 {
   Foo* foo = new Foo();
   foo->set(42);
@@ -86,15 +86,15 @@ TEST(Shared, Upgrade)
     EXPECT_FALSE(shared2.unique());
     EXPECT_FALSE(shared.unique());
 
-    future = shared2.upgrade();
+    future = shared2.own();
 
-    // A shared pointer will be reset after it called upgrade.
+    // A shared pointer will be reset after it called 'own'.
     EXPECT_TRUE(shared2.get() == NULL);
 
-    // Only one upgrade is allowed.
-    AWAIT_FAILED(shared.upgrade());
+    // Do not allow 'own' to be called twice.
+    AWAIT_FAILED(shared.own());
 
-    // Upgrade is not done yet as 'shared' is still holding the reference.
+    // Not "owned" yet as 'shared' is still holding the reference.
     EXPECT_TRUE(future.isPending());
   }
 


[07/14] git commit: Rewrote ZooKeeper watcher initialization using process::Once.

Posted by be...@apache.org.
Rewrote ZooKeeper watcher initialization using process::Once.

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15850


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

Branch: refs/heads/master
Commit: e94ec75b5fe2704689609c8388b7e87efaff7510
Parents: 92bbaf8
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:59:37 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:59:37 2013 -0800

----------------------------------------------------------------------
 src/zookeeper/zookeeper.cpp | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e94ec75b/src/zookeeper/zookeeper.cpp
----------------------------------------------------------------------
diff --git a/src/zookeeper/zookeeper.cpp b/src/zookeeper/zookeeper.cpp
index ca4a61d..cc8a7ca 100644
--- a/src/zookeeper/zookeeper.cpp
+++ b/src/zookeeper/zookeeper.cpp
@@ -24,6 +24,7 @@
 #include <boost/tuple/tuple.hpp>
 
 #include <process/dispatch.hpp>
+#include <process/once.hpp>
 #include <process/process.hpp>
 
 #include <stout/duration.hpp>
@@ -129,20 +130,15 @@ private:
 Watcher::Watcher()
 {
   // Confirm we have created the WatcherProcessManager.
-  static volatile bool initialized = false;
-  static volatile bool initializing = true;
+  static process::Once* initialize = new process::Once();
 
   // Confirm everything is initialized.
-  if (!initialized) {
-    if (__sync_bool_compare_and_swap(&initialized, false, true)) {
-      manager = new WatcherProcessManager();
-      process::spawn(manager);
-      initializing = false;
-    }
+  if (!initialize->once()) {
+    manager = new WatcherProcessManager();
+    process::spawn(manager);
+    initialize->done();
   }
 
-  while (initializing);
-
   WatcherProcess* process =
     process::dispatch(manager->self(),
                       &WatcherProcessManager::create,


[04/14] git commit: Removed Owned from stout.

Posted by be...@apache.org.
Removed Owned from stout.

From: Jie Yu <yu...@gmail.com>
Review: https://reviews.apache.org/r/15837


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

Branch: refs/heads/master
Commit: 1e842bc0d21a3879c7d9d5684f2faa0a1a9aa39c
Parents: 6e251cc
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Dec 1 15:53:26 2013 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sun Dec 1 15:53:26 2013 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/Makefile.am  |  1 -
 .../3rdparty/stout/include/stout/owned.hpp      | 20 --------------------
 2 files changed, 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1e842bc0/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index 47e8dbb..451e614 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -47,7 +47,6 @@ EXTRA_DIST =					\
   include/stout/os/signals.hpp			\
   include/stout/os/pstree.hpp			\
   include/stout/os/sysctl.hpp			\
-  include/stout/owned.hpp			\
   include/stout/path.hpp			\
   include/stout/preprocessor.hpp		\
   include/stout/proc.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/1e842bc0/3rdparty/libprocess/3rdparty/stout/include/stout/owned.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/owned.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/owned.hpp
deleted file mode 100644
index 3433f50..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/owned.hpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __STOUT_OWNED_HPP__
-#define __STOUT_OWNED_HPP__
-
-#include <boost/shared_ptr.hpp>
-
-// Represents a uniquely owned pointer.
-//
-// TODO(bmahler): For now, Owned only provides shared_ptr semantics.
-// When we make the switch to C++11, we will change to provide
-// unique_ptr semantics. Consequently, each usage of Owned that
-// invoked a copy will have to be adjusted to use move semantics.
-template <typename T>
-class Owned : public boost::shared_ptr<T>
-{
-public:
-  Owned(T* t) : boost::shared_ptr<T>(t) {}
-};
-
-
-#endif // __STOUT_OWNED_HPP__