Skip to content

Commit 322f3c0

Browse files
wangshao1wuxianrong
authored andcommitted
cherry-pick 4
1 parent 6706c9d commit 322f3c0

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

codis/pkg/topom/topom_group.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,11 @@ func (s *Topom) tryFixReplicationRelationship(group *models.Group, groupServer *
381381
}
382382
}
383383
} else {
384-
// skip if it has right replication relationship
385-
if state.Replication.GetMasterAddr() == curMasterAddr {
386-
return nil
387-
}
388-
389-
// current server is slave, execute the command `slaveof [new master ip] [new master port] force`
390-
if err = updateMasterToNewOneForcefully(groupServer.Addr, curMasterAddr, s.config.ProductAuth); err != nil {
391-
return err
384+
if state.Replication.GetMasterAddr() != curMasterAddr {
385+
// current server is slave, execute the command `slaveof [new master ip] [new master port]`
386+
if err = updateMasterToNewOne(groupServer.Addr, curMasterAddr, s.config.ProductAuth); err != nil {
387+
return err
388+
}
392389
}
393390
}
394391

codis/pkg/topom/topom_sentinel.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ func (s *Topom) checkAndUpdateGroupServerState(conf *Config, group *models.Group
8585
*recoveredGroupServers = append(*recoveredGroupServers, state)
8686
// update GroupServer to GroupServerStateNormal state later
8787
} else {
88+
// This may contains any of following condition:
89+
// 1. groupServer.State is Normal
90+
// 2. groupServer.State is GroupServerStateSubjectiveOffline and is Master
91+
// 3. groupServer.State is GroupServerStateSubjectiveOffline and is Slave
92+
// for condition 3, if current server's previous state is SubjectiveOffline
93+
// and has been added to slaveofflinegroups before,
94+
// should also resync mappings to proxy to enable replicationgroup
95+
if groupServer.State == models.GroupServerStateSubjectiveOffline &&
96+
!isGroupMaster(state, group) &&
97+
group.OutOfSync {
98+
*recoveredGroupServers = append(*recoveredGroupServers, state)
99+
}
88100
// Update the offset information of the state and role nodes
89101
groupServer.State = models.GroupServerStateNormal
90102
groupServer.ReCallTimes = 0

codis/pkg/utils/redis/sentinel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func (i *InfoReplication) UnmarshalJSON(b []byte) error {
106106
}
107107

108108
i.Role = kvmap["role"]
109-
i.MasterPort = kvmap["master_host"]
110-
i.MasterHost = kvmap["master_port"]
109+
i.MasterPort = kvmap["master_port"]
110+
i.MasterHost = kvmap["master_host"]
111111
i.MasterLinkStatus = kvmap["master_link_status"]
112112
i.IsEligibleForMasterElection = kvmap["is_eligible_for_master_election"] == "true"
113113

0 commit comments

Comments
 (0)