FAQ - Is it possible to create an empty set with an Aerospike client?

The Aerospike Knowledge Base has moved to https://support.aerospike.com. Content on https://discuss.aerospike.com is being migrated to either https://support.aerospike.com or https://docs.aerospike.com. Maintenance on articles stored in this repository ceased on December 31st 2022 and this article may be stale. If you have any questions, please do not hesitate to raise a case via https://support.aerospike.com.

FAQ - Is it possible to create an empty set with an Aerospike client?

Detail

Is it possible to use a method within an Aerospike client to create an empty or null set where the set exists but contains no records?

Answer

It is not possible to create an empty set. Although a set can be considered an analogue of a table within an RDBMS for logical simplicity, unlike a table within an RDBMS, a set is not an object within an Aerospike cluster. A set is a logical construct that exists, primarily in the digest of the records that belong to that set. If there is some reason why a set must exist prior to records being inserted, a workaround would be to insert a record into that set and then delete the record. Though the set will be empty, the set is recorded as metadata for the namespace.

The following example describes this:

root@01e3cabfff23:/opt/aerospike/smd# aql
Seed:         127.0.0.1
User:         None
Config File:  /etc/aerospike/astools.conf /root/.aerospike/astools.conf 
Aerospike Query Client
Version 3.16.0
C Client Version 4.3.20
Copyright 2012-2017 Aerospike. All rights reserved.
aql> insert into test.ben (PK,bin1) values (1,'bin1')
OK, 1 record affected.

aql> show sets
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| disable-eviction | ns     | set-enable-xdr | objects | stop-writes-count | set   | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| "false"          | "test" | "use-default"  | "1"     | "0"               | "ben" | "23"              | "0"          | "0"        |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
[127.0.0.1:3000] 1 row in set (0.002 secs)

+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| disable-eviction | ns     | set-enable-xdr | objects | stop-writes-count | set   | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| "false"          | "test" | "use-default"  | "1"     | "0"               | "ben" | "23"              | "0"          | "0"        |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
[172.17.0.3:3000] 1 row in set (0.004 secs)

OK

aql> delete from test.ben where PK=1
OK, 1 record affected.

aql> show sets
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| disable-eviction | ns     | set-enable-xdr | objects | stop-writes-count | set   | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| "false"          | "test" | "use-default"  | "0"     | "0"               | "ben" | "0"               | "0"          | "0"        |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
[127.0.0.1:3000] 1 row in set (0.001 secs)

+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| disable-eviction | ns     | set-enable-xdr | objects | stop-writes-count | set   | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
| "false"          | "test" | "use-default"  | "0"     | "0"               | "ben" | "0"               | "0"          | "0"        |
+------------------+--------+----------------+---------+-------------------+-------+-------------------+--------------+------------+
[172.17.0.3:3000] 1 row in set (0.002 secs)

OK

aql> 

Notes

  • As set metadata is held in memory (shared memory for the Enterprise Edition), if the node cold starts any empty sets will not be returned to the database unless there is a secondary index defined against it or set based security roles/permissions.
  • Any dummy records entered into the set may return on cold start if durable delete is not used, this behaviour in the Cold restart resurrecting deleted records article.
  • The following Knowledge Base article discusses how to permanently remove sets from Aerospike.
  • The normal way to create a set would be to insert a record belonging to that set into the database as shown above. There is no need to create a set prior to insertion of records as a set is simply a logical grouping of records.

Keywords

CREATE EMPTY SET

Timestamp

September 2019