本文整理汇总了Golang中github.com/coreos/etcd/storage.KV.TxnEnd方法的典型用法代码示例。如果您正苦于以下问题:Golang KV.TxnEnd方法的具体用法?Golang KV.TxnEnd怎么用?Golang KV.TxnEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/etcd/storage.KV
的用法示例。
在下文中一共展示了KV.TxnEnd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: applyTxn
func applyTxn(kv dstorage.KV, le lease.Lessor, rt *pb.TxnRequest) (*pb.TxnResponse, error) {
var revision int64
ok := true
for _, c := range rt.Compare {
if revision, ok = applyCompare(kv, c); !ok {
break
}
}
var reqs []*pb.RequestUnion
if ok {
reqs = rt.Success
} else {
reqs = rt.Failure
}
if err := checkRequestLeases(le, reqs); err != nil {
return nil, err
}
if err := checkRequestRange(kv, reqs); err != nil {
return nil, err
}
// When executing the operations of txn, we need to hold the txn lock.
// So the reader will not see any intermediate results.
txnID := kv.TxnBegin()
defer func() {
err := kv.TxnEnd(txnID)
if err != nil {
panic(fmt.Sprint("unexpected error when closing txn", txnID))
}
}()
resps := make([]*pb.ResponseUnion, len(reqs))
for i := range reqs {
resps[i] = applyUnion(txnID, kv, reqs[i])
}
if len(resps) != 0 {
revision += 1
}
txnResp := &pb.TxnResponse{}
txnResp.Header = &pb.ResponseHeader{}
txnResp.Header.Revision = revision
txnResp.Responses = resps
txnResp.Succeeded = ok
return txnResp, nil
}
示例2: applyTxn
func applyTxn(kv dstorage.KV, le lease.Lessor, rt *pb.TxnRequest) (*pb.TxnResponse, error) {
var revision int64
txnID := kv.TxnBegin()
defer func() {
err := kv.TxnEnd(txnID)
if err != nil {
panic(fmt.Sprint("unexpected error when closing txn", txnID))
}
}()
ok := true
for _, c := range rt.Compare {
if revision, ok = applyCompare(txnID, kv, c); !ok {
break
}
}
// TODO: check potential errors before actually applying anything
var reqs []*pb.RequestUnion
if ok {
reqs = rt.Success
} else {
reqs = rt.Failure
}
if err := checkRequestLeases(le, reqs); err != nil {
return nil, err
}
resps := make([]*pb.ResponseUnion, len(reqs))
for i := range reqs {
resps[i] = applyUnion(txnID, kv, reqs[i])
}
if len(resps) != 0 {
revision += 1
}
txnResp := &pb.TxnResponse{}
txnResp.Header = &pb.ResponseHeader{}
txnResp.Header.Revision = revision
txnResp.Responses = resps
txnResp.Succeeded = ok
return txnResp, nil
}