[SERVER-79914] CollectionRoutingInfoTargeter::targetInsert can incorrectly route a document missing _id Created: 10/Aug/23 Updated: 13/Dec/23 Resolved: 13/Dec/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 7.3.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kaitlin Mahar | Assignee: | Allison Easton |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | shardingemea-qw | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Sharding EMEA
|
| Backwards Compatibility: | Fully Compatible |
| Operating System: | ALL |
| Sprint: | Sharding EMEA 2023-10-02, Sharding EMEA 2023-10-16, Sharding EMEA 2023-10-30, CAR Team 2023-11-13, CAR Team 2023-11-27, CAR Team 2023-12-11, CAR Team 2023-12-25 |
| Participants: | |
| Story Points: | 2 |
| Description |
|
This is because the logic in ShardKeyPattern::extractShardKeyFromDoc will fill in BSON null for any value in the shard key pattern that is not found in the document. This can cause a problem if a document to insert is passed to this method that does not already have an _id, and _id is in the shard key pattern. The document will then be routed to a shard based on an _id of BSON null. But once the document arrives on the shard, the shard will insert it, and give it a new _id, since it lacks one. And once it has a new _id, its value for the shard key has changed, and it may not be on the correct shard given its shard key. This happens to not be a problem right now for the insert command, because mongos always adds _id to incoming insert command requests. But we noticed this problem with the new bulkWrite command where we weren't generating _id on mongos. We will update the bulkWrite command to follow the same logic as insert to ensure there is always an _id, but it might be good to add some safeguard(s) around this. For example, maybe this method should error if _id is in the shard key pattern but not in the document. |
| Comments |
| Comment by Githook User [ 13/Dec/23 ] |
|
Author: {'name': 'Allison Easton', 'email': 'allison.easton@mongodb.com', 'username': 'allisoneaston'}Message: GitOrigin-RevId: 096f7f80ba889d2f64736fc53a48d6ecb6d1c73d |