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

« back to all changes in this revision

Viewing changes to src/mongo/db/index/s2_access_method.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) 2013 10gen 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/index/s2_access_method.h"
 
30
 
 
31
#include <vector>
 
32
 
 
33
#include "mongo/base/status.h"
 
34
#include "mongo/db/geo/geoconstants.h"
 
35
#include "mongo/db/geo/geoparser.h"
 
36
#include "mongo/db/geo/geoquery.h"
 
37
#include "mongo/db/geo/s2.h"
 
38
#include "mongo/db/geo/s2common.h"
 
39
#include "mongo/db/index/expression_params.h"
 
40
#include "mongo/db/index/s2_key_generator.h"
 
41
#include "mongo/db/index_names.h"
 
42
#include "mongo/db/jsobj.h"
 
43
 
 
44
#include "third_party/s2/s2cell.h"
 
45
#include "third_party/s2/s2regioncoverer.h"
 
46
 
 
47
namespace mongo {
 
48
 
 
49
    static const string kIndexVersionFieldName("2dsphereIndexVersion");
 
50
 
 
51
    S2AccessMethod::S2AccessMethod(IndexCatalogEntry* btreeState)
 
52
        : BtreeBasedAccessMethod(btreeState) {
 
53
 
 
54
        const IndexDescriptor* descriptor = btreeState->descriptor();
 
55
 
 
56
        ExpressionParams::parse2dsphereParams(descriptor->infoObj(),
 
57
                                              &_params);
 
58
 
 
59
        _keyGenerator.reset( new S2KeyGenerator( descriptor->keyPattern(), _params ) );
 
60
 
 
61
        int geoFields = 0;
 
62
 
 
63
        // Categorize the fields we're indexing and make sure we have a geo field.
 
64
        BSONObjIterator i(descriptor->keyPattern());
 
65
        while (i.more()) {
 
66
            BSONElement e = i.next();
 
67
            if (e.type() == String && IndexNames::GEO_2DSPHERE == e.String() ) {
 
68
                ++geoFields;
 
69
            }
 
70
            else {
 
71
                // We check for numeric in 2d, so that's the check here
 
72
                uassert( 16823, (string)"Cannot use " + IndexNames::GEO_2DSPHERE +
 
73
                                    " index with other special index types: " + e.toString(),
 
74
                         e.isNumber() );
 
75
            }
 
76
        }
 
77
 
 
78
        uassert(16750, "Expect at least one geo field, spec=" + descriptor->keyPattern().toString(),
 
79
                geoFields >= 1);
 
80
 
 
81
        if (descriptor->isSparse()) {
 
82
            warning() << "Sparse option ignored for index spec "
 
83
                      << descriptor->keyPattern().toString() << "\n";
 
84
        }
 
85
    }
 
86
 
 
87
    // static
 
88
    BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) {
 
89
        // If the spec object has the field "2dsphereIndexVersion", validate it.  If it doesn't, add
 
90
        // {2dsphereIndexVersion: 2}, which is the default for newly-built indexes.
 
91
 
 
92
        BSONElement indexVersionElt = specObj[kIndexVersionFieldName];
 
93
        if (indexVersionElt.eoo()) {
 
94
            BSONObjBuilder bob;
 
95
            bob.appendElements(specObj);
 
96
            bob.append(kIndexVersionFieldName, S2_INDEX_VERSION_2);
 
97
            return bob.obj();
 
98
        }
 
99
 
 
100
        const int indexVersion = indexVersionElt.numberInt();
 
101
        uassert(17394,
 
102
                str::stream() << "unsupported geo index version { " << kIndexVersionFieldName
 
103
                              << " : " << indexVersionElt << " }, only support versions: ["
 
104
                              << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "]",
 
105
                indexVersionElt.isNumber() && (indexVersion == S2_INDEX_VERSION_2
 
106
                                               || indexVersion == S2_INDEX_VERSION_1));
 
107
        return specObj;
 
108
    }
 
109
 
 
110
    void S2AccessMethod::getKeys(const BSONObj& obj, BSONObjSet* keys) {
 
111
        return _keyGenerator->getKeys( obj, keys );
 
112
    }
 
113
 
 
114
}  // namespace mongo