summaryrefslogtreecommitdiff
path: root/src/mongo/client/dbclient.cpp
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2016-08-04 17:29:34 -0400
committerMark Benvenuto <mark.benvenuto@mongodb.com>2016-08-04 17:29:34 -0400
commitad27c92e01758c96e7ace4cba13574e0d97a761d (patch)
tree9ef9c726765d76b531c7090063900484b65ea4c8 /src/mongo/client/dbclient.cpp
parent931a227eedca19bc05fc6318996ffd3c6a2c6f4b (diff)
downloadmongo-ad27c92e01758c96e7ace4cba13574e0d97a761d.tar.gz
SERVER-24611 Implement ClientMetadata class
Diffstat (limited to 'src/mongo/client/dbclient.cpp')
-rw-r--r--src/mongo/client/dbclient.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index cbf72c4ae7d..af53009904a 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -55,6 +55,7 @@
#include "mongo/rpc/factory.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/rpc/metadata.h"
+#include "mongo/rpc/metadata/client_metadata.h"
#include "mongo/rpc/reply_interface.h"
#include "mongo/rpc/request_builder_interface.h"
#include "mongo/s/stale_exception.h" // for RecvStaleConfigException
@@ -74,6 +75,7 @@
#include "mongo/util/password_digest.h"
#include "mongo/util/represent_as.h"
#include "mongo/util/time_support.h"
+#include "mongo/util/version.h"
namespace mongo {
@@ -712,7 +714,8 @@ private:
/**
* Initializes the wire version of conn, and returns the isMaster reply.
*/
-executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn) {
+executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn,
+ StringData applicationName) {
try {
// We need to force the usage of OP_QUERY on this command, even if we have previously
// detected support for OP_COMMAND on a connection. This is necessary to handle the case
@@ -731,6 +734,12 @@ executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn) {
bob.append("hostInfo", sb.str());
}
+ Status serializeStatus = ClientMetadata::serialize(
+ "MongoDB Internal Client", mongo::versionString, applicationName, &bob);
+ if (!serializeStatus.isOK()) {
+ return serializeStatus;
+ }
+
Date_t start{Date_t::now()};
auto result =
conn->runCommandWithMetadata("admin", "isMaster", rpc::makeEmptyMetadata(), bob.done());
@@ -754,8 +763,10 @@ executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn) {
} // namespace
-bool DBClientConnection::connect(const HostAndPort& server, std::string& errmsg) {
- auto connectStatus = connect(server);
+bool DBClientConnection::connect(const HostAndPort& server,
+ StringData applicationName,
+ std::string& errmsg) {
+ auto connectStatus = connect(server, applicationName);
if (!connectStatus.isOK()) {
errmsg = connectStatus.reason();
return false;
@@ -763,13 +774,14 @@ bool DBClientConnection::connect(const HostAndPort& server, std::string& errmsg)
return true;
}
-Status DBClientConnection::connect(const HostAndPort& serverAddress) {
+Status DBClientConnection::connect(const HostAndPort& serverAddress, StringData applicationName) {
auto connectStatus = connectSocketOnly(serverAddress);
if (!connectStatus.isOK()) {
return connectStatus;
}
- auto swIsMasterReply = initWireVersion(this);
+ _applicationName = applicationName.toString();
+ auto swIsMasterReply = initWireVersion(this, applicationName);
if (!swIsMasterReply.isOK()) {
_failed = true;
return swIsMasterReply.status;
@@ -903,7 +915,7 @@ void DBClientConnection::_checkConnection() {
LOG(_logLevel) << "trying reconnect to " << toString() << endl;
string errmsg;
_failed = false;
- auto connectStatus = connect(_serverAddress);
+ auto connectStatus = connect(_serverAddress, _applicationName);
if (!connectStatus.isOK()) {
_failed = true;
LOG(_logLevel) << "reconnect " << toString() << " failed " << errmsg << endl;