diff options
author | Greg Studer <greg@10gen.com> | 2013-02-26 16:23:39 -0500 |
---|---|---|
committer | Greg Studer <greg@10gen.com> | 2013-02-27 23:22:52 -0500 |
commit | cde17b7efa1f41b4bac1fc84fe72566d8740c8cc (patch) | |
tree | 327b5edd43872314324139c1df2a83d5230494a2 /src | |
parent | eb04c21a8be312d2a100fab53456fa25b52d75d2 (diff) | |
download | mongo-cde17b7efa1f41b4bac1fc84fe72566d8740c8cc.tar.gz |
SERVER-8710 check balancer is stopped before upgrading to nonzero config version
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/s/config_upgrade.cpp | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/mongo/s/config_upgrade.cpp b/src/mongo/s/config_upgrade.cpp index 1ac1d72d1c8..a68ff7bf6d9 100644 --- a/src/mongo/s/config_upgrade.cpp +++ b/src/mongo/s/config_upgrade.cpp @@ -25,6 +25,7 @@ #include "mongo/s/mongo_version_range.h" #include "mongo/s/type_config_version.h" #include "mongo/s/type_database.h" +#include "mongo/s/type_settings.h" #include "mongo/s/type_shard.h" #include "mongo/util/assert_util.h" #include "mongo/util/version.h" @@ -277,6 +278,30 @@ namespace mongo { return VersionStatus_NeedUpgrade; } + // Returns true if we can confirm the balancer is stopped + bool _isBalancerStopped(const ConnectionString& configLoc, string* errMsg) { + + // Get the balancer information + scoped_ptr<ScopedDbConnection> connPtr; + + BSONObj balancerDoc; + try { + connPtr.reset(ScopedDbConnection::getInternalScopedDbConnection(configLoc, 30)); + ScopedDbConnection& conn = *connPtr; + + balancerDoc = conn->findOne(SettingsType::ConfigNS, + BSON(SettingsType::key("balancer"))); + } + catch (const DBException& e) { + *errMsg = e.toString(); + return false; + } + + connPtr->done(); + + return balancerDoc[SettingsType::balancerStopped()].trueValue(); + } + // Checks that all config servers are online bool _checkConfigServersAlive(const ConnectionString& configLoc, string* errMsg) { @@ -429,8 +454,11 @@ namespace mongo { // if possible. // + // The first empty version is technically an upgrade, but has special semantics + bool isEmptyVersion = versionInfo->getCurrentVersion() == UpgradeHistory_EmptyVersion; + // First check for the upgrade flag (but no flag is needed if we're upgrading from empty) - if (!versionInfo->getCurrentVersion() == UpgradeHistory_EmptyVersion && !upgrade) { + if (!isEmptyVersion && !upgrade) { *errMsg = stream() << "newer version " << CURRENT_CONFIG_VERSION << " of mongo config metadata is required, " << "current version is " @@ -443,8 +471,24 @@ namespace mongo { // Contact the config servers to make sure all are online - otherwise we wait a long time // for locks. if (!_checkConfigServersAlive(configLoc, errMsg)) { + + if (isEmptyVersion) { + *errMsg = stream() << "all config servers must be reachable for initial" + << " config database creation" << causedBy(errMsg); + } + else { + *errMsg = stream() << "all config servers must be reachable for config upgrade" + << causedBy(errMsg); + } + + return false; + } + + // Check whether or not the balancer is online, if it is online we will not upgrade + // (but we will initialize the config server) + if (!isEmptyVersion && !_isBalancerStopped(configLoc, errMsg)) { - *errMsg = stream() << "all config servers must be reachable for config upgrade" + *errMsg = stream() << "balancer must be stopped for config upgrade" << causedBy(errMsg); return false; |