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 2012/09/10 00:02:46 UTC
svn commit: r1382589 - in /incubator/mesos/trunk: src/exec/ src/java/jni/
src/linux/ src/log/ src/logging/ src/master/ src/mesos/ src/sched/
src/slave/ src/tests/ src/zookeeper/ third_party/libprocess/include/process/
third_party/libprocess/include/sto...
Author: benh
Date: Sun Sep 9 22:02:45 2012
New Revision: 1382589
URL: http://svn.apache.org/viewvc?rev=1382589&view=rev
Log:
Updated most uses of 'double' to represent a duration in seconds to
use 'Duration' instead (https://reviews.apache.org/r/6815).
Modified:
incubator/mesos/trunk/src/exec/exec.cpp
incubator/mesos/trunk/src/java/jni/org_apache_mesos_Log.cpp
incubator/mesos/trunk/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp
incubator/mesos/trunk/src/linux/cgroups.cpp
incubator/mesos/trunk/src/linux/cgroups.hpp
incubator/mesos/trunk/src/log/coordinator.cpp
incubator/mesos/trunk/src/log/log.hpp
incubator/mesos/trunk/src/log/replica.cpp
incubator/mesos/trunk/src/logging/logging.cpp
incubator/mesos/trunk/src/master/constants.hpp
incubator/mesos/trunk/src/master/frameworks_manager.cpp
incubator/mesos/trunk/src/master/hierarchical_allocator_process.hpp
incubator/mesos/trunk/src/master/master.cpp
incubator/mesos/trunk/src/mesos/main.cpp
incubator/mesos/trunk/src/sched/sched.cpp
incubator/mesos/trunk/src/slave/constants.hpp
incubator/mesos/trunk/src/slave/flags.hpp
incubator/mesos/trunk/src/slave/gc.cpp
incubator/mesos/trunk/src/slave/gc.hpp
incubator/mesos/trunk/src/slave/reaper.cpp
incubator/mesos/trunk/src/slave/slave.cpp
incubator/mesos/trunk/src/tests/cgroups_tests.cpp
incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp
incubator/mesos/trunk/src/tests/log_tests.cpp
incubator/mesos/trunk/src/tests/master_tests.cpp
incubator/mesos/trunk/src/zookeeper/group.cpp
incubator/mesos/trunk/third_party/libprocess/include/process/delay.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/latch.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/timeout.hpp
incubator/mesos/trunk/third_party/libprocess/include/process/timer.hpp
incubator/mesos/trunk/third_party/libprocess/include/stout/duration.hpp
incubator/mesos/trunk/third_party/libprocess/src/latch.cpp
incubator/mesos/trunk/third_party/libprocess/src/process.cpp
incubator/mesos/trunk/third_party/libprocess/src/tests.cpp
Modified: incubator/mesos/trunk/src/exec/exec.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/exec/exec.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/exec/exec.cpp (original)
+++ incubator/mesos/trunk/src/exec/exec.cpp Sun Sep 9 22:02:45 2012
@@ -61,7 +61,9 @@ protected:
virtual void initialize()
{
LOG(INFO) << "Scheduling shutdown of the executor";
- delay(slave::EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS, self(), &Self::kill);
+ // TODO(benh): Pass the shutdown timeout with ExecutorRegistered
+ // since it might have gotten configured on the command line.
+ delay(slave::EXECUTOR_SHUTDOWN_TIMEOUT, self(), &Self::kill);
}
void kill()
Modified: incubator/mesos/trunk/src/java/jni/org_apache_mesos_Log.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/java/jni/org_apache_mesos_Log.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/java/jni/org_apache_mesos_Log.cpp (original)
+++ incubator/mesos/trunk/src/java/jni/org_apache_mesos_Log.cpp Sun Sep 9 22:02:45 2012
@@ -18,6 +18,8 @@
#include <jni.h>
+#include <stout/duration.hpp>
+
#include "log/log.hpp"
#include "construct.hpp"
@@ -145,7 +147,7 @@ JNIEXPORT jobject JNICALL Java_org_apach
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Timeout timeout(jseconds);
Result<std::list<Log::Entry> > entries = reader->read(from, to, timeout);
@@ -295,7 +297,7 @@ JNIEXPORT jobject JNICALL Java_org_apach
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Timeout timeout(jseconds);
Result<Log::Position> position = writer->append(data, timeout);
@@ -348,7 +350,7 @@ JNIEXPORT jobject JNICALL Java_org_apach
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Timeout timeout(jseconds);
Result<Log::Position> position = writer->truncate(to, timeout);
@@ -402,7 +404,7 @@ JNIEXPORT void JNICALL Java_org_apache_m
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Timeout timeout(jseconds);
int retries = jretries;
Modified: incubator/mesos/trunk/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp (original)
+++ incubator/mesos/trunk/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp Sun Sep 9 22:02:45 2012
@@ -259,9 +259,9 @@ JNIEXPORT jobject JNICALL Java_org_apach
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Seconds seconds(jseconds);
- if (future->await(timeout.secs())) {
+ if (future->await(seconds)) {
if (future->isFailed()) {
clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
@@ -448,9 +448,9 @@ JNIEXPORT jobject JNICALL Java_org_apach
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Seconds seconds(jseconds);
- if (future->await(timeout.secs())) {
+ if (future->await(seconds)) {
if (future->isFailed()) {
clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
@@ -632,9 +632,9 @@ JNIEXPORT jobject JNICALL Java_org_apach
jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
- Seconds timeout(jseconds);
+ Seconds seconds(jseconds);
- if (future->await(timeout.secs())) {
+ if (future->await(seconds)) {
if (future->isFailed()) {
clazz = env->FindClass("java/util/concurrent/ExecutionException");
env->ThrowNew(clazz, future->failure().c_str());
Modified: incubator/mesos/trunk/src/linux/cgroups.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/cgroups.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/cgroups.cpp (original)
+++ incubator/mesos/trunk/src/linux/cgroups.cpp Sun Sep 9 22:02:45 2012
@@ -36,6 +36,7 @@
#include <process/io.hpp>
#include <process/process.hpp>
+#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include <stout/lambda.hpp>
#include <stout/option.hpp>
@@ -991,7 +992,7 @@ public:
Freezer(const std::string& _hierarchy,
const std::string& _cgroup,
const std::string& _action,
- const seconds& _interval)
+ const Duration& _interval)
: hierarchy(_hierarchy),
cgroup(_cgroup),
action(_action),
@@ -1009,8 +1010,8 @@ protected:
promise.future().onDiscarded(lambda::bind(
static_cast<void (*)(const UPID&, bool)>(terminate), self(), true));
- if (interval.value < 0) {
- promise.fail("Invalid interval: " + stringify(interval.value));
+ if (interval < Seconds(0)) {
+ promise.fail("Invalid interval: " + stringify(interval));
terminate(self());
return;
}
@@ -1109,7 +1110,7 @@ private:
}
// Not done yet, keep watching.
- delay(interval.value, self(), &Freezer::watchFrozen);
+ delay(interval, self(), &Freezer::watchFrozen);
} else {
LOG(FATAL) << "Unexpected state: " << strings::trim(state.get());
}
@@ -1131,7 +1132,7 @@ private:
terminate(self());
} else if (strings::trim(state.get()) == "FROZEN") {
// Not done yet, keep watching.
- delay(interval.value, self(), &Freezer::watchThawed);
+ delay(interval, self(), &Freezer::watchThawed);
} else {
LOG(FATAL) << "Unexpected state: " << strings::trim(state.get());
}
@@ -1140,7 +1141,7 @@ private:
std::string hierarchy;
std::string cgroup;
std::string action;
- const seconds interval;
+ const Duration interval;
Promise<bool> promise;
};
@@ -1150,7 +1151,7 @@ private:
Future<bool> freezeCgroup(const std::string& hierarchy,
const std::string& cgroup,
- const seconds& interval)
+ const Duration& interval)
{
Try<bool> check = checkControl(hierarchy, cgroup, "freezer.state");
if (check.isError()) {
@@ -1178,7 +1179,7 @@ Future<bool> freezeCgroup(const std::str
Future<bool> thawCgroup(const std::string& hierarchy,
const std::string& cgroup,
- const seconds& interval)
+ const Duration& interval)
{
Try<bool> check = checkControl(hierarchy, cgroup, "freezer.state");
if (check.isError()) {
@@ -1212,7 +1213,7 @@ class EmptyWatcher: public Process<Empty
public:
EmptyWatcher(const std::string& _hierarchy,
const std::string& _cgroup,
- const seconds& _interval)
+ const Duration& _interval)
: hierarchy(_hierarchy),
cgroup(_cgroup),
interval(_interval) {}
@@ -1229,8 +1230,8 @@ protected:
promise.future().onDiscarded(lambda::bind(
static_cast<void (*)(const UPID&, bool)>(terminate), self(), true));
- if (interval.value < 0) {
- promise.fail("Invalid interval: " + stringify(interval.value));
+ if (interval < Seconds(0)) {
+ promise.fail("Invalid interval: " + stringify(interval));
terminate(self());
return;
}
@@ -1255,13 +1256,13 @@ private:
terminate(self());
} else {
// Re-check needed.
- delay(interval.value, self(), &EmptyWatcher::check);
+ delay(interval, self(), &EmptyWatcher::check);
}
}
std::string hierarchy;
std::string cgroup;
- const seconds interval;
+ const Duration interval;
Promise<bool> promise;
};
@@ -1272,7 +1273,7 @@ class TasksKiller : public Process<Tasks
public:
TasksKiller(const std::string& _hierarchy,
const std::string& _cgroup,
- const seconds& _interval)
+ const Duration& _interval)
: hierarchy(_hierarchy),
cgroup(_cgroup),
interval(_interval) {}
@@ -1289,8 +1290,8 @@ protected:
promise.future().onDiscarded(lambda::bind(
static_cast<void (*)(const UPID&, bool)>(terminate), self(), true));
- if (interval.value < 0) {
- promise.fail("Invalid interval: " + stringify(interval.value));
+ if (interval < Seconds(0)) {
+ promise.fail("Invalid interval: " + stringify(interval));
terminate(self());
return;
}
@@ -1377,7 +1378,7 @@ private:
std::string hierarchy;
std::string cgroup;
- const seconds interval;
+ const Duration interval;
Promise<bool> promise;
Future<bool> finish;
};
@@ -1387,7 +1388,7 @@ private:
Future<bool> killTasks(const std::string& hierarchy,
const std::string& cgroup,
- const seconds& interval)
+ const Duration& interval)
{
Try<bool> freezerCheck = checkHierarchy(hierarchy, "freezer");
if (freezerCheck.isError()) {
@@ -1415,7 +1416,7 @@ class Destroyer : public Process<Destroy
public:
Destroyer(const std::string& _hierarchy,
const std::vector<std::string>& _cgroups,
- const seconds& _interval)
+ const Duration& _interval)
: hierarchy(_hierarchy),
cgroups(_cgroups),
interval(_interval) {}
@@ -1432,8 +1433,8 @@ protected:
promise.future().onDiscarded(lambda::bind(
static_cast<void (*)(const UPID&, bool)>(terminate), self(), true));
- if (interval.value < 0) {
- promise.fail("Invalid interval: " + stringify(interval.value));
+ if (interval < Seconds(0)) {
+ promise.fail("Invalid interval: " + stringify(interval));
terminate(self());
return;
}
@@ -1487,7 +1488,7 @@ private:
std::string hierarchy;
std::vector<std::string> cgroups;
- const seconds interval;
+ const Duration interval;
Promise<bool> promise;
// The killer processes used to atomically kill tasks in each cgroup.
@@ -1499,7 +1500,7 @@ private:
Future<bool> destroyCgroup(const std::string& hierarchy,
const std::string& cgroup,
- const seconds& interval)
+ const Duration& interval)
{
Try<bool> cgroupCheck = checkCgroup(hierarchy, cgroup);
if (cgroupCheck.isError()) {
Modified: incubator/mesos/trunk/src/linux/cgroups.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/cgroups.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/cgroups.hpp (original)
+++ incubator/mesos/trunk/src/linux/cgroups.hpp Sun Sep 9 22:02:45 2012
@@ -261,7 +261,7 @@ process::Future<uint64_t> listenEvent(co
// the given cgroup is not valid, or the given cgroup has already been frozen.
// @param hierarchy Path to the hierarchy root.
// @param cgroup Path to the cgroup relative to the hierarchy root.
-// @param interval The time interval in seconds between two state check
+// @param interval The time interval between two state check
// requests (default: 0.1 seconds).
// @return A future which will become ready when all processes are frozen.
// Error if some unexpected happens.
@@ -276,7 +276,7 @@ process::Future<bool> freezeCgroup(const
// allow users to cancel the operation.
// @param hierarchy Path to the hierarchy root.
// @param cgroup Path to the cgroup relative to the hierarchy root.
-// @param interval The time interval in seconds between two state check
+// @param interval The time interval between two state check
// requests (default: 0.1 seconds).
// @return A future which will become ready when all processes are thawed.
// Error if some unexpected happens.
@@ -295,7 +295,7 @@ process::Future<bool> thawCgroup(const s
// available or not properly attached to the given hierarchy.
// @param hierarchy Path to the hierarchy root.
// @param cgroup Path to the cgroup relative to the hierarchy root.
-// @param interval The time interval in seconds between two state check
+// @param interval The time interval between two state check
// requests (default: 0.1 seconds).
// @return A future which will become ready when the operation is done.
// Error if some unexpected happens.
@@ -313,7 +313,7 @@ process::Future<bool> killTasks(const st
// process. The future will become ready when the destroy operation finishes.
// @param hierarchy Path to the hierarchy root.
// @param cgroup Path to the cgroup relative to the hierarchy root.
-// @param interval The time interval in seconds between two state check
+// @param interval The time interval between two state check
// requests (default: 0.1 seconds).
// @return A future which will become ready when the operation is done.
// Error if some unexpected happens.
Modified: incubator/mesos/trunk/src/log/coordinator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/log/coordinator.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/log/coordinator.cpp (original)
+++ incubator/mesos/trunk/src/log/coordinator.cpp Sun Sep 9 22:02:45 2012
@@ -21,6 +21,7 @@
#include <process/dispatch.hpp>
#include <process/future.hpp>
+#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include "log/coordinator.hpp"
@@ -99,7 +100,7 @@ Result<uint64_t> Coordinator::elect(cons
}
futures.erase(future.get());
}
- } while (timeout.remaining() > 0);
+ } while (timeout.remaining() > Seconds(0));
// Discard the remaining futures.
discard(futures);
@@ -295,7 +296,7 @@ Result<uint64_t> Coordinator::write(
}
futures.erase(future.get());
}
- } while (timeout.remaining() > 0);
+ } while (timeout.remaining() > Seconds(0));
// Timed out ... discard remaining futures.
discard(futures);
@@ -416,7 +417,7 @@ Result<Action> Coordinator::fill(uint64_
}
futures.erase(future.get());
}
- } while (timeout.remaining() > 0);
+ } while (timeout.remaining() > Seconds(0));
// Discard the remaining futures.
discard(futures);
Modified: incubator/mesos/trunk/src/log/log.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/log/log.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/log/log.hpp (original)
+++ incubator/mesos/trunk/src/log/log.hpp Sun Sep 9 22:02:45 2012
@@ -26,7 +26,6 @@
#include <process/process.hpp>
#include <process/timeout.hpp>
-#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include <stout/result.hpp>
#include <stout/try.hpp>
@@ -123,7 +122,7 @@ public:
// those positions are invalid, in which case returns an error.
Result<std::list<Entry> > read(const Position& from,
const Position& to,
- const Duration& timeout);
+ const Timeout& timeout);
// Returns the beginning position of the log from the perspective
// of the local replica (which may be out of date if the log has
@@ -147,20 +146,20 @@ public:
// one writer (local and remote) is valid at a time. A writer
// becomes invalid if any operation returns an error, and a new
// writer must be created in order perform subsequent operations.
- Writer(Log* log, const Duration& timeout, int retries = 3);
+ Writer(Log* log, const Timeout& timeout, int retries = 3);
~Writer();
// Attempts to append the specified data to the log. A none result
// means the operation timed out, otherwise the new ending
// position of the log is returned or an error. Upon error a new
// Writer must be created.
- Result<Position> append(const std::string& data, const Duration& timeout);
+ Result<Position> append(const std::string& data, const Timeout& timeout);
// Attempts to truncate the log up to but not including the
// specificed position. A none result means the operation timed
// out, otherwise the new ending position of the log is returned
// or an error. Upon error a new Writer must be created.
- Result<Position> truncate(const Position& to, const Duration& timeout);
+ Result<Position> truncate(const Position& to, const Timeout& timeout);
private:
Option<std::string> error;
@@ -194,7 +193,7 @@ public:
Log(int _quorum,
const std::string& path,
const std::string& servers,
- const Seconds& timeout,
+ const Duration& timeout,
const std::string& znode,
const Option<zookeeper::Authentication>& auth
= Option<zookeeper::Authentication>::none())
@@ -277,12 +276,12 @@ Log::Reader::~Reader() {}
Result<std::list<Log::Entry> > Log::Reader::read(
const Log::Position& from,
const Log::Position& to,
- const Duration& timeout)
+ const Timeout& timeout)
{
process::Future<std::list<Action> > actions =
replica->read(from.value, to.value);
- if (!actions.await(timeout.secs())) {
+ if (!actions.await(timeout.remaining())) {
return Result<std::list<Log::Entry> >::none();
} else if (actions.isFailed()) {
return Result<std::list<Log::Entry> >::error(actions.failure());
@@ -337,12 +336,12 @@ Log::Position Log::Reader::ending()
}
-Log::Writer::Writer(Log* log, const Duration& timeout, int retries)
+Log::Writer::Writer(Log* log, const Timeout& timeout, int retries)
: error(Option<std::string>::none()),
coordinator(log->quorum, log->replica, log->network)
{
do {
- Result<uint64_t> result = coordinator.elect(Timeout(timeout.secs()));
+ Result<uint64_t> result = coordinator.elect(timeout);
if (result.isNone()) {
retries--;
} else if (result.isSome()) {
@@ -363,7 +362,7 @@ Log::Writer::~Writer()
Result<Log::Position> Log::Writer::append(
const std::string& data,
- const Duration& timeout)
+ const Timeout& timeout)
{
if (error.isSome()) {
return Result<Log::Position>::error(error.get());
@@ -371,7 +370,7 @@ Result<Log::Position> Log::Writer::appen
LOG(INFO) << "Attempting to append " << data.size() << " bytes to the log";
- Result<uint64_t> result = coordinator.append(data, Timeout(timeout.secs()));
+ Result<uint64_t> result = coordinator.append(data, timeout);
if (result.isError()) {
error = result.error();
@@ -388,7 +387,7 @@ Result<Log::Position> Log::Writer::appen
Result<Log::Position> Log::Writer::truncate(
const Log::Position& to,
- const Duration& timeout)
+ const Timeout& timeout)
{
if (error.isSome()) {
return Result<Log::Position>::error(error.get());
@@ -396,8 +395,7 @@ Result<Log::Position> Log::Writer::trunc
LOG(INFO) << "Attempting to truncate the log to " << to.value;
- Result<uint64_t> result =
- coordinator.truncate(to.value, Timeout(timeout.secs()));
+ Result<uint64_t> result = coordinator.truncate(to.value, timeout);
if (result.isError()) {
error = result.error();
Modified: incubator/mesos/trunk/src/log/replica.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/log/replica.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/log/replica.cpp (original)
+++ incubator/mesos/trunk/src/log/replica.cpp Sun Sep 9 22:02:45 2012
@@ -221,16 +221,14 @@ Try<State> LevelDBStorage::recover(const
return Try<State>::error(status.ToString());
}
- LOG(INFO) << "Opened db in "
- << timer.elapsed().millis() << " milliseconds";
+ LOG(INFO) << "Opened db in " << timer.elapsed();
timer.start(); // Restart the timer.
// TODO(benh): Conditionally compact to avoid long recovery times?
db->CompactRange(NULL, NULL);
- LOG(INFO) << "Compacted db in "
- << timer.elapsed().millis() << " milliseconds";
+ LOG(INFO) << "Compacted db in " << timer.elapsed();
State state;
state.coordinator = 0;
@@ -246,15 +244,13 @@ Try<State> LevelDBStorage::recover(const
leveldb::Iterator* iterator = db->NewIterator(leveldb::ReadOptions());
- LOG(INFO) << "Created db iterator in " << timer.elapsed().millis()
- << " milliseconds";
+ LOG(INFO) << "Created db iterator in " << timer.elapsed();
timer.start(); // Restart the timer.
iterator->SeekToFirst();
- LOG(INFO) << "Seeked to beginning of db in "
- << timer.elapsed().millis() << " milliseconds";
+ LOG(INFO) << "Seeked to beginning of db in " << timer.elapsed();
timer.start(); // Restart the timer.
@@ -305,8 +301,8 @@ Try<State> LevelDBStorage::recover(const
iterator->Next();
}
- LOG(INFO) << "Iterated through " << keys << " keys in the db in "
- << timer.elapsed().millis() << " milliseconds";
+ LOG(INFO) << "Iterated through " << keys
+ << " keys in the db in " << timer.elapsed();
// Determine the first position still in leveldb so during a
// truncation we can attempt to delete all positions from the first
@@ -350,8 +346,7 @@ Try<void> LevelDBStorage::persist(const
}
LOG(INFO) << "Persisting promise (" << value.size()
- << " bytes) to leveldb took "
- << timer.elapsed().millis() << " milliseconds";
+ << " bytes) to leveldb took " << timer.elapsed();
return Try<void>::some();
}
@@ -382,8 +377,7 @@ Try<void> LevelDBStorage::persist(const
}
LOG(INFO) << "Persisting action (" << value.size()
- << " bytes) to leveldb took "
- << timer.elapsed().millis() << " milliseconds";
+ << " bytes) to leveldb took " << timer.elapsed();
// Delete positions if a truncate action has been *learned*. Note
// that we do this in a best-effort fashion (i.e., we ignore any
@@ -430,8 +424,8 @@ Try<void> LevelDBStorage::persist(const
} else {
first = action.truncate().to(); // Save the new first position!
- LOG(INFO) << "Deleting ~" << index << " keys from leveldb took "
- << timer.elapsed().millis() << " milliseconds";
+ LOG(INFO) << "Deleting ~" << index
+ << " keys from leveldb took " << timer.elapsed();
}
}
}
@@ -467,8 +461,7 @@ Try<Action> LevelDBStorage::read(uint64_
return Try<Action>::error("Bad record");
}
- LOG(INFO) << "Reading position from leveldb took "
- << timer.elapsed().millis() << " milliseconds";
+ LOG(INFO) << "Reading position from leveldb took " << timer.elapsed();
return record.action();
}
Modified: incubator/mesos/trunk/src/logging/logging.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/logging/logging.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/logging/logging.cpp (original)
+++ incubator/mesos/trunk/src/logging/logging.cpp Sun Sep 9 22:02:45 2012
@@ -139,7 +139,7 @@ private:
void revert()
{
- if (timeout.remaining() == 0.0) {
+ if (timeout.remaining() == Seconds(0)) {
set(original);
}
}
Modified: incubator/mesos/trunk/src/master/constants.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/constants.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/constants.hpp (original)
+++ incubator/mesos/trunk/src/master/constants.hpp Sun Sep 9 22:02:45 2012
@@ -19,6 +19,8 @@
#ifndef __MASTER_CONSTANTS_HPP__
#define __MASTER_CONSTANTS_HPP__
+#include <stout/duration.hpp>
+
namespace mesos {
namespace internal {
namespace master {
@@ -41,8 +43,8 @@ const uint32_t MAX_CPUS = 1000 * 1000;
// Maximum amount of memory / machine.
const uint32_t MAX_MEM = 1024 * 1024 * Megabyte;
-// Acceptable timeout for slave PING.
-const double SLAVE_PING_TIMEOUT = 15.0;
+// Amount of time within which a slave PING should be received.
+const Duration SLAVE_PING_TIMEOUT = Seconds(15.0);
// Maximum number of ping timeouts until slave is considered failed.
const uint32_t MAX_SLAVE_PING_TIMEOUTS = 5;
@@ -56,7 +58,7 @@ const uint32_t MAX_COMPLETED_FRAMEWORKS
const uint32_t MAX_COMPLETED_TASKS_PER_FRAMEWORK = 500;
// Time interval to check for updated watchers list.
-const uint32_t WATCH_TIMEOUT = 5;
+const Duration WHITELIST_WATCH_INTERVAL = Seconds(5.0);
} // namespace mesos {
} // namespace internal {
Modified: incubator/mesos/trunk/src/master/frameworks_manager.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/frameworks_manager.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/frameworks_manager.cpp (original)
+++ incubator/mesos/trunk/src/master/frameworks_manager.cpp Sun Sep 9 22:02:45 2012
@@ -113,14 +113,13 @@ Future<Result<bool> > FrameworksManager:
return Result<bool>::error("Error removing non-existing framework.");
}
- LOG(INFO) << "Expiring framework " << id
- << " in " << timeout.secs() << " seconds";
+ LOG(INFO) << "Expiring framework " << id << " in " << timeout;
// Set the option to contain the firing time of the message.
infos[id].second = Option<double>::some(Clock::now() + timeout.secs());
Promise<Result<bool> >* promise = new Promise<Result<bool> >();
- delay(timeout.secs(), self(), &FrameworksManager::expire, id, promise);
+ delay(timeout, self(), &FrameworksManager::expire, id, promise);
return promise->future();
}
Modified: incubator/mesos/trunk/src/master/hierarchical_allocator_process.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/hierarchical_allocator_process.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/hierarchical_allocator_process.hpp (original)
+++ incubator/mesos/trunk/src/master/hierarchical_allocator_process.hpp Sun Sep 9 22:02:45 2012
@@ -173,7 +173,7 @@ public:
{
return slaveId == this->slaveId &&
resources <= this->resources && // Refused resources are superset.
- timeout.remaining() > 0.0;
+ timeout.remaining() > Seconds(0);
}
const SlaveID slaveId;
@@ -192,7 +192,7 @@ void HierarchicalAllocatorProcess<UserSo
initialized = true;
userSorter = new UserSorter();
- delay(flags.batch_seconds, self(),
+ delay(Seconds(flags.batch_seconds), self(),
&HierarchicalAllocatorProcess<UserSorter, FrameworkSorter>::batch);
}
@@ -432,17 +432,17 @@ void HierarchicalAllocatorProcess<UserSo
allocatable[slaveId] += resources;
// Create a refused resources filter.
- double timeout = filters.isSome()
- ? filters.get().refuse_seconds()
- : Filters().refuse_seconds();
+ Seconds timeout(filters.isSome()
+ ? filters.get().refuse_seconds()
+ : Filters().refuse_seconds());
- if (timeout != 0.0) {
+ if (timeout != Seconds(0)) {
LOG(INFO) << "Framework " << frameworkId
<< " filtered slave " << slaveId
- << " for " << timeout << " seconds\n";
+ << " for " << timeout;
// Create a new filter and delay it's expiration.
- mesos::internal::master::Filter* filter = new RefusedFilter(slaveId, resources, timeout);
+ mesos::internal::master::Filter* filter = new RefusedFilter(slaveId, resources, timeout.secs());
this->filters.put(frameworkId, filter);
delay(timeout, self(),
@@ -519,7 +519,7 @@ void HierarchicalAllocatorProcess<UserSo
{
CHECK(initialized);
allocate();
- delay(flags.batch_seconds, self(),
+ delay(Seconds(flags.batch_seconds), self(),
&HierarchicalAllocatorProcess<UserSorter, FrameworkSorter>::batch);
}
@@ -536,7 +536,7 @@ void HierarchicalAllocatorProcess<UserSo
LOG(INFO) << "Performed allocation for "
<< slaves.size() << " slaves in "
- << timer.elapsed().millis() << " milliseconds";
+ << timer.elapsed();
}
@@ -555,7 +555,7 @@ void HierarchicalAllocatorProcess<UserSo
LOG(INFO) << "Performed allocation for slave "
<< slaveId << " in "
- << timer.elapsed().millis() << " milliseconds";
+ << timer.elapsed();
}
Modified: incubator/mesos/trunk/src/master/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.cpp (original)
+++ incubator/mesos/trunk/src/master/master.cpp Sun Sep 9 22:02:45 2012
@@ -109,7 +109,7 @@ protected:
// Check again.
lastWhitelist = whitelist;
- delay(WATCH_TIMEOUT, self(), &WhitelistWatcher::watch);
+ delay(WHITELIST_WATCH_INTERVAL, self(), &WhitelistWatcher::watch);
}
private:
@@ -484,10 +484,10 @@ void Master::exited(const UPID& pid)
// Tell the allocator to stop allocating resources to this framework.
dispatch(allocator, &AllocatorProcess::frameworkDeactivated, framework->id);
- double failoverTimeout = framework->info.failover_timeout();
+ Seconds failoverTimeout(framework->info.failover_timeout());
LOG(INFO) << "Giving framework " << framework->id << " "
- << failoverTimeout << " seconds to failover";
+ << failoverTimeout << " to failover";
// Delay dispatching a message to ourselves for the timeout.
delay(failoverTimeout, self(),
Modified: incubator/mesos/trunk/src/mesos/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/mesos/main.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/mesos/main.cpp (original)
+++ incubator/mesos/trunk/src/mesos/main.cpp Sun Sep 9 22:02:45 2012
@@ -96,7 +96,7 @@ int main(int argc, char** argv)
Future<SubmitSchedulerResponse> future = submit(master, request);
- future.await(5.0);
+ future.await(Seconds(5.0));
if (future.isReady()) {
if (future.get().okay()) {
Modified: incubator/mesos/trunk/src/sched/sched.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/sched/sched.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/sched/sched.cpp (original)
+++ incubator/mesos/trunk/src/sched/sched.cpp Sun Sep 9 22:02:45 2012
@@ -38,6 +38,7 @@
#include <process/process.hpp>
#include <process/protobuf.hpp>
+#include <stout/duration.hpp>
#include <stout/fatal.hpp>
#include <stout/hashmap.hpp>
#include <stout/os.hpp>
@@ -263,7 +264,7 @@ protected:
send(master, message);
}
- delay(1.0, self(), &SchedulerProcess::doReliableRegistration);
+ delay(Seconds(1.0), self(), &SchedulerProcess::doReliableRegistration);
}
void resourceOffers(const vector<Offer>& offers,
Modified: incubator/mesos/trunk/src/slave/constants.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/constants.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/constants.hpp (original)
+++ incubator/mesos/trunk/src/slave/constants.hpp Sun Sep 9 22:02:45 2012
@@ -19,14 +19,16 @@
#ifndef __SLAVE_CONSTANTS_HPP__
#define __SLAVE_CONSTANTS_HPP__
+#include <stout/duration.hpp>
+
namespace mesos {
namespace internal {
namespace slave {
// TODO(benh): Also make configuration options be constants.
-const double EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS = 5.0;
-const double STATUS_UPDATE_RETRY_INTERVAL_SECONDS = 10.0;
+const Duration EXECUTOR_SHUTDOWN_TIMEOUT = Seconds(5.0);
+const Duration STATUS_UPDATE_RETRY_INTERVAL = Seconds(10.0);
const double GC_TIMEOUT_HOURS = 7.0 * 24.0; // 1 week.
} // namespace slave {
Modified: incubator/mesos/trunk/src/slave/flags.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/flags.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/flags.hpp (original)
+++ incubator/mesos/trunk/src/slave/flags.hpp Sun Sep 9 22:02:45 2012
@@ -89,7 +89,7 @@ public:
"executor_shutdown_timeout_seconds",
"Amount of time (in seconds) to wait for\n"
"an executor to shut down",
- EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS);
+ EXECUTOR_SHUTDOWN_TIMEOUT.secs());
add(&Flags::gc_timeout_hours,
"gc_timeout_hours",
Modified: incubator/mesos/trunk/src/slave/gc.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/gc.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/gc.cpp (original)
+++ incubator/mesos/trunk/src/slave/gc.cpp Sun Sep 9 22:02:45 2012
@@ -59,7 +59,7 @@ Future<bool> GarbageCollectorProcess::sc
Promise<bool>* promise = new Promise<bool>();
- delay(d.secs(), self(), &Self::remove, path, promise);
+ delay(d, self(), &Self::remove, path, promise);
return promise->future();
}
Modified: incubator/mesos/trunk/src/slave/gc.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/gc.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/gc.hpp (original)
+++ incubator/mesos/trunk/src/slave/gc.hpp Sun Sep 9 22:02:45 2012
@@ -46,7 +46,7 @@ public:
~GarbageCollector();
// Schedules the specified path for removal after the specified
- // amount of time has elapsed and returns true if the file was
+ // duration of time has elapsed and returns true if the file was
// successfully removed and false if the file didn't exist (or an
// error, e.g., permission denied).
process::Future<bool> schedule(const Duration& d, const std::string& path);
Modified: incubator/mesos/trunk/src/slave/reaper.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/reaper.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/reaper.cpp (original)
+++ incubator/mesos/trunk/src/slave/reaper.cpp Sun Sep 9 22:02:45 2012
@@ -49,7 +49,7 @@ void Reaper::addProcessExitedListener(
void Reaper::initialize()
{
- delay(1.0, self(), &Reaper::reap);
+ delay(Seconds(1.0), self(), &Reaper::reap);
}
@@ -67,7 +67,7 @@ void Reaper::reap()
}
}
- delay(1.0, self(), &Reaper::reap); // Reap forever!
+ delay(Seconds(1.0), self(), &Reaper::reap); // Reap forever!
}
} // namespace slave {
Modified: incubator/mesos/trunk/src/slave/slave.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/slave.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/slave.cpp (original)
+++ incubator/mesos/trunk/src/slave/slave.cpp Sun Sep 9 22:02:45 2012
@@ -439,7 +439,7 @@ void Slave::doReliableRegistration()
}
// Re-try registration if necessary.
- delay(1.0, self(), &Slave::doReliableRegistration);
+ delay(Seconds(1.0), self(), &Slave::doReliableRegistration);
}
@@ -1008,7 +1008,7 @@ void Slave::statusUpdate(const StatusUpd
UUID uuid = UUID::fromBytes(update.uuid());
// Send us a message to try and resend after some delay.
- delay(STATUS_UPDATE_RETRY_INTERVAL_SECONDS,
+ delay(STATUS_UPDATE_RETRY_INTERVAL,
self(), &Slave::statusUpdateTimeout,
framework->id, uuid);
@@ -1084,7 +1084,7 @@ void Slave::statusUpdateTimeout(
send(master, message);
// Send us a message to try and resend after some delay.
- delay(STATUS_UPDATE_RETRY_INTERVAL_SECONDS,
+ delay(STATUS_UPDATE_RETRY_INTERVAL,
self(), &Slave::statusUpdateTimeout,
framework->id, uuid);
}
@@ -1455,7 +1455,7 @@ void Slave::shutdownExecutor(Framework*
executor->shutdown = true;
// Prepare for sending a kill if the executor doesn't comply.
- delay(flags.executor_shutdown_timeout_seconds,
+ delay(Seconds(flags.executor_shutdown_timeout_seconds),
self(),
&Slave::shutdownExecutorTimeout,
framework->id, executor->id, executor->uuid);
Modified: incubator/mesos/trunk/src/tests/cgroups_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/cgroups_tests.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/cgroups_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/cgroups_tests.cpp Sun Sep 9 22:02:45 2012
@@ -427,7 +427,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_ListenE
if (pid) {
// In parent process.
- future.await(5.0); // Timeout in 5 seconds.
+ future.await(Seconds(5.0));
EXPECT_TRUE(future.isReady());
@@ -480,13 +480,13 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_Freezer
// Freeze the "/prof" cgroup.
Future<bool> freeze = cgroups::freezeCgroup(hierarchy, "/prof");
- freeze.await(5.0);
+ freeze.await(Seconds(5.0));
ASSERT_TRUE(freeze.isReady());
EXPECT_EQ(true, freeze.get());
// Thaw the "/prof" cgroup.
Future<bool> thaw = cgroups::thawCgroup(hierarchy, "/prof");
- thaw.await(5.0);
+ thaw.await(Seconds(5.0));
ASSERT_TRUE(thaw.isReady());
EXPECT_EQ(true, thaw.get());
@@ -544,7 +544,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_KillTas
::close(pipes[0]);
Future<bool> future = cgroups::killTasks(hierarchy, "/prof");
- future.await(5.0);
+ future.await(Seconds(5.0));
ASSERT_TRUE(future.isReady());
EXPECT_TRUE(future.get());
@@ -580,7 +580,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_KillTas
TEST_F(CgroupsTest, ROOT_CGROUPS_DestroyCgroup)
{
Future<bool> future = cgroups::destroyCgroup(hierarchy, "/stu/under");
- future.await(5.0);
+ future.await(Seconds(5.0));
ASSERT_TRUE(future.isReady());
EXPECT_TRUE(future.get());
@@ -603,7 +603,7 @@ TEST_F(CgroupsTest, ROOT_CGROUPS_Destroy
::close(pipes[0]);
Future<bool> future = cgroups::destroyCgroup(hierarchy, "/");
- future.await(5.0);
+ future.await(Seconds(5.0));
ASSERT_TRUE(future.isReady());
EXPECT_TRUE(future.get());
Modified: incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/fault_tolerance_tests.cpp Sun Sep 9 22:02:45 2012
@@ -44,7 +44,7 @@ using mesos::internal::master::Master;
using mesos::internal::slave::ProcessBasedIsolationModule;
using mesos::internal::slave::Slave;
-using mesos::internal::slave::STATUS_UPDATE_RETRY_INTERVAL_SECONDS;
+using mesos::internal::slave::STATUS_UPDATE_RETRY_INTERVAL;
using process::Clock;
using process::PID;
@@ -177,11 +177,11 @@ TEST(FaultToleranceTest, SlavePartitione
// Now advance through the PINGs.
do {
uint32_t count = pings;
- Clock::advance(master::SLAVE_PING_TIMEOUT);
+ Clock::advance(master::SLAVE_PING_TIMEOUT.secs());
WAIT_UNTIL(pings == count + 1);
} while (pings < master::MAX_SLAVE_PING_TIMEOUTS);
- Clock::advance(master::SLAVE_PING_TIMEOUT);
+ Clock::advance(master::SLAVE_PING_TIMEOUT.secs());
WAIT_UNTIL(slaveLostCall);
@@ -602,7 +602,7 @@ TEST(FaultToleranceTest, SchedulerFailov
WAIT_UNTIL(registeredCall);
- Clock::advance(STATUS_UPDATE_RETRY_INTERVAL_SECONDS);
+ Clock::advance(STATUS_UPDATE_RETRY_INTERVAL.secs());
WAIT_UNTIL(statusUpdateCall);
Modified: incubator/mesos/trunk/src/tests/log_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/log_tests.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/log_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/log_tests.cpp Sun Sep 9 22:02:45 2012
@@ -65,7 +65,7 @@ TEST(ReplicaTest, Promise)
future = protocol::promise(replica.pid(), request);
- future.await(2.0);
+ future.await(Seconds(2.0));
ASSERT_TRUE(future.isReady());
response = future.get();
@@ -79,7 +79,7 @@ TEST(ReplicaTest, Promise)
future = protocol::promise(replica.pid(), request);
- future.await(2.0);
+ future.await(Seconds(2.0));
ASSERT_TRUE(future.isReady());
response = future.get();
@@ -92,7 +92,7 @@ TEST(ReplicaTest, Promise)
future = protocol::promise(replica.pid(), request);
- future.await(2.0);
+ future.await(Seconds(2.0));
ASSERT_TRUE(future.isReady());
response = future.get();
@@ -122,7 +122,7 @@ TEST(ReplicaTest, Append)
Future<PromiseResponse> future1 =
protocol::promise(replica.pid(), request1);
- future1.await(2.0);
+ future1.await(Seconds(2.0));
ASSERT_TRUE(future1.isReady());
PromiseResponse response1 = future1.get();
@@ -141,7 +141,7 @@ TEST(ReplicaTest, Append)
Future<WriteResponse> future2 =
protocol::write(replica.pid(), request2);
- future2.await(2.0);
+ future2.await(Seconds(2.0));
ASSERT_TRUE(future2.isReady());
WriteResponse response2 = future2.get();
@@ -150,7 +150,7 @@ TEST(ReplicaTest, Append)
EXPECT_EQ(1u, response2.position());
Future<std::list<Action> > actions = replica.read(1, 1);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
@@ -187,7 +187,7 @@ TEST(ReplicaTest, Recover)
Future<PromiseResponse> future1 =
protocol::promise(replica1.pid(), request1);
- future1.await(2.0);
+ future1.await(Seconds(2.0));
ASSERT_TRUE(future1.isReady());
PromiseResponse response1 = future1.get();
@@ -206,7 +206,7 @@ TEST(ReplicaTest, Recover)
Future<WriteResponse> future2 =
protocol::write(replica1.pid(), request2);
- future2.await(2.0);
+ future2.await(Seconds(2.0));
ASSERT_TRUE(future2.isReady());
WriteResponse response2 = future2.get();
@@ -215,7 +215,7 @@ TEST(ReplicaTest, Recover)
EXPECT_EQ(1u, response2.position());
Future<std::list<Action> > actions1 = replica1.read(1, 1);
- ASSERT_TRUE(actions1.await(2.0));
+ ASSERT_TRUE(actions1.await(Seconds(2.0)));
ASSERT_TRUE(actions1.isReady());
ASSERT_EQ(1u, actions1.get().size());
@@ -237,7 +237,7 @@ TEST(ReplicaTest, Recover)
Replica replica2(path);
Future<std::list<Action> > actions2 = replica2.read(1, 1);
- ASSERT_TRUE(actions2.await(2.0));
+ ASSERT_TRUE(actions2.await(Seconds(2.0)));
ASSERT_TRUE(actions2.isReady());
ASSERT_EQ(1u, actions2.get().size());
@@ -286,7 +286,7 @@ TEST(CoordinatorTest, Elect)
{
Future<std::list<Action> > actions = replica1.read(0, 0);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
EXPECT_EQ(0u, actions.get().front().position());
@@ -334,7 +334,7 @@ TEST(CoordinatorTest, AppendRead)
{
Future<std::list<Action> > actions = replica1.read(position, position);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
EXPECT_EQ(position, actions.get().front().position());
@@ -384,7 +384,7 @@ TEST(CoordinatorTest, AppendReadError)
{
position += 1;
Future<std::list<Action> > actions = replica1.read(position, position);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isFailed());
EXPECT_EQ("Bad read range (past end of log)", actions.failure());
}
@@ -517,7 +517,7 @@ TEST(CoordinatorTest, Failover)
{
Future<std::list<Action> > actions = replica2.read(position, position);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
EXPECT_EQ(position, actions.get().front().position());
@@ -592,7 +592,7 @@ TEST(CoordinatorTest, Demoted)
{
Future<std::list<Action> > actions = replica2.read(position, position);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
EXPECT_EQ(position, actions.get().front().position());
@@ -660,7 +660,7 @@ TEST(CoordinatorTest, Fill)
{
Future<std::list<Action> > actions = replica3.read(position, position);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
EXPECT_EQ(position, actions.get().front().position());
@@ -738,7 +738,7 @@ TEST(CoordinatorTest, NotLearnedFill)
{
Future<std::list<Action> > actions = replica3.read(position, position);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
ASSERT_EQ(1u, actions.get().size());
EXPECT_EQ(position, actions.get().front().position());
@@ -788,7 +788,7 @@ TEST(CoordinatorTest, MultipleAppends)
{
Future<std::list<Action> > actions = replica1.read(1, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(10u, actions.get().size());
foreach (const Action& action, actions.get()) {
@@ -864,7 +864,7 @@ TEST(CoordinatorTest, MultipleAppendsNot
{
Future<std::list<Action> > actions = replica3.read(1, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(10u, actions.get().size());
foreach (const Action& action, actions.get()) {
@@ -921,14 +921,14 @@ TEST(CoordinatorTest, Truncate)
{
Future<std::list<Action> > actions = replica1.read(6, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isFailed());
EXPECT_EQ("Bad read range (truncated position)", actions.failure());
}
{
Future<std::list<Action> > actions = replica1.read(7, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(4u, actions.get().size());
foreach (const Action& action, actions.get()) {
@@ -1010,14 +1010,14 @@ TEST(CoordinatorTest, TruncateNotLearned
{
Future<std::list<Action> > actions = replica3.read(6, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isFailed());
EXPECT_EQ("Bad read range (truncated position)", actions.failure());
}
{
Future<std::list<Action> > actions = replica3.read(7, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(4u, actions.get().size());
foreach (const Action& action, actions.get()) {
@@ -1093,14 +1093,14 @@ TEST(CoordinatorTest, TruncateLearnedFil
{
Future<std::list<Action> > actions = replica3.read(6, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isFailed());
EXPECT_EQ("Bad read range (truncated position)", actions.failure());
}
{
Future<std::list<Action> > actions = replica3.read(7, 10);
- ASSERT_TRUE(actions.await(2.0));
+ ASSERT_TRUE(actions.await(Seconds(2.0)));
ASSERT_TRUE(actions.isReady());
EXPECT_EQ(4u, actions.get().size());
foreach (const Action& action, actions.get()) {
@@ -1131,16 +1131,16 @@ TEST(LogTest, WriteRead)
Log log(2, path2, pids);
- Log::Writer writer(&log, Seconds(1.0));
+ Log::Writer writer(&log, Timeout(1.0));
- Result<Log::Position> position = writer.append("hello world", Seconds(1.0));
+ Result<Log::Position> position = writer.append("hello world", Timeout(1.0));
ASSERT_TRUE(position.isSome());
Log::Reader reader(&log);
Result<std::list<Log::Entry> > entries =
- reader.read(position.get(), position.get(), Seconds(1.0));
+ reader.read(position.get(), position.get(), Timeout(1.0));
ASSERT_TRUE(entries.isSome());
ASSERT_EQ(1u, entries.get().size());
@@ -1167,9 +1167,9 @@ TEST(LogTest, Position)
Log log(2, path2, pids);
- Log::Writer writer(&log, Seconds(1.0));
+ Log::Writer writer(&log, Timeout(1.0));
- Result<Log::Position> position = writer.append("hello world", Seconds(1.0));
+ Result<Log::Position> position = writer.append("hello world", Timeout(1.0));
ASSERT_TRUE(position.isSome());
Modified: incubator/mesos/trunk/src/tests/master_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/master_tests.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/master_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/master_tests.cpp Sun Sep 9 22:02:45 2012
@@ -1020,7 +1020,7 @@ TEST_F(FrameworksManagerTestFixture, Add
Future<Result<map<FrameworkID, FrameworkInfo> > > future =
process::dispatch(manager, &FrameworksManager::list);
- ASSERT_TRUE(future.await(2.0));
+ ASSERT_TRUE(future.await(Seconds(2.0)));
EXPECT_TRUE(future.get().get().empty());
// Add a dummy framework.
@@ -1035,14 +1035,14 @@ TEST_F(FrameworksManagerTestFixture, Add
Future<Result<bool> > future2 =
process::dispatch(manager, &FrameworksManager::add, id, info);
- ASSERT_TRUE(future2.await(2.0));
+ ASSERT_TRUE(future2.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
// Check if framework manager returns the added framework.
Future<Result<map<FrameworkID, FrameworkInfo> > > future3 =
process::dispatch(manager, &FrameworksManager::list);
- ASSERT_TRUE(future3.await(2.0));
+ ASSERT_TRUE(future3.await(Seconds(2.0)));
map<FrameworkID, FrameworkInfo> result = future3.get().get();
@@ -1054,7 +1054,7 @@ TEST_F(FrameworksManagerTestFixture, Add
Future<Result<bool> > future4 =
process::dispatch(manager, &FrameworksManager::exists, id);
- ASSERT_TRUE(future4.await(2.0));
+ ASSERT_TRUE(future4.await(Seconds(2.0)));
EXPECT_TRUE(future4.get().get());
}
@@ -1070,7 +1070,7 @@ TEST_F(FrameworksManagerTestFixture, Rem
Future<Result<bool> > future1 =
process::dispatch(manager, &FrameworksManager::remove, id, Seconds(0));
- ASSERT_TRUE(future1.await(2.0));
+ ASSERT_TRUE(future1.await(Seconds(2.0)));
EXPECT_TRUE(future1.get().isError());
// Remove an existing framework.
@@ -1087,7 +1087,7 @@ TEST_F(FrameworksManagerTestFixture, Rem
Future<Result<bool> > future2 =
process::dispatch(manager, &FrameworksManager::add, id2, info2);
- ASSERT_TRUE(future2.await(2.0));
+ ASSERT_TRUE(future2.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
// Now remove the added framework.
@@ -1096,14 +1096,14 @@ TEST_F(FrameworksManagerTestFixture, Rem
Clock::update(Clock::now(manager) + 1.0);
- ASSERT_TRUE(future3.await(2.0));
+ ASSERT_TRUE(future3.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
// Now check if the removed framework exists...it shouldn't.
Future<Result<bool> > future4 =
process::dispatch(manager, &FrameworksManager::exists, id2);
- ASSERT_TRUE(future4.await(2.0));
+ ASSERT_TRUE(future4.await(Seconds(2.0)));
EXPECT_FALSE(future4.get().get());
Clock::resume();
@@ -1119,7 +1119,7 @@ TEST_F(FrameworksManagerTestFixture, Res
Future<Result<bool> > future1 =
process::dispatch(manager, &FrameworksManager::resurrect, id);
- ASSERT_TRUE(future1.await(2.0));
+ ASSERT_TRUE(future1.await(Seconds(2.0)));
EXPECT_FALSE(future1.get().get());
// Resurrect an existent framework that is NOT being removed.
@@ -1135,13 +1135,13 @@ TEST_F(FrameworksManagerTestFixture, Res
Future<Result<bool> > future2 =
process::dispatch(manager, &FrameworksManager::add, id2, info2);
- ASSERT_TRUE(future2.await(2.0));
+ ASSERT_TRUE(future2.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
Future<Result<bool> > future3 =
process::dispatch(manager, &FrameworksManager::resurrect, id2);
- ASSERT_TRUE(future3.await(2.0));
+ ASSERT_TRUE(future3.await(Seconds(2.0)));
EXPECT_TRUE(future3.get().get());
}
@@ -1175,12 +1175,12 @@ TEST_F(FrameworksManagerTestFixture, Res
Future<Result<bool> > future2 =
process::dispatch(manager, &FrameworksManager::resurrect, id);
- ASSERT_TRUE(future2.await(2.0));
+ ASSERT_TRUE(future2.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
Clock::update(Clock::now(manager) + 2.0);
- ASSERT_TRUE(future1.await(2.0));
+ ASSERT_TRUE(future1.await(Seconds(2.0)));
EXPECT_FALSE(future1.get().get());
Clock::resume();
@@ -1217,17 +1217,17 @@ TEST_F(FrameworksManagerTestFixture, Res
Future<Result<bool> > future3 =
process::dispatch(manager, &FrameworksManager::remove, id, Seconds(1.0));
- ASSERT_TRUE(future2.await(2.0));
+ ASSERT_TRUE(future2.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
Clock::update(Clock::now(manager) + 1.0);
- ASSERT_TRUE(future3.await(2.0));
+ ASSERT_TRUE(future3.await(Seconds(2.0)));
EXPECT_TRUE(future3.get().get());
Clock::update(Clock::now(manager) + 2.0);
- ASSERT_TRUE(future1.await(2.0));
+ ASSERT_TRUE(future1.await(Seconds(2.0)));
EXPECT_FALSE(future1.get().get());
Clock::resume();
@@ -1263,7 +1263,7 @@ TEST(FrameworksManagerTest, CacheFailure
Future<Result<map<FrameworkID, FrameworkInfo> > > future1 =
process::dispatch(manager, &FrameworksManager::list);
- ASSERT_TRUE(future1.await(2.0));
+ ASSERT_TRUE(future1.await(Seconds(2.0)));
ASSERT_TRUE(future1.get().isError());
EXPECT_EQ(future1.get().error(), "Error caching framework infos.");
@@ -1279,14 +1279,14 @@ TEST(FrameworksManagerTest, CacheFailure
Future<Result<bool> > future2 =
process::dispatch(manager, &FrameworksManager::add, id, info);
- ASSERT_TRUE(future2.await(2.0));
+ ASSERT_TRUE(future2.await(Seconds(2.0)));
EXPECT_TRUE(future2.get().get());
// Remove framework should fail due to caching failure.
Future<Result<bool> > future3 =
process::dispatch(manager, &FrameworksManager::remove, id, Seconds(0));
- ASSERT_TRUE(future3.await(2.0));
+ ASSERT_TRUE(future3.await(Seconds(2.0)));
ASSERT_TRUE(future3.get().isError());
EXPECT_EQ(future3.get().error(), "Error caching framework infos.");
Modified: incubator/mesos/trunk/src/zookeeper/group.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/zookeeper/group.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/src/zookeeper/group.cpp (original)
+++ incubator/mesos/trunk/src/zookeeper/group.cpp Sun Sep 9 22:02:45 2012
@@ -34,7 +34,8 @@ using std::vector;
namespace zookeeper {
-const double RETRY_SECONDS = 2.0; // Time to wait after retryable errors.
+// Time to wait after retryable errors.
+const Duration RETRY_INTERVAL = Seconds(2.0);
class GroupProcess : public Process<GroupProcess>
@@ -83,7 +84,7 @@ private:
// that it is not specific to any particular operation, but rather
// attempts to perform all pending operations (including caching
// memberships if necessary).
- void retry(double seconds);
+ void retry(const Duration& duration);
// Fails all pending operations.
void abort();
@@ -235,7 +236,7 @@ Future<Group::Membership> GroupProcess::
if (membership.isNone()) { // Try again later.
if (!retrying) {
- delay(RETRY_SECONDS, self(), &GroupProcess::retry, RETRY_SECONDS);
+ delay(RETRY_INTERVAL, self(), &GroupProcess::retry, RETRY_INTERVAL);
retrying = true;
}
Join* join = new Join(data);
@@ -276,7 +277,7 @@ Future<bool> GroupProcess::cancel(const
if (cancellation.isNone()) { // Try again later.
if (!retrying) {
- delay(RETRY_SECONDS, self(), &GroupProcess::retry, RETRY_SECONDS);
+ delay(RETRY_INTERVAL, self(), &GroupProcess::retry, RETRY_INTERVAL);
retrying = true;
}
Cancel* cancel = new Cancel(membership);
@@ -344,7 +345,7 @@ Future<set<Group::Membership> > GroupPro
if (memberships.isNone()) { // Try again later.
if (!retrying) {
- delay(RETRY_SECONDS, self(), &GroupProcess::retry, RETRY_SECONDS);
+ delay(RETRY_INTERVAL, self(), &GroupProcess::retry, RETRY_INTERVAL);
retrying = true;
}
Watch* watch = new Watch(expected);
@@ -506,7 +507,7 @@ void GroupProcess::updated(const string&
if (memberships.isNone()) { // Something changed so we must try again later.
if (!retrying) {
- delay(RETRY_SECONDS, self(), &GroupProcess::retry, RETRY_SECONDS);
+ delay(RETRY_INTERVAL, self(), &GroupProcess::retry, RETRY_INTERVAL);
retrying = true;
}
} else {
@@ -812,14 +813,14 @@ bool GroupProcess::sync()
}
-void GroupProcess::retry(double seconds)
+void GroupProcess::retry(const Duration& duration)
{
if (error.isSome() || state != CONNECTED) {
retrying = false; // Stop retrying, we'll sync at reconnect (if no error).
} else if (error.isNone() && state == CONNECTED) {
bool synced = sync(); // Might get another retryable error.
if (!synced && error.isNone()) {
- seconds = std::min(seconds * 2.0, 60.0); // Backoff.
+ Seconds seconds(std::min(duration.secs() * 2.0, 60.0)); // Backoff.
delay(seconds, self(), &GroupProcess::retry, seconds);
} else {
retrying = false;
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/delay.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/delay.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/delay.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/delay.hpp Sun Sep 9 22:02:45 2012
@@ -6,6 +6,8 @@
#include <process/dispatch.hpp>
#include <process/timer.hpp>
+#include <stout/duration.hpp>
+
namespace process {
// The 'delay' mechanism enables you to delay a dispatch to a process
@@ -14,7 +16,7 @@ namespace process {
// executing concurrently).
template <typename T>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const PID<T>& pid,
void (T::*method)())
{
@@ -31,30 +33,30 @@ Timer delay(double secs,
std::tr1::function<void(void)> dispatch =
std::tr1::bind(internal::dispatch, pid, dispatcher);
- return timers::create(secs, dispatch);
+ return Timer::create(duration, dispatch);
}
template <typename T>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>& process,
void (T::*method)())
{
- return delay(secs, process.self(), method);
+ return delay(duration, process.self(), method);
}
template <typename T>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>* process,
void (T::*method)())
{
- return delay(secs, process->self(), method);
+ return delay(duration, process->self(), method);
}
template <typename T, typename P1, typename A1>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const PID<T>& pid,
void (T::*method)(P1),
A1 a1)
@@ -72,34 +74,34 @@ Timer delay(double secs,
std::tr1::function<void(void)> dispatch =
std::tr1::bind(internal::dispatch, pid, dispatcher);
- return timers::create(secs, dispatch);
+ return Timer::create(duration, dispatch);
}
template <typename T, typename P1, typename A1>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>& process,
void (T::*method)(P1),
A1 a1)
{
- return delay(secs, process.self(), method, a1);
+ return delay(duration, process.self(), method, a1);
}
template <typename T, typename P1, typename A1>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>* process,
void (T::*method)(P1),
A1 a1)
{
- return delay(secs, process->self(), method, a1);
+ return delay(duration, process->self(), method, a1);
}
template <typename T,
typename P1, typename P2,
typename A1, typename A2>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const PID<T>& pid,
void (T::*method)(P1, P2),
A1 a1, A2 a2)
@@ -117,38 +119,38 @@ Timer delay(double secs,
std::tr1::function<void(void)> dispatch =
std::tr1::bind(internal::dispatch, pid, dispatcher);
- return timers::create(secs, dispatch);
+ return Timer::create(duration, dispatch);
}
template <typename T,
typename P1, typename P2,
typename A1, typename A2>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>& process,
void (T::*method)(P1, P2),
A1 a1, A2 a2)
{
- return delay(secs, process.self(), method, a1, a2);
+ return delay(duration, process.self(), method, a1, a2);
}
template <typename T,
typename P1, typename P2,
typename A1, typename A2>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>* process,
void (T::*method)(P1, P2),
A1 a1, A2 a2)
{
- return delay(secs, process->self(), method, a1, a2);
+ return delay(duration, process->self(), method, a1, a2);
}
template <typename T,
typename P1, typename P2, typename P3,
typename A1, typename A2, typename A3>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const PID<T>& pid,
void (T::*method)(P1, P2, P3),
A1 a1, A2 a2, A3 a3)
@@ -166,31 +168,31 @@ Timer delay(double secs,
std::tr1::function<void(void)> dispatch =
std::tr1::bind(internal::dispatch, pid, dispatcher);
- return timers::create(secs, dispatch);
+ return Timer::create(duration, dispatch);
}
template <typename T,
typename P1, typename P2, typename P3,
typename A1, typename A2, typename A3>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>& process,
void (T::*method)(P1, P2, P3),
A1 a1, A2 a2, A3 a3)
{
- return delay(secs, process.self(), method, a1, a2, a3);
+ return delay(duration, process.self(), method, a1, a2, a3);
}
template <typename T,
typename P1, typename P2, typename P3,
typename A1, typename A2, typename A3>
-Timer delay(double secs,
+Timer delay(const Duration& duration,
const Process<T>* process,
void (T::*method)(P1, P2, P3),
A1 a1, A2 a2, A3 a3)
{
- return delay(secs, process->self(), method, a1, a2, a3);
+ return delay(duration, process->self(), method, a1, a2, a3);
}
} // namespace process {
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/future.hpp Sun Sep 9 22:02:45 2012
@@ -13,6 +13,7 @@
#include <process/latch.hpp>
+#include <stout/duration.hpp>
#include <stout/option.hpp>
namespace process {
@@ -70,7 +71,7 @@ public:
bool discard();
// Waits for this future to become ready, discarded, or failed.
- bool await(double secs = 0) const;
+ bool await(const Duration& duration = Seconds(0)) const;
// Return the value associated with this future, waits indefinitely
// until a value gets associated or until the future is discarded.
@@ -510,11 +511,11 @@ bool Future<T>::isFailed() const
template <typename T>
-bool Future<T>::await(double secs) const
+bool Future<T>::await(const Duration& duration) const
{
if (!isReady() && !isDiscarded() && !isFailed()) {
assert(latch != NULL);
- return latch->await(secs);
+ return latch->await(duration);
}
return true;
}
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/latch.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/latch.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/latch.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/latch.hpp Sun Sep 9 22:02:45 2012
@@ -3,6 +3,8 @@
#include <process/pid.hpp>
+#include <stout/duration.hpp>
+
namespace process {
class Latch
@@ -15,7 +17,7 @@ public:
bool operator < (const Latch& that) const { return pid < that.pid; }
void trigger();
- bool await(double secs = 0);
+ bool await(const Duration& duration = Seconds(0));
private:
// Not copyable, not assignable.
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/process.hpp Sun Sep 9 22:02:45 2012
@@ -18,6 +18,8 @@
#include <process/pid.hpp>
#include <process/thread.hpp>
+#include <stout/duration.hpp>
+
namespace process {
class ProcessBase : public EventVisitor
@@ -297,9 +299,9 @@ void terminate(const ProcessBase* proces
* @param PID id of the process
* @param secs max time to wait, 0 implies wait for ever
*/
-bool wait(const UPID& pid, double secs = 0);
-bool wait(const ProcessBase& process, double secs = 0);
-bool wait(const ProcessBase* process, double secs = 0);
+bool wait(const UPID& pid, const Duration& duration = Seconds(0));
+bool wait(const ProcessBase& process, const Duration& duration = Seconds(0));
+bool wait(const ProcessBase* process, const Duration& duration = Seconds(0));
/**
@@ -329,15 +331,15 @@ inline void terminate(const ProcessBase*
}
-inline bool wait(const ProcessBase& process, double secs)
+inline bool wait(const ProcessBase& process, const Duration& duration)
{
- return wait(process.self(), secs);
+ return wait(process.self(), duration);
}
-inline bool wait(const ProcessBase* process, double secs)
+inline bool wait(const ProcessBase* process, const Duration& duration)
{
- return wait(process->self(), secs);
+ return wait(process->self(), duration);
}
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/timeout.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/timeout.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/timeout.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/timeout.hpp Sun Sep 9 22:02:45 2012
@@ -45,11 +45,11 @@ public:
return timeout;
}
- // Returns the number of seconds reamining.
- double remaining() const
+ // Returns the amount of time remaining.
+ Duration remaining() const
{
double seconds = timeout - Clock::now();
- return seconds > 0 ? seconds : 0;
+ return Seconds(seconds > 0 ? seconds : 0);
}
private:
Modified: incubator/mesos/trunk/third_party/libprocess/include/process/timer.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/process/timer.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/process/timer.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/process/timer.hpp Sun Sep 9 22:02:45 2012
@@ -7,28 +7,23 @@
#include <process/timeout.hpp>
-namespace process {
-
-// Timer support! Note that we don't store a pointer to the issuing
-// process (if there is one) because we can't dereference it because
-// it might no longer be valid. (Instead we can use the PID to check
-// if the issuing process is still valid and get a refernce to it).
-
-class Timer; // Forward declaration.
+#include <stout/duration.hpp>
-namespace timers {
-
-Timer create(double secs, const std::tr1::function<void(void)>& thunk);
-bool cancel(const Timer& timer);
-
-} // namespace timers {
+namespace process {
+// Timer support!
class Timer
{
public:
Timer() : id(0), t(0), pid(process::UPID()), thunk(&abort) {}
+ static Timer create(
+ const Duration& duration,
+ const std::tr1::function<void(void)>& thunk);
+
+ static bool cancel(const Timer& timer);
+
bool operator == (const Timer& that) const
{
return id == that.id;
@@ -55,8 +50,6 @@ public:
}
private:
- friend Timer timers::create(double, const std::tr1::function<void(void)>&);
-
Timer(long _id,
const Timeout& _t,
const process::UPID& _pid,
@@ -65,8 +58,16 @@ private:
{}
uint64_t id; // Used for equality.
+
Timeout t;
- process::UPID pid; // Running process when this timer was created.
+
+ // We store the PID of the "issuing" (i.e., "running") process (if
+ // there is one). We don't store a pointer to the process because we
+ // can't dereference it since it might no longer be valid. (Instead,
+ // the PID can be used internally to check if the process is still
+ // valid and get a refernce to it.)
+ process::UPID pid;
+
std::tr1::function<void(void)> thunk;
};
Modified: incubator/mesos/trunk/third_party/libprocess/include/stout/duration.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/stout/duration.hpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/stout/duration.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/stout/duration.hpp Sun Sep 9 22:02:45 2012
@@ -3,6 +3,8 @@
#include <ctype.h> // For 'isdigit'.
+#include <iomanip>
+#include <iostream>
#include <string>
#include "numify.hpp"
@@ -12,15 +14,21 @@
class Duration
{
public:
- double nanos() const { return value; }
- double micros() const { return value / MICROSECONDS; }
- double millis() const { return value / MILLISECONDS; }
+ double ns() const { return value; }
+ double us() const { return value / MICROSECONDS; }
+ double ms() const { return value / MILLISECONDS; }
double secs() const { return value / SECONDS; }
double mins() const { return value / MINUTES; }
+ double hrs() const { return value / HOURS; }
double days() const { return value / DAYS; }
double weeks() const { return value / WEEKS; }
bool operator < (const Duration& that) const { return value < that.value; }
+ bool operator <= (const Duration& that) const { return value <= that.value; }
+ bool operator > (const Duration& that) const { return value > that.value; }
+ bool operator >= (const Duration& that) const { return value >= that.value; }
+ bool operator == (const Duration& that) const { return value == that.value; }
+ bool operator != (const Duration& that) const { return value != that.value; }
static Try<Duration> parse(const std::string& s)
{
@@ -147,4 +155,42 @@ public:
: Duration(value, WEEKS) {}
};
+
+inline std::ostream& operator << (
+ std::ostream& stream,
+ const Duration& duration)
+{
+ // Fix the number digits after the decimal point.
+ std::ios_base::fmtflags flags = stream.flags();
+ long precision = stream.precision();
+
+ stream.setf(std::ios::fixed, std::ios::floatfield);
+ stream.precision(2);
+
+ if (duration < Microseconds(1)) {
+ stream << duration.ns() << "ns";
+ } else if (duration < Milliseconds(1)) {
+ stream << duration.us() << "us";
+ } else if (duration < Seconds(1)) {
+ stream << duration.ms() << "ms";
+ } else if (duration < Minutes(1)) {
+ stream << duration.secs() << "secs";
+ } else if (duration < Hours(1)) {
+ stream << duration.mins() << "mins";
+ } else if (duration < Days(1)) {
+ stream << duration.hrs() << "hrs";
+ } else if (duration < Weeks(1)) {
+ stream << duration.days() << "days";
+ } else {
+ stream << duration.weeks() << "weeks";
+ }
+
+ // Return the stream to original formatting state.
+ stream.unsetf(std::ios::floatfield);
+ stream.setf(flags);
+ stream.precision(precision);
+
+ return stream;
+}
+
#endif // __STOUT_DURATION_HPP__
Modified: incubator/mesos/trunk/third_party/libprocess/src/latch.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/latch.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/latch.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/latch.cpp Sun Sep 9 22:02:45 2012
@@ -2,6 +2,8 @@
#include <process/latch.hpp>
#include <process/process.hpp>
+#include <stout/duration.hpp>
+
namespace process {
// TODO(benh): Provide an "optimized" implementation of a latch that
@@ -37,10 +39,10 @@ void Latch::trigger()
}
-bool Latch::await(double secs)
+bool Latch::await(const Duration& duration)
{
if (!triggered) {
- return wait(pid, secs);
+ return wait(pid, duration);
}
return true;
Modified: incubator/mesos/trunk/third_party/libprocess/src/process.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/process.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/process.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/process.cpp Sun Sep 9 22:02:45 2012
@@ -60,6 +60,7 @@
#include <process/thread.hpp>
#include <process/timer.hpp>
+#include <stout/duration.hpp>
#include <stout/foreach.hpp>
#include <stout/lambda.hpp>
#include <stout/os.hpp>
@@ -1428,8 +1429,9 @@ void HttpProxy::handle(Future<Response>*
defer(self(), &HttpProxy::waited, *future));
// Also create a timer so we don't wait forever.
- timer =
- timers::create(30, defer(self(), &HttpProxy::timedout, *future));
+ timer = Timer::create(
+ Seconds(30.0),
+ defer(self(), &HttpProxy::timedout, *future));
}
}
@@ -1443,8 +1445,9 @@ void HttpProxy::next()
defer(self(), &HttpProxy::waited, *item->future));
// Also create a timer so we don't wait forever.
- timer =
- timers::create(30, defer(self(), &HttpProxy::timedout, *item->future));
+ timer = Timer::create(
+ Seconds(30.0),
+ defer(self(), &HttpProxy::timedout, *item->future));
}
}
@@ -1454,7 +1457,7 @@ void HttpProxy::waited(const Future<Resp
if (items.size() > 0) { // The timer might have already fired.
Item* item = items.front();
if (future == *item->future) { // Another future might already be queued.
- timers::cancel(timer);
+ Timer::cancel(timer);
if (item->future->isReady()) {
process(item->future, item->persist);
@@ -2559,13 +2562,13 @@ void ProcessManager::settle()
}
-namespace timers {
-
-Timer create(double secs, const lambda::function<void(void)>& thunk)
+Timer Timer::create(
+ const Duration& duration,
+ const lambda::function<void(void)>& thunk)
{
static uint64_t id = 1; // Start at 1 since Timer() instances start with 0.
- Timeout timeout(secs); // Assumes Clock::now() does Clock::now(__process__).
+ Timeout timeout(duration.secs()); // Assumes Clock::now() does Clock::now(__process__).
UPID pid = __process__ != NULL ? __process__->self() : UPID();
@@ -2593,7 +2596,7 @@ Timer create(double secs, const lambda::
}
-bool cancel(const Timer& timer)
+bool Timer::cancel(const Timer& timer)
{
bool canceled = false;
synchronized (timeouts) {
@@ -2614,8 +2617,6 @@ bool cancel(const Timer& timer)
return canceled;
}
-} // namespace timers {
-
ProcessBase::ProcessBase(const std::string& id)
{
@@ -2903,17 +2904,17 @@ void terminate(const UPID& pid, bool inj
class WaitWaiter : public Process<WaitWaiter>
{
public:
- WaitWaiter(const UPID& _pid, double _secs, bool* _waited)
+ WaitWaiter(const UPID& _pid, const Duration& _duration, bool* _waited)
: ProcessBase(ID::generate("__waiter__")),
pid(_pid),
- secs(_secs),
+ duration(_duration),
waited(_waited) {}
virtual void initialize()
{
VLOG(3) << "Running waiter process for " << pid;
link(pid);
- delay(secs, self(), &WaitWaiter::timeout);
+ delay(duration, self(), &WaitWaiter::timeout);
}
private:
@@ -2933,12 +2934,12 @@ private:
private:
const UPID pid;
- const double secs;
+ const Duration duration;
bool* const waited;
};
-bool wait(const UPID& pid, double secs)
+bool wait(const UPID& pid, const Duration& duration)
{
process::initialize();
@@ -2953,13 +2954,13 @@ bool wait(const UPID& pid, double secs)
<< pid << " that it is currently executing." << std::endl;
}
- if (secs == 0) {
+ if (duration == Seconds(0)) {
return process_manager->wait(pid);
}
bool waited = false;
- WaitWaiter waiter(pid, secs, &waited);
+ WaitWaiter waiter(pid, duration, &waited);
spawn(waiter);
wait(waiter);
Modified: incubator/mesos/trunk/third_party/libprocess/src/tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/src/tests.cpp?rev=1382589&r1=1382588&r2=1382589&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/src/tests.cpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/src/tests.cpp Sun Sep 9 22:02:45 2012
@@ -22,6 +22,7 @@
#include <process/run.hpp>
#include <process/thread.hpp>
+#include <stout/duration.hpp>
#include <stout/os.hpp>
#include "encoder.hpp"
@@ -641,11 +642,9 @@ TEST(Process, delay)
spawn(process);
- double seconds = 5.0;
+ delay(Seconds(5.0), process.self(), &TimeoutProcess::timeout);
- delay(seconds, process.self(), &TimeoutProcess::timeout);
-
- Clock::advance(seconds);
+ Clock::advance(5.0);
while (!timeoutCalled);
@@ -838,7 +837,7 @@ public:
virtual void initialize()
{
usleep(10000);
- delay(0.0, self(), &SettleProcess::afterDelay);
+ delay(Seconds(0), self(), &SettleProcess::afterDelay);
}
void afterDelay()
@@ -1166,7 +1165,7 @@ TEST(Process, read)
// Test on a blocking file descriptor.
future = io::read(pipes[0], data, 3);
- future.await(1.0);
+ future.await(Seconds(1.0));
EXPECT_TRUE(future.isFailed());
close(pipes[0]);
@@ -1174,7 +1173,7 @@ TEST(Process, read)
// Test on a closed file descriptor.
future = io::read(pipes[0], data, 3);
- future.await(1.0);
+ future.await(Seconds(1.0));
EXPECT_TRUE(future.isFailed());
// Create a nonblocking pipe.
@@ -1184,7 +1183,7 @@ TEST(Process, read)
// Test reading nothing.
future = io::read(pipes[0], data, 0);
- future.await(1.0);
+ future.await(Seconds(1.0));
EXPECT_TRUE(future.isFailed());
// Test successful read.
@@ -1192,7 +1191,7 @@ TEST(Process, read)
ASSERT_FALSE(future.isReady());
ASSERT_EQ(2, write(pipes[1], "hi", 2));
- future.await(1.0);
+ future.await(Seconds(1.0));
ASSERT_TRUE(future.isReady());
ASSERT_EQ(2, future.get());
EXPECT_EQ('h', data[0]);
@@ -1207,7 +1206,7 @@ TEST(Process, read)
ASSERT_EQ(3, write(pipes[1], "omg", 3));
future = io::read(pipes[0], data, 3);
- future.await(1.0);
+ future.await(Seconds(1.0));
ASSERT_TRUE(future.isReady());
ASSERT_EQ(3, future.get());
EXPECT_EQ('o', data[0]);
@@ -1220,7 +1219,7 @@ TEST(Process, read)
close(pipes[1]);
- future.await(1.0);
+ future.await(Seconds(1.0));
ASSERT_TRUE(future.isReady());
EXPECT_EQ(0, future.get());