diff options
author | David Storch <david.storch@10gen.com> | 2016-05-23 17:55:01 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-05-25 14:40:31 -0400 |
commit | 439df4c3bdff0194cff402a6268a9bdb9de44a7a (patch) | |
tree | c1d0c8d613d65516cce48327d183776464016634 /src/mongo/db/index | |
parent | 15deafbf2aa6524f3b05dd729b4ff378e18a2162 (diff) | |
download | mongo-439df4c3bdff0194cff402a6268a9bdb9de44a7a.tar.gz |
SERVER-23945 make IndexCatalog::_fixIndexSpec() use Status instead of throwing
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r-- | src/mongo/db/index/s2_access_method.cpp | 39 | ||||
-rw-r--r-- | src/mongo/db/index/s2_access_method.h | 7 |
2 files changed, 30 insertions, 16 deletions
diff --git a/src/mongo/db/index/s2_access_method.cpp b/src/mongo/db/index/s2_access_method.cpp index c6519519b44..a05f72855dc 100644 --- a/src/mongo/db/index/s2_access_method.cpp +++ b/src/mongo/db/index/s2_access_method.cpp @@ -80,7 +80,7 @@ S2AccessMethod::S2AccessMethod(IndexCatalogEntry* btreeState, SortedDataInterfac } // static -BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) { +StatusWith<BSONObj> S2AccessMethod::fixSpec(const BSONObj& specObj) { // If the spec object has the field "2dsphereIndexVersion", validate it. If it doesn't, add // {2dsphereIndexVersion: 3}, which is the default for newly-built indexes. @@ -92,22 +92,33 @@ BSONObj S2AccessMethod::fixSpec(const BSONObj& specObj) { return bob.obj(); } - uassert(40108, - str::stream() << "Invalid type or value for geo index version { " - << kIndexVersionFieldName << " : " << indexVersionElt - << " }, only versions: [" << S2_INDEX_VERSION_1 << "," - << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported", - indexVersionElt.isNumber() && ((indexVersionElt.type() != mongo::NumberDouble) || - std::isnormal(indexVersionElt.numberDouble()))); + if (!indexVersionElt.isNumber()) { + return {ErrorCodes::CannotCreateIndex, + str::stream() << "Invalid type for geo index version { " << kIndexVersionFieldName + << " : " << indexVersionElt << " }, only versions: [" + << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," + << S2_INDEX_VERSION_3 << "] are supported"}; + } + + if (indexVersionElt.type() == BSONType::NumberDouble && + !std::isnormal(indexVersionElt.numberDouble())) { + return {ErrorCodes::CannotCreateIndex, + str::stream() << "Invalid value for geo index version { " << kIndexVersionFieldName + << " : " << indexVersionElt << " }, only versions: [" + << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," + << S2_INDEX_VERSION_3 << "] are supported"}; + } const auto indexVersion = indexVersionElt.numberLong(); + if (indexVersion != S2_INDEX_VERSION_1 && indexVersion != S2_INDEX_VERSION_2 && + indexVersion != S2_INDEX_VERSION_3) { + return {ErrorCodes::CannotCreateIndex, + str::stream() << "unsupported geo index version { " << kIndexVersionFieldName + << " : " << indexVersionElt << " }, only versions: [" + << S2_INDEX_VERSION_1 << "," << S2_INDEX_VERSION_2 << "," + << S2_INDEX_VERSION_3 << "] are supported"}; + } - uassert(17394, - str::stream() << "unsupported geo index version { " << kIndexVersionFieldName << " : " - << indexVersionElt << " }, only versions: [" << S2_INDEX_VERSION_1 << "," - << S2_INDEX_VERSION_2 << "," << S2_INDEX_VERSION_3 << "] are supported", - (indexVersion == S2_INDEX_VERSION_3 || indexVersion == S2_INDEX_VERSION_2 || - indexVersion == S2_INDEX_VERSION_1)); return specObj; } diff --git a/src/mongo/db/index/s2_access_method.h b/src/mongo/db/index/s2_access_method.h index 7bc819adcce..3d39e10fcc9 100644 --- a/src/mongo/db/index/s2_access_method.h +++ b/src/mongo/db/index/s2_access_method.h @@ -29,6 +29,7 @@ #pragma once #include "mongo/base/status.h" +#include "mongo/base/status_with.h" #include "mongo/db/index/index_access_method.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/index/s2_common.h" @@ -44,9 +45,11 @@ public: * Takes an index spec object for this index and returns a copy tweaked to conform to the * expected format. When an index build is initiated, this function is called on the spec * object the user provides, and the return value of this function is the final spec object - * that gets saved in the index catalog. Throws a UserException if 'specObj' is invalid. + * that gets saved in the index catalog. + * + * Returns a non-OK status if 'specObj' is invalid. */ - static BSONObj fixSpec(const BSONObj& specObj); + static StatusWith<BSONObj> fixSpec(const BSONObj& specObj); private: /** |