summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-06-04 17:28:52 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-06-04 20:42:33 -0400
commit975319ad4e7af76ca288d2bcb65c94a4006c2d4d (patch)
tree8742e8d72c7ca1dd0c96258667d359f32ce51637
parent7b6724f3ad2600514c3ae5e59af873de75b026df (diff)
downloadmongo-975319ad4e7af76ca288d2bcb65c94a4006c2d4d.tar.gz
SERVER-18127 Remove all references to configServer
This change gets rid of all references to the global configServer variable. The class still remains with two static methods which will be distributed to Grid.
-rw-r--r--src/mongo/s/SConscript15
-rw-r--r--src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp2
-rw-r--r--src/mongo/s/catalog/type_chunk.cpp4
-rw-r--r--src/mongo/s/catalog/type_chunk.h21
-rw-r--r--src/mongo/s/catalog/type_collection.cpp14
-rw-r--r--src/mongo/s/catalog/type_collection.h7
-rw-r--r--src/mongo/s/catalog/type_shard.cpp14
-rw-r--r--src/mongo/s/catalog/type_shard.h43
-rw-r--r--src/mongo/s/client/shard_registry.cpp89
-rw-r--r--src/mongo/s/client/shard_registry.h12
-rw-r--r--src/mongo/s/collection_metadata.cpp25
-rw-r--r--src/mongo/s/collection_metadata_test.cpp37
-rw-r--r--src/mongo/s/commands/cluster_merge_chunks_cmd.cpp4
-rw-r--r--src/mongo/s/config.cpp154
-rw-r--r--src/mongo/s/config.h29
-rw-r--r--src/mongo/s/config_server_tests.cpp81
-rw-r--r--src/mongo/s/d_state.cpp3
-rw-r--r--src/mongo/s/server.cpp10
18 files changed, 110 insertions, 454 deletions
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index fb5b5ddc7a1..6fa24a749e5 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -288,21 +288,6 @@ env.CppUnitTest(
]
)
-env.CppUnitTest(
- target='config_server_tests',
- source=[
- 'config_server_tests.cpp',
- ],
- LIBDEPS=[
- "$BUILD_DIR/mongo/db/coredb",
- "$BUILD_DIR/mongo/db/auth/authorization_manager_mock_init",
- "$BUILD_DIR/mongo/util/net/message_server_port",
- "$BUILD_DIR/mongo/dbtests/mocklib",
- "coreshard",
- "mongoscore",
- ],
-)
-
env.Library(
target='serveronly',
source=[
diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
index 486ae2258e1..ad248266133 100644
--- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
+++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp
@@ -1148,7 +1148,9 @@ namespace {
if (!settingsResult.isOK()) {
return settingsResult.getStatus();
}
+
const SettingsType& settings = settingsResult.getValue();
+
Status validationStatus = settings.validate();
if (!validationStatus.isOK()) {
return validationStatus;
diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp
index dda684c8475..41498d5373a 100644
--- a/src/mongo/s/catalog/type_chunk.cpp
+++ b/src/mongo/s/catalog/type_chunk.cpp
@@ -197,10 +197,6 @@ namespace mongo {
return builder.obj();
}
- void ChunkType::clear() {
- *this = ChunkType();
- }
-
std::string ChunkType::toString() const {
return toBSON().toString();
}
diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h
index f742ddea19d..5945f722f6f 100644
--- a/src/mongo/s/catalog/type_chunk.h
+++ b/src/mongo/s/catalog/type_chunk.h
@@ -44,22 +44,6 @@ namespace mongo {
* This class represents the layout and contents of documents contained in the
* config.chunks collection. All manipulation of documents coming from that
* collection should be done with this class.
- *
- * Usage Example:
- *
- * // Contact the config. 'conn' has been obtained before.
- * DBClientBase* conn;
- * BSONObj query = QUERY(ChunkType::exampleField("exampleFieldName"));
- * exampleDoc = conn->findOne(ChunkType::ConfigNS, query);
- *
- * // Process the response.
- * StatusWith<ChunkType> exampleResult = ChunkType::fromBSON(exampleDoc);
- * if (!exampleResult.isOK()) {
- * // handle error -- exampleResult.getStatus()
- * }
- * ChunkType exampleType = exampleResult.getValue();
- * // use 'exampleType'
- *
*/
class ChunkType {
public:
@@ -97,11 +81,6 @@ namespace mongo {
BSONObj toBSON() const;
/**
- * Clears the internal state.
- */
- void clear();
-
- /**
* Returns a std::string representation of the current internal state.
*/
std::string toString() const;
diff --git a/src/mongo/s/catalog/type_collection.cpp b/src/mongo/s/catalog/type_collection.cpp
index 9594065fa82..fc19905254e 100644
--- a/src/mongo/s/catalog/type_collection.cpp
+++ b/src/mongo/s/catalog/type_collection.cpp
@@ -49,10 +49,6 @@ namespace mongo {
const BSONField<bool> CollectionType::dropped("dropped");
- CollectionType::CollectionType() {
- clear();
- }
-
StatusWith<CollectionType> CollectionType::fromBSON(const BSONObj& source) {
CollectionType coll;
@@ -207,16 +203,6 @@ namespace mongo {
return builder.obj();
}
- void CollectionType::clear() {
- _fullNs.reset();
- _epoch.reset();
- _updatedAt.reset();
- _keyPattern.reset();
- _unique.reset();
- _allowBalance.reset();
- _dropped.reset();
- }
-
std::string CollectionType::toString() const {
return toBSON().toString();
}
diff --git a/src/mongo/s/catalog/type_collection.h b/src/mongo/s/catalog/type_collection.h
index b0ad9e01c0e..12360d7fef3 100644
--- a/src/mongo/s/catalog/type_collection.h
+++ b/src/mongo/s/catalog/type_collection.h
@@ -60,8 +60,6 @@ namespace mongo {
static const BSONField<bool> dropped;
- CollectionType();
-
/**
* Constructs a new DatabaseType object from BSON. Also does validation of the contents.
*/
@@ -79,11 +77,6 @@ namespace mongo {
BSONObj toBSON() const;
/**
- * Clears the internal state.
- */
- void clear();
-
- /**
* Returns a std::string representation of the current internal state.
*/
std::string toString() const;
diff --git a/src/mongo/s/catalog/type_shard.cpp b/src/mongo/s/catalog/type_shard.cpp
index 7f2375ab873..68d9c3527e8 100644
--- a/src/mongo/s/catalog/type_shard.cpp
+++ b/src/mongo/s/catalog/type_shard.cpp
@@ -47,12 +47,6 @@ namespace mongo {
const BSONField<long long> ShardType::maxSize("maxSize");
const BSONField<BSONArray> ShardType::tags("tags");
- ShardType::ShardType() {
- clear();
- }
-
- ShardType::~ShardType() {
- }
StatusWith<ShardType> ShardType::fromBSON(const BSONObj& source) {
ShardType shard;
@@ -144,14 +138,6 @@ namespace mongo {
return builder.obj();
}
- void ShardType::clear() {
- _name.reset();
- _host.reset();
- _draining.reset();
- _maxSize.reset();
- _tags.reset();
- }
-
std::string ShardType::toString() const {
return toBSON().toString();
}
diff --git a/src/mongo/s/catalog/type_shard.h b/src/mongo/s/catalog/type_shard.h
index 1e6e75da8ad..06bf748d1e1 100644
--- a/src/mongo/s/catalog/type_shard.h
+++ b/src/mongo/s/catalog/type_shard.h
@@ -45,22 +45,6 @@ namespace mongo {
* This class represents the layout and contents of documents contained in the
* config.shards collection. All manipulation of documents coming from that
* collection should be done with this class.
- *
- * Usage Example:
- *
- * // Contact the config. 'conn' has been obtained before.
- * DBClientBase* conn;
- * BSONObj query = QUERY(ShardType::exampleField("exampleFieldName"));
- * exampleDoc = conn->findOne(ShardType::ConfigNS, query);
- *
- * // Process the response.
- * StatusWith<ShardType> exampleResult = ShardType::fromBSON(exampleDoc);
- * if (!exampleResult.isOK()) {
- * // handle error -- exampleResult.getStatus()
- * }
- * ShardType exampleType = exampleResult.getValue();
- * // use 'exampleType'
- *
*/
class ShardType {
public:
@@ -75,8 +59,6 @@ namespace mongo {
static const BSONField<long long> maxSize;
static const BSONField<BSONArray> tags;
- ShardType();
- ~ShardType();
/**
* Constructs a new ShardType object from BSON.
@@ -96,38 +78,25 @@ namespace mongo {
BSONObj toBSON() const;
/**
- * Clears the internal state.
- */
- void clear();
-
- /**
- * Copies all the fields present in 'this' to 'other'.
- */
- void cloneTo(ShardType* other) const;
-
- /**
* Returns a std::string representation of the current internal state.
*/
std::string toString() const;
- bool isNameSet() const { return _name.is_initialized(); }
const std::string& getName() const { return _name.get(); }
void setName(const std::string& name);
- bool isHostSet() const { return _host.is_initialized(); }
const std::string& getHost() const { return _host.get(); }
void setHost(const std::string& host);
- bool isDrainingSet() const { return _draining.is_initialized(); }
- bool getDraining() const { return _draining.get(); }
+ bool getDraining() const { return _draining.value_or(false); }
void setDraining(const bool draining);
- bool isMaxSizeSet() const { return _maxSize.is_initialized(); }
- long long getMaxSize() const { return _maxSize.get(); }
+ long long getMaxSize() const { return _maxSize.value_or(0); }
void setMaxSize(const long long maxSize);
- bool isTagsSet() const { return _tags.is_initialized(); }
- const std::vector<std::string>& getTags() const { return _tags.get(); }
+ const std::vector<std::string> getTags() const {
+ return _tags.value_or(std::vector<std::string>());
+ }
void setTags(const std::vector<std::string>& tags);
private:
@@ -137,7 +106,7 @@ namespace mongo {
boost::optional<std::string> _name;
// (M) connection string for the host(s)
boost::optional<std::string> _host;
- // (O) is it draining drunks?
+ // (O) is it draining chunks?
boost::optional<bool> _draining;
// (O) maximum allowed disk space in MB
boost::optional<long long> _maxSize;
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index ef00a1bb4fa..906c98e9436 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -67,55 +67,25 @@ namespace mongo {
boost::lock_guard<boost::mutex> lk(_mutex);
- // We use the _lookup table for all shards and for the primary config DB. The config DB
- // info, however, does not come from the ShardNS::shard. So when cleaning the _lookup table
- // we leave the config state intact. The rationale is that this way we could drop shards
- // that were removed without reinitializing the config DB information.
+ _lookup.clear();
+ _rsLookup.clear();
- ShardMap::iterator i = _lookup.find("config");
- if (i != _lookup.end()) {
- shared_ptr<Shard> config = i->second;
- _lookup.clear();
- _lookup["config"] = config;
- }
- else {
- _lookup.clear();
- }
+ ShardType configServerShard;
+ configServerShard.setName("config");
+ configServerShard.setHost(_catalogManager->connectionString().toString());
- _rsLookup.clear();
+ _addShard_inlock(configServerShard);
- for (const ShardType& shardData : shards) {
- uassertStatusOK(shardData.validate());
+ for (const ShardType& shardType : shards) {
+ uassertStatusOK(shardType.validate());
- // This validation should ideally go inside the ShardType::validate call. However,
- // doing it there would prevent us from loading previously faulty shard hosts, which
- // might have been stored (i.e., the entire getAllShards call would fail).
- auto shardHostStatus = ConnectionString::parse(shardData.getHost());
- if (!shardHostStatus.isOK()) {
- warning() << "Unable to parse shard host "
- << shardHostStatus.getStatus().toString();
+ // Skip the config host even if there is one left over from legacy installations. The
+ // config host is installed manually from the catalog manager data.
+ if (shardType.getName() == "config") {
+ continue;
}
- const ConnectionString& shardHost(shardHostStatus.getValue());
-
- shared_ptr<Shard> shard = boost::make_shared<Shard>(shardData.getName(),
- shardHost,
- shardData.getMaxSize(),
- shardData.getDraining());
- _lookup[shardData.getName()] = shard;
- _lookup[shardData.getHost()] = shard;
-
- if (shardHost.type() == ConnectionString::SET) {
- if (shardHost.getSetName().size()) {
- boost::lock_guard<boost::mutex> lk(_rsMutex);
- _rsLookup[shardHost.getSetName()] = shard;
- }
-
- vector<HostAndPort> servers = shardHost.getServers();
- for (unsigned i = 0; i < servers.size(); i++) {
- _lookup[servers[i].toString()] = shard;
- }
- }
+ _addShard_inlock(shardType);
}
}
@@ -132,7 +102,7 @@ namespace mongo {
}
Shard ShardRegistry::lookupRSName(const string& name) {
- boost::lock_guard<boost::mutex> lk(_rsMutex);
+ boost::lock_guard<boost::mutex> lk(_mutex);
ShardMap::iterator i = _rsLookup.find(name);
return (i == _rsLookup.end()) ? Shard::EMPTY : *(i->second.get());
@@ -223,6 +193,37 @@ namespace mongo {
result->append("map", b.obj());
}
+ void ShardRegistry::_addShard_inlock(const ShardType& shardType) {
+ // This validation should ideally go inside the ShardType::validate call. However, doing
+ // it there would prevent us from loading previously faulty shard hosts, which might have
+ // been stored (i.e., the entire getAllShards call would fail).
+ auto shardHostStatus = ConnectionString::parse(shardType.getHost());
+ if (!shardHostStatus.isOK()) {
+ warning() << "Unable to parse shard host "
+ << shardHostStatus.getStatus().toString();
+ }
+
+ const ConnectionString& shardHost(shardHostStatus.getValue());
+
+ shared_ptr<Shard> shard = boost::make_shared<Shard>(shardType.getName(),
+ shardHost,
+ shardType.getMaxSize(),
+ shardType.getDraining());
+ _lookup[shardType.getName()] = shard;
+ _lookup[shardType.getHost()] = shard;
+
+ if (shardHost.type() == ConnectionString::SET) {
+ if (shardHost.getSetName().size()) {
+ _rsLookup[shardHost.getSetName()] = shard;
+ }
+
+ vector<HostAndPort> servers = shardHost.getServers();
+ for (unsigned i = 0; i < servers.size(); i++) {
+ _lookup[servers[i].toString()] = shard;
+ }
+ }
+ }
+
shared_ptr<Shard> ShardRegistry::_findUsingLookUp(const string& shardName) {
boost::lock_guard<boost::mutex> lk(_mutex);
ShardMap::iterator it = _lookup.find(shardName);
diff --git a/src/mongo/s/client/shard_registry.h b/src/mongo/s/client/shard_registry.h
index 6b7cf4bb58c..3c0a1222dbe 100644
--- a/src/mongo/s/client/shard_registry.h
+++ b/src/mongo/s/client/shard_registry.h
@@ -38,7 +38,7 @@ namespace mongo {
class BSONObjBuilder;
class CatalogManager;
class Shard;
-
+ class ShardType;
/**
* Maintains the set of all shards known to the MongoS instance.
@@ -73,6 +73,11 @@ namespace mongo {
typedef std::map<std::string, boost::shared_ptr<Shard>> ShardMap;
+ /**
+ * Creates a shard based on the specified information and puts it into the lookup maps.
+ */
+ void _addShard_inlock(const ShardType& shardType);
+
boost::shared_ptr<Shard> _findUsingLookUp(const std::string& shardName);
@@ -80,12 +85,13 @@ namespace mongo {
// the shard registry object.
CatalogManager* const _catalogManager;
- // Map of both shardName -> Shard and hostName -> Shard
+ // Protects the maps below
mutable boost::mutex _mutex;
+
+ // Map of both shardName -> Shard and hostName -> Shard
ShardMap _lookup;
// Map from ReplSet name to shard
- mutable boost::mutex _rsMutex;
ShardMap _rsLookup;
};
diff --git a/src/mongo/s/collection_metadata.cpp b/src/mongo/s/collection_metadata.cpp
index 6bc695c6e68..de9e05ebca4 100644
--- a/src/mongo/s/collection_metadata.cpp
+++ b/src/mongo/s/collection_metadata.cpp
@@ -498,22 +498,25 @@ namespace mongo {
}
bool CollectionMetadata::getNextChunk( const BSONObj& lookupKey, ChunkType* chunk ) const {
-
- RangeMap::const_iterator upperChunkIt = _chunksMap.upper_bound( lookupKey );
+ RangeMap::const_iterator upperChunkIt = _chunksMap.upper_bound(lookupKey);
RangeMap::const_iterator lowerChunkIt = upperChunkIt;
- if ( upperChunkIt != _chunksMap.begin() ) --lowerChunkIt;
- else lowerChunkIt = _chunksMap.end();
- if ( lowerChunkIt != _chunksMap.end() &&
- lowerChunkIt->second.woCompare( lookupKey ) > 0 ) {
- chunk->setMin( lowerChunkIt->first );
- chunk->setMax( lowerChunkIt->second );
+ if (upperChunkIt != _chunksMap.begin()) {
+ --lowerChunkIt;
+ }
+ else {
+ lowerChunkIt = _chunksMap.end();
+ }
+
+ if (lowerChunkIt != _chunksMap.end() && lowerChunkIt->second.woCompare(lookupKey) > 0) {
+ chunk->setMin(lowerChunkIt->first);
+ chunk->setMax(lowerChunkIt->second);
return true;
}
- if ( upperChunkIt != _chunksMap.end() ) {
- chunk->setMin( upperChunkIt->first );
- chunk->setMax( upperChunkIt->second );
+ if (upperChunkIt != _chunksMap.end()) {
+ chunk->setMin(upperChunkIt->first);
+ chunk->setMax(upperChunkIt->second);
return true;
}
diff --git a/src/mongo/s/collection_metadata_test.cpp b/src/mongo/s/collection_metadata_test.cpp
index 2f5f19210a7..cb8bdfebc02 100644
--- a/src/mongo/s/collection_metadata_test.cpp
+++ b/src/mongo/s/collection_metadata_test.cpp
@@ -650,27 +650,24 @@ namespace {
}
TEST_F(SingleChunkFixture, SingleSplit) {
- string errMsg;
- ChunkType chunk;
- scoped_ptr<CollectionMetadata> cloned;
-
- chunk.setMin( BSON("a" << 10) );
- chunk.setMax( BSON("a" << 20) );
-
- vector<BSONObj> splitPoints;
- splitPoints.push_back( BSON("a" << 14) );
-
ChunkVersion version;
- getCollMetadata().getCollVersion().cloneTo( &version );
+ getCollMetadata().getCollVersion().cloneTo(&version);
version.incMinor();
- cloned.reset( getCollMetadata().cloneSplit( chunk,
- splitPoints,
- version,
- &errMsg ) );
+ ChunkType chunk;
+ chunk.setMin(BSON("a" << 10));
+ chunk.setMax(BSON("a" << 20));
- ASSERT_EQUALS( errMsg, "" );
- ASSERT( cloned != NULL );
+ vector<BSONObj> splitPoints;
+ splitPoints.push_back(BSON("a" << 14));
+
+ string errMsg;
+ scoped_ptr<CollectionMetadata> cloned(getCollMetadata().cloneSplit(chunk,
+ splitPoints,
+ version,
+ &errMsg));
+ ASSERT_EQUALS(errMsg, "");
+ ASSERT(cloned != NULL);
ChunkVersion newVersion( cloned->getCollVersion() );
ASSERT_EQUALS( version.epoch(), newVersion.epoch() );
@@ -681,12 +678,10 @@ namespace {
ASSERT( chunk.getMin().woCompare( BSON("a" << 10) ) == 0 );
ASSERT( chunk.getMax().woCompare( BSON("a" << 14) ) == 0 );
- chunk.clear();
ASSERT( cloned->getNextChunk(BSON("a" << 14), &chunk) );
ASSERT( chunk.getMin().woCompare( BSON("a" << 14) ) == 0 );
ASSERT( chunk.getMax().woCompare( BSON("a" << 20) ) == 0 );
- chunk.clear();
ASSERT_FALSE( cloned->getNextChunk(BSON("a" << 20), &chunk) );
}
@@ -719,22 +714,18 @@ namespace {
ASSERT_EQUALS( version.majorVersion(), newVersion.majorVersion() );
ASSERT_EQUALS( version.minorVersion() + 2, newVersion.minorVersion() );
- chunk.clear();
ASSERT( cloned->getNextChunk(BSON("a" << MINKEY), &chunk) );
ASSERT( chunk.getMin().woCompare( BSON("a" << 10) ) == 0 );
ASSERT( chunk.getMax().woCompare( BSON("a" << 14) ) == 0 );
- chunk.clear();
ASSERT( cloned->getNextChunk(BSON("a" << 14), &chunk) );
ASSERT( chunk.getMin().woCompare( BSON("a" << 14) ) == 0 );
ASSERT( chunk.getMax().woCompare( BSON("a" << 16) ) == 0 );
- chunk.clear();
ASSERT( cloned->getNextChunk(BSON("a" << 16), &chunk) );
ASSERT( chunk.getMin().woCompare( BSON("a" << 16) ) == 0 );
ASSERT( chunk.getMax().woCompare( BSON("a" << 20) ) == 0 );
- chunk.clear();
ASSERT_FALSE( cloned->getNextChunk(BSON("a" << 20), &chunk) );
}
diff --git a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp
index ee00655cf5a..fa26e05f25c 100644
--- a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp
+++ b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp
@@ -38,10 +38,10 @@
#include "mongo/db/field_parser.h"
#include "mongo/db/namespace_string.h"
#include "mongo/s/catalog/catalog_cache.h"
+#include "mongo/s/catalog/catalog_manager.h"
#include "mongo/s/chunk_manager.h"
#include "mongo/s/config.h"
#include "mongo/s/grid.h"
-#include "mongo/s/client/shard.h"
namespace mongo {
@@ -169,7 +169,7 @@ namespace {
remoteCmdObjB.append( cmdObj[ ClusterMergeChunksCommand::nsField() ] );
remoteCmdObjB.append( cmdObj[ ClusterMergeChunksCommand::boundsField() ] );
remoteCmdObjB.append( ClusterMergeChunksCommand::configField(),
- configServer.getPrimary().getConnString().toString() );
+ grid.catalogManager()->connectionString().toString() );
remoteCmdObjB.append( ClusterMergeChunksCommand::shardNameField(),
shard.getName() );
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index e54d37e5fb5..e12f39e4556 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -664,133 +664,17 @@ namespace mongo {
/* --- ConfigServer ---- */
- bool ConfigServer::init( const ConnectionString& configCS ) {
- invariant(configCS.isValid());
-
- std::vector<HostAndPort> configHostAndPorts = configCS.getServers();
- uassert( 10187 , "need configdbs" , configHostAndPorts.size() );
-
- std::vector<std::string> configHosts;
- set<string> hosts;
- for ( size_t i=0; i<configHostAndPorts.size(); i++ ) {
- string host = configHostAndPorts[i].toString();
- hosts.insert( getHost( host , false ) );
- configHosts.push_back(getHost( host , true ));
- }
-
- for ( set<string>::iterator i=hosts.begin(); i!=hosts.end(); i++ ) {
-
- string host = *i;
-
- // If this is a CUSTOM connection string (for testing) don't do DNS resolution
- string errMsg;
- if ( ConnectionString::parse( host, errMsg ).type() == ConnectionString::CUSTOM ) {
- continue;
- }
-
- bool ok = false;
- for ( int x=10; x>0; x-- ) {
- if ( ! hostbyname( host.c_str() ).empty() ) {
- ok = true;
- break;
- }
- log() << "can't resolve DNS for [" << host << "] sleeping and trying " << x << " more times" << endl;
- sleepsecs( 10 );
- }
- if ( ! ok )
- return false;
- }
-
- _config = configHosts;
-
- string errmsg;
- if( ! checkHostsAreUnique(configHosts, &errmsg) ) {
- error() << errmsg << endl;;
- return false;
- }
-
- // This should be the first time we are trying to set up the primary shard (i.e. init
- // should be called only once)
- invariant(_primary == Shard::EMPTY);
- _primary = Shard("config", configCS, 0, false);
-
- Shard::installShard("config", _primary);
-
- LOG(1) << " config string : " << configCS.toString();
-
- return true;
- }
-
- bool ConfigServer::checkHostsAreUnique( const vector<string>& configHosts, string* errmsg ) {
-
- //If we have one host, its always unique
- if ( configHosts.size() == 1 ) {
- return true;
- }
-
- //Compare each host with all other hosts.
- set<string> hostsTest;
- pair<set<string>::iterator,bool> ret;
- for ( size_t x=0; x < configHosts.size(); x++) {
- ret = hostsTest.insert( configHosts[x] );
- if ( ret.second == false ) {
- *errmsg = str::stream() << "config servers " << configHosts[x]
- << " exists twice in config listing.";
- return false;
- }
- }
- return true;
- }
-
void ConfigServer::reloadSettings() {
- set<string> got;
+ auto chunkSize = grid.catalogManager()->getGlobalSettings(SettingsType::ChunkSizeDocKey);
+ if (chunkSize.isOK()) {
+ const int csize = chunkSize.getValue().getChunkSize();
+ LOG(1) << "Found MaxChunkSize: " << csize;
- try {
- ScopedDbConnection conn(_primary.getConnString(), 30.0);
- auto_ptr<DBClientCursor> cursor = conn->query(SettingsType::ConfigNS, BSONObj());
- verify(cursor.get());
-
- while (cursor->more()) {
- StatusWith<SettingsType> settingsResult =
- SettingsType::fromBSON(cursor->nextSafe());
- if (!settingsResult.isOK()) {
- warning() << settingsResult.getStatus();
- continue;
- }
- SettingsType settings = settingsResult.getValue();
- string key = settings.getKey();
- got.insert(key);
-
- if (key == SettingsType::ChunkSizeDocKey) {
- int csize = settings.getChunkSize();
-
- // validate chunksize before proceeding
- if (csize == 0) {
- // setting was not modified; mark as such
- got.erase(key);
- log() << "warning: invalid chunksize (" << csize << ") ignored" << endl;
- } else {
- LOG(1) << "MaxChunkSize: " << csize << endl;
- if (!Chunk::setMaxChunkSizeSizeMB(csize)) {
- warning() << "invalid chunksize: " << csize << endl;
- }
- }
- }
- else if (key == SettingsType::BalancerDocKey) {
- // ones we ignore here
- }
- else {
- log() << "warning: unknown setting [" << key << "]";
- }
+ if (!Chunk::setMaxChunkSizeSizeMB(csize)) {
+ warning() << "invalid chunksize: " << csize;
}
-
- conn.done();
- }
- catch (const DBException& ex) {
- warning() << "couldn't load settings on config db" << causedBy(ex);
}
-
- if (!got.count(SettingsType::ChunkSizeDocKey)) {
+ else if (chunkSize == ErrorCodes::NoSuchKey) {
const int chunkSize = Chunk::MaxChunkSize / (1024 * 1024);
Status result =
grid.catalogManager()->insert(SettingsType::ConfigNS,
@@ -801,6 +685,9 @@ namespace mongo {
warning() << "couldn't set chunkSize on config db" << causedBy(result);
}
}
+ else {
+ warning() << "couldn't load settings on config db: " << chunkSize.getStatus();
+ }
// indexes
Status result = clusterCreateIndex( ChunkType::ConfigNS,
@@ -883,25 +770,10 @@ namespace mongo {
}
}
- string ConfigServer::getHost( const std::string& name , bool withPort ) {
- if ( name.find( ":" ) != string::npos ) {
- if ( withPort )
- return name;
- return name.substr( 0 , name.find( ":" ) );
- }
-
- if ( withPort ) {
- stringstream ss;
- ss << name << ":" << ServerGlobalParams::ConfigServerPort;
- return ss.str();
- }
-
- return name;
- }
-
void ConfigServer::replicaSetChange(const string& setName, const string& newConnectionString) {
// This is run in it's own thread. Exceptions escaping would result in a call to terminate.
Client::initThread("replSetChange");
+
try {
Shard s = Shard::lookupRSName(setName);
if (s == Shard::EMPTY) {
@@ -932,6 +804,4 @@ namespace mongo {
}
}
-
- ConfigServer& configServer = *(new ConfigServer());
-}
+} // namespace mongo
diff --git a/src/mongo/s/config.h b/src/mongo/s/config.h
index 3d46baff52e..c45c9d9cc6d 100644
--- a/src/mongo/s/config.h
+++ b/src/mongo/s/config.h
@@ -180,33 +180,10 @@ namespace mongo {
class ConfigServer {
public:
- ConfigServer() = default;
+ static void reloadSettings();
- bool ok( bool checkConsistency = false );
-
- const Shard& getPrimary() const { return _primary; }
-
- /**
- call at startup, this will initiate connection to the grid db
- */
- bool init( const ConnectionString& configCS );
-
- /**
- * Check hosts are unique. Returns true if all configHosts
- * hostname:port entries are unique. Otherwise return false
- * and fill errmsg with message containing the offending server.
- */
- bool checkHostsAreUnique( const std::vector<std::string>& configHosts, std::string* errmsg );
-
- void reloadSettings();
-
- void replicaSetChange(const std::string& setName, const std::string& newConnectionString);
-
- private:
- std::string getHost( const std::string& name , bool withPort );
-
- std::vector<std::string> _config;
- Shard _primary;
+ static void replicaSetChange(const std::string& setName,
+ const std::string& newConnectionString);
};
} // namespace mongo
diff --git a/src/mongo/s/config_server_tests.cpp b/src/mongo/s/config_server_tests.cpp
deleted file mode 100644
index 3e835cff8bb..00000000000
--- a/src/mongo/s/config_server_tests.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-// config_server_tests.cpp
-
-/**
-* Copyright (C) 2013 10gen Inc.
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU Affero General Public License, version 3,
-* as published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU Affero General Public License for more details.
-*
-* You should have received a copy of the GNU Affero General Public License
-* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*
-* As a special exception, the copyright holders give permission to link the
-* code of portions of this program with the OpenSSL library under certain
-* conditions as described in each individual source file and distribute
-* linked combinations including the program with the OpenSSL library. You
-* must comply with the GNU Affero General Public License in all respects
-* for all of the code used other than as permitted herein. If you modify
-* file(s) with this exception, you may extend this exception to your
-* version of the file(s), but you are not obligated to do so. If you do not
-* wish to do so, delete this exception statement from your version. If you
-* delete this exception statement from all source files in the program,
-* then also delete it in the license file.
-*/
-
-#include "mongo/s/config.h"
-#include "mongo/unittest/unittest.h"
-
-namespace mongo {
-
-namespace {
-
- using std::string;
- using std::vector;
-
- ConfigServer configServer;
- const string serverUrl1 = "server1:27001";
- const string serverUrl2 = "server2:27002";
- const string serverUrl3 = "server3:27003";
-
- TEST(sharding, ConfigHostCheck3Different) {
-
- //Test where all three are different - Expected to return true
- vector<string> configHosts;
- string errmsg1;
- configHosts.push_back(serverUrl1);
- configHosts.push_back(serverUrl2);
- configHosts.push_back(serverUrl3);
- ASSERT_TRUE(configServer.checkHostsAreUnique(configHosts, &errmsg1));
- ASSERT_TRUE(errmsg1.empty());
- }
-
- TEST(sharding, ConfigHostCheckOneHost) {
-
- //Test short circuit with one Host - Expected to return true
- vector<string> configHosts;
- string errmsg2;
- configHosts.push_back(serverUrl2);
- ASSERT_TRUE(configServer.checkHostsAreUnique(configHosts, &errmsg2));
- ASSERT_TRUE(errmsg2.empty());
- }
-
- TEST(sharding, ConfigHostCheckTwoIdentical) {
- //Test with two identical hosts - Expected to return false
- vector<string> configHosts;
- string errmsg3;
- configHosts.push_back(serverUrl1);
- configHosts.push_back(serverUrl2);
- configHosts.push_back(serverUrl2);
- ASSERT_FALSE(configServer.checkHostsAreUnique(configHosts, &errmsg3));
- ASSERT_FALSE(errmsg3.empty());
- }
-
-} // unnamed namespace
-
-} // namespace mongo
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index c41f4502877..42172bb8b18 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -487,9 +487,8 @@ namespace mongo {
auto catalogManager = stdx::make_unique<CatalogManagerLegacy>();
uassertStatusOK(catalogManager->init(configServerCS));
- grid.setCatalogManager(std::move(catalogManager));
- configServer.init(configServerCS);
+ grid.setCatalogManager(std::move(catalogManager));
_enabled = true;
}
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 073422a48c7..2c5aae6f9ad 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -211,8 +211,7 @@ static ExitCode runMongosServer( bool doUpgrade ) {
// Mongos shouldn't lazily kill cursors, otherwise we can end up with extras from migration
DBClientConnection::setLazyKillCursor( false );
- ReplicaSetMonitor::setConfigChangeHook(
- stdx::bind(&ConfigServer::replicaSetChange, &configServer, stdx::placeholders::_1 , stdx::placeholders::_2));
+ ReplicaSetMonitor::setConfigChangeHook(&ConfigServer::replicaSetChange);
// Mongos connection pools already takes care of authenticating new connections so the
// replica set connection shouldn't need to.
@@ -253,12 +252,7 @@ static ExitCode runMongosServer( bool doUpgrade ) {
grid.setCatalogManager(std::move(catalogManager));
- if (!configServer.init(mongosGlobalParams.configdbs)) {
- mongo::log(LogComponent::kSharding) << "couldn't resolve config db address";
- return EXIT_SHARDING_ERROR;
- }
-
- configServer.reloadSettings();
+ ConfigServer::reloadSettings();
#if !defined(_WIN32)
mongo::signalForkSuccess();