summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-08-03 18:12:35 -0400
committerEliot Horowitz <eliot@10gen.com>2010-08-03 18:12:35 -0400
commit82af423af6afb9b21afed478a18d816d87a92928 (patch)
treec61c3f6cda2ac0478deb8a20d63d7da55fd158a5
parentc1a0ce0228d75d62a10eeab6aa8aa0ee65b64958 (diff)
parent33c33be7576f0dac9059b30a1fca9d03ae1a7b5e (diff)
downloadmongo-82af423af6afb9b21afed478a18d816d87a92928.tar.gz
Merge branch 'master' of github.com:mongodb/mongo
-rw-r--r--db/repl/rs_sync.cpp2
-rw-r--r--jstests/sharding/stats.js60
-rw-r--r--s/chunk.cpp2
3 files changed, 63 insertions, 1 deletions
diff --git a/db/repl/rs_sync.cpp b/db/repl/rs_sync.cpp
index 8a23612d35d..d64dcd58639 100644
--- a/db/repl/rs_sync.cpp
+++ b/db/repl/rs_sync.cpp
@@ -38,6 +38,8 @@ namespace mongo {
nsToDatabase(ns, db);
if ( *ns == '.' || *ns == 0 ) {
+ if( *o.getStringField("op") == 'n' )
+ return;
log() << "replSet skipping bad op in oplog: " << o.toString() << endl;
return;
}
diff --git a/jstests/sharding/stats.js b/jstests/sharding/stats.js
new file mode 100644
index 00000000000..c75d208a728
--- /dev/null
+++ b/jstests/sharding/stats.js
@@ -0,0 +1,60 @@
+s = new ShardingTest( "stats" , 2 , 1 , 1 );
+s.adminCommand( { enablesharding : "test" } );
+
+a = s._connections[0].getDB( "test" );
+b = s._connections[1].getDB( "test" );
+
+db = s.getDB( "test" );
+
+function numKeys(o){
+ var num = 0;
+ for (var x in o)
+ num++;
+ return num;
+}
+
+// ---------- load some data -----
+
+// need collections sharded before and after main collection for proper test
+s.adminCommand( { shardcollection : "test.aaa" , key : { _id : 1 } } );
+s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } ); // this collection is actually used
+s.adminCommand( { shardcollection : "test.zzz" , key : { _id : 1 } } );
+
+
+N = 10000;
+s.adminCommand( { split : "test.foo" , middle : { _id : N/2 } } )
+s.adminCommand( { moveChunk : "test.foo", find : { _id : 3 } ,to : s.getNonPrimaries( "test" )[0] } )
+
+for ( i=0; i<N; i++ )
+ db.foo.insert( { _id : i } )
+db.getLastError();
+
+x = db.foo.stats();
+assert.eq( N , x.count , "coll total count expected" )
+assert.eq( db.foo.count() , x.count , "coll total count match" )
+assert.eq( 2 , x.nchunks , "coll chunk num" )
+assert.eq( 2 , numKeys(x.shards) , "coll shard num" )
+assert.eq( N / 2 , x.shards.shard0000.count , "coll count on shard0000 expected" )
+assert.eq( N / 2 , x.shards.shard0001.count , "coll count on shard0001 expected" )
+assert.eq( a.foo.count() , x.shards.shard0000.count , "coll count on shard0000 match" )
+assert.eq( b.foo.count() , x.shards.shard0001.count , "coll count on shard0001 match" )
+
+
+a_extras = a.stats().objects - a.foo.count(); // things like system.namespaces and system.indexes
+b_extras = b.stats().objects - b.foo.count(); // things like system.namespaces and system.indexes
+print("a_extras: " + a_extras);
+print("b_extras: " + b_extras);
+
+x = db.stats();
+
+//dbstats uses Future::CommandResult so raw output uses connection strings not shard names
+shards = Object.keySet(x.raw);
+
+assert.eq( N + (a_extras + b_extras) , x.objects , "db total count expected" )
+assert.eq( 2 , numKeys(x.raw) , "db shard num" )
+assert.eq( (N / 2) + a_extras, x.raw[shards[0]].objects , "db count on shard0000 expected" )
+assert.eq( (N / 2) + b_extras, x.raw[shards[1]].objects , "db count on shard0001 expected" )
+assert.eq( a.stats().objects , x.raw[shards[0]].objects , "db count on shard0000 match" )
+assert.eq( b.stats().objects , x.raw[shards[1]].objects , "db count on shard0001 match" )
+
+s.stop()
diff --git a/s/chunk.cpp b/s/chunk.cpp
index c2e0cc78e7c..5df3b6903ba 100644
--- a/s/chunk.cpp
+++ b/s/chunk.cpp
@@ -807,7 +807,7 @@ namespace mongo {
void ChunkManager::getAllShards( set<Shard>& all ){
rwlock lk( _lock , false );
- all = _shards;
+ all.insert(_shards.begin(), _shards.end());
}
void ChunkManager::ensureIndex_inlock(){