当前位置: 首页>>代码示例>>Golang>>正文


Golang Clock.MaxDrift方法代码示例

本文整理汇总了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,
	}
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例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
}
开发者ID:,项目名称:,代码行数:8,代码来源:


注:本文中的github.com/cockroachdb/cockroach/util/hlc.Clock.MaxDrift方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。