`CompareAndSwap` will erase the expiration time of the key.
In go-client V2, the function `CompareAndSwap` will erase the expiration time of the key.
E.g
rawClient.PutWithTTL key1 value1 100
//GetKeyTTL key1 ->*ttl ==100
oldValue :=rawClient.Get key1
previousValue, ok, err := rawClient.CompareAndSwap key1 oldValue newValue
//GetKeyTTL key1 ->*ttl == 0
As far as I know, tikv splices ttl in value and uses it as a compaction filter to delete the key after the life cycle.
In tikv go-client, CompareAndSwap does not specify Ttl
reqArgs := kvrpcpb.RawCASRequest{
Key: key,
Value: newValue,
}
if previousValue == nil {
reqArgs.PreviousNotExist = true
} else {
reqArgs.PreviousValue = previousValue
}
req := tikvrpc.NewRequest(tikvrpc.CmdRawCompareAndSwap, &reqArgs)
req.MaxExecutionDurationMs = uint64(client.MaxWriteExecutionTime.Milliseconds())
resp, _, err := c.sendReq(ctx, key, req, false)
Can I add new ttl to RawCASRequest? Also what can be done to update the value using CAS and keep the historical ttl?@iosmanthus
Originally posted by @wenlive in https://github.com/tikv/client-go/issues/371#issuecomment-1277105165
RawCASRequest has a TTL parameter, this should be a bug, the new TTL should be attached to the request while the key is put with a TTL. Any bugfix pull requests are welcomed! @wenlive
If i'm understanding it correctly, the fix should be introduced in tikv-server side.
To keep the "historical ttl", I think it would better to add an argument (e.g., KeepPreviousTtl) to indicate such request, for backward compatibility.