[SERVER-44980] wrong update result with upsert:true Created: 06/Dec/19  Updated: 09/Dec/19  Resolved: 09/Dec/19

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

Type: Bug Priority: Major - P3
Reporter: FirstName lipengchong Assignee: Carl Champain (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File upsert.py    
Issue Links:
Related
is related to SERVER-14322 Retry on predicate unique index viola... Closed
is related to SERVER-37124 Retry full upsert path when duplicate... Closed
Operating System: ALL
Participants:

 Description   

mongo1886:PRIMARY> db
lpc
mongo1886:PRIMARY> db.lpc.find()
{ "_id" : ObjectId("5de9c501959eef478c3a21d7"), "xid" : 1 }
{ "_id" : ObjectId("5de9c503959eef478c3a21d8"), "xid" : 2 }
{ "_id" : ObjectId("5de9c56a959eef478c3a21da"), "xid" : 3, "xxxx" : 11}
mongo1886:PRIMARY> db.lpc.getIndexes()
[
        {
                "v" : 2,
                "key" : {
                        "_id" : 1
                },
                "name" : "_id_",
                "ns" : "lpc.lpc"
        },
        {
                "v" : 2,
                "key" : {
                        "xid" : "hashed"
                },
                "name" : "xid_hashed",
                "ns" : "lpc.lpc"
        },
        {
                "v" : 2,
                "key" : {
                        "xid" : -1
                },
                "name" : "xid_-1",
                "ns" : "lpc.lpc"
        }
]
mongo1886:PRIMARY> 

then i use a python script with 20 threads to update the {"xid" : 3}.  at last i get the write.

mongo1886:PRIMARY> db.lpc.find()
{ "_id" : ObjectId("5de9c501959eef478c3a21d7"), "xid" : 1 }
{ "_id" : ObjectId("5de9c503959eef478c3a21d8"), "xid" : 2 }
{ "_id" : ObjectId("5de9c56a959eef478c3a21da"), "xid" : 3, "xxxx" : 11, "tmp_test_data" : NumberLong("46211725577525978") }
{ "_id" : ObjectId("5dea0b087cf278ae08d1ba91"), "xid" : 3, "tmp_test_data" : NumberLong("30455178109802127") }

i couldn't get the in other mongod . but in this mongod .it's a really truth.



 Comments   
Comment by Carl Champain (Inactive) [ 09/Dec/19 ]

Hi lpc,

Thanks for the report.
The described behavior is documented here.

To avoid inserting the same document more than once, only use upsert: true if the query field is uniquely indexed.

I'm linking SERVER-37124 and SERVER-14322 since they are about update/upsert and the application logic to retry writes without duplicating a document. 

Importantly, 3.4 version of MongoDB is almost end-of-lifed (January 2020), so I would strongly recommend upgrading to a more recent version.

That said, the SERVER project is for bugs and feature suggestions for the MongoDB server. As this ticket does not appear to be a bug, I will now close it. If you need further assistance troubleshooting, I encourage you to ask our community by posting on the mongodb-user group or on Stack Overflow with the mongodb tag.

Kind regards,
Carl

Comment by FirstName lipengchong [ 06/Dec/19 ]

I can reproduce it on 3.4.18/19/21   mmap stroageEngine .

but for 3.4.22 ,i don't reproduce .

Comment by FirstName lipengchong [ 06/Dec/19 ]

i have test with only xid_hashed or xid_1 index or no index. And only get the result with both xid_hashed and xid_1

Generated at Thu Feb 08 05:07:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.