本文整理汇总了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
}