Skip to content

Commit

Permalink
use internal/backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Jun 12, 2018
1 parent 3123c63 commit 88c6170
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 20 additions & 2 deletions balancer/grpclb/grpclb.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
lbpb "google.golang.org/grpc/balancer/grpclb/grpc_lb_v1"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/internal/backoff"
"google.golang.org/grpc/resolver"
)

Expand All @@ -46,6 +47,23 @@ const (
grpclbName = "grpclb"
)

var (
// defaultBackoffConfig configures the backoff strategy that's used when the
// init handshake in the RPC is unsuccessful. It's not for the clientconn
// reconnect backoff.
//
// It has the same value as the default grpc.DefaultBackoffConfig. Note that
// grpc.DefaultBackoffConfig can actually change, but this won't.
//
// TODO: make backoff configurable.
defaultBackoffConfig = backoff.Config{
MaxDelay: 120 * time.Second,
BaseDelay: 1.0 * time.Second,
Factor: 1.6,
Jitter: 0.2,
}
)

func convertDuration(d *durationpb.Duration) time.Duration {
if d == nil {
return 0
Expand Down Expand Up @@ -147,7 +165,7 @@ func (b *lbBuilder) Build(cc balancer.ClientConn, opt balancer.BuildOptions) bal
scStates: make(map[balancer.SubConn]connectivity.State),
picker: &errPicker{err: balancer.ErrNoSubConnAvailable},
clientStats: newRPCStats(),
backoff: grpc.DefaultBackoffConfig, // TODO: make backoff configurable
backoff: defaultBackoffConfig, // TODO: make backoff configurable.
}

return lb
Expand All @@ -167,7 +185,7 @@ type lbBalancer struct {
// The ClientConn to talk to the remote balancer.
ccRemoteLB *grpc.ClientConn
// backoff for calling remote balancer.
backoff grpc.BackoffConfig
backoff backoff.Config

// Support client side load reporting. Each picker gets a reference to this,
// and will update its content.
Expand Down
2 changes: 1 addition & 1 deletion balancer/grpclb/grpclb_remote_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (lb *lbBalancer) watchRemoteBalancer() {
continue
}

timer := time.NewTimer(lb.backoff.backoff(retryCount))
timer := time.NewTimer(lb.backoff.Backoff(retryCount))
select {
case <-timer.C:
case <-lb.doneCh:
Expand Down

0 comments on commit 88c6170

Please sign in to comment.