diff options
author | Randolph Tan <randolph@10gen.com> | 2017-03-09 10:51:50 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2017-03-09 10:51:50 -0500 |
commit | 4e2cb91ed1fe8a9a8caead72a7f0bd56b2ba28d1 (patch) | |
tree | d17054bdecbcae1effc432ecf041a2ca5a853be9 /src/mongo/rpc/metadata | |
parent | 73d3473fb11ff4fbdb404d0c6c409a309ccd7646 (diff) | |
download | mongo-4e2cb91ed1fe8a9a8caead72a7f0bd56b2ba28d1.tar.gz |
Revert "SERVER-27750 Attach LogicalTimeMetadata to globalConnPool and shardConnectionPool"
This reverts commit 34dbe2a42d1db621f16555878b57f48efb30cc28.
Diffstat (limited to 'src/mongo/rpc/metadata')
4 files changed, 34 insertions, 24 deletions
diff --git a/src/mongo/rpc/metadata/egress_metadata_hook_list.cpp b/src/mongo/rpc/metadata/egress_metadata_hook_list.cpp index 2c2ae6d3349..5e11c84eb60 100644 --- a/src/mongo/rpc/metadata/egress_metadata_hook_list.cpp +++ b/src/mongo/rpc/metadata/egress_metadata_hook_list.cpp @@ -41,9 +41,10 @@ void EgressMetadataHookList::addHook(std::unique_ptr<EgressMetadataHook>&& newHo } Status EgressMetadataHookList::writeRequestMetadata(OperationContext* opCtx, + const HostAndPort& requestDestination, BSONObjBuilder* metadataBob) { for (auto&& hook : _hooks) { - auto status = hook->writeRequestMetadata(opCtx, metadataBob); + auto status = hook->writeRequestMetadata(opCtx, requestDestination, metadataBob); if (!status.isOK()) { return status; } @@ -52,7 +53,7 @@ Status EgressMetadataHookList::writeRequestMetadata(OperationContext* opCtx, return Status::OK(); } -Status EgressMetadataHookList::readReplyMetadata(StringData replySource, +Status EgressMetadataHookList::readReplyMetadata(const HostAndPort& replySource, const BSONObj& metadataObj) { for (auto&& hook : _hooks) { auto status = hook->readReplyMetadata(replySource, metadataObj); diff --git a/src/mongo/rpc/metadata/egress_metadata_hook_list.h b/src/mongo/rpc/metadata/egress_metadata_hook_list.h index 64087bc0e25..54b03b80c5e 100644 --- a/src/mongo/rpc/metadata/egress_metadata_hook_list.h +++ b/src/mongo/rpc/metadata/egress_metadata_hook_list.h @@ -58,14 +58,16 @@ public: * early if one of hooks returned a non OK status and return it. Note that metadataBob should * not be used if Status is not OK as the contents can be partial. */ - Status writeRequestMetadata(OperationContext* opCtx, BSONObjBuilder* metadataBob) override; + Status writeRequestMetadata(OperationContext* opCtx, + const HostAndPort& requestDestination, + BSONObjBuilder* metadataBob) override; /** * Calls readReplyMetadata on every hook in the order they were added. This will terminate * early if one of hooks returned a non OK status and return it. Note that metadataBob should * not be used if Status is not OK as the contents can be partial. */ - Status readReplyMetadata(StringData replySource, const BSONObj& metadataObj) override; + Status readReplyMetadata(const HostAndPort& replySource, const BSONObj& metadataObj) override; private: std::vector<std::unique_ptr<EgressMetadataHook>> _hooks; diff --git a/src/mongo/rpc/metadata/egress_metadata_hook_list_test.cpp b/src/mongo/rpc/metadata/egress_metadata_hook_list_test.cpp index 63293347428..159a78412fb 100644 --- a/src/mongo/rpc/metadata/egress_metadata_hook_list_test.cpp +++ b/src/mongo/rpc/metadata/egress_metadata_hook_list_test.cpp @@ -43,7 +43,7 @@ namespace { struct ReadReplyArgs { public: - StringData replySource; + HostAndPort replySource; BSONObj metadataObj; }; @@ -51,12 +51,14 @@ class TestHook : public EgressMetadataHook { public: TestHook(string fieldName, ReadReplyArgs* arg) : _fieldName(fieldName), _arg(arg) {} - Status writeRequestMetadata(OperationContext* opCtx, BSONObjBuilder* metadataBob) override { - metadataBob->append(_fieldName, ""); + Status writeRequestMetadata(OperationContext* opCtx, + const HostAndPort& requestDestination, + BSONObjBuilder* metadataBob) override { + metadataBob->append(_fieldName, requestDestination.toString()); return Status::OK(); } - Status readReplyMetadata(StringData replySource, const BSONObj& metadataObj) { + Status readReplyMetadata(const HostAndPort& replySource, const BSONObj& metadataObj) { invariant(_arg != nullptr); _arg->replySource = replySource; _arg->metadataObj = metadataObj; @@ -72,11 +74,13 @@ class FixedStatusTestHook : public EgressMetadataHook { public: FixedStatusTestHook(Status status) : _toRet(status) {} - Status writeRequestMetadata(OperationContext* opCtx, BSONObjBuilder* metadataBob) override { + Status writeRequestMetadata(OperationContext* opCtx, + const HostAndPort& requestDestination, + BSONObjBuilder* metadataBob) override { return _toRet; } - Status readReplyMetadata(StringData replySource, const BSONObj& metadataObj) { + Status readReplyMetadata(const HostAndPort& replySource, const BSONObj& metadataObj) { return _toRet; } @@ -86,10 +90,11 @@ private: TEST(EgressMetadataHookListTest, EmptyHookShouldNotFail) { EgressMetadataHookList hookList; - ASSERT_OK(hookList.writeRequestMetadata(nullptr, nullptr)); + HostAndPort emptyHost; + ASSERT_OK(hookList.writeRequestMetadata(nullptr, emptyHost, nullptr)); BSONObj emptyObj; - ASSERT_OK(hookList.readReplyMetadata("", emptyObj)); + ASSERT_OK(hookList.readReplyMetadata(emptyHost, emptyObj)); } TEST(EgressMetadataHookListTest, SingleHook) { @@ -99,12 +104,12 @@ TEST(EgressMetadataHookListTest, SingleHook) { hookList.addHook(std::move(hook1)); BSONObjBuilder builder; - ASSERT_OK(hookList.writeRequestMetadata(nullptr, &builder)); + ASSERT_OK(hookList.writeRequestMetadata(nullptr, HostAndPort("a:123"), &builder)); ASSERT_BSONOBJ_EQ(BSON("h1" - << ""), + << "a:123"), builder.obj()); - string testHost("b:456"); + HostAndPort testHost("b:456"); BSONObj testObj(BSON("x" << 1)); ASSERT_OK(hookList.readReplyMetadata(testHost, testObj)); ASSERT_EQ(testHost, hook1Args.replySource); @@ -122,14 +127,14 @@ TEST(EgressMetadataHookListTest, MultipleHooks) { hookList.addHook(std::move(hook2)); BSONObjBuilder builder; - ASSERT_OK(hookList.writeRequestMetadata(nullptr, &builder)); + ASSERT_OK(hookList.writeRequestMetadata(nullptr, HostAndPort("a:123"), &builder)); ASSERT_BSONOBJ_EQ(BSON("foo" - << "" + << "a:123" << "bar" - << ""), + << "a:123"), builder.obj()); - string testHost("b:456"); + HostAndPort testHost("b:456"); BSONObj testObj(BSON("x" << 1)); ASSERT_OK(hookList.readReplyMetadata(testHost, testObj)); @@ -151,8 +156,8 @@ TEST(EgressMetadataHookListTest, SingleBadHookShouldReturnError) { hookList.addHook(std::move(hook2)); BSONObjBuilder builder; - ASSERT_NOT_OK(hookList.writeRequestMetadata(nullptr, &builder)); - ASSERT_NOT_OK(hookList.readReplyMetadata("b:456", BSON("x" << 1))); + ASSERT_NOT_OK(hookList.writeRequestMetadata(nullptr, HostAndPort("a:123"), &builder)); + ASSERT_NOT_OK(hookList.readReplyMetadata(HostAndPort("b:456"), BSON("x" << 1))); } } // unnamed namespace diff --git a/src/mongo/rpc/metadata/metadata_hook.h b/src/mongo/rpc/metadata/metadata_hook.h index 1bb050e0eda..81f0001f548 100644 --- a/src/mongo/rpc/metadata/metadata_hook.h +++ b/src/mongo/rpc/metadata/metadata_hook.h @@ -35,7 +35,6 @@ class BSONObjBuilder; struct HostAndPort; class OperationContext; class Status; -class StringData; namespace rpc { @@ -59,13 +58,16 @@ public: * not * have an OperationContext as a result. */ - virtual Status writeRequestMetadata(OperationContext* opCtx, BSONObjBuilder* metadataBob) = 0; + virtual Status writeRequestMetadata(OperationContext* opCtx, + const HostAndPort& requestDestination, + BSONObjBuilder* metadataBob) = 0; /** * Reads metadata from an incoming command reply. This method must not throw or block on * database or network operations and can be called by multiple concurrent threads. */ - virtual Status readReplyMetadata(StringData replySource, const BSONObj& metadataObj) = 0; + virtual Status readReplyMetadata(const HostAndPort& replySource, + const BSONObj& metadataObj) = 0; protected: EgressMetadataHook() = default; |