diff options
author | Daniel Gómez Ferro <daniel.gomezferro@mongodb.com> | 2022-02-02 07:59:01 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-02 08:46:57 +0000 |
commit | c7f5e389e4488fcf7bd7a9a2ca4149080c409242 (patch) | |
tree | d1a14dfeaef42df491009b45db32c5b7f3ab6a3d | |
parent | 98d1971726bc2bc7bd8d13365291d79bb9b61a6e (diff) | |
download | mongo-c7f5e389e4488fcf7bd7a9a2ca4149080c409242.tar.gz |
SERVER-62811 Allow special index types on cluster keys
4 files changed, 22 insertions, 7 deletions
diff --git a/buildscripts/resmokeconfig/suites/clustered_collection_passthrough.yml b/buildscripts/resmokeconfig/suites/clustered_collection_passthrough.yml index 6bfa5b5c068..55c1b82b95d 100644 --- a/buildscripts/resmokeconfig/suites/clustered_collection_passthrough.yml +++ b/buildscripts/resmokeconfig/suites/clustered_collection_passthrough.yml @@ -7,8 +7,6 @@ selector: - jstests/core/**/*.js exclude_files: - # Creates a hashed index on _id that conflicts with cluster key. - - jstests/core/single_field_hashed_index.js # Assumes the _id index is real. - jstests/core/collmod_convert_to_ttl.js - jstests/core/index_create_too_many.js diff --git a/buildscripts/resmokeconfig/suites/sharding_clustered_collections.yml b/buildscripts/resmokeconfig/suites/sharding_clustered_collections.yml index 5a7b18befcd..34cbe2b00c8 100644 --- a/buildscripts/resmokeconfig/suites/sharding_clustered_collections.yml +++ b/buildscripts/resmokeconfig/suites/sharding_clustered_collections.yml @@ -16,12 +16,8 @@ selector: - jstests/sharding/shard6.js # Expects hint(_id) to yield an index scan instead of a table scan. - jstests/sharding/shard2.js - # TODO (SERVER-62811): Establish intended behavior. - - jstests/sharding/query/collation_shard_targeting_hashed_shard_key.js # TODO (SERVER-62874): Investigate the following test failures. - - jstests/sharding/transactions_reject_writes_for_moved_chunks.js - jstests/sharding/internal_sessions_partial_index.js - - jstests/sharding/change_stream_chunk_migration.js - jstests/sharding/change_stream_show_migration_events.js - jstests/sharding/move_primary_with_writes.js exclude_with_any_tags: diff --git a/jstests/core/clustered_collection_creation.js b/jstests/core/clustered_collection_creation.js index 3c24f860526..34b5d39a8a6 100644 --- a/jstests/core/clustered_collection_creation.js +++ b/jstests/core/clustered_collection_creation.js @@ -6,7 +6,7 @@ * non-replicated collections. * * @tags: [ - * requires_fcv_52, + * requires_fcv_53, * assumes_against_mongod_not_mongos, * assumes_no_implicit_collection_creation_after_drop, * does_not_support_stepdowns, @@ -38,6 +38,12 @@ const validateCompoundSecondaryIndexes = function(db, coll, clusterKey) { coll.drop(); }; +const overrideIndexType = function(clusterKey, indexType) { + for (const field of Object.keys(clusterKey)) { + return Object.assign(Object.assign({}, clusterKey), {[field]: indexType}); + } +}; + // Tests it is legal to call createIndex on the cluster key with or without {'clustered': true} as // an option. Additionally, confirms it is illegal to call createIndex with the 'clustered' option // on a pattern that is not the cluster key. @@ -75,6 +81,15 @@ const validateCreateIndexOnClusterKey = function(db, collName, fullCreateOptions const listIndexes1 = assert.commandWorked(db[collName].runCommand("listIndexes")); assert.eq(listIndexes1.cursor.firstBatch.length, 1); assert.docEq(listIndexes1.cursor.firstBatch[0], listIndexes0.cursor.firstBatch[0]); + + // It's possible to create 'hashed','2d','2dsphere' and 'text' indexes on the cluster key. + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, 'hashed'))); + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, '2d'))); + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, '2dsphere'))); + assert.commandWorked(db[collName].createIndex(overrideIndexType(clusterKey, 'text'))); + + const finalIndexes = assert.commandWorked(db[collName].runCommand("listIndexes")); + assert.eq(finalIndexes.cursor.firstBatch.length, 5); }; // It is illegal to drop the clusteredIndex. Verify that the various ways of dropping the diff --git a/src/mongo/db/catalog/clustered_collection_util.cpp b/src/mongo/db/catalog/clustered_collection_util.cpp index 8380f1fb4d4..c79adca9054 100644 --- a/src/mongo/db/catalog/clustered_collection_util.cpp +++ b/src/mongo/db/catalog/clustered_collection_util.cpp @@ -136,6 +136,12 @@ bool matchesClusterKey(const BSONObj& keyPatternObj, // Clustered key cannot be compound. return false; } + + if (!keyPatternObj.firstElement().isNumber()) { + // Clustered index can't be of any special type. + return false; + } + return keyPatternObj.firstElement().fieldNameStringData() == collInfo->getIndexSpec().getKey().firstElement().fieldNameStringData(); } |