diff options
author | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-08-24 10:48:21 -0400 |
---|---|---|
committer | Tess Avitabile <tess.avitabile@mongodb.com> | 2016-08-24 12:59:01 -0400 |
commit | 831e20161e766b32b8ea0533077d231490e99883 (patch) | |
tree | 8b52ffe3b7ae2415fe00a4e0a207e6638702873f /src | |
parent | 7658dabcb5dd45d17687651f33775bee81982f5f (diff) | |
download | mongo-831e20161e766b32b8ea0533077d231490e99883.tar.gz |
SERVER-25155 featureCompatibilityVersion document should be created at replica set initiate time
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/commands/feature_compatibility_version.cpp | 45 | ||||
-rw-r--r-- | src/mongo/db/commands/feature_compatibility_version.h | 4 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_external_state_impl.cpp | 3 |
4 files changed, 28 insertions, 27 deletions
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp index 7e069ceda48..d250fb3d37e 100644 --- a/src/mongo/db/commands/feature_compatibility_version.cpp +++ b/src/mongo/db/commands/feature_compatibility_version.cpp @@ -31,7 +31,9 @@ #include "mongo/db/commands/feature_compatibility_version.h" #include "mongo/base/status.h" +#include "mongo/db/catalog/collection_options.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/operation_context.h" #include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" #include "mongo/db/storage/storage_engine.h" @@ -152,35 +154,30 @@ void FeatureCompatibilityVersion::set(OperationContext* txn, StringData version) } } -void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* txn) { - std::vector<std::string> dbNames; - StorageEngine* storageEngine = getGlobalServiceContext()->getGlobalStorageEngine(); - storageEngine->listDatabases(&dbNames); +void FeatureCompatibilityVersion::setIfCleanStartup(OperationContext* txn, + 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; + for (auto&& dbName : dbNames) { + if (dbName != "local") { + return; + } } - } - - if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) { // Insert featureCompatibilityDocument into admin.system.version. - // Do not use writeConcern majority, because we may be holding locks. + txn->setReplicatedWrites(false); NamespaceString nss(FeatureCompatibilityVersion::kCollection); - DBDirectClient client(txn); - BSONObj result; - client.runCommand( - nss.db().toString(), - BSON("insert" << nss.coll() << "documents" - << BSON_ARRAY(BSON("_id" << FeatureCompatibilityVersion::kParameterName - << FeatureCompatibilityVersion::kVersionField - << FeatureCompatibilityVersion::kVersion34))), - result); - auto status = getStatusFromCommandResult(result); - if (!status.isOK() && status != ErrorCodes::InterruptedAtShutdown) { - uassertStatusOK(status); - } + CollectionOptions options; + uassertStatusOK(storageInterface->createCollection(txn, nss, options)); + uassertStatusOK(storageInterface->insertDocument( + txn, + nss, + BSON("_id" << FeatureCompatibilityVersion::kParameterName + << FeatureCompatibilityVersion::kVersionField + << FeatureCompatibilityVersion::kVersion34))); // Update server parameter. serverGlobalParams.featureCompatibilityVersion.store( diff --git a/src/mongo/db/commands/feature_compatibility_version.h b/src/mongo/db/commands/feature_compatibility_version.h index 41764ec7026..bea195f73ed 100644 --- a/src/mongo/db/commands/feature_compatibility_version.h +++ b/src/mongo/db/commands/feature_compatibility_version.h @@ -30,6 +30,8 @@ #include "mongo/base/status_with.h" #include "mongo/base/string_data.h" +#include "mongo/bson/bsonobj.h" +#include "mongo/db/repl/storage_interface.h" #include "mongo/db/server_options.h" namespace mongo { @@ -64,7 +66,7 @@ public: * If there are no non-local databases and we are not running with --shardsvr, set * featureCompatibilityVersion to 3.4. */ - static void setIfCleanStartup(OperationContext* txn); + static void setIfCleanStartup(OperationContext* txn, repl::StorageInterface* storageInterface); /** * Examines a document inserted or updated in admin.system.version. If it is the diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index 6ac580e3d17..9a44b575121 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -766,7 +766,8 @@ static ExitCode _initAndListen(int listenPort) { storageGlobalParams.engine != "devnull") { ScopedTransaction transaction(startupOpCtx.get(), MODE_X); Lock::GlobalWrite lk(startupOpCtx.get()->lockState()); - FeatureCompatibilityVersion::setIfCleanStartup(startupOpCtx.get()); + FeatureCompatibilityVersion::setIfCleanStartup( + startupOpCtx.get(), repl::StorageInterface::get(getGlobalServiceContext())); } } diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 3b0188bbad2..1f35c5a3afd 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -332,6 +332,8 @@ Status ReplicationCoordinatorExternalStateImpl::initializeReplSetStorage(Operati // get angry if the minValid document is present but doesn't have a "ts" field. // Consider removing this once we no longer need to support downgrading to 3.2. _storageInterface->setMinValidToAtLeast(txn, {}); + + FeatureCompatibilityVersion::setIfCleanStartup(txn, _storageInterface); } catch (const DBException& ex) { return ex.toStatus(); } @@ -362,7 +364,6 @@ OpTime ReplicationCoordinatorExternalStateImpl::onTransitionToPrimary(OperationC } const auto opTimeToReturn = fassertStatusOK(28665, loadLastOpTime(txn)); - FeatureCompatibilityVersion::setIfCleanStartup(txn); shardingOnTransitionToPrimaryHook(txn); dropAllTempCollections(txn); |