Skip to content

Commit

Permalink
refactor:rename defaultMaxRetryAttempts
Browse files Browse the repository at this point in the history
  • Loading branch information
No-SilverBullet committed Jul 4, 2024
1 parent 0fa5e9e commit 96adebd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
7 changes: 2 additions & 5 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ func NewClient(target string, opts ...DialOption) (conn *ClientConn, err error)
}

if cc.dopts.defaultServiceConfigRawJSON != nil {
if cc.dopts.maxCallAttempts == 0 {
cc.dopts.maxCallAttempts = defaultMaxCallAttempts
}
scpr := parseServiceConfig(*cc.dopts.defaultServiceConfigRawJSON, cc.dopts.maxCallAttempts)
scpr := parseServiceConfig(*cc.dopts.defaultServiceConfigRawJSON, cc.dopts.maxRetryAttempts)
if scpr.Err != nil {
return nil, fmt.Errorf("%s: %v", invalidDefaultServiceConfigErrPrefix, scpr.Err)
}
Expand Down Expand Up @@ -699,7 +696,7 @@ func (cc *ClientConn) waitForResolvedAddrs(ctx context.Context) error {
var emptyServiceConfig *ServiceConfig

func init() {
cfg := parseServiceConfig("{}", defaultMaxCallAttempts)
cfg := parseServiceConfig("{}", defaultMaxRetryAttempts)
if cfg.Err != nil {
panic(fmt.Sprintf("impossible error parsing empty service config: %v", cfg.Err))
}
Expand Down
20 changes: 10 additions & 10 deletions dialoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

const (
// https://github.com/grpc/proposal/blob/master/A6-client-retries.md#limits-on-retries-and-hedges
defaultMaxCallAttempts = 5
defaultMaxRetryAttempts = 5
)

func init() {
Expand Down Expand Up @@ -94,7 +94,7 @@ type dialOptions struct {
idleTimeout time.Duration
recvBufferPool SharedBufferPool
defaultScheme string
maxCallAttempts int
maxRetryAttempts int
}

// DialOption configures how we set up the connection.
Expand Down Expand Up @@ -678,12 +678,12 @@ func defaultDialOptions() dialOptions {
UseProxy: true,
UserAgent: grpcUA,
},
bs: internalbackoff.DefaultExponential,
healthCheckFunc: internal.HealthCheckFunc,
idleTimeout: 30 * time.Minute,
recvBufferPool: nopBufferPool{},
defaultScheme: "dns",
maxCallAttempts: defaultMaxCallAttempts,
bs: internalbackoff.DefaultExponential,
healthCheckFunc: internal.HealthCheckFunc,
idleTimeout: 30 * time.Minute,
recvBufferPool: nopBufferPool{},
defaultScheme: "dns",
maxRetryAttempts: defaultMaxRetryAttempts,
}
}

Expand Down Expand Up @@ -752,9 +752,9 @@ func WithIdleTimeout(d time.Duration) DialOption {
func WithMaxCallAttempts(n int) DialOption {
return newFuncDialOption(func(o *dialOptions) {
if n < 2 {
n = defaultMaxCallAttempts
n = defaultMaxRetryAttempts
}
o.maxCallAttempts = n
o.maxRetryAttempts = n
})
}

Expand Down
2 changes: 1 addition & 1 deletion resolver_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (ccr *ccResolverWrapper) NewAddress(addrs []resolver.Address) {
// ParseServiceConfig is called by resolver implementations to parse a JSON
// representation of the service config.
func (ccr *ccResolverWrapper) ParseServiceConfig(scJSON string) *serviceconfig.ParseResult {
return parseServiceConfig(scJSON, ccr.cc.dopts.maxCallAttempts)
return parseServiceConfig(scJSON, ccr.cc.dopts.maxRetryAttempts)
}

// addChannelzTraceEvent adds a channelz trace event containing the new
Expand Down
2 changes: 1 addition & 1 deletion service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ type jsonSC struct {

func init() {
internal.ParseServiceConfig = func(js string) *serviceconfig.ParseResult {
return parseServiceConfig(js, defaultMaxCallAttempts)
return parseServiceConfig(js, defaultMaxRetryAttempts)
}
}
func parseServiceConfig(js string, maxAttempts int) *serviceconfig.ParseResult {
Expand Down
2 changes: 1 addition & 1 deletion service_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func runParseTests(t *testing.T, testCases []parseTestCase) {
t.Helper()
for i, c := range testCases {
t.Run(fmt.Sprint(i), func(t *testing.T) {
scpr := parseServiceConfig(c.scjs, defaultMaxCallAttempts)
scpr := parseServiceConfig(c.scjs, defaultMaxRetryAttempts)
var sc *ServiceConfig
sc, _ = scpr.Config.(*ServiceConfig)
if !c.wantErr {
Expand Down

0 comments on commit 96adebd

Please sign in to comment.