summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/index_spec_validate_test.cpp
diff options
context:
space:
mode:
authornehakhatri5 <neha.khatr@mongodb.com>2018-02-01 23:00:54 +1100
committernehakhatri5 <neha.khatr@mongodb.com>2018-02-07 13:54:10 +1100
commit43fbd6a4fbac7d1630a62b3b471c9eeb3222b7e5 (patch)
treef312d8f95b314906b539ea44c963bf74e0b5b7c4 /src/mongo/db/catalog/index_spec_validate_test.cpp
parent603ffac833b945fddf962fc450c65bb67c7733a1 (diff)
downloadmongo-43fbd6a4fbac7d1630a62b3b471c9eeb3222b7e5.tar.gz
SERVER-32756 Enable selection of V2 format unique index
A new unique index format would get added in MongoDB4.0 to overcome the anonmaly of duplicate keys in unique index on secondary instances. Enabled selection of new V2 format unique index via a gating variable. The IndexDescriptor::IndexVersion now has a new flag kV2Unique. The version in an IndexDescriptor object can be either kV2 or kV2Unique. A version value kV2Unique means a V2 format unique index would be created. In this commit all of the V2 format unique index implemetation is a copy of V1(unique index) format. It would change in future commits.
Diffstat (limited to 'src/mongo/db/catalog/index_spec_validate_test.cpp')
-rw-r--r--src/mongo/db/catalog/index_spec_validate_test.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/mongo/db/catalog/index_spec_validate_test.cpp b/src/mongo/db/catalog/index_spec_validate_test.cpp
index f0107cff856..471f1a525ca 100644
--- a/src/mongo/db/catalog/index_spec_validate_test.cpp
+++ b/src/mongo/db/catalog/index_spec_validate_test.cpp
@@ -299,7 +299,7 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsUnsupported) {
BSON("key" << BSON("field" << 1) << "name"
<< "indexName"
<< "v"
- << 3
+ << 4
<< "collation"
<< BSON("locale"
<< "en")),
@@ -398,6 +398,29 @@ TEST(IndexSpecValidateTest, AcceptsIndexVersionV1) {
sorted(result.getValue()));
}
+TEST(IndexSpecValidateTest, AcceptsIndexVersionV2Unique) {
+ ServerGlobalParams::FeatureCompatibility featureCompatibility;
+ featureCompatibility.setVersion(
+ ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36);
+
+ auto result = validateIndexSpec(kDefaultOpCtx,
+ BSON("key" << BSON("field" << 1) << "name"
+ << "indexName"
+ << "v"
+ << 3),
+ kTestNamespace,
+ featureCompatibility);
+ ASSERT_OK(result.getStatus());
+
+ // We don't care about the order of the fields in the resulting index specification.
+ ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name"
+ << "indexName"
+ << "ns"
+ << kTestNamespace.ns()
+ << "v"
+ << 3)),
+ sorted(result.getValue()));
+}
TEST(IndexSpecValidateTest, ReturnsAnErrorIfCollationIsNotAnObject) {
ASSERT_EQ(ErrorCodes::TypeMismatch,
validateIndexSpec(kDefaultOpCtx,