Context
The LUT (last update time) of a record is part of a record's meta data but is currently not returned to the clients through any direct API. The feature to add such capability is internally tracked under jira AER-5566.
As a workaround, one could use a UDF to get the LUT of a record.
Method
Using UDF, one can get the LUT of a record expressed in milliseconds since the Citrusleaf epoch (00:00:00 UTC on 1 Jan 2010).
e.g. You could define a LUA function as such (under record_example.lua for this example):
-- Return LUT of record
function getLUT(r)
return record.last_update_time(r)
end
From the Java client, you can get the LUT like this after registering the above UDF:
// Get record last update time.
long lut = (Long)client.execute(params.writePolicy, key, "record_example", "getLUT");
You can use aql to register the LUA module or simply register it inside the Java application:
RegisterTask task = client.register(params.policy, "udf/record_example.lua", "record_example.lua", Language.LUA);
task.waitTillComplete();
To register the UDF in aql, start by copying the LUA script to /opt/aerospike/usr/udf/lua
root@Test-1:/opt/aerospike/usr/udf/lua# ls -al total 16 drwxr-xr-x 1 aerospike aerospike 4096 Dec 15 12:21 . drwxr-xr-x 1 aerospike aerospike 4096 Feb 17 2023 .. -rw-r--r-- 1 root root 85 Dec 15 12:21 record_example.lua root@Test-1:/opt/aerospike/usr/udf/lua# aql Seed: 127.0.0.1 User: None Config File: /etc/aerospike/astools.conf /root/.aerospike/astools.conf Aerospike Query Client Version 8.0.0 C Client Version 6.3.0 Copyright 2012-2022 Aerospike. All rights reserved. aql> register module 'record_example.lua' OK, 1 module added. aql> execute record_example.getLUT() on test where PK=1 +--------------+ | getLUT | +--------------+ | 440335053256 | +--------------+ 1 row in set (0.001 secs) OK
Notes
- One can use Expression filters to get records that have been last updated between two timestamps or before/after a certain timestamp.
- If the goal is to delete specific records based on their last updated time, you could also use the truncate command.
- If there is a clock skew between master and replica (for replication factor 2 and above) nodes within a cluster, the last update time of a record will be identical for both copies and will be as per the master node's time.
- https://www.aerospike.com/docs/architecture/primary-index.html#index-metadata
- https://www.aerospike.com/docs/udf/api/record.html
- https://docs.aerospike.com/guide/expressions
- https://support.aerospike.com/s/article/Converting-the-LUT-of-a-record-to-readable-time