@@ -355,6 +355,21 @@ func (c *CassandraStore) insertChunk(key string, t0, ttl uint32, data []byte) er
355
355
return nil
356
356
}
357
357
358
+ // we calculate ttl like this:
359
+ // - the chunk's t0 plus maxChunkSpan is the ts of last possible datapoint in the chunk
360
+ // - the timestamp of the last datapoint + ttl is the timestamp until when we want to keep this chunk
361
+ // - then we subtract the current time stamp to get the difference relative to now
362
+ // - the result is the ttl in seconds relative to now
363
+ relativeTtl := int64 (t0 + mdata .MaxChunkSpan ()+ ttl ) - time .Now ().Unix ()
364
+
365
+ // if the ttl relative to now is <=0 then we can omit the insert
366
+ if relativeTtl <= 0 {
367
+ if log .IsLevelEnabled (log .DebugLevel ) {
368
+ log .Debugf ("Omitting insert of chunk with ttl %d: %s, %d" , relativeTtl , key , t0 )
369
+ }
370
+ return nil
371
+ }
372
+
358
373
table , ok := c .TTLTables [ttl ]
359
374
if ! ok {
360
375
return errTableNotFound
@@ -363,7 +378,7 @@ func (c *CassandraStore) insertChunk(key string, t0, ttl uint32, data []byte) er
363
378
row_key := fmt .Sprintf ("%s_%d" , key , t0 / Month_sec ) // "month number" based on unix timestamp (rounded down)
364
379
pre := time .Now ()
365
380
ctx , cancel := context .WithTimeout (context .Background (), c .timeout )
366
- ret := c .Session .Query (table .QueryWrite , row_key , t0 , data , ttl ).WithContext (ctx ).Exec ()
381
+ ret := c .Session .Query (table .QueryWrite , row_key , t0 , data , uint32 ( relativeTtl ) ).WithContext (ctx ).Exec ()
367
382
cancel ()
368
383
cassPutExecDuration .Value (time .Now ().Sub (pre ))
369
384
return ret
0 commit comments