本文整理匯總了Golang中github.com/cockroachdb/cockroach/util/hlc.Clock.MaxDrift方法的典型用法代碼示例。如果您正苦於以下問題:Golang Clock.MaxDrift方法的具體用法?Golang Clock.MaxDrift怎麽用?Golang Clock.MaxDrift使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/util/hlc.Clock
的用法示例。
在下文中一共展示了Clock.MaxDrift方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewTransaction
// NewTransaction creates a new transaction. The transaction key is
// composed using the specified baseKey (for locality with data
// affected by the transaction) and a random UUID to guarantee
// uniqueness. The specified user-level priority is combined with
// a randomly chosen value to yield a final priority, used to settle
// write conflicts in a way that avoids starvation of long-running
// transactions (see Range.InternalPushTxn).
func NewTransaction(baseKey engine.Key, userPriority int32,
isolation proto.IsolationType, clock *hlc.Clock) *proto.Transaction {
// Compute priority by adjusting based on userPriority factor.
if userPriority < 1 {
userPriority = 1
}
priority := math.MaxInt32 - util.CachedRand.Int31n(math.MaxInt32/userPriority)
// Compute timestamp and max timestamp.
now := clock.Now()
max := now
max.WallTime += clock.MaxDrift().Nanoseconds()
return &proto.Transaction{
ID: append(baseKey, []byte(uuid.New())...),
Priority: priority,
Isolation: isolation,
Timestamp: now,
MaxTimestamp: max,
}
}
示例2: Clear
// Clear clears the cache and resets the high water mark to the
// current time plus the maximum clock skew.
func (tc *TimestampCache) Clear(clock *hlc.Clock) {
tc.cache.Clear()
tc.highWater = clock.Now()
tc.highWater.WallTime += clock.MaxDrift().Nanoseconds()
tc.latest = tc.highWater
}