summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-11-11 00:37:38 -0500
committerEliot Horowitz <eliot@10gen.com>2012-11-11 00:37:38 -0500
commit6646391f2d5c0077eaad4fc9836a2abe6278f2f8 (patch)
treead12a0142676e0d62746e063988b8a177a8766c1
parent894cc05556fbf69ee515b3685a60e8a5e6d345aa (diff)
downloadmongo-6646391f2d5c0077eaad4fc9836a2abe6278f2f8.tar.gz
remove some rand() calls, and use Random instead
-rw-r--r--src/mongo/s/chunk.cpp31
-rw-r--r--src/mongo/s/chunk.h2
-rw-r--r--src/mongo/s/d_writeback.cpp20
-rw-r--r--src/mongo/s/d_writeback.h5
-rw-r--r--src/mongo/util/queue.h2
5 files changed, 33 insertions, 27 deletions
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index c7701e36467..798c00e9f85 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -1,7 +1,7 @@
// @file chunk.cpp
/**
- * Copyright (C) 2008 10gen Inc.
+ * Copyright (C) 2008-2012 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
@@ -18,20 +18,20 @@
#include "pch.h"
-#include "../client/connpool.h"
-#include "../db/queryutil.h"
-#include "../util/startup_test.h"
-#include "../util/timer.h"
+#include "mongo/client/connpool.h"
#include "mongo/client/dbclientcursor.h"
-
-#include "chunk.h"
-#include "chunk_diff.h"
-#include "config.h"
-#include "cursors.h"
-#include "grid.h"
-#include "strategy.h"
-#include "client_info.h"
+#include "mongo/db/queryutil.h"
+#include "mongo/platform/random.h"
+#include "mongo/s/chunk.h"
+#include "mongo/s/chunk_diff.h"
+#include "mongo/s/client_info.h"
+#include "mongo/s/config.h"
+#include "mongo/s/cursors.h"
+#include "mongo/s/grid.h"
#include "mongo/util/concurrency/ticketholder.h"
+#include "mongo/s/strategy.h"
+#include "mongo/util/startup_test.h"
+#include "mongo/util/timer.h"
namespace mongo {
@@ -79,8 +79,9 @@ namespace mongo {
: _manager(info), _min(min), _max(max), _shard(shard), _lastmod(lastmod), _jumbo(false), _dataWritten(mkDataWritten())
{}
- long Chunk::mkDataWritten() {
- return rand() % ( MaxChunkSize / ChunkManager::SplitHeuristics::splitTestFactor );
+ int Chunk::mkDataWritten() {
+ PseudoRandom r( time(0) );
+ return r.nextInt32( MaxChunkSize / ChunkManager::SplitHeuristics::splitTestFactor );
}
string Chunk::getns() const {
diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h
index e714268b242..cdec3d32b51 100644
--- a/src/mongo/s/chunk.h
+++ b/src/mongo/s/chunk.h
@@ -230,7 +230,7 @@ namespace mongo {
BSONObj _getExtremeKey( int sort ) const;
/** initializes _dataWritten with a random value so that a mongos restart wouldn't cause delay in splitting */
- static long mkDataWritten();
+ static int mkDataWritten();
ShardKeyPattern skey() const;
};
diff --git a/src/mongo/s/d_writeback.cpp b/src/mongo/s/d_writeback.cpp
index c2b469b0bf6..ae5813d87f5 100644
--- a/src/mongo/s/d_writeback.cpp
+++ b/src/mongo/s/d_writeback.cpp
@@ -18,16 +18,17 @@
#include "pch.h"
-#include "../db/commands.h"
-#include "../util/queue.h"
-#include "../util/net/listen.h"
-#include "../db/curop.h"
-#include "../db/client.h"
+#include "mongo/s/d_writeback.h"
+
+#include "mongo/db/client.h"
+#include "mongo/db/commands.h"
#include "mongo/db/commands/server_status.h"
+#include "mongo/db/curop.h"
+#include "mongo/platform/random.h"
+#include "mongo/util/net/listen.h"
+#include "mongo/util/queue.h"
#include "mongo/util/stacktrace.h"
-#include "d_writeback.h"
-
using namespace std;
namespace mongo {
@@ -169,12 +170,13 @@ namespace mongo {
}
#ifdef _DEBUG
+ PseudoRandom r( time(0) );
// Sleep a short amount of time usually
- int sleepFor = rand() % 10;
+ int sleepFor = r.nextInt32( 10 );
sleepmillis( sleepFor );
// Sleep a longer amount of time every once and awhile
- int sleepLong = rand() % 50;
+ int sleepLong = r.nextInt32( 50 );
if( sleepLong == 0 ) sleepsecs( 2 );
#endif
diff --git a/src/mongo/s/d_writeback.h b/src/mongo/s/d_writeback.h
index 9e96d9a107d..b30b6b515d3 100644
--- a/src/mongo/s/d_writeback.h
+++ b/src/mongo/s/d_writeback.h
@@ -20,8 +20,9 @@
#include "mongo/pch.h"
-#include "../util/queue.h"
-#include "../util/background.h"
+#include "mongo/db/jsobj.h"
+#include "mongo/util/queue.h"
+#include "mongo/util/background.h"
namespace mongo {
diff --git a/src/mongo/util/queue.h b/src/mongo/util/queue.h
index 1f43a0e6dee..49ff3d27d32 100644
--- a/src/mongo/util/queue.h
+++ b/src/mongo/util/queue.h
@@ -22,6 +22,8 @@
#include <limits>
#include <queue>
+#include <boost/thread/condition.hpp>
+
#include "mongo/util/timer.h"
namespace mongo {