summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorAdam Midvidy <amidvidy@gmail.com>2015-06-09 23:30:07 -0400
committerAdam Midvidy <amidvidy@gmail.com>2015-06-16 16:25:33 -0400
commitb5e98006ec7b05d69e9defedce7fe9190db3b60c (patch)
tree355e15b2bcbd77cf214262a80d3477807f99229c /src/mongo
parent0641c637933aef4290963d99fe9cf9c5509a29ef (diff)
downloadmongo-b5e98006ec7b05d69e9defedce7fe9190db3b60c.tar.gz
SERVER-18292 support OP_COMMAND in commands executed with DBClientMultiCommand
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/s/client/dbclient_multi_command.cpp47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/mongo/s/client/dbclient_multi_command.cpp b/src/mongo/s/client/dbclient_multi_command.cpp
index 99f6bde3a82..3d7202f72ac 100644
--- a/src/mongo/s/client/dbclient_multi_command.cpp
+++ b/src/mongo/s/client/dbclient_multi_command.cpp
@@ -34,6 +34,8 @@
#include "mongo/db/audit.h"
#include "mongo/db/dbmessage.h"
#include "mongo/db/wire_version.h"
+#include "mongo/rpc/factory.h"
+#include "mongo/rpc/request_builder_interface.h"
#include "mongo/s/client/shard_connection.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/util/net/message.h"
@@ -87,22 +89,29 @@ namespace mongo {
// THROWS
static void sayAsCmd( DBClientBase* conn, StringData dbName, const BSONObj& cmdObj ) {
- Message toSend;
- BSONObjBuilder usersBuilder;
- usersBuilder.appendElements(cmdObj);
- audit::appendImpersonatedUsers(&usersBuilder);
-
- // see query.h for the protocol we are using here.
- BufBuilder bufB;
- bufB.appendNum( 0 ); // command/query options
- bufB.appendStr( dbName.toString() + ".$cmd" ); // write command ns
- bufB.appendNum( 0 ); // ntoskip (0 for command)
- bufB.appendNum( 1 ); // ntoreturn (1 for command)
- usersBuilder.obj().appendSelfToBufBuilder( bufB );
- toSend.setData( dbQuery, bufB.buf(), bufB.len() );
+ auto requestBuilder = rpc::makeRequestBuilder(conn->getClientRPCProtocols(),
+ conn->getServerRPCProtocols());
+ BSONObj upconvertedCmd;
+ BSONObj upconvertedMetadata;
+
+ // Previous implementation had hardcoded flags of 0 - more specifically, writes
+ // are never secondaryOk.
+ std::tie(upconvertedCmd, upconvertedMetadata) = uassertStatusOK(
+ rpc::upconvertRequestMetadata(cmdObj, 0)
+ );
+
+ BSONObjBuilder metadataBob;
+ metadataBob.appendElements(upconvertedMetadata);
+ if (conn->getRequestMetadataWriter()) {
+ conn->getRequestMetadataWriter()(&metadataBob);
+ }
+ requestBuilder->setDatabase(dbName);
+ requestBuilder->setCommandName(upconvertedCmd.firstElementFieldName());
+ requestBuilder->setMetadata(metadataBob.done());
+ requestBuilder->setCommandArgs(upconvertedCmd);
// Send our command
- conn->say( toSend );
+ conn->say(*requestBuilder->done());
}
// THROWS
@@ -114,9 +123,13 @@ namespace mongo {
"possible socket exception - see logs" );
}
- // A query result is returned from commands
- QueryResult::View recvdQuery = toRecv->singleData().view2ptr();
- *result = BSONObj( recvdQuery.data() );
+ auto reply = rpc::makeReply(toRecv);
+
+ if (conn->getReplyMetadataReader()) {
+ conn->getReplyMetadataReader()(reply->getMetadata(), conn->getServerAddress());
+ }
+
+ *result = reply->getCommandReply();
}
void DBClientMultiCommand::sendAll() {