diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/SConscript | 7 | ||||
-rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 40 | ||||
-rw-r--r-- | src/mongo/db/repl/SConscript | 6 | ||||
-rw-r--r-- | src/mongo/db/s/SConscript | 4 | ||||
-rw-r--r-- | src/mongo/db/s/config/configsvr_shard_collection_command.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/sessions_collection_config_server.cpp | 25 | ||||
-rw-r--r-- | src/mongo/s/catalog/SConscript | 2 |
8 files changed, 66 insertions, 21 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 5abc22b68df..c44483c065f 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -1049,6 +1049,7 @@ env.Library( 'sessions_collection_config_server.cpp', ], LIBDEPS=[ + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', '$BUILD_DIR/mongo/s/client/sharding_client', '$BUILD_DIR/mongo/s/commands/shared_cluster_commands', '$BUILD_DIR/mongo/s/coreshard', diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 94b79efa17f..22ad5b94bd2 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -134,13 +134,12 @@ env.Library( ) env.Library( - target="dcommands_fcv", + target='feature_compatibility_version', source=[ - "feature_compatibility_version.cpp", + 'feature_compatibility_version.cpp', ], LIBDEPS=[ 'core', - '$BUILD_DIR/mongo/db/commands', '$BUILD_DIR/mongo/db/dbdirectclient', ], ) @@ -231,7 +230,7 @@ env.Library( '$BUILD_DIR/mongo/s/client/parallel', 'core', 'current_op_common', - 'dcommands_fcv', + 'feature_compatibility_version', 'dcommands_fsync', 'killcursors_common', 'write_commands_common', diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index f925451227b..42ffaa1d59a 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -45,10 +45,13 @@ #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/server_options.h" +#include "mongo/db/sessions_collection.h" #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/catalog/sharding_catalog_client_impl.h" #include "mongo/s/catalog/sharding_catalog_manager.h" +#include "mongo/s/catalog_cache.h" #include "mongo/s/client/shard_registry.h" +#include "mongo/s/grid.h" #include "mongo/util/exit.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/scopeguard.h" @@ -241,14 +244,49 @@ public: exitCleanly(EXIT_CLEAN); } - // If config server, downgrade shards *before* downgrading self. if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { + // If config server, downgrade shards *before* downgrading self. uassertStatusOK( ShardingCatalogManager::get(opCtx)->setFeatureCompatibilityVersionOnShards( opCtx, Command::appendMajorityWriteConcern(Command::appendPassthroughFields( cmdObj, BSON(FeatureCompatibilityVersion::kCommandName << requestedVersion))))); + + // Drop config.system.sessions collection on downgrade. + auto const catalogClient = Grid::get(opCtx)->catalogClient(); + auto const catalogCache = Grid::get(opCtx)->catalogCache(); + Seconds waitFor(DistLockManager::kDefaultLockTimeout); + + auto backwardsCompatibleDbDistLock = + uassertStatusOK(catalogClient->getDistLockManager()->lock( + opCtx, + SessionsCollection::kSessionsNamespaceString.db() + "-movePrimary", + "dropCollection", + waitFor)); + + auto dbDistLock = uassertStatusOK(catalogClient->getDistLockManager()->lock( + opCtx, + SessionsCollection::kSessionsNamespaceString.db(), + "dropCollection", + waitFor)); + + auto collDistLock = uassertStatusOK(catalogClient->getDistLockManager()->lock( + opCtx, + SessionsCollection::kSessionsNamespaceString.ns(), + "dropCollection", + waitFor)); + + ON_BLOCK_EXIT([&catalogCache] { + catalogCache->invalidateShardedCollection( + SessionsCollection::kSessionsNamespaceString); + }); + + auto dropCollStatus = catalogClient->dropCollection( + opCtx, SessionsCollection::kSessionsNamespaceString); + if (dropCollStatus != ErrorCodes::NamespaceNotFound) { + uassertStatusOK(dropCollStatus); + } } // Stop the background key generator thread from running before trying to drop the diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index 298525d6a21..1a9c3fc7411 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -14,7 +14,7 @@ env.Library( '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/db/background', '$BUILD_DIR/mongo/db/catalog/catalog_helpers', - '$BUILD_DIR/mongo/db/commands/dcommands_fcv', + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/dbdirectclient', '$BUILD_DIR/mongo/db/dbhelpers', @@ -1451,7 +1451,7 @@ env.Library( 'rollback_checker', 'storage_interface', '$BUILD_DIR/mongo/client/fetcher', - '$BUILD_DIR/mongo/db/commands/dcommands_fcv', + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', ], ) @@ -1536,7 +1536,7 @@ env.Library( '$BUILD_DIR/mongo/db/auth/authcore', '$BUILD_DIR/mongo/db/catalog/catalog_helpers', '$BUILD_DIR/mongo/db/cloner', - '$BUILD_DIR/mongo/db/commands/dcommands_fcv', + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', '$BUILD_DIR/mongo/db/commands/list_collections_filter', '$BUILD_DIR/mongo/db/commands/server_status', '$BUILD_DIR/mongo/db/concurrency/lock_manager', diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 449edaf2677..d1816c7d94d 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -190,7 +190,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/db/bson/dotted_path_support', - '$BUILD_DIR/mongo/db/commands/dcommands_fcv', + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', '$BUILD_DIR/mongo/db/commands/server_status', '$BUILD_DIR/mongo/db/db_raii', '$BUILD_DIR/mongo/db/dbhelpers', @@ -305,7 +305,7 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/db/bson/dotted_path_support', '$BUILD_DIR/mongo/db/catalog/catalog_raii', - '$BUILD_DIR/mongo/db/commands/dcommands_fcv', + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', '$BUILD_DIR/mongo/db/commands/server_status', '$BUILD_DIR/mongo/db/dbhelpers', '$BUILD_DIR/mongo/db/index_d', diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp index 1426e84117b..b38e680a384 100644 --- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp +++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp @@ -736,7 +736,7 @@ public: // Do not allow sharding collections while a featureCompatibilityVersion upgrade or // downgrade is in progress (see SERVER-31231 for details). - Lock::ExclusiveLock lk(opCtx->lockState(), FeatureCompatibilityVersion::fcvLock); + Lock::SharedLock lk(opCtx->lockState(), FeatureCompatibilityVersion::fcvLock); const NamespaceString nss(parseNs(dbname, cmdObj)); auto request = ConfigsvrShardCollectionRequest::parse( diff --git a/src/mongo/db/sessions_collection_config_server.cpp b/src/mongo/db/sessions_collection_config_server.cpp index 3640fd80e98..ee5199f54f4 100644 --- a/src/mongo/db/sessions_collection_config_server.cpp +++ b/src/mongo/db/sessions_collection_config_server.cpp @@ -34,6 +34,8 @@ #include "mongo/client/query.h" #include "mongo/db/commands.h" +#include "mongo/db/commands/feature_compatibility_version.h" +#include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/logical_session_id.h" #include "mongo/db/operation_context.h" @@ -63,8 +65,7 @@ Status SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext // First, shard the sessions collection to create it. ConfigsvrShardCollectionRequest shardCollection; - shardCollection.set_configsvrShardCollection( - NamespaceString(SessionsCollection::kSessionsFullNS.toString())); + shardCollection.set_configsvrShardCollection(SessionsCollection::kSessionsNamespaceString); shardCollection.setKey(BSON("_id" << 1)); DBDirectClient client(opCtx); @@ -78,13 +79,12 @@ Status SessionsCollectionConfigServer::_shardCollectionIfNeeded(OperationContext } Status SessionsCollectionConfigServer::_generateIndexesIfNeeded(OperationContext* opCtx) { - auto res = - scatterGatherOnlyVersionIfUnsharded(opCtx, - SessionsCollection::kSessionsDb.toString(), - NamespaceString(SessionsCollection::kSessionsFullNS), - SessionsCollection::generateCreateIndexesCmd(), - ReadPreferenceSetting::get(opCtx), - Shard::RetryPolicy::kNoRetry); + auto res = scatterGatherOnlyVersionIfUnsharded(opCtx, + SessionsCollection::kSessionsDb.toString(), + SessionsCollection::kSessionsNamespaceString, + SessionsCollection::generateCreateIndexesCmd(), + ReadPreferenceSetting::get(opCtx), + Shard::RetryPolicy::kNoRetry); return res.getStatus(); } @@ -103,6 +103,13 @@ Status SessionsCollectionConfigServer::setupSessionsCollection(OperationContext* return Status::OK(); } + Lock::SharedLock lk(opCtx->lockState(), FeatureCompatibilityVersion::fcvLock); + // Prevent recreating the collection on downgrade. + if (serverGlobalParams.featureCompatibility.getVersion() != + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36) { + return Status::OK(); + } + auto res = _shardCollectionIfNeeded(opCtx); if (!res.isOK()) { log() << "Failed to create config.system.sessions: " << res.reason() diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript index aed7e63ab86..23329d25999 100644 --- a/src/mongo/s/catalog/SConscript +++ b/src/mongo/s/catalog/SConscript @@ -148,7 +148,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/db/catalog/catalog_raii', - '$BUILD_DIR/mongo/db/commands/dcommands_fcv', + '$BUILD_DIR/mongo/db/commands/feature_compatibility_version', '$BUILD_DIR/mongo/db/repl/read_concern_args', '$BUILD_DIR/mongo/db/s/balancer', '$BUILD_DIR/mongo/executor/network_interface', |