Skip to content

Commit

Permalink
rawkv: add TTL argument for client method CompareAndSwap
Browse files Browse the repository at this point in the history
Signed-off-by: tutububug <tutububug@hotmail.com>
  • Loading branch information
tutububug committed Aug 15, 2023
1 parent a47e1c2 commit e7f473f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion integration_tests/raw/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (s *apiTestSuite) mustBatchDelete(prefix string, keys []string) {
}

func (s *apiTestSuite) mustCASBytes(prefix, key string, old, new []byte) (bool, []byte) {
oldValue, success, err := s.clientForCas.CompareAndSwap(context.Background(), []byte(withPrefix(prefix, key)), old, new)
oldValue, success, err := s.clientForCas.CompareAndSwap(context.Background(), []byte(withPrefix(prefix, key)), old, new, 0)
s.Nil(err)
return success, oldValue
}
Expand Down
3 changes: 2 additions & 1 deletion rawkv/rawkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func (c *Client) Checksum(ctx context.Context, startKey, endKey []byte, options
// NOTE: This feature is experimental. It depends on the single-row transaction mechanism of TiKV which is conflict
// with the normal write operation in rawkv mode. If multiple clients exist, it's up to the clients the sync the atomic mode flag.
// If some clients write in atomic mode but the other don't, the linearizability of TiKV will be violated.
func (c *Client) CompareAndSwap(ctx context.Context, key, previousValue, newValue []byte, options ...RawOption) ([]byte, bool, error) {
func (c *Client) CompareAndSwap(ctx context.Context, key, previousValue, newValue []byte, ttl uint64, options ...RawOption) ([]byte, bool, error) {
if !c.atomic {
return nil, false, errors.New("using CompareAndSwap without enable atomic mode")
}
Expand All @@ -657,6 +657,7 @@ func (c *Client) CompareAndSwap(ctx context.Context, key, previousValue, newValu
Key: key,
Value: newValue,
Cf: c.getColumnFamily(opts),
Ttl: ttl,
}
if previousValue == nil {
reqArgs.PreviousNotExist = true
Expand Down
3 changes: 3 additions & 0 deletions rawkv/rawkv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ func (s *testRawkvSuite) TestCompareAndSwap() {
key,
value,
newValue,
0,
SetColumnFamily(cf))
s.Error(err)

Expand All @@ -551,6 +552,7 @@ func (s *testRawkvSuite) TestCompareAndSwap() {
key,
newValue,
newValue,
0,
SetColumnFamily(cf))
s.Nil(err)
s.False(swapped)
Expand All @@ -563,6 +565,7 @@ func (s *testRawkvSuite) TestCompareAndSwap() {
key,
value,
newValue,
0,
SetColumnFamily(cf))
s.Nil(err)
s.True(swapped)
Expand Down

0 comments on commit e7f473f

Please sign in to comment.