1

I was just wondering, is there a way to change the TTL of a set through AQL query alone. I have gone through this aerospike page : https://discuss.aerospike.com/t/how-to-modify-ttl-using-udf/5608 and it says I will have to create a lua script and execute using aql query, which is fine.

Is there no support in AQL to change the TTL for a particular set using query alone i.e. without having to write a script? Just curious.

Any help would be appreciated. Thanks

Tom Regner
  • 6,856
  • 4
  • 32
  • 47
T.P.
  • 83
  • 3
  • 12
  • I don't know, but changing the TTL with lua is easy, and everything is written here -> https://stackoverflow.com/q/44988253/7252805 – sheldonzy Sep 20 '22 at 19:24

1 Answers1

3

I don't think with AQL you can do that without a lua module. However the lua module is quite simple. AQL does not have the ability to utilize Operations in execute(), which is the other way you could do using, say, a Java client.

(sets ttl to argument value, in seconds)

mymodule.lua  
============
function mytouch(rec, ttl_val)
   record.set_ttl(rec, ttl_val)
   aerospike:update(rec)
end

Now load this file to the server via AQL.

aql> register module "mymodule.lua"
OK, 1 module added.

I have 10 records, one of them is:

aql> set record_print_metadata true

aql> select * from test.testset where pk="key1"
select * from test.testset where pk="key1"
+--------+-----+--------+-------+
| name   | age | {ttl}  | {gen} |
+--------+-----+--------+-------+
| "Jack" | 26  | 431998 | 1     |
+--------+-----+--------+-------+
1 row in set (0.002 secs)

OK

Lets set all records ttl to 100 seconds..

aql> execute mymodule.mytouch(100) on test.testset
execute mymodule.mytouch(100) on test.testset
OK, Scan job (13085139689609506765) created.

aql> select * from test.testset where pk="key1"
select * from test.testset where pk="key1"
+--------+-----+-------+-------+
| name   | age | {ttl} | {gen} |
+--------+-----+-------+-------+
| "Jack" | 26  | 98    | 2     |
+--------+-----+-------+-------+
1 row in set (0.001 secs)

OK
pgupta
  • 5,130
  • 11
  • 8
  • thanks for the answer. i can see that this script will change the records of already written records. is there a way this script can be modified so that the records that are going to get inserted in future for this set get set with the ttl i want? i am curious if this is possible with UDFs. – T.P. Sep 22 '22 at 06:19
  • 1
    when you insert a new record, in aql all you have to do is: aql> set record_ttl 100 and the aql> insert into .... the record will be inserted with 100 sec ttl. – pgupta Sep 22 '22 at 16:14
  • 1
    Underneath AQL, at C client level, which is what AQL uses, these are two different things, transactions wise. Record insertion is a write transaction where you set ttl through write policy. Modifying all records ttl is a scan operation which can only modify every record it finds via the lua module that you pass to the scan operation. – pgupta Sep 22 '22 at 16:28