diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-07-15 16:42:21 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-07-16 16:18:09 -0400 |
commit | ea73cdf50ede2622c9e005eb6e51cdc6ccb60650 (patch) | |
tree | c4e55e6da208cb9fc90a648835d93f3603534fad /src/mongo/s/version_manager.cpp | |
parent | 0254cdbc2d5f04188e45fe98dec1ca985e2ecf0c (diff) | |
download | mongo-ea73cdf50ede2622c9e005eb6e51cdc6ccb60650.tar.gz |
SERVER-18567 Move Future under the mongos commands
The future class and spawnCommand are only needed for sharding commands,
so this change moves them under cluster_commands_common.
Also moves setShardVersion to be under the version manager.
No functional changes.
Diffstat (limited to 'src/mongo/s/version_manager.cpp')
-rw-r--r-- | src/mongo/s/version_manager.cpp | 128 |
1 files changed, 89 insertions, 39 deletions
diff --git a/src/mongo/s/version_manager.cpp b/src/mongo/s/version_manager.cpp index 17c624e541d..d67de5bf69c 100644 --- a/src/mongo/s/version_manager.cpp +++ b/src/mongo/s/version_manager.cpp @@ -56,8 +56,7 @@ using std::endl; using std::map; using std::string; -// Global version manager -VersionManager versionManager; +namespace { /** * Tracking information, per-connection, of the latest chunk manager iteration or sequence @@ -65,7 +64,8 @@ VersionManager versionManager; * When the chunk manager is replaced, implying new versions were loaded, the chunk manager * sequence number is iterated by 1 and connections need to re-send shard versions. */ -struct ConnectionShardStatus { +class ConnectionShardStatus { +public: bool hasAnySequenceSet(DBClientBase* conn) { stdx::lock_guard<stdx::mutex> lk(_mutex); @@ -98,6 +98,7 @@ struct ConnectionShardStatus { _map.erase(conn->getConnectionId()); } +private: // protects _map stdx::mutex _mutex; @@ -107,19 +108,50 @@ struct ConnectionShardStatus { } connectionShardStatus; -void VersionManager::resetShardVersionCB(DBClientBase* conn) { - connectionShardStatus.reset(conn); -} +/** + * Sends the setShardVersion command on the specified connection. + */ +bool setShardVersion(DBClientBase& conn, + const string& ns, + const string& configServerPrimary, + ChunkVersion version, + ChunkManager* manager, + bool authoritative, + BSONObj& result) { + BSONObjBuilder cmdBuilder; + cmdBuilder.append("setShardVersion", ns); + cmdBuilder.append("configdb", configServerPrimary); + + ShardId shardId; + { + const auto shard = grid.shardRegistry()->getShard(conn.getServerAddress()); + shardId = shard->getId(); + cmdBuilder.append("shard", shardId); + cmdBuilder.append("shardHost", shard->getConnString().toString()); + } -bool VersionManager::isVersionableCB(DBClientBase* conn) { - // We do not version shard connections when issued from mongod - if (!isMongos()) { - return false; + if (ns.size() > 0) { + version.addToBSON(cmdBuilder); + } else { + cmdBuilder.append("init", true); } - return conn->type() == ConnectionString::MASTER || conn->type() == ConnectionString::SET; + if (authoritative) { + cmdBuilder.appendBool("authoritative", 1); + } + + BSONObj cmd = cmdBuilder.obj(); + + LOG(1) << " setShardVersion " << shardId << " " << conn.getServerAddress() << " " << ns + << " " << cmd + << (manager ? string(str::stream() << " " << manager->getSequenceNumber()) : ""); + + return conn.runCommand("admin", cmd, result, 0); } +/** + * Checks whether the specified connection supports versioning. + */ DBClientBase* getVersionable(DBClientBase* conn) { switch (conn->type()) { case ConnectionString::INVALID: @@ -150,32 +182,6 @@ DBClientBase* getVersionable(DBClientBase* conn) { MONGO_UNREACHABLE; } -bool VersionManager::forceRemoteCheckShardVersionCB(const string& ns) { - const NamespaceString nss(ns); - - // This will force the database catalog entry to be reloaded - grid.catalogCache()->invalidate(nss.db().toString()); - - auto status = grid.catalogCache()->getDatabase(nss.db().toString()); - if (!status.isOK()) { - return false; - } - - shared_ptr<DBConfig> conf = status.getValue(); - - // If we don't have a collection, don't refresh the chunk manager - if (nsGetCollection(ns).size() == 0) { - return false; - } - - ChunkManagerPtr manager = conf->getChunkManagerIfExists(ns, true, true); - if (!manager) { - return false; - } - - return true; -} - /** * Special internal logic to run reduced version handshake for empty namespace operations to * shards. @@ -183,7 +189,7 @@ bool VersionManager::forceRemoteCheckShardVersionCB(const string& ns) { * Eventually this should go completely away, but for now many commands rely on unversioned but * mongos-specific behavior on mongod (auditing and replication information in commands) */ -static bool initShardVersionEmptyNS(DBClientBase* conn_in) { +bool initShardVersionEmptyNS(DBClientBase* conn_in) { bool ok; BSONObj result; DBClientBase* conn = NULL; @@ -419,11 +425,55 @@ bool checkShardVersion(DBClientBase* conn_in, return true; } +} // namespace + +// Global version manager +VersionManager versionManager; + +void VersionManager::resetShardVersionCB(DBClientBase* conn) { + connectionShardStatus.reset(conn); +} + +bool VersionManager::isVersionableCB(DBClientBase* conn) { + // We do not version shard connections when issued from mongod + if (!isMongos()) { + return false; + } + + return conn->type() == ConnectionString::MASTER || conn->type() == ConnectionString::SET; +} + +bool VersionManager::forceRemoteCheckShardVersionCB(const string& ns) { + const NamespaceString nss(ns); + + // This will force the database catalog entry to be reloaded + grid.catalogCache()->invalidate(nss.db().toString()); + + auto status = grid.catalogCache()->getDatabase(nss.db().toString()); + if (!status.isOK()) { + return false; + } + + shared_ptr<DBConfig> conf = status.getValue(); + + // If we don't have a collection, don't refresh the chunk manager + if (nsGetCollection(ns).size() == 0) { + return false; + } + + ChunkManagerPtr manager = conf->getChunkManagerIfExists(ns, true, true); + if (!manager) { + return false; + } + + return true; +} + bool VersionManager::checkShardVersionCB(DBClientBase* conn_in, const string& ns, bool authoritative, int tryNumber) { - return checkShardVersion(conn_in, ns, ChunkManagerPtr(), authoritative, tryNumber); + return checkShardVersion(conn_in, ns, nullptr, authoritative, tryNumber); } bool VersionManager::checkShardVersionCB(ShardConnection* conn_in, |