本文整理匯總了Golang中github.com/cockroachdb/cockroach/proto.InternalPushTxnResponse類的典型用法代碼示例。如果您正苦於以下問題:Golang InternalPushTxnResponse類的具體用法?Golang InternalPushTxnResponse怎麽用?Golang InternalPushTxnResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了InternalPushTxnResponse類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InternalPushTxn
// InternalPushTxn resolves conflicts between concurrent txns (or
// between a non-transactional reader or writer and a txn) in several
// ways depending on the statuses and priorities of the conflicting
// transactions. The InternalPushTxn operation is invoked by a
// "pusher" (the writer trying to abort a conflicting txn or the
// reader trying to push a conflicting txn's commit timestamp
// forward), who attempts to resolve a conflict with a "pushee"
// (args.PushTxn -- the pushee txn whose intent(s) caused the
// conflict).
//
// Txn already committed/aborted: If pushee txn is committed or
// aborted return success.
//
// Txn Timeout: If pushee txn entry isn't present or its LastHeartbeat
// timestamp isn't set, use PushTxn.Timestamp as LastHeartbeat. If
// current time - LastHeartbeat > 2 * DefaultHeartbeatInterval, then
// the pushee txn should be either pushed forward, aborted, or
// confirmed not pending, depending on value of Request.PushType.
//
// Old Txn Epoch: If persisted pushee txn entry has a newer Epoch than
// PushTxn.Epoch, return success, as older epoch may be removed.
//
// Lower Txn Priority: If pushee txn has a lower priority than pusher,
// adjust pushee's persisted txn depending on value of
// args.PushType. If args.PushType is ABORT_TXN, set txn.Status to
// ABORTED, and priority to one less than the pusher's priority and
// return success. If args.PushType is PUSH_TIMESTAMP, set
// txn.Timestamp to pusher's Timestamp + 1 (note that we use the
// pusher's Args.Timestamp, not Txn.Timestamp because the args
// timestamp can advance during the txn).
//
// Higher Txn Priority: If pushee txn has a higher priority than
// pusher, return TransactionPushError. Transaction will be retried
// with priority one less than the pushee's higher priority.
func (r *Range) InternalPushTxn(batch engine.Engine, ms *engine.MVCCStats, args *proto.InternalPushTxnRequest, reply *proto.InternalPushTxnResponse) {
if !bytes.Equal(args.Key, args.PusheeTxn.Key) {
reply.SetGoError(util.Errorf("request key %s should match pushee's txn key %s", args.Key, args.PusheeTxn.Key))
return
}
key := keys.TransactionKey(args.PusheeTxn.Key, args.PusheeTxn.ID)
// Fetch existing transaction if possible.
existTxn := &proto.Transaction{}
ok, err := engine.MVCCGetProto(batch, key, proto.ZeroTimestamp,
true /* consistent */, nil /* txn */, existTxn)
if err != nil {
reply.SetGoError(err)
return
}
if ok {
// Start with the persisted transaction record as final transaction.
reply.PusheeTxn = gogoproto.Clone(existTxn).(*proto.Transaction)
// Upgrade the epoch, timestamp and priority as necessary.
if reply.PusheeTxn.Epoch < args.PusheeTxn.Epoch {
reply.PusheeTxn.Epoch = args.PusheeTxn.Epoch
}
reply.PusheeTxn.Timestamp.Forward(args.PusheeTxn.Timestamp)
if reply.PusheeTxn.Priority < args.PusheeTxn.Priority {
reply.PusheeTxn.Priority = args.PusheeTxn.Priority
}
} else {
// Some sanity checks for case where we don't find a transaction record.
if args.PusheeTxn.LastHeartbeat != nil {
reply.SetGoError(proto.NewTransactionStatusError(&args.PusheeTxn,
"no txn persisted, yet intent has heartbeat"))
return
} else if args.PusheeTxn.Status != proto.PENDING {
reply.SetGoError(proto.NewTransactionStatusError(&args.PusheeTxn,
fmt.Sprintf("no txn persisted, yet intent has status %s", args.PusheeTxn.Status)))
return
}
// The transaction doesn't exist yet on disk; use the supplied version.
reply.PusheeTxn = gogoproto.Clone(&args.PusheeTxn).(*proto.Transaction)
}
// If already committed or aborted, return success.
if reply.PusheeTxn.Status != proto.PENDING {
// Trivial noop.
return
}
// If we're trying to move the timestamp forward, and it's already
// far enough forward, return success.
if args.PushType == proto.PUSH_TIMESTAMP && args.Timestamp.Less(reply.PusheeTxn.Timestamp) {
// Trivial noop.
return
}
// pusherWins bool is true in the event the pusher prevails.
var pusherWins bool
// If there's no incoming transaction, the pusher is non-transactional.
// We make a random priority, biased by specified
// args.Header().UserPriority in this case.
var priority int32
if args.Txn != nil {
priority = args.Txn.Priority
} else {
// Make sure we have a deterministic random number when generating
// a priority for this txn-less request, so all replicas see same priority.
//.........這裏部分代碼省略.........