# Records with ttl set never have their expiration time shortened

**URL:** <https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292>\
**Category:** General Discussion\
**Created:** [March 11, 2021, 2:48pm UTC](https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292 "2021-03-11T14:48:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wenbozhang](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@wenbozhang](https://discuss.aerospike.com/u/wenbozhang)\
**Post date:** [March 11, 2021, 2:48pm UTC](https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292/1 "2021-03-11T14:48:39Z")

</div>

I saw the following sentence on the cold start page. “Records with ttl set never have their expiration time shortened.”, What does that mean, please?

---

<div class="post-metadata">

**Author:** ![neelp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/neelp/32/1369_2.png) [@neelp](https://discuss.aerospike.com/u/neelp)\
**Post date:** [March 13, 2021, 6:36pm UTC](https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292/2 "2021-03-13T18:36:12Z")

</div>

I believe the sentence appears on [this](https://www.aerospike.com/docs/operations/manage/aerospike/cold_start/index.html#1-data-expiring-naturally-without-ever-having-any-record-s-expiration-time-shortened-or-durably-deleted) page that describes the behavior during a cold restart. It simply means the record’s ttl was never modified to a smaller value. The significance of a record’s ttl ever being shortened is that there is a possibility of the older, longer ttl version on the disk, reappearing although it has been superseded by a shorter ttl version if that version expired but was not written to disk. If a record’s ttl was never shortened, an older version will not be resurrected during cold restart.

For a more detailed discussion, you can read [this](https://discuss.aerospike.com/t/issues-with-cold-start-resurrecting-deleted-records/3930) article.

---

<div class="post-metadata">

**Author:** ![wenbozhang](https://avatars.discourse-cdn.com/v4/letter/w/f1d935/32.png) [@wenbozhang](https://discuss.aerospike.com/u/wenbozhang)\
**Post date:** [March 16, 2021, 9:17am UTC](https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292/3 "2021-03-16T09:17:08Z")

</div>

Thank for your excellent answer. Does this mean that if I use TTL to create a record, but then update it with a smaller TTL:

- Record created with ttl1 (gen-1 / ttl1 - void time t1)

- Record updated with ttl2 (gen-2 / ttl2 - void time t2 \< t1)

- Record expires

```java
    public static void main(String[] args) {
        // save to aerospike , set ttl to 30s
        saveWithExpiration(30);

        // update record ttl, set ttl to 1s
        saveWithExpiration(1);
    }

    private static void saveWithExpiration(int expire) {
        WritePolicy writePolicy = new WritePolicy();
        writePolicy.expiration = expire;
        Key key = new Key(NAMESPACE, SET_NAME, KEY_NAME);
        Bin bin = new Bin(BIN_NAME, "expire time " + expire);
        aerospikeClient.put(writePolicy, key, bin);
    }

```

The records with Gen-2 may not be written to disk due to the reason that the defragmentation is overwritten, so I will bring back the records with gen-1 when I cold start aerospike.

---

<div class="post-metadata">

**Author:** ![neelp](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/neelp/32/1369_2.png) [@neelp](https://discuss.aerospike.com/u/neelp)\
**Post date:** [March 17, 2021, 3:43pm UTC](https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292/4 "2021-03-17T15:43:17Z")

</div>

The example is correct. Note you may only change the expiration time without bin updates using “touch” operation. A general statement is that if a record’s ttl is _ever_ shortened (set to an earlier expiration time), an older version with farther out expiration _may_ be resurrected during cold restart.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [March 17, 2022, 3:43pm UTC](https://discuss.aerospike.com/t/records-with-ttl-set-never-have-their-expiration-time-shortened/8292/5 "2022-03-17T15:43:54Z")

</div>

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
