[SERVER-69091] Handle additional out-of-bounds expireAfterSeconds values for TTL indexes Created: 23/Aug/22  Updated: 29/Oct/23  Resolved: 17/Oct/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Dan Larkin-York Assignee: Matthew Saltz (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-69783 use integral type for TTL index test ... Closed
related to SERVER-73879 Improve error messages for out-of-bou... Closed
is related to SERVER-68477 Improve NaN-handling for expireAfterS... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Execution Team 2022-10-17, Execution Team 2022-10-31
Participants:

 Description   

We fixed NaN-handling for TTL indexes in SERVER-68477. It appears we may also mishandle other floating point values which are out of bounds for the integer types we convert them to.



 Comments   
Comment by Mukundhan Sampath [ 10/Feb/23 ]

Thanks

Comment by Dan Larkin-York [ 10/Feb/23 ]

I filed SERVER-73879 to update the messaging here.

Comment by Mukundhan Sampath [ 10/Feb/23 ]

@Dan, please update the official document about the upper limit and add more details in the error info

Comment by Mukundhan Sampath [ 09/Feb/23 ]

Perfect, this helps

Comment by Dan Larkin-York [ 09/Feb/23 ]

Hi, mukundhan.sampath@3tsoftwarelabs.com. Thanks for reaching out. The error message here is a bit confusing, or at least less informative than it potentially could be. There's slightly different handling for the maximum value depending on whether you're using the expireAfterSeconds field for a secondary index or a time series collection.

In the case of a secondary index, the allowed range is from 1 to (2^31 - 1) == 2147483647.

Time-series collections are a bit more restricted, and allow a value from 1 to "the number of seconds since the Unix epoch", currently approximately 1675960940 as I type this.

Please let me know if you have any other questions or concerns about this issue.

Comment by Mukundhan Sampath [ 09/Feb/23 ]

After further analysis, came to know that it should not be greater than the current epoch time for time series collections

Comment by Mukundhan Sampath [ 09/Feb/23 ]

Attaching the stacktrace

 

```
com.mongodb.MongoCommandException: Command failed with error 72 (InvalidOptions): 'TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number' on server *****:27017. The full response is {"ok": 0.0, "errmsg": "TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number", "code": 72, "codeName": "InvalidOptions", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1675952975, "i": 9}}, "signature": {"hash": {"$binary": {"base64": "/zm+FhUEu7DmiA/BM+SyUGCT9bw=", "subType": "00"}}, "keyId": 7168488098504900610}}, "operationTime": {"$timestamp":

{"t": 1675952975, "i": 9}

}}

Stacktrace:

_/ java.util.concurrent.CompletionException: com.mongodb.MongoCommandException: Command failed with error 72 (InvalidOptions): 'TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number' on server ****:27017. The full response is {"ok": 0.0, "errmsg": "TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number", "code": 72, "codeName": "InvalidOptions", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1675952975, "i": 9}}, "signature": {"hash": {"$binary": {"base64": "/zm+FhUEu7DmiA/BM+SyUGCT9bw=", "subType": "00"}}, "keyId": 7168488098504900610}}, "operationTime": {"$timestamp": {"t": 1675952975, "i": 9}

}}

____/ Mongo Server error (MongoCommandException): Command failed with error 72 (InvalidOptions): 'TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number' on server ****:27017.
____...
____... The full response is:
____... {| |____... "ok" : 0.0,| |____... "errmsg" : "TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number",| |____... "code" : 72.0,| |____... "codeName" : "InvalidOptions",| |____... "$clusterTime" : \{\| \|____... "clusterTime" : Timestamp(1675952975, 9),\| \|____... "signature" : \{ \\|____... "hash" : BinData(0, "/zm+FhUEu7DmiA/BM+SyUGCT9bw="), \\|____... "keyId" : NumberLong(7168488098504900610) \\|____... }
____... },
____... "operationTime" : Timestamp(1675952975, 9)
____... }
```
Comment by Mukundhan Sampath [ 09/Feb/23 ]

Hi Mathew,

We were using this feature to set ttl - expireAfterSeconds

for time series collection 

```
db.createCollection(

   "t1",

  {

    timeseries: {

    timeField: "timestamp",

    metaField: "metadata",

    granularity: "hours"

 },

    expireAfterSeconds: 2147483648

 }

)

```

and we are getting the following error,

 

```
MongoServerError: TTL index 'expireAfterSeconds' option must be within an acceptable range, try a lower number

```

Could you please provide the upper limit that is configured for the field ?

 

https://github.com/mongodb/mongo/blob/1d79792d701ab899165a7c56108633bbeac3c924/src/mongo/db/catalog/index_key_validate.cpp#L910

 

Have gone through the code, but it still does not help.

 

Using the latest mongodb version in atlas.

 

TIA

 
 

Comment by Githook User [ 17/Oct/22 ]

Author:

{'name': 'Matthew Saltz', 'email': 'matthew.saltz@mongodb.com', 'username': 'saltzm'}

Message: SERVER-69091 Handle invalid TTL expireAfterSeconds values uniformly
Branch: master
https://github.com/mongodb/mongo/commit/16344f9a8ea2264190454a9c880ff8b08730b8ac

Comment by Connie Chen [ 30/Aug/22 ]

This may need to get backported past 5.0, potentially all the way to 4.2

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