summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2011-12-08 16:48:08 -0500
committerAndy Schwerin <schwerin@10gen.com>2012-04-19 15:31:56 -0400
commitdf84cb315987723fc3faff5cdd17dc46a6ca778a (patch)
tree68d64ff86330186f9bdd3eb79893c4c9968d612a
parent87374c2c5cb8a7cd8503d83c86913c94d375e7a8 (diff)
downloadmongo-df84cb315987723fc3faff5cdd17dc46a6ca778a.tar.gz
SERVER-4388 update version of newly sharded collection on mongod primary after first sharding
-rw-r--r--jstests/sharding/mongos_no_detect_sharding.js39
-rw-r--r--s/config.cpp25
2 files changed, 63 insertions, 1 deletions
diff --git a/jstests/sharding/mongos_no_detect_sharding.js b/jstests/sharding/mongos_no_detect_sharding.js
new file mode 100644
index 00000000000..61a094f51ec
--- /dev/null
+++ b/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() \ No newline at end of file
diff --git a/s/config.cpp b/s/config.cpp
index 9017eafbddd..8887c61a03b 100644
--- a/s/config.cpp
+++ b/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 ) {