Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-4808

"Updating stale electionId and setVersion" even when electionId/setVersion match

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.23.0
    • Affects Version/s: 2.22.0
    • Component/s: SDAM
    • Labels:
      None
    • Not Needed
    • Hide

      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?

      Show
      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?

      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));
      

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: