Skip to content

Commit

Permalink
fix max voter check
Browse files Browse the repository at this point in the history
  • Loading branch information
egegunes committed Oct 30, 2024
1 parent b9ddc22 commit 82c2118
Show file tree
Hide file tree
Showing 2 changed files with 309 additions and 134 deletions.
59 changes: 33 additions & 26 deletions pkg/psmdb/mongo/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,35 +917,42 @@ func (m *ConfigMembers) SetVotes(compareWith ConfigMembers, unsafePSA bool) {
continue
}

if votes < MaxVotingMembers {
[]ConfigMember(*m)[i].Votes = 1
votes++

if !member.ArbiterOnly {
lastVoteIdx = i
// In unsafe PSA (Primary with a Secondary and an Arbiter),
// we are unable to set the votes and the priority simultaneously.
// Therefore, setting only the votes.
if !unsafePSA || member.Votes == 1 {
priority := DefaultPriority
if c, ok := cm[member.Host]; ok {
priority = c
}

// Priority can be any number in range [0,1000].
// We're setting it to 2 as default, to allow
// users to configure external nodes with lower
// priority than local nodes.
[]ConfigMember(*m)[i].Priority = priority
}
}
} else if member.ArbiterOnly {
if member.ArbiterOnly {
// Arbiter should always have a vote
[]ConfigMember(*m)[i].Votes = 1
// Arbiter should never have priority
[]ConfigMember(*m)[i].Priority = 0
} else {
[]ConfigMember(*m)[i].Votes = 1
lastVoteIdx = i

// In unsafe PSA (Primary with a Secondary and an Arbiter),
// we are unable to set the votes and the priority simultaneously.
// Therefore, setting only the votes.
if !unsafePSA || member.Votes == 1 {
// Priority can be any number in range [0,1000].
// We're setting it to 2 as default, to allow
// users to configure external nodes with lower
// priority than local nodes.
priority := DefaultPriority

if c, ok := cm[member.Host]; ok {
priority = c
}

// We're over the max voters limit. Make room for the arbiter
[]ConfigMember(*m)[lastVoteIdx].Votes = 0
[]ConfigMember(*m)[lastVoteIdx].Priority = 0
[]ConfigMember(*m)[i].Priority = priority
}
}
votes++

if votes > MaxVotingMembers {
if member.ArbiterOnly {
[]ConfigMember(*m)[lastVoteIdx].Votes = 0
[]ConfigMember(*m)[lastVoteIdx].Priority = 0
} else {
[]ConfigMember(*m)[i].Votes = 0
[]ConfigMember(*m)[i].Priority = 0
}
}
}

Expand Down
Loading

0 comments on commit 82c2118

Please sign in to comment.