~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to src/mongo/db/exec/keep_mutations.cpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *    Copyright (C) 2014 MongoDB Inc.
 
3
 *
 
4
 *    This program is free software: you can redistribute it and/or  modify
 
5
 *    it under the terms of the GNU Affero General Public License, version 3,
 
6
 *    as published by the Free Software Foundation.
 
7
 *
 
8
 *    This program is distributed in the hope that it will be useful,
 
9
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *    GNU Affero General Public License for more details.
 
12
 *
 
13
 *    You should have received a copy of the GNU Affero General Public License
 
14
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 *    As a special exception, the copyright holders give permission to link the
 
17
 *    code of portions of this program with the OpenSSL library under certain
 
18
 *    conditions as described in each individual source file and distribute
 
19
 *    linked combinations including the program with the OpenSSL library. You
 
20
 *    must comply with the GNU Affero General Public License in all respects for
 
21
 *    all of the code used other than as permitted herein. If you modify file(s)
 
22
 *    with this exception, you may extend this exception to your version of the
 
23
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 
24
 *    delete this exception statement from your version. If you delete this
 
25
 *    exception statement from all source files in the program, then also delete
 
26
 *    it in the license file.
 
27
 */
 
28
 
 
29
#include "mongo/db/exec/keep_mutations.h"
 
30
#include "mongo/db/exec/filter.h"
 
31
 
 
32
namespace mongo {
 
33
 
 
34
    KeepMutationsStage::KeepMutationsStage(const MatchExpression* filter,
 
35
                                           WorkingSet* ws,
 
36
                                           PlanStage* child)
 
37
        : _workingSet(ws),
 
38
          _child(child),
 
39
          _filter(filter),
 
40
          _doneReadingChild(false),
 
41
          _doneReturningFlagged(false) { }
 
42
 
 
43
    KeepMutationsStage::~KeepMutationsStage() { }
 
44
 
 
45
    bool KeepMutationsStage::isEOF() {
 
46
        return _doneReadingChild && _doneReturningFlagged;
 
47
    }
 
48
 
 
49
    PlanStage::StageState KeepMutationsStage::work(WorkingSetID* out) {
 
50
        ++_commonStats.works;
 
51
 
 
52
        // If we've returned as many results as we're limited to, isEOF will be true.
 
53
        if (isEOF()) { return PlanStage::IS_EOF; }
 
54
 
 
55
        // Stream child results until the child is all done.
 
56
        if (!_doneReadingChild) {
 
57
            StageState status = _child->work(out);
 
58
 
 
59
            // Child is still returning results.  Pass them through.
 
60
            if (PlanStage::IS_EOF != status) {
 
61
                if (PlanStage::ADVANCED == status) {
 
62
                    ++_commonStats.advanced;
 
63
                }
 
64
                else if (PlanStage::NEED_TIME == status) {
 
65
                    ++_commonStats.needTime;
 
66
                }
 
67
                else if (PlanStage::NEED_FETCH == status) {
 
68
                    ++_commonStats.needFetch;
 
69
                }
 
70
 
 
71
                return status;
 
72
            }
 
73
 
 
74
            // Child is EOF.  We want to stream flagged results if there are any.
 
75
            _doneReadingChild = true;
 
76
            _flaggedIterator = _workingSet->getFlagged().begin();
 
77
        }
 
78
 
 
79
        // We're streaming flagged results.
 
80
        invariant(!_doneReturningFlagged);
 
81
        if (_flaggedIterator == _workingSet->getFlagged().end()) {
 
82
            _doneReturningFlagged = true;
 
83
            return PlanStage::IS_EOF;
 
84
        }
 
85
 
 
86
        WorkingSetID idToTest = *_flaggedIterator;
 
87
        _flaggedIterator++;
 
88
 
 
89
        WorkingSetMember* member = _workingSet->get(idToTest);
 
90
        if (Filter::passes(member, _filter)) {
 
91
            *out = idToTest;
 
92
            ++_commonStats.advanced;
 
93
            return PlanStage::ADVANCED;
 
94
        }
 
95
        else {
 
96
            _workingSet->free(idToTest);
 
97
            ++_commonStats.needTime;
 
98
            return PlanStage::NEED_TIME;
 
99
        }
 
100
    }
 
101
 
 
102
    void KeepMutationsStage::prepareToYield() {
 
103
        ++_commonStats.yields;
 
104
        _child->prepareToYield();
 
105
    }
 
106
 
 
107
    void KeepMutationsStage::recoverFromYield() {
 
108
        ++_commonStats.unyields;
 
109
        _child->recoverFromYield();
 
110
    }
 
111
 
 
112
    void KeepMutationsStage::invalidate(const DiskLoc& dl, InvalidationType type) {
 
113
        ++_commonStats.invalidates;
 
114
        _child->invalidate(dl, type);
 
115
    }
 
116
 
 
117
    PlanStageStats* KeepMutationsStage::getStats() {
 
118
        _commonStats.isEOF = isEOF();
 
119
        auto_ptr<PlanStageStats> ret(new PlanStageStats(_commonStats, STAGE_KEEP_MUTATIONS));
 
120
        // Takes ownership of the object returned from _child->getStats().
 
121
        ret->children.push_back(_child->getStats());
 
122
        return ret.release();
 
123
    }
 
124
 
 
125
}  // namespace mongo