DataStax Help Center

Nodes in the same cluster on running on different timezones and why it's ok with Apache Cassandra

Summary

As the nodes in a cluster must be synced to a common clock source, often the question of timezones comes up and how this will affect Apache Cassandra

Question

If we have several data centers in our cluster which are located around the globe they could be running with different timezones. Would this cause any problems with Cassandra and why?

Answer

Machines on different timezones will not cause any problems with Cassandra. Although a machine might be configured to a timezone, it can still be synced to the same clock source as other machines which are on different timezones.

Our documents recommend that all nodes use NTP, the reason for this is so that all nodes are synced to the same clock source and so that any updates being written into the cluster will all be referenced to the same clock source. 

From our docs:

http://www.datastax.com/documentation/cassandra/2.0/cassandra/install/installRecommendSettings.html

Synchronise clocks

The clocks on all nodes should be synchronised. You can use NTP (Network Time Protocol) or other methods.

This is required because columns are only overwritten if the timestamp in the new version of the column is more recent than the existing column.

 To illustrate the point

Test case - changing timezones and checking writetime in DSE

  • Change my time to UK time
[datastax@DSE4 ~]$ sudo cp /usr/share/zoneinfo/Europe/London /etc/localtime
[sudo] password for datastax: 
[datastax@DSE4 ~]$ date
Wed Nov 26 14:53:31 GMT 2014
[datastax@DSE4 ~]$ date -u
Wed Nov 26 14:53:34 UTC 2014
  • Now login to cqlsh and insert some data
[datastax@DSE4 ~]$ ./dse-4.5.1/bin/cqlsh 192.168.56.23
Connected to MyCluster at 192.168.56.23:9160.
[cqlsh 4.1.1 | Cassandra 2.0.8.39 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> INSERT INTO results.result_test (key, column1 , value ) VALUES ( 'key8', 'col8', 'val8');
cqlsh> exit
  • Change my time to Eastern time:
[datastax@DSE4 ~]$ sudo cp /usr/share/zoneinfo/US/Eastern /etc/localtime
[datastax@DSE4 ~]$ date
Wed Nov 26 09:54:23 EST 2014
[datastax@DSE4 ~]$ date -u
Wed Nov 26 14:54:25 UTC 2014
  • Now login to cqlsh and insert some more data
[datastax@DSE4 ~]$ ./dse-4.5.1/bin/cqlsh 192.168.56.23
Connected to MyCluster at 192.168.56.23:9160.
[cqlsh 4.1.1 | Cassandra 2.0.8.39 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh> INSERT INTO results.result_test (key, column1 , value ) VALUES ( 'key9', 'col9', 'val9');
  • Now we select the writetime of the new data
cqlsh> SELECT WRITETIME (value) from results.result_test where key='key8';

 writetime(value)
------------------
 1417013642307000

(1 rows)

cqlsh> SELECT WRITETIME (value) from results.result_test where key='key9';

 writetime(value)
------------------
 1417013679163000

(1 rows)

cqlsh> exit
  • Now we check the time of the writes note the time is in microseconds where the date function expects seconds so just remove the last 6 digits
[datastax@DSE4 ~]$ date -u -d @1417013642 
Wed Nov 26 14:54:02 UTC 2014
[datastax@DSE4 ~]$ date -u -d @1417013679
Wed Nov 26 14:54:39 UTC 2014

We can see that the second insert although made when the machine was in EST, it was still after the insert made during GMT.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk