summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2018-07-25 17:33:21 -0400
committerMathias Stearn <mathias@10gen.com>2018-07-30 14:13:08 -0400
commita5f3bf878d5059215fbc5a5a371aaf2d8a85e8b9 (patch)
tree86baac1bd319bbe02ca31c2404d0b631ff5a25ad /src/mongo/rpc
parentcca8ad6cf6f47e86158a8636b6a07743bd115fcc (diff)
downloadmongo-a5f3bf878d5059215fbc5a5a371aaf2d8a85e8b9.tar.gz
SERVER-33135 Remove metadata accessors from command reply APIs
Now that OP_COMMAND is dead, all remaining implementations return the same BSONObj for data and metadata.
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/legacy_reply.cpp4
-rw-r--r--src/mongo/rpc/legacy_reply.h8
-rw-r--r--src/mongo/rpc/legacy_reply_builder.cpp26
-rw-r--r--src/mongo/rpc/legacy_reply_builder.h10
-rw-r--r--src/mongo/rpc/op_msg_rpc_impls.h7
-rw-r--r--src/mongo/rpc/reply_builder_interface.h2
-rw-r--r--src/mongo/rpc/reply_builder_test.cpp12
-rw-r--r--src/mongo/rpc/reply_interface.h6
8 files changed, 17 insertions, 58 deletions
diff --git a/src/mongo/rpc/legacy_reply.cpp b/src/mongo/rpc/legacy_reply.cpp
index d21b880e60c..c6ba4bfbb02 100644
--- a/src/mongo/rpc/legacy_reply.cpp
+++ b/src/mongo/rpc/legacy_reply.cpp
@@ -102,10 +102,6 @@ LegacyReply::LegacyReply(const Message* message) {
return;
}
-const BSONObj& LegacyReply::getMetadata() const {
- return _commandReply;
-}
-
const BSONObj& LegacyReply::getCommandReply() const {
return _commandReply;
}
diff --git a/src/mongo/rpc/legacy_reply.h b/src/mongo/rpc/legacy_reply.h
index f283bb954ec..b428319d5a7 100644
--- a/src/mongo/rpc/legacy_reply.h
+++ b/src/mongo/rpc/legacy_reply.h
@@ -41,7 +41,7 @@ namespace rpc {
/**
* Immutable view of an OP_REPLY legacy-style command reply.
*/
-class LegacyReply : public ReplyInterface {
+class LegacyReply final : public ReplyInterface {
public:
/**
* Construct a Reply from a Message.
@@ -50,12 +50,6 @@ public:
explicit LegacyReply(const Message* message);
/**
- * Accessor for the metadata object. Metadata is generally used for information
- * that is independent of any specific command, e.g. auditing information.
- */
- const BSONObj& getMetadata() const final;
-
- /**
* The result of executing the command.
*/
const BSONObj& getCommandReply() const final;
diff --git a/src/mongo/rpc/legacy_reply_builder.cpp b/src/mongo/rpc/legacy_reply_builder.cpp
index 78663e9f75f..1d88eb96aa5 100644
--- a/src/mongo/rpc/legacy_reply_builder.cpp
+++ b/src/mongo/rpc/legacy_reply_builder.cpp
@@ -54,7 +54,7 @@ LegacyReplyBuilder::~LegacyReplyBuilder() {}
LegacyReplyBuilder& LegacyReplyBuilder::setCommandReply(Status nonOKStatus,
BSONObj extraErrorInfo) {
- invariant(_state == State::kCommandReply);
+ invariant(!_haveCommandReply);
if (nonOKStatus == ErrorCodes::StaleConfig) {
_staleConfigError = true;
@@ -77,32 +77,25 @@ LegacyReplyBuilder& LegacyReplyBuilder::setCommandReply(Status nonOKStatus,
}
LegacyReplyBuilder& LegacyReplyBuilder::setRawCommandReply(const BSONObj& commandReply) {
- invariant(_state == State::kCommandReply);
+ invariant(!_haveCommandReply);
+ _bodyOffset = _builder.len();
commandReply.appendSelfToBufBuilder(_builder);
- _state = State::kMetadata;
+ _haveCommandReply = true;
return *this;
}
BSONObjBuilder LegacyReplyBuilder::getBodyBuilder() {
- if (_state == State::kCommandReply) {
+ if (!_haveCommandReply) {
auto bob = BSONObjBuilder(_builder);
_bodyOffset = bob.offset();
- _state = State::kMetadata;
+ _haveCommandReply = true;
return bob;
}
- invariant(_state == State::kMetadata);
invariant(_bodyOffset);
return BSONObjBuilder(BSONObjBuilder::ResumeBuildingTag{}, _builder, _bodyOffset);
}
-LegacyReplyBuilder& LegacyReplyBuilder::setMetadata(const BSONObj& metadata) {
- invariant(_state == State::kMetadata);
- BSONObjBuilder(BSONObjBuilder::ResumeBuildingTag(), _builder, sizeof(QueryResult::Value))
- .appendElements(metadata);
- _state = State::kOutputDocs;
- return *this;
-}
Protocol LegacyReplyBuilder::getProtocol() const {
return rpc::Protocol::kOpQuery;
@@ -116,20 +109,20 @@ void LegacyReplyBuilder::reserveBytes(const std::size_t bytes) {
void LegacyReplyBuilder::reset() {
// If we are in State::kMetadata, we are already in the 'start' state, so by
// immediately returning, we save a heap allocation.
- if (_state == State::kCommandReply) {
+ if (!_haveCommandReply) {
return;
}
_builder.reset();
_builder.skip(sizeof(QueryResult::Value));
_message.reset();
- _state = State::kCommandReply;
+ _haveCommandReply = false;
_staleConfigError = false;
_bodyOffset = 0;
}
Message LegacyReplyBuilder::done() {
- invariant(_state == State::kOutputDocs);
+ invariant(_haveCommandReply);
QueryResult::View qr = _builder.buf();
@@ -148,7 +141,6 @@ Message LegacyReplyBuilder::done() {
_message.setData(_builder.release());
- _state = State::kDone;
return std::move(_message);
}
diff --git a/src/mongo/rpc/legacy_reply_builder.h b/src/mongo/rpc/legacy_reply_builder.h
index 4f3128bb2be..3c90dc7db4f 100644
--- a/src/mongo/rpc/legacy_reply_builder.h
+++ b/src/mongo/rpc/legacy_reply_builder.h
@@ -54,8 +54,6 @@ public:
BSONObjBuilder getBodyBuilder() final;
- LegacyReplyBuilder& setMetadata(const BSONObj& metadata) final;
-
void reset() final;
Message done() final;
@@ -65,14 +63,12 @@ public:
void reserveBytes(const std::size_t bytes) final;
private:
- enum class State { kMetadata, kCommandReply, kOutputDocs, kDone };
-
- BufBuilder _builder{};
+ BufBuilder _builder;
std::size_t _bodyOffset = 0;
Message _message;
- State _state{State::kCommandReply};
+ bool _haveCommandReply = false;
// For stale config errors we need to set the correct ResultFlag.
- bool _staleConfigError{false};
+ bool _staleConfigError = false;
};
} // namespace rpc
diff --git a/src/mongo/rpc/op_msg_rpc_impls.h b/src/mongo/rpc/op_msg_rpc_impls.h
index b16a9a7c0cd..ab09ffc3a2d 100644
--- a/src/mongo/rpc/op_msg_rpc_impls.h
+++ b/src/mongo/rpc/op_msg_rpc_impls.h
@@ -39,9 +39,6 @@ class OpMsgReply final : public rpc::ReplyInterface {
public:
explicit OpMsgReply(const Message* message) : _msg(OpMsg::parseOwned(*message)) {}
explicit OpMsgReply(OpMsg msg) : _msg(std::move(msg)) {}
- const BSONObj& getMetadata() const override {
- return _msg.body;
- }
const BSONObj& getCommandReply() const override {
return _msg.body;
}
@@ -68,10 +65,6 @@ public:
OpMsgBuilder::DocSequenceBuilder getDocSequenceBuilder(StringData name) override {
return _builder.beginDocSequence(name);
}
- ReplyBuilderInterface& setMetadata(const BSONObj& metadata) override {
- _builder.resumeBody().appendElements(metadata);
- return *this;
- }
rpc::Protocol getProtocol() const override {
return rpc::Protocol::kOpMsg;
}
diff --git a/src/mongo/rpc/reply_builder_interface.h b/src/mongo/rpc/reply_builder_interface.h
index 64a8cab8891..e8ba5383090 100644
--- a/src/mongo/rpc/reply_builder_interface.h
+++ b/src/mongo/rpc/reply_builder_interface.h
@@ -75,8 +75,6 @@ public:
uasserted(50875, "Only OpMsg may use document sequences");
}
- virtual ReplyBuilderInterface& setMetadata(const BSONObj& metadata) = 0;
-
/**
* Sets the reply for this command. If an engaged StatusWith<BSONObj> is passed, the command
* reply will be set to the contained BSONObj, augmented with the element {ok, 1.0} if it
diff --git a/src/mongo/rpc/reply_builder_test.cpp b/src/mongo/rpc/reply_builder_test.cpp
index dd0d36a5739..2a15f519bdf 100644
--- a/src/mongo/rpc/reply_builder_test.cpp
+++ b/src/mongo/rpc/reply_builder_test.cpp
@@ -125,7 +125,7 @@ TEST(LegacyReplyBuilder, CommandError) {
const BSONObj extraObj = extra.obj();
rpc::LegacyReplyBuilder replyBuilder;
replyBuilder.setCommandReply(status, extraObj);
- replyBuilder.setMetadata(metadata);
+ replyBuilder.getBodyBuilder().appendElements(metadata);
auto msg = replyBuilder.done();
rpc::LegacyReply parsed(&msg);
@@ -136,7 +136,6 @@ TEST(LegacyReplyBuilder, CommandError) {
return unifiedBuilder.obj();
}());
- ASSERT_BSONOBJ_EQ(parsed.getMetadata(), body);
ASSERT_BSONOBJ_EQ(parsed.getCommandReply(), body);
}
@@ -149,7 +148,7 @@ TEST(OpMsgReplyBuilder, CommandError) {
const BSONObj extraObj = extra.obj();
rpc::OpMsgReplyBuilder replyBuilder;
replyBuilder.setCommandReply(status, extraObj);
- replyBuilder.setMetadata(metadata);
+ replyBuilder.getBodyBuilder().appendElements(metadata);
auto msg = replyBuilder.done();
rpc::OpMsgReply parsed(&msg);
@@ -160,7 +159,6 @@ TEST(OpMsgReplyBuilder, CommandError) {
return unifiedBuilder.obj();
}());
- ASSERT_BSONOBJ_EQ(parsed.getMetadata(), body);
ASSERT_BSONOBJ_EQ(parsed.getCommandReply(), body);
}
@@ -170,7 +168,7 @@ void testRoundTrip(rpc::ReplyBuilderInterface& replyBuilder, bool unifiedBodyAnd
auto commandReply = buildEmptyCommand();
replyBuilder.setCommandReply(commandReply);
- replyBuilder.setMetadata(metadata);
+ replyBuilder.getBodyBuilder().appendElements(metadata);
auto msg = replyBuilder.done();
@@ -184,10 +182,8 @@ void testRoundTrip(rpc::ReplyBuilderInterface& replyBuilder, bool unifiedBodyAnd
}());
ASSERT_BSONOBJ_EQ(parsed.getCommandReply(), body);
- ASSERT_BSONOBJ_EQ(parsed.getMetadata(), body);
} else {
ASSERT_BSONOBJ_EQ(parsed.getCommandReply(), commandReply);
- ASSERT_BSONOBJ_EQ(parsed.getMetadata(), metadata);
}
}
@@ -198,7 +194,7 @@ void testErrors(rpc::ReplyBuilderInterface& replyBuilder) {
const auto status = Status(ErrorExtraInfoExample(123), "Why does this keep failing!");
replyBuilder.setCommandReply(status);
- replyBuilder.setMetadata(buildMetadata());
+ replyBuilder.getBodyBuilder().appendElements(buildMetadata());
const auto msg = replyBuilder.done();
diff --git a/src/mongo/rpc/reply_interface.h b/src/mongo/rpc/reply_interface.h
index a5e72255d6e..c51fb686459 100644
--- a/src/mongo/rpc/reply_interface.h
+++ b/src/mongo/rpc/reply_interface.h
@@ -47,12 +47,6 @@ public:
virtual ~ReplyInterface() = default;
/**
- * Accessor for the metadata object. Metadata is generally used for information
- * that is independent of any specific command, e.g. auditing information.
- */
- virtual const BSONObj& getMetadata() const = 0;
-
- /**
* The result of executing the command.
*/
virtual const BSONObj& getCommandReply() const = 0;