diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2019-01-11 17:37:35 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2019-01-23 20:28:40 +0000 |
commit | e3f8ea9c815a1eeb9ca5d2b55c5b21fa17009ef1 (patch) | |
tree | ba0d71d783c17ac7b751cfe0b12063e5a33490c5 /src/mongo/db/storage | |
parent | ffb19c17927a5a0a07a7cd7cd7744cea80ab3e26 (diff) | |
download | mongo-e3f8ea9c815a1eeb9ca5d2b55c5b21fa17009ef1.tar.gz |
SERVER-38950 Convert WiredTiger ServerParameters to IDL
Diffstat (limited to 'src/mongo/db/storage')
6 files changed, 112 insertions, 128 deletions
diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript index cd313193493..373931db88f 100644 --- a/src/mongo/db/storage/wiredtiger/SConscript +++ b/src/mongo/db/storage/wiredtiger/SConscript @@ -40,6 +40,7 @@ if wiredtiger: 'wiredtiger_index.cpp', 'wiredtiger_kv_engine.cpp', 'wiredtiger_oplog_manager.cpp', + 'wiredtiger_parameters.cpp', 'wiredtiger_prepare_conflict.cpp', 'wiredtiger_record_store.cpp', 'wiredtiger_recovery_unit.cpp', @@ -47,6 +48,7 @@ if wiredtiger: 'wiredtiger_snapshot_manager.cpp', 'wiredtiger_size_storer.cpp', 'wiredtiger_util.cpp', + env.Idlc('wiredtiger_parameters.idl')[0], ], LIBDEPS= [ '$BUILD_DIR/mongo/base', @@ -91,7 +93,6 @@ if wiredtiger: source=[ 'wiredtiger_init.cpp', 'wiredtiger_options_init.cpp', - 'wiredtiger_parameters.cpp', 'wiredtiger_record_store_mongod.cpp', 'wiredtiger_server_status.cpp', ], diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp index 8f1e9d5b8f4..83cef83353e 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_init.cpp @@ -48,7 +48,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h" #include "mongo/db/storage/wiredtiger/wiredtiger_index.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_parameters.h" +#include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" #include "mongo/db/storage/wiredtiger/wiredtiger_server_status.h" #include "mongo/db/storage/wiredtiger/wiredtiger_util.h" @@ -116,7 +116,9 @@ public: kv->setSortedDataInterfaceExtraOptions(wiredTigerGlobalOptions.indexConfig); // Intentionally leaked. new WiredTigerServerStatusSection(kv); - new WiredTigerEngineRuntimeConfigParameter(kv); + auto* param = new WiredTigerEngineRuntimeConfigParameter("wiredTigerEngineRuntimeConfig", + ServerParameterType::kRuntimeOnly); + param->_data.second = kv; KVStorageEngineOptions options; options.directoryPerDB = params.directoryperdb; @@ -185,4 +187,4 @@ ServiceContext::ConstructorActionRegisterer registerWiredTiger( registerStorageEngine(service, std::make_unique<WiredTigerFactory>()); }); } // namespace -} // namespace +} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp index 7f4df8bc885..833f34d98e5 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp @@ -78,6 +78,7 @@ #include "mongo/db/storage/wiredtiger/wiredtiger_extensions.h" #include "mongo/db/storage/wiredtiger/wiredtiger_global_options.h" #include "mongo/db/storage/wiredtiger/wiredtiger_index.h" +#include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h" #include "mongo/db/storage/wiredtiger/wiredtiger_record_store.h" #include "mongo/db/storage/wiredtiger/wiredtiger_recovery_unit.h" #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" @@ -443,51 +444,53 @@ private: }; namespace { +TicketHolder openWriteTransaction(128); +TicketHolder openReadTransaction(128); +} // namespace -class TicketServerParameter : public ServerParameter { - MONGO_DISALLOW_COPYING(TicketServerParameter); +OpenWriteTransactionParam::OpenWriteTransactionParam(StringData name, ServerParameterType spt) + : ServerParameter(name, spt), _data(&openWriteTransaction) {} -public: - TicketServerParameter(TicketHolder* holder, const std::string& name) - : ServerParameter(ServerParameterSet::getGlobal(), name, true, true), _holder(holder) {} +void OpenWriteTransactionParam::append(OperationContext* opCtx, + BSONObjBuilder& b, + const std::string& name) { + b.append(name, _data->outof()); +} - virtual void append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name) { - b.append(name, _holder->outof()); +Status OpenWriteTransactionParam::setFromString(const std::string& str) { + int num = 0; + Status status = parseNumberFromString(str, &num); + if (!status.isOK()) { + return status; } - - virtual Status set(const BSONElement& newValueElement) { - if (!newValueElement.isNumber()) - return Status(ErrorCodes::BadValue, str::stream() << name() << " has to be a number"); - return _set(newValueElement.numberInt()); + if (num <= 0) { + return {ErrorCodes::BadValue, str::stream() << name() << " has to be > 0"}; } + return _data->resize(num); +} - virtual Status setFromString(const std::string& str) { - int num = 0; - Status status = parseNumberFromString(str, &num); - if (!status.isOK()) - return status; - return _set(num); - } +OpenReadTransactionParam::OpenReadTransactionParam(StringData name, ServerParameterType spt) + : ServerParameter(name, spt), _data(&openReadTransaction) {} - Status _set(int newNum) { - if (newNum <= 0) { - return Status(ErrorCodes::BadValue, str::stream() << name() << " has to be > 0"); - } +void OpenReadTransactionParam::append(OperationContext* opCtx, + BSONObjBuilder& b, + const std::string& name) { + b.append(name, _data->outof()); +} - return _holder->resize(newNum); +Status OpenReadTransactionParam::setFromString(const std::string& str) { + int num = 0; + Status status = parseNumberFromString(str, &num); + if (!status.isOK()) { + return status; } + if (num <= 0) { + return {ErrorCodes::BadValue, str::stream() << name() << " has to be > 0"}; + } + return _data->resize(num); +} -private: - TicketHolder* _holder; -}; - -TicketHolder openWriteTransaction(128); -TicketServerParameter openWriteTransactionParam(&openWriteTransaction, - "wiredTigerConcurrentWriteTransactions"); - -TicketHolder openReadTransaction(128); -TicketServerParameter openReadTransactionParam(&openReadTransaction, - "wiredTigerConcurrentReadTransactions"); +namespace { stdx::function<bool(StringData)> initRsOplogBackgroundThreadCallback = [](StringData) -> bool { fassertFailed(40358); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp index f34bbb16026..0cde03f0579 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.cpp @@ -31,8 +31,7 @@ #include "mongo/platform/basic.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_parameters.h" - +#include "mongo/db/storage/wiredtiger/wiredtiger_parameters_gen.h" #include "mongo/logger/parse_log_component_settings.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" @@ -41,31 +40,10 @@ namespace mongo { using std::string; -WiredTigerEngineRuntimeConfigParameter::WiredTigerEngineRuntimeConfigParameter( - WiredTigerKVEngine* engine) - : ServerParameter( - ServerParameterSet::getGlobal(), "wiredTigerEngineRuntimeConfig", false, true), - _engine(engine) {} - - void WiredTigerEngineRuntimeConfigParameter::append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name) { - b << name << _currentValue; -} - -Status WiredTigerEngineRuntimeConfigParameter::set(const BSONElement& newValueElement) { - try { - return setFromString(newValueElement.String()); - } catch (const AssertionException& msg) { - return Status( - ErrorCodes::BadValue, - mongoutils::str::stream() - << "Invalid value for wiredTigerEngineRuntimeConfig via setParameter command: " - << newValueElement - << ", exception: " - << msg.what()); - } + b << name << _data.first; } Status WiredTigerEngineRuntimeConfigParameter::setFromString(const std::string& str) { @@ -80,7 +58,8 @@ Status WiredTigerEngineRuntimeConfigParameter::setFromString(const std::string& log() << "Reconfiguring WiredTiger storage engine with config string: \"" << str << "\""; - int ret = _engine->reconfigure(str.c_str()); + invariant(_data.second); + int ret = _data.second->reconfigure(str.c_str()); if (ret != 0) { string result = (mongoutils::str::stream() << "WiredTiger reconfiguration failed with error code (" @@ -92,7 +71,7 @@ Status WiredTigerEngineRuntimeConfigParameter::setFromString(const std::string& return Status(ErrorCodes::BadValue, result); } - _currentValue = str; + _data.first = str; return Status::OK(); } -} +} // namespace mongo diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.h b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.h deleted file mode 100644 index 1c622c6ab0a..00000000000 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.h +++ /dev/null @@ -1,62 +0,0 @@ - -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/base/disallow_copying.h" -#include "mongo/db/server_parameters.h" -#include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" - -namespace mongo { - -/** - * WT_CONNECTION::reconfigure get/setParameter support - */ -class WiredTigerEngineRuntimeConfigParameter : public ServerParameter { - MONGO_DISALLOW_COPYING(WiredTigerEngineRuntimeConfigParameter); - -public: - explicit WiredTigerEngineRuntimeConfigParameter(WiredTigerKVEngine* engine); - - /** - * Appends the last value that was successfully assigned via a call to `set` or - * `setFromString`. To conclude what options WiredTiger is running with, consult what MongoDB - * logged at startup when making the `wiredtiger_open` call. - */ - virtual void append(OperationContext* opCtx, BSONObjBuilder& b, const std::string& name); - virtual Status set(const BSONElement& newValueElement); - - virtual Status setFromString(const std::string& str); - -private: - WiredTigerKVEngine* _engine; - // This parameter can only be modified at runtime via `setParameter`. This string always - // starts out as the empty string. - std::string _currentValue; -}; -} diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.idl b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.idl new file mode 100644 index 00000000000..899cbed2366 --- /dev/null +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_parameters.idl @@ -0,0 +1,61 @@ +# Copyright (C) 2018-present MongoDB, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Server Side Public License, version 1, +# as published by MongoDB, Inc. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Server Side Public License for more details. +# +# You should have received a copy of the Server Side Public License +# along with this program. If not, see +# <http://www.mongodb.com/licensing/server-side-public-license>. +# +# As a special exception, the copyright holders give permission to link the +# code of portions of this program with the OpenSSL library under certain +# conditions as described in each individual source file and distribute +# linked combinations including the program with the OpenSSL library. You +# must comply with the Server Side Public License in all respects for +# all of the code used other than as permitted herein. If you modify file(s) +# with this exception, you may extend this exception to your version of the +# file(s), but you are not obligated to do so. If you do not wish to do so, +# delete this exception statement from your version. If you delete this +# exception statement from all source files in the program, then also delete +# it in the license file. +# + +global: + cpp_namespace: "mongo" + cpp_includes: + - "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" + - "mongo/util/concurrency/ticketholder.h" + +server_parameters: + wiredTigerConcurrentWriteTransactions: + description: "WiredTiger Concurrent Write Transactions" + set_at: [ startup, runtime ] + cpp_class: + name: OpenWriteTransactionParam + data: 'TicketHolder*' + override_ctor: true + wiredTigerConcurrentReadTransactions: + description: "WiredTiger Concurrent Read Transactions" + set_at: [ startup, runtime ] + cpp_class: + name: OpenReadTransactionParam + data: 'TicketHolder*' + override_ctor: true + wiredTigerEngineRuntimeConfig: + description: 'WiredTiger Configuration' + set_at: runtime + cpp_class: + name: WiredTigerEngineRuntimeConfigParameter + data: 'std::pair<std::string, WiredTigerKVEngine*>' + # The data element of this param gets initialized in three + # disparate ways by different parts of the codebase + # none of which are easily encoded here. + # Defer the initialization with condition: false + # and allow those places to manually set themselves up. + condition: { expr: false } |