381
}
382
384
>
metrics.AcquireShardsCounter.With(c.taggedMetricsHandler).Record(1)
385
>
startTime := time.Now().UTC()
386
>
defer func() {
387
>
metrics.AcquireShardsLatency.With(c.taggedMetricsHandler).Record(time.Since(startTime))
388
>
}()
389
390
>
ctx = headers.SetCallerInfo(ctx, headers.SystemBackgroundHighCallerInfo)
controller_impl.go
391
>
392
>
// Readiness check: if we haven't marked readiness yet, then we need to set up a context to
393
>
// run the readiness check on owned shards.
394
>
var readinessCtx context.Context
395
>
var readinessCancel context.CancelFunc
396
>
if !c.initialShardsAcquired.Ready() {
397
>
readinessCtx, readinessCancel = context.WithCancel(ctx)
398
>
} else {
399
readinessCancel = func() {} // we need a non-nil func for Swap
400
}
401
// Cancel previous readiness check to ensure that the readiness check is always running on
402
// the most recent set of owned shards (e.g. after a membership change).
403
>
if prevCancel := c.shardReadinessCancel.Swap(readinessCancel); prevCancel != nil {
controller_impl.go
404
prevCancel.(context.CancelFunc)()
405
}
406
408
>
var ownedShards []int32 // only populated if we are doing a readiness check
409
>
410
>
tryAcquire := func(shardID int32) {
411
>
if err := c.ownership.verifyOwnership(shardID); err != nil {
412
if IsShardOwnershipLostError(err) {
413
// current host is not owner of shard, unload it if it is already loaded.