本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/util/log.AmbientContext.AnnotateCtx方法的典型用法代碼示例。如果您正苦於以下問題:Golang AmbientContext.AnnotateCtx方法的具體用法?Golang AmbientContext.AnnotateCtx怎麽用?Golang AmbientContext.AnnotateCtx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/util/log.AmbientContext
的用法示例。
在下文中一共展示了AmbientContext.AnnotateCtx方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewContext
// NewContext creates an rpc Context with the supplied values.
func NewContext(
ambient log.AmbientContext, baseCtx *base.Config, hlcClock *hlc.Clock, stopper *stop.Stopper,
) *Context {
ctx := &Context{
Config: baseCtx,
}
if hlcClock != nil {
ctx.localClock = hlcClock
} else {
ctx.localClock = hlc.NewClock(hlc.UnixNano)
}
ctx.breakerClock = breakerClock{
clock: ctx.localClock,
}
var cancel context.CancelFunc
ctx.masterCtx, cancel = context.WithCancel(ambient.AnnotateCtx(context.Background()))
ctx.Stopper = stopper
ctx.RemoteClocks = newRemoteClockMonitor(
ctx.masterCtx, ctx.localClock, 10*defaultHeartbeatInterval)
ctx.HeartbeatInterval = defaultHeartbeatInterval
ctx.HeartbeatTimeout = 2 * defaultHeartbeatInterval
ctx.conns.cache = make(map[string]*connMeta)
stopper.RunWorker(func() {
<-stopper.ShouldQuiesce()
cancel()
ctx.conns.Lock()
for key, meta := range ctx.conns.cache {
meta.Do(func() {
// Make sure initialization is not in progress when we're removing the
// conn. We need to set the error in case we win the race against the
// real initialization code.
if meta.err == nil {
meta.err = &roachpb.NodeUnavailableError{}
}
})
ctx.removeConnLocked(key, meta)
}
ctx.conns.Unlock()
})
return ctx
}
示例2: newRaftScheduler
func newRaftScheduler(
ambient log.AmbientContext, metrics *StoreMetrics, processor raftProcessor, numWorkers int,
) *raftScheduler {
s := &raftScheduler{
processor: processor,
numWorkers: numWorkers,
}
muLogger := syncutil.ThresholdLogger(
ambient.AnnotateCtx(context.Background()),
defaultReplicaMuWarnThreshold,
func(ctx context.Context, msg string, args ...interface{}) {
log.Warningf(ctx, "raftScheduler.mu: "+msg, args...)
},
func(t time.Duration) {
if metrics != nil {
metrics.MuSchedulerNanos.RecordValue(t.Nanoseconds())
}
},
)
s.mu.TimedMutex = syncutil.MakeTimedMutex(muLogger)
s.mu.cond = sync.NewCond(&s.mu.TimedMutex)
s.mu.state = make(map[roachpb.RangeID]raftScheduleState)
return s
}