diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-12-09 15:40:40 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-01-03 16:46:48 -0500 |
commit | 499014391364d74b8ee143e2a9685460ba2a1978 (patch) | |
tree | 1024f2a7c6c92c1aa4fb2c00f06d3bb3c9dc8b9c /src/mongo/s | |
parent | 1ccbda8dd78a6af4893108a4e2fa81df44bae7c8 (diff) | |
download | mongo-499014391364d74b8ee143e2a9685460ba2a1978.tar.gz |
SERVER-27364 Remove DBConfig::setPrimary
Moves its entire functionality to the 'movePrimary' command.
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/commands/cluster_move_primary_cmd.cpp | 21 | ||||
-rw-r--r-- | src/mongo/s/config.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/config.h | 2 |
3 files changed, 15 insertions, 14 deletions
diff --git a/src/mongo/s/commands/cluster_move_primary_cmd.cpp b/src/mongo/s/commands/cluster_move_primary_cmd.cpp index 63d94120343..334e0c823f5 100644 --- a/src/mongo/s/commands/cluster_move_primary_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_primary_cmd.cpp @@ -45,6 +45,7 @@ #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/catalog_cache.h" #include "mongo/s/catalog/sharding_catalog_client.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/s/client/shard_registry.h" #include "mongo/s/commands/sharded_command_processing.h" #include "mongo/s/config.h" @@ -216,15 +217,24 @@ public: hasWCError = true; } - const string oldPrimary = fromShard->getConnString().toString(); - - ScopedDbConnection fromconn(fromShard->getConnString()); + // Update the new primary in the config server metadata + { + DatabaseType dbt; + dbt.setName(dbname); + dbt.setPrimary(toShard->getId()); + dbt.setSharded(config->isShardingEnabled()); - config->setPrimary(txn, toShard->getId()); + uassertStatusOK(Grid::get(txn)->catalogClient(txn)->updateDatabase(txn, dbname, dbt)); + } - // Ensure the next attempt to retrieve the database will do a full reload + // Ensure the next attempt to retrieve the database or any of its collections will do a full + // reload Grid::get(txn)->catalogCache()->invalidate(dbname); + const string oldPrimary = fromShard->getConnString().toString(); + + ScopedDbConnection fromconn(fromShard->getConnString()); + if (shardedColls.empty()) { // TODO: Collections can be created in the meantime, and we should handle in the future. log() << "movePrimary dropping database on " << oldPrimary @@ -253,7 +263,6 @@ public: warning() << "movePrimary legacy mongod behavior detected. " << "User must manually remove unsharded collections in database " << dbname << " on " << oldPrimary; - } else { // We moved some unsharded collections, but not all BSONObjIterator it(cloneRes["clonedColls"].Obj()); diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp index 44c71965afe..3127850c628 100644 --- a/src/mongo/s/config.cpp +++ b/src/mongo/s/config.cpp @@ -385,12 +385,6 @@ std::shared_ptr<ChunkManager> DBConfig::getChunkManager(OperationContext* txn, return ci.getCM(); } -void DBConfig::setPrimary(OperationContext* txn, const ShardId& newPrimaryId) { - stdx::lock_guard<stdx::mutex> lk(_lock); - _primaryId = newPrimaryId; - _save(txn); -} - bool DBConfig::load(OperationContext* txn) { const auto currentReloadIteration = _reloadCount.load(); stdx::lock_guard<stdx::mutex> lk(_lock); diff --git a/src/mongo/s/config.h b/src/mongo/s/config.h index 863bd10beb1..69f1909bb34 100644 --- a/src/mongo/s/config.h +++ b/src/mongo/s/config.h @@ -149,8 +149,6 @@ public: bool reload = false, bool forceReload = false); - void setPrimary(OperationContext* txn, const ShardId& newPrimaryId); - /** * Returns true if it is successful at loading the DBConfig, false if the database is not found, * and throws on all other errors. |