diff options
author | Marcos José Grillo Ramírez <marcos.grillo@10gen.com> | 2020-01-08 13:40:24 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2020-01-08 13:40:24 +0000 |
commit | 7604dad6da718751ad1f04bae1c839e87a1f8651 (patch) | |
tree | b6faa83f091654734f2be451ed673aca845247d5 /src/mongo/s | |
parent | 7b9cc569b327f2b396ddd10f6c1428ab36d4bf07 (diff) | |
download | mongo-7604dad6da718751ad1f04bae1c839e87a1f8651.tar.gz |
SERVER-44598 Shards do not treat the IGNORED version as "intended sharded"
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/chunk_version.cpp | 16 | ||||
-rw-r--r-- | src/mongo/s/chunk_version.h | 22 | ||||
-rw-r--r-- | src/mongo/s/write_ops/write_op.cpp | 1 |
3 files changed, 36 insertions, 3 deletions
diff --git a/src/mongo/s/chunk_version.cpp b/src/mongo/s/chunk_version.cpp index 3f25d474a4a..80d545328fc 100644 --- a/src/mongo/s/chunk_version.cpp +++ b/src/mongo/s/chunk_version.cpp @@ -80,6 +80,13 @@ StatusWith<ChunkVersion> ChunkVersion::fromBSON(const BSONObj& obj) { version._epoch = epochPart.OID(); } + if (it.more()) { + // Expect _canThrowSSVOnIgnored + BSONElement canThrowSSVOnIgnoredPart = it.next(); + + version._canThrowSSVOnIgnored = canThrowSSVOnIgnoredPart && canThrowSSVOnIgnoredPart.Bool(); + } + return version; } @@ -117,6 +124,9 @@ void ChunkVersion::appendWithField(BSONObjBuilder* out, StringData field) const BSONArrayBuilder arr(out->subarrayStart(field)); arr.appendTimestamp(_combined); arr.append(_epoch); + if (_canThrowSSVOnIgnored) { + arr.append(_canThrowSSVOnIgnored); + } } void ChunkVersion::appendLegacyWithField(BSONObjBuilder* out, StringData field) const { @@ -128,6 +138,9 @@ BSONObj ChunkVersion::toBSON() const { BSONArrayBuilder b; b.appendTimestamp(_combined); b.append(_epoch); + if (_canThrowSSVOnIgnored) { + b.append(_canThrowSSVOnIgnored); + } return b.arr(); } @@ -136,7 +149,8 @@ void ChunkVersion::legacyToBSON(StringData field, BSONObjBuilder* out) const { } std::string ChunkVersion::toString() const { - return str::stream() << majorVersion() << "|" << minorVersion() << "||" << _epoch; + return str::stream() << majorVersion() << "|" << minorVersion() << "||" << _epoch + << (_canThrowSSVOnIgnored ? "|||canThrowSSVOnIgnored" : ""); } } // namespace mongo diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h index fea48dc0ace..12628629d3b 100644 --- a/src/mongo/s/chunk_version.h +++ b/src/mongo/s/chunk_version.h @@ -56,11 +56,12 @@ public: */ static constexpr StringData kShardVersionField = "shardVersion"_sd; - ChunkVersion() : _combined(0), _epoch(OID()) {} + ChunkVersion() : _combined(0), _epoch(OID()), _canThrowSSVOnIgnored(false) {} ChunkVersion(uint32_t major, uint32_t minor, const OID& epoch) : _combined(static_cast<uint64_t>(minor) | (static_cast<uint64_t>(major) << 32)), - _epoch(epoch) {} + _epoch(epoch), + _canThrowSSVOnIgnored(false) {} static StatusWith<ChunkVersion> parseFromCommand(const BSONObj& obj) { return parseWithField(obj, kShardVersionField); @@ -134,6 +135,14 @@ public: version.epoch() == IGNORED().epoch(); } + /** + * Indicates that the shard version checking must be skipped but StaleShardVersion error + * must be thrown if the metadata is not loaded + */ + void canThrowSSVOnIgnored() { + _canThrowSSVOnIgnored = true; + } + void incMajor() { uassert( 31180, @@ -175,6 +184,9 @@ public: return _epoch; } + const bool getCanThrowSSVOnIgnored() const { + return _canThrowSSVOnIgnored; + } // // Explicit comparison operators - versions with epochs have non-trivial comparisons. // > < operators do not check epoch cases. Generally if using == we need to handle @@ -251,6 +263,12 @@ public: private: uint64_t _combined; OID _epoch; + + /** + * Temporary flag to indicate shards that a router is able to process and retry + * multi-write operations. This should be removed by 4.4 + */ + bool _canThrowSSVOnIgnored; }; inline std::ostream& operator<<(std::ostream& s, const ChunkVersion& v) { diff --git a/src/mongo/s/write_ops/write_op.cpp b/src/mongo/s/write_ops/write_op.cpp index 85a547e84c5..822b9578268 100644 --- a/src/mongo/s/write_ops/write_op.cpp +++ b/src/mongo/s/write_ops/write_op.cpp @@ -99,6 +99,7 @@ Status WriteOp::targetWrites(OperationContext* opCtx, // can't retry half a regular multi-write. if (endpoints.size() > 1u && !inTransaction) { endpoint.shardVersion = ChunkVersion::IGNORED(); + endpoint.shardVersion.canThrowSSVOnIgnored(); } targetedWrites->push_back(new TargetedWrite(std::move(endpoint), ref)); |