[CSHARP-4808] "Updating stale electionId and setVersion" even when electionId/setVersion match Created: 11/Oct/23  Updated: 28/Oct/23  Resolved: 18/Oct/23

Status: Closed
Project: C# Driver
Component/s: SDAM
Affects Version/s: 2.22.0
Fix Version/s: 2.23.0

Type: Bug Priority: Minor - P4
Reporter: James Kovacs Assignee: Boris Dogadov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

SDAM logs show the following every time a heartbeat is processed even when the cluster topology hasn't changed:

ongoDB-SDAM Information: 509 : {type: "SdamInformationEvent", message: "Updating stale electionId and setVersion: Updating the current (maxSetVersion, maxElectionId) tuple from (18, 7fffffff0000000000000003) to (18, 7fffffff0000000000000003) for replica set "atlas-o9yrji-shard-0" because replica set primary Unspecified/pl-0-us-east-1.ssvpo.mongodb.net:1025 sent (18, 7fffffff0000000000000003)—a larger (setVersion, electionId) tuple then the saved tuple, (18, 7fffffff0000000000000003)." }

This is due to a bug in ElectionInfo.Equals performing object comparison semantics rather than value comparison semantics. MultiServerCluster.cs line 379 contains the line:

if (!_maxElectionInfo.Equals(newMaxElectionInfo))

MultiServerCluster.ElectionInfo implements Equals as follows:

public override bool Equals(object obj)
{
    var other = obj as ElectionInfo;
                                                                                               
    return other != null && _setVersion == other.SetVersion && other.ElectionId == _electionId;
}

Note that ElectionId is an object type and thus performs object comparison semantics. The following program always returns false even when electionId and setVersion are identical because the ElectionId objects are not the same object.

var setVersion1 = 42;
var objectId1 = ObjectId.GenerateNewId();
var electionInfo1 = new ElectionInfo(setVersion1, new ElectionId(objectId1));
var electionInfo2 = new ElectionInfo(setVersion1, new ElectionId(objectId1));
Console.WriteLine(electionInfo1.Equals(electionInfo2));



 Comments   
Comment by Githook User [ 18/Oct/23 ]

Author:

{'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}

Message: CSHARP-4808: "Updating stale electionId and setVersion" even when electionId/setVersion match (#1201)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/6f5b3d2de7abc203edf886b48f5fbc99223089fc

Generated at Wed Feb 07 21:49:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.