Enabling TTL (Time to Live)
Overview
This page describes how to specify TTL (time to live) for graph edges and vertices on with Aerospike Graph Service (AGS). When an element's TTL interval expires, AGS drops the element from the graph.
When a vertex's TTL expires, 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. When an edge's TTL expires, only the specified edge is dropped.
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();
// Create an edge with a TTL of one week.
g.addE(v1, v2, "edge_label").property("~ttl", 604800).iterate();
// Add a TTL to an existing edge.
Edge myEdge = g.addE(v1, v2, "edge_label").next();
g.E(myEdge).property("~ttl", 604800).iterate();
// Reduce the edge's TTL to one day.
g.E(myEdge).property("~ttl", 86400).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.