Skip to content

Commit

Permalink
fixup boolean logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeeken committed Aug 12, 2022
1 parent d499242 commit 96a0b76
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/sdam/topology_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,17 @@ function updateRsFromPrimary(
const electionIdComparison = compareObjectId(maxElectionId, serverDescription.electionId);
const maxElectionIdIsEqual = electionIdComparison === 0;
const maxElectionIdIsLess = electionIdComparison === -1;
const maxSetVersionIsLessOrEqual = (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1);

const setVersionComparison = compareNumber(maxSetVersion, serverDescription.setVersion);
const maxSetVersionIsLess = setVersionComparison === -1;
const maxSetVersionIsEqual = setVersionComparison === 0;

if (
maxElectionIdIsLess ||
(maxElectionIdIsEqual && (maxSetVersionIsLess || maxSetVersionIsEqual))
) {
// We've seen a higher ElectionId! Update both!
// Or the electionId is the same but the setVersion increased
if (maxElectionIdIsLess || (maxElectionIdIsEqual && maxSetVersionIsLessOrEqual)) {
// The reported electionId was greater
// or the electionId was equal and reported setVersion was greater
// Always update both values, they are a tuple
maxElectionId = serverDescription.electionId;
maxSetVersion = serverDescription.setVersion;
} else {
// this primary is stale, we must remove it
// Stale primary
// replace serverDescription with a default ServerDescription of type "Unknown"
serverDescriptions.set(
serverDescription.address,
new ServerDescription(serverDescription.address)
Expand Down

0 comments on commit 96a0b76

Please sign in to comment.