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

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

© 2021 Copyright Aerospike, Inc. | All rights reserved. Creators of the Aerospike Database.