summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2015-11-23 16:56:37 -0500
committerSpencer T Brody <spencer@mongodb.com>2015-11-24 15:54:45 -0500
commit3b3ef4253a6c5d5d3f18127ac2272a9696488aec (patch)
treeda41cacce7c7baa8bd0960bfb68bae950acad474 /src
parent0377c359a6f105ecbec54a7723590235a4e86998 (diff)
downloadmongo-3b3ef4253a6c5d5d3f18127ac2272a9696488aec.tar.gz
SERVER-21603 Revert to old format for gleStats if being talked to by an old mongosr3.2.0-rc4
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/dbcommands.cpp2
-rw-r--r--src/mongo/rpc/legacy_reply_builder.cpp2
-rw-r--r--src/mongo/rpc/metadata/sharding_metadata.cpp10
-rw-r--r--src/mongo/rpc/metadata/sharding_metadata.h6
-rw-r--r--src/mongo/rpc/metadata/sharding_metadata_test.cpp6
5 files changed, 15 insertions, 11 deletions
diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp
index f328296e347..f73b0a186dd 100644
--- a/src/mongo/db/dbcommands.cpp
+++ b/src/mongo/db/dbcommands.cpp
@@ -1446,7 +1446,7 @@ bool Command::run(OperationContext* txn,
// TODO: refactor out of here as part of SERVER-18326
if (isShardingAware || serverGlobalParams.configsvr) {
rpc::ShardingMetadata(lastOpTimeFromClient, replCoord->getElectionId())
- .writeToMetadata(&metadataBob);
+ .writeToMetadata(&metadataBob, request.getProtocol());
}
}
diff --git a/src/mongo/rpc/legacy_reply_builder.cpp b/src/mongo/rpc/legacy_reply_builder.cpp
index 393c3bb3519..609a9483eea 100644
--- a/src/mongo/rpc/legacy_reply_builder.cpp
+++ b/src/mongo/rpc/legacy_reply_builder.cpp
@@ -100,7 +100,7 @@ LegacyReplyBuilder& LegacyReplyBuilder::setMetadata(const BSONObj& metadata) {
// because we already have skipped some bytes for the message header.
BSONObjBuilder resumedBuilder(
BSONObjBuilder::ResumeBuildingTag(), _builder, sizeof(QueryResult::Value));
- shardingMetadata.getValue().writeToMetadata(&resumedBuilder);
+ shardingMetadata.getValue().writeToMetadata(&resumedBuilder, Protocol::kOpQuery);
}
_state = State::kOutputDocs;
return *this;
diff --git a/src/mongo/rpc/metadata/sharding_metadata.cpp b/src/mongo/rpc/metadata/sharding_metadata.cpp
index d04b30fb6c5..a7a926b2868 100644
--- a/src/mongo/rpc/metadata/sharding_metadata.cpp
+++ b/src/mongo/rpc/metadata/sharding_metadata.cpp
@@ -94,9 +94,11 @@ StatusWith<ShardingMetadata> ShardingMetadata::readFromMetadata(const BSONObj& m
return ShardingMetadata(opTime, lastElectionIdElem.OID());
}
-Status ShardingMetadata::writeToMetadata(BSONObjBuilder* metadataBob) const {
+Status ShardingMetadata::writeToMetadata(BSONObjBuilder* metadataBob,
+ rpc::Protocol protocol) const {
BSONObjBuilder subobj(metadataBob->subobjStart(kGLEStatsFieldName));
- if (getLastOpTime().getTerm() > repl::OpTime::kUninitializedTerm) {
+ if (getLastOpTime().getTerm() > repl::OpTime::kUninitializedTerm &&
+ protocol == Protocol::kOpCommandV1) {
getLastOpTime().append(&subobj, kGLEStatsLastOpTimeFieldName);
} else {
subobj.append(kGLEStatsLastOpTimeFieldName, getLastOpTime().getTimestamp());
@@ -115,7 +117,7 @@ Status ShardingMetadata::downconvert(const BSONObj& commandReply,
// We can reuse the same logic to write the sharding metadata out to the legacy
// command as the element has the same format whether it is there or on the metadata
// object.
- swShardingMetadata.getValue().writeToMetadata(legacyCommandReplyBob);
+ swShardingMetadata.getValue().writeToMetadata(legacyCommandReplyBob, Protocol::kOpQuery);
} else if (swShardingMetadata.getStatus() == ErrorCodes::NoSuchKey) {
// It is valid to not have a $gleStats field.
} else {
@@ -131,7 +133,7 @@ Status ShardingMetadata::upconvert(const BSONObj& legacyCommand,
// as it has the same format whether it is there or on the metadata object.
auto swShardingMetadata = readFromMetadata(legacyCommand);
if (swShardingMetadata.isOK()) {
- swShardingMetadata.getValue().writeToMetadata(metadataBob);
+ swShardingMetadata.getValue().writeToMetadata(metadataBob, Protocol::kOpCommandV1);
// Write out the command excluding the $gleStats subobject.
for (const auto& elem : legacyCommand) {
diff --git a/src/mongo/rpc/metadata/sharding_metadata.h b/src/mongo/rpc/metadata/sharding_metadata.h
index cf7dd0019df..9dc5fd6f9ba 100644
--- a/src/mongo/rpc/metadata/sharding_metadata.h
+++ b/src/mongo/rpc/metadata/sharding_metadata.h
@@ -29,6 +29,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/db/repl/optime.h"
+#include "mongo/rpc/protocol.h"
namespace mongo {
class BSONObj;
@@ -53,8 +54,11 @@ public:
/**
* Writes ShardingMetadata to a metadata builder.
+ * If protocol is OP_QUERY, write the metadata in the old format recognizable by 3.0 mongos.
+ * TODO(SERVER-21631): Remove the 'protocol' argument and downconversion logic from this method
+ * after 3.2 is out.
*/
- Status writeToMetadata(BSONObjBuilder* metadataBob) const;
+ Status writeToMetadata(BSONObjBuilder* metadataBob, rpc::Protocol protocol) const;
/**
* Rewrites the ShardingMetadata from the legacy OP_QUERY format to the metadata object
diff --git a/src/mongo/rpc/metadata/sharding_metadata_test.cpp b/src/mongo/rpc/metadata/sharding_metadata_test.cpp
index 9f4fc13914e..cf76750ab94 100644
--- a/src/mongo/rpc/metadata/sharding_metadata_test.cpp
+++ b/src/mongo/rpc/metadata/sharding_metadata_test.cpp
@@ -206,10 +206,8 @@ TEST(ShardingMetadata, Downconvert) {
BSON("$gleStats" << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t"
<< kLastOpTime.getTerm())
<< "electionId" << kElectionId)),
- BSON("ok" << 1 << "$gleStats"
- << BSON("lastOpTime" << BSON("ts" << kLastOpTime.getTimestamp() << "t"
- << kLastOpTime.getTerm()) << "electionId"
- << kElectionId)));
+ BSON("ok" << 1 << "$gleStats" << BSON("lastOpTime" << kLastOpTime.getTimestamp()
+ << "electionId" << kElectionId)));
}
{ checkDownconvert(BSON("ok" << 1), BSONObj(), BSON("ok" << 1)); }
}