diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2020-03-23 17:11:02 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-30 15:29:42 +0000 |
commit | 09980eb0211c8b3adea4e10e97339b05c3a4e602 (patch) | |
tree | a5721625c41b0ea63422527308ad5d94ffd7f0d1 | |
parent | b6a5641e5b0ad21cba312b0703cbb09bea158b05 (diff) | |
download | mongo-09980eb0211c8b3adea4e10e97339b05c3a4e602.tar.gz |
SERVER-46835 Remove FCV branches related to deleting the config server implicit collection creation loop
20 files changed, 2 insertions, 846 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js index 4256257990d..1290c4aae0c 100644 --- a/jstests/auth/lib/commands_lib.js +++ b/jstests/auth/lib/commands_lib.js @@ -2892,20 +2892,6 @@ var authCommandsLib = { ] }, { - testname: "_configsvrCreateCollection", - command: {_configsvrCreateCollection: "test.user"}, - skipSharded: true, - expectFail: true, - testcases: [ - { - runOnDb: "admin", - roles: {__system: 1}, - privileges: [{resource: {cluster: true}, actions: ["internal"]}], - expectFail: true - }, - ] - }, - { testname: "create_views", command: {create: "view", viewOn: "collection", pipeline: [{$match: {}}]}, teardown: function(db) { diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index f836773e36d..2150df1552e 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -91,7 +91,6 @@ let viewsCommandTests = { _configsvrCommitChunkMigration: {skip: isAnInternalCommand}, _configsvrCommitChunkSplit: {skip: isAnInternalCommand}, _configsvrCommitMovePrimary: {skip: isAnInternalCommand}, - _configsvrCreateCollection: {skip: isAnInternalCommand}, _configsvrCreateDatabase: {skip: isAnInternalCommand}, _configsvrDropCollection: {skip: isAnInternalCommand}, _configsvrDropDatabase: {skip: isAnInternalCommand}, diff --git a/jstests/replsets/db_reads_while_recovering_all_commands.js b/jstests/replsets/db_reads_while_recovering_all_commands.js index 6826c1d65de..dc4bdfe3c17 100644 --- a/jstests/replsets/db_reads_while_recovering_all_commands.js +++ b/jstests/replsets/db_reads_while_recovering_all_commands.js @@ -36,7 +36,6 @@ const allCommands = { _configsvrCommitChunkMigration: {skip: isPrimaryOnly}, _configsvrCommitChunkSplit: {skip: isPrimaryOnly}, _configsvrCommitMovePrimary: {skip: isPrimaryOnly}, - _configsvrCreateCollection: {skip: isPrimaryOnly}, _configsvrCreateDatabase: {skip: isPrimaryOnly}, _configsvrDropCollection: {skip: isPrimaryOnly}, _configsvrDropDatabase: {skip: isPrimaryOnly}, @@ -349,4 +348,4 @@ AllCommandsTest.testAllCommands(secondary, allCommands, function(test) { // Turn off maintenance mode and stop the test. assert.commandWorked(secondary.adminCommand({replSetMaintenance: 0})); rst.stopSet(); -})();
\ No newline at end of file +})(); diff --git a/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js b/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js index 33e4c5b735b..8edcab6b8e8 100644 --- a/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js +++ b/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js @@ -140,11 +140,6 @@ checkCommandConfigSvr({_configsvrMovePrimary: dbName, to: st.shard0.name}, setupFuncs.createDatabase, cleanupFuncs.dropDatabase); -// We are using a different name from ns because it was already created in setupFuncs. -checkCommandConfigSvr({_configsvrCreateCollection: dbName + '.bar', options: {}}, - setupFuncs.createDatabase, - cleanupFuncs.dropDatabase); - // shardCollection checkCommandMongos( {shardCollection: ns, key: {_id: 1}}, setupFuncs.enableSharding, cleanupFuncs.dropDatabase); diff --git a/jstests/sharding/read_write_concern_defaults_application.js b/jstests/sharding/read_write_concern_defaults_application.js index dbbbdfa4ce2..da39fa0eddf 100644 --- a/jstests/sharding/read_write_concern_defaults_application.js +++ b/jstests/sharding/read_write_concern_defaults_application.js @@ -85,7 +85,6 @@ let testCases = { _configsvrCommitChunkMigration: {skip: "internal command"}, _configsvrCommitChunkSplit: {skip: "internal command"}, _configsvrCommitMovePrimary: {skip: "internal command"}, - _configsvrCreateCollection: {skip: "internal command"}, _configsvrCreateDatabase: {skip: "internal command"}, _configsvrDropCollection: {skip: "internal command"}, _configsvrDropDatabase: {skip: "internal command"}, diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 1998e069b86..57b7bdba253 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -94,9 +94,7 @@ void serializeReply(OperationContext* opCtx, if (continueOnError && !result.results.empty()) { const auto& lastResult = result.results.back(); - if (lastResult == ErrorCodes::StaleConfig || - lastResult == ErrorCodes::CannotImplicitlyCreateCollection || - lastResult == ErrorCodes::StaleDbVersion) { + if (lastResult == ErrorCodes::StaleConfig || lastResult == ErrorCodes::StaleDbVersion) { // For ordered:false commands we need to duplicate these error results for all ops // after we stopped. See handleError() in write_ops_exec.cpp for more info. auto err = result.results.back(); diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp index cd499617d1f..0dee9592956 100644 --- a/src/mongo/db/ops/write_ops_exec.cpp +++ b/src/mongo/db/ops/write_ops_exec.cpp @@ -78,7 +78,6 @@ #include "mongo/db/write_concern.h" #include "mongo/logv2/log.h" #include "mongo/rpc/get_status_from_command_result.h" -#include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/s/would_change_owning_shard_exception.h" #include "mongo/util/fail_point.h" #include "mongo/util/log_and_backoff.h" @@ -293,14 +292,6 @@ bool handleError(OperationContext* opCtx, // Command reply serializer will handle repeating this error if needed. out->results.emplace_back(ex.toStatus()); return false; - } else if (ex.extraInfo<CannotImplicitlyCreateCollectionInfo>()) { - auto& oss = OperationShardingState::get(opCtx); - oss.setShardingOperationFailedStatus(ex.toStatus()); - - // Don't try doing more ops since they will fail with the same error. - // Command reply serializer will handle repeating this error if needed. - out->results.emplace_back(ex.toStatus()); - return false; } out->results.emplace_back(ex.toStatus()); diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 96d7d910b27..dbb741ef668 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -42,7 +42,6 @@ env.Library( 'collection_sharding_state_factory_shard.cpp', 'collection_sharding_state_factory_standalone.cpp', 'config_server_op_observer.cpp', - 'implicit_create_collection.cpp', 'metadata_manager.cpp', 'migration_chunk_cloner_source_legacy.cpp', 'migration_chunk_cloner_source.cpp', @@ -263,7 +262,6 @@ env.Library( 'config/configsvr_commit_chunk_migration_command.cpp', 'config/configsvr_commit_move_primary_command.cpp', 'config/configsvr_control_balancer_command.cpp', - 'config/configsvr_create_collection_command.cpp', 'config/configsvr_create_database_command.cpp', 'config/configsvr_drop_collection_command.cpp', 'config/configsvr_drop_database_command.cpp', @@ -379,7 +377,6 @@ env.CppUnitTest( 'active_move_primaries_registry_test.cpp', 'active_shard_collection_registry_test.cpp', 'catalog_cache_loader_mock.cpp', - 'implicit_create_collection_test.cpp', 'migration_chunk_cloner_source_legacy_test.cpp', 'migration_destination_manager_test.cpp', 'migration_util_test.cpp', @@ -458,7 +455,6 @@ env.CppUnitTest( 'config/sharding_catalog_manager_clear_jumbo_flag_test.cpp', 'config/sharding_catalog_manager_commit_chunk_migration_test.cpp', 'config/sharding_catalog_manager_config_initialization_test.cpp', - 'config/sharding_catalog_manager_create_collection_test.cpp', 'config/sharding_catalog_manager_create_database_test.cpp', 'config/sharding_catalog_manager_drop_coll_test.cpp', 'config/sharding_catalog_manager_enable_sharding_test.cpp', diff --git a/src/mongo/db/s/config/configsvr_create_collection_command.cpp b/src/mongo/db/s/config/configsvr_create_collection_command.cpp deleted file mode 100644 index ddda9b19d99..00000000000 --- a/src/mongo/db/s/config/configsvr_create_collection_command.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include <set> - -#include "mongo/db/audit.h" -#include "mongo/db/auth/action_set.h" -#include "mongo/db/auth/action_type.h" -#include "mongo/db/auth/authorization_session.h" -#include "mongo/db/catalog/collection_options.h" -#include "mongo/db/commands.h" -#include "mongo/db/operation_context.h" -#include "mongo/db/repl/read_concern_args.h" -#include "mongo/db/s/config/sharding_catalog_manager.h" -#include "mongo/s/grid.h" -#include "mongo/s/request_types/create_collection_gen.h" - -namespace mongo { -namespace { - -/** - * Internal sharding command run on config servers to create a new collection with unassigned shard - * key. Call with { _configsvrCreateCollection: <string collName>, <other create options ...> } - */ -class ConfigSvrCreateCollectionCommand final - : public TypedCommand<ConfigSvrCreateCollectionCommand> { -public: - using Request = ConfigsvrCreateCollection; - - class Invocation final : public InvocationBase { - public: - using InvocationBase::InvocationBase; - - void typedRun(OperationContext* opCtx) { - uassert(ErrorCodes::IllegalOperation, - "_configsvrCreateCollection can only be run on config servers", - serverGlobalParams.clusterRole == ClusterRole::ConfigServer); - uassert(ErrorCodes::InvalidOptions, - str::stream() << "createCollection must be called with majority writeConcern", - opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); - - // Set the operation context read concern level to local for reads into the config - // database. - repl::ReadConcernArgs::get(opCtx) = - repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); - - CollectionOptions options; - if (auto requestOptions = request().getOptions()) { - options = uassertStatusOK(CollectionOptions::parse(*requestOptions)); - } - - auto const catalogClient = Grid::get(opCtx)->catalogClient(); - - auto scopedDbLock = - ShardingCatalogManager::get(opCtx)->serializeCreateOrDropDatabase(opCtx, ns().db()); - auto scopedCollLock = - ShardingCatalogManager::get(opCtx)->serializeCreateOrDropCollection(opCtx, ns()); - - auto dbDistLock = uassertStatusOK(catalogClient->getDistLockManager()->lock( - opCtx, ns().db(), "createCollection", DistLockManager::kDefaultLockTimeout)); - auto collDistLock = uassertStatusOK(catalogClient->getDistLockManager()->lock( - opCtx, ns().ns(), "createCollection", DistLockManager::kDefaultLockTimeout)); - - ShardingCatalogManager::get(opCtx)->createCollection(opCtx, ns(), options); - } - - private: - NamespaceString ns() const override { - return request().getCommandParameter(); - } - - bool supportsWriteConcern() const override { - return true; - } - - void doCheckAuthorization(OperationContext* opCtx) const override { - uassert(ErrorCodes::Unauthorized, - "Unauthorized", - AuthorizationSession::get(opCtx->getClient()) - ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(), - ActionType::internal)); - } - }; - -private: - AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { - return AllowedOnSecondary::kNever; - } - - bool adminOnly() const override { - return true; - } - - std::string help() const override { - return "Internal command, which is exported by the sharding config server. Do not call " - "directly. Create a collection."; - } -} configsvrCreateCollectionCmd; - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h index 8c327def29c..f2a2eacbec1 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.h +++ b/src/mongo/db/s/config/sharding_catalog_manager.h @@ -324,15 +324,6 @@ public: void generateUUIDsForExistingShardedCollections(OperationContext* opCtx); /** - * Creates a new unsharded collection with the given options. - * - * Throws exception on errors. - */ - void createCollection(OperationContext* opCtx, - const NamespaceString& ns, - const CollectionOptions& options); - - /** * Refines the shard key of an existing collection with namespace 'nss'. Here, 'shardKey' * denotes the new shard key, which must contain the old shard key as a prefix. * diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index 29639e79e6c..e669d3478f4 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -538,41 +538,6 @@ void ShardingCatalogManager::generateUUIDsForExistingShardedCollections(Operatio } } -void ShardingCatalogManager::createCollection(OperationContext* opCtx, - const NamespaceString& ns, - const CollectionOptions& collOptions) { - const auto catalogClient = Grid::get(opCtx)->catalogClient(); - auto shardRegistry = Grid::get(opCtx)->shardRegistry(); - - // Forward the create to the primary shard to either create the collection or verify that the - // collection already exists with the same options. - - auto dbEntry = - uassertStatusOK(catalogClient->getDatabase( - opCtx, ns.db().toString(), repl::ReadConcernLevel::kLocalReadConcern)) - .value; - const auto& primaryShardId = dbEntry.getPrimary(); - auto primaryShard = uassertStatusOK(shardRegistry->getShard(opCtx, primaryShardId)); - - BSONObjBuilder createCmdBuilder; - createCmdBuilder.append("create", ns.coll()); - collOptions.appendBSON(&createCmdBuilder); - createCmdBuilder.append(kWriteConcernField, opCtx->getWriteConcern().toBSON()); - auto swResponse = primaryShard->runCommandWithFixedRetryAttempts( - opCtx, - ReadPreferenceSetting{ReadPreference::PrimaryOnly}, - ns.db().toString(), - createCmdBuilder.obj(), - Shard::RetryPolicy::kIdempotent); - - auto createStatus = Shard::CommandResponse::getEffectiveStatus(swResponse); - if (!createStatus.isOK() && createStatus != ErrorCodes::NamespaceExists) { - uassertStatusOK(createStatus); - } - - checkCollectionOptions(opCtx, primaryShard.get(), ns, collOptions); -} - void ShardingCatalogManager::refineCollectionShardKey(OperationContext* opCtx, const NamespaceString& nss, const ShardKeyPattern& newShardKeyPattern) { diff --git a/src/mongo/db/s/config/sharding_catalog_manager_create_collection_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_create_collection_test.cpp deleted file mode 100644 index a25e50b0f4b..00000000000 --- a/src/mongo/db/s/config/sharding_catalog_manager_create_collection_test.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include <set> -#include <string> -#include <vector> - -#include "mongo/client/read_preference.h" -#include "mongo/client/remote_command_targeter_factory_mock.h" -#include "mongo/client/remote_command_targeter_mock.h" -#include "mongo/db/client.h" -#include "mongo/db/commands.h" -#include "mongo/db/s/config/sharding_catalog_manager.h" -#include "mongo/executor/network_interface_mock.h" -#include "mongo/executor/task_executor.h" -#include "mongo/s/catalog/type_database.h" -#include "mongo/s/client/shard_registry.h" -#include "mongo/s/config_server_test_fixture.h" -#include "mongo/s/grid.h" -#include "mongo/s/shard_key_pattern.h" -#include "mongo/stdx/future.h" -#include "mongo/util/scopeguard.h" - -namespace mongo { -namespace { - -using executor::NetworkInterfaceMock; -using executor::RemoteCommandRequest; -using executor::RemoteCommandResponse; -using executor::TaskExecutor; -using std::set; -using std::string; -using std::vector; -using unittest::assertGet; - -class CreateCollectionTest : public ConfigServerTestFixture { -public: - void expectCreate(const HostAndPort& receivingHost, - const NamespaceString& expectedNs, - Status response) { - onCommand([&](const RemoteCommandRequest& request) { - ASSERT_EQUALS(receivingHost, request.target); - string cmdName = request.cmdObj.firstElement().fieldName(); - - ASSERT_EQUALS("create", cmdName); - - const NamespaceString nss(request.dbname, request.cmdObj.firstElement().String()); - ASSERT_EQUALS(expectedNs.toString(), nss.toString()); - - BSONObjBuilder responseBuilder; - CommandHelpers::appendCommandStatusNoThrow(responseBuilder, response); - return responseBuilder.obj(); - }); - } - - void expectListCollection(const HostAndPort& receivingHost, - const string& expectedDb, - StatusWith<BSONObj> collectionOptionsReponse, - const UUID& uuid) { - onCommand([&](const RemoteCommandRequest& request) { - ASSERT_EQUALS(receivingHost, request.target); - string cmdName = request.cmdObj.firstElement().fieldName(); - - ASSERT_EQUALS("listCollections", cmdName); - - ASSERT_EQUALS(expectedDb, request.dbname); - - BSONObjBuilder responseBuilder; - - if (!collectionOptionsReponse.isOK()) { - CommandHelpers::appendCommandStatusNoThrow(responseBuilder, - collectionOptionsReponse.getStatus()); - } else { - BSONObjBuilder listCollResponse(responseBuilder.subobjStart("cursor")); - BSONArrayBuilder collArrayBuilder(listCollResponse.subarrayStart("firstBatch")); - - - BSONObjBuilder collBuilder; - collBuilder.append("options", collectionOptionsReponse.getValue()); - collBuilder.append("info", BSON("uuid" << uuid)); - collArrayBuilder.append(collBuilder.obj()); - - collArrayBuilder.done(); - listCollResponse.done(); - } - - return responseBuilder.obj(); - }); - } - -protected: - void setUp() override { - ConfigServerTestFixture::setUp(); - - extraShard.setName("extra"); - extraShard.setHost("a:10"); - - testPrimaryShard.setName("primary"); - testPrimaryShard.setHost("b:20"); - - setupShards({extraShard, testPrimaryShard}); - - // Prime the shard registry with information about the existing shards - shardRegistry()->reload(operationContext()); - - // Set up all the target mocks return values. - RemoteCommandTargeterMock::get( - uassertStatusOK(shardRegistry()->getShard(operationContext(), extraShard.getName())) - ->getTargeter()) - ->setFindHostReturnValue(HostAndPort(extraShard.getHost())); - RemoteCommandTargeterMock::get( - uassertStatusOK( - shardRegistry()->getShard(operationContext(), testPrimaryShard.getName())) - ->getTargeter()) - ->setFindHostReturnValue(HostAndPort(testPrimaryShard.getHost())); - } - - const ShardType& getPrimaryShard() const { - return testPrimaryShard; - } - -private: - ShardType extraShard; - ShardType testPrimaryShard; -}; - -TEST_F(CreateCollectionTest, BaseCase) { - NamespaceString testNS("test", "foo"); - const auto& primaryShard = getPrimaryShard(); - - setupDatabase(testNS.db().toString(), {primaryShard.getName()}, false); - - CollectionOptions requestOptions; - requestOptions.capped = true; - requestOptions.cappedSize = 256; - - auto future = launchAsync([this, &testNS, &requestOptions] { - ThreadClient tc("BaseCaseTest", getGlobalServiceContext()); - auto opCtx = cc().makeOperationContext(); - ShardingCatalogManager::get(opCtx.get()) - ->createCollection(opCtx.get(), testNS, requestOptions); - }); - - HostAndPort primaryHost(primaryShard.getHost()); - expectCreate(primaryHost, testNS, Status::OK()); - - auto uuid = UUID::gen(); - auto options = fromjson("{ capped: true, size: 256 }"); - expectListCollection(primaryHost, testNS.db().toString(), options, uuid); - future.default_timed_get(); -} - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/s/implicit_create_collection.cpp b/src/mongo/db/s/implicit_create_collection.cpp deleted file mode 100644 index b146eeb5076..00000000000 --- a/src/mongo/db/s/implicit_create_collection.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include "mongo/db/s/implicit_create_collection.h" - -#include <map> -#include <memory> -#include <string> - -#include "mongo/db/catalog/database_holder.h" -#include "mongo/db/catalog_raii.h" -#include "mongo/db/commands.h" -#include "mongo/db/namespace_string.h" -#include "mongo/db/operation_context.h" -#include "mongo/db/service_context.h" -#include "mongo/s/grid.h" -#include "mongo/s/request_types/create_collection_gen.h" - -#include "mongo/platform/mutex.h" -#include "mongo/stdx/condition_variable.h" -#include "mongo/util/scopeguard.h" - -namespace mongo { - -namespace { - -/** - * Responsible for explicitly creating collections in the sharding catalog. Also takes care of - * making sure that concurrent attempts to create a collection for the same ns will be - * synchronized and avoid duplicate work as much as possible. - */ - -class CreateCollectionSerializer { -public: - explicit CreateCollectionSerializer(NamespaceString ns) : _ns(std::move(ns)) {} - - /** - * Initialize this collection so it will be officially tracked in a sharded environment - * by sending the command to the config server to create an entry for this collection in - * the sharding catalog. - */ - Status onCannotImplicitlyCreateCollection(OperationContext* opCtx) noexcept { - invariant(!opCtx->lockState()->isLocked()); - - try { - stdx::unique_lock<Latch> lg(_mutex); - - opCtx->waitForConditionOrInterrupt(_cvIsInProgress, lg, [&] { return !_isInProgress; }); - - _isInProgress = true; - } catch (const DBException& e) { - return e.toStatus(); - } - - ON_BLOCK_EXIT([&] { - stdx::lock_guard<Latch> lg(_mutex); - _isInProgress = false; - _cvIsInProgress.notify_one(); - }); - - try { - // Take the DBLock and CollectionLock directly rather than using AutoGetCollection - // (which calls AutoGetDb) to avoid doing database and shard version checks. - Lock::DBLock dbLock(opCtx, _ns.db(), MODE_IS); - auto databaseHolder = DatabaseHolder::get(opCtx); - auto db = databaseHolder->getDb(opCtx, _ns.db()); - if (db) { - Lock::CollectionLock collLock(opCtx, _ns, MODE_IS); - if (CollectionCatalog::get(opCtx).lookupCollectionByNamespace(opCtx, _ns)) { - // Collection already created, no more work needs to be done. - return Status::OK(); - } - } - } catch (const DBException& ex) { - return ex.toStatus(); - } - - ConfigsvrCreateCollection configCreateCmd(_ns); - configCreateCmd.setDbName(NamespaceString::kAdminDb); - - auto statusWith = - Grid::get(opCtx)->shardRegistry()->getConfigShard()->runCommandWithFixedRetryAttempts( - opCtx, - ReadPreferenceSetting{ReadPreference::PrimaryOnly}, - NamespaceString::kAdminDb.toString(), - CommandHelpers::appendMajorityWriteConcern(configCreateCmd.toBSON({})), - Shard::RetryPolicy::kIdempotent); - - if (!statusWith.isOK()) { - return statusWith.getStatus(); - } - - return Shard::CommandResponse::getEffectiveStatus(statusWith.getValue()); - } - -private: - const NamespaceString _ns; - - Mutex _mutex = MONGO_MAKE_LATCH("CreateCollectionSerializer::_mutex"); - stdx::condition_variable _cvIsInProgress; - bool _isInProgress = false; -}; - -class CreateCollectionSerializerMap { -public: - std::shared_ptr<CreateCollectionSerializer> getForNs(const NamespaceString& ns) { - stdx::lock_guard<Latch> lg(_mutex); - auto iter = _inProgressMap.find(ns.ns()); - if (iter == _inProgressMap.end()) { - std::tie(iter, std::ignore) = - _inProgressMap.emplace(ns.ns(), std::make_shared<CreateCollectionSerializer>(ns)); - } - - return iter->second; - } - - void cleanupNs(const NamespaceString& ns) { - stdx::lock_guard<Latch> lg(_mutex); - _inProgressMap.erase(ns.ns()); - } - -private: - Mutex _mutex = MONGO_MAKE_LATCH("CreateCollectionSerializerMap::_mutex"); - std::map<std::string, std::shared_ptr<CreateCollectionSerializer>> _inProgressMap; -}; - -const auto createCollectionSerializerMap = - ServiceContext::declareDecoration<CreateCollectionSerializerMap>(); - -} // unnamed namespace - -Status onCannotImplicitlyCreateCollection(OperationContext* opCtx, - const NamespaceString& ns) noexcept { - auto& handlerMap = createCollectionSerializerMap(opCtx->getServiceContext()); - auto status = handlerMap.getForNs(ns)->onCannotImplicitlyCreateCollection(opCtx); - - if (status.isOK()) { - handlerMap.cleanupNs(ns); - } else { - // We only cleanup on success because that is our last chance for us to do so. This avoids - // the scenario with multiple handlers for the same ns to exist at the same time if we - // cleanup regardless of success or failure. On the other hand, cleaning it up only on - // success can cause the handler to never get cleaned up when the collection was - // successfully created, but this shard got an error response from the config - // server. - } - - return status; -} - -} // namespace mongo diff --git a/src/mongo/db/s/implicit_create_collection.h b/src/mongo/db/s/implicit_create_collection.h deleted file mode 100644 index d76a9ae7b2b..00000000000 --- a/src/mongo/db/s/implicit_create_collection.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include "mongo/base/status.h" - -namespace mongo { - -class NamespaceString; -class OperationContext; - -/** - * Initialize this collection so it will be officially tracked in a sharded environment - * by sending the command to the config server to create an entry for this collection in - * the sharding catalog. - */ -Status onCannotImplicitlyCreateCollection(OperationContext* opCtx, - const NamespaceString& ns) noexcept; - -} // namespace mongo diff --git a/src/mongo/db/s/implicit_create_collection_test.cpp b/src/mongo/db/s/implicit_create_collection_test.cpp deleted file mode 100644 index 9129b7867fe..00000000000 --- a/src/mongo/db/s/implicit_create_collection_test.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/bson/bsonobjbuilder.h" -#include "mongo/client/remote_command_targeter_mock.h" -#include "mongo/db/client.h" -#include "mongo/db/commands.h" -#include "mongo/db/dbdirectclient.h" -#include "mongo/db/namespace_string.h" -#include "mongo/db/s/implicit_create_collection.h" -#include "mongo/s/request_types/create_collection_gen.h" -#include "mongo/s/shard_server_test_fixture.h" -#include "mongo/unittest/unittest.h" -#include "mongo/util/assert_util.h" - -namespace mongo { -namespace { - -class ImplicitCreateTest : public ShardServerTestFixture { -public: - void expectConfigCreate(const NamespaceString& expectedNss, const Status& response) { - onCommand([&](const executor::RemoteCommandRequest& request) { - auto configHostStatus = configTargeterMock()->findHost(nullptr, {}); - ASSERT_OK(configHostStatus.getStatus()); - auto configHost = configHostStatus.getValue(); - - ASSERT_EQ(configHost, request.target); - auto cmdName = request.cmdObj.firstElement().fieldName(); - ASSERT_EQ(ConfigsvrCreateCollection::kCommandName, cmdName); - - ASSERT_EQ("admin", request.dbname); - ASSERT_EQ(expectedNss.ns(), request.cmdObj.firstElement().String()); - - BSONObjBuilder responseBuilder; - CommandHelpers::appendCommandStatusNoThrow(responseBuilder, response); - return responseBuilder.obj(); - }); - } -}; - -TEST_F(ImplicitCreateTest, NormalCreate) { - const NamespaceString kNs("test.user"); - auto future = launchAsync([this, &kNs] { - ThreadClient tc("Test", getGlobalServiceContext()); - auto opCtx = cc().makeOperationContext(); - ASSERT_OK(onCannotImplicitlyCreateCollection(opCtx.get(), kNs)); - }); - - expectConfigCreate(kNs, Status::OK()); - - future.default_timed_get(); -} - -TEST_F(ImplicitCreateTest, CanCallOnCannotImplicitAgainAfterError) { - const NamespaceString kNs("test.user"); - auto future = launchAsync([this, &kNs] { - ThreadClient tc("Test", getGlobalServiceContext()); - auto opCtx = cc().makeOperationContext(); - auto status = onCannotImplicitlyCreateCollection(opCtx.get(), kNs); - ASSERT_EQ(ErrorCodes::FailPointEnabled, status); - }); - - // return a non retryable error (just for testing) so the handler won't retry. - expectConfigCreate(kNs, {ErrorCodes::FailPointEnabled, "deliberate error"}); - - future.default_timed_get(); - - - // Retry, but this time config server will return success - - future = launchAsync([this, &kNs] { - ThreadClient tc("Test", getGlobalServiceContext()); - auto opCtx = cc().makeOperationContext(); - ASSERT_OK(onCannotImplicitlyCreateCollection(opCtx.get(), kNs)); - }); - - expectConfigCreate(kNs, Status::OK()); - - future.default_timed_get(); -} - -TEST_F(ImplicitCreateTest, ShouldNotCallConfigCreateIfCollectionExists) { - const NamespaceString kNs("test.user"); - auto future = launchAsync([this, &kNs] { - ThreadClient tc("Test", getGlobalServiceContext()); - auto opCtx = cc().makeOperationContext(); - auto status = onCannotImplicitlyCreateCollection(opCtx.get(), kNs); - ASSERT_EQ(ErrorCodes::FailPointEnabled, status); - }); - - // return a non retryable error (just for testing) so the handler won't retry. - expectConfigCreate(kNs, {ErrorCodes::FailPointEnabled, "deliberate error"}); - - future.default_timed_get(); - - // Simulate config server successfully creating the collection despite returning error. - DBDirectClient client(operationContext()); - BSONObj result; - ASSERT_TRUE( - client.runCommand(kNs.db().toString(), BSON("create" << kNs.coll().toString()), result)); - - // Retry, but this time config server will return success - - future = launchAsync([this, &kNs] { - ThreadClient tc("Test", getGlobalServiceContext()); - auto opCtx = cc().makeOperationContext(); - ASSERT_OK(onCannotImplicitlyCreateCollection(opCtx.get(), kNs)); - }); - - // Not expecting this shard to send any remote command. - - future.default_timed_get(); -} - -} // unnamed namespace -} // namespace mongo diff --git a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp index bfe795894a5..aaa09ecbefb 100644 --- a/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp +++ b/src/mongo/db/s/scoped_operation_completion_sharding_actions.cpp @@ -34,12 +34,10 @@ #include "mongo/db/s/scoped_operation_completion_sharding_actions.h" #include "mongo/db/curop.h" -#include "mongo/db/s/implicit_create_collection.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" -#include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/s/stale_exception.h" namespace mongo { @@ -101,20 +99,6 @@ ScopedOperationCompletionShardingActions::~ScopedOperationCompletionShardingActi LOGV2(22054, "Failed to handle database version exception{causedBy_handleMismatchStatus}", "causedBy_handleMismatchStatus"_attr = causedBy(redact(handleMismatchStatus))); - } else if (auto cannotImplicitCreateCollInfo = - status->extraInfo<CannotImplicitlyCreateCollectionInfo>()) { - if (ShardingState::get(_opCtx)->enabled() && - serverGlobalParams.featureCompatibility.getVersion() == - ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo42) { - auto handleCannotImplicitCreateStatus = - onCannotImplicitlyCreateCollection(_opCtx, cannotImplicitCreateCollInfo->getNss()); - if (!handleCannotImplicitCreateStatus.isOK()) - LOGV2(22055, - "Failed to handle CannotImplicitlyCreateCollection " - "exception{causedBy_handleCannotImplicitCreateStatus}", - "causedBy_handleCannotImplicitCreateStatus"_attr = - causedBy(redact(handleCannotImplicitCreateStatus))); - } } } diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index 6dfc27e8d3d..4c3cfc4738e 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -39,7 +39,6 @@ #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/repl/speculative_majority_read_info.h" -#include "mongo/db/s/implicit_create_collection.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/scoped_operation_completion_sharding_actions.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" @@ -50,7 +49,6 @@ #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/rpc/metadata/config_server_metadata.h" #include "mongo/rpc/metadata/sharding_metadata.h" -#include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/s/grid.h" #include "mongo/s/stale_exception.h" @@ -220,14 +218,6 @@ public: opCtx, sce->getDb(), sce->getVersionReceived(), sce->getVersionWanted()) .ignore(); } - } else if (auto cannotImplicitCreateCollInfo = - e.extraInfo<CannotImplicitlyCreateCollectionInfo>()) { - if (ShardingState::get(opCtx)->enabled() && - serverGlobalParams.featureCompatibility.getVersion() == - ServerGlobalParams::FeatureCompatibility::Version::kFullyDowngradedTo42) { - onCannotImplicitlyCreateCollection(opCtx, cannotImplicitCreateCollInfo->getNss()) - .ignore(); - } } } diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index ae5abb32e69..bfa7e9510c0 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -185,7 +185,6 @@ env.Library( env.Idlc('request_types/clone_catalog_data.idl')[0], env.Idlc('request_types/clear_jumbo_flag.idl')[0], env.Idlc('request_types/clone_collection_options_from_primary_shard.idl')[0], - env.Idlc('request_types/create_collection.idl')[0], env.Idlc('request_types/create_database.idl')[0], env.Idlc('request_types/ensure_chunk_version_is_greater_than.idl')[0], env.Idlc('request_types/flush_database_cache_updates.idl')[0], diff --git a/src/mongo/s/commands/cluster_create_cmd.cpp b/src/mongo/s/commands/cluster_create_cmd.cpp index d1a3fc792fc..4d3d0aa7f89 100644 --- a/src/mongo/s/commands/cluster_create_cmd.cpp +++ b/src/mongo/s/commands/cluster_create_cmd.cpp @@ -37,7 +37,6 @@ #include "mongo/rpc/get_status_from_command_result.h" #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/grid.h" -#include "mongo/s/request_types/create_collection_gen.h" namespace mongo { namespace { diff --git a/src/mongo/s/request_types/create_collection.idl b/src/mongo/s/request_types/create_collection.idl deleted file mode 100644 index 3ff3cfa6ea7..00000000000 --- a/src/mongo/s/request_types/create_collection.idl +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (C) 2018-present MongoDB, Inc. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the Server Side Public License, version 1, -# as published by MongoDB, Inc. -# -# 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 -# Server Side Public License for more details. -# -# You should have received a copy of the Server Side Public License -# along with this program. If not, see -# <http://www.mongodb.com/licensing/server-side-public-license>. -# -# As a special exception, the copyright holders give permission to link the -# code of portions of this program with the OpenSSL library under certain -# conditions as described in each individual source file and distribute -# linked combinations including the program with the OpenSSL library. You -# must comply with the Server Side Public License in all respects for -# all of the code used other than as permitted herein. If you modify file(s) -# with this exception, you may extend this exception to your version of the -# file(s), but you are not obligated to do so. If you do not wish to do so, -# delete this exception statement from your version. If you delete this -# exception statement from all source files in the program, then also delete -# it in the license file. -# - -# createDatabase IDL File - -global: - cpp_namespace: "mongo" - -imports: - - "mongo/idl/basic_types.idl" - -commands: - _configsvrCreateCollection: - cpp_name: ConfigsvrCreateCollection - description: "The internal createCollection command on the config server" - strict: false - namespace: type - type: namespacestring - fields: - options: - type: object - optional: true - description: "collection creation options" |