Skip to content

Commit

Permalink
feat(redis): redis强制重建slave同步关系 #7135
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemakeit authored and zhangzhw8 committed Oct 8, 2024
1 parent 25a573b commit a84f9ea
Show file tree
Hide file tree
Showing 9 changed files with 559 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### redis_replicas_force_resync
redis slave 强制重同步.


```
./dbactuator_redis --uid={{uid}} --root_id={{root_id}} --node_id={{node_id}} --version_id={{version_id}} --atom-job-list="redis_replicas_force_resync" --data_dir=/path/to/data --backup_dir=/path/to/backup --payload='{{payload_base64}}'
```

`--data_dir``--backup_dir` 可以留空.

原始payload
```json
{
"slave_ip":"xx.xx.xx.xx",
"slave_ports":[30000,30001]
}
```
30 changes: 30 additions & 0 deletions dbm-services/redis/db-tools/dbactuator/models/myredis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,36 @@ func (db *RedisClient) ClusterMeet(ip, port string) (ret string, err error) {
return
}

// ClusterMeetAndUtilFinish TODO
func (db *RedisClient) ClusterMeetAndUtilFinish(ip, port string) (err error) {
// 执行 cluster addslots 命令只能用 普通redis client
if db.InstanceClient == nil {
err = fmt.Errorf("ClusterMeetAndUtilFinish redis:%s must create a standalone client", db.Addr)
mylog.Logger.Error(err.Error())
return
}
mylog.Logger.Info("redis(%s) 'cluster meet %s %s' start", db.Addr, ip, port)
_, err = db.ClusterMeet(ip, port)
if err != nil {
return
}
targetAddr := fmt.Sprintf("%s:%s", ip, port)
var addrMapToNodes map[string]*ClusterNodeData
for {
addrMapToNodes, err = db.GetAddrMapToNodes()
if err != nil {
return
}
if _, ok := addrMapToNodes[targetAddr]; ok {
mylog.Logger.Info("redis:%s cluster meet %s %s success", db.Addr, ip, port)
break
}
mylog.Logger.Info("redis:%s cluster meet %s %s done,but not in 'cluster nodes'", db.Addr, ip, port)
time.Sleep(3 * time.Second)
}
return nil
}

// ClusterAddSlots 添加slots, 'cluster addslots 'command
func (db *RedisClient) ClusterAddSlots(slots []int) (ret string, err error) {
// 执行 cluster addslots 命令只能用 普通redis client
Expand Down
Loading

0 comments on commit a84f9ea

Please sign in to comment.