summaryrefslogtreecommitdiff
path: root/src/mongo/s/mongos_options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/mongos_options.cpp')
-rw-r--r--src/mongo/s/mongos_options.cpp151
1 files changed, 150 insertions, 1 deletions
diff --git a/src/mongo/s/mongos_options.cpp b/src/mongo/s/mongos_options.cpp
index b73e5898e15..fd0027c6551 100644
--- a/src/mongo/s/mongos_options.cpp
+++ b/src/mongo/s/mongos_options.cpp
@@ -19,19 +19,25 @@
#include <string>
#include <vector>
+#include "mongo/base/init.h"
#include "mongo/base/status.h"
#include "mongo/bson/util/builder.h"
#include "mongo/db/server_options.h"
+#include "mongo/s/chunk.h"
+#include "mongo/s/version_mongos.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/options_parser/option_description.h"
#include "mongo/util/options_parser/option_section.h"
+#include "mongo/util/options_parser/options_parser.h"
+#include "mongo/util/startup_test.h"
+#include "mongo/util/stringutils.h"
namespace mongo {
typedef moe::OptionDescription OD;
typedef moe::PositionalOptionDescription POD;
- extern std::string dbpath;
+ MongosGlobalParams mongosGlobalParams;
Status addMongosOptions(moe::OptionSection* options) {
@@ -124,4 +130,147 @@ namespace mongo {
return Status::OK();
}
+ void printMongosHelp(const moe::OptionSection& options) {
+ std::cout << options.helpString() << std::endl;
+ };
+
+ Status handlePreValidationMongosOptions(const moe::Environment& params,
+ const std::vector<std::string>& args) {
+ if (params.count("help")) {
+ printMongosHelp(serverOptions);
+ ::_exit(EXIT_SUCCESS);
+ }
+ if (params.count("version")) {
+ printShardingVersionInfo(true);
+ ::_exit(EXIT_SUCCESS);
+ }
+
+ return Status::OK();
+ }
+
+ Status storeMongosOptions(const moe::Environment& params,
+ const std::vector<std::string>& args) {
+
+ Status ret = storeServerOptions(params, args);
+ if (!ret.isOK()) {
+ std::cerr << "Error storing command line: " << ret.toString() << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+
+ if ( params.count( "chunkSize" ) ) {
+ int csize = params["chunkSize"].as<int>();
+
+ // validate chunksize before proceeding
+ if ( csize == 0 ) {
+ std::cerr << "error: need a non-zero chunksize" << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+
+ if ( !Chunk::setMaxChunkSizeSizeMB( csize ) ) {
+ std::cerr << "MaxChunkSize invalid" << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+ }
+
+ if (params.count( "port" ) ) {
+ int port = params["port"].as<int>();
+ if ( port <= 0 || port > 65535 ) {
+ out() << "error: port number must be between 1 and 65535" << endl;
+ ::_exit(EXIT_FAILURE);
+ }
+ }
+
+ if ( params.count( "localThreshold" ) ) {
+ serverGlobalParams.defaultLocalThresholdMillis = params["localThreshold"].as<int>();
+ }
+
+ if ( params.count( "ipv6" ) ) {
+ enableIPv6();
+ }
+
+ if ( params.count( "jsonp" ) ) {
+ serverGlobalParams.jsonp = true;
+ }
+
+ if ( params.count( "test" ) ) {
+ ::mongo::logger::globalLogDomain()->setMinimumLoggedSeverity(
+ ::mongo::logger::LogSeverity::Debug(5));
+ StartupTest::runTests();
+ ::_exit(EXIT_SUCCESS);
+ }
+
+ if (params.count("noscripting")) {
+ // This option currently has no effect for mongos
+ }
+
+ if (params.count("httpinterface")) {
+ if (params.count("nohttpinterface")) {
+ std::cerr << "can't have both --httpinterface and --nohttpinterface" << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+ serverGlobalParams.isHttpInterfaceEnabled = true;
+ }
+
+ if (params.count("noAutoSplit")) {
+ warning() << "running with auto-splitting disabled" << endl;
+ Chunk::ShouldAutoSplit = false;
+ }
+
+ if ( ! params.count( "configdb" ) ) {
+ std::cerr << "error: no args for --configdb" << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+
+ splitStringDelim(params["configdb"].as<std::string>(), &mongosGlobalParams.configdbs, ',');
+ if (mongosGlobalParams.configdbs.size() != 1 && mongosGlobalParams.configdbs.size() != 3) {
+ std::cerr << "need either 1 or 3 configdbs" << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+
+ if (mongosGlobalParams.configdbs.size() == 1) {
+ warning() << "running with 1 config server should be done only for testing purposes "
+ << "and is not recommended for production" << endl;
+ }
+
+ mongosGlobalParams.upgrade = params.count("upgrade");
+
+ return Status::OK();
+ }
+
+ MONGO_INITIALIZER_GENERAL(ParseStartupConfiguration,
+ ("GlobalLogManager"),
+ ("default", "completedStartupConfig"))(InitializerContext* context) {
+
+ serverOptions = moe::OptionSection("Allowed options");
+ Status ret = addMongosOptions(&serverOptions);
+ if (!ret.isOK()) {
+ return ret;
+ }
+
+ moe::OptionsParser parser;
+ ret = parser.run(serverOptions, context->args(), context->env(), &serverParsedOptions);
+ if (!ret.isOK()) {
+ std::cerr << "Error parsing command line: " << ret.toString() << std::endl;
+ std::cerr << "use --help for help" << std::endl;
+ ::_exit(EXIT_BADOPTIONS);
+ }
+
+ ret = handlePreValidationMongosOptions(serverParsedOptions, context->args());
+ if (!ret.isOK()) {
+ return ret;
+ }
+
+ ret = serverParsedOptions.validate();
+ if (!ret.isOK()) {
+ return ret;
+ }
+
+ ret = storeMongosOptions(serverParsedOptions, context->args());
+ if (!ret.isOK()) {
+ return ret;
+ }
+
+ return Status::OK();
+ }
+
} // namespace mongo