Is it possible to specify the WRITETIME in a Cassandra INSERT command?

1.3k Views Asked by At

I am having a problem where a few INSERT commands are viewed as being send simultaneously on the Cassandra side when my code clearly does not send them simultaneously. (When you get a little congestion on the network, then the problem happens, otherwise, everything works just fine.)

What I am thinking would solve this problem is a way for me to be able to specify the WRITETIME myself. From what I recall, that was possible in thrift, but maybe not (i.e. we could read it for sure.)

So something like this (to simulate the TTL):

INSERT INTO table_name (a, b, c) VALUES (1, 2, 3) USING WRITETIME = 123;

The problem I'm facing is overwriting the same data and once in a while the update is ignored because it ends up with the same or even an older timestamp (probably because it is sent to a different node and the time of each node is slightly different and since the C++ process uses threads, it can be send before/after without your control...)

1

There are 1 best solutions below

2
On BEST ANSWER

The magic syntax you're looking for is:

INSERT INTO tbl (col1, col2) VALUES (1,2) USING TIMESTAMP 123456789000

Be very cautious using this approach - make sure you use the right units (microseconds, typically).

You can override the meaning of time stamps in some cases - it's a sneaky trick we've used in the past to do clever things like first-write-wins and even stored leaderboard values in the TIMESTAMP field so highest score would be persisted, but you should REALLY understand the concept before trying these (deletes become nontrivial)