Skip to content

Commit fdcdd8f

Browse files
wangshao1wangshaoyi
andauthored
fix: tryFixReplicationRelationships error (#2991)
* fix invalid arguments error when dashboard send slveof force Co-authored-by: wangshaoyi <[email protected]>
1 parent f0704c3 commit fdcdd8f

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

codis/pkg/topom/topom_group.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (s *Topom) GroupPromoteServer(gid int, addr string) error {
330330
}
331331
}
332332

333-
func (s *Topom) tryFixReplicationRelationships(ctx *context, recoveredGroupServers []*redis.ReplicationState, masterOffGroupLen int) {
333+
func (s *Topom) tryFixReplicationRelationships(ctx *context, recoveredGroupServers []*redis.ReplicationState) {
334334
for _, state := range recoveredGroupServers {
335335
log.Infof("group-[%d] try to fix server[%v-%v] replication relationship", state.GroupID, state.Index, state.Addr)
336336
group, err := ctx.getGroup(state.GroupID)
@@ -346,7 +346,7 @@ func (s *Topom) tryFixReplicationRelationships(ctx *context, recoveredGroupServe
346346
continue
347347
}
348348

349-
err = s.tryFixReplicationRelationship(group, state.Server, state, masterOffGroupLen)
349+
err = s.tryFixReplicationRelationship(group, state.Server, state)
350350
if err != nil {
351351
log.Warnf("group-[%d] fix server[%v] replication relationship failed, err: %v", group.Id, state.Addr, err)
352352
continue
@@ -371,19 +371,14 @@ func (s *Topom) tryFixReplicationRelationships(ctx *context, recoveredGroupServe
371371
// only fix which the old state of GroupServer is GroupServerStateOffline.
372372
// It will only update the state of GroupServer to GroupServerStateNormal, If the GroupServer have right
373373
// master-slave replication relationship.
374-
func (s *Topom) tryFixReplicationRelationship(group *models.Group, groupServer *models.GroupServer, state *redis.ReplicationState, masterOffGroupLen int) (err error) {
374+
func (s *Topom) tryFixReplicationRelationship(group *models.Group, groupServer *models.GroupServer, state *redis.ReplicationState) (err error) {
375375
curMasterAddr := group.Servers[0].Addr
376376
if isGroupMaster(state, group) {
377-
// current server is master,
378-
if models.GroupServerRole(state.Replication.Role) == models.RoleMaster {
379-
if masterOffGroupLen > 0 {
380-
return nil
381-
}
382-
}
383-
384377
// execute the command `slaveof no one`
385-
if err = promoteServerToNewMaster(state.Addr, s.config.ProductAuth); err != nil {
386-
return err
378+
if models.GroupServerRole(state.Replication.Role) != models.RoleMaster {
379+
if err = promoteServerToNewMaster(state.Addr, s.config.ProductAuth); err != nil {
380+
return err
381+
}
387382
}
388383
} else {
389384
// skip if it has right replication relationship

codis/pkg/topom/topom_sentinel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *Topom) CheckStateAndSwitchSlavesAndMasters(filter func(index int, g *mo
4848

4949
if len(recoveredGroupServersState) > 0 {
5050
// offline GroupServer's service has recovered, check and fix it's master-slave replication relationship
51-
s.tryFixReplicationRelationships(ctx, recoveredGroupServersState, len(masterOfflineGroups))
51+
s.tryFixReplicationRelationships(ctx, recoveredGroupServersState)
5252
}
5353

5454
return nil

codis/pkg/utils/redis/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (c *Client) SetMaster(master string, force bool) error {
341341
}
342342

343343
if force {
344-
if _, err := c.Do("SLAVEOF", host, port, "-f"); err != nil {
344+
if _, err := c.Do("SLAVEOF", host, port, "force"); err != nil {
345345
return err
346346
}
347347
} else {

0 commit comments

Comments
 (0)