How to delete whole set from Aerospike namespace?
Asked Answered
R

9

7

Is there any way to delete a set from namespace (Aerospike) from aql or CLI ???

My set also contains Ldts .

Please suggest me a way to delete whole Set from LDT

Ramin answered 6/2, 2015 at 12:38 Comment(0)
O
11

You can delete a set by using

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

This link explains more about how the set is deleted

http://www.aerospike.com/docs/operations/manage/sets/#deleting-a-set-in-a-namespace

Oldworld answered 6/2, 2015 at 13:29 Comment(1)
There is a new way to delete sets, available in Aerospike 3.12, documented here: aerospike.com/docs/reference/info#truncateSouthernmost
C
5

There is a new and better way to do this as of Aerospike Server version 3.12.0, released in March 2017:

asinfo -v "truncate:namespace=namespace_name;set=set_name"

This previous command has been DEPRECATED, and works only up to Aerospike 3.12.1, released in April 2017:

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

The new command is better in several ways:

  • Can be issued during migrations
  • Can be issued while data is being written to the set
  • It is sufficient to run it on just one node of the cluster

I used it under those conditions (during migration, while data was being written, on 1 node) and it ran very quickly. A set with 30 million records was reduced to 1000 records in about 6 seconds. (Those 1000 records were presumably the ones written during those 6 seconds)

Details here

Cardiograph answered 24/10, 2017 at 22:11 Comment(0)
S
3

As of Aerospike 3.12, which was released in March 2017, the feature of deleting all data in a set or namespace is now supported in the database.

Please see the following documentation: http://www.aerospike.com/docs/reference/info#truncate

Which provides the command line command that looks like: asinfo truncate:namespace=;set=;lut=

It can also be truncated from the client APIs, here is the java documentation: http://www.aerospike.com/apidocs/java/com/aerospike/client/AerospikeClient.html and scroll down to the "truncate" method.

Please note that this feature can, optionally, take a time specification. This allows you to delete records, then start inserting new records. As timestamps are used, please make certain your server clocks are well synchronized.

Southernmost answered 30/3, 2017 at 2:36 Comment(0)
H
2

You can also delete a set with the Java client as follows:

(1) Use the client "execute" method, which applies a UDF on all queried rows

AerospikeClient.execute(WritePolicy policy, Statement statement, String packageName, String functionName, Value... functionArgs) throws AerospikeException

(2) Define the statement to include all rows of the given set:

Statement statement = new Statement();
statement.setNamespace("my_namespace");
statement.setSetName("my_set");

(3) Specify a UDF that deletes the given record:

function delete_rec(rec)
    aerospike:remove(rec)
end

(4) Call the method:

ExecuteTask task = AerospikeClient.execute(null, statement, "myUdf", "delete_rec")
task.waitTillComplete(timeout);

Is it performant? Unclear, but my guess is asinfo is better. But it's very convenient for testing/debugging/setup.

Hyetograph answered 12/1, 2016 at 4:42 Comment(1)
I suggest checking out the new 'truncate' capability, introduced in 3.12 : aerospike.com/docs/reference/info#truncateSouthernmost
M
2

Using AQL:

TRUNCATE namespace_name.set_name

https://www.aerospike.com/docs/tools/aql/aql-help.html

Mead answered 19/4, 2020 at 19:31 Comment(1)
This will just empty a set, rather than delete it.Sada
M
1

You can't delete a set but you can delete all records that exist in the set by scanning all the records and deleting then one by one. Sample C# code that will do the trick:

AerospikeClient.ScanAll(null, AerospikeNameSpace, category, DeleteAllRecordsCallBack);

Here DeleteAllRecordsCallBack is a callback function where in you can delete records one by one. This callback function gets called for all records.

private void DeleteAllRecordsCallBack(Key key, Record record)
{
    AerospikeClient.Delete(null, key);
}
Mucilaginous answered 15/6, 2016 at 14:12 Comment(0)
I
0

Take care that you'll need to restart your nodes (one by one to avoid downtime) because you'll not retrieve bins left space instead.

I mean maximum limit of bins in Aerospike is 32,767. If you just delete and recreate several times your set, if it's create for example 10000 bins each time, you'll not be able to create more than 2,767 bins the 4th time because bins counter is kept in ram.

If you restart you're cluster, it will be released.

Inflect answered 3/7, 2015 at 9:46 Comment(1)
The limit is on bin names, not actual bins, of course. There is no limit on Maps. If you use a map inside of a bin, you can have as many names as you want.Southernmost
A
0

You can't dynamically delete a set from namespace like "drop table" in RDMS.

The following command using asinfo only lazily delete data inside a set:

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

There is a post about it in aerospike discuss site and I didn't see progress about this issue yet.

Archicarp answered 7/5, 2016 at 3:30 Comment(1)
You can starting in Aerospike 3.12.Southernmost
C
0

In our production experience special java deletion utility works quite well even without recently introduced durable deletes. You build it from sources, put somewhere near the cluster and run this way:

java -jar delete-set-1.0.0-jar-with-dependencies.jar -h <aerospike_host> -p 3000 -s <set_to_delete> -n <namespace_name>

In our prod environment cold restarts are quite rare events, basically when aerospike crashes. And the data flow is quite high so defragmentation kicks in earlier and we don't even have zombie record issue.

BTW asinfo way mentioned earlier didn't work for us. The records stayed there for couple of days so we use delete-set utility which worked right away.

Chibcha answered 23/11, 2016 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.