summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/noPassthrough/refresh_logical_session_cache_now.js44
-rw-r--r--src/mongo/db/commands/SConscript1
-rw-r--r--src/mongo/db/commands/refresh_logical_session_cache_now.cpp93
-rw-r--r--src/mongo/db/logical_session_cache.cpp13
-rw-r--r--src/mongo/db/service_liason_mongod.cpp14
5 files changed, 4 insertions, 161 deletions
diff --git a/jstests/noPassthrough/refresh_logical_session_cache_now.js b/jstests/noPassthrough/refresh_logical_session_cache_now.js
deleted file mode 100644
index e3fe583f074..00000000000
--- a/jstests/noPassthrough/refresh_logical_session_cache_now.js
+++ /dev/null
@@ -1,44 +0,0 @@
-(function() {
- "use script";
-
- var res;
- var refresh = {refreshLogicalSessionCacheNow: 1};
- var startSession = {startSession: 1};
-
- // Start up a standalone server.
- var conn = MongoRunner.runMongod({nojournal: ""});
- var admin = conn.getDB("admin");
-
- // Trigger an initial refresh, as a sanity check.
- res = admin.runCommand(refresh);
- assert.commandWorked(res, "failed to refresh");
-
- // Start a session. Should not be in the collection yet.
- res = admin.runCommand(startSession);
- assert.commandWorked(res, "unable to start session");
-
- assert.eq(admin.system.sessions.count(), 0, "should not have session records yet");
-
- // Trigger a refresh. Session should now be in the collection.
- res = admin.runCommand(refresh);
- assert.commandWorked(res, "failed to refresh");
-
- assert.eq(admin.system.sessions.count(), 1, "should have written session records");
-
- // Start some new sessions. Should not be in the collection yet.
- var numSessions = 100;
- for (var i = 0; i < numSessions; i++) {
- res = admin.runCommand(startSession);
- assert.commandWorked(res, "unable to start session");
- }
-
- assert.eq(admin.system.sessions.count(), 1, "should not have more session records yet");
-
- // Trigger another refresh. All sessions should now be in the collection.
- res = admin.runCommand(refresh);
- assert.commandWorked(res, "failed to refresh");
-
- assert.eq(
- admin.system.sessions.count(), numSessions + 1, "should have written session records");
-
-}());
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index eb16bef934e..c6197fed134 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -65,7 +65,6 @@ env.Library(
"isself.cpp",
"mr_common.cpp",
"parameters.cpp",
- "refresh_logical_session_cache_now.cpp",
"rename_collection_common.cpp",
"start_session_command.cpp",
"user_management_commands_common.cpp",
diff --git a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
deleted file mode 100644
index 8c1c8cef489..00000000000
--- a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * 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/base/init.h"
-#include "mongo/db/client.h"
-#include "mongo/db/commands.h"
-#include "mongo/db/logical_session_cache.h"
-#include "mongo/db/operation_context.h"
-
-namespace mongo {
-
-namespace {
-
-class RefreshLogicalSessionCacheNowCommand final : public BasicCommand {
- MONGO_DISALLOW_COPYING(RefreshLogicalSessionCacheNowCommand);
-
-public:
- RefreshLogicalSessionCacheNowCommand() : BasicCommand("refreshLogicalSessionCacheNow") {}
-
- bool slaveOk() const override {
- return true;
- }
-
- bool adminOnly() const override {
- return false;
- }
-
- bool supportsWriteConcern(const BSONObj& cmd) const override {
- return false;
- }
-
- void help(std::stringstream& help) const override {
- help << "force the logical session cache to refresh. Test command only.";
- }
-
- // No auth needed because it only works when enabled via command line.
- Status checkAuthForOperation(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj) override {
- return Status::OK();
- }
-
- virtual bool run(OperationContext* opCtx,
- const std::string& db,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) override {
- auto cache = LogicalSessionCache::get(opCtx);
- auto client = opCtx->getClient();
-
- cache->refreshNow(client);
-
- return true;
- }
-};
-
-} // namespace
-
-MONGO_INITIALIZER(RegisterRefreshLogicalSessionCacheNowCommand)(InitializerContext* context) {
- if (Command::testCommandsEnabled) {
- // Leaked intentionally: a Command registers itself when constructed.
- new RefreshLogicalSessionCacheNowCommand();
- }
- return Status::OK();
-}
-
-} // namespace mongo
diff --git a/src/mongo/db/logical_session_cache.cpp b/src/mongo/db/logical_session_cache.cpp
index fb3518ada63..7baeb66593d 100644
--- a/src/mongo/db/logical_session_cache.cpp
+++ b/src/mongo/db/logical_session_cache.cpp
@@ -226,17 +226,8 @@ void LogicalSessionCache::_refresh(Client* client) {
// failed to refresh, it means their authoritative records were removed, and
// we should remove such records from our cache as well.
{
- boost::optional<ServiceContext::UniqueOperationContext> uniqueCtx;
- auto* const opCtx = [&client, &uniqueCtx] {
- if (client->getOperationContext()) {
- return client->getOperationContext();
- }
-
- uniqueCtx.emplace(client->makeOperationContext());
- return uniqueCtx->get();
- }();
-
- auto res = _sessionsColl->refreshSessions(opCtx, std::move(activeSessions), time);
+ auto opCtx = client->makeOperationContext();
+ auto res = _sessionsColl->refreshSessions(opCtx.get(), std::move(activeSessions), time);
if (!res.isOK()) {
// TODO SERVER-29709: handle network errors here.
return;
diff --git a/src/mongo/db/service_liason_mongod.cpp b/src/mongo/db/service_liason_mongod.cpp
index 7fc58d53d24..08c49127936 100644
--- a/src/mongo/db/service_liason_mongod.cpp
+++ b/src/mongo/db/service_liason_mongod.cpp
@@ -65,19 +65,9 @@ LogicalSessionIdSet ServiceLiasonMongod::getActiveSessions() const {
// Append any in-use session ids from the global and collection-level cursor managers
{
- boost::optional<ServiceContext::UniqueOperationContext> uniqueCtx;
auto client = Client::getCurrent();
-
- auto* const opCtx = [&client, &uniqueCtx] {
- if (client->getOperationContext()) {
- return client->getOperationContext();
- }
-
- uniqueCtx.emplace(client->makeOperationContext());
- return uniqueCtx->get();
- }();
-
- CursorManager::appendAllActiveSessions(opCtx, &activeSessions);
+ auto opCtx = client->makeOperationContext();
+ CursorManager::appendAllActiveSessions(opCtx.get(), &activeSessions);
}
return activeSessions;