[SERVER-8343] Duplicate Key error exception on secondary sync with $inc Created: 25/Jan/13  Updated: 15/Feb/13  Resolved: 30/Jan/13

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: 2.3.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Randolph Tan Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Operating System: ALL
Participants:

 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



 Comments   
Comment by Randolph Tan [ 30/Jan/13 ]

Test removes min valid collection, so it is invalid.

Comment by Eric Milkie [ 28/Jan/13 ]

I believe this was due to the oplog tests removing the minvalid document when reconstructing the oplog. This will affect when the secondary reaches state SECONDARY versus state RECOVERING, and thus affects how duplicate key errors are handled. When we removed the deletion of the minvalid document in the test framework, the $inc test started passing again.

Generated at Thu Feb 08 03:17:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.