summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2013-02-28 17:01:56 -0500
committerSpencer T Brody <spencer@10gen.com>2013-03-01 14:06:30 -0500
commite528ff70fcc75984331612d20b0496dbb4fcf365 (patch)
treee9dc08c87a9dae4c8202c57ef18a35a7f3557c1b
parent77d55de67cf5700a4472d60ed2df4d7b5157de95 (diff)
downloadmongo-e528ff70fcc75984331612d20b0496dbb4fcf365.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.js47
-rw-r--r--src/mongo/s/d_logic.h5
-rw-r--r--src/mongo/s/d_migrate.cpp5
-rw-r--r--src/mongo/s/d_split.cpp3
-rw-r--r--src/mongo/s/d_state.cpp10
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 f1958c6dc77..c8fdb49b5f3 100644
--- a/src/mongo/s/d_logic.h
+++ b/src/mongo/s/d_logic.h
@@ -44,6 +44,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 06e6f6c002f..914b43b8b21 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -967,8 +967,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 );
@@ -2012,7 +2011,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 01e928a884e..0fc0b6e3458 100644
--- a/src/mongo/s/d_split.cpp
+++ b/src/mongo/s/d_split.cpp
@@ -555,8 +555,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 2736dd5c90e..6ea6ef58b7b 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -63,6 +63,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 ) {
@@ -478,9 +484,7 @@ namespace mongo {
}
if ( locked ) {
- ShardedConnectionInfo::addHook();
- shardingState.enable( configdb );
- configServer.init( configdb );
+ ShardingState::initialize(configdb);
return true;
}