summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2022-08-28 08:31:07 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-28 13:32:23 +0000
commitd6528bf96f08b79ca850902b2d1d81264fa7baa1 (patch)
treeb4ca9dbb83b4527e41e053d30a6b2378c9c24c78 /src/mongo
parentc218ab8f69e51dc747720dcb89acd8bc36d07f54 (diff)
downloadmongo-d6528bf96f08b79ca850902b2d1d81264fa7baa1.tar.gz
SERVER-68477 listIndexes repairs TTL indexes with NaN expireAfterSeconds
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/catalog/index_key_validate.cpp16
-rw-r--r--src/mongo/db/catalog/index_key_validate.h6
-rw-r--r--src/mongo/db/catalog/index_key_validate_test.cpp14
3 files changed, 33 insertions, 3 deletions
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp
index 3fc2aa28304..6e7c5faeb09 100644
--- a/src/mongo/db/catalog/index_key_validate.cpp
+++ b/src/mongo/db/catalog/index_key_validate.cpp
@@ -269,8 +269,8 @@ BSONObj removeUnknownFields(const NamespaceString& ns, const BSONObj& indexSpec)
BSONObj repairIndexSpec(const NamespaceString& ns,
const BSONObj& indexSpec,
const std::set<StringData>& allowedFieldNames) {
- auto fixBoolIndexSpecFn = [&indexSpec, &ns](const BSONElement& indexSpecElem,
- BSONObjBuilder* builder) {
+ auto fixIndexSpecFn = [&indexSpec, &ns](const BSONElement& indexSpecElem,
+ BSONObjBuilder* builder) {
StringData fieldName = indexSpecElem.fieldNameStringData();
if ((IndexDescriptor::kBackgroundFieldName == fieldName ||
IndexDescriptor::kUniqueFieldName == fieldName ||
@@ -285,11 +285,21 @@ BSONObj repairIndexSpec(const NamespaceString& ns,
"fieldName"_attr = redact(fieldName),
"indexSpec"_attr = redact(indexSpec));
builder->appendBool(fieldName, true);
+ } else if (IndexDescriptor::kExpireAfterSecondsFieldName == fieldName &&
+ !(indexSpecElem.isNumber() && !indexSpecElem.isNaN())) {
+ LOGV2_WARNING(6835900,
+ "Fixing expire field from TTL index spec",
+ "namespace"_attr = redact(ns.toString()),
+ "fieldName"_attr = redact(fieldName),
+ "indexSpec"_attr = redact(indexSpec));
+ builder->appendNumber(fieldName,
+ durationCount<Seconds>(kExpireAfterSecondsForInactiveTTLIndex));
} else {
builder->append(indexSpecElem);
}
};
- return buildRepairedIndexSpec(ns, indexSpec, allowedFieldNames, fixBoolIndexSpecFn);
+
+ return buildRepairedIndexSpec(ns, indexSpec, allowedFieldNames, fixIndexSpecFn);
}
StatusWith<BSONObj> validateIndexSpec(OperationContext* opCtx, const BSONObj& indexSpec) {
diff --git a/src/mongo/db/catalog/index_key_validate.h b/src/mongo/db/catalog/index_key_validate.h
index f9680ac035b..2ba7174c1b0 100644
--- a/src/mongo/db/catalog/index_key_validate.h
+++ b/src/mongo/db/catalog/index_key_validate.h
@@ -43,6 +43,12 @@ class StatusWith;
namespace index_key_validate {
+// TTL indexes with 'expireAfterSeconds' are repaired with this duration, which is chosen to be
+// the largest possible value for the 'safeInt' type that can be returned in the listIndexes
+// response.
+constexpr auto kExpireAfterSecondsForInactiveTTLIndex =
+ Seconds(std::numeric_limits<int32_t>::max());
+
static std::set<StringData> allowedFieldNames = {
IndexDescriptor::k2dIndexBitsFieldName,
IndexDescriptor::k2dIndexMaxFieldName,
diff --git a/src/mongo/db/catalog/index_key_validate_test.cpp b/src/mongo/db/catalog/index_key_validate_test.cpp
index 9c4813a2d2e..c60df1b34aa 100644
--- a/src/mongo/db/catalog/index_key_validate_test.cpp
+++ b/src/mongo/db/catalog/index_key_validate_test.cpp
@@ -426,6 +426,20 @@ TEST(IndexKeyValidateTest, RepairIndexSpecs) {
NamespaceString("coll"),
fromjson("{key: {a: 1}, name: 'index', sparse: 'true', background: '1', safe: "
"true, force: true}"))));
+
+ ASSERT(BSON("key" << BSON("a" << 1) << "name"
+ << "index"
+ << "expireAfterSeconds" << std::numeric_limits<int32_t>::max())
+ .binaryEqual(index_key_validate::repairIndexSpec(
+ NamespaceString("coll"),
+ fromjson("{key: {a: 1}, name: 'index', expireAfterSeconds: NaN}"))));
+
+ ASSERT(BSON("key" << BSON("a" << 1) << "name"
+ << "index"
+ << "expireAfterSeconds" << std::numeric_limits<int32_t>::max())
+ .binaryEqual(index_key_validate::repairIndexSpec(
+ NamespaceString("coll"),
+ fromjson("{key: {a: 1}, name: 'index', expireAfterSeconds: '123'}"))));
}
TEST(IndexKeyValidateTest, GeoIndexSpecs) {