// retryIntv calculates a retry interval value given the base
547006
func (c *Client) retryIntv(base time.Duration) time.Duration {
	if c.config.DevMode {
		return devModeRetryIntv
	}
	return base + lib.RandomStagger(base)
}
172385
func sb2Inv(r0, r1, r2, r3 *uint32) {
	*r2 ^= *r3
	*r3 ^= *r0
	r4 := *r3
	*r3 &= *r2
	*r3 ^= *r1
	*r1 |= *r2
	*r1 ^= r4
	r4 &= *r3
	*r2 ^= *r3
	r4 &= *r0
	r4 ^= *r2
	*r2 &= *r1
	*r2 |= *r0
	*r3 = ^*r3
	*r2 ^= *r3
	*r0 ^= *r3
	*r0 &= *r1
	*r3 ^= r4
	*r3 ^= *r0
	//return *r1, r4, *r2, *r3
	*r0 = *r1
	*r1 = r4
}
857059
func RetryOnError(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
	if err == nil {
		return false, nil
	}

	e := errors.Parse(err.Error())
	if e == nil {
		return false, nil
	}

	switch e.Code {
	// retry on timeout or internal server error
	case 408, 500:
		return true, nil
	default:
		return false, nil
	}
}
951544
func RandVal(i int) types.ValidatorUpdate {
	pubkey := cmn.RandBytes(32)
	power := cmn.RandUint16() + 1
	v := types.Ed25519ValidatorUpdate(pubkey, int64(power))
	return v
}
1029089
func RetryAlways(ctx context.Context, req Request, retryCount int, err error) (bool, error) {
	return true, nil
}
795699
func (f *Request) InitialInterval(t time.Duration) *Request {
	f.backoff.InitialInterval = t
	return f
}
15023
func Retry(action Action, strategies ...strategy.Strategy) error {
	var err error

	for attempt := uint(0); (0 == attempt || nil != err) && shouldAttempt(attempt, strategies...); attempt++ {
		err = action(attempt)
	}

	return err
}
1256237
func (s *ClusterRerouteService) RetryFailed(retryFailed bool) *ClusterRerouteService {
	s.retryFailed = &retryFailed
	return s
}
143393
func Retry(ctx context.Context, f func() error) error {
	// container for atomic error value
	type errWrap struct {
		E error
	}

	// Try the function in a goroutine
	var errVal atomic.Value
	doneCh := make(chan struct{})
	go func() {
		defer close(doneCh)

		delay := time.Duration(0)
		for {
			// If our context ended, we want to exit right away.
			select {
			case <-ctx.Done():
				return
			case <-time.After(delay):
			}

			// Try the function call
			err := f()

			// return if we have no error, or a FatalError
			done := false
			switch e := err.(type) {
			case nil:
				done = true
			case Fatal:
				err = e.FatalError()
				done = true
			}

			errVal.Store(errWrap{err})

			if done {
				return
			}

			log.Printf("[WARN] retryable error: %v", err)

			delay *= 2

			if delay == 0 {
				delay = initialBackoffDelay
			}

			if delay > maxBackoffDelay {
				delay = maxBackoffDelay
			}

			log.Printf("[INFO] sleeping for %s", delay)
		}
	}()

	// Wait for completion
	select {
	case <-ctx.Done():
	case <-doneCh:
	}

	var lastErr error
	// Check if we got an error executing
	if ev, ok := errVal.Load().(errWrap); ok {
		lastErr = ev.E
	}

	// Check if we have a context error to check if we're interrupted or timeout
	switch ctx.Err() {
	case context.Canceled:
		return fmt.Errorf("interrupted - last error: %v", lastErr)
	case context.DeadlineExceeded:
		return fmt.Errorf("timeout - last error: %v", lastErr)
	}

	if lastErr != nil {
		return lastErr
	}
	return nil
}
1225838
func (r *Ref) tryGetVal() interface{} {
	if r.tvals == nil {
		return nil
	}
	return r.tvals.val
}
245774
func (f RetrierFunc) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) {
	return f(ctx, retry, req, resp, err)
}
471827
func (r *StopRetrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) {
	return 0, false, nil
}
1169277
func (rb *DelayRetryBehavior) NextInterval(retries uint) time.Duration {
	interval := rb.delayFunc(rb.retryDelay, retries)
	if interval > rb.delayLimit {
		interval = rb.delayLimit
	}

	return interval
}
837848
func (ev binlogEvent) IntVar(f BinlogFormat) (byte, uint64, error) {
	data := ev.Bytes()[f.HeaderLength:]

	typ := data[0]
	if typ != IntVarLastInsertID && typ != IntVarInsertID {
		return 0, 0, vterrors.Errorf(vtrpc.Code_INTERNAL, "invalid IntVar ID: %v", data[0])
	}

	value := binary.LittleEndian.Uint64(data[1 : 1+8])
	return typ, value, nil
}
1190245
func Retry(err error, message string, args ...interface{}) error {
	return WrapWithMessage(&RetryError{
		Message: fmt.Sprintf(message, args...),
		Err:     err,
	}, message, args...)
}
480127
func sb4Inv(r0, r1, r2, r3 *uint32) {
	r4 := *r2
	*r2 &= *r3
	*r2 ^= *r1
	*r1 |= *r3
	*r1 &= *r0
	r4 ^= *r2
	r4 ^= *r1
	*r1 &= *r2
	*r0 = ^*r0
	*r3 ^= r4
	*r1 ^= *r3
	*r3 &= *r0
	*r3 ^= *r2
	*r0 ^= *r1
	*r2 &= *r0
	*r3 ^= *r0
	*r2 ^= r4
	*r2 |= *r3
	*r3 ^= *r0
	*r2 ^= *r1
	//return *r0, *r3, *r2, r4
	*r1 = *r3
	*r3 = r4
}
662874
func (d DefaultRetryer) RetryRules(r *request.Request) time.Duration {
	// Set the upper limit of delay in retrying at ~five minutes
	minTime := 30
	throttle := d.shouldThrottle(r)
	if throttle {
		if delay, ok := getRetryDelay(r); ok {
			return delay
		}

		minTime = 500
	}

	retryCount := r.RetryCount
	if throttle && retryCount > 8 {
		retryCount = 8
	} else if retryCount > 13 {
		retryCount = 13
	}

	delay := (1 << uint(retryCount)) * (sdkrand.SeededRand.Intn(minTime) + minTime)
	return time.Duration(delay) * time.Millisecond
}