Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hard code of failing timeout #2928

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions options.go
Expand Up @@ -147,6 +147,9 @@ type Options struct {

// Add suffix to client name. Default is empty.
IdentitySuffix string

// Failing time limit for a node. Default is 15 seconds.
FailingTimeLimit int
}

func (opt *Options) init() {
Expand Down
10 changes: 9 additions & 1 deletion osscluster.go
Expand Up @@ -89,6 +89,8 @@ type ClusterOptions struct {
DisableIndentity bool // Disable set-lib on connect. Default is false.

IdentitySuffix string // Add suffix to client name. Default is empty.

FailingTimeLimit int // Failing time limit for a node. Default is 15 seconds.
}

func (opt *ClusterOptions) init() {
Expand Down Expand Up @@ -138,6 +140,10 @@ func (opt *ClusterOptions) init() {
if opt.NewClient == nil {
opt.NewClient = NewClient
}

if opt.FailingTimeLimit == 0 {
opt.FailingTimeLimit = 15
}
}

// ParseClusterURL parses a URL into ClusterOptions that can be used to connect to Redis.
Expand Down Expand Up @@ -242,6 +248,7 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er
o.PoolTimeout = q.duration("pool_timeout")
o.ConnMaxLifetime = q.duration("conn_max_lifetime")
o.ConnMaxIdleTime = q.duration("conn_max_idle_time")
o.FailingTimeLimit = q.int("failing_time_limit")

if q.err != nil {
return nil, q.err
Expand Down Expand Up @@ -296,6 +303,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
ConnMaxLifetime: opt.ConnMaxLifetime,
DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
FailingTimeLimit: opt.FailingTimeLimit,
TLSConfig: opt.TLSConfig,
// If ClusterSlots is populated, then we probably have an artificial
// cluster whose nodes are not in clustering mode (otherwise there isn't
Expand Down Expand Up @@ -376,7 +384,7 @@ func (n *clusterNode) MarkAsFailing() {
}

func (n *clusterNode) Failing() bool {
const timeout = 15 // 15 seconds
timeout := int64(n.Client.opt.FailingTimeLimit)

failing := atomic.LoadUint32(&n.failing)
if failing == 0 {
Expand Down