Skip to content

Commit

Permalink
feat(cluster): Add retry delay for the gRPC dial
Browse files Browse the repository at this point in the history
  • Loading branch information
hueypark committed Mar 28, 2023
1 parent 03baa9b commit ba58073
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (c *cluster) establishNewConnection(host string) (*grpc.ClientConn, error)
)
},
retry.WithRetryCount(c.options.ConnectRetryCount),
retry.WithDelay(c.options.ConnectRetryDelay),
)
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions cluster/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ type Options struct {
// ConnectRetryCount specifies the maximum number of retries to connect to other nodes.
ConnectRetryCount int `default:"10"`

// ConnectRetryDelay specifies the delay between retries to connect to other nodes.
ConnectRetryDelay time.Duration `default:"200ms"`

// MaxMessageSize specifies the maximum message size in bytes the gRPC client can receive/send.
// The default value is 500mb.
MaxMessageSize int `default:"524288000"`
Expand Down
11 changes: 11 additions & 0 deletions pkg/retry/option.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package retry

import "time"

type option struct {
maxRetryCount int
delay time.Duration
}

func defaultOption() option {
return option{
maxRetryCount: 3,
delay: 200 * time.Millisecond,
}
}

Expand All @@ -19,3 +23,10 @@ func WithRetryCount(count int) OptionFunc {
o.maxRetryCount = count
}
}

// WithDelay sets the delay between retries.
func WithDelay(delay time.Duration) OptionFunc {
return func(o *option) {
o.delay = delay
}
}

0 comments on commit ba58073

Please sign in to comment.