[SERVER-40363] Change type of "_id" field of replica set config to be different from that of the member index Created: 27/Mar/19  Updated: 29/Oct/23  Resolved: 25/Jun/19

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 4.2.0-rc2, 4.3.1

Type: New Feature Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Allison Easton
Resolution: Fixed Votes: 0
Labels: former-quick-wins, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
is related to SERVER-40355 rs.config that contains an _id greate... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.2
Sprint: Repl 2019-06-03, Repl 2019-06-17, Repl 2019-07-01
Participants:

 Description   

Original Description:

Replica set config documents look like:

{
   _id: 'rs name',
   members: [
      {_id: 0, host: 'host1:27017'},
      {_id: 1, host: 'host2:27017'}
   ]
}

The "_id" field in member subdocuments isn't useful in any way I know, but requires extra typing and it must be chosen to obey certain rules (it must be unique and between 0 and 255 inclusive). If we handle it incorrectly it can cause bugs (SERVER-40355). In summary, the _id field has cost but perhaps no benefit: uniqueness is provided by members' addresses and order is provided by their array position.

Let's consider deprecating _id, and eventually ignoring it completely.

New Description:
Since this has diagnostic value, we'd prefer to change the type of the "_id" field to avoid introducing bugs.



 Comments   
Comment by Githook User [ 03/Jul/19 ]

Author:

{'name': 'Allison Easton', 'email': 'allison.easton@mongodb.com'}

Message: SERVER-40363 Change type of "_id" field of replica set
config to be different from that of the member index

(cherry picked from commit f79258d26879f22cd407d1ce1bf90f365dfc78fe)
Branch: v4.2
https://github.com/mongodb/mongo/commit/0e1a8f17bfc9841a9d5882375817741eddb7b0b6

Comment by Githook User [ 25/Jun/19 ]

Author:

{'name': 'Allison Easton', 'email': 'allison.easton@mongodb.com'}

Message: SERVER-40363 Change type of "_id" field of replica set
config to be different from that of the member index
Branch: master
https://github.com/mongodb/mongo/commit/f79258d26879f22cd407d1ce1bf90f365dfc78fe

Comment by Samyukta Lanka [ 30/May/19 ]

We suggest creating a new class called MemberId and changing the type of _id as well as _memberId to be MemberId. This new class would have one variable for its value, so that we will still be able to store the id as an int, but we will no longer confuse the id and the node's index in the member's array (and we'd be able to catch such a mistake at compile time).

Comment by Judah Schvimer [ 28/Mar/19 ]

schwerin recommended making the _id a different type in the cpp code so that bugs like SERVER-40355 are impossible to introduce.

Comment by Bruce Lucas (Inactive) [ 28/Mar/19 ]

I think there's some diagnostic value to having an _id as a "short name" for a member that doesn't change as members are added to or removed from the replica set - it makes it easier to talk about the members.

Comment by Kevin Pulo [ 27/Mar/19 ]

Based on getMemberId() and setMemberId() in repl::MemberData, the main place that these ids seem to be used is in replSetUpdatePosition and heartbeats. Likely both can be converted to using index position/hostname as appropriate, but upgrade/downgrade means we'll need a transition period where both are accepted. There may be other places in the server which parse the members subdocs and use _id, I'm not sure.

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