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 13, 2018
1 parent 617c849 commit bbab2cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 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,19 @@ 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.
//
// TODO: make backoff configurable.
defaultBackoffConfig = backoff.Exponential{
MaxDelay: 120 * time.Second,
}
)

func convertDuration(d *durationpb.Duration) time.Duration {
if d == nil {
return 0
Expand Down Expand Up @@ -147,7 +161,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 +181,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.Strategy

// 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 bbab2cc

Please sign in to comment.