diff options
author | Spencer T Brody <spencer@10gen.com> | 2013-02-28 17:01:56 -0500 |
---|---|---|
committer | Spencer T Brody <spencer@10gen.com> | 2013-03-01 14:17:01 -0500 |
commit | a332782ad86a83021103fbf3d6f542cb93687975 (patch) | |
tree | ed9d0569b2ddafd911827ea769f7b3e7e690c2c7 | |
parent | cd6d81d6db45da1df6ad5b357d23d7b1e2f514ca (diff) | |
download | mongo-a332782ad86a83021103fbf3d6f542cb93687975.tar.gz |
SERVER-8786 Make sure that the ShardingConnectionHook gets added to the connection pools anytime sharding is initialized
-rw-r--r-- | jstests/sharding/authConnectionHook.js | 47 | ||||
-rw-r--r-- | src/mongo/s/d_logic.h | 5 | ||||
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/d_split.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/d_state.cpp | 10 |
5 files changed, 62 insertions, 8 deletions
diff --git a/jstests/sharding/authConnectionHook.js b/jstests/sharding/authConnectionHook.js new file mode 100644 index 00000000000..03b65fee848 --- /dev/null +++ b/jstests/sharding/authConnectionHook.js @@ -0,0 +1,47 @@ +// Test for SERVER-8786 - if the first operation on an authenticated shard is moveChunk, it breaks the cluster. +var st = new ShardingTest({ keyFile : 'jstests/libs/key1', shards : 2, chunksize : 1, config : 3, verbose : 2, + other : { nopreallocj : 1, verbose : 2, useHostname : true, + configOptions : { verbose : 2 }}}); + +var mongos = st.s; +var adminDB = mongos.getDB('admin'); +var db = mongos.getDB('test') + +adminDB.addUser('admin', 'password'); + +adminDB.auth('admin', 'password'); + +adminDB.runCommand({enableSharding : "test"}); +adminDB.runCommand({shardCollection : "test.foo", key : {x : 1}}); + +for (var i = 0; i < 100; i++) { + db.foo.insert({x:i}); +} + +adminDB.runCommand({split: "test.foo", middle: {x:50}}); +var curShard = st.getShard("test.foo", {x:75}); +var otherShard = st.getOther(curShard).name; +adminDB.runCommand({moveChunk: "test.foo", find: {x:25}, to: otherShard}); + +st.printShardingStatus(); + +var savedOptions = st.shard0.savedOptions; +printjson(savedOptions); +savedOptions.restart = true; +MongoRunner.stopMongod(st.shard0.port); +MongoRunner.runMongod(savedOptions); + +// May fail the first couple times due to socket exceptions +assert.soon( function() { + var res = adminDB.runCommand({moveChunk: "test.foo", + find: {x:75}, + to: otherShard}); + printjson(res); + return res.ok; + }); + + +printjson(db.foo.findOne({x:25})); +printjson(db.foo.findOne({x:75})); + +st.stop();
\ No newline at end of file diff --git a/src/mongo/s/d_logic.h b/src/mongo/s/d_logic.h index cda29094597..dd43a9e2d77 100644 --- a/src/mongo/s/d_logic.h +++ b/src/mongo/s/d_logic.h @@ -45,6 +45,11 @@ namespace mongo { const string& getConfigServer() const { return _configServer; } void enable( const string& server ); + // Initialize sharding state and begin authenticating outgoing connections and handling + // shard versions. If this is not run before sharded operations occur auth will not work + // and versions will not be tracked. + static void initialize(const string& server); + void gotShardName( const string& name ); void gotShardHost( string host ); diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 4cd98e65791..6b25d257f54 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -866,8 +866,7 @@ namespace mongo { return false; } string configdb = cmdObj["configdb"].String(); - shardingState.enable( configdb ); - configServer.init( configdb ); + ShardingState::initialize(configdb); } MoveTimingHelper timing( "from" , ns , min , max , 6 /* steps */ , errmsg ); @@ -1879,7 +1878,7 @@ namespace mongo { } if ( ! configServer.ok() ) - configServer.init( cmdObj["configServer"].String() ); + ShardingState::initialize(cmdObj["configServer"].String()); migrateStatus.prepare(); diff --git a/src/mongo/s/d_split.cpp b/src/mongo/s/d_split.cpp index da7e063d6f9..6168429b4ef 100644 --- a/src/mongo/s/d_split.cpp +++ b/src/mongo/s/d_split.cpp @@ -523,8 +523,7 @@ namespace mongo { return false; } string configdb = cmdObj["configdb"].String(); - shardingState.enable( configdb ); - configServer.init( configdb ); + ShardingState::initialize(configdb); } Shard myShard( from ); diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index 556a090bbd3..025e877a9f4 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -60,6 +60,12 @@ namespace mongo { } } + void ShardingState::initialize(const string& server) { + ShardedConnectionInfo::addHook(); + shardingState.enable(server); + configServer.init(server); + } + void ShardingState::gotShardName( const string& name ) { scoped_lock lk(_mutex); if ( _shardName.size() == 0 ) { @@ -459,9 +465,7 @@ namespace mongo { } if ( locked ) { - ShardedConnectionInfo::addHook(); - shardingState.enable( configdb ); - configServer.init( configdb ); + ShardingState::initialize(configdb); return true; } |