Skip to content

Commit

Permalink
SERVER-4504; minor changes from Mathias' code review
Browse files Browse the repository at this point in the history
  • Loading branch information
U-tellus\cwestin committed May 31, 2012
1 parent fcf1217 commit d079072
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
@@ -1,4 +1,4 @@
//if ( 0 ) {
if ( 0 ) {

/* load the test documents */
load('jstests/aggregation/data/articles.js');
Expand Down Expand Up @@ -557,4 +557,4 @@ var edi3result = {

assert(documentEq(edi3, edi3result), 'edi3 failed');

//}
}
4 changes: 2 additions & 2 deletions src/mongo/db/commands/pipeline.h
Expand Up @@ -122,7 +122,7 @@ namespace mongo {
@returns true if this is an explain
*/
bool getExplain() const;
bool isExplain() const;

/**
The aggregation command name.
Expand Down Expand Up @@ -217,7 +217,7 @@ namespace mongo {
return splitMongodPipeline;
}

inline bool Pipeline::getExplain() const {
inline bool Pipeline::isExplain() const {
return explain;
}

Expand Down
17 changes: 4 additions & 13 deletions src/mongo/db/commands/pipeline_command.cpp
Expand Up @@ -160,7 +160,7 @@ namespace mongo {
lk.reset(new Lock::GlobalRead());
Client::ReadContext ctx(ns, dbpath, requiresAuth()); // read lock

PipelineD::prepareCursorSource(&pSource, pPipeline, db, pCtx);
pSource = PipelineD::prepareCursorSource(pPipeline, db, pCtx);

/* release the Cursor before the lock gets released */
pSource->releaseCursor();
Expand All @@ -182,14 +182,13 @@ namespace mongo {
intrusive_ptr<Pipeline> &pPipeline,
intrusive_ptr<ExpressionContext> &pCtx) {

intrusive_ptr<DocumentSourceCursor> pSource;

scoped_ptr<Lock::GlobalRead> lk;
if(lockGlobally())
lk.reset(new Lock::GlobalRead());
Client::ReadContext ctx(ns, dbpath, requiresAuth()); // read lock

PipelineD::prepareCursorSource(&pSource, pPipeline, db, pCtx);
intrusive_ptr<DocumentSourceCursor> pSource(
PipelineD::prepareCursorSource(pPipeline, db, pCtx));
return executePipeline(result, errmsg, ns, pPipeline, pSource, pCtx);
}

Expand Down Expand Up @@ -293,18 +292,10 @@ namespace mongo {

string ns(parseNs(db, cmdObj));

if (pPipeline->getExplain())
if (pPipeline->isExplain())
return runExplain(result, errmsg, ns, db, pPipeline, pCtx);
else
return runExecute(result, errmsg, ns, db, pPipeline, pCtx);

#ifdef NEVER
intrusive_ptr<DocumentSourceCursor> pSource;
PipelineD::prepareCursorSource(
&pSource, pPipeline, db, pCtx);

return executePipeline(result, errmsg, ns, pPipeline, pSource, pCtx);
#endif
}

} // namespace mongo
14 changes: 8 additions & 6 deletions src/mongo/db/commands/pipeline_d.cpp
Expand Up @@ -24,8 +24,7 @@

namespace mongo {

void PipelineD::prepareCursorSource(
intrusive_ptr<DocumentSourceCursor> *ppSource,
intrusive_ptr<DocumentSourceCursor> PipelineD::prepareCursorSource(
const intrusive_ptr<Pipeline> &pPipeline,
const string &dbName,
const intrusive_ptr<ExpressionContext> &pExpCtx) {
Expand Down Expand Up @@ -134,9 +133,10 @@ namespace mongo {
}

/* wrap the cursor with a DocumentSource and return that */
*ppSource = DocumentSourceCursor::create(pCursor, dbName, pExpCtx);
intrusive_ptr<DocumentSourceCursor> pSource(
DocumentSourceCursor::create(pCursor, dbName, pExpCtx));

(*ppSource)->setNamespace(fullName);
pSource->setNamespace(fullName);

/*
Note the query and sort
Expand All @@ -145,9 +145,11 @@ namespace mongo {
referenced (by reference) by the cursor, which doesn't make its
own copies of them.
*/
(*ppSource)->setQuery(pQueryObj);
pSource->setQuery(pQueryObj);
if (initSort)
(*ppSource)->setSort(pSortObj);
pSource->setSort(pSortObj);

return pSource;
}

} // namespace mongo
5 changes: 2 additions & 3 deletions src/mongo/db/commands/pipeline_d.h
Expand Up @@ -45,13 +45,12 @@ namespace mongo {
early match can be removed and replaced with a Cursor that will
do an index scan.
@param ppSource where to put the wrapped Cursor
@param pPipeline the logical "this" for this operation
@param dbName the name of the database
@param pExpCtx the expression context for this pipeline
@returns the cursor that was created
*/
static void prepareCursorSource(
intrusive_ptr<DocumentSourceCursor> *ppSource,
static intrusive_ptr<DocumentSourceCursor> prepareCursorSource(
const intrusive_ptr<Pipeline> &pPipeline,
const string &dbName,
const intrusive_ptr<ExpressionContext> &pExpCtx);
Expand Down

0 comments on commit d079072

Please sign in to comment.