[SERVER-43394] Explain on mongos with readPref:secondary fails in a wrong way when can't match the read pref Created: 20/Sep/19  Updated: 20/Sep/19  Resolved: 20/Sep/19

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

Type: Bug Priority: Minor - P4
Reporter: Alexander Komyagin Assignee: Danny Hatcher (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-41099 Fix incorrect error propagation from ... Closed
Operating System: ALL
Participants:

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



 Comments   
Comment by Alexander Komyagin [ 20/Sep/19 ]

Yeah!

Comment by Danny Hatcher (Inactive) [ 20/Sep/19 ]

alex.komyagin, this looks like a duplicate of SERVER-41099 and that fix just needs to be backported to the 4.0 release. Do you agree?

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