55
55
#include " mongo/rpc/factory.h"
56
56
#include " mongo/rpc/get_status_from_command_result.h"
57
57
#include " mongo/rpc/metadata.h"
58
+ #include " mongo/rpc/metadata/client_metadata.h"
58
59
#include " mongo/rpc/reply_interface.h"
59
60
#include " mongo/rpc/request_builder_interface.h"
60
61
#include " mongo/s/stale_exception.h" // for RecvStaleConfigException
74
75
#include " mongo/util/password_digest.h"
75
76
#include " mongo/util/represent_as.h"
76
77
#include " mongo/util/time_support.h"
78
+ #include " mongo/util/version.h"
77
79
78
80
namespace mongo {
79
81
@@ -712,7 +714,8 @@ class ScopedForceOpQuery {
712
714
/* *
713
715
* Initializes the wire version of conn, and returns the isMaster reply.
714
716
*/
715
- executor::RemoteCommandResponse initWireVersion (DBClientConnection* conn) {
717
+ executor::RemoteCommandResponse initWireVersion (DBClientConnection* conn,
718
+ StringData applicationName) {
716
719
try {
717
720
// We need to force the usage of OP_QUERY on this command, even if we have previously
718
721
// detected support for OP_COMMAND on a connection. This is necessary to handle the case
@@ -731,6 +734,12 @@ executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn) {
731
734
bob.append (" hostInfo" , sb.str ());
732
735
}
733
736
737
+ Status serializeStatus = ClientMetadata::serialize (
738
+ " MongoDB Internal Client" , mongo::versionString, applicationName, &bob);
739
+ if (!serializeStatus.isOK ()) {
740
+ return serializeStatus;
741
+ }
742
+
734
743
Date_t start{Date_t::now ()};
735
744
auto result =
736
745
conn->runCommandWithMetadata (" admin" , " isMaster" , rpc::makeEmptyMetadata (), bob.done ());
@@ -754,22 +763,25 @@ executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn) {
754
763
755
764
} // namespace
756
765
757
- bool DBClientConnection::connect (const HostAndPort& server, std::string& errmsg) {
758
- auto connectStatus = connect (server);
766
+ bool DBClientConnection::connect (const HostAndPort& server,
767
+ StringData applicationName,
768
+ std::string& errmsg) {
769
+ auto connectStatus = connect (server, applicationName);
759
770
if (!connectStatus.isOK ()) {
760
771
errmsg = connectStatus.reason ();
761
772
return false ;
762
773
}
763
774
return true ;
764
775
}
765
776
766
- Status DBClientConnection::connect (const HostAndPort& serverAddress) {
777
+ Status DBClientConnection::connect (const HostAndPort& serverAddress, StringData applicationName ) {
767
778
auto connectStatus = connectSocketOnly (serverAddress);
768
779
if (!connectStatus.isOK ()) {
769
780
return connectStatus;
770
781
}
771
782
772
- auto swIsMasterReply = initWireVersion (this );
783
+ _applicationName = applicationName.toString ();
784
+ auto swIsMasterReply = initWireVersion (this , applicationName);
773
785
if (!swIsMasterReply.isOK ()) {
774
786
_failed = true ;
775
787
return swIsMasterReply.status ;
@@ -903,7 +915,7 @@ void DBClientConnection::_checkConnection() {
903
915
LOG (_logLevel) << " trying reconnect to " << toString () << endl;
904
916
string errmsg;
905
917
_failed = false ;
906
- auto connectStatus = connect (_serverAddress);
918
+ auto connectStatus = connect (_serverAddress, _applicationName );
907
919
if (!connectStatus.isOK ()) {
908
920
_failed = true ;
909
921
LOG (_logLevel) << " reconnect " << toString () << " failed " << errmsg << endl;
0 commit comments