-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
This proposal provides an implementation of TTL (#746) assuming the application code inserts documents with timestamps. It can be combined with #5813 to avoid that requirement on the application code.
The idea is to trigger deletions whenever the index value of a document passes the current time.
Configuration API
Proposal for an API for configuring expiration on a given table:
tbl.setExpiration(indexName[, replaceFunction])sets expiration based on the given indexindexName. Optionally, a custom function can be provided that allows writes other than deletion when a document expires (e.g. setting a flag on the document). The default isreplaceFunction = function(oldVal) { return null; }.tbl.setExpiration(null)disables expirationtbl.getExpiration()retrieves the current expiration configuration
The setExpiration term requires "config" permissions on tbl.
Notes
Care must be taken when specifying a non-default replaceFunction. If the function fails to lower or remove the value of the index indexName for the document, expiration will not work (though we will catch this case, see below).
Implementation
Runs on each primary replica of the table:
- Run
tbl.between(r.minval, r.now, {index: indexName}).replace(replaceFunction)limited to the shard's range - Fetch
next = tbl.min({index: indexName}), evaluatenextTS = indexFunc(next), limited to the shard's range - If
nextTSis not a datetime, log an error, sleep indefinitely.
(Detail to detect badreplaceFunction: ifnexthas the same primary key as thenextfrom the previous iteration, print an error and sleep indefinitely as well.)
Otherwise, sleep fornextTS - r.now.
In either case, the sleep gets interrupted if any write on the primary's shard range
introduces an index value that's smaller thannextTS. - Go to step 1
CaptainYarb, Cherry, gjuchault, andokai, whyhankee and 23 moreneonrust, OriginalEXE, thinklinux, nha and ChrisTalmanmatth3wga0, ralyodio, mormahr, thinklinux, nha and 1 more