summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2020-05-18 15:50:24 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-02 16:49:35 +0000
commit4184f70adbfac60d6d045d9a0df46c11c3033768 (patch)
tree707ff5af8fa021dae7d958106572dacd5a13abf4 /src/mongo/shell
parent0237c8441b0ba1dfef31c22cad82d4b4570aac16 (diff)
downloadmongo-4184f70adbfac60d6d045d9a0df46c11c3033768.tar.gz
SERVER-46189 Fix shell kill current ops with TLS replica set and down nodes
(cherry picked from commit 2fbd718e0ab222d4b6614c452b0241e325421395)
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/shell_utils.cpp20
-rw-r--r--src/mongo/shell/shell_utils.h5
2 files changed, 10 insertions, 15 deletions
diff --git a/src/mongo/shell/shell_utils.cpp b/src/mongo/shell/shell_utils.cpp
index df0e8aba43c..6a4747d6c45 100644
--- a/src/mongo/shell/shell_utils.cpp
+++ b/src/mongo/shell/shell_utils.cpp
@@ -439,12 +439,11 @@ bool Prompter::confirm() {
ConnectionRegistry::ConnectionRegistry() = default;
-void ConnectionRegistry::registerConnection(DBClientBase& client) {
+void ConnectionRegistry::registerConnection(DBClientBase& client, StringData uri) {
BSONObj info;
if (client.runCommand("admin", BSON("whatsmyuri" << 1), info)) {
- std::string connstr = client.getServerAddress();
stdx::lock_guard<Latch> lk(_mutex);
- _connectionUris[connstr].insert(info["you"].str());
+ _connectionUris[uri.toString()].insert(info["you"].str());
}
}
@@ -452,15 +451,10 @@ void ConnectionRegistry::killOperationsOnAllConnections(bool withPrompt) const {
Prompter prompter("do you want to kill the current op(s) on the server?");
stdx::lock_guard<Latch> lk(_mutex);
for (auto& connection : _connectionUris) {
- auto status = ConnectionString::parse(connection.first);
- if (!status.isOK()) {
- continue;
- }
-
- const ConnectionString cs(status.getValue());
-
std::string errmsg;
- std::unique_ptr<DBClientBase> conn(cs.connect("MongoDB Shell", errmsg));
+
+ auto uri = uassertStatusOK(MongoURI::parse(connection.first));
+ std::unique_ptr<DBClientBase> conn(uri.connect("MongoDB Shell", errmsg));
if (!conn) {
continue;
}
@@ -518,7 +512,7 @@ void ConnectionRegistry::killOperationsOnAllConnections(bool withPrompt) const {
ConnectionRegistry connectionRegistry;
-void onConnect(DBClientBase& c) {
+void onConnect(DBClientBase& c, StringData uri) {
if (shellGlobalParams.nokillop) {
return;
}
@@ -528,7 +522,7 @@ void onConnect(DBClientBase& c) {
c.setClientRPCProtocols(*shellGlobalParams.rpcProtocols);
}
- connectionRegistry.registerConnection(c);
+ connectionRegistry.registerConnection(c, uri);
}
bool fileExists(const std::string& file) {
diff --git a/src/mongo/shell/shell_utils.h b/src/mongo/shell/shell_utils.h
index 5fb2b844eb6..9151faec2ce 100644
--- a/src/mongo/shell/shell_utils.h
+++ b/src/mongo/shell/shell_utils.h
@@ -34,6 +34,7 @@
#include <set>
#include <string>
+#include "mongo/client/mongo_uri.h"
#include "mongo/db/jsobj.h"
#include "mongo/platform/mutex.h"
#include "mongo/util/concurrency/mutex.h"
@@ -52,7 +53,7 @@ void RecordMyLocation(const char* _argv0);
void installShellUtils(Scope& scope);
void initScope(Scope& scope);
-void onConnect(DBClientBase& c);
+void onConnect(DBClientBase& c, StringData uri);
boost::filesystem::path getHistoryFilePath();
void setEnterpriseShellCallback(EnterpriseShellCallback* callback);
@@ -77,7 +78,7 @@ private:
class ConnectionRegistry {
public:
ConnectionRegistry();
- void registerConnection(DBClientBase& client);
+ void registerConnection(DBClientBase& client, StringData uri);
void killOperationsOnAllConnections(bool withPrompt) const;
private: