[SERVER-13539] Update setVersion number on primary and secondary changes Created: 10/Apr/14  Updated: 10/Dec/14  Resolved: 10/Apr/14

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: 2.4.10, 2.6.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Christian Amor Kvalheim Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

Currently setVersion only gets updated when adding or removing servers from the set. It should update when the state of servers change aswell in the state particularly when a new primary is elected.

Currently if your are querying a replicaset it's impossible to properly detect if a new primary got elected as server 1 might respond with the new primary but server 2 shows the old. The driver cannot reason which one is correct potentially causing flip-flops.

Increasing the setVersion on these changes would make it super easy to reason about the correct state as it would be possible to know which "topology" is the newest.



 Comments   
Comment by Scott Hernandez (Inactive) [ 10/Apr/14 ]

The setVersion is the replica set config version, and is used to detect the most up-to-date set of hosts from isMaster:

> db.isMaster()
{
	"setName" : "test7",
	"setVersion" : 1,
	"ismaster" : true,
	"secondary" : false,
	"hosts" : [
		"pans.local:27017"
	],
	"primary" : "pans.local:27017",
	"me" : "pans.local:27017",
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 1000,
	"localTime" : ISODate("2014-04-10T11:18:24.922Z"),
	"maxWireVersion" : 2,
	"minWireVersion" : 0,
	"ok" : 1
}
> var c = rs.conf()
> c.version++
> rs.reconfig(c)
{ "ok" : 1 }
> db.isMaster()
{
	"setName" : "test7",
	"setVersion" : 2,
	"ismaster" : true,
	"secondary" : false,
	"hosts" : [
		"pans.local:27017"
	],
	"primary" : "pans.local:27017",
	"me" : "pans.local:27017",
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 1000,
	"localTime" : ISODate("2014-04-10T11:18:54.346Z"),
	"maxWireVersion" : 2,
	"minWireVersion" : 0,
	"ok" : 1
} 

It is not meant to be used to detect the current primary, or member states, just the configuration version.

If you want a new indicator for when election events happen that would be a new thing. We do have something like this in sharding already. Please create a new issue for that request so it will be clear.

Generated at Thu Feb 08 03:32:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.