diff options
author | Benety Goh <benety@mongodb.com> | 2018-06-27 20:47:46 -0400 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2018-06-27 20:47:46 -0400 |
commit | f03234dd850f45feef0e778e8eaa117b7c9cf41e (patch) | |
tree | 471834668ad3f570f43ca47be856da62c8b04842 | |
parent | 92ba01fe2c62ba716f9d0b05f23e2a2403539811 (diff) | |
download | mongo-f03234dd850f45feef0e778e8eaa117b7c9cf41e.tar.gz |
SERVER-32959 remove limit on index namespace at index creation
-rw-r--r-- | jstests/core/long_index_rename.js | 13 | ||||
-rw-r--r-- | jstests/core/ns_length.js | 5 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog_impl.cpp | 6 |
3 files changed, 12 insertions, 12 deletions
diff --git a/jstests/core/long_index_rename.js b/jstests/core/long_index_rename.js index b1e7fb91b96..bc74b9e39eb 100644 --- a/jstests/core/long_index_rename.js +++ b/jstests/core/long_index_rename.js @@ -1,7 +1,6 @@ -// SERVER-7720 Building an index with a too-long name should always fail -// Formerly, we would allow an index that already existed to be "created" with too long a name, -// but this caused secondaries to crash when replicating what should be a bad createIndex command. -// Here we test that the too-long name is rejected in this situation as well +// SERVER-7720 Building an index with a too-long name is acceptable since 4.2. +// Previously, we would disallow index creation with with too long a name. +// @tags: [requires_non_retryable_commands] (function() { 'use strict'; @@ -21,8 +20,6 @@ // Create an index with the longest name allowed for this collection. assert.commandWorked(coll.createIndex({a: 1}, {name: 'a'.repeat(maxIndexNameLength)})); - // Index namespaces longer than 127 characters are not acceptable. - assert.commandFailedWithCode( - coll.createIndex({b: 1}, {name: 'b'.repeat(maxIndexNameLength) + 1}), - ErrorCodes.CannotCreateIndex); + // Beginning with 4.2, index namespaces longer than 127 characters are acceptable. + assert.commandWorked(coll.createIndex({b: 1}, {name: 'b'.repeat(maxIndexNameLength) + 1})); })(); diff --git a/jstests/core/ns_length.js b/jstests/core/ns_length.js index 200e958cdc8..f632cbafa7f 100644 --- a/jstests/core/ns_length.js +++ b/jstests/core/ns_length.js @@ -71,9 +71,8 @@ collection.insert({}); const maxIndexNameLength = maxNsLength - (collection.getFullName() + ".$").length; for (let i = maxIndexNameLength - 3; i <= maxIndexNameLength + 3; i++) { - assert.eq(canMakeIndexWithName(collection, mkStr(i)), - i <= maxIndexNameLength, - "index ns name length = " + ((collection.getFullName() + ".$").length + i)); + assert(canMakeIndexWithName(collection, mkStr(i)), + "index ns name length = " + ((collection.getFullName() + ".$").length + i)); } // test renaming collections with the destination around the name limit diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 43f01ba2a00..f6ff27d92f6 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -626,7 +626,11 @@ Status IndexCatalogImpl::_isSpecOk(OperationContext* opCtx, const BSONObj& spec) // Drop pending collections are internal to the server and will not be exported to another // storage engine. The indexes contained in these collections are not subject to the same // namespace length constraints as the ones in created by users. - if (!nss.isDropPendingNamespace()) { + // Index names do not limit the maximum allowable length of the target namespace under FCV 4.2 + // and above. + // TODO(SERVER-35824): Re-enable index namespace check under FCV 4.0. + const bool checkIndexNamespace = false; + if (checkIndexNamespace && !nss.isDropPendingNamespace()) { auto indexNamespace = IndexDescriptor::makeIndexNamespace(nss.ns(), name); if (indexNamespace.length() > NamespaceString::MaxNsLen) return Status(ErrorCodes::CannotCreateIndex, |