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

Duplicate Key error exception on secondary sync with $inc

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.3.2
    • Component/s: Replication
    • Labels:
      None
    • ALL

      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

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

              Created:
              Updated:
              Resolved: