diff options
author | Blake Oler <blake.oler@mongodb.com> | 2020-01-06 16:30:23 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-06 16:30:23 +0000 |
commit | ee418d7af4e499a950bbf4b90eca4fed1b08474a (patch) | |
tree | 13c58c11b0598412cf276e045f5b501b6a7104a9 /src/mongo/s/stale_exception.cpp | |
parent | d628d67126fb51cebf8960f4d73816f94f2cb99d (diff) | |
download | mongo-ee418d7af4e499a950bbf4b90eca4fed1b08474a.tar.gz |
SERVER-44587 Modify StaleConfigInfo to take in and store a shard's ID
Diffstat (limited to 'src/mongo/s/stale_exception.cpp')
-rw-r--r-- | src/mongo/s/stale_exception.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/mongo/s/stale_exception.cpp b/src/mongo/s/stale_exception.cpp index 8bc3df2861f..e8f6a9444ee 100644 --- a/src/mongo/s/stale_exception.cpp +++ b/src/mongo/s/stale_exception.cpp @@ -33,28 +33,54 @@ #include "mongo/base/init.h" #include "mongo/util/assert_util.h" - namespace mongo { namespace { MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(StaleConfigInfo); MONGO_INIT_REGISTER_ERROR_EXTRA_INFO(StaleDbRoutingVersion); -boost::optional<ChunkVersion> extractOptionalVersion(const BSONObj& obj, StringData field) { +boost::optional<ChunkVersion> extractOptionalChunkVersion(const BSONObj& obj, StringData field) { auto swChunkVersion = ChunkVersion::parseLegacyWithField(obj, field); if (swChunkVersion == ErrorCodes::NoSuchKey) return boost::none; return uassertStatusOK(std::move(swChunkVersion)); } +boost::optional<ShardId> extractOptionalShardId(const BSONObj& obj, StringData field) { + const auto shardIdElem = obj[field]; + if (shardIdElem.eoo()) { + return boost::none; + } + + const auto shardId = shardIdElem.String(); + if (shardId == "") { + return boost::none; + } + return ShardId(shardId); +} + } // namespace +StaleConfigInfo::StaleConfigInfo(NamespaceString nss, + ChunkVersion received, + boost::optional<ChunkVersion> wanted, + boost::optional<ShardId> shardId, + std::shared_ptr<Notification<void>> criticalSectionSignal) + : _nss(std::move(nss)), + _received(received), + _wanted(wanted), + _shardId(shardId), + _criticalSectionSignal(criticalSectionSignal) {} + void StaleConfigInfo::serialize(BSONObjBuilder* bob) const { bob->append("ns", _nss.ns()); _received.appendLegacyWithField(bob, "vReceived"); if (_wanted) { _wanted->appendLegacyWithField(bob, "vWanted"); } + if (_shardId) { + bob->append("shardId", _shardId->toString()); + } } std::shared_ptr<const ErrorExtraInfo> StaleConfigInfo::parse(const BSONObj& obj) { @@ -64,7 +90,8 @@ std::shared_ptr<const ErrorExtraInfo> StaleConfigInfo::parse(const BSONObj& obj) StaleConfigInfo StaleConfigInfo::parseFromCommandError(const BSONObj& obj) { return StaleConfigInfo(NamespaceString(obj["ns"].String()), uassertStatusOK(ChunkVersion::parseLegacyWithField(obj, "vReceived")), - extractOptionalVersion(obj, "vWanted")); + extractOptionalChunkVersion(obj, "vWanted"), + extractOptionalShardId(obj, "shardId")); } void StaleDbRoutingVersion::serialize(BSONObjBuilder* bob) const { |