diff options
author | gregs <greg@10gen.com> | 2011-11-21 13:23:13 -0500 |
---|---|---|
committer | gregs <greg@10gen.com> | 2011-11-21 14:53:26 -0500 |
commit | bc22bd44871ff4d7ab6ff406f341e8e86d039e2f (patch) | |
tree | 9b4047fbd123477550d20b8a7221e042c4d26db4 | |
parent | d69d52ceef293c7888eb9c507dacf40a48b8abe0 (diff) | |
download | mongo-bc22bd44871ff4d7ab6ff406f341e8e86d039e2f.tar.gz |
track initialization of conns SERVER-4324
-rw-r--r-- | s/shard_version.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/s/shard_version.cpp b/s/shard_version.cpp index 496b9828b18..9c550196ad3 100644 --- a/s/shard_version.cpp +++ b/s/shard_version.cpp @@ -56,6 +56,16 @@ namespace mongo { : _mutex( "ConnectionShardStatus" ) { } + bool isInitialized( DBClientBase * conn ){ + scoped_lock lk( _mutex ); + return _init.find( conn ) != _init.end(); + } + + void setInitialized( DBClientBase * conn ){ + scoped_lock lk( _mutex ); + _init.insert( conn ); + } + S getSequence( DBClientBase * conn , const string& ns ) { scoped_lock lk( _mutex ); return _map[conn][ns]; @@ -69,13 +79,15 @@ namespace mongo { void reset( DBClientBase * conn ) { scoped_lock lk( _mutex ); _map.erase( conn ); + _init.erase( conn ); } - // protects _map + // protects _maps mongo::mutex _mutex; // a map from a connection into ChunkManager's sequence number for each namespace map<DBClientBase*, map<string,unsigned long long> > _map; + set<DBClientBase*> _init; } connectionShardStatus; @@ -133,11 +145,15 @@ namespace mongo { LOG(2) << "initial sharding settings : " << cmd << endl; bool ok = conn->runCommand( "admin" , cmd , result ); + connectionShardStatus.setInitialized( conn ); // HACK for backwards compatibility with v1.8.x, v2.0.0 and v2.0.1 // Result is false, but will still initialize serverID and configdb + // Not master does not initialize serverID and configdb, but we ignore since if the connection is not master, + // we are not setting the shard version at all if( ! ok && ! result["errmsg"].eoo() && ( result["errmsg"].String() == "need to specify namespace"/* 2.0.1/2 */ || - result["errmsg"].String() == "need to speciy namespace" /* 1.8 */ )) + result["errmsg"].String() == "need to speciy namespace" /* 1.8 */ || + result["errmsg"].String() == "not master" /* both */ ) ) { ok = true; } @@ -163,6 +179,11 @@ namespace mongo { DBClientBase* conn = getVersionable( &conn_in ); assert(conn); // errors thrown above + if( ! connectionShardStatus.isInitialized( conn ) ){ + BSONObj result; + uassert( 15918, str::stream() << "cannot initialize version on shard " << conn->getServerAddress() << causedBy( result.toString() ), initShardVersion( *conn, result ) ); + } + unsigned long long officialSequenceNumber = 0; ChunkManagerPtr manager; |