summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2014-12-02 19:51:44 -0500
committerBenety Goh <benety@mongodb.com>2014-12-03 11:55:06 -0500
commit67ed2dc89414df8dcd951fae9964fc3c5b5d0b46 (patch)
treecd0ce71c3ef636404600216e8b285ff5341b0217
parent5ebf0f69ee53cde7c5d2a1289609ee1692705c97 (diff)
downloadmongo-67ed2dc89414df8dcd951fae9964fc3c5b5d0b46.tar.gz
SERVER-16233 common function to validate both collection and index storage options
-rw-r--r--src/mongo/db/catalog/database.cpp42
-rw-r--r--src/mongo/db/global_environment_experiment.cpp39
-rw-r--r--src/mongo/db/global_environment_experiment.h14
3 files changed, 54 insertions, 41 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index 3538c324a9a..88c46cce27c 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -569,45 +569,6 @@ namespace mongo {
getGlobalEnvironment()->getGlobalStorageEngine()->dropDatabase( txn, name );
}
-namespace {
- /*
- * Extracts the storageEngine bson from the CollectionOptions provided. Loops through each
- * provided storageEngine and asks the matching registered storage engine if the collection
- * options are valid. Returns an error if the collection options are invalid.
- * If no matching registered storage engine is found, return an error.
- */
- Status validateStorageOptions(const CollectionOptions& options) {
- BSONObjIterator storageIt(options.storageEngine);
-
- while (storageIt.more()) {
- BSONElement storageElement = storageIt.next();
- StringData storageEngineName = storageElement.fieldNameStringData();
- invariant(storageElement.type() == mongo::Object);
-
- boost::scoped_ptr<StorageFactoriesIterator> sfi(getGlobalEnvironment()->
- makeStorageFactoriesIterator());
- invariant(sfi);
- bool found = false;
- while (sfi->more()) {
- const StorageEngine::Factory* const& factory = sfi->next();
- if (storageEngineName != factory->getCanonicalName()) {
- continue;
- }
- Status status = factory->validateCollectionStorageOptions(storageElement.Obj());
- if ( !status.isOK() ) {
- return status;
- }
- found = true;
- }
- if (!found) {
- return Status(ErrorCodes::InvalidOptions, str::stream() << storageEngineName <<
- " is not a registered storage engine for this server");
- }
- }
- return Status::OK();
- }
-}
-
/** { ..., capped: true, size: ..., max: ... }
* @param createDefaultIndexes - if false, defers id (and other) index creation.
* @return true if successful
@@ -638,7 +599,8 @@ namespace {
if ( !status.isOK() )
return status;
- status = validateStorageOptions(collectionOptions);
+ status = validateStorageOptions(collectionOptions.storageEngine,
+ &StorageEngine::Factory::validateCollectionStorageOptions);
if ( !status.isOK() )
return status;
diff --git a/src/mongo/db/global_environment_experiment.cpp b/src/mongo/db/global_environment_experiment.cpp
index 33c07025c7d..9e6ebe75257 100644
--- a/src/mongo/db/global_environment_experiment.cpp
+++ b/src/mongo/db/global_environment_experiment.cpp
@@ -30,9 +30,10 @@
#include "mongo/db/global_environment_experiment.h"
+#include "mongo/bson/bsonobjiterator.h"
#include "mongo/db/operation_context.h"
#include "mongo/util/assert_util.h"
-
+#include "mongo/util/mongoutils/str.h"
namespace mongo {
@@ -82,4 +83,40 @@ namespace mongo {
return true;
}
+ Status validateStorageOptions(const BSONObj& storageEngineOptions,
+ stdx::function<Status (const StorageEngine::Factory* const, const BSONObj&)> validateFunc) {
+
+ BSONObjIterator storageIt(storageEngineOptions);
+ while (storageIt.more()) {
+ BSONElement storageElement = storageIt.next();
+ StringData storageEngineName = storageElement.fieldNameStringData();
+ if (storageElement.type() != mongo::Object) {
+ return Status(ErrorCodes::BadValue, str::stream()
+ << "'storageEngine." << storageElement.fieldNameStringData()
+ << "' has to be an embedded document.");
+ }
+
+ boost::scoped_ptr<StorageFactoriesIterator> sfi(getGlobalEnvironment()->
+ makeStorageFactoriesIterator());
+ invariant(sfi);
+ bool found = false;
+ while (sfi->more()) {
+ const StorageEngine::Factory* const& factory = sfi->next();
+ if (storageEngineName != factory->getCanonicalName()) {
+ continue;
+ }
+ Status status = validateFunc(factory, storageElement.Obj());
+ if ( !status.isOK() ) {
+ return status;
+ }
+ found = true;
+ }
+ if (!found) {
+ return Status(ErrorCodes::InvalidOptions, str::stream() << storageEngineName <<
+ " is not a registered storage engine for this server");
+ }
+ }
+ return Status::OK();
+ }
+
} // namespace mongo
diff --git a/src/mongo/db/global_environment_experiment.h b/src/mongo/db/global_environment_experiment.h
index 81be028b4ca..67d87bd5437 100644
--- a/src/mongo/db/global_environment_experiment.h
+++ b/src/mongo/db/global_environment_experiment.h
@@ -30,6 +30,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/db/storage/storage_engine.h"
+#include "mongo/stdx/functional.h"
namespace mongo {
@@ -230,4 +231,17 @@ namespace mongo {
*/
bool isMMAPV1();
+ /*
+ * Extracts the storageEngine bson from the CollectionOptions provided. Loops through each
+ * provided storageEngine and asks the matching registered storage engine if the
+ * collection/index options are valid. Returns an error if the collection/index options are
+ * invalid.
+ * If no matching registered storage engine is found, return an error.
+ * Validation function 'func' must be either:
+ * - &StorageEngine::Factory::validateCollectionStorageOptions; or
+ * - &StorageEngine::Factory::validateIndexStorageOptions
+ */
+ Status validateStorageOptions(const BSONObj& storageEngineOptions,
+ stdx::function<Status (const StorageEngine::Factory* const, const BSONObj&)> validateFunc);
+
} // namespace mongo