retry

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2022 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Package retry provides retransmission capabilities to fabric-sdk-go. The only user interaction with this package is expected to be with the defaults defined below. They can be used in conjunction with the WithRetry setting offered by certain clients in the SDK: https://godoc.org/github.com/VoneChain-CS/fabric-sdk-go-gm/pkg/client/channel#WithRetry https://godoc.org/github.com/VoneChain-CS/fabric-sdk-go-gm/pkg/client/resmgmt#WithRetry

Index

Constants

View Source
const (
	// DefaultAttempts number of retry attempts made by default
	DefaultAttempts = 3
	// DefaultInitialBackoff default initial backoff
	DefaultInitialBackoff = 500 * time.Millisecond
	// DefaultMaxBackoff default maximum backoff
	DefaultMaxBackoff = 150 * time.Second
	// DefaultBackoffFactor default backoff factor
	DefaultBackoffFactor = 2.0
)
View Source
const (
	// ResMgmtDefaultAttempts number of retry attempts made by default
	ResMgmtDefaultAttempts = 2
	// ResMgmtDefaultInitialBackoff default initial backoff
	ResMgmtDefaultInitialBackoff = time.Second
	// ResMgmtDefaultMaxBackoff default maximum backoff
	ResMgmtDefaultMaxBackoff = 150 * time.Second
	// ResMgmtDefaultBackoffFactor default backoff factor
	ResMgmtDefaultBackoffFactor = 2.5
)

Resource Management Suggested Defaults

View Source
const (
	// TestAttempts number of retry attempts made by default
	TestAttempts = 10
	// TestInitialBackoff default initial backoff
	TestInitialBackoff = 200 * time.Millisecond
	// TestMaxBackoff default maximum backoff
	TestMaxBackoff = 50 * time.Second
	// TestBackoffFactor default backoff factor
	TestBackoffFactor = 1.75
)

Variables

ChannelClientRetryableCodes are the suggested codes that should be treated as transient by fabric-sdk-go/pkg/client/channel.Client

View Source
var ChannelConfigRetryableCodes = map[status.Group][]status.Code{
	status.EndorserClientStatus: {status.EndorsementMismatch},
}

ChannelConfigRetryableCodes error codes to be taken into account for query channel config retry

View Source
var DefaultChannelOpts = Opts{
	Attempts:       DefaultAttempts,
	InitialBackoff: DefaultInitialBackoff,
	MaxBackoff:     DefaultMaxBackoff,
	BackoffFactor:  DefaultBackoffFactor,
	RetryableCodes: ChannelClientRetryableCodes,
}

DefaultChannelOpts default retry options for the channel client

View Source
var DefaultOpts = Opts{
	Attempts:       DefaultAttempts,
	InitialBackoff: DefaultInitialBackoff,
	MaxBackoff:     DefaultMaxBackoff,
	BackoffFactor:  DefaultBackoffFactor,
	RetryableCodes: DefaultRetryableCodes,
}

DefaultOpts default retry options

View Source
var DefaultResMgmtOpts = Opts{
	Attempts:       ResMgmtDefaultAttempts,
	InitialBackoff: ResMgmtDefaultInitialBackoff,
	MaxBackoff:     ResMgmtDefaultMaxBackoff,
	BackoffFactor:  ResMgmtDefaultBackoffFactor,
	RetryableCodes: ResMgmtDefaultRetryableCodes,
}

DefaultResMgmtOpts default retry options for the resource management client

DefaultRetryableCodes these are the error codes, grouped by source of error, that are considered to be transient error conditions by default

ResMgmtDefaultRetryableCodes are the suggested codes that should be treated as transient by fabric-sdk-go/pkg/client/resmgmt.Client

View Source
var TestRetryOpts = Opts{
	Attempts:       TestAttempts,
	InitialBackoff: TestInitialBackoff,
	MaxBackoff:     TestMaxBackoff,
	BackoffFactor:  TestBackoffFactor,
	RetryableCodes: TestRetryableCodes,
}

TestRetryOpts are used by tests to determine retry parameters.

TestRetryableCodes are used by tests to determine error situations that can be retried.

Functions

This section is empty.

Types

type BeforeRetryHandler

type BeforeRetryHandler func(error)

BeforeRetryHandler is a function that's invoked before a retry attempt.

type Handler

type Handler interface {
	Required(err error) bool
}

Handler retry handler interface decides whether a retry is required for the given error

func New

func New(opts Opts) Handler

New retry Handler with the given opts

func WithAttempts

func WithAttempts(attempts int) Handler

WithAttempts new retry Handler with given attempts. Other opts are set to default.

func WithDefaults

func WithDefaults() Handler

WithDefaults new retry Handler with default opts

type Invocation

type Invocation func() (interface{}, error)

Invocation is the function to be invoked.

type InvokerOpt

type InvokerOpt func(invoker *RetryableInvoker)

InvokerOpt is an invoker option

func WithBeforeRetry

func WithBeforeRetry(beforeRetry BeforeRetryHandler) InvokerOpt

WithBeforeRetry specifies a function to call before a retry attempt

type Opts

type Opts struct {
	// Attempts the number retry attempts
	Attempts int
	// InitialBackoff the backoff interval for the first retry attempt
	InitialBackoff time.Duration
	// MaxBackoff the maximum backoff interval for any retry attempt
	MaxBackoff time.Duration
	// BackoffFactor the factor by which the InitialBackoff is exponentially
	// incremented for consecutive retry attempts.
	// For example, a backoff factor of 2.5 will result in a backoff of
	// InitialBackoff * 2.5 * 2.5 on the second attempt.
	BackoffFactor float64
	// RetryableCodes defines the status codes, mapped by group, returned by fabric-sdk-go
	// that warrant a retry. This will default to retry.DefaultRetryableCodes.
	RetryableCodes map[status.Group][]status.Code
}

Opts defines the retry parameters

type RetryableInvoker

type RetryableInvoker struct {
	// contains filtered or unexported fields
}

RetryableInvoker manages invocations that could return errors and retries the invocation on transient errors.

func NewInvoker

func NewInvoker(handler Handler, opts ...InvokerOpt) *RetryableInvoker

NewInvoker creates a new RetryableInvoker

func (*RetryableInvoker) Invoke

func (ri *RetryableInvoker) Invoke(invocation Invocation) (interface{}, error)

Invoke invokes the given function and performs retries according to the retry options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL