Skip to content

Commit ddf0faa

Browse files
committed
[FAB-5950] exported peer retry policy to config file
exported connection timeout and reconnect maximal delay between subsequent retries of the delivery service to core.yaml config file. Change-Id: I6a555838ea44c7c6ee49b564409e14faa757b8d6 Signed-off-by: nirro <nirro@il.ibm.com>
1 parent a8cc2c4 commit ddf0faa

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

core/deliverservice/deliveryclient.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,22 @@ func init() {
3333

3434
const (
3535
defaultReConnectTotalTimeThreshold = time.Second * 60 * 60
36-
)
37-
38-
var (
39-
connTimeout = time.Second * 3
40-
reConnectBackoffThreshold = float64(time.Hour)
36+
defaultConnectionTimeout = time.Second * 3
37+
defaultReConnectBackoffThreshold = float64(time.Hour)
4138
)
4239

4340
func getReConnectTotalTimeThreshold() time.Duration {
4441
return util.GetDurationOrDefault("peer.deliveryclient.reconnectTotalTimeThreshold", defaultReConnectTotalTimeThreshold)
4542
}
4643

44+
func getConnectionTimeout() time.Duration {
45+
return util.GetDurationOrDefault("peer.deliveryclient.connTimeout", defaultConnectionTimeout)
46+
}
47+
48+
func getReConnectBackoffThreshold() float64 {
49+
return util.GetFloat64OrDefault("peer.deliveryclient.reConnectBackoffThreshold", defaultReConnectBackoffThreshold)
50+
}
51+
4752
// DeliverService used to communicate with orderers to obtain
4853
// new blocks and send them to the committer service
4954
type DeliverService interface {
@@ -222,7 +227,7 @@ func (d *deliverServiceImpl) newClient(chainID string, ledgerInfoProvider blocks
222227
}
223228
sleepIncrement := float64(time.Millisecond * 500)
224229
attempt := float64(attemptNum)
225-
return time.Duration(math.Min(math.Pow(2, attempt)*sleepIncrement, reConnectBackoffThreshold)), true
230+
return time.Duration(math.Min(math.Pow(2, attempt)*sleepIncrement, getReConnectBackoffThreshold())), true
226231
}
227232
connProd := comm.NewConnectionProducer(d.conf.ConnFactory(chainID), d.conf.Endpoints)
228233
bClient := NewBroadcastClient(connProd, d.conf.ABCFactory, broadcastSetup, backoffPolicy)
@@ -259,7 +264,7 @@ func DefaultConnectionFactory(channelID string) func(endpoint string) (*grpc.Cli
259264
}
260265
grpc.EnableTracing = true
261266
ctx := context.Background()
262-
ctx, _ = context.WithTimeout(ctx, connTimeout)
267+
ctx, _ = context.WithTimeout(ctx, getConnectionTimeout())
263268
return grpc.DialContext(ctx, endpoint, dialOpts...)
264269
}
265270
}

gossip/util/misc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ func GetIntOrDefault(key string, defVal int) int {
157157
return defVal
158158
}
159159

160+
// GetFloat64OrDefault returns the float64 value from config if present otherwise default value
161+
func GetFloat64OrDefault(key string, defVal float64) float64 {
162+
viperLock.RLock()
163+
defer viperLock.RUnlock()
164+
165+
if val := viper.GetFloat64(key); val != 0 {
166+
return val
167+
}
168+
169+
return defVal
170+
}
171+
160172
// GetDurationOrDefault returns the Duration value from config if present otherwise default value
161173
func GetDurationOrDefault(key string, defVal time.Duration) time.Duration {
162174
viperLock.RLock()

sampleconfig/core.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ peer:
332332
# attempts until its retry logic gives up and returns an error
333333
reconnectTotalTimeThreshold: 3600s
334334

335+
# It sets the delivery service <-> ordering service node connection timeout
336+
connTimeout: 3s
337+
338+
# It sets the delivery service maximal delay between consecutive retries
339+
reConnectBackoffThreshold: 3600s
340+
335341
# Type for the local MSP - by default it's of type bccsp
336342
localMspType: bccsp
337343

0 commit comments

Comments
 (0)