[DOCS-13307] Improve majority (M) Explanation on Write Concern Doc Page Created: 18/Dec/19  Updated: 30/Oct/23  Resolved: 08/Jan/20

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: 3.2 Required, 3.6 Required, 4.0 Required, 3.4 Required, 4.2 Required
Fix Version/s: Server_Docs_20231030

Type: Improvement Priority: Major - P3
Reporter: Diego Rodriguez (Inactive) Assignee: Kay Kim (Inactive)
Resolution: Fixed Votes: 0
Labels: majority, writeconcern
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

It affects all OS, Software Platforms and/or Hardwares


Participants:
Days since reply: 3 years, 40 weeks, 1 day ago
Epic Link: DOCSP-1769

 Description   

Description

The documentation on “Write Concern” is missing some edge cases when it comes to “writeMajorityCount”. The documentation says:

The majority (M) is calculated as the majority of all voting members. As such, even if a replica set with 3 voting members is a Primary-Secondary-Arbiter (P-S-A), the majority (M) is two. However, since the write can only be applied to data-bearing members, the write must propagate to the primary and the secondary to acknowledge the write concern to the client.

 

 

This can be found at the end of following documentation pages:

 

Version 3.2 documentation page doesn’t have the same saying but the same seems to apply:

 

If we look through line 779 to 787 in the code at https://github.com/mongodb/mongo/blob/master/src/mongo/db/repl/repl_set_config.cpp_, it uses a formula that considers (voters - arbiters) as writeMajority in case that number is less than the _majorityVoteCount:

 

_majorityVoteCount = voters / 2 + 1;
writeMajority = std::min(_majorityVoteCount, voters - arbiters);

 

 

The documentation on Write Concern should describe precisely how “writeMajorityCount” is calculated, making explicit mention to the formula used in the code that makes it clear and non ambiguous. Wherever the explanation for majority (M) appears on the previously mentioned documentation pages (or any other that I might be missing), it should say:

 

 

The majority (M) is calculated as the majority of all voting members, but the write operation returns acknowledgement after propagating to M-number of data-bearing voting members (primary and secondaries with members[n].votes greater than 0). If the amount of data-bearing voting members is less than the majority of all voting members, then w: "majority" number is the result of (#voters - #arbiters). As such, the general formula for calculating w: "majority" is:
  majority = min(majorityVoteCount, #voters - #arbiters);

 

 

I have tested the following scenarios which support and confirm that the previously mentioned formula is used:

Scenario 1: 7 Node Replica Set (3 Data Bearing Nodes, 4 Arbiters)

  • majorityVoteCount is 4
  • writeMajorityCount is 3
    • Because (voters - arbiters = 3) which is less than majorityVoteCount

Scenario 2: 3 Node Replica Set (1 Data Bearing Node, 2 Arbiters)

  • majorityVoteCount is 2
  • writeMajorityCount is 1
  • Because (voters - arbiters = 1) which is less than majorityVoteCount

Scenario 3: Typical PSA

  • majorityVoteCount is 2
  • writeMajorityCount is 2
  • Because (voters - arbiters = 2) which is equal to majorityVoteCount so the std::min function returns the first value (majorityVoteCount)

 

Regards
Diego

 



 Comments   
Comment by Githook User [ 05/May/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: missed two sentences referring to old majority calculations
Branch: v3.4
https://github.com/mongodb/docs/commit/d11bd4450954fedf5396d65ad5d958735e0d1d15

Comment by Githook User [ 05/May/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: missed two sentences referring to old majority calculations
Branch: v3.6
https://github.com/mongodb/docs/commit/c5c594752d99b09bc13ff3048e2c285817ba571e

Comment by Githook User [ 05/May/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: missed two sentences referring to old majority calculations
Branch: v4.0
https://github.com/mongodb/docs/commit/df0e3cdec4ab398bd1a1d2696c3c5e08fc267618

Comment by Githook User [ 05/May/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: missed two sentences referring to old majority calculations
Branch: v4.2
https://github.com/mongodb/docs/commit/ce021b00e0a4c47c4dec50aebc4bae44e5cc01b3

Comment by Githook User [ 05/May/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: missed two sentences referring to old majority calculations
Branch: master
https://github.com/mongodb/docs/commit/9519c68c148e62a6090ae0702a2aeeda1e04b2e6

Comment by Githook User [ 06/Jan/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: wc majority calculation
Branch: v3.2
https://github.com/mongodb/docs/commit/da90f9a3c326e686544b7b80df6b0692a828deb7

Comment by Githook User [ 06/Jan/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: wc majority calculation
Branch: v3.4
https://github.com/mongodb/docs/commit/ab51b255914e725dd72ce7fa6ef7492ab67a5c0c

Comment by Githook User [ 06/Jan/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: wc majority calculation
Branch: v3.6
https://github.com/mongodb/docs/commit/a9ca355345e026f10c079ae51a5c176e37a23ecf

Comment by Githook User [ 06/Jan/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: wc majority calculation
Branch: v4.0
https://github.com/mongodb/docs/commit/77709f2753b0fde0a8fbd4cad69b30e63a3b7e7d

Comment by Githook User [ 06/Jan/20 ]

Author:

{'name': 'Kay Kim', 'email': 'kay.kim@10gen.com', 'username': 'kay-kim'}

Message: DOCS-13307: wc majority calculation
Branch: master
https://github.com/mongodb/docs/commit/a51bc16180a76628920cb415995dd38c030f5a2a

Comment by Arnie Listhaus [ 18/Dec/19 ]

My thoughts are that we should somehow convey an accurate description of the algorithm.  However, in addition we should convey the dangers of of having a topology that requires all data bearing members to be available.  For example: 

In environments with multiple arbiters (not recommended), the majority write concern will at most require acknowledgement from all of the data bearing nodes .

We do not recommend using write concern majority in deployments where the majority would require all of the data nodes to acknowledge writes (as in the case of a PSA deployment).  This type of environment could lead to writes that are either never acknowledged or that timeout when/if a data bearing member is down or unreachable (network partition) and that would defeat the ability to provide high availability which is one of the major benefits of using replica sets.

 

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