Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-60716

Remove out of order writes on unique, non _id indexes

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • ALL
    • Execution Team 2021-11-15

    Description

      Suppose the document being inserted into a collection is of the form:
      RecordId(1) -> X
      and the logical key/value being inserted into the index is of the form:
      KeyString(X) -> RecordId(1)

      WT (non _id) unique indexes will make writes to two keys:

      1. KeyString(X) + RecordId(1)
      2. KeyString(X)

      The first key is persisted (on a successful WT txn commit). The second key is deleted before committing. The purpose of the second key is to correctly maintain the unique index constraint in the face of concurrent transactions at snapshot isolation that can possibly observe write skew .

      For primaries this works fine. For secondaries, we can process oplog entries out of order. This has a consequence for the common key two separate inserts can touch. Consider the following oplog entries being applied to collection with a unique index on x:

      | Oplog                         |
      |-------------------------------|
      | Insert {_id: 1, x: 1} @ TS(1) |
      | Delete {_id: 1}       @ TS(2) |
      | Insert {_id: 2, x: 1} @ TS(3) |
      

      Those oplog entries can be applied with the following interleaving:

      | Applier 1                         | Applier 2                         |
      |-----------------------------------+-----------------------------------|
      |                                   | BeginTxn                          |
      |                                   | SetTimestamp 3                    |
      |                                   | Insert KeyString(1)               |
      |                                   | Delete KeyString(1)               |
      |                                   | Insert KeyString(1) + RecordId(2) |
      |                                   | Commit                            |
      |                                   |                                   |
      | BeginTxn                          |                                   |
      | SetTimestamp 1                    |                                   |
      | Insert KeyString(1)               |                                   |
      | Delete KeyString(1)               |                                   |
      | Insert KeyString(1) + RecordId(1) |                                   |
      | Commit                            |                                   |
      

      Attachments

        Activity

          People

            yuhong.zhang@mongodb.com Yuhong Zhang
            daniel.gottlieb@mongodb.com Daniel Gottlieb (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: