[SERVER-20380] Upsert is not atomic when inserting Created: 11/Sep/15 Updated: 20/Jan/17 Resolved: 14/Sep/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Concurrency, WiredTiger |
| Affects Version/s: | 3.0.6 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Galinkin | Assignee: | Ramon Fernandez Marina |
| Resolution: | Duplicate | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||
| Steps To Reproduce: | Create a file named upsert.js with the following content:
On a Mongo 3.0 WiredTiger setup, run these commands in bash:
This produces something like this:
It should produce something like this:
|
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
When many upserts happen at the same time, and the queried document does not exist, there should be only one insert, and the rest of the upserts should result in updates to the inserted document. In Mongo 3.0 with the WiredTiger engine, more than one document gets inserted in this situation. This does not happen on MMAPv1, or on Mongo 2.6. |
| Comments |
| Comment by Ramon Fernandez Marina [ 15/Sep/15 ] |
|
danielgalinkin@gmail.com, I forgot to add a link to the documentation on upsert that explains this behavior and how to use unique indexes to get the behavior you were expecting. Hope this helps. Ramón. |
| Comment by Daniel Galinkin [ 15/Sep/15 ] |
|
Oh, ok. I'll refactor my indexes to make them unique and retry the upserts on the application side, then. Thanks, |
| Comment by Ramon Fernandez Marina [ 14/Sep/15 ] |
|
danielgalinkin@gmail.com, this issue was previously reported in When a unique index constraint exists on a field affected by this behavior the application receives an error and should be able to retry, but unfortunately in your case it's not possible to identify the spurious inserts. Please feel free to watch Thanks, |