summaryrefslogtreecommitdiff
path: root/src/mongo/s
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/s
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/s')
-rw-r--r--src/mongo/s/commands/cluster_aggregate.cpp3
-rw-r--r--src/mongo/s/commands/cluster_commands_helpers.cpp5
-rw-r--r--src/mongo/s/commands/cluster_commands_helpers.h2
-rw-r--r--src/mongo/s/commands/commands_public.cpp3
-rw-r--r--src/mongo/s/commands/strategy.cpp7
-rw-r--r--src/mongo/s/write_ops/batched_command_request.cpp27
6 files changed, 20 insertions, 27 deletions
diff --git a/src/mongo/s/commands/cluster_aggregate.cpp b/src/mongo/s/commands/cluster_aggregate.cpp
index 72a860f1517..0453bfa1880 100644
--- a/src/mongo/s/commands/cluster_aggregate.cpp
+++ b/src/mongo/s/commands/cluster_aggregate.cpp
@@ -468,7 +468,8 @@ Status ClusterAggregate::aggPassthrough(OperationContext* opCtx,
opCtx,
ReadPreferenceSetting::get(opCtx),
namespaces.executionNss.db().toString(),
- !shard->isConfig() ? appendShardVersion(cmdObj, ChunkVersion::UNSHARDED()) : cmdObj,
+ !shard->isConfig() ? appendShardVersion(std::move(cmdObj), ChunkVersion::UNSHARDED())
+ : std::move(cmdObj),
Shard::RetryPolicy::kNoRetry));
if (ErrorCodes::isStaleShardingError(cmdResponse.commandStatus.code())) {
diff --git a/src/mongo/s/commands/cluster_commands_helpers.cpp b/src/mongo/s/commands/cluster_commands_helpers.cpp
index b7311ac4dbe..a8d44e4017a 100644
--- a/src/mongo/s/commands/cluster_commands_helpers.cpp
+++ b/src/mongo/s/commands/cluster_commands_helpers.cpp
@@ -213,9 +213,8 @@ StatusWith<std::vector<AsyncRequestsSender::Response>> gatherResponses(
} // namespace
-BSONObj appendShardVersion(const BSONObj& cmdObj, ChunkVersion version) {
- BSONObjBuilder cmdWithVersionBob;
- cmdWithVersionBob.appendElements(cmdObj);
+BSONObj appendShardVersion(BSONObj cmdObj, ChunkVersion version) {
+ BSONObjBuilder cmdWithVersionBob(std::move(cmdObj));
version.appendForCommands(&cmdWithVersionBob);
return cmdWithVersionBob.obj();
}
diff --git a/src/mongo/s/commands/cluster_commands_helpers.h b/src/mongo/s/commands/cluster_commands_helpers.h
index 184be2d6063..9445063e7e1 100644
--- a/src/mongo/s/commands/cluster_commands_helpers.h
+++ b/src/mongo/s/commands/cluster_commands_helpers.h
@@ -62,7 +62,7 @@ void appendWriteConcernErrorToCmdResponse(const ShardId& shardID,
/**
* Returns a copy of 'cmdObj' with 'version' appended.
*/
-BSONObj appendShardVersion(const BSONObj& cmdObj, ChunkVersion version);
+BSONObj appendShardVersion(BSONObj cmdObj, ChunkVersion version);
/**
* Generic function for dispatching commands to the cluster.
diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp
index a3cadb1ddb7..398aa6f3123 100644
--- a/src/mongo/s/commands/commands_public.cpp
+++ b/src/mongo/s/commands/commands_public.cpp
@@ -1296,8 +1296,7 @@ public:
// long as we keep getting more chunks. The end condition is when we go to
// look for chunk n and it doesn't exist. This means that the file's last
// chunk is n-1, so we return the computed md5 results.
- BSONObjBuilder bb;
- bb.appendElements(filterCommandRequestForPassthrough(cmdObj));
+ BSONObjBuilder bb(filterCommandRequestForPassthrough(cmdObj));
bb.appendBool("partialOk", true);
bb.append("startAt", n);
if (!lastResult.isEmpty()) {
diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp
index c6e69ee1bdd..afa4f04e55a 100644
--- a/src/mongo/s/commands/strategy.cpp
+++ b/src/mongo/s/commands/strategy.cpp
@@ -473,8 +473,7 @@ DbResponse Strategy::clientOpQueryCommand(OperationContext* opCtx,
// If the slaveOK bit is set, behave as-if read preference secondary-preferred was
// specified.
const auto readPref = ReadPreferenceSetting(ReadPreference::SecondaryPreferred);
- BSONObjBuilder finalCmdObjBuilder;
- finalCmdObjBuilder.appendElements(cmdObj);
+ BSONObjBuilder finalCmdObjBuilder(std::move(cmdObj));
readPref.toContainingBSON(&finalCmdObjBuilder);
cmdObj = finalCmdObjBuilder.obj();
}
@@ -662,11 +661,9 @@ void Strategy::writeOp(OperationContext* opCtx, DbMessage* dbm) {
// Adjust namespace for command
const NamespaceString& fullNS(commandRequest->getNS());
- BSONObj commandBSON = commandRequest->toBSON();
-
BSONObjBuilder builder;
runAgainstRegistered(
- opCtx, OpMsgRequest::fromDBAndBody(fullNS.db(), commandBSON), builder);
+ opCtx, OpMsgRequest::fromDBAndBody(fullNS.db(), commandRequest->toBSON()), builder);
bool parsed = commandResponse.parseBSON(builder.done(), nullptr);
(void)parsed; // for compile
diff --git a/src/mongo/s/write_ops/batched_command_request.cpp b/src/mongo/s/write_ops/batched_command_request.cpp
index e4811ffe763..48c77723db3 100644
--- a/src/mongo/s/write_ops/batched_command_request.cpp
+++ b/src/mongo/s/write_ops/batched_command_request.cpp
@@ -138,21 +138,18 @@ bool BatchedCommandRequest::isValid(std::string* errMsg) const {
}
BSONObj BatchedCommandRequest::toBSON() const {
- BSONObjBuilder builder;
-
- switch (getBatchType()) {
- case BatchedCommandRequest::BatchType_Insert:
- builder.appendElements(_insertReq->toBSON());
- break;
- case BatchedCommandRequest::BatchType_Update:
- builder.appendElements(_updateReq->toBSON());
- break;
- case BatchedCommandRequest::BatchType_Delete:
- builder.appendElements(_deleteReq->toBSON());
- break;
- default:
- MONGO_UNREACHABLE;
- }
+ BSONObjBuilder builder([&] {
+ switch (getBatchType()) {
+ case BatchedCommandRequest::BatchType_Insert:
+ return _insertReq->toBSON();
+ case BatchedCommandRequest::BatchType_Update:
+ return _updateReq->toBSON();
+ case BatchedCommandRequest::BatchType_Delete:
+ return _deleteReq->toBSON();
+ default:
+ MONGO_UNREACHABLE;
+ }
+ }());
// Append the shard version
if (_shardVersion) {