Deleting from a range query

Postby marcb » Wed Aug 06, 2014 11:40 am

My requirement is to archive records that are older than a certain timestamp. My approach is to do a range query where the secondary index is the timestamp and as I retrieve the records, archive and delete. Here is a code snippet:

My Code:

var client = new AerospikeClient(null, "aerospikehost", 3000);
var statement = new Statement();
long begin = 0;
long end = 10000;
statement.SetFilters(Filter.Range("secondaryindex", begin, end));

var recordSet = client.Query(null, statement);
while (recordSet.Next()) {
    //archive the record
    var key = recordSet.Key;
    client.Delete(null, key);

The problem is that I’m getting a connection timeout exception after a couple thousand records:

Client timeout: timeout=0 iterations=3 failedNodes=0 failedConns=0 at Aerospike.Client.SyncCommand.Execute() at Aerospike.Client.AerospikeClient.Delete(WritePolicy policy, Key key)

Is there a better way to approach this?

Better approach would be to set TTL at namespace level (or at record level via API). More info on how-to can be found here: