Trying to delete all in set

Having some syntax issues. Hope someone can help me out here. This is NodeJS specific.

My goal is to delete all items in a set. So I scan and queried through the entire set.

stream.on("data", function(rec) { 
    var key= aerospike.key(rec.key.ns, rec.key.set, rec.key.digest);
    client.remove(key, function(err, key) {
       console.log(err);
    });
});

Record has the format. Digest is in SlowBuffer, whatever that is.

  { bins: { <some data> },
    meta: { ttl: 4294967295, gen: 3 },
    key:   {
             ns: 'storage',
             set: 'instances',
             digest: <SlowBuffer 5e 47 1d d0 3d 48 70 28 fd 89 3f c3> } }

Snippet above returns AEROSPIKE_ERR_RECORD_NOT_FOUND error

Hi Zhongcai_Ng,

We do not have digest based API calls. So the record cannot be deleted by passing the digest. If you want to delete all items in a set, you can delete the whole set. Deleting a set can be done through any of the tools provided by aerospike. (AQL/ asinfo). If you would like to delete the set through node.js API, there is an info API available, which can be used to delete sets. Here are the ways to delete a set, using Aerospike tools.

$asinfo -v "set-config:context=namespace;id=namespace_name;set=set_name;set-delete=true;"

$aql -c 'asinfo "set-config:context=namespace;id=namespace_name;set=set_name;set-delete=true;"'

I see. “Info” returns you the “key” value as well for you to do the delete? I manually added in the “key” as a bin in order to perform the delete subsequently.

Info API is used you need some information about the cluster state. It is not meant to retrieve objects. You can delete the complete set using info API. Here is the link to example demonstrating info usage.

Thanks

1 Like

I have the same issue.

I read here

https://www.aerospike.com/community/labs/deleting_sets_and_data.html

[…] The scanAll() method iterates through the Set and returns the Key for each record found. It is actually the encrypted Digest that is returned, but the Java API nicely wraps it in the Key class […]

Would it be possible to get this feature in the node.js client as well?

On a separate note, I try the following:

AerospikeService.prototype.flush = function(namespace, set, cb) {   
 var cmd = util.format('set-config:context=namespace;id=%s;set=%s;set-delete=true;', namespace, set);   
 console.log(cmd);   
 this._client.info(cmd, function(err, response, host) {    
  if(err.code != Status.AEROSPIKE_OK) {
   return cb(new Error(util.format("error putting %s %s", JSON.stringify(key), JSON.stringify(err))));    
  }   
  console.log(response);    
  cb(null);   
 }); 
}

and I sometime see the following error:

․․․․set-config:context=namespace;id=namespace-test;set=run-data-2015-04-v3;set-delete=true; set-config:context=namespace;id=namespace-test;set=run-data-2015-04-v3;set-delete=true; ok

․set-config:context=namespace;id=namespace-test;set=dmp-opt-score-autoscaler-2015-04;set-delete=true; *** glibc detected *** node: malloc(): smallbin double linked list corrupted: 0x0000000002ba7830 *

**

I wanted to bring this error to your attention

Thank you

Hi Mlabour,

I’ll look into these issues and will update you soon.

Thanks

gayathri

When connecting to aerospike, I added key:1. 1 equals to AS_POLICY_KEY_SEND in ./src/include/aerospike/as_policy.h

 client = aerospike.client({
    hosts: [{addr: config.host[0].split(":")[0], port: parseInt(config.host[0].split(":")[1])}],
    log: {level: aerospike.log.INFO},
    policies: {timeout: config.timeout, key:1}
  });

This allows to get the key and not the digest

key: 
   { ns: 'namespace-test',
     set: 'namespace-test',
     key: '08f0613683fb30e27fa431a9f8c416ac682f58dg' } }

This is good news. I can now delete all keys with the scan function.

Thank you

2 Likes