Secondary and primary can disagree on index build method

XMLWordPrintableJSON

    • ALL
    • Execution Team 2020-03-23
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      The two-phase index build code has an optimization to use single-phase builds on empty collections. In this case it (correctly) writes a "createIndexes" oplog entry instead of the "startIndexBuild"/"commitIndexBuild" pair. However, this optimization is bypassed on some occasions, in particular when moving the primary shard using the database cloner

      https://github.com/mongodb/mongo/blob/35a5d455672e65127a24e7cdb98ea1472124af4a/src/mongo/db/cloner.cpp#L405
      

      This results in a "startIndexBuild"/"commitIndexBuild" pair being written on the primary. However, when the secondary does the startIndexBuild, it will notice that the collection is empty and do a single-phase index build. When the commit is executed, it will see that no build is in progress, attempt to start one, and get an IndexAlreadyExists error.

      I believe the fix is ensuring that the secondary never applies the optimization for startIndexBuild; if the primary did a two-phase build, the secondary should as well.

            Assignee:
            Benety Goh
            Reporter:
            Matthew Russotto
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: