summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/client/dbclient.cpp2
-rw-r--r--src/mongo/client/dbclientcursor.cpp2
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp2
-rw-r--r--src/mongo/db/service_entry_point_common.cpp4
-rw-r--r--src/mongo/rpc/SConscript3
-rw-r--r--src/mongo/rpc/legacy_reply_builder.cpp7
-rw-r--r--src/mongo/s/client/parallel.cpp3
-rw-r--r--src/mongo/s/stale_exception.cpp34
-rw-r--r--src/mongo/s/stale_exception.h6
9 files changed, 35 insertions, 28 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 3b551b8ca2c..e5ef508b1db 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -663,7 +663,7 @@ void DBClientBase::findN(vector<BSONObj>& out,
if (c->hasResultFlag(ResultFlag_ShardConfigStale)) {
BSONObj error;
c->peekError(&error);
- uasserted(StaleConfigInfo(error), "findN stale config");
+ uasserted(StaleConfigInfo::parseFromCommandError(error), "findN stale config");
}
for (int i = 0; i < nToReturn; i++) {
diff --git a/src/mongo/client/dbclientcursor.cpp b/src/mongo/client/dbclientcursor.cpp
index 2736023861a..cbd12145399 100644
--- a/src/mongo/client/dbclientcursor.cpp
+++ b/src/mongo/client/dbclientcursor.cpp
@@ -340,7 +340,7 @@ void DBClientCursor::dataReceived(const Message& reply, bool& retry, string& hos
if (qr.getResultFlags() & ResultFlag_ShardConfigStale) {
BSONObj error;
verify(peekError(&error));
- uasserted(StaleConfigInfo(error), "stale config on lazy receive");
+ uasserted(StaleConfigInfo::parseFromCommandError(error), "stale config on lazy receive");
}
/* this assert would fire the way we currently work:
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index fc0c017d160..edbd9a6d315 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -145,7 +145,7 @@ void serializeReply(OperationContext* opCtx,
error.append("code", int(ErrorCodes::StaleShardVersion)); // Different from exception!
{
BSONObjBuilder errInfo(error.subobjStart("errInfo"));
- staleInfo->getVersionWanted().appendLegacyWithField(&errInfo, "vWanted");
+ staleInfo->serialize(&errInfo);
}
} else {
error.append("code", int(status.code()));
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp
index 963bd063fe7..d16532b8bd0 100644
--- a/src/mongo/db/service_entry_point_common.cpp
+++ b/src/mongo/db/service_entry_point_common.cpp
@@ -170,9 +170,7 @@ void generateLegacyQueryErrorResponse(const AssertionException* exception,
err.append("code", exception->code());
if (scex) {
err.append("ok", 0.0);
- err.append("ns", scex->getNss().ns());
- scex->getVersionReceived().appendLegacyWithField(&err, "vReceived");
- scex->getVersionWanted().appendLegacyWithField(&err, "vWanted");
+ scex->serialize(&err);
}
BSONObj errObj = err.done();
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index 35651a9edd6..fff0a749384 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -125,10 +125,11 @@ env.Library(
'legacy_reply_builder.cpp'
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/s/common_s',
+ '$BUILD_DIR/mongo/util/net/network',
'command_reply',
'metadata',
'object_check',
- '$BUILD_DIR/mongo/util/net/network',
],
)
diff --git a/src/mongo/rpc/legacy_reply_builder.cpp b/src/mongo/rpc/legacy_reply_builder.cpp
index 1696ea42902..c2edc42b1cb 100644
--- a/src/mongo/rpc/legacy_reply_builder.cpp
+++ b/src/mongo/rpc/legacy_reply_builder.cpp
@@ -36,6 +36,7 @@
#include "mongo/db/jsobj.h"
#include "mongo/rpc/metadata.h"
#include "mongo/rpc/metadata/sharding_metadata.h"
+#include "mongo/s/stale_exception.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/assert_util.h"
#include "mongo/util/mongoutils/str.h"
@@ -56,12 +57,18 @@ LegacyReplyBuilder& LegacyReplyBuilder::setCommandReply(Status nonOKStatus,
invariant(_state == State::kCommandReply);
if (nonOKStatus == ErrorCodes::StaleConfig) {
_staleConfigError = true;
+ auto scex = nonOKStatus.extraInfo<StaleConfigInfo>();
+
// Need to use the special $err format for StaleConfig errors to be backwards
// compatible.
BSONObjBuilder err;
+
// $err must be the first field in object.
err.append("$err", nonOKStatus.reason());
err.append("code", nonOKStatus.code());
+ if (scex) {
+ scex->serialize(&err);
+ }
err.appendElements(extraErrorInfo);
setRawCommandReply(err.done());
} else {
diff --git a/src/mongo/s/client/parallel.cpp b/src/mongo/s/client/parallel.cpp
index 866ed55b9ac..d4bfddd22df 100644
--- a/src/mongo/s/client/parallel.cpp
+++ b/src/mongo/s/client/parallel.cpp
@@ -1339,7 +1339,8 @@ void throwCursorStale(DBClientCursor* cursor) {
if (cursor->hasResultFlag(ResultFlag_ShardConfigStale)) {
BSONObj error;
cursor->peekError(&error);
- uasserted(StaleConfigInfo(error), "query returned a stale config error");
+ uasserted(StaleConfigInfo::parseFromCommandError(error),
+ "query returned a stale config error");
}
if (NamespaceString(cursor->getns()).isCommand()) {
diff --git a/src/mongo/s/stale_exception.cpp b/src/mongo/s/stale_exception.cpp
index 3c3f63a26ed..8ebe97e75f0 100644
--- a/src/mongo/s/stale_exception.cpp
+++ b/src/mongo/s/stale_exception.cpp
@@ -48,11 +48,6 @@ ChunkVersion extractOptionalVersion(const BSONObj& obj, StringData field) {
} // namespace
-StaleConfigInfo::StaleConfigInfo(const BSONObj& obj)
- : StaleConfigInfo(NamespaceString(obj["ns"].type() == String ? obj["ns"].String() : ""),
- extractOptionalVersion(obj, "vReceived"),
- extractOptionalVersion(obj, "vWanted")) {}
-
void StaleConfigInfo::serialize(BSONObjBuilder* bob) const {
bob->append("ns", _nss.ns());
_received.appendLegacyWithField(bob, "vReceived");
@@ -60,18 +55,14 @@ void StaleConfigInfo::serialize(BSONObjBuilder* bob) const {
}
std::shared_ptr<const ErrorExtraInfo> StaleConfigInfo::parse(const BSONObj& obj) {
- return std::make_shared<StaleConfigInfo>(obj);
+ return std::make_shared<StaleConfigInfo>(parseFromCommandError(obj));
}
-StaleDbRoutingVersion::StaleDbRoutingVersion(const BSONObj& obj)
- : StaleDbRoutingVersion(
- obj["db"].String(),
- DatabaseVersion::parse(IDLParserErrorContext("StaleDbRoutingVersion-vReceived"),
- obj["vReceived"].Obj()),
- !obj["vWanted"].eoo()
- ? DatabaseVersion::parse(IDLParserErrorContext("StaleDbRoutingVersion-vWanted"),
- obj["vWanted"].Obj())
- : boost::optional<DatabaseVersion>{}) {}
+StaleConfigInfo StaleConfigInfo::parseFromCommandError(const BSONObj& obj) {
+ return StaleConfigInfo(NamespaceString(obj["ns"].str()),
+ extractOptionalVersion(obj, "vReceived"),
+ extractOptionalVersion(obj, "vWanted"));
+}
void StaleDbRoutingVersion::serialize(BSONObjBuilder* bob) const {
bob->append("db", _db);
@@ -82,7 +73,18 @@ void StaleDbRoutingVersion::serialize(BSONObjBuilder* bob) const {
}
std::shared_ptr<const ErrorExtraInfo> StaleDbRoutingVersion::parse(const BSONObj& obj) {
- return std::make_shared<StaleDbRoutingVersion>(obj);
+ return std::make_shared<StaleDbRoutingVersion>(parseFromCommandError(obj));
+}
+
+StaleDbRoutingVersion StaleDbRoutingVersion::parseFromCommandError(const BSONObj& obj) {
+ return StaleDbRoutingVersion(
+ obj["db"].String(),
+ DatabaseVersion::parse(IDLParserErrorContext("StaleDbRoutingVersion-vReceived"),
+ obj["vReceived"].Obj()),
+ !obj["vWanted"].eoo()
+ ? DatabaseVersion::parse(IDLParserErrorContext("StaleDbRoutingVersion-vWanted"),
+ obj["vWanted"].Obj())
+ : boost::optional<DatabaseVersion>{});
}
} // namespace mongo
diff --git a/src/mongo/s/stale_exception.h b/src/mongo/s/stale_exception.h
index 001a10ae77f..bfc98c55ec7 100644
--- a/src/mongo/s/stale_exception.h
+++ b/src/mongo/s/stale_exception.h
@@ -41,8 +41,6 @@ public:
StaleConfigInfo(NamespaceString nss, ChunkVersion received, ChunkVersion wanted)
: _nss(std::move(nss)), _received(received), _wanted(wanted) {}
- StaleConfigInfo(const BSONObj& commandError);
-
const auto& getNss() const {
return _nss;
}
@@ -57,6 +55,7 @@ public:
void serialize(BSONObjBuilder* bob) const override;
static std::shared_ptr<const ErrorExtraInfo> parse(const BSONObj&);
+ static StaleConfigInfo parseFromCommandError(const BSONObj& commandError);
private:
NamespaceString _nss;
@@ -74,8 +73,6 @@ public:
boost::optional<DatabaseVersion> wanted)
: _db(std::move(db)), _received(received), _wanted(wanted) {}
- StaleDbRoutingVersion(const BSONObj& commandError);
-
const auto& getDb() const {
return _db;
}
@@ -90,6 +87,7 @@ public:
void serialize(BSONObjBuilder* bob) const override;
static std::shared_ptr<const ErrorExtraInfo> parse(const BSONObj&);
+ static StaleDbRoutingVersion parseFromCommandError(const BSONObj& commandError);
private:
std::string _db;