Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Conversation

@jsteemann
Copy link
Contributor

Clarify how to use time-zoned values in the TTL index.

* `2019-05-27T21:20:00.123-02:00`: May 27th 2019, 21:20:00.123, -02:00 offset from UTC time

Using an invalid date string value in a document's TTL index attribute will prevent the document
from being inserted into the TTL index, so it will not be expired and removed automatically.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neither be expired nor be removed automatically

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an invalid date string value in a document's TTL index attribute will prevent the document from being inserted into the TTL index

Will this raise an error or it will be accepted as a successful operation?

Also, what if user tries to insert a document that have an already expired valid datetime string?
a) ArangoDB doesn't even insert it and returns no error.
b) ArangoDB doesn't insert it returns and error.
c) ArangoDB inserts the document and lets background job remove it on next iteration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No error will be raised if a document is inserted with an invalid date string or with a date string value in the past.
Documents with invalid date string values will not be indexed, so they will not expire and not be removed automatically.
Documents with valid date string values that are in the past should be removed on the next run of the TTL background thread.

Copy link
Contributor

@dothebart dothebart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls. change that

@ramazanpolat
Copy link

Just tried to confirm if it works.

My server is in GMT+3 timezone. This is timedatectl output:

root@arango:~# timedatectl Local time: Mon 2019-05-27 23:02:07 +03 Universal time: Mon 2019-05-27 20:02:07 UTC RTC time: Mon 2019-05-27 20:02:08 Time zone: Europe/Istanbul (+03, +0300) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no 

I've inserted 10 documents each having different datetime format in expireAfter attribute, which is the field of TTL index.

String[] dates = new String[]{ "2019-05-27T20:18:00", "2019-05-27T20:18:00Z", "2019-05-27T20:18:00Z+03:00", "2019-05-27T20:18:00.123Z", "2019-05-27T20:18:00.123Z+03:00", "2019-05-27T23:18:00", "2019-05-27T23:18:00Z", "2019-05-27T23:18:00Z+03:00", "2019-05-27T23:18:00.123Z", "2019-05-27T23:18:00.123Z+03:00" }; try { int index = 0; for (String date : dates) { BaseDocument myObject = new BaseDocument(); myObject.addAttribute("index", String.valueOf(index)); myObject.addAttribute("expireAfter", date); arangoDB.db(dbName).collection(collectionName).insertDocument(myObject); System.out.println(myObject); index++; } System.out.println("Finished"); } catch (ArangoDBException e) { System.err.println("Failed to create document. " + e.getMessage()); } finally { arangoDB.shutdown(); } 

After inserting all 10 documents and waiting for TTL background thread kick in, only the first two are removed from collection. Rest of them still resides in collection. Is this expected behavior?

@jsteemann
Copy link
Contributor Author

jsteemann commented May 27, 2019

@ramazanpolat : can you try
"2019-05-27T20:18:00+03:00"
instead of
"2019-05-27T20:18:00Z+03:00"?

(there is a superfluous Z in the date string. It stands for Zulu time, but +03:00 is specified then it can't be in Zulu time)

@ramazanpolat
Copy link

@jsteemann Ok, I've updated datetime strings.

Results:

String[] dates = new String[]{ "2019-05-28T02:10:00", "2019-05-28T02:10:00Z", "2019-05-28T02:10:00+03:00", "2019-05-28T02:10:00.123Z", "2019-05-28T02:10:00.123+03:00", "2019-05-28T05:10:00", //not removed "2019-05-28T05:10:00Z", //not removed "2019-05-28T05:10:00+03:00", "2019-05-28T05:10:00.123Z",//not removed "2019-05-28T05:10:00.123+03:00", }; 

This is my server time:

root@arango:~# timedatectl Local time: Tue 2019-05-28 05:16:01 +03 Universal time: Tue 2019-05-28 02:16:01 UTC RTC time: Tue 2019-05-28 02:16:02 Time zone: Europe/Istanbul (+03, +0300) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no 

Although my server time is passed the 2019-05-28T05:10:00+03:00, the relevant document not removed.

@jsteemann
Copy link
Contributor Author

@ramazanpolat : if this is your server time as you stated:

Local time: Tue 2019-05-28 05:16:01 +03 Universal time: Tue 2019-05-28 02:16:01 UTC 

Then any documents with an expire time before 05:16:01+03:00 should be removed and any documents with an expire time before 02:16:01Z.

Looking at the results you posted:

"2019-05-28T05:10:00", //not removed "2019-05-28T05:10:00Z", //not removed "2019-05-28T05:10:00+03:00", "2019-05-28T05:10:00.123Z",//not removed "2019-05-28T05:10:00.123+03:00", 

they seem correct. Let me comment each line:

"2019-05-28T05:10:00", //not removed ## intentional, because this is 05:10:00Z, which is 08:10:00+03:00 "2019-05-28T05:10:00Z", //not removed ## same as above "2019-05-28T05:10:00+03:00", ## ok, because time is in the past "2019-05-28T05:10:00.123Z",//not removed ## intentional, because this is 05:10:00.123Z, which is 08:10:00.123+03:00 "2019-05-28T05:10:00.123+03:00", ## ok, because time is in the past 
@Simran-B Simran-B merged commit 5bd1044 into master May 28, 2019
@Simran-B Simran-B deleted the bug-fix/clarify-timezone-handling branch June 11, 2019 10:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

4 participants