summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-06-13 14:36:56 -0400
committerJason Carey <jcarey@argv.me>2017-07-06 12:39:32 -0400
commit0503521c2375a2e7bfbbda314ff997c77a372d66 (patch)
tree3f2d81aa90da070bf931dfedde195602ab71f5e8 /src/mongo/db
parent3ea2d70f0260b1ec6ec8c60d42d6a6669a802ef2 (diff)
downloadmongo-0503521c2375a2e7bfbbda314ff997c77a372d66.tar.gz
SERVER-29198 Implement ServiceLiasonMongod
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/SConscript18
-rw-r--r--src/mongo/db/logical_session_cache_factory_mongod.cpp5
-rw-r--r--src/mongo/db/service_liason_mongod.cpp91
-rw-r--r--src/mongo/db/service_liason_mongod.h62
4 files changed, 172 insertions, 4 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index fad8e64c954..b5cfd10b189 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -940,6 +940,21 @@ envWithAsio.Library(
)
env.Library(
+ target='service_liason_mongod',
+ source=[
+ 'service_liason_mongod.cpp',
+ ],
+ LIBDEPS=[
+ '$BUILD_DIR/mongo/db/logical_session_id',
+ '$BUILD_DIR/mongo/util/clock_sources',
+ '$BUILD_DIR/mongo/util/periodic_runner',
+ 'clientcursor',
+ 'service_context',
+ 'service_liason',
+ ],
+)
+
+env.Library(
target='sessions_collection',
source=[
'sessions_collection.cpp',
@@ -979,6 +994,7 @@ envWithAsio.CppUnitTest(
'logical_session_cache_test.cpp',
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/executor/async_timer_mock',
'logical_session_cache',
'service_liason_mock',
@@ -993,7 +1009,7 @@ envWithAsio.Library(
],
LIBDEPS=[
'logical_session_cache',
- 'service_liason_mock', # TODO SERVER-29198 replace with service_liason_mongod
+ 'service_liason_mongod',
'sessions_collection_mock', # TODO SERVER-29201, SERVER-29202, SERVER-29203
],
)
diff --git a/src/mongo/db/logical_session_cache_factory_mongod.cpp b/src/mongo/db/logical_session_cache_factory_mongod.cpp
index fcaa6937e68..6f253ca5116 100644
--- a/src/mongo/db/logical_session_cache_factory_mongod.cpp
+++ b/src/mongo/db/logical_session_cache_factory_mongod.cpp
@@ -32,7 +32,7 @@
#include "mongo/db/logical_session_cache_factory_mongod.h"
-#include "mongo/db/service_liason_mock.h"
+#include "mongo/db/service_liason_mongod.h"
#include "mongo/db/sessions_collection_mock.h"
#include "mongo/stdx/memory.h"
@@ -62,8 +62,7 @@ std::unique_ptr<SessionsCollection> makeSessionsCollection(LogicalSessionCacheSe
} // namespace
std::unique_ptr<LogicalSessionCache> makeLogicalSessionCacheD(LogicalSessionCacheServer state) {
- // TODO SERVER-29198 replace with ServiceLiasonMongod
- auto liason = stdx::make_unique<MockServiceLiason>(std::make_shared<MockServiceLiasonImpl>());
+ auto liason = stdx::make_unique<ServiceLiasonMongod>();
// Set up the logical session cache
auto sessionsColl = makeSessionsCollection(state);
diff --git a/src/mongo/db/service_liason_mongod.cpp b/src/mongo/db/service_liason_mongod.cpp
new file mode 100644
index 00000000000..fdbf811de18
--- /dev/null
+++ b/src/mongo/db/service_liason_mongod.cpp
@@ -0,0 +1,91 @@
+/**
+ * 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 "mongo/db/service_liason_mongod.h"
+
+#include "mongo/db/client.h"
+#include "mongo/db/cursor_manager.h"
+#include "mongo/db/operation_context.h"
+#include "mongo/db/service_context.h"
+#include "mongo/stdx/mutex.h"
+#include "mongo/util/clock_source.h"
+#include "mongo/util/periodic_runner.h"
+
+namespace mongo {
+
+LogicalSessionIdSet ServiceLiasonMongod::getActiveSessions() const {
+ LogicalSessionIdSet activeSessions;
+
+ invariant(hasGlobalServiceContext());
+
+ // Walk through the service context and append lsids for all currently-running ops.
+ for (ServiceContext::LockedClientsCursor cursor(getGlobalServiceContext());
+ Client* client = cursor.next();) {
+
+ stdx::lock_guard<Client> lk(*client);
+ auto clientOpCtx = client->getOperationContext();
+
+ // Ignore clients without currently-running operations
+ if (!clientOpCtx)
+ continue;
+
+ // Append this op ctx's session to our list, if it has one
+ auto lsid = clientOpCtx->getLogicalSessionId();
+ if (lsid) {
+ activeSessions.insert(*lsid);
+ }
+ }
+
+ // Append any in-use session ids from the global and collection-level cursor managers
+ {
+ auto client = Client::getCurrent();
+ auto opCtx = client->makeOperationContext();
+ CursorManager::appendAllActiveSessions(opCtx.get(), &activeSessions);
+ }
+
+ return activeSessions;
+}
+
+void ServiceLiasonMongod::scheduleJob(PeriodicRunner::PeriodicJob job) {
+ invariant(hasGlobalServiceContext());
+ getGlobalServiceContext()->getPeriodicRunner()->scheduleJob(std::move(job));
+}
+
+void ServiceLiasonMongod::join() {
+ invariant(hasGlobalServiceContext());
+ getGlobalServiceContext()->getPeriodicRunner()->shutdown();
+}
+
+Date_t ServiceLiasonMongod::now() const {
+ invariant(hasGlobalServiceContext());
+ return getGlobalServiceContext()->getFastClockSource()->now();
+}
+
+} // namespace mongo
diff --git a/src/mongo/db/service_liason_mongod.h b/src/mongo/db/service_liason_mongod.h
new file mode 100644
index 00000000000..21c677feb8c
--- /dev/null
+++ b/src/mongo/db/service_liason_mongod.h
@@ -0,0 +1,62 @@
+/**
+ * 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 "mongo/db/logical_session_id.h"
+#include "mongo/db/operation_context.h"
+#include "mongo/db/service_liason.h"
+#include "mongo/util/periodic_runner.h"
+#include "mongo/util/time_support.h"
+
+namespace mongo {
+
+/**
+ * This is the service liason to mongod for the logical session cache.
+ *
+ * This class will return active sessions for cursors stored in the
+ * global cursor manager and cursors in per-collection managers. This
+ * class will also walk the service context to find all sessions for
+ * currently-running operations on this server.
+ *
+ * Job scheduling on this class will be handled behind the scenes by a
+ * periodic runner for this mongod. The time will be returned from the
+ * system clock.
+ */
+class ServiceLiasonMongod : public ServiceLiason {
+public:
+ LogicalSessionIdSet getActiveSessions() const override;
+
+ void scheduleJob(PeriodicRunner::PeriodicJob job) override;
+
+ void join() override;
+
+ Date_t now() const override;
+};
+
+} // namespace mongo