diff options
author | samantharitter <samantha.ritter@10gen.com> | 2017-06-16 08:33:15 -0400 |
---|---|---|
committer | samantharitter <samantha.ritter@10gen.com> | 2017-06-16 09:43:53 -0400 |
commit | 12014e33b8de9fd9daa6da37b478066c5486857f (patch) | |
tree | d1e3e1153965923107d1d4638fa3c9ae48a725f8 /src | |
parent | b9739a9b4bf02790d427a8e4910629f8c378c5fb (diff) | |
download | mongo-12014e33b8de9fd9daa6da37b478066c5486857f.tar.gz |
SERVER-29475 Install the logical session cache
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/SConscript | 28 | ||||
-rw-r--r-- | src/mongo/db/auth/SConscript | 12 | ||||
-rw-r--r-- | src/mongo/db/db.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/logical_session_cache.cpp | 13 | ||||
-rw-r--r-- | src/mongo/db/logical_session_cache.h | 16 | ||||
-rw-r--r-- | src/mongo/db/logical_session_cache_factory_mongod.cpp | 74 | ||||
-rw-r--r-- | src/mongo/db/logical_session_cache_factory_mongod.h | 42 | ||||
-rw-r--r-- | src/mongo/db/logical_session_cache_factory_mongos.cpp | 55 | ||||
-rw-r--r-- | src/mongo/db/logical_session_cache_factory_mongos.h | 40 | ||||
-rw-r--r-- | src/mongo/db/service_context.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/service_context.h | 21 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/s/server.cpp | 5 |
14 files changed, 325 insertions, 5 deletions
diff --git a/src/mongo/SConscript b/src/mongo/SConscript index b62608ae224..82a56d5a98e 100644 --- a/src/mongo/SConscript +++ b/src/mongo/SConscript @@ -289,6 +289,7 @@ mongod = env.Program( 'db/ftdc/ftdc_mongod', 'db/index_d', 'db/initialize_snmp', + 'db/logical_session_cache_factory_mongod', 'db/mongod_options', 'db/mongodandmongos', 'db/op_observer_d', diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 4cc3e6058c9..6bf1329dce7 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -453,6 +453,7 @@ env.Library( '$BUILD_DIR/mongo/util/periodic_runner', '$BUILD_DIR/mongo/transport/transport_layer_common', '$BUILD_DIR/mongo/transport/transport_layer_manager', + 'logical_session_cache', ], ) @@ -885,7 +886,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/auth/authcore', + '$BUILD_DIR/mongo/db/auth/user_name', '$BUILD_DIR/mongo/idl/idl_parser', 'logical_session_id' ], @@ -956,6 +957,7 @@ env.Library( LIBDEPS=[ 'logical_session_record', 'sessions_collection', + 'server_parameters', 'service_liason', ], ) @@ -973,6 +975,30 @@ envWithAsio.CppUnitTest( ], ) +envWithAsio.Library( + target='logical_session_cache_factory_mongod', + source=[ + 'logical_session_cache_factory_mongod.cpp', + ], + LIBDEPS=[ + 'logical_session_cache', + 'service_liason_mock', # TODO SERVER-29198 replace with service_liason_mongod + 'sessions_collection_mock', # TODO SERVER-29201, SERVER-29202, SERVER-29203 + ], +) + +envWithAsio.Library( + target='logical_session_cache_factory_mongos', + source=[ + 'logical_session_cache_factory_mongos.cpp', + ], + LIBDEPS=[ + 'logical_session_cache', + 'service_liason_mock', # TODO SERVER-29199 replace with service_liason_mongos + 'sessions_collection_mock', # TODO SERVER-29203 replace with sessions_collection_sharded + ], +) + env.Library( target='logical_time', source=[ diff --git a/src/mongo/db/auth/SConscript b/src/mongo/db/auth/SConscript index eb0ea879cd3..5b2b1d74f07 100644 --- a/src/mongo/db/auth/SConscript +++ b/src/mongo/db/auth/SConscript @@ -31,6 +31,16 @@ env.Library( ], ) +env.Library( + target='user_name', + source=[ + 'user_name.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + ], +) + # Just the data structures used env.Library('authcore', ['action_set.cpp', 'action_type.cpp', @@ -49,11 +59,11 @@ env.Library('authcore', ['action_set.cpp', 'user.cpp', 'user_document_parser.cpp', 'user_management_commands_parser.cpp', - 'user_name.cpp', 'user_set.cpp'], LIBDEPS=['auth_rolename', 'authentication_restriction', 'sasl_options', + 'user_name', '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/bson/mutable/mutable_bson', '$BUILD_DIR/mongo/bson/util/bson_extract', diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp index ad611f45006..b64de3f0dbd 100644 --- a/src/mongo/db/db.cpp +++ b/src/mongo/db/db.cpp @@ -74,6 +74,8 @@ #include "mongo/db/json.h" #include "mongo/db/log_process_details.h" #include "mongo/db/logical_clock.h" +#include "mongo/db/logical_session_cache.h" +#include "mongo/db/logical_session_cache_factory_mongod.h" #include "mongo/db/logical_time_metadata_hook.h" #include "mongo/db/logical_time_validator.h" #include "mongo/db/mongod_options.h" @@ -707,6 +709,17 @@ ExitCode _initAndListen(int listenPort) { runner->startup(); globalServiceContext->setPeriodicRunner(std::move(runner)); + // Set up the logical session cache + LogicalSessionCacheServer kind = LogicalSessionCacheServer::kStandalone; + if (shardingInitialized) { + kind = LogicalSessionCacheServer::kSharded; + } else if (replSettings.usingReplSets()) { + kind = LogicalSessionCacheServer::kReplicaSet; + } + + auto sessionCache = makeLogicalSessionCacheD(kind); + globalServiceContext->setLogicalSessionCache(std::move(sessionCache)); + // MessageServer::run will return when exit code closes its socket and we don't need the // operation context anymore startupOpCtx.reset(); diff --git a/src/mongo/db/logical_session_cache.cpp b/src/mongo/db/logical_session_cache.cpp index 1c94e019ac3..8aa1eaba802 100644 --- a/src/mongo/db/logical_session_cache.cpp +++ b/src/mongo/db/logical_session_cache.cpp @@ -32,12 +32,25 @@ #include "mongo/db/logical_session_cache.h" +#include "mongo/db/server_parameters.h" #include "mongo/util/duration.h" #include "mongo/util/log.h" #include "mongo/util/periodic_runner.h" namespace mongo { +MONGO_EXPORT_STARTUP_SERVER_PARAMETER(logicalSessionRecordCacheSize, + int, + LogicalSessionCache::kLogicalSessionCacheDefaultCapacity); + +MONGO_EXPORT_STARTUP_SERVER_PARAMETER(localLogicalSessionTimeoutMinutes, + int, + LogicalSessionCache::kLogicalSessionDefaultTimeout.count()); + +MONGO_EXPORT_STARTUP_SERVER_PARAMETER(logicalSessionRefreshMinutes, + int, + LogicalSessionCache::kLogicalSessionDefaultRefresh.count()); + constexpr int LogicalSessionCache::kLogicalSessionCacheDefaultCapacity; constexpr Minutes LogicalSessionCache::kLogicalSessionDefaultTimeout; constexpr Minutes LogicalSessionCache::kLogicalSessionDefaultRefresh; diff --git a/src/mongo/db/logical_session_cache.h b/src/mongo/db/logical_session_cache.h index 4e4bc4023af..a88bb3f31d0 100644 --- a/src/mongo/db/logical_session_cache.h +++ b/src/mongo/db/logical_session_cache.h @@ -39,6 +39,10 @@ namespace mongo { +extern int logicalSessionRecordCacheSize; +extern int localLogicalSessionTimeoutMinutes; +extern int logicalSessionRefreshMinutes; + /** * A thread-safe cache structure for logical session records. * @@ -59,15 +63,19 @@ public: /** * The number of session records to keep in the cache. + * + * May be set with --setParameter logicalSessionRecordCacheSize=X. */ - int capacity = kLogicalSessionCacheDefaultCapacity; + int capacity = logicalSessionRecordCacheSize; /** * A timeout value to use for sessions in the cache, in minutes. * * By default, this is set to 30 minutes. + * + * May be set with --setParameter localLogicalSessionTimeoutMinutes=X. */ - Minutes sessionTimeout = kLogicalSessionDefaultTimeout; + Minutes sessionTimeout = Minutes(localLogicalSessionTimeoutMinutes); /** * The interval over which the cache will refresh session records. @@ -75,8 +83,10 @@ public: * By default, this is set to every 5 minutes. If the caller is * setting the sessionTimeout by hand, it is suggested that they * consider also setting the refresh interval accordingly. + * + * May be set with --setParameter logicalSessionRefreshMinutes=X. */ - Minutes refreshInterval = kLogicalSessionDefaultRefresh; + Minutes refreshInterval = Minutes(logicalSessionRefreshMinutes); }; /** diff --git a/src/mongo/db/logical_session_cache_factory_mongod.cpp b/src/mongo/db/logical_session_cache_factory_mongod.cpp new file mode 100644 index 00000000000..fcaa6937e68 --- /dev/null +++ b/src/mongo/db/logical_session_cache_factory_mongod.cpp @@ -0,0 +1,74 @@ +/** + * Copyright (C) 2017 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 <memory> + +#include "mongo/db/logical_session_cache_factory_mongod.h" + +#include "mongo/db/service_liason_mock.h" +#include "mongo/db/sessions_collection_mock.h" +#include "mongo/stdx/memory.h" + +namespace mongo { + +namespace { + +std::unique_ptr<SessionsCollection> makeSessionsCollection(LogicalSessionCacheServer state) { + switch (state) { + case LogicalSessionCacheServer::kSharded: + // TODO SERVER-29203, replace with SessionsCollectionSharded + return stdx::make_unique<MockSessionsCollection>( + std::make_shared<MockSessionsCollectionImpl>()); + case LogicalSessionCacheServer::kReplicaSet: + // TODO SERVER-29202, replace with SessionsCollectionRS + return stdx::make_unique<MockSessionsCollection>( + std::make_shared<MockSessionsCollectionImpl>()); + case LogicalSessionCacheServer::kStandalone: + // TODO SERVER-29201, replace with SessionsCollectionStandalone + return stdx::make_unique<MockSessionsCollection>( + std::make_shared<MockSessionsCollectionImpl>()); + default: + MONGO_UNREACHABLE; + } +} + +} // namespace + +std::unique_ptr<LogicalSessionCache> makeLogicalSessionCacheD(LogicalSessionCacheServer state) { + // TODO SERVER-29198 replace with ServiceLiasonMongod + auto liason = stdx::make_unique<MockServiceLiason>(std::make_shared<MockServiceLiasonImpl>()); + + // Set up the logical session cache + auto sessionsColl = makeSessionsCollection(state); + return stdx::make_unique<LogicalSessionCache>( + std::move(liason), std::move(sessionsColl), LogicalSessionCache::Options{}); +} + +} // namespace mongo diff --git a/src/mongo/db/logical_session_cache_factory_mongod.h b/src/mongo/db/logical_session_cache_factory_mongod.h new file mode 100644 index 00000000000..e69c459d469 --- /dev/null +++ b/src/mongo/db/logical_session_cache_factory_mongod.h @@ -0,0 +1,42 @@ +/** + * Copyright (C) 2017 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 "mongo/db/logical_session_cache.h" +#include "mongo/db/service_liason.h" + +namespace mongo { + +enum class LogicalSessionCacheServer { kSharded, kReplicaSet, kStandalone }; + +std::unique_ptr<LogicalSessionCache> makeLogicalSessionCacheD(LogicalSessionCacheServer state); + +} // namespace mongo diff --git a/src/mongo/db/logical_session_cache_factory_mongos.cpp b/src/mongo/db/logical_session_cache_factory_mongos.cpp new file mode 100644 index 00000000000..b3d8d04362c --- /dev/null +++ b/src/mongo/db/logical_session_cache_factory_mongos.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (C) 2017 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 <memory> + +#include "mongo/db/logical_session_cache_factory_mongos.h" + +#include "mongo/db/server_parameters.h" +#include "mongo/db/service_liason_mock.h" +#include "mongo/db/sessions_collection_mock.h" +#include "mongo/stdx/memory.h" + +namespace mongo { + +std::unique_ptr<LogicalSessionCache> makeLogicalSessionCacheS() { + + // TODO SERVER-29199 replace with ServiceLiasonMongos + auto liason = stdx::make_unique<MockServiceLiason>(std::make_shared<MockServiceLiasonImpl>()); + + // TODO SERVER-29203, replace with SessionsCollectionSharded + auto sessionsColl = + stdx::make_unique<MockSessionsCollection>(std::make_shared<MockSessionsCollectionImpl>()); + + return stdx::make_unique<LogicalSessionCache>( + std::move(liason), std::move(sessionsColl), LogicalSessionCache::Options{}); +} + +} // namespace mongo diff --git a/src/mongo/db/logical_session_cache_factory_mongos.h b/src/mongo/db/logical_session_cache_factory_mongos.h new file mode 100644 index 00000000000..f8d23412168 --- /dev/null +++ b/src/mongo/db/logical_session_cache_factory_mongos.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2017 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 "mongo/db/logical_session_cache.h" +#include "mongo/db/service_liason.h" + +namespace mongo { + +std::unique_ptr<LogicalSessionCache> makeLogicalSessionCacheS(); + +} // namespace mongo diff --git a/src/mongo/db/service_context.cpp b/src/mongo/db/service_context.cpp index ae3ac610da8..fdf6d8e49a3 100644 --- a/src/mongo/db/service_context.cpp +++ b/src/mongo/db/service_context.cpp @@ -164,6 +164,15 @@ PeriodicRunner* ServiceContext::getPeriodicRunner() const { return _runner.get(); } +void ServiceContext::setLogicalSessionCache(std::unique_ptr<LogicalSessionCache> cache)& { + invariant(!_sessionCache); + _sessionCache = std::move(cache); +} + +LogicalSessionCache* ServiceContext::getLogicalSessionCache() const& { + return _sessionCache.get(); +} + transport::TransportLayer* ServiceContext::getTransportLayer() const { return _transportLayerManager.get(); } diff --git a/src/mongo/db/service_context.h b/src/mongo/db/service_context.h index 720f03f3826..97a0193e2c5 100644 --- a/src/mongo/db/service_context.h +++ b/src/mongo/db/service_context.h @@ -33,6 +33,7 @@ #include <vector> #include "mongo/base/disallow_copying.h" +#include "mongo/db/logical_session_cache.h" #include "mongo/db/logical_session_id.h" #include "mongo/db/storage/storage_engine.h" #include "mongo/platform/atomic_word.h" @@ -332,6 +333,21 @@ public: PeriodicRunner* getPeriodicRunner() const; // + // Logical sessions. + // + + /** + * Set the logical session cache on this service context. + */ + void setLogicalSessionCache(std::unique_ptr<LogicalSessionCache> cache) &; + + /** + * Return a pointer to the logical session cache on this service context. + */ + LogicalSessionCache* getLogicalSessionCache() const&; + LogicalSessionCache* getLogicalSessionCache() && = delete; + + // // Transport. // @@ -441,6 +457,11 @@ private: std::unique_ptr<PeriodicRunner> _runner; /** + * The logical session cache. + */ + std::unique_ptr<LogicalSessionCache> _sessionCache; + + /** * The TransportLayerManager. */ std::unique_ptr<transport::TransportLayerManager> _transportLayerManager; diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index f11059fbaee..79c8d001fd1 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -30,6 +30,7 @@ env.Library( '$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl', '$BUILD_DIR/mongo/s/catalog/dist_lock_catalog_impl', '$BUILD_DIR/mongo/s/catalog/replset_dist_lock_manager', + '$BUILD_DIR/mongo/db/logical_session_cache_factory_mongos', '$BUILD_DIR/mongo/db/s/sharding_task_executor', '$BUILD_DIR/mongo/util/periodic_runner_factory', 'client/sharding_connection_hook', diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp index 0e898b1f022..c44d3da8585 100644 --- a/src/mongo/s/server.cpp +++ b/src/mongo/s/server.cpp @@ -54,6 +54,8 @@ #include "mongo/db/lasterror.h" #include "mongo/db/log_process_details.h" #include "mongo/db/logical_clock.h" +#include "mongo/db/logical_session_cache.h" +#include "mongo/db/logical_session_cache_factory_mongos.h" #include "mongo/db/logical_time_metadata_hook.h" #include "mongo/db/logical_time_validator.h" #include "mongo/db/operation_context.h" @@ -348,6 +350,9 @@ static ExitCode runMongosServer() { runner->startup(); getGlobalServiceContext()->setPeriodicRunner(std::move(runner)); + // Set up the logical session cache + getGlobalServiceContext()->setLogicalSessionCache(makeLogicalSessionCacheS()); + auto start = getGlobalServiceContext()->addAndStartTransportLayer(std::move(transportLayer)); if (!start.isOK()) { return EXIT_NET_ERROR; |