From f679bf106621a273a8502c9bd4018fbef6bde6a9 Mon Sep 17 00:00:00 2001 From: Benjamin Pearce Date: Mon, 2 Feb 2026 15:28:56 -0500 Subject: [PATCH] SERVER-118713 Revert SERVER-113888 SERVER-113889 (#47356) GitOrigin-RevId: 67480f41dfa5802ce14af5c95bd0e9826d3b2131 --- ...kports_required_for_multiversion_tests.yml | 4 -- .../index/index_on_incorrect_collection.js | 25 -------- .../index_create_illegal_options.js | 62 ------------------- src/mongo/db/commands/create_indexes_cmd.cpp | 21 ------- src/mongo/db/index_names.cpp | 14 ----- src/mongo/db/index_names.h | 5 -- .../timeseries_dotted_path_support.cpp | 8 +-- 7 files changed, 3 insertions(+), 136 deletions(-) delete mode 100644 jstests/core/index/index_on_incorrect_collection.js delete mode 100644 jstests/noPassthrough/index_create_illegal_options.js diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index 3a79c762853..457e1b8521b 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -635,8 +635,6 @@ last-continuous: ticket: SERVER-93153 - test_file: jstests/change_streams/resume_expanded_events.js ticket: SERVER-93153 - - test_file: jstests/core/index/index_on_incorrect_collection.js - ticket: SERVER-113888 - test_file: jstests/replsets/insert_documents_close_to_size_limit.js ticket: SERVER-113532 suites: null @@ -1326,8 +1324,6 @@ last-lts: ticket: SERVER-93153 - test_file: jstests/change_streams/resume_expanded_events.js ticket: SERVER-93153 - - test_file: jstests/core/index/index_on_incorrect_collection.js - ticket: SERVER-113888 - test_file: jstests/replsets/insert_documents_close_to_size_limit.js ticket: SERVER-113532 suites: null diff --git a/jstests/core/index/index_on_incorrect_collection.js b/jstests/core/index/index_on_incorrect_collection.js deleted file mode 100644 index fa89118a98f..00000000000 --- a/jstests/core/index/index_on_incorrect_collection.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * If an incompatible index exists on a collection, the server should prevent updates to that index - * with non-fatal errors. - */ - -// Nonfatal error when attempting to update an improper timeseries-only index on a non-timeseries -// collection. - -const collName = jsTestName(); - -const coll = db.getCollection(collName); -coll.drop(); -assert.commandWorked(db.createCollection(collName)); - -// Prevents updating 2dsphere_bucket indices for top-level measurements. -// Authorization rules will normally prevent a non-system user from creating this index. -assert.commandWorked(coll.createIndex({x: "2dsphere_bucket"})); -assert.commandFailed(coll.insert({control: {version: 2}, x: HexData(0, "00")})); - -// Prevents updating 2dsphere_bucket indices for nested measurements. -// Authorization rules will normally prevent a non-system user from creating this index. -assert.commandWorked(coll.createIndex({"data.a.b.c": "2dsphere_bucket"})); -assert.commandFailed(coll.insert({control: {version: 2}, data: {a: {b: {c: [0, 0]}}}})); - -coll.drop(); diff --git a/jstests/noPassthrough/index_create_illegal_options.js b/jstests/noPassthrough/index_create_illegal_options.js deleted file mode 100644 index be17d280332..00000000000 --- a/jstests/noPassthrough/index_create_illegal_options.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Ensures that a createIndexes command request fails when creating an index with illegal options. - */ - -// Specifying index type in the createIndex command. -const collName = jsTestName(); -const testUser = "mongo"; -const testPass = "mongo"; - -const conn = MongoRunner.runMongod({auth: "", bind_ip: "127.0.0.1"}); -const admin = conn.getDB("admin"); -admin.createUser({ - user: testUser, - pwd: testPass, - roles: jsTest.adminUserRoles, -}); -admin.logout(); -admin.auth({user: testUser, pwd: testPass}); -const test = admin.getSiblingDB("test"); - -const illegalIndexTypes = [ - {type: "2dsphere_bucket", codes: [ErrorCodes.IndexOptionsConflict]}, - { - type: "queryable_encrypted_range", - codes: [ErrorCodes.IndexOptionsConflict], - }, - {type: "wildcard", codes: [7246202, ErrorCodes.CannotCreateIndex]}, - { - type: "columnstore", - codes: [ErrorCodes.NotImplemented, ErrorCodes.CannotCreateIndex], - }, - {type: "geoHaystack", codes: [ErrorCodes.CannotCreateIndex]}, -]; - -const legalIndexTypes = [1, "2d", "2dsphere", "text", "hashed"]; - -// Cannot create illegal indexes. -illegalIndexTypes.forEach((args) => { - const indexType = args.type; - const expectedErrorCodes = args.codes; - const testCollName = collName + "." + indexType; - assert.commandFailedWithCode(test[testCollName].createIndex({foo: indexType}), - expectedErrorCodes); - // TODO(SERVER-114308): Primary-driven index builds eagerly create the collection, this - // assertion will fail on those build variants. Reenable this check. - // assert.doesNotContain( - // test.getCollectionNames(), - // [testCollName], - // `The ${testCollName} collection should not be implicitly created upon failing to create - // the index.` - // ); - // test[testCollName].drop(); -}); - -// Can create illegal indexes. -legalIndexTypes.forEach(function(indexType) { - testCollName = collName + "." + indexType; - assert.commandWorked(test[testCollName].createIndex({foo: indexType})); - test[testCollName].drop(); -}); - -MongoRunner.stopMongod(conn); diff --git a/src/mongo/db/commands/create_indexes_cmd.cpp b/src/mongo/db/commands/create_indexes_cmd.cpp index 2b6f627df7c..2cbc87aceb1 100644 --- a/src/mongo/db/commands/create_indexes_cmd.cpp +++ b/src/mongo/db/commands/create_indexes_cmd.cpp @@ -179,26 +179,6 @@ void validateTTLOptions(OperationContext* opCtx, } } -/** - * Ensures that the user is authorized to create an index of a given type. - */ -void validateIndexType(OperationContext* opCtx, const CreateIndexesCommand& cmd) { - const bool isAuthForInternal = - AuthorizationSession::get(opCtx->getClient()) - ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(), - ActionType::internal); - for (const auto& elem : cmd.getIndexes()) { - for (const auto& key : elem.getField("key").Obj()) { - const auto type = key.str(); // will return "" for btree - if (IndexNames::isInternalOnly(type)) { - uassert(ErrorCodes::IndexOptionsConflict, - fmt::format("Index Type {} is for internal use only", type), - isAuthForInternal); - } - } - } -} - void checkEncryptedFieldIndexRestrictions(OperationContext* opCtx, const NamespaceString& ns, const CreateIndexesCommand& cmd) { @@ -528,7 +508,6 @@ CreateIndexesReply runCreateIndexesWithCoordinator(OperationContext* opCtx, } validateTTLOptions(opCtx, collection.getCollection(), cmd); - validateIndexType(opCtx, cmd); if (collection && collection->isCapped() && MONGO_likely(!ignoreTTLIndexCappedCollectionCheck.shouldFail())) { diff --git a/src/mongo/db/index_names.cpp b/src/mongo/db/index_names.cpp index b894b8bd7c7..bc9e01f1d57 100644 --- a/src/mongo/db/index_names.cpp +++ b/src/mongo/db/index_names.cpp @@ -99,18 +99,4 @@ IndexType IndexNames::nameToType(StringData accessMethod) { return typeIt->second; } -// static -bool IndexNames::isInternalOnly(const std::string& name) { - if (isKnownName(name)) { - switch (nameToType(name)) { - case INDEX_2DSPHERE_BUCKET: - case INDEX_ENCRYPTED_RANGE: - return true; - default: - return false; - } - } - return false; -} - } // namespace mongo diff --git a/src/mongo/db/index_names.h b/src/mongo/db/index_names.h index d6138ef3b29..f0ed4e7bc0b 100644 --- a/src/mongo/db/index_names.h +++ b/src/mongo/db/index_names.h @@ -85,11 +85,6 @@ public: * Convert an index name to an IndexType. */ static IndexType nameToType(StringData accessMethod); - - /** - * Index is not intended to be user facing. - */ - static bool isInternalOnly(const std::string& name); }; /** diff --git a/src/mongo/db/timeseries/timeseries_dotted_path_support.cpp b/src/mongo/db/timeseries/timeseries_dotted_path_support.cpp index 20ad333c90c..18696cf6ec4 100644 --- a/src/mongo/db/timeseries/timeseries_dotted_path_support.cpp +++ b/src/mongo/db/timeseries/timeseries_dotted_path_support.cpp @@ -166,7 +166,7 @@ boost::optional _extractAllElementsAlongBucketPath( case 0: case 1: { if (auto res = _splitPath(path)) { - const auto& [left, next] = *res; + auto& [left, next] = *res; BSONElement e = obj.getField(left); if (depth > 0 || left == timeseries::kBucketDataFieldName) { if (e.type() == Object) { @@ -221,9 +221,7 @@ boost::optional _extractAllElementsAlongBucketPath( // measurement field (i.e. data.a) and we need to iterate over each of the // numerically-indexed entries (i.e. data.a.1, data.a.5, etc.) to extract // the actual field we want. - massert(11388801, - "Malformed measurement field in compressed timeseries bucket", - depth == 1); + invariant(depth == 1); BSONColumn storage{e}; for (const BSONElement& e2 : storage) { if (!e2.eoo()) { @@ -245,7 +243,7 @@ boost::optional _extractAllElementsAlongBucketPath( // numerically-indexed entries (i.e. data.a.1, data.a.5, etc.) to extract the actual // field we want. If we are after a top-level field, then we already have the element we // want in 'e'. If we are after a nested field, then we need to recurse. - massert(11388802, "Expected uncompressed bucket", !isCompressed); + invariant(!isCompressed); for (const BSONElement& e : obj) { if (path.empty()) { // The top-level measurement field (i.e. data.a) is the indexed field we are