diff options
author | Benety Goh <benety@mongodb.com> | 2014-12-02 15:31:58 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2014-12-03 11:55:07 -0500 |
commit | 225aa52bd22a54d06cc090e7cd4b0fd4312213b2 (patch) | |
tree | 0f39645d6c5fe5952107eb96e7d0670143d263e7 | |
parent | 67ed2dc89414df8dcd951fae9964fc3c5b5d0b46 (diff) | |
download | mongo-225aa52bd22a54d06cc090e7cd4b0fd4312213b2.tar.gz |
SERVER-16233 validate storage engine options at index creation
-rw-r--r-- | src/mongo/db/catalog/index_catalog.cpp | 21 | ||||
-rw-r--r-- | src/mongo/dbtests/indexupdatetests.cpp | 47 |
2 files changed, 68 insertions, 0 deletions
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp index c2360ea12d6..379b78ca1ee 100644 --- a/src/mongo/db/catalog/index_catalog.cpp +++ b/src/mongo/db/catalog/index_catalog.cpp @@ -60,6 +60,7 @@ #include "mongo/db/operation_context.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" +#include "mongo/util/mongoutils/str.h" namespace mongo { @@ -579,6 +580,26 @@ namespace { } } + BSONElement storageEngineElement = spec.getField("storageEngine"); + if (storageEngineElement.eoo()) { + return Status::OK(); + } + if (storageEngineElement.type() != mongo::Object) { + return Status(ErrorCodes::BadValue, "'storageEngine' has to be a document."); + } + BSONObj storageEngineOptions = storageEngineElement.Obj(); + if (storageEngineOptions.isEmpty()) { + return Status(ErrorCodes::BadValue, + "Empty 'storageEngine' options are invalid. " + "Please remove, or include valid options."); + + } + Status storageEngineStatus = validateStorageOptions(storageEngineOptions, + &StorageEngine::Factory::validateIndexStorageOptions); + if (!storageEngineStatus.isOK()) { + return storageEngineStatus; + } + return Status::OK(); } diff --git a/src/mongo/dbtests/indexupdatetests.cpp b/src/mongo/dbtests/indexupdatetests.cpp index 504d04c528a..f76292e2871 100644 --- a/src/mongo/dbtests/indexupdatetests.cpp +++ b/src/mongo/dbtests/indexupdatetests.cpp @@ -846,6 +846,52 @@ namespace IndexUpdateTests { } }; + class StorageEngineOptions : public IndexBuildBase { + public: + void run() { + // "storageEngine" field has to be an object if present. + ASSERT_NOT_OK(createIndex("unittest", _createSpec(12345))); + + // 'storageEngine' must not be empty. + ASSERT_NOT_OK(createIndex("unittest", _createSpec(BSONObj()))); + + // Every field under "storageEngine" must match a registered storage engine. + ASSERT_NOT_OK(createIndex("unittest", + _createSpec(BSON("unknownEngine" << BSONObj())))); + + // Testing with 'wiredTiger' because the registered storage engine factory + // supports custom index options under 'storageEngine'. + const std::string storageEngineName = "wiredTiger"; + + // Run 'wiredTiger' tests if the storage engine is supported. + if (getGlobalEnvironment()->isRegisteredStorageEngine(storageEngineName)) { + // Every field under "storageEngine" has to be an object. + ASSERT_NOT_OK(createIndex("unittest", _createSpec(BSON(storageEngineName << 1)))); + + // Storage engine options must pass validation by the storage engine factory. + // For 'wiredTiger', embedded document must contain 'configString'. + ASSERT_NOT_OK(createIndex("unittest", _createSpec( + BSON(storageEngineName << BSON("unknown" << 1))))); + + // Configuration string for 'wiredTiger' must be a string. + ASSERT_NOT_OK(createIndex("unittest", _createSpec( + BSON(storageEngineName << BSON("configString" << 1))))); + + // Valid 'wiredTiger' configuration. + ASSERT_OK(createIndex("unittest", _createSpec( + BSON(storageEngineName << BSON("configString" << "block_compressor=zlib"))))); + } + } + protected: + template <typename T> + BSONObj _createSpec(T storageEngineValue) { + return BSON("name" << "super2" + << "ns" << _ns + << "key" << BSON("a" << 1) + << "storageEngine" << storageEngineValue); + } + }; + class IndexCatatalogFixIndexKey { public: void run() { @@ -893,6 +939,7 @@ namespace IndexUpdateTests { add<SameSpecDifferentUnique>(); add<SameSpecDifferentSparse>(); add<SameSpecDifferentTTL>(); + add<StorageEngineOptions>(); add<IndexCatatalogFixIndexKey>(); } |