本文整理汇总了Golang中github.com/cockroachdb/cockroach/proto.EndTransactionResponse类的典型用法代码示例。如果您正苦于以下问题:Golang EndTransactionResponse类的具体用法?Golang EndTransactionResponse怎么用?Golang EndTransactionResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EndTransactionResponse类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: EndTransaction
// EndTransaction either commits or aborts (rolls back) an extant
// transaction according to the args.Commit parameter.
func (r *Range) EndTransaction(args *proto.EndTransactionRequest, reply *proto.EndTransactionResponse) {
reply.SetGoError(util.Error("unimplemented"))
}
开发者ID:kuguobing,项目名称:cockroach,代码行数:5,代码来源:range.go
示例2: EndTransaction
// EndTransaction either commits or aborts (rolls back) an extant
// transaction according to the args.Commit parameter.
func (r *Range) EndTransaction(batch engine.Engine, ms *engine.MVCCStats, args *proto.EndTransactionRequest, reply *proto.EndTransactionResponse) {
if args.Txn == nil {
reply.SetGoError(util.Errorf("no transaction specified to EndTransaction"))
return
}
key := keys.TransactionKey(args.Txn.Key, args.Txn.ID)
// Fetch existing transaction if possible.
existTxn := &proto.Transaction{}
ok, err := engine.MVCCGetProto(batch, key, proto.ZeroTimestamp, true, nil, existTxn)
if err != nil {
reply.SetGoError(err)
return
}
// If the transaction record already exists, verify that we can either
// commit it or abort it (according to args.Commit), and also that the
// Timestamp and Epoch have not suffered regression.
if ok {
// Use the persisted transaction record as final transaction.
reply.Txn = gogoproto.Clone(existTxn).(*proto.Transaction)
if existTxn.Status == proto.COMMITTED {
reply.SetGoError(proto.NewTransactionStatusError(existTxn, "already committed"))
return
} else if existTxn.Status == proto.ABORTED {
reply.SetGoError(proto.NewTransactionAbortedError(existTxn))
return
} else if args.Txn.Epoch < existTxn.Epoch {
reply.SetGoError(proto.NewTransactionStatusError(existTxn, fmt.Sprintf("epoch regression: %d", args.Txn.Epoch)))
return
} else if args.Txn.Epoch == existTxn.Epoch && existTxn.Timestamp.Less(args.Txn.OrigTimestamp) {
// The transaction record can only ever be pushed forward, so it's an
// error if somehow the transaction record has an earlier timestamp
// than the original transaction timestamp.
reply.SetGoError(proto.NewTransactionStatusError(existTxn, fmt.Sprintf("timestamp regression: %s", args.Txn.OrigTimestamp)))
return
}
// Take max of requested epoch and existing epoch. The requester
// may have incremented the epoch on retries.
if reply.Txn.Epoch < args.Txn.Epoch {
reply.Txn.Epoch = args.Txn.Epoch
}
// Take max of requested priority and existing priority. This isn't
// terribly useful, but we do it for completeness.
if reply.Txn.Priority < args.Txn.Priority {
reply.Txn.Priority = args.Txn.Priority
}
} else {
// The transaction doesn't exist yet on disk; use the supplied version.
reply.Txn = gogoproto.Clone(args.Txn).(*proto.Transaction)
}
// Take max of requested timestamp and possibly "pushed" txn
// record timestamp as the final commit timestamp.
if reply.Txn.Timestamp.Less(args.Timestamp) {
reply.Txn.Timestamp = args.Timestamp
}
// Set transaction status to COMMITTED or ABORTED as per the
// args.Commit parameter.
if args.Commit {
// If the isolation level is SERIALIZABLE, return a transaction
// retry error if the commit timestamp isn't equal to the txn
// timestamp.
if args.Txn.Isolation == proto.SERIALIZABLE && !reply.Txn.Timestamp.Equal(args.Txn.OrigTimestamp) {
reply.SetGoError(proto.NewTransactionRetryError(reply.Txn))
return
}
reply.Txn.Status = proto.COMMITTED
} else {
reply.Txn.Status = proto.ABORTED
}
// Persist the transaction record with updated status (& possibly timestamp).
if err := engine.MVCCPutProto(batch, ms, key, proto.ZeroTimestamp, nil, reply.Txn); err != nil {
reply.SetGoError(err)
return
}
// Run triggers if successfully committed. Any failures running
// triggers will set an error and prevent the batch from committing.
if ct := args.InternalCommitTrigger; ct != nil {
// Resolve any explicit intents.
for _, key := range ct.Intents {
if log.V(1) {
log.Infof("resolving intent at %s on end transaction [%s]", key, reply.Txn.Status)
}
if err := engine.MVCCResolveWriteIntent(batch, ms, key, reply.Txn.Timestamp, reply.Txn); err != nil {
reply.SetGoError(err)
return
}
reply.Resolved = append(reply.Resolved, key)
}
// Run appropriate trigger.
if reply.Txn.Status == proto.COMMITTED {
if ct.SplitTrigger != nil {
*ms = engine.MVCCStats{} // clear stats, as split will recompute from scratch.
reply.SetGoError(r.splitTrigger(batch, ct.SplitTrigger))
//.........这里部分代码省略.........
开发者ID:simonzhangsm,项目名称:cockroach,代码行数:101,代码来源:range_command.go
示例3: EndTransaction
// EndTransaction either commits or aborts (rolls back) an extant
// transaction according to the args.Commit parameter.
func (r *Range) EndTransaction(args *proto.EndTransactionRequest, reply *proto.EndTransactionResponse) {
// Create the actual key to the system-local transaction table.
key := engine.MakeKey(engine.KeyLocalTransactionPrefix, args.Key)
// Start with supplied transaction, then possibly load from txn record.
reply.Txn = gogoproto.Clone(args.Txn).(*proto.Transaction)
// Fetch existing transaction if possible.
existTxn := &proto.Transaction{}
ok, err := engine.GetProto(r.engine, key, existTxn)
if err != nil {
reply.SetGoError(err)
return
}
// If the transaction record already exists, verify that we can either
// commit it or abort it (according to args.Commit), and also that the
// Timestamp and Epoch have not suffered regression.
if ok {
if existTxn.Status == proto.COMMITTED {
reply.SetGoError(proto.NewTransactionStatusError(existTxn, "already committed"))
return
} else if existTxn.Status == proto.ABORTED {
reply.SetGoError(proto.NewTransactionStatusError(existTxn, "already aborted"))
return
} else if args.Txn.Epoch < existTxn.Epoch {
reply.SetGoError(proto.NewTransactionStatusError(existTxn, fmt.Sprintf("epoch regression: %d", args.Txn.Epoch)))
return
} else if existTxn.Timestamp.Less(args.Txn.Timestamp) {
// The transaction record can only ever be pushed forward, so it's an
// error if somehow the transaction record has an earlier timestamp
// than the transaction timestamp.
reply.SetGoError(proto.NewTransactionStatusError(existTxn, fmt.Sprintf("timestamp regression: %+v", args.Txn.Timestamp)))
return
}
// Use the persisted transaction record as final transaction.
gogoproto.Merge(reply.Txn, existTxn)
}
// Take max of requested timestamp and possibly "pushed" txn
// record timestamp as the final commit timestamp.
if reply.Txn.Timestamp.Less(args.Timestamp) {
reply.Txn.Timestamp = args.Timestamp
}
// Set transaction status to COMMITTED or ABORTED as per the
// args.Commit parameter.
if args.Commit {
// If the isolation level is SERIALIZABLE, return a transaction
// retry error if the commit timestamp isn't equal to the txn
// timestamp.
if args.Txn.Isolation == proto.SERIALIZABLE && !reply.Txn.Timestamp.Equal(args.Txn.Timestamp) {
reply.SetGoError(proto.NewTransactionRetryError(reply.Txn))
return
}
reply.Txn.Status = proto.COMMITTED
} else {
reply.Txn.Status = proto.ABORTED
}
// Persist the transaction record with updated status (& possibly timestmap).
if err := engine.PutProto(r.engine, key, reply.Txn); err != nil {
reply.SetGoError(err)
return
}
}
开发者ID:embark,项目名称:cockroach,代码行数:66,代码来源:range.go
注:本文中的github.com/cockroachdb/cockroach/proto.EndTransactionResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论