[SERVER-39158] Change updates to prefer target by the query Created: 23/Jan/19  Updated: 29/Oct/23  Resolved: 22/May/19

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: None
Fix Version/s: 4.1.12

Type: Bug Priority: Major - P3
Reporter: Janna Golden Assignee: Arun Banala
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-40338 Add tests that replacement style and ... Closed
is depended on by DRIVERS-660 Change updates to prefer target by th... Closed
is depended on by MONGOID-4759 Change updates to prefer target by th... Backlog
is depended on by SERVER-40903 Ensure full shard key in query to all... Closed
Documented
is documented by DOCS-12742 Docs for SERVER-39158: Change updates... Closed
Related
related to SERVER-46505 Add back requirement that full shard ... Closed
is related to SERVER-41184 Add metrics to indicate the amount of... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: Query 2019-04-08, Query 2019-04-22, Query 2019-05-06, Query 2019-05-20, Query 2019-06-03
Participants:
Case:

 Description   

Currently, replacement style updates target using the update rather than the query. We should change this to target using the query instead.

As of today, we do not allow users to change the shard key for a document. If shard 1 owns the chunk with range (shardKey : min, shardKey : 500) and shard 2 owns the chunk with range (shardKey : 500, shardKey : max) and a user sends

db.coll.update({shardKey : 100}, {shardKey : 800})

the update will be sent to shard 2 and we return

{ok: 1.0, nMatched : 0)

We should actually get an ImmutableField error.

Once we allow a user to update the shard key for a document (PM-1163), the above update should cause the document to change shards. However, since the update would be sent to shard 2, shard 1 will never actually see this update and the update will not be applied.



 Comments   
Comment by Arun Banala [ 28/May/19 ]

Summary of the changes implemented as part of this ticket:

1. Replacement-style updates will now attempt to target by the query first.
2. If we cannot target a single shard, and if the operation is NOT an upsert, we fall back to targeting by the replacement document in order to maintain backwards-compatible behaviour.
3. If the operation is an upsert, then we do NOT fall back to targeting by replacement; an upsert must have full shard key in query. If not we throw an operation-fatal exception.
4. A full shard key must be specified in the query to update a shard key field.

Comment by Githook User [ 22/May/19 ]

Author:

{'email': 'arun.banala@mongodb.com', 'name': 'Arun Banala', 'username': 'banarun'}

Message: SERVER-39158 Change updates to prefer target by the query
Branch: master
https://github.com/mongodb/mongo/commit/713a1575150594222866b085c14bae4f13fe93b5

Generated at Thu Feb 08 04:51:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.