diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-04-09 17:05:00 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-04-10 16:29:38 -0400 |
commit | 8e6804d268895c01678a1a3d2feb57a82cafec62 (patch) | |
tree | ae85091e56240546aae3c92160fef1f8d64fcc6b /src/mongo/s/config.cpp | |
parent | cb236301e4016469c9b5c2802050e7bda08c33b9 (diff) | |
download | mongo-8e6804d268895c01678a1a3d2feb57a82cafec62.tar.gz |
SERVER-17723 Sharding catalog cache
This change builds a sharding catalog cache on top of the CatalogManager
abstraction and use this in place of the direct network calls to the
config server.
Diffstat (limited to 'src/mongo/s/config.cpp')
-rw-r--r-- | src/mongo/s/config.cpp | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp index 3da36a2e69a..1184e04625d 100644 --- a/src/mongo/s/config.cpp +++ b/src/mongo/s/config.cpp @@ -1,32 +1,30 @@ -// config.cpp - /** -* Copyright (C) 2008 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. -*/ + * Copyright (C) 2008-2015 MongoDB 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. + */ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding @@ -43,6 +41,7 @@ #include "mongo/db/lasterror.h" #include "mongo/db/server_options.h" #include "mongo/db/write_concern.h" +#include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/catalog/catalog_manager.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_shard.h" @@ -160,16 +159,12 @@ namespace mongo { _dirty = false; } + DBConfig::DBConfig(std::string name, const DatabaseType& dbt) + : _name(name) { - DBConfig::DBConfig(std::string name) - : _name(name), - _primary("config", "", 0 /* maxSize */, false /* draining */), - _shardingEnabled(false) { - invariant(!_name.empty()); - } - - DBConfig::~DBConfig() { - + invariant(_name == dbt.getName()); + _primary.reset(dbt.getPrimary()); + _shardingEnabled = dbt.getSharded(); } bool DBConfig::isSharded( const string& ns ) { @@ -401,7 +396,9 @@ namespace mongo { } } - ChunkManagerPtr DBConfig::getChunkManager( const string& ns , bool shouldReload, bool forceReload ) { + boost::shared_ptr<ChunkManager> DBConfig::getChunkManager(const string& ns, + bool shouldReload, + bool forceReload) { BSONObj key; ChunkVersion oldVersion; ChunkManagerPtr oldManager; @@ -637,12 +634,11 @@ namespace mongo { successful = _reload(); } - // // If we aren't successful loading the database entry, we don't want to keep the stale - // object around which has invalid data. We should remove it instead. - // - - if( ! successful ) grid.removeDBIfExists( *this ); + // object around which has invalid data. + if (!successful) { + grid.catalogCache()->invalidate(_name); + } return successful; } @@ -671,7 +667,7 @@ namespace mongo { } // 2 - grid.removeDB(_name); + grid.catalogCache()->invalidate(_name); Status result = grid.catalogManager()->remove(DatabaseType::ConfigNS, BSON(DatabaseType::name(_name)), @@ -777,8 +773,8 @@ namespace mongo { return true; } - void DBConfig::getAllShards(set<Shard>& shards) const { - boost::lock_guard<boost::mutex> lk( _lock ); + void DBConfig::getAllShards(set<Shard>& shards) { + boost::lock_guard<boost::mutex> lk(_lock); shards.insert(getPrimary()); for (CollectionInfoMap::const_iterator it(_collections.begin()), end(_collections.end()); it != end; ++it) { if (it->second.isSharded()) { @@ -787,9 +783,8 @@ namespace mongo { } } - void DBConfig::getAllShardedCollections( set<string>& namespaces ) const { - - boost::lock_guard<boost::mutex> lk( _lock ); + void DBConfig::getAllShardedCollections( set<string>& namespaces ) { + boost::lock_guard<boost::mutex> lk(_lock); for( CollectionInfoMap::const_iterator i = _collections.begin(); i != _collections.end(); i++ ) { log() << "Coll : " << i->first << " sharded? " << i->second.isSharded() << endl; @@ -805,6 +800,10 @@ namespace mongo { return _primary.getConnString(); } + ConnectionString ConfigServer::getConnectionString() const { + return ConnectionString(_primary.getConnString(), ConnectionString::SYNC); + } + bool ConfigServer::init( const std::string& s ) { vector<string> configdbs; splitStringDelim( s, &configdbs, ',' ); @@ -1264,5 +1263,5 @@ namespace mongo { } - ConfigServer& configServer = dynamic_cast<ConfigServer&>(*(new ConfigServer())); + ConfigServer& configServer = *(new ConfigServer()); } |