[SERVER-19361] Insert of document with duplicate _id fields should be forbidden Created: 10/Jul/15 Updated: 08/Apr/23 Resolved: 16/Sep/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Write Ops |
| Affects Version/s: | None |
| Fix Version/s: | 3.0.7, 3.1.9 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | David Golden | Assignee: | YunHe Wang |
| Resolution: | Done | Votes: | 0 |
| Labels: | neweng | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||
| Backport Completed: | |||||||||||||||||||||||||
| Steps To Reproduce: | Construct a BSON document with multiple _id fields and send it to the server. E.g. with MongoDB Perl driver v0.708.2.0:
Then look at the test.duptest collection in the mongo shell. |
||||||||||||||||||||||||
| Sprint: | Quint 9 09/18/15 | ||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Description |
|
(At behackett's suggestion, I'm opening this separate from SERVER-6439 to highlight the impact on _id, specifically.) A bug in the Perl driver revealed that it's possible to insert a document with duplicate/multiple _id fields.
I reproduced this against 3.1.5, 3.0.4, 2.6.10, and 2.4.14. |
| Comments |
| Comment by Githook User [ 16/Sep/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {u'username': u'yhjw88', u'name': u'Yunhe (John) Wang', u'email': u'yunhe.wang@mongodb.com'}Message: (cherry picked from commit 61baf779dacca5ae17ac3ea1c3338b039824c280) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 16/Sep/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {u'name': u'Yunhe (John) Wang', u'email': u'yunhe.wang@mongodb.com'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by YunHe Wang [ 14/Sep/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
New behavior:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by J Rassi [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ah, well in that case, I can confirm this as a legitimate bug separate from SERVER-6439. After running a couple of test scenarios, I've determined that documents with duplicate _id fields only replicate one copy of the field (and that documents with other duplicate fields do not suffer from this issue). Scott suggests that Updating issue title and moving issue to the "Needs Triage" state. We'll schedule this at our next triage meeting. Thanks again, folks. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Bernie Hackett [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Can you use the insert command directly to reproduce? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by David Golden [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I can't test this for other fields, as the Perl bug was specific to _id. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by J Rassi [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
David, could post the log from the failed secondary? Also, I suspect that the same behavior will be exhibited when the duplicated field has a different name than "_id"; would you mind confirming this? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by David Golden [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
With a replica set, the duplicate _id doesn't replicate and then unsetting the _id field cleans up the duplicate on the primary and crashes the secondary. Here's an example with MongoDB 3.0.4. I used the repro Perl code above to create the duplicate fields and then did the rest with the shell. The replica set had one primary, one secondary and one arbiter. On the primary:
On the secondary:
Unsetting the _id on the primary:
Secondary crashed:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Bernie Hackett [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There are definitely replication implications for not having an _id at all. I don't know what the implications are for having multiple _id fields. The fact is, MongoDB gives special treatment in various ways to _id. That might make this a distinct issue from having duplicates of any other arbitrary field. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by J Rassi [ 10/Jul/15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
From the server's perspective, are the consequences of inserting a document with duplicate _id fields any different than the consequence of inserting a document with some other duplicate field (for example, do updates on these documents replicate correctly)? If not, I'd be inclined to close this as a dup of SERVER-6439. |