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

Duplicate Key error exception on secondary sync with $inc

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 2.3.2
    • None
    • Replication
    • None
    • ALL

    Description

      Consider the sets of operations below:

      db.user.ensureIndex({ x: 1 }, { unique: true });
      db,user.insert({ x: 1, y: 1 });
      db.user.insert({ x: 3, y: 2 });
      db.user.update({ y: 1 }, { $inc: { x: 1 }, $set: { z: 1 }});
      db.user.update({ y: 1 }, { $inc: { x: -1 }});
      db.user.update({ y: 2 }, { $inc: { x: -1 }});

      If you let the secondary apply all ops, but only record the oplog upto line#3, the secondary will fassert if you restart it. A variant using array also has the same problem:

      db.user.ensureIndex({ 'a.x': 1 }, { unique: true });
      db.user.insert({ a: [ { x: 1, y: 1 }, { x: 3, y: 2 } ]});
      db.user.update({ 'a.y': 1 }, { $inc: { 'a.$.x': 1 }, $set: { 'a.$.z': 1 }});
      db.user.update({ 'a.y': 1 }, { $inc: { 'a.$.x': -1 }});
      db.user.update({ 'a.y': 2 }, { $inc: { 'a.$.x': -1 }});

      Note: tested on commit 3dfc22e239d7455608a2ad2bc1197eac78550a23

      Attachments

        Activity

          People

            randolph@mongodb.com Randolph Tan
            randolph@mongodb.com Randolph Tan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: