Search code examples
javaaerospikettl

Aerospike TTL listener


I am doing a POC with Aerospike. It seems to fit all my needs except for one. When I set a TTL on a record, it expires after the TTL expires as expected, but I have a requirement where I want aerospike to notify me when a record is being evicted. Is that even possible?


Solution

  • You can get the record TTL with a UDF and compare to the current time

    A skeleton UDF is given here:

    local function get_metadata(rec) return record.ttl(rec); end

    https://discuss.aerospike.com/t/how-to-query-the-metadata-such-as-ttl-of-record-from-tools/916

    I suspect this would be pretty resource heavy if you are doing it for every single record periodically but it's possible to have your application run that UDF every so often and ping a notification when the record is close to expiry.

    If you are looking at a more general level you can grep the logs for NSUP (this is the subsystem that handles expiration and eviction) and there is a clear log message indicating when NSUP is removing records.