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

Explain on mongos with readPref:secondary fails in a wrong way when can't match the read pref

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Sharding
    • Labels:
      None
    • Operating System:
      ALL

      Description

      4.0.12
      mongos
      single shard - 1 node

      mongos> db.getMongo().setReadPref('secondary')
      mongos> db.test.find().explain()
      2019-09-20T10:39:20.947-0500 E QUERY    [js] Error: explain failed: {
      	"ok" : 0,
      	"errmsg" : "Explain command on shard db1/localhost:27030 failed, caused by: { ok: 1.0 }",
      	"code" : 96,
      	"codeName" : "OperationFailed",
      	"operationTime" : Timestamp(1568993960, 1),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1568993960, 1),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      

      It doesn't fail with 'can't find the node matching read pref' because of a bug in ClusterExplain::downconvert

         OperationContext* opCtx, const std::vector<AsyncRequestsSender::Response>& responses) {
          std::vector<Strategy::CommandResult> results;
          for (auto& response : responses) {
              Status status = Status::OK();
              if (response.swResponse.isOK()) {
                  auto& result = response.swResponse.getValue().data;
                  status = getStatusFromCommandResult(result);
                  if (status.isOK()) {
                      invariant(response.shardHostAndPort);
                      results.emplace_back(
                          response.shardId, ConnectionString(*response.shardHostAndPort), result);
                      continue;
                  }
              }
      /////////////////// need to add this ------->
              else status = response.swResponse.getStatus();
      ///////////////////
                  
              // Convert the error status back into the format of a command result.
              BSONObjBuilder statusObjBob;
              CommandHelpers::appendCommandStatusNoThrow(statusObjBob, status);
       
              // Get the Shard object in order to get the ConnectionString.
              auto shard =
                  uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, response.shardId));
              results.emplace_back(response.shardId, shard->getConnString(), statusObjBob.obj());
          }
          return results;
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              daniel.hatcher Danny Hatcher (Inactive)
              Reporter:
              alex.komyagin Alexander Komyagin
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: