Skip to content

Commit b7e0511

Browse files
committed
Make ExpressionContext a simple struct
At some point it should probably be renamed since it has nothing to do with Expressions.
1 parent bab9ab6 commit b7e0511

17 files changed

+61
-139
lines changed

src/mongo/SConscript

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ env.StaticLibrary("coredb", [
341341
"db/pipeline/document_source_sort.cpp",
342342
"db/pipeline/document_source_unwind.cpp",
343343
"db/pipeline/expression.cpp",
344-
"db/pipeline/expression_context.cpp",
345344
"db/pipeline/field_path.cpp",
346345
"db/pipeline/value.cpp",
347346
"db/projection.cpp",

src/mongo/db/commands/pipeline_command.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace mongo {
212212
string ns = parseNs(db, cmdObj);
213213

214214
intrusive_ptr<ExpressionContext> pCtx =
215-
ExpressionContext::create(&InterruptStatusMongod::status, NamespaceString(ns));
215+
new ExpressionContext(InterruptStatusMongod::status, NamespaceString(ns));
216216

217217
/* try to parse the command; if this fails, then we didn't run */
218218
intrusive_ptr<Pipeline> pPipeline = Pipeline::parseCommand(errmsg, cmdObj, pCtx);
@@ -227,7 +227,7 @@ namespace mongo {
227227
#if _DEBUG
228228
// This is outside of the if block to keep the object alive until the pipeline is finished.
229229
BSONObj parsed;
230-
if (!pPipeline->isExplain() && !pCtx->getInShard()) {
230+
if (!pPipeline->isExplain() && !pCtx->inShard) {
231231
// Make sure all operations round-trip through Pipeline::toBson()
232232
// correctly by reparsing every command on DEBUG builds. This is
233233
// important because sharded aggregations rely on this ability.
@@ -281,7 +281,7 @@ namespace mongo {
281281
intrusive_ptr<Pipeline>& pPipeline,
282282
intrusive_ptr<ExpressionContext>& pCtx) {
283283
/* setup as if we're in the router */
284-
pCtx->setInRouter(true);
284+
pCtx->inRouter = true;
285285

286286
/*
287287
Here, we'll split the pipeline in the same way we would for sharding,
@@ -315,8 +315,8 @@ namespace mongo {
315315
}
316316

317317
/* on the shard servers, create the local pipeline */
318-
intrusive_ptr<ExpressionContext> pShardCtx(
319-
ExpressionContext::create(&InterruptStatusMongod::status, NamespaceString(ns)));
318+
intrusive_ptr<ExpressionContext> pShardCtx =
319+
new ExpressionContext(InterruptStatusMongod::status, NamespaceString(ns));
320320
intrusive_ptr<Pipeline> pShardPipeline(
321321
Pipeline::parseCommand(errmsg, shardBson, pShardCtx));
322322
if (!pShardPipeline.get()) {

src/mongo/db/interrupt_status.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#pragma once
1818

19-
#include "mongo/pch.h"
20-
2119
namespace mongo {
2220

2321
/**
@@ -38,7 +36,7 @@ namespace mongo {
3836
3937
@throws a uassert if the process has received an interrupt (SIGINT)
4038
*/
41-
virtual void checkForInterrupt() = 0;
39+
virtual void checkForInterrupt() const =0;
4240

4341
/**
4442
Check for interrupt.
@@ -47,7 +45,7 @@ namespace mongo {
4745
"" if there hasn't been an interrupt. These strings are static
4846
and don't need to be freed.
4947
*/
50-
virtual const char *checkForInterruptNoAssert() = 0;
48+
virtual const char *checkForInterruptNoAssert() const =0;
5149

5250
protected:
5351
/**

src/mongo/db/interrupt_status_mongod.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323

2424
namespace mongo {
2525

26-
InterruptStatusMongod InterruptStatusMongod::status;
26+
const InterruptStatusMongod InterruptStatusMongod::status;
2727

2828
InterruptStatusMongod::InterruptStatusMongod() {
2929
}
3030

31-
void InterruptStatusMongod::checkForInterrupt() {
31+
void InterruptStatusMongod::checkForInterrupt() const {
3232
killCurrentOp.checkForInterrupt();
3333
}
3434

35-
const char *InterruptStatusMongod::checkForInterruptNoAssert() {
35+
const char *InterruptStatusMongod::checkForInterruptNoAssert() const {
3636
return killCurrentOp.checkForInterruptNoAssert();
3737
}
3838

src/mongo/db/interrupt_status_mongod.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#pragma once
1818

19-
#include "mongo/pch.h"
2019
#include "mongo/db/interrupt_status.h"
2120

2221
namespace mongo {
@@ -26,13 +25,13 @@ namespace mongo {
2625
boost::noncopyable {
2726
public:
2827
// virtuals from InterruptStatus
29-
virtual void checkForInterrupt();
30-
virtual const char *checkForInterruptNoAssert();
28+
virtual void checkForInterrupt() const;
29+
virtual const char *checkForInterruptNoAssert() const;
3130

3231
/*
3332
Static singleton instance.
3433
*/
35-
static InterruptStatusMongod status;
34+
static const InterruptStatusMongod status;
3635

3736
private:
3837
InterruptStatusMongod();

src/mongo/db/pipeline/document_source_geo_near.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace mongo {
101101

102102
BSONObjBuilder geoNear; // not building a subField
103103

104-
geoNear.append("geoNear", pExpCtx->getNs().coll()); // not in toBson
104+
geoNear.append("geoNear", pExpCtx->ns.coll()); // not in toBson
105105

106106
if (coordsIsArray) {
107107
geoNear.appendArray("near", coords);
@@ -131,7 +131,7 @@ namespace mongo {
131131
massert(16603, "Already ran geoNearCommand",
132132
!resultsIterator);
133133

134-
bool ok = _mongod->directClient()->runCommand(pExpCtx->getNs().db().toString(),
134+
bool ok = _mongod->directClient()->runCommand(pExpCtx->ns.db().toString(),
135135
buildGeoNearCmd(),
136136
cmdOutput);
137137
uassert(16604, "geoNear command failed: " + cmdOutput.toString(),

src/mongo/db/pipeline/document_source_group.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ namespace mongo {
8080
_firstPartOfNextGroup = _sorterIterator->next();
8181
}
8282

83-
return makeDocument(_currentId, _currentAccumulators, pExpCtx->getInShard());
83+
return makeDocument(_currentId, _currentAccumulators, pExpCtx->inShard);
8484

8585
} else {
8686
if (groups.empty())
8787
return boost::none;
8888

8989
Document out = makeDocument(groupsIterator->first,
9090
groupsIterator->second,
91-
pExpCtx->getInShard());
91+
pExpCtx->inShard);
9292

9393
if (++groupsIterator == groups.end())
9494
dispose();
@@ -158,7 +158,7 @@ namespace mongo {
158158
, populated(false)
159159
, _doingMerge(false)
160160
, _spilled(false)
161-
, _extSortAllowed(pExpCtx->getExtSortAllowed() && !pExpCtx->getInRouter())
161+
, _extSortAllowed(pExpCtx->extSortAllowed && !pExpCtx->inRouter)
162162
, _maxMemoryUsageBytes(100*1024*1024)
163163
{}
164164

@@ -391,7 +391,7 @@ namespace mongo {
391391
DEV {
392392
// In debug mode, spill every time we have a duplicate id to stress merge logic.
393393
if (!inserted // is a dup
394-
&& !pExpCtx->getInRouter() // can't spill to disk in router
394+
&& !pExpCtx->inRouter // can't spill to disk in router
395395
&& !_extSortAllowed // don't change behavior when testing external sort
396396
&& sortedFiles.size() < 20 // don't open too many FDs
397397
) {

src/mongo/db/pipeline/document_source_merge_cursors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace mongo {
9090
// open each cursor and send message asking for a batch
9191
for (CursorIds::const_iterator it = _cursorIds.begin(); it !=_cursorIds.end(); ++it) {
9292
_cursors.push_back(boost::make_shared<CursorAndConnection>(
93-
it->first, pExpCtx->getNs(), it->second));
93+
it->first, pExpCtx->ns, it->second));
9494
verify(_cursors.back()->connection->lazySupported());
9595
_cursors.back()->cursor.initLazy(); // shouldn't block
9696
}

src/mongo/db/pipeline/document_source_out.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ namespace mongo {
138138
<< typeName(pBsonElement->type()),
139139
pBsonElement->type() == String);
140140

141-
NamespaceString outputNs(pExpCtx->getNs().db().toString() + '.' + pBsonElement->str());
141+
NamespaceString outputNs(pExpCtx->ns.db().toString() + '.' + pBsonElement->str());
142142
return new DocumentSourceOut(outputNs, pExpCtx);
143143
}
144144

145145
void DocumentSourceOut::sourceToBson(BSONObjBuilder *pBuilder, bool explain) const {
146146
massert(17000, "$out shouldn't have different db than input",
147-
_outputNs.db() == pExpCtx->getNs().db());
147+
_outputNs.db() == pExpCtx->ns.db());
148148

149149
pBuilder->append("$out", _outputNs.coll());
150150
}

src/mongo/db/pipeline/document_source_sort.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ namespace mongo {
184184
opts.limit = limitSrc->getLimit();
185185

186186
opts.maxMemoryUsageBytes = 100*1024*1024;
187-
opts.extSortAllowed = pExpCtx->getExtSortAllowed() && !pExpCtx->getInRouter();
187+
opts.extSortAllowed = pExpCtx->extSortAllowed && !pExpCtx->inRouter;
188188

189189
scoped_ptr<MySorter> sorter (MySorter::make(opts, Comparator(*this)));
190190

0 commit comments

Comments
 (0)