Skip to content

Commit 0ee537f

Browse files
committed
topom: option sentinel_client_timeout
1 parent e0e0a10 commit 0ee537f

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

config/dashboard.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ migration_async_numkeys = 500
2828
migration_timeout = "30s"
2929

3030
# Set configs for redis sentinel.
31+
sentinel_client_timeout = "10s"
3132
sentinel_quorum = 2
3233
sentinel_parallel_syncs = 1
3334
sentinel_down_after = "30s"

pkg/topom/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ migration_async_numkeys = 500
4545
migration_timeout = "30s"
4646
4747
# Set configs for redis sentinel.
48+
sentinel_client_timeout = "10s"
4849
sentinel_quorum = 2
4950
sentinel_parallel_syncs = 1
5051
sentinel_down_after = "30s"
@@ -71,6 +72,7 @@ type Config struct {
7172
MigrationAsyncNumKeys int `toml:"migration_async_numkeys" json:"migration_async_numkeys"`
7273
MigrationTimeout timesize.Duration `toml:"migration_timeout" json:"migration_timeout"`
7374

75+
SentinelClientTimeout timesize.Duration `toml:"sentinel_client_timeout" json:"sentinel_client_timeout"`
7476
SentinelQuorum int `toml:"sentinel_quorum" json:"sentinel_quorum"`
7577
SentinelParallelSyncs int `toml:"sentinel_parallel_syncs" json:"sentinel_parallel_syncs"`
7678
SentinelDownAfter timesize.Duration `toml:"sentinel_down_after" json:"sentinel_down_after"`
@@ -137,6 +139,9 @@ func (c *Config) Validate() error {
137139
if c.MigrationTimeout <= 0 {
138140
return errors.New("invalid migration_timeout")
139141
}
142+
if c.SentinelClientTimeout <= 0 {
143+
return errors.New("invalid sentinel_client_timeout")
144+
}
140145
if c.SentinelQuorum <= 0 {
141146
return errors.New("invalid sentinel_quorum")
142147
}

pkg/topom/topom_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ func (s *apiServer) InfoSentinelMonitored(params martini.Params) (int, string) {
546546
return rpc.ApiResponseError(err)
547547
}
548548
sentinel := redis.NewSentinel(s.topom.Config().ProductName, s.topom.Config().ProductAuth)
549-
if info, err := sentinel.MastersAndSlaves(addr, time.Second); err != nil {
549+
if info, err := sentinel.MastersAndSlaves(addr, s.topom.Config().SentinelClientTimeout.Duration()); err != nil {
550550
return rpc.ApiResponseError(err)
551551
} else {
552552
return rpc.ApiResponseJson(info)

pkg/topom/topom_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func (s *Topom) GroupPromoteServer(gid int, addr string) error {
275275
}
276276
groupIds := map[int]bool{g.Id: true}
277277
sentinel := redis.NewSentinel(s.config.ProductName, s.config.ProductAuth)
278-
if err := sentinel.RemoveGroups(p.Servers, time.Second*5, groupIds); err != nil {
278+
if err := sentinel.RemoveGroups(p.Servers, s.config.SentinelClientTimeout.Duration(), groupIds); err != nil {
279279
log.WarnErrorf(err, "group-[%d] remove sentinels failed", g.Id)
280280
}
281281
if s.ha.masters != nil {

pkg/topom/topom_sentinel.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (s *Topom) AddSentinel(addr string) error {
3434
}
3535

3636
sentinel := redis.NewSentinel(s.config.ProductName, s.config.ProductAuth)
37-
if err := sentinel.FlushConfig(addr, time.Second*5); err != nil {
37+
if err := sentinel.FlushConfig(addr, s.config.SentinelClientTimeout.Duration()); err != nil {
3838
return err
3939
}
4040
defer s.dirtySentinelCache()
@@ -74,7 +74,7 @@ func (s *Topom) DelSentinel(addr string, force bool) error {
7474
}
7575

7676
sentinel := redis.NewSentinel(s.config.ProductName, s.config.ProductAuth)
77-
if err := sentinel.RemoveGroupsAll([]string{addr}, time.Second*5); err != nil {
77+
if err := sentinel.RemoveGroupsAll([]string{addr}, s.config.SentinelClientTimeout.Duration()); err != nil {
7878
log.WarnErrorf(err, "remove sentinel %s failed", addr)
7979
if !force {
8080
return errors.Errorf("remove sentinel %s failed", addr)
@@ -194,10 +194,10 @@ func (s *Topom) ResyncSentinels() error {
194194
}
195195

196196
sentinel := redis.NewSentinel(s.config.ProductName, s.config.ProductAuth)
197-
if err := sentinel.RemoveGroupsAll(p.Servers, time.Second*5); err != nil {
197+
if err := sentinel.RemoveGroupsAll(p.Servers, s.config.SentinelClientTimeout.Duration()); err != nil {
198198
log.WarnErrorf(err, "remove sentinels failed")
199199
}
200-
if err := sentinel.MonitorGroups(p.Servers, time.Second*5, config, ctx.getGroupMasters()); err != nil {
200+
if err := sentinel.MonitorGroups(p.Servers, s.config.SentinelClientTimeout.Duration(), config, ctx.getGroupMasters()); err != nil {
201201
log.WarnErrorf(err, "resync sentinels failed")
202202
return err
203203
}

0 commit comments

Comments
 (0)