summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kneiser <matt.kneiser@mongodb.com>2022-03-22 21:52:16 +0000
committerMatt Kneiser <matt.kneiser@mongodb.com>2022-03-24 22:20:55 +0000
commit065475a734e110b4d440b25a79518c6c060e7e42 (patch)
tree8f4e5846cda9992a0dc8680f51574f207decdb8b
parentfa09b63b30289d92f6bcc77027844bfb49463a04 (diff)
downloadmongo-065475a734e110b4d440b25a79518c6c060e7e42.tar.gz
SERVER-64796 Fixes Clustered Index Bug
-rw-r--r--jstests/libs/clustered_collections/clustered_collection_create_index_clustered_common.js34
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp8
2 files changed, 41 insertions, 1 deletions
diff --git a/jstests/libs/clustered_collections/clustered_collection_create_index_clustered_common.js b/jstests/libs/clustered_collections/clustered_collection_create_index_clustered_common.js
index c225f25c1f5..83b95160714 100644
--- a/jstests/libs/clustered_collections/clustered_collection_create_index_clustered_common.js
+++ b/jstests/libs/clustered_collections/clustered_collection_create_index_clustered_common.js
@@ -17,6 +17,15 @@ const CreateIndexesClusteredTest = (function() {
// Start with the collection empty.
assert.commandFailedWithCode(
testColl.createIndex({_id: 1}, {clustered: true, unique: true}), 6243700);
+
+ // Pass non-boolean value to safeBool 'clustered' option. Should be equivalent to next
+ // command.
+ assert.commandFailedWithCode(testDB.runCommand({
+ createIndexes: collName,
+ "indexes": [{key: {"newKey": 1}, name: "anyName", clustered: 2, unique: true}],
+ }),
+ 6243700);
+
assert.commandFailedWithCode(testColl.createIndex({a: 1}, {clustered: true, unique: true}),
6243700);
@@ -30,6 +39,15 @@ const CreateIndexesClusteredTest = (function() {
assert.commandWorked(bulk.execute());
assert.commandFailedWithCode(
testColl.createIndex({_id: 1}, {clustered: true, unique: true}), 6243700);
+
+ // Pass non-boolean value to safeBool 'clustered' option. Should be equivalent to next
+ // command.
+ assert.commandFailedWithCode(testDB.runCommand({
+ createIndexes: collName,
+ "indexes": [{key: {"newKey2": 1}, name: "anyName2", clustered: 2, unique: true}],
+ }),
+ 6243700);
+
assert.commandFailedWithCode(testColl.createIndex({a: 1}, {clustered: true, unique: true}),
6243700);
};
@@ -67,6 +85,14 @@ const CreateIndexesClusteredTest = (function() {
// createIndex on the cluster key with the 'clustered' option is a no-op.
assert.commandWorked(testColl.createIndex({_id: 1}, {clustered: true, unique: true}));
+ // Pass non-boolean value to safeBool 'clustered' option. Should be equivalent to next
+ // command.
+ assert.commandFailedWithCode(testDB.runCommand({
+ createIndexes: collName,
+ "indexes": [{key: {"newKey": 1}, name: "anyName", clustered: 2, unique: true}],
+ }),
+ 6243700);
+
// 'clustered' is not a valid option for an index not on the cluster key.
assert.commandFailedWithCode(
testColl.createIndex({notMyIndex: 1}, {clustered: true, unique: true}), 6243700);
@@ -83,6 +109,14 @@ const CreateIndexesClusteredTest = (function() {
assert.commandWorked(testColl.createIndex({_id: 1}));
assert.commandWorked(testColl.createIndex({_id: 1}, {clustered: true, unique: true}));
+ // Pass non-boolean value to safeBool 'clustered' option. Should be equivalent to next
+ // command.
+ assert.commandFailedWithCode(testDB.runCommand({
+ createIndexes: collName,
+ "indexes": [{key: {"newKey2": 1}, name: "anyName2", clustered: 2, unique: true}],
+ }),
+ 6243700);
+
// 'clustered' is still not a valid option for an index not on the cluster key.
assert.commandFailedWithCode(testColl.createIndex({a: 1}, {clustered: true, unique: true}),
6243700);
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index 431e35dfbb3..baf64017acb 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -116,7 +116,7 @@ Status isSpecOKClusteredIndexCheck(const BSONObj& indexSpec,
bool keysMatch = clustered_util::matchesClusterKey(key, collInfo);
bool clusteredOptionPresent =
- indexSpec.hasField("clustered") && indexSpec.getBoolField("clustered");
+ indexSpec.hasField("clustered") && indexSpec["clustered"].trueValue();
if (clusteredOptionPresent && !keysMatch) {
// The 'clustered' option implies the indexSpec must match the clustered index.
@@ -135,6 +135,12 @@ Status isSpecOKClusteredIndexCheck(const BSONObj& indexSpec,
return Status::OK();
}
+ if (!collInfo) {
+ return Status(ErrorCodes::Error(6479600),
+ str::stream() << "Cannot create an index with 'clustered' in the spec on a "
+ << "collection that is not clustered");
+ }
+
// The collection is guaranteed to be clustered since at least the name or key matches a
// clustered index.
auto clusteredIndexSpec = collInfo->getIndexSpec();