[SERVER-10075] Should forbid illegal form of TTL indexes Created: 01/Jul/13  Updated: 16/Sep/22  Resolved: 16/May/19

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.4.4
Fix Version/s: 4.1.12

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Gregory Wlodarek
Resolution: Done Votes: 2
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-37983 createIndexes should validate the 'ex... Closed
Related
related to SERVER-69783 use integral type for TTL index test ... Closed
related to SERVER-52525 support expireAfterSeconds for time-s... Closed
is related to SERVER-11374 Can create indexes on non-insertable ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

> db.expire.ensureIndex({b:1, ts:1,_id:1}, {expireAfterSeconds: 30})
> db.expire.ensureIndex({ts:1, expireAfterSeconds: 30})
> db.expire.getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"ns" : "ttl.expire",
		"name" : "_id_"
	},
	{
		"v" : 1,
		"key" : {
			"ts" : 1,
			"expireAfterSeconds" : 30
		},
		"ns" : "ttl.expire",
		"name" : "ts_1_expireAfterSeconds_30"
	},
	{
		"v" : 1,
		"key" : {
			"ts" : 1
		},
		"ns" : "ttl.expire",
		"name" : "ts_1",
		"expireAfterSeconds" : 30
	},
	{
		"v" : 1,
		"key" : {
			"b" : 1,
			"ts" : 1,
			"_id" : 1
		},
		"ns" : "ttl.expire",
		"name" : "b_1_ts_1__id_1",
		"expireAfterSeconds" : 30
	}
]

Sprint: Storage NYC 2019-05-20
Participants:
Case:

 Description   

I can create a TTL index with multiple fields and it succeeds. It's not until the TTL thread runs that I get an error in the logs:
Mon Jul 1 12:22:13.189 [TTLMonitor] ERROR: key for ttl index can only have 1 field

The time to show error (and maybe disallow the index creation?) is when an illegal index is specified.

In a related case, user incorrectly specifying expireAfterSeconds as the last field of the index also should get an error rather than the value other than 1 or -1 for field name being accepted.



 Comments   
Comment by Githook User [ 16/May/19 ]

Author:

{'email': 'gregory.wlodarek@mongodb.com', 'name': 'Gregory Wlodarek', 'username': 'GWlodarek'}

Message: SERVER-10075 Forbid illegal forms of TTL indexes during index creation
Branch: master
https://github.com/mongodb/mongo/commit/0dd0b000b4c8df0e7d7bee1826c252af60c73410

Comment by Asya Kamsky [ 09/May/19 ]

Also validate that the number specified isn't too high.

 

For instance,  we probably shouldn't have accepted a number that's big enough to cause this error:

expireAfterSeconds: 9223372036854775807 } -- 159 Overflow casting from a lower-precision duration to a higher-precision duration 

Comment by Asya Kamsky [ 18/Jul/16 ]

Same in 3.3.9 - we allow unknown fields as attributes of indexes, and having compound field just causes the same error in the logs every minute.

Comment by Asya Kamsky [ 09/Sep/15 ]

Still the same behavior in 3.1.6

Comment by Scott Hernandez (Inactive) [ 15/Oct/13 ]

Also should validate that the type is a number.

Generated at Thu Feb 08 03:22:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.