[SERVER-3217] $push and $pushAll oplog is not idempotent Created: 08/Jun/11  Updated: 28/Sep/12  Resolved: 28/Sep/12

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

Type: Bug Priority: Major - P3
Reporter: Alexey Guseynov Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3407 oplog is not idempotent for array ope... Closed
Related
is related to SERVER-5961 $push array size constraint can cause... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Run following commands on replica set:

replica:PRIMARY> db.foo.insert(

{"_id":"test", x:[1, 2, 3]}

)
replica:PRIMARY> db.foo.update(

{"_id":"test"}

, {$pushAll: {x:[4]}})
replica:PRIMARY> db.foo.update(

{"_id":"test"}

, {$pull: {x:1}})
replica:PRIMARY> db.foo.find(

{"_id":"test"}

)

{ "_id" : "test", "x" : [ 2, 3, 4 ] }

View oplog:

{ "ts" :

{ "t" : 1307521384000, "i" : 1 }

, "h" : NumberLong("-2482281928928604340"), "op" : "i", "ns" : "points.foo", "o" :

{ "_id" : "test", "x" : [ 1, 2, 3 ] }

}
{ "ts" :

{ "t" : 1307521392000, "i" : 1 }

, "h" : NumberLong("9215593517142594101"), "op" : "u", "ns" : "points.foo", "o2" : { "_id" : "test", "x" :

{ "$size" : 3 }

}, "o" : { "$pushAll" :

{ "x" : [ 4 ] }

} }
{ "ts" :

{ "t" : 1307521404000, "i" : 1 }

, "h" : NumberLong("-4865163357721582816"), "op" : "u", "ns" : "points.foo", "o2" :

{ "_id" : "test" }

, "o" : { "$pull" :

{ "x" : 1 }

} }

Now let's reexecute last two commands from oplog. They must be idempotent so after execution database content must not change:

replica:PRIMARY> db.foo.update({ "_id" : "test", "x" :

{ "$size" : 3 }

}, { "$pushAll" :

{ "x" : [ 4 ] }

})
replica:PRIMARY> db.foo.update(

{ "_id" : "test" }

, { "$pull" :

{ "x" : 1 }

})
replica:PRIMARY> db.foo.find(

{"_id":"test"}

)

{ "_id" : "test", "x" : [ 2, 3, 4, 4 ] }

But it changes. Because $pushAll was not rewritten in idempotent way.

If you change $pushAll with $push the same example would work. Corresponding oplog message is:

{ "ts" :

{ "t" : 1307521870000, "i" : 1 }

, "h" : NumberLong("-6895072222265747191"), "op" : "u", "ns" : "points.foo", "o2" : { "_id" : "test2", "x" :

{ "$size" : 3 }

}, "o" : { "$push" :

{ "x" : 4 }

} }

again mongo tests only array size.



 Comments   
Comment by Daniel Pasette (Inactive) [ 28/Sep/12 ]

see SERVER-3407.

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