summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2012-03-22 17:10:00 -0400
committerSpencer T Brody <spencer@10gen.com>2012-04-09 17:43:10 -0400
commitee33c0b90fd74c0c3c48e2437648b1c2f3339dc5 (patch)
tree4f44d787fda245f8ae38c671ebaadc190e6e9969
parent493a19e39fcd68f97ca47cdbc7b3b5f41ba3cb77 (diff)
downloadmongo-ee33c0b90fd74c0c3c48e2437648b1c2f3339dc5.tar.gz
Clean up ReplicaSetMonitor after failed addShard command. SERVER-4447.
-rw-r--r--jstests/sharding/addshard4.js6
-rw-r--r--src/mongo/client/dbclient_rs.cpp5
-rw-r--r--src/mongo/client/dbclient_rs.h7
-rw-r--r--src/mongo/s/grid.cpp3
4 files changed, 20 insertions, 1 deletions
diff --git a/jstests/sharding/addshard4.js b/jstests/sharding/addshard4.js
index 4a44b5537b2..ce459ac2824 100644
--- a/jstests/sharding/addshard4.js
+++ b/jstests/sharding/addshard4.js
@@ -17,9 +17,15 @@ var master = r.getMaster();
var members = config.members.map(function(elem) { return elem.host; });
var shardName = "addshard4/"+members.join(",");
+var invalidShardName = "addshard4/foobar";
print("adding shard "+shardName);
+// First try adding shard with the correct replica set name but incorrect hostname
+// This will make sure that the metadata for this replica set name is cleaned up
+// so that the set can be added correctly when it has the proper hostnames.
+assert.throws(function() {s.adminCommand({"addshard" : invalidShardName});});
+
var result = s.adminCommand({"addshard" : shardName});
printjson(result);
diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp
index ec6c349b44b..e6772303fc3 100644
--- a/src/mongo/client/dbclient_rs.cpp
+++ b/src/mongo/client/dbclient_rs.cpp
@@ -180,6 +180,11 @@ namespace mongo {
}
+ void ReplicaSetMonitor::remove( const string& name ) {
+ scoped_lock lk( _setsLock );
+ _sets.erase( name );
+ }
+
void ReplicaSetMonitor::setConfigChangeHook( ConfigChangeHook hook ) {
massert( 13610 , "ConfigChangeHook already specified" , _hook == 0 );
_hook = hook;
diff --git a/src/mongo/client/dbclient_rs.h b/src/mongo/client/dbclient_rs.h
index 3cf3d00b873..62fdd082dc6 100644
--- a/src/mongo/client/dbclient_rs.h
+++ b/src/mongo/client/dbclient_rs.h
@@ -63,7 +63,12 @@ namespace mongo {
static void checkAll( bool checkAllSecondaries );
/**
- * this is called whenever the config of any repclia set changes
+ * deletes the ReplicaSetMonitor for the given set name.
+ */
+ static void remove( const string& name );
+
+ /**
+ * this is called whenever the config of any replica set changes
* currently only 1 globally
* asserts if one already exists
* ownership passes to ReplicaSetMonitor and the hook will actually never be deleted
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index f3a8d9da29e..b19b359508d 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -278,6 +278,9 @@ namespace mongo {
newShardConn.done();
}
catch ( DBException& e ) {
+ if ( servers.type() == ConnectionString::SET ) {
+ ReplicaSetMonitor::remove( servers.getSetName() );
+ }
ostringstream ss;
ss << "couldn't connect to new shard ";
ss << e.what();