summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-08-10 15:02:41 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-08-10 17:38:54 -0400
commite1978af38dff725f0a0a60bca39a21b072751218 (patch)
treee2e4dcb138db49bbe2e069497ecb19ed753825a8 /src
parent1e1d27c271431f24cddcd2339151d7215c1178d1 (diff)
downloadmongo-e1978af38dff725f0a0a60bca39a21b072751218.tar.gz
SERVER-29202 Add a refreshLogicalSessionCacheNow test command
Diffstat (limited to 'src')
-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
4 files changed, 117 insertions, 4 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index c6197fed134..eb16bef934e 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -65,6 +65,7 @@ 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
new file mode 100644
index 00000000000..8c1c8cef489
--- /dev/null
+++ b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
@@ -0,0 +1,93 @@
+/**
+ * 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 7baeb66593d..fb3518ada63 100644
--- a/src/mongo/db/logical_session_cache.cpp
+++ b/src/mongo/db/logical_session_cache.cpp
@@ -226,8 +226,17 @@ 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.
{
- auto opCtx = client->makeOperationContext();
- auto res = _sessionsColl->refreshSessions(opCtx.get(), std::move(activeSessions), time);
+ 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);
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 08c49127936..7fc58d53d24 100644
--- a/src/mongo/db/service_liason_mongod.cpp
+++ b/src/mongo/db/service_liason_mongod.cpp
@@ -65,9 +65,19 @@ 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 opCtx = client->makeOperationContext();
- CursorManager::appendAllActiveSessions(opCtx.get(), &activeSessions);
+
+ auto* const opCtx = [&client, &uniqueCtx] {
+ if (client->getOperationContext()) {
+ return client->getOperationContext();
+ }
+
+ uniqueCtx.emplace(client->makeOperationContext());
+ return uniqueCtx->get();
+ }();
+
+ CursorManager::appendAllActiveSessions(opCtx, &activeSessions);
}
return activeSessions;