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/akorosmezey/fabric-sdk-go/pkg/client/channel#WithRetry https://godoc.org/github.com/akorosmezey/fabric-sdk-go/pkg/client/resmgmt#WithRetry
Index ¶
Constants ¶
const ( // DefaultAttempts number of retry attempts made by default DefaultAttempts = 3 // DefaultInitialBackoff default initial backoff DefaultInitialBackoff = 500 * time.Millisecond // DefaultMaxBackoff default maximum backoff DefaultMaxBackoff = 60 * time.Second // DefaultBackoffFactor default backoff factor DefaultBackoffFactor = 2.0 )
const ( // ResMgmtDefaultAttempts number of retry attempts made by default ResMgmtDefaultAttempts = 5 // ResMgmtDefaultInitialBackoff default initial backoff ResMgmtDefaultInitialBackoff = time.Second // ResMgmtDefaultMaxBackoff default maximum backoff ResMgmtDefaultMaxBackoff = 60 * time.Second // ResMgmtDefaultBackoffFactor default backoff factor ResMgmtDefaultBackoffFactor = 2.5 )
Resource Management Suggested Defaults
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 ¶
var ChannelClientRetryableCodes = map[status.Group][]status.Code{ status.EndorserClientStatus: { status.ConnectionFailed, status.EndorsementMismatch, status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), status.ChaincodeNameNotFound, }, status.EndorserServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), status.PvtDataDisseminationFailed, }, status.OrdererClientStatus: { status.ConnectionFailed, }, status.OrdererServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), }, status.EventServerStatus: { status.Code(pb.TxValidationCode_DUPLICATE_TXID), status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE), status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT), }, status.GRPCTransportStatus: { status.Code(grpcCodes.Unavailable), }, }
ChannelClientRetryableCodes are the suggested codes that should be treated as transient by fabric-sdk-go/pkg/client/channel.Client
var ChannelConfigRetryableCodes = map[status.Group][]status.Code{ status.EndorserClientStatus: {status.EndorsementMismatch}, }
ChannelConfigRetryableCodes error codes to be taken into account for query channel config retry
var DefaultChannelOpts = Opts{ Attempts: DefaultAttempts, InitialBackoff: DefaultInitialBackoff, MaxBackoff: DefaultMaxBackoff, BackoffFactor: DefaultBackoffFactor, RetryableCodes: ChannelClientRetryableCodes, }
DefaultChannelOpts default retry options for the channel client
var DefaultOpts = Opts{ Attempts: DefaultAttempts, InitialBackoff: DefaultInitialBackoff, MaxBackoff: DefaultMaxBackoff, BackoffFactor: DefaultBackoffFactor, RetryableCodes: DefaultRetryableCodes, }
DefaultOpts default retry options
var DefaultResMgmtOpts = Opts{ Attempts: ResMgmtDefaultAttempts, InitialBackoff: ResMgmtDefaultInitialBackoff, MaxBackoff: ResMgmtDefaultMaxBackoff, BackoffFactor: ResMgmtDefaultBackoffFactor, RetryableCodes: ResMgmtDefaultRetryableCodes, }
DefaultResMgmtOpts default retry options for the resource management client
var DefaultRetryableCodes = map[status.Group][]status.Code{ status.EndorserClientStatus: { status.EndorsementMismatch, status.ChaincodeNameNotFound, }, status.EndorserServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), }, status.OrdererServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), }, status.EventServerStatus: { status.Code(pb.TxValidationCode_DUPLICATE_TXID), status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE), status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT), }, status.GRPCTransportStatus: { status.Code(grpcCodes.Unavailable), }, }
DefaultRetryableCodes these are the error codes, grouped by source of error, that are considered to be transient error conditions by default
var ResMgmtDefaultRetryableCodes = map[status.Group][]status.Code{ status.EndorserClientStatus: { status.ConnectionFailed, status.EndorsementMismatch, status.ChaincodeNameNotFound, }, status.EndorserServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), }, status.OrdererServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), status.Code(common.Status_BAD_REQUEST), status.Code(common.Status_NOT_FOUND), }, status.EventServerStatus: { status.Code(pb.TxValidationCode_DUPLICATE_TXID), status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE), status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT), }, status.GRPCTransportStatus: { status.Code(grpcCodes.Unavailable), }, }
ResMgmtDefaultRetryableCodes are the suggested codes that should be treated as transient by fabric-sdk-go/pkg/client/resmgmt.Client
var TestRetryOpts = Opts{ Attempts: TestAttempts, InitialBackoff: TestInitialBackoff, MaxBackoff: TestMaxBackoff, BackoffFactor: TestBackoffFactor, RetryableCodes: TestRetryableCodes, }
TestRetryOpts are used by tests to determine retry parameters.
var TestRetryableCodes = map[status.Group][]status.Code{ status.TestStatus: { status.GenericTransient, }, status.DiscoveryServerStatus: { status.QueryEndorsers, status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), }, status.EndorserClientStatus: { status.ConnectionFailed, status.EndorsementMismatch, status.ChaincodeNameNotFound, status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), }, status.EndorserServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), }, status.OrdererClientStatus: { status.ConnectionFailed, }, status.OrdererServerStatus: { status.Code(common.Status_SERVICE_UNAVAILABLE), status.Code(common.Status_INTERNAL_SERVER_ERROR), }, status.EventServerStatus: { status.Code(pb.TxValidationCode_DUPLICATE_TXID), status.Code(pb.TxValidationCode_ENDORSEMENT_POLICY_FAILURE), status.Code(pb.TxValidationCode_MVCC_READ_CONFLICT), status.Code(pb.TxValidationCode_PHANTOM_READ_CONFLICT), }, status.GRPCTransportStatus: { status.Code(grpcCodes.Unavailable), }, }
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 ¶
Handler retry handler interface decides whether a retry is required for the given error
func WithAttempts ¶
WithAttempts new retry Handler with given attempts. Other opts are set to default.
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.