Defining a Table with Row Expiration

When defining a table, you can set the default_ttl property to a non-zero value to enable row expiration. The time interval is specified in seconds. Unless a different TTL was set on a particular row, rows inserted in a table inherits the default TTL value set on the table and expires after their TTL interval has elapsed. If the default_ttl is not set or is set to 0 (zero), the rows of the table never expire.

Procedure

  • Open the command prompt, and run tibdg using the following syntax to create a table in which rows expire:
    table create [default_ttl=<time interval in seconds>] table_name key_column_name key_column_type
    For example, if rows expire after 1 hour, the table would be created with the following tibdg command:
    tibdg table create default_ttl=3600 t1 key long value string
    For the same example, you can use the following SQL DDL command:
    CREATE TABLE t1 (key INT PRIMARY KEY, value VARCHAR) default_ttl=3600
    Note: To ensure that a table is scanned for expired rows periodically, use the option expiration_scan_period. The default value is 3600 seconds and the minimum value is 1 second.

Result

All rows in the table expire after the specified TTL.

If you are using the C or Java APIs for ActiveSpaces, you can override the TTL for a table by setting the TTL property at a row level. For more details, see Overriding the Default TTL for a Single Row.