2

I have so many records in aerospike, i want to fetch the records whose ttl is -1 please provide solution

Ronen Botzer
  • 6,951
  • 22
  • 41
Ashu
  • 347
  • 1
  • 9
  • 1
    Okay, but what do you want to do with all those records? Do you want to read their content? Do you want to delete them? Do you want to reset their TTL to a specified amount of time? – Ronen Botzer Jul 17 '17 at 15:43
  • That's different to what you asked on discuss: https://discuss.aerospike.com/t/how-to-get-records-whose-ttl-is-1/4400/5 - you open a duplicate question but give different information? What is that about? – Ronen Botzer Jul 19 '17 at 14:23
  • To save the work I put into answering your question from being lost, I created a duplicate question (https://stackoverflow.com/questions/45193957/how-to-modify-the-ttl-of-all-records-set-with-a-ttl-of-1-in-aerospike). Now I need to edit this question, because you've contradicted yourself. This is discourteous - you ask someone to solve _your_ problem, then you change your mind about what the problem is, after posting a poorly written question. – Ronen Botzer Jul 19 '17 at 14:47

1 Answers1

2

Just to clarify, setting a TTL of -1 in the client means never expire (equivalent to a default-ttl of 0 in the server's aerospike.conf file), while setting a TTL of 0 in the client means inherit the default-ttl for this namespace.

With Predicate Filtering:

If you're using the Java, C, C# and Go clients the easiest way to identify the records with a void time of 0 would be to use a predicate filter.

In the Java app:

Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setPredExp(
  PredExp.recVoidTime(),
  PredExp.integerValue(0),
  PredExp.integerEqual()
  );

RecordSet rs = client.query(null, stmt);

Without Predicate Filtering:

With other clients that don't yet have predicate filtering (Python, PHP, etc), you would do it all through a stream UDF. The filtering logic would have to live inside the UDF.

ttl.lua

local function filter_ttl_zero(rec)
  local rec_ttl = record.ttl(rec)
  if rec_ttl == 0 then
    return true
  end
  return false
end

local function map_record(rec)
  local ret = map()
  for i, bin_name in ipairs(record.bin_names(rec)) do
    ret[bin_name] = rec[bin_name]
  end
  return ret
end

function get_zero_ttl_recs(stream)
  return stream : filter(filter_ttl_zero) : map(map_record)
end

In AQL:

$ aql
Aerospike Query Client
Version 3.12.0
C Client Version 4.1.4
Copyright 2012-2017 Aerospike. All rights reserved.
aql> register module './ttl.lua'
OK, 1 module added.

aql> AGGREGATE ttl.get_zero_ttl_recs() on test.foo

Alternatively, you could run the stream UDF from the client. The following example is for the Python client:

import aerospike
import pprint

config = {'hosts': [('127.0.0.1', 3000)],
          'lua': {'system_path':'/usr/local/aerospike/lua/',
                  'user_path':'/usr/local/aerospike/usr-lua/'}}
client = aerospike.client(config).connect()

pp = pprint.PrettyPrinter(indent=2)
query = client.query('test', 'foo')
query.apply('ttl', 'get_zero_ttl_recs')
records = query.results()
# we expect a dict (map) whose keys are bin names
# each with the associated bin value
pp.pprint(records)
client.close()
Ronen Botzer
  • 6,951
  • 22
  • 41