Migrate all OldTxn calls to Txn
Signed-off-by: Aleksander Mistewicz <amistewicz@google.com>
This commit is contained in:
@ -174,23 +174,6 @@ func (c *RecordingClient) Txn(ctx context.Context) clientv3.Txn {
|
|||||||
return &wrappedTxn{txn: c.client.Txn(ctx), c: c}
|
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) {
|
func (c *RecordingClient) LeaseGrant(ctx context.Context, ttl int64) (*clientv3.LeaseGrantResponse, error) {
|
||||||
c.kvMux.Lock()
|
c.kvMux.Lock()
|
||||||
defer c.kvMux.Unlock()
|
defer c.kvMux.Unlock()
|
||||||
|
@ -213,7 +213,9 @@ func (c etcdTrafficClient) Request(ctx context.Context, request etcdRequestType,
|
|||||||
}
|
}
|
||||||
case MultiOpTxn:
|
case MultiOpTxn:
|
||||||
var resp *clientv3.TxnResponse
|
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 {
|
if resp != nil {
|
||||||
rev = resp.Header.Revision
|
rev = resp.Header.Revision
|
||||||
}
|
}
|
||||||
@ -234,7 +236,11 @@ func (c etcdTrafficClient) Request(ctx context.Context, request etcdRequestType,
|
|||||||
}
|
}
|
||||||
txnCtx, txnCancel := context.WithTimeout(ctx, RequestTimeout)
|
txnCtx, txnCancel := context.WithTimeout(ctx, RequestTimeout)
|
||||||
var resp *clientv3.TxnResponse
|
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()
|
txnCancel()
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
rev = resp.Header.Revision
|
rev = resp.Header.Revision
|
||||||
|
Reference in New Issue
Block a user