Skip to main content
Loading
Version: Graph 2.2.0

Enabling TTL (Time to Live)

Aerospike Graph Service (AGS) supports TTL on vertices and edges. When an element's TTL interval expires, AGS drops the element from the graph. When a vertex is dropped using TTL, it behaves the same way it would if it were deleted by other means. All edges associated with the dropped vertex are dropped at the same time.

To assign a TTL interval to an element, assign the element a virtual property with the key ~ttl and a numeric value indicating how long the element should live, in seconds, before AGS drops it from the graph.

AGS TTL configuration options

To enable TTL for AGS, set the aerospike.graph.ttl.enabled configuration option to true. You can specify configuration options when you start the Graph Docker container, or use a .properties file. See Graph Installation for more information about configuring AGS. See Configuration Options for a complete list of AGS configuration options.

aerospike.graph.ttl.enabled=true

Usage

To assign a TTL to an element, assign it a property with the key ~ttl using a regular Gremlin traversal for adding properties. The value must be numeric and is the number of seconds which the element should live from creation until it expires and is dropped from the graph.

// Create a Vertex with a TTL of 10 hours.
g.addV("v1").property("~ttl", 36000).iterate();

// Add a TTL to an existing vertex.
g.addV("v2").iterate();
g.V().hasLabel("v2").property("~ttl", 36000).iterate();

// Update a TTL of an existing vertex with TTL. (10 hours -> 5 hours)
g.V().hasLabel("v1").property("~ttl", 18000).iterate();

Secondary index creation

When you enable TTL on a graph, AGS creates a secondary index on the associated database to allow efficient deletion of elements as their TTL expires. Background worker threads in AGS perform the deletions as needed.

Concurrency

Under normal conditions, TTL expiration deletions may take up to two seconds to complete.

Deleting elements whose TTL has expired requires processing time, and if the system must delete a large number of elements at once it can delay the completion of the delete operation. If you observe system delays when large TTL expirations occur, you may want to add processing capacity by adding AGS instances or upgrading system hardware.