Skip to content

Commit

Permalink
SERVER-17282 update find command parsing to conform to find command s…
Browse files Browse the repository at this point in the history
…pec changes

Also updates the shell to construct the find command according to the new spec.
This means that explain with special options (e.g. snapshot()) will not be compatible
when mixing 3.2 shell / 3.0 server or 3.0 shell / 3.2 server. Explain of find with
standard options like filter, query, projection, sort, and hint will be both backwards
and forwards compatible.
  • Loading branch information
dstorch committed Mar 11, 2015
1 parent 665f406 commit 8ca1f78
Show file tree
Hide file tree
Showing 13 changed files with 392 additions and 451 deletions.
6 changes: 2 additions & 4 deletions jstests/core/explain_find.js
Expand Up @@ -24,10 +24,8 @@ assert.eq(3, explain.executionStats.nReturned);
explain = db.runCommand({
explain: {
find: collName,
options: {
min: {a: 4},
max: {a: 6}
}
min: {a: 4},
max: {a: 6}
},
verbosity: "executionStats"
});
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/commands/find_cmd.cpp
Expand Up @@ -100,7 +100,7 @@ namespace mongo {
// We have a parsed query. Time to get the execution plan for it.
PlanExecutor* rawExec;
Status execStatus = Status::OK();
if (cq->getParsed().getOptions().oplogReplay) {
if (cq->getParsed().isOplogReplay()) {
execStatus = getOplogStartHack(txn, collection, cq.release(), &rawExec);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/idhack.cpp
Expand Up @@ -229,7 +229,7 @@ namespace mongo {
&& query.getParsed().getHint().isEmpty()
&& 0 == query.getParsed().getSkip()
&& CanonicalQuery::isSimpleIdQuery(query.getParsed().getFilter())
&& !query.getParsed().getOptions().tailable;
&& !query.getParsed().isTailable();
}

vector<PlanStage*> IDHackStage::getChildren() const {
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/exec/subplan.cpp
Expand Up @@ -91,7 +91,7 @@ namespace mongo {
}

// Tailable cursors won't get cached, just turn into collscans.
if (query.getParsed().getOptions().tailable) {
if (query.getParsed().isTailable()) {
return false;
}

Expand Down
18 changes: 9 additions & 9 deletions src/mongo/db/query/find.cpp
Expand Up @@ -564,7 +564,7 @@ namespace mongo {
params.collection = collection;
params.start = *startLoc;
params.direction = CollectionScanParams::FORWARD;
params.tailable = cq->getParsed().getOptions().tailable;
params.tailable = cq->getParsed().isTailable();

WorkingSet* ws = new WorkingSet();
CollectionScan* cs = new CollectionScan(txn, params, ws, cq->root());
Expand Down Expand Up @@ -663,7 +663,7 @@ namespace mongo {
// Otherwise we go through the selection of which executor is most suited to the
// query + run-time context at hand.
Status status = Status::OK();
if (NULL != collection && cq->getParsed().getOptions().oplogReplay) {
if (NULL != collection && cq->getParsed().isOplogReplay()) {
status = getOplogStartHack(txn, collection, cq.release(), &rawExec);
}
else {
Expand Down Expand Up @@ -723,7 +723,7 @@ namespace mongo {
txn->checkForInterrupt(); // May trigger maxTimeAlwaysTimeOut fail point.

// uassert if we are not on a primary, and not a secondary with SlaveOk query parameter set.
bool slaveOK = pq.getOptions().slaveOk || pq.hasReadPref();
bool slaveOK = pq.isSlaveOk() || pq.hasReadPref();
status = repl::getGlobalReplicationCoordinator()->checkCanServeReadsFor(
txn,
nss,
Expand Down Expand Up @@ -773,7 +773,7 @@ namespace mongo {
++numResults;

// Possibly note slave's position in the oplog.
if (pq.getOptions().oplogReplay) {
if (pq.isOplogReplay()) {
BSONElement e = obj["ts"];
if (Date == e.type() || Timestamp == e.type()) {
slaveReadTill = e._opTime();
Expand Down Expand Up @@ -814,7 +814,7 @@ namespace mongo {
if (PlanExecutor::DEAD == state) {
saveClientCursor = false;
}
else if (pq.getOptions().tailable) {
else if (pq.isTailable()) {
// If we're tailing a capped collection, we don't bother saving the cursor if the
// collection is empty. Otherwise, the semantics of the tailable cursor is that the
// client will keep trying to read from it. So we'll keep it around.
Expand Down Expand Up @@ -873,14 +873,14 @@ namespace mongo {
ClientCursor* cc = new ClientCursor(collection->getCursorManager(),
exec.release(),
nss.ns(),
pq.getOptions().toInt(),
pq.getOptions(),
pq.getFilter());
ccId = cc->cursorid();

if (txn->getClient()->isInDirectClient()) {
cc->setUnownedRecoveryUnit(txn->recoveryUnit());
}
else if (state == PlanExecutor::IS_EOF && pq.getOptions().tailable) {
else if (state == PlanExecutor::IS_EOF && pq.isTailable()) {
// Don't stash the RU for tailable cursors at EOF, let them get a new RU on their
// next getMore.
}
Expand All @@ -897,12 +897,12 @@ namespace mongo {
<< " after returning " << numResults << " results" << endl;

// TODO document
if (pq.getOptions().oplogReplay && !slaveReadTill.isNull()) {
if (pq.isOplogReplay() && !slaveReadTill.isNull()) {
cc->slaveReadTill(slaveReadTill);
}

// TODO document
if (pq.getOptions().exhaust) {
if (pq.isExhaust()) {
curop.debug().exhaust = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/query/get_executor.cpp
Expand Up @@ -267,7 +267,7 @@ namespace mongo {
}

// Tailable: If the query requests tailable the collection must be capped.
if (canonicalQuery->getParsed().getOptions().tailable) {
if (canonicalQuery->getParsed().isTailable()) {
if (!collection->isCapped()) {
return Status(ErrorCodes::BadValue,
"error processing query: " + canonicalQuery->toString() +
Expand Down

0 comments on commit 8ca1f78

Please sign in to comment.