summaryrefslogtreecommitdiff
path: root/src/mongo/rpc
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-06-09 19:20:07 -0400
committerMathias Stearn <mathias@10gen.com>2017-06-19 17:08:35 -0400
commit1babec6a705c242628a765935ac9d98b56a41218 (patch)
tree1b917e39f921cce0a2cd41db170ea6c22e6348bc /src/mongo/rpc
parenta9a849b21ced693f2345d4507ee14541818244d9 (diff)
downloadmongo-1babec6a705c242628a765935ac9d98b56a41218.tar.gz
SERVER-29564 BSONObjBuilder can now be seeded with a BSONObj prefix
This will avoid copying whenever it is safe.
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r--src/mongo/rpc/command_request.cpp3
-rw-r--r--src/mongo/rpc/legacy_reply_builder.cpp4
-rw-r--r--src/mongo/rpc/legacy_reply_builder.h2
-rw-r--r--src/mongo/rpc/legacy_request.cpp2
-rw-r--r--src/mongo/rpc/metadata.cpp3
-rw-r--r--src/mongo/rpc/reply_builder_interface.cpp15
-rw-r--r--src/mongo/rpc/reply_builder_interface.h3
7 files changed, 14 insertions, 18 deletions
diff --git a/src/mongo/rpc/command_request.cpp b/src/mongo/rpc/command_request.cpp
index a796f6f8a19..067abeef636 100644
--- a/src/mongo/rpc/command_request.cpp
+++ b/src/mongo/rpc/command_request.cpp
@@ -105,8 +105,7 @@ ParsedOpCommand ParsedOpCommand::parse(const Message& message) {
OpMsgRequest opMsgRequestFromCommandRequest(const Message& message) {
auto parsed = ParsedOpCommand::parse(message);
- BSONObjBuilder bodyBuilder;
- bodyBuilder.appendElements(parsed.body);
+ BSONObjBuilder bodyBuilder(std::move(parsed.body));
// OP_COMMAND is only used when communicating with 3.4 nodes and they serialize their metadata
// fields differently. We do all up-conversion here so that the rest of the code only has to
diff --git a/src/mongo/rpc/legacy_reply_builder.cpp b/src/mongo/rpc/legacy_reply_builder.cpp
index 5fb373d12c8..340d892472f 100644
--- a/src/mongo/rpc/legacy_reply_builder.cpp
+++ b/src/mongo/rpc/legacy_reply_builder.cpp
@@ -52,7 +52,7 @@ LegacyReplyBuilder::LegacyReplyBuilder(Message&& message) : _message{std::move(m
LegacyReplyBuilder::~LegacyReplyBuilder() {}
LegacyReplyBuilder& LegacyReplyBuilder::setCommandReply(Status nonOKStatus,
- const BSONObj& extraErrorInfo) {
+ BSONObj extraErrorInfo) {
invariant(_state == State::kCommandReply);
if (nonOKStatus == ErrorCodes::SendStaleConfig) {
_staleConfigError = true;
@@ -66,7 +66,7 @@ LegacyReplyBuilder& LegacyReplyBuilder::setCommandReply(Status nonOKStatus,
setRawCommandReply(err.done());
} else {
// All other errors proceed through the normal path, which also handles state transitions.
- ReplyBuilderInterface::setCommandReply(std::move(nonOKStatus), extraErrorInfo);
+ ReplyBuilderInterface::setCommandReply(std::move(nonOKStatus), std::move(extraErrorInfo));
}
return *this;
}
diff --git a/src/mongo/rpc/legacy_reply_builder.h b/src/mongo/rpc/legacy_reply_builder.h
index beb7806147c..d72fdc6b93b 100644
--- a/src/mongo/rpc/legacy_reply_builder.h
+++ b/src/mongo/rpc/legacy_reply_builder.h
@@ -49,7 +49,7 @@ public:
~LegacyReplyBuilder() final;
// Override of setCommandReply specifically used to handle SendStaleConfigException.
- LegacyReplyBuilder& setCommandReply(Status nonOKStatus, const BSONObj& extraErrorInfo) final;
+ LegacyReplyBuilder& setCommandReply(Status nonOKStatus, BSONObj extraErrorInfo) final;
LegacyReplyBuilder& setRawCommandReply(const BSONObj& commandReply) final;
BSONObjBuilder getInPlaceReplyBuilder(std::size_t) final;
diff --git a/src/mongo/rpc/legacy_request.cpp b/src/mongo/rpc/legacy_request.cpp
index 9d5beae3af2..8247c7d3923 100644
--- a/src/mongo/rpc/legacy_request.cpp
+++ b/src/mongo/rpc/legacy_request.cpp
@@ -55,7 +55,7 @@ OpMsgRequest opMsgRequestFromLegacyRequest(const Message& message) {
auto bodyAndMetadata = rpc::upconvertRequestMetadata(qm.query, qm.queryOptions);
return OpMsgRequest::fromDBAndBody(
- ns.db(), std::get<0>(bodyAndMetadata), std::get<1>(bodyAndMetadata));
+ ns.db(), std::move(std::get<0>(bodyAndMetadata)), std::get<1>(bodyAndMetadata));
}
} // namespace rpc
diff --git a/src/mongo/rpc/metadata.cpp b/src/mongo/rpc/metadata.cpp
index bf3aab6c8e4..715532f453d 100644
--- a/src/mongo/rpc/metadata.cpp
+++ b/src/mongo/rpc/metadata.cpp
@@ -164,8 +164,7 @@ CommandAndMetadata upconvertRequestMetadata(BSONObj legacyCmdObj, int queryFlags
LegacyCommandAndFlags downconvertRequestMetadata(BSONObj cmdObj, BSONObj metadata) {
int legacyQueryFlags = 0;
if (auto logicalTime = metadata[LogicalTimeMetadata::fieldName()]) {
- BSONObjBuilder logicalTimeCommandBob;
- logicalTimeCommandBob.appendElements(cmdObj);
+ BSONObjBuilder logicalTimeCommandBob(std::move(cmdObj));
logicalTimeCommandBob.append(logicalTime);
cmdObj = logicalTimeCommandBob.obj();
}
diff --git a/src/mongo/rpc/reply_builder_interface.cpp b/src/mongo/rpc/reply_builder_interface.cpp
index 34a99cd4176..99fe2edcb1e 100644
--- a/src/mongo/rpc/reply_builder_interface.cpp
+++ b/src/mongo/rpc/reply_builder_interface.cpp
@@ -48,14 +48,13 @@ const char kErrorField[] = "errmsg";
// similar to appendCommandStatus (duplicating logic here to avoid cyclic library
// dependency)
-BSONObj augmentReplyWithStatus(const Status& status, const BSONObj& reply) {
+BSONObj augmentReplyWithStatus(const Status& status, BSONObj reply) {
auto okField = reply.getField(kOKField);
if (!okField.eoo() && okField.trueValue()) {
return reply;
}
- BSONObjBuilder bob;
- bob.appendElements(reply);
+ BSONObjBuilder bob(std::move(reply));
if (okField.eoo()) {
bob.append(kOKField, status.isOK() ? 1.0 : 0.0);
}
@@ -63,11 +62,11 @@ BSONObj augmentReplyWithStatus(const Status& status, const BSONObj& reply) {
return bob.obj();
}
- if (!reply.hasField(kErrorField)) {
+ if (!bob.asTempObj().hasField(kErrorField)) {
bob.append(kErrorField, status.reason());
}
- if (!reply.hasField(kCodeField)) {
+ if (!bob.asTempObj().hasField(kCodeField)) {
bob.append(kCodeField, status.code());
bob.append(kCodeNameField, ErrorCodes::errorString(status.code()));
}
@@ -78,13 +77,13 @@ BSONObj augmentReplyWithStatus(const Status& status, const BSONObj& reply) {
ReplyBuilderInterface& ReplyBuilderInterface::setCommandReply(StatusWith<BSONObj> commandReply) {
auto reply = commandReply.isOK() ? std::move(commandReply.getValue()) : BSONObj();
- return setRawCommandReply(augmentReplyWithStatus(commandReply.getStatus(), reply));
+ return setRawCommandReply(augmentReplyWithStatus(commandReply.getStatus(), std::move(reply)));
}
ReplyBuilderInterface& ReplyBuilderInterface::setCommandReply(Status nonOKStatus,
- const BSONObj& extraErrorInfo) {
+ BSONObj extraErrorInfo) {
invariant(!nonOKStatus.isOK());
- return setRawCommandReply(augmentReplyWithStatus(nonOKStatus, extraErrorInfo));
+ return setRawCommandReply(augmentReplyWithStatus(nonOKStatus, std::move(extraErrorInfo)));
}
} // namespace rpc
diff --git a/src/mongo/rpc/reply_builder_interface.h b/src/mongo/rpc/reply_builder_interface.h
index b2631bfaf0e..a157f41167e 100644
--- a/src/mongo/rpc/reply_builder_interface.h
+++ b/src/mongo/rpc/reply_builder_interface.h
@@ -84,8 +84,7 @@ public:
* interfacing with legacy code that adds additional data to a failed command reply and
* its use is discouraged in new code.
*/
- virtual ReplyBuilderInterface& setCommandReply(Status nonOKStatus,
- const BSONObj& extraErrorInfo);
+ virtual ReplyBuilderInterface& setCommandReply(Status nonOKStatus, BSONObj extraErrorInfo);
/**
* Gets the protocol used to serialize this reply. This should be used for validity checks