summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/s2_access_method.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/index/s2_access_method.cpp')
-rw-r--r--src/mongo/db/index/s2_access_method.cpp111
1 files changed, 55 insertions, 56 deletions
diff --git a/src/mongo/db/index/s2_access_method.cpp b/src/mongo/db/index/s2_access_method.cpp
index a9c9630ef67..3fcf4d013a1 100644
--- a/src/mongo/db/index/s2_access_method.cpp
+++ b/src/mongo/db/index/s2_access_method.cpp
@@ -44,67 +44,66 @@
namespace mongo {
- static const string kIndexVersionFieldName("2dsphereIndexVersion");
-
- S2AccessMethod::S2AccessMethod(IndexCatalogEntry* btreeState, SortedDataInterface* btree)
- : IndexAccessMethod(btreeState, btree) {
-
- const IndexDescriptor* descriptor = btreeState->descriptor();
-
- ExpressionParams::parse2dsphereParams(descriptor->infoObj(),
- &_params);
-
- int geoFields = 0;
-
- // Categorize the fields we're indexing and make sure we have a geo field.
- BSONObjIterator i(descriptor->keyPattern());
- while (i.more()) {
- BSONElement e = i.next();
- if (e.type() == String && IndexNames::GEO_2DSPHERE == e.String() ) {
- ++geoFields;
- }
- else {
- // We check for numeric in 2d, so that's the check here
- uassert( 16823, (string)"Cannot use " + IndexNames::GEO_2DSPHERE +
- " index with other special index types: " + e.toString(),
- e.isNumber() );
- }
- }
-
- uassert(16750, "Expect at least one geo field, spec=" + descriptor->keyPattern().toString(),
- geoFields >= 1);
-
- if (descriptor->isSparse()) {
- warning() << "Sparse option ignored for index spec "
- << descriptor->keyPattern().toString() << "\n";
+static const string kIndexVersionFieldName("2dsphereIndexVersion");
+
+S2AccessMethod::S2AccessMethod(IndexCatalogEntry* btreeState, SortedDataInterface* btree)
+ : IndexAccessMethod(btreeState, btree) {
+ const IndexDescriptor* descriptor = btreeState->descriptor();
+
+ ExpressionParams::parse2dsphereParams(descriptor->infoObj(), &_params);
+
+ int geoFields = 0;
+
+ // Categorize the fields we're indexing and make sure we have a geo field.
+ BSONObjIterator i(descriptor->keyPattern());
+ while (i.more()) {
+ BSONElement e = i.next();
+ if (e.type() == String && IndexNames::GEO_2DSPHERE == e.String()) {
+ ++geoFields;
+ } else {
+ // We check for numeric in 2d, so that's the check here
+ uassert(16823,
+ (string) "Cannot use " + IndexNames::GEO_2DSPHERE +
+ " index with other special index types: " + e.toString(),
+ e.isNumber());
}
}
- // static
- BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) {
- // If the spec object has the field "2dsphereIndexVersion", validate it. If it doesn't, add
- // {2dsphereIndexVersion: 2}, which is the default for newly-built indexes.
-
- BSONElement indexVersionElt = specObj[kIndexVersionFieldName];
- if (indexVersionElt.eoo()) {
- BSONObjBuilder bob;
- bob.appendElements(specObj);
- bob.append(kIndexVersionFieldName, S2_INDEX_VERSION_2);
- return bob.obj();
- }
+ uassert(16750,
+ "Expect at least one geo field, spec=" + descriptor->keyPattern().toString(),
+ geoFields >= 1);
- const int indexVersion = indexVersionElt.numberInt();
- uassert(17394,
- str::stream() << "unsupported geo index version { " << kIndexVersionFieldName
- << " : " << indexVersionElt << " }, only support versions: ["
- << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "]",
- indexVersionElt.isNumber() && (indexVersion == S2_INDEX_VERSION_2
- || indexVersion == S2_INDEX_VERSION_1));
- return specObj;
+ if (descriptor->isSparse()) {
+ warning() << "Sparse option ignored for index spec " << descriptor->keyPattern().toString()
+ << "\n";
}
-
- void S2AccessMethod::getKeys(const BSONObj& obj, BSONObjSet* keys) const {
- ExpressionKeysPrivate::getS2Keys(obj, _descriptor->keyPattern(), _params, keys);
+}
+
+// static
+BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) {
+ // If the spec object has the field "2dsphereIndexVersion", validate it. If it doesn't, add
+ // {2dsphereIndexVersion: 2}, which is the default for newly-built indexes.
+
+ BSONElement indexVersionElt = specObj[kIndexVersionFieldName];
+ if (indexVersionElt.eoo()) {
+ BSONObjBuilder bob;
+ bob.appendElements(specObj);
+ bob.append(kIndexVersionFieldName, S2_INDEX_VERSION_2);
+ return bob.obj();
}
+ const int indexVersion = indexVersionElt.numberInt();
+ uassert(17394,
+ str::stream() << "unsupported geo index version { " << kIndexVersionFieldName << " : "
+ << indexVersionElt << " }, only support versions: [" << S2_INDEX_VERSION_1
+ << "," << S2_INDEX_VERSION_2 << "]",
+ indexVersionElt.isNumber() &&
+ (indexVersion == S2_INDEX_VERSION_2 || indexVersion == S2_INDEX_VERSION_1));
+ return specObj;
+}
+
+void S2AccessMethod::getKeys(const BSONObj& obj, BSONObjSet* keys) const {
+ ExpressionKeysPrivate::getS2Keys(obj, _descriptor->keyPattern(), _params, keys);
+}
+
} // namespace mongo