summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/s2_access_method.cpp
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2014-02-15 11:40:13 -0500
committerJason Rassi <rassi@10gen.com>2014-02-15 13:56:12 -0500
commitecda90ce4ac91aea66f076aacbbe28f7286a7351 (patch)
tree8ae7880e6f7c19a526c4bea4f187d990db7bb354 /src/mongo/db/index/s2_access_method.cpp
parentb855e3e54b2cbe9e93ab97866b37beef53d12696 (diff)
downloadmongo-ecda90ce4ac91aea66f076aacbbe28f7286a7351.tar.gz
SERVER-12175 Add 2dsphere index option "2dsphereIndexVersion"
- Defines version 1 and 2; both are supported. - Indexes without this option are assumed to be version 1. - New builds get version 2 (if version unspecified). - Version 1 throws in getKeys if the geometry is one of the types introduced since 2.4.0 (MultiPoint, MultiLineString, MultiPolygon, GeometryCollection).
Diffstat (limited to 'src/mongo/db/index/s2_access_method.cpp')
-rw-r--r--src/mongo/db/index/s2_access_method.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mongo/db/index/s2_access_method.cpp b/src/mongo/db/index/s2_access_method.cpp
index 328c7031550..fff6fbba7f3 100644
--- a/src/mongo/db/index/s2_access_method.cpp
+++ b/src/mongo/db/index/s2_access_method.cpp
@@ -38,6 +38,8 @@
#include "mongo/db/jsobj.h"
namespace mongo {
+ static const string kIndexVersionFieldName("2dsphereIndexVersion");
+
static int configValueWithDefault(const IndexDescriptor *desc, const string& name, int def) {
BSONElement e = desc->getInfoElement(name);
if (e.isNumber()) { return e.numberInt(); }
@@ -60,10 +62,21 @@ namespace mongo {
S2::kAvgEdge.GetClosestLevel(500.0 / _params.radius));
_params.coarsestIndexedLevel = configValueWithDefault(descriptor, "coarsestIndexedLevel",
S2::kAvgEdge.GetClosestLevel(100 * 1000.0 / _params.radius));
+ // Determine which version of this index we're using. If none was set in the descriptor,
+ // assume S2_INDEX_VERSION_1 (alas, the first version predates the existence of the version
+ // field).
+ _params.indexVersion = static_cast<S2IndexVersion>(configValueWithDefault(
+ descriptor, kIndexVersionFieldName, S2_INDEX_VERSION_1));
uassert(16747, "coarsestIndexedLevel must be >= 0", _params.coarsestIndexedLevel >= 0);
uassert(16748, "finestIndexedLevel must be <= 30", _params.finestIndexedLevel <= 30);
uassert(16749, "finestIndexedLevel must be >= coarsestIndexedLevel",
_params.finestIndexedLevel >= _params.coarsestIndexedLevel);
+ massert(17395,
+ str::stream() << "unsupported geo index version { " << kIndexVersionFieldName
+ << " : " << _params.indexVersion << " }, only support versions: ["
+ << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "]",
+ _params.indexVersion == S2_INDEX_VERSION_2
+ || _params.indexVersion == S2_INDEX_VERSION_1);
int geoFields = 0;
@@ -85,6 +98,29 @@ namespace mongo {
geoFields >= 1);
}
+ // 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) {
BSONObjSet keysToAdd;
// We output keys in the same order as the fields we index.