# Getting created time stamp of a record to measure record age (not ttl)

**URL:** <https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426>\
**Category:** General Discussion\
**Tags:** query, udf\
**Created:** [August 7, 2018, 5:36am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426 "2018-08-07T05:36:09Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 7, 2018, 5:36am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/1 "2018-08-07T05:36:09Z")

</div>

Hi, As per the thread: [Get bin insert time/modification time - #3 by holmes](https://discuss.aerospike.com/t/get-bin-insert-time-modification-time/850/3), we don’t have any inbuilt support for `created timestamp` or `modification timestamp`.

For `modification timestamp`, we can write (update policy) unix epoch in a bin, with each write invocations.

But for `created timestamp` we can do either of following things:

1. Create a UDF, which when invoked checks if a record exists or not, if record doesn’t exists then add a column `created_timestamp` and put unix epoch in it.

2. Make two operations to Aerospike, one will check existence of record and another operation to put columns with `created_timestamp` (if record doesn’t exists). (Created timestamp is generated on the application)

Note that while doing write (via any of the above two method) it is made sure that new/updated values are also getting written in their respective column(s). `created_timestamp` is a non-aerospike provided metadata for use-case of my application.

Now, the problem is that UDF is not much optimized as compared to Native Operations, I was earlier using UDF to achieve the goal, but when I switched to combination of Native Operations (2nd point), the CPU utilization decreased by approx **15%** , so it is a big no for me to use UDF for such a small task.

If you notice that the task or goal which I am trying to achieve here is being done by two _aerospike operations_ (batching won’t help as it creates one connection to aerospike node, but does the passed number of operations individually on a record).

I am looking forward to optimize the two operations into one and at the same time achieving `created_timestamp` (rather than `modified_timestamp`) goal.

Please suggest something better which I may be missing here.

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [August 7, 2018, 6:39pm UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/2 "2018-08-07T18:39:21Z")

</div>

2- may not work 100%. checking exists is a separate lock than create the record. another client could have possibly created the record after your exists check.

Explore WritePolicy UPDATE\_ONLY (Java enum) - fails to update the record if the record does not exist - and in that case, on failure, use CREATE\_ONLY (fail if it exists) and create it. So still two transactions but the probability of doing two operations every time greatly reduced. If CREATE\_ONLY also fails (rare possibility) try UPDATE\_ONLY again and it should succeed … unless you are also DELETING records!

---

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 7, 2018, 9:11pm UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/3 "2018-08-07T21:11:53Z")

</div>

@pgupta -

Sorry, I forgot to mention that I am writing from a one particular client, and other clients are just reading the columns. Since no other clients except the one who is checking for existence is writing (or updating the bin), the 2 won’t fail.

Every time I invoke a write operation I need to update the value of other columns, but not created\_timestamp (except that it is write for the first time) value. So using CREATE\_ONLY and then UPDATE\_ONLY, essentially increases my number of operations in all scenario.

---

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 7, 2018, 9:20pm UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/4 "2018-08-07T21:20:19Z")

</div>

Use case for my requirement of `created_timestamp`:

1. To determine the age of record (age: in any time unit)
2. & also if age of record is greater than some value then update the ttl (which can be handled by other clients)

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [August 7, 2018, 9:43pm UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/5 "2018-08-07T21:43:57Z")

</div>

Is your true use case - update the record without changing the ttl but if the ttl is below a certain value, update the ttl also? (ie are you adding these timestamps etc to achieve this functionality?)

---

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 7, 2018, 11:33pm UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/6 "2018-08-07T23:33:25Z")

</div>

No, I understand that I can get TTL from record metadata. But the use case is totally based on when record first came into the system.

Let’s take an example:

1. Record gets inserted with a TTL of 1 Day (first insert)
2. Record appeared after 4th hour of its creation, don’t update the TTL. (Remaining TTL: 20hours)
3. Record appeared after 8th hour of its creation (Remaining TTL: 16hours), update the TTL. (TTL now changed to a new value, let’s say 24 hours)
4. Record appeared after 16th hour (measured by when it was created in 1st step) of its creation, then don’t update the TTL. (Remaining TTL: 16 hours)

If I check on TTL (let’s say `TTL>16` then update the TTL) then at 4th condition I will need to update the TTL also, when it was actually not required.

For the example sake, pls assume that record is coming at different time/hours via some API.

* * *

Quick question: Why cannot be record creation/insertion time be a record metadata (user driven model, if user marks set/record for the miscellaneous metadata tracking) ? Is there any roadmap for it?

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [August 8, 2018, 1:23am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/7 "2018-08-08T01:23:54Z")

</div>

So what you are saying is that any updates within 16 hours of creation should add another 24 hours to the TTL, but after 16 hours of creation, you don’t want to add any TTL on updates. So can you start with initial TTL of 16+24 hours and do ALL updates with TTL=-2…? Then its really just a sizing issue - records will hang around for a little bit longer than you wanted but will get cleared out.

---

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 8, 2018, 4:37am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/8 "2018-08-08T04:37:22Z")

</div>

@pgupta - for example sake, it was small TTL value. But if record really hangs around a little more because of initial TTL set the way you suggested it will increase resource utilisation to great extent, as count of records are in billion.

To me it looks like not possible directly. Will re-think the situation and approach.

---

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 8, 2018, 4:38am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/9 "2018-08-08T04:38:54Z")

</div>

By the way, why created timestamp cannot be in metadata as suggested in previous reply of mine…

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [August 8, 2018, 7:24am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/10 "2018-08-08T07:24:32Z")

</div>

The only timestamp type metadata you have is the LastUpdateTime (LUT) which is currently only accessible via UDF - cannot be read back into the client application. LUT is updated every time you update the record though. So no way to get original creation time unless you store it explicitly in a record bin. You can make a feature request on this forum - in the feature requests section.

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [August 8, 2018, 7:32am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/11 "2018-08-08T07:32:05Z")

</div>

> [@harshvladha](#):
>
> s count of records are in billion.

That is not much of a count for Aerospike. Depends on size of each record. Using the data size / number of bins approx, go through the capacity planning page - [https://www.aerospike.com/docs/operations/plan/capacity/index.html](https://www.aerospike.com/docs/operations/plan/capacity/index.html) - do a basic sizing of your cluster.

---

<div class="post-metadata">

**Author:** ![harshvladha](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/harshvladha/32/1035_2.png) [@harshvladha](https://discuss.aerospike.com/u/harshvladha)\
**Post date:** [August 8, 2018, 9:25am UTC](https://discuss.aerospike.com/t/getting-created-time-stamp-of-a-record-to-measure-record-age-not-ttl/5426/12 "2018-08-08T09:25:43Z")

</div>

Agree but keeping records hanging around for no more use will still Primary Key’s 64byte (per record) in RAM. So if I have 100M+ records which I pre-deterministically know that is not going to be used then I am using extra 6GB+ RAM.
