diff options
-rw-r--r-- | jstests/sharding/shard3.js | 15 | ||||
-rw-r--r-- | s/commands_admin.cpp | 31 | ||||
-rw-r--r-- | s/d_logic.cpp | 1 | ||||
-rw-r--r-- | shell/collection.js | 5 | ||||
-rw-r--r-- | shell/mongo.js | 9 | ||||
-rw-r--r-- | shell/servers.js | 19 |
6 files changed, 76 insertions, 4 deletions
diff --git a/jstests/sharding/shard3.js b/jstests/sharding/shard3.js index a956e1f3a1f..099304e9a02 100644 --- a/jstests/sharding/shard3.js +++ b/jstests/sharding/shard3.js @@ -49,24 +49,33 @@ secondary.save( { num : -3 } ); doCounts( "after wrong save" ) // --- move all to 1 --- +print( "MOVE ALL TO 1" ); assert.eq( 2 , s.onNumShards( "foo" ) , "on 2 shards" ); +s.printCollectionInfo( "test.foo" ); assert( a.findOne( { num : 1 } ) ) assert( b.findOne( { num : 1 } ) ) +print( "GOING TO MOVE" ); +s.printCollectionInfo( "test.foo" ); s.adminCommand( { movechunk : "test.foo" , find : { num : 1 } , to : s.getOther( s.getServer( "test" ) ).name } ); +s.printCollectionInfo( "test.foo" ); assert.eq( 1 , s.onNumShards( "foo" ) , "on 1 shard again" ); assert( a.findOne( { num : 1 } ) ) assert( b.findOne( { num : 1 } ) ) -// ---- drop ---- +print( "*** drop" ); +s.printCollectionInfo( "test.foo" , "before drop" ); a.drop(); +s.printCollectionInfo( "test.foo" , "after drop" ); assert.eq( 0 , a.count() , "a count after drop" ) assert.eq( 0 , b.count() , "b count after drop" ) +s.printCollectionInfo( "test.foo" , "after counts" ); + assert.eq( 0 , primary.count() , "p count after drop" ) assert.eq( 0 , secondary.count() , "s count after drop" ) @@ -76,7 +85,9 @@ secondary.save( { num : 4 } ); assert.eq( 1 , primary.count() , "p count after drop adn save" ) assert.eq( 1 , secondary.count() , "s count after drop save " ) -// this makes sure that sharding knows where things live + +print("*** makes sure that sharding knows where things live" ); + assert.eq( 1 , a.count() , "a count after drop and save" ) assert.eq( 1 , b.count() , "b count after drop and save" ) assert( a.findOne( { num : 1 } ) , "a drop1" ); diff --git a/s/commands_admin.cpp b/s/commands_admin.cpp index 2b1f8ca13c3..854d729015f 100644 --- a/s/commands_admin.cpp +++ b/s/commands_admin.cpp @@ -293,6 +293,37 @@ namespace mongo { } } shardCollectionCmd; + class GetShardVersion : public GridAdminCmd { + public: + GetShardVersion() : GridAdminCmd( "getShardVersion" ){} + virtual void help( stringstream& help ) const { + help << " example: { getShardVersion : 'alleyinsider.foo' } "; + } + + bool run(const char *cmdns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){ + string ns = cmdObj["getShardVersion"].valuestrsafe(); + if ( ns.size() == 0 ){ + errmsg = "need to speciy fully namespace"; + return false; + } + + DBConfig * config = grid.getDBConfig( ns ); + if ( ! config->isSharded( ns ) ){ + errmsg = "ns not sharded."; + return false; + } + + ChunkManager * cm = config->getChunkManager( ns ); + if ( ! cm ){ + errmsg = "no chunk manager?"; + return false; + } + + result.appendTimestamp( "version" , cm->getVersion() ); + + return 1; + } + } getShardVersionCmd; class SplitCollectionHelper : public GridAdminCmd { public: diff --git a/s/d_logic.cpp b/s/d_logic.cpp index 05f1b838222..705a097e67a 100644 --- a/s/d_logic.cpp +++ b/s/d_logic.cpp @@ -235,7 +235,6 @@ namespace mongo { else result.appendTimestamp( "mine" , 0 ); - result.append( "ok" , 1 ); return true; } diff --git a/shell/collection.js b/shell/collection.js index b339e71a35e..8a2a1842e70 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -55,6 +55,7 @@ DBCollection.prototype.help = function(){ print("\tdb.foo.totalSize() - storage allocated for all data and indexes"); print("\tdb.foo.update(query, object[, upsert_bool])"); print("\tdb.foo.validate() - SLOW"); + print("\tdb.foo.getShardVersion() - only for use with sharding" ); } DBCollection.prototype.getFullName = function(){ @@ -327,6 +328,10 @@ DBCollection.prototype.validate = function() { return res; } +DBCollection.prototype.getShardVersion = function(){ + return this._db._adminCommand( { getShardVersion : this._fullName } ); +} + DBCollection.prototype.getIndexes = function(){ return this.getDB().getCollection( "system.indexes" ).find( { ns : this.getFullName() } ).toArray(); } diff --git a/shell/mongo.js b/shell/mongo.js index f9dacf66c22..78e3fa6c516 100644 --- a/shell/mongo.js +++ b/shell/mongo.js @@ -46,6 +46,15 @@ Mongo.prototype.getDBNames = function(){ ); } +Mongo.prototype.getCollection = function(ns){ + var idx = ns.indexOf( "." ); + if ( idx < 0 ) + throw "need . in ns"; + var db = ns.substring( 0 , idx ); + var c = ns.substring( idx + 1 ); + return this.getDB( db ).getCollection( c ); +} + Mongo.prototype.toString = function(){ return "mongo connection to " + this.host; } diff --git a/shell/servers.js b/shell/servers.js index b396479e4a8..b83675cadec 100644 --- a/shell/servers.js +++ b/shell/servers.js @@ -203,6 +203,23 @@ ShardingTest.prototype.printShardingStatus = function(){ printShardingStatus( this.config ); } +ShardingTest.prototype.printCollectionInfo = function( ns , msg ){ + var out = ""; + if ( msg ) + out += msg + "\n"; + out += "sharding collection info: " + ns + "\n"; + for ( var i=0; i<this._connections.length; i++ ){ + var c = this._connections[i]; + out += " mongod " + c + " " + tojson( c.getCollection( ns ).getShardVersion() , " " , true ) + "\n"; + } + for ( var i=0; i<this._mongos.length; i++ ){ + var c = this._mongos[i]; + out += " mongos " + c + " " + tojson( c.getCollection( ns ).getShardVersion() , " " , true ) + "\n"; + } + + print( out ); +} + printShardingStatus = function( configDB ){ var version = configDB.getCollection( "version" ).findOne(); @@ -240,7 +257,7 @@ printShardingStatus = function( configDB ){ ); } ); - + print( raw ); } |