diff options
author | Bernard Gorman <bernard.gorman@gmail.com> | 2018-10-06 11:28:49 +0100 |
---|---|---|
committer | Bernard Gorman <bernard.gorman@gmail.com> | 2018-10-15 18:35:44 -0400 |
commit | df2ffa891fbddc7ff0d51713afd739a5c9348e64 (patch) | |
tree | eb3ddcd9fdbf68053e08da2e40e680c2c70c0a6e | |
parent | 03c7e9e4688583394b3ac10e306546e8413bb52c (diff) | |
download | mongo-df2ffa891fbddc7ff0d51713afd739a5c9348e64.tar.gz |
SERVER-31698 Enable $** index builds by default in non-test configurations
-rw-r--r-- | src/mongo/db/catalog/index_key_validate_test.cpp | 31 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_spec_validate_test.cpp | 56 | ||||
-rw-r--r-- | src/mongo/db/index_names.cpp | 6 |
3 files changed, 17 insertions, 76 deletions
diff --git a/src/mongo/db/catalog/index_key_validate_test.cpp b/src/mongo/db/catalog/index_key_validate_test.cpp index 1800e6d06d5..4e41a3b20c2 100644 --- a/src/mongo/db/catalog/index_key_validate_test.cpp +++ b/src/mongo/db/catalog/index_key_validate_test.cpp @@ -46,26 +46,6 @@ 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); - } - - ~TestCommandQueryKnobGuard() { - setTestCommandsEnabled(_prevEnabled); - } - -private: - bool _prevEnabled; -}; - TEST(IndexKeyValidateTest, KeyElementValueOfSmallPositiveIntSucceeds) { for (auto indexVersion : IndexDescriptor::getSupportedIndexVersions()) { ASSERT_OK(validateKeyPattern(BSON("x" << 1), indexVersion)); @@ -244,17 +224,14 @@ TEST(IndexKeyValidateTest, KeyElementNameTextSucceedsOnTextIndex) { } TEST(IndexKeyValidateTest, KeyElementNameWildcardSucceedsOnSubPath) { - TestCommandQueryKnobGuard guard; ASSERT_OK(validateKeyPattern(BSON("a.$**" << 1), IndexVersion::kV2)); } TEST(IndexKeyValidateTest, KeyElementNameWildcardSucceeds) { - TestCommandQueryKnobGuard guard; ASSERT_OK(validateKeyPattern(BSON("$**" << 1), IndexVersion::kV2)); } TEST(IndexKeyValidateTest, WildcardIndexNumericKeyElementValueFailsIfNotPositive) { - TestCommandQueryKnobGuard guard; ASSERT_EQ(ErrorCodes::CannotCreateIndex, validateKeyPattern(BSON("$**" << 0.0), IndexVersion::kV2)); ASSERT_EQ(ErrorCodes::CannotCreateIndex, @@ -268,36 +245,30 @@ TEST(IndexKeyValidateTest, WildcardIndexNumericKeyElementValueFailsIfNotPositive } TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsOnRepeat) { - TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**.$**" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); } TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsOnSubPathRepeat) { - TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("a.$**.$**" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); } TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsOnCompound) { - TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << 1 << "a" << 1), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); } TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsOnIncorrectValue) { - TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << false), IndexVersion::kV2); ASSERT_NOT_OK(status); ASSERT_EQ(status, ErrorCodes::CannotCreateIndex); } TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsWhenValueIsPluginNameWithInvalidKeyName) { - // TODO: Remove test command enabling/disabling in SERVER-36198 - TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("a" << "wildcard"), IndexVersion::kV2); @@ -306,8 +277,6 @@ TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsWhenValueIsPluginNameWithI } TEST(IndexKeyValidateTest, KeyElementNameWildcardFailsWhenValueIsPluginNameWithValidKeyName) { - // TODO: Remove test command enabling/disabling in SERVER-36198 - TestCommandQueryKnobGuard guard; auto status = validateKeyPattern(BSON("$**" << "wildcard"), IndexVersion::kV2); diff --git a/src/mongo/db/catalog/index_spec_validate_test.cpp b/src/mongo/db/catalog/index_spec_validate_test.cpp index 32255f51ab3..a1c19e32427 100644 --- a/src/mongo/db/catalog/index_spec_validate_test.cpp +++ b/src/mongo/db/catalog/index_spec_validate_test.cpp @@ -43,6 +43,7 @@ #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/ensure_fcv.h" #include "mongo/unittest/unittest.h" namespace mongo { @@ -51,37 +52,12 @@ namespace { using index_key_validate::validateIndexSpec; using index_key_validate::validateIdIndexSpec; using index_key_validate::validateIndexSpecCollation; +using unittest::EnsureFCV; const NamespaceString kTestNamespace("test", "index_spec_validate"); constexpr OperationContext* kDefaultOpCtx = nullptr; /** - * Helper class to ensure proper FCV & test commands enabled. - */ -class TestCommandFcvGuard { - -public: - TestCommandFcvGuard() { - _prevVersion = serverGlobalParams.featureCompatibility.getVersion(); - serverGlobalParams.featureCompatibility.setVersion( - ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); - // TODO: Remove test command enabling/disabling in SERVER-36198 - _prevEnabled = getTestCommandsEnabled(); - setTestCommandsEnabled(true); - } - - ~TestCommandFcvGuard() { - serverGlobalParams.featureCompatibility.setVersion(_prevVersion); - setTestCommandsEnabled(_prevEnabled); - } - -private: - bool _prevEnabled; - ServerGlobalParams::FeatureCompatibility::Version _prevVersion; -}; - - -/** * Helper function used to return the fields of a BSONObj in a consistent order. */ BSONObj sorted(const BSONObj& obj) { @@ -833,7 +809,7 @@ TEST(IndexSpecPartialFilterTest, AcceptsValidPartialFilterExpression) { } TEST(IndexSpecWildcard, SucceedsWithInclusion) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -845,7 +821,7 @@ TEST(IndexSpecWildcard, SucceedsWithInclusion) { } TEST(IndexSpecWildcard, SucceedsWithExclusion) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -857,7 +833,7 @@ TEST(IndexSpecWildcard, SucceedsWithExclusion) { } TEST(IndexSpecWildcard, SucceedsWithExclusionIncludingId) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -869,7 +845,7 @@ TEST(IndexSpecWildcard, SucceedsWithExclusionIncludingId) { } TEST(IndexSpecWildcard, SucceedsWithInclusionExcludingId) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -881,7 +857,7 @@ TEST(IndexSpecWildcard, SucceedsWithInclusionExcludingId) { } TEST(IndexSpecWildcard, FailsWithInclusionExcludingIdSubfield) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -893,7 +869,7 @@ TEST(IndexSpecWildcard, FailsWithInclusionExcludingIdSubfield) { } TEST(IndexSpecWildcard, FailsWithExclusionIncludingIdSubfield) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -905,7 +881,7 @@ TEST(IndexSpecWildcard, FailsWithExclusionIncludingIdSubfield) { } TEST(IndexSpecWildcard, FailsWithImproperFeatureCompatabilityVersion) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); serverGlobalParams.featureCompatibility.setVersion( ServerGlobalParams::FeatureCompatibility::Version::kUpgradingTo42); auto result = validateIndexSpec(kDefaultOpCtx, @@ -917,7 +893,7 @@ TEST(IndexSpecWildcard, FailsWithImproperFeatureCompatabilityVersion) { } TEST(IndexSpecWildcard, FailsWithMixedProjection) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -929,7 +905,7 @@ TEST(IndexSpecWildcard, FailsWithMixedProjection) { } TEST(IndexSpecWildcard, FailsWithComputedFieldsInProjection) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -942,7 +918,7 @@ TEST(IndexSpecWildcard, FailsWithComputedFieldsInProjection) { } TEST(IndexSpecWildcard, FailsWhenProjectionPluginNotWildcard) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("a" << 1) << "name" << "indexName" @@ -954,7 +930,7 @@ TEST(IndexSpecWildcard, FailsWhenProjectionPluginNotWildcard) { } TEST(IndexSpecWildcard, FailsWhenProjectionIsNotAnObject) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -966,7 +942,7 @@ TEST(IndexSpecWildcard, FailsWhenProjectionIsNotAnObject) { } TEST(IndexSpecWildcard, FailsWithEmptyProjection) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("$**" << 1) << "name" << "indexName" @@ -978,7 +954,7 @@ TEST(IndexSpecWildcard, FailsWithEmptyProjection) { } TEST(IndexSpecWildcard, FailsWhenInclusionWithSubpath) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("a.$**" << 1) << "name" << "indexName" @@ -990,7 +966,7 @@ TEST(IndexSpecWildcard, FailsWhenInclusionWithSubpath) { } TEST(IndexSpecWildcard, FailsWhenExclusionWithSubpath) { - TestCommandFcvGuard guard; + EnsureFCV guard(ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo42); auto result = validateIndexSpec(kDefaultOpCtx, BSON("key" << BSON("a.$**" << 1) << "name" << "indexName" diff --git a/src/mongo/db/index_names.cpp b/src/mongo/db/index_names.cpp index edff5c2feb5..76aee4749bc 100644 --- a/src/mongo/db/index_names.cpp +++ b/src/mongo/db/index_names.cpp @@ -28,7 +28,6 @@ #include "mongo/db/index_names.h" -#include "mongo/db/commands/test_commands_enabled.h" #include "mongo/db/jsobj.h" namespace mongo { @@ -71,10 +70,7 @@ string IndexNames::findPluginName(const BSONObj& keyPattern) { // static bool IndexNames::isKnownName(const string& name) { - return name == IndexNames::GEO_2D || name == IndexNames::GEO_2DSPHERE || - name == IndexNames::GEO_HAYSTACK || name == IndexNames::TEXT || - name == IndexNames::HASHED || name == IndexNames::BTREE || - (getTestCommandsEnabled() && name == IndexNames::WILDCARD); + return (name == IndexNames::BTREE || kIndexNameToType.count(name)); } // static |