Skip to content

Commit

Permalink
Optimize Replication with ack instruction processing and calculation …
Browse files Browse the repository at this point in the history
…of majority nodes, excluding only voting nodes
  • Loading branch information
snower committed Apr 26, 2024
1 parent f541f99 commit 4843b42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions server/arbiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,19 @@ func (self *ArbiterManager) GetMembers() []*ArbiterMember {
return self.members
}

func (self *ArbiterManager) GetMajorityMemberCount() int {
if self.members == nil || len(self.members) == 0 {
return 0
}
workCount := 0
for _, member := range self.members {
if member.arbiter == 0 {
workCount++
}
}
return workCount/2 + 1
}

func (self *ArbiterManager) QuitLeader() error {
self.slock.Log().Infof("Arbiter quit leader start")
err := self.slock.replicationManager.transparencyManager.ChangeLeader("")
Expand Down
6 changes: 3 additions & 3 deletions server/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,7 @@ func (self *ReplicationManager) addServerChannel(channel *ReplicationServer) err
self.serverCount = uint32(len(self.serverChannels))
ackCount := 0
if self.slock.arbiterManager != nil {
ackCount = len(self.slock.arbiterManager.GetMembers())/2 + 1
ackCount = self.slock.arbiterManager.GetMajorityMemberCount()
} else {
ackCount = len(self.serverChannels) + 1
}
Expand Down Expand Up @@ -1833,7 +1833,7 @@ func (self *ReplicationManager) GetOrNewAckDB(dbId uint8) *ReplicationAckDB {
if self.ackDbs[dbId] == nil {
ackCount := 0
if self.slock.arbiterManager != nil {
ackCount = len(self.slock.arbiterManager.GetMembers())/2 + 1
ackCount = self.slock.arbiterManager.GetMajorityMemberCount()
} else {
ackCount = len(self.serverChannels) + 1
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ func (self *ReplicationManager) SwitchToLeader() error {
self.leaderAddress = ""

if self.slock.arbiterManager != nil {
ackCount := len(self.slock.arbiterManager.GetMembers())/2 + 1
ackCount := self.slock.arbiterManager.GetMajorityMemberCount()
for _, db := range self.ackDbs {
if db != nil {
db.ackCount = uint8(ackCount)
Expand Down

0 comments on commit 4843b42

Please sign in to comment.