Browse files

SERVER-7906 fix sharded geonear

  • Loading branch information...
1 parent 60c93ff commit 9783afcb785f4fe6d90377b84a895632e83a4388 Hari Khalsa committed Dec 12, 2012
Showing with 59 additions and 3 deletions.
  1. +50 −0 jstests/geo_shardedgeonear.js
  2. +9 −3 src/mongo/s/commands_public.cpp
View
50 jstests/geo_shardedgeonear.js
@@ -0,0 +1,50 @@
+// SERVER-7906
+load('jstests/libs/geo_near_random.js');
+
+var coll = 'points'
+
+function test(db, sharded, indexType) {
+ db[coll].drop();
+
+ if (sharded) {
+ var shards = []
+ var config = shardedDB.getSiblingDB("config");
+ config.shards.find().forEach(function(shard) { shards.push(shard._id) });
+
+ shardedDB.adminCommand({shardCollection: shardedDB[coll].getFullName(), key: {rand:1}});
+ for (var i=1; i < 10; i++) {
+ // split at 0.1, 0.2, ... 0.9
+ shardedDB.adminCommand({split: shardedDB[coll].getFullName(), middle: {rand: i/10}});
+ shardedDB.adminCommand({moveChunk: shardedDB[coll].getFullName(), find: {rand: i/10},
+ to: shards[i%shards.length]});
+ }
+
+ assert.eq(config.chunks.count({'ns': shardedDB[coll].getFullName()}), 10);
+ }
+
+ var pointMaker = new GeoNearRandomTest(coll);
+ var numPts = 10*1000;
+ for (var i=0; i < numPts; i++) {
+ db[coll].insert({rand:Math.random(), loc: pointMaker.mkPt()})
+ }
+ db.getLastError();
+ assert.eq(db[coll].count(), numPts);
+
+ db[coll].ensureIndex({loc: indexType})
+
+ var queryPoint = pointMaker.mkPt(0.25) // stick to center of map
+ geoCmd = {geoNear: coll, near: queryPoint, includeLocs: true};
+ assert.commandWorked(db.runCommand(geoCmd), tojson({sharded: sharded, indexType: indexType}));
+}
+
+var sharded = new ShardingTest({shards: 3, verbose: 0, mongos: 1});
+sharded.stopBalancer();
+sharded.adminCommand( { enablesharding : "test" } );
+var shardedDB = sharded.getDB('test');
+
+
+test(db, false, '2d');
+test(db, false, '2dsphere');
+test(shardedDB, true, '2d');
+test(shardedDB, true, '2dsphere');
+sharded.stop();
View
12 src/mongo/s/commands_public.cpp
@@ -1233,11 +1233,17 @@ namespace mongo {
return false;
}
- nearStr = res->result()["near"].String();
+ if (res->result().hasField("near")) {
+ nearStr = res->result()["near"].String();
+ }
time += res->result()["stats"]["time"].Number();
- btreelocs += res->result()["stats"]["btreelocs"].Number();
+ if (!res->result()["stats"]["btreelocs"].eoo()) {
+ btreelocs += res->result()["stats"]["btreelocs"].Number();
+ }
nscanned += res->result()["stats"]["nscanned"].Number();
- objectsLoaded += res->result()["stats"]["objectsLoaded"].Number();
+ if (!res->result()["stats"]["objectsLoaded"].eoo()) {
+ objectsLoaded += res->result()["stats"]["objectsLoaded"].Number();
+ }
BSONForEach(obj, res->result()["results"].embeddedObject()) {
results.insert(make_pair(obj["dis"].Number(), obj.embeddedObject().getOwned()));

0 comments on commit 9783afc

Please sign in to comment.