Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-54040

Resharding may fail to throw WouldChangeOwningShard despite destined recipient having changed

    • Fully Compatible
    • ALL
    • Sharding 2021-02-08
    • 1

      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}}]}
      

            Assignee:
            janna.golden@mongodb.com Janna Golden
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: