diff options
-rw-r--r-- | jstests/auth/lib/commands_lib.js | 28 | ||||
-rw-r--r-- | jstests/core/commands_namespace_parsing.js | 6 | ||||
-rw-r--r-- | jstests/core/views/views_all_commands.js | 1 | ||||
-rw-r--r-- | jstests/libs/override_methods/network_error_and_txn_override.js | 1 | ||||
-rw-r--r-- | jstests/libs/override_methods/read_and_write_concern_helpers.js | 1 | ||||
-rw-r--r-- | jstests/noPassthrough/collation_clone_collection.js | 76 | ||||
-rw-r--r-- | jstests/noPassthrough/index_version_autoupgrade.js | 14 | ||||
-rw-r--r-- | jstests/noPassthroughWithMongod/clonecollection.js | 69 | ||||
-rw-r--r-- | jstests/sharding/safe_secondary_reads_drop_recreate.js | 1 | ||||
-rw-r--r-- | jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js | 1 | ||||
-rw-r--r-- | jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/commands/clone_collection.cpp | 170 | ||||
-rw-r--r-- | src/mongo/shell/db.js | 27 |
14 files changed, 0 insertions, 397 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js index 92f7a324913..0e036a65835 100644 --- a/jstests/auth/lib/commands_lib.js +++ b/jstests/auth/lib/commands_lib.js @@ -2034,34 +2034,6 @@ var authCommandsLib = { ] }, { - testname: "cloneCollection_1", - command: {cloneCollection: firstDbName + ".x"}, - skipSharded: true, - testcases: [{ - runOnDb: firstDbName, - roles: roles_write, - privileges: [{ - resource: {db: firstDbName, collection: "x"}, - actions: ["insert", "createIndex"] - }], - expectFail: true - }] - }, - { - testname: "cloneCollection_2", - command: {cloneCollection: secondDbName + ".x"}, - skipSharded: true, - testcases: [{ - runOnDb: secondDbName, - roles: {readWriteAnyDatabase: 1, restore: 1, root: 1, __system: 1}, - privileges: [{ - resource: {db: secondDbName, collection: "x"}, - actions: ["insert", "createIndex"] - }], - expectFail: true - }] - }, - { testname: "cloneCollectionAsCapped", command: {cloneCollectionAsCapped: "x", toCollection: "y", size: 1000}, skipSharded: true, diff --git a/jstests/core/commands_namespace_parsing.js b/jstests/core/commands_namespace_parsing.js index ab9750bfbb5..7a48c4df7a8 100644 --- a/jstests/core/commands_namespace_parsing.js +++ b/jstests/core/commands_namespace_parsing.js @@ -243,12 +243,6 @@ "create", {create: ""}, isNotFullyQualified, isNotAdminCommand); if (!isMongos) { - // Test cloneCollection fails with an invalid collection name. - assertFailsWithInvalidNamespacesForField("cloneCollection", - {cloneCollection: "", from: "fakehost"}, - isNotFullyQualified, - isNotAdminCommand); - // Test cloneCollectionAsCapped fails with an invalid source collection name. assertFailsWithInvalidNamespacesForField( "cloneCollectionAsCapped", diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index 716e82c5fac..48ea40041c8 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -133,7 +133,6 @@ skip: "Tested in views/views_sharded.js", }, clearLog: {skip: isUnrelated}, - cloneCollection: {skip: "Tested in noPassthroughWithMongod/clonecollection.js"}, cloneCollectionAsCapped: { command: {cloneCollectionAsCapped: "view", toCollection: "testcapped", size: 10240}, expectFailure: true, diff --git a/jstests/libs/override_methods/network_error_and_txn_override.js b/jstests/libs/override_methods/network_error_and_txn_override.js index 440f10d3c50..8c9090bb6ba 100644 --- a/jstests/libs/override_methods/network_error_and_txn_override.js +++ b/jstests/libs/override_methods/network_error_and_txn_override.js @@ -88,7 +88,6 @@ "captrunc", "cleanupOrphaned", "clone", - "cloneCollection", "cloneCollectionAsCapped", "collMod", "convertToCapped", diff --git a/jstests/libs/override_methods/read_and_write_concern_helpers.js b/jstests/libs/override_methods/read_and_write_concern_helpers.js index 6a04d6dc260..6581960eea5 100644 --- a/jstests/libs/override_methods/read_and_write_concern_helpers.js +++ b/jstests/libs/override_methods/read_and_write_concern_helpers.js @@ -40,7 +40,6 @@ var kCommandsSupportingWriteConcern = new Set([ "captrunc", "cleanupOrphaned", "clone", - "cloneCollection", "cloneCollectionAsCapped", "collMod", "commitTransaction", diff --git a/jstests/noPassthrough/collation_clone_collection.js b/jstests/noPassthrough/collation_clone_collection.js deleted file mode 100644 index 538b49d2077..00000000000 --- a/jstests/noPassthrough/collation_clone_collection.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Tests that the "cloneCollection" command inherits the collection-default collation and that it is - * used when filtering the source collection. - */ -(function() { - "use strict"; - - var source = MongoRunner.runMongod({}); - assert.neq(null, source, "mongod was unable to start up"); - - var dest = MongoRunner.runMongod({}); - assert.neq(null, dest, "mongod was unable to start up"); - - var sourceColl = source.getDB("test").collation; - var destColl = dest.getDB("test").collation; - - assert.commandWorked(sourceColl.getDB().runCommand( - {create: sourceColl.getName(), collation: {locale: "en", strength: 2}})); - // We remove UUIDs before comparing as collection cloning results in a new UUID. - var sourceCollectionInfos = - sourceColl.getDB().getCollectionInfos({name: sourceColl.getName()}).map((collInfo) => { - delete collInfo.info.uuid; - return collInfo; - }); - - assert.writeOK(sourceColl.insert({_id: "FOO"})); - assert.writeOK(sourceColl.insert({_id: "bar"})); - assert.eq([{_id: "FOO"}], - sourceColl.find({_id: "foo"}).toArray(), - "query should have performed a case-insensitive match"); - - assert.commandWorked( - sourceColl.createIndex({withSimpleCollation: 1}, {collation: {locale: "simple"}})); - assert.commandWorked(sourceColl.createIndex({withDefaultCollation: 1})); - assert.commandWorked( - sourceColl.createIndex({withNonDefaultCollation: 1}, {collation: {locale: "fr"}})); - var sourceIndexInfos = sourceColl.getIndexes().map(function(indexInfo) { - // We remove the "ns" field from the index specification when comparing whether the indexes - // that were cloned are equivalent because they were built on a different namespace. - delete indexInfo.ns; - return indexInfo; - }); - - // Test that the "cloneCollection" command respects the collection-default collation. - destColl.drop(); - assert.commandWorked(destColl.getDB().runCommand({ - cloneCollection: sourceColl.getFullName(), - from: sourceColl.getMongo().host, - query: {_id: "foo"} - })); - - var destCollectionInfos = - destColl.getDB().getCollectionInfos({name: destColl.getName()}).map((collInfo) => { - delete collInfo.info.uuid; - return collInfo; - }); - assert.eq(sourceCollectionInfos, destCollectionInfos); - assert.eq([{_id: "FOO"}], destColl.find({}).toArray()); - - var destIndexInfos = destColl.getIndexes().map(function(indexInfo) { - // We remove the "ns" field from the index specification when comparing whether the indexes - // that were cloned are equivalent because they were built on a different namespace. - delete indexInfo.ns; - return indexInfo; - }); - - assert.eq(sourceIndexInfos.length, - destIndexInfos.length, - "Number of indexes don't match; source: " + tojson(sourceIndexInfos) + ", dest: " + - tojson(destIndexInfos)); - for (var i = 0; i < sourceIndexInfos.length; ++i) { - assert.contains(sourceIndexInfos[i], destIndexInfos); - } - MongoRunner.stopMongod(source); - MongoRunner.stopMongod(dest); -})(); diff --git a/jstests/noPassthrough/index_version_autoupgrade.js b/jstests/noPassthrough/index_version_autoupgrade.js index fef289ddca5..cbb8710a2bb 100644 --- a/jstests/noPassthrough/index_version_autoupgrade.js +++ b/jstests/noPassthrough/index_version_autoupgrade.js @@ -122,19 +122,5 @@ return coll; }, false); - // Test that the "cloneCollection" command doesn't upgrade existing indexes to the latest - // version. - var cloneConn = MongoRunner.runMongod({}); - assert.neq(null, cloneConn, "mongod was unable to start up"); - testIndexVersionAutoUpgrades(function(coll) { - var cloneDB = cloneConn.getDB(coll.getDB().getName()); - assert.commandWorked(cloneDB.runCommand({ - cloneCollection: coll.getFullName(), - from: conn.host, - })); - return cloneDB[coll.getName()]; - }, false); - MongoRunner.stopMongod(cloneConn); - MongoRunner.stopMongod(conn); })(); diff --git a/jstests/noPassthroughWithMongod/clonecollection.js b/jstests/noPassthroughWithMongod/clonecollection.js deleted file mode 100644 index 8ae9203a93a..00000000000 --- a/jstests/noPassthroughWithMongod/clonecollection.js +++ /dev/null @@ -1,69 +0,0 @@ -// @tags: [requires_capped, requires_profiling] -// Test cloneCollection command -var baseName = "jstests_clonecollection"; - -var fromMongod = MongoRunner.runMongod({bind_ip: "127.0.0.1"}); -var toMongod = MongoRunner.runMongod({bind_ip: "127.0.0.1"}); -var f = fromMongod.getDB(baseName); -var t = toMongod.getDB(baseName); - -for (i = 0; i < 1000; ++i) { - f.a.save({i: i}); -} -assert.eq(1000, f.a.find().count(), "A1"); - -assert.commandWorked(t.cloneCollection("localhost:" + fromMongod.port, "a")); -assert.eq(1000, t.a.find().count(), "A2"); - -t.a.drop(); - -assert.commandWorked( - t.cloneCollection("localhost:" + fromMongod.port, "a", {i: {$gte: 10, $lt: 20}})); -assert.eq(10, t.a.find().count(), "A3"); - -t.a.drop(); -assert.eq(0, t.a.getIndexes().length, "prep 2"); - -f.a.ensureIndex({i: 1}); -assert.eq(2, f.a.getIndexes().length, "expected index missing"); -assert.commandWorked(t.cloneCollection("localhost:" + fromMongod.port, "a")); -if (t.a.getIndexes().length != 2) { - printjson(t.a.getIndexes()); -} -assert.eq(2, t.a.getIndexes().length, "expected index missing"); -// Verify index works -x = t.a.find({i: 50}).hint({i: 1}).explain("executionStats"); -printjson(x); -assert.eq(1, x.executionStats.nReturned, "verify 1"); -assert.eq( - 1, t.a.find({i: 50}).hint({i: 1}).toArray().length, "match length did not match expected"); - -// Check that capped-ness is preserved on clone -f.a.drop(); -t.a.drop(); - -f.createCollection("a", {capped: true, size: 1000}); -assert(f.a.isCapped()); -assert.commandWorked(t.cloneCollection("localhost:" + fromMongod.port, "a")); -assert(t.a.isCapped(), "cloned collection not capped"); - -// Check that cloning to "system.profile" is disallowed. -f.a.drop(); -f.system.profile.drop(); -assert.commandWorked(f.setProfilingLevel(2)); -assert.writeOK(f.a.insert({})); -assert.gt(f.system.profile.count(), 0); -t.system.profile.drop(); -assert.commandFailed(t.cloneCollection("localhost:" + fromMongod.port, "system.profile")); - -// Check that cloning a view is disallowed. -f.a.drop(); -t.a.drop(); - -assert.commandWorked(f.createCollection("a")); -assert.commandWorked(f.createView("viewA", "a", [])); -assert.commandFailedWithCode(t.cloneCollection("localhost:" + fromMongod.port, "viewA"), - ErrorCodes.CommandNotSupportedOnView, - "cloneCollection on view expected to fail"); -MongoRunner.stopMongod(fromMongod); -MongoRunner.stopMongod(toMongod); diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index 1f36e62d4ed..33f0f59b437 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -95,7 +95,6 @@ cleanupOrphaned: {skip: "primary only"}, clearLog: {skip: "does not return user data"}, clone: {skip: "primary only"}, - cloneCollection: {skip: "primary only"}, cloneCollectionAsCapped: {skip: "primary only"}, collMod: {skip: "primary only"}, collStats: {skip: "does not return user data"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js index be3fff92b50..08904a0bc1b 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js @@ -108,7 +108,6 @@ cleanupOrphaned: {skip: "primary only"}, clearLog: {skip: "does not return user data"}, clone: {skip: "primary only"}, - cloneCollection: {skip: "primary only"}, cloneCollectionAsCapped: {skip: "primary only"}, commitTransaction: {skip: "primary only"}, collMod: {skip: "primary only"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js index 8e252ffeda0..a6286881c8e 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js @@ -96,7 +96,6 @@ cleanupOrphaned: {skip: "primary only"}, clearLog: {skip: "does not return user data"}, clone: {skip: "primary only"}, - cloneCollection: {skip: "primary only"}, cloneCollectionAsCapped: {skip: "primary only"}, collMod: {skip: "primary only"}, collStats: {skip: "does not return user data"}, diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 92f872ff445..69c9bca759b 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -342,7 +342,6 @@ env.Library( target="mongod", source=[ "apply_ops_cmd.cpp", - "clone_collection.cpp", "collection_to_capped.cpp", "compact.cpp", "cpuload.cpp", diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp deleted file mode 100644 index 5fa66f56b23..00000000000 --- a/src/mongo/db/commands/clone_collection.cpp +++ /dev/null @@ -1,170 +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::kCommand - -#include "mongo/platform/basic.h" - -#include "mongo/base/init.h" -#include "mongo/base/status.h" -#include "mongo/bson/util/builder.h" -#include "mongo/client/dbclient_connection.h" -#include "mongo/db/auth/action_set.h" -#include "mongo/db/auth/authorization_session.h" -#include "mongo/db/auth/resource_pattern.h" -#include "mongo/db/catalog/collection.h" -#include "mongo/db/catalog/document_validation.h" -#include "mongo/db/cloner.h" -#include "mongo/db/commands.h" -#include "mongo/db/commands/rename_collection.h" -#include "mongo/db/jsobj.h" -#include "mongo/db/namespace_string.h" -#include "mongo/db/ops/insert.h" -#include "mongo/db/repl/isself.h" -#include "mongo/db/storage/storage_options.h" -#include "mongo/util/log.h" - -namespace mongo { - -using std::unique_ptr; -using std::string; -using std::stringstream; -using std::endl; - -/** - * The cloneCollection command is deprecated. - * See http://dochub.mongodb.org/core/clonecollection-deprecation. - */ -class CmdCloneCollection : public ErrmsgCommandDeprecated { -public: - CmdCloneCollection() : ErrmsgCommandDeprecated("cloneCollection") {} - - AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { - return AllowedOnSecondary::kNever; - } - - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { - return true; - } - - virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const { - return CommandHelpers::parseNsFullyQualified(cmdObj); - } - - virtual Status checkAuthForCommand(Client* client, - const std::string& dbname, - const BSONObj& cmdObj) const { - std::string ns = parseNs(dbname, cmdObj); - - ActionSet actions; - actions.addAction(ActionType::insert); - actions.addAction(ActionType::createIndex); // SERVER-11418 - if (shouldBypassDocumentValidationForCommand(cmdObj)) { - actions.addAction(ActionType::bypassDocumentValidation); - } - - if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forExactNamespace(NamespaceString(ns)), actions)) { - return Status(ErrorCodes::Unauthorized, "Unauthorized"); - } - return Status::OK(); - } - - std::string help() const override { - return "{ cloneCollection: <collection>, from: <host> [,query: <query_filter>] " - "[,copyIndexes:<bool>] }" - "\nCopies a collection from one server to another. Do not use on a single server " - "as the destination " - "is placed at the same db.collection (namespace) as the source.\n"; - } - - virtual bool errmsgRun(OperationContext* opCtx, - const string& dbname, - const BSONObj& cmdObj, - string& errmsg, - BSONObjBuilder& result) { - const char* deprecationWarning = - "Support for the cloneCollection command has been deprecated. See " - "http://dochub.mongodb.org/core/clonecollection-deprecation"; - warning() << deprecationWarning; - result.append("note", deprecationWarning); - - boost::optional<DisableDocumentValidation> maybeDisableValidation; - if (shouldBypassDocumentValidationForCommand(cmdObj)) - maybeDisableValidation.emplace(opCtx); - - string fromhost = cmdObj.getStringField("from"); - if (fromhost.empty()) { - errmsg = "missing 'from' parameter"; - return false; - } - - { - HostAndPort h(fromhost); - if (repl::isSelf(h, opCtx->getServiceContext())) { - errmsg = "can't cloneCollection from self"; - return false; - } - } - - auto ns = parseNs(dbname, cmdObj); - - // In order to clone a namespace, a user must be allowed to both create and write to that - // namespace. There exist namespaces that are legal to create but not write to (e.g. - // system.profile), and there exist namespaces that are legal to write to but not create, - // so we must check that it is legal to both create and write to the namespace. - auto allowedCreateStatus = userAllowedCreateNS(dbname, nsToCollectionSubstring(ns)); - uassertStatusOK(allowedCreateStatus); - auto allowedWriteStatus = userAllowedWriteNS(dbname, nsToCollectionSubstring(ns)); - uassertStatusOK(allowedWriteStatus); - - BSONObj query = cmdObj.getObjectField("query"); - if (query.isEmpty()) - query = BSONObj(); - - BSONElement copyIndexesSpec = cmdObj.getField("copyindexes"); - bool copyIndexes = copyIndexesSpec.isBoolean() ? copyIndexesSpec.boolean() : true; - - log() << "cloneCollection. collection: " << ns << " from: " << fromhost - << " query: " << redact(query) << " " << (copyIndexes ? "" : ", not copying indexes"); - - Cloner cloner; - auto myconn = std::make_unique<DBClientConnection>(); - if (!myconn->connect(HostAndPort(fromhost), StringData(), errmsg)) - return false; - - cloner.setConnection(std::move(myconn)); - - return cloner.copyCollection( - opCtx, ns, query, errmsg, copyIndexes, CollectionOptions::parseForCommand); - } - -} cmdCloneCollection; - -} // namespace mongo diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js index 234f905a9db..a309bda09d2 100644 --- a/src/mongo/shell/db.js +++ b/src/mongo/shell/db.js @@ -462,33 +462,6 @@ var DB; }; /** - Clone collection on another server to here. - <p> - Generally, you should drop() first as otherwise the cloned information will MERGE - into whatever data is already present in this collection. (That is however a valid way to use - clone if you are trying to do something intentionally, such as union three non-overlapping - collections into one.) - <p> - This is a low level administrative function is not typically used. - - * @param {String} from mongod instance from which to clnoe (dbhostname:port). May - not be this mongod instance, as clone from self is not allowed. - * @param {String} collection name of collection to clone. - * @param {Object} query query specifying which elements of collection are to be cloned. - * @return Object returned has member ok set to true if operation succeeds, false otherwise. - * See also: db.cloneDatabase() - */ - DB.prototype.cloneCollection = function(from, collection, query) { - print( - "WARNING: db.cloneCollection is deprecated. See http://dochub.mongodb.org/core/clonecollection-deprecation"); - assert(isString(from) && from.length); - assert(isString(collection) && collection.length); - collection = this._name + "." + collection; - query = query || {}; - return this._dbCommand({cloneCollection: collection, from: from, query: query}); - }; - - /** Copy database from one server or name to another server or name. This functionality was removed as of MongoDB 4.2. The shell helper is kept to maintain compatibility with previous versions of MongoDB. |