forked from hyperledger/fabric-sdk-go
/
defaults.go
166 lines (153 loc) · 5.66 KB
/
defaults.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package retry
import (
"time"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/status"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
grpcCodes "google.golang.org/grpc/codes"
)
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
)
// Resource Management Suggested Defaults
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
)
// DefaultOpts default retry options
var DefaultOpts = Opts{
Attempts: DefaultAttempts,
InitialBackoff: DefaultInitialBackoff,
MaxBackoff: DefaultMaxBackoff,
BackoffFactor: DefaultBackoffFactor,
RetryableCodes: DefaultRetryableCodes,
}
// DefaultChannelOpts default retry options for the channel client
var DefaultChannelOpts = Opts{
Attempts: DefaultAttempts,
InitialBackoff: DefaultInitialBackoff,
MaxBackoff: DefaultMaxBackoff,
BackoffFactor: DefaultBackoffFactor,
RetryableCodes: ChannelClientRetryableCodes,
}
// DefaultResMgmtOpts default retry options for the resource management client
var DefaultResMgmtOpts = Opts{
Attempts: ResMgmtDefaultAttempts,
InitialBackoff: ResMgmtDefaultInitialBackoff,
MaxBackoff: ResMgmtDefaultMaxBackoff,
BackoffFactor: ResMgmtDefaultBackoffFactor,
RetryableCodes: ResMgmtDefaultRetryableCodes,
}
// DefaultRetryableCodes these are the error codes, grouped by source of error,
// that are considered to be transient error conditions by default
var DefaultRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: {
status.EndorsementMismatch,
status.PrematureChaincodeExecution,
status.ChaincodeAlreadyLaunching,
},
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),
},
// TODO: gRPC introduced retries in v1.8.0. This can be replaced with the
// gRPC fail fast option, once available
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 ResMgmtDefaultRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: {
status.EndorsementMismatch,
status.PrematureChaincodeExecution,
status.ChaincodeAlreadyLaunching,
},
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),
},
// TODO: gRPC introduced retries in v1.8.0. This can be replaced with the
// gRPC fail fast option, once available
status.GRPCTransportStatus: {
status.Code(grpcCodes.Unavailable),
},
status.DiscoveryServerStatus: {
status.QueryEndorsers,
},
}
// ChannelClientRetryableCodes are the suggested codes that should be treated as
// transient by fabric-sdk-go/pkg/client/channel.Client
var ChannelClientRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: {
status.ConnectionFailed, status.EndorsementMismatch,
status.PrematureChaincodeExecution,
status.ChaincodeAlreadyLaunching,
},
status.EndorserServerStatus: {
status.Code(common.Status_SERVICE_UNAVAILABLE),
status.Code(common.Status_INTERNAL_SERVER_ERROR),
},
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),
},
// TODO: gRPC introduced retries in v1.8.0. This can be replaced with the
// gRPC fail fast option, once available
status.GRPCTransportStatus: {
status.Code(grpcCodes.Unavailable),
},
}
// ChannelConfigRetryableCodes error codes to be taken into account for query channel config retry
var ChannelConfigRetryableCodes = map[status.Group][]status.Code{
status.EndorserClientStatus: {status.EndorsementMismatch},
}