summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2017-10-23 13:40:49 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2017-10-24 10:03:33 -0400
commit5d4b316b243757029b78bc7b4db91de4f6197931 (patch)
tree4f03e7967dccacc79e2e6ae5d7effcabff0af252 /src
parent2ff0f268538b713b457a16eb3e8f731bd2e63028 (diff)
downloadmongo-5d4b316b243757029b78bc7b4db91de4f6197931.tar.gz
SERVER-31634 FeatureCompatibilityVersion::setIfCleanStartup() should store FCV=3.4 for shardsvrs
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp72
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.h5
-rw-r--r--src/mongo/db/db.cpp11
3 files changed, 47 insertions, 41 deletions
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index d88cbdf46fc..cef9f6d123a 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -202,49 +202,59 @@ void FeatureCompatibilityVersion::unsetTargetUpgradeOrDowngrade(OperationContext
void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* opCtx,
repl::StorageInterface* storageInterface) {
- if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) {
- std::vector<std::string> dbNames;
- StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
- storageEngine->listDatabases(&dbNames);
-
- for (auto&& dbName : dbNames) {
- if (dbName != "local") {
- return;
- }
+ // A clean startup means there are no databases on disk besides the local database.
+ std::vector<std::string> dbNames;
+ StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine();
+ storageEngine->listDatabases(&dbNames);
+
+ for (auto&& dbName : dbNames) {
+ if (dbName != "local") {
+ return;
}
+ }
- UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx);
- NamespaceString nss(FeatureCompatibilityVersion::kCollection);
+ // If the server was not started with --shardsvr, the default featureCompatibilityVersion on
+ // clean startup is the upgrade version. If it was started with --shardsvr, the default
+ // featureCompatibilityVersion is the downgrade version, so that it can be safely added to a
+ // downgrade version cluster. The config server will run setFeatureCompatibilityVersion as part
+ // of addShard.
+ const bool storeUpgradeVersion = serverGlobalParams.clusterRole != ClusterRole::ShardServer;
- {
- AutoGetOrCreateDb autoDB(opCtx, nss.db(), MODE_X);
+ UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx);
+ NamespaceString nss(FeatureCompatibilityVersion::kCollection);
- // We reached this point because the only database that exists on the server is "local"
- // and we have just created an empty "admin" database. Therefore, it is safe to create
- // the "admin.system.version" collection.
- invariant(autoDB.justCreated());
+ {
+ AutoGetOrCreateDb autoDB(opCtx, nss.db(), MODE_X);
+ // We reached this point because the only database that exists on the server is "local"
+ // and we have just created an empty "admin" database. Therefore, it is safe to create
+ // the "admin.system.version" collection.
+ invariant(autoDB.justCreated());
+
+ if (storeUpgradeVersion) {
// We update the value of the version server parameter so that the admin.system.version
// collection gets a UUID.
serverGlobalParams.featureCompatibility.setVersion(
ServerGlobalParams::FeatureCompatibility::Version::kUpgradingTo36);
-
- uassertStatusOK(storageInterface->createCollection(opCtx, nss, {}));
}
- // We then insert the featureCompatibilityVersion document into the "admin.system.version"
- // collection. The server parameter will be updated on commit by the op observer.
- uassertStatusOK(storageInterface->insertDocument(
- opCtx,
- nss,
- repl::TimestampedBSONObj{BSON("_id"
- << FeatureCompatibilityVersion::kParameterName
- << FeatureCompatibilityVersion::kVersionField
- << FeatureCompatibilityVersionCommandParser::kVersion36),
- SnapshotName()},
- repl::OpTime::kUninitializedTerm)); // No timestamp or term because this write is not
- // replicated.
+ uassertStatusOK(storageInterface->createCollection(opCtx, nss, {}));
}
+
+ // We then insert the featureCompatibilityVersion document into the "admin.system.version"
+ // collection. The server parameter will be updated on commit by the op observer.
+ uassertStatusOK(storageInterface->insertDocument(
+ opCtx,
+ nss,
+ repl::TimestampedBSONObj{
+ BSON("_id" << FeatureCompatibilityVersion::kParameterName
+ << FeatureCompatibilityVersion::kVersionField
+ << (storeUpgradeVersion
+ ? FeatureCompatibilityVersionCommandParser::kVersion36
+ : FeatureCompatibilityVersionCommandParser::kVersion34)),
+ SnapshotName()},
+ repl::OpTime::kUninitializedTerm)); // No timestamp or term because this write is not
+ // replicated.
}
namespace {
diff --git a/src/mongo/db/commands/feature_compatibility_version.h b/src/mongo/db/commands/feature_compatibility_version.h
index d1fa7fc742c..dd7db37d5b5 100644
--- a/src/mongo/db/commands/feature_compatibility_version.h
+++ b/src/mongo/db/commands/feature_compatibility_version.h
@@ -118,8 +118,9 @@ public:
static void unsetTargetUpgradeOrDowngrade(OperationContext* opCtx, StringData version);
/**
- * If there are no non-local databases and we are not running with --shardsvr, set
- * featureCompatibilityVersion to the latest value.
+ * If there are no non-local databases, store the featureCompatibilityVersion document. If we
+ * are not running with --shardsvr, set the version to be the upgrade value. If we are running
+ * with --shardsvr, set the version to be the downgrade value.
*/
static void setIfCleanStartup(OperationContext* opCtx,
repl::StorageInterface* storageInterface);
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index af021dcf0ed..420428087ac 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -787,15 +787,10 @@ ExitCode _initAndListen(int listenPort) {
bool nonLocalDatabases = repairDatabasesAndCheckVersion(startupOpCtx.get());
// Assert that the in-memory featureCompatibilityVersion parameter has been explicitly set. If
- // we are part of a sharded cluster and are started up with no data files, we do not set the
- // featureCompatibilityVersion until addShard is called. If we are part of a non-shard replica
- // set and are also started up with no data files, we do not set the featureCompatibilityVersion
- // until a primary is chosen. For these cases, we expect the in-memory
+ // we are part of a replica set and are started up with no data files, we do not set the
+ // featureCompatibilityVersion until a primary is chosen. For this case, we expect the in-memory
// featureCompatibilityVersion parameter to still be uninitialized until after startup.
- if (canCallFCVSetIfCleanStartup &&
- ((!replSettings.usingReplSets() &&
- serverGlobalParams.clusterRole != ClusterRole::ShardServer) ||
- nonLocalDatabases)) {
+ if (canCallFCVSetIfCleanStartup && (!replSettings.usingReplSets() || nonLocalDatabases)) {
invariant(serverGlobalParams.featureCompatibility.isVersionInitialized());
}