summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@10gen.com>2013-02-13 14:28:31 -0500
committerAndy Schwerin <schwerin@10gen.com>2013-02-15 11:33:38 -0500
commit31a2028d80848e1770bf91ced08bae9ca7139d58 (patch)
tree8dc81e94a7685c2c0d3931d7dc8026928729e94d /src/mongo
parenta09abdaa6c93c50d3b58ee97597baff96e02475b (diff)
downloadmongo-31a2028d80848e1770bf91ced08bae9ca7139d58.tar.gz
SERVER-8087 Make it possible to declare startup-only and runtime-only server parameters.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/auth/auth_external_state_server_common.cpp2
-rw-r--r--src/mongo/db/auth/auth_server_parameters.cpp2
-rw-r--r--src/mongo/db/cmdline.cpp7
-rw-r--r--src/mongo/db/commands.cpp5
-rw-r--r--src/mongo/db/commands/parameters.cpp16
-rw-r--r--src/mongo/db/server_extra_log_context.cpp5
-rw-r--r--src/mongo/db/server_parameters.cpp15
-rw-r--r--src/mongo/db/server_parameters.h53
-rw-r--r--src/mongo/db/server_parameters_test.cpp4
9 files changed, 86 insertions, 23 deletions
diff --git a/src/mongo/db/auth/auth_external_state_server_common.cpp b/src/mongo/db/auth/auth_external_state_server_common.cpp
index 201e0c02342..2f34c3c1b1b 100644
--- a/src/mongo/db/auth/auth_external_state_server_common.cpp
+++ b/src/mongo/db/auth/auth_external_state_server_common.cpp
@@ -25,7 +25,7 @@
namespace mongo {
namespace {
- MONGO_EXPORT_SERVER_PARAMETER(enableLocalhostAuthBypass, bool, true);
+ MONGO_EXPORT_STARTUP_SERVER_PARAMETER(enableLocalhostAuthBypass, bool, true);
} // namespace
// NOTE: we default _allowLocalhost to true under the assumption that _checkShouldAllowLocalhost
diff --git a/src/mongo/db/auth/auth_server_parameters.cpp b/src/mongo/db/auth/auth_server_parameters.cpp
index 6c9dbf2abf3..85ae1f11ca8 100644
--- a/src/mongo/db/auth/auth_server_parameters.cpp
+++ b/src/mongo/db/auth/auth_server_parameters.cpp
@@ -21,7 +21,7 @@
namespace mongo {
namespace {
- MONGO_EXPORT_SERVER_PARAMETER(supportCompatibilityFormPrivilegeDocuments, bool, true);
+ MONGO_EXPORT_STARTUP_SERVER_PARAMETER(supportCompatibilityFormPrivilegeDocuments, bool, true);
MONGO_INITIALIZER(AuthSetPrivilegeDocumentCompatibilitySupport)(InitializerContext*) {
AuthorizationManager::setSupportOldStylePrivilegeDocuments(
diff --git a/src/mongo/db/cmdline.cpp b/src/mongo/db/cmdline.cpp
index 6c989bed806..253181d3f1d 100644
--- a/src/mongo/db/cmdline.cpp
+++ b/src/mongo/db/cmdline.cpp
@@ -394,7 +394,12 @@ namespace {
name,
static_cast<ServerParameter*>(NULL));
if (NULL == parameter) {
- cout << "Illegal --option parameter: \"" << name << "\"" << endl;
+ cout << "Illegal --setParameter parameter: \"" << name << "\"" << endl;
+ return false;
+ }
+ if (!parameter->allowedToChangeAtStartup()) {
+ cout << "Cannot use --setParameter to set \"" << name << "\" at startup" <<
+ endl;
return false;
}
Status status = parameter->setFromString(value);
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 919630d33fc..87e9129e612 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -42,10 +42,11 @@ namespace mongo {
int Command::testCommandsEnabled = 0;
namespace {
- // TODO: This should only be settable at the command line, not at runtime. Need SERVER-7778
ExportedServerParameter<int> testCommandsParameter(ServerParameterSet::getGlobal(),
"enableTestCommands",
- &Command::testCommandsEnabled);
+ &Command::testCommandsEnabled,
+ true,
+ false);
}
string Command::parseNsFullyQualified(const string& dbname, const BSONObj& cmdObj) const {
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index 60da2a6a955..3a4c49f4096 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -162,19 +162,27 @@ namespace mongo {
namespace {
ExportedServerParameter<int> LogLevelSetting( ServerParameterSet::getGlobal(),
"logLevel",
- &logLevel );
+ &logLevel,
+ true,
+ true );
ExportedServerParameter<bool> NoTableScanSetting( ServerParameterSet::getGlobal(),
"notablescan",
- &cmdLine.noTableScan );
+ &cmdLine.noTableScan,
+ true,
+ true );
ExportedServerParameter<bool> QuietSetting( ServerParameterSet::getGlobal(),
"quiet",
- &cmdLine.quiet );
+ &cmdLine.quiet,
+ true,
+ true );
ExportedServerParameter<double> SyncdelaySetting( ServerParameterSet::getGlobal(),
"syncdelay",
- &cmdLine.syncdelay );
+ &cmdLine.syncdelay,
+ true,
+ true );
}
}
diff --git a/src/mongo/db/server_extra_log_context.cpp b/src/mongo/db/server_extra_log_context.cpp
index 86c1cad0a0c..866ccc3ac06 100644
--- a/src/mongo/db/server_extra_log_context.cpp
+++ b/src/mongo/db/server_extra_log_context.cpp
@@ -28,10 +28,7 @@ namespace mongo {
namespace {
// Server parameter controlling whether or not user ids are included in log entries.
- //
- // TODO: Only really settable at startup. Changes at runtime won't change behavior; disable
- // them.
- MONGO_EXPORT_SERVER_PARAMETER(logUserIds, int, 0);
+ MONGO_EXPORT_STARTUP_SERVER_PARAMETER(logUserIds, bool, false);
/**
* Note: When appending new strings to the builder, make sure to pass false to the
diff --git a/src/mongo/db/server_parameters.cpp b/src/mongo/db/server_parameters.cpp
index 02f0d1371d5..abf6858e1e1 100644
--- a/src/mongo/db/server_parameters.cpp
+++ b/src/mongo/db/server_parameters.cpp
@@ -26,8 +26,21 @@ namespace mongo {
ServerParameterSet* GLOBAL = NULL;
}
+ ServerParameter::ServerParameter( ServerParameterSet* sps, const std::string& name,
+ bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime )
+ : _name( name ),
+ _allowedToChangeAtStartup( allowedToChangeAtStartup ),
+ _allowedToChangeAtRuntime( allowedToChangeAtRuntime ) {
+
+ if ( sps ) {
+ sps->add( this );
+ }
+ }
+
ServerParameter::ServerParameter( ServerParameterSet* sps, const std::string& name )
- : _name( name ) {
+ : _name( name ),
+ _allowedToChangeAtStartup( true ),
+ _allowedToChangeAtRuntime( true ) {
if ( sps ) {
sps->add( this );
diff --git a/src/mongo/db/server_parameters.h b/src/mongo/db/server_parameters.h
index 328cb4f59a1..c328d905ef4 100644
--- a/src/mongo/db/server_parameters.h
+++ b/src/mongo/db/server_parameters.h
@@ -36,6 +36,8 @@ namespace mongo {
public:
typedef std::map< std::string, ServerParameter* > Map;
+ ServerParameter( ServerParameterSet* sps, const std::string& name,
+ bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime );
ServerParameter( ServerParameterSet* sps, const std::string& name );
virtual ~ServerParameter();
@@ -44,12 +46,12 @@ namespace mongo {
/**
* @return if you can set on command line or config file
*/
- virtual bool allowedToChangeAtStartup() const { return true; }
+ bool allowedToChangeAtStartup() const { return _allowedToChangeAtStartup; }
/**
* @param if you can use (get|set)Parameter
*/
- virtual bool allowedToChangeAtRuntime() const { return true; }
+ bool allowedToChangeAtRuntime() const { return _allowedToChangeAtRuntime; }
virtual void append( BSONObjBuilder& b, const string& name ) = 0;
@@ -60,6 +62,8 @@ namespace mongo {
private:
string _name;
+ bool _allowedToChangeAtStartup;
+ bool _allowedToChangeAtRuntime;
};
class ServerParameterSet {
@@ -76,11 +80,26 @@ namespace mongo {
Map _map;
};
+ /**
+ * Implementation of ServerParameter for reading and writing a server parameter with a given
+ * name and type into a specific C++ variable.
+ */
template<typename T>
class ExportedServerParameter : public ServerParameter {
public:
- ExportedServerParameter( ServerParameterSet* sps, const std::string& name, T* value )
- : ServerParameter( sps, name ), _value( value ) {}
+
+ /**
+ * Construct an ExportedServerParameter in parameter set "sps", named "name", whose storage
+ * is at "value".
+ *
+ * If allowedToChangeAtStartup is true, the parameter may be set at the command line,
+ * e.g. via the --setParameter switch. If allowedToChangeAtRuntime is true, the parameter
+ * may be set at runtime, e.g. via the setParameter command.
+ */
+ ExportedServerParameter( ServerParameterSet* sps, const std::string& name, T* value,
+ bool allowedToChangeAtStartup, bool allowedToChangeAtRuntime)
+ : ServerParameter( sps, name, allowedToChangeAtStartup, allowedToChangeAtRuntime ),
+ _value( value ) {}
virtual ~ExportedServerParameter() {}
virtual void append( BSONObjBuilder& b, const string& name ) {
@@ -100,11 +119,31 @@ namespace mongo {
T* _value; // owned elsewhere
};
+}
+#define MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, \
+ CHANGE_AT_STARTUP, CHANGE_AT_RUNTIME ) \
+ TYPE NAME = INITIAL_VALUE; \
+ ExportedServerParameter<TYPE> _##NAME(\
+ ServerParameterSet::getGlobal(), #NAME, &NAME, CHANGE_AT_STARTUP, CHANGE_AT_RUNTIME )
+
+/**
+ * Create a global variable of type "TYPE" named "NAME" with the given INITIAL_VALUE. The
+ * value may be set at startup or at runtime.
+ */
#define MONGO_EXPORT_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
- TYPE NAME = INITIAL_VALUE; \
- ExportedServerParameter<TYPE> _##NAME( ServerParameterSet::getGlobal(), #NAME, &NAME )
+ MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, true, true )
-}
+/**
+ * Like MONGO_EXPORT_SERVER_PARAMETER, but the value may only be set at startup.
+ */
+#define MONGO_EXPORT_STARTUP_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
+ MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, true, false )
+
+/**
+ * Like MONGO_EXPORT_SERVER_PARAMETER, but the value may only be set at runtime.
+ */
+#define MONGO_EXPORT_RUNTIME_SERVER_PARAMETER( NAME, TYPE, INITIAL_VALUE ) \
+ MONGO_EXPORT_SERVER_PARAMETER_IMPL( NAME, TYPE, INITIAL_VALUE, false, true )
#include "server_parameters_inline.h"
diff --git a/src/mongo/db/server_parameters_test.cpp b/src/mongo/db/server_parameters_test.cpp
index 5bb01f7f851..4a5aa38b415 100644
--- a/src/mongo/db/server_parameters_test.cpp
+++ b/src/mongo/db/server_parameters_test.cpp
@@ -24,7 +24,7 @@ namespace mongo {
TEST( ServerParameters, Simple1 ) {
int f = 5;
- ExportedServerParameter<int> ff( NULL, "ff", &f );
+ ExportedServerParameter<int> ff( NULL, "ff", &f, true, true );
ASSERT_EQUALS( "ff" , ff.name() );
ASSERT_EQUALS( 5, ff.get() );
@@ -45,7 +45,7 @@ namespace mongo {
TEST( ServerParameters, Vector1 ) {
vector<string> v;
- ExportedServerParameter< vector<string> > vv( NULL, "vv", &v );
+ ExportedServerParameter< vector<string> > vv( NULL, "vv", &v, true, true );
BSONObj x = BSON( "x" << BSON_ARRAY( "a" << "b" << "c" ) );
vv.set( x.firstElement() );