summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage
diff options
context:
space:
mode:
authorDaniel Gottlieb <daniel.gottlieb@10gen.com>2016-11-10 10:49:37 -0500
committerDaniel Gottlieb <daniel.gottlieb@10gen.com>2016-11-10 10:49:37 -0500
commit5ce001e6b364953c588d16410eb569939aa205ca (patch)
treee6b2beaab7f254c3d1514c23f3471f92281db5f5 /src/mongo/db/storage
parent5ab5efc9b17be8a4ecebf845c9e07c0f15a67e0e (diff)
downloadmongo-5ce001e6b364953c588d16410eb569939aa205ca.tar.gz
SERVER-26646: Add structure that allows multiple WT extensions to be declared.
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r--src/mongo/db/storage/wiredtiger/SConscript7
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.cpp3
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h8
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_extensions.cpp84
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_extensions.h60
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp5
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp4
9 files changed, 162 insertions, 13 deletions
diff --git a/src/mongo/db/storage/wiredtiger/SConscript b/src/mongo/db/storage/wiredtiger/SConscript
index 032257889f0..9d2a8fc8035 100644
--- a/src/mongo/db/storage/wiredtiger/SConscript
+++ b/src/mongo/db/storage/wiredtiger/SConscript
@@ -10,14 +10,17 @@ if sanitizer_list:
env.Library(
target='storage_wiredtiger_customization_hooks',
- source= ['wiredtiger_customization_hooks.cpp'],
+ source= [
+ 'wiredtiger_customization_hooks.cpp',
+ 'wiredtiger_extensions.cpp',
+ ],
LIBDEPS= ['$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/service_context'],
PROGDEPS_DEPENDENTS=[
'$BUILD_DIR/mongo/mongod',
'$BUILD_DIR/mongo/mongos',
],
- )
+)
if wiredtiger:
wtEnv = env.Clone()
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.cpp
index fb4c85109cb..d14b33de5f7 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.cpp
@@ -76,11 +76,10 @@ bool EmptyWiredTigerCustomizationHooks::restartRequired() {
return false;
}
-std::string EmptyWiredTigerCustomizationHooks::getOpenConfig(StringData tableName) {
+std::string EmptyWiredTigerCustomizationHooks::getTableCreateConfig(StringData tableName) {
return "";
}
-
std::unique_ptr<DataProtector> EmptyWiredTigerCustomizationHooks::getDataProtector() {
return std::unique_ptr<DataProtector>();
}
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h b/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h
index b604fb70c9c..e78995481bd 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h
@@ -69,10 +69,10 @@ public:
virtual bool restartRequired() = 0;
/**
- * Gets the WiredTiger encryption configuration string for the
- * provided table name
+ * Gets an additional configuration string for the provided table name on a
+ * `WT_SESSION::create` call.
*/
- virtual std::string getOpenConfig(StringData tableName) = 0;
+ virtual std::string getTableCreateConfig(StringData tableName) = 0;
/**
* Returns the maximum size addition when doing transforming temp data.
@@ -113,7 +113,7 @@ public:
bool restartRequired() override;
- std::string getOpenConfig(StringData tableName) override;
+ std::string getTableCreateConfig(StringData tableName) override;
std::unique_ptr<DataProtector> getDataProtector() override;
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_extensions.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_extensions.cpp
new file mode 100644
index 00000000000..f9bd90126e2
--- /dev/null
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_extensions.cpp
@@ -0,0 +1,84 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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/platform/basic.h"
+
+#include "mongo/db/storage/wiredtiger/wiredtiger_extensions.h"
+
+#include "mongo/base/init.h"
+#include "mongo/base/string_data.h"
+#include "mongo/db/service_context.h"
+#include "mongo/stdx/memory.h"
+
+namespace mongo {
+
+MONGO_INITIALIZER_WITH_PREREQUISITES(SetWiredTigerExtensions, ("SetGlobalEnvironment"))
+(InitializerContext* context) {
+ auto configHooks = stdx::make_unique<WiredTigerExtensions>();
+ WiredTigerExtensions::set(getGlobalServiceContext(), std::move(configHooks));
+
+ return Status::OK();
+}
+
+namespace {
+const auto getConfigHooks =
+ ServiceContext::declareDecoration<std::unique_ptr<WiredTigerExtensions>>();
+} // namespace
+
+void WiredTigerExtensions::set(ServiceContext* service,
+ std::unique_ptr<WiredTigerExtensions> configHooks) {
+ auto& hooks = getConfigHooks(service);
+ invariant(configHooks);
+ hooks = std::move(configHooks);
+}
+
+WiredTigerExtensions* WiredTigerExtensions::get(ServiceContext* service) {
+ return getConfigHooks(service).get();
+}
+
+std::string WiredTigerExtensions::getOpenExtensionsConfig() const {
+ if (_wtExtensions.size() == 0) {
+ return "";
+ }
+
+ StringBuilder extensions;
+ extensions << "extensions=[";
+ for (const auto& ext : _wtExtensions) {
+ extensions << ext << ",";
+ }
+ extensions << "],";
+
+ return extensions.str();
+}
+
+void WiredTigerExtensions::addExtension(StringData extensionConfigStr) {
+ _wtExtensions.emplace_back(extensionConfigStr.toString());
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_extensions.h b/src/mongo/db/storage/wiredtiger/wiredtiger_extensions.h
new file mode 100644
index 00000000000..ba73a7ff060
--- /dev/null
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_extensions.h
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2016 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ *
+ * 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
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * 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 GNU Affero General 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.
+ */
+
+#pragma once
+
+#include <memory>
+#include <vector>
+
+namespace mongo {
+
+class StringData;
+class ServiceContext;
+
+class WiredTigerExtensions {
+public:
+ static void set(ServiceContext* service, std::unique_ptr<WiredTigerExtensions> custHooks);
+
+ static WiredTigerExtensions* get(ServiceContext* service);
+
+ /**
+ * Return the `extensions=[...]` piece for a `wiredtiger_open` call.
+ */
+ std::string getOpenExtensionsConfig() const;
+
+ /**
+ * Add an item to the `wiredtiger_open` extensions list.
+ */
+ void addExtension(StringData extensionConfigStr);
+
+private:
+ std::vector<std::string> _wtExtensions;
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
index 5396ae918f7..de3de61bf6d 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
@@ -167,7 +167,7 @@ StatusWith<std::string> WiredTigerIndex::generateCreateString(const std::string&
ss << "block_compressor=" << wiredTigerGlobalOptions.indexBlockCompressor << ",";
ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())
- ->getOpenConfig(desc.parentNS());
+ ->getTableCreateConfig(desc.parentNS());
ss << sysIndexConfig << ",";
ss << collIndexConfig << ",";
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
index 2d5bff3f4d5..463c4effcb9 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp
@@ -59,6 +59,7 @@
#include "mongo/db/storage/journal_listener.h"
#include "mongo/db/storage/storage_options.h"
#include "mongo/db/storage/wiredtiger/wiredtiger_customization_hooks.h"
+#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_record_store.h"
@@ -226,7 +227,9 @@ WiredTigerKVEngine::WiredTigerKVEngine(const std::string& canonicalName,
ss << ",log_size=2GB),";
ss << "statistics_log=(wait=" << wiredTigerGlobalOptions.statisticsLogDelaySecs << "),";
}
- ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getOpenConfig("system");
+ ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())
+ ->getTableCreateConfig("system");
+ ss << WiredTigerExtensions::get(getGlobalServiceContext())->getOpenExtensionsConfig();
ss << extraOpenOptions;
if (_readOnly) {
invariant(!_durable);
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
index d8be71400fc..fb254424b5a 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp
@@ -722,7 +722,7 @@ StatusWith<std::string> WiredTigerRecordStore::generateCreateString(
ss << "block_compressor=" << wiredTigerGlobalOptions.collectionBlockCompressor << ",";
- ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getOpenConfig(ns);
+ ss << WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getTableCreateConfig(ns);
ss << extraStrings << ",";
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp
index e2a30e54365..7783cea4cbf 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp
@@ -61,8 +61,8 @@ WiredTigerSizeStorer::WiredTigerSizeStorer(WT_CONNECTION* conn, const std::strin
int ret = session->open_cursor(session, storageUri.c_str(), NULL, "overwrite=true", &_cursor);
if (ret == ENOENT) {
// Need to create table.
- std::string config =
- WiredTigerCustomizationHooks::get(getGlobalServiceContext())->getOpenConfig(storageUri);
+ std::string config = WiredTigerCustomizationHooks::get(getGlobalServiceContext())
+ ->getTableCreateConfig(storageUri);
invariantWTOK(session->create(session, storageUri.c_str(), config.c_str()));
ret = session->open_cursor(session, storageUri.c_str(), NULL, "overwrite=true", &_cursor);
}