Aerospike java client stores data even when the "set" name is null

444 views Asked by At

I was debugging my code, and I found that this Aerospike java client code with the set name as "null" works and inserts data in aerospike:

AerospikeClient client = new AerospikeClient("localhost", 3000);
Key key = new Key("test", null, inputPayload.getUuid());//Note that the set name is given as "null"

Bin bin1 = new Bin("segments", inputPayload.getSegments());

client.put(null, key, bin1);

I was able to insert and retrieve the data, but show sets didn't reveal any set name. After some debugging I found the data using select * from <namespace>

enter image description here

My question is

  1. If the data is not stored in a set, then where is it stored?
  2. We know that aerospike compares to relational database as: namespace == database and set == table. But in relational databases, we are not allowed to insert the data directly in a db, we need to create a table first. And that makes sense. So, why does aerospike allow us to do that with null sets?
3

There are 3 answers

1
pgupta On BEST ANSWER

In Aerospike, you can define a max of 1024 sets, (0 thru 1023) ... default set #0 being the "null" set. Set name is just a metadata on the record - a data modeling convenience and helps with certain commands - especially the newest feature released in version 5.6, set indexing - that greatly speeds up scanning a small number of records (say 1,000) belonging to say, "setA", in an otherwise huge namespace (say, 1 billion records). There are other operational advantages of always attaching a set metadata to your records i.e. specifying a set name with each record, such as using persistent truncate in Enterprise Edition. If you have a mix of records in null set and named sets, you cannot truncate the records in the null set only. If you have a dedicated namespace for like records that you don't want to assign a set name, it saves you storage - the set name is stored with each and every record on device storage. So, there is an incentive in certain data models to not use a set name. A set name can be max 63 characters, each character costing you a byte of storage on device, with each record.

2
Meher On

Good question :) If the set is not specified, the record will be stored in the 'null' set as you figured out. But you can disable this behavior by setting the disallow-null-setname config param to true.

0
kporter On

We know that aerospike compares to relational database as:

Sets and tables are similar concepts but they aren't the same. Early versions of Aerospike didn't have the concept of a "set" and many applications developed then and now prefer to save network and storage overhead by not sending a set name.

For your application, you can disallow the 'null' set by adding disallow-null-setname = true to your namespace configurations.