Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-13307

Improve majority (M) Explanation on Write Concern Doc Page

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 3.2 Required, 3.6 Required, 4.0 Required, 3.4 Required, 4.2 Required
    • None
    • Server
    • It affects all OS, Software Platforms and/or Hardwares

    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

       

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            diego.rodriguez@mongodb.com Diego Rodriguez (Inactive)
            Jess Mokrzecki Jess Mokrzecki
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              2 years, 38 weeks, 5 days ago