Migrate all OldTxn calls to Txn

Signed-off-by: Aleksander Mistewicz <amistewicz@google.com>
This commit is contained in:
Aleksander Mistewicz
2025-01-08 10:52:00 +01:00
parent 7c7d3ce8ae
commit 8335e70304
2 changed files with 8 additions and 19 deletions

View File

@ -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()

View File

@ -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
}
@ -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