Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support geo indexing with points equal to max (+180 by default) SERVE…

…R-4027
  • Loading branch information...
commit 86b5b89c2785f3f45ad2674f48fe3189c137904c 1 parent ca02fab
@RedBeard0531 RedBeard0531 authored
View
49 jstests/geo_max.js
@@ -0,0 +1,49 @@
+// Test where points are on _max (180)
+// Using GeoNearRandom because this test needs a lot of points in the index.
+// If there aren't enough points the test passes even if the code is broken.
+load("jstests/libs/geo_near_random.js");
+
+var test = new GeoNearRandomTest("geo_near_max")
+
+test.insertPts(/*numPts*/1000, /*indexBounds*/{min:-180, max:180}, /*scale*/0.9);
+
+test.t.insert({loc: [ 180, 0]})
+test.t.insert({loc: [-180, 0]})
+test.t.insert({loc: [ 179.999, 0]})
+test.t.insert({loc: [-179.999, 0]})
+
+assertXIsNegative = function(obj) { assert.lt(obj.loc[0], 0); }
+assertXIsPositive = function(obj) { assert.gt(obj.loc[0], 0); }
+
+assert.eq(test.t.count({loc:{$within: {$center:[[ 180, 0], 1]}}}), 2)
+assert.eq(test.t.count({loc:{$within: {$center:[[-180, 0], 1]}}}), 2)
+test.t.find({loc:{$within: {$center:[[ 180, 0], 1]}}}).forEach(assertXIsPositive)
+test.t.find({loc:{$within: {$center:[[-180, 0], 1]}}}).forEach(assertXIsNegative)
+
+var oneDegree = Math.PI / 180; // in radians
+
+// errors out due to SERVER-1760
+if (0) {
+assert.eq(test.t.count({loc:{$within: {$centerSphere:[[ 180, 0], oneDegree]}}}), 2)
+assert.eq(test.t.count({loc:{$within: {$centerSphere:[[-180, 0], oneDegree]}}}), 2)
+test.t.find({loc:{$within: {$centerSphere:[[ 180, 0], oneDegree]}}}).forEach(assertXIsPositive)
+test.t.find({loc:{$within: {$centerSphere:[[-180, 0], oneDegree]}}}).forEach(assertXIsNegative)
+}
+
+assert.eq(test.t.count({loc:{$within: {$box:[[ 180, 0.1], [ 179, -0.1]]}}}), 2)
+assert.eq(test.t.count({loc:{$within: {$box:[[-180, 0.1], [-179, -0.1]]}}}), 2)
+test.t.find({loc:{$within: {$box:[[ 180, 0.1], [ 179, -0.1]]}}}).forEach(assertXIsPositive)
+test.t.find({loc:{$within: {$box:[[-180, 0.1], [-179, -0.1]]}}}).forEach(assertXIsNegative)
+
+assert.eq(test.t.count({loc:{$within: {$polygon:[[ 180, 0], [ 179, 0], [ 179.5, 0.5]]}}}), 2)
+assert.eq(test.t.count({loc:{$within: {$polygon:[[-180, 0], [-179, 0], [ 179.5, 0.5]]}}}), 2)
+test.t.find({loc:{$within: {$polygon:[[ 180, 0], [ 179, 0], [ 179.5, 0.5]]}}}).forEach(assertXIsPositive)
+test.t.find({loc:{$within: {$polygon:[[-180, 0], [-179, 0], [ 179.5, 0.5]]}}}).forEach(assertXIsNegative)
+
+assert.eq(test.t.find({loc:{$near:[ 180, 0]}}, {_id:0}).limit(2).toArray(), [{loc: [ 180, 0]}, {loc: [ 179.999, 0]}])
+assert.eq(test.t.find({loc:{$near:[-180, 0]}}, {_id:0}).limit(2).toArray(), [{loc: [-180, 0]}, {loc: [-179.999, 0]}])
+
+// These will need to change when SERVER-1760 is fixed
+assert.eq(test.t.find({loc:{$nearSphere:[ 180, 0]}}, {_id:0}).limit(2).toArray(), [{loc: [ 180, 0]}, {loc: [ 179.999, 0]}])
+assert.eq(test.t.find({loc:{$nearSphere:[-180, 0]}}, {_id:0}).limit(2).toArray(), [{loc: [-180, 0]}, {loc: [-179.999, 0]}])
+
View
4 jstests/libs/geo_near_random.js
@@ -25,12 +25,12 @@ GeoNearRandomTest.prototype.mkPt = function mkPt(scale, indexBounds){
}
-GeoNearRandomTest.prototype.insertPts = function(nPts, indexBounds) {
+GeoNearRandomTest.prototype.insertPts = function(nPts, indexBounds, scale) {
assert.eq(this.nPts, 0, "insertPoints already called");
this.nPts = nPts;
for (var i=0; i<nPts; i++){
- this.t.insert({_id: i, loc: this.mkPt(undefined, indexBounds)});
+ this.t.insert({_id: i, loc: this.mkPt(scale, indexBounds)});
}
if(!indexBounds)
View
5 src/mongo/db/db.cpp
@@ -835,6 +835,11 @@ static int mongoDbMain(int argc, char* argv[]) {
out() << "repairpath is empty" << endl;
dbexit( EXIT_BADOPTIONS );
}
+
+ if (cmdLine.dur && !str::startsWith(repairpath, dbpath)) {
+ out() << "You must use a --repairpath that is a subdirectory of --dbpath when using journaling" << endl;
+ dbexit( EXIT_BADOPTIONS );
+ }
}
if (params.count("nohints")) {
useHints = false;
View
9 src/mongo/db/geo/2d.cpp
@@ -353,7 +353,14 @@ namespace mongo {
}
unsigned _convert( double in ) const {
- uassert( 13027 , str::stream() << "point not in interval of [ " << _min << ", " << _max << " )", in < _max && in >= _min );
+ uassert( 13027 , str::stream() << "point not in interval of [ " << _min << ", " << _max << " ]", in <= _max && in >= _min );
+
+ if (in == _max) {
+ // prevent aliasing with _min by moving inside the "box"
+ // makes 180 == 179.999 (roughly)
+ in -= _error / 2;
+ }
+
in -= _min;
verify( in >= 0 );
return (unsigned)(in * _scaling);
View
4 src/mongo/db/geo/core.h
@@ -506,8 +506,8 @@ namespace mongo {
// Technically lat/long bounds, not really tied to earth radius.
inline void checkEarthBounds( Point p ) {
- uassert( 14808, str::stream() << "point " << p.toString() << " must be in earth-like bounds of long : [-180, 180), lat : [-90, 90] ",
- p._x >= -180 && p._x < 180 && p._y >= -90 && p._y <= 90 );
+ uassert( 14808, str::stream() << "point " << p.toString() << " must be in earth-like bounds of long : [-180, 180], lat : [-90, 90] ",
+ p._x >= -180 && p._x <= 180 && p._y >= -90 && p._y <= 90 );
}
inline double deg2rad(double deg) { return deg * (M_PI/180); }
Please sign in to comment.
Something went wrong with that request. Please try again.