Skip to content

Commit

Permalink
fix(redis): DBHA探测超时太久 #8638
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepaup authored and iSecloud committed Dec 16, 2024
1 parent 51e9ff5 commit cecc8a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
16 changes: 12 additions & 4 deletions dbm-services/common/dbha/ha-module/client/redis_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (r *RedisClient) InitCluster(addr string, passwd string, timeout int) {
DialTimeout: timeoutVal,
ReadTimeout: timeoutVal,
WriteTimeout: timeoutVal,

// disable retry.
MaxRedirects: -1,
MaxRetries: -1,
})
r.mode = RedisCluster
return
Expand All @@ -45,12 +49,16 @@ func (r *RedisClient) InitCluster(addr string, passwd string, timeout int) {
func (r *RedisClient) Init(addr string, passwd string, timeout int, dbnum int) {
timeoutVal := time.Duration(timeout) * time.Second
r.rdb = redis.NewClient(&redis.Options{
Addr: addr,
Password: passwd,
DB: dbnum,
DialTimeout: timeoutVal,
Addr: addr,
Password: passwd,
DB: dbnum,

// Dial timeout for establishing new connections. Default is 5 seconds.
// DialTimeout: timeoutVal,
ReadTimeout: timeoutVal,
WriteTimeout: timeoutVal,
// Default is 3 retries; -1 (not 0) disables retries.
MaxRetries: -1,
})
r.mode = RedisInstance
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ type RedisProxySwitchInfo struct {
// CheckSSH redis do ssh check
func (ins *RedisDetectBase) CheckSSH() error {
sshStart := time.Now().Unix()
defer log.Logger.Debugf("finish ssh detect [%s] , cost: %d", ins.Ip, time.Now().Unix()-sshStart)
touchFile := fmt.Sprintf("%s_%s_%d", ins.SshInfo.Dest, "agent", ins.Port)

touchStr := fmt.Sprintf("touch %s && if [ -d \"/data1/dbha\" ]; then touch /data1/dbha/%s ; fi "+
"&& if [ -d \"/data/dbha\" ]; then touch /data/dbha/%s ; fi", touchFile, touchFile, touchFile)

if err := ins.DoExtendSSH(touchStr); err != nil {
log.Logger.Errorf("RedisDetection do ssh failed. err:%s", err.Error())
log.Logger.Errorf("do ssh failed[%s], cost: %d. err:%s", ins.Ip, time.Now().Unix()-sshStart, err.Error())
return err
}
return nil
Expand Down

0 comments on commit cecc8a2

Please sign in to comment.