Skip to content

Commit 86bd3e6

Browse files
committed
CXX-650 Backport server r2.6.11..r2.6.12 changes
Server SHAs picked into this commit: 52ae817 ce9d96d c980c02 ec270ef aa5a2f5 1290ac9 d73c92b
1 parent 6067bc9 commit 86bd3e6

File tree

6 files changed

+110
-20
lines changed

6 files changed

+110
-20
lines changed

SConstruct

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,17 @@ usePCH = has_option( "usePCH" )
445445

446446
justClientLib = (COMMAND_LINE_TARGETS == ['mongoclient'])
447447

448-
env = Environment( BUILD_DIR=variantDir,
448+
# On some branches, we honor several scons Variables on the command
449+
# line. Those don't exist on 2.6, but it is easy to get in the habit
450+
# of using them. By default SCons silently ignores them, which can be
451+
# very confusing if you say 'scons CC=clang' on the v2.6 branch, for
452+
# instance. We create an empty Variables object here and feed it to
453+
# the Environment constructor so that we can ask for any unknown
454+
# variables (and all should be), below.
455+
env_vars = Variables()
456+
457+
env = Environment( variables=env_vars,
458+
BUILD_DIR=variantDir,
449459
DIST_ARCHIVE_SUFFIX='.tgz',
450460
EXTRAPATH=get_option("extrapath"),
451461
MODULE_BANNERS=[],
@@ -466,6 +476,12 @@ env = Environment( BUILD_DIR=variantDir,
466476
CONFIGURELOG = '#' + scons_data_dir + '/config.log'
467477
)
468478

479+
# Report any unknown variables as an error.
480+
unknown_vars = env_vars.UnknownVariables()
481+
if unknown_vars:
482+
print "Unknown variables specified: {0}".format(", ".join(unknown_vars.keys()))
483+
Exit(1)
484+
469485
if has_option("cache"):
470486
EnsureSConsVersion( 2, 3, 0 )
471487
if has_option("release"):

src/mongo/base/error_codes.err

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ error_code("IndexOptionsConflict", 85 )
8787
error_code("IndexKeySpecsConflict", 86 )
8888
error_code("OutdatedClient", 101)
8989
error_code("IncompatibleAuditMetadata", 102)
90+
error_code("CappedPositionLost", 103)
9091

9192
# Non-sequential error codes (for compatibility only)
9293
error_code("NetworkTimeout", 89)

src/mongo/platform/random.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,49 +35,53 @@ namespace mongo {
3535

3636
// ---- PseudoRandom -----
3737

38-
int32_t PseudoRandom::nextInt32() {
39-
int32_t t = _x ^ (_x << 11);
38+
uint32_t PseudoRandom::nextUInt32() {
39+
uint32_t t = _x ^ (_x << 11);
4040
_x = _y;
4141
_y = _z;
4242
_z = _w;
4343
return _w = _w ^ (_w >> 19) ^ (t ^ (t >> 8));
4444
}
4545

4646
namespace {
47-
const int32_t default_y = 362436069;
48-
const int32_t default_z = 521288629;
49-
const int32_t default_w = 88675123;
47+
const uint32_t default_y = 362436069;
48+
const uint32_t default_z = 521288629;
49+
const uint32_t default_w = 88675123;
5050
}
5151

5252
PseudoRandom::PseudoRandom( int32_t seed ) {
53-
_x = seed;
53+
_x = static_cast<uint32_t>(seed);
5454
_y = default_y;
5555
_z = default_z;
5656
_w = default_w;
5757
}
5858

5959

6060
PseudoRandom::PseudoRandom( uint32_t seed ) {
61-
_x = static_cast<int32_t>(seed);
61+
_x = seed;
6262
_y = default_y;
6363
_z = default_z;
6464
_w = default_w;
6565
}
6666

6767

6868
PseudoRandom::PseudoRandom( int64_t seed ) {
69-
int32_t high = seed >> 32;
70-
int32_t low = seed & 0xFFFFFFFF;
69+
uint32_t high = seed >> 32;
70+
uint32_t low = seed & 0xFFFFFFFF;
7171

7272
_x = high ^ low;
7373
_y = default_y;
7474
_z = default_z;
7575
_w = default_w;
7676
}
7777

78+
int32_t PseudoRandom::nextInt32() {
79+
return nextUInt32();
80+
}
81+
7882
int64_t PseudoRandom::nextInt64() {
79-
int64_t a = nextInt32();
80-
int64_t b = nextInt32();
83+
uint64_t a = nextUInt32();
84+
uint64_t b = nextUInt32();
8185
return ( a << 32 ) | b;
8286
}
8387

src/mongo/platform/random.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,21 @@ namespace mongo {
3939
/**
4040
* @return a number between 0 and max
4141
*/
42-
int32_t nextInt32( int32_t max ) { return nextInt32() % max; }
42+
int32_t nextInt32( int32_t max ) {
43+
return static_cast<uint32_t>(nextInt32()) % static_cast<uint32_t>(max);
44+
}
4345

4446
/**
4547
* @return a number between 0 and max
4648
*/
47-
int64_t nextInt64( int64_t max ) { return nextInt64() % max; }
49+
int64_t nextInt64( int64_t max ) {
50+
return static_cast<uint64_t>(nextInt64()) % static_cast<uint64_t>(max);
51+
}
4852

4953
/**
5054
* @return a number between 0 and max
5155
*
52-
* This makes PsuedoRandom instances passable as the third argument to std::random_shuffle
56+
* This makes PseudoRandom instances passable as the third argument to std::random_shuffle
5357
*/
5458
intptr_t operator()(intptr_t max) {
5559
if (sizeof(intptr_t) == 4)
@@ -58,10 +62,12 @@ namespace mongo {
5862
}
5963

6064
private:
61-
int32_t _x;
62-
int32_t _y;
63-
int32_t _z;
64-
int32_t _w;
65+
uint32_t nextUInt32();
66+
67+
uint32_t _x;
68+
uint32_t _y;
69+
uint32_t _z;
70+
uint32_t _w;
6571
};
6672

6773
/**

src/mongo/platform/random_test.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <set>
20+
#include <vector>
2021

2122
#include "mongo/platform/random.h"
2223

@@ -86,6 +87,68 @@ namespace mongo {
8687
ASSERT_EQUALS( 100U, s.size() );
8788
}
8889

90+
TEST(RandomTest, NextInt32SanityCheck) {
91+
// Generate 1000 int32s and assert that each bit is set between 40% and 60% of the time.
92+
// This is a bare minimum sanity check, not an attempt to ensure quality random numbers.
93+
94+
PseudoRandom a(11);
95+
std::vector<int32_t> nums;
96+
for (int i = 0; i < 1000; i++) {
97+
nums.push_back(a.nextInt32());
98+
}
99+
100+
for (int bit = 0; bit < 32; bit++) {
101+
int onesCount = 0;
102+
for (size_t i=0; i < nums.size(); i++) {
103+
bool isSet = (nums[i] >> bit) & 1;
104+
if (isSet)
105+
onesCount++;
106+
}
107+
108+
ASSERT_FALSE(onesCount < 400 || onesCount > 600);
109+
}
110+
}
111+
112+
TEST(RandomTest, NextInt64SanityCheck) {
113+
// Generate 1000 int64s and assert that each bit is set between 40% and 60% of the time.
114+
// This is a bare minimum sanity check, not an attempt to ensure quality random numbers.
115+
116+
PseudoRandom a(11);
117+
std::vector<int64_t> nums;
118+
for (int i = 0; i < 1000; i++) {
119+
nums.push_back(a.nextInt64());
120+
}
121+
122+
for (int bit = 0; bit < 64; bit++) {
123+
int onesCount = 0;
124+
for (size_t i=0; i < nums.size(); i++) {
125+
bool isSet = (nums[i] >> bit) & 1;
126+
if (isSet)
127+
onesCount++;
128+
}
129+
130+
ASSERT_FALSE(onesCount < 400 || onesCount > 600);
131+
}
132+
}
133+
134+
TEST(RandomTest, NextInt32InRange) {
135+
PseudoRandom a(11);
136+
for (int i = 0; i < 1000; i++) {
137+
int32_t res = a.nextInt32(10);
138+
ASSERT_GREATER_THAN_OR_EQUALS(res, 0);
139+
ASSERT_LESS_THAN(res, 10);
140+
}
141+
}
142+
143+
TEST(RandomTest, NextInt64InRange) {
144+
PseudoRandom a(11);
145+
for (int i = 0; i < 1000; i++) {
146+
int64_t res = a.nextInt64(10);
147+
ASSERT_GREATER_THAN_OR_EQUALS(res, 0);
148+
ASSERT_LESS_THAN(res, 10);
149+
}
150+
}
151+
89152

90153
TEST( RandomTest, Secure1 ) {
91154
SecureRandom* a = SecureRandom::create();

src/mongo/util/version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace mongo {
3131
* 1.2.3-rc4-pre-
3232
* If you really need to do something else you'll need to fix _versionArray()
3333
*/
34-
const char versionString[] = "2.6.11";
34+
const char versionString[] = "2.6.12";
3535

3636
// See unit test for example outputs
3737
BSONArray toVersionArray(const char* version){

0 commit comments

Comments
 (0)