Skip to content

Commit

Permalink
Migrate all OldTxn calls to Txn
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksander Mistewicz <[email protected]>
  • Loading branch information
AwesomePatrol committed Jan 8, 2025
1 parent 9966740 commit 5c2fa44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
17 changes: 0 additions & 17 deletions tests/robustness/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,6 @@ func (c *RecordingClient) Txn(ctx context.Context) clientv3.Txn {
return &wrappedTxn{txn: c.client.Txn(ctx), c: c}
}

func (c *RecordingClient) OldTxn(ctx context.Context, conditions []clientv3.Cmp, onSuccess []clientv3.Op, onFailure []clientv3.Op) (*clientv3.TxnResponse, error) {
txn := c.client.Txn(ctx).If(
conditions...,
).Then(
onSuccess...,
).Else(
onFailure...,
)
c.kvMux.Lock()
defer c.kvMux.Unlock()
callTime := time.Since(c.baseTime)
resp, err := txn.Commit()
returnTime := time.Since(c.baseTime)
c.kvOperations.AppendTxn(conditions, onSuccess, onFailure, callTime, returnTime, resp, err)
return resp, err
}

func (c *RecordingClient) LeaseGrant(ctx context.Context, ttl int64) (*clientv3.LeaseGrantResponse, error) {
c.kvMux.Lock()
defer c.kvMux.Unlock()
Expand Down
10 changes: 8 additions & 2 deletions tests/robustness/traffic/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ func (c etcdTrafficClient) Request(ctx context.Context, request etcdRequestType,
}
case MultiOpTxn:
var resp *clientv3.TxnResponse
resp, err = c.client.OldTxn(opCtx, nil, c.pickMultiTxnOps(), nil)
resp, err = c.client.Txn(opCtx).Then(
c.pickMultiTxnOps()...,
).Commit()
if resp != nil {
rev = resp.Header.Revision
}
Expand All @@ -234,7 +236,11 @@ func (c etcdTrafficClient) Request(ctx context.Context, request etcdRequestType,
}
txnCtx, txnCancel := context.WithTimeout(ctx, RequestTimeout)
var resp *clientv3.TxnResponse
resp, err = c.client.OldTxn(txnCtx, []clientv3.Cmp{clientv3.Compare(clientv3.ModRevision(key), "=", expectedRevision)}, []clientv3.Op{clientv3.OpPut(key, fmt.Sprintf("%d", c.idProvider.NewRequestID()))}, nil)
resp, err = c.client.Txn(txnCtx).If(
clientv3.Compare(clientv3.ModRevision(key), "=", expectedRevision),
).Then(
clientv3.OpPut(key, fmt.Sprintf("%d", c.idProvider.NewRequestID())),
).Commit()
txnCancel()
if resp != nil {
rev = resp.Header.Revision
Expand Down

0 comments on commit 5c2fa44

Please sign in to comment.