diff options
29 files changed, 30 insertions, 229 deletions
diff --git a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_100ms_refresh_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_100ms_refresh_jscore_passthrough.yml index 3a76ef4b0b0..fe9734de910 100644 --- a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_100ms_refresh_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_100ms_refresh_jscore_passthrough.yml @@ -64,7 +64,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. diff --git a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_10sec_refresh_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_10sec_refresh_jscore_passthrough.yml index 36ca87d9587..553be272de3 100644 --- a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_10sec_refresh_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_10sec_refresh_jscore_passthrough.yml @@ -64,7 +64,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. diff --git a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_1sec_refresh_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_1sec_refresh_jscore_passthrough.yml index e383e9771d3..9cabeac41a6 100644 --- a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_1sec_refresh_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_1sec_refresh_jscore_passthrough.yml @@ -64,7 +64,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. diff --git a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_default_refresh_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_default_refresh_jscore_passthrough.yml index b21d11671b3..954521c68ba 100644 --- a/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_default_refresh_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/logical_session_cache_sharding_default_refresh_jscore_passthrough.yml @@ -64,7 +64,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. diff --git a/buildscripts/resmokeconfig/suites/multi_shard_local_read_write_multi_stmt_txn_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/multi_shard_local_read_write_multi_stmt_txn_jscore_passthrough.yml index 8b6001fb74e..89817886bc4 100644 --- a/buildscripts/resmokeconfig/suites/multi_shard_local_read_write_multi_stmt_txn_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/multi_shard_local_read_write_multi_stmt_txn_jscore_passthrough.yml @@ -65,7 +65,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. @@ -213,7 +212,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_jscore_passthrough.yml index df5469ade22..c354b2a4501 100644 --- a/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_jscore_passthrough.yml @@ -65,7 +65,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. @@ -232,7 +231,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_kill_primary_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_kill_primary_jscore_passthrough.yml index d4e3cf62f58..e1f50247123 100644 --- a/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_kill_primary_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_kill_primary_jscore_passthrough.yml @@ -65,7 +65,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. @@ -224,7 +223,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_stepdown_primary_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_stepdown_primary_jscore_passthrough.yml index 68bca7241a3..ea29663a077 100644 --- a/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_stepdown_primary_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/multi_shard_multi_stmt_txn_stepdown_primary_jscore_passthrough.yml @@ -65,7 +65,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. @@ -233,7 +232,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/multi_stmt_txn_jscore_passthrough_with_migration.yml b/buildscripts/resmokeconfig/suites/multi_stmt_txn_jscore_passthrough_with_migration.yml index f950cc7360c..b919db9de0e 100644 --- a/buildscripts/resmokeconfig/suites/multi_stmt_txn_jscore_passthrough_with_migration.yml +++ b/buildscripts/resmokeconfig/suites/multi_stmt_txn_jscore_passthrough_with_migration.yml @@ -65,7 +65,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. @@ -249,7 +248,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_jscore_passthrough.yml index b410d992b46..e259d666b48 100644 --- a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_jscore_passthrough.yml @@ -145,7 +145,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_kill_primary_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_kill_primary_jscore_passthrough.yml index d1efa9fc8c3..62a3289a1d8 100644 --- a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_kill_primary_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_kill_primary_jscore_passthrough.yml @@ -142,7 +142,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_stepdown_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_stepdown_jscore_passthrough.yml index f7d0e6f0122..fe9b5c962c8 100644 --- a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_stepdown_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_stepdown_jscore_passthrough.yml @@ -142,7 +142,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_terminate_primary_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_terminate_primary_jscore_passthrough.yml index fa050d52bfa..dced4b45c1f 100644 --- a/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_terminate_primary_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/replica_sets_multi_stmt_txn_terminate_primary_jscore_passthrough.yml @@ -139,7 +139,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_passthrough.yml index 2446c3b4422..a25ccae3179 100644 --- a/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharded_causally_consistent_jscore_passthrough.yml @@ -60,7 +60,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # TODO: Remove after fixing SERVER-14324. mapReduce behaves unpredictably when the out diff --git a/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml index e4eb9547279..6ddae0f2c5a 100644 --- a/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharded_collections_jscore_passthrough.yml @@ -65,7 +65,6 @@ selector: - jstests/core/dbcase.js - jstests/core/dbcase2.js - jstests/core/no_db_created.js - - jstests/core/ns_length.js - jstests/core/views/*.js # Views tests aren't expected to work when collections are implicitly sharded. - jstests/core/killop_drop_collection.js # Uses fsyncLock. # These tests fail because sharded clusters do not clean up correctly after failed index builds. diff --git a/buildscripts/resmokeconfig/suites/sharded_multi_stmt_txn_jscore_passthrough.yml b/buildscripts/resmokeconfig/suites/sharded_multi_stmt_txn_jscore_passthrough.yml index 1c5e2052f5c..3959f118c97 100644 --- a/buildscripts/resmokeconfig/suites/sharded_multi_stmt_txn_jscore_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/sharded_multi_stmt_txn_jscore_passthrough.yml @@ -187,7 +187,6 @@ selector: - jstests/core/doc_validation_options.js - jstests/core/geo_multinest0.js - jstests/core/insert_illegal_doc.js - - jstests/core/ns_length.js - jstests/core/push2.js - jstests/core/remove6.js - jstests/core/removeb.js diff --git a/jstests/core/create_collection.js b/jstests/core/create_collection.js index 06c820f1462..00368b38462 100644 --- a/jstests/core/create_collection.js +++ b/jstests/core/create_collection.js @@ -18,6 +18,12 @@ assert.commandFailedWithCode(db.createCollection("a\0b"), ErrorCodes.InvalidNamespace); assert.commandFailedWithCode(db.createCollection("ab\0"), ErrorCodes.InvalidNamespace); + // The collection name length limit was removed in 4.4, try creating a collection with a longer + // name than previously allowed. + const longCollName = 'a'.repeat(8192); + db[longCollName].drop(); + assert.commandWorked(db.createCollection(longCollName)); + // // Tests for "idIndex" field. // diff --git a/jstests/core/long_index_rename.js b/jstests/core/long_index_rename.js index 06361a10cde..41e89825570 100644 --- a/jstests/core/long_index_rename.js +++ b/jstests/core/long_index_rename.js @@ -12,16 +12,8 @@ coll.save({a: i}); } - // Compute maximum index name length for this collection under FCV 4.0. - const maxNsLength = 127; - const maxIndexNameLength = maxNsLength - (coll.getFullName() + ".$").length; - jsTestLog('Max index name length under FCV 4.0 = ' + maxIndexNameLength); - - // Create an index with the longest name allowed for this collection. - assert.commandWorked(coll.createIndex({a: 1}, {name: 'a'.repeat(maxIndexNameLength)})); - // Beginning with 4.2, index namespaces longer than 127 characters are acceptable. - assert.commandWorked(coll.createIndex({b: 1}, {name: 'b'.repeat(maxIndexNameLength) + 1})); + assert.commandWorked(coll.createIndex({b: 1}, {name: 'a'.repeat(8192)})); // Before 4.2, index namespace lengths were checked while renaming collections. const dest = db.long_index_rename2; diff --git a/jstests/core/ns_length.js b/jstests/core/ns_length.js deleted file mode 100644 index 405d319630a..00000000000 --- a/jstests/core/ns_length.js +++ /dev/null @@ -1,95 +0,0 @@ -/** SERVER-7282 Faulty logic when testing maximum collection name length. - * @tags: [requires_non_retryable_commands, assumes_unsharded_collection] - */ - -(function() { - 'use strict'; - - // constants from server - const maxNsLength = 127; - const maxNsCollectionLength = 120; - - const myDb = db.getSiblingDB("ns_length"); - myDb.dropDatabase(); // start empty - - function mkStr(length) { - let s = ""; - while (s.length < length) { - s += "x"; - } - return s; - } - - function canMakeCollectionWithName(name) { - assert.eq(myDb.stats().storageSize, 0, "initial conditions"); - - let success = false; - try { - // may either throw or return an error - success = !(myDb[name].insert({}).hasWriteError()); - } catch (e) { - success = false; - } - - if (!success) { - assert.eq(myDb.stats().storageSize, 0, "no files should be created on error"); - return false; - } - - myDb.dropDatabase(); - return true; - } - - function canMakeIndexWithName(collection, name) { - var success = collection.ensureIndex({x: 1}, {name: name}).ok; - if (success) { - assert.commandWorked(collection.dropIndex(name)); - } - return success; - } - - function canRenameCollection(from, to) { - var success = myDb[from].renameCollection(to).ok; - if (success) { - // put it back - assert.commandWorked(myDb[to].renameCollection(from)); - } - return success; - } - - // test making collections around the name limit - const prefixOverhead = (myDb.getName() + ".").length; - const maxCollectionNameLength = maxNsCollectionLength - prefixOverhead; - for (let i = maxCollectionNameLength - 3; i <= maxCollectionNameLength + 3; i++) { - assert.eq(canMakeCollectionWithName(mkStr(i)), - i <= maxCollectionNameLength, - "ns name length = " + (prefixOverhead + i)); - } - - // test making indexes around the name limit - const collection = myDb.collection; - collection.insert({}); - const maxIndexNameLength = maxNsLength - (collection.getFullName() + ".$").length; - for (let i = maxIndexNameLength - 3; i <= maxIndexNameLength + 3; i++) { - assert(canMakeIndexWithName(collection, mkStr(i)), - "index ns name length = " + ((collection.getFullName() + ".$").length + i)); - } - - // test renaming collections with the destination around the name limit - myDb.from.insert({}); - for (let i = maxCollectionNameLength - 3; i <= maxCollectionNameLength + 3; i++) { - assert.eq(canRenameCollection("from", mkStr(i)), - i <= maxCollectionNameLength, - "new ns name length = " + (prefixOverhead + i)); - } - - // test renaming collections with the destination around the name limit due to long indexe names - myDb.from.ensureIndex({a: 1}, {name: mkStr(100)}); - const indexNsNameOverhead = - (myDb.getName() + "..$").length + 100; // index ns name - collection name - var maxCollectionNameWithIndex = maxNsLength - indexNsNameOverhead; - for (let i = maxCollectionNameWithIndex - 3; i <= maxCollectionNameWithIndex + 3; i++) { - assert(canRenameCollection("from", mkStr(i)), - "index ns name length = " + (indexNsNameOverhead + i)); - } -})(); diff --git a/jstests/replsets/drop_collections_two_phase_rename_drop_target.js b/jstests/replsets/drop_collections_two_phase_rename_drop_target.js index 4f989bf337a..ad180601c2d 100644 --- a/jstests/replsets/drop_collections_two_phase_rename_drop_target.js +++ b/jstests/replsets/drop_collections_two_phase_rename_drop_target.js @@ -48,8 +48,7 @@ const testDb = primary.getDB(dbName); const fromColl = testDb.getCollection(fromCollName); const toColl = testDb.getCollection(toCollName); - let maxNsLength = 127; - let longIndexName = ''.pad(maxNsLength - (toColl.getFullName() + '.$').length, true, 'a'); + let longIndexName = 'a'.repeat(8192); let shortIndexName = "short_name"; // In the target collection, which will be dropped, create one index with a "too long" name, and @@ -96,28 +95,6 @@ const droppedCollName = isPendingDropResult.name; jsTestLog('Original target collection is now in a drop-pending state: ' + droppedCollName); - // Check that indexes that would violate the namespace length constraints after rename were - // dropped. - const indexes = listIndexes(testDb, droppedCollName); - jsTestLog('Indexes in ' + droppedCollName + ': ' + tojson(indexes)); - assert(indexes.find(idx => idx.name === shortIndexName)); - assert.eq(undefined, indexes.find(idx => idx.name === longIndexName)); - - // Check that index drop appears before collection rename in the oplog. - const oplogColl = primary.getCollection('local.oplog.rs'); - const cmdNs = testDb.getCollection('$cmd').getFullName(); - const renameOplogEntry = - oplogColl.findOne({ns: cmdNs, 'o.renameCollection': fromColl.getFullName()}); - const dropIndexOplogEntry = - oplogColl.findOne({ns: cmdNs, o: {dropIndexes: toCollName, index: longIndexName}}); - const renameTimestamp = renameOplogEntry.ts; - const dropIndexTimestamp = dropIndexOplogEntry.ts; - assert.lt(dropIndexTimestamp, - renameTimestamp, - 'index was not dropped before collection. index drop: ' + - tojson(dropIndexOplogEntry) + ' . collection rename: ' + - tojson(renameOplogEntry)); - // COMMIT collection drop. twoPhaseDropTest.resumeOplogApplication(secondary); replTest.awaitReplication(); diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index f4eb17d7b13..98fb3ff9eb9 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -570,16 +570,9 @@ void DatabaseImpl::_checkCanCreateCollection(OperationContext* opCtx, uassert(14037, "can't create user databases on a --configsvr instance", serverGlobalParams.clusterRole != ClusterRole::ConfigServer || nss.isOnInternalDb()); - - // This check only applies for actual collections, not indexes or other types of ns. - uassert(17381, - str::stream() << "fully qualified namespace " << nss << " is too long " - << "(max is " - << NamespaceString::MaxNsCollectionLen - << " bytes)", - !nss.isNormal() || nss.size() <= NamespaceString::MaxNsCollectionLen); - - uassert(17316, "cannot create a blank collection", nss.coll() > nullptr); + uassert(17316, + str::stream() << "cannot create a collection with an empty name on db: " << nss.db(), + !nss.coll().empty()); uassert(28838, "cannot create a non-capped oplog collection", options.capped || !nss.isOplog()); uassert(ErrorCodes::DatabaseDropPending, str::stream() << "Cannot create collection " << nss @@ -728,20 +721,14 @@ StatusWith<NamespaceString> DatabaseImpl::makeUniqueCollectionNamespace( OperationContext* opCtx, StringData collectionNameModel) { invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_X)); - // There must be at least one percent sign within the first MaxNsCollectionLen characters of the - // generated namespace after accounting for the database name prefix and dot separator: - // <db>.<truncated collection model name> - auto maxModelLength = NamespaceString::MaxNsCollectionLen - (_name.length() + 1); - auto model = collectionNameModel.substr(0, maxModelLength); - auto numPercentSign = std::count(model.begin(), model.end(), '%'); + // There must be at least one percent sign in the collection name model. + auto numPercentSign = std::count(collectionNameModel.begin(), collectionNameModel.end(), '%'); if (numPercentSign == 0) { return Status(ErrorCodes::FailedToParse, str::stream() << "Cannot generate collection name for temporary collection: " "model for collection name " << collectionNameModel - << " must contain at least one percent sign within first " - << maxModelLength - << " characters."); + << " must contain at least one percent sign."); } if (!_uniqueCollectionNamespacePseudoRandom) { @@ -765,7 +752,7 @@ StatusWith<NamespaceString> DatabaseImpl::makeUniqueCollectionNamespace( auto numGenerationAttempts = numPercentSign * charsToChooseFrom.size() * 100U; for (decltype(numGenerationAttempts) i = 0; i < numGenerationAttempts; ++i) { - auto collectionName = model.toString(); + auto collectionName = collectionNameModel.toString(); std::transform(collectionName.begin(), collectionName.end(), collectionName.begin(), diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp index 981edc0aca4..53f58eb1cb5 100644 --- a/src/mongo/db/catalog/database_test.cpp +++ b/src/mongo/db/catalog/database_test.cpp @@ -393,18 +393,8 @@ TEST_F(DatabaseTest, ErrorCodes::FailedToParse, db->makeUniqueCollectionNamespace(_opCtx.get(), "CollectionModelWithoutPercentSign")); - // Generated namespace has to satisfy namespace length constraints so we will reject - // any collection model where the first substituted percent sign will not be in the - // generated namespace. See NamespaceString::MaxNsCollectionLen. - auto dbPrefix = _nss.db() + "."; - auto modelTooLong = - (StringBuilder() << dbPrefix - << std::string('x', - NamespaceString::MaxNsCollectionLen - dbPrefix.size()) - << "%") - .str(); - ASSERT_EQUALS(ErrorCodes::FailedToParse, - db->makeUniqueCollectionNamespace(_opCtx.get(), modelTooLong)); + std::string longCollModel(8192, '%'); + ASSERT_OK(db->makeUniqueCollectionNamespace(_opCtx.get(), StringData(longCollModel))); }); } diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 578a2f5fe43..249d79928f6 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -492,33 +492,31 @@ TEST_F(RenameCollectionTest, RenameCollectionReturnsNotMasterIfNotPrimary) { TEST_F(RenameCollectionTest, TargetCollectionNameLong) { _createCollection(_opCtx.get(), _sourceNss); - const std::string targetCollectionName(NamespaceString::MaxNsCollectionLen, 'a'); + const std::string targetCollectionName(8192, 'a'); NamespaceString longTargetNss(_sourceNss.db(), targetCollectionName); ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, longTargetNss, {})); } TEST_F(RenameCollectionTest, LongIndexNameAllowedForTargetCollection) { ASSERT_GREATER_THAN(_targetNssDifferentDb.size(), _sourceNss.size()); - std::size_t longestIndexNameAllowedForSource = - NamespaceString::MaxNsLen - 2U /*strlen(".$")*/ - _sourceNss.size(); _createCollection(_opCtx.get(), _sourceNss); - const std::string indexName(longestIndexNameAllowedForSource, 'a'); + std::size_t longIndexLength = 8192; + const std::string indexName(longIndexLength, 'a'); _createIndexOnEmptyCollection(_opCtx.get(), _sourceNss, indexName); ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, _targetNssDifferentDb, {})); } TEST_F(RenameCollectionTest, LongIndexNameAllowedForTemporaryCollectionForRenameAcrossDatabase) { ASSERT_GREATER_THAN(_targetNssDifferentDb.size(), _sourceNss.size()); - std::size_t longestIndexNameAllowedForTarget = - NamespaceString::MaxNsLen - 2U /*strlen(".$")*/ - _targetNssDifferentDb.size(); // Using XXXXX to check namespace length. Each 'X' will be replaced by a random character in // renameCollection(). const NamespaceString tempNss(_targetNssDifferentDb.getSisterNS("tmpXXXXX.renameCollection")); _createCollection(_opCtx.get(), _sourceNss); - const std::string indexName(longestIndexNameAllowedForTarget, 'a'); + std::size_t longIndexLength = 8192; + const std::string indexName(longIndexLength, 'a'); _createIndexOnEmptyCollection(_opCtx.get(), _sourceNss, indexName); ASSERT_OK(renameCollection(_opCtx.get(), _sourceNss, _targetNssDifferentDb, {})); } diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index 37ffc965c08..566b23a2604 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -146,7 +146,7 @@ NamespaceString NamespaceString::makeDropPendingNamespace(const repl::OpTime& op ss << db() << "." << dropPendingNSPrefix; ss << opTime.getSecs() << "i" << opTime.getTimestamp().getInc() << "t" << opTime.getTerm(); ss << "." << coll(); - return NamespaceString(ss.stringData().substr(0, MaxNsCollectionLen)); + return NamespaceString(ss.stringData()); } StatusWith<repl::OpTime> NamespaceString::getDropPendingNamespaceOpTime() const { diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index de41e5a5d1d..1ad127e4b32 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -157,23 +157,6 @@ public: static NamespaceString makeListCollectionsNSS(StringData dbName); /** - * Note that these values are derived from the mmap_v1 implementation and that is the only - * reason they are constrained as such. - */ - enum MaxNsLenValue { - // Maximum possible length of name any namespace, including special ones like $extra. - // This includes rum for the NUL byte so it can be used when sizing buffers. - MaxNsLenWithNUL = 128, - - // MaxNsLenWithNUL excluding the NUL byte. Use this when comparing std::string lengths. - MaxNsLen = MaxNsLenWithNUL - 1, - - // Maximum allowed length of fully qualified namespace name of any real collection. - // Does not include NUL so it can be directly compared to std::string lengths. - MaxNsCollectionLen = MaxNsLen - 7 /*strlen(".$extra")*/, - }; - - /** * NOTE: DollarInDbNameBehavior::allow is deprecated. * * Please use DollarInDbNameBehavior::disallow and check explicitly for any DB names that must @@ -306,9 +289,6 @@ public: * * Example: * test.foo -> test.system.drop.<timestamp seconds>i<timestamp increment>t<term>.foo - * - * Original collection name may be truncated so that the generated namespace length does not - * exceed MaxNsCollectionLen. */ NamespaceString makeDropPendingNamespace(const repl::OpTime& opTime) const; diff --git a/src/mongo/db/namespace_string_test.cpp b/src/mongo/db/namespace_string_test.cpp index f44406139bf..0d7989b3dc8 100644 --- a/src/mongo/db/namespace_string_test.cpp +++ b/src/mongo/db/namespace_string_test.cpp @@ -189,14 +189,11 @@ TEST(NamespaceStringTest, MakeDropPendingNamespace) { ASSERT_EQUALS(NamespaceString{"test.system.drop.1234567i8t9.foo"}, NamespaceString{"test.foo"}.makeDropPendingNamespace( repl::OpTime(Timestamp(Seconds(1234567), 8U), 9LL))); - // If the collection name is too long to fit in the generated drop pending namespace, it will be - // truncated. - std::string dbName("test"); - std::string collName(std::size_t(NamespaceString::MaxNsCollectionLen) - dbName.size() - 1, 't'); - NamespaceString nss(dbName, collName); - auto dropPendingNss = - nss.makeDropPendingNamespace(repl::OpTime(Timestamp(Seconds(1234567), 8U), 9LL)); - ASSERT_EQUALS(std::size_t(NamespaceString::MaxNsCollectionLen), dropPendingNss.size()); + + std::string collName(8192, 't'); + NamespaceString nss("test", collName); + ASSERT_EQUALS(NamespaceString{"test.system.drop.1234567i8t9." + collName}, + nss.makeDropPendingNamespace(repl::OpTime(Timestamp(Seconds(1234567), 8U), 9LL))); } TEST(NamespaceStringTest, GetDropPendingNamespaceOpTime) { diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp index 1939cbe1e3b..d48b4c104db 100644 --- a/src/mongo/db/ops/insert.cpp +++ b/src/mongo/db/ops/insert.cpp @@ -204,14 +204,6 @@ Status userAllowedCreateNS(StringData db, StringData coll) { if (!NamespaceString::validCollectionName(coll)) return Status(ErrorCodes::InvalidNamespace, "invalid collection name"); - if (db.size() + 1 /* dot */ + coll.size() > NamespaceString::MaxNsCollectionLen) - return Status(ErrorCodes::InvalidNamespace, - str::stream() << "fully qualified namespace " << db << '.' << coll - << " is too long " - << "(max is " - << NamespaceString::MaxNsCollectionLen - << " bytes)"); - // check spceial areas if (db == "system") diff --git a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp index fc7922c10ce..04ebe4c6312 100644 --- a/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp +++ b/src/mongo/db/repl/replication_consistency_markers_impl_test.cpp @@ -59,8 +59,7 @@ using namespace mongo::repl; */ template <typename T> NamespaceString makeNamespace(const T& t, const std::string& suffix = "") { - return NamespaceString(std::string("local." + t.getSuiteName() + "_" + t.getTestName()) - .substr(0, NamespaceString::MaxNsCollectionLen - suffix.length()) + + return NamespaceString(std::string("local." + t.getSuiteName() + "_" + t.getTestName()) + suffix); } diff --git a/src/mongo/db/repl/storage_interface_impl_test.cpp b/src/mongo/db/repl/storage_interface_impl_test.cpp index 248142c5bc6..56b2b97c2ea 100644 --- a/src/mongo/db/repl/storage_interface_impl_test.cpp +++ b/src/mongo/db/repl/storage_interface_impl_test.cpp @@ -82,8 +82,7 @@ BSONObj makeIdIndexSpec(const NamespaceString& nss) { */ template <typename T> NamespaceString makeNamespace(const T& t, const std::string& suffix = "") { - return NamespaceString(std::string("local." + t.getSuiteName() + "_" + t.getTestName()) - .substr(0, NamespaceString::MaxNsCollectionLen - suffix.length()) + + return NamespaceString(std::string("local." + t.getSuiteName() + "_" + t.getTestName()) + suffix); } |