[SERVER-54040] Resharding may fail to throw WouldChangeOwningShard despite destined recipient having changed Created: 25/Jan/21  Updated: 29/Oct/23  Resolved: 27/Jan/21

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

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Janna Golden
Resolution: Fixed Votes: 0
Labels: PM-234-M2.5, PM-234-T-oplog-fetch
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-52974 Checking if destined recipient has ch... Closed
is related to SERVER-49825 Replicate updates changing value unde... Closed
is related to SERVER-52683 Relax restrictions for updates to new... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Sharding 2021-02-08
Participants:
Story Points: 1

 Description   

UpdateStage::wasExistingShardKeyUpdated() and UpdateStage::wasReshardingKeyUpdated() are both functions which either return true, return false, or throw. Due to the short-circuiting behavior of || it is possible for UpdateStage::wasExistingShardKeyUpdated() to return true when UpdateStage::wasReshardingKeyUpdated() would have thrown a WouldChangeOwningShard exception.

const auto& newObj = newObjCopy ? *newObjCopy : _doc.getObject();
return wasExistingShardKeyUpdated(css, collDesc, newObj, oldObj) ||
    wasReshardingKeyUpdated(collDesc, newObj, oldObj);

https://github.com/mongodb/mongo/blob/2210368e6ef89de49491087750345197dcae96b8/src/mongo/db/exec/update_stage.cpp#L617-L618

With a current shard key pattern of {donor: 1, slot: 1} and a new shard key pattern of {recipient: 1, slot: 1}, the following update would cause UpdateStage::wasExistingShardKeyUpdated() to return true and cause UpdateStage::wasReshardingKeyUpdated() to throw WouldChangeOwningShard.

{insert: "reshard_coll", documents: [{_id: 452, donor: "donor1", recipient: "recipient0", slot: 25, num: 10}]}
{update: "reshard_coll", updates: [{q: {donor: "donor1", slot: 25}, u: {donor: "donor1", recipient: "recipient1", slot: 14, num: 12}}]}



 Comments   
Comment by Githook User [ 27/Jan/21 ]

Author:

{'name': 'jannaerin', 'email': 'golden.janna@gmail.com', 'username': 'jannaerin'}

Message: SERVER-54040 Resharding may fail to throw WouldChangeOwningShard despite destined recipient having changed
Branch: master
https://github.com/mongodb/mongo/commit/ee7a58e7af9fa14cf837a8f066eec784d1a9e2a6

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