diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-04-06 13:48:53 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-04-12 08:57:13 -0400 |
commit | 999ec2fca89384f57b3fe0468ee7b57c40dabf14 (patch) | |
tree | 4ae0d9f798c2768174d89e4464702c79093d8deb /src/mongo/rpc | |
parent | 9cc021793df988637ec07dd68abc8ae4acff45c8 (diff) | |
download | mongo-999ec2fca89384f57b3fe0468ee7b57c40dabf14.tar.gz |
SERVER-28663 rename config server metadata from configsvr to $configsvr
This is prep for OP_MSG where "configsvr" conflicts with a field of the same
name in the reply to isMaster. OP_COMMAND will continue to use the old name
since it will only be used to communicate with older nodes.
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r-- | src/mongo/rpc/command_reply.cpp | 17 | ||||
-rw-r--r-- | src/mongo/rpc/command_reply_builder.cpp | 12 | ||||
-rw-r--r-- | src/mongo/rpc/command_request.cpp | 14 | ||||
-rw-r--r-- | src/mongo/rpc/command_request_builder.cpp | 12 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/config_server_metadata.h | 2 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/config_server_metadata_test.cpp | 2 |
6 files changed, 52 insertions, 7 deletions
diff --git a/src/mongo/rpc/command_reply.cpp b/src/mongo/rpc/command_reply.cpp index c5ff1b9ab78..884a63fae61 100644 --- a/src/mongo/rpc/command_reply.cpp +++ b/src/mongo/rpc/command_reply.cpp @@ -55,8 +55,21 @@ CommandReply::CommandReply(const Message* message) : _message(message) { _commandReply = uassertStatusOK(cur.readAndAdvance<Validated<BSONObj>>()).val; _commandReply.shareOwnershipWith(message->sharedBuffer()); - _metadata = uassertStatusOK(cur.readAndAdvance<Validated<BSONObj>>()).val; - _metadata.shareOwnershipWith(message->sharedBuffer()); + + // OP_COMMAND is only used when communicating with 3.4 nodes and they serialize their metadata + // fields differently. We do all up- and down-conversion here so that the rest of the code only + // has to deal with the current format. + auto rawMetadata = uassertStatusOK(cur.readAndAdvance<Validated<BSONObj>>()).val; + BSONObjBuilder metadataBuilder; + for (auto elem : rawMetadata) { + if (elem.fieldNameStringData() == "configsvr") { + metadataBuilder.appendAs(elem, "$configServerState"); + } else { + metadataBuilder.append(elem); + } + } + _metadata = metadataBuilder.obj(); + uassert(40420, "OP_COMMAND reply contains trailing bytes following metadata", cur.empty()); } diff --git a/src/mongo/rpc/command_reply_builder.cpp b/src/mongo/rpc/command_reply_builder.cpp index b47b0545c80..001522163ce 100644 --- a/src/mongo/rpc/command_reply_builder.cpp +++ b/src/mongo/rpc/command_reply_builder.cpp @@ -65,7 +65,17 @@ BSONObjBuilder CommandReplyBuilder::getInPlaceReplyBuilder(std::size_t reserveBy CommandReplyBuilder& CommandReplyBuilder::setMetadata(const BSONObj& metadata) { invariant(_state == State::kMetadata); - metadata.appendSelfToBufBuilder(_builder); + // OP_COMMAND is only used when communicating with 3.4 nodes and they serialize their metadata + // fields differently. We do all up- and down-conversion here so that the rest of the code only + // has to deal with the current format. + BSONObjBuilder bob(_builder); + for (auto elem : metadata) { + if (elem.fieldNameStringData() == "$configServerState") { + bob.appendAs(elem, "configsvr"); + } else { + bob.append(elem); + } + } _state = State::kOutputDocs; return *this; } diff --git a/src/mongo/rpc/command_request.cpp b/src/mongo/rpc/command_request.cpp index 024b8ebe9c1..98df6c3ed84 100644 --- a/src/mongo/rpc/command_request.cpp +++ b/src/mongo/rpc/command_request.cpp @@ -110,8 +110,20 @@ CommandRequest::CommandRequest(const Message* message) : _message(message) { << '\'', _commandArgs.firstElementFieldName() == _commandName); + // OP_COMMAND is only used when communicating with 3.4 nodes and they serialize their metadata + // fields differently. We do all up- and down-conversion here so that the rest of the code only + // has to deal with the current format. uassertStatusOK(cur.readAndAdvance<>(&obj)); - _metadata = std::move(obj.val); + BSONObjBuilder metadataBuilder; + for (auto elem : obj.val) { + if (elem.fieldNameStringData() == "configsvr") { + metadataBuilder.appendAs(elem, "$configServerState"); + } else { + metadataBuilder.append(elem); + } + } + _metadata = metadataBuilder.obj(); + uassert(40419, "OP_COMMAND request contains trailing bytes following metadata", cur.empty()); } diff --git a/src/mongo/rpc/command_request_builder.cpp b/src/mongo/rpc/command_request_builder.cpp index 11b25beef6e..34f6daa0888 100644 --- a/src/mongo/rpc/command_request_builder.cpp +++ b/src/mongo/rpc/command_request_builder.cpp @@ -70,7 +70,17 @@ CommandRequestBuilder& CommandRequestBuilder::setCommandArgs(BSONObj commandArgs CommandRequestBuilder& CommandRequestBuilder::setMetadata(BSONObj metadata) { invariant(_state == State::kMetadata); - metadata.appendSelfToBufBuilder(_builder); + // OP_COMMAND is only used when communicating with 3.4 nodes and they serialize their metadata + // fields differently. We do all up- and down-conversion here so that the rest of the code only + // has to deal with the current format. + BSONObjBuilder bob(_builder); + for (auto elem : metadata) { + if (elem.fieldNameStringData() == "$configServerState") { + bob.appendAs(elem, "configsvr"); + } else { + bob.append(elem); + } + } _state = State::kInputDocs; return *this; } diff --git a/src/mongo/rpc/metadata/config_server_metadata.h b/src/mongo/rpc/metadata/config_server_metadata.h index 7865281ad26..9369f6d949e 100644 --- a/src/mongo/rpc/metadata/config_server_metadata.h +++ b/src/mongo/rpc/metadata/config_server_metadata.h @@ -83,7 +83,7 @@ public: } static StringData fieldName() { - return "configsvr"; + return "$configServerState"; } private: diff --git a/src/mongo/rpc/metadata/config_server_metadata_test.cpp b/src/mongo/rpc/metadata/config_server_metadata_test.cpp index 6d8749ac495..0b2d649e52d 100644 --- a/src/mongo/rpc/metadata/config_server_metadata_test.cpp +++ b/src/mongo/rpc/metadata/config_server_metadata_test.cpp @@ -48,7 +48,7 @@ TEST(ConfigSvrMetadataTest, Roundtrip) { metadata.writeToMetadata(&builder); BSONObj expectedObj( - BSON("configsvr" << BSON( + BSON("$configServerState" << BSON( "opTime" << BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm())))); BSONObj serializedObj = builder.obj(); |