summaryrefslogtreecommitdiff
path: root/src/mongo/s/stale_exception.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-04-04 11:58:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-04 12:38:14 +0000
commit8798813a699db794ca86e12d518b40dc19eb92ee (patch)
tree1bfd032aa0e1b5fe07cfe25cd66577ff9873902f /src/mongo/s/stale_exception.cpp
parent93b609f94dd58452ba28f277a6739b7740b9980a (diff)
downloadmongo-8798813a699db794ca86e12d518b40dc19eb92ee.tar.gz
SERVER-65160 Make StaleShardVersion as obsolete
Diffstat (limited to 'src/mongo/s/stale_exception.cpp')
-rw-r--r--src/mongo/s/stale_exception.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/mongo/s/stale_exception.cpp b/src/mongo/s/stale_exception.cpp
index 3ea4c75816f..9f201a157b3 100644
--- a/src/mongo/s/stale_exception.cpp
+++ b/src/mongo/s/stale_exception.cpp
@@ -27,8 +27,6 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
#include "mongo/s/stale_exception.h"
#include "mongo/base/init.h"
@@ -43,6 +41,44 @@ MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(StaleDbRoutingVersion);
} // namespace
+void StaleConfigInfo::serialize(BSONObjBuilder* bob) const {
+ bob->append("ns", _nss.ns());
+ _received.appendLegacyWithField(bob, "vReceived");
+ if (_wanted) {
+ _wanted->appendLegacyWithField(bob, "vWanted");
+ }
+
+ invariant(_shardId != "");
+ bob->append("shardId", _shardId.toString());
+}
+
+std::shared_ptr<const ErrorExtraInfo> StaleConfigInfo::parse(const BSONObj& obj) {
+ return std::make_shared<StaleConfigInfo>(parseFromCommandError(obj));
+}
+
+StaleConfigInfo StaleConfigInfo::parseFromCommandError(const BSONObj& obj) {
+ const auto shardId = obj["shardId"].String();
+ invariant(shardId != "");
+
+ auto extractOptionalChunkVersion = [&obj](StringData field) -> boost::optional<ChunkVersion> {
+ try {
+ return boost::make_optional<ChunkVersion>(
+ ChunkVersion::fromBSONLegacyOrNewerFormat(obj, field));
+ } catch (const DBException& ex) {
+ auto status = ex.toStatus();
+ if (status != ErrorCodes::NoSuchKey) {
+ throw;
+ }
+ }
+ return boost::none;
+ };
+
+ return StaleConfigInfo(NamespaceString(obj["ns"].String()),
+ ChunkVersion::fromBSONLegacyOrNewerFormat(obj, "vReceived"),
+ extractOptionalChunkVersion("vWanted"),
+ ShardId(shardId));
+}
+
void StaleDbRoutingVersion::serialize(BSONObjBuilder* bob) const {
bob->append("db", _db);
bob->append("vReceived", _received.toBSON());