summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
authorU-tellus\cwestin <cwestin@10gen.com>2012-02-15 16:33:17 -0800
committerU-tellus\cwestin <cwestin@10gen.com>2012-02-15 19:14:06 -0800
commit7ada09610e73211856e4ca906eb06d54d2354641 (patch)
tree1f141e35b5f40c4d84d1ef52ccb9b687769f935f /src/mongo/db/pipeline
parentc94d2c910a2cd185c804abffe4bdbdfa28cc598e (diff)
downloadmongo-7ada09610e73211856e4ca906eb06d54d2354641.tar.gz
SERVER-4844
Diffstat (limited to 'src/mongo/db/pipeline')
-rwxr-xr-xsrc/mongo/db/pipeline/document_source.h6
-rw-r--r--src/mongo/db/pipeline/document_source_limit.cpp15
-rw-r--r--src/mongo/db/pipeline/document_source_skip.cpp14
-rwxr-xr-xsrc/mongo/db/pipeline/expression_context.cpp15
-rwxr-xr-xsrc/mongo/db/pipeline/expression_context.h7
5 files changed, 45 insertions, 12 deletions
diff --git a/src/mongo/db/pipeline/document_source.h b/src/mongo/db/pipeline/document_source.h
index 0a3614198e7..f3fba64922a 100755
--- a/src/mongo/db/pipeline/document_source.h
+++ b/src/mongo/db/pipeline/document_source.h
@@ -953,8 +953,9 @@ namespace mongo {
virtual ~DocumentSourceLimit();
virtual bool eof();
virtual bool advance();
- virtual const char *getSourceName() const;
virtual intrusive_ptr<Document> getCurrent();
+ virtual const char *getSourceName() const;
+ virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSource);
/**
Create a new limiting DocumentSource.
@@ -1003,8 +1004,9 @@ namespace mongo {
virtual ~DocumentSourceSkip();
virtual bool eof();
virtual bool advance();
- virtual const char *getSourceName() const;
virtual intrusive_ptr<Document> getCurrent();
+ virtual const char *getSourceName() const;
+ virtual bool coalesce(const intrusive_ptr<DocumentSource> &pNextSource);
/**
Create a new skipping DocumentSource.
diff --git a/src/mongo/db/pipeline/document_source_limit.cpp b/src/mongo/db/pipeline/document_source_limit.cpp
index 74fefbd0424..7b04a6c02ce 100644
--- a/src/mongo/db/pipeline/document_source_limit.cpp
+++ b/src/mongo/db/pipeline/document_source_limit.cpp
@@ -41,6 +41,21 @@ namespace mongo {
return limitName;
}
+ bool DocumentSourceLimit::coalesce(
+ const intrusive_ptr<DocumentSource> &pNextSource) {
+ DocumentSourceLimit *pLimit =
+ dynamic_cast<DocumentSourceLimit *>(pNextSource.get());
+
+ /* if it's not another $skip, we can't coalesce */
+ if (!pLimit)
+ return false;
+
+ /* we need to limit by the minimum of the two limits */
+ if (pLimit->limit < limit)
+ limit = pLimit->limit;
+ return true;
+ }
+
bool DocumentSourceLimit::eof() {
return pSource->eof() || count >= limit;
}
diff --git a/src/mongo/db/pipeline/document_source_skip.cpp b/src/mongo/db/pipeline/document_source_skip.cpp
index f0b2d3d44d9..605f85e7f92 100644
--- a/src/mongo/db/pipeline/document_source_skip.cpp
+++ b/src/mongo/db/pipeline/document_source_skip.cpp
@@ -42,6 +42,20 @@ namespace mongo {
return skipName;
}
+ bool DocumentSourceSkip::coalesce(
+ const intrusive_ptr<DocumentSource> &pNextSource) {
+ DocumentSourceSkip *pSkip =
+ dynamic_cast<DocumentSourceSkip *>(pNextSource.get());
+
+ /* if it's not another $skip, we can't coalesce */
+ if (!pSkip)
+ return false;
+
+ /* we need to skip over the sum of the two consecutive $skips */
+ skip += pSkip->skip;
+ return true;
+ }
+
void DocumentSourceSkip::skipper() {
if (count == 0) {
while (!pSource->eof() && count++ < skip) {
diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp
index cfde1670bfb..b56b243f25f 100755
--- a/src/mongo/db/pipeline/expression_context.cpp
+++ b/src/mongo/db/pipeline/expression_context.cpp
@@ -16,7 +16,7 @@
#include "pch.h"
-#include "db/curop.h"
+#include "db/interrupt_status.h"
#include "db/pipeline/expression_context.h"
namespace mongo {
@@ -24,10 +24,11 @@ namespace mongo {
ExpressionContext::~ExpressionContext() {
}
- inline ExpressionContext::ExpressionContext():
+ inline ExpressionContext::ExpressionContext(InterruptStatus *pS):
inShard(false),
inRouter(false),
- intCheckCounter(1) {
+ intCheckCounter(1),
+ pStatus(pS) {
}
void ExpressionContext::checkForInterrupt() {
@@ -35,14 +36,12 @@ namespace mongo {
Only really check periodically; the check gets a mutex, and could
be expensive, at least in relative terms.
*/
-#ifdef MONGO_LATER_SERVER_4844
if ((++intCheckCounter % 128) == 0)
- killCurrentOp.checkForInterrupt();
-#endif /* MONGO_LATER_SERVER_4844 */
+ pStatus->checkForInterrupt();
}
- ExpressionContext *ExpressionContext::create() {
- return new ExpressionContext();
+ ExpressionContext *ExpressionContext::create(InterruptStatus *pStatus) {
+ return new ExpressionContext(pStatus);
}
}
diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h
index 0f4de1461ae..893826af222 100755
--- a/src/mongo/db/pipeline/expression_context.h
+++ b/src/mongo/db/pipeline/expression_context.h
@@ -22,6 +22,8 @@
namespace mongo {
+ class InterruptStatus;
+
class ExpressionContext :
public IntrusiveCounterUnsigned {
public:
@@ -40,14 +42,15 @@ namespace mongo {
*/
void checkForInterrupt();
- static ExpressionContext *create();
+ static ExpressionContext *create(InterruptStatus *pStatus);
private:
- ExpressionContext();
+ ExpressionContext(InterruptStatus *pStatus);
bool inShard;
bool inRouter;
unsigned intCheckCounter; // interrupt check counter
+ InterruptStatus *const pStatus;
};
}