How to remove the Primary Key stored alongside your data without altering the record TTL

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.

How to remove the Primary Key stored alongside your data without altering the record TTL

Context

By default, Aerospike does not store the PK (Primary Key) alongside the data in the database. This can be enabled by using the sendKey Write Policy, which will then also store the value of the PK.

Method

Should you have stored the PK with your data and later wish to remove it, this can be achieved with the following UDF:

function dk(rec)
   record.drop_key(rec)
   record.set_ttl(rec, -2)
   aerospike:update(rec)
end

Notes

  • The record.set_ttl(rec, -2) line causes the TTL (if it was initially set) to remain the same. If you require something else you can either remove this line entirely for the TTL to be reset to the default value, or manually set this to the value you require. If you are doing this, please also be aware that the function will run against all data, irrespective of whether it has the PK stored or not. This means that even records where the PK is not removed will have their TTL reset.

Keywords

REMOVE PK PRIMARY KEY STORED SENDKEY KEY_SEND TRUE

Timestamp

December 2020