summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorBernard Gorman <bernard.gorman@gmail.com>2018-03-14 17:46:22 +0000
committerBernard Gorman <bernard.gorman@gmail.com>2018-03-15 17:33:50 +0000
commit5ecf2c0a5bffa837c96ad20dea23a94c5165739a (patch)
tree254b1baa62ecd3092b8962778fcc0480c066de03 /src/mongo/rpc
parent8c639f958eb5edff4d52560e4c3dfe04c7a78f31 (diff)
downloadmongo-5ecf2c0a5bffa837c96ad20dea23a94c5165739a.tar.gz
SERVER-18094 Add 'localOps' parameter to $currentOp to show local mongoS operations
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/metadata/client_metadata.cpp21
-rw-r--r--src/mongo/rpc/metadata/client_metadata_test.cpp2
2 files changed, 21 insertions, 2 deletions
diff --git a/src/mongo/rpc/metadata/client_metadata.cpp b/src/mongo/rpc/metadata/client_metadata.cpp
index adcb3711b71..eebf1b6d9dc 100644
--- a/src/mongo/rpc/metadata/client_metadata.cpp
+++ b/src/mongo/rpc/metadata/client_metadata.cpp
@@ -306,9 +306,26 @@ void ClientMetadata::setMongoSMetadata(StringData hostAndPort,
sub.append(kVersion, version);
}
- _document = builder.obj();
-}
+ auto document = builder.obj();
+
+ if (!_appName.empty()) {
+ // The _appName field points into the existing _document, which we are about to replace.
+ // We must redirect _appName to point into the new doc *before* replacing the old doc. We
+ // expect the 'application' metadata of the new document to be identical to the old.
+ auto appMetaData = document[kApplication];
+ invariant(appMetaData.isABSONObj());
+
+ auto appNameEl = appMetaData[kName];
+ invariant(appNameEl.type() == BSONType::String);
+
+ auto appName = appNameEl.valueStringData();
+ invariant(appName == _appName);
+ _appName = appName;
+ }
+
+ _document = std::move(document);
+}
void ClientMetadata::serialize(StringData driverName,
StringData driverVersion,
diff --git a/src/mongo/rpc/metadata/client_metadata_test.cpp b/src/mongo/rpc/metadata/client_metadata_test.cpp
index 7d3166127f4..30e96b33bf8 100644
--- a/src/mongo/rpc/metadata/client_metadata_test.cpp
+++ b/src/mongo/rpc/metadata/client_metadata_test.cpp
@@ -313,6 +313,8 @@ TEST(ClientMetadatTest, TestMongoSAppend) {
ASSERT_EQUALS("g", swParseStatus.getValue().get().getApplicationName());
swParseStatus.getValue().get().setMongoSMetadata("h", "i", "j");
+ ASSERT_EQUALS("g", swParseStatus.getValue().get().getApplicationName());
+
auto doc = swParseStatus.getValue().get().getDocument();
constexpr auto kMongos = "mongos"_sd;