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

add a runBatchWriteCommand() method to Shard that checks for errors by unwrapping the BatchedCommandResponse

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.10
    • Affects Version/s: 3.3.8
    • Component/s: Sharding
    • Fully Compatible
    • Sharding 17 (07/15/16)

      The current Shard::runCommand() method only checks for the request status, command status, and write concern error.

      Since Shard::runCommand simply takes a BSONObj cmdObj, it's dangerously easy to pass in a BatchedCommandRequest in BSONObj form and assume that retries and error checking will be correctly handled.

      Status _getEffectiveCommandStatus(StatusWith<Shard::CommandResponse> cmdResponse) {
          // Make sure the command even received a valid response
          if (!cmdResponse.isOK()) {
              return cmdResponse.getStatus();
          }
      
          // If the request reached the shard, check if the command itself failed.
          if (!cmdResponse.getValue().commandStatus.isOK()) {
              return cmdResponse.getValue().commandStatus;
          }
      
          // Finally check if the write concern failed
          if (!cmdResponse.getValue().writeConcernStatus.isOK()) {
              return cmdResponse.getValue().writeConcernStatus;
          }
      
          return Status::OK();
      }
      

            Assignee:
            jess.fan Jess Fan
            Reporter:
            esha.maharishi@mongodb.com Esha Maharishi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: