diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/index_key_validate.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_key_validate_test.cpp | 58 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_spec_validate_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/query/query_knobs.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/query/query_knobs.h | 6 |
5 files changed, 57 insertions, 24 deletions
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp index e4b86cf0a3d..3feddcaf30d 100644 --- a/src/mongo/db/catalog/index_key_validate.cpp +++ b/src/mongo/db/catalog/index_key_validate.cpp @@ -45,6 +45,7 @@ #include "mongo/db/matcher/expression_parser.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/collation/collator_factory_interface.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/db/service_context.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/mongoutils/str.h" @@ -118,6 +119,13 @@ Status validateKeyPattern(const BSONObj& key, IndexDescriptor::IndexVersion inde code, mongoutils::str::stream() << "Unknown index plugin '" << pluginName << '\''); } + if (pluginName == IndexNames::ALLPATHS && !internalQueryAllowAllPathsIndexes.load()) { + // TODO: SERVER-36198 remove this check once AllPaths indexes are complete. + return Status( + ErrorCodes::NotImplemented, + "Cannot use an allPaths index without enabling internalQueryAllowAllPathsIndexes"); + } + BSONObjIterator it(key); while (it.more()) { BSONElement keyElement = it.next(); diff --git a/src/mongo/db/catalog/index_key_validate_test.cpp b/src/mongo/db/catalog/index_key_validate_test.cpp index cc8978d0673..1d170fbbde7 100644 --- a/src/mongo/db/catalog/index_key_validate_test.cpp +++ b/src/mongo/db/catalog/index_key_validate_test.cpp @@ -36,6 +36,7 @@ #include "mongo/bson/bsonmisc.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/unittest/unittest.h" namespace mongo { @@ -45,6 +46,31 @@ namespace { using IndexVersion = IndexDescriptor::IndexVersion; using index_key_validate::validateKeyPattern; +/** + * Helper class to ensure proper FCV & test commands enabled. + * TODO: Remove test command enabling/disabling in SERVER-36198 + */ +class TestCommandQueryKnobGuard { + +public: + TestCommandQueryKnobGuard() { + _prevEnabled = getTestCommandsEnabled(); + setTestCommandsEnabled(true); + + _prevKnobEnabled = internalQueryAllowAllPathsIndexes.load(); + internalQueryAllowAllPathsIndexes.store(true); + } + + ~TestCommandQueryKnobGuard() { + setTestCommandsEnabled(_prevEnabled); + internalQueryAllowAllPathsIndexes.store(_prevKnobEnabled); + } + +private: + bool _prevEnabled; + bool _prevKnobEnabled; +}; + TEST(IndexKeyValidateTest, KeyElementValueOfSmallPositiveIntSucceeds) { for (auto indexVersion : IndexDescriptor::getSupportedIndexVersions()) { ASSERT_OK(validateKeyPattern(BSON("x" << 1), indexVersion)); @@ -237,77 +263,61 @@ TEST(IndexKeyValidateTest, KeyElementNameTextSucceedsOnTextIndex) { } TEST(IndexKeyValidateTest, KeyElementNameAllPathsSucceedsOnSubPath) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; ASSERT_OK(validateKeyPattern(BSON("a.$**" << 1), IndexVersion::kV2)); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsSucceeds) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; ASSERT_OK(validateKeyPattern(BSON("$**" << 1), IndexVersion::kV2)); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnRepeat) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**.$**" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnSubPathRepeat) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("a.$**.$**" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnCompound) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << 1 << "a" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsOnIncorrectValue) { - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << false), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsWhenValueIsPluginNameWithInvalidKeyName) { // TODO: Remove test command enabling/disabling in SERVER-36198 - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("a" << "allPaths"), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } TEST(IndexKeyValidateTest, KeyElementNameAllPathsFailsWhenValueIsPluginNameWithValidKeyName) { // TODO: Remove test command enabling/disabling in SERVER-36198 - const bool temp = getTestCommandsEnabled(); - setTestCommandsEnabled(true); + TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << "allPaths"), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); - setTestCommandsEnabled(temp); } } // namespace diff --git a/src/mongo/db/catalog/index_spec_validate_test.cpp b/src/mongo/db/catalog/index_spec_validate_test.cpp index e49d09eb675..35dfc7adbe9 100644 --- a/src/mongo/db/catalog/index_spec_validate_test.cpp +++ b/src/mongo/db/catalog/index_spec_validate_test.cpp @@ -40,6 +40,7 @@ #include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/namespace_string.h" #include "mongo/db/query/collation/collator_interface_mock.h" +#include "mongo/db/query/query_knobs.h" #include "mongo/db/query/query_test_service_context.h" #include "mongo/db/server_options.h" #include "mongo/unittest/unittest.h" @@ -67,15 +68,21 @@ public: // TODO: Remove test command enabling/disabling in SERVER-36198 _prevEnabled = getTestCommandsEnabled(); setTestCommandsEnabled(true); + + // TODO: Remove knob enabling/disabling in SERVER-36198. + _prevKnobEnabled = internalQueryAllowAllPathsIndexes.load(); + internalQueryAllowAllPathsIndexes.store(true); } ~TestCommandFcvGuard() { serverGlobalParams.featureCompatibility.setVersion(_prevVersion); setTestCommandsEnabled(_prevEnabled); + internalQueryAllowAllPathsIndexes.store(_prevKnobEnabled); } private: bool _prevEnabled; + bool _prevKnobEnabled; ServerGlobalParams::FeatureCompatibility::Version _prevVersion; }; diff --git a/src/mongo/db/query/query_knobs.cpp b/src/mongo/db/query/query_knobs.cpp index 920b04af17d..2ab5f838e4e 100644 --- a/src/mongo/db/query/query_knobs.cpp +++ b/src/mongo/db/query/query_knobs.cpp @@ -92,4 +92,6 @@ MONGO_EXPORT_SERVER_PARAMETER(internalQueryPlannerGenerateCoveredWholeIndexScans MONGO_EXPORT_SERVER_PARAMETER(internalQueryIgnoreUnknownJSONSchemaKeywords, bool, false); MONGO_EXPORT_SERVER_PARAMETER(internalQueryProhibitBlockingMergeOnMongoS, bool, false); + +MONGO_EXPORT_SERVER_PARAMETER(internalQueryAllowAllPathsIndexes, bool, false); } // namespace mongo diff --git a/src/mongo/db/query/query_knobs.h b/src/mongo/db/query/query_knobs.h index a361e875dcc..e17502d0bd7 100644 --- a/src/mongo/db/query/query_knobs.h +++ b/src/mongo/db/query/query_knobs.h @@ -130,4 +130,10 @@ extern AtomicInt32 internalDocumentSourceCursorBatchSizeBytes; extern AtomicInt32 internalDocumentSourceLookupCacheSizeBytes; extern AtomicBool internalQueryProhibitBlockingMergeOnMongoS; + +// +// In-progress features. +// +// TODO: Remove in SERVER-36198. +extern AtomicBool internalQueryAllowAllPathsIndexes; } // namespace mongo |