[SERVER-32233] NewPrimaryWithMaxElectionId test should ensure that electionId is newer every iteration Created: 08/Dec/17  Updated: 30/Oct/23  Resolved: 14/Feb/18

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 3.6.0
Fix Version/s: 3.7.3

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Randolph Tan
Resolution: Fixed Votes: 1
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2017-12-30 at 10.17.08 AM.png     PNG File Screen Shot 2018-01-24 at 1.29.29 AM.png    
Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:
Linked BF Score: 0

 Description   

Test should make sure that OID generated here is increasing for every iteration:

https://github.com/mongodb/mongo/blob/r3.7.0/src/mongo/client/replica_set_monitor_test.cpp#L1013



 Comments   
Comment by Githook User [ 14/Feb/18 ]

Author:

{'email': 'cramaechi@me.com', 'name': 'Chibuikem Amaechi', 'username': 'cramaechi'}

Message: SERVER-32233 Ensure electionId is increasing per iteration

NewPrimaryWithMaxElectionId test should ensure that electionId is newer
every iteration.

The problem is that the test assumes that OID generated per iteration is
increasing. And this assumption is based on the fact that OID::gen
constructs a value based on the return value from time(). However, there
is no guarantee that time() will consistently be returning values that
increases over time.

Use OID::fromTerm() in place of OID::gen().

Closes #1207

Signed-off-by: Randolph Tan <randolph@10gen.com>
Branch: master
https://github.com/mongodb/mongo/commit/538354fddd70b3b2de8ea13f2f8dec72c973db87

Comment by Chibuikem Amaechi [ 24/Jan/18 ]

Hi Randolph,

Thanks for the clarification. In that case, I propose we use OID::fromTerm() in place of OID::gen() to ensure that electionId is increasing per iteration. As the integer value that is passed to OID::fromTerm() increases due to the for-loop, so does the underlying data of the OID object that is returned.

Comment by Randolph Tan [ 23/Jan/18 ]

cramaechi Thanks for sharing. However, this does not fix the underlying issue. The problem is that the test assumes that OID generated per iteration is increasing. And this assumption is based on the fact that OID::gen constructs a value based on the return value from time(). However, there is no guarantee that time() will consistently be returning values that increases over time.

Comment by Chibuikem Amaechi [ 30/Dec/17 ]

As mentioned above, there are currently no checks in place to ensure that a new electionId is generated for every iteration of the for-loop. My proposed change would be to declare an OID variable named nextOID and a string variable named prevOID outside the for-loop, and then maintain them inside the for-loop so that a less-than comparison between prevOID and nextOID.toString() can be passed to an ASSERT macro for processing.

ex.

src/mongo/client/replica_set_monitor_test.cpp

Please share your thoughts.

Generated at Thu Feb 08 04:29:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.