summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2019-03-01 19:51:48 +0000
committerSara Golemon <sara.golemon@mongodb.com>2019-03-03 01:46:09 +0000
commit217588a5eff6d4c4d2621a03a0cee1b4566e00f1 (patch)
treed1844aa3218512dc9ff3f1e943c9587cbe7da3fe /src/mongo/idl
parent857d20826c15d6a8fccf0b2b364bf7c4791220a1 (diff)
downloadmongo-217588a5eff6d4c4d2621a03a0cee1b4566e00f1.tar.gz
SERVER-37092 Remove old server parameter API
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/SConscript1
-rw-r--r--src/mongo/idl/server_parameter.cpp84
-rw-r--r--src/mongo/idl/server_parameter.h110
-rw-r--r--src/mongo/idl/server_parameter_with_storage.h5
4 files changed, 196 insertions, 4 deletions
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript
index f320ffdff3c..0ce5bf975dc 100644
--- a/src/mongo/idl/SConscript
+++ b/src/mongo/idl/SConscript
@@ -36,7 +36,6 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/db/server_parameters',
],
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/util/options_parser/options_parser',
diff --git a/src/mongo/idl/server_parameter.cpp b/src/mongo/idl/server_parameter.cpp
index c2e4255bed1..76c64725a64 100644
--- a/src/mongo/idl/server_parameter.cpp
+++ b/src/mongo/idl/server_parameter.cpp
@@ -43,6 +43,51 @@ MONGO_INITIALIZER_GROUP(EndServerParameterRegistration,
("BeginServerParameterRegistration"),
("BeginStartupOptionHandling"))
+ServerParameter::ServerParameter(StringData name, ServerParameterType spt)
+ : ServerParameter(ServerParameterSet::getGlobal(),
+ name,
+ spt != SPT::kRuntimeOnly,
+ spt != SPT::kStartupOnly) {}
+
+ServerParameter::ServerParameter(ServerParameterSet* sps,
+ StringData name,
+ bool allowedToChangeAtStartup,
+ bool allowedToChangeAtRuntime)
+ : _name(name.toString()),
+ _allowedToChangeAtStartup(allowedToChangeAtStartup),
+ _allowedToChangeAtRuntime(allowedToChangeAtRuntime) {
+ if (sps) {
+ sps->add(this);
+ }
+}
+
+ServerParameter::ServerParameter(ServerParameterSet* sps, StringData name)
+ : _name(name.toString()), _allowedToChangeAtStartup(true), _allowedToChangeAtRuntime(true) {
+ if (sps) {
+ sps->add(this);
+ }
+}
+
+namespace {
+ServerParameterSet* gGlobalServerParameterSet = nullptr;
+} // namespace
+
+ServerParameterSet* ServerParameterSet::getGlobal() {
+ if (!gGlobalServerParameterSet) {
+ gGlobalServerParameterSet = new ServerParameterSet();
+ }
+ return gGlobalServerParameterSet;
+}
+
+void ServerParameterSet::add(ServerParameter* sp) {
+ ServerParameter*& x = _map[sp->name()];
+ if (x) {
+ severe() << "'" << x->name() << "' already exists in the server parameter set.";
+ abort();
+ }
+ x = sp;
+}
+
IDLServerParameterDeprecatedAlias::IDLServerParameterDeprecatedAlias(StringData name,
ServerParameter* sp)
: ServerParameter(ServerParameterSet::getGlobal(),
@@ -75,4 +120,43 @@ Status IDLServerParameterDeprecatedAlias::setFromString(const std::string& str)
return _sp->setFromString(str);
}
+namespace {
+class DisabledTestParameter : public ServerParameter {
+public:
+ DisabledTestParameter() = delete;
+
+ DisabledTestParameter(ServerParameter* sp)
+ : ServerParameter(
+ nullptr, sp->name(), sp->allowedToChangeAtStartup(), sp->allowedToChangeAtRuntime()),
+ _sp(sp) {
+ setTestOnly();
+ }
+
+ void append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name) final {}
+
+ Status setFromString(const std::string&) final {
+ return {ErrorCodes::BadValue,
+ str::stream() << "setParameter: '" << name()
+ << "' is only supported with 'enableTestCommands=true'"};
+ }
+
+ Status set(const BSONElement& newValueElement) final {
+ return setFromString("");
+ }
+
+private:
+ // Retain the original pointer to avoid ASAN complaining.
+ ServerParameter* _sp;
+};
+} // namespace
+
+void ServerParameterSet::disableTestParameters() {
+ for (auto& spit : _map) {
+ auto*& sp = spit.second;
+ if (sp->isTestOnly()) {
+ sp = new DisabledTestParameter(sp);
+ }
+ }
+}
+
} // namespace mongo
diff --git a/src/mongo/idl/server_parameter.h b/src/mongo/idl/server_parameter.h
index 794bde5761e..7325e4ee5a1 100644
--- a/src/mongo/idl/server_parameter.h
+++ b/src/mongo/idl/server_parameter.h
@@ -35,14 +35,13 @@
* rather parameters should be defined in .idl files.
*/
-#include <functional>
#include <string>
+#include "mongo/base/checked_cast.h"
#include "mongo/base/init.h"
#include "mongo/base/status.h"
#include "mongo/bson/bsonelement.h"
#include "mongo/bson/bsonobjbuilder.h"
-#include "mongo/db/server_parameters.h"
#define MONGO_SERVER_PARAMETER_REGISTER(name) \
MONGO_INITIALIZER_GENERAL( \
@@ -51,6 +50,113 @@
namespace mongo {
/**
+ * Server Parameters can be set startup up and/or runtime.
+ *
+ * At startup, --setParameter ... or config file is used.
+ * At runtime, { setParameter : 1, ...} is used.
+ */
+enum class ServerParameterType {
+
+ /**
+ * Parameter can only be set via runCommand.
+ */
+ kRuntimeOnly,
+
+ /**
+ * Parameter can only be set via --setParameter, and is only read at startup after command-line
+ * parameters, and the config file are processed.
+ */
+ kStartupOnly,
+
+ /**
+ * Parameter can be set at both startup and runtime.
+ */
+ kStartupAndRuntime,
+};
+
+class ServerParameterSet;
+class OperationContext;
+
+class ServerParameter {
+public:
+ using Map = std::map<std::string, ServerParameter*>;
+
+ ServerParameter(StringData name, ServerParameterType spt);
+ ServerParameter(ServerParameterSet* sps,
+ StringData name,
+ bool allowedToChangeAtStartup,
+ bool allowedToChangeAtRuntime);
+ ServerParameter(ServerParameterSet* sps, StringData name);
+ virtual ~ServerParameter() = default;
+
+ std::string name() const {
+ return _name;
+ }
+
+ /**
+ * @return if you can set on command line or config file
+ */
+ bool allowedToChangeAtStartup() const {
+ return _allowedToChangeAtStartup;
+ }
+
+ /**
+ * @param if you can use (get|set)Parameter
+ */
+ bool allowedToChangeAtRuntime() const {
+ return _allowedToChangeAtRuntime;
+ }
+
+
+ virtual void append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name) = 0;
+
+ virtual Status set(const BSONElement& newValueElement) = 0;
+
+ virtual Status setFromString(const std::string& str) = 0;
+
+ bool isTestOnly() const {
+ return _testOnly;
+ }
+
+ void setTestOnly() {
+ _testOnly = true;
+ }
+
+private:
+ std::string _name;
+ bool _allowedToChangeAtStartup;
+ bool _allowedToChangeAtRuntime;
+ bool _testOnly = false;
+};
+
+class ServerParameterSet {
+public:
+ using Map = ServerParameter::Map;
+
+ void add(ServerParameter* sp);
+
+ const Map& getMap() const {
+ return _map;
+ }
+
+ static ServerParameterSet* getGlobal();
+
+ void disableTestParameters();
+
+ template <typename T = ServerParameter>
+ T* get(StringData name) {
+ const auto& it = _map.find(name.toString());
+ uassert(ErrorCodes::NoSuchKey,
+ str::stream() << "Unknown server parameter: " << name,
+ it != _map.end());
+ return checked_cast<T*>(it->second);
+ }
+
+private:
+ Map _map;
+};
+
+/**
* Proxy instance for deprecated aliases of set parameters.
*/
class IDLServerParameterDeprecatedAlias : public ServerParameter {
diff --git a/src/mongo/idl/server_parameter_with_storage.h b/src/mongo/idl/server_parameter_with_storage.h
index 16fa7d82789..81b1517135e 100644
--- a/src/mongo/idl/server_parameter_with_storage.h
+++ b/src/mongo/idl/server_parameter_with_storage.h
@@ -42,7 +42,10 @@
#include "mongo/base/string_data.h"
#include "mongo/bson/bsonelement.h"
#include "mongo/bson/bsonobjbuilder.h"
-#include "mongo/db/server_parameters.h"
+#include "mongo/idl/server_parameter.h"
+#include "mongo/platform/atomic_proxy.h"
+#include "mongo/platform/atomic_word.h"
+#include "mongo/util/stringutils.h"
#include "mongo/util/synchronized_value.h"
namespace mongo {