Skip to content

Commit

Permalink
Merge "[FAB-6515]Make reConnectTotalTimeThreshold in core.yaml"
Browse files Browse the repository at this point in the history
  • Loading branch information
muralisrini authored and Gerrit Code Review committed Oct 20, 2017
2 parents 1e6ed66 + 6a16bd3 commit 9cea8c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
19 changes: 10 additions & 9 deletions core/deliverservice/deliveryclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/core/deliverservice/blocksprovider"
"github.com/hyperledger/fabric/gossip/api"
"github.com/hyperledger/fabric/gossip/util"
"github.com/hyperledger/fabric/protos/orderer"
"github.com/op/go-logging"
"golang.org/x/net/context"
Expand All @@ -29,17 +30,17 @@ func init() {
logger = flogging.MustGetLogger("deliveryClient")
}

const (
defaultReConnectTotalTimeThreshold = time.Second * 60 * 60
)

var (
reConnectTotalTimeThreshold = time.Second * 60 * 5
connTimeout = time.Second * 3
reConnectBackoffThreshold = float64(time.Hour)
connTimeout = time.Second * 3
reConnectBackoffThreshold = float64(time.Hour)
)

// SetReconnectTotalTimeThreshold sets the total time the delivery service
// may spend in reconnection attempts until its retry logic gives up
// and returns an error
func SetReconnectTotalTimeThreshold(duration time.Duration) {
reConnectTotalTimeThreshold = duration
func getReConnectTotalTimeThreshold() time.Duration {
return util.GetDurationOrDefault("peer.deliveryclient.reconnectTotalTimeThreshold", defaultReConnectTotalTimeThreshold)
}

// DeliverService used to communicate with orderers to obtain
Expand Down Expand Up @@ -191,7 +192,7 @@ func (d *deliverServiceImpl) newClient(chainID string, ledgerInfoProvider blocks
return requester.RequestBlocks(ledgerInfoProvider)
}
backoffPolicy := func(attemptNum int, elapsedTime time.Duration) (time.Duration, bool) {
if elapsedTime.Nanoseconds() > reConnectTotalTimeThreshold.Nanoseconds() {
if elapsedTime.Nanoseconds() > getReConnectTotalTimeThreshold().Nanoseconds() {
return 0, false
}
sleepIncrement := float64(time.Millisecond * 500)
Expand Down
2 changes: 1 addition & 1 deletion gossip/service/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestLeaderYield(t *testing.T) {
// There isn't any orderer present so the leader peer won't be able to
// connect to the orderer, and should relinquish its leadership after a while.
// Make sure the other peer declares itself as the leader soon after.
deliverclient.SetReconnectTotalTimeThreshold(time.Second * 5)
viper.Set("peer.deliveryclient.reconnectTotalTimeThreshold", time.Second*5)
viper.Set("peer.gossip.useLeaderElection", true)
viper.Set("peer.gossip.orgLeader", false)
n := 2
Expand Down
6 changes: 6 additions & 0 deletions sampleconfig/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ peer:
# will not be identified as valid by other nodes.
localMspId: DEFAULT

# Delivery service related config
deliveryclient:
# It sets the total time the delivery service may spend in reconnection
# attempts until its retry logic gives up and returns an error
reconnectTotalTimeThreshold: 3600s

# Used with Go profiling tools only in none production environment. In
# production, it should be disabled (eg enabled: false)
profile:
Expand Down

0 comments on commit 9cea8c7

Please sign in to comment.