This behavior in Kassandra seems counterintuitive, and I want to know why this is happening, and possibly get around it.
Imagine I have a table with three columns: pk
, primary key, type text
, foo
, bigint
and bar
, another text
.
insert into keyspace.table (pk, foo, bar) values ('first', 1, 'test') using ttl 60;
This creates a row in my table that has a life time of 60 seconds. Looking at this, it looks like this:
pk | foo | bar ------------------ first | 1 | test
Now I do:
update keyspace.table using ttl 10 set bar='change' where pk='first';
And then, watching the line, I see that it undergoes the following changes:
pk | foo | bar -------------------- first | 1 | change first | 1 | <<null>> // after 10 seconds << deleted >> // after the initial 60 seconds
All is well and good. What I wanted was for bar
time for a break, but nothing else, especially not the primary key. This behavior was expected.
However, if my update does not have ttl
in it or it is set to 0:
update keyspace.table set bar='change' where pk='first';
Then I see this behavior over time.
pk | foo | bar -------------------- first | 1 | change first | 0 | change // after the initial 60 seconds
In other words, the string is never deleted. foo
not changed, therefore its lifetime remained valid, and after its transfer the value was deleted (set to 0). But pk
has changed its lifetime. This is completely unexpected.
Why does a primary key change in real time only change if I do not specify the lifetime in the update? And how can I get around this so that the primary key of the lifetime changes if I say this explicitly?
Edit I also found that if I use a lifetime that is higher than the initial, it also seems to change the lifetime on the primary key.
update keyspace.table using ttl 70 set bar='change' where pk='first'; pk | foo | bar