Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-4388 update version of newly sharded collection on mongod prim…

…ary after first sharding
  • Loading branch information...
commit df84cb315987723fc3faff5cdd17dc46a6ca778a 1 parent 87374c2
Greg Studer authored andy10gen committed
Showing with 63 additions and 1 deletion.
  1. +39 −0 jstests/sharding/mongos_no_detect_sharding.js
  2. +24 −1 s/config.cpp
View
39 jstests/sharding/mongos_no_detect_sharding.js
@@ -0,0 +1,39 @@
+// Tests whether new sharding is detected on insert by mongos
+
+var st = new ShardingTest( name = "test", shards = 1, verbose = 2, mongos = 2, other = { separateConfig : true } )
+
+var mongos = st.s
+var config = mongos.getDB("config")
+
+config.settings.update({ _id : "balancer" }, { $set : { stopped : true } }, true )
+
+
+print( "Creating unsharded connection..." )
+
+
+var mongos2 = st._mongos[1]
+
+var coll = mongos2.getCollection( "test.foo" )
+coll.insert({ i : 0 })
+
+print( "Sharding collection..." )
+
+var admin = mongos.getDB("admin")
+
+admin.runCommand({ enableSharding : "test" })
+admin.runCommand({ shardCollection : "test.foo", key : { _id : 1 } })
+
+print( "Seeing if data gets inserted unsharded..." )
+print( "No splits occur here!" )
+
+// Insert a bunch of data which should trigger a split
+for( var i = 0; i < 100; i++ ){
+ coll.insert({ i : i + 1 })
+}
+coll.getDB().getLastError()
+
+config.printShardingStatus( true )
+
+assert.gt( config.chunks.find({ _id : /test.foo/ }).itcount(), 1 )
+
+st.stop()
View
25 s/config.cpp
@@ -150,7 +150,30 @@ namespace mongo {
_save();
}
- return getChunkManager(ns,true,true);
+ ChunkManagerPtr manager = getChunkManager(ns,true,true);
+
+ // Tell the primary mongod to refresh it's data
+ // TODO: Think the real fix here is for mongos to just assume all collections sharded, when we get there
+ for( int i = 0; i < 4; i++ ){
+ if( i == 3 ){
+ warning() << "too many tries updating initial version of " << ns << " on shard primary " << getPrimary() <<
+ ", other mongoses may not see the collection as sharded immediately" << endl;
+ break;
+ }
+ try {
+ ShardConnection conn( getPrimary(), ns );
+ conn.setVersion();
+ conn.done();
+ break;
+ }
+ catch( DBException& e ){
+ warning() << "could not update initial version of " << ns << " on shard primary " << getPrimary() <<
+ causedBy( e ) << endl;
+ }
+ sleepsecs( i );
+ }
+
+ return manager;
}
bool DBConfig::removeSharding( const string& ns ) {
Please sign in to comment.
Something went wrong with that request. Please try again.