diff --git a/core/deliverservice/deliveryclient.go b/core/deliverservice/deliveryclient.go index c9d6aaded09..7fbcd910dda 100644 --- a/core/deliverservice/deliveryclient.go +++ b/core/deliverservice/deliveryclient.go @@ -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" @@ -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 @@ -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) diff --git a/gossip/service/integration_test.go b/gossip/service/integration_test.go index c1f86e431ba..41aeb2c9eda 100644 --- a/gossip/service/integration_test.go +++ b/gossip/service/integration_test.go @@ -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 diff --git a/sampleconfig/core.yaml b/sampleconfig/core.yaml index 594b77d3064..0b5e86b5fc1 100644 --- a/sampleconfig/core.yaml +++ b/sampleconfig/core.yaml @@ -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: