summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests
diff options
context:
space:
mode:
authorQingyang Chen <qingyang.chen@10gen.com>2015-06-19 17:20:36 -0400
committerQingyang Chen <qingyang.chen@10gen.com>2015-06-26 10:10:34 -0400
commit159f54fcb550d6ff660efd2832ac5ae8b6fced56 (patch)
tree2b6ac085b3375ce151d92fa1db9b4a38d92da25f /src/mongo/dbtests
parent2931e33f4d6efb3aa176eaa951be6c91abce2b43 (diff)
downloadmongo-159f54fcb550d6ff660efd2832ac5ae8b6fced56.tar.gz
SERVER-16889 Modernize getExecutor*(), PlanExecutor::make() signatures
Diffstat (limited to 'src/mongo/dbtests')
-rw-r--r--src/mongo/dbtests/documentsourcetests.cpp6
-rw-r--r--src/mongo/dbtests/executor_registry.cpp18
-rw-r--r--src/mongo/dbtests/query_multi_plan_runner.cpp23
-rw-r--r--src/mongo/dbtests/query_plan_executor.cpp37
-rw-r--r--src/mongo/dbtests/query_stage_collscan.cpp42
-rw-r--r--src/mongo/dbtests/query_stage_merge_sort.cpp148
-rw-r--r--src/mongo/dbtests/query_stage_sort.cpp58
-rw-r--r--src/mongo/dbtests/query_stage_tests.cpp20
8 files changed, 156 insertions, 196 deletions
diff --git a/src/mongo/dbtests/documentsourcetests.cpp b/src/mongo/dbtests/documentsourcetests.cpp
index 971acb64317..f9f644cc03b 100644
--- a/src/mongo/dbtests/documentsourcetests.cpp
+++ b/src/mongo/dbtests/documentsourcetests.cpp
@@ -182,11 +182,9 @@ protected:
auto statusWithCQ = CanonicalQuery::canonicalize(ns, /*query=*/BSONObj());
uassertStatusOK(statusWithCQ.getStatus());
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
- PlanExecutor* execBare;
- uassertStatusOK(getExecutor(
- &_opCtx, ctx.getCollection(), cq.release(), PlanExecutor::YIELD_MANUAL, &execBare));
+ _exec = uassertStatusOK(
+ getExecutor(&_opCtx, ctx.getCollection(), std::move(cq), PlanExecutor::YIELD_MANUAL));
- _exec.reset(execBare);
_exec->saveState();
_exec->registerExec();
diff --git a/src/mongo/dbtests/executor_registry.cpp b/src/mongo/dbtests/executor_registry.cpp
index 3601ecc80e0..dc02f95c58f 100644
--- a/src/mongo/dbtests/executor_registry.cpp
+++ b/src/mongo/dbtests/executor_registry.cpp
@@ -76,17 +76,15 @@ public:
ASSERT_OK(statusWithCQ.getStatus());
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
- PlanExecutor* exec;
// Takes ownership of 'ws', 'scan', and 'cq'.
- Status status = PlanExecutor::make(&_opCtx,
- ws.release(),
- scan.release(),
- cq.release(),
- _ctx->db()->getCollection(ns()),
- PlanExecutor::YIELD_MANUAL,
- &exec);
- ASSERT_OK(status);
- return exec;
+ auto statusWithPlanExecutor = PlanExecutor::make(&_opCtx,
+ std::move(ws),
+ std::move(scan),
+ std::move(cq),
+ _ctx->db()->getCollection(ns()),
+ PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ return statusWithPlanExecutor.getValue().release();
}
void registerExecutor(PlanExecutor* exec) {
diff --git a/src/mongo/dbtests/query_multi_plan_runner.cpp b/src/mongo/dbtests/query_multi_plan_runner.cpp
index 02e66609dc2..bd9efe25fd0 100644
--- a/src/mongo/dbtests/query_multi_plan_runner.cpp
+++ b/src/mongo/dbtests/query_multi_plan_runner.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/query/query_planner_test_lib.h"
#include "mongo/db/query/stage_builder.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/stdx/memory.h"
namespace mongo {
@@ -58,6 +59,7 @@ namespace QueryMultiPlanRunner {
using std::unique_ptr;
using std::vector;
+using stdx::make_unique;
/**
* Create query solution.
@@ -157,7 +159,8 @@ public:
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
verify(NULL != cq.get());
- MultiPlanStage* mps = new MultiPlanStage(&_txn, ctx.getCollection(), cq.get());
+ unique_ptr<MultiPlanStage> mps =
+ make_unique<MultiPlanStage>(&_txn, ctx.getCollection(), cq.get());
mps->addPlan(createQuerySolution(), firstRoot.release(), sharedWs.get());
mps->addPlan(createQuerySolution(), secondRoot.release(), sharedWs.get());
@@ -168,16 +171,14 @@ public:
ASSERT_EQUALS(0, mps->bestPlanIdx());
// Takes ownership of arguments other than 'collection'.
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- sharedWs.release(),
- mps,
- cq.release(),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(&_txn,
+ std::move(sharedWs),
+ std::move(mps),
+ std::move(cq),
+ coll,
+ PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ std::unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
// Get all our results out.
int results = 0;
diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp
index 7cbd86ab9cb..e24638ee5c7 100644
--- a/src/mongo/dbtests/query_plan_executor.cpp
+++ b/src/mongo/dbtests/query_plan_executor.cpp
@@ -103,17 +103,11 @@ public:
// Make the stage.
unique_ptr<PlanStage> root(new CollectionScan(&_txn, csparams, ws.get(), cq.get()->root()));
- PlanExecutor* exec;
// Hand the plan off to the executor.
- Status stat = PlanExecutor::make(&_txn,
- ws.release(),
- root.release(),
- cq.release(),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &exec);
- ASSERT_OK(stat);
- return exec;
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(root), std::move(cq), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ return statusWithPlanExecutor.getValue().release();
}
/**
@@ -150,17 +144,11 @@ public:
unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
verify(NULL != cq.get());
- PlanExecutor* exec;
// Hand the plan off to the executor.
- Status stat = PlanExecutor::make(&_txn,
- ws.release(),
- root.release(),
- cq.release(),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &exec);
- ASSERT_OK(stat);
- return exec;
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(root), std::move(cq), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ return statusWithPlanExecutor.getValue().release();
}
static const char* ns() {
@@ -296,11 +284,10 @@ public:
new PipelineProxyStage(pipeline, innerExec, ws.get()));
Collection* collection = ctx.getCollection();
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(
- &_txn, ws.release(), proxy.release(), collection, PlanExecutor::YIELD_MANUAL, &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> outerExec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(proxy), collection, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ std::unique_ptr<PlanExecutor> outerExec = std::move(statusWithPlanExecutor.getValue());
// Only the outer executor gets registered.
registerExec(outerExec.get());
diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp
index e7af7378099..84593bc62f0 100644
--- a/src/mongo/dbtests/query_stage_collscan.cpp
+++ b/src/mongo/dbtests/query_stage_collscan.cpp
@@ -44,12 +44,14 @@
#include "mongo/db/query/plan_executor.h"
#include "mongo/db/storage/record_store.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/stdx/memory.h"
#include "mongo/util/fail_point_service.h"
namespace QueryStageCollectionScan {
using std::unique_ptr;
using std::vector;
+using stdx::make_unique;
//
// Stage-specific tests.
@@ -91,14 +93,14 @@ public:
unique_ptr<MatchExpression> filterExpr(swme.getValue());
// Make a scan and have the runner own it.
- WorkingSet* ws = new WorkingSet();
- PlanStage* ps = new CollectionScan(&_txn, params, ws, filterExpr.get());
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
+ unique_ptr<PlanStage> ps =
+ make_unique<CollectionScan>(&_txn, params, ws.get(), filterExpr.get());
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(
- &_txn, ws, ps, params.collection, PlanExecutor::YIELD_MANUAL, &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(ps), params.collection, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
// Use the runner to count the number of objects scanned.
int count = 0;
@@ -207,14 +209,13 @@ public:
params.tailable = false;
// Make a scan and have the runner own it.
- WorkingSet* ws = new WorkingSet();
- PlanStage* ps = new CollectionScan(&_txn, params, ws, NULL);
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
+ unique_ptr<PlanStage> ps = make_unique<CollectionScan>(&_txn, params, ws.get(), nullptr);
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(
- &_txn, ws, ps, params.collection, PlanExecutor::YIELD_MANUAL, &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(ps), params.collection, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
int count = 0;
for (BSONObj obj; PlanExecutor::ADVANCED == exec->getNext(&obj, NULL);) {
@@ -241,14 +242,13 @@ public:
params.direction = CollectionScanParams::BACKWARD;
params.tailable = false;
- WorkingSet* ws = new WorkingSet();
- PlanStage* ps = new CollectionScan(&_txn, params, ws, NULL);
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
+ unique_ptr<PlanStage> ps = make_unique<CollectionScan>(&_txn, params, ws.get(), nullptr);
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(
- &_txn, ws, ps, params.collection, PlanExecutor::YIELD_MANUAL, &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(ps), params.collection, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
int count = 0;
for (BSONObj obj; PlanExecutor::ADVANCED == exec->getNext(&obj, NULL);) {
diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp
index 884ec1bda55..55f27b3059e 100644
--- a/src/mongo/dbtests/query_stage_merge_sort.cpp
+++ b/src/mongo/dbtests/query_stage_merge_sort.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/stdx/memory.h"
/**
* This file tests db/exec/merge_sort.cpp
@@ -46,9 +47,10 @@
namespace QueryStageMergeSortTests {
-using std::unique_ptr;
using std::set;
using std::string;
+using std::unique_ptr;
+using stdx::make_unique;
class QueryStageMergeSortTestBase {
public:
@@ -134,11 +136,11 @@ public:
addIndex(firstIndex);
addIndex(secondIndex);
- WorkingSet* ws = new WorkingSet();
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
// Sort by c:1
MergeSortStageParams msparams;
msparams.pattern = BSON("c" << 1);
- MergeSortStage* ms = new MergeSortStage(msparams, ws, coll);
+ MergeSortStage* ms = new MergeSortStage(msparams, ws.get(), coll);
// a:1
IndexScanParams params;
@@ -148,22 +150,19 @@ public:
params.bounds.endKey = objWithMaxKey(1);
params.bounds.endKeyInclusive = true;
params.direction = 1;
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
// b:1
params.descriptor = getIndex(secondIndex, coll);
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
+ unique_ptr<FetchStage> fetchStage =
+ make_unique<FetchStage>(&_txn, ws.get(), ms, nullptr, coll);
// Must fetch if we want to easily pull out an obj.
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, ms, NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
for (int i = 0; i < N; ++i) {
BSONObj first, second;
@@ -207,11 +206,11 @@ public:
addIndex(firstIndex);
addIndex(secondIndex);
- WorkingSet* ws = new WorkingSet();
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
// Sort by c:1
MergeSortStageParams msparams;
msparams.pattern = BSON("c" << 1);
- MergeSortStage* ms = new MergeSortStage(msparams, ws, coll);
+ MergeSortStage* ms = new MergeSortStage(msparams, ws.get(), coll);
// a:1
IndexScanParams params;
@@ -221,21 +220,18 @@ public:
params.bounds.endKey = objWithMaxKey(1);
params.bounds.endKeyInclusive = true;
params.direction = 1;
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
// b:1
params.descriptor = getIndex(secondIndex, coll);
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
-
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, ms, NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
+ unique_ptr<FetchStage> fetchStage =
+ make_unique<FetchStage>(&_txn, ws.get(), ms, nullptr, coll);
+
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
for (int i = 0; i < N; ++i) {
BSONObj first, second;
@@ -278,12 +274,12 @@ public:
addIndex(firstIndex);
addIndex(secondIndex);
- WorkingSet* ws = new WorkingSet();
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
// Sort by c:1
MergeSortStageParams msparams;
msparams.dedup = false;
msparams.pattern = BSON("c" << 1);
- MergeSortStage* ms = new MergeSortStage(msparams, ws, coll);
+ MergeSortStage* ms = new MergeSortStage(msparams, ws.get(), coll);
// a:1
IndexScanParams params;
@@ -293,21 +289,18 @@ public:
params.bounds.endKey = objWithMaxKey(1);
params.bounds.endKeyInclusive = true;
params.direction = 1;
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
// b:1
params.descriptor = getIndex(secondIndex, coll);
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
-
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, ms, NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
+ unique_ptr<FetchStage> fetchStage =
+ make_unique<FetchStage>(&_txn, ws.get(), ms, nullptr, coll);
+
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
for (int i = 0; i < N; ++i) {
BSONObj first, second;
@@ -353,11 +346,11 @@ public:
addIndex(firstIndex);
addIndex(secondIndex);
- WorkingSet* ws = new WorkingSet();
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
// Sort by c:-1
MergeSortStageParams msparams;
msparams.pattern = BSON("c" << -1);
- MergeSortStage* ms = new MergeSortStage(msparams, ws, coll);
+ MergeSortStage* ms = new MergeSortStage(msparams, ws.get(), coll);
// a:1
IndexScanParams params;
@@ -368,21 +361,18 @@ public:
params.bounds.endKeyInclusive = true;
// This is the direction along the index.
params.direction = 1;
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
// b:1
params.descriptor = getIndex(secondIndex, coll);
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
-
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, ms, NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
+ unique_ptr<FetchStage> fetchStage =
+ make_unique<FetchStage>(&_txn, ws.get(), ms, nullptr, coll);
+
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
for (int i = 0; i < N; ++i) {
BSONObj first, second;
@@ -426,11 +416,11 @@ public:
addIndex(firstIndex);
addIndex(secondIndex);
- WorkingSet* ws = new WorkingSet();
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
// Sort by c:1
MergeSortStageParams msparams;
msparams.pattern = BSON("c" << 1);
- MergeSortStage* ms = new MergeSortStage(msparams, ws, coll);
+ MergeSortStage* ms = new MergeSortStage(msparams, ws.get(), coll);
// a:1
IndexScanParams params;
@@ -440,23 +430,20 @@ public:
params.bounds.endKey = objWithMaxKey(1);
params.bounds.endKeyInclusive = true;
params.direction = 1;
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
// b:51 (EOF)
params.descriptor = getIndex(secondIndex, coll);
params.bounds.startKey = BSON("" << 51 << "" << MinKey);
params.bounds.endKey = BSON("" << 51 << "" << MaxKey);
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
-
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, ms, NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
+ unique_ptr<FetchStage> fetchStage =
+ make_unique<FetchStage>(&_txn, ws.get(), ms, nullptr, coll);
+
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
// Only getting results from the a:1 index scan.
for (int i = 0; i < N; ++i) {
@@ -485,11 +472,11 @@ public:
wuow.commit();
}
- WorkingSet* ws = new WorkingSet();
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
// Sort by foo:1
MergeSortStageParams msparams;
msparams.pattern = BSON("foo" << 1);
- MergeSortStage* ms = new MergeSortStage(msparams, ws, coll);
+ MergeSortStage* ms = new MergeSortStage(msparams, ws.get(), coll);
IndexScanParams params;
params.bounds.isSimpleRange = true;
@@ -507,18 +494,15 @@ public:
BSONObj indexSpec = BSON(index << 1 << "foo" << 1);
addIndex(indexSpec);
params.descriptor = getIndex(indexSpec, coll);
- ms->addChild(new IndexScan(&_txn, params, ws, NULL));
+ ms->addChild(new IndexScan(&_txn, params, ws.get(), NULL));
}
+ unique_ptr<FetchStage> fetchStage =
+ make_unique<FetchStage>(&_txn, ws.get(), ms, nullptr, coll);
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, ms, NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
for (int i = 0; i < numIndices; ++i) {
BSONObj obj;
diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp
index c2b30c1d084..0de6c1a3d9e 100644
--- a/src/mongo/dbtests/query_stage_sort.cpp
+++ b/src/mongo/dbtests/query_stage_sort.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/stdx/memory.h"
/**
* This file tests db/exec/sort.cpp
@@ -46,8 +47,9 @@
namespace QueryStageSortTests {
-using std::unique_ptr;
using std::set;
+using std::unique_ptr;
+using stdx::make_unique;
class QueryStageSortTestBase {
public:
@@ -100,9 +102,8 @@ public:
* which is owned by the caller.
*/
PlanExecutor* makePlanExecutorWithSortStage(Collection* coll) {
- PlanExecutor* exec;
// Build the mock scan stage which feeds the data.
- std::unique_ptr<WorkingSet> ws(new WorkingSet());
+ unique_ptr<WorkingSet> ws(new WorkingSet());
unique_ptr<QueuedDataStage> ms(new QueuedDataStage(ws.get()));
insertVarietyOfObjects(ms.get(), coll);
@@ -114,10 +115,10 @@ public:
// The PlanExecutor will be automatically registered on construction due to the auto
// yield policy, so it can receive invalidations when we remove documents later.
- Status execStatus = PlanExecutor::make(
- &_txn, ws.release(), ss.release(), coll, PlanExecutor::YIELD_AUTO, &exec);
- invariant(execStatus.isOK());
- return exec;
+ auto statusWithPlanExecutor =
+ PlanExecutor::make(&_txn, std::move(ws), std::move(ss), coll, PlanExecutor::YIELD_AUTO);
+ invariant(statusWithPlanExecutor.isOK());
+ return statusWithPlanExecutor.getValue().release();
}
// Return a value in the set {-1, 0, 1} to represent the sign of parameter i. Used to
@@ -135,8 +136,8 @@ public:
* If limit is not zero, we limit the output of the sort stage to 'limit' results.
*/
void sortAndCheck(int direction, Collection* coll) {
- WorkingSet* ws = new WorkingSet();
- QueuedDataStage* ms = new QueuedDataStage(ws);
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
+ QueuedDataStage* ms = new QueuedDataStage(ws.get());
// Insert a mix of the various types of data.
insertVarietyOfObjects(ms, coll);
@@ -146,17 +147,14 @@ public:
params.pattern = BSON("foo" << direction);
params.limit = limit();
+ unique_ptr<FetchStage> fetchStage = make_unique<FetchStage>(
+ &_txn, ws.get(), new SortStage(params, ws.get(), ms), nullptr, coll);
+
// Must fetch so we can look at the doc as a BSONObj.
- PlanExecutor* rawExec;
- Status status =
- PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, new SortStage(params, ws, ms), NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
// Look at pairs of objects to make sure that the sort order is pairwise (and therefore
// totally) correct.
@@ -316,7 +314,7 @@ public:
set<RecordId> locs;
getLocs(&locs, coll);
- std::unique_ptr<PlanExecutor> exec(makePlanExecutorWithSortStage(coll));
+ unique_ptr<PlanExecutor> exec(makePlanExecutorWithSortStage(coll));
SortStage* ss = static_cast<SortStage*>(exec->getRootStage());
QueuedDataStage* ms = static_cast<QueuedDataStage*>(ss->getChildren()[0]);
@@ -425,7 +423,7 @@ public:
set<RecordId> locs;
getLocs(&locs, coll);
- std::unique_ptr<PlanExecutor> exec(makePlanExecutorWithSortStage(coll));
+ unique_ptr<PlanExecutor> exec(makePlanExecutorWithSortStage(coll));
SortStage* ss = static_cast<SortStage*>(exec->getRootStage());
QueuedDataStage* ms = static_cast<QueuedDataStage*>(ss->getChildren()[0]);
@@ -514,8 +512,8 @@ public:
wuow.commit();
}
- WorkingSet* ws = new WorkingSet();
- QueuedDataStage* ms = new QueuedDataStage(ws);
+ unique_ptr<WorkingSet> ws = make_unique<WorkingSet>();
+ QueuedDataStage* ms = new QueuedDataStage(ws.get());
for (int i = 0; i < numObj(); ++i) {
WorkingSetMember member;
@@ -534,16 +532,12 @@ public:
params.pattern = BSON("b" << -1 << "c" << 1 << "a" << 1);
params.limit = 0;
+ unique_ptr<FetchStage> fetchStage = make_unique<FetchStage>(
+ &_txn, ws.get(), new SortStage(params, ws.get(), ms), nullptr, coll);
// We don't get results back since we're sorting some parallel arrays.
- PlanExecutor* rawExec;
- Status status =
- PlanExecutor::make(&_txn,
- ws,
- new FetchStage(&_txn, ws, new SortStage(params, ws, ms), NULL, coll),
- coll,
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(fetchStage), coll, PlanExecutor::YIELD_MANUAL);
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
PlanExecutor::ExecState runnerState = exec->getNext(NULL, NULL);
ASSERT_EQUALS(PlanExecutor::FAILURE, runnerState);
diff --git a/src/mongo/dbtests/query_stage_tests.cpp b/src/mongo/dbtests/query_stage_tests.cpp
index 2f7d59b3aa6..73dc9e9f23e 100644
--- a/src/mongo/dbtests/query_stage_tests.cpp
+++ b/src/mongo/dbtests/query_stage_tests.cpp
@@ -38,6 +38,7 @@
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/dbtests/dbtests.h"
+#include "mongo/stdx/memory.h"
/**
* This file tests db/exec/index_scan.cpp
@@ -80,17 +81,14 @@ public:
verify(swme.isOK());
unique_ptr<MatchExpression> filterExpr(swme.getValue());
- WorkingSet* ws = new WorkingSet();
-
- PlanExecutor* rawExec;
- Status status = PlanExecutor::make(&_txn,
- ws,
- new IndexScan(&_txn, params, ws, filterExpr.get()),
- ctx.getCollection(),
- PlanExecutor::YIELD_MANUAL,
- &rawExec);
- ASSERT_OK(status);
- std::unique_ptr<PlanExecutor> exec(rawExec);
+ unique_ptr<WorkingSet> ws = stdx::make_unique<WorkingSet>();
+ unique_ptr<IndexScan> ix =
+ stdx::make_unique<IndexScan>(&_txn, params, ws.get(), filterExpr.get());
+
+ auto statusWithPlanExecutor = PlanExecutor::make(
+ &_txn, std::move(ws), std::move(ix), ctx.getCollection(), PlanExecutor::YIELD_MANUAL);
+ ASSERT_OK(statusWithPlanExecutor.getStatus());
+ unique_ptr<PlanExecutor> exec = std::move(statusWithPlanExecutor.getValue());
int count = 0;
for (RecordId dl; PlanExecutor::ADVANCED == exec->getNext(NULL, &dl);) {