/
defaults.go
228 lines (212 loc) · 7.61 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package retry
import (
"time"
"app/service/fabric-sdk-go-gm/pkg/common/errors/status"
"github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/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.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),
},
// 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.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),
},
// 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),
},
}
// 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.Code(pb.TxValidationCode_MVCC_READ_CONFLICT),
status.ChaincodeAlreadyLaunching,
status.ChaincodeNameNotFound,
},
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},
}
// TestRetryableCodes are used by tests to determine error situations that can be retried.
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.PrematureChaincodeExecution,
status.ChaincodeAlreadyLaunching,
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),
},
// 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),
},
}
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
)
// TestRetryOpts are used by tests to determine retry parameters.
var TestRetryOpts = Opts{
Attempts: TestAttempts,
InitialBackoff: TestInitialBackoff,
MaxBackoff: TestMaxBackoff,
BackoffFactor: TestBackoffFactor,
RetryableCodes: TestRetryableCodes,
}