Skip to content

Commit

Permalink
Windows: [3/3] Used os::random.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpravat authored and jmlvanre committed May 13, 2016
1 parent 2f83201 commit 148348b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/executor/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class MesosProcess : public ProtobufProcess<MesosProcess>

// Linearly backoff by picking a random duration between 0 and
// `maxBackoff`.
Duration backoff = maxBackoff.get() * ((double) ::random() / RAND_MAX);
Duration backoff = maxBackoff.get() * ((double) os::random() / RAND_MAX);

VLOG(1) << "Will retry connecting with the agent again in " << backoff;

Expand Down
3 changes: 2 additions & 1 deletion src/log/consensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stout/check.hpp>
#include <stout/duration.hpp>
#include <stout/lambda.hpp>
#include <stout/os.hpp>
#include <stout/nothing.hpp>
#include <stout/foreach.hpp>

Expand Down Expand Up @@ -771,7 +772,7 @@ class FillProcess : public Process<FillProcess>
// one proposer usually times out and wins before others wake up.
// On the other hand, we want T to be as small as possible such
// that we can reduce the wait time.
Duration d = T * (1.0 + (double) ::random() / RAND_MAX);
Duration d = T * (1.0 + (double) os::random() / RAND_MAX);
delay(d, self(), &Self::runPromisePhase);
}

Expand Down
3 changes: 2 additions & 1 deletion src/log/recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <stout/lambda.hpp>
#include <stout/none.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>

#include "log/catchup.hpp"
#include "log/recover.hpp"
Expand Down Expand Up @@ -332,7 +333,7 @@ class RecoverProtocolProcess : public Process<RecoverProtocolProcess>
// likelihood of conflicts (i.e., a replica receives a recover
// request while it is changing its status).
static const Duration T = Milliseconds(500);
Duration d = T * (1.0 + (double) ::random() / RAND_MAX);
Duration d = T * (1.0 + (double) os::random() / RAND_MAX);
VLOG(2) << "Didn't receive enough responses for recovery, retrying "
<< "in " << stringify(d);

Expand Down
3 changes: 2 additions & 1 deletion src/log/tool/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stout/bytes.hpp>
#include <stout/error.hpp>
#include <stout/foreach.hpp>
#include <stout/os.hpp>
#include <stout/stopwatch.hpp>
#include <stout/strings.hpp>
#include <stout/os/read.hpp>
Expand Down Expand Up @@ -216,7 +217,7 @@ Try<Nothing> Benchmark::execute(int argc, char** argv)
if (flags.type == "one") {
data.push_back(string(sizes[i].bytes(), static_cast<char>(0xff)));
} else if (flags.type == "random") {
data.push_back(string(sizes[i].bytes(), ::random() % 256));
data.push_back(string(sizes[i].bytes(), os::random() % 256));
} else {
data.push_back(string(sizes[i].bytes(), 0));
}
Expand Down
2 changes: 1 addition & 1 deletion src/sched/sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ class SchedulerProcess : public ProtobufProcess<SchedulerProcess>
// Determine the delay for next attempt by picking a random
// duration between 0 and 'maxBackoff'.
// TODO(vinod): Use random numbers from <random> header.
Duration delay = maxBackoff * ((double) ::random() / RAND_MAX);
Duration delay = maxBackoff * ((double) os::random() / RAND_MAX);

VLOG(1) << "Will retry registration in " << delay << " if necessary";

Expand Down
4 changes: 2 additions & 2 deletions src/slave/slave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ void Slave::detected(const Future<Option<MasterInfo>>& _master)
// Wait for a random amount of time before authentication or
// registration.
Duration duration =
flags.registration_backoff_factor * ((double) ::random() / RAND_MAX);
flags.registration_backoff_factor * ((double) os::random() / RAND_MAX);

if (credential.isSome()) {
// Authenticate with the master.
Expand Down Expand Up @@ -1480,7 +1480,7 @@ void Slave::doReliableRegistration(Duration maxBackoff)

// Determine the delay for next attempt by picking a random
// duration between 0 and 'maxBackoff'.
Duration delay = maxBackoff * ((double) ::random() / RAND_MAX);
Duration delay = maxBackoff * ((double) os::random() / RAND_MAX);

VLOG(1) << "Will retry registration in " << delay << " if necessary";

Expand Down

0 comments on commit 148348b

Please sign in to comment.