Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SERVER-7984 minor nits for config upgrade

  • Loading branch information...
commit 5b24436ec22e8925d921a5f070e5c46132915f6c 1 parent e9208a0
Greg Studer authored
View
8 src/mongo/dbtests/config_upgrade_tests.cpp
@@ -66,7 +66,7 @@ namespace mongo {
*/
OID storeConfigVersion(int configVersion) {
- if (configVersion < UpgradeHistory_ManditoryEpochVersion) {
+ if (configVersion < UpgradeHistory_MandatoryEpochVersion) {
storeLegacyConfigVersion(configVersion);
return OID();
}
@@ -245,7 +245,7 @@ namespace mongo {
VersionType newVersion;
newVersion.setMinCompatibleVersion(UpgradeHistory_NoEpochVersion);
- newVersion.setCurrentVersion(UpgradeHistory_ManditoryEpochVersion);
+ newVersion.setCurrentVersion(UpgradeHistory_MandatoryEpochVersion);
storeConfigVersion(newVersion);
newVersion.clear();
@@ -259,7 +259,7 @@ namespace mongo {
OID clusterId = OID::gen();
newVersion.setClusterId(clusterId);
newVersion.setMinCompatibleVersion(UpgradeHistory_NoEpochVersion);
- newVersion.setCurrentVersion(UpgradeHistory_ManditoryEpochVersion);
+ newVersion.setCurrentVersion(UpgradeHistory_MandatoryEpochVersion);
clearVersion();
storeConfigVersion(newVersion);
@@ -271,7 +271,7 @@ namespace mongo {
ASSERT(status.isOK());
ASSERT_EQUALS(newVersion.getMinCompatibleVersion(), UpgradeHistory_NoEpochVersion);
- ASSERT_EQUALS(newVersion.getCurrentVersion(), UpgradeHistory_ManditoryEpochVersion);
+ ASSERT_EQUALS(newVersion.getCurrentVersion(), UpgradeHistory_MandatoryEpochVersion);
ASSERT_EQUALS(newVersion.getClusterId(), clusterId);
}
View
6 src/mongo/s/cluster_client_internal.cpp
@@ -21,9 +21,9 @@
#include "mongo/client/connpool.h"
#include "mongo/s/field_parser.h"
+#include "mongo/s/type_changelog.h"
#include "mongo/s/type_mongos.h"
#include "mongo/s/type_shard.h"
-#include "mongo/s/type_changelog.h"
#include "mongo/util/stringutils.h"
namespace mongo {
@@ -297,7 +297,9 @@ namespace mongo {
const BSONObj& details)
{
//
- // Duplicated here to avoid dependency issues
+ // The code for writing to the changelog collection exists elsewhere - we duplicate here to
+ // avoid dependency issues.
+ // TODO: Merge again once config.cpp is cleaned up.
//
string changeID = stream() << getHostNameCached() << "-" << terseCurrentTime() << "-"
View
2  src/mongo/s/cluster_client_internal.h
@@ -21,6 +21,8 @@
* TODO: See if this stuff is more generally useful, distribute if so.
*/
+#pragma once
+
#include "mongo/base/owned_pointer_map.h"
#include "mongo/base/owned_pointer_vector.h"
#include "mongo/client/dbclientinterface.h"
View
16 src/mongo/s/config_upgrade.cpp
@@ -236,15 +236,15 @@ namespace mongo {
// Check that we aren't too old
if (CURRENT_CONFIG_VERSION < versionInfo.getMinCompatibleVersion()) {
- *whyNot = stream() << "not compatible with current config version "
- << versionInfo.getMinCompatibleVersion() << ", our version is "
- << CURRENT_CONFIG_VERSION;
+ *whyNot = stream() << "the config version " << CURRENT_CONFIG_VERSION
+ << " of our process is too old "
+ << "for the detected config version "
+ << versionInfo.getMinCompatibleVersion();
return VersionStatus_Incompatible;
}
- // Check that we aren't excluded
-
+ // Check that the mongo version of this process hasn't been excluded from the cluster
vector<MongoVersionRange> excludedRanges;
if (!MongoVersionRange::parseBSONArray(versionInfo.getExcludedRanges(),
&excludedRanges,
@@ -325,9 +325,7 @@ namespace mongo {
return false;
}
- // Get the config version we've upgraded to
- // This can't be done in _nextUpgrade, since
-
+ // Get the config version we've upgraded to and make sure it's sane
Status verifyConfigStatus = getConfigVersion(configLoc, upgradedVersionInfo);
if (!verifyConfigStatus.isOK()) {
@@ -393,7 +391,7 @@ namespace mongo {
// if possible.
//
- // First check for the upgrade flag
+ // First check for the upgrade flag (but no flag is needed if we're upgrading from empty)
if (!versionInfo->getCurrentVersion() == UpgradeHistory_EmptyVersion && !upgrade) {
*errMsg = stream() << "newer version " << CURRENT_CONFIG_VERSION
View
10 src/mongo/s/config_upgrade.h
@@ -62,6 +62,12 @@ namespace mongo {
UpgradeHistory_UnreportedVersion = 1,
/**
+ * NOTE: We skip version 2 here since it is very old and we shouldn't see it in the wild.
+ *
+ * Do not skip upgrade versions in the future.
+ */
+
+ /**
* Base version used by pre-2.4 mongoses with no collection epochs.
*/
UpgradeHistory_NoEpochVersion = 3,
@@ -77,7 +83,7 @@ namespace mongo {
* + Mongos pings include a "configVersion" field indicating the current config version
* + Mongos explicitly ignores any collection with a "primary" field
*/
- UpgradeHistory_ManditoryEpochVersion = 4
+ UpgradeHistory_MandatoryEpochVersion = 4
};
//
@@ -89,7 +95,7 @@ namespace mongo {
const int MIN_COMPATIBLE_CONFIG_VERSION = UpgradeHistory_NoEpochVersion;
// Latest version we know how to communicate with
- const int CURRENT_CONFIG_VERSION = UpgradeHistory_ManditoryEpochVersion;
+ const int CURRENT_CONFIG_VERSION = UpgradeHistory_MandatoryEpochVersion;
//
// DECLARATION OF UPGRADE FUNCTIONALITY
View
1  src/mongo/s/config_upgrade_helpers.cpp
@@ -228,6 +228,7 @@ namespace mongo {
verify(fromNSS.isValid());
+ // TODO: EnsureIndex at some point, if it becomes easier?
string indexesNS = fromNSS.db + ".system.indexes";
scoped_ptr<DBClientCursor> cursor(_safeCursor(conn->query(indexesNS,
BSON("ns" << fromNS))));
View
110 src/mongo/s/config_upgrade_v3_to_v4.cpp
@@ -51,6 +51,8 @@ namespace mongo {
"http://docs.mongodb.org/upgrade\n"
"******\n";
+ static const char* minMongoProcessVersion = "2.2";
+
// Custom field used in upgrade state to determine if/where we failed on last upgrade
const BSONField<bool> inCriticalSectionField(string("inCriticalSection"));
@@ -164,13 +166,14 @@ namespace mongo {
// We can't upgrade if there are active pre-v2.2 processes in the cluster
//
- Status mongoVersionStatus = checkClusterMongoVersions(configLoc, "2.2");
+ Status mongoVersionStatus = checkClusterMongoVersions(configLoc,
+ string(minMongoProcessVersion));
if (!mongoVersionStatus.isOK()) {
- *errMsg = stream()
- << "cannot upgrade with pre-2.2 mongo processes active in the cluster"
- << causedBy(mongoVersionStatus);
+ *errMsg = stream() << "cannot upgrade with pre-v" << minMongoProcessVersion
+ << " mongo processes active in the cluster"
+ << causedBy(mongoVersionStatus);
return false;
}
@@ -233,6 +236,8 @@ namespace mongo {
OwnedPointerVector<ScopedDistributedLock> collectionLocks;
+ log() << "acquiring locks for " << collections.size() << " sharded collections..." << endl;
+
for (map<string, CollectionType*>::const_iterator it = collections.begin();
it != collections.end(); ++it)
{
@@ -254,6 +259,12 @@ namespace mongo {
}
collectionLocks.mutableVector().push_back(namespaceLock);
+
+ // Progress update
+ if (collectionLocks.vector().size() % 10 == 0) {
+ log() << "acquired " << collectionLocks.vector().size() << " locks out of "
+ << collections.size() << " for config upgrade" << endl;
+ }
}
// We are now preventing all splits and migrates for all sharded collections
@@ -262,6 +273,9 @@ namespace mongo {
string workingSuffix = genWorkingSuffix(upgradeId);
string backupSuffix = genBackupSuffix(upgradeId);
+ log() << "copying collection and chunk metadata to working and backup collections..."
+ << endl;
+
// Get a backup and working copy of the config.collections and config.chunks collections
Status copyStatus = copyFrozenCollection(configLoc,
@@ -433,37 +447,83 @@ namespace mongo {
return false;
}
- // Paranoid verify the write
- try {
- ScopedDbConnection& conn = *connPtr;
+ connPtr->done();
+ }
+ }
+
+ //
+ // Paranoid verify the collection writes
+ //
- // Find chunks with a different epoch
- BSONObj diffChunk =
- conn->findOne(ChunkType::ConfigNS + workingSuffix,
- BSON(ChunkType::ns(collection.getNS())
- << ChunkType::DEPRECATED_epoch() << NE << epoch));
+ {
+ scoped_ptr<ScopedDbConnection> connPtr;
- if (!diffChunk.isEmpty()) {
+ try {
+ connPtr.reset(ScopedDbConnection::getInternalScopedDbConnection(configLoc, 30));
+ ScopedDbConnection& conn = *connPtr;
+
+ // Find collections with no epochs
+ BSONObj emptyDoc =
+ conn->findOne(CollectionType::ConfigNS + workingSuffix,
+ BSON("$unset" << BSON(CollectionType::DEPRECATED_lastmodEpoch() << 1)));
- *errMsg = stream() << "could not update chunk " << diffChunk
- << " with new epoch " << epoch.toString()
- << " in collection " << collection.getNS();
+ if (!emptyDoc.isEmpty()) {
- return false;
+ *errMsg = stream() << "collection " << emptyDoc
+ << " is still missing epoch after config upgrade";
- }
+ connPtr->done();
+ return false;
}
- catch (const DBException& e) {
- *errMsg = stream() << "could not verify new epoch " << epoch.toString()
- << " written for chunks in " << collection.getNS()
- << causedBy(e);
+ // Find collections with empty epochs
+ emptyDoc = conn->findOne(CollectionType::ConfigNS + workingSuffix,
+ BSON(CollectionType::DEPRECATED_lastmodEpoch(OID())));
+ if (!emptyDoc.isEmpty()) {
+
+ *errMsg = stream() << "collection " << emptyDoc
+ << " still has empty epoch after config upgrade";
+
+ connPtr->done();
return false;
}
- connPtr->done();
+ // Find chunks with no epochs
+ emptyDoc =
+ conn->findOne(ChunkType::ConfigNS + workingSuffix,
+ BSON("$unset" << BSON(ChunkType::DEPRECATED_epoch() << 1)));
+
+ if (!emptyDoc.isEmpty()) {
+
+ *errMsg = stream() << "chunk " << emptyDoc
+ << " is still missing epoch after config upgrade";
+
+ connPtr->done();
+ return false;
+ }
+
+ // Find chunks with empty epochs
+ emptyDoc = conn->findOne(ChunkType::ConfigNS + workingSuffix,
+ BSON(ChunkType::DEPRECATED_epoch(OID())));
+
+ if (!emptyDoc.isEmpty()) {
+
+ *errMsg = stream() << "chunk " << emptyDoc
+ << " still has empty epoch after config upgrade";
+
+ connPtr->done();
+ return false;
+ }
+ }
+ catch (const DBException& e) {
+
+ *errMsg = stream() << "could not verify epoch writes" << causedBy(e);
+
+ return false;
}
+
+ connPtr->done();
}
//
@@ -562,7 +622,7 @@ namespace mongo {
}
//
- // Finally update the version to 4 and add clusterId to version
+ // Finally update the version to latest and add clusterId to version
//
OID newClusterId = OID::gen();
@@ -572,7 +632,7 @@ namespace mongo {
// we want to save the excludes that were set.
newVersionInfo.setMinCompatibleVersion(UpgradeHistory_NoEpochVersion);
- newVersionInfo.setCurrentVersion(UpgradeHistory_ManditoryEpochVersion);
+ newVersionInfo.setCurrentVersion(UpgradeHistory_MandatoryEpochVersion);
newVersionInfo.setClusterId(newClusterId);
// Leave critical section
View
21 src/mongo/s/mongo_version_range.cpp
@@ -1,16 +1,17 @@
-/* Copyright 2009 10gen Inc.
+/**
+ * Copyright (C) 2012 10gen Inc.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 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/>.
*/
#include "mongo/s/mongo_version_range.h"
View
30 src/mongo/s/mongo_version_range.h
@@ -1,16 +1,17 @@
-/* Copyright 2009 10gen Inc.
+/**
+ * Copyright (C) 2012 10gen Inc.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * 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/>.
*/
#pragma once
@@ -23,6 +24,15 @@
namespace mongo {
+ /**
+ * The MongoVersionRange represents a min/max of MongoDB versions, useful for
+ * excluding/including particular versions.
+ *
+ * The ranges may be single-version, in which case maxVersion == "", where only exact prefix
+ * matches are included in the range. Alternately, the range may have a min and max version
+ * and include any version with a prefix of the min and max version as well as all versions
+ * between the two.
+ */
struct MongoVersionRange {
static bool parseBSONArray(const BSONArray& arr,
View
3  src/mongo/s/mongo_version_range_test.cpp
@@ -16,6 +16,9 @@
#include "mongo/s/mongo_version_range.h"
+#include <string>
+#include <vector>
+
#include "mongo/bson/bsonmisc.h"
#include "mongo/unittest/unittest.h"
Please sign in to comment.
Something went wrong with that request. Please try again.